Here I will post some assembler macros for Unofficial-MagicKit assembler. You can post your own macros too, for this or other macro assemblers. Or possibly, put in wiki too, and organize it on there.
Multibyte constant macro:
One example of a macro to create tables for use with RTS tricks:
Here is a set of macros for creating tables of digits to convert binary numbers into decimal (make_digit_table 100,256,128 generates 128 entries for the hundreds place when converting from the high byte, for example):
This macro is used in Famizork to create Z-character decoding tables:
And then, there is the postprocessor/output-routine, where you can do a lot more things; I didn't even get started with describing the uses of that in this message!
Multibyte constant macro:
Code:
; Implementation of multibyte constants for Unofficial-MagicKit.
; This file is in the public domain.
macro mbyt
macset 2,4,\$1>1
macgoto mbyt_\2
endm
macro mbyt_0
endm
macro mbyt_1
macset 2,2,1
macset 2,5,2
db $\2
mbyt_0 \>1
macset 1,1,1
mbyt_0 \>1
macset 1,1,1
macgoto mbyt
endm
; Example:
; mbyt 09F91102 9D74E35B D84156C5 635688C0
; This file is in the public domain.
macro mbyt
macset 2,4,\$1>1
macgoto mbyt_\2
endm
macro mbyt_0
endm
macro mbyt_1
macset 2,2,1
macset 2,5,2
db $\2
mbyt_0 \>1
macset 1,1,1
mbyt_0 \>1
macset 1,1,1
macgoto mbyt
endm
; Example:
; mbyt 09F91102 9D74E35B D84156C5 635688C0
One example of a macro to create tables for use with RTS tricks:
Code:
; Instruction assigning macro
macro def_inst
macset 2,4,*
macset 3,4,?B
bank bank(instadl)
org instadl+(\1)
db low(\2-1)
org instadh+(\1)
db high(\2-1)
bank \3
org \2
endm
macro def_inst
macset 2,4,*
macset 3,4,?B
bank bank(instadl)
org instadl+(\1)
db low(\2-1)
org instadh+(\1)
db high(\2-1)
bank \3
org \2
endm
Here is a set of macros for creating tables of digits to convert binary numbers into decimal (make_digit_table 100,256,128 generates 128 entries for the hundreds place when converting from the high byte, for example):
Code:
macro make_digit_table
macset 4,4,0
macgoto make_digit_table_0
endm
macro make_digit_table_0
db ((\4*\2)/\1)%10
macset 4,4,\4+1
macset 5,4,\4=\3
macgoto make_digit_table_\5
endm
macro make_digit_table_1
; Empty macro
endm
macset 4,4,0
macgoto make_digit_table_0
endm
macro make_digit_table_0
db ((\4*\2)/\1)%10
macset 4,4,\4+1
macset 5,4,\4=\3
macgoto make_digit_table_\5
endm
macro make_digit_table_1
; Empty macro
endm
This macro is used in Famizork to create Z-character decoding tables:
Code:
; Z-character-decoding assigning macro
macro def_zchars
if \#=1
macset 2,4,\1
else
macset 2,4,\2
endif
macset 1,4,\1
macset 3,4,*
macset 4,4,?B
bank bank(zchad)
macgoto def_zchars_0
endm
macro def_zchars_0
macset 5,4,\1=\2
org zchad+\1
db low(\3-1)
if \3<$FE01
fail "Z-character routine out of range"
endif
if \3>$FF00
fail "Z-character routine out of range"
endif
macset 1,4,\1+1
macgoto def_zchars_\5
endm
macro def_zchars_1
bank \4
org \3
endm
macro def_zchars
if \#=1
macset 2,4,\1
else
macset 2,4,\2
endif
macset 1,4,\1
macset 3,4,*
macset 4,4,?B
bank bank(zchad)
macgoto def_zchars_0
endm
macro def_zchars_0
macset 5,4,\1=\2
org zchad+\1
db low(\3-1)
if \3<$FE01
fail "Z-character routine out of range"
endif
if \3>$FF00
fail "Z-character routine out of range"
endif
macset 1,4,\1+1
macgoto def_zchars_\5
endm
macro def_zchars_1
bank \4
org \3
endm
And then, there is the postprocessor/output-routine, where you can do a lot more things; I didn't even get started with describing the uses of that in this message!