1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-12-01 14:51:52 +00:00
C02/include/ctype.a02

123 lines
4.1 KiB
Plaintext
Raw Normal View History

2018-01-28 18:30:49 +00:00
;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
2018-01-28 18:30:49 +00:00
;Machine Language Subroutines modify Flags but not Accumulator
; Carry will be Set if True and Cleared if False
;Index Registers X an Y are not modified by any routines
SUBROUTINE CTYPE
2018-01-28 18:30:49 +00:00
;Character Test Functions - Set Accumulator
ISALNM: JSR ISALN ;Is Alphanumeric Character
BVC .ISBTF
ISALPH: JSR ISALP ;Is Alphabetic Character
BVC .ISBTF
2018-01-28 18:30:49 +00:00
ISBDGT: JSR ISBIN ;Is Binary Digit
BVC .ISBTF
2018-01-28 18:30:49 +00:00
ISCTRL: JSR ISCTL ;Is Control Character
BVC .ISBTF
2018-01-28 18:30:49 +00:00
ISDIGT: JSR ISDGT ;Is Digit
BVC .ISBTF
2018-01-28 18:30:49 +00:00
ISGRPH: JSR ISGRP ;Is Graphical Character
BVC .ISBTF
2018-01-28 18:30:49 +00:00
ISHDGT: JSR ISHEX ;Is Hex Digit
BVC .ISBTF
2018-01-28 18:30:49 +00:00
ISLOWR: JSR ISLWR ;Is Lowercase Character
BVC .ISBTF
2018-01-28 18:30:49 +00:00
ISPNCT: JSR ISPNC ;Is Punctuation Character
BVC .ISBTF
2018-01-28 18:30:49 +00:00
ISPRNT: JSR ISPRT ;Is Printable Character
BVC .ISBTF
2018-01-28 18:30:49 +00:00
ISSPCE: JSR ISSPC ;Is White Space Character
BVC .ISBTF
2018-01-28 18:30:49 +00:00
ISUPPR: JSR ISUPR ;Is Uppercase Character
BVC .ISBTF
2018-01-28 18:30:49 +00:00
;Internal Routines - Set Accumulator based on Carry Flag
.ISBTF BCC .ISFLS ;If Carry Set
.ISTRU LDA #$FF ; Return TRUE
2018-01-28 18:30:49 +00:00
RTS ;Else
.ISFLS LDA #$00 ; Return FALSE
2018-01-28 18:30:49 +00:00
RTS
;C02/ML Character Conversion Routines
2019-03-23 01:18:49 +00:00
TOLOWR: JSR ISUPR ;If Char IS Not Upper Case
BCC .ISRTS ; Return
2018-01-28 18:30:49 +00:00
ORA #$20 ;Else Set Bit 5
RTS ; and Return
2019-03-23 01:18:49 +00:00
TOUPPR: JSR ISLWR ;If Char IS Not Lower Case
BCC .ISRTS ; Return
2018-01-28 18:30:49 +00:00
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
2018-01-28 18:30:49 +00:00
;Else
ISALP: JSR ISUPR ;If Char IS Upper Case
BCS .ISRTS ; Return Carry Set
2018-01-28 18:30:49 +00:00
;Else
ISLWR: CMP #$61 ;If Char < 'a'
BCC .ISRTS ; Return with Carry Clear
2018-01-28 18:30:49 +00:00
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
2018-01-28 18:30:49 +00:00
CMP #$5B ;Else If Char >= '['
ISBCS: BCS .ISCLC ; Return with Carry Clear
BCC .ISSEC ;Else Return with Carry Set
2018-01-28 18:30:49 +00:00
.ISSEC SEC ;Set Carry
BCS .ISRTS ; and Return
2018-01-28 18:30:49 +00:00
.ISCLC CLC ;Clear Carry
.ISRTS CLV ;Clear Overflow - for C02 calls
2018-01-28 18:30:49 +00:00
RTS ;Return from Subroutine
ISCTL: CMP #$7F ;If Char = DEL
BEQ .ISSEC ; Return Carry Set
2018-01-28 18:30:49 +00:00
CMP #$20 ;Else If Char < ' '
JMP ISBCS ; Return Carry Set Else Return Carry Clear
ISBIN: CMP #$32 ;If Char >= '2'
BCS .ISCLC ; Return Carry Set
2018-01-28 18:30:49 +00:00
;Else
ISDGT: CMP #$30 ;If Char < '0'
BCC .ISRTS ; Return Carry Clear
2018-01-28 18:30:49 +00:00
CMP #$3A ;Else If Char >= ':'
JMP ISBCS ; Return FALSE Else Return TRUE
ISPNC: JSR ISALN ;If Char IS Alphanumeric
BCS .ISCLC ; Return Carry Clear
2018-01-28 18:30:49 +00:00
;Else
ISGRP: CMP #$20 ;If Char IS Space
BEQ .ISCLC ; Return Carry Clear
2018-01-28 18:30:49 +00:00
;Else
ISPRT: CMP #$80 ;If Char IS High ASCII
BCS .ISCLC ; Return Carry Clear
2018-01-28 18:30:49 +00:00
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
2018-01-28 18:30:49 +00:00
CMP #$09 ;If Char < '\t'
BCC .ISRTS ; Return Carry Clear
2018-01-28 18:30:49 +00:00
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
2018-01-28 18:30:49 +00:00
CMP #$61 ;Else If Char < 'a'
BCC .ISRTS ; Return Carry Clear
2018-01-28 18:30:49 +00:00
CMP #$67 ;Else If Char >= 'g'
JMP ISBCS ; Return Carry Clear Else Return Carry Set
ENDSUBROUTINE