summaryrefslogtreecommitdiff
path: root/programs
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2020-05-18 13:14:08 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2020-05-18 13:14:08 -0400
commit5dd788d5a1acc7f23835882420d50e9f020728ac (patch)
tree2b9226863fc44e5bce88eb85be1f0ee97ede1922 /programs
parent545bb8591e8003912b6c6b494acefd74e6b3abfd (diff)
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.
Diffstat (limited to 'programs')
-rw-r--r--programs/subasm-2.s242
-rw-r--r--programs/subeditor.s24
2 files changed, 226 insertions, 40 deletions
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 <b0nk@b0nk.xyz>
-
-.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.
diff --git a/programs/subeditor.s b/programs/subeditor.s
index d16915d..bdd3a11 100644
--- a/programs/subeditor.s
+++ b/programs/subeditor.s
@@ -13,6 +13,9 @@ step = $C010 ; Enables clock stepping, when set.
maxrow = 23 ; Screen's row count.
maxcol = 79 ; Screen's column count.
+; Include SuBAsm.
+.include "subasm-2.s"
+
.org $A000
; String Literals/Constants.
tok:
@@ -35,6 +38,8 @@ bits:
.byte $02
.byte $01
+; This label is for any included files.
+incl:
; Linewrap table.
.org $1000
@@ -127,6 +132,7 @@ reset:
lda.w #buffer ; Set the array to be cleared to the screen buffer.
jsl clr_arr ; Clear the screen buffer.
jmp start ; Goto the start of the main program.
+
clr_arr:
phb #1 ; Preserve whatever was in B.
ldb #0 ; Clear B.
@@ -371,7 +377,9 @@ cmd_cpy_lp1:
sta (ptr2), y ; Copy one byte from the screen buffer, to the command buffer.
inx ; Increment the command buffer index.
ply #2 ; Get back the screen index.
- iny ; Increment the screen index.
+ cpx.w #$3FF ; Are we at the end of the command buffer?
+ bcs cmd_cpy_nd0 ; Yes, so we're done.
+ iny ; No, so increment the screen index.
inb ; Increment the byte count.
lsr #8 ; Shift in the next byte.
stb g ; Save the byte count.
@@ -383,13 +391,17 @@ cmd_cpy_lp1:
cpb #7 ; Did we shift in eight bytes?
beq cmd_cpy_lp ; Yes, so get eight more bytes.
jmp cmd_cpy_lp1 ; No, so keep shifting in more bytes.
+cmd_cpy_nd0:
+ ldb #0 ; Reset B.
+ phy #2 ; Save the screen index.
+ txy ; Get the command buffer index.
+ stb (ptr2), y ; Terminate the command buffer.
+ ply #2 ; Get back the screen index.
cmd_cpy_nd:
tab ; The B register is zero, so clear the Accumulator.
rtl ; End of cmd_cpy.
-
-
findst:
lda #0 ;
findst_lp:
@@ -406,6 +418,7 @@ findst_done:
cmp #0 ;
rtl ;
+
fndend:
phb #1 ; Save the contents of the B register.
ldb #0 ; Make sure that set_ptr sets the first pointer.
@@ -1194,7 +1207,7 @@ print_buf:
jsl print_str ;
lsr #$10 ; Clear the Accumulator.
cmd_clr:
- lda #10 ;
+ lda #'\n' ;
jsl print_char ;
jmp start ;
@@ -1243,6 +1256,9 @@ set_ptr3:
setptr_end:
rtl ; End of set_ptr.
+; Entry point for SuBAsm.
+parser:
+
.org $FFC0
.qword reset
a