1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-09 11:30:29 +00:00
cc65/libsrc/common/ctypemask.s

51 lines
1.2 KiB
ArmAsm
Raw Normal View History

2020-04-02 22:58:16 +02:00
; ctypemask.s
2020-01-02 18:57:03 +01:00
;
; This file is part of
; cc65 - a freeware C compiler for 6502 based systems
;
2020-02-02 18:21:25 +01:00
; https://cc65.github.io
2020-01-02 18:57:03 +01:00
;
; See "LICENSE" file for legal information.
;
2020-04-02 22:58:16 +02:00
; ctypemask(int c)
2020-01-02 18:57:03 +01:00
;
2022-04-17 16:06:22 +02:00
; converts a character to test via the is*-functions to the matching ctype-masks
2020-01-02 18:57:03 +01:00
; 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 22:58:16 +02:00
.export ctypemask
.export ctypemaskdirect
2020-01-02 18:57:03 +01:00
.import __ctype
2020-04-02 22:58:16 +02:00
.import __ctypeidx
2020-01-02 18:57:03 +01:00
2020-04-02 22:58:16 +02:00
ctypemask:
2020-01-02 18:57:03 +01:00
cpx #$00 ; char range ok?
bne SC ; branch if not
2020-04-02 22:58:16 +02:00
ctypemaskdirect:
2020-01-02 18:57:03 +01:00
lsr a
tax
2020-04-02 22:58:16 +02:00
lda __ctypeidx,x
2020-01-02 18:57:03 +01:00
bcc @lowerNibble
@upperNibble:
lsr a
lsr a
lsr a
lsr a
clc ; remove out of bounds flag
@lowerNibble:
2020-04-02 10:03:01 +02:00
and #%00001111
2020-01-02 18:57:03 +01:00
tax
2020-04-02 10:03:01 +02:00
lda __ctype,x
ldx #$00
2020-01-02 18:57:03 +01:00
rts
SC: sec
2020-04-02 10:03:01 +02:00
lda #$00
2020-01-02 18:57:03 +01:00
tax
rts