Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
; z80dasm 1.1.3
; command line: z80dasm -l -a -g 0h original_rom.bin
; Peripheral mappings
; YM3514
ym3514_addr: equ 0e000h
; YM2142
ym2142_addr: equ 0e030h
; ROM mappings
; RAM mappings
key_states: equ 08000h
key_diffs: equ 08009h
key_state1: equ 08012h
common_c1: equ 08014h ; Some kind of output note array?
kpr_08018h: equ 08018h ; kpr = key-press related
common_c2: equ 0801ch ; Some kind of output note array?
common_c5: equ 08020h ; Some kind of output note array?
common_c3: equ 08024h ; Some kind of output note array?
common_c4: equ 08028h ; Some kind of output note array?
kpr_0802ch: equ 0802ch ; kpr = key-press related
ym2142_source1: equ 08030h
common_b1: equ 08033h
common_b2: equ 08034h
num_keys_ignore: equ 08035h ; "Loop while key_remaining < (num_keys_ignore)"
common_a1: equ 08036h
common_a2: equ 08037h
common_a3: equ 08038h
ym3514_thing1: equ 0804eh
ym3514_thing2: equ 0804fh
common_elsewhere1: equ 080b9h
loaded_thing7: equ 0805dh
loaded_thing8: equ 0805fh
loaded_thing3: equ 08061h
loaded_thing4: equ 08063h
loaded_thing9: equ 08065h
loaded_thing10: equ 08067h
loaded_thing5: equ 08069h
loaded_thing6: equ 0806bh
loaded_thing12: equ 080b5h
loaded_thing11: equ 080b7h
loaded_thing1: equ 080bdh
loaded_thing2: equ 080bbh
flags1: equ 080ceh
; flags1:
; - 6: YM2142_DIRTY (???)
flags2: equ 080d1h
flags3: equ 080d2h
common_array1: equ 080d3h
; common_array1:
; - ???
key_result_flags1: equ 080cdh
stack_start_addr: equ 0873fh
; Constants
; Start of program
org 00000h
di ;0000
ld sp,stack_start_addr ;0001
im 1 ;0004
jp entry_point ;0006
rst 0 ;0009
rst 0 ;000a
rst 0 ;000b
rst 0 ;000c
rst 0 ;000d
rst 0 ;000e
rst 0 ;000f
rst 0 ;0010
rst 0 ;0011
rst 0 ;0012
rst 0 ;0013
rst 0 ;0014
rst 0 ;0015
rst 0 ;0016
rst 0 ;0017
rst 0 ;0018
rst 0 ;0019
rst 0 ;001a
rst 0 ;001b
rst 0 ;001c
rst 0 ;001d
rst 0 ;001e
rst 0 ;001f
rst 0 ;0020
rst 0 ;0021
rst 0 ;0022
rst 0 ;0023
rst 0 ;0024
rst 0 ;0025
rst 0 ;0026
rst 0 ;0027
rst 0 ;0028
rst 0 ;0029
rst 0 ;002a
rst 0 ;002b
rst 0 ;002c
rst 0 ;002d
rst 0 ;002e
rst 0 ;002f
rst 0 ;0030
rst 0 ;0031
rst 0 ;0032
rst 0 ;0033
rst 0 ;0034
rst 0 ;0035
rst 0 ;0036
rst 0 ;0037
jp interrupt_handler_1 ;0038
rst 0 ;003b
rst 0 ;003c
rst 0 ;003d
rst 0 ;003e
rst 0 ;003f
rst 0 ;0040
rst 0 ;0041
rst 0 ;0042
rst 0 ;0043
rst 0 ;0044
rst 0 ;0045
rst 0 ;0046
rst 0 ;0047
rst 0 ;0048
rst 0 ;0049
rst 0 ;004a
rst 0 ;004b
rst 0 ;004c
rst 0 ;004d
rst 0 ;004e
rst 0 ;004f
rst 0 ;0050
rst 0 ;0051
rst 0 ;0052
rst 0 ;0053
rst 0 ;0054
rst 0 ;0055
rst 0 ;0056
rst 0 ;0057
rst 0 ;0058
rst 0 ;0059
rst 0 ;005a
rst 0 ;005b
rst 0 ;005c
rst 0 ;005d
rst 0 ;005e
rst 0 ;005f
rst 0 ;0060
rst 0 ;0061
rst 0 ;0062
rst 0 ;0063
rst 0 ;0064
rst 0 ;0065
jp interrupt_handler_2 ;0066
sub_ym3514_write_and_calc_2:
ld a,002h ;0069
ld (ym3514_addr+01h),a ;006b
xor a ;006e
ld (ym3514_addr+27h),a ;006f
ld a,01eh ;0072
ld (ym3514_thing2),a ;0074
ld (ym3514_addr+02h),a ;0077
xor a ;007a
l007bh:
cp 01eh ;007b
l007dh:
jp z,l0093h ;007d
l0080h:
ld (ym3514_thing1),a ;0080
ld (ym3514_addr+03h),a ;0083
push af ;0086
ld hl,0028h ;0087
push hl ;008a
call sub_delay_variable_time_1 ;008b
pop af ;008e
inc a ;008f
l0090h:
jp l007bh ;0090
l0093h:
ld bc,key_states ;0093
l0096h:
xor a ;0096
ld (bc),a ;0097
inc bc ;0098
ld hl,086dbh ;0099
sbc hl,bc ;009c
jp nz,l0096h ;009e
ld hl,common_c1 ;00a1
xor a ;00a4
l00a5h:
ld (hl),a ;00a5
inc hl ;00a6
inc a ;00a7
cp 004h ;00a8
jp nz,l00a5h ;00aa
ld a,004h ;00ad
ld (0803eh),a ;00af
ld (common_b2),a ;00b2
ld a,012h ;00b5
ld (num_keys_ignore),a ;00b7
ld a,00fh ;00ba
ld (08043h),a ;00bc
ld (08045h),a ;00bf
call sub_0fc5h_calc_with_b1c1_array1_and_b2 ;00c2
xor a ;00c5
ld (ym3514_addr+01h),a ;00c6
call sub_delay_roughly_5_cycles ;00c9
ld (ym3514_addr+13h),a ;00cc
ret ;00cf
interrupt_handler_1:
push af ;00d0
push bc ;00d1
push de ;00d2
push hl ;00d3
push ix ;00d4
push iy ;00d6
ld a,(flags2) ;00d8
bit 1,a ;00db
jp nz,l01a7h ;00dd
ld a,(common_a1) ;00e0
srl a ;00e3
ld hl,common_a2 ;00e5
cp (hl) ;00e8
jp z,l0172h ;00e9
ld (hl),a ;00ec
ld d,000h ;00ed
ld e,a ;00ef
ld a,(0803eh) ;00f0
cp 001h ;00f3
jp nz,l00feh ;00f5
ld hl,l0921h ;00f8
jp l0101h ;00fb
l00feh:
ld hl,l08f1h ;00fe
l0101h:
add hl,de ;0101
ld a,(common_a3) ;0102
and 00fh ;0105
cp (hl) ;0107
l0108h:
jp z,l010eh ;0108
call sub_01b2h_calc_and_write_12B_to_ym2142 ;010b
l010eh:
ld a,(flags1) ;010e
and 007h ;0111
jp z,l0172h ;0113
ld a,(08054h) ;0116
or a ;0119
jp z,l0147h ;011a
dec a ;011d
jp nz,l0132h ;011e
ld hl,0808fh ;0121
ld a,(hl) ;0124
and 03fh ;0125
ld (08054h),a ;0127
ld hl,080d8h ;012a
set 2,(hl) ;012d
jp l0147h ;012f
l0132h:
ld (08054h),a ;0132
cp 001h ;0135
jp nz,l0147h ;0137
ld hl,080d8h ;013a
bit 6,(hl) ;013d
jp nz,l0147h ;013f
ld hl,flags2 ;0142
set 1,(hl) ;0145
l0147h:
ld a,(08053h) ;0147
or a ;014a
jp z,l0167h ;014b
dec a ;014e
jp nz,l0164h ;014f
ld hl,0808fh ;0152
inc hl ;0155
ld a,(hl) ;0156
and 03fh ;0157
ld (08053h),a ;0159
ld hl,080d8h ;015c
set 3,(hl) ;015f
jp l0167h ;0161
l0164h:
ld (08053h),a ;0164
l0167h:
ld a,(08050h) ;0167
or a ;016a
jp z,l0172h ;016b
dec a ;016e
ld (08050h),a ;016f
l0172h:
ld a,(0803eh) ;0172
or a ;0175
jp nz,l017eh ;0176
ld a,047h ;0179
jp l0180h ;017b
l017eh:
ld a,05fh ;017e
l0180h:
ld hl,common_a1 ;0180
cp (hl) ;0183
jp nz,l019dh ;0184
xor a ;0187
ld (hl),a ;0188
ld hl,080d8h ;0189
set 4,(hl) ;018c
bit 7,(hl) ;018e
jp z,l0198h ;0190
set 7,(hl) ;0193
jp l01a7h ;0195
l0198h:
res 7,(hl) ;0198
jp l01a7h ;019a
l019dh:
inc (hl) ;019d
cp (hl) ;019e
jp nz,l01a7h ;019f
ld hl,080d8h ;01a2
set 5,(hl) ;01a5
l01a7h:
pop iy ;01a7
pop ix ;01a9
pop hl ;01ab
pop de ;01ac
pop bc ;01ad
pop af ;01ae
ei ;01af
reti ;01b0
; This is called from interrupt_handler_1 if:
; flags2 & (1<<1) == 0 &&
; common_a2 != 0 &&
; common_a3 & 0x7 != 0
sub_01b2h_calc_and_write_12B_to_ym2142:
ld a,(hl) ;01b2
or a ;01b3
ld a,(common_a3) ;01b4
jp nz,l01c3h ;01b7
bit 7,a ;01ba
ld a,(hl) ;01bc
jp nz,l01cbh ;01bd
jp l01c9h ;01c0
l01c3h:
bit 7,a ;01c3
ld a,(hl) ;01c5
jp z,l01cbh ;01c6
l01c9h:
set 7,a ;01c9
l01cbh:
ld (common_a3),a ;01cb
ld a,(flags1) ;01ce
and 007h ;01d1
jp z,l01e1h ;01d3
ld hl,flags1 ;01d6
bit 4,(hl) ;01d9
jp nz,l01f1h ;01db
jp l01feh ;01de
l01e1h:
ld a,(key_result_flags1) ;01e1
bit 0,a ;01e4
jp z,l025ah ;01e6
ld a,01eh ;01e9
ld (ym3514_thing2),a ;01eb
ld (ym3514_addr+02h),a ;01ee
l01f1h:
ld a,(common_a3) ;01f1
and 00fh ;01f4
jp nz,l01feh ;01f6
ld a,01dh ;01f9
jp l0200h ;01fb
l01feh:
ld a,01eh ;01fe
l0200h:
ld (ym3514_thing1),a ;0200
ld (ym3514_addr+03h),a ;0203
ld a,(key_result_flags1) ;0206
bit 0,a ;0209
jp z,l0228h ;020b
ld hl,l0090h ;020e
push hl ;0211
ld h,000h ;0212
ld a,(08042h) ;0214
ld l,a ;0217
push hl ;0218
call sub_ym2142_write_2B ;0219
xor a ;021c
ld (08042h),a ;021d
ld a,(key_result_flags1) ;0220
bit 1,a ;0223
jp nz,l0230h ;0225
l0228h:
ld a,(flags1) ;0228
and 007h ;022b
jp z,l025ah ;022d
l0230h:
ld a,(common_a3) ;0230
ld h,000h ;0233
ld l,a ;0235
push hl ;0236
push hl ;0237
call sub_15fdh_calc ;0238
pop hl ;023b
ld a,l ;023c
cp 0ffh ;023d
jp z,l0249h ;023f
ld hl,00001h+1 ;0242
push hl ;0245
call sub_078dh_maybe_write_many_to_ym2142 ;0246
l0249h:
call sub_165ch ;0249
pop hl ;024c
ld a,l ;024d
cp 0ffh ;024e
jp z,l025ah ;0250
ld hl,00001h+2 ;0253
push hl ;0256
call sub_078dh_maybe_write_many_to_ym2142 ;0257
l025ah:
ret ;025a
interrupt_handler_2:
ld a,01eh ;025b
ld (ym3514_thing2),a ;025d
ld (ym3514_addr+02h),a ;0260
ld (ym3514_thing1),a ;0263
ld (ym3514_addr+03h),a ;0266
call sub_delay_roughly_5_cycles ;0269
ld (ym3514_addr+26h),a ;026c
ld a,(ym3514_addr+25h) ;026f
and 060h ;0272
jp nz,l0282h ;0274
ld hl,flags1 ;0277
res 5,(hl) ;027a
ld hl,0 ;027c
ld (common_elsewhere1),hl ;027f
l0282h:
cp 020h ;0282
jp z,l029eh ;0284
ld (loaded_thing1),hl ;0287
ld (loaded_thing2),hl ;028a
ld (loaded_thing7),hl ;028d
ld (loaded_thing8),hl ;0290
ld (loaded_thing9),hl ;0293
ld (loaded_thing10),hl ;0296
cp 040h ;0299
jp z,interrupt_handler_2_jump_table_execute ;029b
l029eh:
ld (loaded_thing3),hl ;029e
ld (loaded_thing4),hl ;02a1
ld (loaded_thing5),hl ;02a4
ld (loaded_thing6),hl ;02a7
ld (loaded_thing11),hl ;02aa
ld (loaded_thing12),hl ;02ad
interrupt_handler_2_jump_table_execute:
ld a,(ym3514_addr+25h) ;02b0
and 00fh ;02b3
; Now: a = i0 = (ym3514_addr+25h) & 0xf
ld c,a ;02b5
; Now: c = i0
rlca ;02b6
; Now: a = i0 << 1
add a,c ;02b7
; Now a = (i0 << 1) + i0 = i0 * 3
; Set hl = 02c0h + a
ld e,a ;02b8
ld d,000h ;02b9
ld hl,l02c0h ;02bb
add hl,de ;02be
; Jump to the following table
jp (hl) ;02bf
l02c0h:
jp interrupt_handler_2_subpath_default ;02c0
jp interrupt_handler_2_subpath_1 ;02c3
jp interrupt_handler_2_subpath_2 ;02c6
jp interrupt_handler_2_subpath_3 ;02c9
jp interrupt_handler_2_subpath_4 ;02cc
jp interrupt_handler_2_subpath_5 ;02cf
jp interrupt_handler_2_subpath_6 ;02d2
jp interrupt_handler_2_jump_table_execute ;02d5
jp interrupt_handler_2_jump_table_execute ;02d8
jp interrupt_handler_2_subpath_7 ;02db
jp interrupt_handler_2_subpath_8 ;02de
jp interrupt_handler_2_subpath_9 ;02e1
jp interrupt_handler_2_subpath_check_loaded_things ;02e4
jp interrupt_handler_2_subpath_default ;02e7
jp interrupt_handler_2_subpath_default ;02ea
jp interrupt_handler_2_subpath_default ;02ed
sub_ym3514_21_25_26_do_stuff_1:
ld a,(ym3514_addr+25h) ;02f0
and 00fh ;02f3
jp z,l032dh ;02f5
cp 00dh ;02f8
jp p,l032dh ;02fa
cp 007h ;02fd
jp z,l0307h ;02ff
cp 008h ;0302
jp nz,l030bh ;0304
l0307h:
cp c ;0307
jp nz,l0329h ;0308
l030bh:
ld a,(ym3514_addr+21h) ;030b
bit 7,a ;030e
jp z,sub_ym3514_21_25_26_do_stuff_1 ;0310
ld a,h ;0313
cp 004h ;0314
jp z,l032dh ;0316
l0319h:
ld (ym3514_addr+26h),a ;0319
call sub_delay_roughly_5_cycles ;031c
ld a,(ym3514_addr+21h) ;031f
bit 7,a ;0322
jp nz,l0319h ;0324
or a ;0327
ret ;0328
l0329h:
ld a,001h ;0329
scf ;032b
ret ;032c
l032dh:
ld a,0ffh ;032d
scf ;032f
ret ;0330
interrupt_handler_2_subpath_1:
ld hl,0 ;0331
call sub_ym3514_21_25_26_do_stuff_1 ;0334
jp c,interrupt_handler_2_subpath_default ;0337
l033ah:
ld a,(ym3514_addr+25h) ;033a
and 00fh ;033d
cp c ;033f
jp z,l033ah ;0340
jp interrupt_handler_2_jump_table_execute ;0343
interrupt_handler_2_subpath_2:
ld b,003h ;0346
ld hl,0802dh ;0348
l034bh:
call sub_ym3514_21_25_26_do_stuff_1 ;034b
jp c,interrupt_handler_2_subpath_default ;034e
ld a,(ym3514_addr+23h) ;0351
ld (hl),a ;0354
inc hl ;0355
dec b ;0356
ld a,(ym3514_addr+25h) ;0357
and 00fh ;035a
cp c ;035c
jp z,l034bh ;035d
ld a,b ;0360
and a ;0361
jp nz,interrupt_handler_2_subpath_default ;0362
jp interrupt_handler_2_jump_table_execute ;0365
interrupt_handler_2_subpath_3:
ld hl,0 ;0368
call sub_ym3514_21_25_26_do_stuff_1 ;036b
jp c,interrupt_handler_2_subpath_default ;036e
ld a,(ym3514_addr+23h) ;0371
and 01fh ;0374
ld b,a ;0376
l0377h:
ld a,(ym3514_addr+25h) ;0377
and 00fh ;037a
cp c ;037c
jp z,l0377h ;037d
jp interrupt_handler_2_jump_table_execute ;0380
interrupt_handler_2_subpath_4:
ld hl,(common_elsewhere1) ;0383
ld (loaded_thing1),hl ;0386
l0389h:
call sub_ym3514_21_25_26_do_stuff_1 ;0389
jp c,interrupt_handler_2_subpath_default ;038c
ld a,(ym3514_addr+24h) ;038f
ex de,hl ;0392
ld hl,080dah ;0393
add hl,de ;0396
ld (hl),a ;0397
ex de,hl ;0398
inc hl ;0399
dec b ;039a
ld a,(ym3514_addr+25h) ;039b
and 00fh ;039e
cp c ;03a0
jp z,l0389h ;03a1
ld a,b ;03a4
and a ;03a5
jp nz,interrupt_handler_2_subpath_default ;03a6
ld (common_elsewhere1),hl ;03a9
dec hl ;03ac
ld (loaded_thing2),hl ;03ad
jp interrupt_handler_2_jump_table_execute ;03b0
interrupt_handler_2_subpath_5:
ld hl,(common_elsewhere1) ;03b3
ld (loaded_thing7),hl ;03b6
call sub_ym3514_21_25_26_do_stuff_1_with_globals_1 ;03b9
jp c,interrupt_handler_2_subpath_default ;03bc
ld (loaded_thing9),hl ;03bf
jp interrupt_handler_2_jump_table_execute ;03c2
interrupt_handler_2_subpath_6:
ld hl,(common_elsewhere1) ;03c5
ld (loaded_thing8),hl ;03c8
call sub_ym3514_21_25_26_do_stuff_1_with_globals_1 ;03cb
jp c,interrupt_handler_2_subpath_default ;03ce
ld (loaded_thing10),hl ;03d1
jp interrupt_handler_2_jump_table_execute ;03d4
sub_ym3514_21_25_26_do_stuff_1_with_globals_1:
call sub_ym3514_21_25_26_do_stuff_1 ;03d7
jp nc,l03e3h ;03da
cp 001h ;03dd
jp z,l040dh ;03df
ret ;03e2
l03e3h:
ld a,(ym3514_addr+21h) ;03e3
and 01fh ;03e6
ld d,000h ;03e8
ld e,a ;03ea
ld ix,(loaded_thing1) ;03eb
add ix,de ;03ef
ld de,080dah ;03f1
add ix,de ;03f4
ld a,(ix+000h) ;03f6
ex de,hl ;03f9
ld hl,080dah ;03fa
add hl,de ;03fd
ld (hl),a ;03fe
l03ffh:
ex de,hl ;03ff
inc hl ;0400
ld (ym3514_addr+20h),a ;0401
ld a,(ym3514_addr+25h) ;0404
and 00fh ;0407
cp c ;0409
jp z,sub_ym3514_21_25_26_do_stuff_1_with_globals_1 ;040a
l040dh:
ld (common_elsewhere1),hl ;040d
dec hl ;0410
or a ;0411
ret ;0412
interrupt_handler_2_subpath_7:
ld hl,(common_elsewhere1) ;0413
ld (loaded_thing11),hl ;0416
l0419h:
call sub_ym3514_21_25_26_do_stuff_1 ;0419
jp c,interrupt_handler_2_subpath_default ;041c
ld a,(ym3514_addr+22h) ;041f
ld d,a ;0422
ld a,(ym3514_addr+23h) ;0423
ld b,a ;0426
or a ;0427
jp nz,l0431h ;0428
ld a,d ;042b
and 003h ;042c
jp z,l0443h ;042e
l0431h:
ld a,d ;0431
ex de,hl ;0432
ld hl,080dah ;0433
add hl,de ;0436
ld (hl),a ;0437
ex de,hl ;0438
inc hl ;0439
ld a,b ;043a
ex de,hl ;043b
ld hl,080dah ;043c
add hl,de ;043f
ld (hl),a ;0440
ex de,hl ;0441
inc hl ;0442
l0443h:
ld a,(ym3514_addr+25h) ;0443
and 00fh ;0446
cp c ;0448
jp z,l0419h ;0449
ld (common_elsewhere1),hl ;044c
dec hl ;044f
ld (loaded_thing12),hl ;0450
jp interrupt_handler_2_jump_table_execute ;0453
interrupt_handler_2_subpath_8:
ld hl,(common_elsewhere1) ;0456
ld (loaded_thing3),hl ;0459
call sub_ym3514_21_25_26_do_stuff_1_with_globals_2 ;045c
jp c,interrupt_handler_2_subpath_default ;045f
ld a,h ;0462
or b ;0463
ld h,a ;0464
ld (loaded_thing5),hl ;0465
jp interrupt_handler_2_jump_table_execute ;0468
interrupt_handler_2_subpath_9:
ld hl,(common_elsewhere1) ;046b
ld (loaded_thing4),hl ;046e
call sub_ym3514_21_25_26_do_stuff_1_with_globals_2 ;0471
jp c,interrupt_handler_2_subpath_default ;0474
ld a,h ;0477
or b ;0478
ld h,a ;0479
ld (loaded_thing6),hl ;047a
jp interrupt_handler_2_jump_table_execute ;047d
sub_ym3514_21_25_26_do_stuff_1_with_globals_2:
ld b,080h ;0480
l0482h:
call sub_ym3514_21_25_26_do_stuff_1 ;0482
; Return if carry is set
ret c ;0485
ld a,(ym3514_addr+23h) ;0486
and 00fh ;0489
bit 7,b ;048b
jp z,l0499h ;048d
rlca ;0490
rlca ;0491
rlca ;0492
rlca ;0493
res 7,b ;0494
jp l04a8h ;0496
l0499h:
dec hl ;0499
push hl ;049a
pop de ;049b
ld ix,080dah ;049c
add ix,de ;04a0
ld d,(ix+000h) ;04a2
or d ;04a5
set 7,b ;04a6
l04a8h:
ex de,hl ;04a8
ld hl,080dah ;04a9
add hl,de ;04ac
ld (hl),a ;04ad
ex de,hl ;04ae
inc hl ;04af
ld a,(ym3514_addr+25h) ;04b0
and 00fh ;04b3
cp c ;04b5
jp z,l0482h ;04b6
ld (common_elsewhere1),hl ;04b9
dec hl ;04bc
or a ;04bd
ret ;04be
interrupt_handler_2_subpath_check_loaded_things:
; Loop while (ym3514+25) & 0xf == 0 ???
ld a,(ym3514_addr+25h) ;04bf
and 00fh ;04c2
; c is probably 0 here
cp c ;04c4
jp z,interrupt_handler_2_subpath_check_loaded_things ;04c5
; Load ym3514+25 to a and b; mask a with 0x90
ld a,(ym3514_addr+25h) ;04c8
ld b,a ;04cb
and 090h ;04cc
; Skip all if ym3514+25 & 0x90 != 0
jp nz,interrupt_handler_2_subpath_default ;04ce
; Skip all if ym3514+25 & 0x60 == 0
ld a,b ;04d1
and 060h ;04d2
ld b,a ;04d4
jp z,interrupt_handler_2_subpath_default ;04d5
; Skip some if ym3514+25 & 0x60 == 0x40
cp 040h ;04d8
jp z,l05a1h ;04da
; Load stuff:
; hl = (loaded_thing1)
; de = (loaded_thing2)
ld hl,loaded_thing1 ;04dd
ld a,001h ;04e0
call sub_load_to_de_or_bc ;04e2
push de ;04e5
ld hl,loaded_thing2 ;04e6
ld a,001h ;04e9
call sub_load_to_de_or_bc ;04eb
pop hl ;04ee
; If loaded_thing1 >= loaded_thing2, skip all
call sub_compare_hl_with_de ;04ef
cp 002h ;04f2
jp nz,interrupt_handler_2_subpath_default ;04f4
; Load stuff:
; hl = (loaded_thing7)
; de = (loaded_thing9)
ld hl,loaded_thing7 ;04f7
ld a,001h ;04fa
call sub_load_to_de_or_bc ;04fc
push de ;04ff
ld hl,loaded_thing9 ;0500
ld a,001h ;0503
call sub_load_to_de_or_bc ;0505
pop hl ;0508
; If loaded_thing7 >= loaded_thing9, skip all
call sub_compare_hl_with_de ;0509
cp 002h ;050c
jp nz,interrupt_handler_2_subpath_default ;050e
ld hl,loaded_thing7 ;0511
inc hl ;0514
inc hl ;0515
ld a,001h ;0516
call sub_load_to_de_or_bc ;0518
push de ;051b
ld hl,loaded_thing9 ;051c
inc hl ;051f
inc hl ;0520
ld a,001h ;0521
call sub_load_to_de_or_bc ;0523
pop hl ;0526
call sub_compare_hl_with_de ;0527
cp 002h ;052a
jp nz,interrupt_handler_2_subpath_default ;052c
ld hl,loaded_thing1 ;052f
ld a,001h ;0532
call sub_load_to_de_or_bc ;0534
push de ;0537
ld hl,loaded_thing7 ;0538
ld a,001h ;053b
call sub_load_to_de_or_bc ;053d
pop hl ;0540
call sub_compare_hl_with_de ;0541
cp 002h ;0544
jp nz,interrupt_handler_2_subpath_default ;0546
ld hl,loaded_thing7 ;0549
ld a,001h ;054c
call sub_load_to_de_or_bc ;054e
push de ;0551
ld hl,loaded_thing7 ;0552
inc hl ;0555
inc hl ;0556
ld a,001h ;0557
call sub_load_to_de_or_bc ;0559
pop hl ;055c
call sub_compare_hl_with_de ;055d
cp 002h ;0560
jp nz,interrupt_handler_2_subpath_default ;0562
ld hl,loaded_thing2 ;0565
ld a,001h ;0568
call sub_load_to_de_or_bc ;056a
push de ;056d
ld hl,loaded_thing9 ;056e
ld a,001h ;0571
call sub_load_to_de_or_bc ;0573
pop hl ;0576
call sub_compare_hl_with_de ;0577
cp 002h ;057a
jp nz,interrupt_handler_2_subpath_default ;057c
ld hl,loaded_thing9 ;057f
ld a,001h ;0582
call sub_load_to_de_or_bc ;0584
push de ;0587
ld hl,loaded_thing9 ;0588
inc hl ;058b
inc hl ;058c
ld a,001h ;058d
call sub_load_to_de_or_bc ;058f
pop hl ;0592
call sub_compare_hl_with_de ;0593
cp 002h ;0596
jp nz,interrupt_handler_2_subpath_default ;0598
ld a,b ;059b
cp 020h ;059c
jp z,l066ah ;059e
; if ... {
l05a1h:
ld hl,loaded_thing11 ;05a1
ld a,001h ;05a4
call sub_load_to_de_or_bc ;05a6
push de ;05a9
ld hl,loaded_thing12 ;05aa
ld a,001h ;05ad
call sub_load_to_de_or_bc ;05af
pop hl ;05b2
call sub_compare_hl_with_de ;05b3
cp 002h ;05b6
jp nz,interrupt_handler_2_subpath_default ;05b8
ld hl,loaded_thing3 ;05bb
ld a,001h ;05be
call sub_load_to_de_or_bc ;05c0
push de ;05c3
ld hl,loaded_thing5 ;05c4
ld a,001h ;05c7
call sub_load_to_de_or_bc ;05c9
res 7,d ;05cc
pop hl ;05ce
call sub_compare_hl_with_de ;05cf
cp 002h ;05d2
jp nz,interrupt_handler_2_subpath_default ;05d4
ld hl,loaded_thing3 ;05d7
inc hl ;05da
inc hl ;05db
ld a,001h ;05dc
call sub_load_to_de_or_bc ;05de
push de ;05e1
ld hl,loaded_thing5 ;05e2
inc hl ;05e5
inc hl ;05e6
ld a,001h ;05e7
call sub_load_to_de_or_bc ;05e9
res 7,d ;05ec
pop hl ;05ee
call sub_compare_hl_with_de ;05ef
cp 002h ;05f2
jp nz,interrupt_handler_2_subpath_default ;05f4
ld hl,loaded_thing11 ;05f7
ld a,001h ;05fa
call sub_load_to_de_or_bc ;05fc
push de ;05ff
ld hl,loaded_thing3 ;0600
ld a,001h ;0603
call sub_load_to_de_or_bc ;0605
pop hl ;0608
call sub_compare_hl_with_de ;0609
cp 002h ;060c
jp nz,interrupt_handler_2_subpath_default ;060e
ld hl,loaded_thing3 ;0611
ld a,001h ;0614
call sub_load_to_de_or_bc ;0616
push de ;0619
ld hl,loaded_thing3 ;061a
inc hl ;061d
inc hl ;061e
ld a,001h ;061f
call sub_load_to_de_or_bc ;0621
pop hl ;0624
call sub_compare_hl_with_de ;0625
cp 002h ;0628
jp nz,interrupt_handler_2_subpath_default ;062a
ld hl,loaded_thing12 ;062d
ld a,001h ;0630
call sub_load_to_de_or_bc ;0632
push de ;0635
ld hl,loaded_thing5 ;0636
ld a,001h ;0639
call sub_load_to_de_or_bc ;063b
res 7,d ;063e
pop hl ;0640
call sub_compare_hl_with_de ;0641
cp 002h ;0644
jp nz,interrupt_handler_2_subpath_default ;0646
ld hl,loaded_thing5 ;0649
ld a,001h ;064c
call sub_load_to_de_or_bc ;064e
res 7,d ;0651
push de ;0653
ld hl,loaded_thing5 ;0654
inc hl ;0657
inc hl ;0658
ld a,001h ;0659
call sub_load_to_de_or_bc ;065b
res 7,d ;065e
pop hl ;0660
call sub_compare_hl_with_de ;0661
cp 002h ;0664
jp nz,interrupt_handler_2_subpath_default ;0666
ld a,b ;0669
; }
l066ah:
cp 060h ;066a
jp nz,l06ech ;066c
ld hl,loaded_thing1 ;066f
ld a,001h ;0672
call sub_load_to_de_or_bc ;0674
push de ;0677
ld hl,loaded_thing11 ;0678
ld a,001h ;067b
call sub_load_to_de_or_bc ;067d
pop hl ;0680
call sub_compare_hl_with_de ;0681
cp 001h ;0684
jp z,interrupt_handler_2_subpath_default ;0686
ld hl,loaded_thing7 ;0689
inc hl ;068c
inc hl ;068d
ld a,001h ;068e
call sub_load_to_de_or_bc ;0690
push de ;0693
ld hl,loaded_thing3 ;0694
inc hl ;0697
inc hl ;0698
ld a,001h ;0699
call sub_load_to_de_or_bc ;069b
pop hl ;069e
call sub_compare_hl_with_de ;069f
cp 001h ;06a2
jp z,interrupt_handler_2_subpath_default ;06a4
ld hl,loaded_thing7 ;06a7
inc hl ;06aa
inc hl ;06ab
ld a,001h ;06ac
call sub_load_to_de_or_bc ;06ae
push de ;06b1
ld hl,loaded_thing11 ;06b2
ld a,001h ;06b5
call sub_load_to_de_or_bc ;06b7
pop hl ;06ba
call sub_compare_hl_with_de ;06bb
cp 001h ;06be
jp z,interrupt_handler_2_subpath_default ;06c0
ld hl,loaded_thing1 ;06c3
ld a,001h ;06c6
call sub_load_to_de_or_bc ;06c8
push de ;06cb
ld hl,loaded_thing3 ;06cc
inc hl ;06cf
inc hl ;06d0
ld a,001h ;06d1
call sub_load_to_de_or_bc ;06d3
pop hl ;06d6
call sub_compare_hl_with_de ;06d7
cp 001h ;06da
jp z,interrupt_handler_2_subpath_default ;06dc
ld hl,flags1 ;06df
res 5,(hl) ;06e2
ld a,080h ;06e4
ld (flags2),a ;06e6
jp l06fdh ;06e9
l06ech:
ld hl,flags1 ;06ec
set 5,(hl) ;06ef
jp l06f9h ;06f1
; Skipped to here if ym3514+25 & 0x90 != 0
; Skipped to here if ym3514+25 & 0x60 != 0
interrupt_handler_2_subpath_default:
ld hl,flags1 ;06f4
res 5,(hl) ;06f7
l06f9h:
xor a ;06f9
ld (flags2),a ;06fa
l06fdh:
ld a,(key_result_flags1) ;06fd
and 0c0h ;0700
ld (key_result_flags1),a ;0702
ld a,00fh ;0705
ld (08043h),a ;0707
; flags1 &= 0x28
; flags1 |= YM2142_DIRTY
ld a,(flags1) ;070a
and 028h ;070d
set 6,a ;070f
ld (flags1),a ;0711
; Initialize ym2142 notes to zero = not playing
; Send to ym2142: 84h 00h 85h 00h 86h 00h 87h 00h
ld b,004h ;0714
ld c,084h ;0716
ym2142_init_loop_1:
ld a,c ;0718
ld (ym2142_addr),a ;0719
call sub_delay_roughly_20_cycles ;071c
xor a ;071f
ld (ym2142_addr),a ;0720
call sub_delay_roughly_20_cycles ;0723
inc c ;0726
djnz ym2142_init_loop_1 ;0727
; Zero out four bytes, incrementing hl
ld b,004h ;0729
ld hl,common_array1 ;072b
xor a ;072e
l072fh:
ld (hl),a ;072f
inc hl ;0730
djnz l072fh ;0731
; Zero out some variables
ld (080cfh),a ;0733
ld (080d7h),a ;0736
ld (080d0h),a ;0739
ld (080d8h),a ;073c
ld (080d9h),a ;073f
; Reset stack pointer ??? why would we do this
ld sp,stack_start_addr ;0742a
; Reset bit 2 in I
ld a,i ;0745
res 2,a ;0747
ld i,a ;0749
jp entry_point_jump2 ;074b
sub_delay_variable_time_1:
pop hl ;074e
ex (sp),hl ;074f
l0750h:
ld a,h ;0750
or l ;0751
jp z,l075ch ;0752
call sub_delay_roughly_200_cycles ;0755
dec hl ;0758
jp l0750h ;0759
l075ch:
ret ;075c
sub_delay_roughly_200_cycles:
push bc ;075d
ld b,0c5h ;075e
l0760h:
nop ;0760
nop ;0761
nop ;0762
djnz l0760h ;0763
pop bc ;0765
ret ;0766
sub_delay_roughly_5_cycles:
push bc ;0767
ld b,001h ;0768
l076ah:
djnz l076ah ;076a
pop bc ;076c
ret ;076d
sub_delay_roughly_10_cycles:
push bc ;076e
ld b,007h ;076f
l0771h:
djnz l0771h ;0771
pop bc ;0773
ret ;0774
sub_delay_roughly_20_cycles:
push bc ;0775
ld b,00dh ;0776
l0778h:
djnz l0778h ;0778
pop bc ;077a
ret ;077b
; Parameters:
; st+1: first byte
; st+0: second byte
sub_ym2142_write_2B:
; Pop return address
pop hl ;077c
; Pop second pushed parameter
pop de ;077d
; Get first pushed parameter
ex (sp),hl ;077e
; Write to ym2142
ld a,l ;077f
ld (ym2142_addr),a ;0780
call sub_delay_roughly_5_cycles ;0783
ld a,e ;0786
and 07fh ;0787
ld (ym2142_addr),a ;0789
ret ;078c
; Parameters:
; st+0: offset1
sub_078dh_maybe_write_many_to_ym2142:
pop hl ;078d
ex (sp),hl ;078e
ld de,common_c1 ;078f
add hl,de ;0792
; Now hl = common_c1 + offset1
ld l,(hl) ;0793
ld h,000h ;0794
ex de,hl ;0796
; Now e = (common_c1 + offset1) = index1
ld hl,common_array1 ;0797
add hl,de ;079a
; Now hl = common_array1 + index1
ld a,(hl) ;079b
bit 0,a ;079c
; Skip if (common_array1 + index1) bit 0 is zero
jp z,l07b2h ;079e
push de ;07a1
push hl ;07a2
ld hl,84h ;07a3
add hl,de ;07a6
; Now hl = 84h + index1
push hl ;07a7
ld hl,0 ;07a8
push hl ;07ab
; st+1 = 84h + index1
; st+0 = 0
call sub_ym2142_write_2B ;07ac
pop hl ;07af
pop de ;07b0
ld a,(hl) ;07b1
l07b2h:
bit 1,a ;07b2
; Skip if (common_array1 + index1) bit 1 is zero
jp z,l07cfh ;07b4
push de ;07b7
push hl ;07b8
ld hl,84h ;07b9
add hl,de ;07bc
; Now hl = 84h + index1
push hl ;07bd
ld hl,common_c2 ;07be
add hl,de ;07c1
; Now hl = common_c2 + index1
ld a,(hl) ;07c2
and 03fh ;07c3
ld h,000h ;07c5
ld l,a ;07c7
; Now hl = (common_c2 + index1) & 0x3f
push hl ;07c8
; st+1 = 84h + index1
; st+0 = (common_c2 + index1) & 0x3f
call sub_ym2142_write_2B ;07c9
pop hl ;07cc
pop de ;07cd
ld a,(hl) ;07ce
l07cfh:
bit 2,a ;07cf
; Skip if (common_array1 + index1) bit 2 is zero
jp z,l07e9h ;07d1
push de ;07d4
push hl ;07d5
ld hl,00088h ;07d6
add hl,de ;07d9
; Now hl = 88h + index1
push hl ;07da
ld hl,common_c4 ;07db
add hl,de ;07de
ld l,(hl) ;07df
ld h,000h ;07e0
; Now hl = (common_c4 + index1)
push hl ;07e2
; st+1 = 88h + index1
; st+0 = (common_c4 + index1)
call sub_ym2142_write_2B ;07e3
pop hl ;07e6
pop de ;07e7
ld a,(hl) ;07e8
l07e9h:
bit 3,a ;07e9
; Skip if (common_array1 + index1) bit 3 is zero
jp z,l0803h ;07eb
push de ;07ee
push hl ;07ef
ld hl,0008ch ;07f0
add hl,de ;07f3
; Now hl = 8ch + index1
push hl ;07f4
ld hl,common_c3 ;07f5
add hl,de ;07f8
ld l,(hl) ;07f9
ld h,000h ;07fa
; Now hl = (common_c3 + index1)
push hl ;07fc
; st+1 = 8ch + index1
; st+0 = (common_c3 + index1)
call sub_ym2142_write_2B ;07fd
l0800h:
pop hl ;0800
l0801h:
pop de ;0801
ld a,(hl) ;0802
l0803h:
bit 4,a ;0803
l0805h:
jp z,l081dh ;0805
push hl ;0808
ld hl,84h ;0809
add hl,de ;080c
; Now hl = 84h + index1
push hl ;080d
ld hl,common_c5 ;080e
add hl,de ;0811
ld a,(hl) ;0812
or 040h ;0813
ld h,000h ;0815
ld l,a ;0817
; Now hl = (common_c5 + index) | 0x40
push hl ;0818
; st+1 = 84h + index1
; st+0 = (common_c5 + index) | 0x40
; Is called when C has been pressed and something should start happening (close to end)
call sub_ym2142_write_2B ;0819
pop hl ;081c
l081dh:
ld (hl),000h ;081d
ret ;081f
; Arguments:
; sp+0: Address to read from (src_addr)
; sp+1: Address of key_states (&key_states)
; NOTE: sp+1 is not popped; instead it is replaced by the value of sp+0
; ???
sub_0820h_load_12_things_return_quickly_if_YM2142_DIRTY:
; Pop sp+0 into hl.
pop hl ;0820
; sp+0 = &key_states
; hl = src_addr
; Exchange between sp+0 and hl.
ex (sp),hl a ;0821
; sp+0 = src_addr
; hl = &key_states
; Now proceed to read 16 bytes starting from &key_states
call sub_load_ed_from_hl_incr_check_YM2142_DIRTY ;0822
jp nz,l08e6h ;0825
ld (loaded_thing1),de ;0828
call sub_load_ed_from_hl_incr_check_YM2142_DIRTY ;082c
jp nz,l08e6h ;082f
ld (loaded_thing2),de ;0832
call sub_load_ed_from_hl_incr_check_YM2142_DIRTY ;0836
jp nz,l08e6h ;0839
ld (loaded_thing3),de ;083c
call sub_load_ed_from_hl_incr_check_YM2142_DIRTY ;0840
jp nz,l08e6h ;0843
ld (loaded_thing4),de ;0846
call sub_load_ed_from_hl_incr_check_YM2142_DIRTY ;084a
jp nz,l08e6h ;084d
ld (loaded_thing5),de ;0850
call sub_load_ed_from_hl_incr_check_YM2142_DIRTY ;0854
jp nz,l08e6h ;0857
ld (loaded_thing6),de ;085a
call sub_load_ed_from_hl_incr_check_YM2142_DIRTY ;085e
jp nz,l08e6h ;0861
ld (loaded_thing7),de ;0864
call sub_load_ed_from_hl_incr_check_YM2142_DIRTY ;0868
jp nz,l08e6h ;086b
ld (loaded_thing8),de ;086e
call sub_load_ed_from_hl_incr_check_YM2142_DIRTY ;0872
jp nz,l08e6h ;0875
ld (loaded_thing9),de ;0878
call sub_load_ed_from_hl_incr_check_YM2142_DIRTY ;087c
jp nz,l08e6h ;087f
ld (loaded_thing10),de ;0882
call sub_load_ed_from_hl_incr_check_YM2142_DIRTY ;0886
jp nz,l08e6h ;0889
ld (loaded_thing11),de ;088c
call sub_load_ed_from_hl_incr_check_YM2142_DIRTY ;0890
jp nz,l08e6h ;0893
ld (loaded_thing12),de ;0896
ld bc,00001h+2 ;089a
ld de,0802dh ;089d
l08a0h:
; If flags1 & YM2142_DIRTY, return
ld a,(flags1) ;08a0
bit 6,a ;08a3
jp nz,l08e6h ;08a5
ldi ;08a8a
; If overflow is set, loop (???)
jp pe,l08a0h ;08aa
ld c,(hl) ;08ad
inc hl ;08ae
ld b,(hl) ;08af
inc hl ;08b0
ld de,080dah ;08b1
l08b4h:
; If flags1 & YM2142_DIRTY, return
ld a,(flags1) ;08b4
bit 6,a ;08b7
jp nz,l08e6h ;08b9
ldi ;08bc
; If overflow is set, loop (???)
jp pe,l08b4h ;08be
call sub_1b00h_calc ;08c1
call sub_2846h ;08c4
ld de,6+2 ;08c7
ld hl,key_states ;08ca
add hl,de ;08cd
ld (hl),001h ;08ce
ld hl,key_diffs ;08d0
add hl,de ;08d3
ld (hl),001h ;08d4
ld hl,flags2 ;08d6
res 5,(hl) ;08d9
res 7,(hl) ;08db
set 6,(hl) ;08dd
ld hl,flags1 ;08df
res 5,(hl) ;08e2
set 7,(hl) ;08e4
l08e6h:
ret ;08e6
; Loads (hl++), (hl++) into de and checks YM2142_DIRTY
sub_load_ed_from_hl_incr_check_YM2142_DIRTY:
ld e,(hl) ;08e7
inc hl ;08e8
ld d,(hl) ;08e9
inc hl ;08ea
ld a,(flags1) ;08eb
bit 6,a ;08ee
ret ;08f0
l08f1h:
nop ;08f1 DATA?
nop ;08f2 DATA?
nop ;08f3 DATA?
ld bc,l0101h ;08f4 DATA?
ld (bc),a ;08f7 DATA?
ld (bc),a ;08f8 DATA?
ld (bc),a ;08f9 DATA?
inc bc ;08fa DATA?
inc bc ;08fb DATA?
inc bc ;08fc DATA?
inc b ;08fd DATA?
inc b ;08fe DATA?
inc b ;08ff DATA?
dec b ;0900 DATA?
dec b ;0901 DATA?
dec b ;0902 DATA?
ld b,006h ;0903 DATA?
ld b,007h ;0905 DATA?
rlca ;0907 DATA?
rlca ;0908 DATA?
ex af,af' ;0909 DATA?
ex af,af' ;090a DATA?
ex af,af' ;090b DATA?
add hl,bc ;090c DATA?
add hl,bc ;090d DATA?
add hl,bc ;090e DATA?
ld a,(bc) ;090f DATA?
ld a,(bc) ;0910 DATA?
ld a,(bc) ;0911 DATA?
dec bc ;0912 DATA?
dec bc ;0913 DATA?
dec bc ;0914 DATA?
inc c ;0915 DATA?
inc c ;0916 DATA?
inc c ;0917 DATA?
dec c ;0918 DATA?
dec c ;0919 DATA?
dec c ;091a DATA?
ld c,00eh ;091b DATA?
ld c,00fh ;091d DATA?
rrca ;091f DATA?
rrca ;0920 DATA?
l0921h:
nop ;0921 DATA?
nop ;0922 DATA?
nop ;0923 DATA?
nop ;0924 DATA?
ld bc,l0101h ;0925 DATA?
ld bc,l0200h+2 ;0928 DATA?
ld (bc),a ;092b DATA?
ld (bc),a ;092c DATA?
inc bc ;092d DATA?
inc bc ;092e DATA?
inc bc ;092f DATA?
inc bc ;0930 DATA?
inc b ;0931 DATA?
inc b ;0932 DATA?
inc b ;0933 DATA?
inc b ;0934 DATA?
dec b ;0935 DATA?
dec b ;0936 DATA?
dec b ;0937 DATA?
dec b ;0938 DATA?
ld b,006h ;0939 DATA?
ld b,006h ;093b DATA?
rlca ;093d DATA?
rlca ;093e DATA?
rlca ;093f DATA?
rlca ;0940 DATA?
ex af,af' ;0941 DATA?
ex af,af' ;0942 DATA?
ex af,af' ;0943 DATA?
ex af,af' ;0944 DATA?
add hl,bc ;0945 DATA?
add hl,bc ;0946 DATA?
add hl,bc ;0947 DATA?
add hl,bc ;0948 DATA?
ld a,(bc) ;0949 DATA?
ld a,(bc) ;094a DATA?
ld a,(bc) ;094b DATA?
ld a,(bc) ;094c DATA?
dec bc ;094d DATA?
dec bc ;094e DATA?
dec bc ;094f DATA?
dec bc ;0950 DATA?
entry_point:
xor a ;0951
ld (ym3514_addr+27h),a ;0952
call sub_delay_roughly_10_cycles ;0955
ld a,01eh ;0958
ld (ym3514_addr+02h),a ;095a
call sub_delay_roughly_10_cycles ;095d
ld (ym3514_addr+03h),a ;0960
call sub_delay_roughly_10_cycles ;0963
ld a,001h ;0966
ld (ym3514_addr+01h),a ;0968
call sub_delay_roughly_10_cycles ;096b
ld a,(ym3514_addr+01h) ;096e
cpl ;0971
and 00fh ;0972
cp 00fh ;0974
jp nz,entry_point_jump_1_last ;0976
xor a ;0979
ld (ym3514_addr+01h),a ;097a
ld hl,key_states ;097d
l0980h:
ld a,h ;0980
and 00fh ;0981
ld (ym3514_addr+02h),a ;0983
xor a ;0986
l0987h:
ld (hl),a ;0987
cp (hl) ;0988
jp nz,l0a98h ;0989
inc a ;098c
jp nz,l0987h ;098d
ld (hl),a ;0990
inc hl ;0991
ld a,h ;0992
cp 088h ;0993
jp nz,l0980h ;0995
ld sp,stack_start_addr ;0998
and 00fh ;099b
ld (ym3514_addr+02h),a ;099d
call sub_delay_roughly_10_cycles ;09a0
ld a,080h ;09a3
call sub_0a7eh ;09a5
ld a,009h ;09a8
ld (ym3514_addr+02h),a ;09aa
call sub_delay_roughly_10_cycles ;09ad
ld a,040h ;09b0
call sub_0a7eh ;09b2
ld a,00ah ;09b5
ld (ym3514_addr+02h),a ;09b7
call sub_delay_roughly_10_cycles ;09ba
ld a,080h ;09bd
ld (ym3514_addr+00h),a ;09bf
call sub_delay_roughly_10_cycles ;09c2
ld a,(ym3514_addr+01h) ;09c5
cpl ;09c8
bit 6,a ;09c9
jp nz,l0a98h ;09cb
ld a,00bh ;09ce
ld (ym3514_addr+02h),a ;09d0
call sub_delay_roughly_10_cycles ;09d3
ld a,040h ;09d6
ld (ym3514_addr+00h),a ;09d8
call sub_delay_roughly_10_cycles ;09db
ld a,(ym3514_addr+01h) ;09de
cpl ;09e1
bit 6,a ;09e2
jp nz,l0a98h ;09e4
ld b,00ch ;09e7
ld c,001h ;09e9
l09ebh:
ld a,b ;09eb
ld (ym3514_addr+02h),a ;09ec
call sub_delay_roughly_10_cycles ;09ef
ld a,c ;09f2
ld (ym3514_addr+00h),a ;09f3
call sub_delay_roughly_10_cycles ;09f6
ld a,(ym3514_addr+01h) ;09f9
cpl ;09fc
and 03fh ;09fd
jp z,l0a11h ;09ff
ld d,0ffh ;0a02
l0a04h:
inc d ;0a04
srl a ;0a05
jp nc,l0a04h ;0a07
ld a,d ;0a0a
ld (ym3514_addr+03h),a ;0a0b
jp l0a98h ;0a0e
l0a11h:
inc b ;0a11
sla c ;0a12
ld a,c ;0a14
cp 020h ;0a15
jp nz,l09ebh ;0a17
ld a,b ;0a1a
ld (ym3514_addr+02h),a ;0a1b
call sub_delay_roughly_10_cycles ;0a1e
ld a,c ;0a21
ld (ym3514_addr+00h),a ;0a22
call sub_delay_roughly_10_cycles ;0a25
ld a,(ym3514_addr+01h) ;0a28
cpl ;0a2b
and 003h ;0a2c
jp z,l0a40h ;0a2e
ld d,0ffh ;0a31
l0a33h:
inc d ;0a33
srl a ;0a34
jp nc,l0a33h ;0a36
ld a,d ;0a39
ld (ym3514_addr+03h),a ;0a3a
jp l0a98h ;0a3d
l0a40h:
xor a ;0a40
ld (ym3514_addr+00h),a ;0a41
call sub_delay_roughly_20_cycles ;0a44
ld a,012h ;0a47
ld (ym3514_addr+02h),a ;0a49
call sub_delay_roughly_10_cycles ;0a4c
ld a,001h ;0a4f
ld (ym3514_addr+01h),a ;0a51
call sub_delay_roughly_10_cycles ;0a54
ld a,(ym3514_addr+01h) ;0a57
cpl ;0a5a
and 00fh ;0a5b
jp z,l0a6fh ;0a5d
ld d,0ffh ;0a60
l0a62h:
inc d ;0a62
srl a ;0a63
jp nc,l0a62h ;0a65
ld a,d ;0a68
ld (ym3514_addr+03h),a ;0a69
jp l0a98h ;0a6c
l0a6fh:
xor a ;0a6f
ld (ym3514_addr+01h),a ;0a70
call sub_delay_roughly_10_cycles ;0a73
ld a,01eh ;0a76
ld (ym3514_addr+02h),a ;0a78
jp entry_point_jump_1_last ;0a7b
sub_0a7eh:
ld (ym3514_addr+00h),a ;0a7e
call sub_delay_roughly_10_cycles ;0a81
ld a,(ym3514_addr+01h) ;0a84
cpl ;0a87
and 03fh ;0a88
jp z,l0a98h ;0a8a
or a ;0a8d
l0a8eh:
srl a ;0a8e
jp nc,l0a8eh ;0a90
or a ;0a93
jp nz,l0a98h ;0a94
ret ;0a97
l0a98h:
jp l0a98h ;0a98
sub_clear_common_a123:
xor a ;0a9b
ld (common_a1),a ;0a9c
ld (common_a2),a ;0a9f
ld (common_a3),a ;0aa2
ret ;0aa5
sub_0aa6h:
ld a,(0803eh) ;0aa6
cp 002h ;0aa9
jp nz,l0ab4h ;0aab
ld hl,000fh ;0aae
jp l0ab7h ;0ab1
l0ab4h:
ld hl,0000bh ;0ab4
l0ab7h:
ex (sp),hl ;0ab7
jp (hl) ;0ab8
sub_0ab9h:
call sub_0aa6h ;0ab9
pop hl ;0abc
ld a,(common_a3) ;0abd
and 00fh ;0ac0
cp l ;0ac2
jp nz,l0adah ;0ac3
ld a,(common_a3) ;0ac6
bit 7,a ;0ac9
jp z,l0ad4h ;0acb
ld hl,0 ;0ace
jp l0ae1h ;0ad1
l0ad4h:
ld hl,l0080h ;0ad4
jp l0ae1h ;0ad7
l0adah:
ld hl,common_a3 ;0ada
ld l,(hl) ;0add
ld h,000h ;0ade
inc hl ;0ae0
l0ae1h:
ex (sp),hl ;0ae1
jp (hl) ;0ae2
; Reads key input from ym3514 to key_states+de
sub_ym3514_read_key_byte:
call sub_delay_roughly_10_cycles ;0ae3
; Read ym3514+1
ld a,(ym3514_addr+01h) ;0ae6
; Invert and mask the result
cpl ;0ae9
and 07fh ;0aea
ld c,a ;0aec
; Read old value from key_states+de
ld hl,key_states ;0aed
add hl,de ;0af0
ld b,(hl) ;0af1
ld a,b ;0af2
; Check difference with new value
xor c ;0af3
ld b,a ;0af4
; Save new value to key_states+de
ld (hl),c ;0af5
; Save difference to key_diffs+de
ld hl,key_diffs ;0af6
add hl,de ;0af9
ld (hl),b ;0afa
ret ;0afb
sub_ym3514_read_keys:
ld a,(key_state1) ;0afc
or a ;0aff
l0b00h:
jp nz,l0b33h ;0b00
; if key_state1 != 0 {
ld b,001h ;0b03
ld de,0 ;0b05
l0b08h:
; Write 01h to ym3514+0
ld a,b ;0b08
ld (ym3514_addr+00h),a ;0b09
; Read result (key_states[de], key_diffs[de])
push bc ;0b0c
call sub_ym3514_read_key_byte ;0b0d
pop bc ;0b10
; Increment to next step: b <<= 1; de++
sla b ;0b11
inc de ;0b13
; Loop until e == 8
ld a,e ;0b14
cp 008h ;0b15
jp nz,l0b08h ;0b17
; Write 00h to ym3514+0
xor a ;0b1a
ld (ym3514_addr+00h),a ;0b1b
call sub_delay_roughly_10_cycles ;0b1e
; Ask and read key_*[8]
ld de,6+2 ;0b21
ld a,001h ;0b24
ld (ym3514_addr+01h),a ;0b26
call sub_ym3514_read_key_byte ;0b29
; Write 00h to ym3514+1
xor a ;0b2c
ld (ym3514_addr+01h),a ;0b2d
; Return
jp l0b50h ;0b30
; }
l0b33h:
; Reset key_diffs[6:7] bit 6
ld hl,key_diffs ;0b33
ld de,6 ;0b36
add hl,de ;0b39
res 6,(hl) ;0b3a
inc hl ;0b3c
res 6,(hl) ;0b3d
; key_diffs[8] &= 0xf0;
inc hl ;0b3f
ld a,(hl) ;0b40
and 0f0h ;0b41
ld (hl),a ;0b43
; key_state1++
ld hl,key_state1 ;0b44
inc (hl) ;0b47
; Compare key_state with 1
ld a,001h ;0b48
cp (hl) ;0b4a
jp nc,l0b50h ;0b4b
; if key_state1 <= 1 {
ld (hl),000h ;0b4e
; }
l0b50h:
ret ;0b50
sub_0b51h_process_maybe_keys_wrap2:
; key_result_flags1 &= 0xcfh
ld hl,key_result_flags1 ;0b51
ld a,(hl) ;0b54
and 0cfh ;0b55
ld (hl),a ;0b57
; If bit 4 of flags2 is zero,
; reset bit 7 of flags1 and return
ld hl,flags2 ;0b58
bit 4,(hl) ;0b5b
jp nz,l0b68h ;0b5d
ld hl,flags1 ;0b60
res 7,(hl) ;0b63
jp l0b72h ;0b65
l0b68h:
; Reset bit 4 of flags2
res 4,(hl) ;0b68
; If bit 5 of flags2 is non-zero,
; call sub_19a4h_process_maybe_keys_wrap1
bit 5,(hl) ;0b6a
jp z,l0b72h ;0b6c
call sub_19a4h_process_maybe_keys_wrap1 ;0b6f
l0b72h:
ret ;0b72
sub_0b73h_main_calc_and_write_ym3514_03:
; Is called when C has been pressed and something should start happening
call sub_0fdfh_handle_special_keys_maybe ;0b73
call sub_1374h_ym3514_calc_more_and_write_03_2 ;0b76
ld a,(flags1) ;0b79
and 007h ;0b7c
jp nz,l0b84h ;0b7e
; Is called when C has been pressed and something should start happening
call sub_151ch_adjust_key_result_flags1_based_on_keys ;0b81
l0b84h:
call sub_1a34h_handle_special_keys_maybe ;0b84
ret ;0b87
; Is NOT called when C has been pressed and something should start happening
sub_0b88h_long_calc_global_1:
ld bc,0 ;0b88
ld a,(common_b1) ;0b8b
or a ;0b8e
jp z,l0bbeh ;0b8f
l0b92h:
ld a,(common_b1) ;0b92
ld b,a ;0b95
ld a,c ;0b96
cp b ;0b97
jp nc,l0bbeh ;0b98
ld b,000h ;0b9b
ld hl,common_c1 ;0b9d
add hl,bc ;0ba0
ld d,000h ;0ba1
ld e,(hl) ;0ba3
ld hl,kpr_08018h ;0ba4
add hl,de ;0ba7
ld a,(hl) ;0ba8
cp 020h ;0ba9
jp nc,l0bbah ;0bab
push bc ;0bae
ld l,(hl) ;0baf
ld h,000h ;0bb0
push hl ;0bb2
call sub_107eh_calc_a_lot ;0bb3
pop bc ;0bb6
jp l0b92h ;0bb7
l0bbah:
inc bc ;0bba
jp l0b92h ;0bbb
l0bbeh:
ld a,(key_result_flags1) ;0bbe
bit 1,a ;0bc1
jp z,l0bd3h ;0bc3
ld a,002h ;0bc6
ld (common_b2),a ;0bc8
ld a,020h ;0bcb
ld (num_keys_ignore),a ;0bcd
jp l0bf9h ;0bd0
l0bd3h:
ld a,(flags1) ;0bd3
bit 0,a ;0bd6
jp z,l0be2h ;0bd8
xor a ;0bdb
ld (common_b2),a ;0bdc
jp l0bf4h ;0bdf
l0be2h:
and 006h ;0be2
jp z,l0befh ;0be4
ld a,001h ;0be7
ld (common_b2),a ;0be9
jp l0bf4h ;0bec
l0befh:
ld a,004h ;0bef
ld (common_b2),a ;0bf1
l0bf4h:
ld a,012h ;0bf4
ld (num_keys_ignore),a ;0bf6
l0bf9h:
ld de,0 ;0bf9
l0bfch:
ld hl,common_array1 ;0bfc
add hl,de ;0bff
l0c00h:
xor a ;0c00
ld (hl),a ;0c01
set 0,(hl) ;0c02
inc de ;0c04
ld a,e ;0c05
cp 004h ;0c06
jp nz,l0bfch ;0c08
ld a,(flags1) ;0c0b
and 007h ;0c0e
jp nz,l0c25h ;0c10
ld de,0 ;0c13
l0c16h:
ld hl,key_states ;0c16
add hl,de ;0c19
ld a,(hl) ;0c1a
and 0c0h ;0c1b
ld (hl),a ;0c1d
inc de ;0c1e
ld a,e ;0c1f
cp 006h ;0c20
jp nz,l0c16h ;0c22
l0c25h:
ld a,(common_b1) ;0c25
ld b,a ;0c28
ld a,(common_b2) ;0c29
cp b ;0c2c
jp nc,l0c36h ;0c2d
ld a,(common_b2) ;0c30
ld (common_b1),a ;0c33
l0c36h:
ld a,(common_b1) ;0c36
ld d,000h ;0c39
ld e,a ;0c3b
l0c3ch:
ld hl,common_c1 ;0c3c
add hl,de ;0c3f
ld b,000h ;0c40
ld c,(hl) ;0c42
xor a ;0c43
ld hl,kpr_08018h ;0c44
add hl,bc ;0c47
ld (hl),a ;0c48
ld hl,common_c5 ;0c49
add hl,bc ;0c4c
ld (hl),a ;0c4d
ld hl,common_c2 ;0c4e
add hl,bc ;0c51
ld (hl),a ;0c52
inc de ;0c53
ld a,e ;0c54
cp 004h ;0c55
jp nz,l0c3ch ;0c57
call sub_0fc5h_calc_with_b1c1_array1_and_b2 ;0c5a
ld a,00fh ;0c5d
ld (08043h),a ;0c5f
ld (08045h),a ;0c62
ret ;0c65
sub_0c66h_ym3514:
ld hl,key_result_flags1 ;0c66
bit 0,(hl) ;0c69
jp nz,l0c9ch ;0c6b
ld a,(flags1) ;0c6e
and 007h ;0c71
jp nz,l0c9ch ;0c73
ld a,(ym3514_addr+01h) ;0c76
bit 7,a ;0c79
jp z,l0c9ch ;0c7b
ld a,(08013h) ;0c7e
or a ;0c81
jp nz,l0c9ch ;0c82
ld a,(ym3514_thing1) ;0c85
ld b,a ;0c88
ld a,01dh ;0c89
cp b ;0c8b
jp nc,l0c94h ;0c8c
ld a,01dh ;0c8f
jp l0c96h ;0c91
l0c94h:
ld a,01eh ;0c94
l0c96h:
ld (ym3514_thing1),a ;0c96
ld (ym3514_addr+03h),a ;0c99
l0c9ch:
ld hl,08013h ;0c9c
inc (hl) ;0c9f
ld a,064h ;0ca0
cp (hl) ;0ca2
jp nc,l0ca8h ;0ca3
ld (hl),000h ;0ca6
l0ca8h:
ret ;0ca8
entry_point_jump_1_last:
call sub_ym3514_write_and_calc_2 ;0ca9
ei ;0cac
entry_point_jump2:
call sub_ym3514_read_keys ;0cad
call sub_0b51h_process_maybe_keys_wrap2 ;0cb0
ld a,(flags1) ;0cb3
bit 6,a ;0cb6
jp z,l0cbeh ;0cb8
; Called if flags1 & YM2142_DIRTY
; Is NOT called when C has been pressed and something should start happening
call sub_ym2142_output_fours_of_things_1 ;0cbb
l0cbeh:
; Is called when C has been pressed and something should start happening
call sub_0b73h_main_calc_and_write_ym3514_03 ;0cbe
ld a,(key_result_flags1) ;0cc1
bit 5,a ;0cc4
jp z,l0ccch ;0cc6
; Is NOT called when C has been pressed and something should start happening
call sub_0b88h_long_calc_global_1 ;0cc9
l0ccch:
; Is called when C has been pressed and something should start happening
call sub_1027h_loop_key_states_diffs ;0ccc
ld a,(flags3) ;0ccf
bit 4,a ;0cd2
jp z,l0cdah ;0cd4
; Is called when C has been pressed and something should start happening
call sub_123eh_loop_key_states_diffs_twice_if_common_b2_nonzero ;0cd7
l0cdah:
ld hl,flags1 ;0cda
ld a,(hl) ;0cdd
and 007h ;0cde
jp z,l0cf7h ;0ce0
bit 7,(hl) ;0ce3
jp z,l0ceeh ;0ce5
; Could be one song mode
; Is NOT called when C has been pressed and something should start happening
call sub_am3514_write_and_calc_3 ;0ce8
jp l0cf1h ;0ceb
l0ceeh:
; Could be another song mode
; Is NOT called when C has been pressed and something should start happening
call sub_ym3514_do_like_absolutely_everything_1 ;0cee
l0cf1h:
; Called after both of the former calls
; Is NOT called when C has been pressed and something should start happening
call sub_177fh_common_highlevel_calc ;0cf1
jp l0d05h ;0cf4
l0cf7h:
ld a,(key_result_flags1) ;0cf7
bit 1,a ;0cfa
jp z,l0d05h ;0cfc
; if key_result_flags1 & (1<<1) {
call sub_1588h_calc_a_lot ;0cff
call sub_177fh_common_highlevel_calc ;0d02
; }
l0d05h:
ld a,(key_result_flags1) ;0d05
l0d08h:
bit 0,a ;0d08
jp z,l0d10h ;0d0a
; if key_result_flags1 & (1<<0) {
call sub_ym2142_do_lots_of_stuff ;0d0d
; }
l0d10h:
; Is called when C has been pressed and something should start happening
call sub_124ch_calc_and_maybe_write_many_to_ym2412 ;0d10
call sub_0c66h_ym3514 ;0d13
jp entry_point_jump2 ;0d16
; Result: hl + b * 2 + (c == 1 ? 1 : 0)
; Arguments:
; reg hl: Base value
; reg b: Multiplier
; reg c: Choice of addition
; reg a:
; If a==1, result is put into hl
; If a==2, result is put into de
; If a==3, result is put into bc
; Else, result is put into af
sub_add_2c_b_to_hl_put_result_in_hl_de_bc_af:
push hl ;0d19
push bc ;0d1a
push af ;0d1b
ld a,b ;0d1c
ld b,c ;0d1d
ld c,a ;0d1e
ld a,001h ;0d1f
; Now b = arg_c
; Now a = 1 -> result goes to hl
; Now c = arg_b -> result is hl + arg_b * 2
call sub_add_2c_to_hl_put_result_in_hl_de_bc_af ;0d21
; If arg_c == 1, hl++
dec b ;0d24
jp nz,l0d29h ;0d25
inc hl ;0d28
l0d29h:
pop af ;0d29
pop bc ;0d2a
; Put the value of hl on stack
; (in place of hl which was pushed previously)
; (hl is invalid after this and is not used)
ex (sp),hl ;0d2b
; Select result location based on a
dec a ;0d2c
jp z,l0d3ch ;0d2d
dec a ;0d30
jp z,l0d40h ;0d31
dec a ;0d34
jp z,l0d44h ;0d35
pop af ;0d38
jp l0d45h ;0d39
l0d3ch:
pop hl ;0d3c
jp l0d45h ;0d3d
l0d40h:
pop de ;0d40
jp l0d45h ;0d41
l0d44h:
pop bc ;0d44
l0d45h:
ret ;0d45
sub_0d46h_plain_calculate:
pop hl ;0d46
ex (sp),hl ;0d47
ld de,common_c4 ;0d48
add hl,de ;0d4b
ld a,(hl) ;0d4c
and 060h ;0d4d
jp nz,l0d58h ;0d4f
ld hl,0ffffh ;0d52
jp l0d5bh ;0d55
l0d58h:
ld hl,0 ;0d58
l0d5bh:
ex (sp),hl ;0d5b
jp (hl) ;0d5c
sub_0d5dh_plain_calculate_skip_1:
pop hl ;0d5d
ex (sp),hl ;0d5e
ld a,l ;0d5f
cp 031h ;0d60
jp nz,l0d6ch ;0d62
ld b,030h ;0d65
ld c,00dh ;0d67
jp l0d9ch ;0d69
l0d6ch:
ld a,024h ;0d6c
cp l ;0d6e
jp nc,l0d7bh ;0d6f
ld b,030h ;0d72
ld a,l ;0d74
sub 024h ;0d75
ld c,a ;0d77
jp l0d9ch ;0d78
l0d7bh:
ld a,018h ;0d7b
cp l ;0d7d
jp nc,l0d8ah ;0d7e
ld b,020h ;0d81
ld a,l ;0d83
sub 018h ;0d84
ld c,a ;0d86
jp l0d9ch ;0d87
l0d8ah:
ld a,00ch ;0d8a
cp l ;0d8c
jp nc,l0d99h ;0d8d
ld b,010h ;0d90
ld a,l ;0d92
sub 00ch ;0d93
ld c,a ;0d95
jp l0d9ch ;0d96
l0d99h:
ld b,000h ;0d99
ld c,l ;0d9b
l0d9ch:
ld a,b ;0d9c
add a,c ;0d9d
ld h,000h ;0d9e
ld l,a ;0da0
ex (sp),hl ;0da1
jp (hl) ;0da2
; Is called when C has been pressed and something should start happening (end half)
sub_0da3h_plain_calculate_skip_2:
pop hl ;0da3
pop de ;0da4
ex (sp),hl ;0da5
push de ;0da6
ld a,e ;0da7
ex de,hl ;0da8
ld hl,kpr_08018h ;0da9
add hl,de ;0dac
ld (hl),a ;0dad
pop hl ;0dae
push de ;0daf
push hl ;0db0
; Is called when C has been pressed and something should start happening
call sub_0d5dh_plain_calculate_skip_1 ;0db1
pop hl ;0db4
ld a,l ;0db5
or 040h ;0db6
ld hl,common_c5 ;0db8
pop de ;0dbb
add hl,de ;0dbc
ld (hl),a ;0dbd
ld hl,common_array1 ;0dbe
add hl,de ;0dc1
set 4,(hl) ;0dc2
ret ;0dc4
sub_calc_with_common_array1_1:
pop hl ;0dc5
ex (sp),hl ;0dc6
ex de,hl ;0dc7
ld hl,common_array1 ;0dc8
add hl,de ;0dcb
bit 1,(hl) ;0dcc
jp nz,l0de6h ;0dce
ld hl,common_c5 ;0dd1
add hl,de ;0dd4
push hl ;0dd5
ld a,(hl) ;0dd6
ld hl,common_c2 ;0dd7
add hl,de ;0dda
ld (hl),a ;0ddb
and 03fh ;0ddc
pop hl ;0dde
ld (hl),a ;0ddf
ld hl,common_array1 ;0de0
add hl,de ;0de3
set 1,(hl) ;0de4
l0de6h:
res 4,(hl) ;0de6
ret ;0de8
sub_0de9h_handle_special_keys_maybe_sub1:
ld a,(common_b2) ;0de9
or a ;0dec
jp nz,l0df5h ;0ded
ld b,000h ;0df0
jp l0df7h ;0df2
l0df5h:
dec a ;0df5
ld b,a ;0df6
l0df7h:
ld hl,0 ;0df7
l0dfah:
push bc ;0dfa
push hl ;0dfb
ld a,(ym2142_source1) ;0dfc
ld b,a ;0dff
ld c,000h ;0e00
ld hl,l2cfch_data_for_ym2142_things ;0e02
ld a,001h ;0e05
call sub_add_2c_b_to_hl_put_result_in_hl_de_bc_af ;0e07
ld d,(hl) ;0e0a
ld c,001h ;0e0b
ld hl,l2cfch_data_for_ym2142_things ;0e0d
ld a,001h ;0e10
call sub_add_2c_b_to_hl_put_result_in_hl_de_bc_af ;0e12
ld e,(hl) ;0e15
ld a,(flags1) ;0e16
and 007h ;0e19
jp z,l0e30h ;0e1b
ld a,(flags2) ;0e1e
bit 2,a ;0e21
jp z,l0e28h ;0e23
set 4,d ;0e26
l0e28h:
ld a,b ;0e28
cp 002h ;0e29
jp nz,l0e30h ;0e2b
set 1,e ;0e2e
l0e30h:
ex de,hl ;0e30
ex (sp),hl ;0e31
pop bc ;0e32
push hl ;0e33
ex de,hl ;0e34
ld hl,common_c1 ;0e35
add hl,de ;0e38
ld d,000h ;0e39
ld e,(hl) ;0e3b
ld hl,common_c4 ;0e3c
add hl,de ;0e3f
ld (hl),b ;0e40
ld hl,common_c3 ;0e41
add hl,de ;0e44
ld (hl),c ;0e45
ld hl,common_array1 ;0e46
add hl,de ;0e49
set 2,(hl) ;0e4a
set 3,(hl) ;0e4c
pop hl ;0e4e
pop bc ;0e4f
inc hl ;0e50
ld a,b ;0e51
inc a ;0e52
cp l ;0e53
jp nz,l0dfah ;0e54
ld a,(common_b1) ;0e57
or a ;0e5a
jp z,l0e90h ;0e5b
ld de,0 ;0e5e
l0e61h:
push de ;0e61
ld hl,common_c1 ;0e62
add hl,de ;0e65
ld c,(hl) ;0e66
ld b,000h ;0e67
push bc ;0e69
ld hl,common_array1 ;0e6a
add hl,bc ;0e6d
set 0,(hl) ;0e6e
push bc ;0e70
call sub_0d46h_plain_calculate ;0e71
pop hl ;0e74
pop bc ;0e75
ld a,l ;0e76
or a ;0e77
jp nz,l0e87h ;0e78
push bc ;0e7b
ld hl,kpr_08018h ;0e7c
add hl,bc ;0e7f
ld l,(hl) ;0e80
ld h,000h ;0e81
push hl ;0e83
call sub_0da3h_plain_calculate_skip_2 ;0e84
l0e87h:
pop de ;0e87
inc de ;0e88
ld a,(common_b1) ;0e89
cp e ;0e8c
jp nz,l0e61h ;0e8d
l0e90h:
ret ;0e90
sub_0e91h:
ld a,(key_result_flags1) ;0e91
bit 0,a ;0e94
jp nz,l0ea1h ;0e96
ld a,(flags1) ;0e99
and 007h ;0e9c
jp z,l0f76h ;0e9e
l0ea1h:
ld a,(0803fh) ;0ea1
ld d,000h ;0ea4
ld e,a ;0ea6
ld a,(080d0h) ;0ea7
bit 7,a ;0eaa
jp nz,l0ebdh ;0eac
ld a,(flags2) ;0eaf
bit 3,a ;0eb2
jp nz,l0ebdh ;0eb4
ld hl,02d12h ;0eb7
jp l0ec0h ;0eba
l0ebdh:
ld hl,l2d1ch ;0ebd
l0ec0h:
add hl,de ;0ec0
ld b,(hl) ;0ec1
ld a,003h ;0ec2
cp b ;0ec4
jp nz,l0ecdh ;0ec5
ld c,010h ;0ec8
jp l0ecfh ;0eca
l0ecdh:
ld c,000h ;0ecd
l0ecfh:
push bc ;0ecf
ld hl,common_c1 ;0ed0
ld de,00001h+1 ;0ed3
add hl,de ;0ed6
push hl ;0ed7
ld d,000h ;0ed8
ld e,(hl) ;0eda
ld hl,common_c4 ;0edb
add hl,de ;0ede
push hl ;0edf
ld c,000h ;0ee0
ld hl,l2cfch_data_for_ym2142_things ;0ee2
ld a,001h ;0ee5
call sub_add_2c_b_to_hl_put_result_in_hl_de_bc_af ;0ee7
ld a,(hl) ;0eea
pop hl ;0eeb
ld (hl),a ;0eec
ld hl,common_c3 ;0eed
add hl,de ;0ef0
push hl ;0ef1
ld c,001h ;0ef2
ld hl,l2cfch_data_for_ym2142_things ;0ef4
ld a,001h ;0ef7
call sub_add_2c_b_to_hl_put_result_in_hl_de_bc_af ;0ef9
ld a,(hl) ;0efc
pop hl ;0efd
pop de ;0efe
pop bc ;0eff
add a,c ;0f00
ld (hl),a ;0f01
inc de ;0f02
ex de,hl ;0f03
ld d,000h ;0f04
ld e,(hl) ;0f06
ld hl,common_c4 ;0f07
add hl,de ;0f0a
push hl ;0f0b
ld b,002h ;0f0c
ld c,000h ;0f0e
ld hl,l2cfch_data_for_ym2142_things ;0f10
ld a,001h ;0f13
call sub_add_2c_b_to_hl_put_result_in_hl_de_bc_af ;0f15
ld a,(hl) ;0f18
pop hl ;0f19
ld (hl),a ;0f1a
ld hl,common_c3 ;0f1b
add hl,de ;0f1e
push hl ;0f1f
ld c,001h ;0f20
ld hl,l2cfch_data_for_ym2142_things ;0f22
ld a,001h ;0f25
call sub_add_2c_b_to_hl_put_result_in_hl_de_bc_af ;0f27
ld a,(hl) ;0f2a
pop hl ;0f2b
ld (hl),a ;0f2c
ld a,(flags1) ;0f2d
and 007h ;0f30
jp z,l0f5dh ;0f32
ld a,(0803fh) ;0f35
cp 007h ;0f38
jp nz,l0f5dh ;0f3a
ld hl,common_c1 ;0f3d
ld de,00001h+1 ;0f40
add hl,de ;0f43
push hl ;0f44
ld d,000h ;0f45
ld e,(hl) ;0f47
ld hl,common_c3 ;0f48
add hl,de ;0f4b
ld a,(hl) ;0f4c
add a,010h ;0f4d
ld (hl),a ;0f4f
pop hl ;0f50
inc hl ;0f51
ld d,000h ;0f52
ld e,(hl) ;0f54
ld hl,common_c3 ;0f55
add hl,de ;0f58
ld a,(hl) ;0f59
add a,010h ;0f5a
ld (hl),a ;0f5c
l0f5dh:
ld de,00001h+1 ;0f5d
l0f60h:
ld hl,common_c1 ;0f60
add hl,de ;0f63
ld b,000h ;0f64
ld c,(hl) ;0f66
ld hl,common_array1 ;0f67
add hl,bc ;0f6a
set 2,(hl) ;0f6b
set 3,(hl) ;0f6d
inc de ;0f6f
ld a,e ;0f70
cp 004h ;0f71
jp nz,l0f60h ;0f73
l0f76h:
ret ;0f76
sub_0f77h_calc_with_common_c1_array1:
ld a,(08032h) ;0f77
ld b,a ;0f7a
ld c,001h ;0f7b
ld hl,l2cfch_data_for_ym2142_things ;0f7d
ld a,001h ;0f80
call sub_add_2c_b_to_hl_put_result_in_hl_de_bc_af ;0f82
ld c,(hl) ;0f85
ld a,(08032h) ;0f86
cp 007h ;0f89
ld a,c ;0f8b
jp nz,l0f91h ;0f8c
add a,010h ;0f8f
l0f91h:
ld hl,flags2 ;0f91
bit 0,(hl) ;0f94
jp z,l0f9bh ;0f96
add a,010h ;0f99
l0f9bh:
push af ;0f9b
ld c,000h ;0f9c
ld hl,l2cfch_data_for_ym2142_things ;0f9e
ld a,001h ;0fa1
call sub_add_2c_b_to_hl_put_result_in_hl_de_bc_af ;0fa3
ld a,(hl) ;0fa6
ld hl,common_c1 ;0fa7
ld de,00001h ;0faa
add hl,de ;0fad
ld d,000h ;0fae
ld e,(hl) ;0fb0
ld hl,common_c4 ;0fb1
add hl,de ;0fb4
ld (hl),a ;0fb5
ld hl,common_c3 ;0fb6
add hl,de ;0fb9
pop af ;0fba
ld (hl),a ;0fbb
ld hl,common_array1 ;0fbc
add hl,de ;0fbf
set 2,(hl) ;0fc0
set 3,(hl) ;0fc2
ret ;0fc4
sub_0fc5h_calc_with_b1c1_array1_and_b2:
call sub_0de9h_handle_special_keys_maybe_sub1 ;0fc5
ld a,(common_b2) ;0fc8
cp 004h ;0fcb
jp nc,l0fd3h ;0fcd
call sub_0e91h ;0fd0
l0fd3h:
ld a,(common_b2) ;0fd3
cp 002h ;0fd6
jp nc,l0fdeh ;0fd8
call sub_0f77h_calc_with_common_c1_array1 ;0fdb
l0fdeh:
ret ;0fde
sub_0fdfh_handle_special_keys_maybe:
ld de,6 ;0fdf
ld hl,key_states ;0fe2
add hl,de ;0fe5
ld a,(hl) ;0fe6
; Now a = (key_states + 6)
ld hl,key_diffs ;0fe7
add hl,de ;0fea
and (hl) ;0feb
and 03fh ;0fec
; Now a = (key_states + 6) & (key_diffs + 6) & 0x3f
; Return if a == 0
; This jump occurs when C has been pressed and something should start happening
jp z,l1026h ;0fee
rra ;0ff1
jp nc,l0ffah ;0ff2
ld a,00ah ;0ff5
jp l1020h ;0ff7
l0ffah:
rra ;0ffa
jp nc,l1003h ;0ffb
ld a,000h ;0ffe
jp l1020h ;1000
l1003h:
rra ;1003
jp nc,l100ch ;1004
ld a,001h ;1007
jp l1020h ;1009
l100ch:
rra ;100c
jp nc,l1015h ;100d
ld a,002h ;1010
jp l1020h ;1012
l1015h:
rra ;1015
jp nc,l101eh ;1016
ld a,003h ;1019
jp l1020h ;101b
l101eh:
ld a,006h ;101e
l1020h:
ld (ym2142_source1),a ;1020
; Is NOT called when C has been pressed and something should start happening
call sub_0de9h_handle_special_keys_maybe_sub1 ;1023
l1026h:
ret ;1026
; Is called when C has been pressed and something should start happening
sub_1027h_loop_key_states_diffs:
; flags3 &= 0xcc;
ld a,(flags3) ;1027
and 0cch ;102a
ld (flags3),a ;102c
; Loop de = loop_i = 0...5 (inclusive)
ld de,0 ;102f
l1032h_loop:
ld hl,key_states ;1032
add hl,de ;1035
ld a,(hl) ;1036
and 03fh ;1037
; Now a = (key_states + de) & 0x3f
; Skip if a == 0
jp z,l1054h ;1039
; If key_result_flags1 & (1<<1) && loop_i <= 2:
; flags3 |= (1<<1)
; Else:
; flags3 |= (1<<0)
ld hl,flags3 ;103c
ld a,(key_result_flags1) ;103f
bit 1,a ;1042
jp z,l1052h ;1044
ld a,002h ;1047
cp e ;1049
jp nc,l1052h ;104a
set 1,(hl) ;104d
jp l1054h ;104f
l1052h:
set 0,(hl) ;1052
l1054h:
ld hl,key_diffs ;1054
add hl,de ;1057
ld a,(hl) ;1058
and 03fh ;1059
; Now a = (key_diffs + de) & 0x3f
; Skip if a == 0
jp z,l1076h ;105b
; If key_result_flags1 & (1<<1) && loop_i <= 2:
; flags3 |= (1<<5)
; Else:
; flags3 |= (1<<4)
ld hl,flags3 ;105e
ld a,(key_result_flags1) ;1061
bit 1,a ;1064
jp z,l1074h ;1066
ld a,002h ;1069
cp e ;106b
jp nc,l1074h ;106c
set 5,(hl) ;106f
jp l1076h ;1071
l1074h:
set 4,(hl) ;1074
l1076h:
; Loop until de=6
inc de ;1076
ld a,e ;1077
cp 006h ;1078
jp nz,l1032h_loop ;107a
ret ;107d
sub_107eh_calc_a_lot:
pop hl ;107e
ex (sp),hl ;107f
ld b,l ;1080
ld de,0 ;1081
ld a,0ffh ;1084
ld (kpr_0802ch),a ;1086
l1089h:
ld hl,common_b1 ;1089
ld a,e ;108c
cp (hl) ;108d
jp nc,l10b5h ;108e
ld a,(kpr_0802ch) ;1091
cp 0ffh ;1094
jp nz,l10b5h ;1096
ld hl,common_c1 ;1099
add hl,de ;109c
ld c,(hl) ;109d
ld a,b ;109e
ld hl,kpr_08018h ;109f
ld b,000h ;10a2
add hl,bc ;10a4
ld b,a ;10a5
cp (hl) ;10a6
jp nz,l10b1h ;10a7
ld hl,kpr_0802ch ;10aa
ld (hl),c ;10ad
jp l1089h ;10ae
l10b1h:
inc de ;10b1
jp l1089h ;10b2
l10b5h:
ld a,(kpr_0802ch) ;10b5
cp 0ffh ;10b8
jp z,l10eah ;10ba
l10bdh:
ld a,(common_b2) ;10bd
dec a ;10c0
ld b,a ;10c1
ld a,e ;10c2
cp b ;10c3
jp nc,l10d4h ;10c4
ld hl,common_c1 ;10c7
add hl,de ;10ca
push hl ;10cb
inc hl ;10cc
ld a,(hl) ;10cd
pop hl ;10ce
ld (hl),a ;10cf
inc de ;10d0
jp l10bdh ;10d1
l10d4h:
ld a,(common_b2) ;10d4
dec a ;10d7
ld d,000h ;10d8
ld e,a ;10da
ld hl,common_c1 ;10db
add hl,de ;10de
ld (hl),c ;10df
ld b,000h ;10e0
push bc ;10e2
call sub_calc_with_common_array1_1 ;10e3
ld hl,common_b1 ;10e6
dec (hl) ;10e9
l10eah:
ret ;10ea
sub_10ebh_loop_key_states_diffs_2:
; Loop in an outer and inner loop:
; - b = keys_remaining is used in both loops
; - e is counted by the outer loop to be used here as the key_states index when d is zeroed
; - d is used by the inner loop, along with the keys_activated bits
ld b,031h ;10eb
ld de,0 ;10ed
l10f0h_loop:
ld hl,key_states ;10f0
add hl,de ;10f3
ld a,(hl) ;10f4
cpl ;10f5
; Now a = ~(key_states + de)
ld hl,key_diffs ;10f6
add hl,de ;10f9
and (hl) ;10fa
and 03fh ;10fb
ld c,a ;10fd
ld a,e ;10fe
; Now c = keys_activated =
; (key_states + de) & (key_diffs + de) & 0x3f
; Now a = loop_i
; If loop_i == 5:
; d = 2
; Else:
; d = 6
cp 5 ;10ff
jp nz,l1109h ;1101
ld d,2 ;1104
jp l110bh_inner_loop ;1106
l1109h:
ld d,6 ;1109
l110bh_inner_loop:
ld a,c ;110b
; Now a = c = keys_activated
; Skip if keys_activated == 0
or a ;110c
jp z,l1127h ;110d
; Skip if !(keys_activated & (1<<0))
bit 0,a ;1110
jp z,l1120h ;1112
push bc ;1115
push de ;1116
ld h,000h ;1117
ld l,b ;1119
push hl ;111a
; Is NOT called when C has been pressed and something should start happening
call sub_107eh_calc_a_lot ;111b
pop de ;111e
pop bc ;111f
l1120h:
; Loop
; c=keys_activated <<= 1
srl c ;1120
; b-- (counts down from 0x31)
dec b ;1122
; d-- (was set to 2 or 6 before inner loop)
dec d ;1123
jp l110bh_inner_loop ;1124
l1127h:
; b=keys_remaining -= d
ld a,b ;1127
sub d ;1128
ld b,a ;1129
; Clear d and increment e so that de can be used to index stuff at the beginning of l10f0h_loop
ld d,000h ;112a
inc de ;112c
ld a,(num_keys_ignore) ;112d
ld c,a ;1130
ld a,b ;1131
; Now c = (num_keys_ignore)
; Now a = keys_remaining
; Loop while key_remaining < (num_keys_ignore)
cp c ;1132
jp nc,l10f0h_loop ;1133
ret ;1136
sub_1137h:
pop hl ;1137
ex (sp),hl ;1138
ex de,hl ;1139
ld b,0ffh ;113a
ld a,(common_b1) ;113c
or a ;113f
jp z,l1163h ;1140
ld c,000h ;1143
l1145h:
push bc ;1145
ld b,000h ;1146
ld hl,common_c1 ;1148
add hl,bc ;114b
ld b,000h ;114c
ld c,(hl) ;114e
ld hl,kpr_08018h ;114f
add hl,bc ;1152
pop bc ;1153
ld a,(hl) ;1154
cp e ;1155
jp nz,l115bh ;1156
ld b,000h ;1159
l115bh:
inc c ;115b
ld a,(common_b1) ;115c
cp c ;115f
jp nz,l1145h ;1160
l1163h:
ld h,000h ;1163
ld l,b ;1165
ex (sp),hl ;1166
jp (hl) ;1167
sub_1168h:
pop hl ;1168
ex (sp),hl ;1169
push hl ;116a
push hl ;116b
; Is called when C has been pressed and something should start happening (about halfway in time)
call sub_1137h ;116c
pop hl ;116f
ld a,l ;1170
pop hl ;1171
or a ;1172
jp z,l11f7h ;1173
ld a,(common_b2) ;1176
ld b,a ;1179
ld a,(common_b1) ;117a
cp b ;117d
jp nc,l11f7h ;117e
ld a,(common_b1) ;1181
ld c,a ;1184
ld a,0ffh ;1185
ld (kpr_0802ch),a ;1187
l118ah:
push hl ;118a
ld a,(common_b2) ;118b
ld h,a ;118e
ld a,c ;118f
cp h ;1190
jp nc,l11bah ;1191
ld a,(kpr_0802ch) ;1194
cp 0ffh ;1197
jp nz,l11bah ;1199
ld hl,common_c1 ;119c
ld b,000h ;119f
add hl,bc ;11a1
ld d