mirror of
https://github.com/byteworksinc/ORCALib.git
synced 2024-09-29 17:55:17 +00:00
1 line
28 KiB
NASM
1 line
28 KiB
NASM
|
keep obj/string
case on
mcopy string.macros
****************************************************************
*
* String - String Processing Library
*
* This code implements the subroutines needed to support the
* standard C library STRING.
*
* December 1988
* Mike Westerfield
*
* Copyright 1988
* Byte Works, Inc.
*
****************************************************************
*
String start dummy routine
end
****************************************************************
*
* c2pCommon - common work buffer for c2pstr and p2cstr
*
****************************************************************
*
c2pCommon privdata
str1 ds 258
end
****************************************************************
*
* char *c2pstr(str)
* char *str;
*
* Inputs:
* str - pointer to the c string to convert
*
* Outputs:
* Returns a pointer to the p string.
*
* Notes:
* Any characters after the 255th are truncated without
* warning.
*
****************************************************************
*
c2pstr start
using c2pCommon
addr equ 1
csubroutine (4:str),4
phb
phk
plb
short I,M
ldy #0
lb1 lda [str],Y
sta str1+1,Y
beq lb2
iny
bne lb1
dey
lb2 sty str1
long I,M
lla addr,str1
plb
creturn 4:addr
end
****************************************************************
*
* makeset - create a set of characters
*
* This subroutine is called by strspn, strcspn, strpbrk and
* strrpbrk to create a set of characters.
*
* Inputs:
* set - pointer to the set of characters
*
* Outputs:
* strset - set of bytes; non-sero for chars in set
*
****************************************************************
*
makeset private
set equ 8 string set
lda set if the set is null then
ora set+2
beq lb3 return
lda #0 clear the string set
sta >strset
phb
move strset,strset+1,#255
plb
short I,M while there are chars in the set do
ldy #0
lb1 lda [set],Y
beq lb2
tax set the array element for this char
lda #1
sta >strset,X
iny endwhile
bne lb1
inc set+1
bne lb1
inc set+2
bra lb1
lb2 long I,M
lb3 rts
end
****************************************************************
*
* memchr - find a byte in memory
*
* Returns a pointer to the byte in memory
*
* Inputs:
* ptr - first byte to search
* val - byte to search for
* len - # bytes to search
*
* Outputs:
* A,X - pointer to the byte; NULL for no match
*
****************************************************************
*
memchr start
ptr equ 4 pointer to the first byte
val equ 8 byte to search for
len equ 10 # bytes to search
rtl equ 1 return address
tsc establish DP addressing
phd
tcd
short M
ldy #0
ldx len+2 scan 64K blocks
beq lb1a
lb1 lda [ptr],Y
cmp val
beq lb3
iny
bne lb1
inc ptr+2
dex
bne lb1
lb1a ldx len
beq lb2a
lb2 lda [ptr],Y scan the remaining characters
cmp val
beq lb3
iny
dex
bne lb2
lb2a long M no match found -> return NULL
ldx #0
txy
bra lb4
lb3 long M compute the length
tya
clc
adc ptr
tay
ldx ptr+2
bcc lb4
inx
lb4 lda rtl+1 remove parameters from the stack
sta len+2
lda rtl
sta len+1
pld
tsc
clc
adc #10
tcs
tya return the pointer in X-A
rtl
end
****************************************************************
*
* memcmp - memory compare
*
* Compare *s1 to *s2. If *s1 < *s2 then return -1; if they are
* equal, return 0; otherwise, return 1.
*
* Inputs:
* p1 - string to concatonate to
* p2 - string to concatonate
*
* Outputs:
* A - result
*
****************************************************************
*
memcmp start
p1 equ 4 pointer to memory area 1
p2 equ 8 pointer to memory area 2
len equ 12 length to compare
rtl equ 1 return address
tsc establish DP addressing
phd
tcd
short M
ldy #0 scan 64K chunks
ldx len+2
beq lb2
lb1 lda [p1],Y
cmp [p2],Y
bne lb4
iny
bne lb1
inc p1+2
inc p2+2
dex
bne lb1
lb2 ldx len
beq lb5
lb3 lda [p1],Y scan until the end of memory is reached
cmp [p2],Y or a difference is found
bne lb4
iny
dex
bne lb3
ldx #0 memory matches
bra lb5
lb4 blt less memory differs - set the result
ldx #1
bra lb5
less ldx #-1
lb5 long M
lda rtl r
|