fox32rom: Add compare_string

This commit is contained in:
Ry 2022-04-23 22:31:44 -07:00
parent bcfeac816b
commit c078c2b917
3 changed files with 39 additions and 0 deletions

View File

@ -61,6 +61,7 @@ copy_memory_words: jmp [0xF0046004]
copy_string: jmp [0xF0046008]
compare_memory_bytes: jmp [0xF004600C]
compare_memory_words: jmp [0xF0046010]
compare_string: jmp [0xF0046014]
; event types
const EVENT_TYPE_MOUSE_CLICK: 0x00000000

View File

@ -231,6 +231,7 @@ get_rom_version:
data.32 copy_string
data.32 compare_memory_bytes
data.32 compare_memory_words
data.32 compare_string
org.pad 0xF004F000
standard_font_width:

View File

@ -1,3 +1,5 @@
; string copy/compare routines
; copy string from source pointer to destination pointer
; if the source and destination overlap, the behavior is undefined
; inputs:
@ -22,3 +24,38 @@ copy_string_loop:
pop r1
pop r0
ret
; compare string from source pointer with destination pointer
; inputs:
; r0: pointer to source
; r1: pointer to destinaton
; outputs:
; Z flag
compare_string:
push r0
push r1
compare_string_loop:
; check if the strings match
cmp.8 [r0], [r1]
ifnz jmp compare_string_not_equal
; if this is the end of string 1, then this must also be the end of string 2
; the cmp above alredy ensured that both strings have a null-terminator here
cmp.8 [r0], 0
ifz jmp compare_string_equal
inc r0
inc r1
jmp compare_string_loop
compare_string_not_equal:
; Z flag is already cleared at this point
pop r1
pop r0
ret
compare_string_equal:
; set Z flag
mov r0, 0
cmp r0, 0
pop r1
pop r0
ret