]> Shamusworld >> Repos - virtualjaguar/blob - src/cdrom.cpp
This commit was generated by cvs2svn to compensate for changes in r8,
[virtualjaguar] / src / 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 void cdrom_byte_write(uint32 offset, uint8 data)
32 {
33         offset &= 0xFF;
34         cdrom_ram[offset] = data;
35
36 #ifdef CDROM_LOG
37         fprintf(log_get(),"cdrom: writing byte 0x%.2x at 0x%.8x\n",data,offset);
38 #endif
39 }
40
41 void cdrom_word_write(uint32 offset, uint16 data)
42 {
43         offset &= 0xFF;
44         cdrom_ram[offset+0] = (data >> 8) & 0xFF;
45         cdrom_ram[offset+1] = data & 0xFF;
46                 
47         // command register
48 /*
49         if (offset==0x0A)
50         {
51                 cdrom_cmd=data;
52                 if ((data&0xff00)==0x1500)
53                 {
54                         fprintf(log_get(),"cdrom: setting mode 0x%.2x\n",data&0xff);
55                         return;
56                 }
57                 if (data==0x7001)
58                 {
59                         uint32 offset=cdrom_ram[0x00];
60                         offset<<=8;
61                         offset|=cdrom_ram[0x01];
62                         offset<<=8;
63                         offset|=cdrom_ram[0x02];
64                         offset<<=8;
65                         offset|=cdrom_ram[0x03];
66
67                         uint32 size=cdrom_ram[0x04];
68                         offset<<=8;
69                         offset|=cdrom_ram[0x05];
70                         
71                         fprintf(log_get(),"cdrom: READ(0x%.8x, 0x%.4x) [68k pc=0x%.8x]\n",offset,size,s68000readPC());
72                         return;
73                 }
74                 else
75                         fprintf(log_get(),"cdrom: unknown command 0x%.4x\n",data);
76         }
77 */
78 #ifdef CDROM_LOG
79         fprintf(log_get(),"cdrom: writing word 0x%.4x at 0x%.8x\n",data,offset);
80 #endif
81 }
82
83 uint8 cdrom_byte_read(uint32 offset)
84 {
85 #ifdef CDROM_LOG
86         fprintf(log_get(),"cdrom: reading byte from 0x%.8x\n",offset);
87 #endif
88         return cdrom_ram[offset & 0xFF];
89 }
90
91 uint16 cdrom_word_read(uint32 offset)
92 {
93         offset &= 0xFF;
94
95         uint16 data = 0x0000;
96         
97         if (offset == 0x00) 
98                 data = 0x0000;
99         else if (offset == 0x02) 
100                 data = 0x2000;
101         else if (offset == 0x0A) 
102         {
103                 if (cdrom_cmd == 0x7001)
104                         data = cdrom_cmd;
105                 else
106                         data = 0x0400;
107         }
108         else
109                 data = (cdrom_ram[offset+0] << 8) | cdrom_ram[offset+1];
110
111 #ifdef CDROM_LOG
112         fprintf(log_get(),"cdrom: reading word 0x%.4x from 0x%.8x [68k pc=0x%.8x]\n",data,offset,s68000readPC());
113 #endif
114         return data;
115 }