cdrom_exploration.txt (13470B)
1 -------------------------------------------------------------------------- 2 Quick CDrom explanation... 2000/doomed 3 4 There's a *LOT* missing here, and the other half might be incorrect, so 5 i won't take any responsibility for strange stuff happening. It should 6 give you some pointers in the right direction for your own CD explorations 7 though. More might follow at some later time.. 8 -------------------------------------------------------------------------- 9 CDREG0 = $1f801800 10 CDREG1 = $1f801801 11 CDREG2 = $1f801802 12 CDREG3 = $1f801803 13 -------------------------------------------------------------------------- 14 CDREG0 write : 0 - to send a command 15 1 - to get the result 16 read : I/O status? 17 bit 0- 0 REG1 command send 18 - 1 REG1 data read 19 bit 1- 0 data transfer finished 20 1 data transfer ready/in progress 21 bit 7- 1 command being processed. 22 23 CDREG1 write : command 24 read : results 25 26 CDREG2 write : send arguments 27 write : 7 = flush arg buffer? 28 29 CDREG3 write : 7 = flush irq 30 read : hi nibble: ? 31 low nibble: interrupt status 32 -------------------------------------------------------------------------- 33 Modes for SetMode: 34 M_Speed bit 7 0: normal speed 1: double speed 35 M_Strsnd bit 6 0: ADPCM off 1: ADPCM on 36 M_Size bit 5 0: 2048 byte 1: 2340 byte 37 M_Size2 bit 4 0: - 1: 2328 byte 38 M_SF bit 3 0: Channel off 1: Channel on 39 M_Report bit 2 0: Report off 1: Report on 40 M_AutoPause bit 1 0: AutoPause off 1: AutoPause on 41 M_CDDA bit 0 0: CD-DA off 1: CD-DA on 42 43 These modes can be set using the setmode command. 44 -------------------------------------------------------------------------- 45 Status bits: 46 Play bit 7 playing CD-DA 47 Seek bit 6 seeking 48 Read bit 5 reading data sectors 49 ShellOpen bit 4 once shell open 50 SeekError bit 3 seek error detected 51 Standby bit 2 spindle motor rotating 52 Error bit 1 command error detected 53 54 These are the bit values for the status byte recieved from CD commands. 55 -------------------------------------------------------------------------- 56 Interrupt values: 57 NoIntr $00 No interrupt 58 DataReady $01 Data Ready 59 Acknowledge $02 Command Complete 60 Complete $03 Acknowledge 61 DataEnd $04 End of Data Detected 62 DiskError $05 Error Detected 63 64 These are returned in the low nibble of CDREG3. First write a 1 to CDREG0 65 before reading CDREG3. When a command is completed it returns 3. 66 To acknowledge an irq value after you've handled it, write a 1 to CDREG0 67 then a 7 to both CDREG2 and CDREG3. Another interrupt may be queued, so 68 you should check CDREG3 again if 0 or if there's another interrupt to 69 be handled. 70 -------------------------------------------------------------------------- 71 Sync $00 - status 72 Nop $01 - status 73 Setloc $02 min,sec,sector status 74 Play $03 B - status 75 Forward $04 B - status 76 Backward $05 B - status 77 ReadN $06 B - status 78 Standby $07 B - status 79 Stop $08 B - status 80 Pause $09 B - status 81 Init $0a - status 82 Mute $0b - status 83 Demute $0c - status 84 Setfilter $0d file,channel status 85 Setmode $0e mode status 86 Getparam $0f - status,mode,file?,chan?,?,? 87 GetlocL $10 - min,sec,sector,mode,file,channel 88 GetlocP $11 - track,index,min,sec,frame,amin, 89 asec,aframe 90 GetTN $13 - status,first,total (BCD) 91 GetTD $14 track(BCD) status,min,sec (BCD) 92 SeekL $15 B * status 93 SeekP $16 B * status 94 Test $19 # depends on parameter 95 ID $1A B - success,flag1,flag2,00 96 4 letters of ID (SCEx) 97 ReadS $1B B - status 98 Reset $1C - status 99 ReadTOC $1E B? - status 100 101 * These commands' targets are set using Setloc. 102 # Command 19 is really a portal to another set of commands. 103 104 B means blocking. These commands return an immediate result saying the 105 command was started, but you need to wait for an IRQ in order to get 106 real results. 107 108 Command descriptions: 109 00 Sync: Command does not succeed until all other commands complete. 110 This can be used for synchronization - hence the name. 111 01 Nop: Does nothing; use this if you just want the status. 112 02 Setloc: This command, with its parameters, sets the target for 113 commands with a * for their parameter list. 114 03 Play: Plays audio sectors from the last point seeked. This is 115 almost identical to CdlReadS, believe it or not. The main 116 difference is that this does not trigger a completed read 117 IRQ. CdlPlay may be used on data sectors. However, all 118 sectors from data tracks are treated as 00, so no sound is 119 played. As CdlPlay is reading, the audio data appears in 120 the sector buffer, but is not reliable. Game Shark 121 "enhancement CDs" for the 2.x and 3.x versions used this 122 to get around the PSX copy protection. 123 04 Forward: Seek to next track ? 124 05 Backward: Seek to beginning of current track, or previous track if 125 early in current track (like a CD player's back button) 126 06 ReadN: Read with retry. Each sector causes an IRQ (type 1) if 127 ModeRept is on (I think). ReadN and ReadS cause errors if 128 you're trying to read a non-PSX CD or audio CD without a 129 mod chip. 130 07 Standby: CD-ROM aborts all reads and playing, but continues 131 spinning. CD-ROM does not attempt to keep its place. 132 08 Stop: Stops motor. Official way to restart is 0A, but almost 133 any command will restart it. 134 09 Pause: Like Standby, except the point is to maintain the current 135 location within reasonable error. 136 0A Init: Multiple effects at once. Setmode = 00, Standby, abort 137 all commands. 138 0B Mute: Turn off CDDA stream to SPU. 139 0C Demute: Turn on CDDA streaming to SPU. 140 0D Setfilter: Automatic ADPCM (CD-ROM XA) filter ignores sectors except 141 those which have the same channel and file (parameters) 142 in their subheader area. This is the mechanism used to 143 select which of multiple songs in a single XA to play. 144 Setfilter does not affect actual reading (sector reads 145 still occur for all sectors). 146 0E Setmode: Sets parameters such as read mode and spin speed. See 147 chart above the command list. 148 0F Getparam: ??? returns status, mode, file, channel, ?, ? 149 10 GetlocL: Retrieves first 6 (8?) bytes of last read sector (header) 150 This is used to know where the sector came from, but is 151 generally pointless in 2340 byte read mode. All results 152 are in BCD ($12 is considered track twelve, not eighteen) 153 Command may execute concurrently with a read or play 154 (GetlocL returns results immediately). 155 11 GetlocP: Retrieves 8 of 12 bytes of sub-Q data for the last-read 156 sector. Same purpose as GetlocL, but more powerful, and 157 works while playing audio. All results are in BCD. 158 track: track number ($AA for lead-out area) 159 index: index number (INDEX lines in CUE sheets) 160 min: minute number within track 161 sec: second number within track 162 frame: sector number within "sec" (0 to 74) 163 amin: minute number on entire disk 164 asec: second number on entire disk 165 aframe: sector number within "asec" (0 to 74) 166 13 GetTN: Get first track number and number of tracks in the TOC. 167 14 GetTD: Gets start of specified track (does it return sector??) 168 15 SeekL: Seek to Setloc's location in data mode (can only seek to 169 data sectors, but is accurate to the sector) 170 16 SeekP: Seek to Setloc's location in audio mode (can seek to 171 any sector, but is only accurate to the second) 172 19 Test: This function has many subcommands that are completely 173 different. 174 1A ID: Returns copy protection status. StatError for invalid 175 data CD, StatStandby for valid PSX CD or audio CD. The 176 following bits I'm unsure about, but I think the 3rd 177 byte has $80 bit for "CD denied" and $10 bit for 178 "import". $80 = copy, $90 = denied import, $10 = 179 accepted import (Yaroze only). The 5th through 8th 180 bytes are the SCEx ASCII string from the CD. 181 1B ReadS: Read without automatic retry. 182 1C Reset: Same as opening and closing the drive door. 183 1E ReadTOC: Reread the Table of Contents without reset. 184 185 ----------------------------------------------------------------------- 186 -------------------------------------------------------------------------- 187 To send a command: 188 189 - First send any arguments by writing 0 to CDREG0, then all arguments 190 sequentially to CDREG2 191 192 - Then write 0 to CDREG0, and the command to CDREG1. 193 194 To wait for a command to complete: 195 196 - Wait until a CDrom irq occurs (bit 3 of the interrupt regs) The cause 197 of the cdrom irq is in the low nibble of CDREG3. This is usually 3 198 on a succesful comletion. Failure to complete the command will result 199 in a 5. If you don't wish to use irq's you can just check for the 200 low nibble of cdreg3 to become something other than 0, but make sure 201 it doesn't get cleared in any irq setup by the bios or some such. 202 203 To Get the results 204 205 - Write a 1 to CDREG0, then read CDREG0, If bit 5 is set, read a return 206 value from CDREG1, then read CDREG0 again repeat until bit 5 goes low. 207 208 To Clear the irq 209 210 - After command completion the irq cause should be cleared, do this by 211 writing a 1 to CDREG0 then 7 to CDREG2 and CDREG3. My guess is that 212 the write to CDREG2 clears the arguments previously set from some 213 buffer. 214 Note that irq's are queued, and if you clear the current, another may 215 come up directly.. 216 -------------------------------------------------------------------------- 217 To init the CD: 218 219 -Flush all irq's 220 -CDREG0=0 221 -CDREG3=0 222 -Com_Delay=4901 ($1f801020) 223 -Send 2 NOP's 224 -Command $0a, no args. (<- what's this??) 225 -Demute 226 -------------------------------------------------------------------------- 227 To set up the cd for audio playback, some weird init stuff needs to be 228 done: 229 230 CDREG0=2 231 CDREG2=$80 232 CDREG3=0 233 CDREG0=3 234 CDREG1=$80 235 CDREG2=0 236 CDREG3=$20 237 238 Also don't forget to init the SPU. (CDvol and CD enable especially) 239 -------------------------------------------------------------------------- 240 You should not send some commands while the CD is seeking. (ie. status 241 returns with bit 6 set.) Thing is that the status only gets updated after 242 a new command. I haven't tested this for other command, but for the 243 play command ($03) you can just keep repeating the command and checking 244 the status returned by that, for bit 6 to go low(and bit 7 to go high in 245 this case) If you don't and try to do a getloc directly after the play 246 command reports it's done, the cd will stop. (I guess the cd can't 247 get it's current location while it's seeking, so the logic stops the seek 248 to get an exact fix, but never restarts..) 249 250 251 ----------------------------------------------------------------------- 252 19 subcommands. 253 ----------------------------------------------------------------------- 254 255 For one reason or another, there is a counter that counts the number of 256 SCEx strings received by the CD-ROM controller. 257 258 Be aware that the results for these commands can exceed 8 bytes. 259 260 04: Read SCEx counter (returned in 1st byte?) 261 05: Reset SCEx counter. This also sets 1A's SCEx response to 262 00 00 00 00, but doesn't appear to force a protection failure. 263 20: Returns an ASCII string specifying where the CD-ROM firmware is 264 intended to be used ("for Japan", "for U/C"). 265 22: Returns a chip number inside the PSX in use. 266 23: Returns another chip number. 267 24: Returns yet another chip number. Same as 22's on some PSXs. 268 269 -------------------------------------------------------------------------- 270 3/nov/1999 Initial version 271 3/feb/2000 Update. Big thanks to Barubary, who rewrote a large part. 272 -------------------------------------------------------------------------- 273 psx.padua.org www.padua.org doomed@c64.org 274 --------------------------------------------------------------------------