init/cards.68k
2024-03-19 09:23:21 -05:00

52 lines
1.7 KiB
Plaintext

include syscalls.i
section .text,text
public cards_init
cards_init:
move.l #$ffff0000, d0
move.l #16, d1
move.l #$2, d2
jsr syscall_vmem_map_free_to
move.l a0, (io_space_start)
rts
; Finds the first card with the type in d0.b, and returns it's IO base address in a0, or 0 if not found
; Clobbers d1
public find_first_card
find_first_card:
move.l io_space_start, a0 ; a0 holds the address of the current card
ffc_loop:
lea ($100,a0), a0 ; Move to the next card
move.w ($fe,a0), d1 ; Load the type of the card into d1
beq.b ffc_done ; If the type is 0 (empty slot), we have scanned all cards, so exit the loop
cmp.b d0, d1 ; If the card is the type we want, return with the address in a0
beq.b ffc_done
bra.b ffc_loop ; Loop back and check the next card
ffc_done:
rts
get_all_cards:
; Gets the indexes of the cards with the specified type
; a0 is a pointer to the buffer to store the results in
; d0 is the length of the buffer in 4 byte units
; d1 is the type of card to find
move.l io_space_start, a1 ; a0 holds the address of the current card
gac_loop:
lea ($100,a1), a1 ; Move to the next card
move.w ($fe,a1), d2 ; Load the type of the card into d1
cmp.b d1, d2 ; Check whether the type of the current card is the type we want
bne.b gac_next ; Skip the card if it is not
move.l a1, (a0) ; Put the card base into the buffer
lea ($4,a0), a0 ; Move to the next buffer location
subq.w #1, d0 ; Decement the count of available buffer locations
gac_next:
cmpa.l #$ffff00, a1 ; Check if we have gone through all the cards
beq.b gac_done ; If so, return
cmpi.b #0, d0 ; Check if we have filled the buffer
beq.b gac_done ; If so, returm
bra.b gac_loop
gac_done:
rts
section .bss,bss
io_space_start: ds.l 1