146 lines
3 KiB
NASM
146 lines
3 KiB
NASM
|
arch nes.cpu
|
||
|
|
||
|
output "decode.bin", create
|
||
|
fill 65536
|
||
|
origin 0
|
||
|
|
||
|
macro align(size) { // Align Byte Amount
|
||
|
while (pc() % {size}) {
|
||
|
db 0
|
||
|
}
|
||
|
}
|
||
|
|
||
|
macro nops(new_pc) {
|
||
|
if (pc() > {new_pc}) {
|
||
|
error "PC is already past the point specified"
|
||
|
}
|
||
|
while (pc() < {new_pc}) {
|
||
|
print "adding a byte of padding at "
|
||
|
print pc()
|
||
|
print "\n"
|
||
|
nop
|
||
|
}
|
||
|
}
|
||
|
|
||
|
define version(6)
|
||
|
|
||
|
fill 8, $02 // jams
|
||
|
|
||
|
start:
|
||
|
cld // clear BCD flag
|
||
|
clc // clear carry
|
||
|
clv // clear overflow
|
||
|
// TODO: what i actually should be doing is an RTI
|
||
|
pla
|
||
|
pla
|
||
|
tax
|
||
|
tay
|
||
|
nop //php // push processor status just to advance stack a bit
|
||
|
|
||
|
macro when_to_stop() {
|
||
|
if 1 {
|
||
|
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
|
||
|
} else {
|
||
|
// FIXME: doesn't work because output has already advanced to a null byte.
|
||
|
ldy #0
|
||
|
lda #$20 // ascii space
|
||
|
eor ($00),y // load from output
|
||
|
beq decode_begin_next
|
||
|
lda $02
|
||
|
cmp #(name5 & 0xFF)
|
||
|
beq decode_exit
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// decode subroutine arguments:
|
||
|
lda #(names_out)
|
||
|
sta $00
|
||
|
lda #(names_out >> 8)
|
||
|
sta $01
|
||
|
lda #(names)
|
||
|
sta $02
|
||
|
lda #(names >> 8)
|
||
|
sta $03
|
||
|
jsr decode
|
||
|
db $D2 // jam (D for Done, i guess)
|
||
|
|
||
|
align(16)
|
||
|
// reorder() { python3 -c 's=__import__("sys").argv[1];print("".join(s[int(bin(len(s)|i)[-1:2:-1],2)] for i in range(len(s))))' "$@"; }
|
||
|
decode_lut0xxx:
|
||
|
db "ETAOINSH"
|
||
|
//db "EIASTNOH"
|
||
|
decode_lut10xx:
|
||
|
db "RDLU"
|
||
|
//db "RDLU"
|
||
|
if {version} >= 3 && {version} <= 6 {
|
||
|
db "????"
|
||
|
}
|
||
|
decode_lut11xxxx:
|
||
|
db "CMFPGWYBVKXJQZ. "
|
||
|
//db "CVGQFXY.MKWZPJB "
|
||
|
|
||
|
//origin 0x100 - 6 * 5 * 2
|
||
|
align(16)
|
||
|
names_out:
|
||
|
fill 6 * 5 * 2
|
||
|
|
||
|
db $FF
|
||
|
|
||
|
origin 0x200
|
||
|
names:
|
||
|
name0:
|
||
|
// FIXME: names are truncated unless they end in a padding byte!
|
||
|
db $0A,$4F,$4B,$70,$17,$FF // Elizabeth
|
||
|
name1:
|
||
|
db $C4,$A3,$6F,$FF,$FF,$FF // Mary 110001 00.10 1000 11.0110
|
||
|
name2:
|
||
|
db $CC,$86,$13,$04,$2F,$FF // Patricia
|
||
|
name3:
|
||
|
db $EC,$B1,$06,$FF,$FF,$FF // James 111011 00.10 110001. 0000 0110.
|
||
|
name4:
|
||
|
db $83,$DC,$20,$7F,$FF,$FF // Robert
|
||
|
name5:
|
||
|
|
||
|
origin 0x300
|
||
|
if {version} == 1 { ; include "decode_v1.asm"
|
||
|
} else if {version} == 2 { ;include "decode_v2.asm"
|
||
|
} else if {version} == 3 { ;include "decode_v3.asm"
|
||
|
} else if {version} == 4 { ;include "decode_v4.asm"
|
||
|
} else if {version} == 5 { ;include "decode_v5.asm"
|
||
|
} else if {version} == 6 { ;include "decode_v6.asm"
|
||
|
}
|
||
|
|
||
|
align(16)
|
||
|
db "DONE: "
|
||
|
dw done
|
||
|
|
||
|
origin 0xFFFC
|
||
|
db start
|
||
|
db start >> 8
|
||
|
|
||
|
//macro revbit(variable x) {
|
||
|
// evaluate lo(((x&(1<<7))>>7)|((x&(1<<6))>>5)|((x&(1<<5))>>3)|((x&(1<<4))>>1))
|
||
|
// evaluate hi(((x&(1<<3))<<1)|((x&(1<<2))<<3)|((x&(1<<1))<<5)|((x&(1<<0))<<7))
|
||
|
// db {lo}|{hi}
|
||
|
//}
|
||
|
//macro makename(variable a, variable b, variable c, variable d, variable e) {
|
||
|
// revbit(a)
|
||
|
// revbit(b)
|
||
|
// revbit(c)
|
||
|
// revbit(d)
|
||
|
// revbit(e)
|
||
|
//}
|
||
|
//makename($01,$23,$45,$67,$89)
|
||
|
|
||
|
// vim:ft=snes_bass
|