Hi there,
I'm trying to write a demoscene effect and therefore I need about $1800 bytes of free ram for tables, from what I read free RAM is very limited, is there a way to have fixed area of 6 kb of RAM free for my program?
Easily. Assuming your program leaves 6KB of usermem free, you can use insertmem to reserve a block of memory, then delmem when you're done with it. Just be sure not to create or delete any variables while that memory is reserved.
thanks for the hint, I tried to create AppVar and expand it to $1900 bytes

Code:

reserve_memory:

 ld hl,AmountOfRAMINeed; where AmountOfRAMINeed is a the number of bytes you need
 bcall(_enoughmem)
 ret c
 ld hl,AppVarName
 rst rMOV9TOOP1
 ld hl,AmountOfRAMINeed
 bcall(_CreateAppVar)

insert_memory:
 ld hl,reserve ; number bytes to insert
 b_call(_enoughmem) ; check for free ram
 ret c ; ret ca = 1 if not
;
 ld hl,AppVarName
 b_call(_mov9toop1) ; op1 = name of appvar
 b_call(_chkfindsym) ; de = pointer to data if exists
 inc de
 inc de
 ld (variable_data_start),de
 dec de
 dec de
 ret c ; ret if not found
 ld a,b ; archived status
 add a,0ffh ; if archived then ca = 1
 ret c ; ret if archived
;
 push de ; save pointer to size bytes of
; data
 inc de
 inc de ; move de past size bytes
;
 ld hl,reserve ; number bytes to insert
 b_call(_insertmem) ; insert the memory
 pop hl ; hl = pointer to size bytes
 push hl ; save
;
 b_call(_ldhlind) ; hl = old size of appvar,
; number bytes
 ld bc,reserve
 add hl,bc ; increase by 10, amount inserted
 ex de,hl ; de = new size
 pop hl ; pointer to size bytes location
 ld (hl),e
 inc hl
 ld (hl),d ; write new size.
 or a ; ca = 0 each or resets C
 ret

reserve .equ $1980
AmountOfRAMINeed .equ 10
AppVarName:
.db AppVarObj,"AVDATA",0

variable_data_start .dw $ffff


but when I try to use "variable_data_start" as a pointer to free memory I get garbage on screen, I tested the very same code on ZX Spectrum and it works with no problems whatsoever. I make sure that the intervals between writes to lcd are long enough. What could be the reason for the bad data in the window I reserved?
oh, it turned out that I needed to disable interrupts each time I entered the loop, wasn't aware of that Smile
gorgh wrote:
oh, it turned out that I needed to disable interrupts each time I entered the loop, wasn't aware of that Smile
Interrupts shouldn't affect anything in your AppVar, but if you're using the shadow registers, the iy register, or a few other things, you should avoid interrupts (and probably also BCALLs).
  
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