I've tried to search for it..
Anyway: is it possible to use some kind of macros in asm files?
I want to 'inline' some asm routines in the bios I am writing for my zalt target/machine...
z80asm itself does not do macros yet but we've adopted m4 as a macro pre-processor. This is the standard macro processor in linux (the windows build also includes a binary) - it takes getting used to but it's very powerful. Links to the manual and a quick overview can be found here:
https://www.z88dk.org/wiki/doku.php?id=temp:front#m4
zcc will invoke m4 on any file ending in .m4. The intention is to use it with file extensions like these:
.h.m4 -- zcc expands to .h file
.c.m4 -- zcc expands to .c file
.asm.m4 -- zcc expands to .asm file
The expansion means zcc writes the resulting file type into the original source directory immediately. So if you have a "foo.asm.m4" file, zcc will create the file "foo.asm" after m4 expansion in the same source directory alongside "foo.asm.m4". zcc will then process the resulting .c or .asm file as normal. The reason why these files have to be written to the source directory is so that include paths are properly resolved. This also means any file ending in ".ext.m4" also reserves the filename ending in ".ext" in the source directory as zcc will overwrite any file with that name during macro expansion.
Very recently (ie last couple of days) I added a few standard z88dk m4 macros to the file "z88dk.m4" in m4's path. If you include that in your m4 file like so:
include(`z88dk.m4')
you can use those macros. You can see the macro definitions online:
http://z88dk.cvs.sourceforge.net/viewvc ... 4/z88dk.m4
This will give you a for loop and a foreach loop. It's just a beginning and I expect we will put more useful macros in as time passes.
Here's a short example using m4 as macro processor for an asm file:
test.asm.m4
"
include(`../../../../clib_target_cfg.asm')
include(`z88dk.m4')
SECTION NIRVANAP
PUBLIC __NIRVANAP_bitmaps
__NIRVANAP_bitmaps:
; lookup table with screen addresses
defs 16
z88dk_for(ROWREPT, 0, eval(NIRVANAP_TOTAL_ROWS - 1),
`define(`HROW', eval((ROWREPT+1)/8))define(`LROW', eval((ROWREPT+1)%8))
defw 16384 + (HROW*2048) + (LROW*32)
defw 16384 + (HROW*2048) + 512 + (LROW*32)
defw 16384 + (HROW*2048) + 1024 + (LROW*32)
defw 16384 + (HROW*2048) + 1536 + (LROW*32)')
defs 4*(23 - NIRVANAP_TOTAL_ROWS)
"
The example above uses a for loop (z88dk_for) which is equivalent to:
for(ROWREPT = 0; ROWREPT <= NIRVANAP_TOTAL_ROWS - 1; ROWREPT++)
{
HROW = (ROWREPT+1)/8
LROW = (ROWREPT+1)%8
defw 16384 + (HROW*2048) + (LROW*32)
defw 16384 + (HROW*2048) + 512 + (LROW*32)
defw 16384 + (HROW*2048) + 1024 + (LROW*32)
defw 16384 + (HROW*2048) + 1536 + (LROW*32)
}
m4 looks bizarre to the uninitiated (and it still does to me since I'm only a beginner) but it's hidden everywhere in the linux world so knowing it can be a useful skill.
I can compile the above using zcc:
zcc +zalt .... test.asm.m4 -o test -create-app
Or I can stop zcc after m4 expansion to examine the resulting asm file:
zcc +zalt -m4 .... test.asm.m4
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org!
http://sdm.link/slashdot