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.s257
1 files changed, 40 insertions, 217 deletions
diff --git a/programs/sub-suite/utils.s b/programs/sub-suite/utils.s
index a66f036..046164a 100644
--- a/programs/sub-suite/utils.s
+++ b/programs/sub-suite/utils.s
@@ -1,22 +1,5 @@
; Utility subroutines for SuBAsm.
-.org util_data
-; Hex character table.
-hex_char:
- .byte "0123456789ABCDEF"
-
-; Compare, and return table for pre-tokens.
-ptok_tab:
- .byte ".@:=+-><(),xy\"\'#;$%"
-; Compare, and return table for isdelm.
-dtab:
- .byte "\n,\"\' "
-; Compare, and return table for isdelm2.
-dtab2:
- .byte "),.+<>-=;\n"
-
-.org utils
-
print_hi:
and #0 ; Reset A.
sta idx3 ; Clear the string index.
@@ -139,48 +122,6 @@ print_hex:
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.
@@ -188,164 +129,46 @@ charcpy:
rts ; End of charcpy.
-strlen:
- ldb #1 ; Set the second pointer
- jsr set_ptr ; to the passed pointer.
- deb ; Reset B.
- tba ; Reset A.
- tax ; Reset X.
- 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.
- bra @loop ; Keep looping.
-@end:
- tyx ; Return the length in X.
- ply.w ; Get the preserved value back.
- rts ; End of strlen.
-
-
-strcmp:
- ldb #1 ; Set the second pointer
- jsr set_ptr ; to the passed pointer.
- deb ; Reset B.
- tba ; Reset A.
- phy.w ; Preserve Y.
- tay ; Reset Y.
-@loop:
- ldb #0 ; Set the islong flag to false.
- lda (ptr), y ; Are we at the end of the first string?
- beq cmpr ; Yes, so check if we're too short, or too long.
- ldb #1 ; No, so set the islong flag to true.
- 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.
- 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.w ; Preserve Y.
- tay ; Reset Y.
-@loop:
- ldb #0 ; Set the islong flag to false.
- lda (ptr), y ; Are we at the end of the first string?
- 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 ; 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 ; Get the character of string 1 back.
- cab ; Is the character of both strings, the same?
- 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.
- bra @loop ; Keep looping.
-
-cmpr:
- lda (ptr2), y ; Are we at the end of the second string?
- beq @islong ; Yes, so check the islong flag.
-@isshort:
- lda (ptr), y ; No, but are we at the end of the first string?
- beq @short ; Yes, so return -1.
-@islong:
- cpb #1 ; Is the islong flag true?
- bne @equ ; No, so return 0.
-@long:
- lda #1 ; Yes, so return 1.
- bra @end ; We are done.
-@equ:
- lda #0 ; Return 0.
- bra @end ; We are done.
-@short:
- lda #$FF ; Return -1.
-@end:
- ply.w ; Get the preserved value back.
- rts ; End of strcmp.
-
-
-isdigit:
- sec ; Prepare for a non carrying subtraction.
- sbc #'0' ; Subtract $30 from the passed character.
- and #$FF ; Make sure that we have only one byte.
- cmp #10 ; Is the subtracted value, less than 10?
- bcs @false ; No, so return false.
-@true:
- lda #1 ; Yes, so return true.
- bra @end ; We are done.
-@false:
- lda #0 ; Return false.
-@end:
- rts ; End of isdigit.
-
-isxdigit:
- pha ; Preserve the character.
- jsr isdigit ; Is this character, a decimal digit?
- pla ; Get the character back.
- bne @true ; Yes, so return true.
-@alpha:
- sec ; No, so prepare for a non carrying subtract.
- ora #$20 ; Convert it to lowercase.
- sbc #'a' ; Subtract $61 from the character.
- and #$FF ; Make sure that we have only one byte.
- cmp #6 ; Is the subtracted value, less than 6?
- bcs @false ; No, so return false.
-@true:
- lda #1 ; Yes, so return true.
- bra @end ; We are done.
-@false:
- lda #0 ; Return false.
-@end:
- rts ; End of isxdigit.
-
-
-isupper:
- sec ; Prepare for a non carrying subtraction.
- sbc #'A' ; Subtract $41 from the passed character.
- 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.
-isletter:
- and #$FF ; Make sure that we have only one byte.
- cmp #26 ; Is the subtracted value, less than 26?
- bcs @false ; No, so return false.
-@true:
- lda #1 ; Yes, so return true.
- bra @end ; We are done.
-@false:
- lda #0 ; Return false.
-@end:
- rts ; End of isletter.
-
-
-tolower:
- pha ; Preserve the character.
- jsr isupper ; Is this character, an uppercase character?
- pla ; Get the character back.
- beq @end ; No, so we're done.
-@lower:
- ora #$20 ; Yes, so convert it to lowercase.
-@end:
- rts ; End of tolower.
-
-
-toupper:
- pha ; Preserve the character.
- jsr islower ; Is this character, a lowercase character?
- pla ; Get the character back.
- beq @end ; No, so we're done.
-@upper:
- and #$5F ; Yes, so convert it to uppercase.
-@end:
- rts ; End of toupper.
+strcmpg:
+ ldb.w #strcmp ; Get the address of strcmp.
+ phb.q ; Use it for an indirect call.
+ ldb.q ptr ; Get the first pointer.
+ bra gargs ; Jump to the argument handler.
+strcaseg:
+ ldb.w #strccmp ; Get the address of strcasecmp.
+ phb.q ; Use it for an indirect call.
+ ldb.q ptr ; Get the first pointer.
+ bra gargs ; Jump to the argument handler.
+gargs:
+ phb.q ; Use the pointer in B as the first arg.
+ pha.q ; Use the value in A as the second arg.
+ and #0 ; reset a.
+ tab ; reset b.
+ jsr (sp+17) ; call the pushed routine.
+ tab ; Preserve the return value.
+ pla.q ; Get the second arg back.
+ pla.q ; Get the first arg back.
+ pla.q ; Get the pushed routine back.
+ tba ; Get the return value back.
+ rts ; End of gargs.
+
+
+strtoullg:
+ ldb.q ptr3 ; Get the third pointer.
+ phb.q ; Push the first arg.
+ pha ; Push the second arg.
+ and #0 ; Reset A.
+ tab ; Reset B.
+ jsr strtoull ; Call strtoull.
+ tab ; Preserve the return value.
+ pla ; Get the second arg back.
+ pla.q ; Get the first arg back.
+ tba ; Get the return value back.
+ pha.q ; Preserve the return value.
+ and #0 ; Reset A.
+ tab ; Reset B.
+ pla.q ; Get the return value back.
+ rts ; End of strtoullg.
isdelm2: