;
;  MEMORY.MAC - Memory Operations
;
;  @  2!  !  C@  C!  2@  +!  MOVE  FILL  ERASE  ON  OFF
;  TOGGLE
;

;	@  ( a-addr -- x )

	hdr	1,'@'
at:	pop	hl
at1:	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	push	de
	jp	next

;	2!  ( x1 x2 a-addr -- )

	hdr	1,'2!'
tstor:	pop	hl
tstor1:	pop	de
	ld	(hl),e
	inc	hl
	ld	(hl),d
	inc	hl
;	jp	store1
	ignore1

;	!  ( x a-addr -- )

	hdr	1,'!'
store:	pop	hl
store1:	pop	de
store2:	ld	(hl),e
	inc	hl
	ld	(hl),d
	jp	next

;	C@  ( c-addr -- char )

	hdr	1,'C@'
cat:	pop	hl
	ld	l,(hl)
	ld	h,0
	jp	hpush

;	C!  ( char c-addr -- )

	hdr	1,'C!'
cstor:	pop	hl
	pop	de
cstor1:	ld	(hl),e
	jp	next

;	2@  ( a-addr -- x1 x2 )

	hdr	1,'2@'
tat:	pop	hl
tat1:	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	inc	hl
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a
	ex	de,hl
	jp	dpush

;	+!  ( x a-addr -- )

	hdr	1,'+!'
pstor:	pop	hl
	pop	de
pstor1:	ld	a,(hl)
	add	a,e
	ld	(hl),a
	inc	hl
	ld	a,(hl)
	adc	a,d
	ld	(hl),a
	jp	next

;	MOVE  ( addr1 addr2 u -- )

	hdr	1,'MOVE'	; ANS
move:	ld	l,c
	ld	h,b
	pop	bc
	pop	de
	ex	(sp),hl
	call	bmove
	pop	bc
	jp	next

;	ERASE  ( addr u -- )

	hdr	1,'ERASE'
erase:	ld	e,0
;	jp	fill1
	ignore1

;	FILL  ( c-addr u char -- )

	hdr	1,'FILL'
fill:	pop	de
fill1:	ld	l,c
	ld	h,b
	pop	bc
	ex	(sp),hl
	jp	fill3

fill2:	ld	(hl),e
	inc	hl
	dec	bc
fill3:	ld	a,c
	or	b
	jp	nz,fill2
	pop	bc
	jp	next

;	ON  ( addr -- )		-1 swap !

	hdr	1,'ON'
on:	pop	hl
on1:	ld	de,-1
	jp	store2

;	OFF  ( addr -- )	0 swap !

	hdr	1,'OFF'
off:	pop	hl
off1:	ld	de,0
	jp	store2

;	TOGGLE  ( c-addr x -- )

	hdr	1,'TOGGLE'
toggl:	pop	de
	pop	hl
toggl1:	ld	a,(hl)
	xor	e
	ld	(hl),a
	jp	next

;	end

