I've been manually adding zero page memory locations to my kernel, with a list at the beginning of my source code. However, as I'm splitting things up into more and more library files, it would be nice to be able to group memory allocations with the code relevant to them. So I've created these macros, in ACME:
Code: Select all
!set zero_page_pointer = $0 ; pointer to next available zero page address
!set gp_memory_pointer = $0200 ; pointer to next available general purpose memory address
; alloc_zp: allocate a given amount of bytes on the zero page
;
; use: +alloc_zp foo, 2 ; sets label of foo to the first available zero page address, and reserve 2 bytes
!macro alloc_zp ~.address, .amount {
!address .address = zero_page_pointer
!set zero_page_pointer = zero_page_pointer + .amount
}
; alloc_mem: allocate a given amount of bytes in general purpose memory
;
; use: +alloc_mem foo, 2 ; sets label of foo to the first available memory address, and reserve 2 bytes
!macro alloc_mem ~.address, .amount {
!address .address = gp_memory_pointer
!set gp_memory_pointer = gp_memory_pointer + .amount
}Code: Select all
+alloc_zp ~kb_rptr, 1
lda kb_rptrI've tried various incarnations of using the "<" operator to truncate the address (does nothing), and using the "+1" postfix (says it is "too late for postfix", pointing to an execution order issue). Changing my final "lda kb_rptr" into "lda+1 kb_rptr" works, but it does not look great and means I have to change all the code, so I would rather avoid that.
Has anyone experimented with something similar and got it to work?