6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu May 09, 2024 8:19 pm

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Wed Apr 27, 2022 9:13 pm 
Offline
User avatar

Joined: Sat Jul 24, 2021 1:37 pm
Posts: 282
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:

Code:
!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
}


Then, the goal is to be able to use this code:

Code:
+alloc_zp ~kb_rptr, 1

lda kb_rptr


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?

_________________
BB816 Computer YouTube series


Last edited by akohlbecker on Wed Apr 27, 2022 9:20 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Wed Apr 27, 2022 9:19 pm 
Offline
User avatar

Joined: Sat Jul 24, 2021 1:37 pm
Posts: 282
I have found this similar idea here https://www.lemon64.com/forum/viewtopic ... 788#168788, but even using a variable and defining the label outside of the macro, I still get the same issue of ACME not using zero-page addressing and spitting out this warning.

_________________
BB816 Computer YouTube series


Top
 Profile  
Reply with quote  
PostPosted: Wed Apr 27, 2022 9:40 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8432
Location: Southern California
I'm not familiar with ACME; but can you AND it with $FF, to force it into a single byte? I've done that with the assemblers I use.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Wed Apr 27, 2022 11:01 pm 
Offline
User avatar

Joined: Sat Jul 24, 2021 1:37 pm
Posts: 282
It looks like that did the trick! Not sure why I didn't think of it as I use it in other places... Thanks, Garth!

_________________
BB816 Computer YouTube series


Top
 Profile  
Reply with quote  
PostPosted: Wed Apr 27, 2022 11:06 pm 
Offline
User avatar

Joined: Sat Jul 24, 2021 1:37 pm
Posts: 282
Updated macros, with added overflow check

Code:
!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 = $ff & zero_page_pointer
    !set zero_page_pointer = zero_page_pointer + .amount
    !if zero_page_pointer > $ff {
      !error "out of zero page addresses"
    }
}

; 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
    !if gp_memory_pointer > $7f7f {
      !error "out of memory addresses"
    }
}

_________________
BB816 Computer YouTube series


Top
 Profile  
Reply with quote  
PostPosted: Sat May 07, 2022 6:41 pm 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 993
Location: near Heidelberg, Germany
Does acme not support segments? Incl a zeropage segment that is automatically located in zeropage....

_________________
Author of the GeckOS multitasking operating system, the usb65 stack, designer of the Micro-PET and many more 6502 content: http://6502.org/users/andre/


Top
 Profile  
Reply with quote  
PostPosted: Sat May 07, 2022 7:01 pm 
Offline
User avatar

Joined: Sat Jul 24, 2021 1:37 pm
Posts: 282
Do you mean the *= directive? How would you use it for this?

_________________
BB816 Computer YouTube series


Top
 Profile  
Reply with quote  
PostPosted: Sun May 08, 2022 7:24 am 
Offline

Joined: Sun May 07, 2017 3:59 pm
Posts: 20
I don't think ACME has segment support.

Out of the assemblers I frequently use, 64tass (aka tass64) has "sections", and ca65 (from cc65) has segments, along with a linker.


Top
 Profile  
Reply with quote  
PostPosted: Sun May 08, 2022 7:54 pm 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 993
Location: near Heidelberg, Germany
xa65 has at least basic segment support.

You can use .zero .text .data and .bss to switch between these four segments. Each segment has its own PC. Start address is typically given by command line option, or by the relocating loader

_________________
Author of the GeckOS multitasking operating system, the usb65 stack, designer of the Micro-PET and many more 6502 content: http://6502.org/users/andre/


Top
 Profile  
Reply with quote  
PostPosted: Sun May 08, 2022 7:58 pm 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 993
Location: near Heidelberg, Germany
.zero is uninitialized zeropage memory
.text is program code
.data is memory initialized with some data
.bss is uninitialized memory

This way the loader can put each segment into the right area, eg text into executable but read only area, zero into zeropage etc

Only works with a file format that allows that, like o65

_________________
Author of the GeckOS multitasking operating system, the usb65 stack, designer of the Micro-PET and many more 6502 content: http://6502.org/users/andre/


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: Hermes and 9 guests


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 post attachments in this forum

Search for:
Jump to: