backyard/6502_name_codec/decode_v2.asm

177 lines
3.5 KiB
NASM

// included by decode.asm
// cycles on extra-padded "Elizabeth Mary Patricia James Robert":
// 4035-55=3980 (includes jsr and rts)
// program size: 0xCF
// instructions: 1358-17=1341 (includes jsr and rts)
decode_advance_input:
// do not modify X or Y here
inc $02
beq die // never branch (unless page boundary)
when_to_stop()
rts
decode_exit:
pla
pla
rts
//db $D2 // jam (D is for Done, i guess)
decode_common:
tay
lda decode_lut0xxx,y
ldy #$00
sta ($00),y // write to output
inc $00 // advance output
beq die // never branch (unless page boundary)
rts
decode_uncommon:
tay
lda decode_lut11xxxx,y
ldy #$00
sta ($00),y // write to output
inc $00 // advance output
beq die // never branch (unless page boundary)
rts
die:
db $F2 // um lammer jammy
decode_begin_next:
//inc $00 // advance output
//beq die // never branch (unless page boundary)
pla
pla
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
jsr decode_common
bne decode40 // always branch (unless page boundary)
decode06: // decode from offset 0, 6-bit code (then 2 under)
txa
lsr
lsr
and #$0F
jsr decode_uncommon
bne decode60 // always branch (unless page boundary)
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
jsr decode_common
bne decode60 // always branch (unless page boundary)
decode26: // decode from offset 2, 6-bit code (then aligned)
jsr decode_advance_input
txa
and #$0F
jsr decode_uncommon
bne decode00 // always branch (unless page boundary)
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
jsr decode_common
bne decode00 // always branch (unless page boundary)
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
jsr decode_uncommon
bne decode20 // always branch (unless page boundary)
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
jsr decode_common
bne decode20 // always branch (unless page boundary)
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
jsr decode_uncommon
bne decode40 // always branch (unless page boundary)
// //
done:
db $02 // jam
// //
// vim:ft=snes_bass