;$30FF-$3265 ;Compression format: One byte(XXX YYYYY) or two byte (111 XXX YY-YYYYYYYY) headers ;XXX = instruction, YYYYYYYYYY = counter lorom org $80B0FF LDA $02, S ; One-to-one STA $45 ; One-to-one LDA $01, S ; One-to-one STA $44 ; One-to-one CLC ; One-to-one ADC #$0003 ; One-to-one STA $01, S ; One-to-one LDY #$0001 ; One-to-one LDA [$44], Y ; One-to-one STA $4C ; One-to-one INY ; One-to-one LDA [$44], Y ; One-to-one STA $4D ; One-to-one ;80B119 : Later JSL start if 4C (target address) is specified PHP ; One-to-one PHB ; One-to-one SEP #$20 ; One-to-one REP #$10 ; One-to-one LDA $49 ; One-to-one PHA ; One-to-one PLB ; One-to-one STZ $50 ; One-to-one LDY #$0000 ; One-to-one BRA NextByte End: ; This has been moved here, which is good PLB ; because taking a branch costs extra PLP ; cycles and this one can only happen once RTL NextByte: LDA ($47) ; Loads indirect instead of indexed INC $47 ; Loads indirect instead of indexed BNE + JSR IncrementBank2 + STA $4A CMP #$FF BEQ End CMP #$E0 ; Rather than masking and testing equality BCC ++ ; Prevents the need to reload the value and quicker to check ASL A ; One-to-one ASL A ; One-to-one ASL A ; One-to-one AND #$E0 ; One-to-one PHA ; One-to-one LDA $4A ; One-to-one AND #$03 ; One-to-one XBA ; One-to-one LDA ($47) ; Loads indirect instead of indexed INC $47 ; Loads indirect instead of indexed BNE + JSR IncrementBank2 + BRA +++ ; One-to-one ++ AND #$E0 ; Mask moved to here PHA ; One-to-one TDC ; Rather than LDA #00 : XBA LDA $4A ; One-to-one AND #$1F ; One-to-one +++ TAX ; One-to-one INX ; One-to-one PLA ; One-to-one BMI Option4567 ; Removes a redundant CMP #$00 and manages to avoid BPL $03 : JMP Option4567 BEQ Option0 ; Tests this rather than #$60 (removing a CMP) CMP #$20 ; One-to-one BEQ BRANCH_THETA ; One-to-one CMP #$40 ; One-to-one BEQ BRANCH_IOTA ; One-to-one ;X = 3: Store an ascending number (starting with the value of the next byte) Y times. LDA ($47) ; Loads indirect instead of indexed INC $47 ; Loads indirect instead of indexed BNE + JSR IncrementBank2 + - STA [$4C], Y ; One-to-one INC A ; One-to-one INY ; One-to-one DEX ; One-to-one ; One-to-one BNE - ; One-to-one ; One-to-one JMP NextByte ; One-to-one Option0: - ;X = 0: Directly copy Y bytes LDA ($47) ; Loads indirect instead of indexed INC $47 ; Loads indirect instead of indexed BNE + JSR IncrementBank2 + STA [$4C], Y ; One-to-one INY ; One-to-one DEX ; One-to-one ; One-to-one BNE - ; One-to-one JMP NextByte BRANCH_THETA: ;X = 1: Copy the next byte Y times. LDA ($47) ; Loads indirect instead of indexed INC $47 ; Loads indirect instead of indexed BNE + JSR IncrementBank2 + - STA [$4C], Y ; One-to-one INY ; One-to-one DEX ; One-to-one BNE - ; One-to-one JMP NextByte ; One-to-one BRANCH_IOTA: ;X = 2: Copy the next two bytes, one at a time, for the next Y bytes. LDA ($47) ; Loads indirect instead of indexed INC $47 ; Loads indirect instead of indexed BNE + JSR IncrementBank2 + XBA ; Uses A rather than storing to $4A LDA ($47) ; Loads indirect instead of indexed INC $47 ; Loads indirect instead of indexed BNE + JSR IncrementBank2 + XBA ; Uses A rather than storing to $4B REP #$20 ; Writes 16-bit rather than two 8-bit - STA [$4C], Y INY DEX BEQ ++ INY DEX BNE - ++ SEP #$20 JMP NextByte Option4567: CMP #$C0 ;X = 4: Copy Y bytes starting from a given address in the decompressed data. ;X = 5: Copy and invert (EOR #$FF) Y bytes starting from a given address in the decompressed data. AND #$20 ; Does this now rather than after branching STA $4F ; Does this now rather than after branching BCS +++ ;X = 6 or 7 branch LDA ($47) ; Loads indirect instead of indexed INC $47 ; Loads indirect instead of indexed BNE + JSR IncrementBank2 + XBA ; Uses A rather than storing to $4A LDA ($47) ; Loads indirect instead of indexed INC $47 ; Loads indirect instead of indexed BNE + JSR IncrementBank2 + XBA ; Uses A rather than storing to $4B REP #$21 ; Uses 16-bit and clears carry ADC $4C ; Sets up address only once STY $44 ; Sets up address only once SEC ; Sets up address only once -- ; Sets up address only once SBC $44 ; Sets up address only once STA $44 ; Sets up address only once SEP #$20 ;XBA : XBA : REP : ADC dp : STY dp : SEC : SBC dp : STA dp : SEP. 3+3+3+4+4+2+4+4+3 = 30 ;STA dp : STA dp : REP : TYA : EOR : INC : ADC dp : CLC : ADC dp : STA dp : SEP. 3+3+3+2+3+2+4+2+4+4+3 = 33 ;-- LDA $4E ; Sets up address only once BCS + ; Sets up address only once DEC ; Sets up address only once + ; Sets up address only once STA $46 ; Sets up address only once + LDA $4F BNE + ;Inverted - LDA [$44], Y ; Loop just here rather than whole section of routine STA [$4C], Y ; Loop just here rather than whole section of routine INY ; Loop just here rather than whole section of routine DEX ; Loop just here rather than whole section of routine ; Loop just here rather than whole section of routine BNE - ; Loop just here rather than whole section of routine JMP NextByte ; Loop just here rather than whole section of routine + - LDA [$44], Y ; Same as above EOR #$FF STA [$4C], Y INY DEX BNE - JMP NextByte +++ ;X = 6: Copy Y bytes starting from a given number of bytes ago in the decompressed data. ;X = 7: Copy and invert (EOR #$FF) Y bytes starting from a given number of bytes ago in the decompressed data. TDC LDA ($47) ; Loads indirect instead of indexed INC $47 ; Loads indirect instead of indexed BNE + JSR IncrementBank2 + REP #$20 STA $44 ;\ LDA $4C ;} Reuses more of the previous routine ; SEC ;I think I can get away without this :D ; SBC $4A ; STA $44 ; SEP #$20 BRA -- IncrementBank2: ; Incrementing the high byte of the source and checking its bank overflow is left here INC $48 BNE + ; One-to-one PHA ; One-to-one PHB ; One-to-one PLA ; One-to-one INC A ; One-to-one PHA ; One-to-one PLB ; One-to-one LDA #$80 STA $48 PLA + RTS