A86: Re: getting op1 into a and more


[Prev][Next][Index][Thread]

A86: Re: getting op1 into a and more




1) Use _FINDSYM (rst 10h) to find the variable, then use the ABS addressing
commands to copy the variable to a more usable location like ram page 1:

loaddata:
 ld hl,mapvar-1		; point to var name (first byte is irrelevant)
 rst 20h		        ; load name into OP1
 rst 10h		        ; call _FINDSYM
 ret c 			; if it doesn't exist, return from program
 ld a,b			; copy high byte
 ex de,hl		; swap low bytes
 call $4c3f 		; skip length word (ahl += 2)
 call _SET_ABS_SRC_ADDR	; set the source address as the var
 ld a,1			; copy to ram page 1
 ld hl,Map-$8000	        ; start at $8000 on page 1 (page 1 is at $10000
ABS)
 call _SET_ABS_DEST_ADDR ; set the destination as ram page 1
 xor a			; clear high byte
 ld hl,4096		; size of string var
 call _SET_MM_NUM_BYTES	; set the number of bytes to copy
 call _mm_ldir		; copy the map
 call _RAM_PAGE_1	; make sure ram page 1 is still loaded
 jr dataloaded		; put mapvar somewhere else so you don't have
mapvar:			; to jump over it--I just like to keep it together
 .db 8,"cnc86map"	; so it's easy to find, and besides, this routine
dataloaded:		; is just a little hack anyway...

2) call _CONVOP1

3) Use program write-back.  I learned how from ZTetris (thanks Jimmy!).
Here's a little routine I wrote to copy a block of data you have in your
program (.db's) back to the program's variable so that they stay the same
when you reload the program.  This can be very useful if you let the user
change the settings and want them to stay between uses.  Put all your
setting variables between SettingData and SettingDataEnd:

SaveSettings:
 ld hl,ProgName		        ; point to program name
 rst 20h			        ; load into OP1 with _MOV10TOOP1
 rst 10h			        ; find it with _FINDSYM
 ex de,hl		        ; point to start of variable
 ld a,b			        ; get top of absolute pointer
 ld de,SettingData-$d748+4	; relative offset - 4
 add hl,de			; form pointer to var
 adc a,0			        ; add carry
 ld de,SettingData		; point to data in _asm_exec_ram
 ld b,SettingDataEnd-SettingData ; copy entire length of SettingData
SaveSettingsL:
 call _GETB_AHL			; convert abs pointer
 ld a,(de)			; read value
 ld (hl),a			; save new value to variable
 call _inc_ptr_ahl		; move to next destination byte
 djnz SaveSettingsL		; loop for all bytes
ProgName:
 .db $12,5,"CnC86"

SettingData:
PlayCount:
 .dw 1
SettingDataEnd:

>
>First, how do I use an on-calc variable in my program?  Second how do I get

>OP1 into a.  Third how do I get a into the on-calc variable?  I don't mean
a
>.db variable, I mean a variable that will stay on the calc after the prog
is
>done running...

--
David Phillips <david@acz.org>
http://www.acz.org/