diff --git a/fox32rom.def b/fox32rom.def index 43b5754..d1f7a1e 100644 --- a/fox32rom.def +++ b/fox32rom.def @@ -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 diff --git a/main.asm b/main.asm index 4a216c3..246c5ab 100644 --- a/main.asm +++ b/main.asm @@ -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: diff --git a/string.asm b/string.asm index bef50a2..ba6c476 100644 --- a/string.asm +++ b/string.asm @@ -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