#[1] seek2.s 10 11 0001 .ifdef HUC #[3] huc.inc 12 .include "huc.inc" ; HUC 1 ; 2 ; Hu-C internal include file 3 ; 4 5 6 ; variables 7 ; ---- 8 9 2000 .zp 10 --:2000 __sp 11 --:2000 __stack .ds 2 12 --:2002 __arg_idx .ds 1 13 --:2003 __temp .ds 8 14 --:200B __ptr .ds 2 15 --:200D __fbank .ds 1 16 --:200E __fptr .ds 2 17 --:2010 __expr .ds 2 18 19 20 ; macros 21 ; ---- 22 23 .macro __farptr 24 ldy #bank(\1) 25 sty \2 26 ldy #low(\1) 27 sty \3 28 ldy #high(\1) 29 sty \3+1 30 .endm 31 32 .macro __farptr_i 33 sax 34 add #low(\1) 35 .if (\# = 3) 36 sta <\3 37 .else 38 sta <__fptr 39 .endif 40 sax 41 adc #high(\1) & $1F 42 .if (\# = 3) 43 sta <\3+1 44 .else 45 tax 46 .endif 47 rol A 48 rol A 49 rol A 50 rol A 51 and #$F 52 add #bank(\1) 53 .if (\# = 3) 54 sta <\2 55 .endif 56 .endm 57 58 .macro __farptr_get 59 stx <\1 60 ldy #2 61 lda [__ptr],Y 62 sta <\2 63 iny 64 lda [__ptr],Y 65 sta <\2+1 66 .endm 67 68 .macro __fgetb 69 tam #3 70 txa 71 and #$1F 72 ora #$60 73 sta <__fptr+1 74 lda [__fptr] 75 tax 76 cla 77 .endm 78 79 __ldb .macro 80 .if (\# = 2) 81 clx 82 lda \1 83 clc 84 adc #low(\2) 85 sax 86 adc #high(\2) 87 .else 88 ldx \1 89 __extw 90 .endif 91 .endm 92 93 __ldbp .macro 94 lda [\1] 95 tax 96 __extw 97 .endm 98 99 __stbps .macro 100 __stw <__temp 101 __ldwp __stack 102 __stw <__ptr 103 __ldw <__temp 104 sax 105 sta [__ptr] 106 sax 107 __addmi 2,__stack 108 .endm 109 110 __ldw .macro 111 .if (\# = 2) 112 lda \1 113 clc 114 adc #low(\2) 115 tax 116 lda \1+1 117 adc #high(\2) 118 .else 119 ldx \1 120 lda \1+1 121 .endif 122 .endm 123 124 __ldwp .macro 125 lda [\1] 126 tax 127 ldy #1 128 lda [\1],Y 129 .endm 130 131 __ldwi .macro 132 ldx #low(\1) 133 lda #high(\1) 134 .endm 135 136 __stw .macro 137 stx \1 138 sta \1+1 139 .endm 140 141 __stwp .macro 142 sax 143 sta [\1] 144 sax 145 ldy #1 146 sta [\1],Y 147 .endm 148 149 __stwps .macro 150 __stw <__temp 151 __ldwp __stack 152 __stw <__ptr 153 __ldw <__temp 154 __stwp __ptr 155 __addmi 2,__stack 156 .endm 157 158 __pushw .macro 159 __submi 2,__stack 160 sax 161 sta [__stack] 162 sax 163 ldy #1 164 sta [__stack],Y 165 .endm 166 167 __popw .macro 168 lda [__stack] 169 tax 170 ldy #1 171 lda [__stack],Y 172 __addmi 2,__stack 173 .endm 174 175 __calls .macro 176 pha 177 ldy #\1 178 lda [__stack],Y 179 sta <__ptr 180 incw <__stack 181 lda [__stack],Y 182 sta <__ptr+1 183 incw <__stack 184 pla 185 jsr hook 186 .endm 187 188 __swapw .macro 189 pha 190 ldy #1 191 lda [__stack],Y 192 sta <__temp 193 lda [__stack] 194 sax 195 sta [__stack] 196 pla 197 sta [__stack],Y 198 lda <__temp 199 .endm 200 201 202 ; TODO : check if we need pha/pla or not 203 __tstw .macro 204 ; pha 205 stx <__temp 206 ora <__temp 207 ; pla 208 .endm 209 210 __lsrw .macro 211 lsr A 212 sax 213 ror A 214 sax 215 .endm 216 217 __aslw .macro 218 sax 219 asl A 220 sax 221 rol A 222 .endm 223 224 __aslws .macro 225 asl [__stack] 226 ldy #1 227 rol [__stack],Y 228 .endm 229 230 __asrw .macro 231 cmp #$80 232 ror A 233 sax 234 ror A 235 sax 236 .endm 237 238 __extw .macro 239 ; txa ; signed 240 ; cla 241 ; bpl .x_\@ 242 ; dec A 243 ;.x_\@: 244 cla ; unsigned 245 .endm 246 247 __comw .macro 248 sax 249 eor #$FF 250 sax 251 eor #$FF 252 .endm 253 254 __negw .macro 255 sax 256 eor #$FF 257 clc 258 adc #1 259 sax 260 eor #$FF 261 adc #0 262 .endm 263 264 __boolw .macro 265 stx <__temp 266 ora <__temp 267 clx 268 beq .x\@ 269 inx 270 .x\@ cla 271 .endm 272 273 __notw .macro 274 stx <__temp 275 ora <__temp 276 clx 277 bne .x\@ 278 inx 279 .x\@ cla 280 .endm 281 282 __addw .macro 283 clc 284 sax 285 adc \1 286 sax 287 adc \1+1 288 .endm 289 290 __addwi .macro 291 clc 292 sax 293 adc #low(\1) 294 sax 295 adc #high(\1) 296 .endm 297 298 __addmi .macro 299 pha 300 clc 301 lda <\2 302 adc #low(\1) 303 sta <\2 304 lda <\2+1 305 adc #high(\1) 306 sta <\2+1 307 pla 308 .endm 309 310 __subw .macro 311 sec 312 sax 313 sbc \1 314 sax 315 sbc \1+1 316 .endm 317 318 __subwi .macro 319 sec 320 sax 321 sbc #low(\1) 322 sax 323 sbc #high(\1) 324 .endm 325 326 __submi .macro 327 pha 328 sec 329 lda <\2 330 sbc #low(\1) 331 sta <\2 332 lda <\2+1 333 sbc #high(\1) 334 sta <\2+1 335 pla 336 .endm 337 338 __addws .macro 339 sax 340 clc 341 adc [__stack] 342 sax 343 ldy #1 344 adc [__stack],Y 345 __addmi 2, __stack 346 .endm 347 348 __subws .macro 349 stx <__temp 350 sta <__temp+1 351 sec 352 lda [__stack] 353 sbc <__temp 354 tax 355 ldy #1 356 lda [__stack],Y 357 sbc <__temp+1 358 __addmi 2, __stack 359 .endm 360 361 __orws .macro 362 sax 363 ora [__stack] 364 sax 365 ldy #1 366 ora [__stack],Y 367 __addmi 2,__stack 368 .endm 369 370 __orwi .macro 371 sax 372 ora #low(\1) 373 sax 374 ora #high(\1) 375 .endm 376 377 __orw .macro 378 sax 379 ora \1 380 sax 381 ora \1+1 382 .endm 383 384 __andws .macro 385 sax 386 and [__stack] 387 sax 388 ldy #1 389 and [__stack],Y 390 __addmi 2,__stack 391 .endm 392 393 __andwi .macro 394 sax 395 and #low(\1) 396 sax 397 and #high(\1) 398 .endm 399 400 __andw .macro 401 sax 402 and \1 403 sax 404 and \1+1 405 .endm 406 407 __eorws .macro 408 sax 409 eor [__stack] 410 sax 411 ldy #1 412 eor [__stack],Y 413 __addmi 2,__stack 414 .endm 415 416 __lbra .macro 417 jmp \1 418 .endm 419 420 __lbeq .macro 421 bne .x\@ 422 jmp \1 423 .x\@ 424 .endm 425 426 __lbne .macro 427 beq .x\@ 428 jmp \1 429 .x\@ 430 .endm 431 432 __call .macro 433 call \1 434 .endm 435 436 _set_bgpal .macro 437 set_bgpal \1,\2,\3 438 .endm 439 440 _set_sprpal .macro 441 set_sprpal \1,\2,\3 442 .endm 443 444 _load_background .macro 445 vload $1000,\1,#$4000 446 vsync 447 set_bgpal #0, \2,#16 448 batcpy #$0, \3, \4, \5 449 .endm 450 #[2] startup.asm #[3] huc_opt.inc 13 .include "huc_opt.inc" 1 ; 2 ; Hu-C internal include file 3 ; 4 5 ; optimized macros 6 ; ---- 7 8 ; phw 9 ; 10 .macro __phw 11 ; #1 (bytes : 9, cycles : 16) 12 ; #2 (bytes : 16, cycles : 28) 13 14 .if (\# = 2) 15 tay 16 lda <__arg_idx 17 add #\2 18 sta <__arg_idx 19 say 20 .else 21 ldy <__arg_idx 22 .endif 23 24 sta __arg-(\1),Y 25 txa 26 sta __arg-(\1-1),Y 27 .endm 28 29 ; phb 30 ; 31 .macro __phb 32 ; #1 (bytes : 6, cycles : 11) 33 ; #2 (bytes : 12, cycles : 21) 34 35 .if (\# = 2) 36 lda <__arg_idx 37 add #\2 38 sta <__arg_idx 39 tay 40 .else 41 ldy <__arg_idx 42 .endif 43 44 txa 45 sta __arg-(\1),Y 46 .endm 47 48 ; plw 49 ; 50 .macro __plw 51 ; (bytes : 9/12, cycles : 16/22) 52 53 dey 54 lda __arg,Y 55 .if (\#) 56 sta \1 57 .else 58 tax 59 .endif 60 dey 61 lda __arg,Y 62 .if (\#) 63 sta \1+1 64 .endif 65 .endm 66 67 ; plb 68 ; 69 .macro __plb 70 ; (bytes : 6/7, cycles : 11/12) 71 72 .if (\# = 2) 73 dey 74 ldx __arg,Y 75 stx \1 76 .else 77 dey 78 lda __arg,Y 79 .if (\#) 80 sta \1 81 .endif 82 .endif 83 .endm 84 85 ; lea_s 86 ; 87 .macro __lea_s 88 ; (bytes : 10, cycles : 16) 89 90 lda <__sp 91 clc 92 adc #LOW(\1) 93 tax 94 lda <__sp+1 95 adc #HIGH(\1) 96 .endm 97 98 ; pea_s 99 ; 100 .macro __pea_s 101 ; (bytes : 25, cycles : 44) 102 103 lda <__sp 104 sec 105 sbc #2 106 bcs .x_\@ 107 dec <__sp+1 108 .x_\@: sta <__sp 109 clc 110 adc #LOW(\1+2) 111 sta [__sp] 112 tax 113 lda <__sp+1 114 adc #HIGH(\1+2) 115 ldy #1 116 sta [__sp],Y 117 .endm 118 119 ; ldb_s 120 ; 121 .macro __ldb_s 122 .if (\1 < 256) 123 ; short index (bytes : 9, cycles : 13/17) 124 125 ldy #\1 126 lda [__sp],Y 127 tax 128 cla 129 ; bpl .x_\@ ; signed 130 ; dec A 131 ;.x_\@: 132 .else 133 ; long index (bytes : 20, cycles : 37/41) 134 135 addw #\1,<__sp,<__ptr ; 13,26 136 lda [__ptr] 137 tax 138 cla 139 ; bpl .x_\@ ; signed 140 ; dec A 141 ;.x_\@: 142 .endif 143 .endm 144 145 ; ldb_p 146 ; 147 .macro __ldb_p 148 ; (bytes : 11, cycles : 19/23) 149 stx <__ptr 150 sta <__ptr+1 151 lda [__ptr] 152 tax 153 cla 154 ; bpl .x_\@ ; signed 155 ; dec A 156 ;.x_\@: 157 .endm 158 159 ; ldw_s 160 ; 161 .macro __ldw_s 162 .if (\1 < 255) 163 ; short index (bytes : 7/8, cycles : 18/20) 164 .if (\1 = 0) 165 lda [__sp] 166 tax 167 ldy #1 168 lda [__sp],Y 169 .else 170 ldy #\1 171 lda [__sp],Y 172 tax 173 iny 174 lda [__sp],Y 175 .endif 176 .else 177 ; long index (bytes : 20, cycles : 44) 178 179 addw #\1,<__sp,<__ptr ; 13,26 180 lda [__ptr] 181 tax 182 ldy #1 183 lda [__ptr],Y 184 .endif 185 .endm 186 187 ; stbi_s 188 ; 189 .macro __stbi_s 190 .if (\2 < 256) 191 ; short index (bytes : 8/ 9, cycles : 15) 192 193 lda #LOW(\1) 194 ldy #\2 195 sta [__sp],Y 196 tax 197 ; lda #HIGH(\1) 198 cla 199 .else 200 ; long index (bytes : 19/20, cycles : 39) 201 202 addw #\2,<__sp,<__ptr ; 13,26 203 lda #LOW(\1) 204 sta [__ptr] 205 tax 206 ; lda #HIGH(\1) 207 cla 208 .endif 209 .endm 210 211 ; stwi_s 212 ; 213 .macro __stwi_s 214 .if (\2 < 255) 215 ; short index (bytes : 12, cycles : 24) 216 217 lda #LOW(\1) 218 ldy #\2 219 sta [__sp],Y 220 tax 221 lda #HIGH(\1) 222 iny 223 sta [__sp],Y 224 .else 225 ; long index (bytes : 24, cycles : 48) 226 227 addw #\2,<__sp,<__ptr ; 13,26 228 lda #LOW(\1) 229 sta [__ptr] 230 tax 231 lda #HIGH(\1) 232 ldy #1 233 sta [__ptr],Y 234 .endif 235 .endm 236 237 ; stb_s 238 ; 239 .macro __stb_s 240 .if (\1 < 255) 241 ; short index (bytes : 6, cycles : 13) 242 243 sax 244 ldy #\1 245 sta [__sp],Y 246 sax 247 .else 248 ; long index (bytes : 18, cycles : 42) 249 250 pha 251 addw #\1,<__sp,<__ptr ; 13,26 252 txa 253 sta [__ptr] 254 pla 255 .endif 256 .endm 257 258 ; stw_s 259 ; 260 .macro __stw_s 261 .if (\1 < 255) 262 ; short index (bytes : 9, cycles : 22) 263 264 sax 265 ldy #\1 266 sta [__sp],Y 267 sax 268 iny 269 sta [__sp],Y 270 .else 271 ; long index (bytes : 22, cycles : 51) 272 273 pha 274 addw #\1,<__sp,<__ptr ; 13,26 275 txa 276 sta [__ptr] 277 pla 278 ldy #1 279 sta [__ptr],Y 280 .endif 281 .endm 282 283 ; addw_s 284 ; 285 .macro __addw_s 286 .if (\1 < 255) 287 ; short index (bytes : 10, cycles : 24) 288 289 ldy #\1 290 clc 291 sax 292 adc [__sp],Y 293 sax 294 iny 295 adc [__sp],Y 296 .else 297 ; long index (bytes : 24, cycles : 55) 298 299 pha ; 1, 3 300 addw #\1,<__sp,<__ptr ; 13,26 301 pla ; 1, 4 302 clc 303 sax 304 adc [__ptr] 305 sax 306 ldy #1 307 adc [__ptr],Y 308 .endif 309 .endm 310 311 ; incw_s 312 ; 313 .macro __incw_s 314 ; (bytes : 16, cycles : 24/40) 315 316 pha 317 ldy #\1 318 txa 319 inc A 320 sta [__sp],Y 321 bne .x_\@ 322 iny 323 lda [__sp],Y 324 inc A 325 sta [__sp],Y 326 .x_\@: 327 pla 328 .endm 329 330 ; ldd_i 331 ; 332 .macro __ldd_i 333 stw #(\1) & 0xFFFF,<\2 334 stw #(\1) >> 16,<\3 335 ldx #low(\2) 336 lda #high(\2) 337 .endm 338 339 ; ldd_b 340 ; 341 .macro __ldd_b 342 lda \1 343 sta <\2 344 stz <\2+1 345 stwz <\3 346 ldx #low(\2) 347 lda #high(\2) 348 .endm 349 350 ; ldd_w 351 ; 352 .macro __ldd_w 353 stw \1,<\2 354 stwz <\3 355 ldx #low(\2) 356 lda #high(\2) 357 .endm 358 359 ; ldd_s_b 360 ; 361 .macro __ldd_s_b 362 __ldb_s \1 363 stx <\2 364 sta <\2+1 365 stwz <\3 366 ldx #low(\2) 367 lda #high(\2) 368 .endm 369 370 ; ldd_s_w 371 ; 372 .macro __ldd_s_w 373 __ldw_s \1 374 stx <\2 375 sta <\2+1 376 stwz <\3 377 ldx #low(\2) 378 lda #high(\2) 379 .endm 380 #[2] startup.asm 14 .endif ; HUC 15 #[3] standard.inc 16 .include "standard.inc" ; HUCARD 1 ; 2 ; STANDARD.INC - MagicKit standard include file 3 ; #[4] equ.inc 4 .include "equ.inc" 1 ; 2 ; EQU.INC - MagicKit Standard Equates 3 ; 4 ; 5 6 7 ; -------- 8 ; This block defines standard system variables 9 ; in zero-page. 10 ; 11 12 20F3 vdc_crl = $20F3 ; VDC control register (copy of) 13 20F4 vdc_crh = $20F4 ; 14 20F5 irq_m = $20F5 ; interrupt control mask (copy of) 15 20F6 vdc_sr = $20F6 ; VDC status register (copy of) 16 20F7 vdc_reg = $20F7 ; VDC register index (copy of) 17 18 ; old aliases (for compatibility only, don't use them) 19 20 0000 .ifndef HUC 24 .endif 25 26 ; -------- 27 ; This block defines standard parameter-passing 28 ; areas (in zero-page) for subroutines. 29 ; 30 31 20EC _bp = $20EC ; base pointer 32 20EE _si = $20EE ; source address 33 20F0 _di = $20F0 ; destination address 34 20F8 _ax = $20F8 35 20F8 _al = $20F8 36 20F9 _ah = $20F9 37 20FA _bx = $20FA 38 20FA _bl = $20FA 39 20FB _bh = $20FB 40 20FC _cx = $20FC 41 20FC _cl = $20FC 42 20FD _ch = $20FD 43 20FE _dx = $20FE 44 20FE _dl = $20FE 45 20FF _dh = $20FF 46 47 48 ; -------- 49 ; This block defines names for standard 50 ; devices and equipment on the PC-Engine. 51 ; (they should be self-explanatory...) 52 ; 53 54 ; ---- 55 ; VDC (Video Display Controller) 56 57 0000 videoport .equ $0000 58 59 0000 video_reg .equ videoport 60 0000 video_reg_l .equ video_reg 61 0001 video_reg_h .equ video_reg+1 62 63 0002 video_data .equ videoport+2 64 0002 video_data_l .equ video_data 65 0003 video_data_h .equ video_data+1 66 67 68 ; ---- 69 ; VCE (Video Color Encoder) 70 71 0400 colorport .equ $0400 72 0400 color_ctrl .equ colorport 73 74 0402 color_reg .equ colorport+2 75 0402 color_reg_l .equ color_reg 76 0403 color_reg_h .equ color_reg+1 77 78 0404 color_data .equ colorport+4 79 0404 color_data_l .equ color_data 80 0405 color_data_h .equ color_data+1 81 82 0001 .ifdef HUC 83 0402 _color_reg .equ colorport+2 84 0404 _color_data .equ colorport+4 85 .endif 86 87 ; ---- 88 ; PSG (Programmable Sound Generator) 89 90 0800 psgport .equ $0800 91 0800 psg_ch .equ psgport 92 0801 psg_mainvol .equ psgport+1 93 0802 psg_freqlo .equ psgport+2 94 0803 psg_freqhi .equ psgport+3 95 0804 psg_ctrl .equ psgport+4 96 0805 psg_pan .equ psgport+5 97 0806 psg_wavebuf .equ psgport+6 98 0807 psg_noise .equ psgport+7 99 0808 psg_lfofreq .equ psgport+8 100 0809 psg_lfoctrl .equ psgport+9 101 102 103 ; ---- 104 ; TIMER 105 106 0C00 timerport .equ $0C00 107 0C00 timer_cnt .equ timerport 108 0C01 timer_ctrl .equ timerport+1 109 110 111 ; ---- 112 ; I/O port 113 114 1000 joyport .equ $1000 115 116 117 ; ---- 118 ; IRQ ports 119 120 1400 irqport .equ $1400 121 1402 irq_disable .equ irqport+2 122 1403 irq_status .equ irqport+3 123 124 ; ---- 125 ; CDROM/Expansion ports 126 127 1800 cd_port .equ $1800 128 129 1803 bram_lock .equ cd_port+3 ; a read access here will do it 130 1807 bram_unlock .equ cd_port+7 ; actually, bit #$80 of this byte 131 132 ; ---- 133 ; Arcade Card ports 134 135 1A00 ac_port .equ $1A00 136 1A00 ac_data1 .equ ac_port 137 1A01 ac_data1_alt .equ ac_port+1 138 1A02 ac_base1_l .equ ac_port+2 139 1A03 ac_base1_m .equ ac_port+3 140 1A04 ac_base1_h .equ ac_port+4 141 1A05 ac_offset1_l .equ ac_port+5 142 1A06 ac_offset1_m .equ ac_port+6 143 1A09 ac_cntrol1 .equ ac_port+9 144 1A0A ac_addoffset1 .equ ac_port+$0A 145 146 1AE0 ac_shftreg .equ $1AE0 ; actually, probably rotate register 147 1AE0 ac_shftreg_0 .equ ac_shftreg 148 1AE1 ac_shftreg_1 .equ ac_shftreg+1 149 1AE2 ac_shftreg_2 .equ ac_shftreg+2 150 1AE3 ac_shftreg_3 .equ ac_shftreg+3 151 1AE4 ac_shft_bits .equ ac_shftreg+4 ; positive = shift left 152 153 1AFD ac_identbase .equ $1AFD 154 1AFD ac_identver_l .equ ac_identbase 155 1AFE ac_identver_h .equ ac_identbase+1 156 1AFF ac_identflag .equ ac_identbase+2 157 158 0051 AC_IDENT .equ $51 ; if ac_identflag = AC_IDENT, then AC in use 159 160 161 ; -------- 162 ; This block defines names for macro 163 ; argument types (\?x). 164 ; 165 166 0000 ARG_NONE .equ 0 167 0001 ARG_REG .equ 1 168 0002 ARG_IMMED .equ 2 169 0003 ARG_ABS .equ 3 170 0003 ARG_ABSOLUTE .equ 3 171 0004 ARG_INDIRECT .equ 4 172 0005 ARG_STRING .equ 5 173 0006 ARG_LABEL .equ 6 174 #[3] standard.inc #[4] macro.inc 5 .include "macro.inc" 1 ; 2 ; MACRO.INC - MagicKit standard MACRO definitions 3 ; 4 5 map .macro ; map a memory bank into 6 lda #bank(\1) ; addressable memory 7 tam #page(\1) 8 .endm 9 10 ; 11 ; MAPLIBFUNC - Re-map a library function into $A000-space if it's 12 ; not in library bank #1 13 ; 14 maplibfunc .macro 15 tay 16 tma #page(\1) 17 pha 18 lda #bank(\1) 19 tam #page(\1) 20 tya 21 jsr \1 22 tay 23 pla 24 tam #page(\1) 25 tya 26 .endm 27 28 29 ; 30 ; STWZ - store a word-sized zero value at stated memory location 31 ; 32 stwz .macro 33 stz LOW_BYTE \1 34 stz HIGH_BYTE \1 35 .endm 36 37 ; 38 ; STW - store a word-sized value at stated memory location 39 ; 40 stw .macro 41 lda LOW_BYTE \1 42 sta LOW_BYTE \2 43 lda HIGH_BYTE \1 44 sta HIGH_BYTE \2 45 .endm 46 47 stb .macro 48 lda \1 49 sta \2 50 .endm 51 52 ; 53 ; ADDW - add word-sized value to value at stated memory location, 54 ; storing result back into stated memory location (or into 55 ; another destination memory location - third arg) 56 ; 57 addw .macro 58 .if (\# = 3) 59 ; 3-arg mode 60 ; 61 clc 62 lda LOW_BYTE \2 63 adc LOW_BYTE \1 64 sta LOW_BYTE \3 65 lda HIGH_BYTE \2 66 adc HIGH_BYTE \1 67 sta HIGH_BYTE \3 68 .else 69 ; 2-arg mode 70 ; 71 clc 72 lda LOW_BYTE \2 73 adc LOW_BYTE \1 74 sta LOW_BYTE \2 75 lda HIGH_BYTE \2 76 adc HIGH_BYTE \1 77 sta HIGH_BYTE \2 78 .endif 79 .endm 80 81 ; 82 ; ADCW - add word-sized value plus carry to value at stated memory location, 83 ; storing result back into stated memory location 84 ; 85 adcw .macro 86 lda LOW_BYTE \2 87 adc LOW_BYTE \1 88 sta LOW_BYTE \2 89 lda HIGH_BYTE \2 90 adc HIGH_BYTE \1 91 sta HIGH_BYTE \2 92 .endm 93 94 ; 95 ; SUBW - substract word-sized value from value at stated memory location, 96 ; storing result back into stated memory location 97 ; 98 subw .macro 99 sec 100 lda LOW_BYTE \2 101 sbc LOW_BYTE \1 102 sta LOW_BYTE \2 103 lda HIGH_BYTE \2 104 sbc HIGH_BYTE \1 105 sta HIGH_BYTE \2 106 .endm 107 108 ; 109 ; SBCW - substract word-sized value plus carry from value at stated memory 110 ; location, storing result back into stated memory location 111 ; 112 sbcw .macro 113 lda LOW_BYTE \2 114 sbc LOW_BYTE \1 115 sta LOW_BYTE \2 116 lda HIGH_BYTE \2 117 sbc HIGH_BYTE \1 118 sta HIGH_BYTE \2 119 .endm 120 121 cmpw .macro 122 lda HIGH_BYTE \2 123 cmp HIGH_BYTE \1 124 bne .x_\@ 125 lda LOW_BYTE \2 126 cmp LOW_BYTE \1 127 .x_\@: 128 .endm 129 130 tstw .macro ; test if the word-sized 131 lda \1 ; value at stated memory 132 ora \1+1 ; location is zero 133 .endm 134 135 incw .macro ; increment a word-sized 136 inc \1 ; value at stated memory 137 bne .x_\@ ; location 138 inc \1+1 139 .x_\@: 140 .endm 141 142 decw .macro ; decrement a word-sized 143 sec ; value at stated memory 144 lda \1 ; location 145 sbc #1 146 sta \1 147 lda \1+1 148 sbc #0 149 sta \1+1 150 .endm 151 152 rolw .macro ; rotate word-sized value 153 rol \1 ; (at stated memory location) 154 rol \1+1 155 .endm 156 157 aslw .macro ; arithmetic shift-left 158 asl \1 ; word-sized value (at stated 159 rol \1+1 ; memory location) 160 .endm 161 162 lsrw .macro ; logical shift-right word-sized 163 lsr \1+1 ; value (at stated memory 164 ror \1 ; location) 165 .endm 166 167 rorw .macro ; rotate right word-sized value 168 ror \1+1 ; (at stated memory location) 169 ror \1 170 .endm 171 172 negw .macro ; negate word-sized value 173 cla ; (at stated memory location) 174 sub \1 ; 2's complement 175 sta \1 176 cla 177 sbc \1+1 178 sta \1+1 179 .endm 180 181 neg .macro ; negate byte-sized value 182 eor #$FF ; in register A 183 inc A ; 2's complement 184 .endm 185 186 add .macro ; add byte-sized value to 187 .if (\# = 2) ; register A (handle carry 188 lda \2 ; flag) 189 clc 190 adc \1 191 sta \2 192 .else 193 clc 194 adc \1 195 .endif 196 .endm 197 198 sub .macro ; subtract byte-sized value 199 .if (\# = 2) ; from register A (handle 200 lda \2 ; carry flag) 201 sec 202 sbc \1 203 sta \2 204 .else 205 sec 206 sbc \1 207 .endif 208 .endm 209 210 blo .macro ; branch if 'lower' 211 bcc \1 212 .endm 213 214 bhs .macro ; branch if 'higher or same' 215 bcs \1 216 .endm 217 218 bhi .macro ; branch if 'higher' 219 beq .x_\@ 220 bcs \1 221 .x_\@: 222 .endm 223 224 ;------------------------------- 225 226 ; 227 ; Long branch MACROs 228 ; 229 230 lbne .macro 231 beq .x_\@ 232 jmp \1 233 .x_\@ 234 .endm 235 236 lbeq .macro 237 bne .x_\@ 238 jmp \1 239 .x_\@ 240 .endm 241 242 lbpl .macro 243 bmi .x_\@ 244 jmp \1 245 .x_\@ 246 .endm 247 248 lbmi .macro 249 bpl .x_\@ 250 jmp \1 251 .x_\@ 252 .endm 253 254 lbcc .macro 255 bcs .x_\@ 256 jmp \1 257 .x_\@ 258 .endm 259 260 lbcs .macro 261 bcc .x_\@ 262 jmp \1 263 .x_\@ 264 .endm 265 266 lblo .macro 267 bcs .x_\@ 268 jmp \1 269 .x_\@ 270 .endm 271 272 lbhs .macro 273 bcc .x_\@ 274 jmp \1 275 .x_\@ 276 .endm 277 278 279 ;------------------------------- 280 281 ; 282 ; These MACROs are the same as the MACROs 283 ; without an underscore; the difference 284 ; is these MACROs preserve the state of 285 ; the registers they use (at the expense 286 ; of speed) 287 ; 288 289 _stw .macro 290 pha 291 stw \1,\2 292 pla 293 .endm 294 295 _addw .macro 296 pha 297 addw \1,\2 298 pla 299 .endm 300 301 _adcw .macro 302 pha 303 adcw \1,\2 304 pla 305 .endm 306 307 _subw .macro 308 pha 309 subw \1,\2 310 pla 311 .endm 312 313 _sbcw .macro 314 pha 315 sbcw \1,\2 316 pla 317 .endm 318 319 _cmpw .macro 320 pha 321 cmpw \1,\2 322 pla 323 .endm 324 325 _tstw .macro 326 pha 327 tstw \1 328 pla 329 .endm 330 331 _incw .macro 332 incw \1 333 .endm 334 335 _decw .macro 336 pha 337 decw \1 338 pla 339 .endm 340 #[3] standard.inc #[4] func.inc 6 .include "func.inc" 1 ; 2 ; FUNC.INC - MagicKit Standard Functions 3 ; 4 ; 5 6 ; ---- 7 ; BATVAL - create a value for the BAT map 8 ; 9 ; parameters: 10 ; \1 = palette (0-15) 11 ; \2 = VRAM address of tile 12 13 BATVAL .func (\1<<12)|(\2>>4) 14 15 16 ; ---- 17 ; CHAR - create a BAT value for a character defined 18 ; using '.defchar' (uses default palette) 19 ; 20 ; parameters: 21 ; \1 = name of character 22 ; 23 CHAR .func (PAL(\1)<<12|VRAM(\1)>>4) 24 25 ; ---- 26 ; SPR_VRAM - return shifted value of sprite-pattern VRAM address 27 ; 28 ; parameters: 29 ; \1 = VRAM address of sprite 30 ; 31 SPR_VRAM .func (VRAM(\1)>>5) 32 #[3] standard.inc #[4] library.inc 7 .include "library.inc" 1 ; 2 ; LIBRARY.INC - MagicKit include-interface to LIBRARY.ASM 3 ; 4 5 ; 6 ; These MACROs are just simple one-line setups to the 7 ; back-end library subroutines. They simply setup 8 ; calling parameters, and call the subroutine 9 ; 10 11 12 ; set video memory read and write address: 13 ; 14 ; setvraddr(addr) 15 ; ---- 16 ; addr, new address in VRAM to read at 17 ; 18 .macro setvraddr 19 stw #\1,<_di 20 jsr set_read 21 .endm 22 23 ; setvwaddr(addr) 24 ; ---- 25 ; addr, new address in VRAM to write at 26 ; 27 .macro setvwaddr 28 stw #\1,<_di 29 jsr set_write 30 .endm 31 32 ; set_bgpal(index, data [, nb]) 33 ; ---- 34 ; index, sub-palette index (0-15) 35 ; data, color data memory address 36 ; nb, number of sub-palette to load (optional, one by default) 37 38 .macro set_bgpal 39 lda \1 40 sta <_al 41 .if (\?2 = ARG_LABEL) 42 stb #BANK(\2),<_bl 43 .else 44 stb #$FE,<_bl 45 .endif 46 stw #\2,<_si 47 .if \?3 48 lda \3 49 .else 50 lda #1 51 .endif 52 sta <_cl 53 jsr load_palette 54 .endm 55 56 ; set_sprpal(index, data [, nb]) 57 ; ---- 58 ; index, sub-palette index (0-15) 59 ; data, palette data memory address 60 ; nb, number of sub-palette to update (optional, one by default) 61 62 .macro set_sprpal 63 lda \1 64 add #16 65 sta <_al 66 .if (\?2 = ARG_LABEL) 67 stb #BANK(\2),<_bl 68 .else 69 stb #$FE,<_bl 70 .endif 71 stw #\2,<_si 72 .if \?3 73 lda \3 74 .else 75 lda #1 76 .endif 77 sta <_cl 78 jsr load_palette 79 .endm 80 81 ; setcolor(index, r, g, b) 82 ; ---- 83 ; index, color index 84 ; r, red (0-7) 85 ; g, green (0-7) 86 ; b, blue (0-7) 87 88 .macro setcolor 89 stw \1,color_reg 90 stw #(((\3) << 6) + ((\2) << 3) + (\4)),color_data 91 .endm 92 93 ; vload([vram,] data, size) 94 ; ---- 95 ; vram, VRAM base address 96 ; data, video data memory address 97 ; size, number of words to copy 98 99 .macro vload 100 .if (\# = 3) 101 stw #\1,<_di 102 .if (\?2 = ARG_LABEL) 103 stb #BANK(\2),<_bl 104 .else 105 stb #$FE,<_bl 106 .endif 107 stw #\2,<_si 108 stw \3,<_cx 109 .else 110 stw #VRAM(\1),<_di 111 stb #BANK(\1),<_bl 112 stw #\1,<_si 113 stw #\2,<_cx 114 .endif 115 jsr load_vram 116 .endm 117 118 ; batcpy(vram, bat, w, h) 119 ; ---- 120 ; vram, VRAM base address 121 ; bat, BAT address in memory 122 ; w, nb of column to copy 123 ; h, nb of row 124 125 .macro batcpy 126 .if (\# = 5) 127 .fail "batcpy syntax has changed, update your code!" 128 .endif 129 stw \1,<_di 130 .if (\?2 = ARG_LABEL) 131 stb #BANK(\2),<_bl 132 .else 133 stb #$FE,<_bl 134 .endif 135 stw #\2,<_si 136 lda \3 137 sta <_cl 138 lda \4 139 sta <_ch 140 jsr load_bat 141 .endm 142 143 ; setmap(map, tile, ctable, w ,h) 144 ; ---- 145 ; map, map base address 146 ; tile, tile vram address 147 ; ctable, tile palette table address 148 ; w, map width 149 ; h, map height 150 151 .macro setmap 152 stw #BANK(\1),mapbank 153 stw #\1,mapaddr 154 stw #(\2)>>4,maptilebase 155 stw #\3,mapctable 156 stb #BANK(\3),mapctablebank 157 stw \4,mapwidth 158 stw \5,mapheight 159 .endm 160 161 ; mapcpy(vram, x, y, w, h) 162 ; ---- 163 ; vram, VRAM base address 164 ; x, x start coordinate in the map 165 ; y, y start coordinate 166 ; w, nb of column to copy 167 ; h, nb of row 168 169 .macro mapcpy 170 stw #\1,<_di 171 lda \2 172 sta <_cl 173 lda \3 174 sta <_ch 175 lda \4 176 sta <_dl 177 lda \5 178 sta <_dh 179 jsr load_map 180 .endm 181 182 ; fntcpy(vram, font, color, bg, nb) 183 ; ---- 184 ; vram, VRAM base address 185 ; font, font address in memory 186 ; color, character color 187 ; bg, bg color 188 ; nb, nb of char. to copy 189 190 .macro fntcpy 191 stw #\1,<_di 192 stb #BANK(\2),<_bl 193 stw #\2,<_si 194 lda \3 195 sta <_al 196 lda \4 197 sta <_ah 198 lda \4 199 sta <_cl 200 jsr load_font 201 .endm 202 203 ; scroll(num, x, y, top, bottom, cr) 204 ; ---- 205 ; num, scroll number (0-3) 206 ; x, BAT x position 207 ; y, BAT y position 208 ; top, screen window top 209 ; bottom, screen window bottom 210 ; cr, screen window display control (bg/sp) 211 212 .macro scroll 213 lda \1 214 tax 215 lda LOW_BYTE \2 216 sta scroll_xl,X 217 lda HIGH_BYTE \2 218 sta scroll_xh,X 219 lda LOW_BYTE \3 220 sta scroll_yl,X 221 lda HIGH_BYTE \3 222 sta scroll_yh,X 223 lda \4 224 sta scroll_top,X 225 lda \5 226 sta scroll_bottom,X 227 lda \6 228 ora #$01 229 sta scroll_cr,X 230 .endm 231 232 ; scroll_disable(num) 233 ; ---- 234 ; num, scroll number (0-3) 235 236 .macro scroll_disable 237 lda \1 238 tax 239 lda scroll_cr,X 240 and #$fe 241 sta scroll_cr,X 242 .endm 243 244 ; setxres (xres) 245 ; ---- 246 ; xres, horizontal display resolution 247 248 .macro setxres 249 stw #\1,<_ax 250 jsr set_xres 251 .endm 252 #[3] standard.inc #[4] sprites.inc 8 .include "sprites.inc" 1 ; 2 ; SPRITES.INC - MagicKit sprite MACRO definitions 3 ; 4 5 6 ; load_sprites(vram_addr, spr_bank, #nb_group) 7 ; ---- 8 ; vram_addr, destination address in VRAM 9 ; spr_bank, sprite bank address 10 ; nb_group, number of 32x64 patterns to copy 11 12 .macro load_sprites 13 14 ; put the VRAM address in _di 15 16 stw #\1,<_di 17 18 ; put the sprite bank address in _si/_bl 19 20 stw #\2,<_si 21 stb #BANK(\2),<_bl 22 23 ; get the number of patterns to copy, multiply it by $200 - 24 ; the size in words of a 32x64 pattern (remember that 25 ; 'load_vram' need a size in words), and put it in _cx 26 27 lda \3 28 asl A 29 stz <_cx 30 sta <_cx+1 31 32 ; call the 'load_vram' function 33 34 jsr load_vram 35 .endm 36 37 38 ; spr_set(#sprite, satb) 39 ; ---- 40 ; sprite, the sprite number (0-63) 41 ; satb, the address of the SATB in RAM 42 43 .macro spr_set 44 45 ; multiply the sprite number by 8 (the size of a SATB entry) 46 ; and put the result in _si 47 48 stz <_si+1 49 lda \1 50 asl A 51 asl A 52 asl A 53 rol <_si+1 54 sta <_si 55 56 ; add the satb address to _si 57 58 addw #\2,<_si 59 .endm 60 61 62 ; spr_x(#x [,offset]) 63 ; ---- 64 ; x, the new x coordinate 65 66 .macro spr_x 67 ldy #2 68 .if (\# = 2) 69 lda LOW_BYTE \1 70 clc 71 adc LOW_BYTE \2 72 sta [_si],Y 73 lda HIGH_BYTE \1 74 adc HIGH_BYTE \2 75 .else 76 lda LOW_BYTE \1 77 sta [_si],Y 78 lda HIGH_BYTE \1 79 .endif 80 iny 81 sta [_si],Y 82 .endm 83 84 85 ; spr_y(#y [,offset]) 86 ; ---- 87 ; y, the new y coordinate 88 89 .macro spr_y 90 .if (\# = 2) 91 lda LOW_BYTE \1 92 clc 93 adc LOW_BYTE \2 94 sta [_si] 95 lda HIGH_BYTE \1 96 adc HIGH_BYTE \2 97 .else 98 lda LOW_BYTE \1 99 sta [_si] 100 lda HIGH_BYTE \1 101 .endif 102 ldy #1 103 sta [_si],Y 104 .endm 105 106 107 ; spr_pattern(#addr) 108 ; ---- 109 ; addr, address of the sprite pattern in VRAM 110 111 .macro spr_pattern 112 ldy #4 113 .if (\?1 = ARG_IMMED) 114 lda #LOW((\1) >> 5) 115 sta [_si],Y 116 lda #HIGH((\1) >> 5) 117 .else 118 lda \1 119 sta [_si],Y 120 lda \1+1 121 .endif 122 iny 123 sta [_si],Y 124 .endm 125 126 127 ; spr_ctrl(#mask, #flag) 128 ; ---- 129 ; mask, mask of the bits to change 130 ; flag, new bit value 131 132 .macro spr_ctrl 133 ldy #7 134 lda \1 135 eor #$FF 136 and [_si],Y 137 ora \2 138 sta [_si],Y 139 .endm 140 141 142 ; spr_pri(#flag) 143 ; ---- 144 ; flag, new priority (1 = in foreground, 0 = in background) 145 146 .macro spr_pri 147 ldy #6 148 lda [_si],Y 149 and #$7F 150 ldx \1 151 beq .x\@ 152 ora #$80 153 .x\@: 154 sta [_si],Y 155 .endm 156 157 158 ; spr_pal(#index) 159 ; ---- 160 ; index, palette index (0-15) 161 162 .macro spr_pal 163 ldy #6 164 lda [_si],Y 165 and #$F0 166 ora \1 167 sta [_si],Y 168 .endm 169 170 171 ; init_satb(addr) 172 ; ---- 173 ; addr, the address of the local RAM SATB 174 175 .macro init_satb 176 stz \1 177 tii \1,\1+1,511 178 .endm 179 180 181 ; update_satb(satb[, addr] [,nb_sprite]) 182 ; ---- 183 ; satb, the address of the local RAM SATB 184 ; addr, the address where to copy the SATB in VRAM ($7F00 by default) 185 ; nb_sprite, number of sprite entry to copy (64 by default) 186 187 .macro update_satb 188 stw #\1,<_si 189 stb #BANK(\1),<_bl 190 .if (\?2) 191 stw #\2,<_di 192 .else 193 stw #$7F00,<_di 194 .endif 195 .if (\?3) 196 stw #(\3)*4,<_cx 197 .else 198 stw #$100,<_cx 199 .endif 200 jsr load_vram 201 .endm 202 203 204 ; ---- 205 0008 FLIP_X_MASK .equ $08 206 0080 FLIP_Y_MASK .equ $80 207 0088 FLIP_MASK .equ $88 208 0031 SIZE_MASK .equ $31 209 210 0000 NO_FLIP .equ 0 211 0000 NO_FLIP_X .equ 0 212 0000 NO_FLIP_Y .equ 0 213 0008 FLIP_X .equ $08 214 0080 FLIP_Y .equ $80 215 0000 SIZE_16x16 .equ 0 216 0010 SIZE_16x32 .equ $10 217 0030 SIZE_16x64 .equ $30 218 0001 SIZE_32x16 .equ $01 219 0011 SIZE_32x32 .equ $11 220 0031 SIZE_32x64 .equ $31 221 #[3] standard.inc #[4] vdc.inc 9 .include "vdc.inc" 1 ; 2 ; VDC.INC - MagicKit PC-Engine video MACRO definitions 3 ; 4 5 6 ; 7 ; VREG - set up video register to be read/written 8 ; 9 10 .macro vreg 11 lda \1 12 sta 99 --:2245 scr_w: .ds 1 100 --:2246 scr_h: .ds 1 101 102 2284 .org $2284 103 --:2284 soft_reset: .ds 2 ; soft reset jump loc (run+select) 104 105 0000 .if !(CDROM) 107 .endif 108 109 2680 .org $2680 110 --:2680 vsync_cnt: .ds 1 ; counter for 'wait_vsync' routine 111 112 --:2681 joybuf: .ds 5 ; 'delta' pad values collector 113 --:2686 joyhook: .ds 2 ; 'read_joypad' routine hook 114 --:2688 joycallback: .ds 6 ; joypad enhanced callback support 115 --:268E disp_cr: .ds 1 ; display control (1 = on, 0 = off) 116 --:268F clock_hh .ds 1 ; system clock, hours since startup (0-255) 117 --:2690 clock_mm .ds 1 ; system clock, minutes since startup (0-59) 118 --:2691 clock_ss .ds 1 ; system clock, seconds since startup (0-59) 119 --:2692 clock_tt .ds 1 ; system clock, ticks (1/60th sec) since startup (0-59) 120 121 --:2693 joy6: .ds 5 ; second byte for 6-button joysticks 122 --:2698 joytrg6: .ds 5 123 --:269D joyold6: .ds 5 124 --:26A2 joybuf6: .ds 5 125 126 --:26A7 joytmp: .ds 5 127 --:26AC joytmp6: .ds 5 128 129 0001 .if (CDROM) 130 --:26B1 ovl_running .ds 1 ; overlay # that is currently running 131 --:26B2 cd_super .ds 1 ; Major CDROM version # 132 --:26B3 irq_storea .ds 1 ; CDROM IRQ-specific handling stuff 133 --:26B4 irq_storeb .ds 1 134 --:26B5 ram_vsync_hndl .ds 25 135 --:26CE ram_hsync_hndl .ds 25 136 .endif ; (CDROM) 137 138 ;±±±[ STARTUP CODE ]±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± 139 140 ; Let's prepare this secondary libray bank first, for use later. 141 ; The reason, as you will see, is because code for a given function 142 ; which sits together in a file, may have things in zero-page, 143 ; bss, LIB1_BANK (ie. START_BANK), and LIB2_BANK. 144 ; 145 ; The assembler must know beforehand what address etc. to use as a basis. 146 ; 147 E000 .data 148 0001 .bank LIB2_BANK,"Base Library 2/Font" 149 6000 .org $6000 #[3] font.inc 150 .include "font.inc" 1 ; 8x8 monochrome font(s) 2 3 01:6000 font_1: 4 01:6000 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ;SPACE 01:6003 00 00 00 01:6006 00 00 5 01:6008 CC CC CC .db $cc,$cc,$cc,$88,$88,$00,$cc,$00 ;! 01:600B 88 88 00 01:600E CC 00 6 01:6010 6C 6C D8 .db $6c,$6c,$d8,$00,$00,$00,$00,$00 ;" 01:6013 00 00 00 01:6016 00 00 7 01:6018 6C FE 6C .db $6c,$fe,$6c,$6c,$6c,$fe,$6c,$00 ;# 01:601B 6C 6C FE 01:601E 6C 00 8 01:6020 10 38 40 .db $10,$38,$40,$38,$04,$38,$10,$00 ;$ 01:6023 38 04 38 01:6026 10 00 9 01:6028 42 A4 48 .db $42,$a4,$48,$10,$24,$4a,$84,$00 ;% 01:602B 10 24 4A 01:602E 84 00 10 01:6030 20 50 20 .db $20,$50,$20,$54,$88,$94,$62,$00 ;& 01:6033 54 88 94 01:6036 62 00 11 01:6038 18 30 60 .db $18,$30,$60,$00,$00,$00,$00,$00 ;' 01:603B 00 00 00 01:603E 00 00 12 01:6040 18 30 60 .db $18,$30,$60,$60,$60,$30,$18,$00 ;( 01:6043 60 60 30 01:6046 18 00 13 01:6048 30 18 0C .db $30,$18,$0c,$0c,$0c,$18,$30,$00 ;) 01:604B 0C 0C 18 01:604E 30 00 14 01:6050 54 38 7C .db $54,$38,$7c,$38,$54,$00,$00,$00 ;* 01:6053 38 54 00 01:6056 00 00 15 01:6058 00 10 10 .db $00,$10,$10,$7c,$10,$10,$00,$00 ;+ 01:605B 7C 10 10 01:605E 00 00 16 01:6060 00 00 00 .db $00,$00,$00,$18,$18,$08,$10,$00 ;, 01:6063 18 18 08 01:6066 10 00 17 01:6068 00 00 00 .db $00,$00,$00,$78,$00,$00,$00,$00 ;- 01:606B 78 00 00 01:606E 00 00 18 01:6070 00 00 00 .db $00,$00,$00,$00,$60,$60,$00,$00 ;. 01:6073 00 60 60 01:6076 00 00 19 01:6078 06 0C 18 .db $06,$0c,$18,$30,$60,$c0,$00,$00 ;/ 01:607B 30 60 C0 01:607E 00 00 20 21 01:6080 38 4C C6 .db $38,$4c,$c6,$c6,$c6,$64,$38,$00 ;0 01:6083 C6 C6 64 01:6086 38 00 22 01:6088 18 78 18 .db $18,$78,$18,$18,$18,$18,$7e,$00 ;1 01:608B 18 18 18 01:608E 7E 00 23 01:6090 7C C6 0E .db $7c,$c6,$0e,$3c,$78,$e0,$fe,$00 ;2 01:6093 3C 78 E0 01:6096 FE 00 24 01:6098 FE 0C 18 .db $fe,$0c,$18,$7c,$06,$c6,$7c,$00 ;3 01:609B 7C 06 C6 01:609E 7C 00 25 01:60A0 3C 6C CC .db $3c,$6c,$cc,$cc,$cc,$fe,$0c,$00 ;4 01:60A3 CC CC FE 01:60A6 0C 00 26 01:60A8 FE C0 FC .db $fe,$c0,$fc,$06,$06,$c6,$7c,$00 ;5 01:60AB 06 06 C6 01:60AE 7C 00 27 01:60B0 3C 60 C0 .db $3c,$60,$c0,$fc,$c6,$c6,$7c,$00 ;6 01:60B3 FC C6 C6 01:60B6 7C 00 28 01:60B8 FE C6 0C .db $fe,$c6,$0c,$18,$30,$30,$30,$00 ;7 01:60BB 18 30 30 01:60BE 30 00 29 01:60C0 7C C6 C6 .db $7c,$c6,$c6,$7c,$c6,$c6,$7c,$00 ;8 01:60C3 7C C6 C6 01:60C6 7C 00 30 01:60C8 7C C6 C6 .db $7c,$c6,$c6,$7e,$06,$0c,$78,$00 ;9 01:60CB 7E 06 0C 01:60CE 78 00 31 01:60D0 00 18 18 .db $00,$18,$18,$00,$18,$18,$00,$00 ;: 01:60D3 00 18 18 01:60D6 00 00 32 01:60D8 00 18 18 .db $00,$18,$18,$00,$18,$18,$30,$00 ;; 01:60DB 00 18 18 01:60DE 30 00 33 01:60E0 0C 18 30 .db $0c,$18,$30,$60,$30,$18,$0c,$00 ;< 01:60E3 60 30 18 01:60E6 0C 00 34 01:60E8 00 00 7C .db $00,$00,$7c,$00,$7c,$00,$00,$00 ;= 01:60EB 00 7C 00 01:60EE 00 00 35 01:60F0 60 30 18 .db $60,$30,$18,$0c,$18,$30,$60,$00 ;> 01:60F3 0C 18 30 01:60F6 60 00 36 01:60F8 7C C6 9E .db $7c,$c6,$9e,$38,$20,$00,$30,$00 ;? 01:60FB 38 20 00 01:60FE 30 00 37 38 01:6100 3C 42 9A .db $3c,$42,$9a,$aa,$aa,$5c,$00,$00 ;@ 01:6103 AA AA 5C 01:6106 00 00 39 01:6108 38 6C C6 .db $38,$6c,$c6,$c6,$fe,$c6,$c6,$00 ;A 01:610B C6 FE C6 01:610E C6 00 40 01:6110 FC C6 C6 .db $fc,$c6,$c6,$fc,$c6,$c6,$fc,$00 ;B 01:6113 FC C6 C6 01:6116 FC 00 41 01:6118 3C 66 C0 .db $3c,$66,$c0,$c0,$c0,$66,$3c,$00 ;C 01:611B C0 C0 66 01:611E 3C 00 42 01:6120 F8 CC C6 .db $f8,$cc,$c6,$c6,$c6,$cc,$f8,$00 ;D 01:6123 C6 C6 CC 01:6126 F8 00 43 01:6128 FE C0 C0 .db $fe,$c0,$c0,$fc,$c0,$c0,$fe,$00 ;E 01:612B FC C0 C0 01:612E FE 00 44 01:6130 FE C0 C0 .db $fe,$c0,$c0,$fc,$c0,$c0,$c0,$00 ;F 01:6133 FC C0 C0 01:6136 C0 00 45 01:6138 3C 66 C0 .db $3c,$66,$c0,$ce,$c6,$66,$3e,$00 ;G 01:613B CE C6 66 01:613E 3E 00 46 01:6140 C6 C6 C6 .db $c6,$c6,$c6,$fe,$c6,$c6,$c6,$00 ;H 01:6143 FE C6 C6 01:6146 C6 00 47 01:6148 7E 18 18 .db $7e,$18,$18,$18,$18,$18,$7e,$00 ;I 01:614B 18 18 18 01:614E 7E 00 48 01:6150 06 06 06 .db $06,$06,$06,$06,$06,$c6,$7c,$00 ;J 01:6153 06 06 C6 01:6156 7C 00 49 01:6158 C6 CC D8 .db $c6,$cc,$d8,$f0,$d8,$cc,$c6,$00 ;K 01:615B F0 D8 CC 01:615E C6 00 50 01:6160 C0 C0 C0 .db $c0,$c0,$c0,$c0,$c0,$c0,$fe,$00 ;L 01:6163 C0 C0 C0 01:6166 FE 00 51 01:6168 82 C6 EE .db $82,$c6,$ee,$fe,$d6,$c6,$c6,$00 ;M 01:616B FE D6 C6 01:616E C6 00 52 01:6170 86 C6 E6 .db $86,$c6,$e6,$f6,$de,$ce,$c6,$00 ;N 01:6173 F6 DE CE 01:6176 C6 00 53 01:6178 7C C6 C6 .db $7c,$c6,$c6,$c6,$c6,$c6,$7c,$00 ;O 01:617B C6 C6 C6 01:617E 7C 00 54 55 01:6180 FC C6 C6 .db $fc,$c6,$c6,$c6,$fc,$c0,$c0,$00 ;P 01:6183 C6 FC C0 01:6186 C0 00 56 01:6188 7C C6 C6 .db $7c,$c6,$c6,$c6,$de,$cc,$76,$00 ;Q 01:618B C6 DE CC 01:618E 76 00 57 01:6190 FC C6 C6 .db $fc,$c6,$c6,$fc,$d8,$cc,$c6,$00 ;R 01:6193 FC D8 CC 01:6196 C6 00 58 01:6198 7C C6 F0 .db $7c,$c6,$f0,$7c,$1e,$c6,$7c,$00 ;S 01:619B 7C 1E C6 01:619E 7C 00 59 01:61A0 7E 18 18 .db $7e,$18,$18,$18,$18,$18,$18,$00 ;T 01:61A3 18 18 18 01:61A6 18 00 60 01:61A8 C6 C6 C6 .db $c6,$c6,$c6,$c6,$c6,$c6,$7c,$00 ;U 01:61AB C6 C6 C6 01:61AE 7C 00 61 01:61B0 C6 C6 C6 .db $c6,$c6,$c6,$c6,$c6,$6c,$38,$00 ;V 01:61B3 C6 C6 6C 01:61B6 38 00 62 01:61B8 C6 C6 C6 .db $c6,$c6,$c6,$d6,$fe,$ee,$c6,$00 ;W 01:61BB D6 FE EE 01:61BE C6 00 63 01:61C0 C6 EE 7C .db $c6,$ee,$7c,$38,$7c,$ee,$c6,$00 ;X 01:61C3 38 7C EE 01:61C6 C6 00 64 01:61C8 66 66 66 .db $66,$66,$66,$3c,$18,$18,$18,$00 ;Y 01:61CB 3C 18 18 01:61CE 18 00 65 01:61D0 FE 0E 1C .db $fe,$0e,$1c,$38,$70,$e0,$fe,$00 ;Z 01:61D3 38 70 E0 01:61D6 FE 00 66 01:61D8 78 60 60 .db $78,$60,$60,$60,$60,$60,$78,$00 ;[ 01:61DB 60 60 60 01:61DE 78 00 67 01:61E0 C0 60 30 .db $c0,$60,$30,$18,$0c,$06,$00,$00 ;\ 01:61E3 18 0C 06 01:61E6 00 00 68 01:61E8 3C 0C 0C .db $3c,$0c,$0c,$0c,$0c,$0c,$3c,$00 ;] 01:61EB 0C 0C 0C 01:61EE 3C 00 69 01:61F0 10 28 44 .db $10,$28,$44,$00,$00,$00,$00,$00 ;^ 01:61F3 00 00 00 01:61F6 00 00 70 01:61F8 00 00 00 .db $00,$00,$00,$00,$00,$00,$fe,$00 ;_ 01:61FB 00 00 00 01:61FE FE 00 71 72 01:6200 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:6203 00 00 00 01:6206 00 00 73 01:6208 00 00 3C .db $00,$00,$3c,$06,$7e,$c6,$7e,$00 ;a 01:620B 06 7E C6 01:620E 7E 00 74 01:6210 C0 C0 FC .db $c0,$c0,$fc,$c6,$c6,$c6,$fc,$00 ;b 01:6213 C6 C6 C6 01:6216 FC 00 75 01:6218 00 00 7C .db $00,$00,$7c,$c6,$c0,$c6,$7c,$00 ;c 01:621B C6 C0 C6 01:621E 7C 00 76 01:6220 06 06 7E .db $06,$06,$7e,$c6,$c6,$c6,$7e,$00 ;d 01:6223 C6 C6 C6 01:6226 7E 00 77 01:6228 00 00 7C .db $00,$00,$7c,$c6,$fc,$c0,$7e,$00 ;e 01:622B C6 FC C0 01:622E 7E 00 78 01:6230 3E 60 60 .db $3e,$60,$60,$f8,$60,$60,$60,$00 ;f 01:6233 F8 60 60 01:6236 60 00 79 01:6238 00 00 7C .db $00,$00,$7c,$c6,$c6,$7e,$06,$7c ;g 01:623B C6 C6 7E 01:623E 06 7C 80 01:6240 C0 C0 FC .db $c0,$c0,$fc,$c6,$c6,$c6,$c6,$00 ;h 01:6243 C6 C6 C6 01:6246 C6 00 81 01:6248 18 00 18 .db $18,$00,$18,$18,$18,$18,$18,$00 ;i 01:624B 18 18 18 01:624E 18 00 82 01:6250 0C 0C 00 .db $0c,$0c,$00,$0c,$0c,$0c,$0c,$78 ;j 01:6253 0C 0C 0C 01:6256 0C 78 83 01:6258 C0 C0 D8 .db $c0,$c0,$d8,$f0,$e0,$f0,$d8,$00 ;k 01:625B F0 E0 F0 01:625E D8 00 84 01:6260 70 30 30 .db $70,$30,$30,$30,$30,$30,$78,$00 ;l 01:6263 30 30 30 01:6266 78 00 85 01:6268 00 00 7C .db $00,$00,$7c,$d6,$d6,$d6,$d6,$00 ;m 01:626B D6 D6 D6 01:626E D6 00 86 01:6270 00 00 7C .db $00,$00,$7c,$66,$66,$66,$66,$00 ;n 01:6273 66 66 66 01:6276 66 00 87 01:6278 00 00 3C .db $00,$00,$3c,$66,$66,$66,$3c,$00 ;o 01:627B 66 66 66 01:627E 3C 00 88 89 01:6280 00 00 7C .db $00,$00,$7c,$66,$66,$7c,$60,$60 ;p 01:6283 66 66 7C 01:6286 60 60 90 01:6288 00 00 3E .db $00,$00,$3e,$66,$66,$3e,$06,$06 ;q 01:628B 66 66 3E 01:628E 06 06 91 01:6290 00 00 D8 .db $00,$00,$d8,$fc,$e0,$c0,$c0,$00 ;r 01:6293 FC E0 C0 01:6296 C0 00 92 01:6298 00 00 3C .db $00,$00,$3c,$60,$38,$0c,$78,$00 ;s 01:629B 60 38 0C 01:629E 78 00 93 01:62A0 30 30 78 .db $30,$30,$78,$30,$30,$30,$1c,$00 ;t 01:62A3 30 30 30 01:62A6 1C 00 94 01:62A8 00 00 66 .db $00,$00,$66,$66,$66,$66,$3e,$00 ;u 01:62AB 66 66 66 01:62AE 3E 00 95 01:62B0 00 00 C6 .db $00,$00,$c6,$c6,$6c,$38,$10,$00 ;v 01:62B3 C6 6C 38 01:62B6 10 00 96 01:62B8 00 00 C6 .db $00,$00,$c6,$d6,$d6,$d6,$6c,$00 ;w 01:62BB D6 D6 D6 01:62BE 6C 00 97 01:62C0 00 00 C6 .db $00,$00,$c6,$6c,$10,$6c,$c6,$00 ;x 01:62C3 6C 10 6C 01:62C6 C6 00 98 01:62C8 00 00 66 .db $00,$00,$66,$66,$66,$3e,$06,$3c ;y 01:62CB 66 66 3E 01:62CE 06 3C 99 01:62D0 00 00 FE .db $00,$00,$fe,$0c,$38,$60,$fe,$00 ;z 01:62D3 0C 38 60 01:62D6 FE 00 100 01:62D8 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:62DB 00 00 00 01:62DE 00 00 101 01:62E0 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:62E3 00 00 00 01:62E6 00 00 102 01:62E8 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:62EB 00 00 00 01:62EE 00 00 103 01:62F0 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:62F3 00 00 00 01:62F6 00 00 104 01:62F8 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:62FB 00 00 00 01:62FE 00 00 105 106 01:6300 font_2: 107 01:6300 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ;SPACE 01:6303 00 00 00 01:6306 00 00 108 01:6308 04 0C 0C .db $04,$0c,$0c,$08,$08,$00,$10,$00 ;! 01:630B 08 08 00 01:630E 10 00 109 01:6310 36 12 24 .db $36,$12,$24,$00,$00,$00,$00,$00 ;" 01:6313 00 00 00 01:6316 00 00 110 01:6318 12 3F 12 .db $12,$3f,$12,$22,$24,$7e,$24,$00 ;# 01:631B 22 24 7E 01:631E 24 00 111 01:6320 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ;$ 01:6323 00 00 00 01:6326 00 00 112 01:6328 00 31 32 .db $00,$31,$32,$04,$18,$26,$46,$00 ;% 01:632B 04 18 26 01:632E 46 00 113 01:6330 08 14 14 .db $08,$14,$14,$38,$4a,$44,$3a,$00 ;& 01:6333 38 4A 44 01:6336 3A 00 114 01:6338 18 08 10 .db $18,$08,$10,$00,$00,$00,$00,$00 ;' 01:633B 00 00 00 01:633E 00 00 115 01:6340 0C 10 20 .db $0c,$10,$20,$20,$20,$10,$08,$00 ;( 01:6343 20 20 10 01:6346 08 00 116 01:6348 10 08 04 .db $10,$08,$04,$04,$04,$08,$30,$00 ;) 01:634B 04 04 08 01:634E 30 00 117 01:6350 00 08 2A .db $00,$08,$2a,$1c,$1c,$2a,$08,$00 ;* 01:6353 1C 1C 2A 01:6356 08 00 118 01:6358 00 08 08 .db $00,$08,$08,$3e,$08,$08,$00,$00 ;+ 01:635B 3E 08 08 01:635E 00 00 119 01:6360 00 00 00 .db $00,$00,$00,$00,$60,$60,$20,$40 ;, 01:6363 00 60 60 01:6366 20 40 120 01:6368 00 00 00 .db $00,$00,$00,$1e,$00,$00,$00,$00 ;- 01:636B 1E 00 00 01:636E 00 00 121 01:6370 00 00 00 .db $00,$00,$00,$00,$00,$60,$60,$00 ;. 01:6373 00 00 60 01:6376 60 00 122 01:6378 00 02 04 .db $00,$02,$04,$08,$10,$20,$40,$00 ;/ 01:637B 08 10 20 01:637E 40 00 123 124 01:6380 1C 22 22 .db $1c,$22,$22,$42,$42,$44,$38,$00 ;0 01:6383 42 42 44 01:6386 38 00 125 01:6388 0C 1C 04 .db $0c,$1c,$04,$08,$08,$08,$3c,$00 ;1 01:638B 08 08 08 01:638E 3C 00 126 01:6390 1C 22 02 .db $1c,$22,$02,$0c,$30,$40,$7c,$00 ;2 01:6393 0C 30 40 01:6396 7C 00 127 01:6398 1C 22 02 .db $1c,$22,$02,$0c,$02,$44,$38,$00 ;3 01:639B 0C 02 44 01:639E 38 00 128 01:63A0 0E 12 24 .db $0e,$12,$24,$44,$7f,$08,$08,$00 ;4 01:63A3 44 7F 08 01:63A6 08 00 129 01:63A8 1F 10 20 .db $1f,$10,$20,$3c,$02,$42,$3c,$00 ;5 01:63AB 3C 02 42 01:63AE 3C 00 130 01:63B0 1E 21 20 .db $1e,$21,$20,$7c,$42,$42,$3c,$00 ;6 01:63B3 7C 42 42 01:63B6 3C 00 131 01:63B8 3E 22 44 .db $3e,$22,$44,$04,$08,$08,$10,$00 ;7 01:63BB 04 08 08 01:63BE 10 00 132 01:63C0 1C 22 22 .db $1c,$22,$22,$3c,$42,$42,$3c,$00 ;8 01:63C3 3C 42 42 01:63C6 3C 00 133 01:63C8 1C 22 22 .db $1c,$22,$22,$1e,$02,$44,$38,$00 ;9 01:63CB 1E 02 44 01:63CE 38 00 134 01:63D0 00 00 08 .db $00,$00,$08,$00,$00,$00,$10,$00 ;: 01:63D3 00 00 00 01:63D6 10 00 135 01:63D8 00 00 08 .db $00,$00,$08,$00,$00,$00,$10,$20 ;; 01:63DB 00 00 00 01:63DE 10 20 136 01:63E0 00 04 08 .db $00,$04,$08,$10,$10,$08,$04,$00 ;< 01:63E3 10 10 08 01:63E6 04 00 137 01:63E8 00 00 00 .db $00,$00,$00,$1e,$00,$1e,$00,$00 ;= 01:63EB 1E 00 1E 01:63EE 00 00 138 01:63F0 00 10 08 .db $00,$10,$08,$04,$04,$08,$10,$00 ;> 01:63F3 04 04 08 01:63F6 10 00 139 01:63F8 1C 22 02 .db $1c,$22,$02,$04,$08,$00,$10,$00 ;? 01:63FB 04 08 00 01:63FE 10 00 140 141 01:6400 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ;@ 01:6403 00 00 00 01:6406 00 00 142 01:6408 0E 12 12 .db $0e,$12,$12,$22,$3e,$42,$42,$00 ;A 01:640B 22 3E 42 01:640E 42 00 143 01:6410 1C 12 22 .db $1c,$12,$22,$3c,$22,$42,$7c,$00 ;B 01:6413 3C 22 42 01:6416 7C 00 144 01:6418 1C 22 22 .db $1c,$22,$22,$40,$40,$44,$38,$00 ;C 01:641B 40 40 44 01:641E 38 00 145 01:6420 18 14 22 .db $18,$14,$22,$22,$42,$44,$f8,$00 ;D 01:6423 22 42 44 01:6426 F8 00 146 01:6428 1E 10 20 .db $1e,$10,$20,$3c,$20,$40,$7c,$00 ;E 01:642B 3C 20 40 01:642E 7C 00 147 01:6430 1E 10 20 .db $1e,$10,$20,$3c,$20,$40,$40,$00 ;F 01:6433 3C 20 40 01:6436 40 00 148 01:6438 1C 22 20 .db $1c,$22,$20,$40,$47,$44,$38,$00 ;G 01:643B 40 47 44 01:643E 38 00 149 01:6440 11 11 22 .db $11,$11,$22,$3e,$22,$44,$44,$00 ;H 01:6443 3E 22 44 01:6446 44 00 150 01:6448 1E 08 08 .db $1e,$08,$08,$10,$10,$20,$f0,$00 ;I 01:644B 10 10 20 01:644E F0 00 151 01:6450 1E 04 04 .db $1e,$04,$04,$08,$88,$90,$60,$00 ;J 01:6453 08 88 90 01:6456 60 00 152 01:6458 10 12 24 .db $10,$12,$24,$38,$28,$44,$44,$00 ;K 01:645B 38 28 44 01:645E 44 00 153 01:6460 10 10 20 .db $10,$10,$20,$20,$20,$40,$7c,$00 ;L 01:6463 20 20 40 01:6466 7C 00 154 01:6468 21 27 5A .db $21,$27,$5a,$52,$42,$84,$84,$00 ;M 01:646B 52 42 84 01:646E 84 00 155 01:6470 21 21 52 .db $21,$21,$52,$52,$4a,$84,$84,$00 ;N 01:6473 52 4A 84 01:6476 84 00 156 01:6478 1C 22 22 .db $1c,$22,$22,$42,$42,$44,$38,$00 ;O 01:647B 42 42 44 01:647E 38 00 157 158 01:6480 1C 12 22 .db $1c,$12,$22,$3c,$20,$40,$40,$00 ;P 01:6483 3C 20 40 01:6486 40 00 159 01:6488 1C 22 22 .db $1c,$22,$22,$42,$4a,$44,$34,$02 ;Q 01:648B 42 4A 44 01:648E 34 02 160 01:6490 1C 12 22 .db $1c,$12,$22,$3c,$28,$48,$46,$00 ;R 01:6493 3C 28 48 01:6496 46 00 161 01:6498 1C 22 20 .db $1c,$22,$20,$18,$04,$44,$38,$00 ;S 01:649B 18 04 44 01:649E 38 00 162 01:64A0 3E 08 10 .db $3e,$08,$10,$10,$10,$20,$20,$00 ;T 01:64A3 10 10 20 01:64A6 20 00 163 01:64A8 22 22 42 .db $22,$22,$42,$44,$44,$44,$38,$00 ;U 01:64AB 44 44 44 01:64AE 38 00 164 01:64B0 42 44 44 .db $42,$44,$44,$48,$50,$50,$60,$00 ;V 01:64B3 48 50 50 01:64B6 60 00 165 01:64B8 41 41 42 .db $41,$41,$42,$52,$52,$6c,$44,$00 ;W 01:64BB 52 52 6C 01:64BE 44 00 166 01:64C0 22 24 18 .db $22,$24,$18,$18,$28,$44,$44,$00 ;X 01:64C3 18 28 44 01:64C6 44 00 167 01:64C8 42 42 24 .db $42,$42,$24,$18,$10,$20,$20,$00 ;Y 01:64CB 18 10 20 01:64CE 20 00 168 01:64D0 3E 02 04 .db $3e,$02,$04,$18,$20,$40,$7c,$00 ;Z 01:64D3 18 20 40 01:64D6 7C 00 169 01:64D8 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ;[ 01:64DB 00 00 00 01:64DE 00 00 170 01:64E0 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ;\ 01:64E3 00 00 00 01:64E6 00 00 171 01:64E8 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ;] 01:64EB 00 00 00 01:64EE 00 00 172 01:64F0 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ;^ 01:64F3 00 00 00 01:64F6 00 00 173 01:64F8 00 00 00 .db $00,$00,$00,$00,$00,$00,$3e,$00 ;_ 01:64FB 00 00 00 01:64FE 3E 00 174 175 01:6500 00 10 18 .db $00,$10,$18,$18,$00,$00,$00,$00 ; 01:6503 18 00 00 01:6506 00 00 176 01:6508 00 1C 02 .db $00,$1c,$02,$3c,$44,$48,$34,$00 ;a 01:650B 3C 44 48 01:650E 34 00 177 01:6510 00 08 08 .db $00,$08,$08,$1c,$12,$22,$3c,$00 ;b 01:6513 1C 12 22 01:6516 3C 00 178 01:6518 00 00 1C .db $00,$00,$1c,$22,$40,$40,$38,$00 ;c 01:651B 22 40 40 01:651E 38 00 179 01:6520 00 02 02 .db $00,$02,$02,$3c,$44,$48,$38,$00 ;d 01:6523 3C 44 48 01:6526 38 00 180 01:6528 00 00 1C .db $00,$00,$1c,$22,$7e,$40,$38,$00 ;e 01:652B 22 7E 40 01:652E 38 00 181 01:6530 00 06 08 .db $00,$06,$08,$3c,$10,$20,$20,$00 ;f 01:6533 3C 10 20 01:6536 20 00 182 01:6538 00 00 3A .db $00,$00,$3a,$44,$44,$38,$08,$70 ;g 01:653B 44 44 38 01:653E 08 70 183 01:6540 00 08 08 .db $00,$08,$08,$1c,$12,$22,$24,$00 ;h 01:6543 1C 12 22 01:6546 24 00 184 01:6548 00 04 00 .db $00,$04,$00,$08,$08,$10,$10,$00 ;i 01:654B 08 08 10 01:654E 10 00 185 01:6550 00 02 00 .db $00,$02,$00,$04,$44,$48,$38,$00 ;j 01:6553 04 44 48 01:6556 38 00 186 01:6558 00 10 12 .db $00,$10,$12,$24,$38,$48,$46,$00 ;k 01:655B 24 38 48 01:655E 46 00 187 01:6560 00 0C 04 .db $00,$0c,$04,$08,$08,$10,$10,$00 ;l 01:6563 08 08 10 01:6566 10 00 188 01:6568 00 00 2A .db $00,$00,$2a,$15,$25,$29,$4a,$00 ;m 01:656B 15 25 29 01:656E 4A 00 189 01:6570 00 00 2C .db $00,$00,$2c,$12,$12,$24,$26,$00 ;n 01:6573 12 12 24 01:6576 26 00 190 01:6578 00 00 0C .db $00,$00,$0c,$12,$22,$24,$18,$00 ;o 01:657B 12 22 24 01:657E 18 00 191 192 01:6580 00 0E 09 .db $00,$0e,$09,$11,$1e,$20,$20,$00 ;p 01:6583 11 1E 20 01:6586 20 00 193 01:6588 00 1E 22 .db $00,$1e,$22,$24,$1c,$08,$08,$00 ;q 01:658B 24 1C 08 01:658E 08 00 194 01:6590 00 00 2C .db $00,$00,$2c,$12,$10,$20,$20,$00 ;r 01:6593 12 10 20 01:6596 20 00 195 01:6598 00 00 1C .db $00,$00,$1c,$22,$18,$44,$38,$00 ;s 01:659B 22 18 44 01:659E 38 00 196 01:65A0 00 08 3C .db $00,$08,$3c,$10,$20,$20,$18,$00 ;t 01:65A3 10 20 20 01:65A6 18 00 197 01:65A8 00 00 22 .db $00,$00,$22,$42,$44,$48,$34,$00 ;u 01:65AB 42 44 48 01:65AE 34 00 198 01:65B0 00 00 22 .db $00,$00,$22,$24,$28,$28,$10,$00 ;v 01:65B3 24 28 28 01:65B6 10 00 199 01:65B8 00 00 21 .db $00,$00,$21,$41,$49,$5a,$2c,$00 ;w 01:65BB 41 49 5A 01:65BE 2C 00 200 01:65C0 00 00 11 .db $00,$00,$11,$0a,$0c,$14,$22,$00 ;x 01:65C3 0A 0C 14 01:65C6 22 00 201 01:65C8 00 00 11 .db $00,$00,$11,$21,$22,$1e,$04,$38 ;y 01:65CB 21 22 1E 01:65CE 04 38 202 01:65D0 00 00 3E .db $00,$00,$3e,$04,$18,$20,$7c,$00 ;z 01:65D3 04 18 20 01:65D6 7C 00 203 01:65D8 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:65DB 00 00 00 01:65DE 00 00 204 01:65E0 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:65E3 00 00 00 01:65E6 00 00 205 01:65E8 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:65EB 00 00 00 01:65EE 00 00 206 01:65F0 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:65F3 00 00 00 01:65F6 00 00 207 01:65F8 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:65FB 00 00 00 01:65FE 00 00 #[2] startup.asm 151 E000 .code 152 0001 .bank LIB2_BANK 153 A600 .org $A600 154 155 156 6600 .data 157 0002 .bank CONST_BANK,"Constants" 158 159 0000 .data 160 0003 .bank DATA_BANK,"User Program" 161 6000 .org $6000 162 ; 163 ; place overlay array here 164 ; 50 entries, each containing 165 ; 2 bytes for start sector, 166 ; 2 bytes for # sectors 167 ; 168 03:6000 ovlarray: .ds 200 169 170 171 A600 .code 172 0000 .bank START_BANK,"Base Library 1" 173 174 ; A little introduction to the boot sequence: 175 ; 176 ; A HuCard has its origin at bank 0, and is mapped at $E000 177 ; It needs to grab the interrupt vectors at $FFF6 and implement 178 ; implement handlers for them 179 ; 180 ; A CDROM will load at bank $80 ($68 for SCD), and the initial 181 ; loader will be mapped at $4000. The current MagicKit sequence 182 ; also maps $C000 to this same bank. However, the initial boot 183 ; sequence will execute at $4070, proceeding to load additional 184 ; code and data, and then jump to a post-boot section called 185 ; 'init_go'. This is the point at which the loader explicitly 186 ; relinquishes the $4000 segment. It should be noted that there 187 ; are library subroutines loaded as part of this initial segment, 188 ; and those routines are located in the $C000 range as well. 189 ; 190 ; Sectors are loaded, up to and including the first "DATA_BANK", 191 ; where the overlay array is stored - so that the CDROM error 192 ; overlay can be located and executed in the event of a CDROM 193 ; system version mismatch (ie. playing SCD games on CDROM) 194 ; 195 ; A second entry point is defined for overlays that are not 196 ; being booted (ie. they are loaded and executed from another 197 ; overlay). This entry point is at $4000, after the segments 198 ; have all found their natural loading spots (ie. segment $68 199 ; for Super CDROMs). This entry point maps the necessary 200 ; segments and resets the stack, without clearing memory or 201 ; performing other setup chores, and then maps and executes 202 ; _main() to run the module. The user has no choice regarding 203 ; this function, although he can pass values through the global 204 ; variables which main() can use to decide what to do next. 205 ; 206 ; An additional "Hook" area has now been defined at $4028, 207 ; which is used at initial load time, in case a SCD overlay 208 ; program is run on plain CDROM hardware, and the author 209 ; wishes to override the default text error message by 210 ; loading and executing a plain CDROM program instead 211 ; 212 ; ---- 213 ; interrupt vectors 214 215 0000 .if !(CDROM) 223 .endif ; !(CDROM) 224 225 ; ---- 226 ; develo startup code 227 228 0000 .if (DEVELO) 238 .endif ; (DEVELO) 239 240 241 ; ---- 242 ; reset 243 ; ---- 244 ; things start here 245 ; ---- 246 247 ; ---- 248 ; CDROM re-map library bank 249 ; 250 ; 251 ; overlay entry point 252 ; 253 ; assume MMR0, MMR1, MMR6, MMR7 are set. 254 ; set others & reset stack pointer 255 ; 256 0001 .if (CDROM) 257 C000 .org $C000 258 259 ; current overlay number that is running 260 ; this is overwritten by the isolink prgram; the load 261 ; statement must be the first in the block 262 ; 263 00:C000 ovlentry: 264 00:C000 A9 01 lda #1 265 00:C002 8D B1 26 sta ovl_running 266 267 00:C005 A9 82 lda #CONST_BANK+_bank_base 268 00:C007 53 04 tam #2 269 00:C009 A9 83 lda #DATA_BANK+_bank_base 270 00:C00B 53 08 tam #3 271 00:C00D A9 86 lda #_call_bank 272 00:C00F 53 10 tam #4 273 274 00:8011 stw #$4000,<__sp 275 00:C019 A2 FF ldx #$ff 276 00:C01B 9A txs 277 278 00:801C map _main 279 00:C020 20 00 A0 jsr _main 280 00:C023 80 FE bra * 281 282 ; 283 ; CDROM error message alternate load entry point 284 ; 285 4028 .org $4028 286 287 00:4028 00 cderr_override: .db 0 288 00:4029 00 cderr_overlay_num: .db 0 289 290 00:402A cdrom_err_load: 291 292 ; since CDROM program will load into same area in RAM, 293 ; this load routine must be executed from scratch RAM 294 ; re-use the ram interrupt handler areas (not yet initialized) 295 296 00:402A 73 34 40 tii .load_cd_ovl, ram_vsync_hndl, 64 00:402D B5 26 40 00:4030 00 297 00:4031 4C B5 26 jmp ram_vsync_hndl 298 299 00:4034 .load_cd_ovl: 300 00:4034 AD 29 40 lda cderr_overlay_num 301 00:4037 0A asl A 302 00:4038 0A asl A 303 00:4039 A8 tay 304 00:403A A9 83 lda #DATA_BANK+$80 305 00:403C 53 08 tam #3 306 00:403E BE 00 60 ldx ovlarray,Y++ 00:4041 C8 307 00:4042 B9 00 60 lda ovlarray,Y++ 00:4045 C8 308 00:4046 64 FC stz <_cl ; sector (offset from base of track) 309 00:4048 85 FD sta <_ch 310 00:404A 86 FE stx <_dl 311 00:404C B9 00 60 lda ovlarray,Y 312 00:404F 85 F8 sta <_al ; # sectors 313 00:4051 A9 80 lda #$80 314 00:4053 85 FA sta <_bl ; bank # 315 00:4055 A9 03 lda #3 316 00:4057 85 FF sta <_dh ; MPR # 317 00:4059 20 09 E0 jsr cd_read 318 00:405C C9 00 cmp #0 319 00:405E D0 07 bne .error 320 00:4060 A9 80 lda #$80 321 00:4062 53 04 tam #2 322 00:4064 4C 70 40 jmp _boot 323 324 00:4067 4C 00 E0 .error: jmp cd_boot ; Can't load - reboot CDROM system card 325 326 327 ; 328 ; Proper Boot-time entry point 329 ; 330 4070 .org $4070 331 00:4070 _boot: 332 00:4070 9C 80 26 stz $2680 ; clear program RAM 333 00:4073 73 80 26 tii $2680,$2681,$197F 00:4076 81 26 7F 00:4079 19 334 335 ; 336 ; Note: All CDROM boot loaders will load into MMR $80 region 337 ; regardless of whether they are CD or SCD. 338 ; Here, we will move the information to occupy 339 ; base memory at MMR $68 if appropriate 340 ; 341 0000 .if (CDROM = SUPER_CD) 355 .endif ; (CDROM = SUPER_CD) 356 357 .else ; (ie. if HuCard...) 373 .endif ; (CDROM) 374 375 ; ---- 376 ; initialize the hardware 377 378 00:407A _init: 379 0001 .if (CDROM) 380 00:407A 20 99 E0 jsr ex_dspoff 381 00:407D 20 81 E0 jsr ex_rcroff 382 00:4080 20 87 E0 jsr ex_irqoff 383 00:4083 20 30 E0 jsr ad_reset 384 .else 386 .endif ; (CDROM) 387 388 00:4086 20 97 C5 jsr init_psg ; init sound 389 00:4089 20 78 C4 jsr init_vdc ; init video 390 00:408C A9 1F lda #$1F ; init joypad 391 00:408E 8D 27 22 sta joyena 392 393 ; ---- 394 ; initialize interrupt vectors 395 396 0001 .if (CDROM) 397 00:4091 20 96 E0 jsr ex_dspon 398 00:4094 20 7E E0 jsr ex_rcron 399 00:4097 20 84 E0 jsr ex_irqon 400 .else 433 .endif ; (CDROM) 434 435 ; ---- 436 ; init TIA instruction in RAM (fast BLiTter to hardware) 437 438 00:409A A9 E3 lda #$E3 ; TIA instruction opcode 439 00:409C 8D 02 27 sta _ram_hdwr_tia 440 00:409F A9 60 lda #$60 ; RTS instruction opcode 441 00:40A1 8D 09 27 sta _ram_hdwr_tia_rts 442 443 ; ---- 444 ; init random number generator 445 446 00:40A4 A9 01 lda #1 447 00:40A6 20 42 DE jsr wait_vsync ; wait for one frame & randomize _rndseed 448 00:80A9 stw #$03E7,<_cx ; set random seed 449 00:80B1 stw _rndseed,<_dx 450 00:40BB 20 73 C7 jsr srand 451 452 0001 .if (CDROM) 453 0000 .if (CDROM = SUPER_CD) 460 .endif ; (SUPER_CD) 461 462 ; ---- 463 ; load program 464 ; ---- 465 ; CL/CH/DL = sector address 466 ; DH = load mode - bank mode ($6000-$7FFF) 467 ; BL = bank index 468 ; AL = number of sectors 469 ; 470 00:40BE loadprog: 471 00:40BE AD 01 C0 lda ovlentry+1 ; current overlay (as written by ISOLINK) 472 00:40C1 C9 01 cmp #1 ; is it initial overlay ? 473 00:80C3 lbne _init_go ; if not initial overlay, somebody else already 474 ; loaded us completely; do not try to load remainder 475 ; (ie. executing CDROM error overlay) 476 477 00:40C8 64 FC stz <_cl ; initial boot doesn't load complete program; 478 00:40CA 64 FD stz <_ch ; prepare to load remainder 479 00:40CC A9 0A lda #10 ; 10th sector (0-1 are boot; 480 ; 2-9 are this library...) 481 00:40CE 85 FE sta <_dl 482 00:40D0 A9 03 lda #3 ; load mode (consecutive banks; use MPR 3) 483 00:40D2 85 FF sta <_dh 484 00:80D4 stw #(_bank_base+2),<_bx ; 2 banks are boot/base library 485 00:80DC stw #(_nb_bank-2)*4,<_ax 486 00:40E4 20 09 E0 jsr cd_read 487 00:40E7 C9 00 cmp #$00 488 00:80E9 lbeq _init_go 489 490 ; ---- 491 00:40EE 4C 00 E0 jmp cd_boot ; reset 492 493 494 ; This is the point in the CDROM loader where the code no longer 495 ; executes in the $4000 segment, in favour of using the $C000 496 ; segment (also used for the library subroutines) 497 498 C130 .org $C130 499 500 501 ; These routines will be run from RAM @ $2000 so we 502 ; need to count bytes to determine how much to xfer 503 ; (The total is 24 bytes, but we copy 25) 504 505 0001 .bank LIB2_BANK 506 507 01:A600 vsync_irq_ramhndlr: 508 01:A600 08 php ; 1 byte 509 01:A601 48 pha ; 1 510 01:A602 43 40 tma #6 ; 2 511 01:A604 8D B3 26 sta irq_storea ; 3 512 01:A607 A9 80 lda #BANK(_vsync_hndl) ; 2 513 01:A609 53 40 tam #6 ; 2 514 01:A60B 68 pla ; 1 515 01:A60C 48 pha ; 1 516 01:A60D 20 EF C1 jsr _vsync_hndl ; 3 517 01:A610 AD B3 26 lda irq_storea ; 3 518 01:A613 53 40 tam #6 ; 2 519 01:A615 68 pla ; 1 520 01:A616 28 plp ; 1 521 01:A617 60 rts ; 1 = 24 bytes 522 523 01:A618 hsync_irq_ramhndlr: 524 01:A618 08 php ; 1 byte 525 01:A619 48 pha ; 1 526 01:A61A 43 40 tma #6 ; 2 527 01:A61C 8D B4 26 sta irq_storeb ; 3 528 01:A61F A9 80 lda #BANK(_hsync_hndl) ; 2 529 01:A621 53 40 tam #6 ; 2 530 01:A623 68 pla ; 1 531 01:A624 48 pha ; 1 532 01:A625 20 55 C2 jsr _hsync_hndl ; 3 533 01:A628 AD B4 26 lda irq_storeb ; 3 534 01:A62B 53 40 tam #6 ; 2 535 01:A62D 68 pla ; 1 536 01:A62E 28 plp ; 1 537 01:A62F 60 rts ; 1 = 24 bytes 538 539 0000 .bank LIB1_BANK 540 541 00:C130 _init_go: 542 0000 .if (CDROM = SUPER_CD) 544 .endif 545 546 .endif ; (CDROM) 547 548 ; ---- 549 ; jump to main routine 550 551 ; ---- 552 ; load font 553 554 0001 .ifdef HUC 555 00:8130 stw #$4000,<__sp ; init stack ptr first 556 557 00:8138 stw #FONT_VADDR,<_di ; Load Font @ VRAM addr 558 559 ; 560 ; this section of font loading was stolen 561 ; from _load_default_font because the default 562 ; FONT segment number is not yet guaranteed 563 ; if the SCD is being run on a plain CDROM system 564 ; so we need to trick the segment pointer 565 ; with a reliable one 566 ; 567 00:8140 __ldw <_di ; stolen from _load_default_font 568 ; because segment# default not reliable 569 570 00:C144 20 0A CD jsr _set_font_addr ; set VRAM 571 572 0001 .if (CDROM) 573 00:8147 stb #FONT_BANK+$80,<_bl ; guarantee FONT_BANK even if 574 ; SCD on regular CDROM system 575 .else 577 .endif 578 579 00:814B stb #96,<_cl 580 00:814F stb _font_color+1,<_ah 581 00:C154 AD A7 27 lda _font_color 582 00:C157 D0 01 bne .fntld 583 00:C159 1A inc A 584 00:C15A 85 F8 .fntld: sta <_al 585 00:C15C 82 clx 586 00:C15D BD 48 C3 lda font_table,X 587 00:C160 85 EE sta <_si 588 00:C162 E8 inx 589 00:C163 BD 48 C3 lda font_table,X 590 00:C166 85 EF sta <_si+1 591 592 593 ; Now, load the font 594 ; 595 ; Note for CDROM/Super CDROM: 596 ; 597 ; The 'REAL' mapping for the lib2_load_font function 598 ; maybe doesn't exist yet (we are executing from bank $80, 599 ; not from $68 if it's a Super CDROM) 600 ; 601 ; So we must map the version at bank ($80 + LIB2_BANK) 602 ; before executing it. We remap the bank after completion, 603 ; 'just in case' 604 605 0001 .if (CDROM) 606 00:C168 43 20 tma #page(lib2_load_font) 607 00:C16A 48 pha 608 00:C16B A9 81 lda #LIB2_BANK+$80 609 00:C16D 53 20 tam #page(lib2_load_font) 610 00:C16F 20 5E A9 jsr lib2_load_font 611 00:C172 68 pla 612 00:C173 53 20 tam #page(lib2_load_font) 613 .else 615 .endif 616 617 ; 618 ; END stolen font-load 619 ; 620 621 00:C175 20 BE CC jsr _cls 622 623 00:C178 9C 02 04 stz color_reg ; set color #0 = 0/0/0 rgb 624 00:C17B 9C 03 04 stz color_reg+1 625 00:C17E 9C 04 04 stz color_data 626 00:C181 9C 05 04 stz color_data+1 627 628 00:C184 A9 01 lda #1 ; set color #1 = 7/7/7 rgb 629 00:C186 8D 02 04 sta color_reg 630 00:C189 9C 03 04 stz color_reg+1 631 00:C18C A2 FF ldx #$ff 632 00:C18E 8E 04 04 stx color_data 633 00:C191 8D 05 04 sta color_data+1 634 635 ; ---- 636 ; Super CDROM error message 637 ; ---- 638 639 0001 .if (CDROM) 640 0000 .if (CDROM = SUPER_CD) 685 .endif ; (CDROM = SUPER_CD) 686 687 .endif ; (CDROM) 688 .endif ; (HUC) 689 690 691 0001 .ifdef SUPPORT_MOUSE 692 00:C194 20 8B DB jsr mousinit ; check existence of mouse 693 .endif ; SUPPORT_MOUSE 694 695 0001 .if (CDROM) 696 697 ; Now, install the RAM-based version of the 698 ; interrupt-handlers and activate them 699 700 00:C197 43 20 tma #page(vsync_irq_ramhndlr) 701 00:C199 48 pha 702 00:C19A A9 81 lda #bank(vsync_irq_ramhndlr) 703 00:C19C 53 20 tam #page(vsync_irq_ramhndlr) 704 00:C19E 73 00 A6 tii vsync_irq_ramhndlr,ram_vsync_hndl,25 00:C1A1 B5 26 19 00:C1A4 00 705 00:C1A5 73 18 A6 tii hsync_irq_ramhndlr,ram_hsync_hndl,25 00:C1A8 CE 26 19 00:C1AB 00 706 00:C1AC 68 pla 707 00:C1AD 53 20 tam #page(vsync_irq_ramhndlr) 708 709 00:81AF stw #ram_vsync_hndl,vsync_hook ; set VSYNC handler 710 00:C1B9 C7 F5 smb #4, $f400 230 00:C7FD C9 F4 cmp #$f4 231 00:87FF blo .l1 232 00:C801 A9 E0 lda #$e0 233 00:C803 85 15 sta <_rndzp+1 234 00:C805 .l1: 235 00:8805 stw <_rndzp,_rndptr 236 00:C80F 60 rts 237 238 239 ; ---- 240 ; random 241 ; ---- 242 ; return a random number in the interval 0 <= x < A 243 ; ---- 244 ; IN : A = range (1 - 128) 245 ; ---- 246 ; OUT : A = random number 247 ; ---- 248 ; 249 00:C810 random: 250 00:C810 48 pha 251 00:C811 20 99 C7 jsr rand 252 00:C814 68 pla 253 ; ---- 254 00:C815 C9 80 cmp #128 255 00:8817 blo .l1 256 257 00:C819 A5 FF lda <_dh 258 00:C81B 29 7F and #$7f 259 00:C81D 60 rts 260 261 00:C81E .l1: ; asl A 262 00:C81E 85 F8 sta <_al 263 00:C820 A5 FE lda <_dl 264 00:C822 85 FA sta <_bl 265 00:C824 20 BD E0 jsr mulu8 266 267 00:C827 A5 FD lda <_ch 268 00:C829 60 rts 269 #[2] startup.asm 1214 1215 0001 .ifdef HUC #[3] huc.asm 1216 .include "huc.asm" 1 ; 2 ; HUC.ASM - HuC Internal Library 3 ; 4 5 ; ---- 6 ; local variables 7 8 277D .bss 9 --:277D _vdc .ds 20*2 10 11 2016 .zp 12 --:2016 __sign 13 --:2016 __remain .ds 2 14 15 C82A .code 17 18 ; ---- 19 ; eq 20 ; ---- 21 ; test egality of two words 22 ; ---- 23 ; IN : First word on the C stack 24 ; Another word in A:X 25 ; ---- 26 ; OUT : word A:X equals 0 is the two args are egals 27 ; else non nul 28 ; ---- 29 ; REMARK : signed compatible 30 ; ---- 31 32 ; old version is 75 bytes long 33 ; new version is 31 bytes long (58% shorter :) 34 ; DAVE: newer version 45 bytes but much faster 35 ; best case was: 56 cycles (worst = 70) 36 ; best case now: 45 cycles (worst = 59) 37 38 00:C82A eq: 39 00:C82A 22 sax 40 00:C82B D2 00 cmp [__stack] 41 00:C82D D0 18 bne .eq_endno 42 43 00:C82F A0 01 ldy #1 44 00:C831 22 sax 45 00:C832 D1 00 cmp [__stack],Y 46 00:C834 D0 11 bne .eq_endno 47 48 00:C836 .eq_endyes: 49 addw #2,<__stack ; don't push A/X; they are thrown away 0000 .if (2 = 3) .else ; 2-arg mode ; 00:C836 18 clc 00:C837 A5 00 lda LOW_BYTE <__stack 00:C839 69 02 adc LOW_BYTE #2 00:C83B 85 00 sta LOW_BYTE <__stack 00:C83D A5 01 lda HIGH_BYTE <__stack 00:C83F 69 00 adc HIGH_BYTE #2 00:C841 85 01 sta HIGH_BYTE <__stack .endif 50 00:C843 A9 FF lda #$FF ; A=255 -> true 51 00:C845 82 clx 52 00:C846 60 rts 53 54 00:C847 .eq_endno: 55 addw #2,<__stack 0000 .if (2 = 3) .else ; 2-arg mode ; 00:C847 18 clc 00:C848 A5 00 lda LOW_BYTE <__stack 00:C84A 69 02 adc LOW_BYTE #2 00:C84C 85 00 sta LOW_BYTE <__stack 00:C84E A5 01 lda HIGH_BYTE <__stack 00:C850 69 00 adc HIGH_BYTE #2 00:C852 85 01 sta HIGH_BYTE <__stack .endif 56 00:C854 A9 00 lda #0 57 00:C856 82 clx 58 00:C857 60 rts 59 60 ; streamlined version MACRO - uses zp ( <__temp ) instead of stack 61 ; returns A:X = 0 if false, FF00 if true 62 ; 15 bytes, best = 12 cycles; worst = 23 63 64 00:C858 eqzp: 65 00:C858 C5 04 cmp <__temp+1 66 00:C85A D0 09 bne .x_ne 67 00:C85C 22 sax 68 00:C85D C5 03 cmp <__temp 69 00:C85F D0 04 bne .x_ne 70 00:C861 A9 FF lda #$FF ; ensure Z flag not set 71 00:C863 80 02 bra .x1_eq 72 00:C865 .x_ne: 73 00:C865 A9 00 lda #0 ; ensure Z flag set 74 00:C867 .x1_eq: 75 00:C867 82 clx 76 00:C868 60 rts 77 78 79 ; ---- 80 ; lt 81 ; ---- 82 ; compare two words 83 ; ---- 84 ; IN : First word on the C stack 85 ; Another word in A:X 86 ; ---- 87 ; OUT : word A:X is non nul if pushed word is strictly lower than 88 ; the word in A:X else nul 89 ; ---- 90 91 00:C869 lt: ; signed version 92 00:C869 A0 01 ldy #1 93 00:C86B C9 80 cmp #$80 94 00:C86D B0 0A bcs lt_primary_minus 95 96 ; if here, the A:X value is positive 97 98 00:C86F 85 03 sta <__temp 99 00:C871 B1 00 lda [__stack], Y 100 00:C873 30 55 bmi cmp_ok ; stack value is negative, so reply OK 101 102 00:C875 A5 03 lda <__temp ; stack value is also positive, so just go for the unsigned version 103 00:C877 80 1B bra ult_y1 104 105 106 00:C879 lt_primary_minus: 107 108 ; if here, the A:X value is negative 109 110 00:C879 85 03 sta <__temp 111 00:C87B B1 00 lda [__stack], Y 112 00:C87D 30 11 bmi getA_ult ; stack value is also negative, so restore A val from 113 ; __temp and call ult 114 115 00:C87F cmp_false: 116 addw #2,<__stack ; OK to kill A/X 0000 .if (2 = 3) .else ; 2-arg mode ; 00:C87F 18 clc 00:C880 A5 00 lda LOW_BYTE <__stack 00:C882 69 02 adc LOW_BYTE #2 00:C884 85 00 sta LOW_BYTE <__stack 00:C886 A5 01 lda HIGH_BYTE <__stack 00:C888 69 00 adc HIGH_BYTE #2 00:C88A 85 01 sta HIGH_BYTE <__stack .endif 117 00:C88C A9 00 lda #0 118 00:C88E 82 clx 119 00:C88F 60 rts 120 121 00:C890 getA_ult: 122 00:C890 A5 03 lda <__temp 123 124 00:C892 ult: ; unsigned version 125 00:C892 A0 01 ldy #1 ; false by default 126 127 00:C894 ult_y1: ; same thing but Y is assumed to be egal to 1 128 129 00:C894 D1 00 cmp [__stack],Y 130 00:C896 F0 04 beq .lt_must_test_lobyte 131 00:C898 B0 30 bcs cmp_ok 132 00:C89A 80 07 bra .lt_end ; hibyte of the reg var < hibyte of the pushed var 133 134 00:C89C .lt_must_test_lobyte: 135 00:C89C 22 sax 136 00:C89D D2 00 cmp [__stack] 137 00:C89F F0 02 beq .lt_end 138 00:C8A1 B0 27 bcs cmp_ok ; set result to true 139 ; lobyte of the reg var < lobyte of the pushed var 140 141 00:C8A3 .lt_end: 142 addw #2,<__stack 0000 .if (2 = 3) .else ; 2-arg mode ; 00:C8A3 18 clc 00:C8A4 A5 00 lda LOW_BYTE <__stack 00:C8A6 69 02 adc LOW_BYTE #2 00:C8A8 85 00 sta LOW_BYTE <__stack 00:C8AA A5 01 lda HIGH_BYTE <__stack 00:C8AC 69 00 adc HIGH_BYTE #2 00:C8AE 85 01 sta HIGH_BYTE <__stack .endif 143 144 00:C8B0 98 tya ; if Y was 1, return A=X=0 -> false 145 00:C8B1 3A dec A ; if Y was 0, return A=255 -> true 146 147 00:C8B2 82 clx 148 00:C8B3 60 rts 149 150 151 152 ; ---- 153 ; gt 154 ; ---- 155 ; compare two words 156 ; ---- 157 ; IN : First word on the C stack 158 ; Another word in A:X 159 ; ---- 160 ; OUT : word A:X is non nul if pushed word is strictly greater than 161 ; the word in A:X else nul 162 ; ---- 163 164 00:C8B4 gt: ; signed version of > 165 00:C8B4 A0 01 ldy #1 166 00:C8B6 C9 80 cmp #$80 167 00:C8B8 B0 0A bcs .gt_primary_minus 168 169 ; if here, the A:X value is positive 170 171 00:C8BA 85 03 sta <__temp 172 00:C8BC B1 00 lda [__stack], Y 173 00:C8BE 30 BF bmi cmp_false ; stack value is negative, so reply False 174 175 00:C8C0 A5 03 lda <__temp ; stack value is also positive, so just go for the unsigned version 176 00:C8C2 80 1B bra ugt_y1 ; we spare one instruction, since we already have Y=1 177 178 00:C8C4 .gt_primary_minus: 179 180 ; if here, the A:X value is negative 181 182 00:C8C4 85 03 sta <__temp 183 00:C8C6 B1 00 lda [__stack], Y 184 00:C8C8 30 11 bmi getA_ugt ; stack value is also negative, so restore A val from 185 ; __temp and call ugt 186 187 00:C8CA cmp_ok: 188 addw #2,<__stack ; OK to kill A/X 0000 .if (2 = 3) .else ; 2-arg mode ; 00:C8CA 18 clc 00:C8CB A5 00 lda LOW_BYTE <__stack 00:C8CD 69 02 adc LOW_BYTE #2 00:C8CF 85 00 sta LOW_BYTE <__stack 00:C8D1 A5 01 lda HIGH_BYTE <__stack 00:C8D3 69 00 adc HIGH_BYTE #2 00:C8D5 85 01 sta HIGH_BYTE <__stack .endif 189 00:C8D7 A9 FF lda #$FF 190 00:C8D9 82 clx 191 00:C8DA 60 rts 192 193 00:C8DB getA_ugt: ; we grab back the value of A before entering the unsigned 194 ; version of > 195 00:C8DB A5 03 lda <__temp 196 197 00:C8DD ugt: ; unsigned version of > 198 199 00:C8DD A0 01 ldy #1 200 201 00:C8DF ugt_y1: ; unsigned version of >, assuming Y = 1 202 203 00:C8DF D1 00 cmp [__stack],Y 204 00:C8E1 F0 05 beq .gt_must_test_lobyte 205 00:C8E3 B0 09 bcs .gt_end ; hibyte of the reg var >= hibyte of the pushed var 206 00:C8E5 C2 cly 207 00:C8E6 80 06 bra .gt_end 208 209 00:C8E8 .gt_must_test_lobyte 210 00:C8E8 22 sax 211 00:C8E9 D2 00 cmp [__stack] 212 00:C8EB B0 01 bcs .gt_end ; lobyte of the reg var >= lobyte of the pushed var 213 00:C8ED C2 cly 214 215 00:C8EE .gt_end: 216 addw #2,<__stack 0000 .if (2 = 3) .else ; 2-arg mode ; 00:C8EE 18 clc 00:C8EF A5 00 lda LOW_BYTE <__stack 00:C8F1 69 02 adc LOW_BYTE #2 00:C8F3 85 00 sta LOW_BYTE <__stack 00:C8F5 A5 01 lda HIGH_BYTE <__stack 00:C8F7 69 00 adc HIGH_BYTE #2 00:C8F9 85 01 sta HIGH_BYTE <__stack .endif 217 00:C8FB 98 tya 218 00:C8FC 3A dec A 219 00:C8FD 82 clx 220 00:C8FE 60 rts 221 222 223 ; ---- 224 ; zero page versions of lt/gt/ult/ugt: 225 ; ---- 226 227 00:C8FF ltzp: ; signed, zero page 228 00:C8FF 85 05 sta <__temp+2 229 00:C901 45 04 eor <__temp+1 230 00:C903 10 0C bpl .geta_ult 231 00:C905 A5 05 lda <__temp+2 232 00:C907 10 04 bpl .true 233 00:C909 A9 00 .false: lda #0 234 00:C90B 82 clx 235 00:C90C 60 rts 236 00:C90D A9 FF .true: lda #$ff 237 00:C90F 82 clx 238 00:C910 60 rts 239 00:C911 .geta_ult: 240 00:C911 A5 05 lda <__temp+2 ; and fall through to unsigned test 241 242 00:C913 C5 04 ultzp: cmp <__temp+1 243 00:C915 F0 06 beq .test_lo 244 00:C917 90 0B bcc .false 245 00:C919 A9 FF .true: lda #$ff 246 00:C91B 82 clx 247 00:C91C 60 rts 248 00:C91D .test_lo: 249 00:C91D 22 sax 250 00:C91E C5 03 cmp <__temp 251 00:C920 F0 02 beq .false 252 00:C922 B0 F5 bcs .true 253 00:C924 A9 00 .false: lda #0 254 00:C926 82 clx 255 00:C927 60 rts 256 ; ---- 257 00:C928 gtzp: ; signed, zero page 258 00:C928 85 05 sta <__temp+2 259 00:C92A 45 04 eor <__temp+1 260 00:C92C 10 0C bpl .geta_ugt 261 00:C92E A5 05 lda <__temp+2 262 00:C930 10 04 bpl .false 263 00:C932 A9 FF .true: lda #$ff 264 00:C934 82 clx 265 00:C935 60 rts 266 00:C936 A9 00 .false: lda #0 267 00:C938 82 clx 268 00:C939 60 rts 269 00:C93A .geta_ugt: 270 00:C93A A5 05 lda <__temp+2 ; and fall through to unsigned test 271 272 00:C93C ugtzp: 273 00:C93C C5 04 cmp <__temp+1 274 00:C93E F0 06 beq .test_lo 275 00:C940 B0 0B bcs .false 276 00:C942 A9 FF .true: lda #$ff 277 00:C944 82 clx 278 00:C945 60 rts 279 00:C946 .test_lo: 280 00:C946 22 sax 281 00:C947 C5 03 cmp <__temp 282 00:C949 F0 02 beq .false 283 00:C94B 90 F5 bcc .true 284 00:C94D A9 00 .false: lda #0 285 00:C94F 82 clx 286 00:C950 60 rts 287 288 289 ; ---- 290 ; ge 291 ; ---- 292 ; compare two signed words 293 ; ---- 294 ; IN : First word on the C stack 295 ; Another word in A:X 296 ; ---- 297 ; OUT : word A:X is non nul if pushed word is greater or egal to 298 ; the word in A:X else nul 299 ; ---- 300 301 00:C951 ge: ; signed version of > 302 00:C951 20 69 C8 jsr lt 303 00:C954 1A inc A ; assuming that true is represented by A = 255 304 00:C955 60 rts 305 306 00:C956 20 FF C8 gezp: jsr ltzp 307 00:C959 49 FF eor #$ff 308 00:C95B 60 rts 309 310 ; ---- 311 ; uge 312 ; ---- 313 ; compare two unsigned signed words 314 ; ---- 315 ; IN : First word on the C stack 316 ; Another word in A:X 317 ; ---- 318 ; OUT : word A:X is non nul if pushed word is greater or egal to 319 ; the word in A:X else nul 320 ; ---- 321 322 00:C95C uge: ; unsigned version of > 323 00:C95C 20 92 C8 jsr ult 324 00:C95F 1A inc A ; assuming that true is represented by A = 255 325 00:C960 60 rts 326 327 00:C961 20 13 C9 ugezp: jsr ultzp 328 00:C964 49 FF eor #$ff 329 00:C966 60 rts 330 331 ; ---- 332 ; ne 333 ; ---- 334 ; compare two words 335 ; ---- 336 ; IN : First word on the C stack 337 ; Another word in A:X 338 ; ---- 339 ; OUT : word A:X is non null if pushed word is different from 340 ; the word in A:X else null 341 ; ---- 342 ; REMARK : signed compatible 343 ; ---- 344 345 ; previous version called 'eq' as subroutine and returned 346 ; opposite value; should be fully implemented for speed 347 ; since '!=' is such a common operand 348 349 00:C967 ne: 350 00:C967 22 sax 351 00:C968 D2 00 cmp [__stack] 352 00:C96A D0 18 bne .ne_endne 353 354 00:C96C A0 01 ldy #1 355 00:C96E 22 sax 356 00:C96F D1 00 cmp [__stack],Y 357 00:C971 D0 11 bne .ne_endne 358 359 00:C973 .ne_endeq: 360 addw #2,<__stack ; don't push A/X; they are thrown away 0000 .if (2 = 3) .else ; 2-arg mode ; 00:C973 18 clc 00:C974 A5 00 lda LOW_BYTE <__stack 00:C976 69 02 adc LOW_BYTE #2 00:C978 85 00 sta LOW_BYTE <__stack 00:C97A A5 01 lda HIGH_BYTE <__stack 00:C97C 69 00 adc HIGH_BYTE #2 00:C97E 85 01 sta HIGH_BYTE <__stack .endif 361 00:C980 A9 00 lda #0 362 00:C982 82 clx 363 00:C983 60 rts 364 365 00:C984 .ne_endne: 366 addw #2,<__stack 0000 .if (2 = 3) .else ; 2-arg mode ; 00:C984 18 clc 00:C985 A5 00 lda LOW_BYTE <__stack 00:C987 69 02 adc LOW_BYTE #2 00:C989 85 00 sta LOW_BYTE <__stack 00:C98B A5 01 lda HIGH_BYTE <__stack 00:C98D 69 00 adc HIGH_BYTE #2 00:C98F 85 01 sta HIGH_BYTE <__stack .endif 367 00:C991 A9 FF lda #$ff 368 00:C993 82 clx 369 00:C994 60 rts 370 371 ; streamlined version MACRO - uses zp ( <__temp ) instead of stack 372 ; returns A:X = 0 if false, FF00 if true 373 ; 15 bytes, best = 12 cycles; worst = 23 374 375 00:C995 nezp: 376 00:C995 C5 04 cmp <__temp+1 377 00:C997 D0 09 bne .x_ne 378 00:C999 22 sax 379 00:C99A C5 03 cmp <__temp 380 00:C99C D0 04 bne .x_ne 381 00:C99E A9 00 lda #0 ; ensure Z flag set 382 00:C9A0 80 02 bra .x1_eq 383 00:C9A2 .x_ne: 384 00:C9A2 A9 FF lda #$ff ; ensure Z flag not set 385 00:C9A4 .x1_eq: 386 00:C9A4 82 clx 387 00:C9A5 60 rts 388 389 ; ---- 390 ; le 391 ; ---- 392 ; compare two signed words 393 ; ---- 394 ; IN : First word on the C stack 395 ; Another word in A:X 396 ; ---- 397 ; OUT : word A:X is non nul if pushed word is lower or egal to 398 ; the word in A:X else nul 399 ; ---- 400 401 00:C9A6 le: ; signed version 402 00:C9A6 20 B4 C8 jsr gt 403 00:C9A9 1A inc A ; assuming that A=255 if true 404 00:C9AA 60 rts 405 406 00:C9AB 20 28 C9 lezp: jsr gtzp 407 00:C9AE 49 FF eor #$ff 408 00:C9B0 60 rts 409 410 ; ---- 411 ; ule 412 ; ---- 413 ; compare two unsigned words 414 ; ---- 415 ; IN : First word on the C stack 416 ; Another word in A:X 417 ; ---- 418 ; OUT : word A:X is non nul if pushed word is lower or egal to 419 ; the word in A:X else nul 420 ; ---- 421 422 00:C9B1 ule: ; unsigned version 423 00:C9B1 20 DD C8 jsr ugt 424 00:C9B4 1A inc A ; assuming that A=255 if true 425 00:C9B5 60 rts 426 427 00:C9B6 20 3C C9 ulezp: jsr ugtzp 428 00:C9B9 49 FF eor #$ff 429 00:C9BB 60 rts 430 431 432 ; ---- 433 ; asl 434 ; ---- 435 ; shift the pushed word left by the register word 436 ; ---- 437 ; IN : First word on the C stack 438 ; Another word in A:X 439 ; ---- 440 ; OUT : Register word egals the previous pushed value 441 ; shifted left by A:X 442 ; ---- 443 ; REMARK : only the lower byte of the right operand is taken in account 444 ; signed compatible 445 ; ---- 446 00:C9BC asl: 447 00:C9BC 86 03 stx <__temp 448 __ldwp __stack 00:C9BE B2 00 lda [__stack] 00:C9C0 AA tax 00:C9C1 A0 01 ldy #1 00:C9C3 B1 00 lda [__stack],Y 449 00:C9C5 A4 03 ldy <__temp 450 00:C9C7 F0 0C beq .asl_end 451 00:C9C9 85 03 sta <__temp 452 00:C9CB 22 sax 453 454 00:C9CC .asl_begin 455 00:C9CC 0A asl a 456 00:C9CD 26 03 rol <__temp 457 00:C9CF 88 dey 458 00:C9D0 D0 FA bne .asl_begin 459 460 00:C9D2 22 sax 461 00:C9D3 A5 03 lda <__temp 462 00:C9D5 .asl_end 463 00:C9D5 A8 tay 464 addw #2,<__stack 0000 .if (2 = 3) .else ; 2-arg mode ; 00:C9D6 18 clc 00:C9D7 A5 00 lda LOW_BYTE <__stack 00:C9D9 69 02 adc LOW_BYTE #2 00:C9DB 85 00 sta LOW_BYTE <__stack 00:C9DD A5 01 lda HIGH_BYTE <__stack 00:C9DF 69 00 adc HIGH_BYTE #2 00:C9E1 85 01 sta HIGH_BYTE <__stack .endif 465 00:C9E3 98 tya 466 00:C9E4 60 rts 467 468 469 ; ---- 470 ; asr 471 ; ---- 472 ; shift the pushed word right by the register word 473 ; ---- 474 ; IN : First word on the C stack 475 ; Another word in A:X 476 ; ---- 477 ; OUT : Register word egals the previous pushed value 478 ; shifted right by A:X 479 ; ---- 480 ; REMARK : only the lower byte of the right operand is taken in account 481 ; signed compatible 482 ; ---- 483 00:C9E5 asr: 484 00:C9E5 86 03 stx <__temp 485 __ldwp __stack 00:C9E7 B2 00 lda [__stack] 00:C9E9 AA tax 00:C9EA A0 01 ldy #1 00:C9EC B1 00 lda [__stack],Y 486 00:C9EE A4 03 ldy <__temp 487 00:C9F0 F0 0E beq .asr_end 488 00:C9F2 85 03 sta <__temp 489 00:C9F4 22 sax 490 491 00:C9F5 .asr_begin 492 00:C9F5 E0 80 cpx #$80 493 00:C9F7 66 03 ror <__temp 494 00:C9F9 6A ror a 495 496 00:C9FA 88 dey 497 00:C9FB D0 F8 bne .asr_begin 498 499 00:C9FD 22 sax 500 00:C9FE A5 03 lda <__temp 501 00:CA00 .asr_end 502 00:CA00 A8 tay 503 addw #2,<__stack 0000 .if (2 = 3) .else ; 2-arg mode ; 00:CA01 18 clc 00:CA02 A5 00 lda LOW_BYTE <__stack 00:CA04 69 02 adc LOW_BYTE #2 00:CA06 85 00 sta LOW_BYTE <__stack 00:CA08 A5 01 lda HIGH_BYTE <__stack 00:CA0A 69 00 adc HIGH_BYTE #2 00:CA0C 85 01 sta HIGH_BYTE <__stack .endif 504 00:CA0E 98 tya 505 00:CA0F 60 rts 506 507 508 ; ---- 509 ; smul 510 ; ---- 511 ; multiply two SIGNED words 512 ; ---- 513 ; IN : First word on the C stack 514 ; Another word in A:X 515 ; ---- 516 ; OUT : Register word egals the previous pushed value 517 ; multiplied by A:X 518 ; ---- 519 520 00:CA10 smul: 521 00:CA10 64 16 stz <__sign ; until we call umul, __sign keeps the sign parity 522 ; of operand 523 00:CA12 C9 80 cmp #$80 524 00:CA14 90 0D bcc smul_no_invert_primary 525 526 __negw 00:CA16 22 sax 00:CA17 49 FF eor #$FF 00:CA19 18 clc 00:CA1A 69 01 adc #1 00:CA1C 22 sax 00:CA1D 49 FF eor #$FF 00:CA1F 69 00 adc #0 527 528 00:CA21 E6 16 inc <__sign ; __sign ++ 529 530 00:CA23 smul_no_invert_primary: 531 532 00:CA23 85 03 sta <__temp 533 00:CA25 A0 01 ldy #1 534 00:CA27 B1 00 lda [__stack],Y 535 00:CA29 C9 80 cmp #$80 536 00:CA2B 90 1B bcc smul_no_invert_secondary 537 538 00:CA2D E6 16 inc <__sign ; this time, no optimisation possible, IMHO :) 539 ; are you sure? :)) 540 00:CA2F 86 04 stx <__temp+1 541 542 00:CA31 B2 00 lda [__stack] 543 00:CA33 AA tax 544 00:CA34 B1 00 lda [__stack],Y ; we assumed Y = 1 since we set it at the beginning of 545 ; smul_no_invert_primary 546 __negw 00:CA36 22 sax 00:CA37 49 FF eor #$FF 00:CA39 18 clc 00:CA3A 69 01 adc #1 00:CA3C 22 sax 00:CA3D 49 FF eor #$FF 00:CA3F 69 00 adc #0 547 00:CA41 91 00 sta [__stack],Y 548 00:CA43 22 sax 549 00:CA44 92 00 sta [__stack] 550 551 00:CA46 A6 04 ldx <__temp+1 552 553 00:CA48 smul_no_invert_secondary: 554 555 00:CA48 A5 16 lda <__sign 556 00:CA4A 48 pha 557 00:CA4B A5 03 lda <__temp ; saved at the beginning of smul_no_invert_primary 558 ; where we're sure we passed 559 560 00:CA4D 20 65 CA jsr umul 561 562 00:CA50 42 say 563 00:CA51 68 pla 564 00:CA52 29 01 and #$01 565 00:CA54 F0 0D beq smul_end 566 567 00:CA56 42 say 568 __negw 00:CA57 22 sax 00:CA58 49 FF eor #$FF 00:CA5A 18 clc 00:CA5B 69 01 adc #1 00:CA5D 22 sax 00:CA5E 49 FF eor #$FF 00:CA60 69 00 adc #0 569 00:CA62 60 rts 570 571 00:CA63 smul_end: 572 00:CA63 42 say 573 00:CA64 60 rts 574 575 576 ; ---- 577 ; umul 578 ; ---- 579 ; multiply two UNSIGNED words 580 ; ---- 581 ; IN : First word on the C stack 582 ; Another word in A:X 583 ; ---- 584 ; OUT : Register word egals the previous pushed value 585 ; multiplied by A:X 586 ; ---- 587 588 00:CA65 umul: 589 __stw <__temp+2 ; bx 00:CA65 86 05 stx <__temp+2 00:CA67 85 06 sta <__temp+2+1 590 __ldwp __stack 00:CA69 B2 00 lda [__stack] 00:CA6B AA tax 00:CA6C A0 01 ldy #1 00:CA6E B1 00 lda [__stack],Y 591 __stw <__temp ; ax 00:CA70 86 03 stx <__temp 00:CA72 85 04 sta <__temp+1 592 00:CA74 20 89 CA jsr umul16 593 addw #2,<__stack 0000 .if (2 = 3) .else ; 2-arg mode ; 00:CA77 18 clc 00:CA78 A5 00 lda LOW_BYTE <__stack 00:CA7A 69 02 adc LOW_BYTE #2 00:CA7C 85 00 sta LOW_BYTE <__stack 00:CA7E A5 01 lda HIGH_BYTE <__stack 00:CA80 69 00 adc HIGH_BYTE #2 00:CA82 85 01 sta HIGH_BYTE <__stack .endif 594 __ldw <__ptr 0000 .if (1 = 2) .else 00:CA84 A6 0B ldx <__ptr 00:CA86 A5 0C lda <__ptr+1 .endif 595 00:CA88 60 rts 596 00:CA89 umul16: 597 00:CA89 A5 06 lda <__temp+3 598 00:CA8B 05 04 ora <__temp+1 599 00:CA8D F0 21 beq umul8 600 stwz <__ptr 00:CA8F 64 0B stz LOW_BYTE <__ptr 00:CA91 64 0C stz HIGH_BYTE <__ptr 601 00:CA93 A0 10 ldy #16 602 603 .l1: aslw <__ptr 00:CA95 06 0B asl <__ptr ; word-sized value (at stated 00:CA97 26 0C rol <__ptr+1 ; memory location) 604 aslw <__temp+2 00:CA99 06 05 asl <__temp+2 ; word-sized value (at stated 00:CA9B 26 06 rol <__temp+2+1 ; memory location) 605 00:CA9D 90 0D bcc .l2 606 addw <__temp,<__ptr 0000 .if (2 = 3) .else ; 2-arg mode ; 00:CA9F 18 clc 00:CAA0 A5 0B lda LOW_BYTE <__ptr 00:CAA2 65 03 adc LOW_BYTE <__temp 00:CAA4 85 0B sta LOW_BYTE <__ptr 00:CAA6 A5 0C lda HIGH_BYTE <__ptr 00:CAA8 65 04 adc HIGH_BYTE <__temp 00:CAAA 85 0C sta HIGH_BYTE <__ptr .endif 607 00:CAAC 88 .l2: dey 608 00:CAAD D0 E6 bne .l1 609 00:CAAF 60 rts 610 00:CAB0 umul8: 611 00:CAB0 A5 05 lda <__temp+2 612 00:CAB2 85 0C sta <__ptr+1 613 00:CAB4 62 cla 614 00:CAB5 A0 08 ldy #8 615 616 00:CAB7 0A .l1: asl A 617 00:CAB8 26 0C rol <__ptr+1 618 00:CABA 90 07 bcc .l2 619 add <__temp 0000 .if (1 = 2) ; register A (handle carry .else 00:CABC 18 clc 00:CABD 65 03 adc <__temp .endif 620 00:CABF 90 02 bcc .l2 621 00:CAC1 E6 0C inc <__ptr+1 622 00:CAC3 88 .l2: dey 623 00:CAC4 D0 F1 bne .l1 624 625 00:CAC6 85 0B sta <__ptr 626 00:CAC8 60 rts 627 628 629 ; ---- 630 ; sdiv 631 ; ---- 632 ; divide two SIGNED words 633 ; ---- 634 ; IN : First word on the C stack 635 ; Another word in A:X 636 ; ---- 637 ; OUT : Register word egals the previous pushed value 638 ; divided by A:X 639 ; ---- 640 641 00:CAC9 sdiv: 642 00:CAC9 64 16 stz <__sign ; until we call udiv, __sign keeps the sign parity 643 ; of operand 644 00:CACB C9 80 cmp #$80 645 00:CACD 90 0D bcc sdiv_no_invert_primary 646 647 __negw 00:CACF 22 sax 00:CAD0 49 FF eor #$FF 00:CAD2 18 clc 00:CAD3 69 01 adc #1 00:CAD5 22 sax 00:CAD6 49 FF eor #$FF 00:CAD8 69 00 adc #0 648 649 00:CADA E6 16 inc <__sign ; __sign ++ 650 651 00:CADC sdiv_no_invert_primary: 652 653 00:CADC 85 03 sta <__temp 654 00:CADE A0 01 ldy #1 655 00:CAE0 B1 00 lda [__stack],Y 656 00:CAE2 C9 80 cmp #$80 657 00:CAE4 90 1B bcc sdiv_no_invert_secondary 658 659 00:CAE6 E6 16 inc <__sign 660 661 00:CAE8 86 04 stx <__temp+1 662 663 00:CAEA B2 00 lda [__stack] 664 00:CAEC AA tax 665 00:CAED B1 00 lda [__stack],Y ; we assumed Y = 1 since we set it at the beginning of 666 ; sdiv_no_invert_primary 667 __negw 00:CAEF 22 sax 00:CAF0 49 FF eor #$FF 00:CAF2 18 clc 00:CAF3 69 01 adc #1 00:CAF5 22 sax 00:CAF6 49 FF eor #$FF 00:CAF8 69 00 adc #0 668 00:CAFA 91 00 sta [__stack],Y 669 00:CAFC 22 sax 670 00:CAFD 92 00 sta [__stack] 671 672 00:CAFF A6 04 ldx <__temp+1 673 674 00:CB01 sdiv_no_invert_secondary: 675 676 00:CB01 A5 16 lda <__sign 677 00:CB03 48 pha 678 00:CB04 A5 03 lda <__temp ; saved at the beginning of sdiv_no_invert_primary 679 ; where we're sure we passed 680 00:CB06 20 1E CB jsr udiv 681 682 00:CB09 42 say 683 00:CB0A 68 pla 684 00:CB0B 29 01 and #$01 685 00:CB0D F0 0D beq sdiv_end 686 687 00:CB0F 42 say 688 __negw 00:CB10 22 sax 00:CB11 49 FF eor #$FF 00:CB13 18 clc 00:CB14 69 01 adc #1 00:CB16 22 sax 00:CB17 49 FF eor #$FF 00:CB19 69 00 adc #0 689 00:CB1B 60 rts 690 691 00:CB1C sdiv_end: 692 00:CB1C 42 say 693 00:CB1D 60 rts 694 695 696 ; ---- 697 ; udiv 698 ; ---- 699 ; divide two UNSIGNED words 700 ; ---- 701 ; IN : First word on the C stack 702 ; Another word in A:X 703 ; ---- 704 ; OUT : Register word egals the previous pushed value 705 ; divided by A:X 706 ; ---- 707 708 00:CB1E udiv: 709 __stw <__ptr 00:CB1E 86 0B stx <__ptr 00:CB20 85 0C sta <__ptr+1 710 __ldwp __stack 00:CB22 B2 00 lda [__stack] 00:CB24 AA tax 00:CB25 A0 01 ldy #1 00:CB27 B1 00 lda [__stack],Y 711 __stw <__temp 00:CB29 86 03 stx <__temp 00:CB2B 85 04 sta <__temp+1 712 713 00:CB2D A9 00 lda #0 714 00:CB2F 85 17 sta <__remain+1 715 00:CB31 A0 10 ldy #16 716 00:CB33 06 03 .sdiv_begin: asl <__temp 717 00:CB35 26 04 rol <__temp+1 718 00:CB37 2A rol a 719 00:CB38 26 17 rol <__remain+1 720 00:CB3A 48 pha 721 00:CB3B C5 0B cmp <__ptr 722 00:CB3D A5 17 lda <__remain+1 723 00:CB3F E5 0C sbc <__ptr+1 724 00:CB41 90 08 bcc .sdiv_end 725 00:CB43 85 17 sta <__remain+1 726 00:CB45 68 pla 727 00:CB46 E5 0B sbc <__ptr 728 00:CB48 48 pha 729 00:CB49 E6 03 inc <__temp 730 00:CB4B 68 .sdiv_end: pla 731 00:CB4C 88 dey 732 00:CB4D D0 E4 bne .sdiv_begin 733 00:CB4F 85 16 sta <__remain 734 735 addw #2,<__stack 0000 .if (2 = 3) .else ; 2-arg mode ; 00:CB51 18 clc 00:CB52 A5 00 lda LOW_BYTE <__stack 00:CB54 69 02 adc LOW_BYTE #2 00:CB56 85 00 sta LOW_BYTE <__stack 00:CB58 A5 01 lda HIGH_BYTE <__stack 00:CB5A 69 00 adc HIGH_BYTE #2 00:CB5C 85 01 sta HIGH_BYTE <__stack .endif 736 __ldw <__temp 0000 .if (1 = 2) .else 00:CB5E A6 03 ldx <__temp 00:CB60 A5 04 lda <__temp+1 .endif 737 738 00:CB62 60 rts 739 740 741 ; ---- 742 ; smod 743 ; ---- 744 ; give the integer remainder of the two words 745 ; ---- 746 ; IN : First word on the C stack 747 ; Another word in A:X 748 ; ---- 749 ; OUT : Register word egals the remainder of the division of the 750 ; pushed value by A:X 751 ; ---- 752 ; REMARK : signed NON compatible 753 ; ---- 754 755 00:CB63 smod: 756 00:CB63 umod: 757 __stw <__ptr 00:CB63 86 0B stx <__ptr 00:CB65 85 0C sta <__ptr+1 758 __ldwp __stack 00:CB67 B2 00 lda [__stack] 00:CB69 AA tax 00:CB6A A0 01 ldy #1 00:CB6C B1 00 lda [__stack],Y 759 __stw <__temp 00:CB6E 86 03 stx <__temp 00:CB70 85 04 sta <__temp+1 760 761 00:CB72 A9 00 lda #0 762 00:CB74 85 17 sta <__remain+1 763 00:CB76 A0 10 ldy #16 764 00:CB78 06 03 .smod_begin: asl <__temp 765 00:CB7A 26 04 rol <__temp+1 766 00:CB7C 2A rol a 767 00:CB7D 26 17 rol <__remain+1 768 00:CB7F 48 pha 769 00:CB80 C5 0B cmp <__ptr 770 00:CB82 A5 17 lda <__remain+1 771 00:CB84 E5 0C sbc <__ptr+1 772 00:CB86 90 08 bcc .smod_end 773 00:CB88 85 17 sta <__remain+1 774 00:CB8A 68 pla 775 00:CB8B E5 0B sbc <__ptr 776 00:CB8D 48 pha 777 00:CB8E E6 03 inc <__temp 778 00:CB90 68 .smod_end: pla 779 00:CB91 88 dey 780 00:CB92 D0 E4 bne .smod_begin 781 00:CB94 85 16 sta <__remain 782 783 addw #2,<__stack 0000 .if (2 = 3) .else ; 2-arg mode ; 00:CB96 18 clc 00:CB97 A5 00 lda LOW_BYTE <__stack 00:CB99 69 02 adc LOW_BYTE #2 00:CB9B 85 00 sta LOW_BYTE <__stack 00:CB9D A5 01 lda HIGH_BYTE <__stack 00:CB9F 69 00 adc HIGH_BYTE #2 00:CBA1 85 01 sta HIGH_BYTE <__stack .endif 784 __ldw <__remain 0000 .if (1 = 2) .else 00:CBA3 A6 16 ldx <__remain 00:CBA5 A5 17 lda <__remain+1 .endif 785 786 00:CBA7 60 rts 787 788 ; ---- 789 ; ___case 790 ; ---- 791 ; implement a switch instruction in C 792 ; ---- 793 ; IN : primary register (A:X) contain the discriminant value 794 ; i.e. the one that will be checked against those indicated in the 795 ; various case instructions 796 ; On the stack, a pointer is passed 797 ; This is a pointer toward an array 798 ; Each item of this array is a 4 bytes long structure 799 ; The structure is the following : 800 ; WORD value_to_check 801 ; WORD label_to_jump_to 802 ; We have to parse the whole array in order to compare the primary 803 ; register with all the 'value_to_check' field. If we ever find that 804 ; the primary register is egal to such a value, we must jump to the 805 ; corresponding 'label_to_jump_to'. 806 ; The default value (which also means that we reached the end of the 807 ; array) can be recognized with its 'label_to_jump_to' field set to 0. 808 ; Then the 'value_to_check' field become the default label we have to 809 ; use for the rest of the execution. 810 ; ---- 811 ; OUT : The execution goes to another place 812 ; ---- 813 ; REMARK : Also use __remain variable as a temporary value 814 ; ---- 815 00:CBA8 ___case: 816 __stw <__remain ; store the value to check to 00:CBA8 86 16 stx <__remain 00:CBAA 85 17 sta <__remain+1 817 __ldwp __stack 00:CBAC B2 00 lda [__stack] 00:CBAE AA tax 00:CBAF A0 01 ldy #1 00:CBB1 B1 00 lda [__stack],Y 818 __stw <__ptr ; __ptr contain the address of the array 00:CBB3 86 0B stx <__ptr 00:CBB5 85 0C sta <__ptr+1 819 820 addw #2,<__stack 0000 .if (2 = 3) .else ; 2-arg mode ; 00:CBB7 18 clc 00:CBB8 A5 00 lda LOW_BYTE <__stack 00:CBBA 69 02 adc LOW_BYTE #2 00:CBBC 85 00 sta LOW_BYTE <__stack 00:CBBE A5 01 lda HIGH_BYTE <__stack 00:CBC0 69 00 adc HIGH_BYTE #2 00:CBC2 85 01 sta HIGH_BYTE <__stack .endif 821 822 00:CBC4 .begin_case: 823 addw #2,<__ptr 0000 .if (2 = 3) .else ; 2-arg mode ; 00:CBC4 18 clc 00:CBC5 A5 0B lda LOW_BYTE <__ptr 00:CBC7 69 02 adc LOW_BYTE #2 00:CBC9 85 0B sta LOW_BYTE <__ptr 00:CBCB A5 0C lda HIGH_BYTE <__ptr 00:CBCD 69 00 adc HIGH_BYTE #2 00:CBCF 85 0C sta HIGH_BYTE <__ptr .endif 824 __ldwp __ptr 00:CBD1 B2 0B lda [__ptr] 00:CBD3 AA tax 00:CBD4 A0 01 ldy #1 00:CBD6 B1 0B lda [__ptr],Y 825 __tstw ; pha 00:CBD8 86 03 stx <__temp 00:CBDA 05 03 ora <__temp ; pla 826 __lbeq .end_case_default 00:CBDC D0 03 bne .x00217 00:CBDE 4C 44 CC jmp .end_case_default 00:CBE1 .x00217 827 828 addw #-2,<__ptr 0000 .if (2 = 3) .else ; 2-arg mode ; 00:CBE1 18 clc 00:CBE2 A5 0B lda LOW_BYTE <__ptr 00:CBE4 69 FE adc LOW_BYTE #-2 00:CBE6 85 0B sta LOW_BYTE <__ptr 00:CBE8 A5 0C lda HIGH_BYTE <__ptr 00:CBEA 69 FF adc HIGH_BYTE #-2 00:CBEC 85 0C sta HIGH_BYTE <__ptr .endif 829 830 __ldwp __ptr 00:CBEE B2 0B lda [__ptr] 00:CBF0 AA tax 00:CBF1 A0 01 ldy #1 00:CBF3 B1 0B lda [__ptr],Y 831 832 __addmi -2,__stack 00:CBF5 48 pha 00:CBF6 18 clc 00:CBF7 A5 00 lda <__stack 00:CBF9 69 FE adc #low(-2) 00:CBFB 85 00 sta <__stack 00:CBFD A5 01 lda <__stack+1 00:CBFF 69 FF adc #high(-2) 00:CC01 85 01 sta <__stack+1 00:CC03 68 pla 833 __stwp __stack 00:CC04 22 sax 00:CC05 92 00 sta [__stack] 00:CC07 22 sax 00:CC08 A0 01 ldy #1 00:CC0A 91 00 sta [__stack],Y 834 835 addw #4,<__ptr 0000 .if (2 = 3) .else ; 2-arg mode ; 00:CC0C 18 clc 00:CC0D A5 0B lda LOW_BYTE <__ptr 00:CC0F 69 04 adc LOW_BYTE #4 00:CC11 85 0B sta LOW_BYTE <__ptr 00:CC13 A5 0C lda HIGH_BYTE <__ptr 00:CC15 69 00 adc HIGH_BYTE #4 00:CC17 85 0C sta HIGH_BYTE <__ptr .endif 836 837 __ldw <__remain 0000 .if (1 = 2) .else 00:CC19 A6 16 ldx <__remain 00:CC1B A5 17 lda <__remain+1 .endif 838 839 00:CC1D 20 2A C8 jsr eq 840 __tstw ; pha 00:CC20 86 03 stx <__temp 00:CC22 05 03 ora <__temp ; pla 841 __lbeq .begin_case 00:CC24 D0 03 bne .x00225 00:CC26 4C C4 CB jmp .begin_case 00:CC29 .x00225 842 843 addw #-2,<__ptr 0000 .if (2 = 3) .else ; 2-arg mode ; 00:CC29 18 clc 00:CC2A A5 0B lda LOW_BYTE <__ptr 00:CC2C 69 FE adc LOW_BYTE #-2 00:CC2E 85 0B sta LOW_BYTE <__ptr 00:CC30 A5 0C lda HIGH_BYTE <__ptr 00:CC32 69 FF adc HIGH_BYTE #-2 00:CC34 85 0C sta HIGH_BYTE <__ptr .endif 844 __ldwp __ptr 00:CC36 B2 0B lda [__ptr] 00:CC38 AA tax 00:CC39 A0 01 ldy #1 00:CC3B B1 0B lda [__ptr],Y 845 __stw <__temp 00:CC3D 86 03 stx <__temp 00:CC3F 85 04 sta <__temp+1 846 847 00:CC41 6C 03 20 jmp [__temp] 848 849 00:CC44 .end_case_default: ; if we haven't found any corresponding value 850 ; then we jump to the default supplied label 851 852 addw #-2,<__ptr 0000 .if (2 = 3) .else ; 2-arg mode ; 00:CC44 18 clc 00:CC45 A5 0B lda LOW_BYTE <__ptr 00:CC47 69 FE adc LOW_BYTE #-2 00:CC49 85 0B sta LOW_BYTE <__ptr 00:CC4B A5 0C lda HIGH_BYTE <__ptr 00:CC4D 69 FF adc HIGH_BYTE #-2 00:CC4F 85 0C sta HIGH_BYTE <__ptr .endif 853 __ldwp __ptr 00:CC51 B2 0B lda [__ptr] 00:CC53 AA tax 00:CC54 A0 01 ldy #1 00:CC56 B1 0B lda [__ptr],Y 854 __stw <__temp 00:CC58 86 03 stx <__temp 00:CC5A 85 04 sta <__temp+1 855 856 00:CC5C 6C 03 20 jmp [__temp] 857 858 859 ; ---- 860 ; hook 861 ; ---- 862 ; indirect call to sub-routine 863 ; ---- 864 ; IN : sub-routine addr in __ptr 865 ; ---- 866 867 00:CC5F hook: 868 00:CC5F 6C 0B 20 jmp [__ptr] 869 870 ; ---- 871 ; setvdc 872 ; ---- 873 ; set a vdc register 874 ; ---- 875 ; IN : - reg index on the C stack 876 ; - value in A:X 877 ; ---- 878 879 00:CC62 setvdc: 880 00:CC62 A8 tay 881 00:CC63 B2 00 lda [__sp] 882 00:CC65 4A lsr A 883 ; -- 884 00:CC66 C9 09 cmp #$09 885 00:CC68 F0 2E beq .l3 886 00:CC6A C9 0A cmp #$0A 887 blo .l1 00:CC6C 90 04 bcc .l1 888 00:CC6E C9 0F cmp #$0F 889 blo .l2 00:CC70 90 18 bcc .l2 890 ; -- 891 00:CC72 85 F7 .l1: sta _cx 1599 1600 stw <_bp,_line_curry ; swap coordinates 01:ABD7 A5 EC lda LOW_BYTE <_bp 01:ABD9 8D AC 29 sta LOW_BYTE _line_curry 01:ABDC A5 ED lda HIGH_BYTE <_bp 01:ABDE 8D AD 29 sta HIGH_BYTE _line_curry 1601 stw <_cx,<_bp 01:ABE1 A5 FC lda LOW_BYTE <_cx 01:ABE3 85 EC sta LOW_BYTE <_bp 01:ABE5 A5 FD lda HIGH_BYTE <_cx 01:ABE7 85 ED sta HIGH_BYTE <_bp 1602 stw <_si,_line_currx 01:ABE9 A5 EE lda LOW_BYTE <_si 01:ABEB 8D AA 29 sta LOW_BYTE _line_currx 01:ABEE A5 EF lda HIGH_BYTE <_si 01:ABF0 8D AB 29 sta HIGH_BYTE _line_currx 1603 stw <_bx,<_si 01:ABF3 A5 FA lda LOW_BYTE <_bx 01:ABF5 85 EE sta LOW_BYTE <_si 01:ABF7 A5 FB lda HIGH_BYTE <_bx 01:ABF9 85 EF sta HIGH_BYTE <_si 1604 1605 01:ABFB 80 14 bra .l2 1606 1607 .l1: stw <_bx,_line_currx 01:ABFD A5 FA lda LOW_BYTE <_bx 01:ABFF 8D AA 29 sta LOW_BYTE _line_currx 01:AC02 A5 FB lda HIGH_BYTE <_bx 01:AC04 8D AB 29 sta HIGH_BYTE _line_currx 1608 stw <_cx,_line_curry 01:AC07 A5 FC lda LOW_BYTE <_cx 01:AC09 8D AC 29 sta LOW_BYTE _line_curry 01:AC0C A5 FD lda HIGH_BYTE <_cx 01:AC0E 8D AD 29 sta HIGH_BYTE _line_curry 1609 1610 ; now: 1611 ; line_currx and line_curry are start point 1612 ; <_si and <_bp are end point 1613 ; <_bx and <_cx are 'dont care' 1614 1615 01:AC11 .l2: 1616 01:AC11 A5 EC lda LOW_BYTE <_bp 1617 sub LOW_BYTE _line_curry 0000 .if (1 = 2) ; from register A (handle .else 01:AC13 38 sec 01:AC14 ED AC 29 sbc LOW_BYTE _line_curry .endif 1618 01:AC17 8D B0 29 sta LOW_BYTE _line_deltay 1619 01:AC1A A5 ED lda HIGH_BYTE <_bp 1620 01:AC1C ED AD 29 sbc HIGH_BYTE _line_curry 1621 01:AC1F 8D B1 29 sta HIGH_BYTE _line_deltay 1622 1623 01:AC22 A5 EE lda LOW_BYTE <_si 1624 sub LOW_BYTE _line_currx 0000 .if (1 = 2) ; from register A (handle .else 01:AC24 38 sec 01:AC25 ED AA 29 sbc LOW_BYTE _line_currx .endif 1625 01:AC28 8D AE 29 sta LOW_BYTE _line_deltax 1626 01:AC2B A5 EF lda HIGH_BYTE <_si 1627 01:AC2D ED AB 29 sbc HIGH_BYTE _line_currx 1628 01:AC30 8D AF 29 sta HIGH_BYTE _line_deltax 1629 1630 01:AC33 9C B6 29 stz _line_xdir ; 0 = positive 1631 1632 01:AC36 AD AF 29 lda HIGH_BYTE _line_deltax 1633 01:AC39 10 14 bpl .l3 1634 1635 01:AC3B A9 01 lda #1 1636 01:AC3D 8D B6 29 sta _line_xdir ; 1 = negative 1637 negw _line_deltax 01:AC40 62 cla ; (at stated memory location) sub _line_deltax ; 2's complement 0000 .if (1 = 2) ; from register A (handle .else 01:AC41 38 sec 01:AC42 ED AE 29 sbc _line_deltax .endif 01:AC45 8D AE 29 sta _line_deltax 01:AC48 62 cla 01:AC49 ED AF 29 sbc _line_deltax+1 01:AC4C 8D AF 29 sta _line_deltax+1 1638 1639 ; now: 1640 ; line_deltay is difference from end to start (positive) 1641 ; line_deltax is difference from end to start (positive) 1642 ; line_xdir shows whether to apply deltax positive or negative 1643 1644 1645 01:AC4F .l3: 1646 cmpw _line_deltax,_line_deltay 01:AC4F AD B1 29 lda HIGH_BYTE _line_deltay 01:AC52 CD AF 29 cmp HIGH_BYTE _line_deltax 01:AC55 D0 06 bne .x_00403 01:AC57 AD B0 29 lda LOW_BYTE _line_deltay 01:AC5A CD AE 29 cmp LOW_BYTE _line_deltax 01:AC5D .x_00403: 1647 lbhs .ybiglp ; jump if deltay > |deltax| 01:AC5D 90 03 bcc .x_00404 01:AC5F 4C 5B AD jmp .ybiglp 01:AC62 .x_00404 1648 1649 01:AC62 .xbiglp: 1650 __ldw _line_deltay 0000 .if (1 = 2) .else 01:AC62 AE B0 29 ldx _line_deltay 01:AC65 AD B1 29 lda _line_deltay+1 .endif 1651 __aslw 01:AC68 22 sax 01:AC69 0A asl A 01:AC6A 22 sax 01:AC6B 2A rol A 1652 __stw _line_adjust 01:AC6C 8E B4 29 stx _line_adjust 01:AC6F 8D B5 29 sta _line_adjust+1 1653 __stw _line_error 01:AC72 8E B2 29 stx _line_error 01:AC75 8D B3 29 sta _line_error+1 1654 1655 subw _line_deltax,_line_adjust 01:AC78 38 sec 01:AC79 AD B4 29 lda LOW_BYTE _line_adjust 01:AC7C ED AE 29 sbc LOW_BYTE _line_deltax 01:AC7F 8D B4 29 sta LOW_BYTE _line_adjust 01:AC82 AD B5 29 lda HIGH_BYTE _line_adjust 01:AC85 ED AF 29 sbc HIGH_BYTE _line_deltax 01:AC88 8D B5 29 sta HIGH_BYTE _line_adjust 1656 subw _line_deltax,_line_adjust 01:AC8B 38 sec 01:AC8C AD B4 29 lda LOW_BYTE _line_adjust 01:AC8F ED AE 29 sbc LOW_BYTE _line_deltax 01:AC92 8D B4 29 sta LOW_BYTE _line_adjust 01:AC95 AD B5 29 lda HIGH_BYTE _line_adjust 01:AC98 ED AF 29 sbc HIGH_BYTE _line_deltax 01:AC9B 8D B5 29 sta HIGH_BYTE _line_adjust 1657 1658 subw _line_deltax,_line_error 01:AC9E 38 sec 01:AC9F AD B2 29 lda LOW_BYTE _line_error 01:ACA2 ED AE 29 sbc LOW_BYTE _line_deltax 01:ACA5 8D B2 29 sta LOW_BYTE _line_error 01:ACA8 AD B3 29 lda HIGH_BYTE _line_error 01:ACAB ED AF 29 sbc HIGH_BYTE _line_deltax 01:ACAE 8D B3 29 sta HIGH_BYTE _line_error 1659 1660 incw _line_deltax ; used as counter - get both endpoints 01:ACB1 EE AE 29 inc _line_deltax ; value at stated memory 01:ACB4 D0 03 bne .x_00412 ; location 01:ACB6 EE AF 29 inc _line_deltax+1 01:ACB9 .x_00412: 1661 1662 01:ACB9 .xlp1: 1663 stw _line_currx,<_bx ; draw pixel 01:ACB9 AD AA 29 lda LOW_BYTE _line_currx 01:ACBC 85 FA sta LOW_BYTE <_bx 01:ACBE AD AB 29 lda HIGH_BYTE _line_currx 01:ACC1 85 FB sta HIGH_BYTE <_bx 1664 stw _line_curry,<_cx 01:ACC3 AD AC 29 lda LOW_BYTE _line_curry 01:ACC6 85 FC sta LOW_BYTE <_cx 01:ACC8 AD AD 29 lda HIGH_BYTE _line_curry 01:ACCB 85 FD sta HIGH_BYTE <_cx 1665 01:ACCD AE B7 29 ldx _line_color 1666 01:ACD0 62 cla 1667 01:ACD1 20 52 AE jsr lib2_gfx_plot.3 1668 1669 decw _line_deltax ; dec counter 01:ACD4 38 sec ; value at stated memory 01:ACD5 AD AE 29 lda _line_deltax ; location 01:ACD8 E9 01 sbc #1 01:ACDA 8D AE 29 sta _line_deltax 01:ACDD AD AF 29 lda _line_deltax+1 01:ACE0 E9 00 sbc #0 01:ACE2 8D AF 29 sta _line_deltax+1 1670 tstw _line_deltax 01:ACE5 AD AE 29 lda _line_deltax ; value at stated memory 01:ACE8 0D AF 29 ora _line_deltax+1 ; location is zero 1671 lbeq .out 01:ACEB D0 03 bne .x_00417 01:ACED 4C 51 AE jmp .out 01:ACF0 .x_00417 1672 1673 01:ACF0 AD B6 29 lda _line_xdir ; adjust currx 1674 01:ACF3 F0 13 beq .xlppos 1675 1676 decw _line_currx 01:ACF5 38 sec ; value at stated memory 01:ACF6 AD AA 29 lda _line_currx ; location 01:ACF9 E9 01 sbc #1 01:ACFB 8D AA 29 sta _line_currx 01:ACFE AD AB 29 lda _line_currx+1 01:AD01 E9 00 sbc #0 01:AD03 8D AB 29 sta _line_currx+1 1677 01:AD06 80 08 bra .xlp2 1678 1679 .xlppos: incw _line_currx 01:AD08 EE AA 29 inc _line_currx ; value at stated memory 01:AD0B D0 03 bne .x_00419 ; location 01:AD0D EE AB 29 inc _line_currx+1 01:AD10 .x_00419: 1680 1681 01:AD10 .xlp2: 1682 01:AD10 AD B3 29 lda HIGH_BYTE _line_error 1683 01:AD13 30 1D bmi .xlp3 1684 1685 addw _line_adjust,_line_error 0000 .if (2 = 3) .else ; 2-arg mode ; 01:AD15 18 clc 01:AD16 AD B2 29 lda LOW_BYTE _line_error 01:AD19 6D B4 29 adc LOW_BYTE _line_adjust 01:AD1C 8D B2 29 sta LOW_BYTE _line_error 01:AD1F AD B3 29 lda HIGH_BYTE _line_error 01:AD22 6D B5 29 adc HIGH_BYTE _line_adjust 01:AD25 8D B3 29 sta HIGH_BYTE _line_error .endif 1686 incw _line_curry 01:AD28 EE AC 29 inc _line_curry ; value at stated memory 01:AD2B D0 03 bne .x_00421 ; location 01:AD2D EE AD 29 inc _line_curry+1 01:AD30 .x_00421: 1687 01:AD30 80 87 bra .xlp1 1688 01:AD32 .xlp3: 1689 addw _line_deltay,_line_error 0000 .if (2 = 3) .else ; 2-arg mode ; 01:AD32 18 clc 01:AD33 AD B2 29 lda LOW_BYTE _line_error 01:AD36 6D B0 29 adc LOW_BYTE _line_deltay 01:AD39 8D B2 29 sta LOW_BYTE _line_error 01:AD3C AD B3 29 lda HIGH_BYTE _line_error 01:AD3F 6D B1 29 adc HIGH_BYTE _line_deltay 01:AD42 8D B3 29 sta HIGH_BYTE _line_error .endif 1690 addw _line_deltay,_line_error 0000 .if (2 = 3) .else ; 2-arg mode ; 01:AD45 18 clc 01:AD46 AD B2 29 lda LOW_BYTE _line_error 01:AD49 6D B0 29 adc LOW_BYTE _line_deltay 01:AD4C 8D B2 29 sta LOW_BYTE _line_error 01:AD4F AD B3 29 lda HIGH_BYTE _line_error 01:AD52 6D B1 29 adc HIGH_BYTE _line_deltay 01:AD55 8D B3 29 sta HIGH_BYTE _line_error .endif 1691 01:AD58 4C B9 AC jmp .xlp1 1692 1693 01:AD5B .ybiglp: 1694 __ldw _line_deltax 0000 .if (1 = 2) .else 01:AD5B AE AE 29 ldx _line_deltax 01:AD5E AD AF 29 lda _line_deltax+1 .endif 1695 __aslw 01:AD61 22 sax 01:AD62 0A asl A 01:AD63 22 sax 01:AD64 2A rol A 1696 __stw _line_adjust 01:AD65 8E B4 29 stx _line_adjust 01:AD68 8D B5 29 sta _line_adjust+1 1697 __stw _line_error 01:AD6B 8E B2 29 stx _line_error 01:AD6E 8D B3 29 sta _line_error+1 1698 1699 subw _line_deltay,_line_adjust 01:AD71 38 sec 01:AD72 AD B4 29 lda LOW_BYTE _line_adjust 01:AD75 ED B0 29 sbc LOW_BYTE _line_deltay 01:AD78 8D B4 29 sta LOW_BYTE _line_adjust 01:AD7B AD B5 29 lda HIGH_BYTE _line_adjust 01:AD7E ED B1 29 sbc HIGH_BYTE _line_deltay 01:AD81 8D B5 29 sta HIGH_BYTE _line_adjust 1700 subw _line_deltay,_line_adjust 01:AD84 38 sec 01:AD85 AD B4 29 lda LOW_BYTE _line_adjust 01:AD88 ED B0 29 sbc LOW_BYTE _line_deltay 01:AD8B 8D B4 29 sta LOW_BYTE _line_adjust 01:AD8E AD B5 29 lda HIGH_BYTE _line_adjust 01:AD91 ED B1 29 sbc HIGH_BYTE _line_deltay 01:AD94 8D B5 29 sta HIGH_BYTE _line_adjust 1701 1702 subw _line_deltay,_line_error 01:AD97 38 sec 01:AD98 AD B2 29 lda LOW_BYTE _line_error 01:AD9B ED B0 29 sbc LOW_BYTE _line_deltay 01:AD9E 8D B2 29 sta LOW_BYTE _line_error 01:ADA1 AD B3 29 lda HIGH_BYTE _line_error 01:ADA4 ED B1 29 sbc HIGH_BYTE _line_deltay 01:ADA7 8D B3 29 sta HIGH_BYTE _line_error 1703 1704 incw _line_deltay ; used as counter - get both endpoints 01:ADAA EE B0 29 inc _line_deltay ; value at stated memory 01:ADAD D0 03 bne .x_00431 ; location 01:ADAF EE B1 29 inc _line_deltay+1 01:ADB2 .x_00431: 1705 1706 01:ADB2 .ylp1: 1707 stw _line_currx,<_bx ; draw pixel 01:ADB2 AD AA 29 lda LOW_BYTE _line_currx 01:ADB5 85 FA sta LOW_BYTE <_bx 01:ADB7 AD AB 29 lda HIGH_BYTE _line_currx 01:ADBA 85 FB sta HIGH_BYTE <_bx 1708 stw _line_curry,<_cx 01:ADBC AD AC 29 lda LOW_BYTE _line_curry 01:ADBF 85 FC sta LOW_BYTE <_cx 01:ADC1 AD AD 29 lda HIGH_BYTE _line_curry 01:ADC4 85 FD sta HIGH_BYTE <_cx 1709 01:ADC6 AE B7 29 ldx _line_color 1710 01:ADC9 62 cla 1711 01:ADCA 20 52 AE jsr lib2_gfx_plot.3 1712 1713 decw _line_deltay ; dec counter 01:ADCD 38 sec ; value at stated memory 01:ADCE AD B0 29 lda _line_deltay ; location 01:ADD1 E9 01 sbc #1 01:ADD3 8D B0 29 sta _line_deltay 01:ADD6 AD B1 29 lda _line_deltay+1 01:ADD9 E9 00 sbc #0 01:ADDB 8D B1 29 sta _line_deltay+1 1714 tstw _line_deltay 01:ADDE AD B0 29 lda _line_deltay ; value at stated memory 01:ADE1 0D B1 29 ora _line_deltay+1 ; location is zero 1715 01:ADE4 F0 6B beq .out 1716 1717 incw _line_curry 01:ADE6 EE AC 29 inc _line_curry ; value at stated memory 01:ADE9 D0 03 bne .x_00436 ; location 01:ADEB EE AD 29 inc _line_curry+1 01:ADEE .x_00436: 1718 1719 01:ADEE AD B3 29 lda HIGH_BYTE _line_error 1720 01:ADF1 30 35 bmi .ylp2 1721 1722 addw _line_adjust,_line_error 0000 .if (2 = 3) .else ; 2-arg mode ; 01:ADF3 18 clc 01:ADF4 AD B2 29 lda LOW_BYTE _line_error 01:ADF7 6D B4 29 adc LOW_BYTE _line_adjust 01:ADFA 8D B2 29 sta LOW_BYTE _line_error 01:ADFD AD B3 29 lda HIGH_BYTE _line_error 01:AE00 6D B5 29 adc HIGH_BYTE _line_adjust 01:AE03 8D B3 29 sta HIGH_BYTE _line_error .endif 1723 01:AE06 AD B6 29 lda _line_xdir 1724 01:AE09 F0 13 beq .ylppos 1725 1726 decw _line_currx 01:AE0B 38 sec ; value at stated memory 01:AE0C AD AA 29 lda _line_currx ; location 01:AE0F E9 01 sbc #1 01:AE11 8D AA 29 sta _line_currx 01:AE14 AD AB 29 lda _line_currx+1 01:AE17 E9 00 sbc #0 01:AE19 8D AB 29 sta _line_currx+1 1727 01:AE1C 80 94 bra .ylp1 1728 1729 .ylppos: incw _line_currx 01:AE1E EE AA 29 inc _line_currx ; value at stated memory 01:AE21 D0 03 bne .x_00439 ; location 01:AE23 EE AB 29 inc _line_currx+1 01:AE26 .x_00439: 1730 01:AE26 80 8A bra .ylp1 1731 1732 01:AE28 .ylp2: 1733 addw _line_deltax,_line_error 0000 .if (2 = 3) .else ; 2-arg mode ; 01:AE28 18 clc 01:AE29 AD B2 29 lda LOW_BYTE _line_error 01:AE2C 6D AE 29 adc LOW_BYTE _line_deltax 01:AE2F 8D B2 29 sta LOW_BYTE _line_error 01:AE32 AD B3 29 lda HIGH_BYTE _line_error 01:AE35 6D AF 29 adc HIGH_BYTE _line_deltax 01:AE38 8D B3 29 sta HIGH_BYTE _line_error .endif 1734 addw _line_deltax,_line_error 0000 .if (2 = 3) .else ; 2-arg mode ; 01:AE3B 18 clc 01:AE3C AD B2 29 lda LOW_BYTE _line_error 01:AE3F 6D AE 29 adc LOW_BYTE _line_deltax 01:AE42 8D B2 29 sta LOW_BYTE _line_error 01:AE45 AD B3 29 lda HIGH_BYTE _line_error 01:AE48 6D AF 29 adc HIGH_BYTE _line_deltax 01:AE4B 8D B3 29 sta HIGH_BYTE _line_error .endif 1735 01:AE4E 4C B2 AD jmp .ylp1 1736 1737 01:AE51 .out: 1738 01:AE51 60 rts 1739 1740 1741 ; gfx_plot(int x [bx], int y [cx], char color [reg acc]) 1742 ; ---- 1743 ; Plot a point at location (x,y) in color 1744 ; ---- 1745 1746 01:AE52 lib2_gfx_plot.3: 1747 01:AE52 86 FE stx <_dl ; color 1748 01:AE54 20 63 AF jsr gfx_getaddr 1749 1750 ; same as vm_rawread - save 21 cycles by inlining 1751 ; 1752 vreg #1 ; video read register 01:AE57 A9 01 lda #1 01:AE59 85 F7 sta 14 cycles by inlining 1772 ; 1773 01:AE8C DA phx 1774 01:AE8D AA tax 1775 vreg #0 ; video write register 01:AE8E A9 00 lda #0 01:AE90 85 F7 sta 14 cycles by inlining 1807 ; 1808 01:AEED DA phx 1809 01:AEEE AA tax 1810 vreg #0 ; video write register 01:AEEF A9 00 lda #0 01:AEF1 85 F7 sta cancel fade 63 ; $08 -> PCM fadeout 6 seconds 64 ; $0A -> ADPCM fadeout 6 seconds 65 ; $0C -> PCM fadeout 2.5 seconds 66 ; $0E -> ADPCM fadeout 2.5 seconds 67 ; ---- 68 ; Fade-out PCM/ADPCM audio 69 ; ---- 70 ; 71 00:DBD7 8A _cd_fade: txa 72 00:DBD8 20 2D E0 jsr cd_fade 73 00:DBDB AA tax 74 00:DBDC 62 cla 75 00:DBDD 60 rts 76 77 78 ; 79 ; cd_playtrk(int start_track [bx], int end_track [cx], int mode [acc]) 80 ; mode = CDPLAY_MUTE / CDPLAY_REPEAT / CDPLAY_NORMAL 81 ; ---- 82 ; Play CDROM audio track 83 ; ---- 84 ; 85 00:DBDE 8A _cd_playtrk.3: txa 86 00:DBDF 29 3F and #CD_PLAYMODE 87 00:DBE1 09 80 ora #CD_TRACK 88 00:DBE3 85 FF sta <_dh ; end type + play mode 89 00:DBE5 8D BD 29 sta cdplay_end_ctl 90 00:DBE8 A9 80 lda #CD_TRACK 91 00:DBEA 85 FB sta <_bh ; start type 92 93 00:DBEC A5 FC lda <_cl 94 00:DBEE D0 0B bne .endtrk 95 96 00:DBF0 A5 FF .endofdisc: lda <_dh ; repeat to end of disc 97 00:DBF2 09 C0 ora #CD_LEADOUT 98 00:DBF4 85 FF sta <_dh 99 00:DBF6 8D BD 29 sta cdplay_end_ctl 100 00:DBF9 80 12 bra .starttrk 101 102 00:DBFB 20 B4 E0 .endtrk: jsr ex_binbcd 103 00:DBFE 85 FC sta <_cl ; end track 104 00:DC00 8D BE 29 sta cdplay_end_h 105 00:DC03 64 FD stz <_ch 106 00:DC05 9C BF 29 stz cdplay_end_m 107 00:DC08 64 FE stz <_dl 108 00:DC0A 9C C0 29 stz cdplay_end_l 109 110 00:DC0D A5 FA .starttrk: lda <_bl ; track # 111 00:DC0F 20 B4 E0 jsr ex_binbcd 112 00:DC12 85 F8 sta <_al ; from track 113 00:DC14 64 F9 stz <_ah 114 00:DC16 64 FA stz <_bl 115 00:DC18 20 12 E0 jsr cd_play 116 00:DC1B AA tax 117 00:DC1C 62 cla 118 00:DC1D 60 rts 119 120 121 ; 122 ; cd_playmsf(int start_minute [al], int start_second [ah], int start_frame [bl], 123 ; int end_minute [cl], int end_second [ch], int end_frame [dl], int mode [acc]) 124 ; mode = CDPLAY_MUTE / CDPLAY_REPEAT / CDPLAY_NORMAL 125 ; ---- 126 ; Play CDROM from/to 'minute/second/frame' 127 ; ---- 128 ; 129 00:DC1E 8A _cd_playmsf.7: txa 130 00:DC1F 29 3F and #CD_PLAYMODE 131 00:DC21 09 40 ora #CD_MSF 132 00:DC23 85 FF sta <_dh ; end type + play mode 133 00:DC25 8D BD 29 sta cdplay_end_ctl 134 00:DC28 A9 40 lda #CD_MSF 135 00:DC2A 85 FB sta <_bh ; start type 136 137 00:DC2C A5 FE .endmsf: lda <_dl ; end frame 138 00:DC2E 20 B4 E0 jsr ex_binbcd 139 00:DC31 85 FE sta <_dl 140 00:DC33 8D C0 29 sta cdplay_end_l 141 142 00:DC36 A5 FD lda <_ch ; end second 143 00:DC38 20 B4 E0 jsr ex_binbcd 144 00:DC3B 85 FD sta <_ch 145 00:DC3D 8D BF 29 sta cdplay_end_m 146 147 00:DC40 A5 FC lda <_cl ; end minute 148 00:DC42 20 B4 E0 jsr ex_binbcd 149 00:DC45 85 FC sta <_cl 150 00:DC47 8D BE 29 sta cdplay_end_h 151 152 00:DC4A .startmsf: 153 00:DC4A A5 FA lda <_bl ; start frame 154 00:DC4C 20 B4 E0 jsr ex_binbcd 155 00:DC4F 85 FA sta <_bl 156 157 00:DC51 A5 F9 lda <_ah ; start second 158 00:DC53 20 B4 E0 jsr ex_binbcd 159 00:DC56 85 F9 sta <_ah 160 161 00:DC58 A5 F8 lda <_al ; start minute 162 00:DC5A 20 B4 E0 jsr ex_binbcd 163 00:DC5D 85 F8 sta <_al 164 165 00:DC5F 20 12 E0 jsr cd_play 166 00:DC62 AA tax 167 00:DC63 62 cla 168 00:DC64 60 rts 169 170 ; 171 ; char cd_numtrk(void) 172 ; ---- 173 ; return number of tracks on CDROM 174 ; ---- 175 ; 176 _cd_numtrk: stw #cd_buf,<_bx 00:DC65 A9 C1 lda LOW_BYTE #cd_buf 00:DC67 85 FA sta LOW_BYTE <_bx 00:DC69 A9 29 lda HIGH_BYTE #cd_buf 00:DC6B 85 FB sta HIGH_BYTE <_bx 177 00:DC6D 64 F8 stz <_al ; request type 0 178 00:DC6F 20 21 E0 jsr cd_dinfo 179 00:DC72 C9 00 cmp #$00 180 00:DC74 D0 09 bne .err 181 00:DC76 AD C2 29 lda cd_buf+1 182 00:DC79 20 B7 E0 jsr ex_bcdbin 183 00:DC7C 82 clx 184 00:DC7D 22 sax 185 00:DC7E 60 rts 186 00:DC7F A9 FF .err: lda #$ff 187 00:DC81 AA tax 188 00:DC82 60 rts 189 190 ; 191 ; char cd_trkinfo(char track [ax], char *min [cx], char *sec [dx], char *frm [bp]) 192 ; ---- 193 ; Return information about track 194 ; ---- 195 ; 196 00:DC83 _cd_trkinfo.4: 197 __ldw <_ax 0000 .if (1 = 2) .else 00:DC83 A6 F8 ldx <_ax 00:DC85 A5 F9 lda <_ax+1 .endif 198 00:DC87 20 A5 DC jsr _cd_trktype 199 00:DC8A DA phx 200 00:DC8B AD C1 29 lda cd_buf 201 00:DC8E 20 B7 E0 jsr ex_bcdbin 202 00:DC91 92 FC sta [_cx] 203 204 00:DC93 AD C2 29 lda cd_buf+1 205 00:DC96 20 B7 E0 jsr ex_bcdbin 206 00:DC99 92 FE sta [_dx] 207 208 00:DC9B AD C3 29 lda cd_buf+2 209 00:DC9E 20 B7 E0 jsr ex_bcdbin 210 00:DCA1 92 EC sta [_bp] 211 212 00:DCA3 FA plx 213 00:DCA4 60 rts 214 215 ; 216 ; char cd_trktype(char track) 217 ; ---- 218 ; Return type of track (data/audio) 219 ; ---- 220 ; 221 00:DCA5 22 _cd_trktype: sax 222 00:DCA6 20 B4 E0 jsr ex_binbcd 223 00:DCA9 85 F9 sta <_ah ; track # 224 stw #cd_buf,<_bx 00:DCAB A9 C1 lda LOW_BYTE #cd_buf 00:DCAD 85 FA sta LOW_BYTE <_bx 00:DCAF A9 29 lda HIGH_BYTE #cd_buf 00:DCB1 85 FB sta HIGH_BYTE <_bx 225 00:DCB3 C9 00 cmp #0 226 00:DCB5 F0 04 beq .discnottrk 227 00:DCB7 A9 02 lda #2 228 00:DCB9 80 02 bra .go 229 00:DCBB A9 01 .discnottrk lda #1 230 00:DCBD 85 F8 .go: sta <_al ; request type 2 231 00:DCBF 20 21 E0 jsr cd_dinfo 232 00:DCC2 C9 00 cmp #$00 233 00:DCC4 D0 05 bne .err 234 00:DCC6 AE C4 29 ldx cd_buf+3 ; track type 235 00:DCC9 62 cla 236 00:DCCA 60 rts 237 00:DCCB A9 FF .err: lda #$ff 238 00:DCCD AA tax 239 00:DCCE 60 rts 240 241 ; 242 ; char cd_execoverlay(int ovl_index) 243 ; ---- 244 ; Execute program overlay from disc 245 ; ---- 246 ; 247 00:DCCF _cd_execoverlay: 248 00:DCCF 20 E3 DC jsr cd_overlay 249 00:DCD2 C9 00 cmp #0 250 00:DCD4 D0 03 bne .error 251 00:DCD6 4C 00 C0 jmp $C000 ; loaded fine... now run it 252 00:DCD9 48 .error: pha 253 00:DCDA AE B1 26 ldx ovl_running ; failed; reload old segment for error recovery 254 00:DCDD 20 E3 DC jsr cd_overlay 255 00:DCE0 FA plx ; return error 256 00:DCE1 62 cla 257 00:DCE2 60 rts 258 259 00:DCE3 cd_overlay: 260 00:DCE3 20 CB DD jsr prep_rdsect 261 00:DCE6 64 FC stz <_cl ; sector (offset from base of track) 262 00:DCE8 85 FD sta <_ch 263 00:DCEA 86 FE stx <_dl 264 00:DCEC C8 iny 265 00:DCED B9 00 60 lda ovlarray,Y 266 00:DCF0 85 F8 sta <_al ; # sectors 267 00:DCF2 43 40 tma #6 268 00:DCF4 85 FA sta <_bl ; Bank # 269 00:DCF6 A9 03 lda #3 270 00:DCF8 85 FF sta <_dh ; MPR # 271 00:DCFA 20 09 E0 jsr cd_read 272 00:DCFD 60 rts 273 274 ; 275 ; char cd_loadvram(int ovl_index [di], int sect_offset [si], int vramaddr [bx], int bytes [acc]) 276 ; ---- 277 ; Load CDROM data directly into VRAM 278 ; ---- 279 ; 280 00:DCFE _cd_loadvram.4: 281 __stw <_ax 00:DCFE 86 F8 stx <_ax 00:DD00 85 F9 sta <_ax+1 282 __ldw <_di 0000 .if (1 = 2) .else 00:DD02 A6 F0 ldx <_di 00:DD04 A5 F1 lda <_di+1 .endif 283 00:DD06 20 CB DD jsr prep_rdsect 284 __addw <_si 00:DD09 18 clc 00:DD0A 22 sax 00:DD0B 65 EE adc <_si 00:DD0D 22 sax 00:DD0E 65 EF adc <_si+1 285 00:DD10 64 FC stz <_cl 286 00:DD12 85 FD sta <_ch 287 00:DD14 86 FE stx <_dl 288 00:DD16 A9 FE lda #$FE 289 00:DD18 85 FF sta <_dh 290 00:DD1A 20 09 E0 jsr cd_read 291 00:DD1D AA tax 292 00:DD1E 62 cla 293 00:DD1F 60 rts 294 ; 295 ; char cd_loaddata(int ovl_index [di], int sect_offset [si], farptr array [bl:bp], int bytes [acc]) 296 ; ---- 297 ; Load CDROM data directly into data area, replacing predefined data 298 ; ---- 299 ; 300 29C5 .bss 301 --:29C5 cdtemp_l .ds 1 302 --:29C6 cdtemp_m .ds 1 303 --:29C7 cdtemp_bank .ds 1 304 --:29C8 cdtemp_savbnk60 .ds 1 305 --:29C9 cdtemp_savbnk80 .ds 1 306 --:29CA cdtemp_addr .ds 2 307 --:29CC cdtemp_bytes .ds 2 308 DD20 .code 309 310 00:DD20 _cd_loaddata.4: 311 __stw cdtemp_bytes 00:DD20 8E CC 29 stx cdtemp_bytes 00:DD23 8D CD 29 sta cdtemp_bytes+1 312 __ldw <_di 0000 .if (1 = 2) .else 00:DD26 A6 F0 ldx <_di 00:DD28 A5 F1 lda <_di+1 .endif 313 00:DD2A 20 CB DD jsr prep_rdsect 314 __addw <_si 00:DD2D 18 clc 00:DD2E 22 sax 00:DD2F 65 EE adc <_si 00:DD31 22 sax 00:DD32 65 EF adc <_si+1 315 00:DD34 8E C5 29 stx cdtemp_l ; calculate sector adddress 316 00:DD37 8D C6 29 sta cdtemp_m 317 318 00:DD3A 43 08 tma #3 ; save entry banks 319 00:DD3C 8D C8 29 sta cdtemp_savbnk60 320 00:DD3F 43 10 tma #4 321 00:DD41 8D C9 29 sta cdtemp_savbnk80 322 323 00:DD44 A5 FA lda <_bl 324 00:DD46 8D C7 29 sta cdtemp_bank ; load addr (bank/address) 325 __ldw <_bp 0000 .if (1 = 2) .else 00:DD49 A6 EC ldx <_bp 00:DD4B A5 ED lda <_bp+1 .endif 326 00:DD4D 29 1F and #$1f ; correct to a $6000-relative addr. 327 00:DD4F 09 60 ora #$60 328 __stw cdtemp_addr 00:DD51 8E CA 29 stx cdtemp_addr 00:DD54 8D CB 29 sta cdtemp_addr+1 329 330 00:DD57 .loop: 331 00:DD57 AD C7 29 lda cdtemp_bank ; get 2 adjacent banks just in case 332 00:DD5A 53 08 tam #3 333 00:DD5C 1A inc A 334 00:DD5D 53 10 tam #4 335 336 __ldw cdtemp_addr ; load address 0000 .if (1 = 2) .else 00:DD5F AE CA 29 ldx cdtemp_addr 00:DD62 AD CB 29 lda cdtemp_addr+1 .endif 337 __stw <_bx 00:DD65 86 FA stx <_bx 00:DD67 85 FB sta <_bx+1 338 339 00:DD69 64 FC stz <_cl ; sector address 340 00:DD6B AD C6 29 lda cdtemp_m 341 00:DD6E 85 FD sta <_ch 342 00:DD70 AD C5 29 lda cdtemp_l 343 00:DD73 85 FE sta <_dl 344 00:DD75 64 FF stz <_dh ; address type (local, # bytes) 345 346 __ldw cdtemp_bytes 0000 .if (1 = 2) .else 00:DD77 AE CC 29 ldx cdtemp_bytes 00:DD7A AD CD 29 lda cdtemp_bytes+1 .endif 347 sub #$20 0000 .if (1 = 2) ; from register A (handle .else 00:DD7D 38 sec 00:DD7E E9 20 sbc #$20 .endif 348 00:DD80 30 0C bmi .less2000 349 __stw cdtemp_bytes 00:DD82 8E CC 29 stx cdtemp_bytes 00:DD85 8D CD 29 sta cdtemp_bytes+1 350 __ldwi $2000 00:DD88 A2 00 ldx #low($2000) 00:DD8A A9 20 lda #high($2000) 351 00:DD8C 80 09 bra .read 352 353 .less2000: add #$20 0000 .if (1 = 2) ; register A (handle carry .else 00:DD8E 18 clc 00:DD8F 69 20 adc #$20 .endif 354 stwz cdtemp_bytes 00:DD91 9C CC 29 stz LOW_BYTE cdtemp_bytes 00:DD94 9C CD 29 stz HIGH_BYTE cdtemp_bytes 355 .read: __stw <_ax 00:DD97 86 F8 stx <_ax 00:DD99 85 F9 sta <_ax+1 356 357 00:DD9B 20 09 E0 jsr cd_read 358 00:DD9E C9 00 cmp #0 359 00:DDA0 D0 1C bne .error 360 361 __tstw cdtemp_bytes ; if still some bytes to read ; pha 00:DDA2 86 03 stx <__temp 00:DDA4 05 03 ora <__temp ; pla 362 00:DDA6 F0 16 beq .error ; but A = 0 so no error 363 364 addw #4,cdtemp_l ; add 4 sectors (with 16-bit carry) 0000 .if (2 = 3) .else ; 2-arg mode ; 00:DDA8 18 clc 00:DDA9 AD C5 29 lda LOW_BYTE cdtemp_l 00:DDAC 69 04 adc LOW_BYTE #4 00:DDAE 8D C5 29 sta LOW_BYTE cdtemp_l 00:DDB1 AD C6 29 lda HIGH_BYTE cdtemp_l 00:DDB4 69 00 adc HIGH_BYTE #4 00:DDB6 8D C6 29 sta HIGH_BYTE cdtemp_l .endif 365 00:DDB9 EE C7 29 inc cdtemp_bank ; go back for next bank 366 00:DDBC 80 99 bra .loop 367 368 00:DDBE AA .error: tax 369 00:DDBF AD C8 29 lda cdtemp_savbnk60 370 00:DDC2 53 08 tam #3 371 00:DDC4 AD C9 29 lda cdtemp_savbnk80 372 00:DDC7 53 10 tam #4 373 00:DDC9 62 cla 374 00:DDCA 60 rts 375 376 ; 377 ; prepare the sector address 378 ; 379 00:DDCB 8A prep_rdsect: txa 380 00:DDCC 0A asl A 381 00:DDCD 0A asl A 382 00:DDCE A8 tay 383 map ovlarray ; in DATA_BANK 00:DDCF A9 83 lda #bank(ovlarray) ; addressable memory 00:DDD1 53 08 tam #page(ovlarray) 384 00:DDD3 BE 00 60 ldx ovlarray,Y 385 00:DDD6 C8 iny 386 00:DDD7 B9 00 60 lda ovlarray,Y 387 00:DDDA 60 rts 388 389 ;-------------------- 390 ; NOT IMPLEMENTED YET 391 ;-------------------- 392 ; 393 ; 394 ; cd_status() 395 ; ---- 396 ; Get CDROM status 397 ; 398 ; input $00 (= busy check) -> return $00 if not busy, else busy 399 ; (other) (= ready check) -> return $00 if ready, else sub error code 400 ; ---- 401 ; 402 00:DDDB _cd_status: 403 00:DDDB 8A txa 404 00:DDDC 20 1B E0 jsr cd_stat 405 00:DDDF AA tax 406 00:DDE0 62 cla 407 00:DDE1 60 rts 408 409 410 ;-------------------- 411 412 413 ; 414 ; int cd_getver() 415 ; ---- 416 ; get CDROM system card version number 417 ; MSB = major number 418 ; LSB = minor number 419 ; ---- 420 ; 421 00:DDE2 _cd_getver: 422 00:DDE2 20 5A E0 jsr ex_getver 423 00:DDE5 98 tya 424 00:DDE6 22 sax 425 00:DDE7 60 rts 426 427 428 ; 429 ; int ac_exists(void) 430 ; ---- 431 ; Detect Arcade Card (return 1 if true) 432 ; ---- 433 ; 434 00:DDE8 AD FF 1A _ac_exists: lda ac_identflag 435 00:DDEB A2 01 ldx #1 436 00:DDED C9 51 cmp #AC_IDENT 437 00:DDEF F0 01 beq .true 438 00:DDF1 82 clx 439 00:DDF2 62 .true: cla 440 00:DDF3 60 rts 441 442 ; 443 ; ad_reset(void) 444 ; ---- 445 ; Reset ADPCM device 446 ; ---- 447 ; 448 00:DDF4 20 30 E0 _ad_reset: jsr ad_reset 449 00:DDF7 60 rts 450 451 ; 452 ; ad_stop(void) 453 ; ---- 454 ; stop ADPCM playing 455 ; ---- 456 ; 457 00:DDF8 20 42 E0 _ad_stop: jsr ad_stop 458 00:DDFB 60 rts 459 460 ; 461 ; char ad_stat(void) 462 ; ---- 463 ; Get ADPCM status 464 ; ---- 465 ; 466 00:DDFC 20 45 E0 _ad_stat: jsr ad_stat 467 00:DDFF AA tax 468 00:DE00 62 cla 469 00:DE01 60 rts 470 471 ; 472 ; char ad_trans(int ovl_index [di], int sect_offset [si], char nb_sectors [al], int ad_addr [bx]) 473 ; ---- 474 ; Load CDROM data directly into ADPCM RAM 475 ; ---- 476 ; 477 00:DE02 _ad_trans.4: 478 __ldw <_di 0000 .if (1 = 2) .else 00:DE02 A6 F0 ldx <_di 00:DE04 A5 F1 lda <_di+1 .endif 479 00:DE06 20 CB DD jsr prep_rdsect 480 __addw <_si 00:DE09 18 clc 00:DE0A 22 sax 00:DE0B 65 EE adc <_si 00:DE0D 22 sax 00:DE0E 65 EF adc <_si+1 481 00:DE10 64 FC stz <_cl 482 00:DE12 85 FD sta <_ch 483 00:DE14 86 FE stx <_dl 484 00:DE16 64 FF stz <_dh 485 00:DE18 20 33 E0 jsr ad_trans 486 00:DE1B AA tax 487 00:DE1C 62 cla 488 00:DE1D 60 rts 489 490 ; 491 ; char ad_read(int ad_addr [cx], char mode [dh], int buf [bx], int bytes [ax]) 492 ; ---- 493 ; copy data from ADPCM RAM directly to RAM or VRAM 494 ; ---- 495 ; 496 00:DE1E _ad_read.4: 497 00:DE1E 20 36 E0 jsr ad_read 498 00:DE21 AA tax 499 00:DE22 62 cla 500 00:DE23 60 rts 501 502 ; 503 ; char ad_write(int ad_addr [cx], char mode [dh], int buf [bx], int bytes [ax]) 504 ; ---- 505 ; copy data from RAM or VRAM directly to ADPCM VRAM 506 ; ---- 507 ; 508 00:DE24 _ad_write.4: 509 00:DE24 20 39 E0 jsr ad_write 510 00:DE27 AA tax 511 00:DE28 62 cla 512 00:DE29 60 rts 513 514 ; 515 ; char ad_play(int ad_addr [bx], int bytes [ax], char freq [dh], char mode [dl]) 516 ; ---- 517 ; play ADPCM sample 518 ; ---- 519 ; 520 00:DE2A _ad_play.4: 521 00:DE2A 20 3C E0 jsr ad_play 522 00:DE2D AA tax 523 00:DE2E 62 cla 524 00:DE2F 60 rts #[2] startup.asm 1229 .else 1231 .endif ; CDROM 1232 1233 ; ---- 1234 ; disp_on 1235 ; ---- 1236 ; enable display 1237 ; ---- 1238 1239 0001 .ifdef HUC 1240 00:DE30 _disp_on: 1241 00:DE30 AE 8E 26 ldx disp_cr 1242 00:DE33 A9 01 lda #1 1243 00:DE35 8D 8E 26 sta disp_cr 1244 00:DE38 62 cla 1245 00:DE39 60 rts 1246 .else 1251 .endif ; HUC 1252 1253 ; ---- 1254 ; disp_off 1255 ; ---- 1256 ; disable display 1257 ; ---- 1258 1259 0001 .ifdef HUC 1260 00:DE3A _disp_off: 1261 00:DE3A AE 8E 26 ldx disp_cr 1262 00:DE3D 9C 8E 26 stz disp_cr 1263 00:DE40 62 cla 1264 00:DE41 60 rts 1265 .else 1269 .endif ; HUC 1270 1271 ; ---- 1272 ; set_intvec 1273 ; ---- 1274 ; set interrupt vector 1275 ; ---- 1276 ; IN : A = vector number 1277 ; 0 IRQ2 1278 ; 1 IRQ1 (VDC) 1279 ; 2 TIMER 1280 ; 3 NMI 1281 ; 4 VSYNC 1282 ; 5 HSYNC 1283 ; 6 SOFT RESET (RUN + SELECT) 1284 ; X = vector address low byte 1285 ; Y = " " high byte 1286 ; ---- 1287 1288 0000 .if !(CDROM) 1312 .endif ; !(CDROM) 1313 1314 ; ---- 1315 ; wait_vsync 1316 ; ---- 1317 ; wait the next vsync 1318 ; ---- 1319 ; IN : A = number of frames to be sync'ed on 1320 ; ---- 1321 ; OUT: A = number of elapsed frames since last call 1322 ; ---- 1323 1324 00:DE42 wait_vsync: 1325 00:DE42 1F F5 03 bbr1