From fbb9fb6c8a343f8dc54665912544512b3eecf96c Mon Sep 17 00:00:00 2001 From: p4plus2 Date: Mon, 28 Aug 2017 17:34:42 -0700 Subject: [PATCH] Update and label decompression routine. --- bank_80.asm | 142 ++--- bank_B4.asm | 14 +- bank_B5.asm | 2 +- bank_BA.asm | 4 +- bank_BB.asm | 1628 ++++++++++++++++++++++++----------------------- compression.asm | 1620 +++++++++++++++++++++++----------------------- notes.txt | 2 + 7 files changed, 1736 insertions(+), 1676 deletions(-) diff --git a/bank_80.asm b/bank_80.asm index 6d86843..6b0c3a0 100644 --- a/bank_80.asm +++ b/bank_80.asm @@ -395,14 +395,14 @@ start_engine: ; \ BPL .rare_string_copy ;$8085DE |/ Copy the string until there are no more bytes JSL CODE_B58000 ;$8085E0 | Upload the SPC engine init_rare_logo: ; | - JSL CODE_BB91D9 ;$8085E4 | Disable the screen - JSR CODE_808EAE ;$8085E8 | Clear WRAM + JSL disable_screen ;$8085E4 | Disable the screen + JSR clear_wram_reset ;$8085E8 | Clear WRAM JML CODE_8090DA ;$8085EB / Run the Rareware logo CODE_8085EF: LDA #$FFFF ;$8085EF \ STA $00090F ;$8085F2 | - JSL CODE_BB91D9 ;$8085F6 | + JSL disable_screen ;$8085F6 | LDA #CODE_80B3D7 ;$8085FA | STA $24 ;$8085FD | STZ $2102 ;$8085FF | @@ -479,7 +479,7 @@ CODE_80867E: ; | STA $0987 ;$80867E | JMP CODE_80860C ;$808681 / - JSL CODE_BB91D9 ;$808684 | + JSL disable_screen ;$808684 | SEP #$20 ;$808688 | LDA #$FF ;$80868A | STA $210E ;$80868C | @@ -525,7 +525,7 @@ CODE_8086F4: ; | BRA CODE_8086F4 ;$8086F4 / CODE_8086F6: - JSL CODE_BB91D9 ;$8086F6 \ + JSL disable_screen ;$8086F6 \ PHK ;$8086FA | PLB ;$8086FB | LDA #$8000 ;$8086FC | @@ -622,7 +622,7 @@ CODE_8087B9: CODE_8087C5: JML CODE_80F482 ;$8087C5 / - JSL CODE_BB91D9 ;$8087C9 | + JSL disable_screen ;$8087C9 | PHK ;$8087CD | PLB ;$8087CE | JSR CODE_808712 ;$8087CF | @@ -636,7 +636,7 @@ CODE_8087D9: CODE_8087E1: PHK ;$8087E1 \ PLB ;$8087E2 | - JSL CODE_BB91D9 ;$8087E3 | + JSL disable_screen ;$8087E3 | JSL CODE_BB9210 ;$8087E7 | PHK ;$8087EB | PLB ;$8087EC | @@ -1036,7 +1036,7 @@ CODE_808B41: LDA.l DATA_808B7E,x ;$808B48 | CMP #$1000 ;$808B4C | BNE CODE_808B40 ;$808B4F | - JSL CODE_BB91D9 ;$808B51 | + JSL disable_screen ;$808B51 | LDA #$0505 ;$808B55 | JSL CODE_B58021 ;$808B58 | LDA #$0000 ;$808B5C | @@ -1468,36 +1468,36 @@ CODE_808E6A: PLB ;$808EAC | RTL ;$808EAD / -CODE_808EAE: - PLA ;$808EAE \ - INC A ;$808EAF | - STA $32 ;$808EB0 | - LDA #$0000 ;$808EB2 | - STA $7F0000 ;$808EB5 | - LDX #$0000 ;$808EB9 | - LDA #$FFFF ;$808EBC | - TXY ;$808EBF | - INY ;$808EC0 | - MVN $7F, $7F ;$808EC1 | - LDA #$0000 ;$808EC4 | - STA $000911 ;$808EC7 | - LDX #$0911 ;$808ECB | - LDA #$F6ED ;$808ECE | - TXY ;$808ED1 | - INY ;$808ED2 | - MVN $7E, $7E ;$808ED3 | - STZ $34 ;$808ED6 | - LDX #$0034 ;$808ED8 | - LDA #$08D1 ;$808EDB | - TXY ;$808EDE | - INY ;$808EDF | - MVN $80, $80 ;$808EE0 | - LDX #$01FF ;$808EE3 | - TXS ;$808EE6 | - JMP ($0032) ;$808EE7 / +clear_wram_reset: ; \ + PLA ;$808EAE |\ Store the return address in scratch ram + INC A ;$808EAF | | + STA $32 ;$808EB0 |/ + LDA #$0000 ;$808EB2 |\ Clear bank 7F using an MVN copy + STA $7F0000 ;$808EB5 | | (Clear the first byte the recursive MVN) + LDX #$0000 ;$808EB9 | | + LDA #$FFFF ;$808EBC | | + TXY ;$808EBF | | + INY ;$808EC0 | | + MVN $7F, $7F ;$808EC1 |/ + LDA #$0000 ;$808EC4 |\ Clear bank 7E above $0911 using an MVN copy + STA $000911 ;$808EC7 | | + LDX #$0911 ;$808ECB | | + LDA #$F6ED ;$808ECE | | + TXY ;$808ED1 | | + INY ;$808ED2 | | + MVN $7E, $7E ;$808ED3 |/ + STZ $34 ;$808ED6 |\ Clean $7E0034-$7E0906 with an MVN copy + LDX #$0034 ;$808ED8 | | + LDA #$08D1 ;$808EDB | | + TXY ;$808EDE | | + INY ;$808EDF | | + MVN $80, $80 ;$808EE0 |/ + LDX #$01FF ;$808EE3 |\ Reset the stack + TXS ;$808EE6 |/ + JMP ($0032) ;$808EE7 / Return using address from scratch RAM CODE_808EEA: - JSL CODE_BB91D9 ;$808EEA \ + JSL disable_screen ;$808EEA \ PHK ;$808EEE | PLB ;$808EEF | JSR CODE_808FFB ;$808EF0 | @@ -1508,7 +1508,7 @@ CODE_808EEA: JML CODE_808C9E ;$808F00 / CODE_808F04: - JSL CODE_BB91D9 ;$808F04 \ + JSL disable_screen ;$808F04 \ PHK ;$808F08 | PLB ;$808F09 | JSR CODE_808FFB ;$808F0A | @@ -1717,7 +1717,7 @@ CODE_8090B1: RTS ;$8090BA / CODE_8090BB: - JSL CODE_BB91D9 ;$8090BB \ + JSL disable_screen ;$8090BB \ LDA #$0006 ;$8090BF | STA $000689 ;$8090C2 | LDA #CODE_808D02 ;$8090C6 | @@ -1772,7 +1772,7 @@ CODE_809139: ; | LDX #DATA_FA4C3E ;$80913F | LDY.w #DATA_FA4C3E>>16 ;$809142 | LDA #$0000 ;$809145 | - JSL CODE_BB8D91 ;$809148 | + JSL decompress_data ;$809148 | STZ $2116 ;$80914C | SEP #$20 ;$80914F | LDX #$0000 ;$809151 | @@ -1820,7 +1820,7 @@ CODE_809154: ; | LDX #DATA_F52FC7 ;$8091B2 | LDY.w #DATA_F52FC7>>16 ;$8091B5 | LDA #$0000 ;$8091B8 | - JSL CODE_BB8D91 ;$8091BB | + JSL decompress_data ;$8091BB | LDA #$0000 ;$8091BF | STA $7F0100 ;$8091C2 | STA $7F013E ;$8091C6 | @@ -1833,7 +1833,7 @@ CODE_809154: ; | LDX #DATA_F80D10 ;$8091DD | LDY.w #DATA_F80D10>>16 ;$8091E0 | LDA #$0000 ;$8091E3 | - JSL CODE_BB8D91 ;$8091E6 | + JSL decompress_data ;$8091E6 | LDA #$76BA ;$8091EA | STA $2116 ;$8091ED | LDX #$007F ;$8091F0 | @@ -1843,7 +1843,7 @@ CODE_809154: ; | LDX #DATA_F50004 ;$8091FD | LDY.w #DATA_F50004>>16 ;$809200 | LDA #$0000 ;$809203 | - JSL CODE_BB8D91 ;$809206 | + JSL decompress_data ;$809206 | LDA #$78E0 ;$80920A | STA $2116 ;$80920D | LDX #$007F ;$809210 | @@ -1853,7 +1853,7 @@ CODE_809154: ; | LDX #DATA_F56AC9 ;$80921D | LDY.w #DATA_F56AC9>>16 ;$809220 | LDA #$0000 ;$809223 | - JSL CODE_BB8D91 ;$809226 | + JSL decompress_data ;$809226 | LDA #$7CE0 ;$80922A | STA $2116 ;$80922D | LDX #$007F ;$809230 | @@ -1863,7 +1863,7 @@ CODE_809154: ; | LDX #DATA_F55D4A ;$80923D | LDY.w #DATA_F55D4A>>16 ;$809240 | LDA #$0000 ;$809243 | - JSL CODE_BB8D91 ;$809246 | + JSL decompress_data ;$809246 | LDA #$4000 ;$80924A | STA $2116 ;$80924D | LDX #$007F ;$809250 | @@ -1873,7 +1873,7 @@ CODE_809154: ; | LDX #DATA_F8063E ;$80925D | LDY.w #DATA_F8063E>>16 ;$809260 | LDA #$0000 ;$809263 | - JSL CODE_BB8D91 ;$809266 | + JSL decompress_data ;$809266 | LDA #$6000 ;$80926A | STA $2116 ;$80926D | LDX #$007F ;$809270 | @@ -1883,7 +1883,7 @@ CODE_809154: ; | LDX #DATA_D9F7C9 ;$80927D | LDY.w #DATA_D9F7C9>>16 ;$809280 | LDA #$0000 ;$809283 | - JSL CODE_BB8D91 ;$809286 | + JSL decompress_data ;$809286 | LDA #$7000 ;$80928A | STA $2116 ;$80928D | LDX #$007F ;$809290 | @@ -1893,15 +1893,15 @@ CODE_809154: ; | LDX #DATA_F5325B ;$80929D | LDY.w #DATA_F5325B>>16 ;$8092A0 | LDA #$0000 ;$8092A3 | - JSL CODE_BB8D91 ;$8092A6 | + JSL decompress_data ;$8092A6 | LDX #DATA_EB2B84 ;$8092AA | LDY.w #DATA_EB2B84>>16 ;$8092AD | LDA #$0000 ;$8092B0 | - JSL CODE_BB8D91 ;$8092B3 | + JSL decompress_data ;$8092B3 | LDX #DATA_F5325B ;$8092B7 | LDY.w #DATA_F5325B>>16 ;$8092BA | LDA #$0500 ;$8092BD | - JSL CODE_BB8D91 ;$8092C0 | + JSL decompress_data ;$8092C0 | LDA #$000F ;$8092C4 | STA $0512 ;$8092C7 | LDA #$0000 ;$8092CA | @@ -2494,7 +2494,7 @@ CODE_8097CA: ; | BRA CODE_8097CA ;$8097CB / CODE_8097CD: - JSL CODE_BB91D9 ;$8097CD \ + JSL disable_screen ;$8097CD \ PHK ;$8097D1 | PLB ;$8097D2 | JSR clear_vram ;$8097D3 | @@ -2572,7 +2572,7 @@ CODE_8097EB: ; | LDX #DATA_EC83A0 ;$8098A6 | LDY.w #DATA_EC83A0>>16 ;$8098A9 | LDA #$0000 ;$8098AC | - JSL CODE_BB8D91 ;$8098AF | + JSL decompress_data ;$8098AF | LDA #$1000 ;$8098B3 | STA $2116 ;$8098B6 | LDX #$007F ;$8098B9 | @@ -2582,7 +2582,7 @@ CODE_8097EB: ; | LDX #DATA_EC4D40 ;$8098C6 | LDY.w #DATA_EC4D40>>16 ;$8098C9 | LDA #$0000 ;$8098CC | - JSL CODE_BB8D91 ;$8098CF | + JSL decompress_data ;$8098CF | LDA #$4000 ;$8098D3 | STA $2116 ;$8098D6 | LDX #$007F ;$8098D9 | @@ -2598,7 +2598,7 @@ CODE_8097EB: ; | LDX #DATA_EC7CF0 ;$8098F9 | LDY.w #DATA_EC7CF0>>16 ;$8098FC | LDA #$0000 ;$8098FF | - JSL CODE_BB8D91 ;$809902 | + JSL decompress_data ;$809902 | LDA #$7C00 ;$809906 | STA $2116 ;$809909 | LDX #$007F ;$80990C | @@ -2612,7 +2612,7 @@ CODE_8097EB: ; | LDX #DATA_EC4749 ;$809925 | LDY.w #DATA_EC4749>>16 ;$809928 | LDA #$0000 ;$80992B | - JSL CODE_BB8D91 ;$80992E | + JSL decompress_data ;$80992E | LDA #$7420 ;$809932 | STA $2116 ;$809935 | LDX #$007F ;$809938 | @@ -2622,7 +2622,7 @@ CODE_8097EB: ; | LDX #DATA_EC4AAD ;$809945 | LDY.w #DATA_EC4AAD>>16 ;$809948 | LDA #$0000 ;$80994B | - JSL CODE_BB8D91 ;$80994E | + JSL decompress_data ;$80994E | LDA #$7780 ;$809952 | STA $2116 ;$809955 | LDX #$007F ;$809958 | @@ -2632,7 +2632,7 @@ CODE_8097EB: ; | LDX #DATA_EC4C1C ;$809965 | LDY.w #DATA_EC4C1C>>16 ;$809968 | LDA #$0000 ;$80996B | - JSL CODE_BB8D91 ;$80996E | + JSL decompress_data ;$80996E | LDA #$78C0 ;$809972 | STA $2116 ;$809975 | LDX #$007F ;$809978 | @@ -3239,7 +3239,7 @@ DATA_809F6C: db $00 CODE_809F85: - JSL CODE_BB91D9 ;$809F85 \ + JSL disable_screen ;$809F85 \ PHK ;$809F89 | PLB ;$809F8A | JSR clear_vram ;$809F8B | @@ -3397,7 +3397,7 @@ CODE_80A0E9: ; | LDX #DATA_F99400 ;$80A133 | LDY.w #DATA_F99400>>16 ;$80A136 | LDA #$0000 ;$80A139 | - JSL CODE_BB8D91 ;$80A13C | + JSL decompress_data ;$80A13C | LDA #$2000 ;$80A140 | STA $2116 ;$80A143 | LDX #$007F ;$80A146 | @@ -3407,7 +3407,7 @@ CODE_80A0E9: ; | LDX #DATA_F661C1 ;$80A153 | LDY.w #DATA_F661C1>>16 ;$80A156 | LDA #$0000 ;$80A159 | - JSL CODE_BB8D91 ;$80A15C | + JSL decompress_data ;$80A15C | LDA #$6000 ;$80A160 | STA $2116 ;$80A163 | LDX #$007F ;$80A166 | @@ -3417,7 +3417,7 @@ CODE_80A0E9: ; | LDX #DATA_F9C775 ;$80A173 | LDY.w #DATA_F9C775>>16 ;$80A176 | LDA #$0000 ;$80A179 | - JSL CODE_BB8D91 ;$80A17C | + JSL decompress_data ;$80A17C | LDA #$7C20 ;$80A180 | STA $2116 ;$80A183 | LDX #$007F ;$80A186 | @@ -3433,7 +3433,7 @@ CODE_80A0E9: ; | LDX #DATA_F67D1B ;$80A1A6 | LDY.w #DATA_F67D1B>>16 ;$80A1A9 | LDA #$0000 ;$80A1AC | - JSL CODE_BB8D91 ;$80A1AF | + JSL decompress_data ;$80A1AF | LDA #$7800 ;$80A1B3 | STA $2116 ;$80A1B6 | LDX #$007F ;$80A1B9 | @@ -3914,7 +3914,7 @@ CODE_80A5D1: ; | RTS ;$80A5F0 / CODE_80A5F1: - JSL CODE_BB91D9 ;$80A5F1 \ + JSL disable_screen ;$80A5F1 \ PHK ;$80A5F5 | PLB ;$80A5F6 | JSR clear_vram ;$80A5F7 | @@ -4031,7 +4031,7 @@ CODE_80A65D: ; | LDX #DATA_ED5E3F ;$80A720 | LDY.w #DATA_ED5E3F>>16 ;$80A723 | LDA #$0000 ;$80A726 | - JSL CODE_BB8D91 ;$80A729 | + JSL decompress_data ;$80A729 | LDA #$5000 ;$80A72D | STA $2116 ;$80A730 | LDX #$007F ;$80A733 | @@ -4073,7 +4073,7 @@ CODE_80A795: ; | LDX #DATA_EC83A0 ;$80A795 | LDY.w #DATA_EC83A0>>16 ;$80A798 | LDA #$0000 ;$80A79B | - JSL CODE_BB8D91 ;$80A79E | + JSL decompress_data ;$80A79E | LDA #$1000 ;$80A7A2 | STA $2116 ;$80A7A5 | LDX #$007F ;$80A7A8 | @@ -4083,7 +4083,7 @@ CODE_80A795: ; | LDX #DATA_EC7CF0 ;$80A7B5 | LDY.w #DATA_EC7CF0>>16 ;$80A7B8 | LDA #$0000 ;$80A7BB | - JSL CODE_BB8D91 ;$80A7BE | + JSL decompress_data ;$80A7BE | LDA #$7C00 ;$80A7C2 | STA $2116 ;$80A7C5 | LDX #$007F ;$80A7C8 | @@ -5438,7 +5438,7 @@ DATA_80B379: db $00, $00, $06, $00, $01, $07 CODE_80B3D7: - JSL CODE_BB91D9 ;$80B3D7 \ + JSL disable_screen ;$80B3D7 \ PHK ;$80B3DB | PLB ;$80B3DC | STZ $099B ;$80B3DD | @@ -5636,7 +5636,7 @@ CODE_80B560: LDX #DATA_ED0997 ;$80B59C | LDY.w #DATA_ED0997>>16 ;$80B59F | LDA #$0000 ;$80B5A2 | - JSL CODE_BB8D91 ;$80B5A5 | + JSL decompress_data ;$80B5A5 | LDA #$4000 ;$80B5A9 | STA $2116 ;$80B5AC | LDX #$007F ;$80B5AF | @@ -5646,7 +5646,7 @@ CODE_80B560: LDX #DATA_ED02A1 ;$80B5BC | LDY.w #DATA_ED02A1>>16 ;$80B5BF | LDA #$0000 ;$80B5C2 | - JSL CODE_BB8D91 ;$80B5C5 | + JSL decompress_data ;$80B5C5 | LDA #$1C00 ;$80B5C9 | STA $2116 ;$80B5CC | LDX #$007F ;$80B5CF | @@ -5665,7 +5665,7 @@ CODE_80B560: RTS ;$80B5F9 / CODE_80B5FA: - JSL CODE_BB91D9 ;$80B5FA \ + JSL disable_screen ;$80B5FA \ JSL clear_vram ;$80B5FE | JSL init_registers_wrapper ;$80B602 | JSL CODE_BB91F7 ;$80B606 | @@ -12657,7 +12657,7 @@ IRQ_start: RTI ;$80F3FA / CODE_80F3FB: - JSL CODE_BB91D9 ;$80F3FB \ + JSL disable_screen ;$80F3FB \ PHK ;$80F3FF | PLB ;$80F400 | JSL clear_vram_wrapper ;$80F401 | @@ -13239,7 +13239,7 @@ CODE_80FA70: ; | JML [$05A9] ;$80FA79 / CODE_80FA7C: - JSL CODE_BB91D9 ;$80FA7C \ + JSL disable_screen ;$80FA7C \ PHK ;$80FA80 | PLB ;$80FA81 | JSL clear_vram_wrapper ;$80FA82 | diff --git a/bank_B4.asm b/bank_B4.asm index 3705c01..b6f3df3 100644 --- a/bank_B4.asm +++ b/bank_B4.asm @@ -684,7 +684,7 @@ CODE_B485E6: STA $065A ;$B485F5 | LDX #$065A ;$B485F8 | JSR ($0000,x) ;$B485FB | - JSL CODE_BB91D9 ;$B485FE | + JSL disable_screen ;$B485FE | LDA #CODE_8087D9 ;$B48602 | JML CODE_808C9E ;$B48605 / @@ -1475,7 +1475,7 @@ CODE_B48C9D: LDA $06A1 ;$B48CA4 | AND #$DDFF ;$B48CA7 | STA $06A1 ;$B48CAA | - JSL CODE_BB91D9 ;$B48CAD | + JSL disable_screen ;$B48CAD | JSL clear_vram_wrapper ;$B48CB1 | JSL CODE_BAC7C0 ;$B48CB5 | LDA #$0200 ;$B48CB9 | @@ -1610,7 +1610,7 @@ CODE_B48DF9: ; | RTS ;$B48DF9 / CODE_B48DFA: - JSL CODE_BB91D9 ;$B48DFA \ + JSL disable_screen ;$B48DFA \ LDA #$0040 ;$B48DFE | TSB $08FB ;$B48E01 | LDA #$0040 ;$B48E04 | @@ -2006,7 +2006,7 @@ CODE_B491BF: ; | CODE_B491C5: JSR CODE_B4AE58 ;$B491C5 \ STZ $08FE ;$B491C8 | - JSL CODE_BB91D9 ;$B491CB | + JSL disable_screen ;$B491CB | JSL CODE_BBC5AB ;$B491CF | JML CODE_809F85 ;$B491D3 / @@ -3986,7 +3986,7 @@ CODE_B4A288: RTS ;$B4A291 / CODE_B4A292: - JSL CODE_BB91D9 ;$B4A292 \ + JSL disable_screen ;$B4A292 \ JSL CODE_BBC5F4 ;$B4A296 | LDA #$0001 ;$B4A29A | STA $0613 ;$B4A29D | @@ -7423,7 +7423,7 @@ CODE_B4BEEF: LDA #$0019 ;$B4BF33 | JSL CODE_B5800C ;$B4BF36 | CODE_B4BF3A: ; | - JSL CODE_BB91D9 ;$B4BF3A | + JSL disable_screen ;$B4BF3A | JSL clear_vram_wrapper ;$B4BF3E | JSL CODE_BAC7C0 ;$B4BF42 | JSL CODE_8088D2 ;$B4BF46 | @@ -7634,7 +7634,7 @@ CODE_B4C122: ; | BRA CODE_B4C0DE ;$B4C137 / CODE_B4C139: - JSL CODE_BB91D9 ;$B4C139 \ + JSL disable_screen ;$B4C139 \ LDA #$0010 ;$B4C13D | TRB $08FC ;$B4C140 | STZ $08FE ;$B4C143 | diff --git a/bank_B5.asm b/bank_B5.asm index 02cb550..4114605 100644 --- a/bank_B5.asm +++ b/bank_B5.asm @@ -7876,7 +7876,7 @@ CODE_B5CDEF: CODE_B5CDFD: STA $0006B1 ;$B5CDFD \ - JSL CODE_BB91D9 ;$B5CE01 | + JSL disable_screen ;$B5CE01 | JSL CODE_8088D2 ;$B5CE05 | JSL init_registers_wrapper ;$B5CE09 | JSL CODE_808E6A ;$B5CE0D | diff --git a/bank_BA.asm b/bank_BA.asm index a5ac39d..e4b9ced 100644 --- a/bank_BA.asm +++ b/bank_BA.asm @@ -3370,7 +3370,7 @@ CODE_BAB1B9: TAX ;$BAB1D1 | LDA DATA_BAB3FE,x ;$BAB1D2 | STA $000650 ;$BAB1D5 | - JSL CODE_BB91D9 ;$BAB1D9 | + JSL disable_screen ;$BAB1D9 | JSL clear_vram_wrapper ;$BAB1DD | JSL CODE_BAC7C0 ;$BAB1E1 | SEP #$20 ;$BAB1E5 | @@ -3847,7 +3847,7 @@ CODE_BAB633: PHK ;$BAB645 | PLA ;$BAB646 | STA $CC ;$BAB647 | - JSL CODE_BB91D9 ;$BAB649 | + JSL disable_screen ;$BAB649 | JSL clear_vram_wrapper ;$BAB64D | JSL CODE_BAC7C0 ;$BAB651 | JSL CODE_8088D2 ;$BAB655 | diff --git a/bank_BB.asm b/bank_BB.asm index 03b7a58..b923974 100644 --- a/bank_BB.asm +++ b/bank_BB.asm @@ -1,97 +1,131 @@ - NOP ;$BB8000 | - JMP CODE_BB8E2A ;$BB8001 / +;Command set 1 jump table +copy_or_return_1_entry: + NOP ;$BB8000 \ Decompression command entry + JMP copy_or_return_1 ;$BB8001 / + +stream_byte_1_entry: + NOP ;$BB8004 \ Decompression command entry + JMP stream_byte_1 ;$BB8005 / + +stream_word_1_entry: + NOP ;$BB8008 \ Decompression command entry + JMP stream_word_1 ;$BB8009 / + +stream_byte_fill_1_entry: + NOP ;$BB800C \ Decompression command entry + JMP stream_byte_fill_1 ;$BB800D / + +direct_byte_1_fill_1_entry: + NOP ;$BB8010 \ Decompression command entry + JMP direct_byte_1_fill_1 ;$BB8011 / + +direct_byte_2_fill_1_entry: + NOP ;$BB8014 \ Decompression command entry + JMP direct_byte_2_fill_1 ;$BB8015 / + +direct_word_put_1_entry: + NOP ;$BB8018 \ Decompression command entry + JMP direct_word_put_1 ;$BB8019 / + +direct_byte_1_put_1_entry: + NOP ;$BB801C \ Decompression command entry + JMP direct_byte_1_put_1 ;$BB801D / + +direct_byte_2_put_1_entry: + NOP ;$BB8020 \ Decompression command entry + JMP direct_byte_2_put_1 ;$BB8021 / + +back_copy_word_1_entry: + NOP ;$BB8024 \ Decompression command entry + JMP back_copy_word_1 ;$BB8025 / + +back_copy_1_entry: + NOP ;$BB8028 \ Decompression command entry + JMP back_copy_1 ;$BB8029 / + +back_copy_far_1_entry: + NOP ;$BB802C \ Decompression command entry + JMP back_copy_far_1 ;$BB802D / + +back_copy_arbitrary_1_entry: + NOP ;$BB8030 \ Decompression command entry + JMP back_copy_arbitrary_1 ;$BB8031 / + +duplicate_byte_1_entry: + NOP ;$BB8034 \ Decompression command entry + JMP duplicate_byte_1 ;$BB8035 / + +duplicate_word_1_entry: + NOP ;$BB8038 \ Decompression command entry + JMP duplicate_word_1 ;$BB8039 / + +copy_future_word_1_entry: + NOP ;$BB803C \ Decompression command entry + JMP copy_future_word_1 ;$BB803D / - NOP ;$BB8004 | - JMP CODE_BB8E96 ;$BB8005 / - - NOP ;$BB8008 | - JMP CODE_BB8EB4 ;$BB8009 / - - NOP ;$BB800C | - JMP CODE_BB8EEB ;$BB800D / - - NOP ;$BB8010 | - JMP CODE_BB8F26 ;$BB8011 / - - NOP ;$BB8014 | - JMP CODE_BB8F53 ;$BB8015 / - - NOP ;$BB8018 | - JMP CODE_BB8F80 ;$BB8019 / - - NOP ;$BB801C | - JMP CODE_BB8F9C ;$BB801D / - - NOP ;$BB8020 | - JMP CODE_BB8FAE ;$BB8021 / - - NOP ;$BB8024 | - JMP CODE_BB8FC0 ;$BB8025 / - - NOP ;$BB8028 | - JMP CODE_BB8FFF ;$BB8029 / - - NOP ;$BB802C | - JMP CODE_BB9062 ;$BB802D / - - NOP ;$BB8030 | - JMP CODE_BB90C9 ;$BB8031 / - - NOP ;$BB8034 | - JMP CODE_BB9138 ;$BB8035 / - - NOP ;$BB8038 | - JMP CODE_BB9150 ;$BB8039 / - - NOP ;$BB803C | - JMP CODE_BB9176 ;$BB803D / - - JMP CODE_BB8E6F ;$BB8040 / - - NOP ;$BB8043 | - JMP CODE_BB8EAA ;$BB8044 / - - NOP ;$BB8047 | - JMP CODE_BB8EDB ;$BB8048 / - - NOP ;$BB804B | - JMP CODE_BB8F01 ;$BB804C / - - NOP ;$BB804F | - JMP CODE_BB8F3B ;$BB8050 / - - NOP ;$BB8053 | - JMP CODE_BB8F68 ;$BB8054 / - - NOP ;$BB8057 | - JMP CODE_BB8F8E ;$BB8058 / - - NOP ;$BB805B | - JMP CODE_BB8FA5 ;$BB805C / - - NOP ;$BB805F | - JMP CODE_BB8FB7 ;$BB8060 / - - NOP ;$BB8063 | - JMP CODE_BB8FDE ;$BB8064 / - - NOP ;$BB8067 | - JMP CODE_BB9029 ;$BB8068 / - - NOP ;$BB806B | - JMP CODE_BB9097 ;$BB806C / - - NOP ;$BB806F | - JMP CODE_BB90F2 ;$BB8070 / - - NOP ;$BB8073 | - JMP CODE_BB9144 ;$BB8074 / - - NOP ;$BB8077 | - JMP CODE_BB9163 ;$BB8078 / - - NOP ;$BB807B | - JMP CODE_BB9190 ;$BB807C / +;Command set 2 jump table +copy_or_return_2_entry: + JMP copy_or_return_2 ;$BB8040 > Decompression command entry + +stream_byte_2_entry: + NOP ;$BB8043 \ Decompression command entry + JMP stream_byte_2 ;$BB8044 / + +stream_word_2_entry: + NOP ;$BB8047 \ Decompression command entry + JMP stream_word_2 ;$BB8048 / + +stream_byte_fill_2_entry: + NOP ;$BB804B \ Decompression command entry + JMP stream_byte_fill_2 ;$BB804C / + +direct_byte_1_fill_2_entry: + NOP ;$BB804F \ Decompression command entry + JMP direct_byte_1_fill_2 ;$BB8050 / + +direct_byte_2_fill_2_entry: + NOP ;$BB8053 \ Decompression command entry + JMP direct_byte_2_fill_2 ;$BB8054 / + +direct_word_put_2_entry: + NOP ;$BB8057 \ Decompression command entry + JMP direct_word_put_2 ;$BB8058 / + +direct_byte_1_put_2_entry: + NOP ;$BB805B \ Decompression command entry + JMP direct_byte_1_put_2 ;$BB805C / + +direct_byte_2_put_2_entry: + NOP ;$BB805F \ Decompression command entry + JMP direct_byte_2_put_2 ;$BB8060 / + +back_copy_word_2_entry: + NOP ;$BB8063 \ Decompression command entry + JMP back_copy_word_2 ;$BB8064 / + +back_copy_2_entry: + NOP ;$BB8067 \ Decompression command entry + JMP back_copy_2 ;$BB8068 / + +back_copy_far_2_entry: + NOP ;$BB806B \ Decompression command entry + JMP back_copy_far_2 ;$BB806C / + +back_copy_arbitrary_2_entry: + NOP ;$BB806F \ Decompression command entry + JMP back_copy_arbitrary_2 ;$BB8070 / + +duplicate_byte_2_entry: + NOP ;$BB8073 \ Decompression command entry + JMP duplicate_byte_2 ;$BB8074 / + +duplicate_word_2_entry: + NOP ;$BB8077 \ Decompression command entry + JMP duplicate_word_2 ;$BB8078 / + +copy_future_word_2_entry: + NOP ;$BB807B \ Decompression command entry + JMP copy_future_word_2 ;$BB807C / CODE_BB807F: STX $32 ;$BB807F \ @@ -1937,6 +1971,7 @@ CODE_BB8CC0: ; | REP #$20 ;$BB8CCC | BRL CODE_BB8D54 ;$BB8CCE / +CODE_BB8CD1: SEP #$20 ;$BB8CD1 | LDA.w DATA_FD819A,x ;$BB8CD3 | STA $004304 ;$BB8CD6 | @@ -1979,7 +2014,7 @@ CODE_BB8D18: PHB ;$BB8D26 | PHK ;$BB8D27 | PLB ;$BB8D28 | - JSL CODE_BB8D9E ;$BB8D29 | + JSL decompress_data_default ;$BB8D29 | PLB ;$BB8D2D | PLX ;$BB8D2E | SEP #$20 ;$BB8D2F | @@ -2025,701 +2060,724 @@ CODE_BB8D80: ; | PLX ;$BB8D8B | SEP #$20 ;$BB8D8C | BRL CODE_BB8CEC ;$BB8D8E / + +;$38 -- destination +;$34 -- source +;$32 -- run dma after upload (always #$FFFF so never) +;The follow two tables map to the opposite intended nibbles. +;$42 -- index >> 4 (look up table pointer, set low byte and read for value) +; This table allow direct indexing of low nibbles +;$46 -- (index & 0x0F) << 4 (look up table pointer, set low byte and read for value) +; This table allow direct indexing of high nibbles +;$4A -- command set starting at $BB8040 +;$4E -- command set starting at $BB8000 +;These are the 6 header bytes of compressed data +;$52 -- fill byte 1 +;$53 -- fill byte 2 +;$56 -- direct byte 1 +;$57 -- direct byte 2 +;$54 -- direct word +;Misc addresses +;$3C -- operand 1 (usually count) +;$3E -- operand 2 (usually offset) -CODE_BB8D91: - STA $38 ;$BB8D91 \ +;Extra notes +;All commands are return addresses - 1 so RTS can be used + +decompress_data: ; + STA $38 ;$BB8D91 \ Set decompression parameters LDA #$007F ;$BB8D93 | - STA $3A ;$BB8D96 | - STX $34 ;$BB8D98 | + STA $3A ;$BB8D96 | Bank 7F + address from A + STX $34 ;$BB8D98 | Source from X STY $36 ;$BB8D9A | - BRA CODE_BB8DAE ;$BB8D9C / - -CODE_BB8D9E: - TXA ;$BB8D9E \ - TYX ;$BB8D9F | - STA $34 ;$BB8DA0 | - STX $36 ;$BB8DA2 | - LDA #$0000 ;$BB8DA4 | - STA $38 ;$BB8DA7 | - LDA #$007F ;$BB8DA9 | - STA $3A ;$BB8DAC | -CODE_BB8DAE: ; | - LDA #$FFFF ;$BB8DAE | - STA $32 ;$BB8DB1 | - PHB ;$BB8DB3 | - PHY ;$BB8DB4 | - LDA #$2100 ;$BB8DB5 | - STA $46 ;$BB8DB8 | - LDA #$007E ;$BB8DBA | - STA $48 ;$BB8DBD | - STA $44 ;$BB8DBF | - LDA #$2000 ;$BB8DC1 | - STA $42 ;$BB8DC4 | - JSL CODE_BB91AF ;$BB8DC6 | - LDX $38 ;$BB8DCA | - LDY #$0001 ;$BB8DCC | - LDA #$8001 ;$BB8DCF | - STA $4E ;$BB8DD2 | - LDA #$8040 ;$BB8DD4 | - STA $4A ;$BB8DD7 | + BRA start_decompression ;$BB8D9C / + ; +decompress_data_default: ; \ + TXA ;$BB8D9E |\ Set decompression parameters + TYX ;$BB8D9F | | + STA $34 ;$BB8DA0 | | + STX $36 ;$BB8DA2 | | + LDA #$0000 ;$BB8DA4 | | Default destination $7F0000 + STA $38 ;$BB8DA7 | | + LDA #$007F ;$BB8DA9 | | + STA $3A ;$BB8DAC |/ +start_decompression: ; | + LDA #$FFFF ;$BB8DAE |\ Disble auto DMA of data + STA $32 ;$BB8DB1 |/ + PHB ;$BB8DB3 |\ Preserve call bank/Y + PHY ;$BB8DB4 |/ + LDA #$2100 ;$BB8DB5 |\ Setup pointers to nibble look up tables + STA $46 ;$BB8DB8 | | + LDA #$007E ;$BB8DBA | | + STA $48 ;$BB8DBD | | + STA $44 ;$BB8DBF | | + LDA #$2000 ;$BB8DC1 | | + STA $42 ;$BB8DC4 |/ + JSL build_decompression_lookup ;$BB8DC6 | Generate nibble offset table at RAM $7E2000 + LDX $38 ;$BB8DCA | Load the decompression index + LDY #$0001 ;$BB8DCC | Load the compression index + LDA #$8001 ;$BB8DCF |\ Load default decompression function A 8001 + STA $4E ;$BB8DD2 |/ The high byte will never change. + LDA #$8040 ;$BB8DD4 |\ Load default decompression function B 8040 + STA $4A ;$BB8DD7 |/ SEP #$20 ;$BB8DD9 | - LDA $3A ;$BB8DDB | - PHA ;$BB8DDD | - PLB ;$BB8DDE | - LDA [$34],y ;$BB8DDF | - STA $52 ;$BB8DE1 | - INY ;$BB8DE3 | - LDA [$34],y ;$BB8DE4 | - STA $53 ;$BB8DE6 | - INY ;$BB8DE8 | - LDA [$34],y ;$BB8DE9 | - STA $56 ;$BB8DEB | - INY ;$BB8DED | - LDA [$34],y ;$BB8DEE | - STA $57 ;$BB8DF0 | - INY ;$BB8DF2 | - REP #$20 ;$BB8DF3 | - LDA [$34],y ;$BB8DF5 | - STA $54 ;$BB8DF7 | - LDY #$0027 ;$BB8DF9 | - STZ $3C ;$BB8DFC | - STZ $3E ;$BB8DFE | - SEP #$20 ;$BB8E00 | -CODE_BB8E02: ; | - LDA [$34],y ;$BB8E02 | - INY ;$BB8E04 | - STA $46 ;$BB8E05 | - AND #$F0 ;$BB8E07 | - LSR A ;$BB8E09 | - LSR A ;$BB8E0A | - STA $4E ;$BB8E0B | - PEI ($4E) ;$BB8E0D | - RTS ;$BB8E0F / - -CODE_BB8E10: - LDA $46 ;$BB8E10 \ - AND #$0F ;$BB8E12 | - ASL A ;$BB8E14 | - ASL A ;$BB8E15 | - ADC #$3F ;$BB8E16 | + LDA $3A ;$BB8DDB |\ Set the data bank to the destination bank + PHA ;$BB8DDD | | + PLB ;$BB8DDE |/ + LDA [$34],y ;$BB8DDF |\ Read fill byte 1 + STA $52 ;$BB8DE1 | | + INY ;$BB8DE3 |/ + LDA [$34],y ;$BB8DE4 |\ Read fill byte 2 + STA $53 ;$BB8DE6 | | + INY ;$BB8DE8 |/ + LDA [$34],y ;$BB8DE9 |\ Read direct byte 1 + STA $56 ;$BB8DEB | | + INY ;$BB8DED |/ + LDA [$34],y ;$BB8DEE |\ Read direct byte 2 + STA $57 ;$BB8DF0 | | + INY ;$BB8DF2 |/ + REP #$20 ;$BB8DF3 |\ Read direct word + LDA [$34],y ;$BB8DF5 | | + STA $54 ;$BB8DF7 |/ + LDY #$0027 ;$BB8DF9 | Skip to compressed byte #$27 + STZ $3C ;$BB8DFC |\ Clear generic operand 1 + STZ $3E ;$BB8DFE |/ Clean generic operand 2 + SEP #$20 ;$BB8E00 | Return to 8 bit +execute_command_set_1: ; | + LDA [$34],y ;$BB8E02 |\ Read the first command byte + INY ;$BB8E04 | | + STA $46 ;$BB8E05 |/ + AND #$F0 ;$BB8E07 |\ Command = (byte & 0xF0) >> 2 + LSR A ;$BB8E09 | | Range $00-$3C + LSR A ;$BB8E0A | | + STA $4E ;$BB8E0B |/ + PEI ($4E) ;$BB8E0D | Push command address onto the stack + RTS ;$BB8E0F / Return to execute command + ; +execute_command_set_2_wide: ; + LDA $46 ;$BB8E10 \ Read next command byte + AND #$0F ;$BB8E12 |\ Command = (byte & 0xF0) >> 2 + ASL A ;$BB8E14 | | Range $3F-$7B + ASL A ;$BB8E15 | | + ADC #$3F ;$BB8E16 |/ STA $4A ;$BB8E18 | - PEI ($4A) ;$BB8E1A | - RTS ;$BB8E1C / - -CODE_BB8E1D: - LDA $42 ;$BB8E1D \ - AND #$0F ;$BB8E1F | - ASL A ;$BB8E21 | - ASL A ;$BB8E22 | - ADC #$3F ;$BB8E23 | - STA $4A ;$BB8E25 | - PEI ($4A) ;$BB8E27 | - RTS ;$BB8E29 / - -CODE_BB8E2A: - LDA $46 ;$BB8E2A \ - AND #$0F ;$BB8E2C | - BEQ CODE_BB8E40 ;$BB8E2E | - STA $3C ;$BB8E30 | -CODE_BB8E32: ; | - LDA [$34],y ;$BB8E32 | - INY ;$BB8E34 | - STA $0000,x ;$BB8E35 | - INX ;$BB8E38 | - DEC $3C ;$BB8E39 | - BNE CODE_BB8E32 ;$BB8E3B | - JMP CODE_BB8E02 ;$BB8E3D / - -CODE_BB8E40: - REP #$20 ;$BB8E40 \ - PLY ;$BB8E42 | - PLB ;$BB8E43 | - TXA ;$BB8E44 | - SEC ;$BB8E45 | - SBC $38 ;$BB8E46 | - TAX ;$BB8E48 | - LDA $32 ;$BB8E49 | - BMI CODE_BB8E6E ;$BB8E4B | - LDA $58 ;$BB8E4D | - STA $2116 ;$BB8E4F | - LDA $38 ;$BB8E52 | - STA $4302 ;$BB8E54 | - LDA $3A ;$BB8E57 | - STA $4304 ;$BB8E59 | - STX $4305 ;$BB8E5C | - LDA #$1801 ;$BB8E5F | - STA $4300 ;$BB8E62 | - SEP #$20 ;$BB8E65 | - LDA #$01 ;$BB8E67 | - STA $420B ;$BB8E69 | - REP #$20 ;$BB8E6C | -CODE_BB8E6E: ; | - RTL ;$BB8E6E / - -CODE_BB8E6F: - LDA [$34],y ;$BB8E6F \ - INY ;$BB8E71 | - STA $42 ;$BB8E72 | - STA $46 ;$BB8E74 | - LDA [$42] ;$BB8E76 | - BEQ CODE_BB8E40 ;$BB8E78 | - STA $3C ;$BB8E7A | -CODE_BB8E7C: ; | - LDA [$46] ;$BB8E7C | - STA $3E ;$BB8E7E | - LDA [$34],y ;$BB8E80 | - INY ;$BB8E82 | - STA $42 ;$BB8E83 | - STA $46 ;$BB8E85 | - LDA $3E ;$BB8E87 | - ORA [$42] ;$BB8E89 | - STA $0000,x ;$BB8E8B | - INX ;$BB8E8E | - DEC $3C ;$BB8E8F | - BNE CODE_BB8E7C ;$BB8E91 | - JMP CODE_BB8E10 ;$BB8E93 / - -CODE_BB8E96: - LDA [$46] ;$BB8E96 \ - STA $3E ;$BB8E98 | - LDA [$34],y ;$BB8E9A | - INY ;$BB8E9C | - STA $42 ;$BB8E9D | - LDA $3E ;$BB8E9F | - ORA [$42] ;$BB8EA1 | - STA $0000,x ;$BB8EA3 | - INX ;$BB8EA6 | - JMP CODE_BB8E1D ;$BB8EA7 / - -CODE_BB8EAA: - LDA [$34],y ;$BB8EAA \ - INY ;$BB8EAC | - STA $0000,x ;$BB8EAD | - INX ;$BB8EB0 | - JMP CODE_BB8E02 ;$BB8EB1 / - -CODE_BB8EB4: - LDA [$46] ;$BB8EB4 \ - STA $3E ;$BB8EB6 | - LDA [$34],y ;$BB8EB8 | - INY ;$BB8EBA | - STA $42 ;$BB8EBB | - STA $46 ;$BB8EBD | - LDA $3E ;$BB8EBF | - ORA [$42] ;$BB8EC1 | - STA $0000,x ;$BB8EC3 | - INX ;$BB8EC6 | - LDA [$46] ;$BB8EC7 | - STA $3E ;$BB8EC9 | - LDA [$34],y ;$BB8ECB | - INY ;$BB8ECD | - STA $42 ;$BB8ECE | - LDA $3E ;$BB8ED0 | - ORA [$42] ;$BB8ED2 | - STA $0000,x ;$BB8ED4 | - INX ;$BB8ED7 | - JMP CODE_BB8E1D ;$BB8ED8 / - -CODE_BB8EDB: - REP #$20 ;$BB8EDB \ - LDA [$34],y ;$BB8EDD | - STA $0000,x ;$BB8EDF | - INY ;$BB8EE2 | - INY ;$BB8EE3 | - INX ;$BB8EE4 | - INX ;$BB8EE5 | - SEP #$20 ;$BB8EE6 | - JMP CODE_BB8E02 ;$BB8EE8 / - -CODE_BB8EEB: - LDA $46 ;$BB8EEB \ - AND #$0F ;$BB8EED | - ADC #$03 ;$BB8EEF | - STA $3C ;$BB8EF1 | - LDA [$34],y ;$BB8EF3 | - INY ;$BB8EF5 | -CODE_BB8EF6: ; | - STA $0000,x ;$BB8EF6 | - INX ;$BB8EF9 | - DEC $3C ;$BB8EFA | - BNE CODE_BB8EF6 ;$BB8EFC | - JMP CODE_BB8E02 ;$BB8EFE / - -CODE_BB8F01: - LDA [$34],y ;$BB8F01 \ - INY ;$BB8F03 | - STA $42 ;$BB8F04 | - STA $46 ;$BB8F06 | - LDA [$42] ;$BB8F08 | - ADC #$03 ;$BB8F0A | - STA $3C ;$BB8F0C | - LDA [$46] ;$BB8F0E | - STA $3E ;$BB8F10 | - LDA [$34],y ;$BB8F12 | - INY ;$BB8F14 | - STA $42 ;$BB8F15 | - LDA $3E ;$BB8F17 | - ORA [$42] ;$BB8F19 | -CODE_BB8F1B: ; | - STA $0000,x ;$BB8F1B | - INX ;$BB8F1E | - DEC $3C ;$BB8F1F | - BNE CODE_BB8F1B ;$BB8F21 | - JMP CODE_BB8E1D ;$BB8F23 / - -CODE_BB8F26: - LDA $46 ;$BB8F26 \ - AND #$0F ;$BB8F28 | - ADC #$03 ;$BB8F2A | - STA $3C ;$BB8F2C | - LDA $52 ;$BB8F2E | -CODE_BB8F30: ; | - STA $0000,x ;$BB8F30 | - INX ;$BB8F33 | - DEC $3C ;$BB8F34 | - BNE CODE_BB8F30 ;$BB8F36 | - JMP CODE_BB8E02 ;$BB8F38 / - -CODE_BB8F3B: - LDA [$34],y ;$BB8F3B \ - INY ;$BB8F3D | - STA $42 ;$BB8F3E | - LDA [$42] ;$BB8F40 | - ADC #$03 ;$BB8F42 | - STA $3C ;$BB8F44 | - LDA $52 ;$BB8F46 | -CODE_BB8F48: ; | - STA $0000,x ;$BB8F48 | - INX ;$BB8F4B | - DEC $3C ;$BB8F4C | - BNE CODE_BB8F48 ;$BB8F4E | - JMP CODE_BB8E1D ;$BB8F50 / - -CODE_BB8F53: - LDA $46 ;$BB8F53 \ - AND #$0F ;$BB8F55 | - ADC #$03 ;$BB8F57 | - STA $3C ;$BB8F59 | - LDA $53 ;$BB8F5B | -CODE_BB8F5D: ; | - STA $0000,x ;$BB8F5D | - INX ;$BB8F60 | - DEC $3C ;$BB8F61 | - BNE CODE_BB8F5D ;$BB8F63 | - JMP CODE_BB8E02 ;$BB8F65 / - -CODE_BB8F68: - LDA [$34],y ;$BB8F68 \ - INY ;$BB8F6A | - STA $42 ;$BB8F6B | - LDA [$42] ;$BB8F6D | - ADC #$03 ;$BB8F6F | - STA $3C ;$BB8F71 | - LDA $53 ;$BB8F73 | -CODE_BB8F75: ; | - STA $0000,x ;$BB8F75 | - INX ;$BB8F78 | - DEC $3C ;$BB8F79 | - BNE CODE_BB8F75 ;$BB8F7B | - JMP CODE_BB8E1D ;$BB8F7D / - -CODE_BB8F80: - REP #$20 ;$BB8F80 \ - LDA $54 ;$BB8F82 | - STA $0000,x ;$BB8F84 | - INX ;$BB8F87 | - INX ;$BB8F88 | - SEP #$20 ;$BB8F89 | - JMP CODE_BB8E10 ;$BB8F8B / - -CODE_BB8F8E: - REP #$20 ;$BB8F8E \ - LDA $54 ;$BB8F90 | - STA $0000,x ;$BB8F92 | - INX ;$BB8F95 | - INX ;$BB8F96 | - SEP #$20 ;$BB8F97 | - JMP CODE_BB8E02 ;$BB8F99 / - -CODE_BB8F9C: - LDA $56 ;$BB8F9C \ - STA $0000,x ;$BB8F9E | - INX ;$BB8FA1 | - JMP CODE_BB8E10 ;$BB8FA2 / - -CODE_BB8FA5: - LDA $56 ;$BB8FA5 \ - STA $0000,x ;$BB8FA7 | - INX ;$BB8FAA | - JMP CODE_BB8E02 ;$BB8FAB / - -CODE_BB8FAE: - LDA $57 ;$BB8FAE \ - STA $0000,x ;$BB8FB0 | - INX ;$BB8FB3 | - JMP CODE_BB8E10 ;$BB8FB4 / - -CODE_BB8FB7: - LDA $57 ;$BB8FB7 \ - STA $0000,x ;$BB8FB9 | - INX ;$BB8FBC | - JMP CODE_BB8E02 ;$BB8FBD / - -CODE_BB8FC0: - PHY ;$BB8FC0 \ - LDA $46 ;$BB8FC1 | - AND #$0F ;$BB8FC3 | - ADC #$02 ;$BB8FC5 | - STA $3E ;$BB8FC7 | - REP #$20 ;$BB8FC9 | - TXA ;$BB8FCB | - SEC ;$BB8FCC | - SBC $3E ;$BB8FCD | - TAY ;$BB8FCF | - LDA $0000,y ;$BB8FD0 | - STA $0000,x ;$BB8FD3 | - INX ;$BB8FD6 | - INX ;$BB8FD7 | - SEP #$20 ;$BB8FD8 | - PLY ;$BB8FDA | - JMP CODE_BB8E02 ;$BB8FDB / - -CODE_BB8FDE: - LDA [$34],y ;$BB8FDE \ - INY ;$BB8FE0 | - STA $42 ;$BB8FE1 | - LDA [$42] ;$BB8FE3 | - ADC #$02 ;$BB8FE5 | - STA $3E ;$BB8FE7 | - PHY ;$BB8FE9 | - REP #$20 ;$BB8FEA | - TXA ;$BB8FEC | - SEC ;$BB8FED | - SBC $3E ;$BB8FEE | - TAY ;$BB8FF0 | - LDA $0000,y ;$BB8FF1 | - STA $0000,x ;$BB8FF4 | - INX ;$BB8FF7 | - INX ;$BB8FF8 | - SEP #$20 ;$BB8FF9 | - PLY ;$BB8FFB | - JMP CODE_BB8E1D ;$BB8FFC / - -CODE_BB8FFF: - LDA $46 ;$BB8FFF \ - AND #$0F ;$BB9001 | - ADC #$03 ;$BB9003 | - STA $3C ;$BB9005 | - LDA [$34],y ;$BB9007 | - STA $3E ;$BB9009 | - INY ;$BB900B | - PHY ;$BB900C | - REP #$20 ;$BB900D | - TXA ;$BB900F | - SEC ;$BB9010 | - SBC $3C ;$BB9011 | - SEC ;$BB9013 | - SBC $3E ;$BB9014 | - TAY ;$BB9016 | - SEP #$20 ;$BB9017 | -CODE_BB9019: ; | - LDA $0000,y ;$BB9019 | - INY ;$BB901C | - STA $0000,x ;$BB901D | - INX ;$BB9020 | - DEC $3C ;$BB9021 | - BNE CODE_BB9019 ;$BB9023 | - PLY ;$BB9025 | - JMP CODE_BB8E02 ;$BB9026 / - -CODE_BB9029: - LDA [$34],y ;$BB9029 \ - INY ;$BB902B | - STA $42 ;$BB902C | - STA $46 ;$BB902E | - LDA [$42] ;$BB9030 | - ADC #$03 ;$BB9032 | - STA $3C ;$BB9034 | - LDA [$46] ;$BB9036 | - STA $3E ;$BB9038 | - LDA [$34],y ;$BB903A | - INY ;$BB903C | - STA $42 ;$BB903D | - LDA [$42] ;$BB903F | - ORA $3E ;$BB9041 | - STA $3E ;$BB9043 | - PHY ;$BB9045 | - REP #$20 ;$BB9046 | - TXA ;$BB9048 | - SEC ;$BB9049 | - SBC $3C ;$BB904A | - SEC ;$BB904C | - SBC $3E ;$BB904D | - TAY ;$BB904F | - SEP #$20 ;$BB9050 | -CODE_BB9052: ; | - LDA $0000,y ;$BB9052 | - INY ;$BB9055 | - STA $0000,x ;$BB9056 | - INX ;$BB9059 | - DEC $3C ;$BB905A | - BNE CODE_BB9052 ;$BB905C | - PLY ;$BB905E | - JMP CODE_BB8E1D ;$BB905F / - -CODE_BB9062: - LDA $46 ;$BB9062 \ - AND #$0F ;$BB9064 | - ADC #$03 ;$BB9066 | - STA $3C ;$BB9068 | - LDA [$34],y ;$BB906A | - INY ;$BB906C | - XBA ;$BB906D | - LDA [$34],y ;$BB906E | - INY ;$BB9070 | - STA $46 ;$BB9071 | - REP #$20 ;$BB9073 | - LSR A ;$BB9075 | - LSR A ;$BB9076 | - LSR A ;$BB9077 | - LSR A ;$BB9078 | - CLC ;$BB9079 | - ADC #$0103 ;$BB907A | - STA $40 ;$BB907D | - PHY ;$BB907F | - TXA ;$BB9080 | - SEC ;$BB9081 | - SBC $40 ;$BB9082 | - TAY ;$BB9084 | - SEP #$20 ;$BB9085 | -CODE_BB9087: ; | - LDA $0000,y ;$BB9087 | - INY ;$BB908A | - STA $0000,x ;$BB908B | - INX ;$BB908E | - DEC $3C ;$BB908F | - BNE CODE_BB9087 ;$BB9091 | - PLY ;$BB9093 | - JMP CODE_BB8E10 ;$BB9094 / - -CODE_BB9097: - LDA [$34],y ;$BB9097 \ - INY ;$BB9099 | - STA $42 ;$BB909A | - LDA [$42] ;$BB909C | - ADC #$03 ;$BB909E | - STA $3C ;$BB90A0 | - LDA $42 ;$BB90A2 | - AND #$0F ;$BB90A4 | - XBA ;$BB90A6 | - LDA [$34],y ;$BB90A7 | - INY ;$BB90A9 | - REP #$20 ;$BB90AA | - ADC #$0103 ;$BB90AC | - STA $40 ;$BB90AF | - PHY ;$BB90B1 | - TXA ;$BB90B2 | - SEC ;$BB90B3 | - SBC $40 ;$BB90B4 | - TAY ;$BB90B6 | - SEP #$20 ;$BB90B7 | -CODE_BB90B9: ; | - LDA $0000,y ;$BB90B9 | - INY ;$BB90BC | - STA $0000,x ;$BB90BD | - INX ;$BB90C0 | - DEC $3C ;$BB90C1 | - BNE CODE_BB90B9 ;$BB90C3 | - PLY ;$BB90C5 | - JMP CODE_BB8E02 ;$BB90C6 / - -CODE_BB90C9: - LDA $46 ;$BB90C9 \ - AND #$0F ;$BB90CB | - ADC #$03 ;$BB90CD | - STA $3C ;$BB90CF | - REP #$20 ;$BB90D1 | - LDA [$34],y ;$BB90D3 | - XBA ;$BB90D5 | - STA $40 ;$BB90D6 | - INY ;$BB90D8 | - INY ;$BB90D9 | - PHY ;$BB90DA | - TXA ;$BB90DB | - SEC ;$BB90DC | - SBC $40 ;$BB90DD | - TAY ;$BB90DF | - SEP #$20 ;$BB90E0 | -CODE_BB90E2: ; | - LDA $0000,y ;$BB90E2 | - INY ;$BB90E5 | - STA $0000,x ;$BB90E6 | - INX ;$BB90E9 | - DEC $3C ;$BB90EA | - BNE CODE_BB90E2 ;$BB90EC | - PLY ;$BB90EE | - JMP CODE_BB8E02 ;$BB90EF / - -CODE_BB90F2: - LDA [$34],y ;$BB90F2 \ - INY ;$BB90F4 | - STA $42 ;$BB90F5 | - LDA [$42] ;$BB90F7 | - ADC #$03 ;$BB90F9 | - STA $3C ;$BB90FB | - LDA $42 ;$BB90FD | - XBA ;$BB90FF | - LDA [$34],y ;$BB9100 | - INY ;$BB9102 | - REP #$20 ;$BB9103 | - ASL A ;$BB9105 | - ASL A ;$BB9106 | - ASL A ;$BB9107 | - ASL A ;$BB9108 | - STA $40 ;$BB9109 | - AND #$00FF ;$BB910B | - SEP #$20 ;$BB910E | - LDA [$34],y ;$BB9110 | - INY ;$BB9112 | - PHY ;$BB9113 | - STA $42 ;$BB9114 | - LDA [$42] ;$BB9116 | - REP #$20 ;$BB9118 | - AND #$000F ;$BB911A | - ORA $40 ;$BB911D | - STA $40 ;$BB911F | - TXA ;$BB9121 | - SEC ;$BB9122 | - SBC $40 ;$BB9123 | - TAY ;$BB9125 | - SEP #$20 ;$BB9126 | -CODE_BB9128: ; | - LDA $0000,y ;$BB9128 | - INY ;$BB912B | - STA $0000,x ;$BB912C | - INX ;$BB912F | - DEC $3C ;$BB9130 | - BNE CODE_BB9128 ;$BB9132 | - PLY ;$BB9134 | - JMP CODE_BB8E1D ;$BB9135 / - -CODE_BB9138: - DEX ;$BB9138 \ - LDA $0000,x ;$BB9139 | - STA $0001,x ;$BB913C | - INX ;$BB913F | - INX ;$BB9140 | - JMP CODE_BB8E10 ;$BB9141 / - -CODE_BB9144: - DEX ;$BB9144 \ - LDA $0000,x ;$BB9145 | - STA $0001,x ;$BB9148 | - INX ;$BB914B | - INX ;$BB914C | - JMP CODE_BB8E02 ;$BB914D / - -CODE_BB9150: - REP #$20 ;$BB9150 \ - DEX ;$BB9152 | - DEX ;$BB9153 | - LDA $0000,x ;$BB9154 | - STA $0002,x ;$BB9157 | - SEP #$20 ;$BB915A | - INX ;$BB915C | - INX ;$BB915D | - INX ;$BB915E | - INX ;$BB915F | - JMP CODE_BB8E10 ;$BB9160 / - -CODE_BB9163: - REP #$20 ;$BB9163 \ - DEX ;$BB9165 | - DEX ;$BB9166 | - LDA $0000,x ;$BB9167 | - STA $0002,x ;$BB916A | - SEP #$20 ;$BB916D | - INX ;$BB916F | - INX ;$BB9170 | - INX ;$BB9171 | - INX ;$BB9172 | - JMP CODE_BB8E02 ;$BB9173 / - -CODE_BB9176: - PHY ;$BB9176 \ - LDA $46 ;$BB9177 | - REP #$20 ;$BB9179 | - AND #$000F ;$BB917B | - ASL A ;$BB917E | - ADC #$0007 ;$BB917F | - TAY ;$BB9182 | - LDA [$34],y ;$BB9183 | - STA $0000,x ;$BB9185 | - SEP #$20 ;$BB9188 | - INX ;$BB918A | - INX ;$BB918B | - PLY ;$BB918C | - JMP CODE_BB8E02 ;$BB918D / - -CODE_BB9190: - LDA [$34],y ;$BB9190 \ - INY ;$BB9192 | - STA $46 ;$BB9193 | - REP #$20 ;$BB9195 | - AND #$00F0 ;$BB9197 | - LSR A ;$BB919A | - LSR A ;$BB919B | - LSR A ;$BB919C | - PHY ;$BB919D | - ADC #$0007 ;$BB919E | - TAY ;$BB91A1 | - LDA [$34],y ;$BB91A2 | - STA $0000,x ;$BB91A4 | - SEP #$20 ;$BB91A7 | - INX ;$BB91A9 | - INX ;$BB91AA | - PLY ;$BB91AB | - JMP CODE_BB8E10 ;$BB91AC / - -CODE_BB91AF: - LDY #$0100 ;$BB91AF \ - TDC ;$BB91B2 | - TAX ;$BB91B3 | - SEP #$20 ;$BB91B4 | -CODE_BB91B6: ; | - STA $7E2100,x ;$BB91B6 | - CLC ;$BB91BA | - ADC #$10 ;$BB91BB | - AND #$F0 ;$BB91BD | - INX ;$BB91BF | - DEY ;$BB91C0 | - BNE CODE_BB91B6 ;$BB91C1 | - LDY #$0100 ;$BB91C3 | + PEI ($4A) ;$BB8E1A | Push command address onto the stack + RTS ;$BB8E1C / Return to execute command + ; +execute_command_set_2: ; + LDA $42 ;$BB8E1D \ Read next command byte + AND #$0F ;$BB8E1F |\ Command = (byte & 0xF0) >> 2 + ASL A ;$BB8E21 | | Range $3F-$7B + ASL A ;$BB8E22 | | + ADC #$3F ;$BB8E23 | | + STA $4A ;$BB8E25 |/ + PEI ($4A) ;$BB8E27 | Push command address onto the stack + RTS ;$BB8E29 / Return to execute command + ; +copy_or_return_1: ; \ + LDA $46 ;$BB8E2A |\ Read number of bytes to copy + AND #$0F ;$BB8E2C | | + BEQ finalize_decompression ;$BB8E2E |/ If zero bytes, conclude decompression + STA $3C ;$BB8E30 | Store number of bytes to copy +.copy_byte ; | + LDA [$34],y ;$BB8E32 |\ Direct copy of up to 16 bytes + INY ;$BB8E34 | | + STA $0000,x ;$BB8E35 | | + INX ;$BB8E38 | | + DEC $3C ;$BB8E39 | | + BNE .copy_byte ;$BB8E3B |/ + JMP execute_command_set_1 ;$BB8E3D / Read new command + ; +finalize_decompression: ; \ + REP #$20 ;$BB8E40 |\ Restore 16 bit A, data bank and Y + PLY ;$BB8E42 | | + PLB ;$BB8E43 |/ + TXA ;$BB8E44 |\ Calculate the number of decompressed bytes (stored in X) + SEC ;$BB8E45 | | X = X - destination (Where X as an operand is the destination offset) + SBC $38 ;$BB8E46 | | + TAX ;$BB8E48 |/ + LDA $32 ;$BB8E49 |\ Check if DMA should run + BMI .skip_DMA ;$BB8E4B |/ + LDA $58 ;$BB8E4D |\ This would be a be a DMA to VRAM + STA $2116 ;$BB8E4F | | However $32 is a constant and will always be skipped (0xFFFF) + LDA $38 ;$BB8E52 | | + STA $4302 ;$BB8E54 | | + LDA $3A ;$BB8E57 | | + STA $4304 ;$BB8E59 | | + STX $4305 ;$BB8E5C | | + LDA #$1801 ;$BB8E5F | | + STA $4300 ;$BB8E62 | | + SEP #$20 ;$BB8E65 | | + LDA #$01 ;$BB8E67 | | + STA $420B ;$BB8E69 | | + REP #$20 ;$BB8E6C |/ +.skip_DMA ; | + RTL ;$BB8E6E / Done with decompression + ; +copy_or_return_2: ; \ + LDA [$34],y ;$BB8E6F |\ Load next operand + INY ;$BB8E71 |/ + STA $42 ;$BB8E72 |\ Store in nibble lookup tables + STA $46 ;$BB8E74 |/ + LDA [$42] ;$BB8E76 |\ Load number of bytes to write + BEQ finalize_decompression ;$BB8E78 | | If zero bytes, conclude decompression + STA $3C ;$BB8E7A |/ Store number of bytes to write +.copy_byte ; | + LDA [$46] ;$BB8E7C |\ operand2 = high byte + STA $3E ;$BB8E7E |/ + LDA [$34],y ;$BB8E80 |\ Load next operand + INY ;$BB8E82 |/ + STA $42 ;$BB8E83 |\ Store in nibble lookup tables + STA $46 ;$BB8E85 |/ + LDA $3E ;$BB8E87 | Load operand2 + ORA [$42] ;$BB8E89 |\ write operand2 | low nibble + STA $0000,x ;$BB8E8B |/ + INX ;$BB8E8E |\ Continue until no there are no more bytes + DEC $3C ;$BB8E8F | | + BNE .copy_byte ;$BB8E91 |/ + JMP execute_command_set_2_wide ;$BB8E93 / Run next command + ; +stream_byte_1: ; \ + LDA [$46] ;$BB8E96 |\ Load operand high nibble + STA $3E ;$BB8E98 |/ + LDA [$34],y ;$BB8E9A |\ Load next operand + INY ;$BB8E9C | | + STA $42 ;$BB8E9D |/ + LDA $3E ;$BB8E9F | Load operand high nibble + ORA [$42] ;$BB8EA1 |\ write high nibble | low nibble + STA $0000,x ;$BB8EA3 | | + INX ;$BB8EA6 |/ + JMP execute_command_set_2 ;$BB8EA7 / Run next command + ; +stream_byte_2: ; \ + LDA [$34],y ;$BB8EAA |\ Copy one byte from the compression stream + INY ;$BB8EAC | | + STA $0000,x ;$BB8EAD | | + INX ;$BB8EB0 |/ + JMP execute_command_set_1 ;$BB8EB1 / Run next command + ; +stream_word_1: ; \ + LDA [$46] ;$BB8EB4 |\ Load operand high nibble into operand2 + STA $3E ;$BB8EB6 |/ + LDA [$34],y ;$BB8EB8 |\ Load next operand + INY ;$BB8EBA |/ + STA $42 ;$BB8EBB |\ Store in nibble lookup tables + STA $46 ;$BB8EBD |/ + LDA $3E ;$BB8EBF | Load operand2 + ORA [$42] ;$BB8EC1 |\ write operand2 | low nibble + STA $0000,x ;$BB8EC3 | | + INX ;$BB8EC6 |/ + LDA [$46] ;$BB8EC7 |\ Load operand high nibble into operand2 + STA $3E ;$BB8EC9 |/ + LDA [$34],y ;$BB8ECB |\ Load next operand + INY ;$BB8ECD |/ + STA $42 ;$BB8ECE | Store in low nibble lookup table + LDA $3E ;$BB8ED0 | Load operand2 + ORA [$42] ;$BB8ED2 |\ write operand2 | low nibble + STA $0000,x ;$BB8ED4 | | + INX ;$BB8ED7 |/ + JMP execute_command_set_2 ;$BB8ED8 / Run next command + ; +stream_word_2: ; \ + REP #$20 ;$BB8EDB |\ Copy one word from the compression stream + LDA [$34],y ;$BB8EDD | | + STA $0000,x ;$BB8EDF | | + INY ;$BB8EE2 | | + INY ;$BB8EE3 | | + INX ;$BB8EE4 | | + INX ;$BB8EE5 | | + SEP #$20 ;$BB8EE6 |/ + JMP execute_command_set_1 ;$BB8EE8 / Run next command + ; +stream_byte_fill_1: ; \ + LDA $46 ;$BB8EEB |\ Load operand + AND #$0F ;$BB8EED | | Count = operand & 0x0F + 3 + ADC #$03 ;$BB8EEF | | + STA $3C ;$BB8EF1 |/ + LDA [$34],y ;$BB8EF3 |\ Load fill byte + INY ;$BB8EF5 |/ +.fill_byte ; | + STA $0000,x ;$BB8EF6 |\ Store and repeat with fill byte. + INX ;$BB8EF9 | | + DEC $3C ;$BB8EFA | | + BNE .fill_byte ;$BB8EFC |/ + JMP execute_command_set_1 ;$BB8EFE / Run next command + ; +stream_byte_fill_2: ; \ + LDA [$34],y ;$BB8F01 |\ Load next operand + INY ;$BB8F03 |/ + STA $42 ;$BB8F04 |\ Store in nibble lookup tables + STA $46 ;$BB8F06 |/ + LDA [$42] ;$BB8F08 |\ Count = low nibble + 3 + ADC #$03 ;$BB8F0A | | + STA $3C ;$BB8F0C |/ + LDA [$46] ;$BB8F0E |\ Operand2 = high nibble + STA $3E ;$BB8F10 |/ + LDA [$34],y ;$BB8F12 |\ Load next operand + INY ;$BB8F14 | | + STA $42 ;$BB8F15 |/ Store low nibble look up + LDA $3E ;$BB8F17 |\ Load operand2 + ORA [$42] ;$BB8F19 |/ fill byte = operand2 | low nibble +.fill_byte ; | + STA $0000,x ;$BB8F1B |\ Store and repeat with fill byte. + INX ;$BB8F1E | | + DEC $3C ;$BB8F1F | | + BNE .fill_byte ;$BB8F21 |/ + JMP execute_command_set_2 ;$BB8F23 / Run next command + ; +direct_byte_1_fill_1: ; \ + LDA $46 ;$BB8F26 |\ Load operand + AND #$0F ;$BB8F28 | | Count = operand & 0x0F + 3 + ADC #$03 ;$BB8F2A | | + STA $3C ;$BB8F2C |/ + LDA $52 ;$BB8F2E | Load fill byte 1 +.fill_byte ; | + STA $0000,x ;$BB8F30 |\ Store and repeat with fill byte. + INX ;$BB8F33 | | + DEC $3C ;$BB8F34 | | + BNE .fill_byte ;$BB8F36 |/ + JMP execute_command_set_1 ;$BB8F38 / Run next command + ; +direct_byte_1_fill_2: ; \ + LDA [$34],y ;$BB8F3B |\ Load next operand + INY ;$BB8F3D | | + STA $42 ;$BB8F3E |/ Store in low nibble lookup + LDA [$42] ;$BB8F40 |\ Count = low nibble + 3 + ADC #$03 ;$BB8F42 | | + STA $3C ;$BB8F44 |/ + LDA $52 ;$BB8F46 | Load fill byte 1 +.fill_byte ; | + STA $0000,x ;$BB8F48 |\ Store and repeat with fill byte. + INX ;$BB8F4B | | + DEC $3C ;$BB8F4C | | + BNE .fill_byte ;$BB8F4E |/ + JMP execute_command_set_2 ;$BB8F50 / Run next command + ; +direct_byte_2_fill_1: ; \ + LDA $46 ;$BB8F53 |\ Load operand + AND #$0F ;$BB8F55 | | Count = (operand & 0x0F) + 3 + ADC #$03 ;$BB8F57 | | + STA $3C ;$BB8F59 |/ + LDA $53 ;$BB8F5B | Load fill byte 2 +.fill_byte ; | + STA $0000,x ;$BB8F5D |\ Store and repeat with fill byte. + INX ;$BB8F60 | | + DEC $3C ;$BB8F61 | | + BNE .fill_byte ;$BB8F63 |/ + JMP execute_command_set_1 ;$BB8F65 / Run next command + ; +direct_byte_2_fill_2: ; \ + LDA [$34],y ;$BB8F68 |\ Load next operand + INY ;$BB8F6A | | + STA $42 ;$BB8F6B |/ Store in low nibble lookup + LDA [$42] ;$BB8F6D |\ Count = low nibble + 3 + ADC #$03 ;$BB8F6F | | + STA $3C ;$BB8F71 |/ + LDA $53 ;$BB8F73 | Load fill byte 2 +.fill_byte ; | + STA $0000,x ;$BB8F75 |\ Store and repeat with fill byte. + INX ;$BB8F78 | | + DEC $3C ;$BB8F79 | | + BNE .fill_byte ;$BB8F7B |/ + JMP execute_command_set_2 ;$BB8F7D / Run next command + ; +direct_word_put_1: ; \ + REP #$20 ;$BB8F80 |\ Store direct word + LDA $54 ;$BB8F82 | | + STA $0000,x ;$BB8F84 | | + INX ;$BB8F87 | | + INX ;$BB8F88 | | + SEP #$20 ;$BB8F89 |/ + JMP execute_command_set_2_wide ;$BB8F8B / Run next command + ; +direct_word_put_2: ; \ + REP #$20 ;$BB8F8E |\ Store direct word + LDA $54 ;$BB8F90 | | + STA $0000,x ;$BB8F92 | | + INX ;$BB8F95 | | + INX ;$BB8F96 | | + SEP #$20 ;$BB8F97 |/ + JMP execute_command_set_1 ;$BB8F99 / Run next command + ; +direct_byte_1_put_1: ; \ + LDA $56 ;$BB8F9C |\ Store direct byte 1 + STA $0000,x ;$BB8F9E | | + INX ;$BB8FA1 |/ + JMP execute_command_set_2_wide ;$BB8FA2 / Run next command + ; +direct_byte_1_put_2: ; \ + LDA $56 ;$BB8FA5 |\ Store direct byte 1 + STA $0000,x ;$BB8FA7 | | + INX ;$BB8FAA |/ + JMP execute_command_set_1 ;$BB8FAB / Run next command + ; +direct_byte_2_put_1: ; \ + LDA $57 ;$BB8FAE |\ Store direct byte 2 + STA $0000,x ;$BB8FB0 | | + INX ;$BB8FB3 |/ + JMP execute_command_set_2_wide ;$BB8FB4 / Run next command + ; +direct_byte_2_put_2: ; \ + LDA $57 ;$BB8FB7 |\ Store direct byte 2 + STA $0000,x ;$BB8FB9 | | + INX ;$BB8FBC |/ + JMP execute_command_set_1 ;$BB8FBD / Run next command + ; +back_copy_word_1: ; + PHY ;$BB8FC0 \ Preserve compression index + LDA $46 ;$BB8FC1 | Load operand + AND #$0F ;$BB8FC3 |\ Offset = (operand & 0x0F) + 2 + ADC #$02 ;$BB8FC5 | | + STA $3E ;$BB8FC7 |/ + REP #$20 ;$BB8FC9 |\ Prepare to copy (1 word) from a previous point in decompressed data + TXA ;$BB8FCB | | The new offset is stored in Y + SEC ;$BB8FCC | | Y = X - offset + SBC $3E ;$BB8FCD | | + TAY ;$BB8FCF |/ + LDA $0000,y ;$BB8FD0 |\ Copy from previous data + STA $0000,x ;$BB8FD3 | | + INX ;$BB8FD6 | | + INX ;$BB8FD7 |/ + SEP #$20 ;$BB8FD8 | Return to 8 bit A + PLY ;$BB8FDA | Restore compression index + JMP execute_command_set_1 ;$BB8FDB / Run next command + ; +back_copy_word_2: ; \ + LDA [$34],y ;$BB8FDE |\ Load next operand + INY ;$BB8FE0 | | + STA $42 ;$BB8FE1 |/ + LDA [$42] ;$BB8FE3 |\ Offset = low nibble + 2 + ADC #$02 ;$BB8FE5 | | + STA $3E ;$BB8FE7 |/ + PHY ;$BB8FE9 | Preserve compression index + REP #$20 ;$BB8FEA |\ Prepare to copy (1 word) from a previous point in decompressed data + TXA ;$BB8FEC | | The new offset is stored in Y + SEC ;$BB8FED | | Y = X - offset + SBC $3E ;$BB8FEE | | + TAY ;$BB8FF0 |/ + LDA $0000,y ;$BB8FF1 |\ Copy from previous data + STA $0000,x ;$BB8FF4 | | + INX ;$BB8FF7 | | + INX ;$BB8FF8 |/ + SEP #$20 ;$BB8FF9 | Return to 8 bit A + PLY ;$BB8FFB | Restore compression index + JMP execute_command_set_2 ;$BB8FFC / Run next command + ; +back_copy_1: ; + LDA $46 ;$BB8FFF \ Load next operand + AND #$0F ;$BB9001 |\ Count = (operand & 0x0F) + 3 + ADC #$03 ;$BB9003 | | + STA $3C ;$BB9005 |/ + LDA [$34],y ;$BB9007 |\ Load next operand + STA $3E ;$BB9009 | | + INY ;$BB900B |/ + PHY ;$BB900C | Preserve compression index + REP #$20 ;$BB900D |\ Prepare to copy from a previous point in decompressed data + TXA ;$BB900F | | The new offset is stored in Y + SEC ;$BB9010 | | Y = X - count - offset + SBC $3C ;$BB9011 | | + SEC ;$BB9013 | | + SBC $3E ;$BB9014 | | + TAY ;$BB9016 |/ + SEP #$20 ;$BB9017 | Back to 8 bit A +.byte_copy ; | + LDA $0000,y ;$BB9019 |\ Copy from previous data + INY ;$BB901C | | + STA $0000,x ;$BB901D | | + INX ;$BB9020 |/ + DEC $3C ;$BB9021 |\ Copy count number of bytes + BNE .byte_copy ;$BB9023 |/ + PLY ;$BB9025 | Restore compression index + JMP execute_command_set_1 ;$BB9026 / Run next command + ; +back_copy_2: ; \ + LDA [$34],y ;$BB9029 |\ Load next operand + INY ;$BB902B |/ + STA $42 ;$BB902C |\ Store in nibble look up tables + STA $46 ;$BB902E |/ + LDA [$42] ;$BB9030 |\ Count = low nibble + 3 + ADC #$03 ;$BB9032 | | + STA $3C ;$BB9034 |/ + LDA [$46] ;$BB9036 |\ Store high nibble in offset + STA $3E ;$BB9038 |/ + LDA [$34],y ;$BB903A |\ Load next operand and store in the low nibble lookup + INY ;$BB903C | | + STA $42 ;$BB903D |/ + LDA [$42] ;$BB903F |\ offset = low nibble | offset + ORA $3E ;$BB9041 | | + STA $3E ;$BB9043 |/ + PHY ;$BB9045 | Preserve compression index + REP #$20 ;$BB9046 |\ Prepare to copy from a previous point in decompressed data + TXA ;$BB9048 | | The new offset is stored in Y + SEC ;$BB9049 | | Y = X - count - offset + SBC $3C ;$BB904A | | + SEC ;$BB904C | | + SBC $3E ;$BB904D | | + TAY ;$BB904F |/ + SEP #$20 ;$BB9050 | Back to 8 bit A +.byte_copy ; | + LDA $0000,y ;$BB9052 |\ Copy from previous data + INY ;$BB9055 | | + STA $0000,x ;$BB9056 | | + INX ;$BB9059 |/ + DEC $3C ;$BB905A |\ Copy count number of bytes + BNE .byte_copy ;$BB905C |/ + PLY ;$BB905E | Restore compression index + JMP execute_command_set_2 ;$BB905F / Run next command + ; +back_copy_far_1: ; + LDA $46 ;$BB9062 \ Load next operand + AND #$0F ;$BB9064 |\ Count = (operand & 0x0F) + 3 + ADC #$03 ;$BB9066 | | + STA $3C ;$BB9068 |/ + LDA [$34],y ;$BB906A |\ Load next operand + INY ;$BB906C | | + XBA ;$BB906D |/ Store as high byte for the full operand + LDA [$34],y ;$BB906E |\ Load next operand store in high byte look up + INY ;$BB9070 | | + STA $46 ;$BB9071 |/ + REP #$20 ;$BB9073 | Switch to 16 bit A + LSR A ;$BB9075 |\ Offset = (operand >> 4) + 0x0103 + LSR A ;$BB9076 | | + LSR A ;$BB9077 | | + LSR A ;$BB9078 | | + CLC ;$BB9079 | | + ADC #$0103 ;$BB907A | | + STA $40 ;$BB907D |/ + PHY ;$BB907F | Preserve compression index + TXA ;$BB9080 |\ Prepare to copy from a previous point in decompressed data + SEC ;$BB9081 | | Y = X - offset + SBC $40 ;$BB9082 | | + TAY ;$BB9084 |/ + SEP #$20 ;$BB9085 | Back to 8 bit A +.byte_copy ; | + LDA $0000,y ;$BB9087 |\ Copy from previous data + INY ;$BB908A | | + STA $0000,x ;$BB908B | | + INX ;$BB908E |/ + DEC $3C ;$BB908F |\ Copy count number of bytes + BNE .byte_copy ;$BB9091 |/ + PLY ;$BB9093 | Restore compression index + JMP execute_command_set_2_wide ;$BB9094 / Run next command + ; +back_copy_far_2: ; \ + LDA [$34],y ;$BB9097 |\ Load next operand + INY ;$BB9099 | | + STA $42 ;$BB909A |/ Store in low nibble look up table + LDA [$42] ;$BB909C |\ Count = low nibble + 3 + ADC #$03 ;$BB909E | | + STA $3C ;$BB90A0 |/ + LDA $42 ;$BB90A2 |\ Copy the low nibble to the operand high byte + AND #$0F ;$BB90A4 | | + XBA ;$BB90A6 |/ + LDA [$34],y ;$BB90A7 |\ Load the operand low byte + INY ;$BB90A9 |/ + REP #$20 ;$BB90AA |\ Offset = operand + 0x0103 + ADC #$0103 ;$BB90AC | | + STA $40 ;$BB90AF |/ + PHY ;$BB90B1 | Preserve compression index + TXA ;$BB90B2 |\ Prepare to copy from a previous point in decompressed data + SEC ;$BB90B3 | | Y = X - offset + SBC $40 ;$BB90B4 | | + TAY ;$BB90B6 |/ + SEP #$20 ;$BB90B7 | Back to 8 bit A +.byte_copy ; | + LDA $0000,y ;$BB90B9 |\ Copy from previous data + INY ;$BB90BC | | + STA $0000,x ;$BB90BD | | + INX ;$BB90C0 |/ + DEC $3C ;$BB90C1 |\ Copy count number of bytes + BNE .byte_copy ;$BB90C3 |/ + PLY ;$BB90C5 | Restore compression index + JMP execute_command_set_1 ;$BB90C6 / Run next command + ; +back_copy_arbitrary_1: ; + LDA $46 ;$BB90C9 \ Load next operand + AND #$0F ;$BB90CB |\ Count = (operand & 0x0F) + 3 + ADC #$03 ;$BB90CD | | + STA $3C ;$BB90CF |/ + REP #$20 ;$BB90D1 |\ Read a big endian word for the offset + LDA [$34],y ;$BB90D3 | | + XBA ;$BB90D5 | | + STA $40 ;$BB90D6 |/ + INY ;$BB90D8 |\ Increment the compression index + INY ;$BB90D9 |/ + PHY ;$BB90DA | Preserve compression index + TXA ;$BB90DB |\ Prepare to copy from a previous point in decompressed data + SEC ;$BB90DC | | Y = X - offset + SBC $40 ;$BB90DD | | + TAY ;$BB90DF |/ + SEP #$20 ;$BB90E0 | Back to 8 bit A +.byte_copy ; | + LDA $0000,y ;$BB90E2 |\ Copy from previous data + INY ;$BB90E5 | | + STA $0000,x ;$BB90E6 | | + INX ;$BB90E9 |/ + DEC $3C ;$BB90EA |\ Copy count number of bytes + BNE .byte_copy ;$BB90EC |/ + PLY ;$BB90EE | Restore compression index + JMP execute_command_set_1 ;$BB90EF / Run next command + ; +back_copy_arbitrary_2: ; \ + LDA [$34],y ;$BB90F2 |\ Load next operand + INY ;$BB90F4 | | + STA $42 ;$BB90F5 |/ Store in low nibble look up table + LDA [$42] ;$BB90F7 |\ Count = low nibble + 3 + ADC #$03 ;$BB90F9 | | + STA $3C ;$BB90FB |/ + LDA $42 ;$BB90FD |\ Copy as the operand high byte + XBA ;$BB90FF |/ + LDA [$34],y ;$BB9100 |\ Load the operand low byte + INY ;$BB9102 |/ + REP #$20 ;$BB9103 | Set A to 16 bit + ASL A ;$BB9105 |\ Offset = (operand << 4) + ASL A ;$BB9106 | | + ASL A ;$BB9107 | | + ASL A ;$BB9108 | | + STA $40 ;$BB9109 |/ + AND #$00FF ;$BB910B | Clear the high byte of the offset + SEP #$20 ;$BB910E | Resume 8 bit A + LDA [$34],y ;$BB9110 |\ Load next operand + INY ;$BB9112 |/ + PHY ;$BB9113 | Preserve compression index + STA $42 ;$BB9114 | Store the operand in the low nibble look up table + LDA [$42] ;$BB9116 |\ Load low nibble + REP #$20 ;$BB9118 | | + AND #$000F ;$BB911A |/ + ORA $40 ;$BB911D |\ offset = offset | low nibble + STA $40 ;$BB911F |/ + TXA ;$BB9121 |\ Prepare to copy from a previous point in decompressed data + SEC ;$BB9122 | | Y = X - offset + SBC $40 ;$BB9123 | | + TAY ;$BB9125 |/ + SEP #$20 ;$BB9126 | Back to 8 bit A +.copy_byte ; | + LDA $0000,y ;$BB9128 |\ Copy from previous data + INY ;$BB912B | | + STA $0000,x ;$BB912C | | + INX ;$BB912F |/ + DEC $3C ;$BB9130 |\ Copy count number of bytes + BNE .copy_byte ;$BB9132 |/ + PLY ;$BB9134 | Restore compression index + JMP execute_command_set_2 ;$BB9135 / Run next command Run next command + ; +duplicate_byte_1: ; \ + DEX ;$BB9138 |\ Copy previous byte to the decompression stream + LDA $0000,x ;$BB9139 | | + STA $0001,x ;$BB913C | | + INX ;$BB913F | | + INX ;$BB9140 |/ + JMP execute_command_set_2_wide ;$BB9141 / Run next command + ; +duplicate_byte_2: ; \ + DEX ;$BB9144 |\ Copy previous byte to the decompression stream + LDA $0000,x ;$BB9145 | | + STA $0001,x ;$BB9148 | | + INX ;$BB914B | | + INX ;$BB914C |/ + JMP execute_command_set_1 ;$BB914D / Run next command + ; +duplicate_word_1: ; \ + REP #$20 ;$BB9150 |\ Copy the previous word to the decompression stream + DEX ;$BB9152 | | + DEX ;$BB9153 | | First go back two bytes + LDA $0000,x ;$BB9154 | | + STA $0002,x ;$BB9157 | | + SEP #$20 ;$BB915A | | + INX ;$BB915C | | Then jump ahead four bytes + INX ;$BB915D | | + INX ;$BB915E | | + INX ;$BB915F |/ + JMP execute_command_set_2_wide ;$BB9160 / Run next command + ; +duplicate_word_2: ; \ + REP #$20 ;$BB9163 |\ Copy the previous word to the decompression stream + DEX ;$BB9165 | | + DEX ;$BB9166 | | First go back two bytes + LDA $0000,x ;$BB9167 | | + STA $0002,x ;$BB916A | | + SEP #$20 ;$BB916D | | + INX ;$BB916F | | Then jump ahead four bytes + INX ;$BB9170 | | + INX ;$BB9171 | | + INX ;$BB9172 |/ + JMP execute_command_set_1 ;$BB9173 / Run next command + ; +copy_future_word_1: ; + PHY ;$BB9176 \ Preserve compression index + LDA $46 ;$BB9177 | Load next operand + REP #$20 ;$BB9179 | Set A to 16 bit + AND #$000F ;$BB917B |\ Y = (operand << 1) + 7 + ASL A ;$BB917E | | + ADC #$0007 ;$BB917F | | + TAY ;$BB9182 |/ + LDA [$34],y ;$BB9183 |\ Copy word from compression stream to the decompression stream + STA $0000,x ;$BB9185 |/ + SEP #$20 ;$BB9188 |\ Return to 8 bit A and increment the decompression index + INX ;$BB918A | | + INX ;$BB918B |/ + PLY ;$BB918C | Restore compression index + JMP execute_command_set_1 ;$BB918D / Run next command + ; +copy_future_word_2: ; \ + LDA [$34],y ;$BB9190 |\ Load next operand + INY ;$BB9192 | | + STA $46 ;$BB9193 |/ Store to high nibble look up table + REP #$20 ;$BB9195 | Set A to 16 bit + AND #$00F0 ;$BB9197 |\ Operand = operand >> 3 + LSR A ;$BB919A | | + LSR A ;$BB919B | | + LSR A ;$BB919C |/ + PHY ;$BB919D | Preserve compression index + ADC #$0007 ;$BB919E |\ Y = operand + 7 + TAY ;$BB91A1 |/ + LDA [$34],y ;$BB91A2 |\ Copy word from compression stream to the decompression stream + STA $0000,x ;$BB91A4 |/ + SEP #$20 ;$BB91A7 |\ Return to 8 bit A and increment the decompression index + INX ;$BB91A9 | | + INX ;$BB91AA |/ + PLY ;$BB91AB | Restore compression index + JMP execute_command_set_2_wide ;$BB91AC / Run next command + ; +build_decompression_lookup: ; + LDY #$0100 ;$BB91AF \ Prepare to generate the high nibble table + TDC ;$BB91B2 |\ Zero A and X and set 8 bit A + TAX ;$BB91B3 | | + SEP #$20 ;$BB91B4 |/ +.build_high_nibble ; | + STA $7E2100,x ;$BB91B6 |\ Store look up value (index & 0x0F) << 4 + CLC ;$BB91BA | | + ADC #$10 ;$BB91BB | | + AND #$F0 ;$BB91BD |/ + INX ;$BB91BF |\ Loop through all 256 values + DEY ;$BB91C0 | | + BNE .build_high_nibble ;$BB91C1 |/ + LDY #$0100 ;$BB91C3 | Prepare to generate the low nibble table LDX #$0000 ;$BB91C6 | -CODE_BB91C9: ; | - TXA ;$BB91C9 | - LSR A ;$BB91CA | - LSR A ;$BB91CB | - LSR A ;$BB91CC | - LSR A ;$BB91CD | - STA $7E2000,x ;$BB91CE | - INX ;$BB91D2 | - DEY ;$BB91D3 | - BNE CODE_BB91C9 ;$BB91D4 | - REP #$20 ;$BB91D6 | - RTL ;$BB91D8 / +.build_low_nibble ; | + TXA ;$BB91C9 |\ Store look up value (index >> 4) + LSR A ;$BB91CA | | + LSR A ;$BB91CB | | + LSR A ;$BB91CC | | + LSR A ;$BB91CD | | + STA $7E2000,x ;$BB91CE |/ + INX ;$BB91D2 |\ Loop through all 256 values + DEY ;$BB91D3 | | + BNE .build_low_nibble ;$BB91D4 |/ + REP #$20 ;$BB91D6 | Return to 16 bit A + RTL ;$BB91D8 / Done -CODE_BB91D9: +disable_screen: SEP #$20 ;$BB91D9 \ - LDA #$00 ;$BB91DB | - STA $00420C ;$BB91DD | - LDA #$01 ;$BB91E1 | - STA $004200 ;$BB91E3 | - LDA #$8F ;$BB91E7 | - STA $002100 ;$BB91E9 | + LDA #$00 ;$BB91DB |\ Disable HDMA + STA $00420C ;$BB91DD |/ + LDA #$01 ;$BB91E1 |\ Turn on autojoy, turn on NMI + STA $004200 ;$BB91E3 |/ + LDA #$8F ;$BB91E7 |\ Enable f-blank + STA $002100 ;$BB91E9 |/ REP #$20 ;$BB91ED | - LDA #$0000 ;$BB91EF | - STA $00059B ;$BB91F2 | + LDA #$0000 ;$BB91EF |\ Disable OAM DMA + STA $00059B ;$BB91F2 |/ RTL ;$BB91F6 / CODE_BB91F7: @@ -2824,7 +2882,7 @@ CODE_BB92C9: ; | AND #$00FF ;$BB92E7 | TAY ;$BB92EA | LDA #$1000 ;$BB92EB | - JSL CODE_BB8D91 ;$BB92EE | + JSL decompress_data ;$BB92EE | LDA #$1000 ;$BB92F2 | STA $98 ;$BB92F5 | SEP #$20 ;$BB92F7 | @@ -3206,7 +3264,7 @@ CODE_BB966F: LDX #DATA_E98B07 ;$BB9694 | LDY.w #DATA_E98B07>>16 ;$BB9697 | LDA #$F800 ;$BB969A | - JSL CODE_BB8D91 ;$BB969D | + JSL decompress_data ;$BB969D | LDA #$6000 ;$BB96A1 | STA $2116 ;$BB96A4 | LDX #$0000 ;$BB96A7 | @@ -3463,7 +3521,7 @@ CODE_BB98E8: LDX #DATA_C2FAC9 ;$BB9910 | LDY.w #DATA_C2FAC9>>16 ;$BB9913 | LDA #$F800 ;$BB9916 | - JSL CODE_BB8D91 ;$BB9919 | + JSL decompress_data ;$BB9919 | LDA #$7000 ;$BB991D | STA $2116 ;$BB9920 | LDY #$02FE ;$BB9923 | @@ -3486,7 +3544,7 @@ CODE_BB9926: ; | LDX #DATA_C6FC11 ;$BB994C | LDY.w #DATA_C6FC11>>16 ;$BB994F | LDA #$F800 ;$BB9952 | - JSL CODE_BB8D91 ;$BB9955 | + JSL decompress_data ;$BB9955 | LDA #$7400 ;$BB9959 | STA $2116 ;$BB995C | LDY #$02FE ;$BB995F | @@ -5916,7 +5974,7 @@ CODE_BBB227: LDA.l $0017B4 ;$BBB233 | SEC ;$BBB237 | SBC #$0000 ;$BBB238 | - JSL CODE_BB8D91 ;$BBB23B | + JSL decompress_data ;$BBB23B | BRA CODE_BBB225 ;$BBB23F / DATA_BBB241: diff --git a/compression.asm b/compression.asm index f182f33..30e2fbe 100644 --- a/compression.asm +++ b/compression.asm @@ -1,133 +1,133 @@ ;Command set 1 jump table -CODE_BB8000: - NOP - JMP CODE_BB8E2A - -CODE_BB8004: - NOP - JMP CODE_BB8E96 - -CODE_BB8008: - NOP - JMP CODE_BB8EB4 - -CODE_BB800C: - NOP - JMP CODE_BB8EEB - -CODE_BB8010: - NOP - JMP CODE_BB8F26 - -CODE_BB8014: - NOP - JMP CODE_BB8F53 - -CODE_BB8018: - NOP - JMP CODE_BB8F80 - -CODE_BB801C: - NOP - JMP CODE_BB8F9C - -CODE_BB8020: - NOP - JMP CODE_BB8FAE - -CODE_BB8024: - NOP - JMP CODE_BB8FC0 - -CODE_BB8028: - NOP - JMP CODE_BB8FFF - -CODE_BB802C: - NOP - JMP CODE_BB9062 - -CODE_BB8030: - NOP - JMP CODE_BB90C9 - -CODE_BB8034: - NOP - JMP CODE_BB9138 - -CODE_BB8038: - NOP - JMP CODE_BB9150 - -CODE_BB803C: - NOP - JMP CODE_BB9176 +copy_or_return_1_entry: + NOP ;$BB8000 \ Decompression command entry + JMP copy_or_return_1 ;$BB8001 / + +stream_byte_1_entry: + NOP ;$BB8004 \ Decompression command entry + JMP stream_byte_1 ;$BB8005 / + +stream_word_1_entry: + NOP ;$BB8008 \ Decompression command entry + JMP stream_word_1 ;$BB8009 / + +stream_byte_fill_1_entry: + NOP ;$BB800C \ Decompression command entry + JMP stream_byte_fill_1 ;$BB800D / + +direct_byte_1_fill_1_entry: + NOP ;$BB8010 \ Decompression command entry + JMP direct_byte_1_fill_1 ;$BB8011 / + +direct_byte_2_fill_1_entry: + NOP ;$BB8014 \ Decompression command entry + JMP direct_byte_2_fill_1 ;$BB8015 / + +direct_word_put_1_entry: + NOP ;$BB8018 \ Decompression command entry + JMP direct_word_put_1 ;$BB8019 / + +direct_byte_1_put_1_entry: + NOP ;$BB801C \ Decompression command entry + JMP direct_byte_1_put_1 ;$BB801D / + +direct_byte_2_put_1_entry: + NOP ;$BB8020 \ Decompression command entry + JMP direct_byte_2_put_1 ;$BB8021 / + +back_copy_word_1_entry: + NOP ;$BB8024 \ Decompression command entry + JMP back_copy_word_1 ;$BB8025 / + +back_copy_1_entry: + NOP ;$BB8028 \ Decompression command entry + JMP back_copy_1 ;$BB8029 / + +back_copy_far_1_entry: + NOP ;$BB802C \ Decompression command entry + JMP back_copy_far_1 ;$BB802D / + +back_copy_arbitrary_1_entry: + NOP ;$BB8030 \ Decompression command entry + JMP back_copy_arbitrary_1 ;$BB8031 / + +duplicate_byte_1_entry: + NOP ;$BB8034 \ Decompression command entry + JMP duplicate_byte_1 ;$BB8035 / + +duplicate_word_1_entry: + NOP ;$BB8038 \ Decompression command entry + JMP duplicate_word_1 ;$BB8039 / + +copy_future_word_1_entry: + NOP ;$BB803C \ Decompression command entry + JMP copy_future_word_1 ;$BB803D / ;Command set 2 jump table -CODE_BB8040: - JMP CODE_BB8E6F - -CODE_BB8043: - NOP - JMP CODE_BB8EAA - -CODE_BB8047: - NOP - JMP CODE_BB8EDB - -CODE_BB804B: - NOP - JMP CODE_BB8F01 - -CODE_BB804F: - NOP - JMP CODE_BB8F3B - -CODE_BB8053: - NOP - JMP CODE_BB8F68 - -CODE_BB8057: - NOP - JMP CODE_BB8F8E - -CODE_BB805B: - NOP - JMP CODE_BB8FA5 - -CODE_BB805F: - NOP - JMP CODE_BB8FB7 - -CODE_BB8063: - NOP - JMP CODE_BB8FDE - -CODE_BB8067: - NOP - JMP CODE_BB9029 - -CODE_BB806B: - NOP - JMP CODE_BB9097 - -CODE_BB806F: - NOP - JMP CODE_BB90F2 - -CODE_BB8073: - NOP - JMP CODE_BB9144 - -CODE_BB8077: - NOP - JMP CODE_BB9163 - -CODE_BB807B: - NOP - JMP CODE_BB9190 - - +copy_or_return_2_entry: + JMP copy_or_return_2 ;$BB8040 > Decompression command entry + +stream_byte_2_entry: + NOP ;$BB8043 \ Decompression command entry + JMP stream_byte_2 ;$BB8044 / + +stream_word_2_entry: + NOP ;$BB8047 \ Decompression command entry + JMP stream_word_2 ;$BB8048 / + +stream_byte_fill_2_entry: + NOP ;$BB804B \ Decompression command entry + JMP stream_byte_fill_2 ;$BB804C / + +direct_byte_1_fill_2_entry: + NOP ;$BB804F \ Decompression command entry + JMP direct_byte_1_fill_2 ;$BB8050 / + +direct_byte_2_fill_2_entry: + NOP ;$BB8053 \ Decompression command entry + JMP direct_byte_2_fill_2 ;$BB8054 / + +direct_word_put_2_entry: + NOP ;$BB8057 \ Decompression command entry + JMP direct_word_put_2 ;$BB8058 / + +direct_byte_1_put_2_entry: + NOP ;$BB805B \ Decompression command entry + JMP direct_byte_1_put_2 ;$BB805C / + +direct_byte_2_put_2_entry: + NOP ;$BB805F \ Decompression command entry + JMP direct_byte_2_put_2 ;$BB8060 / + +back_copy_word_2_entry: + NOP ;$BB8063 \ Decompression command entry + JMP back_copy_word_2 ;$BB8064 / + +back_copy_2_entry: + NOP ;$BB8067 \ Decompression command entry + JMP back_copy_2 ;$BB8068 / + +back_copy_far_2_entry: + NOP ;$BB806B \ Decompression command entry + JMP back_copy_far_2 ;$BB806C / + +back_copy_arbitrary_2_entry: + NOP ;$BB806F \ Decompression command entry + JMP back_copy_arbitrary_2 ;$BB8070 / + +duplicate_byte_2_entry: + NOP ;$BB8073 \ Decompression command entry + JMP duplicate_byte_2 ;$BB8074 / + +duplicate_word_2_entry: + NOP ;$BB8077 \ Decompression command entry + JMP duplicate_word_2 ;$BB8078 / + +copy_future_word_2_entry: + NOP ;$BB807B \ Decompression command entry + JMP copy_future_word_2 ;$BB807C / + + ;$38 -- destination ;$34 -- source ;$32 -- run dma after upload (always #$FFFF so never) @@ -150,686 +150,686 @@ CODE_BB807B: ;Extra notes ;All commands are return addresses - 1 so RTS can be used - -CODE_BB8D91: ; - STA $38 ;\ Set decompression parameters - LDA #$007F ; | - STA $3A ; | - STX $34 ; | - STY $36 ; | - BRA CODE_BB8DAE ;/ - ; -CODE_BB8D9E: ; - TXA ;\ Set decompression parameters - TYX ; | - STA $34 ; | - STX $36 ; | - LDA #$0000 ; | Default destination $7F0000 - STA $38 ; | - LDA #$007F ; | - STA $3A ;/ -CODE_BB8DAE: ; - LDA #$FFFF ;\ Disble auto DMA of data - STA $32 ;/ - PHB ;\ Preserve call bank/Y - PHY ;/ - LDA #$2100 ;\ Setup pointers to nibble look up tables - STA $46 ; | - LDA #$007E ; | - STA $48 ; | - STA $44 ; | - LDA #$2000 ; | - STA $42 ;/ - JSL CODE_BB91AF ; Generate nibble offset table at RAM $7E2000 - LDX $38 ; Load the decompression index - LDY #$0001 ; Load the compression index - LDA #$8001 ;\ Load default decompression function A 8001 - STA $4E ;/ The high byte will never change. - LDA #$8040 ;\ Load default decompression function B 8040 - STA $4A ;/ - SEP #$20 ; - LDA $3A ;\ Set the data bank to the destination bank - PHA ; | - PLB ;/ - LDA [$34],y ;\ Read fill byte 1 - STA $52 ; | - INY ;/ - LDA [$34],y ;\ Read fill byte 2 - STA $53 ; | - INY ;/ - LDA [$34],y ;\ Read direct byte 1 - STA $56 ; | - INY ;/ - LDA [$34],y ;\ Read direct byte 2 - STA $57 ; | - INY ;/ - REP #$20 ;\ Read direct word - LDA [$34],y ; | - STA $54 ;/ - LDY #$0027 ; Skip to compressed byte #$27 - STZ $3C ;\ Clear generic operand 1 - STZ $3E ;/ Clean generic operand 2 - SEP #$20 ; Return to 8 bit -CODE_BB8E02: ; - LDA [$34],y ;\ Read the first command byte - INY ; | - STA $46 ;/ - AND #$F0 ;\ Command = (byte & 0xF0) >> 2 - LSR A ; | Range $00-$3C - LSR A ; | - STA $4E ;/ - PEI ($4E) ;\ Push and execute command - RTS ;/ - ; -CODE_BB8E10: ; - LDA $46 ; Read next command byte - AND #$0F ;\ Command = (byte & 0xF0) >> 2 - ASL A ; | Range $3F-$7B - ASL A ; | - ADC #$3F ;/ - STA $4A ; - PEI ($4A) ;\ Push and execute command - RTS ;/ - ; -CODE_BB8E1D: ; - LDA $42 ; Read next command byte - AND #$0F ;\ Command = (byte & 0xF0) >> 2 - ASL A ; | Range $3F-$7B - ASL A ; | - ADC #$3F ; | - STA $4A ;/ - PEI ($4A) ;\ Push and execute command - RTS ;/ - ; -CODE_BB8E2A: ; - LDA $46 ;\ Read number of bytes to copy - AND #$0F ; | - BEQ CODE_BB8E40 ;/ If zero bytes, conclude decompression - STA $3C ; Store number of bytes to copy -CODE_BB8E32: ; - LDA [$34],y ;\ Direct copy of up to 16 bytes - INY ; | - STA $0000,x ; | - INX ; | - DEC $3C ; | - BNE CODE_BB8E32 ;/ - JMP CODE_BB8E02 ; Read new command - ; -CODE_BB8E40: ; - REP #$20 ;\ Restore 16 bit A, data bank and Y - PLY ; | - PLB ;/ - TXA ;\ Calculate the number of decompressed bytes (stored in X) - SEC ; | X = X - destination (Where X as an operand is the destination offset) - SBC $38 ; | - TAX ;/ - LDA $32 ;\ Check if DMA should run - BMI CODE_BB8E6E ;/ - LDA $58 ;\ This would be a be a DMA to VRAM - STA $2116 ; | However $32 is a constant and will always be skipped (0xFFFF) - LDA $38 ; | - STA $4302 ; | - LDA $3A ; | - STA $4304 ; | - STX $4305 ; | - LDA #$1801 ; | - STA $4300 ; | - SEP #$20 ; | - LDA #$01 ; | - STA $420B ; | - REP #$20 ;/ -CODE_BB8E6E: ; - RTL ; Done with decompression - ; -CODE_BB8E6F: ; - LDA [$34],y ;\ Load next operand - INY ;/ - STA $42 ;\ Store in nibble lookup tables - STA $46 ;/ - LDA [$42] ;\ Load number of bytes to write - BEQ CODE_BB8E40 ; | If zero bytes, conclude decompression - STA $3C ;/ Store number of bytes to write -CODE_BB8E7C: ; - LDA [$46] ;\ operand2 = high byte - STA $3E ;/ - LDA [$34],y ;\ Load next operand - INY ;/ - STA $42 ;\ Store in nibble lookup tables - STA $46 ;/ - LDA $3E ; Load operand2 - ORA [$42] ;\ write operand2 | low nibble - STA $0000,x ;/ - INX ;\ Continue until no there are no more bytes - DEC $3C ; | - BNE CODE_BB8E7C ;/ - JMP CODE_BB8E10 ; Run next command - ; -CODE_BB8E96: ; - LDA [$46] ;\ Load operand high nibble - STA $3E ;/ - LDA [$34],y ;\ Load next operand - INY ; | - STA $42 ;/ - LDA $3E ; Load operand high nibble - ORA [$42] ;\ write high nibble | low nibble - STA $0000,x ; | - INX ;/ - JMP CODE_BB8E1D ; Run next command - ; -CODE_BB8EAA: ; - LDA [$34],y ;\ Copy one byte from the compression stream - INY ; | - STA $0000,x ; | - INX ;/ - JMP CODE_BB8E02 ; Run next command - ; -CODE_BB8EB4: ; - LDA [$46] ;\ Load operand high nibble into operand2 - STA $3E ;/ - LDA [$34],y ;\ Load next operand - INY ;/ - STA $42 ;\ Store in nibble lookup tables - STA $46 ;/ - LDA $3E ; Load operand2 - ORA [$42] ;\ write operand2 | low nibble - STA $0000,x ; | - INX ;/ - LDA [$46] ;\ Load operand high nibble into operand2 - STA $3E ;/ - LDA [$34],y ;\ Load next operand - INY ;/ - STA $42 ; Store in low nibble lookup table - LDA $3E ; Load operand2 - ORA [$42] ;\ write operand2 | low nibble - STA $0000,x ; | - INX ;/ - JMP CODE_BB8E1D ; Run next command - ; -CODE_BB8EDB: ; - REP #$20 ;\ Copy one word from the compression stream - LDA [$34],y ; | - STA $0000,x ; | - INY ; | - INY ; | - INX ; | - INX ; | - SEP #$20 ;/ - JMP CODE_BB8E02 ; Run next command - ; -CODE_BB8EEB: ; - LDA $46 ;\ Load operand - AND #$0F ; | Count = operand & 0x0F + 3 - ADC #$03 ; | - STA $3C ;/ - LDA [$34],y ;\ Load fill byte - INY ;/ -CODE_BB8EF6: ; - STA $0000,x ;\ Store and repeat with fill byte. - INX ; | - DEC $3C ; | - BNE CODE_BB8EF6 ;/ - JMP CODE_BB8E02 ; Run next command - ; -CODE_BB8F01: ; - LDA [$34],y ;\ Load next operand - INY ;/ - STA $42 ;\ Store in nibble lookup tables - STA $46 ;/ - LDA [$42] ;\ Count = low nibble + 3 - ADC #$03 ; | - STA $3C ;/ - LDA [$46] ;\ Operand2 = high nibble - STA $3E ;/ - LDA [$34],y ;\ Load next operand - INY ; | - STA $42 ;/ Store low nibble look up - LDA $3E ;\ Load operand2 - ORA [$42] ;/ fill byte = operand2 | low nibble -CODE_BB8F1B: ; - STA $0000,x ;\ Store and repeat with fill byte. - INX ; | - DEC $3C ; | - BNE CODE_BB8F1B ;/ - JMP CODE_BB8E1D ; Run next command - ; -CODE_BB8F26: ; - LDA $46 ;\ Load operand - AND #$0F ; | Count = operand & 0x0F + 3 - ADC #$03 ; | - STA $3C ;/ - LDA $52 ; Load fill byte 1 -CODE_BB8F30: ; - STA $0000,x ;\ Store and repeat with fill byte. - INX ; | - DEC $3C ; | - BNE CODE_BB8F30 ;/ - JMP CODE_BB8E02 ; Run next command - ; -CODE_BB8F3B: ; - LDA [$34],y ;\ Load next operand - INY ; | - STA $42 ;/ Store in low nibble lookup - LDA [$42] ;\ Count = low nibble + 3 - ADC #$03 ; | - STA $3C ;/ - LDA $52 ; Load fill byte 1 -CODE_BB8F48: ; - STA $0000,x ;\ Store and repeat with fill byte. - INX ; | - DEC $3C ; | - BNE CODE_BB8F48 ;/ - JMP CODE_BB8E1D ; Run next command - ; -CODE_BB8F53: ; - LDA $46 ;\ Load operand - AND #$0F ; | Count = (operand & 0x0F) + 3 - ADC #$03 ; | - STA $3C ;/ - LDA $53 ; Load fill byte 2 -CODE_BB8F5D: ; - STA $0000,x ;\ Store and repeat with fill byte. - INX ; | - DEC $3C ; | - BNE CODE_BB8F5D ;/ - JMP CODE_BB8E02 ; Run next command - ; -CODE_BB8F68: ; - LDA [$34],y ;\ Load next operand - INY ; | - STA $42 ;/ Store in low nibble lookup - LDA [$42] ;\ Count = low nibble + 3 - ADC #$03 ; | - STA $3C ;/ - LDA $53 ; Load fill byte 2 -CODE_BB8F75: ; - STA $0000,x ;\ Store and repeat with fill byte. - INX ; | - DEC $3C ; | - BNE CODE_BB8F75 ;/ - JMP CODE_BB8E1D ; Run next command - ; -CODE_BB8F80: ; - REP #$20 ;\ Store direct word - LDA $54 ; | - STA $0000,x ; | - INX ; | - INX ; | - SEP #$20 ;/ - JMP CODE_BB8E10 ; Run next command - ; -CODE_BB8F8E: ; - REP #$20 ;\ Store direct word - LDA $54 ; | - STA $0000,x ; | - INX ; | - INX ; | - SEP #$20 ;/ - JMP CODE_BB8E02 ; Run next command - ; -CODE_BB8F9C: ; - LDA $56 ;\ Store direct byte 1 - STA $0000,x ; | - INX ;/ - JMP CODE_BB8E10 ; Run next command - ; -CODE_BB8FA5: ; - LDA $56 ;\ Store direct byte 1 - STA $0000,x ; | - INX ;/ - JMP CODE_BB8E02 ; Run next command - ; -CODE_BB8FAE: ; - LDA $57 ;\ Store direct byte 2 - STA $0000,x ; | - INX ;/ - JMP CODE_BB8E10 ; Run next command - ; -CODE_BB8FB7: ; - LDA $57 ;\ Store direct byte 2 - STA $0000,x ; | - INX ;/ - JMP CODE_BB8E02 ; Run next command - ; -CODE_BB8FC0: ; - PHY ; Preserve compression index - LDA $46 ; Load operand - AND #$0F ;\ Offset = (operand & 0x0F) + 2 - ADC #$02 ; | - STA $3E ;/ - REP #$20 ;\ Prepare to copy (1 word) from a previous point in decompressed data - TXA ; | The new offset is stored in Y - SEC ; | Y = X - offset - SBC $3E ; | - TAY ;/ - LDA $0000,y ;\ Copy from previous data - STA $0000,x ; | - INX ; | - INX ;/ - SEP #$20 ; Return to 8 bit A - PLY ; Restore compression index - JMP CODE_BB8E02 ; Run next command - ; -CODE_BB8FDE: ; - LDA [$34],y ;\ Load next operand - INY ; | - STA $42 ;/ - LDA [$42] ;\ Offset = low nibble + 2 - ADC #$02 ; | - STA $3E ;/ - PHY ; Preserve compression index - REP #$20 ;\ Prepare to copy (1 word) from a previous point in decompressed data - TXA ; | The new offset is stored in Y - SEC ; | Y = X - offset - SBC $3E ; | - TAY ;/ - LDA $0000,y ;\ Copy from previous data - STA $0000,x ; | - INX ; | - INX ;/ - SEP #$20 ; Return to 8 bit A - PLY ; Restore compression index - JMP CODE_BB8E1D ; Run next command - ; -CODE_BB8FFF: ; - LDA $46 ; Load next operand - AND #$0F ;\ Count = (operand & 0x0F) + 3 - ADC #$03 ; | - STA $3C ;/ - LDA [$34],y ;\ Load next operand - STA $3E ; | - INY ;/ - PHY ; Preserve compression index - REP #$20 ;\ Prepare to copy from a previous point in decompressed data - TXA ; | The new offset is stored in Y - SEC ; | Y = X - count - offset - SBC $3C ; | - SEC ; | - SBC $3E ; | - TAY ;/ - SEP #$20 ; Back to 8 bit A -CODE_BB9019: ; - LDA $0000,y ;\ Copy from previous data - INY ; | - STA $0000,x ; | - INX ;/ - DEC $3C ;\ Copy count number of bytes - BNE CODE_BB9019 ;/ - PLY ; Restore compression index - JMP CODE_BB8E02 ; Run next command - ; -CODE_BB9029: ; - LDA [$34],y ;\ Load next operand - INY ;/ - STA $42 ;\ Store in nibble look up tables - STA $46 ;/ - LDA [$42] ;\ Count = low nibble + 3 - ADC #$03 ; | - STA $3C ;/ - LDA [$46] ;\ Store high nibble in offset - STA $3E ;/ - LDA [$34],y ;\ Load next operand and store in the low nibble lookup - INY ; | - STA $42 ;/ - LDA [$42] ;\ offset = low nibble | offset - ORA $3E ; | - STA $3E ;/ - PHY ; Preserve compression index - REP #$20 ;\ Prepare to copy from a previous point in decompressed data - TXA ; | The new offset is stored in Y - SEC ; | Y = X - count - offset - SBC $3C ; | - SEC ; | - SBC $3E ; | - TAY ;/ - SEP #$20 ; Back to 8 bit A -CODE_BB9052: ; - LDA $0000,y ;\ Copy from previous data - INY ; | - STA $0000,x ; | - INX ;/ - DEC $3C ;\ Copy count number of bytes - BNE CODE_BB9052 ;/ - PLY ; Restore compression index - JMP CODE_BB8E1D ; Run next command - ; -CODE_BB9062: ; - LDA $46 ; Load next operand - AND #$0F ;\ Count = (operand & 0x0F) + 3 - ADC #$03 ; | - STA $3C ;/ - LDA [$34],y ;\ Load next operand - INY ; | - XBA ;/ Store as high byte for the full operand - LDA [$34],y ;\ Load next operand store in high byte look up - INY ; | - STA $46 ;/ - REP #$20 ; Switch to 16 bit A - LSR A ;\ Offset = (operand >> 4) + 0x0103 - LSR A ; | - LSR A ; | - LSR A ; | - CLC ; | - ADC #$0103 ; | - STA $40 ;/ - PHY ; Preserve compression index - TXA ;\ Prepare to copy from a previous point in decompressed data - SEC ; | Y = X - offset - SBC $40 ; | - TAY ;/ - SEP #$20 ; Back to 8 bit A -CODE_BB9087: ; - LDA $0000,y ;\ Copy from previous data - INY ; | - STA $0000,x ; | - INX ;/ - DEC $3C ;\ Copy count number of bytes - BNE CODE_BB9087 ;/ - PLY ; Restore compression index - JMP CODE_BB8E10 ; Run next command - ; -CODE_BB9097: ; - LDA [$34],y ;\ Load next operand - INY ; | - STA $42 ;/ Store in low nibble look up table - LDA [$42] ;\ Count = low nibble + 3 - ADC #$03 ; | - STA $3C ;/ - LDA $42 ;\ Copy the low nibble to the operand high byte - AND #$0F ; | - XBA ;/ - LDA [$34],y ;\ Load the operand low byte - INY ;/ - REP #$20 ;\ Offset = operand + 0x0103 - ADC #$0103 ; | - STA $40 ;/ - PHY ; Preserve compression index - TXA ;\ Prepare to copy from a previous point in decompressed data - SEC ; | Y = X - offset - SBC $40 ; | - TAY ;/ - SEP #$20 ; Back to 8 bit A -CODE_BB90B9: ; - LDA $0000,y ;\ Copy from previous data - INY ; | - STA $0000,x ; | - INX ;/ - DEC $3C ;\ Copy count number of bytes - BNE CODE_BB90B9 ;/ - PLY ; Restore compression index - JMP CODE_BB8E02 ; Run next command - ; -CODE_BB90C9: ; - LDA $46 ; Load next operand - AND #$0F ;\ Count = (operand & 0x0F) + 3 - ADC #$03 ; | - STA $3C ;/ - REP #$20 ;\ Read a big endian word for the offset - LDA [$34],y ; | - XBA ; | - STA $40 ;/ - INY ;\ Increment the compression index - INY ;/ - PHY ; Preserve compression index - TXA ;\ Prepare to copy from a previous point in decompressed data - SEC ; | Y = X - offset - SBC $40 ; | - TAY ;/ - SEP #$20 ; Back to 8 bit A -CODE_BB90E2: ; - LDA $0000,y ;\ Copy from previous data - INY ; | - STA $0000,x ; | - INX ;/ - DEC $3C ;\ Copy count number of bytes - BNE CODE_BB90E2 ;/ - PLY ; Restore compression index - JMP CODE_BB8E02 ; Run next command - ; -CODE_BB90F2: ; - LDA [$34],y ;\ Load next operand - INY ; | - STA $42 ;/ Store in low nibble look up table - LDA [$42] ;\ Count = low nibble + 3 - ADC #$03 ; | - STA $3C ;/ - LDA $42 ;\ Copy as the operand high byte - XBA ;/ - LDA [$34],y ;\ Load the operand low byte - INY ;/ - REP #$20 ; Set A to 16 bit - ASL A ;\ Offset = (operand << 4) - ASL A ; | - ASL A ; | - ASL A ; | - STA $40 ;/ - AND #$00FF ; Clear the high byte of the offset - SEP #$20 ; Resume 8 bit A - LDA [$34],y ;\ Load next operand - INY ;/ - PHY ; Preserve compression index - STA $42 ; Store the operand in the low nibble look up table - LDA [$42] ;\ Load low nibble - REP #$20 ; | - AND #$000F ;/ - ORA $40 ;\ offset = offset | low nibble - STA $40 ;/ - TXA ;\ Prepare to copy from a previous point in decompressed data - SEC ; | Y = X - offset - SBC $40 ; | - TAY ;/ - SEP #$20 ; Back to 8 bit A -CODE_BB9128: ; - LDA $0000,y ;\ Copy from previous data - INY ; | - STA $0000,x ; | - INX ;/ - DEC $3C ;\ Copy count number of bytes - BNE CODE_BB9128 ;/ - PLY ; Restore compression index - JMP CODE_BB8E1D ; Run next command Run next command - ; -CODE_BB9138: ; - DEX ;\ Copy previous byte to the decompression stream - LDA $0000,x ; | - STA $0001,x ; | - INX ; | - INX ;/ - JMP CODE_BB8E10 ; Run next command - ; -CODE_BB9144: ; - DEX ;\ Copy previous byte to the decompression stream - LDA $0000,x ; | - STA $0001,x ; | - INX ; | - INX ;/ - JMP CODE_BB8E02 ; Run next command - ; -CODE_BB9150: ; - REP #$20 ;\ Copy the previous word to the decompression stream - DEX ; | - DEX ; | First go back two bytes - LDA $0000,x ; | - STA $0002,x ; | - SEP #$20 ; | - INX ; | Then jump ahead four bytes - INX ; | - INX ; | - INX ;/ - JMP CODE_BB8E10 ; Run next command - ; -CODE_BB9163: ; - REP #$20 ;\ Copy the previous word to the decompression stream - DEX ; | - DEX ; | First go back two bytes - LDA $0000,x ; | - STA $0002,x ; | - SEP #$20 ; | - INX ; | Then jump ahead four bytes - INX ; | - INX ; | - INX ;/ - JMP CODE_BB8E02 ; Run next command - ; -CODE_BB9176: ; - PHY ; Preserve compression index - LDA $46 ; Load next operand - REP #$20 ; Set A to 16 bit - AND #$000F ;\ Y = (operand << 1) + 7 - ASL A ; | - ADC #$0007 ; | - TAY ;/ - LDA [$34],y ;\ Copy word from compression stream to the decompression stream - STA $0000,x ;/ - SEP #$20 ;\ Return to 8 bit A and increment the decompression index - INX ; | - INX ;/ - PLY ; Restore compression index - JMP CODE_BB8E02 ; Run next command - ; -CODE_BB9190: ; - LDA [$34],y ;\ Load next operand - INY ; | - STA $46 ;/ Store to high nibble look up table - REP #$20 ; Set A to 16 bit - AND #$00F0 ;\ Operand = operand >> 3 - LSR A ; | - LSR A ; | - LSR A ;/ - PHY ; Preserve compression index - ADC #$0007 ;\ Y = operand + 7 - TAY ;/ - LDA [$34],y ;\ Copy word from compression stream to the decompression stream - STA $0000,x ;/ - SEP #$20 ;\ Return to 8 bit A and increment the decompression index - INX ; | - INX ;/ - PLY ; Restore compression index - JMP CODE_BB8E10 ; Run next command - ; -CODE_BB91AF: ; - LDY #$0100 ; Prepare to generate the high nibble table - TDC ;\ Zero A and X and set 8 bit A - TAX ; | - SEP #$20 ;/ -CODE_BB91B6: ; - STA $7E2100,x ;\ Store look up value (index & 0x0F) << 4 - CLC ; | - ADC #$10 ; | - AND #$F0 ;/ - INX ;\ Loop through all 256 values - DEY ; | - BNE CODE_BB91B6 ;/ - LDY #$0100 ; Prepare to generate the low nibble table - LDX #$0000 ; -CODE_BB91C9: ; - TXA ;\ Store look up value (index >> 4) - LSR A ; | - LSR A ; | - LSR A ; | - LSR A ; | - STA $7E2000,x ;/ - INX ;\ Loop through all 256 values - DEY ; | - BNE CODE_BB91C9 ;/ - REP #$20 ; Return to 16 bit A - RTL ; Done + +decompress_data: ; + STA $38 ;$BB8D91 \ Set decompression parameters + LDA #$007F ;$BB8D93 | + STA $3A ;$BB8D96 | Bank 7F + address from A + STX $34 ;$BB8D98 | Source from X + STY $36 ;$BB8D9A | + BRA start_decompression ;$BB8D9C / + ; +decompress_data_default: ; \ + TXA ;$BB8D9E |\ Set decompression parameters + TYX ;$BB8D9F | | + STA $34 ;$BB8DA0 | | + STX $36 ;$BB8DA2 | | + LDA #$0000 ;$BB8DA4 | | Default destination $7F0000 + STA $38 ;$BB8DA7 | | + LDA #$007F ;$BB8DA9 | | + STA $3A ;$BB8DAC |/ +start_decompression: ; | + LDA #$FFFF ;$BB8DAE |\ Disble auto DMA of data + STA $32 ;$BB8DB1 |/ + PHB ;$BB8DB3 |\ Preserve call bank/Y + PHY ;$BB8DB4 |/ + LDA #$2100 ;$BB8DB5 |\ Setup pointers to nibble look up tables + STA $46 ;$BB8DB8 | | + LDA #$007E ;$BB8DBA | | + STA $48 ;$BB8DBD | | + STA $44 ;$BB8DBF | | + LDA #$2000 ;$BB8DC1 | | + STA $42 ;$BB8DC4 |/ + JSL build_decompression_lookup ;$BB8DC6 | Generate nibble offset table at RAM $7E2000 + LDX $38 ;$BB8DCA | Load the decompression index + LDY #$0001 ;$BB8DCC | Load the compression index + LDA #$8001 ;$BB8DCF |\ Load default decompression function A 8001 + STA $4E ;$BB8DD2 |/ The high byte will never change. + LDA #$8040 ;$BB8DD4 |\ Load default decompression function B 8040 + STA $4A ;$BB8DD7 |/ + SEP #$20 ;$BB8DD9 | + LDA $3A ;$BB8DDB |\ Set the data bank to the destination bank + PHA ;$BB8DDD | | + PLB ;$BB8DDE |/ + LDA [$34],y ;$BB8DDF |\ Read fill byte 1 + STA $52 ;$BB8DE1 | | + INY ;$BB8DE3 |/ + LDA [$34],y ;$BB8DE4 |\ Read fill byte 2 + STA $53 ;$BB8DE6 | | + INY ;$BB8DE8 |/ + LDA [$34],y ;$BB8DE9 |\ Read direct byte 1 + STA $56 ;$BB8DEB | | + INY ;$BB8DED |/ + LDA [$34],y ;$BB8DEE |\ Read direct byte 2 + STA $57 ;$BB8DF0 | | + INY ;$BB8DF2 |/ + REP #$20 ;$BB8DF3 |\ Read direct word + LDA [$34],y ;$BB8DF5 | | + STA $54 ;$BB8DF7 |/ + LDY #$0027 ;$BB8DF9 | Skip to compressed byte #$27 + STZ $3C ;$BB8DFC |\ Clear generic operand 1 + STZ $3E ;$BB8DFE |/ Clean generic operand 2 + SEP #$20 ;$BB8E00 | Return to 8 bit +execute_command_set_1: ; | + LDA [$34],y ;$BB8E02 |\ Read the first command byte + INY ;$BB8E04 | | + STA $46 ;$BB8E05 |/ + AND #$F0 ;$BB8E07 |\ Command = (byte & 0xF0) >> 2 + LSR A ;$BB8E09 | | Range $00-$3C + LSR A ;$BB8E0A | | + STA $4E ;$BB8E0B |/ + PEI ($4E) ;$BB8E0D | Push command address onto the stack + RTS ;$BB8E0F / Return to execute command + ; +execute_command_set_2_wide: ; + LDA $46 ;$BB8E10 \ Read next command byte + AND #$0F ;$BB8E12 |\ Command = (byte & 0xF0) >> 2 + ASL A ;$BB8E14 | | Range $3F-$7B + ASL A ;$BB8E15 | | + ADC #$3F ;$BB8E16 |/ + STA $4A ;$BB8E18 | + PEI ($4A) ;$BB8E1A | Push command address onto the stack + RTS ;$BB8E1C / Return to execute command + ; +execute_command_set_2: ; + LDA $42 ;$BB8E1D \ Read next command byte + AND #$0F ;$BB8E1F |\ Command = (byte & 0xF0) >> 2 + ASL A ;$BB8E21 | | Range $3F-$7B + ASL A ;$BB8E22 | | + ADC #$3F ;$BB8E23 | | + STA $4A ;$BB8E25 |/ + PEI ($4A) ;$BB8E27 | Push command address onto the stack + RTS ;$BB8E29 / Return to execute command + ; +copy_or_return_1: ; \ + LDA $46 ;$BB8E2A |\ Read number of bytes to copy + AND #$0F ;$BB8E2C | | + BEQ finalize_decompression ;$BB8E2E |/ If zero bytes, conclude decompression + STA $3C ;$BB8E30 | Store number of bytes to copy +.copy_byte ; | + LDA [$34],y ;$BB8E32 |\ Direct copy of up to 16 bytes + INY ;$BB8E34 | | + STA $0000,x ;$BB8E35 | | + INX ;$BB8E38 | | + DEC $3C ;$BB8E39 | | + BNE .copy_byte ;$BB8E3B |/ + JMP execute_command_set_1 ;$BB8E3D / Read new command + ; +finalize_decompression: ; \ + REP #$20 ;$BB8E40 |\ Restore 16 bit A, data bank and Y + PLY ;$BB8E42 | | + PLB ;$BB8E43 |/ + TXA ;$BB8E44 |\ Calculate the number of decompressed bytes (stored in X) + SEC ;$BB8E45 | | X = X - destination (Where X as an operand is the destination offset) + SBC $38 ;$BB8E46 | | + TAX ;$BB8E48 |/ + LDA $32 ;$BB8E49 |\ Check if DMA should run + BMI .skip_DMA ;$BB8E4B |/ + LDA $58 ;$BB8E4D |\ This would be a be a DMA to VRAM + STA $2116 ;$BB8E4F | | However $32 is a constant and will always be skipped (0xFFFF) + LDA $38 ;$BB8E52 | | + STA $4302 ;$BB8E54 | | + LDA $3A ;$BB8E57 | | + STA $4304 ;$BB8E59 | | + STX $4305 ;$BB8E5C | | + LDA #$1801 ;$BB8E5F | | + STA $4300 ;$BB8E62 | | + SEP #$20 ;$BB8E65 | | + LDA #$01 ;$BB8E67 | | + STA $420B ;$BB8E69 | | + REP #$20 ;$BB8E6C |/ +.skip_DMA ; | + RTL ;$BB8E6E / Done with decompression + ; +copy_or_return_2: ; \ + LDA [$34],y ;$BB8E6F |\ Load next operand + INY ;$BB8E71 |/ + STA $42 ;$BB8E72 |\ Store in nibble lookup tables + STA $46 ;$BB8E74 |/ + LDA [$42] ;$BB8E76 |\ Load number of bytes to write + BEQ finalize_decompression ;$BB8E78 | | If zero bytes, conclude decompression + STA $3C ;$BB8E7A |/ Store number of bytes to write +.copy_byte ; | + LDA [$46] ;$BB8E7C |\ operand2 = high byte + STA $3E ;$BB8E7E |/ + LDA [$34],y ;$BB8E80 |\ Load next operand + INY ;$BB8E82 |/ + STA $42 ;$BB8E83 |\ Store in nibble lookup tables + STA $46 ;$BB8E85 |/ + LDA $3E ;$BB8E87 | Load operand2 + ORA [$42] ;$BB8E89 |\ write operand2 | low nibble + STA $0000,x ;$BB8E8B |/ + INX ;$BB8E8E |\ Continue until no there are no more bytes + DEC $3C ;$BB8E8F | | + BNE .copy_byte ;$BB8E91 |/ + JMP execute_command_set_2_wide ;$BB8E93 / Run next command + ; +stream_byte_1: ; \ + LDA [$46] ;$BB8E96 |\ Load operand high nibble + STA $3E ;$BB8E98 |/ + LDA [$34],y ;$BB8E9A |\ Load next operand + INY ;$BB8E9C | | + STA $42 ;$BB8E9D |/ + LDA $3E ;$BB8E9F | Load operand high nibble + ORA [$42] ;$BB8EA1 |\ write high nibble | low nibble + STA $0000,x ;$BB8EA3 | | + INX ;$BB8EA6 |/ + JMP execute_command_set_2 ;$BB8EA7 / Run next command + ; +stream_byte_2: ; \ + LDA [$34],y ;$BB8EAA |\ Copy one byte from the compression stream + INY ;$BB8EAC | | + STA $0000,x ;$BB8EAD | | + INX ;$BB8EB0 |/ + JMP execute_command_set_1 ;$BB8EB1 / Run next command + ; +stream_word_1: ; \ + LDA [$46] ;$BB8EB4 |\ Load operand high nibble into operand2 + STA $3E ;$BB8EB6 |/ + LDA [$34],y ;$BB8EB8 |\ Load next operand + INY ;$BB8EBA |/ + STA $42 ;$BB8EBB |\ Store in nibble lookup tables + STA $46 ;$BB8EBD |/ + LDA $3E ;$BB8EBF | Load operand2 + ORA [$42] ;$BB8EC1 |\ write operand2 | low nibble + STA $0000,x ;$BB8EC3 | | + INX ;$BB8EC6 |/ + LDA [$46] ;$BB8EC7 |\ Load operand high nibble into operand2 + STA $3E ;$BB8EC9 |/ + LDA [$34],y ;$BB8ECB |\ Load next operand + INY ;$BB8ECD |/ + STA $42 ;$BB8ECE | Store in low nibble lookup table + LDA $3E ;$BB8ED0 | Load operand2 + ORA [$42] ;$BB8ED2 |\ write operand2 | low nibble + STA $0000,x ;$BB8ED4 | | + INX ;$BB8ED7 |/ + JMP execute_command_set_2 ;$BB8ED8 / Run next command + ; +stream_word_2: ; \ + REP #$20 ;$BB8EDB |\ Copy one word from the compression stream + LDA [$34],y ;$BB8EDD | | + STA $0000,x ;$BB8EDF | | + INY ;$BB8EE2 | | + INY ;$BB8EE3 | | + INX ;$BB8EE4 | | + INX ;$BB8EE5 | | + SEP #$20 ;$BB8EE6 |/ + JMP execute_command_set_1 ;$BB8EE8 / Run next command + ; +stream_byte_fill_1: ; \ + LDA $46 ;$BB8EEB |\ Load operand + AND #$0F ;$BB8EED | | Count = operand & 0x0F + 3 + ADC #$03 ;$BB8EEF | | + STA $3C ;$BB8EF1 |/ + LDA [$34],y ;$BB8EF3 |\ Load fill byte + INY ;$BB8EF5 |/ +.fill_byte ; | + STA $0000,x ;$BB8EF6 |\ Store and repeat with fill byte. + INX ;$BB8EF9 | | + DEC $3C ;$BB8EFA | | + BNE .fill_byte ;$BB8EFC |/ + JMP execute_command_set_1 ;$BB8EFE / Run next command + ; +stream_byte_fill_2: ; \ + LDA [$34],y ;$BB8F01 |\ Load next operand + INY ;$BB8F03 |/ + STA $42 ;$BB8F04 |\ Store in nibble lookup tables + STA $46 ;$BB8F06 |/ + LDA [$42] ;$BB8F08 |\ Count = low nibble + 3 + ADC #$03 ;$BB8F0A | | + STA $3C ;$BB8F0C |/ + LDA [$46] ;$BB8F0E |\ Operand2 = high nibble + STA $3E ;$BB8F10 |/ + LDA [$34],y ;$BB8F12 |\ Load next operand + INY ;$BB8F14 | | + STA $42 ;$BB8F15 |/ Store low nibble look up + LDA $3E ;$BB8F17 |\ Load operand2 + ORA [$42] ;$BB8F19 |/ fill byte = operand2 | low nibble +.fill_byte ; | + STA $0000,x ;$BB8F1B |\ Store and repeat with fill byte. + INX ;$BB8F1E | | + DEC $3C ;$BB8F1F | | + BNE .fill_byte ;$BB8F21 |/ + JMP execute_command_set_2 ;$BB8F23 / Run next command + ; +direct_byte_1_fill_1: ; \ + LDA $46 ;$BB8F26 |\ Load operand + AND #$0F ;$BB8F28 | | Count = operand & 0x0F + 3 + ADC #$03 ;$BB8F2A | | + STA $3C ;$BB8F2C |/ + LDA $52 ;$BB8F2E | Load fill byte 1 +.fill_byte ; | + STA $0000,x ;$BB8F30 |\ Store and repeat with fill byte. + INX ;$BB8F33 | | + DEC $3C ;$BB8F34 | | + BNE .fill_byte ;$BB8F36 |/ + JMP execute_command_set_1 ;$BB8F38 / Run next command + ; +direct_byte_1_fill_2: ; \ + LDA [$34],y ;$BB8F3B |\ Load next operand + INY ;$BB8F3D | | + STA $42 ;$BB8F3E |/ Store in low nibble lookup + LDA [$42] ;$BB8F40 |\ Count = low nibble + 3 + ADC #$03 ;$BB8F42 | | + STA $3C ;$BB8F44 |/ + LDA $52 ;$BB8F46 | Load fill byte 1 +.fill_byte ; | + STA $0000,x ;$BB8F48 |\ Store and repeat with fill byte. + INX ;$BB8F4B | | + DEC $3C ;$BB8F4C | | + BNE .fill_byte ;$BB8F4E |/ + JMP execute_command_set_2 ;$BB8F50 / Run next command + ; +direct_byte_2_fill_1: ; \ + LDA $46 ;$BB8F53 |\ Load operand + AND #$0F ;$BB8F55 | | Count = (operand & 0x0F) + 3 + ADC #$03 ;$BB8F57 | | + STA $3C ;$BB8F59 |/ + LDA $53 ;$BB8F5B | Load fill byte 2 +.fill_byte ; | + STA $0000,x ;$BB8F5D |\ Store and repeat with fill byte. + INX ;$BB8F60 | | + DEC $3C ;$BB8F61 | | + BNE .fill_byte ;$BB8F63 |/ + JMP execute_command_set_1 ;$BB8F65 / Run next command + ; +direct_byte_2_fill_2: ; \ + LDA [$34],y ;$BB8F68 |\ Load next operand + INY ;$BB8F6A | | + STA $42 ;$BB8F6B |/ Store in low nibble lookup + LDA [$42] ;$BB8F6D |\ Count = low nibble + 3 + ADC #$03 ;$BB8F6F | | + STA $3C ;$BB8F71 |/ + LDA $53 ;$BB8F73 | Load fill byte 2 +.fill_byte ; | + STA $0000,x ;$BB8F75 |\ Store and repeat with fill byte. + INX ;$BB8F78 | | + DEC $3C ;$BB8F79 | | + BNE .fill_byte ;$BB8F7B |/ + JMP execute_command_set_2 ;$BB8F7D / Run next command + ; +direct_word_put_1: ; \ + REP #$20 ;$BB8F80 |\ Store direct word + LDA $54 ;$BB8F82 | | + STA $0000,x ;$BB8F84 | | + INX ;$BB8F87 | | + INX ;$BB8F88 | | + SEP #$20 ;$BB8F89 |/ + JMP execute_command_set_2_wide ;$BB8F8B / Run next command + ; +direct_word_put_2: ; \ + REP #$20 ;$BB8F8E |\ Store direct word + LDA $54 ;$BB8F90 | | + STA $0000,x ;$BB8F92 | | + INX ;$BB8F95 | | + INX ;$BB8F96 | | + SEP #$20 ;$BB8F97 |/ + JMP execute_command_set_1 ;$BB8F99 / Run next command + ; +direct_byte_1_put_1: ; \ + LDA $56 ;$BB8F9C |\ Store direct byte 1 + STA $0000,x ;$BB8F9E | | + INX ;$BB8FA1 |/ + JMP execute_command_set_2_wide ;$BB8FA2 / Run next command + ; +direct_byte_1_put_2: ; \ + LDA $56 ;$BB8FA5 |\ Store direct byte 1 + STA $0000,x ;$BB8FA7 | | + INX ;$BB8FAA |/ + JMP execute_command_set_1 ;$BB8FAB / Run next command + ; +direct_byte_2_put_1: ; \ + LDA $57 ;$BB8FAE |\ Store direct byte 2 + STA $0000,x ;$BB8FB0 | | + INX ;$BB8FB3 |/ + JMP execute_command_set_2_wide ;$BB8FB4 / Run next command + ; +direct_byte_2_put_2: ; \ + LDA $57 ;$BB8FB7 |\ Store direct byte 2 + STA $0000,x ;$BB8FB9 | | + INX ;$BB8FBC |/ + JMP execute_command_set_1 ;$BB8FBD / Run next command + ; +back_copy_word_1: ; + PHY ;$BB8FC0 \ Preserve compression index + LDA $46 ;$BB8FC1 | Load operand + AND #$0F ;$BB8FC3 |\ Offset = (operand & 0x0F) + 2 + ADC #$02 ;$BB8FC5 | | + STA $3E ;$BB8FC7 |/ + REP #$20 ;$BB8FC9 |\ Prepare to copy (1 word) from a previous point in decompressed data + TXA ;$BB8FCB | | The new offset is stored in Y + SEC ;$BB8FCC | | Y = X - offset + SBC $3E ;$BB8FCD | | + TAY ;$BB8FCF |/ + LDA $0000,y ;$BB8FD0 |\ Copy from previous data + STA $0000,x ;$BB8FD3 | | + INX ;$BB8FD6 | | + INX ;$BB8FD7 |/ + SEP #$20 ;$BB8FD8 | Return to 8 bit A + PLY ;$BB8FDA | Restore compression index + JMP execute_command_set_1 ;$BB8FDB / Run next command + ; +back_copy_word_2: ; \ + LDA [$34],y ;$BB8FDE |\ Load next operand + INY ;$BB8FE0 | | + STA $42 ;$BB8FE1 |/ + LDA [$42] ;$BB8FE3 |\ Offset = low nibble + 2 + ADC #$02 ;$BB8FE5 | | + STA $3E ;$BB8FE7 |/ + PHY ;$BB8FE9 | Preserve compression index + REP #$20 ;$BB8FEA |\ Prepare to copy (1 word) from a previous point in decompressed data + TXA ;$BB8FEC | | The new offset is stored in Y + SEC ;$BB8FED | | Y = X - offset + SBC $3E ;$BB8FEE | | + TAY ;$BB8FF0 |/ + LDA $0000,y ;$BB8FF1 |\ Copy from previous data + STA $0000,x ;$BB8FF4 | | + INX ;$BB8FF7 | | + INX ;$BB8FF8 |/ + SEP #$20 ;$BB8FF9 | Return to 8 bit A + PLY ;$BB8FFB | Restore compression index + JMP execute_command_set_2 ;$BB8FFC / Run next command + ; +back_copy_1: ; + LDA $46 ;$BB8FFF \ Load next operand + AND #$0F ;$BB9001 |\ Count = (operand & 0x0F) + 3 + ADC #$03 ;$BB9003 | | + STA $3C ;$BB9005 |/ + LDA [$34],y ;$BB9007 |\ Load next operand + STA $3E ;$BB9009 | | + INY ;$BB900B |/ + PHY ;$BB900C | Preserve compression index + REP #$20 ;$BB900D |\ Prepare to copy from a previous point in decompressed data + TXA ;$BB900F | | The new offset is stored in Y + SEC ;$BB9010 | | Y = X - count - offset + SBC $3C ;$BB9011 | | + SEC ;$BB9013 | | + SBC $3E ;$BB9014 | | + TAY ;$BB9016 |/ + SEP #$20 ;$BB9017 | Back to 8 bit A +.byte_copy ; | + LDA $0000,y ;$BB9019 |\ Copy from previous data + INY ;$BB901C | | + STA $0000,x ;$BB901D | | + INX ;$BB9020 |/ + DEC $3C ;$BB9021 |\ Copy count number of bytes + BNE .byte_copy ;$BB9023 |/ + PLY ;$BB9025 | Restore compression index + JMP execute_command_set_1 ;$BB9026 / Run next command + ; +back_copy_2: ; \ + LDA [$34],y ;$BB9029 |\ Load next operand + INY ;$BB902B |/ + STA $42 ;$BB902C |\ Store in nibble look up tables + STA $46 ;$BB902E |/ + LDA [$42] ;$BB9030 |\ Count = low nibble + 3 + ADC #$03 ;$BB9032 | | + STA $3C ;$BB9034 |/ + LDA [$46] ;$BB9036 |\ Store high nibble in offset + STA $3E ;$BB9038 |/ + LDA [$34],y ;$BB903A |\ Load next operand and store in the low nibble lookup + INY ;$BB903C | | + STA $42 ;$BB903D |/ + LDA [$42] ;$BB903F |\ offset = low nibble | offset + ORA $3E ;$BB9041 | | + STA $3E ;$BB9043 |/ + PHY ;$BB9045 | Preserve compression index + REP #$20 ;$BB9046 |\ Prepare to copy from a previous point in decompressed data + TXA ;$BB9048 | | The new offset is stored in Y + SEC ;$BB9049 | | Y = X - count - offset + SBC $3C ;$BB904A | | + SEC ;$BB904C | | + SBC $3E ;$BB904D | | + TAY ;$BB904F |/ + SEP #$20 ;$BB9050 | Back to 8 bit A +.byte_copy ; | + LDA $0000,y ;$BB9052 |\ Copy from previous data + INY ;$BB9055 | | + STA $0000,x ;$BB9056 | | + INX ;$BB9059 |/ + DEC $3C ;$BB905A |\ Copy count number of bytes + BNE .byte_copy ;$BB905C |/ + PLY ;$BB905E | Restore compression index + JMP execute_command_set_2 ;$BB905F / Run next command + ; +back_copy_far_1: ; + LDA $46 ;$BB9062 \ Load next operand + AND #$0F ;$BB9064 |\ Count = (operand & 0x0F) + 3 + ADC #$03 ;$BB9066 | | + STA $3C ;$BB9068 |/ + LDA [$34],y ;$BB906A |\ Load next operand + INY ;$BB906C | | + XBA ;$BB906D |/ Store as high byte for the full operand + LDA [$34],y ;$BB906E |\ Load next operand store in high byte look up + INY ;$BB9070 | | + STA $46 ;$BB9071 |/ + REP #$20 ;$BB9073 | Switch to 16 bit A + LSR A ;$BB9075 |\ Offset = (operand >> 4) + 0x0103 + LSR A ;$BB9076 | | + LSR A ;$BB9077 | | + LSR A ;$BB9078 | | + CLC ;$BB9079 | | + ADC #$0103 ;$BB907A | | + STA $40 ;$BB907D |/ + PHY ;$BB907F | Preserve compression index + TXA ;$BB9080 |\ Prepare to copy from a previous point in decompressed data + SEC ;$BB9081 | | Y = X - offset + SBC $40 ;$BB9082 | | + TAY ;$BB9084 |/ + SEP #$20 ;$BB9085 | Back to 8 bit A +.byte_copy ; | + LDA $0000,y ;$BB9087 |\ Copy from previous data + INY ;$BB908A | | + STA $0000,x ;$BB908B | | + INX ;$BB908E |/ + DEC $3C ;$BB908F |\ Copy count number of bytes + BNE .byte_copy ;$BB9091 |/ + PLY ;$BB9093 | Restore compression index + JMP execute_command_set_2_wide ;$BB9094 / Run next command + ; +back_copy_far_2: ; \ + LDA [$34],y ;$BB9097 |\ Load next operand + INY ;$BB9099 | | + STA $42 ;$BB909A |/ Store in low nibble look up table + LDA [$42] ;$BB909C |\ Count = low nibble + 3 + ADC #$03 ;$BB909E | | + STA $3C ;$BB90A0 |/ + LDA $42 ;$BB90A2 |\ Copy the low nibble to the operand high byte + AND #$0F ;$BB90A4 | | + XBA ;$BB90A6 |/ + LDA [$34],y ;$BB90A7 |\ Load the operand low byte + INY ;$BB90A9 |/ + REP #$20 ;$BB90AA |\ Offset = operand + 0x0103 + ADC #$0103 ;$BB90AC | | + STA $40 ;$BB90AF |/ + PHY ;$BB90B1 | Preserve compression index + TXA ;$BB90B2 |\ Prepare to copy from a previous point in decompressed data + SEC ;$BB90B3 | | Y = X - offset + SBC $40 ;$BB90B4 | | + TAY ;$BB90B6 |/ + SEP #$20 ;$BB90B7 | Back to 8 bit A +.byte_copy ; | + LDA $0000,y ;$BB90B9 |\ Copy from previous data + INY ;$BB90BC | | + STA $0000,x ;$BB90BD | | + INX ;$BB90C0 |/ + DEC $3C ;$BB90C1 |\ Copy count number of bytes + BNE .byte_copy ;$BB90C3 |/ + PLY ;$BB90C5 | Restore compression index + JMP execute_command_set_1 ;$BB90C6 / Run next command + ; +back_copy_arbitrary_1: ; + LDA $46 ;$BB90C9 \ Load next operand + AND #$0F ;$BB90CB |\ Count = (operand & 0x0F) + 3 + ADC #$03 ;$BB90CD | | + STA $3C ;$BB90CF |/ + REP #$20 ;$BB90D1 |\ Read a big endian word for the offset + LDA [$34],y ;$BB90D3 | | + XBA ;$BB90D5 | | + STA $40 ;$BB90D6 |/ + INY ;$BB90D8 |\ Increment the compression index + INY ;$BB90D9 |/ + PHY ;$BB90DA | Preserve compression index + TXA ;$BB90DB |\ Prepare to copy from a previous point in decompressed data + SEC ;$BB90DC | | Y = X - offset + SBC $40 ;$BB90DD | | + TAY ;$BB90DF |/ + SEP #$20 ;$BB90E0 | Back to 8 bit A +.byte_copy ; | + LDA $0000,y ;$BB90E2 |\ Copy from previous data + INY ;$BB90E5 | | + STA $0000,x ;$BB90E6 | | + INX ;$BB90E9 |/ + DEC $3C ;$BB90EA |\ Copy count number of bytes + BNE .byte_copy ;$BB90EC |/ + PLY ;$BB90EE | Restore compression index + JMP execute_command_set_1 ;$BB90EF / Run next command + ; +back_copy_arbitrary_2: ; \ + LDA [$34],y ;$BB90F2 |\ Load next operand + INY ;$BB90F4 | | + STA $42 ;$BB90F5 |/ Store in low nibble look up table + LDA [$42] ;$BB90F7 |\ Count = low nibble + 3 + ADC #$03 ;$BB90F9 | | + STA $3C ;$BB90FB |/ + LDA $42 ;$BB90FD |\ Copy as the operand high byte + XBA ;$BB90FF |/ + LDA [$34],y ;$BB9100 |\ Load the operand low byte + INY ;$BB9102 |/ + REP #$20 ;$BB9103 | Set A to 16 bit + ASL A ;$BB9105 |\ Offset = (operand << 4) + ASL A ;$BB9106 | | + ASL A ;$BB9107 | | + ASL A ;$BB9108 | | + STA $40 ;$BB9109 |/ + AND #$00FF ;$BB910B | Clear the high byte of the offset + SEP #$20 ;$BB910E | Resume 8 bit A + LDA [$34],y ;$BB9110 |\ Load next operand + INY ;$BB9112 |/ + PHY ;$BB9113 | Preserve compression index + STA $42 ;$BB9114 | Store the operand in the low nibble look up table + LDA [$42] ;$BB9116 |\ Load low nibble + REP #$20 ;$BB9118 | | + AND #$000F ;$BB911A |/ + ORA $40 ;$BB911D |\ offset = offset | low nibble + STA $40 ;$BB911F |/ + TXA ;$BB9121 |\ Prepare to copy from a previous point in decompressed data + SEC ;$BB9122 | | Y = X - offset + SBC $40 ;$BB9123 | | + TAY ;$BB9125 |/ + SEP #$20 ;$BB9126 | Back to 8 bit A +.copy_byte ; | + LDA $0000,y ;$BB9128 |\ Copy from previous data + INY ;$BB912B | | + STA $0000,x ;$BB912C | | + INX ;$BB912F |/ + DEC $3C ;$BB9130 |\ Copy count number of bytes + BNE .copy_byte ;$BB9132 |/ + PLY ;$BB9134 | Restore compression index + JMP execute_command_set_2 ;$BB9135 / Run next command Run next command + ; +duplicate_byte_1: ; \ + DEX ;$BB9138 |\ Copy previous byte to the decompression stream + LDA $0000,x ;$BB9139 | | + STA $0001,x ;$BB913C | | + INX ;$BB913F | | + INX ;$BB9140 |/ + JMP execute_command_set_2_wide ;$BB9141 / Run next command + ; +duplicate_byte_2: ; \ + DEX ;$BB9144 |\ Copy previous byte to the decompression stream + LDA $0000,x ;$BB9145 | | + STA $0001,x ;$BB9148 | | + INX ;$BB914B | | + INX ;$BB914C |/ + JMP execute_command_set_1 ;$BB914D / Run next command + ; +duplicate_word_1: ; \ + REP #$20 ;$BB9150 |\ Copy the previous word to the decompression stream + DEX ;$BB9152 | | + DEX ;$BB9153 | | First go back two bytes + LDA $0000,x ;$BB9154 | | + STA $0002,x ;$BB9157 | | + SEP #$20 ;$BB915A | | + INX ;$BB915C | | Then jump ahead four bytes + INX ;$BB915D | | + INX ;$BB915E | | + INX ;$BB915F |/ + JMP execute_command_set_2_wide ;$BB9160 / Run next command + ; +duplicate_word_2: ; \ + REP #$20 ;$BB9163 |\ Copy the previous word to the decompression stream + DEX ;$BB9165 | | + DEX ;$BB9166 | | First go back two bytes + LDA $0000,x ;$BB9167 | | + STA $0002,x ;$BB916A | | + SEP #$20 ;$BB916D | | + INX ;$BB916F | | Then jump ahead four bytes + INX ;$BB9170 | | + INX ;$BB9171 | | + INX ;$BB9172 |/ + JMP execute_command_set_1 ;$BB9173 / Run next command + ; +copy_future_word_1: ; + PHY ;$BB9176 \ Preserve compression index + LDA $46 ;$BB9177 | Load next operand + REP #$20 ;$BB9179 | Set A to 16 bit + AND #$000F ;$BB917B |\ Y = (operand << 1) + 7 + ASL A ;$BB917E | | + ADC #$0007 ;$BB917F | | + TAY ;$BB9182 |/ + LDA [$34],y ;$BB9183 |\ Copy word from compression stream to the decompression stream + STA $0000,x ;$BB9185 |/ + SEP #$20 ;$BB9188 |\ Return to 8 bit A and increment the decompression index + INX ;$BB918A | | + INX ;$BB918B |/ + PLY ;$BB918C | Restore compression index + JMP execute_command_set_1 ;$BB918D / Run next command + ; +copy_future_word_2: ; \ + LDA [$34],y ;$BB9190 |\ Load next operand + INY ;$BB9192 | | + STA $46 ;$BB9193 |/ Store to high nibble look up table + REP #$20 ;$BB9195 | Set A to 16 bit + AND #$00F0 ;$BB9197 |\ Operand = operand >> 3 + LSR A ;$BB919A | | + LSR A ;$BB919B | | + LSR A ;$BB919C |/ + PHY ;$BB919D | Preserve compression index + ADC #$0007 ;$BB919E |\ Y = operand + 7 + TAY ;$BB91A1 |/ + LDA [$34],y ;$BB91A2 |\ Copy word from compression stream to the decompression stream + STA $0000,x ;$BB91A4 |/ + SEP #$20 ;$BB91A7 |\ Return to 8 bit A and increment the decompression index + INX ;$BB91A9 | | + INX ;$BB91AA |/ + PLY ;$BB91AB | Restore compression index + JMP execute_command_set_2_wide ;$BB91AC / Run next command + ; +build_decompression_lookup: ; + LDY #$0100 ;$BB91AF \ Prepare to generate the high nibble table + TDC ;$BB91B2 |\ Zero A and X and set 8 bit A + TAX ;$BB91B3 | | + SEP #$20 ;$BB91B4 |/ +.build_high_nibble ; | + STA $7E2100,x ;$BB91B6 |\ Store look up value (index & 0x0F) << 4 + CLC ;$BB91BA | | + ADC #$10 ;$BB91BB | | + AND #$F0 ;$BB91BD |/ + INX ;$BB91BF |\ Loop through all 256 values + DEY ;$BB91C0 | | + BNE .build_high_nibble ;$BB91C1 |/ + LDY #$0100 ;$BB91C3 | Prepare to generate the low nibble table + LDX #$0000 ;$BB91C6 | +.build_low_nibble ; | + TXA ;$BB91C9 |\ Store look up value (index >> 4) + LSR A ;$BB91CA | | + LSR A ;$BB91CB | | + LSR A ;$BB91CC | | + LSR A ;$BB91CD | | + STA $7E2000,x ;$BB91CE |/ + INX ;$BB91D2 |\ Loop through all 256 values + DEY ;$BB91D3 | | + BNE .build_low_nibble ;$BB91D4 |/ + REP #$20 ;$BB91D6 | Return to 16 bit A + RTL ;$BB91D8 / Done diff --git a/notes.txt b/notes.txt index 2d06bf8..17d4427 100644 --- a/notes.txt +++ b/notes.txt @@ -148,6 +148,8 @@ CODE_B5BCA8 ;Map loading stuff CODE_808B6F ;Weird code CODE_BBB70C ;Looks like sprite level load code +DATA_FD819A ;has pointers in some interlaced format (possibly RLE tilemap decoding) + $38 -- Mirror of 211C, DMA size, and some index