summaryrefslogtreecommitdiff
path: root/programs/sub-suite/subeditor.s
diff options
context:
space:
mode:
Diffstat (limited to 'programs/sub-suite/subeditor.s')
-rw-r--r--programs/sub-suite/subeditor.s232
1 files changed, 57 insertions, 175 deletions
diff --git a/programs/sub-suite/subeditor.s b/programs/sub-suite/subeditor.s
index cc18b4c..2282a72 100644
--- a/programs/sub-suite/subeditor.s
+++ b/programs/sub-suite/subeditor.s
@@ -3,145 +3,15 @@
; Writen in Sux assembly by
; mr b0nk 500 <b0nk@b0nk.xyz>
-; I/O constants.
-status = $100 ; Keyboard status.
-scr = $101 ; Character that is to be printed.
-kbd = $102 ; Character from the Keyboard.
-step = $110 ; Enables clock stepping, when set.
-
-; Screen constants.
-maxrow = 23 ; Screen's row count.
-maxcol = 79 ; Screen's column count.
-
-; Include SuBAsm.
-.include "subasm.s"
-
-.org $A000
-; String Literals/Constants.
-tok:
- .byte "dab"
-msg:
- .byte "oof, you divided a, and b on me.\n"
-
-ed_name:
- .byte "SuBEditor"
-ed_ver:
- .byte "1"
-ed_sver:
- .byte ".0.0"
-
-ver_str:
- .byte ", version "
-made:
- .byte "Created by, "
-
-author:
- .byte "mr b0nk 500"
-
-string2:
- .byte "You typed, "
-
-; Linewrap bitmask table.
-bits:
- .byte $80, $40, $20, $10, $08, $04, $02, $01
-
-; This label is for any included files.
-incl:
-
-; Linewrap table.
-.org $30000
-bitabl:
- .qword 0
- .qword 0
-
-; SCreen buffer.
-.org bitabl+$1000
-buffer:
-
-; Command buffer.
-.org buffer+$2000
-cmd_buf:
-
-
-; Screen variables.
-.org 0
-scr_row:
- .byte 0
-scr_col:
- .byte 0
-scr_trow:
- .byte 0
-scr_tcol:
- .byte 0
-scr_ptr:
- .word 0
-scr_ptr2:
- .word 0
-scr_ptr3:
- .word 0
-
-; Pseudo registers.
-a:
- .byte 0
-b:
- .byte 0
-c:
- .byte 0
-d:
- .byte 0
-e:
- .byte 0
-f:
- .byte 0
-g:
- .byte 0
-; This pseudo register is always zero.
-zero:
- .qword 0
-; End of pseudo registers.
-
-end:
- .qword 0
-bitmask:
- .byte 0
-scr_str:
- .byte 0
-scr_end:
- .byte 0
-wrapped:
- .byte 0
-
-; Pointers
-ptr:
- .qword 0
-ptr2:
- .qword 0
-ptr3:
- .qword 0
-
-; Main program
.org $8000
reset:
cps ; Reset the processor status register.
ldx.w #$FFFF ; Reset the stack pointer.
txs ;
- ldy #0 ; Reset the Y register.
- sty end ;
- tyx ; Reset the X register.
- lda #maxrow ; Set the end of the screen to the screen's max row count.
- sta scr_end ;
- tya ; Reset the Accumulator.
- sta scr_str ; Set the start of the screen back to zero.
- sta.q bitabl ; Reset the first half of the linewrap table.
- sta.q bitabl+8 ; Reset the second half of the linewrap table.
- inc end ;
- lda.w #$1FFF ; Set the clear count to $1FFF.
- sta.w scr_ptr ;
- lda.d #buffer ; Set the array to be cleared to the screen buffer.
- jsr clr_arr ; Clear the screen buffer.
+ ldy #0 ; Reset Y.
+ tyx ; Reset X.
+ jsr clr_scr ; Clear the screen.
jsr pnt_strt ; Print the starting message.
- lda #$C ; Clear the screen.
- sta scr ;
bra start ; Goto the start of the main program.
clr_arr:
@@ -193,30 +63,32 @@ pnt_strt:
jsr print_char ;
rts ; End of pnt_strt.
-start:
- lda #0 ; TODO: Update this for the Super VIA.
- sta status ; Clear the control register of the I/O adapter.
- tax ; Reset X.
- phy.w ; Save the cursor index for later.
- tay ; Reset the cursor index.
+
+clr_cmd:
+ and #0 ; Reset A.
+ tay ; Reset Y.
lda.w #$3FF ; Set the clear count to $3FF.
sta.w scr_ptr ;
lda.d #cmd_buf ; Set the array to be cleared to the command buffer.
jsr clr_arr ; Clear the command buffer.
- ply.w ; Get back the cursor index.
+ rts ; End of clr_cmd.
+
+
+start:
+ lda #0 ; TODO: Update this for the Super VIA.
+ sta status ; Clear the control register of the I/O adapter.
+ tax ; Reset X.
+ jsr clr_cmd ; Clear the command buffer.
+ jsr update_ptr ; Get the screen buffer index.
+ tay ; Save it in Y.
and #0 ; Reset the Accumulator.
- sta end ;
bra read ; Start reading the keyboard.
read:
- lda #0 ; Reset the Accumulator.
- sta end ; Disable the dummy flag.
- inc end ; Enable the dummy flag.
- lda status ; Did we get a key?
- beq read ; No, so try again.
- jsr getchar ; Yes, and was it a newline?
- beq parse ; Yes, so start parsing the line.
- bra read ; No, so keep looping.
+ jsr getchar ; Get a character.
+ jsr handle_char ; Send the character to the handler routine.
+ beq parse ; The handled character was a newline, so start parsing.
+ bra read ; Keep looping.
parse:
lda #0 ;
@@ -225,6 +97,16 @@ parse:
bra start ;
+getchar:
+ and #0 ; Reset A.
+@loop:
+ lda status ; Did we get a key?
+ beq @loop ; No, so try again.
+ lda kbd ; Yes, so get the typed character.
+@end:
+ rts ; End of getchar.
+
+
print_str:
ldx #0 ; Reset X.
sta.q end ; Save the parameter.
@@ -240,17 +122,19 @@ print_str:
cmp.q end ; Did the pointer change?
bne @reset ; Yes, so set it back.
and #0 ; No, reset the accumulator.
- phy.w ; Save the cursor index.
txy ; Copy the string index into Y.
- lda (ptr), y ; Are we at the end of the string?
- ply.w ; Get the cursor index back.
- beq @end ; Yes, so we're done.
- inx ; No, so increment the string index.
+ ldb (ptr), y ; Are we at the end of the string?
+ beq @end ; Yes, so we're done.
+ jsr update_ptr ; No, so get the screen buffer index.
+ tay ; Save it in Y.
+ tba ; Get the character back.
+ inx ; Increment the string index.
jsr print_char ; Print the character.
bra @loop ; Keep looping.
@end:
ldb #0 ; Enable insert mode.
stb b ;
+ tba ; Reset A.
rts ; End of print_str.
getbit:
@@ -335,8 +219,8 @@ bitpos:
pla ; Get back the bitmask.
rts ; End of bitpos.
-getchar:
- lda kbd ; Get the character that was typed from the keyboard.
+
+handle_char:
ldb #0 ; Reset the B register.
stb e ; Set the temporary row position to zero, in case we get a newline.
stb b ; Enable insert mode.
@@ -354,7 +238,7 @@ getchar:
jsr print_char ; No, so print the character.
lda a ; Get the return value.
cmp #'\n' ; Is the return value, a newline?
- beq @true ; Yes, so return true.
+ beq @true ; Yes, so return true.
bra @false ; No, so return false.
@row:
ldb e ; Get the temporary row position.
@@ -373,7 +257,7 @@ getchar:
@false:
lda #1 ; Return false.
@end:
- rts ; End of getchar.
+ rts ; End of handle_char.
cmd_cpy:
@@ -633,11 +517,11 @@ clr_scr:
sta.w scr_ptr ;
lda.d #buffer ; Set the array to be cleared to the screen buffer.
jsr clr_arr ; Clear the screen buffer.
- tay ;
- lda.w #$3FF ; Set the clear count to $3FF.
- sta.w scr_ptr ;
- lda.d #cmd_buf ; Set the array to be cleared to the command buffer.
- jsr clr_arr ; Clear the screen buffer.
+; tay ;
+; lda.w #$3FF ; Set the clear count to $3FF.
+; sta.w scr_ptr ;
+; lda.d #cmd_buf ; Set the array to be cleared to the command buffer.
+; jsr clr_arr ; Clear the screen buffer.
sta scr_col ;
sta scr_row ;
jsr update_pos ;
@@ -1051,9 +935,7 @@ isshftdown:
rts ;
-update_pos:
- ldb #1 ; Set the F pseudo register to one, to fix some bugs.
- stb f ;
+update_ptr:
clc ; Clear the carry flag.
lda scr_row ; Add the cursor's line number,
adc scr_str ; with the starting line number to get the absolute line number.
@@ -1061,6 +943,13 @@ update_pos:
mul #maxcol+1 ; Multiply the line number by the screen's max column count, plus 1.
clc ; Clear the carry flag.
adc scr_col ; Add the cursor's column number to get the screen index.
+ rts ; End of update_ptr.
+
+
+update_pos:
+ ldb #1 ; Set the F pseudo register to one, to fix some bugs.
+ stb f ;
+ jsr update_ptr ; Update the screen buffer index.
tay ; Place the index into the Y register.
tba ; Reset A.
lda #$1B ; Print an escape character
@@ -1071,6 +960,7 @@ update_pos:
jsr getcol ; Start printing the column number to the screen.
lda #'H' ; Print 'H'
sta scr ; to the screen.
+ ;inc step ;
rts ; End of update_pos.
getrow:
@@ -1206,6 +1096,7 @@ rdrw_ln:
sta f ;
rts ;
+
set_ptr:
cpb #1 ; Are we setting the second pointer?
beq @ptr2 ; Yes, so start setting it.
@@ -1224,12 +1115,3 @@ set_ptr:
sta.q ptr3 ; Set the third pointer.
@end:
rts ; End of set_ptr.
-
-; Entry point for SuBAsm.
-parser:
-
-.org $FFC0
-.qword reset
-a
-d
-