6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 10:44 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Mon Sep 20, 2021 10:01 pm 
Offline

Joined: Tue Sep 14, 2021 5:36 pm
Posts: 8
https://github.com/geon/zpallocator/blo ... xample.asm

The idea is to be able to use the zero page for all variables. You allocate a zp address when you need it, and when you are done with it (ie. at the end of the macro/function scope), you deallocate it.

Code:
   // BackgroundColor will contain a free zp address.
   .var backgroundColor = allocateZpByte()

   // Do stuff with backgroundColor
   lda #BROWN
   sta backgroundColor
   // ...
   deallocateZpByte(backgroundColor)


This way, I can write macros and pass arguments by reference without worrying about collisions.

I could use some help to define a couple of ranges of reserved zp addresses. I don't care about basic, so I can use $02-$70 or so without problem, but I might want to use some kernal routines like screen io and the jiffy clock. I'm not sure what other areas of the zp are important.


Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 21, 2021 6:06 am 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 1043
Location: near Heidelberg, Germany
geon wrote:
https://github.com/geon/zpallocator/blob/master/zpallocator.example.asm

The idea is to be able to use the zero page for all variables. You allocate a zp address when you need it, and when you are done with it (ie. at the end of the macro/function scope), you deallocate it.


Not sure I understand. It looks like you're allocating at build time, right? How do you handle run time conflicts like one routine reusing the location reserved by another routine but calling each other?

André

_________________
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: Tue Sep 21, 2021 10:47 am 
Offline

Joined: Tue Sep 14, 2021 5:36 pm
Posts: 8
fachat wrote:
It looks like you're allocating at build time, right?


Yes.

fachat wrote:
How do you handle run time conflicts like one routine reusing the location reserved by another routine but calling each other?


For a function, you would need to allocate the address permanently. It works better with macros.


Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 21, 2021 2:16 pm 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 1043
Location: near Heidelberg, Germany
Then don't you use macros in functions?

Did you try to 'simulate' it e.g. with a paper walk through?

Writing up how it works for a few real world test cases helps a great deal in understanding if it really works or where the pitfalls are.

_________________
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: Tue Sep 21, 2021 4:07 pm 
Offline

Joined: Tue Sep 14, 2021 5:36 pm
Posts: 8
fachat wrote:
Then don't you use macros in functions?


Actually no. Or rather, I haven't used functions at all so far, just macros.

fachat wrote:
Writing up how it works for a few real world test cases helps a great deal in understanding if it really works or where the pitfalls are.


Yes, I do TDD. I'll have to look at functions.


Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 21, 2021 8:11 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8507
Location: Midwestern USA
This sort of thing is easily done at run-time with the 65C816. Functions (subroutines) save the current value of DP (direct page pointer) on the stack, reserve stack space as needed and then point DP to that space. when the function exits it releases the stack space and restores DP to its entry value.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 22, 2021 8:08 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Well done geon, thanks for sharing your creation!


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 16 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: