forked from calc84maniac/tiboyce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext.asm
279 lines (245 loc) · 4.02 KB
/
text.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
Wait:
_
ld a,(mpIntMaskedStatus)
rra
ret c
ld a,(mpKeypadGrp6)
rra
jr c,-_
_
ld a,(mpIntMaskedStatus)
rra
ret c
ld a,(mpKeypadGrp6)
rra
jr nc,-_
ret
#ifdef DEBUG
debug_printf:
ld ix,text_buffer
ex (sp),ix
call _sprintf
pop hl
push ix
debug_print:
; HL points to string
_
ld a,(hl)
inc hl
ld (mpCEmuDbg),a
or a
jr nz,-_
ret
#endif
SetEmulatorMessage:
ld a,120
; Call like printf, DE=format string (offset into appvar), A=duration
SetEmulatorMessageWithDuration:
ld ix,(ArcBase)
add ix,de
ex (sp),ix
ld hl,emulatorMessageDuration
ld (hl),a
inc hl
push hl
ld a,(MessageDisplay)
or a
call nz,_sprintf
pop hl
ex (sp),ix
jp reset_preserved_area
PutEmulatorMessage:
xor a
ld (cursorCol),a
ld (cursorRow),a
ld a,(ScalingMode)
or a
ld a,BLACK_BYTE
jr nz,_
; Modify PutChar to use 8-bit pixels
ld a,8
ld (PutChar_8BitSMC1),a
ld (PutChar_8BitSMC2),a
ld a,$37 ;SCF
ld (PutChar_8BitSMC3),a
ld (PutChar_8BitSMC3+1),a
ld a,160-8
ld (PutChar_8BitSMC4),a
ld a,BLACK
_
call SetStringBgColor
ld a,WHITE
ACALL(PutStringColor)
; Restore PutChar to 4-bit
ld a,4
ld (PutChar_8BitSMC1),a
ld (PutChar_8BitSMC2),a
ld a,$CB ;SLA C
ld (PutChar_8BitSMC3),a
ld a,$21 ;SLA C
ld (PutChar_8BitSMC3+1),a
ld a,160-4
ld (PutChar_8BitSMC4),a
ld a,BLUE_BYTE
call SetStringBgColor
ld hl,(cursorCol)
add hl,hl
add hl,hl
ld h,10
jp PutEmulatorMessageRet
; Call like printf, A=color
PutStringFormatColor:
call SetStringColor
; Call like printf
PutStringFormat:
ld ix,text_buffer
ex (sp),ix
call _sprintf
pop hl
push ix
jr PutString
; HL points to string, A=color
PutStringColor:
call SetStringColor
; HL points to string
PutString:
ld a,(hl)
inc hl
or a
ret z
push hl
call PutChar
pop hl
jr PutString
PutNStringColor:
call SetStringColor
PutNString:
ld b,(hl)
inc hl
PutNString_B:
push bc
ld a,(hl)
inc hl
push hl
call PutChar
pop hl
pop bc
djnz PutNString_B
ret
PutNewLine:
push hl
ld hl,cursorCol
ld (hl),0
inc hl
ld a,(hl)
add a,10
cp 240
jr nc,_
ld (hl),a
_
pop hl
ret
font:
#import "font.bin"
digits_encoded:
.db %11101010,%10101010,%11100000
.db %01001100,%01000100,%11100000
.db %11000010,%01001000,%11100000
.db %11000010,%01000010,%11000000
.db %10101010,%11100010,%00100000
.db %11101000,%11000010,%11000000
.db %01101000,%11101010,%11100000
.db %11100010,%01001000,%10000000
.db %11101010,%11101010,%11100000
.db %11101010,%11100010,%11000000
.db %10100010,%01001000,%10100000
generate_digits:
APTR(digits_encoded)
ex de,hl
ld hl,digits
ld (display_digit_smc_1),a
ld (display_digit_smc_2),a
cpl
add a,161
ld (display_digit_smc_3),a
cp 160-4
jr z,generate_digits_8bit
ld b,11
_
push bc
ld b,3
_
ld a,(de)
inc de
ld c,a
_
sla c
sbc a,a
or BLACK+(15-WHITE)
sub 15-WHITE
ld (hl),a
sla c
sbc a,a
or BLACK+(15-WHITE)
sub 15-WHITE
rld
inc hl
ld a,l
and 3
jr nz,-_
djnz --_
ld c,12
add hl,bc
pop bc
djnz ---_
ret
generate_digits_8bit:
ld b,3*11
_
ld a,(de)
inc de
ld c,a
_
sla c
sbc a,a
or BLACK-(1+WHITE)
add a,1+WHITE
ld (hl),a
inc hl
ld a,l
and 7
jr nz,-_
djnz --_
ret
#ifdef DEBUG
StartText:
.db "Starting!\n",0
WaitLoopSearchMessage:
.db "Searching for waitloop at %04X.\n",0
WaitLoopIdentifiedMessage:
.db "Setting waitloop at %04X, var %04X.\n",0
ByteFormat:
.db "%02X",0
LookupGBMessage:
.db "Looking up GB address from %04X\n",0
LookupGBFoundMessage:
.db "Found GB %06X @ %04X\n",0
FlushMessage:
.db "Flushing recompiled code!\n",0
CacheMissMessage:
.db "Cache miss at %02X:%04X\n",0
LookupMessage:
.db "Looking up GB code at %02X:%04X\n",0
RecompileMessage:
.db "Recompiling %02X:%04X (%06X) to %04X\n",0
RecompileRamMessage:
.db "Recompiling RAM:%04X (%06X) to %04X\n",0
CoherencyFailedMessage:
.db "RAM coherency failed, routine=%04X\n",0
PaddingUpdateMessage:
.db "RAM block padding increased to %06X\n",0
RuntimeErrorMessage:
.db "Runtime error occurred!\n",0
InvalidOpcodeErrorMessage:
.db "Encountered invalid opcode at %04X\n",0
#endif