]> Shamusworld >> Repos - virtualjaguar/blob - cdrom.cpp
d5d2b8eadf7dc327474e1cbfabaea4380544f6b3
[virtualjaguar] / cdrom.cpp
1 //
2 // CD handler
3 //
4 // by cal2
5 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
6 // Cleanups by James L. Hammons
7 //
8
9 #include "cdrom.h"
10
11 //#define CDROM_LOG
12
13 static uint8 cdrom_ram[0x100];
14 static uint16 cdrom_cmd = 0;
15
16
17 void cdrom_init(void)
18 {
19 }
20
21 void cdrom_reset(void)
22 {
23         memset(cdrom_ram, 0x00, 0x100);
24         cdrom_cmd = 0;
25 }
26
27 void cdrom_done(void)
28 {
29 }
30
31 //
32 // CD-ROM memory access functions
33 //
34
35 uint8 CDROMReadByte(uint32 offset, uint32 who/*=UNKNOWN*/)
36 {
37 #ifdef CDROM_LOG
38         WriteLog("CDROM: reading byte from 0x%.8x\n",offset);
39 #endif
40         return cdrom_ram[offset & 0xFF];
41 }
42
43 uint16 CDROMReadWord(uint32 offset, uint32 who/*=UNKNOWN*/)
44 {
45         offset &= 0xFF;
46
47         uint16 data = 0x0000;
48         
49         if (offset == 0x00) 
50                 data = 0x0000;
51         else if (offset == 0x02) 
52                 data = 0x2000;
53         else if (offset == 0x0A) 
54         {
55                 if (cdrom_cmd == 0x7001)
56                         data = cdrom_cmd;
57                 else
58                         data = 0x0400;
59         }
60         else
61                 data = (cdrom_ram[offset+0] << 8) | cdrom_ram[offset+1];
62
63 #ifdef CDROM_LOG
64         WriteLog("CDROM: reading word 0x%.4x from 0x%.8x [68k pc=0x%.8x]\n",data,offset,s68000readPC());
65 #endif
66         return data;
67 }
68
69 void CDROMWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/)
70 {
71         offset &= 0xFF;
72         cdrom_ram[offset] = data;
73
74 #ifdef CDROM_LOG
75         WriteLog("CDROM: writing byte 0x%.2x at 0x%.8x\n",data,offset);
76 #endif
77 }
78
79 void CDROMWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/)
80 {
81         offset &= 0xFF;
82         cdrom_ram[offset+0] = (data >> 8) & 0xFF;
83         cdrom_ram[offset+1] = data & 0xFF;
84                 
85         // command register
86 /*
87         if (offset==0x0A)
88         {
89                 cdrom_cmd=data;
90                 if ((data&0xff00)==0x1500)
91                 {
92                         WriteLog("CDROM: setting mode 0x%.2x\n",data&0xff);
93                         return;
94                 }
95                 if (data==0x7001)
96                 {
97                         uint32 offset=cdrom_ram[0x00];
98                         offset<<=8;
99                         offset|=cdrom_ram[0x01];
100                         offset<<=8;
101                         offset|=cdrom_ram[0x02];
102                         offset<<=8;
103                         offset|=cdrom_ram[0x03];
104
105                         uint32 size=cdrom_ram[0x04];
106                         offset<<=8;
107                         offset|=cdrom_ram[0x05];
108                         
109                         WriteLog("CDROM: READ(0x%.8x, 0x%.4x) [68k pc=0x%.8x]\n",offset,size,s68000readPC());
110                         return;
111                 }
112                 else
113                         WriteLog("CDROM: unknown command 0x%.4x\n",data);
114         }
115 */
116 #ifdef CDROM_LOG
117         WriteLog("CDROM: writing word 0x%.4x at 0x%.8x\n",data,offset);
118 #endif
119 }