forked from liliambean/s3unlocked
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsonic3k.macrosetup.asm
94 lines (84 loc) · 2.48 KB
/
sonic3k.macrosetup.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
padding off ; we don't want AS padding out dc.b instructions
listing purecode ; Want listing file, but only the final code in expanded macros
supmode on ; we don't need warnings about privileged instructions
page 0 ; Don't want form feeds
notZ80 function cpu,(cpu<>128)&&(cpu<>32988)
; make org safer (impossible to overwrite previously assembled bytes)
org macro address
if notZ80(MOMCPU)
.diff := address - *
if .diff < 0
error "too much stuff before org $\{address} ($\{(-.diff)} bytes)"
else
while .diff > 1024
; AS can only generate 1 kb of code on a single line
dc.b [1024]$FF
.diff := .diff - 1024
endm
dc.b [.diff]$FF
endif
else
if address < $
error "too much stuff before org 0\{address}h (0\{($-address)}h bytes)"
else
while address > $
db 0
endm
endif
endif
endm
; define an alternate org that fills the extra space with 0s instead of FFs
org0 macro address
.diff := address - *
if .diff < 0
error "too much stuff before org0 $\{address} ($\{(-.diff)} bytes)"
else
while .diff > 1024
; AS can only generate 1 kb of code on a single line
dc.b [1024]0
.diff := .diff - 1024
endm
dc.b [.diff]0
endif
endm
; define the cnop pseudo-instruction
cnop macro offset,alignment
if notZ80(MOMCPU)
org (*-1+(alignment)-((*-1+(-(offset)))#(alignment)))
else
org ($-1+(alignment)-(($-1+(-(offset)))#(alignment)))
endif
endm
; define an alternate cnop that fills the extra space with 0s instead of FFs
cnop0 macro offset,alignment
org0 (*-1+(alignment)-((*-1+(-(offset)))#(alignment)))
endm
; redefine align in terms of cnop, because the built-in align can be stupid sometimes
align macro alignment
cnop 0,alignment
endm
; define an alternate align that fills the extra space with 0s instead of FFs
align0 macro alignment
cnop0 0,alignment
endm
; define the even pseudo-instruction
even macro
align0 2
endm
; define a trace macro
; lets you easily check what address a location in this disassembly assembles to
trace macro optionalMessageWithoutQuotes
if MOMPASS=1
if ("ALLARGS"<>"")
message "#\{tracenum/1.0}: line=\{MOMLINE/1.0} PC=$\{(*)&$FFFFFFFF} msg=ALLARGS"
else
message "#\{tracenum/1.0}: line=\{MOMLINE/1.0} PC=$\{(*)&$FFFFFFFF}"
endif
tracenum := (tracenum+1)
endif
endm
tracenum := 0
bit function nBits,1<<(nBits-1)
signmask function val,nBits,-((-(val&bit(nBits)))&bit(nBits))
signextend function val,nBits,(val+signmask(val,nBits))!signmask(val,nBits)
signextendB function val,signextend(val,8)