File: ctypemask.s

package info (click to toggle)
cc65 2.19-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,268 kB
  • sloc: ansic: 117,151; asm: 66,339; pascal: 4,248; makefile: 1,009; perl: 607
file content (50 lines) | stat: -rw-r--r-- 1,255 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
; ctypemask.s
;
; This file is part of
; cc65 - a freeware C compiler for 6502 based systems
;
; https://cc65.github.io
;
; See "LICENSE" file for legal information.
;
; ctypemask(int c)
;
; 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!
;

        .export         ctypemask
        .export         ctypemaskdirect
        .import         __ctype
        .import         __ctypeidx

ctypemask:
        cpx     #$00            ; char range ok?
        bne     SC              ; branch if not
ctypemaskdirect:
        lsr     a
        tax
        lda     __ctypeidx,x
        bcc     @lowerNibble
@upperNibble:
        lsr     a
        lsr     a
        lsr     a
        lsr     a
        clc                     ; remove out of bounds flag
@lowerNibble:
        and     #%00001111
        tax
        lda     __ctype,x
        ldx     #$00
        rts

SC:     sec
        lda     #$00
        tax
        rts