51 #define NREGS_GDROM_DMA (0x100/sizeof(uint32_t)) 73 #define GDROM_BUSY 0x18 74 #define GDROM_DATA 0x80 75 #define GDROM_REGX 0x84 76 #define GDROM_UNKNOWN_0x88 0x88 77 #define GDROM_STAT 0x8c 78 #define GDROM_CNTLO 0x90 79 #define GDROM_CNTHI 0x94 80 #define GDROM_COND 0x9c 83 #define COND_DATA_AVAIL 0x08 97 int64_t sector_nr, sector_count;
100 debug(
"[ GDROM cmd: ");
120 fatal(
"GDROM Read TOC not 408 bytes?\n");
138 d->
data[0*4+3] = 0x96;
142 d->
data[1*4+2] = 0x2e;
143 d->
data[1*4+3] = 0x4c;
145 d->
data[99*4] = 0x01;
146 d->
data[99*4+1] = 0x01;
150 d->
data[100*4] = 0x41;
151 d->
data[100*4+1] = 0x02;
152 d->
data[100*4+2] = 0;
153 d->
data[100*4+3] = 0;
155 d->
data[101*4] = 0x61;
156 d->
data[101*4+1] = 0;
157 d->
data[101*4+2] = 0xe6;
158 d->
data[101*4+3] = 0x41;
168 if (d->
cmd[1] == 0x24) {
169 fatal(
"GDROM unimplemented data format 0x%02x. Continuing anway.\n", d->
cmd[1]);
170 }
else if (d->
cmd[1] != 0x20) {
171 fatal(
"GDROM unimplemented data format 0x%02x\n",
175 sector_nr = d->
cmd[2] * 65536 + d->
cmd[3] * 256 + d->
cmd[4];
176 sector_count = d->
cmd[8] * 65536 + d->
cmd[9] * 256 + d->
cmd[10];
184 d->
cnt = 2048 * sector_count;
186 if (sector_count * 2048 != d->
cnt) {
187 fatal(
"Huh? GDROM data_len=0x%x, but sector_count" 188 "=0x%x\n", (
int)d->
cnt, (
int)sector_count);
218 fatal(
"GDROM: diskimage_access failed? TODO\n");
242 default:
fatal(
"GDROM handle_command: unimplemented command 0x%02x" 249 if (d->
data != NULL) {
280 uint64_t idata = 0, odata = 0;
285 switch (relative_addr) {
298 if (len !=
sizeof(uint16_t)) {
299 fatal(
"Non-16bit GDROM data access? TODO\n");
305 fatal(
"Read from GDROM_DATA when no data" 306 " is available? TODO\n");
313 d->
cur_cnt +=
sizeof(uint16_t);
325 fatal(
"Read too much from GDROM_DATA\n");
329 if (d->
busy & 0x08) {
331 fatal(
"Too much GDROM_DATA?\n");
339 handle_command(cpu, d);
342 fatal(
"Write to GDROM_DATA, but not waiting" 351 debug(
"[ Read to GDROM_REGX? ]\n");
355 debug(
"[ Write 0x%x to GDROM_REGX? ]\n", (
int)idata);
361 fatal(
"Read from GDROM_UNKNOWN_0x88?\n");
365 fatal(
"[ Write to GDROM_UNKNOWN_0x88: TODO ]\n");
376 fatal(
"[ Write to GDROM_STAT? ]\n");
383 odata = d->
cnt & 0xff;
385 d->
cnt = (d->
cnt & 0xff00) | (idata & 0xff);
391 odata = (d->
cnt >> 8) & 0xff;
393 d->
cnt = (d->
cnt & 0x00ff) | ((idata & 0xff) << 8);
420 }
else if (idata == 0xef) {
421 debug(
"dreamcast_gdrom: ROM: TODO\n");
424 fatal(
"dreamcast_gdrom: unimplemented " 425 "GDROM_COND = 0x%02x\n", (
int)idata);
431 default:
if (writeflag ==
MEM_READ) {
432 fatal(
"[ dreamcast_gdrom: read from addr 0x%x ]\n",
435 fatal(
"[ dreamcast_gdrom: write to addr 0x%x: 0x%x ]\n",
436 (
int)relative_addr, (
int)idata);
452 uint64_t idata = 0, odata = 0;
459 odata = d->
dma_reg[relative_addr /
sizeof(uint32_t)];
461 switch (relative_addr) {
472 if (d->
dma_reg[0x0c /
sizeof(uint32_t)] == 1 &&
473 d->
dma_reg[0x14 /
sizeof(uint32_t)] == 1) {
475 uint32_t dst = d->
dma_reg[0x04 /
sizeof(uint32_t)];
476 int length = d->
dma_reg[0x08 /
sizeof(uint32_t)];
477 fatal(
"[ dreamcast_gdrom_dma: Transfering %i bytes to 0x%08" PRIx32
" ]\n", length, dst);
479 if (d->
data == NULL) {
480 fatal(
"dreamcast_gdrom_dma: DMA transfer but d->data is NULL. TODO\n");
492 fatal(
"Unimplemented GDROM DMA start? TODO\n");
493 fatal(
" %08x\n", (
int) d->
dma_reg[4 /
sizeof(uint32_t)]);
494 fatal(
" %08x\n", (
int) d->
dma_reg[8 /
sizeof(uint32_t)]);
495 fatal(
" %08x\n", (
int) d->
dma_reg[0xc /
sizeof(uint32_t)]);
496 fatal(
" %08x\n", (
int) d->
dma_reg[0x14 /
sizeof(uint32_t)]);
502 default:
if (writeflag ==
MEM_READ) {
503 fatal(
"[ dreamcast_gdrom_dma: read from addr 0x%x ]\n",
506 fatal(
"[ dreamcast_gdrom_dma: write to addr 0x%x: " 507 "0x%x ]\n", (
int)relative_addr, (
int)idata);
515 d->
dma_reg[relative_addr /
sizeof(uint32_t)] = idata;
532 0x005f7000, 0x100, dev_dreamcast_gdrom_access, d,
536 0x80, dev_dreamcast_gdrom_dma_access, d,
DM_DEFAULT, NULL);
uint64_t memory_readmax64(struct cpu *cpu, unsigned char *buf, int len)
void fatal(const char *fmt,...)
int diskimage_exist(struct machine *machine, int id, int type)
#define SYSASIC_EVENT_GDROM
DEVICE_ACCESS(dreamcast_gdrom)
#define SYSASIC_TRIGGER_EVENT(e)
#define CHECK_ALLOCATION(ptr)
int(* memory_rw)(struct cpu *cpu, struct memory *mem, uint64_t vaddr, unsigned char *data, size_t len, int writeflag, int cache_flags)
uint32_t dma_reg[NREGS_GDROM_DMA]
void dreamcast_gdrom_update_stat(struct cpu *cpu, struct dreamcast_gdrom_data *d)
int64_t diskimage_get_baseoffset(struct machine *machine, int id, int type)
#define GDROM_UNKNOWN_0x88
void memory_writemax64(struct cpu *cpu, unsigned char *buf, int len, uint64_t data)
void memory_device_register(struct memory *mem, const char *, uint64_t baseaddr, uint64_t len, int(*f)(struct cpu *, struct memory *, uint64_t, unsigned char *, size_t, int, void *), void *extra, int flags, unsigned char *dyntrans_data)
int diskimage_access(struct machine *machine, int id, int type, int writeflag, off_t offset, unsigned char *buf, size_t len)
#define SYSASIC_EVENT_GDROM_DMA