summaryrefslogtreecommitdiff
path: root/programs/sub-suite/utils.s
diff options
context:
space:
mode:
Diffstat (limited to 'programs/sub-suite/utils.s')
-rw-r--r--programs/sub-suite/utils.s130
1 files changed, 86 insertions, 44 deletions
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.