2020-04-02 20:58:16 +00:00
|
|
|
; ctypemask.s
|
2020-01-02 17:57:03 +00:00
|
|
|
;
|
|
|
|
; This file is part of
|
|
|
|
; cc65 - a freeware C compiler for 6502 based systems
|
|
|
|
;
|
2020-02-02 17:21:25 +00:00
|
|
|
; https://cc65.github.io
|
2020-01-02 17:57:03 +00:00
|
|
|
;
|
|
|
|
; See "LICENSE" file for legal information.
|
|
|
|
;
|
2020-04-02 20:58:16 +00:00
|
|
|
; ctypemask(int c)
|
2020-01-02 17:57:03 +00:00
|
|
|
;
|
|
|
|
; converts a character to test via the is*-functions to the matching ctype-masks
|
|
|
|
; If c is out of the 8-bit range, the function returns with carry set and accu cleared.
|
|
|
|
; Return value is in accu and x has to be always clear when returning
|
|
|
|
; (makes calling code shorter)!
|
|
|
|
;
|
|
|
|
; IMPORTANT: stricmp, strlower, strnicmp, strupper and atoi rely that Y is not changed
|
|
|
|
; while calling this function!
|
|
|
|
;
|
|
|
|
|
2020-04-02 20:58:16 +00:00
|
|
|
.export ctypemask
|
|
|
|
.export ctypemaskdirect
|
2020-01-02 17:57:03 +00:00
|
|
|
.import __ctype
|
2020-04-02 20:58:16 +00:00
|
|
|
.import __ctypeidx
|
2020-01-02 17:57:03 +00:00
|
|
|
|
2020-04-02 20:58:16 +00:00
|
|
|
ctypemask:
|
2020-01-02 17:57:03 +00:00
|
|
|
cpx #$00 ; char range ok?
|
|
|
|
bne SC ; branch if not
|
2020-04-02 20:58:16 +00:00
|
|
|
ctypemaskdirect:
|
2020-01-02 17:57:03 +00:00
|
|
|
lsr a
|
|
|
|
tax
|
2020-04-02 20:58:16 +00:00
|
|
|
lda __ctypeidx,x
|
2020-01-02 17:57:03 +00:00
|
|
|
bcc @lowerNibble
|
|
|
|
@upperNibble:
|
|
|
|
lsr a
|
|
|
|
lsr a
|
|
|
|
lsr a
|
|
|
|
lsr a
|
|
|
|
clc ; remove out of bounds flag
|
|
|
|
@lowerNibble:
|
2020-04-02 08:03:01 +00:00
|
|
|
and #%00001111
|
2020-01-02 17:57:03 +00:00
|
|
|
tax
|
2020-04-02 08:03:01 +00:00
|
|
|
lda __ctype,x
|
|
|
|
ldx #$00
|
2020-01-02 17:57:03 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
SC: sec
|
2020-04-02 08:03:01 +00:00
|
|
|
lda #$00
|
2020-01-02 17:57:03 +00:00
|
|
|
tax
|
|
|
|
rts
|