This repository has been archived by the owner on Oct 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmacros.asm
executable file
·183 lines (159 loc) · 4.8 KB
/
macros.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
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
; ===========================================================================
; ----------------------------------------------------------------
; MACROS
; ----------------------------------------------------------------
; ====================================================================
; ---------------------------------------------
; Functions
; ---------------------------------------------
; dword function l,r,(l<<16&$FFFF0000|r&$FFFF) ; LLLL RRRR
mapsize function l,r,(((l-1)/8)<<16&$FFFF0000|((r-1)/8)&$FFFF) ; Full w/h sizes, for cell sizes use doubleword
locate function a,b,c,(c&$FF)|(b<<8&$FF00)|(a<<16&$FF0000) ; VDP locate: Layer|X pos|Y pos for some video routines
cell_vram function a,(a<<5) ; Vram position in 8x8 CELLS
; ====================================================================
; ---------------------------------------------
; Macros
; ---------------------------------------------
paddingSoFar set 0
notZ80 function cpu,(cpu<>128)&&(cpu<>32988)
; -------------------------------------
; Reserve memory section
;
; NOTE: This doesn't work for Z80
; -------------------------------------
struct macro thisinput ; Reserve memory address
GLBL_LASTPC set *
dephase
GLBL_LASTORG set *
phase thisinput
endm
; -------------------------------------
; Finish struct
; -------------------------------------
endstruct macro ; Then finish the custom struct.
!org GLBL_LASTORG
phase GLBL_LASTPC
endm
; -------------------------------------
; Report RAM usage
; -------------------------------------
report macro text,dis,dat
if MOMPASS == 2
if dat == -1
message text+": \{(dis)&$FFFFFF}"
else
if dis > dat
warning "RAN OUT OF "+text+" SPACE (\{(dis)&$FFFFFF} of \{(dat)&$FFFFFF})"
else
message text+" uses \{(dis)&$FFFFFF} of \{(dat)&$FFFFFF}"
endif
endif
endif
endm
; -------------------------------------
; Same thing but only report
; error
; -------------------------------------
erreport macro text,dis,dat
if MOMPASS == 2
if dat == -1
message text+": \{(dis)&$FFFFFF}"
else
if dis > dat
error "RAN OUT OF "+text+" SPACE (\{(dis)&$FFFFFF} of \{(dat)&$FFFFFF})"
; else
; message text+" uses \{(dis)&$FFFFFF} of \{(dat)&$FFFFFF}"
endif
endif
endif
endm
; -------------------------------------
; VDP color debug
; -------------------------------------
vdp_showme macro this
move.l #$C0000000,(vdp_ctrl).l
move.w #this,(vdp_data).l
endm
; -------------------------------------
; Custom ORG-filler
;
; (from s2disasm)
; -------------------------------------
org macro address
if notZ80(MOMCPU)
if address < *
error "too much stuff before org $\{address} ($\{(*-address)} bytes)"
elseif address > *
paddingSoFar set paddingSoFar + address - *
!org address
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
; -------------------------------------
; ZERO Fill padding
; -------------------------------------
rompad macro address ; Zero fill
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]0
diff := diff - 1024
endm
dc.b [diff]0
endif
endm
; ====================================================================
; ---------------------------------------------
; ISO filesystem macros
; ---------------------------------------------
; Set a ISO file
; NOTE: a valid ISO head is required ($8000 to $B7FF)
iso_setfs macro type,start,end
.fstrt: dc.b .fend-.fstrt ; Block size
dc.b 0 ; zero
dc.b (start>>11&$FF),(start>>19&$FF) ; Start sector, little
dc.b (start>>27&$FF),(start>>35&$FF)
dc.l start>>11 ; Start sector, big
dc.b ((end-start)&$FF),((end-start)>>8&$FF) ; Filesize, little
dc.b ((end-start)>>16&$FF),((end-start)>>24&$FF)
dc.l end-start ; Filesize, big
dc.b (2023-1900)+1 ; Year
dc.b 0,0,0,0,0,0 ; TODO
dc.b 2 ; File flags
dc.b 0,0
dc.b 1,0 ; Volume sequence number, little
dc.b 0,1 ; Volume sequence number, big
dc.b 1,type
.fend:
endm
iso_file macro filename,start,end
.fstrt: dc.b .fend-.fstrt ; Block size
dc.b 0 ; zero
dc.b (start>>11&$FF),(start>>19&$FF) ; Start sector, little
dc.b (start>>27&$FF),(start>>35&$FF)
dc.l start>>11 ; Start sector, big
dc.b ((end-start)&$FF),((end-start)>>8&$FF) ; Filesize, little
dc.b ((end-start)>>16&$FF),((end-start)>>24&$FF)
dc.l end-start ; Filesize, big
dc.b (2023-1900)+1 ; Year
dc.b 0,0,0,0,0,0 ; TODO
dc.b 0 ; File flags
dc.b 0,0
dc.b 1,0 ; Volume sequence number, little
dc.b 0,1 ; Volume sequence number, big
dc.b .flend-.flen
.flen: dc.b filename,";1"
.flend: dc.b 0
.fend:
endm