0 Members and 3 Guests are viewing this topic.
Hi-Score: .db 496Achievements: .db 1Whatever: .db 9999
ld hl, AppVarName ;ld hl with the string for the name of the appvarrst 20h ;move 9 to op1, takes the data at hl, and moves it into op1ld hl, [size of appvar] ;size of appvar, self explanitorybcall _createappvar ;this creates an appvar with the name at HLld hl, de ;de points to the data structure for the newly created appvarinc hl \ inc hl ;iirc HL starts at the spot where the size bytes are, so you need to inc hl past themld (hl), first byte of data inc hlld (hl), second byte of data;etc, I'm sure there is a better routine to do that than lding data at hl, and incrementing though >.<retAppVarName: .db 06h,[some other byte, sorry I'll look it up in a second],"AppvarAA",0 ;06h is the appvar data type byte iirc
getAppVar: ld hl, appVarName rst 20h ;move9ToOp1 bcall(_chkFindSym) jr nc, found ld hl, size push hl bcall(_createAppVar) inc de ;skip size bytes inc de ex de, hl pop bc bcall(_clearMem) ;fills hl with bc 0's jr getAppVarfound: ld a, b or a jr z, inRam bcall(_arc_unarc) jr getAppVarinRam: inc de inc de retappVarName: .db appVarObj, "appVar", 0, 0 ; 15h
@Jerros, here is a nice routine to get you to the start of the appVar. It will create it if it doesn't exist, and it will unarchive it if it's archived.Code: [Select]getAppVar: ld hl, appVarName rst 20h ;move9ToOp1 bcall(_chkFindSym) jr nc, found ld hl, size push hl bcall(_createAppVar) inc de ;skip size bytes inc de ex de, hl pop bc bcall(_clearMem) ;fills hl with bc 0's jr getAppVarfound: ld a, b or a jr z, inRam bcall(_arc_unarc) jr getAppVarinRam: inc de inc de retappVarName: .db appVarObj, "appVar", 0, 0 ; 15hJust be sure to archive it when you program quits.
bcall(_createAppVar)Code: [Select] bcall(_clearMem) ;fills hl with bc 0's
bcall(_clearMem) ;fills hl with bc 0's
getAppVar: ld hl, CHData rst 20h bcall(_chkFindSym) jr nc, found ; AppVar exists ld hl, 500 ; Size of AppVar, random. bcall(_createAppVar) JR RestOfProgrammfound: ; Unarchive if not already ld hl, CHData rst 20h bcall(_chkfindsym) ld a, b or a bcallnz(_arc_unarc) ;only unrchive if not already in RAM jr RestOfProgrammCHData: .db appVarObj, "CHData ", 0, 0RestOfProgramm:.........quit: ld hl, CHData rst 20h bcall(_chkfindsym) ld a, b or a bcallz(_arc_unarc) b_call _JforceCmdNoChaR
ld hl, name rst 20h bcall(_chkFindSym) inc de inc de ex de, hl ld (hl), a inc hl ld (hl), b inc hl ld (hl), c inc hl ld de, (score) ld (hl), e inc hl ld (hl), d
dataStart equ appBackUpScreenenemyBuf equ dataStart ;256bulletBuf equ enemyBuf+256 ;256score equ bulletBuf+256 ;2lives equ score+2 ;1reload equ lives+1 ;1dataEnd equ reload+1 ;1 ld hl, name rst 20h bcall(_chkFindSym) inc de inc de ld hl, dataStart ld bc, dataEnd-dataStart ldir
Code: [Select] ld (hl), a inc hl ld (hl), b inc hl ld (hl), c inc hl ld de, (score) ld (hl), e inc hl ld (hl), d
ld (hl), a inc hl ld (hl), b inc hl ld (hl), c inc hl ld de, (score) ld (hl), e inc hl ld (hl), d
;To read form the appvar:call Routine_that_Gets_pointer_of_appvar_in_HLld de,AppDataStartld bc,AppDataEnd-AppDataStart ;Size of dataldir ;copy the appvar TO your data;If appvar wasn't found, fill the data area with default valuesld hl,DefaultDataStartld de,AppDataStartld bc,AppDataEnd-AppDataStart ;Size of dataldir ;copy the default TO your data;To write to your appvar:call Routine_that_Gets_pointer_of_appvar_in_HLex de,hlld hl,AppDataStartld bc,AppDataEnd-AppDataStart ;Size of dataldir ;copy the data TO the appvar;This is how I hold my variables using this macro I made:#define VAR(name,size) name: \ .org name+(size).org SomeFreeRamLocationAppDataStart:VAR(MyVar1,1) ;A one byte variableVAR(MyWord,2) ;A two byte variableVAR(MyArray,100) ;A 100 byte arrayAppDataEnd:
;To create if none exists, and unarchive if it does: ld hl, "NameOfAppVar" rst 20h bcall(_chkFindSym) jr nc, found ld hl, "random size" bcall(_createAppVar) JR Programmfound: ld hl, "NameOfAppVar" rst 20h bcall(_chkfindsym) ld a, b or a bcallnz(_arc_unarc)Programm:............;And archiving it again upon exitingquit: ld hl, CHData rst 20h bcall(_chkfindsym) ld a, b or a bcallz(_arc_unarc) b_call _JforceCmdNoChaR;To store numbers: ld hl, "NameOfAppVar" rst 20h bcall(_chkFindSym) inc de inc de ex de, hl ld a, "Number to be stored" ld (hl), a inc HL inc HL ;whatever many times needed, depending on the size of the previous number stored inc HL ld a, "Another number to be stored" ld (hl), a ; ect ect ect ; ; To read from the Var, I use the same lines as the "To store numbers:" part, just switch around (hl) and a.
cp 3 call z, label
or a sbc hl, de add hl, de
Yes, calls can be conditional. They can also use all the conditions not just z nz c nc. Like m for negative or p for positive.Also, you only need one inc hl after you write a variable to memory. That's because A is one byte, ld (hl), a stores one byte, so you only need to increase one byte. If you have a bigger number to store, you have to split it into bytes. So DE is stored E then D.
Code: [Select] or a sbc hl, de add hl, de
or a sbc hl, de add hl, de JR "condition", "Label-DE-is-Bigger".....code DE-and-HL-were-equal-or-HL-was-Bigger.....