6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Mon May 20, 2024 4:51 pm

All times are UTC




Post new topic Reply to topic  [ 47 posts ]  Go to page Previous  1, 2, 3, 4
Author Message
PostPosted: Sun Jul 29, 2012 12:31 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8440
Location: Southern California
I managed to synthesize a stack in the C32 assembler (a way that could be done in nearly any assembler) so as to be able to nest program structures, and wrote up an article about structure macros, with accompanying source code (which I've tested but have not used extensively yet), at http://wilsonminesco.com/StructureMacros/index.html .

_________________
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: Fri Nov 09, 2012 6:59 am 
Offline

Joined: Fri Nov 09, 2012 6:52 am
Posts: 16
Hi,

I implemented some hl stuff with ca65 and come across this thread. It's easy to have a stack in ca65.

Code:

.macro push stackname, value, sp   ; stackname, value to assign, stackpointer
   .ident( .sprintf("%s_%04X_",stackname,sp)) .set value
   sp .set sp + 1
.endmacro


.macro pop stackname, var, sp    ; stackname, identifier to assign value to, stackpointer
   sp .set sp - 1
   var  .set .ident( .sprintf("%s_%04X_",stackname,sp))   
.endmacro



These two macros give you as many stacks as you like, just identify which stack you are working with by name. I would like to write up better documentation, but there is some decent stuff here: http://mynesdev.blogspot.ca/2012/10/ca6 ... again.html

Although my goal is a NES project, this would work for any 6502 (just standard 6502 at this point since I am targeting the NES.)

Edit: Actually, I was thinking, it complicates these macros slightly, but makes for nicer code elsewhere - the macros should take care of the stack pointers too:

Code:
.macro push stackname, value

   .ifndef ::.ident(.sprintf("_%s_POINTER", stackname))
      ::.ident(.sprintf("_%s_POINTER", stackname)) .set 0
   .endif

   ::.ident( .sprintf("%s_%04X_",stackname,::.ident(.sprintf("_%s_POINTER", stackname)))) .set value

   ::.ident(.sprintf("_%s_POINTER", stackname))  .set ::.ident(.sprintf("_%s_POINTER", stackname))  + 1
.endmacro


.macro pop stackname, var ; puts a -1 in var if there is a problem
   
    .ifndef ::.ident(.sprintf("_%s_POINTER", stackname)) ; unknown stack pointer
         var .set -1
         .exitmacro
   .endif
   
    ::.ident(.sprintf("_%s_POINTER", stackname))  .set ::.ident(.sprintf("_%s_POINTER", stackname))  - 1
    .if ::.ident(.sprintf("_%s_POINTER", stackname)) < 0 ; stackpointer is negative
      var .set -1
   .else
      var  .set ::.ident( .sprintf("%s_%04X_",stackname,::.ident(.sprintf("_%s_POINTER", stackname))))   
   .endif
   
.endmacro



Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 47 posts ]  Go to page Previous  1, 2, 3, 4

All times are UTC


Who is online

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