Soooooo, I want to store my games data in an appvar in archive. So far I got the app to create the appvar in ram. On archiving it somehow freezes my calc, after resetting it the appvar is in archive.
Anyways, here's my code:

Code:

   ; load appvar
   ld hl,AppVarName
   bcall(_Mov9toOp1)
   bcall(_ChkFindSym)
   jr c,_Run_No_AppVar
   
   ld a,b
   or a
   jr nz,_Run_AppVar_in_Flash
   
   di
   
   ld hl,AppVarName
   
   bcall(_Mov9toOp1)
   bcall(_Arc_Unarc)
   
   ei
   ;bcall(_ChkFindSym)
   
   ld a,b
_Run_AppVar_in_Flash:
   
   
   ex de,hl
   
   ld bc,23
   ld de,reuben
   ;bcall(_FlashToRAM)
   jr {+1@}
_Run_No_AppVar:
   ld hl,AppVarName ; create the appvar
   rst rMov9ToOP1
   ld hl,23
   bcall(_CreateAppVar)
   inc de ; header
   inc de
   ld hl,ReubenDefaultData
   ld bc,23
   ldir
@:

And yes I am using interrupts, the table reaching from $800 until $8100 (including), but also when completley removing interrupts it still froze on archive.
I forget which operations exactly, but some flash operations use appData ($8000). If either of _Arc_Unarc or _FlashToRAM is one of them, then that could certainly explain a crash when your custom interrupt is enabled. My first suggestion, then, would be to relocate this data. I'd also avoid ramCode ($8100), as that's also used for some flash operations.

Other things of note:
    bcall(_Mov9toOp1) can be rst rMOV9TOOP1, which does the same thing but in two fewer bytes. You even used the latter in one place; not sure why you didn't in the others.

    ▪ There's no need to reload the appvar's name into OP1 after the first time. It'll still be there, at least up through the operations for which you need it to be there.

    ▪ You do need to re-_ChkFindSym the appvar if it's in RAM and you archive it. bcall(_Arc_Unarc) will not provide the same meaningful register outputs.

    ▪ Variables in archive have headers that need to be skipped to access the actual variable data. There's one byte that signals the start of a valid archived variable, then two bytes (little-endian) that specify the size of the remaining data, then a VAT entry for the variable (not reversed like VAT entries in RAM), and finally the normal variable data (starting with a two-byte size word). Here's my attempt at creating code to copy the data from the archived variable to the RAM location reuben:

    Code:
    ; Assuming B and DE hold the results of _ChkFindSym
    _Run_AppVar_in_Flash:
       ex de,hl
    ; Cheeky way to skip the archive header: increment pointer <header size> times
       ld a,1+2+7+AppVarNameLength+2
    _Run_AppVar_in_Flash_Skip_Header:
       B_CALL(_LoadDEIndPaged)
       dec a
       jr nz,_Run_AppVar_in_Flash_Skip_Header
    ; Do the do
       ld bc,23
       ld de,reuben
       B_CALL(_FlashToRAM)
       ;jr done_whatever


    ▪ If the appvar didn't exist, you still need to copy the default data to the RAM location reuben, not just to the appvar, correct? Combining this with the fact that you also probably want to archive it and neither of these things are being done, an easy solution would just be to jump to the case in which the appvar exists in RAM after bcall(_CreateAppVar).


That's all I see for now. Hopefully all of these notes lead to it working. If not, follow up and hopefully I (or someone else) can continue to assist.
The copying from flash to ram is working now, i think. But another issue is that the archiving freezes the calculator (NOT crashes) even though I have interrupts disabled and before enabling them i re-create the jump table.

EDIT: Ok, it seems like I got it working now.
What i have is this:


Code:
   di ; turn off interrupts
   
   ; set up im2 table
   ld hl, $8000
   ld de, $8001
   ld (hl), $85
   ld bc, 257
   ldir
   
   ; set up the jump handler
   ld hl,$8585
   ld (hl),$c3
   ld de,keyToStr ; that is where it will be
   inc hl
   ld (hl),e
   inc hl
   ld (hl),d
   
   ;copy the interrupt loader
   ld hl,LoadInterrupt
   ld de,keyToStr
   ld bc,17
   ldir
   
   ld a,INTRPT_MASK ; activate interrupts
   out (3),a
   
   ld a,$80
   ld i,a
   
   im 2
   ei
   
   di
   
   ; load appvar
   ld hl,AppVarName
   rst rMov9ToOP1
   bcall(_ChkFindSym)
   jr c,_Run_No_AppVar
   
   ld a,b
   or a
   jr nz,_Run_AppVar_in_Flash
   jr _Run_AppVar_in_RAM
_Run_No_AppVar:
   ld hl,AppVarName ; create the appvar
   rst rMov9ToOP1
   ld hl,23
   bcall(_CreateAppVar)
   inc de ; header
   inc de
   ld hl,ReubenDefaultData
   ld bc,23
   ldir
   
   ld hl,AppVarName
   rst rMov9ToOP1
   bcall(_ChkFindSym)
   
   
