Finish RAM card sort
This commit is contained in:
parent
6223392b9d
commit
5633e6154a
34
rom.68k
34
rom.68k
@ -5,12 +5,14 @@ _start:
|
||||
bra.b find_first_card
|
||||
romfindret:
|
||||
move.l a0, a6 | Save the ROM card IO base in a6 for later
|
||||
lea (0xF0, a6), a7 | Set up the stack at the end of the ROM's IO space RAM
|
||||
move.l #0x8000, a1
|
||||
bsr.w find_all_ram_cards
|
||||
bsr.b find_largest_ram | Find the largest RAM card and put the IO base in a5
|
||||
move.l #0x10000, a7 | Set up the stack at the end of the ROM card's RAM
|
||||
bsr.w find_largest_ram | Find the largest RAM card and put the IO base in a5
|
||||
move.l a0, a5
|
||||
move.l d0, d7
|
||||
move.l #0x8100, a1
|
||||
bsr.w find_all_ram_cards
|
||||
move.l #0x8100, a0
|
||||
bsr.w sort_ram_cards
|
||||
move.w #0x4, d0 | Find a storage card and put the IO base in a4
|
||||
bsr.b find_first_card
|
||||
move.l a0, a4
|
||||
@ -81,6 +83,7 @@ fakestack:
|
||||
|
||||
| 1KB buffer in a1
|
||||
| Returns list length in d0
|
||||
| Clobbers a1, d1
|
||||
find_all_ram_cards:
|
||||
move.b #0, d0 | d0 holds the number of RAM cards found.
|
||||
move.l #0xff0000, a0 | a0 holds the address of the current card.
|
||||
@ -94,24 +97,35 @@ farc_loop:
|
||||
addq.b #1, d0 | Increment the count of found RAM cards
|
||||
bra.b farc_loop | Loop back and check the next card
|
||||
farc_done:
|
||||
move.l #0, (a1) | Write a null terminator on the end of the list
|
||||
rts
|
||||
|
||||
| optimized bubble sort to sort RAM cards by size
|
||||
| Buffer in a0
|
||||
| Length in d0
|
||||
| optimized bubble sort to sort RAM cards by size
|
||||
| Clobbers d1, d2, d3, d4, a1, a2
|
||||
sort_ram_cards:
|
||||
move.b #0, d1 | d1 = newlen
|
||||
move.b #1, d2 | d2 = i
|
||||
move.l a0, a1 | a1 holds the pointer to the current pair
|
||||
src_inner_loop:
|
||||
| todo compare sizes
|
||||
| PSEUDO: cmp snd, fst
|
||||
cmp.b d0, d2 | if i >= length, exit the inner loop
|
||||
bge.b src_inner_loop_done
|
||||
move.l (a1), a2 | Read the first card's size
|
||||
move.l (0x4, a2), d3
|
||||
move.l (4, a1), a2 | Read the second card's size
|
||||
move.l (0x4, a2), d4
|
||||
cmp.l d3, d4 | if d4 <= d3, branch to src_pair_sorted
|
||||
ble.b src_pair_sorted
|
||||
| todo swap values
|
||||
move.l (a1), d3 | Read the first value
|
||||
move.l (0x4, a1), d4 | Read the second value
|
||||
move.l d3, (0x4, a1) | Write the first value where the second value was
|
||||
move.l d4, (a1)+ | Write the second value where the first value was and increment a1 for the next pair
|
||||
move.b d2, d1 | i = newlem
|
||||
src_pair_sorted:
|
||||
addq.b #1, d2 | i++
|
||||
cmp.b d0, d2 | if i < length, branch to inner loop
|
||||
blt.b src_inner_loop
|
||||
bra.b src_inner_loop
|
||||
src_inner_loop_done:
|
||||
move.b d1, d0 | len = newlen
|
||||
cmp #1, d0 | if n > 1, branch to outer loop
|
||||
bgt.b sort_ram_cards
|
||||
|
Loading…
Reference in New Issue
Block a user