Start work on RAM card sort
This commit is contained in:
parent
e49c2e2047
commit
6223392b9d
40
rom.68k
40
rom.68k
@ -6,6 +6,8 @@ _start:
|
||||
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 a0, a5
|
||||
move.l d0, d7
|
||||
@ -76,3 +78,41 @@ flr_done:
|
||||
rts
|
||||
fakestack:
|
||||
.long romfindret
|
||||
|
||||
| 1KB buffer in a1
|
||||
| Returns list length in d0
|
||||
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.
|
||||
farc_loop:
|
||||
lea (0x100, a0), a0 | adda.l #$100,a0 ; Move to the next card
|
||||
move.w (0xfe, a0), d1 | Load the type of the card into d1
|
||||
beq.b farc_done | If the type is 0 (empty slot), we have scanned all cards, so exit the loop
|
||||
cmp.w #0x2, d1 | If the card isn't a RAM card, skip it
|
||||
bne.b farc_loop
|
||||
move.l a0, (a1)+ | Write the IO base address into the buffer and advance the buffer pointer
|
||||
addq.b #1, d0 | Increment the count of found RAM cards
|
||||
bra.b farc_loop | Loop back and check the next card
|
||||
farc_done:
|
||||
rts
|
||||
|
||||
| Buffer in a0
|
||||
| Length in d0
|
||||
| optimized bubble sort to sort RAM cards by size
|
||||
sort_ram_cards:
|
||||
move.b #0, d1 | d1 = newlen
|
||||
move.b #1, d2 | d2 = i
|
||||
src_inner_loop:
|
||||
| todo compare sizes
|
||||
| PSEUDO: cmp snd, fst
|
||||
ble.b src_pair_sorted
|
||||
| todo swap values
|
||||
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
|
||||
move.b d1, d0 | len = newlen
|
||||
cmp #1, d0 | if n > 1, branch to outer loop
|
||||
bgt.b sort_ram_cards
|
||||
rts
|
||||
|
Loading…
Reference in New Issue
Block a user