From 5dd788d5a1acc7f23835882420d50e9f020728ac Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Mon, 18 May 2020 13:14:08 -0400 Subject: Did alot of stuff while I was up at the family trailer. - Moved the large enums, and large tables into separate header files. - Added enums for implementing the base extension - Fixed a bug in the assembler. - Worked more on SuBAsm. --- programs/subasm-2.s | 242 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 206 insertions(+), 36 deletions(-) (limited to 'programs/subasm-2.s') diff --git a/programs/subasm-2.s b/programs/subasm-2.s index f77116b..26af017 100644 --- a/programs/subasm-2.s +++ b/programs/subasm-2.s @@ -3,8 +3,7 @@ ; ; by mr b0nk 500 - -.org $A000 +.org incl ; String Constants. prg_name: .byte "SuBAsm" @@ -20,15 +19,23 @@ dir: .byte "word" .byte "dword" .byte "qword" -tok: - .byte '.' - .byte '#' - .byte '$' - .byte '%' - .byte '(' - .byte ')' - .byte ',' + .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" @@ -121,31 +128,194 @@ mne: .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 $8600 +.org parser subasm: - ldb #0 - lda.w #tok - sta.q ptr2 - tba - jsl chk_tok - - jsl chk_mne -chk_tok: - phy #2 - txy - lda (ptr6), y - cmp (ptr2), y - ply #2 - cpx #7 - beq tok_false -tok_true: - inb -tok_false: - stb f -tok_end: - ldb #0 - rtl - -chk_mne: - ply #2 + 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. + 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. -- cgit v1.2.3-13-gbd6f