summaryrefslogtreecommitdiff
path: root/programs
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2020-07-06 20:04:41 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2020-07-06 20:04:41 -0400
commit756c606af68be8ccca7aced3b9c3d56fb2d5087f (patch)
treefbc02b63feb1933a213d26ae68ab1b1a104e4ef3 /programs
parent887802efcdb3b56263069cc6778a8f53ed89d599 (diff)
- Implemented a new opcode table.
- Added a new preifx called the OF prefix, which adds the contents of a specific register to the current operand. - Added a table generator, which parses opcode table csv files.
Diffstat (limited to 'programs')
-rw-r--r--programs/sub-suite/lexer.s180
-rw-r--r--programs/sub-suite/subasm.s34
-rw-r--r--programs/sub-suite/subeditor.s405
-rw-r--r--programs/sub-suite/utils.s130
4 files changed, 448 insertions, 301 deletions
diff --git a/programs/sub-suite/lexer.s b/programs/sub-suite/lexer.s
index 315bee4..cd7a33a 100644
--- a/programs/sub-suite/lexer.s
+++ b/programs/sub-suite/lexer.s
@@ -97,16 +97,16 @@ util_data:
lex:
ldx #0 ; Reset X.
txa ; Reset A.
- phy #2 ; Preserve the screen buffer index.
+ phy.w ; Preserve the screen buffer index.
txy ; Reset Y.
sty.q idx0 ; Clear the first index.
sty.q idx1 ; Clear the second index.
sty.q idx2 ; Clear the third index.
sty b ; Clear the isop flag.
; lda (ptr), y ; Get a character from the line.
-; pha #1 ; Preserve the character.
+; pha ; Preserve the character.
; jsr isdigit ; Is this character a digit?
-; pla #1 ; Get the character back.
+; pla ; Get the character back.
@getline:
lda #2 ; Get the third byte, of the line table address.
lsl #$10 ; Shift it by 2 bytes.
@@ -126,27 +126,27 @@ lex:
@spaces:
ldy.w idx0 ; Get the string index.
lda (ptr), y ; Get a character from the line.
- pha #1 ; Preserve the character.
+ pha ; Preserve the character.
jsr isdelm ; Get the delimiter.
and #$10 ; Is this character, a space, or tab?
- pla #1 ; Get the character back.
+ pla ; Get the character back.
beq @isstart ; No, so check for the start of the line.
inc.w idx0 ; Yes, so increment the string index.
cmp #' ' ; Is this character, a space?
beq @incs ; Yes, so increment the starting space count.
cmp #'\t' ; No, but is it a tab?
beq @inct ; Yes, so increment the starting tab count.
- jmp @spaces ; No, so Keep looping.
+ bra @spaces ; No, so Keep looping.
@incs:
inc idx1 ; Increment the space count.
- jmp @spaces ; Keep looping.
+ bra @spaces ; Keep looping.
@inct:
inc idx1+1 ; Increment the tab count.
- jmp @spaces ; Keep looping.
+ bra @spaces ; Keep looping.
@isstart:
- pha #2 ; Preserve the character.
+ pha.w ; Preserve the character.
lda.w idx1 ; Was there any whitespace?
- pla #2 ; Get the character back.
+ pla.w ; Get the character back.
beq @switch ; No, so start lexing.
cpb #1 ; Yes, and are we at the start of the line?
bne @switch ; No, so start lexing.
@@ -163,27 +163,27 @@ lex:
jsr get_ptok ; Get the pre-token.
jsr parse_ptok ; Parse the pre-token.
; beq @end ; We got to the end of the string.
- jmp @loop ; Keep looping.
+ bra @loop ; Keep looping.
@end:
- ply #2 ; Get the screen buffer index back.
+ ply.w ; Get the screen buffer index back.
rts ; End of lex.
parse_ptok:
- pha #1 ; Preserve the pre-token.
+ pha ; Preserve the pre-token.
ldb #2 ; Set the third pointer
lda.w #swtab ; to the start of the jump table.
jsr set_ptr ;
and #0 ; Reset A.
- pla #1 ; Get the pre-token back.
- phy #2 ; Preserve Y.
+ pla ; Get the pre-token back.
+ phy.w ; Preserve Y.
lsl #1 ; Multiply the pre-token by two, to get the jump index.
tay ; Get the index of the jump table.
lda.w (ptr3), y ; Get the address to jump to.
jsr set_ptr ; Set the third pointer to the case address.
and #0 ; Reset A.
tab ; Reset B.
- ply #2 ; Get Y back.
+ ply.w ; Get Y back.
jmp (ptr3) ; Jump to the case label.
ptok_dot:
ldb #1 ; Make init_lex increment the string index.
@@ -200,7 +200,7 @@ ptok_dot:
dey ; Decrement the lexeme index.
lda (ptr3), y ; Get the suffix character.
jsr get_rs ; Get the register size.
- jmp @end ; We are done.
+ bra @end ; We are done.
@dir:
lda #TOK_DIR ; Set the lexeme type to TOK_DIR.
sta lex_type ;
@@ -211,9 +211,9 @@ ptok_dot:
lda.w #dir ; Get pointer to the start of the directive table.
clc ; Prepare for a non carrying add.
adc.w idx2 ; Offset the pointer, by the length of the previous string.
- pha #8 ; Preserve the directive string pointer.
+ pha.q ; Preserve the directive string pointer.
jsr strcasecmp ; Is the lexeme buffer, the same as the directive string?
- pla #8 ; Get the directive string pointer back.
+ pla.q ; Get the directive string pointer back.
beq @found ; Yes, so create a new token.
ldb idx1 ; No, so Get the directive ID.
cpb #6 ; Have we reached the end of the directive table?
@@ -226,7 +226,7 @@ ptok_dot:
clc ; Prepare for a non carrying add.
adc.w idx2 ; Add the string offset to the current length
sta.w idx2 ; Save the offset in the third index.
- jmp @dir_loop ; Keep looping.
+ bra @dir_loop ; Keep looping.
@found:
nop ;
@end:
@@ -234,59 +234,102 @@ ptok_dot:
jsr set_cmdbuf ; Set the first pointer to the command buffer.
rts ; End of parse_ptok.
ptok_at:
+ inc.w idx0 ;
rts ; End of parse_ptok.
ptok_col:
+ inc.w idx0 ;
rts ; End of parse_ptok.
ptok_equ:
+ inc.w idx0 ;
rts ; End of parse_ptok.
ptok_plus:
+ inc.w idx0 ;
rts ; End of parse_ptok.
ptok_min:
+ inc.w idx0 ;
rts ; End of parse_ptok.
ptok_gt:
+ inc.w idx0 ;
rts ; End of parse_ptok.
ptok_lt:
+ inc.w idx0 ;
rts ; End of parse_ptok.
ptok_lbrk:
+ inc.w idx0 ;
rts ; End of parse_ptok.
ptok_rbrk:
+ inc.w idx0 ;
rts ; End of parse_ptok.
ptok_com:
+ inc.w idx0 ;
rts ; End of parse_ptok.
ptok_xr:
+ inc.w idx0 ;
rts ; End of parse_ptok.
ptok_yr:
+ inc.w idx0 ;
rts ; End of parse_ptok.
ptok_dqu:
ldb #1 ; Make init_lex increment the string index.
jsr init_lex ; Initialize the lexeme buffer for copying.
ldb #4 ; Set the delimiter comparison value to a double quote.
jsr delmcpy ; Copy the string, to the lexeme buffer, until delimiter.
-@term:
+@end:
rts ; End of parse_ptok.
ptok_squ:
+ ldb #1 ; Make init_lex increment the string index.
+ jsr init_lex ; Initialize the lexeme buffer for copying.
+ ldb #8 ; Set the delimiter comparison value to a single quote.
+ jsr delmcpy ; Copy the string, to the lexeme buffer, until delimiter.
+@end:
rts ; End of parse_ptok.
ptok_hash:
+ inc.w idx0 ;
rts ; End of parse_ptok.
ptok_scol:
+ ldb #1 ; Make init_lex increment the string index.
+ jsr init_lex ; Initialize the lexeme buffer for copying.
+ jsr delmcpy ; Copy the string, to the lexeme buffer, until EOL.
+@end:
rts ; End of parse_ptok.
ptok_dolr:
- rts ; End of parse_ptok.
+ lda #TOK_HEX ; Set the lexeme type to TOK_HEX.
+ sta lex_type ;
+ lda #$10 ; Set the base to Hexadecimal.
+ ldb #1 ; Make init_lex increment the string index.
+ bra ptok_num2 ; Parse the value.
ptok_prcn:
- rts ; End of parse_ptok.
+ lda #TOK_BIN ; Set the lexeme type to TOK_BIN.
+ sta lex_type ;
+ lda #2 ; Set the base to Binary.
+ ldb #1 ; Make init_lex increment the string index.
+ bra ptok_num2 ; Parse the value.
ptok_num:
+ lda #TOK_DEC ; Set the lexeme type to TOK_DEC.
+ sta lex_type ;
+ lda #10 ; Set the base to Decimal.
+ ldb #0 ; Do not let init_lex increment the string index.
+ptok_num2:
+ pha ; Preserve the base.
+ jsr init_lex ; Initialize the lexeme buffer for copying.
+ ldb #3 ; Set the delimiter to both the EOL, or a comma.
+ jsr delmcpy ; Copy the string, to the lexeme buffer, until delimiter.
+ pla ; Get the base back.
+ jsr strtoull ; Convert the string into a numeric value.
+ jsr make_tok ; Create the token.
+ jsr set_cmdbuf ; Set the first pointer to the command buffer.
rts ; End of parse_ptok.
ptok_alph:
ldb #0 ; Do not let init_lex increment the string index.
jsr init_lex ; Initialize the lexeme buffer for copying.
- ldb #1 ; Stop at any possible delimiter, except whitespace.
+ ldb #3 ; Stop at any possible delimiter.
tba ; Use isdelm2 for the comparison.
jsr delmcpy ; Copy the string, to the lexeme buffer, until delimiter.
lda #0 ; Reset A.
sta b ; Clear the isop flag.
@isop:
ldb #0 ; Make the lexeme buffer, the first pointer.
- stb.q idx1 ; Reset the first index.
+ stb.q idx1 ; Reset the second index.
jsr set_lexptr ; Set up the lexeme buffer.
@isop_loop:
lda.w #mne ; Get pointer to the start of the instruction table.
@@ -303,7 +346,7 @@ ptok_alph:
clc ; Prepare for a non carrying multiply.
mul idx1 ; Multiply the base offset, by the instruction ID.
sta.w idx2 ; Save the offset in the third index.
- jmp @isop_loop ; Keep looping.
+ bra @isop_loop ; Keep looping.
@found:
lda #TOK_MNE ; Set the lexeme type to TOK_MNE.
sta lex_type ;
@@ -313,6 +356,7 @@ ptok_alph:
jsr set_cmdbuf ; Set the first pointer to the command buffer.
rts ; End of parse_ptok.
ptok_othr:
+ inc.w idx0 ;
rts ; End of parse_ptok.
@@ -322,6 +366,7 @@ set_lexptr:
and #0 ; Reset A.
tab ; Reset B.
sta.q idx1 ; Reset the second index.
+ sta.q idx2 ; Reset the third index
rts ; End of set_lexptr.
@@ -340,11 +385,19 @@ init_lex:
@inc_str:
inc.w idx0 ; Yes, so increment the string index.
@init:
- lda #0 ; Reset A.
- sta.q idx1 ; Reset the second index
- sta.q idx2 ; Reset the third index
ldb #2 ; Make the lexeme buffer, the third pointer.
jsr set_lexptr ; Set up the lexeme buffer.
+ phy.w ; Preserve Y.
+ tay ; Reset Y.
+@loop:
+ lda (ptr3), y ; Have we hit the end of the previous lexeme string?
+ beq @end ; Yes, so we're done.
+ lda #0 ; No, so start clearing the character.
+ sta (ptr3), y ; Clear the character.
+ iny ; Increment the lexeme index.
+ bra @loop ; Keep looping.
+@end:
+ ply.w ; Get Y back.
rts ; End of init_lex.
@@ -352,37 +405,80 @@ delmcpy:
sta a ; Save the delimiter check flag.
stb c ; Save the delimiter comparison value.
@loop:
+ ldb #0 ; Reset the B register.
+ stb g ; Reset the byte count.
ldy.w idx0 ; Get the string index.
- lda (ptr), y ; Get a character from the line.
- pha #1 ; Preserve the character.
+ lda.q (ptr), y ; Get eight bytes from the current line.
+@loop1:
+ pha.q ; Save the string buffer.
+ and #$FF ; Get the current byte.
+ pha ; Preserve the character.
lda a ; Are we calling isdelm2?
- pla #1 ; Get the character back.
+ pla ; Get the character back.
bne @isdelm2 ; Yes, so use isdelm2.
jsr isdelm ; No, so get the delimiter value from isdelm.
+@delmchk:
and c ; Are both delimiter values, the same?
+ pla.q ; Get back the string buffer.
bne @end ; Yes, so we're done.
- jmp @copy ; No, so start copying the character.
+ bra @copy ; No, so start copying the character.
@isdelm2:
jsr isdelm2 ; Get the delimiter value from isdelm2.
- cmp c ; Are both delimiter values, the same?
- beq @end ; Yes, so we're done.
+ bra @delmchk ; Check the delimiter.
@copy:
- lda (ptr), y ; Get a character from the line.
ldy.w idx1 ; Get the lexeme index.
- sta (ptr3), y ; Copy the character to the lexeme buffer.
+ sta (ptr3), y ; Copy one byte from the screen buffer, to the command buffer.
inc.w idx0 ; Increment the string index.
inc.w idx1 ; Increment the lexeme index.
- jmp @loop ; Keep looping.
+ lsr #8 ; Shift in the next byte.
+ inc g ; Increment the byte count.
+ ldb g ; Get back the byte count.
+ cpb #7 ; Did we shift in eight bytes?
+ beq @loop ; Yes, so get eight more bytes.
+ bra @loop1 ; No, so keep shifting in more bytes.
@end:
- lda #0 ; Terminate the lexeme buffer.
- sta (ptr3), y ;
+ ldb #0 ; Reset B.
+ ldy.w idx1 ; Get the lexeme index.
+ stb (ptr3), y ; Terminate the command buffer.
+@end1:
+ ldy.w idx0 ; Get the string index.
+ tba ; Reset A.
rts ; End of delmcpy.
+;@loop:
+; ldy.w idx0 ; Get the string index.
+; lda (ptr), y ; Get a character from the line.
+; pha ; Preserve the character.
+; lda a ; Are we calling isdelm2?
+; pla ; Get the character back.
+; bne @isdelm2 ; Yes, so use isdelm2.
+; jsr isdelm ; No, so get the delimiter value from isdelm.
+;@delmchk:
+; and c ; Are both delimiter values, the same?
+; bne @end ; Yes, so we're done.
+; bra @copy ; No, so start copying the character.
+;@isdelm2:
+; jsr isdelm2 ; Get the delimiter value from isdelm2.
+; bra @delmchk ; Check the delimiter.
+;@copy:
+; lda (ptr), y ; Get a character from the line.
+; ldy.w idx1 ; Get the lexeme index.
+; sta (ptr3), y ; Copy the character to the lexeme buffer.
+; inc.w idx0 ; Increment the string index.
+; inc.w idx1 ; Increment the lexeme index.
+; bra @loop ; Keep looping.
+;@end:
+; ldy.w idx1 ; Get the lexeme index.
+; lda #0 ; Terminate the lexeme buffer.
+; sta (ptr3), y ;
+; ldy.w idx0 ; Get the string index.
+; rts ; End of delmcpy.
+
get_rs:
- phb #1 ; Preserve B.
+ phb ; Preserve B.
ldb #0 ; Set the isop flag to false.
- plb #1 ; Get B back.
+ plb ; Get B back.
jsr tolower ; Convert the character to lowercase.
cmp #'w' ; Is it .w?
beq @r1 ; Yes, so return 1.
diff --git a/programs/sub-suite/subasm.s b/programs/sub-suite/subasm.s
index 9c6c3f0..d661695 100644
--- a/programs/sub-suite/subasm.s
+++ b/programs/sub-suite/subasm.s
@@ -187,6 +187,14 @@ idx2:
idx3:
.qword 0
+; Value buffer used by strtoull.
+valbuf:
+ .qword 0
+
+; Copy buffer used by delmcpy.
+cpybuf:
+ .qword 0
+
; Current token line.
ctok:
.word 0
@@ -225,7 +233,7 @@ subasm:
jsr chk_cmd ; No, but did we get a full command?
bne @cmd ; Yes, so skip everything else.
jsr lex ; No, so start lexing this line.
- jmp @end ; We are done.
+ bra @end ; We are done.
@cmd:
ldb #1 ; Set the second pointer
lda.d #cmd_srt ; to the command subroutine table.
@@ -236,10 +244,10 @@ subasm:
cmp #8 ; Is the command ID greater than the command count?
bcs @end ; Yes, so we're done.
lsl #1 ; No, so multiply the command ID by two.
- phy #2 ; Preserve the screen buffer position.
+ phy.w ; 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.
+ ply.w ; Get back the screen buffer position.
ldb #2 ; Save it in the third pointer.
jsr set_ptr ;
ldb #0 ; Reset B.
@@ -254,7 +262,7 @@ chk_shcmd:
jsr set_ptr ;
deb ; Reset B.
tba ; Reset A.
- phy #2 ; Preserve the screen buffer position.
+ phy.w ; Preserve the screen buffer position.
txy ; Set our index to zero.
lda (ptr), y ; Is there nothing in the command buffer?
beq @false ; Yes, so return that we failed.
@@ -267,7 +275,7 @@ chk_shcmd:
cab ; No, so did the character match?
beq @found ; Yes, so check if there are any arguments.
iny ; No, so check the next command.
- jmp @loop ; Keep looping.
+ bra @loop ; Keep looping.
@found:
sty f ; Save the command ID.
ldy #1 ; Check the next character in the command buffer.
@@ -275,16 +283,16 @@ chk_shcmd:
beq @true ; Yes, so return that we succeded.
cmp #' ' ; No, but is this a space?
beq @true ; Yes, so return that we succeded.
- jmp @false ; No, so return that we failed.
+ bra @false ; No, so return that we failed.
@true:
lda #1 ; Return true.
- jmp @end ; We are done.
+ bra @end ; We are done.
@false:
ldb #0 ; Reset B.
tba ; Return false.
tax ; Reset X.
@end:
- ply #2 ; Get back the screen buffer position.
+ ply.w ; Get back the screen buffer position.
rts ; End of chk_shcmd.
@@ -297,9 +305,9 @@ chk_cmd:
lda.w #cmds ; Get pointer to the start of the command table.
clc ; Prepare for a non carrying add.
adc.w idx0 ; Offset the pointer, by the length of the previous string.
- pha #8 ; Preserve the command string pointer.
+ pha.q ; Preserve the command string pointer.
jsr strcasecmp ; Is the command buffer, the same as the command string?
- pla #8 ; Get the command string pointer back.
+ pla.q ; Get the command string pointer back.
beq @true ; Yes, so return true.
ldb idx1 ; No, so Get the command ID.
cpb #7 ; Have we reached the end of the command table?
@@ -312,12 +320,12 @@ chk_cmd:
clc ; Prepare for a non carrying add.
adc.w idx0 ; Add the string offset to the current length
sta.w idx0 ; Save the offset in the first index.
- jmp @loop ; Keep looping.
+ bra @loop ; Keep looping.
@true:
ldb idx1 ; Get the command ID.
stb f ; Return the command ID.
ldb #1 ; Return true.
- jmp @end ; We are done.
+ bra @end ; We are done.
@false:
ldb #0 ; Return false.
@end:
@@ -351,7 +359,7 @@ viewmem:
adc #$10 ; Add 16 to the address.
sta.q idx0 ; Put it back into the address.
and #0 ; Reset A.
- jmp @loop ; Keep looping.
+ bra @loop ; Keep looping.
@end:
lda #'\n' ; Print a newline.
jsr print_char ;
diff --git a/programs/sub-suite/subeditor.s b/programs/sub-suite/subeditor.s
index 1768d62..cc18b4c 100644
--- a/programs/sub-suite/subeditor.s
+++ b/programs/sub-suite/subeditor.s
@@ -140,10 +140,12 @@ reset:
lda.d #buffer ; Set the array to be cleared to the screen buffer.
jsr clr_arr ; Clear the screen buffer.
jsr pnt_strt ; Print the starting message.
- jmp start ; Goto the start of the main program.
+ lda #$C ; Clear the screen.
+ sta scr ;
+ bra start ; Goto the start of the main program.
clr_arr:
- phb #1 ; Preserve whatever was in B.
+ phb ; Preserve whatever was in B.
ldb #0 ; Clear B.
jsr set_ptr ; Set the first pointer to the parameter.
adc #8 ; Set the second pointer to the parameter, plus eight.
@@ -166,10 +168,10 @@ clr_arr:
adc #$10 ;
tay ;
tba ;
- jmp @loop ; Keep looping.
+ bra @loop ; Keep looping.
@end:
ldy.w zero ; Set the index back to zero.
- plb #1 ; Get whatever was in the B register, back.
+ plb ; Get whatever was in the B register, back.
rts ; End of clr_arr.
pnt_strt:
@@ -195,16 +197,16 @@ 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 #2 ; Save the cursor index for later.
+ phy.w ; Save the cursor index for later.
tay ; Reset the cursor index.
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 #2 ; Get back the cursor index.
+ ply.w ; Get back the cursor index.
and #0 ; Reset the Accumulator.
sta end ;
- jmp read ; Start reading the keyboard.
+ bra read ; Start reading the keyboard.
read:
lda #0 ; Reset the Accumulator.
@@ -214,7 +216,14 @@ read:
beq read ; No, so try again.
jsr getchar ; Yes, and was it a newline?
beq parse ; Yes, so start parsing the line.
- jmp read ; No, so keep looping.
+ bra read ; No, so keep looping.
+
+parse:
+ lda #0 ;
+ tax ;
+ jsr subasm ;
+ bra start ;
+
print_str:
ldx #0 ; Reset X.
@@ -231,14 +240,14 @@ print_str:
cmp.q end ; Did the pointer change?
bne @reset ; Yes, so set it back.
and #0 ; No, reset the accumulator.
- phy #2 ; Save the cursor index.
+ 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 #2 ; Get the cursor index back.
+ ply.w ; Get the cursor index back.
beq @end ; Yes, so we're done.
inx ; No, so increment the string index.
jsr print_char ; Print the character.
- jmp @loop ; Keep looping.
+ bra @loop ; Keep looping.
@end:
ldb #0 ; Enable insert mode.
stb b ;
@@ -249,81 +258,81 @@ getbit:
lda scr_str ; Has the screen been scrolled?
bne getbt0 ; Yes, so add the screen offset to the current line number.
ldx scr_row ; No, so just use the current line number.
- jmp getbt1 ; Start getting the bit.
+ bra getbt1 ; Start getting the bit.
getbt0:
lda scr_row ; Get the current line number.
adc scr_str ; Add the screen offset to it.
tax ; Use it as the wrap index.
getbt1:
- pha #1 ; Save the parameter.
+ pha ; Save the parameter.
ldb #1 ; Make sure that set_ptr sets the second pointer.
lda.d #bitabl ; Set the second pointer to the linewrap table.
jsr set_ptr ;
lsr #$10 ; Clear the Accumulator.
- pla #1 ; Get the return byte back.
+ pla ; Get the return byte back.
jsr bitpos ; Get the bit, and byte position.
- phy #2 ; Save the screen index.
+ phy.w ; Save the screen index.
txy ; Get the byte position.
ldb (ptr2), y ; Get one byte of the wrap table.
- ply #2 ; Get the screen index back.
+ ply.w ; Get the screen index back.
aba ; Mask out the bit of the current line number.
cmp #1 ; Set the carry flag, if true.
- jmp bitout ; We are done.
+ bra bitout ; We are done.
clrbit:
- pha #1 ; Save the parameter.
+ pha ; Save the parameter.
ldb #1 ; Make sure that set_ptr sets the second pointer.
lda.d #bitabl ; Set the second pointer to the linewrap table.
jsr set_ptr ;
and #0 ; Clear the Accumulator.
- pla #1 ; Get the return byte back.
+ pla ; Get the return byte back.
jsr bitpos ; Get the bit, and byte position.
xor #$FF ; Invert the bitmask.
- phy #2 ; Save the screen index.
+ phy.w ; Save the screen index.
txy ; Get the byte position.
ldb (ptr2), y ; Get one byte of the wrap table.
aba ; Clear the bit of the current line number.
bitsav:
sta (ptr2), y ; Update the wrap table.
- ply #2 ; Get the screen index back.
+ ply.w ; Get the screen index back.
bitout:
ldx bitmask ; Return the bitmask.
rts ; We are done.
setbit:
- pha #1 ; Save the parameter.
+ pha ; Save the parameter.
ldb #1 ; Make sure that set_ptr sets the second pointer.
lda.d #bitabl ; Set the second pointer to the linewrap table.
jsr set_ptr ;
and #0 ; Clear the Accumulator.
- pla #1 ; Get the return byte back.
+ pla ; Get the return byte back.
jsr bitpos ; Get the bit, and byte position.
- phy #2 ; Save the screen index.
+ phy.w ; Save the screen index.
txy ; Get the byte position.
ldb (ptr2), y ; Get one byte of the wrap table.
oab ; Set the bit of the current line number.
- jmp bitsav ; Save the bit.
+ bra bitsav ; Save the bit.
bitpos:
- pha #1 ; Save the parameter.
+ pha ; Save the parameter.
ldb #0 ; Make sure that set_ptr sets the first pointer.
lda.w #bits ; Set the first pointer to the bitmask table.
jsr set_ptr ;
and #0 ; Clear the Accumulator.
- pla #1 ; Get the parameter back.
+ pla ; Get the parameter back.
stx bitmask ; Make the line number the bitmask.
txa ; Copy it to the Accumulator.
and #7 ; Get the bit position.
- phy #2 ; Save the cursor index.
+ phy.w ; Save the cursor index.
tay ; Use the bit position as the index.
tax ; Copy it into X.
lda (ptr), y ; Get the bitmask.
- ply #2 ; Get back the cursor index.
- pha #1 ; Save the bitmask.
+ ply.w ; Get back the cursor index.
+ pha ; Save the bitmask.
lda bitmask ; Get the line number.
lsr #3 ; Get the byte position.
tax ; Copy it into X.
- pla #1 ; Get back the bitmask.
+ pla ; Get back the bitmask.
rts ; End of bitpos.
getchar:
@@ -331,14 +340,14 @@ getchar:
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.
- pha #1 ; Save the character.
- phy #2 ; Save the cursor index.
+ pha ; Save the character.
+ phy.w ; Save the cursor index.
cmp #'\n' ; Was the character that was typed, a newline?
bne @print ; No, so just print the character.
jsr cmd_cpy ; Yes, so start copying the line to the command buffer.
@print:
- ply #2 ; Get back the cursor index.
- pla #1 ; Get back the character.
+ ply.w ; Get back the cursor index.
+ pla ; Get back the character.
ldb e ; Is the temporary row position non zero?
bne @row ; Yes, so reset the row positon.
@print1:
@@ -346,21 +355,21 @@ getchar:
lda a ; Get the return value.
cmp #'\n' ; Is the return value, a newline?
beq @true ; Yes, so return true.
- jmp @false ; No, so return false.
+ bra @false ; No, so return false.
@row:
ldb e ; Get the temporary row position.
cpb #maxrow ; Is temporary row position, at, or above the bottom of the screen?
beq @row2 ; Yes, so leave it as is.
bcs @row1 ; No, so set it to the bottom of the screen.
- jmp @row2 ; Yes, so leave it as is.
+ bra @row2 ; Yes, so leave it as is.
@row1:
ldb #maxrow ; Set the row position to the bottom of the screen.
@row2:
stb scr_row ; Set the row position.
- jmp @print1 ; Print the character.
+ bra @print1 ; Print the character.
@true:
lda #0 ; Return true.
- jmp @end ; We are done.
+ bra @end ; We are done.
@false:
lda #1 ; Return false.
@end:
@@ -399,11 +408,11 @@ cmd_cpy:
ldb #0 ; Reset the B register.
lda.q (ptr), y ; Get eight bytes from the current line.
@loop1:
- phy #2 ; Save the screen index.
+ phy.w ; Save the screen index.
txy ; Get the command buffer index.
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.
+ ply.w ; Get back the screen index.
cpx.w #$3FF ; Are we at the end of the command buffer?
bcs @end ; Yes, so we're done.
iny ; No, so increment the screen index.
@@ -417,13 +426,13 @@ cmd_cpy:
ldb g ; Get back the byte count.
cpb #7 ; Did we shift in eight bytes?
beq @loop ; Yes, so get eight more bytes.
- jmp @loop1 ; No, so keep shifting in more bytes.
+ bra @loop1 ; No, so keep shifting in more bytes.
@end:
ldb #0 ; Reset B.
- phy #2 ; Save the screen index.
+ phy.w ; Save the screen index.
txy ; Get the command buffer index.
stb (ptr2), y ; Terminate the command buffer.
- ply #2 ; Get back the screen index.
+ ply.w ; Get back the screen index.
@end1:
tab ; The B register is zero, so clear the Accumulator.
rts ; End of cmd_cpy.
@@ -432,9 +441,9 @@ cmd_cpy:
findst:
lda #0 ; Reset A.
@loop:
- pha #1 ; Save the current line number.
+ pha ; Save the current line number.
jsr getbit ; Is this the start of the line?
- pla #1 ; Get the current line number back.
+ pla ; Get the current line number back.
bcc @end ; Yes, so we're done.
inc ; No, so check the next physical line.
dec scr_row ; Are we at the top of the screen?
@@ -447,21 +456,21 @@ findst:
fndend:
- phb #1 ; Save the contents of the B register.
+ phb ; Save the contents of the B register.
ldb #0 ; Make sure that set_ptr sets the first pointer.
lda.d #buffer ; Set the first pointer to the start of the screen buffer.
jsr set_ptr ;
tba ; Set the Accumulator to zero.
- plb #1 ; Restore the contents of the B register.
- phy #2 ;
+ plb ; Restore the contents of the B register.
+ phy.w ;
@loop:
lda (ptr), y ; Are we at the end of the string?
beq @end ; Yes, so we're done.
iny ; No, so increment the cursor index.
- jmp @loop ; Keep looping.
+ bra @loop ; Keep looping.
@end:
sty.w scr_ptr3 ;
- ply #2 ;
+ ply.w ;
rts ; End of fndend.
findend:
@@ -470,11 +479,6 @@ findend:
div #maxcol+1 ;
rts ;
-parse:
- lda #0 ;
- tax ;
- jsr subasm ;
- jmp start ;
print_char:
sta a ; Save the typed character for now.
@@ -507,7 +511,7 @@ printc:
bne @save ; Yes, so don't shift the line.
sty.w scr_ptr ; No, so save the cursor index for later.
jsr fndend ; Find the end of the line.
- jmp @shift ; Start shifting the line right.
+ bra @shift ; Start shifting the line right.
@update:
lda scr_col ; Save the current column position for later.
sta scr_tcol ;
@@ -526,7 +530,7 @@ printc:
sta scr_col ;
jsr update_pos ; Update the cursor's position.
dec d ;
- jmp @save1 ;
+ bra @save1 ;
@shift:
ldy.w scr_ptr3 ;
inc scr_ptr3 ;
@@ -541,7 +545,7 @@ printc:
sta (ptr3), y ; store typed character into the input buffer.
lda scr_row ;
sta scr_trow ;
- jmp @update ;
+ bra @update ;
@save:
ldb d ;
bne @update ;
@@ -561,7 +565,7 @@ printc:
sta scr ; Echo typed character.
ldb f ;
beq @wrap ;
- jmp printc_end ;
+ bra printc_end ;
@scrolled:
ldb scr_row ;
cpb #maxrow ;
@@ -569,7 +573,7 @@ printc:
@wrapped2:
ldb #0 ;
stb f ;
- jmp @print ;
+ bra @print ;
@scroll:
sta scr ; Echo typed character.
clc ;
@@ -585,13 +589,13 @@ printc:
@wrap1:
inc scr_row ;
@wrap2:
- phx #2 ;
+ phx.w ;
clc ;
lda scr_row ;
adc scr_str ;
tax ;
jsr setbit ;
- plx #2 ;
+ plx.w ;
jsr update_pos ;
printc_end:
rts ;
@@ -607,14 +611,15 @@ nl:
cmp #maxrow ; Are we at the bottom of the screen?
bcc @incr ; No, so move down one line.
jsr scrl_down ; Yes, so scroll down one line.
- jmp @end ; We are done.
+ bra @end ; We are done.
@incr:
inc scr_row ; Move the cursor down by one line.
jsr update_pos ; Update the cursor's position.
@end:
lda #'\n' ; Print the newline.
sta a ;
- jmp printc_end ;
+ rts ;
+
clr_scr:
lda #maxrow ;
@@ -638,26 +643,57 @@ clr_scr:
jsr update_pos ;
lda #$C ;
sta scr ;
- jmp printc_end ;
+ rts ;
en_step:
lda step ;
beq step_en ;
- jmp printc_end ;
+ rts ;
step_en:
lda #1 ;
sta step ;
- jmp printc_end ;
+ rts ;
dis_step:
lda step ;
bne step_dis ;
- jmp printc_end ;
+ rts ;
step_dis:
lda #0 ;
sta step ;
- jmp printc_end ;
+ rts ;
+
+bs:
+ lda scr_col ; Are we at the far left of the screen?
+ beq @wrap ; Yes, so check for a wrapped line.
+ bra back ; No, so add the backspace to the buffer.
+@wrap:
+ jsr getbit ; Is this line, a wrapped line?
+ bcs @wrap1 ; Yes, so check if the cursor is at the top.
+ rts ; No, so we're done.
+@wrap1:
+ lda scr_row ; Are we at the top of the screen?
+ beq @wrap2 ; Yes, so check if the screen is at the top of the buffer.
+ bra @wrap3 ; No, so start clearing the wrap bit.
+@wrap2:
+ lda scr_str ; Are we at the top of the buffer?
+ bne @scroll ; Yes, so scroll up.
+ rts ; No, so we're done.
+@scroll:
+ clc ; Clear the carry flag, so that we don't get odd behaviour.
+ jsr scrl_up ; Scroll up.
+ inc scr_row ; Move down by one row.
+@wrap3:
+ clc ; Clear the carry flag.
+ lda scr_row ; Add the cursor's row position,
+ adc scr_str ; and the screen's starting row.
+ tax ; Transfer that into X.
+@wrap4:
+ dec scr_row ; Move up by one row.
+ ldb #maxcol+1 ; Move the cursor to the absolute right of the screen.
+ stb scr_col ;
+ jsr update_pos ; Update the cursor's position.
back:
ldb #0 ; Reset B, and some flags.
stb e ;
@@ -698,54 +734,23 @@ back:
sta scr_row ;
dec scr_col ; Move the cursor back by one column,
jsr update_pos ; and update it's position.
- jmp printc_end ; We are done.
+ rts ; We are done.
@update:
lda scr_row ; Set the line to start redrawing, to the start of the line.
sta f ;
inc e ; Set the redraw flag to true.
- jmp @shift ; Start shifting the line back.
+ bra @shift ; Start shifting the line back.
-bs:
- lda scr_col ; Are we at the far left of the screen?
- beq @wrap ; Yes, so check for a wrapped line.
- jmp back ; No, so add the backspace to the buffer.
-@wrap:
- jsr getbit ; Is this line, a wrapped line?
- bcs @wrap1 ; Yes, so check if the cursor is at the top.
- jmp printc_end ; No, so we're done.
-@wrap1:
- lda scr_row ; Are we at the top of the screen?
- beq @wrap2 ; Yes, so check if the screen is at the top of the buffer.
- jmp @wrap3 ; No, so start clearing the wrap bit.
-@wrap2:
- lda scr_str ; Are we at the top of the buffer?
- bne @scroll ; Yes, so scroll up.
- jmp printc_end ; No, so we're done.
-@scroll:
- clc ; Clear the carry flag, so that we don't get odd behaviour.
- jsr scrl_up ; Scroll up.
- inc scr_row ; Move down by one row.
-@wrap3:
- clc ; Clear the carry flag.
- lda scr_row ; Add the cursor's row position,
- adc scr_str ; and the screen's starting row.
- tax ; Transfer that into X.
-@wrap4:
- dec scr_row ; Move up by one row.
- ldb #maxcol+1 ; Move the cursor to the absolute right of the screen.
- stb scr_col ;
- jsr update_pos ; Update the cursor's position.
- jmp back ; Delete the previous character.
shftln:
ldb d ; Is the flag not set?
beq @dec_loop ; Yes, so shift, and decrement.
ldb #0 ; Clear the B register.
- jmp @inc_loop ; No, so shift, and increment.
+ bra @inc_loop ; No, so shift, and increment.
@neg:
ldy.w zero ; Set the source poition to 0.
stb (ptr3), y ; Clear the character that is in the source.
- jmp @end ; We are done.
+ bra @end ; We are done.
@inc_loop:
sty.w scr_ptr2 ; Save the source position for later.
ldy.w scr_ptr ; Get the previous cursor index.
@@ -755,35 +760,35 @@ shftln:
@inc_loop1:
ldy.w scr_ptr2 ; Get the source position.
lda (ptr3), y ; Get the character from the source position.
- phy #2 ; Save the source position for later.
+ phy.w ; Save the source position for later.
txy ; Set our position to the destination.
sta (ptr3), y ; Place the character from the source position, to the destination position.
- ply #2 ; Set our position back to the source.
+ ply.w ; Set our position back to the source.
stb (ptr3), y ; Clear the character that is in the source.
bng @neg ; The source underflowed, so set it back to zero,
dey ; Decrement the source position.
dex ; Decrement the destination position.
- jmp @inc_loop ; Keep looping.
+ bra @inc_loop ; Keep looping.
@dec_loop:
stx.w scr_ptr2 ; Save the destination position for later.
lda (ptr3), y ; Is the character at the source position, a null terminator?
beq @end3 ; Yes, so we're done.
- phy #2 ; No, so save the source position for later.
+ phy.w ; No, so save the source position for later.
txy ; Set our position to the destination.
sta (ptr3), y ; Place the character from the source position, to the destination position.
inx ; Increment the destination position.
- ply #2 ; Set our position back to the source.
+ ply.w ; Set our position back to the source.
stb (ptr3), y ; Clear the character that is in the source.
iny ; Increment the source position.
- jmp @dec_loop ; Keep looping.
+ bra @dec_loop ; Keep looping.
@wrap:
tax ; Use the ending line as a parameter for setbit.
jsr setbit ; Set the wrap bit of the ending line.
- jmp @end5 ; We are done.
+ bra @end5 ; We are done.
@wrap1:
tax ; Use the ending line as a parameter for clrbit.
jsr clrbit ; Clear the wrap bit of the ending line.
- jmp @end5 ; We are done.
+ bra @end5 ; We are done.
@end:
lda (ptr3), y ; Is this character a null terminator?
bne @end1 ; No, so just find the end of the line.
@@ -802,12 +807,12 @@ shftln:
cmp scr_row ; Is the ending line greater than the starting line?
beq @end5 ; No, so we're done.
bcs @wrap ; Yes, so set the wrap bit.
- jmp @end5 ; No, so we're done.
+ bra @end5 ; No, so we're done.
@end3:
jsr findend ; Find the ending line.
cpb #0 ; Is the remainder zero?
beq @end4 ; Yes, so check if the ending line is greater than the starting line.
- jmp @end5 ; No, so we're done.
+ bra @end5 ; No, so we're done.
@end4:
cmp scr_row ; Is the ending line greater than the starting line?
beq @end5 ; No, so we're done.
@@ -821,44 +826,45 @@ esc:
cmp #$1B ; Is this character an escape character?
beq shftesc ; Yes, so check the other set of escape routines.
lda status ; No, so wait for the next character.
- beq printc_end ; We have an error, so discard it, and go back to getting user input.
+ beq @end ; We have an error, so discard it, and go back to getting user input.
lda kbd ; Get the escape code.
sta c ; Store the escape code, until we need it.
lda #0 ; Set the D pseudo register to zero.
sta d ;
jsr isup ; Check if the user pressed up.
lda d ; Did the user press up?
- bne esc_end ; Yes, so we're done.
+ bne @end ; Yes, so we're done.
jsr isdown ; No, so check if the user pressed down.
lda d ; Did the user press down?
- bne esc_end ; Yes, so we're done.
+ bne @end ; Yes, so we're done.
lda #0 ; No, so check if the user pressed left.
jsr isleft ;
lda d ; Did the user press left?
- bne esc_end ; Yes, so we're done.
+ bne @end ; Yes, so we're done.
jsr isright ; No, so check if the user pressed right.
-esc_end:
+@end:
lda #0 ; Clear the D pseudo register.
sta d ;
- jmp printc_end ; We are done.
+ rts ; We are done.
shftesc:
lda status ; Skip the '['.
lda kbd ;
lda status ; Wait for the next character.
- beq printc_end ; We have an error, so discard it, and go back to getting user input.
+ beq @end ; We have an error, so discard it, and go back to getting user input.
lda kbd ; Get the escape code.
sta c ; Store the escape code, until we need it.
lda #0 ; Use the D pseudo register as a skip flag.
sta d ;
jsr isshftup ; Check if the user pressed shift+up.
lda d ; Was it successful?
- bne shftesc_end ; Yes, so we're done.
+ bne @end ; Yes, so we're done.
jsr isshftdown ; No, so check if the user pressed shift+down.
-shftesc_end:
+@end:
lda #0 ; Clear the D pseudo register.
sta d ;
- jmp printc_end ; We are done.
+ rts ; We are done.
+
isup:
lda c ; Load the escape code into the accumulator.
@@ -869,8 +875,14 @@ isup:
@check2:
lda c ; No, so load the escape code back into the accumulator.
cmp #'A' ; Did the user press the up arrow key?
- beq up ; Yes, so move the cursor up.
- jmp @end ; No, so we're done.
+ beq @up ; Yes, so move the cursor up.
+ bra @end ; No, so we're done.
+@up:
+ dec scr_row ; Move the cursor up a line.
+ jsr update_pos ; Update it's position.
+ lda #1 ; Tell the escape routine that we succeded.
+ sta d ;
+ rts ; We are done.
@scroll:
lda scr_str ; Are we at the top of the screen buffer?
beq @end ; Yes, so we're done.
@@ -878,9 +890,9 @@ isup:
lda #1 ; Tell the escape routine that we were successful.
sta d ;
@end:
-isup_done:
rts ; End of isup.
+
isdown:
lda c ; Load the escape code into the accumulator.
cmp #'B' ; Did the user press the down arrow key?
@@ -890,8 +902,14 @@ isdown:
beq @scroll ; Yes, so scroll down.
lda c ; No, so load the escape code back into the accumulator.
cmp #'B' ; Did the user press the down arrow key?
- beq down ; Yes, so move the cursor down.
- jmp @end ; No, so we're done.
+ beq @down ; Yes, so move the cursor down.
+ bra @end ; No, so we're done.
+@down:
+ inc scr_row ; Move the cursor down a line.
+ jsr update_pos ; Update it's position.
+ lda #1 ; Tell the escape routine that we succeded.
+ sta d ;
+ rts ; We are done.
@scroll:
lda scr_row ; Save the cursor's row number.
sta scr_trow ;
@@ -905,9 +923,9 @@ isdown:
lda #1 ; Tell the escape routine that we were successful.
sta d ;
@end:
-isdown_done:
rts ; End of isdown.
+
isright:
lda c ; Load the escape code into the accumulator.
cmp #'C' ; Did the user press the right arrow key?
@@ -915,20 +933,20 @@ isright:
lda scr_col ; Yes, so start checking the x coordinate of the cursor.
cmp #maxcol ; Is the cursor at the far right of the screen?
beq @wrap ; Yes, so check if this is a wrapped line.
- jmp right ; No, so move the cursor right, like normal.
+ bra @right ; No, so move the cursor right, like normal.
@wrap:
inc scr_row ; Move down a row.
jsr getbit ; Is the current line, a wrapped line?
bcs @incr ; Yes, so leave the cursor where it is.
dec scr_row ; No, so move the cursor back up a row.
- jmp @end2 ; We are done.
+ bra @end2 ; We are done.
@scroll:
lda scr_str ; Are we at the top of the screen buffer?
beq @end ; Yes, so we're done.
lda #1 ; No, so scroll down.
sta wrapped ; Set the wrapped flag.
jsr scrl_down ; Scroll down.
- jmp @end ; We are done.
+ bra @end ; We are done.
@incr:
lda #0 ; Set the cursor to the far left of the screen.
sta scr_col ;
@@ -936,17 +954,21 @@ isright:
cmp #maxrow ; Are we at the bottom of the screen?
beq @end1 ; No, so we're done.
bcs @scroll ; Yes, so check if we are scrolling down.
- jmp @end1 ; No, so we're done.
+ bra @end1 ; No, so we're done.
+@right:
+ inc scr_col ; Move the cursor right by one character.
+ jsr update_pos ; Update it's position.
+ rts ; End of isright.
@end:
dec scr_row ; Move back up a row.
@end1:
jsr update_pos ; Update the cursor position.
@end2:
-isright_dne:
lda #0 ; Unset the wrapped flag.
sta wrapped ;
rts ; End of isright.
+
isleft:
lda c ; Load the escape code into the accumulator.
cmp #'C' ; Did the user press right?
@@ -955,12 +977,12 @@ isleft:
beq @wrap ; Yes, so start checking if this is a wrapped line.
lda c ; No, so load the escape code back into the accumulator.
cmp #'D' ; Did the user press the left arrow key?
- beq left ; Yes, so move the cursor left.
- jmp @end1 ; No, so we're done.
+ beq @left ; Yes, so move the cursor left.
+ bra @end1 ; No, so we're done.
@wrap:
jsr getbit ; Is the current line, a wrapped line?
bcs @decr ; Yes, so wrap back up a line.
- jmp @end1 ; No, so we're done.
+ bra @end1 ; No, so we're done.
@decr:
lda scr_row ; Is the cursor at the top of the screen?
beq @decr1 ; Yes, so don't move up a line.
@@ -974,81 +996,60 @@ isleft:
sta d ;
lda scr_row ; Are we at the top of the screen?
beq @scroll ; Yes, so check if we need to scroll.
- jmp @end ; No, so we're done.
+ bra @end ; No, so we're done.
@scroll:
lda wrapped ; Was the wrapped flag set somewhere else?
bne @end ; Yes so we're done.
lda scr_str ; No, but are we actually at the top of the screen buffer?
beq @end1 ; Yes, so we're done.
jsr scrl_up ; No, so scroll up.
- jmp @end1 ; We are done.
+ bra @end1 ; We are done.
+@left:
+ dec scr_col ; Move the cursor left a character.
+ jsr update_pos ; Update it's position.
+ lda #1 ; Tell the escape routine that we succeded.
+ sta d ;
+ rts ; We are done
@end:
jsr update_pos ; Update the cursor position.
@end1:
-isleft_done:
lda #0 ; Unset the wrapped flag.
sta wrapped ;
rts ; End of isleft.
-up:
- dec scr_row ; Move the cursor up a line.
- jsr update_pos ; Update it's position.
- lda #1 ; Tell the escape routine that we succeded.
- sta d ;
- jmp isup_done ; We are done.
-down:
- inc scr_row ; Move the cursor down a line.
- jsr update_pos ; Update it's position.
- lda #1 ; Tell the escape routine that we succeded.
- sta d ;
- jmp isdown_done ; We are done.
-right:
- inc scr_col ; Move the cursor right by one character.
- jsr update_pos ; Update it's position.
- jmp isright_dne ; We are done.
-left:
- dec scr_col ; Move the cursor left a character.
- jsr update_pos ; Update it's position.
- lda #1 ; Tell the escape routine that we succeded.
- sta d ;
- jmp isleft_done ; We are done
isshftup:
lda c ; Load the escape code back into the accumulator.
cmp #'A' ; Did the user press the up arrow key?
- bne shftup_done ;
+ bne @end ;
lda #1 ;
sta d ;
lda scr_str ;
- beq shftup_done ;
- jmp shftup ;
-shftup_done:
+ beq @end ;
+@shftup:
+ jsr scrl_up ;
+ lda #1 ;
+ sta d ;
+@end:
rts ;
+
isshftdown:
lda c ; Load the escape code back into the accumulator.
cmp #'B' ; Did the user press the down arrow key?
- bne shftdn_done ;
+ bne @end ;
lda #1 ;
sta d ;
lda scr_end ;
cmp #71 ;
- bcs shftdn_done ;
- jmp shftdown ;
-shftdn_done:
- rts ;
-
-shftup:
- jsr scrl_up ;
- lda #1 ;
- sta d ;
- jmp shftup_done ;
-
-shftdown:
+ bcs @end ;
+@shftdown:
jsr scrl_down ;
lda #1 ;
sta d ;
- jmp shftdn_done ;
+@end:
+ rts ;
+
update_pos:
ldb #1 ; Set the F pseudo register to one, to fix some bugs.
@@ -1074,7 +1075,7 @@ update_pos:
getrow:
lda scr_row ; Get the cursor's y coordinate.
- jmp bcd ; Convert it to BCD.
+ bra bcd ; Convert it to BCD.
getcol:
lda #';' ; Print ';'
sta scr ; to the screen.
@@ -1098,23 +1099,23 @@ scrl_down:
lda #'T' ; Print 'T'
sta scr ; to the screen, and end the escape sequence.
lda scr_row ; Get the cursor's line number.
- pha #1 ; Save it in the stack.
+ pha ; Save it in the stack.
lda wrapped ; Was the wrapped flag set?
beq @save ; Yes, so save the cursor position.
@redraw:
jsr rdrw_row ; No, so redraw this row.
lda wrapped ; Was the wrapped flag set?
beq @load ; Yes, so load the previous cursor position back.
- jmp @end ; No, so we're done.
+ bra @end ; No, so we're done.
@save:
lda scr_col ; Get the cursor's column number.
- pha #1 ; Save it in the stack.
- jmp @redraw ; Start redrawing the current row.
+ pha ; Save it in the stack.
+ bra @redraw ; Start redrawing the current row.
@load:
- pla #1 ; Get the cursor's previous column number back.
+ pla ; Get the cursor's previous column number back.
sta scr_col ;
@end:
- pla #1 ; Get the cursor's previous line number back.
+ pla ; Get the cursor's previous line number back.
sta scr_row ;
jsr update_pos ; Update the cursor's position.
lda #0 ; Clear the wrapped flag.
@@ -1132,15 +1133,15 @@ scrl_up:
lda #'S' ; Print 'S'
sta scr ; to the screen, and end the escape sequence.
lda scr_row ;
- pha #1 ;
+ pha ;
lda scr_col ;
- pha #1 ;
+ pha ;
lda #0 ;
sta scr_row ;
jsr rdrw_row ;
- pla #1 ;
+ pla ;
sta scr_col ;
- pla #1 ;
+ pla ;
sta scr_row ;
jsr update_pos ;
@end:
@@ -1164,11 +1165,11 @@ rdrw_row:
lda scr_col ;
cmp #maxcol+1 ;
bcs @end ;
- jmp @loop ;
+ bra @loop ;
@skip:
lda #' ' ;
sta scr ; to the screen.
- jmp @incr1 ;
+ bra @incr1 ;
@end:
lda #0 ;
sta scr_col ;
@@ -1178,11 +1179,11 @@ rdrw_row:
rdrw_ln:
lda scr_row ;
- pha #1 ;
+ pha ;
lda f ;
sta scr_row ;
lda scr_col ;
- pha #1 ;
+ pha ;
jsr update_pos ;
@loop:
lda scr_row ;
@@ -1193,11 +1194,11 @@ rdrw_ln:
jsr rdrw_row ;
@incr:
inc scr_row ;
- jmp @loop ;
+ bra @loop ;
@end:
- pla #1 ;
+ pla ;
sta scr_col ;
- pla #1 ;
+ pla ;
sta scr_row ;
jsr update_pos ;
lda #0 ;
@@ -1213,11 +1214,11 @@ set_ptr:
@ptr1:
stb.q ptr ; Reset the first pointer.
sta.q ptr ; No, so set the first pointer.
- jmp @end ; We are done.
+ bra @end ; We are done.
@ptr2:
stb.q ptr2 ; Reset the second pointer.
sta.q ptr2 ; Set the second pointer.
- jmp @end ; We are done.
+ bra @end ; We are done.
@ptr3:
stb.q ptr3 ; Reset the third pointer.
sta.q ptr3 ; Set the third pointer.
diff --git a/programs/sub-suite/utils.s b/programs/sub-suite/utils.s
index 580e4da..a66f036 100644
--- a/programs/sub-suite/utils.s
+++ b/programs/sub-suite/utils.s
@@ -42,22 +42,22 @@ print_lo:
sta idx3 ; Clear the string index.
@loop:
ldx #2 ; Set digit count to 2.
- pha #1 ; Preserve the nibble offset.
+ pha ; Preserve the nibble offset.
jsr print_hex ; Print the low nibble offset.
lda.w (ptr3) ; Get the two digits.
jsr charcpy ; Copy the first digit.
lsr #8 ; Copy the next digit.
jsr charcpy ;
- pla #1 ; Get the nibble offset back.
+ pla ; Get the nibble offset back.
inc ; Increment the offset.
cmp #$10 ; Are we at the last offset?
bcs @end ; Yes, so we're done.
@loop1:
- pha #1 ; No, so preserve the nibble offset.
+ pha ; No, so preserve the nibble offset.
lda #' ' ; Add a space to the string buffer.
jsr charcpy ;
- pla #1 ; Get the nibble offset back.
- jmp @loop ; Keep looping.
+ pla ; Get the nibble offset back.
+ bra @loop ; Keep looping.
@end:
inx ; Increment the index by one.
lda #0 ; Null terminate the string buffer.
@@ -69,7 +69,7 @@ print_lo:
print_chunk:
ldx #0 ; Reset X.
- phy #2 ; Preserve the screen buffer index.
+ phy.w ; Preserve the screen buffer index.
txy ; Copy the byte index to it.
@loop:
and #0 ; Reset A.
@@ -85,9 +85,9 @@ print_chunk:
beq @end ; Yes, so we're done.
lda #' ' ; No, so add a soace to the string buffer.
jsr charcpy ;
- jmp @loop ; Keep looping.
+ bra @loop ; Keep looping.
@end:
- ply #2 ; Get the screen buffer index back.
+ ply.w ; Get the screen buffer index back.
inx ; Increment the index by one.
and #0 ; Null terminate the string.
sta strbuf, x ;
@@ -97,7 +97,7 @@ print_chunk:
print_hex:
- pha #8 ; Preserve the hex value.
+ pha.q ; Preserve the hex value.
and #0 ; Reset A.
ldb #1 ; Set the second pointer
lda.w #hex_char ; to the start of hex character table.
@@ -108,37 +108,79 @@ print_hex:
adc #$10 ;
jsr set_ptr ;
ldb #0 ; Reset B.
- pla #8 ; Get the hex value back.
+ pla.q ; Get the hex value back.
@loop:
- pha #8 ; Preserve the hex value.
+ pha.q ; Preserve the hex value.
and #$F ; Mask the lowest nibble.
- phy #2 ; Preserve the screen buffer position.
+ phy.w ; Preserve the screen buffer position.
tay ; Get the index for the hex digit.
lda (ptr2), y ; Get the hex digit.
dec ptr3 ; Decrement the string pointer.
sta (ptr3) ; Save the hex digit character in the string.
- ply #2 ; Get back the screen buffer position.
- pla #8 ; Get the hex value back.
+ ply.w ; Get back the screen buffer position.
+ pla.q ; Get the hex value back.
@isauto:
cpx #1 ; Is the digit count less than one?
bcc @auto ; Yes, so don't decrement the digit count.
dex ; No, but was the digit count zero, when decremented?
beq @end ; Yes, so we're done.
- jmp @next ; No, so get the next nibble.
+ bra @next ; No, so get the next nibble.
@auto:
ldb #1 ; Enable auto digit count.
@next:
lsr #4 ; Is the next nibble, a zero?
beq @isauto1 ; Yes, so check if auto digit count is enabled.
- jmp @loop ; No, so print the next digit.
+ bra @loop ; No, so print the next digit.
@isauto1:
cpb #1 ; Is auto digit count enabled?
beq @end ; Yes, so we're done.
- jmp @loop ; No, so keep printing more digits.
+ bra @loop ; No, so keep printing more digits.
@end:
rts ; End of print_hex.
+strtoull:
+ phy.w ; Preserve Y.
+ sta f ; Save the base.
+ and #0 ; Reset A.
+ tay ; Reset Y.
+ sta.q valbuf ; Reset the value buffer.
+@loop:
+ lda (ptr3), y ; Get a character from the string.
+ pha ; Preserve the character.
+ jsr isdigit ; Is this character, a digit?
+ pla ; Get the character back.
+ bne @digit ; Yes, so extract the value from it.
+ jsr tolower ; No, so convert the character to lowercase.
+ pha ; Preserve the character.
+ jsr islower ; Is this an alphabetical character?
+ pla ; Get the character back.
+ beq @end ; No, so we're done.
+@alpha:
+ sec ; Yes, so prepare for a non borrowing subtract.
+ sbc #'a'-10 ; Get the numeric value from this digit.
+ bra @chkbase ; Check if the value matches the base.
+@digit:
+ sec ; Prepare for a non borrowing subtract.
+ sbc #'0' ; Get the numeric value from this digit.
+@chkbase:
+ cmp f ; Does the value match the base?
+ bcs @end ; No, so we're done.
+@addval:
+ tab ; Save the digit value.
+ lda.q valbuf ; Get the value from the value buffer.
+ mul f ; Multiply the value by the base.
+ clc ; Prepare for a non carrying add.
+ aab ; Add the digit value to the total value.
+ sta.q valbuf ; Place the value in the value buffer.
+ iny ; Increment the string index.
+ bra @loop ; Keep looping.
+@end:
+ ply.w ; Get Y back.
+ ldb #0 ; Reset B.
+ rts ; End of strtoull.
+
+
charcpy:
ldx idx3 ; Get the string index.
sta strbuf, x ; Save it in the string buffer.
@@ -152,16 +194,16 @@ strlen:
deb ; Reset B.
tba ; Reset A.
tax ; Reset X.
- phy #2 ; Preserve Y.
+ phy.w ; Preserve Y.
txy ; Reset Y.
@loop:
lda (ptr2), y ; Are we at the end of the string?
beq @end ; Yes, so we're done.
iny ; No, so increment the index.
- jmp @loop ; Keep looping.
+ bra @loop ; Keep looping.
@end:
tyx ; Return the length in X.
- ply #2 ; Get the preserved value back.
+ ply.w ; Get the preserved value back.
rts ; End of strlen.
@@ -170,7 +212,7 @@ strcmp:
jsr set_ptr ; to the passed pointer.
deb ; Reset B.
tba ; Reset A.
- phy #2 ; Preserve Y.
+ phy.w ; Preserve Y.
tay ; Reset Y.
@loop:
ldb #0 ; Set the islong flag to false.
@@ -180,14 +222,14 @@ strcmp:
cmp (ptr2), y ; Is the character of both strings, the same?
bne cmpr ; No, so check if we're too short, or too long.
iny ; Yes, so increment the index.
- jmp @loop ; Keep looping.
+ bra @loop ; Keep looping.
strcasecmp:
ldb #1 ; Set the second pointer
jsr set_ptr ; to the passed pointer.
deb ; Reset B.
tba ; Reset A.
- phy #2 ; Preserve Y.
+ phy.w ; Preserve Y.
tay ; Reset Y.
@loop:
ldb #0 ; Set the islong flag to false.
@@ -195,17 +237,17 @@ strcasecmp:
beq cmpr ; Yes, so check if we're too short, or too long.
ldb #1 ; No, so set the islong flag to true.
jsr tolower ; Convert the character of string 1 to lowercase.
- phb #1 ; Preserve the islong flag.
- pha #1 ; Preserve the converted character.
+ phb ; Preserve the islong flag.
+ pha ; Preserve the converted character.
lda (ptr2), y ; Get the character of the second string.
jsr tolower ; Convert the character of string 2 to lowercase.
tab ; Place it in B.
- pla #1 ; Get the character of string 1 back.
+ pla ; Get the character of string 1 back.
cab ; Is the character of both strings, the same?
- plb #1 ; Get the islong flag back.
+ plb ; Get the islong flag back.
bne cmpr ; No, so check if we're too short, or too long.
iny ; Yes, so increment the index.
- jmp @loop ; Keep looping.
+ bra @loop ; Keep looping.
cmpr:
lda (ptr2), y ; Are we at the end of the second string?
@@ -218,14 +260,14 @@ cmpr:
bne @equ ; No, so return 0.
@long:
lda #1 ; Yes, so return 1.
- jmp @end ; We are done.
+ bra @end ; We are done.
@equ:
lda #0 ; Return 0.
- jmp @end ; We are done.
+ bra @end ; We are done.
@short:
lda #$FF ; Return -1.
@end:
- ply #2 ; Get the preserved value back.
+ ply.w ; Get the preserved value back.
rts ; End of strcmp.
@@ -237,16 +279,16 @@ isdigit:
bcs @false ; No, so return false.
@true:
lda #1 ; Yes, so return true.
- jmp @end ; We are done.
+ bra @end ; We are done.
@false:
lda #0 ; Return false.
@end:
rts ; End of isdigit.
isxdigit:
- pha #1 ; Preserve the character.
+ pha ; Preserve the character.
jsr isdigit ; Is this character, a decimal digit?
- pla #1 ; Get the character back.
+ pla ; Get the character back.
bne @true ; Yes, so return true.
@alpha:
sec ; No, so prepare for a non carrying subtract.
@@ -257,7 +299,7 @@ isxdigit:
bcs @false ; No, so return false.
@true:
lda #1 ; Yes, so return true.
- jmp @end ; We are done.
+ bra @end ; We are done.
@false:
lda #0 ; Return false.
@end:
@@ -267,7 +309,7 @@ isxdigit:
isupper:
sec ; Prepare for a non carrying subtraction.
sbc #'A' ; Subtract $41 from the passed character.
- jmp isletter ; Check if it's less than 26.
+ bra isletter ; Check if it's less than 26.
islower:
sec ; Prepare for a non carrying subtraction.
sbc #'a' ; Subtract $61 from the passed character.
@@ -277,7 +319,7 @@ isletter:
bcs @false ; No, so return false.
@true:
lda #1 ; Yes, so return true.
- jmp @end ; We are done.
+ bra @end ; We are done.
@false:
lda #0 ; Return false.
@end:
@@ -285,9 +327,9 @@ isletter:
tolower:
- pha #1 ; Preserve the character.
+ pha ; Preserve the character.
jsr isupper ; Is this character, an uppercase character?
- pla #1 ; Get the character back.
+ pla ; Get the character back.
beq @end ; No, so we're done.
@lower:
ora #$20 ; Yes, so convert it to lowercase.
@@ -296,9 +338,9 @@ tolower:
toupper:
- pha #1 ; Preserve the character.
+ pha ; Preserve the character.
jsr islower ; Is this character, a lowercase character?
- pla #1 ; Get the character back.
+ pla ; Get the character back.
beq @end ; No, so we're done.
@upper:
and #$5F ; Yes, so convert it to uppercase.
@@ -314,7 +356,7 @@ isdelm2:
cab ; Are they the same?
beq @r1 ; Yes, so return 1.
inx ; No, so increment the table index.
- jmp @loop ; Keep looping.
+ bra @loop ; Keep looping.
@other:
ldx #0 ; Reset X.
cmp #0 ; Is this a null terminator?
@@ -344,7 +386,7 @@ isdelm:
cab ; Are they the same?
beq @rshft ; Yes, so return 1 << index.
inx ; No, so increment the table index.
- jmp @loop ; Keep looping.
+ bra @loop ; Keep looping.
@other:
ldx #0 ; Reset X.
cmp #0 ; Is this a null terminator?
@@ -373,7 +415,7 @@ get_ptok:
cab ; Are they the same?
beq @rtab ; Yes, so return X.
inx ; No, so increment the table index.
- jmp @loop ; Keep looping.
+ bra @loop ; Keep looping.
@rtab:
txa ; Return X.
rts ; End of get_ptok.