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PE EQU 4ed7
CH1_W_DURATION EQU 4ed8
CH1_W_DIR EQU 4ed9
CH1_W_BASE_FREQ EQU 4eda
CH1_W_VOL EQU 4edb
009d ld hl,#CH1_FREQ0 00a0 ld de,#5050 00a3 ld bc,#0010 00a6 ldir
00a8 ld a,(#CH1_W_NUM) 00ab and a
00ac ld a,(#CH1_W_SEL) 00af jr nz,#00b4
00b1 ld a,(#CH1_E_TABLE0)
00b4 ld (#5045),a
00b7 ld a,(#CH2_W_NUM)
00ba and a
00bb ld a,(#CH2_W_SEL)
00be jr nz,#00c3
00c0 ld a,(#CH2_E_TABLE0)
00c3 ld (#504a),a
00c6 ld a,(#CH3_W_NUM)
00c9 and a
00ca ld a,(#CH3_W_SEL)
00cd jr nz,#00d2
00cf ld a,(#CH3_E_TABLE0)
00d2 ld (#504f),a
01b9 call #2d0c 01bc call #2cc1
#if MSPACMAN
2cc1 jp #9797 #else
2cc1 ld hl,#SONG_TABLE_1
#endif
2cc4 ld ix,#CH1_W_NUM 2cc8 ld iy,#CH1_FREQ0 2ccc call #2d44 2ccf ld b,a 2cd0 ld a,(#CH1_W_NUM) 2cd3 and a
2cd4 jr z,#2cda
2cd6 ld a,b 2cd7 ld (#CH1_VOL),a
2cda ld hl,#SONG_TABLE_2
2cdd ld ix,#CH2_W_NUM
2ce1 ld iy,#CH2_FREQ1
2ce5 call #2d44
2ce8 ld b,a
2ce9 ld a,(#CH2_W_NUM)
2cec and a
2ced jr z,#2cf3
2cef ld a,b
2cf0 ld (#CH2_VOL),a
2cf3 ld hl,#SONG_TABLE_3
2cf6 ld ix,#CH3_W_NUM
2cfa ld iy,#CH3_FREQ1
2cfe call #2d44
2d01 ld b,a
2d02 ld a,(#CH3_W_NUM)
2d05 and a
2d06 ret z
2d07 ld a,b
2d08 ld (#CH3_VOL),a
2d0b ret
2d44 ld a,(ix+#00) 2d47 and a
2d48 jp z,#2df4
2d4b ld c,a 2d4c ld b,#08 2d4e ld e,#80
2d50 ld a,e 2d51 and c
2d52 jr nz,#2d59 2d54 srl e
2d56 djnz #2d50
2d58 ret
2d59 ld a,(ix+#02) 2d5c and e
2d5d jr nz,#2d66 2d5f ld (ix+#02),e 2d62 jp #364e
2d65 inc c
2d66 dec (ix+#0c) 2d69 jp nz,#2dd7 2d6c ld l,(ix+#06) 2d6f ld h,(ix+#07)
2d72 ld a,(hl) 2d73 inc hl
2d74 ld (ix+#06),l 2d77 ld (ix+#07),h
2d7a cp #f0 2d7c jr c,#2da5 2d7e ld hl,#2d6c 2d81 push hl 2d82 and #0f 2d84 rst #20
2d85 55 2f 2d87 65 2f 2d89 77 2f 2d8b 89 2f 2d8d 9b 2f 2d8f 0c 00 2d91 0c 00 2d93 0c 00 2d95 0c 00 2d97 0c 00 2d99 0c 00 2d9b 0c 00 2d9d 0c 00 2d9f 0c 00 2da1 0c 00 2da3 ad 2f
2f55 ld l,(ix+#06)
2f58 ld h,(ix+#07) 2f5b ld a,(hl)
2f5c ld (ix+#06),a
2f5f inc hl
2f60 ld a,(hl)
2f61 ld (ix+#07),a 2f64 ret
2f65 ld l,(ix+#06)
2f68 ld h,(ix+#07)
2f6b ld a,(hl) 2f6c inc hl
2f6d ld (ix+#06),l
2f70 ld (ix+#07),h
2f73 ld (ix+#03),a 2f76 ret
2f77 ld l,(ix+#06)
2f7a ld h,(ix+#07)
2f7d ld a,(hl) 2f7e inc hl
2f7f ld (ix+#06),l
2f82 ld (ix+#07),h
2f85 ld (ix+#04),a 2f88 ret
2f89 ld l,(ix+#06)
2f8c ld h,(ix+#07)
2f8f ld a,(hl) 2f90 inc hl
2f91 ld (ix+#06),l
2f94 ld (ix+#07),h
2f97 ld (ix+#09),a 2f9a ret
2f9b ld l,(ix+#06)
2f9e ld h,(ix+#07)
2fa1 ld a,(hl) 2fa2 inc hl
2fa3 ld (ix+#06),l
2fa6 ld (ix+#07),h
2fa9 ld (ix+#0b),a 2fac ret
2fad ld a,(ix+#02)
2fb0 cpl
2fb1 and (ix+#00)
2fb4 ld (ix+#00),a 2fb7 jp #2df4
364e dec b 364f push bc 3650 ld a,b
3651 cp #01
3653 jr z,#3659
3655 ld b,#00
3657 jr #366a
3659 ld a,(#4e13)
365c ld b,#01
365e cp #01
3660 jr z,#366a
3662 ld b,#02
3664 cp #04
3666 jr z,#366a
3668 ld b,#03 366a rst #18 366b pop bc
366c jp #2d72
2da5 ld b,a
2da6 and #1f
2da8 jr z,#2dad 2daa ld (ix+#0d),b 2dad ld c,(ix+#09) 2db0 ld a,(ix+#0b)
2db3 and #08
2db5 jr z,#2db9 2db7 ld c,#00 2db9 ld (ix+#0f),c
2dbc ld a,b 2dbd rlca
2dbe rlca
2dbf rlca
2dc0 and #07 2dc2 ld hl,#3bb0
2dc5 rst #10
2dc6 ld (ix+#0c),a
2dc9 ld a,b 2dca and #1f
2dcc jr z,#2dd7 2dce and #0f 2dd0 ld hl,#3bb8 2dd3 rst #10
2dd4 ld (ix+#0e),a
2dd7 ld l,(ix+#0e)
2dda ld h,#00
2ddc ld a,(ix+#0d) 2ddf and #10
2de1 jr z,#2de5 2de3 ld a,#01 2de5 add a,(ix+#04)
2de8 jp z,#2ee8 2deb jp #2ee4
2d0c ld hl,#EFFECT_TABLE_1 2d0f ld ix,#CH1_E_NUM 2d13 ld iy,#CH1_FREQ0
2d17 call #2dee 2d1a ld (#CH1_VOL),a
2d1d ld hl,#EFFECT_TABLE_2 2d20 ld ix,#CH2_E_NUM
2d24 ld iy,#CH2_FREQ1
2d28 call #2dee
2d2b ld (#CH2_VOL),a
2d2e ld hl,#EFFECT_TABLE_3 2d31 ld ix,#CH3_E_NUM
2d35 ld iy,#CH3_FREQ1
2d39 call #2dee
2d3c ld (#CH3_VOL),a
2d3f xor a 2d40 ld (#CH1_FREQ4),a 2d43 ret
2dee ld a,(ix+#00) 2df1 and a 2df2 jr nz,#2e1b
2df4 ld a,(ix+#02) 2df7 and a
2df8 ret z
2df9 ld (ix+#02),#00 2dfd ld (ix+#0d),#00 2e01 ld (ix+#0e),#00 2e05 ld (ix+#0f),#00 2e09 ld (iy+#00),#00 2e0d ld (iy+#01),#00 2e11 ld (iy+#02),#00 2e15 ld (iy+#03),#00 2e19 xor a 2e1a ret
2e1b ld c,a 2e1c ld b,#08 2e1e ld e,#80
2e20 ld a,e 2e21 and c
2e22 jr nz,#2e29 2e24 srl e
2e26 djnz #2e20
2e28 ret
2e29 ld a,(ix+#02) 2e2c and e
2e2d jr nz,#2e6e 2e2f ld (ix+#02),e
2e32 dec b 2e33 ld a,b
2e34 rlca
2e35 rlca
2e36 rlca
2e37 ld c,a 2e38 ld b,#00 2e3a push hl 2e3b add hl,bc 2e3c push ix
2e3e pop de 2e3f inc de
2e40 inc de
2e41 inc de 2e42 ld bc,#0008
2e45 ldir 2e47 pop hl
2e48 ld a,(ix+#06)
2e4b and #7f
2e4d ld (ix+#0c),a
2e50 ld a,(ix+#04)
2e53 ld (ix+#0e),a
2e56 ld a,(ix+#09)
2e59 ld b,a 2e5a rrca
2e5b rrca
2e5c rrca
2e5d rrca
2e5e and #0f
2e60 ld (ix+#0b),a
2e63 and #08
2e65 jr nz,#2e6e 2e67 ld (ix+#0f),b 2e6a ld (ix+#0d),#00
2e6e dec (ix+#0c) 2e71 jr nz,#2ecd 2e73 ld a,(ix+#08)
2e76 and a
2e77 jr z,#2e89 2e79 dec (ix+#08) 2e7c jr nz,#2e89 2e7e ld a,e
2e7f cpl
2e80 and (ix+#00)
2e83 ld (ix+#00),a 2e86 jp #2dee 2e89 ld a,(ix+#06)
2e8c and #7f
2e8e ld (ix+#0c),a 2e91 bit 7,(ix+#06)
2e95 jr z,#2ead 2e97 ld a,(ix+#05)
2e9a neg
2e9c ld (ix+#05),a 2e9f bit 0,(ix+#0d) 2ea3 set 0,(ix+#0d) 2ea7 jr z,#2ecd 2ea9 res 0,(ix+#0d) 2ead ld a,(ix+#04)
2eb0 add a,(ix+#07)
2eb3 ld (ix+#04),a 2eb6 ld (ix+#0e),a 2eb9 ld a,(ix+#09)
2ebc add a,(ix+#0a)
2ebf ld (ix+#09),a 2ec2 ld b,a
2ec3 ld a,(ix+#0b)
2ec6 and #08
2ec8 jr nz,#2ecd 2eca ld (ix+#0f),b
2ecd ld a,(ix+#0e)
2ed0 add a,(ix+#05)
2ed3 ld (ix+#0e),a
2ed6 ld l,a
2ed7 ld h,#00
2ed9 ld a,(ix+#03) 2edc and #70 2ede jr z,#2ee8
2ee0 rrca
2ee1 rrca
2ee2 rrca
2ee3 rrca
2ee4 ld b,a 2ee5 add hl,hl 2ee6 djnz #2ee5
2ee8 ld (iy+#00),l 2eeb ld a,l
2eec rrca
2eed rrca
2eee rrca
2eef rrca
2ef0 ld (iy+#01),a 2ef3 ld (iy+#02),h 2ef6 ld a,h
2ef7 rrca
2ef8 rrca
2ef9 rrca
2efa rrca
2efb ld (iy+#03),a
2efe ld a,(ix+#0b) 2f01 rst #20
2f02 22 2f 26 2f 2b 2f 3c 2f 43 2f 4a 2f 4b 2f 4c 2f
2f12 4d 2f 4e 2f 4f 2f 50 2f 51 2f 52 2f 53 2f 54 2f
2f22 ld a,(ix+#0f) 2f25 ret
2f26 ld a,(ix+#0f) 2f29 jr #2f34
2f2b ld a,(#4c84) 2f2e and #01
2f30 ld a,(ix+#0f) 2f33 ret nz
2f34 and #0f 2f36 ret z
2f37 dec a
2f38 ld (ix+#0f),a
2f3b ret
2f3c ld a,(#4c84) 2f3f and #03
2f41 jr #2f30
2f43 ld a,(#4c84) 2f46 and #07
2f48 jr #2f30
2f4a ret
2f4b ret
2f4c ret
2f4d ret
2f4e ret
2f4f ret
2f50 ret
2f51 ret
2f52 ret
2f53 ret
2f54 ret
3B30 73 20 00 0C 00 0A 1F 00 72 20 FB 87 00 02 0F 00
3B40 36 20 04 8C 00 00 06 00 36 28 05 8B 00 00 06 00
3B50 36 30 06 8A 00 00 06 00 36 3C 07 89 00 00 06 00
3B60 36 48 08 88 00 00 06 00 24 00 06 08 00 00 0A 00
3B70 40 70 FA 10 00 00 0A 00 70 04 00 00 00 00 08 00
3B80 42 18 FD 06 00 01 0C 00 42 04 03 06 00 01 0C 00
3B90 56 0C FF 8C 00 02 0F 00 05 00 02 20 00 01 0C 00
3BA0 41 20 FF 86 FE 1C 0F FF 70 00 01 0C 00 01 08 00
3BB0 01 02 04 08 10 20 40 80
3BB8 00 57 5C 61 67 6D 74 7B 82 8A 92 9A A3 AD B8 C3
3BC8 D4 3B F3 3B
3BCC 58 3C 95 3C
3BD0 DE 3C DF 3C
3BD4 F1 02 F2 03 F3 0F F4 01 82 70 69 82 70 69 83 70
3BE4 6A 83 70 6A 82 70 69 82 70 69 89 8B 8D 8E FF
3BF3 F1 02 F2 03 F3 0F F4 01 67 50 30 47 30 67 50 30
3C03 47 30 67 50 30 47 30 4B 10 4C 10 4D 10 4E 10 67
3C13 50 30 47 30 67 50 30 47 30 67 50 30 47 30 4B 10
3C23 4C 10 4D 10 4E 10 67 50 30 47 30 67 50 30 47 30
3C33 67 50 30 47 30 4B 10 4C 10 4D 10 4E 10 77 20 4E
3C43 10 4D 10 4C 10 4A 10 47 10 46 10 65 30 66 30 67
3C53 40 70 F0 FB 3B
3C58 F1 00 F2 02 F3 0F F4 00 42 50 4E 50 49 50 46 50
3C68 4E 49 70 66 70 43 50 4F 50 4A 50 47 50 4F 4A 70
3C78 67 70 42 50 4E 50 49 50 46 50 4E 49 70 66 70 45
3C88 46 47 50 47 48 49 50 49 4A 4B 50 6E FF
3C95 F1 01 F2 01 F3 0F F4 00 26 67 26 67 26 67 23 44
3CA4 42 47 30 67 2A 8B 70 26 67 26 67 26 67 23 44 42
3CB4 47 30 67 23 84 70 26 67 26 67 26 67 23 44 42 47
3CC4 30 67 29 6A 2B 6C 30 2C 6D 40 2B 6C 29 6A 67 20
3CD4 29 6A 40 26 87 70 F0 9D 3C
3CDD 00 00 00
3b30 73 20 00 0c 00 0a 1f 00 72 20 fb 87 00 02 0f 00
3b40 59 01 06 08 00 00 02 00 59 01 06 09 00 00 02 00
3b50 59 02 06 0a 00 00 02 00 59 03 06 0b 00 00 02 00
3b60 59 04 06 0c 00 06 02 00 24 00 06 08 02 00 0a 00
3b70 36 07 87 6f 00 00 04 00 70 04 00 00 00 00 08 00
3b80 1c 70 8b 08 00 01 06 00 1c 70 8b 08 00 01 06 00
3b90 56 0c ff 8c 00 02 08 00 56 00 02 0a 07 03 0c 00
3ba0 36 38 fe 12 f8 04 0f fc 22 01 01 06 00 01 07 00
3bb0 01 02 04 08 10 20 40 80
3bb8 00 57 5c 61 67 6d 74 7b 82 8a 92 9a a3 ad b8 c3
3bc8 d4 3b f3 3b 58 3c 95 3c de 3c df 3c
3bd4 f1 03 f2 03 f3 0a f4 02 90 7c 7b 7a 79 79 78 97
3be4 76 75 74 73 73 72 91 a8 88 60 4a 4c 91 95 88 95
3bf4 91 95 88 95 91 95 88 95 95 98 94 97 93 96 88 96
3c04 93 96 88 96 93 96 88 96 b6 b3 75 76 77 78 78 75
3c14 73 68 91 95 88 95 91 95 88 95 86 96 95 92 93 8c
3c24 8a 88 86 90 90 96 95 90 90 86 90 96 90 96 91 88
3c34 81 ff
3c36 47 30 4b 10 4c 10 4d 10 4e 10 77 20 4e 10 4d 10
3c46 4c 10 4a 10 47 10 46 10 65 30 66 30 67 40 70 f0
3c56 fb 3b
3c58 f1 00 f2 02 f3 0a f4 00 88 6c 71 72 73 73 71 93
3c68 6c 73 75 76 76 75 96 7c 7a 78 76 75 96 6c 91 a0
3c78 88 75 76 77 78 71 73 74 75 71 75 71 68 68 65 66
3d78 67 a8 ab ac 8c 86 76 75 6c 71 75 73 6b 6c 73 76
3d88 7a 78 78 76 73 6c aa a8 71 73 74 75 6a 6b 6c 73
3d98 75 76 77 78 71 73 74 75 71 75 71 68 48 40 68 67
3da8 68 aa a9 aa 6a 60 8a 76 75 73 71 71 73 95 75 73
3db8 71 68 68 61 63 6a a8 6c 76 6a 6c 91 90 91 ff
3dc7 40 26 87 70 f0 9d 3c 00 00
967d 95 96 d6 96 58 3c 4f 97
9685 b6 96 19 97 d4 3b 72 97
968d 96 97 96 97 96 97 96 97
9695 f1 00 f2 02 f3 0a f4 00 41 43 45 86 8a 88 8b 6a
96a5 6b 71 6a 88 8b 6a 6b 71 6a 6b 71 73 75 96 95 96
96b5 ff
96b6 f1 02 f2 03 f3 0a f4 02 50 70 86 90 81 90 86 90
96c6 68 6a 6b 68 6a 68 66 6a 68 66 65 68 86 81 86 ff
96d6 f1 00 f2 02 f3 0a f4 00 69 6b 69 86 61 64 65 86
96e6 86 64 66 64 61 69 6b 69 86 61 64 64 a1 70 71 74
96f6 75 35 76 30 50 35 76 30 50 54 56 54 51 6b 69 6b
9706 69 6b 91 6b 69 66 f2 01 74 76 74 71 74 71 6b 69
9716 a6 a6 ff
9719 f1 03 f2 03 f3 0a f4 02 70 66 70 46 50 86 90 70
9729 66 70 46 50 86 90 70 66 70 46 50 86 90 70 61 70
9739 41 50 81 90 f4 00 a6 a4 a2 a1 f4 01 86 89 8b 81
9749 74 71 6b 69 a6 ff
974f f1 00 f2 02 f3 0a f4 00 65 64 65 88 67 88 61 63
975f 64 85 64 85 6a 69 6a 8c 75 93 90 91 90 91 70 8a
976f 68 71 ff
9772 f1 02 f2 03 f3 0a f4 02 65 90 68 70 68 67 66 65
9782 90 61 70 61 65 68 66 90 63 90 86 90 85 90 85 70
9792 86 68 65 ff
9796 ff
0020 pop hl 0021 add a,a
0022 rst #10 0023 ld e,a 0024 inc hl 0025 ld d,(hl) 0026 ex de,hl 0027 jp (hl)
0010 add a,l
0011 ld l,a
0012 ld a,#00
0014 adc a,h
0015 ld h,a
0016 ld a,(hl)
0017 ret
0018 78 ld a,b
0019 87 add a,a
001a d7 rst #10
001b 5f ld e,a 001c 23 inc hl
001d 56 ld d,(hl) 001e eb ex de,hl 001f c9 ret