1
0
mirror of https://github.com/KarolS/millfork.git synced 2026-04-22 00:17:03 +00:00

Add scrstring module

This commit is contained in:
Karol Stasiak
2019-10-31 17:29:05 +01:00
parent 939431aaf9
commit 2c52b98beb
7 changed files with 173 additions and 3 deletions
+61
View File
@@ -0,0 +1,61 @@
import string
#if NULLCHAR_SAME
alias scrstrzlen = strzlen
alias scrstrzcmp = strzcmp
alias scrstrzcopy = strzcopy
alias scrstrzappendchar = strzappendchar
alias scrstrz2word = strz2word
alias scrstrzappend = strzappend
#else
#if ARCH_I80
import scrstring_fastpointers
#else
import scrstring_fastindices
#endif
void scrstrzappend(pointer buffer, pointer str) {
scrstrzcopy(buffer + scrstrzlen(buffer), str)
}
void scrstrzappendchar(pointer buffer, byte char) {
buffer += scrstrzlen(buffer)
buffer[0] = char
buffer[1] = nullchar_scr
}
word scrstrz2word(pointer str) {
byte i
byte char
word next
word result
result = 0
i = 0
errno = err_ok
while true {
char = str[i]
if char == nullchar_scr {
if i == 0 {
errno = err_numberformat
}
return result
}
if '0'scr <= char <= '0'scr + 9 {
next = result * 10
next += char - '0'scr
if next < result {
errno = err_range
}
result = next
} else {
errno = err_numberformat
return result
}
i += 1
}
}
#endif
+41
View File
@@ -0,0 +1,41 @@
#if NULLCHAR_SAME
#error The module scrstring_fastindices should not be included directly
#endif
byte scrstrzlen(pointer str) {
byte index
index = 0
while str[index] != nullchar_scr {
index += 1
}
return index
}
sbyte scrstrzcmp(pointer str1, pointer str2) {
byte i1
byte i2
i1 = 0
i2 = 0
while true {
if str1[i1] != str2[i2] {
if str1[i1] < str2[i2] { return -1 }
return 1
}
if str1[i1] == nullchar_scr {
return 0
}
i1 += 1
i2 += 1
}
}
void scrstrzcopy(pointer dest, pointer src) {
byte i
byte c
i = 0
do {
c = src[i]
dest[i] = c
i += 1
} while c != nullchar_scr
}
+55
View File
@@ -0,0 +1,55 @@
#if NULLCHAR_SAME
#error The module scrstring_fastpointers should not be included directly
#endif
#pragma zilog_syntax
byte scrstrzlen(pointer str) {
pointer end
end = str
while end[0] != nullchar_scr {
end += 1
}
return lo(end - str)
}
sbyte scrstrzcmp(pointer str1, pointer str2) {
while true {
if str1[0] == nullchar_scr {
if str2[0] == nullchar_scr {
return 0
} else {
return -1
}
} else if str1[0] != str2[0] {
if str1[0] < str2[0] { return -1 }
return 1
}
str1 += 1
str2 += 1
}
}
#if CPUFEATURE_Z80 || CPUFEATURE_8080
void scrstrzcopy(pointer dest, pointer src) {
asm {
? LD HL,(src)
? LD DE,(dest)
___scrstrzcopy_loop:
LD A,(HL)
LD (DE),A
? CP nullchar_scr
? JP NZ, ___scrstrzcopy_loop
}
}
#else
void scrstrzcopy(pointer dest, pointer src) {
byte c
do {
c = src[0]
dest[0] = c
src += 1
dest += 1
} while c != nullchar_scr
}
#endif