diff options
Diffstat (limited to 'programs/subeditor.s')
-rw-r--r-- | programs/subeditor.s | 302 |
1 files changed, 139 insertions, 163 deletions
diff --git a/programs/subeditor.s b/programs/subeditor.s index bdd3a11..e344588 100644 --- a/programs/subeditor.s +++ b/programs/subeditor.s @@ -4,17 +4,17 @@ ; mr b0nk 500 <b0nk@b0nk.xyz> ; I/O constants. -status = $C000 ; Keyboard status. -scr = $C001 ; Character that is to be printed. -kbd = $C002 ; Character from the Keyboard. -step = $C010 ; Enables clock stepping, when set. +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-2.s" +.include "subasm.s" .org $A000 ; String Literals/Constants. @@ -22,36 +22,49 @@ tok: .byte "dab" msg: .byte "oof, you divided a, and b on me.\n" -string: - .byte "Please, type something.\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" + +;sub_name: +; .byte "SuB Suite" +;sub_ver: +; .byte "0.9" + string2: .byte "You typed, " ; Linewrap bitmask table. bits: - .byte $80 - .byte $40 - .byte $20 - .byte $10 - .byte $08 - .byte $04 - .byte $02 - .byte $01 + .byte $80, $40, $20, $10, $08, $04, $02, $01 ; This label is for any included files. incl: ; Linewrap table. -.org $1000 +.org $30000 bitabl: .qword 0 .qword 0 -; Input buffer. -.org $2000 +; SCreen buffer. +.org bitabl+$1000 buffer: -.org $4000 +; Command buffer. +.org buffer+$2000 cmd_buf: @@ -93,7 +106,7 @@ zero: ; End of pseudo registers. end: - .word 0 + .qword 0 bitmask: .byte 0 scr_str: @@ -129,8 +142,9 @@ reset: inc end ; lda.w #$1FFF ; Set the clear count to $1FFF. sta.w scr_ptr ; - lda.w #buffer ; Set the array to be cleared to the screen buffer. + lda.d #buffer ; Set the array to be cleared to the screen buffer. jsl clr_arr ; Clear the screen buffer. + jsl pnt_strt ; Print the starting message. jmp start ; Goto the start of the main program. clr_arr: @@ -163,6 +177,25 @@ clr_arr_end: plb #1 ; Get whatever was in the B register, back. rtl ; End of clr_arr. +pnt_strt: + lda.w #ed_name ; Print the name of the editor. + jsl print_str ; + lda.w #ver_str ; Print the version text. + jsl print_str ; + lda.w #ed_ver ; Print the version number. + jsl print_str ; + lda.w #ed_sver ; Print the sub version number. + jsl print_str ; + lda #'\n' ; Print a newline. + jsl print_char ; + lda.w #made ; Print the "Created by" text. + jsl print_str ; + lda.w #author ; Print the name of the author. + jsl print_str ; + lda #'\n' ; Print a newline. + jsl print_char ; + rtl ; 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. @@ -171,12 +204,10 @@ start: tay ; Reset the cursor index. lda.w #$3FF ; Set the clear count to $3FF. sta.w scr_ptr ; - lda.w #cmd_buf ; Set the array to be cleared to the command buffer. + lda.d #cmd_buf ; Set the array to be cleared to the command buffer. jsl clr_arr ; Clear the command buffer. ply #2 ; Get back the cursor index. - lda.w #string ; Print the startup message. - jsl print_str ; - lsr #$10 ; Reset the Accumulator. + and #0 ; Reset the Accumulator. sta end ; jmp read ; Start reading the keyboard. @@ -191,19 +222,20 @@ read: jmp read ; No, so keep looping. print_str: - sta.w end ; Save the parameter. + ldx #0 ; Reset X. + sta.q end ; Save the parameter. print_str2: - lda.w end ; Get the parameter. + lda.q end ; Get the parameter. ldb #0 ; Clear the B register. jsl set_ptr ; Set the first pointer to the parameter. tba ; Clear the Accumulator. - inb ; Enable replace mode. - stb b ; pntstr_lp: - lda.w ptr ; Get the first pointer. - cmp.w end ; Did the pointer change? + ldb #1 ; Enable replace mode. + stb b ; + lda.q ptr ; Get the first pointer. + cmp.q end ; Did the pointer change? bne print_str2 ; Yes, so set it back. - lsr #$10 ; No, reset the accumulator. + and #0 ; No, reset the accumulator. phy #2 ; Save the cursor index. txy ; Copy the string index into Y. lda (ptr), y ; Are we at the end of the string? @@ -230,7 +262,7 @@ getbt0: getbt1: pha #1 ; Save the parameter. ldb #1 ; Make sure that set_ptr sets the second pointer. - lda.w #bitabl ; Set the second pointer to the linewrap table. + lda.d #bitabl ; Set the second pointer to the linewrap table. jsl set_ptr ; lsr #$10 ; Clear the Accumulator. pla #1 ; Get the return byte back. @@ -246,9 +278,9 @@ getbt1: clrbit: pha #1 ; Save the parameter. ldb #1 ; Make sure that set_ptr sets the second pointer. - lda.w #bitabl ; Set the second pointer to the linewrap table. + lda.d #bitabl ; Set the second pointer to the linewrap table. jsl set_ptr ; - lsr #$10 ; Clear the Accumulator. + and #0 ; Clear the Accumulator. pla #1 ; Get the return byte back. jsl bitpos ; Get the bit, and byte position. xor #$FF ; Invert the bitmask. @@ -266,9 +298,9 @@ bitout: setbit: pha #1 ; Save the parameter. ldb #1 ; Make sure that set_ptr sets the second pointer. - lda.w #bitabl ; Set the second pointer to the linewrap table. + lda.d #bitabl ; Set the second pointer to the linewrap table. jsl set_ptr ; - lsr #$10 ; Clear the Accumulator. + and #0 ; Clear the Accumulator. pla #1 ; Get the return byte back. jsl bitpos ; Get the bit, and byte position. phy #2 ; Save the screen index. @@ -282,7 +314,7 @@ bitpos: ldb #0 ; Make sure that set_ptr sets the first pointer. lda.w #bits ; Set the first pointer to the bitmask table. jsl set_ptr ; - lsr #$10 ; Clear the Accumulator. + and #0 ; Clear the Accumulator. pla #1 ; Get the parameter back. stx bitmask ; Make the line number the bitmask. txa ; Copy it to the Accumulator. @@ -361,10 +393,10 @@ cmd_cpy3: tay ; Place it into the index. ldx.w #0 ; Reset the X register. ldb #0 ; Make sure that set_ptr sets the first pointer. - lda.w #buffer ; Set the first pointer to the start of the screen buffer. + lda.d #buffer ; Set the first pointer to the start of the screen buffer. jsl set_ptr ; inb ; Make sure that set_ptr sets the second pointer. - lda.w #cmd_buf ; Set the second pointer to the start of the command buffer. + lda.d #cmd_buf ; Set the second pointer to the start of the command buffer. jsl set_ptr ; deb ; Set B back to zero. tba ; Set the accumulator to zero. @@ -403,26 +435,26 @@ cmd_cpy_nd: findst: - lda #0 ; + lda #0 ; Reset A. findst_lp: - pha #1 ; - jsl getbit ; - pla #1 ; - bcc findst_done ; - inc ; - dec scr_row ; - bpo findst_lp ; - dec ; - inc scr_row ; + pha #1 ; Save the current line number. + jsl getbit ; Is this the start of the line? + pla #1 ; Get the current line number back. + bcc findst_done ; Yes, so we're done. + inc ; No, so check the next physical line. + dec scr_row ; Are we at the top of the screen? + bpo findst_lp ; No, so keep looping. + dec ; Yes, so move back one line. + inc scr_row ; Put the row postiion back to zero. findst_done: - cmp #0 ; - rtl ; + cmp #0 ; Update all the flags. + rtl ; End of findst. fndend: phb #1 ; Save the contents of the B register. ldb #0 ; Make sure that set_ptr sets the first pointer. - lda.w #buffer ; Set the first pointer to the start of the screen buffer. + lda.d #buffer ; Set the first pointer to the start of the screen buffer. jsl set_ptr ; tba ; Set the Accumulator to zero. plb #1 ; Restore the contents of the B register. @@ -446,16 +478,13 @@ findend: parse: lda #0 ; tax ; - jsl dabbed ; - beq start ; - lda #0 ; - tax ; - jmp result ; + jsl subasm ; + jmp start ; print_char: sta a ; Save the typed character for now. ldb #2 ; Make sure that set_ptr sets the third pointer. - lda.w #buffer ; Set the third pointer to the start of the screen buffer. + lda.d #buffer ; Set the third pointer to the start of the screen buffer. jsl set_ptr ; ldb #0 ; Set B to zero. tba ; Set the Accumulator to zero. @@ -482,25 +511,25 @@ printc: lda b ; No, but was the flag set? bne printc_save ; Yes, so don't shift the line. sty.w scr_ptr ; No, so save the cursor index for later. - jsl fndend ; - jmp prntc_movln ; + jsl fndend ; Find the end of the line. + jmp prntc_movln ; Start shifting the line right. prntc_updt: - lda scr_col ; + lda scr_col ; Save the current column position for later. sta scr_tcol ; prntc_updt2: - jsl findend ; - sta e ; - sta scr_row ; - jsl findst ; - lda scr_row ; + jsl findend ; Find the end of the line. + sta e ; Use it for redrawing the line. + sta scr_row ; Set the row position to to the end of the line. + jsl findst ; Find the start of the line. + lda scr_row ; Get the start of the line. prntc_updt3: - sta f ; - jsl rdrw_ln ; - lda scr_trow ; + sta f ; Set the starting line, to the start of the line. + jsl rdrw_ln ; Redraw the line. + lda scr_trow ; Get the real row position back. sta scr_row ; - lda scr_tcol ; + lda scr_tcol ; Get the real column position back. sta scr_col ; - jsl update_pos ; + jsl update_pos ; Update the cursor's position. dec d ; jmp printc_sav1 ; prntc_movln: @@ -574,22 +603,22 @@ printc_end: rtl ; nl: - lda #0 ; - ldb (ptr3), y ; - bne nl1 ; - sta (ptr3), y ; Store said terminator into the input buffer. + lda #0 ; Reset A. + ldb (ptr3), y ; Is this character not a null terminator? + bne nl1 ; Yes, so don't overwrite it. + sta (ptr3), y ; No, so overwrite it. nl1: - sta scr_col ; - lda scr_row ; - cmp #maxrow ; - bcc nl_inc ; - jsl scrl_down ; - jmp nl_end ; + sta scr_col ; Move the cursor to the start of the next line. + lda scr_row ; Get the row position. + cmp #maxrow ; Are we at the bottom of the screen? + bcc nl_inc ; No, so move down one line. + jsl scrl_down ; Yes, so scroll down one line. + jmp nl_end ; We are done. nl_inc: - inc scr_row ; - jsl update_pos ; + inc scr_row ; Move the cursor down by one line. + jsl update_pos ; Update the cursor's position. nl_end: - lda #'\n' ; + lda #'\n' ; Print the newline. sta a ; jmp printc_end ; @@ -603,12 +632,12 @@ clr_scr: tay ; lda.w #$1FFF ; Set the clear count to $1FFF. sta.w scr_ptr ; - lda.w #buffer ; Set the array to be cleared to the command buffer. + lda.d #buffer ; Set the array to be cleared to the screen buffer. jsl clr_arr ; Clear the screen buffer. tay ; lda.w #$3FF ; Set the clear count to $3FF. sta.w scr_ptr ; - lda.w #buffer ; Set the array to be cleared to the command buffer. + lda.d #cmd_buf ; Set the array to be cleared to the command buffer. jsl clr_arr ; Clear the screen buffer. sta scr_col ; sta scr_row ; @@ -636,18 +665,18 @@ step_dis: jmp printc_end ; back: - ldb #0 ; + ldb #0 ; Reset B, and some flags. stb e ; stb f ; - lda scr_row ; + lda scr_row ; Save the current row position for later. sta scr_trow ; - jsl findend ; - sta scr_row ; + jsl findend ; Find the end of the line. + sta scr_row ; Set our row position to the end of the line. back0: - jsl findst ; - beq back1 ; - bcs back_updt ; - lda scr_trow ; + jsl findst ; Does this line take up more than one real line? + beq back1 ; No, so skip updating any other lines. + bcs back_updt ; Yes, so update the other lines. + lda scr_trow ; Get the real row position back. sta scr_row ; back1: dey ; Decrement the buffer's offset. @@ -655,32 +684,32 @@ back1: sta (ptr3), y ; into the buffer. tyx ; Copy the current cursor index to X. iny ; Increment cursor index. - ldb #0 ; + ldb #0 ; Set shifting direction to left. stb d ; jsl shftln ; Shift line back by one character. lda #$7F ; Print a backspace to the screen. sta scr ; - lda e ; - beq back3 ; + lda e ; Are we updating more than one line? + beq back3 ; No, so skip to the next step. back2: - jsl findend ; - sta e ; - lda scr_col ; + jsl findend ; Yes, so find the end of the line. + sta e ; Set the end parameter to it. + lda scr_col ; Save the current column position for now. sta scr_tcol ; - jsl rdrw_ln ; - lda scr_tcol ; + jsl rdrw_ln ; Start redrawing the line. + lda scr_tcol ; Get the real column position back. sta scr_col ; back3: - lda scr_trow ; + lda scr_trow ; Get the real row position bac. sta scr_row ; dec scr_col ; Move the cursor back by one column, jsl update_pos ; and update it's position. jmp printc_end ; We are done. back_updt: - lda scr_row ; + lda scr_row ; Set the line to start redrawing, to the start of the line. sta f ; - inc e ; - jmp back1 ; + inc e ; Set the redraw flag to true. + jmp back1 ; Start shifting the line back. bs: lda scr_col ; Are we at the far left of the screen? @@ -1155,62 +1184,6 @@ rdrow_end: rdrow_done: rtl ; -result: - lda.w #string2 ; - ldx.w zero ; - jsl print_str ; -rset_x: - lda #0 ; Reset a. - tax ; Reset x. - jmp print_buf ; Print the input buffer. - -dabbed: - ldb #0 ; Make sure that set_ptr is setting the first pointer. - lda.w #cmd_buf ; Set the first pointer to the start of the command buffer. - jsl set_ptr ; - inb ; Make set_ptr set the second pointer. - lda.w #tok ; Set the second pointer to the start of the token string. - jsl set_ptr ; - deb ; Set B back to zero. - tba ; Also set the accumulator back to zero. -dab_st: - phy #2 ; - txy ; - lda (ptr), y ; Are we at the end of the string? - beq dab_pend ; Yes, so return false. - cmp (ptr2), y ; No, but is this character the same as the character in the token string? - beq chk_str ; Yes, so increment the character count. - jmp dab_pend ; No, so return false. -chk_str: - ply #2 ; - inx ; - cpx #3 ; - bne dab_st ; - ldx #0 ; -pnt_msg: - lda.w #msg ; - ldx #0 ; - jsl print_str ; - jmp dab_peqnd ; -dab_pend: - ply #2 ; - lda #1 ; - jmp dab_end ; -dab_peqnd: - lda #0 ; - jmp dab_end ; -dab_end: - rtl ; - -print_buf: - lda.w #cmd_buf ; - jsl print_str ; - lsr #$10 ; Clear the Accumulator. -cmd_clr: - lda #'\n' ; - jsl print_char ; - jmp start ; - rdrw_ln: lda scr_row ; pha #1 ; @@ -1246,12 +1219,15 @@ set_ptr: cpb #2 ; No, but are we setting the third pointer? beq set_ptr3 ; Yes, so start setting it. set_ptr1: + stb.q ptr ; Reset the first pointer. sta.q ptr ; No, so set the first pointer. jmp setptr_end ; We are done. set_ptr2: + stb.q ptr2 ; Reset the second pointer. sta.q ptr2 ; Set the second pointer. jmp setptr_end ; We are done. set_ptr3: + stb.q ptr3 ; Reset the third pointer. sta.q ptr3 ; Set the third pointer. setptr_end: rtl ; End of set_ptr. |