Hey people,
I'm working on a test unit for KnightOS (test_sort) which tests the in-place sort function. The thing is, test units are ran from ROM, so I need to copy the string to sort in RAM before the actual sort. I'm pretty sure the problem isn't in any of the routines I call but in my own code.
Code:
Here's how I use each routine of this code :
Any idea ?
I'm working on a test unit for KnightOS (test_sort) which tests the in-place sort function. The thing is, test units are ran from ROM, so I need to copy the string to sort in RAM before the actual sort. I'm pretty sure the problem isn't in any of the routines I call but in my own code.
Code:
; sort 000E
.macro assert(input, payloadSize, expected)
in a, (6)
push af
xor a
out (6), a
ld bc, payloadSize
call malloc
push ix \ pop de \ push de
ld hl, input
ld bc, payloadSize
ldir
pop hl \ push hl
ld de, payloadSize - 1
add hl, de
pop de \ push de
ex de, hl
call radixSort
pop hl \ push hl
ld de, expected
call compareStrings
jr z, $ + 6
ld e, 1
jr $ + 4
ld e, 0
pop ix
call free
pop af
out (6), a
xor a
or e
jr nz, .fail
.endmacro
test_sort:
assert(.test1, 5, .expected1)
assert(.test2, 8, .expected2)
assert(.test3, 10, .expected3)
assert(.test4, 2, .expected4)
assert_pass()
.fail:
assert_fail()
.undefine assert
.test1:
.db 7, 4, 8, 6, 0
.expected1:
.db 4, 5, 7, 8, 0
.test2:
.db 7, 6, 5, 4, 3, 2, 1, 0
.expected2:
.db 1, 2, 3, 4, 5, 6, 7, 0
.test3:
.db 4, 5, 7, 10, 15, 17, 18, 22, 25, 0
.expected3:
.db 4, 5, 7, 10, 15, 17, 18, 22, 25, 0
.test4:
.db 7, 0
.expected4:
.db 7, 0
Here's how I use each routine of this code :
- malloc gets the number of bytes to allocate in BC and returns the allocated memory in IX.
- radixSort gets the start of the data to sort in HL and its last element in DE. This is an in-place sort.
- compareStrings gets two strings in HL and DE to compare. Z = strings equal.
- assert_pass() and assert_fail() are macros, but they never execute from what I saw on the output.
- free frees the memory whose first byte is pointed to by IX.
Any idea ?