Here's my code from Buttonz for reading/creating a highscore app var:
Code:
;*Load High Scores*
Load:
;before we do anything crazy, get a pointer to the high score data
ld hl,VarName ;find or create high score appvar
bcall(_Mov9ToOP1)
bcall(_ChkFindSym)
jr nc,VarFound
CreateVar:
ld hl,VarName
bcall(_Mov9ToOP1)
ld hl,70 ;high score app var is 70 bytes long (old = 65)
bcall(_CreateAppVar) ;expecting os to handle a memory error
push de
inc de
inc de
ld hl,InitHighScoreData
ld bc,70
ldir
pop de
jr VarInRam
VarFound:
ld a,b
or a
jr z,VarInRam
ld hl,VarName
bcall(_Mov9ToOP1)
bcall(_Arc_Unarc) ;expecting os to handle a memory error
jr Load ;find again in ram
VarInRam:
inc de ;skip over size
inc de
ld (HighScoreTable),de ;store pointer to HighScoreTable
;Appvar info
VarName:
.db $15,"ButtonzD",0
InitHighScoreData:
.db "ASM BANDIT",0
.dw 9936
.db 11
.db "**********", 0,0,0,0
.db "**********", 0,0,0,0
.db "**********", 0,0,0,0
.db "**********", 0,0,0,0
HighScoreTable: ;points to start of high score data
.dw 0
Here's my code from Buttonz for reading keystrokes:
Code:
;--- UpdateKeys ---
;Stores pressed keys to KeyFlag
;doesnt allow repeating keypresses
ld a,$fe ; a=(||||,up,right,left,down)
out (KeypadPort),a
nop
nop
nop
nop
nop
nop
nop
nop
in a,(KeypadPort)
and $06 ; a=(|||||,right,left,|)
rra ; a=(||||||,right,left)
ld b,a
ld a,$ff
out (KeypadPort),a
nop
nop
nop
nop
nop
nop
nop
nop
ld a,$bf ; a=(||,2nd,f1,f2,f3,f4,f5)
out (KeypadPort),a
nop
nop
nop
nop
nop
nop
nop
nop
in a,(KeypadPort)
rla
rla
rla ; a=(f1,f2,f3,f4,f5,|||)
rl b ; b=(|||||,right,left,2nd)
and $f8
or b ; a=(f1,f2,f3,f4,f5,right,left,2nd)
ld b,a ;reset bit = button pressed
ld a,$ff
out (KeypadPort),a
ld a,(OldKey)
xor 255
or b ;ignore key while held down
ld c,a
ld a,(KeyFlag)
and c ;keep key clear if not acknowledged but add any new presses
ld (KeyFlag),a ;reset bit = button pressed
ld a,b
ld (OldKey),a
reti ;performed during interrupt (doesn't have to be though!)
MainKeyLoop:
xor a
ei
halt
di
or a
jp nz,Exit
in a,(IntStatusPort) ;have on button exit immediately out of program
bit 3,a
jp z,Exit
ld a,(KeyFlag)
bit KF1,a
call z,C1Press ;use calls to read simultaneous presses must save a!
bit KF2,a
call z,C2Press
bit KF3,a
call z,C3Press
bit KF4,a
call z,C4Press
bit KF5,a
call z,C5Press
bit KLeft,a
call z,ShiftLeft
bit KRight,a
call z,ShiftRight
bit K2nd,a
call z,IncreaseLevel ;2nd now skips level
ld a,(UpdateFlag)
or a
call nz,UpdateBlocks ;addblock is called during update if needed
ld a,(DrawFlag)
or a
call nz,DrawBlocks
jr MainKeyLoop
KeyFlag: ;read to get keypresses
.db 0
OldKey: ;prevents buttons from being held down
.db 0
For the computer app I would write a program using VC++ where I could enter text that would save it as an appvar (basically just create a file header, throw in the text, write the checksum).
[/code]