2022-03-19 00:20:01 +00:00
|
|
|
; Internal library routines - always included by the compiler
|
|
|
|
|
2022-03-27 13:23:32 +00:00
|
|
|
%import textio
|
|
|
|
|
2022-03-19 00:20:01 +00:00
|
|
|
prog8_lib {
|
2022-03-21 20:19:32 +00:00
|
|
|
%option force_output
|
2022-03-19 00:20:01 +00:00
|
|
|
|
2022-03-27 13:23:32 +00:00
|
|
|
sub string_contains(ubyte needle, str haystack) -> ubyte {
|
2022-03-27 19:59:46 +00:00
|
|
|
repeat {
|
|
|
|
if @(haystack)==0
|
|
|
|
return false
|
|
|
|
if @(haystack)==needle
|
|
|
|
return true
|
|
|
|
haystack++
|
|
|
|
}
|
2022-03-27 13:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub bytearray_contains(ubyte needle, uword haystack_ptr, ubyte num_elements) -> ubyte {
|
2022-03-27 19:59:46 +00:00
|
|
|
haystack_ptr--
|
|
|
|
while num_elements {
|
|
|
|
if haystack_ptr[num_elements]==needle
|
|
|
|
return true
|
|
|
|
num_elements--
|
|
|
|
}
|
|
|
|
return false
|
2022-03-27 13:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub wordarray_contains(ubyte needle, uword haystack_ptr, ubyte num_elements) -> ubyte {
|
2022-03-27 19:59:46 +00:00
|
|
|
haystack_ptr += (num_elements-1) * 2
|
|
|
|
while num_elements {
|
|
|
|
if peekw(haystack_ptr)==needle
|
|
|
|
return true
|
|
|
|
haystack_ptr -= 2
|
|
|
|
num_elements--
|
|
|
|
}
|
|
|
|
return false
|
2022-03-27 13:23:32 +00:00
|
|
|
}
|
2022-05-13 21:10:13 +00:00
|
|
|
|
|
|
|
sub string_compare(str st1, str st2) -> byte {
|
|
|
|
; Compares two strings for sorting.
|
|
|
|
; Returns -1 (255), 0 or 1 depending on wether string1 sorts before, equal or after string2.
|
|
|
|
; Note that you can also directly compare strings and string values with eachother using
|
|
|
|
; comparison operators ==, < etcetera (it will use strcmp for you under water automatically).
|
|
|
|
%asm {{
|
|
|
|
loadm.w r0, {prog8_lib.string_compare.st1}
|
|
|
|
loadm.w r1, {prog8_lib.string_compare.st2}
|
|
|
|
syscall 29
|
|
|
|
return
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2022-03-19 00:20:01 +00:00
|
|
|
}
|
2022-05-13 21:10:13 +00:00
|
|
|
|