Awesome replies everyone, as usual.
I think I can smell a defect in the calling code, it looks odd and I'm going to look closer at it, however, here is the actual call that does the variable growth.
Note: this part was written when I was a fresh noob at Z80 (now I'm a stale noob
)
Code: InsertMemory:
;=========================================================
; Insert DefaultBlockSize bytes to the end of the variable
;=========================================================
;??????DEBUG THIS THING...WRITES PROBABLY NOT THE WRITE THING TO INCREASE MEMORY
; .using GlobalVariables
bcall(_MemChk)
ld hl, (App.DefaultBlockSize)
bcall(_EnoughMem)
jp c, ErrorScreen
call GetTestObj
;DE points to ti var size bytes
push de ; save pointer to start of size bytes of data
;======================================
;Set DE to the last memory location of
;current variable
;======================================
ldDEInd() ;ld de, (de)
pop hl ; add to var addy to get insertion point
push hl
add hl, de ; calculate insertion address
ld d, h ; set de to insertion address
ld e, l
ld hl, (App.DefaultBlockSize) ; hl to size insert
bcall(_InsertMem)
pop de ; size address (start of variable)
push de ; save it back again
ldDEind()
ld hl, (App.DefaultBlockSize) ; hl to size
add hl, de ; hl = hl + de
;===========================
; Write hl to the size bytes
;===========================
pop de ; ld (de), hl
ld a, l
ld (de), a
inc de
ld a, h
ld (de), a
ret
Here is the delete code
Code: DeleteLastBlockMemory:
;hl = address of first byte to delete
;de = number of bytes to delete
call SetDEToBlockSizeValue ; destroys a lot of registers, do first
ld (App.BlockSizeTemp), de
ld hl, (App.EndBlockStartByte) ; start of delete
bcall(_DelMem)
call GetTestObj ;de pointing to size bytes (variable)
push de
ldDEind() ; de = (de)
xor a ; clear CA
ld bc, (App.BlockSizeTemp)
ex de, hl
sbc hl, bc ; hl is new size of variable
;write hl to the size location of the variable
ex de, hl ; de is new size of variable
pop hl ; pointer to size bytes location
ld (hl), e
inc hl
ld (hl), d
ret