; PackBits RLE unpacker ; Copyright (c) 2015 Johnathan Roatch ; ; Copying and distribution of this file, with or without ; modification, are permitted in any medium without royalty ; provided the copyright notice and this notice are preserved ; in all source code copies. ; This file is offered as-is, without any warranty. ; ; PackBits stream format: ; 0nnnnnnn ... : N+1 literal bytes. ; 10000000 : End stream. ; 1nnnnnnn xx : 129-N Run of X. ; .export pkb_decompress temp = $00 PPU_ADDR = $2006 PPU_DATA = $2007 .segment "CODE" ;; ; Decompresses a PackBits stream directly to PPU_ADDR. ; Compiles to 50 bytes ; ; PPU_ADDR is assumed set ; Y, A: low, high bytes of stream pointer ; X: Preserved ; Trashes: temp 0~1 .proc pkb_decompress ptr = temp ptr_lo = ptr+0 ptr_hi = ptr+1 sta ptr_hi txa ;;or pha ; stx temp_x ldx #$00 stx ptr_lo input_loop: lda (ptr), y iny bne skip_hi inc ptr_hi skip_hi: cpx #$00 beq read_tag bpl run_mode lit_mode: sta PPU_DATA inx jmp input_loop run_mode: inx run_loop: sta PPU_DATA dex bne run_loop beq input_loop ; bra read_tag: eor #$ff tax bmi input_loop inx bpl input_loop end_stream: pla ;; or tax ; ldx temp_x lda ptr_hi rts .endproc