_Run_AppVar_in_RAM:
   
   
   ld hl,AppVarName
   
   rst rMov9ToOP1
   bcall(_Arc_Unarc)
   
   
   bcall(_ChkFindSym)
   
   
   
_Run_AppVar_in_Flash:
   
   
   ex de,hl
   ld a,1+2+7+5+2
_Run_AppVar_in_Flash_Skip_Header:
   bcall(_LoadDEIndPaged)
   dec a
   jr nz,_Run_AppVar_in_Flash_Skip_Header
   
   
   ld bc,23
   ld de,reuben
   bcall(_FlashToRAM)

   
   
   
   
   ; set up im2 table
   ld hl, $8000
   ld de, $8001
   ld (hl), $85
   ld bc, 257
   ldir
   im 2
   ei

I know that ei \ di doesn't make much sense but it is currently proof-of-concept

EDIT2: ok somehow in my pointer 'reuben' doesn't seem to be the default data if i delete the appvar and let the program create it :/

EDIT3: my AppVarName is .db AppVarObj,"R2Sav",0

EDIT4: my save routine somehow causes that keypresses aren't recognizes anymore and it also clears my screen...

Code:
Save:
   ld hl,PlotSScreen
   call ClrBuffer
   ld hl,AppBackUpScreen
   call ClrBuffer
   halt ; make sure screend is cleared
   di
      ld iy,flags
      
      
      ld hl,AppVarName     ; appvar is in ram now
      rst rMov9ToOP1
      bcall(_Arc_Unarc)
      ;bcall(_ChkFindSym)
      
      ;inc de  ; header
      ;inc de
      ;ld hl,reuben
      ;ld bc,23
      ;ldir
      
      ld hl,AppVarName     ; appvar is in archive now
      rst rMov9ToOP1
      bcall(_Arc_Unarc)
      
      
      ld hl, $8000
      ld de, $8001
      ld (hl), $85
      ld bc, 257
      ldir
      im2
   ei
   ld a,%10111110 ; listen to key groups
   out (1),a
   call Update
   ret

Update copies SaveSScreen to PlotSScreen and StatVars to AppBackUpScreen

EDIT5: Ok, unkownln told me to do im 1 before flash access, that resolves the freezing issue in my save routine but copying to the appvar/reading from it still doesn't work
Hmm... I can't see anything immediately wrong, so all I could suggest is debugging. You could try it yourself or I/others could try it if you provide a build and the addresses of potentially faulty routines.
Ok, talking over with runer on IRC i got it working!
It seems like, for initial reading, I needed to add an ld a,b so that it looks now like this:

Code:

   di
   im 1
   ; load appvar
   ld hl,AppVarName
   rst rMov9ToOP1
   bcall(_ChkFindSym)
   jr c,_Run_No_AppVar
   
   ld a,b
   or a
   jr nz,_Run_AppVar_in_Flash
   jr _Run_AppVar_in_RAM
_Run_No_AppVar:
   ld hl,AppVarName ; create the appvar
   rst rMov9ToOP1
   ld hl,23
   bcall(_CreateAppVar)
   inc de ; header
   inc de
   ld hl,ReubenDefaultData
   ld bc,23
   ldir
   
   ld hl,AppVarName
   rst rMov9ToOP1
   bcall(_ChkFindSym)
   
_Run_AppVar_in_RAM:
   ld hl,AppVarName
   rst rMov9ToOP1
   bcall(_Arc_Unarc)
   bcall(_ChkFindSym)
_Run_AppVar_in_Flash:
   
   ex de,hl
   
   ld a,1+2+7+AppVarNameLen+2
_Run_AppVar_in_Flash_Skip_Header:
   bcall(_LoadDEIndPaged)
   dec a
   jr nz,_Run_AppVar_in_Flash_Skip_Header
   ld a,b
   
   ld bc,23
   ld de,reuben
   bcall(_FlashToRAM)
   
   ; set up im2 table
   ld hl, $8000
   ld de, $8001
   ld (hl), $85
   ld bc, 257
   ldir
   im 2
   ei


And for saving bcall(_Arc_Unarc) didn't work as expected, resulting in this:

Code:

Save:
   ld hl,PlotSScreen
   call ClrBuffer
   ld hl,AppBackUpScreen
   call ClrBuffer
   halt ; make sure screend is cleared
   di
   im 1
      ld iy,flags
      
      
      ld hl,AppVarName     ; appvar is in ram now
      rst rMov9ToOP1
      bcall(_Arc_Unarc)
      
      inc de  ; header
      inc de
      ld hl,reuben
      ld bc,23
      ldir
      
      ld hl,AppVarName     ; appvar is in archive now
      rst rMov9ToOP1
      bcall(_Arc_Unarc)
      
      
      ld hl, $8000
      ld de, $8001
      ld (hl), $85
      ld bc, 257
      ldir
   im 2
   ei
   ld a,%10111110 ; listen to key groups
   out (1),a
   call Update
   ret
Yeah, _ChkFindSym will return the Flash page the variable is on (or 0 if in RAM) in b.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement