ACME memory allocation macro and oversized addressing
Posted: Wed Apr 27, 2022 9:13 pm
Hello all,
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:
Then, the goal is to be able to use this code:
Unforunately, while alloc_mem works perfectly, ACME is unable to infer zero-page addressing for the alloc_zp example above, and I get the following warning: "Using oversized addressing mode.". It appears that choosing the addressing mode happens before the macro has executed, and so ACME does not know that kb_rptr is a byte.
I'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?
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?