So, I have been trying to use the OS routine InsertMem, and it doesn't seem to be behaving like I would like it to. In theory, does it insert extra bytes at the given pointer, expanding something like this:


Code:

Addr: $0000 -- $FA,$FF,$02,$56 ...


To this?:


Code:

Addr: $0000 -- $FA,$FF,$00,$00,$00,$02,$56 ...


If this is called?:


Code:

 ld de,Addr+3
 ld hl,3
 bcall InsertMem


While this is not really a working example, this is the problem that I have been having. How does the InsertMem routine behave? Does it simply return a pointer to free ram, or something else along those lines? Thanks!
InsertMem should only be used at addresses >= UserMem. It works by pushing all of the user variables in RAM the specified number of bytes higher, thus leaving a gap that you can use. If you specify an address in the middle or at the end of a variable, you can use that to enlarge the variable, as long as you remember to update its size words. You can also use it to give yourself temporary space to use, as long as you _DelMem afterwards. What are you trying to use it for?
EDIT: Don't even bother looking at this. It seems like it did work. Silly me. Now I feel like one of those people who post lengthy questions when there is nothing wrong in the first place. Take a look below. Rolling Eyes

Okay, this may be kind of long, but it is not too bad. So, here's the code: (All other routines not here work fine). I would like to add a certain number of bytes to an AppVar depending on the offset in the AppVar, which is stored in (LevelPTR):
(PackPTR) points to the start of the data for the AppVar.


Code:
SaveLevel:
   bcall   _ClearGraphBuf
   ld   hl,(PackPTR)
   ld   de,1
   ld   (pencol),de
   call   DispHL
   ld   de,256*9+1
   ld   (pencol),de
   ld   hl,(LevelPTR)
   call   DispHL
   ld   hl,TestName
   rst   20h
   bcall   _ChkFindSym
   ex   de,hl
   ld   de,256*18+1
   ld   (pencol),de   
   call   DispHL
   bcall   _CopyGraphBuf
TestingLoop:
   bcall   _GetCSC
   cp   $36                          ;[2ND]
   jr   z,NowTest
   jr   TestingLoop

NowTest:
   call   AddMemoryToAppVar

   bcall   _ClearGraphBuf
   ld   hl,(PackPTR)
   ld   de,1
   ld   (pencol),de
   bcall   _ChkFindSym
   ex   de,hl   
   call   DispHL
   bcall   _CopyGraphBuf
TestingLoop2:
   bcall   _GetCSC
   cp   $0F
   jp   z,FullExit
   jr   TestingLoop2

AddMemoryToAppVar:
   ld   de,(PackPTR)
   push   de      ; save pointer to start of size bytes data

   ld   de,(LevelPTR)
   ld   hl,5      ; number bytes to insert
   bcall   _InsertMem   ; insert the memory

   pop   hl      ; Reload Size pointer bytes
   push   hl      ; Save pointer for later

   ld   a, (hl)      ;Load Size Bytes
   inc   hl
   ld   h, (hl)
   ld   l, a
            ; HL = size of AppVar
   ld   bc,5
   add   hl,bc      ; increase size by 5

   ex   de,hl
   pop   hl      ; Load pointer to size bytes location

   ld   (hl),e
   inc   hl
   ld   (hl),d      ; write new size.
   ret


Now, when I run it through the first time to see all of the values of the variables, I get this:



This corresponds to this in memory:



Now, when I press [2ND] to save the new data, I get this on the calculator:



But in memory, it looks like this:



For some reason, it only updated the size bytes, and did not insert the memory where I wanted it to be. Any ideas on why this is happening? Could be quite a challenge to figure this out... Thanks!

EDIT: Scroll down a little farther...

At least you wrote a thorough post when asking your question, which I think deserves to be acknowledged. And as discussed on IRC, _InsertMem doesn't initialize the bytes inserted to anything; that is up to you.
  
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