// included by decode.asm // cycles on extra-padded "Elizabeth Mary Patricia James Robert": // 3485-55=3430 (includes jsr and rts) // program size: 0xFB // instructions: 1248-17=1231 (includes jsr and rts) decode: // NOTE: output/input pointers cannot cross page boundaries. // that means the effective longest lengths of output/input are 256/192 bytes. decode00: // decode from offset 0, unknown code length (READS A BYTE) ldy #$00 lda ($02),y // load from input tax // stash for after branch eor #$C0 // TODO: just use a cmp instruction? and #$C0 beq decode06 // branch when mask is fully set // fallthru decode04 decode04: // decode from offset 0, 4-bit code (then 4 under) txa lsr lsr lsr lsr tay lda decode_lut0xxx,y ldy #$00 sta ($00),y // write to output inc $00 // advance output //jsr decode_advance_output bne decode40 // always branch (unless page boundary) db $02 // jam decode06: // decode from offset 0, 6-bit code (then 2 under) txa lsr lsr and #$0F tay lda decode_lut11xxxx,y ldy #$00 sta ($00),y // write to output inc $00 // advance output //jsr decode_advance_output bne decode60 // always branch (unless page boundary) db $02 // jam decode20: // decode from offset 2, unknown code length txa eor #$30 and #$30 beq decode26 // branch when mask is fully set decode24: // decode from offset 2, 4-bit code (then 2 under) txa lsr lsr and #$0F tay lda decode_lut0xxx,y ldy #$00 sta ($00),y // write to output inc $00 // advance output //jsr decode_advance_output bne decode60 // always branch (unless page boundary) db $02 // jam decode26: // decode from offset 2, 6-bit code (then aligned) txa and #$0F tay lda decode_lut11xxxx,y ldy #$00 sta ($00),y // write to output //inc $02 // advance input //beq die // never branch (unless page boundary) jsr decode_advance_input inc $00 // advance output //jsr decode_advance_output bne decode00 // always branch (unless page boundary) db $02 // jam decode40: // decode from offset 4, unknown code length //inc $02 // advance input //beq die // never branch (unless page boundary) jsr decode_advance_input txa eor #$0C // TODO: just use a cmp instruction? and #$0C beq decode46 // branch when mask is fully set // fallthru decode04 decode44: // decode from offset 4, 4-bit code (then aligned) txa and #$0F tay lda decode_lut0xxx,y ldy #$00 sta ($00),y // write to output inc $00 // advance output //jsr decode_advance_output bne decode00 // always branch (unless page boundary) db $02 // jam decode46: // decode from offset 4, 6-bit code (then 2 over) (READS A BYTE) txa and #$03 asl asl sta $04 ldy #$00 lda ($02),y // load from input tax rol rol rol and #$03 ora $04 tay lda decode_lut11xxxx,y ldy #$00 sta ($00),y // write to output inc $00 // advance output //jsr decode_advance_output bne decode20 // always branch (unless page boundary) db $02 // jam decode60: // decode from offset 6, unknown code length (READS A BYTE) //inc $02 // advance input //beq die // never branch (unless page boundary) jsr decode_advance_input ldy #$00 lda ($02),y // load from input tay txa eor #$03 and #$03 beq decode66 // branch when mask is fully set // fallthru decode64 decode64: // decode from offset 6, 4-bit code (then 2 over) txa and #$03 asl asl sta $04 tya // load in (restore) the new input tax // and put it in X like the rest of the code expects rol rol rol and #$03 ora $04 tay lda decode_lut0xxx,y ldy #$00 sta ($00),y // write to output inc $00 // advance output //jsr decode_advance_output bne decode20_shim // always branch (unless page boundary) db $02 // jam die: db $F2 // um lammer jammy decode20_shim: jmp decode20 decode66: // decode from offset 6, 6-bit code (then 4 over) tya // load in (restore) the new input tax // and put it in X like the rest of the code expects lsr lsr lsr lsr tay lda decode_lut11xxxx,y ldy #$00 sta ($00),y // write to output inc $00 // advance output //jsr decode_advance_output bne decode40 // always branch (unless page boundary) db $02 // jam decode_advance_input: // do not modify X or Y here inc $02 beq die // never branch (unless page boundary) when_to_stop() rts if 0 { decode_advance_output: // do not modify X or Y here lda $02 cmp #(name1 & 0xFF) beq decode_begin_next cmp #(name2 & 0xFF) beq decode_begin_next cmp #(name3 & 0xFF) beq decode_begin_next cmp #(name4 & 0xFF) beq decode_begin_next cmp #(name5 & 0xFF) beq decode_exit inc $00 // advance output //beq die // never branch (unless page boundary) rts } decode_begin_next: //inc $00 // advance output //beq die // never branch (unless page boundary) pla pla jmp decode00 decode_exit: pla pla rts //db $D2 // jam (D is for Done, i guess) // // done: db $02 // jam // // // vim:ft=snes_bass