Hello everyone! I have a quick question regarding a certain thing in SPASM. I understand I can use the .seek directive to seek to a certain location using the program counter, but I was wondering if I could insert anything rather than just seeking. The .seek directive basically makes it so I have to allocate chunks, and then fill them, rather than trying to do it dynamically. Is there a way around this? Thanks for any help! Smile
Filling them dynamically?
Do you mean that you want to fill a chunk with 0's and then jump back to where you where without having to explicitly say .seek twice?

Look in to making it a macro I guess.
NanoWar might possibly know.

EDIT:
The (old) documentation on Spasm also warns people from using .seek..
Well, kind of. .seek only works after the program is assembled, so I was wondering if there was a solution to dynamically allocate space at the start of a program for a table or something. It's easy to do when the table already exists, and then populate it, but it cannot create the table on the fly.
I'm still not sure what you mean, either. Why don't you just use .fill with something like .fill dataEnd-dataStart? If you want the PC to start after the table, just put the .org statement after the .fill statement. This is something NanoWar would definitely be able to help out with, though. Can you give some simple code examples of what you'd like it to do?
So, here are my current macros that I am employing:

Code:
#MACRO numreloc(xxxx)
 #DEFINE NUMRELOCATIONS eval(xxxx)
 .dl xxxx*3
#ENDMACRO

#MACRO lib_begin()
 #DEFINE COUNTRELOCATIONS 0
 #DEFINE SEEKP   000000h
 .assume adl=1
 .org 000000h
 .block NUMRELOCATIONS*3
#ENDMACRO

#MACRO relocate()
 #DEFINE COUNTRELOCATIONS eval(COUNTRELOCATIONS+1)
 #DEFINE currOffset eval($)
 .seek SEEKP
 .dl currOffset
 .seek currOffset
 #DEFINE SEEKP eval(SEEKP+3)
#ENDMACRO

When I use them in code, they look like this:

Code:
 numreloc(1)
 
 lib_begin()

_DispHL259:
 call _HomeUp
relocate()
 jp ldhl

ldhl:
 ld hl,259
 call _DispHL
 ret


The problem is that I am building a relocations table, and the relocate() macro stores the address of the absolute position into the table. However, the table has to be generated first with the numreloc() macro, which tells me how many relocations I have. It would be nice if the relocate() macro were able to expand the table on the fly, rather than having to create the table initially.
Hmm... I can't really think of a way to do that without separating the building of the relocation table and the code itself, then joining the binaries later. That or perhaps putting the relocation table at the end of the program where you can define a counter that increases each time you use the relocate macro then multiply that by three. You might need another pointer at the beginning which points you to the start of the relocation table, though.
Yeah you can only seek into existing data in the second assemble round (pass 2). The problem lies at the table code point. Does it have to be before all other code? Or just at ".org 0" ? When I want to arrange tables like this, I use file io and includes:

Code:
#macro add_relocate_entry(_add_relocate_entry_address)
    .echo >> "relocate_table.z80" " .dl ", _add_relocate_entry_address
#endmacro

and then include it later.
NanoWar wrote:
Yeah you can only seek into existing data in the second assemble round (pass 2). The problem lies at the table code point. Does it have to be before all other code? Or just at ".org 0" ? When I want to arrange tables like this, I use file io and includes:

Code:
#macro add_relocate_entry(_add_relocate_entry_address)
    .echo >> "relocate_table.z80" " .dl ", _add_relocate_entry_address
#endmacro

and then include it later.

Hm, that might actually work if I #include the file at the end, and simply store a pointer to the relocation table at the beginning of the program. Thank you! Smile
Or you could run spasm twice. Output the table in the first run, include it in the second to update positions.
NanoWar wrote:
Or you could run spasm twice. Output the table in the first run, include it in the second to update positions.

Oh yes! Because if the include file is empty to begin with it won't have anything, and then I fill it up and reassemble. Brilliant. Thanks! Smile
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
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 vote in polls in this forum

 

Advertisement