summaryrefslogtreecommitdiff
path: root/programs/subasm-2.s
diff options
context:
space:
mode:
Diffstat (limited to 'programs/subasm-2.s')
-rw-r--r--programs/subasm-2.s323
1 files changed, 0 insertions, 323 deletions
diff --git a/programs/subasm-2.s b/programs/subasm-2.s
deleted file mode 100644
index f10dac8..0000000
--- a/programs/subasm-2.s
+++ /dev/null
@@ -1,323 +0,0 @@
-; SuBAsm
-; The Sux Bootstrapped Assembler.
-;
-; by mr b0nk 500 <b0nk@b0nk.xyz>
-
-.org incl
-; String Constants.
-prg_name:
- .byte "SuBAsm"
-ver_txt:
- .byte ", version "
-ver_num:
- .byte "0.1"
-
-; Directives.
-dir:
- .byte "org"
- .byte "byte"
- .byte "word"
- .byte "dword"
- .byte "qword"
- .byte "include"
-
-; Short form Commands.
-sh_cmds:
- .byte "vlahirs"
-
-; Commands.
-cmds:
- .byte "viewmem"
- .byte "list"
- .byte "asm"
- .byte "help"
- .byte "inst"
- .byte "run"
- .byte "set"
-
-; Instruction Mnemonics.
-mne:
- .byte "AAB"
- .byte "ABA"
- .byte "ADC"
- .byte "AND"
- .byte "ARB"
- .byte "ASR"
- .byte "BCC"
- .byte "BCS"
- .byte "BEQ"
- .byte "BNE"
- .byte "BNG"
- .byte "BPO"
- .byte "BRK"
- .byte "BVC"
- .byte "BVS"
- .byte "CAB"
- .byte "CLC"
- .byte "CLI"
- .byte "CLV"
- .byte "CMP"
- .byte "CPB"
- .byte "CPS"
- .byte "CPX"
- .byte "CPY"
- .byte "DAB"
- .byte "DEB"
- .byte "DEC"
- .byte "DEX"
- .byte "DEY"
- .byte "DIV"
- .byte "ENT"
- .byte "INB"
- .byte "INC"
- .byte "INX"
- .byte "INY"
- .byte "JMP"
- .byte "JSL"
- .byte "JSR"
- .byte "LDA"
- .byte "LDB"
- .byte "LDX"
- .byte "LDY"
- .byte "LLB"
- .byte "LRB"
- .byte "LSL"
- .byte "LSR"
- .byte "MAB"
- .byte "MUL"
- .byte "NOP"
- .byte "OAB"
- .byte "ORA"
- .byte "PHA"
- .byte "PHB"
- .byte "PHP"
- .byte "PHX"
- .byte "PHY"
- .byte "PLA"
- .byte "PLB"
- .byte "PLP"
- .byte "PLX"
- .byte "PLY"
- .byte "RLB"
- .byte "ROL"
- .byte "ROR"
- .byte "RRB"
- .byte "RTI"
- .byte "RTL"
- .byte "RTS"
- .byte "SAB"
- .byte "SBC"
- .byte "SEC"
- .byte "SEI"
- .byte "STA"
- .byte "STB"
- .byte "STT"
- .byte "STX"
- .byte "STY"
- .byte "TAB"
- .byte "TAX"
- .byte "TAY"
- .byte "TBA"
- .byte "TSX"
- .byte "TXA"
- .byte "TXS"
- .byte "TXY"
- .byte "TYA"
- .byte "TYX"
- .byte "WAI"
- .byte "XAB"
- .byte "XOR"
-
-; Command subroutine table.
-cmd_srt:
- .word viewmem
- .word list
- .word asm
- .word help
- .word inst
- .word run
- .word set
-
-; Hex character table.
-hex_char:
- .byte "0123456789ABCDEF"
-
-
-.org $4400
-; Subroutine pointer.
-sub_ptr:
- .word 0
-
-; Indecies.
-idx0:
- .word 0
-idx1:
- .word 0
-idx2:
- .word 0
-
-; Program Counter.
-prg_cnt:
- .qword 0
-
-; Start of program code.
-.org parser
-subasm:
- ldb #0 ; Set the first pointer
- lda.w #cmd_buf ; to the command buffer.
- jsl set_ptr ;
- tba ; Reset A.
- tax ; Reset X.
- jsl chk_shcmd ; Did we get a shortend command?
- bne parse_cmd ; Yes, so skip everything else.
- jsl chk_cmd ; No, but did we get a full command?
- bne parse_cmd ; Yes, so skip everything else.
- jsl lexer ; No, so start lexing this line.
-subasm_end:
- rtl ; End of subasm.
-
-parse_cmd:
- inb ; Set the second pointer
- lda.w #cmd_srt ; to the command subroutine table.
- jsl set_ptr ;
- deb ; Reset B.
- tba ; Reset A.
- lda f ; Get the command ID.
- cmp #8 ; Is the command ID greater than the command count?
- bcs subasm_end ; Yes, so we're done.
- lsl #1 ; No, so multiply the command ID by two.
- phy #2 ; Preserve the screen buffer position.
- tay ; Set the index to the offset that we just calculated.
- lda.w (ptr2), y ; Get the command subroutine, from the command subroutine table.
- ply #2 ; Get back the screen buffer position.
- ldb #2 ; Save it in the third pointer.
- jsl set_ptr ;
- ldb #0 ; Reset B.
- jsr (ptr3) ; Run the command's subroutine.
- jmp subasm_end ; We are done.
-
-chk_shcmd:
- inb ; Set the second pointer
- lda.w #sh_cmds ; to the shortend command table.
- jsl set_ptr ;
- deb ; Reset B.
- tba ; Reset A.
- phy #2 ; Preserve the screen buffer position.
- txy ; Set our index to zero.
- lda (ptr), y ; Is there nothing in the command buffer?
- beq shcmd_fail ; Yes, so return that we failed.
- cmp #' ' ; No, but is this character, a space?
- beq shcmd_fail ; Yes, so return that we failed.
-shcmd_loop:
- ldb (ptr2), y ; Are we at the end of the table?
- beq shcmd_fail ; Yes, so return that we failed.
- cab ; No, so did the character match?
- beq shcmd_fnd ; Yes, so check if there are any arguments.
- iny ; No, so check the next command.
- jmp shcmd_loop ; Keep looping.
-shcmd_fnd:
- sty f ; Save the command ID.
- ldy #1 ; Check the next character in the command buffer.
- lda (ptr), y ; Is this the end of the buffer?
- beq shcmd_true ; Yes, so return that we succeded.
- cmp #' ' ; No, but is this a space?
- beq shcmd_true ; Yes, so return that we succeded.
- jmp shcmd_fail ; No, so return that we failed.
-shcmd_true:
- lda #1 ; Return true.
- jmp shcmd_end ; We are done.
-shcmd_fail:
- tba ; Return false.
- tax ; Reset X.
-shcmd_end:
- ldb #0 ; Reset B.
- ply #2 ; Get back the screen buffer position.
- rtl ; End of chk_shcmd.
-
-print_hex:
- pha #8 ; Preserve the hex value.
- ldb #1 ; Set the second pointer
- lda.w hex_char ; to the start of hex character table.
- jsl set_ptr ;
- ldb #0 ; Reset B.
- pla #8 ; Get the hex value back.
-pnthex_lp:
- pha #8 ; Preserve the hex value.
- and #$F ; Mask the lowest nibble.
- phx #2 ; Preserve the digit count.
- phy #2 ; Preserve the screen buffer position.
- tay ; Get the index for the hex digit.
- lda (ptr2), y ; Get the hex digit.
- ply #2 ; Get back the screen buffer position.
- jsl print_char ; Print the hex digit.
- plx #2 ; Get the digit count back.
- pla #8 ; Get the hex value back.
-pnthex_lp1:
- cpx #1 ; Is the digit count less than one?
- bcc pnthex_lp2 ; Yes, so don't decrement the digit count.
- dex ; No, but was the digit count zero, when decremented?
- beq pnthex_end ; Yes, so we're done.
- jmp pnthex_lp3 ; No, so get the next nibble.
-pnthex_lp2:
- ldb #1 ; Enable auto digit count.
-pnthex_lp3:
- lsr #4 ; No, but is the next nibble, a zero?
- beq pnthex_lp4 ; Yes, so check if auto digit count is enabled.
- jmp pnthex_lp ; No, so print the next digit.
-pnthex_lp4:
- cpb #1 ; Is auto digit count enabled?
- beq pnthex_end ; Yes, so we're done.
- jmp pnthex_lp ; No, so keep printing more digits.
-pnthex_end:
- ldb #0 ; Reset B.
- rtl ; End of print_hex.
-
-print_space:
- lda #' ' ; Set the character to a space.
- phb #1 ; Preserve the spacing count.
- ldb #1 ; Enable replace mode.
- stb b ;
- jsl print_char ; Print the space.
- plb #1 ; Get the spacing count back.
- deb ; Have we printed all of the spacing?
- beq pntsp_end ; Yes, so we're done.
- jmp print_space ; No, so keep printing spaces.
-pntsp_end:
- rtl ; End of print_space.
-
-viewmem:
- pha #8 ; Preserve the address.
- lda #'\n' ; Print a newline.
- jsl print_char ;
- ldb #19 ; Print 19 spaces.
- jsl print_space ;
-vmem_lp:
- pla #8 ; Get the address back.
- nop ;
-vmem_end:
- rts ; End of viewmem.
-
-list:
- nop ;
-list_end:
- rts ; End of list.
-asm:
- nop ;
-asm_end:
- rts ; End of asm.
-help:
- nop ;
-help_end:
- rts ; End of help.
-inst:
- nop ;
-inst_end:
- rts ; End of inst.
-run:
- nop ;
-run_end:
- rts ; End of run.
-set:
- nop ;
-set_end:
- rts ; End of set.