Rivet
Member
- Messages
- 26
Recently I've been getting back into programming for the Sega CD and I figured I should ask some questions I missed last time before I continue
What's going on with PRG-RAM?
I can't seem to find details on what's in PRG-RAM and where. I know the SP is in there as well as the Sub-CPU's vector table but I don't know where they all are and what else is in there. I was able to find this map in the BIOS manual but it still leaves me somewhat confused.
What about the Main-CPU?
I'm guessing that it's just loaded to the top of Main-CPU RAM. I know the Main-CPUs vector table is at $FFFFFD00 onward. Is there anything else I should worry about?
And to finish off!
I've been using a base that Luke Usher made (https://github.com/LukeUsher/ProjectCD) and in his SP he has a few routines to load files and initialize things. He uses BIOS_ROMREADN to retrieve the data and has a label at the bottom named SectorBuffer and says not to put any code past there. I'm confused what's going on with his code, and does that mean I have to avoid putting stuff 2kb past that label in PRG-RAM? Here's the code if anyone can help:
Any help is appreciated!
What's going on with PRG-RAM?
I can't seem to find details on what's in PRG-RAM and where. I know the SP is in there as well as the Sub-CPU's vector table but I don't know where they all are and what else is in there. I was able to find this map in the BIOS manual but it still leaves me somewhat confused.
What about the Main-CPU?
I'm guessing that it's just loaded to the top of Main-CPU RAM. I know the Main-CPUs vector table is at $FFFFFD00 onward. Is there anything else I should worry about?
And to finish off!
I've been using a base that Luke Usher made (https://github.com/LukeUsher/ProjectCD) and in his SP he has a few routines to load files and initialize things. He uses BIOS_ROMREADN to retrieve the data and has a label at the bottom named SectorBuffer and says not to put any code past there. I'm confused what's going on with his code, and does that mean I have to avoid putting stuff 2kb past that label in PRG-RAM? Here's the code if anyone can help:
Code:
; =======================================================================================
; ReadCD
; Input: d0.l start sector
; d1.l sectors to read
; a0.l destination
; =======================================================================================
ReadCD:
push d0-d7/a0-a6 ; Store all registers
lea BiosPacket(pc), a5 ; Load bios packet
move.l d0, (a5) ; Write start sector to packet
move.l d1, 4(a5) ; Write size to packet
move.l a0, 8(a5) ; Write destination to packet
movea.l a5, a0 ; Put packet to a0 (for BIOS)
BIOS_CDCSTOP ; Stop CDC
BIOS_ROMREADN ; Begin data read
@waitSTAT:
BIOS_CDCSTAT ; Check CDC status
bcs @waitSTAT ; If not ready, branch
@waitREAD:
BIOS_CDCREAD ; Read data
bcc @waitREAD ; If not done, branch
@WaitTransfer:
movea.l 8(a5), a0 ; Get destination address
lea 12(a5), a1 ; Get header
BIOS_CDCTRN ; Transfer sector
bcc @waitTransfer ; If not done, branch
BIOS_CDCACK ; Acknowledge transfer
addq.l #1, (a5) ; Increment starting sector
addi.l #$0800, 8(a5) ; Increment destination address
subq.l #1, 4(a5) ; Decrement sectors left
bne @waitSTAT ; If not finished, branch
pop d0-d7/a0-a6 ; Restore all registers
rts ; Return
; =======================================================================================
; BiosPacket
; Stores paramaters for BIOS calls
; =======================================================================================
BiosPacket:
dc.l 0, 0, 0, 0, 0
Header:
ds.l 32
; =======================================================================================
; ISO9660 Driver
; =======================================================================================
Init9660:
push d0-d7/a0-a6 ; Store all registers
; Load Volume VolumeDescriptor
move.l #$10, d0 ; Start Sector
move.l #2, d1 ; Size in sector
lea.l SectorBuffer, a0 ; Destination
bsr ReadCD ; Read Data
; Load Root Directory
lea.l SectorBuffer,a0 ; Get pointer to sector buffer
lea.l 156(a0),a1 ; Get root directory record
move.b 6(a1),d0 ; Get first part of Sector address
lsl.l #8,d0 ; bitshift
move.b 7(a1),d0 ; Get next part of sector address
lsl.l #8,d0 ; bitshift
move.b 8(a1),d0 ; get next part of sector address
lsl.l #8,d0 ; bitshift
move.b 9(a1),d0 ; get final part of sector address.
; d0 now contains start sector address
move.l #$20, d1 ; Size ($20 Sectors)
bsr ReadCD
pop d0-d7/a0-a6 ; Restore all registers
rts
; =======================================================================================
; Find File (ISO9660)
; Input: a0.l - Pointer to filename
; Output: d0.l - Start sector
; d1.l - Filesize
; =======================================================================================
FindFile:
push a1/a2/a6 ; Store used registers
lea.l SectorBuffer,a1 ; Get sector buffer
@ReadFilenameStart:
movea.l a0,a6 ; Store filename pointer
move.b (a6)+,d0 ; Read character from filename
@findFirstChar:
movea.l a1,a2 ; Store Sector buffer pointer
cmp.b (a1)+,d0 ; Compare with first letter of filename and increment
bne.b @findFirstChar ; If not matched, branch
@checkChars:
move.b (a6)+,d0 ; Read next charactor of filename and increment
beq @getInfo ; If all characters were matched, branch
cmp.b (a1)+,d0 ; Else, check next character
bne.b @ReadFilenameStart ; If not matched, find next file
bra.b @checkChars ; else, check next character
@getInfo:
sub.l #33,a2 ; Move to beginning of directory entry
move.b 6(a2),d0 ; Get first part of Sector address
lsl.l #8,d0 ; bitshift
move.b 7(a2),d0 ; Get next part of sector address
lsl.l #8,d0 ; bitshift
move.b 8(a2),d0 ; get next part of sector address
lsl.l #8,d0 ; bitshift
move.b 9(a2),d0 ; get final part of sector address.
; d0 now contains start sector address
move.b 14(a2),d1 ; Same as above, but for FileSize
lsl.l #8,d1
move.b 15(a2),d1
lsl.l #8,d1
move.b 16(a2),d1
lsl.l #8,d1
move.b 17(a2),d1
lsr.l #8,d1 ; Bitshift filesize (to get sector count)
lsr.l #3,d1
pop a1/a2/a6 ; Restore used registers
rts
; =======================================================================================
; ANY CODE PAST THIS POINT WILL BE OVERWRITTEN AT RUNTIME AND IS USED AS A READ BUFFER
; Any and all additions to this Sub-Program must be added BEFORE the definition of this
; memory area
; =======================================================================================
SectorBuffer:
dc.l 0
Any help is appreciated!