mirror of
https://github.com/RevCurtisP/C02.git
synced 2024-12-01 14:51:52 +00:00
121 lines
4.0 KiB
Plaintext
121 lines
4.0 KiB
Plaintext
|
;ctype.h02 assembly language subroutines
|
||
|
;
|
||
|
;C02 Functions modify Accumulator and Flags
|
||
|
; ISxxxx will load $FF into Accumulator to and Set Carry if True
|
||
|
; and load $00 into Accumulator to and clear Carry if False
|
||
|
; toxxxx set Carry if character IS converted, otherwISe clear Carry
|
||
|
;Machine Language Subroutines modify Flags but not Accumulator
|
||
|
; Carry will be Set if True and Cleared if False
|
||
|
;Index RegISters are not modified by any routines
|
||
|
|
||
|
;Character Test Functions - Set Accumulator
|
||
|
ISALNM: JSR ISALN ;Is Alphanumeric Character
|
||
|
BVC ISBTF
|
||
|
ISALPH: JSR ISALP; ;Is Alphabetic Character
|
||
|
BVC ISBTF
|
||
|
ISBDGT: JSR ISBIN ;Is Binary Digit
|
||
|
BVC ISBTF
|
||
|
ISCTRL: JSR ISCTL ;Is Control Character
|
||
|
BVC ISBTF
|
||
|
ISDIGT: JSR ISDGT ;Is Digit
|
||
|
BVC ISBTF
|
||
|
ISGRPH: JSR ISGRP ;Is Graphical Character
|
||
|
BVC ISBTF
|
||
|
ISHDGT: JSR ISHEX ;Is Hex Digit
|
||
|
BVC ISBTF
|
||
|
ISLOWR: JSR ISLWR ;Is Lowercase Character
|
||
|
BVC ISBTF
|
||
|
ISPNCT: JSR ISPNC ;Is Punctuation Character
|
||
|
BVC ISBTF
|
||
|
ISPRNT: JSR ISPRT ;Is Printable Character
|
||
|
BVC ISBTF
|
||
|
ISSPCE: JSR ISSPC ;Is White Space Character
|
||
|
BVC ISBTF
|
||
|
ISUPPR: JSR ISUPR ;Is Uppercase Character
|
||
|
BVC ISBTF
|
||
|
|
||
|
;Internal Routines - Set Accumulator based on Carry Flag
|
||
|
ISBTF: BCC ISFLS ;If Carry Set
|
||
|
ISTRU: LDA #$FF ; Return TRUE
|
||
|
RTS ;Else
|
||
|
ISFLS: LDA #$00 ; Return FALSE
|
||
|
RTS
|
||
|
|
||
|
;C02/ML Character Conversion Routines
|
||
|
tolowr: JSR ISUPR ;If Char IS Not Upper Case
|
||
|
BCC ISRTS ; Return
|
||
|
ORA #$20 ;Else Set Bit 5
|
||
|
RTS ; and Return
|
||
|
|
||
|
touppr: JSR ISLWR ;If Char IS Not Lower Case
|
||
|
BCC ISRTS ; Return
|
||
|
AND #$DF ;Else Clear Bit 5
|
||
|
RTS ; and Return
|
||
|
|
||
|
;Machine Language Subroutines - Set/Clear Carry, Preserve Accumulator
|
||
|
ISALN: JSR ISDGT ;If Char IS Digit
|
||
|
BCS ISRTS ; Return Carry Set
|
||
|
;Else
|
||
|
ISALP: JSR ISUPR ;If Char IS Upper Case
|
||
|
BCS ISRTS ; Return Carry Set
|
||
|
;Else
|
||
|
ISLWR: CMP #$61 ;If Char < 'a'
|
||
|
BCC ISRTS ; Return with Carry Clear
|
||
|
CMP #$7B ;Else If Char >= '{'
|
||
|
JMP ISBCS ; Return with Carry Clear Else Return with Carry Set
|
||
|
|
||
|
ISUPR: CMP #$41 ;If Char < 'A'
|
||
|
BCC ISRTS ; Return with Carry Clear
|
||
|
CMP #$5B ;Else If Char >= '['
|
||
|
ISBCS: BCS ISCLC ; Return with Carry Clear
|
||
|
BCC ISSEC ;Else Return with Carry Set
|
||
|
|
||
|
ISSEC: SEC ;Set Carry
|
||
|
BCS ISRTS ; and Return
|
||
|
|
||
|
ISCLC: CLC ;Clear Carry
|
||
|
ISRTS: CLV ;Clear Overflow - for C02 calls
|
||
|
RTS ;Return from Subroutine
|
||
|
|
||
|
ISCTL: CMP #$7F ;If Char = DEL
|
||
|
BEQ ISSEC ; Return Carry Set
|
||
|
CMP #$20 ;Else If Char < ' '
|
||
|
JMP ISBCS ; Return Carry Set Else Return Carry Clear
|
||
|
|
||
|
ISBIN: CMP #$32 ;If Char >= '2'
|
||
|
|
||
|
BCS ISCLC ; Return Carry Clear
|
||
|
;Else
|
||
|
ISDGT: CMP #$30 ;If Char < '0'
|
||
|
BCC ISRTS ; Return Carry Clear
|
||
|
CMP #$3A ;Else If Char >= ':'
|
||
|
JMP ISBCS ; Return FALSE Else Return TRUE
|
||
|
|
||
|
ISPNC: JSR ISALN ;If Char IS Alphanumeric
|
||
|
BCS ISCLC ; Return Carry Clear
|
||
|
;Else
|
||
|
ISGRP: CMP #$20 ;If Char IS Space
|
||
|
BEQ ISCLC ; Return Carry Clear
|
||
|
;Else
|
||
|
ISPRT: CMP #$80 ;If Char IS High ASCII
|
||
|
BCS ISCLC ; Return Carry Clear
|
||
|
JSR ISCTL ;If Char IS Not Control
|
||
|
JMP ISBCS ; Return Carry Clear Else Return Carry Set
|
||
|
|
||
|
ISSPC: CMP #$20 ;If Char IS ' '
|
||
|
BEQ ISSEC ; Return Carry Set
|
||
|
CMP #$09 ;If Char < '\t'
|
||
|
BCC ISRTS ; Return Carry Clear
|
||
|
CMP #$0E ;Else If Char > '\r'
|
||
|
JMP ISBCS ; Return Carry Clear Else Return Carry Set
|
||
|
|
||
|
ISHEX: CMP #$41 ;If Char < 'A'
|
||
|
BCC ISDGT ; Check for Digit
|
||
|
CMP #$47 ;Else If Char < 'G'
|
||
|
BCC ISSEC ; Return Carry Set
|
||
|
CMP #$61 ;Else If Char < 'a'
|
||
|
BCC ISRTS ; Return Carry Clear
|
||
|
CMP #$67 ;Else If Char >= 'g'
|
||
|
JMP ISBCS ; Return Carry Clear Else Return Carry Set
|
||
|
|