mirror of
https://github.com/cc65/cc65.git
synced 2024-12-27 00:29:31 +00:00
Shortened names and adjusted style.
This commit is contained in:
parent
411fe87f64
commit
0981c020b2
@ -14,15 +14,15 @@
|
||||
|
||||
; Define bitmapped constants for the table entries
|
||||
|
||||
CT_NONE = $00 ; Nothing special
|
||||
CT_LOWER = $01 ; 0 - Lower case char
|
||||
CT_UPPER = $02 ; 1 - Upper case char
|
||||
CT_DIGIT = $04 ; 2 - Numeric digit
|
||||
CT_XDIGIT = $08 ; 3 - Hex digit (both, lower and upper)
|
||||
CT_CTRL = $10 ; 4 - Control character
|
||||
CT_SPACE = $20 ; 5 - The space character itself
|
||||
CT_OTHER_WS = $40 ; 6 - Other whitespace ('\f', '\n', '\r', '\t' and '\v')
|
||||
CT_SPACE_TAB = $80 ; 7 - Space or tab character
|
||||
CT_NONE = %00000000 ; Nothing special
|
||||
CT_LOWER = %00000001 ; 0 - Lower case char
|
||||
CT_UPPER = %00000010 ; 1 - Upper case char
|
||||
CT_DIGIT = %00000100 ; 2 - Numeric digit
|
||||
CT_XDIGIT = %00001000 ; 3 - Hex digit (both, lower and upper)
|
||||
CT_CTRL = %00010000 ; 4 - Control character
|
||||
CT_SPACE = %00100000 ; 5 - The space character itself
|
||||
CT_OTHER_WS = %01000000 ; 6 - Other whitespace ('\f', '\n', '\r', '\t' and '\v')
|
||||
CT_SPACE_TAB = %10000000 ; 7 - Space or tab character
|
||||
|
||||
; Combined stuff
|
||||
CT_ALNUM = (CT_LOWER | CT_UPPER | CT_DIGIT)
|
||||
|
@ -11,13 +11,13 @@
|
||||
;
|
||||
|
||||
.include "ctypetable.inc"
|
||||
.export __ctypeIdx
|
||||
.export __ctypeidx
|
||||
|
||||
; The tables are readonly, put them into the rodata segment
|
||||
|
||||
.rodata
|
||||
|
||||
__ctypeIdx:
|
||||
__ctypeidx:
|
||||
ct_mix CT_CTRL_IDX, CT_CTRL_IDX ; 0/00 ___ctrl_@___, 1/01 ___ctrl_A___
|
||||
ct_mix CT_CTRL_IDX, CT_CTRL_IDX ; 2/02 ___ctrl_B___, 3/03 ___ctrl_C___
|
||||
ct_mix CT_CTRL_IDX, CT_CTRL_IDX ; 4/04 ___ctrl_D___, 5/05 ___ctrl_E___
|
||||
|
@ -11,13 +11,13 @@
|
||||
;
|
||||
|
||||
.include "ctypetable.inc"
|
||||
.export __ctypeIdx
|
||||
.export __ctypeidx
|
||||
|
||||
; The tables are readonly, put them into the rodata segment
|
||||
|
||||
.rodata
|
||||
|
||||
__ctypeIdx:
|
||||
__ctypeidx:
|
||||
ct_mix CT_NONE_IDX, CT_NONE_IDX ; 0/00 ___heart____, 1/01 ___l_tee____
|
||||
ct_mix CT_NONE_IDX, CT_NONE_IDX ; 2/02 ___ctrl_B___, 3/03 ___ctrl_C___
|
||||
ct_mix CT_NONE_IDX, CT_NONE_IDX ; 4/04 ___r_tee____, 5/05 ___ctrl_E___
|
||||
|
@ -11,13 +11,13 @@
|
||||
;
|
||||
|
||||
.include "ctypetable.inc"
|
||||
.export __ctypeIdx
|
||||
.export __ctypeidx
|
||||
|
||||
; The tables are readonly, put them into the rodata segment
|
||||
|
||||
.rodata
|
||||
|
||||
__ctypeIdx:
|
||||
__ctypeidx:
|
||||
ct_mix CT_CTRL_IDX, CT_CTRL_IDX ; 0/00 ___ctrl_@___, 1/01 ___ctrl_A___
|
||||
ct_mix CT_CTRL_IDX, CT_CTRL_IDX ; 2/02 ___ctrl_B___, 3/03 ___ctrl_C___
|
||||
ct_mix CT_CTRL_IDX, CT_CTRL_IDX ; 4/04 ___ctrl_D___, 5/05 ___ctrl_E___
|
||||
|
@ -12,13 +12,13 @@
|
||||
; This table is taken from Craig S. Bruce's technical docs. for the ACE OS.
|
||||
|
||||
.include "ctypetable.inc"
|
||||
.export __ctypeIdx
|
||||
.export __ctypeidx
|
||||
|
||||
; The tables are readonly, put them into the rodata segment
|
||||
|
||||
.rodata
|
||||
|
||||
__ctypeIdx:
|
||||
__ctypeidx:
|
||||
ct_mix CT_CTRL_IDX, CT_CTRL_IDX ; 0/00 ___rvs_@___, 1/01 ___rvs_a___
|
||||
ct_mix CT_CTRL_IDX, CT_CTRL_IDX ; 2/02 ___rvs_b___, 3/03 ___rvs_c___
|
||||
ct_mix CT_CTRL_IDX, CT_CTRL_IDX ; 4/04 ___rvs_d___, 5/05 ___rvs_e___
|
||||
|
@ -8,7 +8,7 @@
|
||||
.export _atoi, _atol
|
||||
.import negeax, __ctype
|
||||
.importzp sreg, ptr1, ptr2, tmp1
|
||||
.import ctype_preprocessor_no_check
|
||||
.import ctypemaskdirect
|
||||
.include "ctype.inc"
|
||||
;
|
||||
; Conversion routine (32 bit)
|
||||
@ -26,9 +26,7 @@ _atol: sta ptr1 ; store s
|
||||
; Skip whitespace
|
||||
|
||||
L1: lda (ptr1),y
|
||||
; get character classification
|
||||
jsr ctype_preprocessor_no_check
|
||||
|
||||
jsr ctypemaskdirect ; get character classification
|
||||
and #CT_SPACE_TAB ; tab or space?
|
||||
beq L2 ; jump if no
|
||||
iny
|
||||
|
@ -11,13 +11,13 @@
|
||||
;
|
||||
|
||||
.include "ctypetable.inc"
|
||||
.export __ctypeIdx
|
||||
.export __ctypeidx
|
||||
|
||||
; The tables are readonly, put them into the rodata segment
|
||||
|
||||
.rodata
|
||||
|
||||
__ctypeIdx:
|
||||
__ctypeidx:
|
||||
|
||||
.repeat 2 ; 2 times for normal and inverted
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
; ctype_preprocessor.s
|
||||
; ctypemask.s
|
||||
;
|
||||
; This file is part of
|
||||
; cc65 - a freeware C compiler for 6502 based systems
|
||||
@ -7,7 +7,7 @@
|
||||
;
|
||||
; See "LICENSE" file for legal information.
|
||||
;
|
||||
; ctype_preprocessor(int c)
|
||||
; 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.
|
||||
@ -18,18 +18,18 @@
|
||||
; while calling this function!
|
||||
;
|
||||
|
||||
.export ctype_preprocessor
|
||||
.export ctype_preprocessor_no_check
|
||||
.export ctypemask
|
||||
.export ctypemaskdirect
|
||||
.import __ctype
|
||||
.import __ctypeIdx
|
||||
.import __ctypeidx
|
||||
|
||||
ctype_preprocessor:
|
||||
ctypemask:
|
||||
cpx #$00 ; char range ok?
|
||||
bne SC ; branch if not
|
||||
ctype_preprocessor_no_check:
|
||||
ctypemaskdirect:
|
||||
lsr a
|
||||
tax
|
||||
lda __ctypeIdx,x
|
||||
lda __ctypeidx,x
|
||||
bcc @lowerNibble
|
||||
@upperNibble:
|
||||
lsr a
|
@ -12,10 +12,10 @@
|
||||
|
||||
.export _isalnum
|
||||
.include "ctype.inc"
|
||||
.import ctype_preprocessor
|
||||
.import ctypemask
|
||||
|
||||
_isalnum:
|
||||
jsr ctype_preprocessor ; (always clears X)
|
||||
jsr ctypemask ; (always clears X)
|
||||
bcs @L1 ; out of range? (everything already clear -> false)
|
||||
and #CT_ALNUM ; mask character/digit bits
|
||||
@L1: rts
|
||||
|
@ -12,10 +12,10 @@
|
||||
|
||||
.export _isalpha
|
||||
.include "ctype.inc"
|
||||
.import ctype_preprocessor
|
||||
.import ctypemask
|
||||
|
||||
_isalpha:
|
||||
jsr ctype_preprocessor ; (always clears X)
|
||||
jsr ctypemask ; (always clears X)
|
||||
bcs @L1 ; out of range? (everything already clear -> false)
|
||||
and #CT_ALPHA ; mask character bits
|
||||
@L1: rts
|
||||
|
@ -14,10 +14,10 @@
|
||||
|
||||
.export _isblank
|
||||
.include "ctype.inc"
|
||||
.import ctype_preprocessor
|
||||
.import ctypemask
|
||||
|
||||
_isblank:
|
||||
jsr ctype_preprocessor ; (always clears X)
|
||||
jsr ctypemask ; (always clears X)
|
||||
bcs @L1 ; out of range? (everything already clear -> false)
|
||||
and #CT_SPACE_TAB ; mask blank bit
|
||||
@L1: rts
|
||||
|
@ -12,10 +12,10 @@
|
||||
|
||||
.export _iscntrl
|
||||
.include "ctype.inc"
|
||||
.import ctype_preprocessor
|
||||
.import ctypemask
|
||||
|
||||
_iscntrl:
|
||||
jsr ctype_preprocessor ; (always clears X)
|
||||
jsr ctypemask ; (always clears X)
|
||||
bcs @L1 ; out of range? (everything already clear -> false)
|
||||
and #CT_CTRL ; mask control character bit
|
||||
@L1: rts
|
||||
|
@ -12,10 +12,10 @@
|
||||
|
||||
.export _isdigit
|
||||
.include "ctype.inc"
|
||||
.import ctype_preprocessor
|
||||
.import ctypemask
|
||||
|
||||
_isdigit:
|
||||
jsr ctype_preprocessor ; (always clears X)
|
||||
jsr ctypemask ; (always clears X)
|
||||
bcs @L1 ; out of range? (everything already clear -> false)
|
||||
and #CT_DIGIT ; mask digit bit
|
||||
@L1: rts
|
||||
|
@ -12,10 +12,10 @@
|
||||
|
||||
.export _isgraph
|
||||
.include "ctype.inc"
|
||||
.import ctype_preprocessor
|
||||
.import ctypemask
|
||||
|
||||
_isgraph:
|
||||
jsr ctype_preprocessor ; (always clears X)
|
||||
jsr ctypemask ; (always clears X)
|
||||
bcs @L1 ; out of range? (everything already clear -> false)
|
||||
and #CT_CTRL_SPACE ; mask character bits
|
||||
cmp #1 ; if false, then set "borrow" flag
|
||||
|
@ -12,12 +12,12 @@
|
||||
|
||||
.export _islower
|
||||
.include "ctype.inc"
|
||||
.import ctype_preprocessor
|
||||
.import ctypemask
|
||||
|
||||
_islower:
|
||||
jsr ctype_preprocessor ; (always clears X)
|
||||
bcs @L1 ; out of range? (everything already clear -> false)
|
||||
and #CT_LOWER ; mask lower char bit
|
||||
jsr ctypemask ; (always clears X)
|
||||
bcs @L1 ; out of range? (everything already clear -> false)
|
||||
and #CT_LOWER ; mask lower char bit
|
||||
@L1: rts
|
||||
|
||||
|
||||
|
@ -12,11 +12,11 @@
|
||||
|
||||
.export _isprint
|
||||
.include "ctype.inc"
|
||||
.import ctype_preprocessor
|
||||
.import ctypemask
|
||||
|
||||
_isprint:
|
||||
jsr ctype_preprocessor ; (always clears X)
|
||||
bcs @L1 ; out of range? (everything already clear -> false)
|
||||
eor #CT_CTRL ; NOT a control char
|
||||
and #CT_CTRL ; mask control char bit
|
||||
jsr ctypemask ; (always clears X)
|
||||
bcs @L1 ; out of range? (everything already clear -> false)
|
||||
eor #CT_CTRL ; NOT a control char
|
||||
and #CT_CTRL ; mask control char bit
|
||||
@L1: rts
|
||||
|
@ -12,13 +12,13 @@
|
||||
|
||||
.export _ispunct
|
||||
.include "ctype.inc"
|
||||
.import ctype_preprocessor
|
||||
.import ctypemask
|
||||
|
||||
_ispunct:
|
||||
jsr ctype_preprocessor ; (always clears X)
|
||||
bcs @L1 ; out of range? (everything already clear -> false)
|
||||
and #CT_NOT_PUNCT ; mask relevant bits
|
||||
cmp #1 ; if false, then set "borrow" flag
|
||||
jsr ctypemask ; (always clears X)
|
||||
bcs @L1 ; out of range? (everything already clear -> false)
|
||||
and #CT_NOT_PUNCT ; mask relevant bits
|
||||
cmp #1 ; if false, then set "borrow" flag
|
||||
lda #0
|
||||
sbc #0 ; invert logic (return NOT (space | control | digit | alpha))
|
||||
sbc #0 ; invert logic (return NOT (space | control | digit | alpha))
|
||||
@L1: rts
|
||||
|
@ -12,10 +12,10 @@
|
||||
|
||||
.export _isspace
|
||||
.include "ctype.inc"
|
||||
.import ctype_preprocessor
|
||||
.import ctypemask
|
||||
|
||||
_isspace:
|
||||
jsr ctype_preprocessor ; (always clears X)
|
||||
bcs @L1 ; out of range? (everything already clear -> false)
|
||||
and #(CT_SPACE | CT_OTHER_WS) ; mask space bits
|
||||
jsr ctypemask ; (always clears X)
|
||||
bcs @L1 ; out of range? (everything already clear -> false)
|
||||
and #(CT_SPACE | CT_OTHER_WS) ; mask space bits
|
||||
@L1: rts
|
||||
|
@ -12,10 +12,10 @@
|
||||
|
||||
.export _isupper
|
||||
.include "ctype.inc"
|
||||
.import ctype_preprocessor
|
||||
.import ctypemask
|
||||
|
||||
_isupper:
|
||||
jsr ctype_preprocessor ; (always clears X)
|
||||
bcs @L1 ; out of range? (everything already clear -> false)
|
||||
and #CT_UPPER ; mask upper char bit
|
||||
jsr ctypemask ; (always clears X)
|
||||
bcs @L1 ; out of range? (everything already clear -> false)
|
||||
and #CT_UPPER ; mask upper char bit
|
||||
@L1: rts
|
||||
|
@ -12,10 +12,10 @@
|
||||
|
||||
.export _isxdigit
|
||||
.include "ctype.inc"
|
||||
.import ctype_preprocessor
|
||||
.import ctypemask
|
||||
|
||||
_isxdigit:
|
||||
jsr ctype_preprocessor ; (always clears X)
|
||||
bcs @L1 ; out of range? (everything already clear -> false)
|
||||
and #CT_XDIGIT ; mask xdigit bit
|
||||
jsr ctypemask ; (always clears X)
|
||||
bcs @L1 ; out of range? (everything already clear -> false)
|
||||
and #CT_XDIGIT ; mask xdigit bit
|
||||
@L1: rts
|
||||
|
@ -14,7 +14,7 @@
|
||||
.export _stricmp, _strcasecmp
|
||||
.import popptr1
|
||||
.importzp ptr1, ptr2, tmp1, tmp2
|
||||
.import ctype_preprocessor_no_check
|
||||
.import ctypemaskdirect
|
||||
.include "ctype.inc"
|
||||
|
||||
_stricmp:
|
||||
@ -26,22 +26,20 @@ _strcasecmp:
|
||||
|
||||
loop: lda (ptr2),y ; get char from second string
|
||||
sta tmp2 ; and save it
|
||||
; get character classification
|
||||
jsr ctype_preprocessor_no_check
|
||||
jsr ctypemaskdirect ; get character classification
|
||||
and #CT_LOWER ; lower case char?
|
||||
beq L1 ; jump if no
|
||||
lda #<('A'-'a') ; make upper case char
|
||||
adc tmp2 ; ctype_preprocessor_no_check ensures carry clear!
|
||||
adc tmp2 ; ctypemaskdirect ensures carry clear!
|
||||
sta tmp2 ; remember upper case equivalent
|
||||
|
||||
L1: lda (ptr1),y ; get character from first string
|
||||
sta tmp1
|
||||
; get character classification
|
||||
jsr ctype_preprocessor_no_check
|
||||
jsr ctypemaskdirect ; get character classification
|
||||
and #CT_LOWER ; lower case char?
|
||||
beq L2 ; jump if no
|
||||
lda #<('A'-'a') ; make upper case char
|
||||
adc tmp1 ; ctype_preprocessor_no_check ensures carry clear!
|
||||
adc tmp1 ; ctypemaskdirect ensures carry clear!
|
||||
sta tmp1 ; remember upper case equivalent
|
||||
|
||||
L2: ldx tmp1
|
||||
|
@ -11,7 +11,7 @@
|
||||
.export _strlower, _strlwr
|
||||
.import popax
|
||||
.importzp ptr1, ptr2
|
||||
.import ctype_preprocessor_no_check
|
||||
.import ctypemaskdirect
|
||||
.include "ctype.inc"
|
||||
|
||||
_strlower:
|
||||
@ -24,12 +24,11 @@ _strlwr:
|
||||
|
||||
loop: lda (ptr1),y ; get character
|
||||
beq L9 ; jump if done
|
||||
; get character classification
|
||||
jsr ctype_preprocessor_no_check
|
||||
jsr ctypemaskdirect ; get character classification
|
||||
and #CT_UPPER ; upper case char?
|
||||
beq L1 ; jump if no
|
||||
lda (ptr1),y ; fetch character again
|
||||
adc #<('a'-'A') ; make lower case char (ctype_preprocessor_no_check ensures carry clear)
|
||||
adc #<('a'-'A') ; make lower case char (ctypemaskdirect ensures carry clear)
|
||||
sta (ptr1),y ; store back
|
||||
L1: iny ; next char
|
||||
bne loop
|
||||
|
@ -9,7 +9,7 @@
|
||||
.export _strnicmp, _strncasecmp
|
||||
.import popax, popptr1
|
||||
.importzp ptr1, ptr2, ptr3, tmp1, tmp2
|
||||
.import ctype_preprocessor_no_check
|
||||
.import ctypemaskdirect
|
||||
.include "ctype.inc"
|
||||
|
||||
_strnicmp:
|
||||
@ -47,22 +47,20 @@ Loop: inc ptr3
|
||||
|
||||
Comp: lda (ptr2),y
|
||||
sta tmp2 ; remember original char
|
||||
; get character classification
|
||||
jsr ctype_preprocessor_no_check
|
||||
jsr ctypemaskdirect ; get character classification
|
||||
and #CT_LOWER ; lower case char?
|
||||
beq L1 ; jump if no
|
||||
lda #<('A'-'a') ; make upper case char
|
||||
adc tmp2 ; ctype_preprocessor_no_check ensures carry clear!
|
||||
adc tmp2 ; ctypemaskdirect ensures carry clear!
|
||||
sta tmp2 ; remember upper case equivalent
|
||||
|
||||
L1: lda (ptr1),y ; get character from first string
|
||||
sta tmp1 ; remember original char
|
||||
; get character classification
|
||||
jsr ctype_preprocessor_no_check
|
||||
jsr ctypemaskdirect ; get character classification
|
||||
and #CT_LOWER ; lower case char?
|
||||
beq L2 ; jump if no
|
||||
lda #<('A'-'a') ; make upper case char
|
||||
adc tmp1 ; ctype_preprocessor_no_check ensures carry clear!
|
||||
adc tmp1 ; ctypemaskdirect ensures carry clear!
|
||||
sta tmp1 ; remember upper case equivalent
|
||||
|
||||
L2: ldx tmp1
|
||||
|
@ -11,7 +11,7 @@
|
||||
.export _strupper, _strupr
|
||||
.import popax
|
||||
.importzp ptr1, ptr2
|
||||
.import ctype_preprocessor_no_check
|
||||
.import ctypemaskdirect
|
||||
.include "ctype.inc"
|
||||
|
||||
_strupper:
|
||||
@ -24,11 +24,11 @@ _strupr:
|
||||
|
||||
loop: lda (ptr1),y ; get character
|
||||
beq L9 ; jump if done
|
||||
jsr ctype_preprocessor_no_check
|
||||
jsr ctypemaskdirect ; get character classification
|
||||
and #CT_LOWER ; lower case char?
|
||||
beq L1 ; jump if no
|
||||
lda (ptr1),y ; fetch character again
|
||||
adc #<('A'-'a') ; make upper case char (ctype_preprocessor_no_check ensures carry clear)
|
||||
adc #<('A'-'a') ; make upper case char (ctypemaskdirect ensures carry clear)
|
||||
sta (ptr1),y ; store back
|
||||
L1: iny ; next char
|
||||
bne loop
|
||||
|
@ -12,17 +12,17 @@
|
||||
|
||||
.export _tolower
|
||||
.include "ctype.inc"
|
||||
.import ctype_preprocessor_no_check
|
||||
.import ctypemaskdirect
|
||||
|
||||
_tolower:
|
||||
cpx #$00 ; out of range?
|
||||
bne @L2 ; if so, return the argument unchanged
|
||||
tay ; save char
|
||||
jsr ctype_preprocessor_no_check
|
||||
jsr ctypemaskdirect ; get character classification
|
||||
and #CT_UPPER ; upper case char?
|
||||
beq @L1 ; jump if no
|
||||
tya ; restore char
|
||||
adc #<('a'-'A') ; make lower case char (ctype_preprocessor_no_check ensures carry clear)
|
||||
adc #<('a'-'A') ; make lower case char (ctypemaskdirect ensures carry clear)
|
||||
rts
|
||||
@L1: tya ; restore char
|
||||
@L2: rts
|
||||
|
@ -12,17 +12,17 @@
|
||||
|
||||
.export _toupper
|
||||
.include "ctype.inc"
|
||||
.import ctype_preprocessor_no_check
|
||||
.import ctypemaskdirect
|
||||
|
||||
_toupper:
|
||||
cpx #$00 ; out of range?
|
||||
bne @L2 ; if so, return the argument unchanged
|
||||
tay ; save char
|
||||
jsr ctype_preprocessor_no_check
|
||||
jsr ctypemaskdirect ; get character classification
|
||||
and #CT_LOWER ; lower case char?
|
||||
beq @L1 ; jump if no
|
||||
tya ; restore char
|
||||
adc #<('A'-'a') ; make upper case char (ctype_preprocessor_no_check ensures carry clear)
|
||||
adc #<('A'-'a') ; make upper case char (ctypemaskdirect ensures carry clear)
|
||||
rts
|
||||
@L1: tya ; restore char
|
||||
@L2: rts
|
||||
|
@ -13,13 +13,13 @@
|
||||
; http://lyonlabs.org/commodore/onrequest/geos-manuals/The_Hitchhikers_Guide_to_GEOS.pdf
|
||||
|
||||
.include "ctypetable.inc"
|
||||
.export __ctypeIdx
|
||||
.export __ctypeidx
|
||||
|
||||
; The tables are readonly, put them into the rodata segment
|
||||
|
||||
.rodata
|
||||
|
||||
__ctypeIdx:
|
||||
__ctypeidx:
|
||||
ct_mix CT_CTRL_IDX, CT_CTRL_IDX ; 0/00 ____NULL___, 1/01 ____N/A____
|
||||
ct_mix CT_CTRL_IDX, CT_CTRL_IDX ; 2/02 ____N/A____, 3/03 ____N/A____
|
||||
ct_mix CT_CTRL_IDX, CT_CTRL_IDX ; 4/04 ____N/A____, 5/05 ____N/A____
|
||||
|
Loading…
Reference in New Issue
Block a user