-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathps4.macrosetup.asm
More file actions
171 lines (150 loc) · 3.47 KB
/
ps4.macrosetup.asm
File metadata and controls
171 lines (150 loc) · 3.47 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
padding off ; Don't want AS padding out dc.b instructions
;listing off ; Don't need to generate anything for a listing file
;listing on ; Want full listing file
;listing noskipped ; Want listing file, but only the non-skipped part of conditional assembly
listing purecode ; Want listing file, but only the final code in expanded macros
page 0 ; Don't want form feeds
supmode on ; Don't need warnings about privileged instructions
; 128 = 80h = z80, 32988 = 80DCh = z80unDoC
notZ80 function cpu,(cpu<>128)&&(cpu<>32988)
; 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, for the padding counter
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
if notZ80(MOMCPU)
if (*)&1
dc.b 0 ;ds.b 1
endif
else
if ($)&1
db 0
endif
endif
endm
; make ds work in Z80 code without creating a new segment
ds macro
if notZ80(MOMCPU)
!ds.ATTRIBUTE ALLARGS
else
rept ALLARGS
db 0
endm
endif
endm
chkop function op,ref,(substr(lowstring(op),0,strlen(ref))<>ref)
; 1-arg instruction that's self-patching to remove 0-offset optimization
insn1op macro oper,x
if (chkop("x","0("))
!oper x
else
!oper 1+x
!org *-1
!dc.b 0
endif
endm
; 2-arg instruction that's self-patching to remove 0-offset optimization
insn2op macro oper,x,y
if (chkop("x","0("))
if (chkop("y","0("))
!oper x,y
else
!oper x,1+y
!org *-1
!dc.b 0
endif
else
if chkop("y","d")
if (chkop("y","0("))
start:
!oper 1+x,y
end:
!org start+3
!dc.b 0
!org end
else
!oper 1+x,1+y
!org *-3
!dc.b 0
!org *+1
!dc.b 0
endif
else
!oper 1+x,y
!org *-1
!dc.b 0
endif
endif
endm
; instructions that were used with 0(a#) syntax
; defined to assemble as they originally did
_move macro
insn2op move.ATTRIBUTE, ALLARGS
endm
_lea macro
insn2op lea, ALLARGS
endm
_btst macro
insn2op btst.ATTRIBUTE, ALLARGS
endm
_bset macro
insn2op bset.ATTRIBUTE, ALLARGS
endm
_clr macro
insn1op clr.ATTRIBUTE, ALLARGS
endm
_tst macro
insn1op tst.ATTRIBUTE, ALLARGS
endm
; when managing dialogues compressed vs uncompressed,
; we must modify some code to store the saved dialogue
; in a different location because it needs to be a
; 24-bit value, since in ROM the dialogue size is > 64KB
; (and also it'S not in RAM so we can't just sign-extend)
pushdlg macro
if dialogue_uncompressed = 1
move.l a0, (Saved_Dialogue_Addr).w
else
move.w a0, (Saved_Dialogue_Addr).w
endif
endm
popdlg macro
if dialogue_uncompressed = 1
move.l (Saved_Dialogue_Addr).w, d0
else
moveq #-1, d0
move.w (Saved_Dialogue_Addr).w, d0
endif
movea.l d0, a0
endm