MAX_SYM = $800
.include "lexer.s"
.include "utils.s"
.org incl
asm_name:
.byte "SuBAsm"
asm_ver:
.byte "0.1"
dir:
.byte "org"
.byte "byte"
.byte "word"
.byte "dword"
.byte "qword"
.byte "include"
sh_cmds:
.byte "vlahirs"
cmds:
.byte "viewmem"
.byte "list"
.byte "asm"
.byte "help"
.byte "inst"
.byte "run"
.byte "set"
mne:
.byte "CPS", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $00
.byte "ADC", $01, $06, $FF, $FF, $FF, $FF, $FF, $04, $FF
.byte "AAB", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $02
.byte "PHP", $08, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
.byte "CPB", $09, $2D, $FF, $FF, $55, $AD, $AC, $2C, $FF
.byte "PHB", $0A, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
.byte "DEC", $FF, $0D, $FF, $FF, $FF, $FF, $FF, $0C, $E5
.byte "JMP", $FF, $0E, $FF, $FF, $CE, $FF, $FF, $10, $FF
.byte "SBC", $11, $16, $FF, $FF, $FF, $FF, $FF, $14, $FF
.byte "SAB", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $12
.byte "ENT", $18, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
.byte "CPY", $19, $3D, $FF, $FF, $85, $FF, $FF, $4C, $FF
.byte "PLB", $1A, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
.byte "INC", $FF, $1D, $FF, $FF, $FF, $FF, $FF, $1C, $F5
.byte "JSR", $FF, $1E, $FF, $FF, $BE, $FF, $FF, $20, $FF
.byte "AND", $21, $26, $FF, $FF, $FF, $FF, $FF, $24, $FF
.byte "ABA", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $22
.byte "PLP", $28, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
.byte "CPX", $29, $4D, $FF, $FF, $B5, $FF, $FF, $3C, $FF
.byte "PHY", $2A, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
.byte "BPO", $FF, $2E, $FF, $FF, $FF, $FF, $FF, $30, $FF
.byte "ORA", $31, $36, $FF, $FF, $FF, $FF, $FF, $34, $FF
.byte "OAB", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $32
.byte "STT", $38, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
.byte "PLY", $3A, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
.byte "BNG", $FF, $3E, $FF, $FF, $FF, $FF, $FF, $40, $FF
.byte "XOR", $41, $46, $FF, $FF, $FF, $FF, $FF, $44, $FF
.byte "XAB", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $42
.byte "PHA", $48, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
.byte "PHX", $4A, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
.byte "BCS", $FF, $4E, $FF, $FF, $FF, $FF, $FF, $50, $FF
.byte "LSL", $51, $56, $FF, $FF, $FF, $FF, $FF, $54, $FF
.byte "LLB", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $52
.byte "CLC", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $58
.byte "PLX", $5A, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
.byte "BCC", $FF, $5E, $FF, $FF, $FF, $FF, $FF, $60, $FF
.byte "LSR", $61, $66, $FF, $FF, $FF, $FF, $FF, $64, $FF
.byte "LRB", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $62
.byte "PLA", $68, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
.byte "TAB", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $6A
.byte "BEQ", $FF, $6E, $FF, $FF, $FF, $FF, $FF, $70, $FF
.byte "ROL", $71, $76, $FF, $FF, $FF, $FF, $FF, $74, $FF
.byte "RLB", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $72
.byte "SEC", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $78
.byte "TBA", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $7A
.byte "BNE", $FF, $7E, $FF, $FF, $FF, $FF, $FF, $80, $FF
.byte "ROR", $81, $86, $FF, $FF, $FF, $FF, $FF, $84, $FF
.byte "RRB", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $82
.byte "DEY", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $88
.byte "TAY", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $8A
.byte "BVS", $FF, $8E, $FF, $FF, $FF, $FF, $FF, $90, $FF
.byte "MUL", $91, $96, $FF, $FF, $FF, $FF, $FF, $94, $FF
.byte "MAB", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $92
.byte "CLI", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $98
.byte "TYA", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $9A
.byte "BVC", $FF, $9E, $FF, $FF, $FF, $FF, $FF, $A0, $FF
.byte "DIV", $A1, $A6, $FF, $FF, $FF, $FF, $FF, $A4, $FF
.byte "DAB", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $A2
.byte "INY", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $A8
.byte "TAX", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $AA
.byte "RTS", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $AE
.byte "CMP", $B1, $B6, $FF, $FF, $25, $7D, $7C, $B4, $FF
.byte "CAB", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $B2
.byte "SEI", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $B8
.byte "LDX", $B9, $BD, $FF, $C9, $95, $FF, $FF, $BC, $FF
.byte "TXA", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $BA
.byte "RTI", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $C0
.byte "LDA", $C1, $C6, $79, $39, $05, $5D, $5C, $C4, $FF
.byte "DEX", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $C5
.byte "CLV", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $C8
.byte "TYX", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $CA
.byte "STA", $FF, $CD, $89, $49, $15, $6D, $6C, $CC, $FF
.byte "TSX", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $D0
.byte "LDB", $D1, $D6, $99, $59, $35, $8D, $8C, $D4, $FF
.byte "INX", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $D5
.byte "WAI", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $D8
.byte "TXY", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $DA
.byte "STB", $FF, $DD, $A9, $69, $45, $9D, $9C, $DC, $FF
.byte "TXS", $E0, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
.byte "LDY", $E1, $E6, $E9, $FF, $65, $FF, $FF, $E4, $FF
.byte "BRK", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $E8
.byte "NOP", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $EA
.byte "STY", $FF, $ED, $F9, $FF, $75, $FF, $FF, $EC, $FF
.byte "DEB", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $EE
.byte "ASR", $F1, $F6, $FF, $FF, $FF, $FF, $FF, $F4, $FF
.byte "ARB", $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $F2
.byte "STX", $FF, $FD, $FF, $D9, $A5, $FF, $FF, $FC, $FF
.byte "INB" $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FE
cmd_srt:
.word viewmem
.word list
.word asm
.word help
.word inst
.word run
.word set
lexer_data:
.org $20000
tokline:
.org cmd_buf+$400
prg_cnt:
.qword 0
hex_str:
.qword 0, 0
strbuf:
.org strbuf+$80
sub_ptr:
.word 0
idx0:
.qword 0
idx1:
.qword 0
idx2:
.qword 0
idx3:
.qword 0
ctok:
.word 0
ltok:
.word 0
lexeme:
.org lexeme+$100
sym:
.org sym+$8000
fix:
.org parser
subasm:
ldb
lda.d
jsr set_ptr
tba
tax
jsr chk_shcmd
bne @cmd
jsr chk_cmd
bne @cmd
jsr lex
jmp @end
@cmd:
ldb
lda.d
jsr set_ptr
deb
tba
lda f
cmp
bcs @end
lsl
phy
tay
lda.w (ptr2), y
ply
ldb
jsr set_ptr
ldb
jsr (ptr3)
@end:
rts
chk_shcmd:
tba
inb
lda.w
jsr set_ptr
deb
tba
phy
txy
lda (ptr), y
beq @false
cmp
beq @false
jsr tolower
@loop:
ldb (ptr2), y
beq @false
cab
beq @found
iny
jmp @loop
@found:
sty f
ldy
lda (ptr), y
beq @true
cmp
beq @true
jmp @false
@true:
lda
jmp @end
@false:
ldb
tba
tax
@end:
ply
rts
chk_cmd:
tba
tax
sta.q idx0
sta.q idx1
@loop:
lda.w
clc
adc.w idx0
pha
jsr strcasecmp
pla
beq @true
ldb idx1
cpb
beq @false
inc idx1
@getlen:
jsr strlen
inx
txa
clc
adc.w idx0
sta.w idx0
jmp @loop
@true:
ldb idx1
stb f
ldb
jmp @end
@false:
ldb
@end:
rts
viewmem:
lda.q prg_cnt
sta.q idx0
and
sta idx0
lda
sta scr_col
jsr update_pos
jsr print_lo
ldx
ldb
stb idx1
@loop:
lda
jsr print_char
jsr print_hi
jsr print_chunk
lda.d
jsr print_str
inc idx1
ldb idx1
cpb
beq @end
lda.q idx0
clc
adc
sta.q idx0
and
jmp @loop
@end:
lda
jsr print_char
and
rts
list:
nop
@end:
rts
asm:
nop
@end:
rts
help:
nop
@end:
rts
inst:
nop
@end:
rts
run:
nop
@end:
rts
set:
nop
@end:
rts
lexer: