1 |
/* |
/* |
2 |
* Copyright (C) 2006 Anders Gavare. All rights reserved. |
* Copyright (C) 2006-2007 Anders Gavare. All rights reserved. |
3 |
* |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: dreamcast.c,v 1.12 2006/11/02 06:47:14 debug Exp $ |
* $Id: dreamcast.c,v 1.15 2006/12/30 13:31:02 debug Exp $ |
29 |
* |
* |
30 |
* Dreamcast PROM emulation. |
* Dreamcast PROM emulation. |
31 |
* |
* |
52 |
/* The ROM FONT seems to be located just after 1MB, in a real Dreamcast: */ |
/* The ROM FONT seems to be located just after 1MB, in a real Dreamcast: */ |
53 |
#define DREAMCAST_ROMFONT_BASE 0x80100020 |
#define DREAMCAST_ROMFONT_BASE 0x80100020 |
54 |
|
|
55 |
|
static int booting_from_cdrom = 0; |
56 |
|
|
57 |
|
|
58 |
/* |
/* |
59 |
* dreamcast_romfont_init() |
* dreamcast_romfont_init() |
120 |
int i; |
int i; |
121 |
struct cpu *cpu = machine->cpus[0]; |
struct cpu *cpu = machine->cpus[0]; |
122 |
|
|
123 |
for (i=0xb0; i<=0xfc; i+=sizeof(uint32_t)) { |
for (i=0; i<0x50; i+=sizeof(uint32_t)) { |
124 |
/* Store pointer to PROM routine... */ |
/* Store pointer to PROM routine... */ |
125 |
store_32bit_word(cpu, 0x8c000000 + i, 0x8c000100 + i); |
store_32bit_word(cpu, 0x8c0000b0 + i, 0x8c000040 + i); |
126 |
|
|
127 |
/* ... which contains only 1 instruction, a special |
/* ... which contains only 1 instruction, a special |
128 |
0x00ff opcode which triggers PROM emulation: */ |
opcode which triggers PROM emulation: */ |
129 |
store_16bit_word(cpu, 0x8c000100 + i, 0x00ff); |
store_16bit_word(cpu, 0x8c000040 + i, SH_INVALID_INSTR); |
130 |
} |
} |
131 |
|
|
132 |
/* PROM reboot, in case someone jumps to 0xa0000000: */ |
/* PROM reboot, in case someone jumps to 0xa0000000: */ |
133 |
store_16bit_word(cpu, 0xa0000000, 0x00ff); |
store_16bit_word(cpu, 0xa0000000, SH_INVALID_INSTR); |
134 |
|
|
135 |
dreamcast_romfont_init(machine); |
dreamcast_romfont_init(machine); |
136 |
} |
} |
141 |
*/ |
*/ |
142 |
int dreamcast_emul(struct cpu *cpu) |
int dreamcast_emul(struct cpu *cpu) |
143 |
{ |
{ |
144 |
int addr = cpu->pc & 0xff; |
int addr = (cpu->pc & 0xff) - 0x40 + 0xb0; |
145 |
int r1 = cpu->cd.sh.r[1]; |
int r1 = cpu->cd.sh.r[1]; |
146 |
int r6 = cpu->cd.sh.r[6]; |
int r6 = cpu->cd.sh.r[6]; |
147 |
int r7 = cpu->cd.sh.r[7]; |
int r7 = cpu->cd.sh.r[7]; |
148 |
|
|
149 |
switch (addr) { |
/* Special case: Reboot */ |
150 |
|
if ((uint32_t)cpu->pc == 0xa0000000) { |
151 |
case 0x00: |
fatal("[ dreamcast reboot ]\n"); |
|
/* Special case: Reboot */ |
|
|
fatal("[ dreamcast reboot ]\n"); |
|
152 |
cpu->running = 0; |
cpu->running = 0; |
153 |
break; |
return 1; |
154 |
|
} |
155 |
|
|
156 |
|
switch (addr) { |
157 |
|
|
158 |
case 0xb0: |
case 0xb0: |
159 |
/* SYSINFO */ |
/* SYSINFO */ |
230 |
* The easiest way to support both is probably to keep track |
* The easiest way to support both is probably to keep track |
231 |
* of whether the IP.BIN code was started by the (software) |
* of whether the IP.BIN code was started by the (software) |
232 |
* ROM emulation code, or not. |
* ROM emulation code, or not. |
233 |
|
*/ |
234 |
|
if (booting_from_cdrom) { |
235 |
|
fatal("[ dreamcast: Switching to bootstrap 1 ]\n"); |
236 |
|
booting_from_cdrom = 0; |
237 |
|
cpu->pc = 0x8c00b800; |
238 |
|
return 1; |
239 |
|
} else { |
240 |
|
fatal("[ dreamcast: Returning to main menu. ]\n"); |
241 |
|
cpu->running = 0; |
242 |
|
} |
243 |
|
break; |
244 |
|
|
245 |
|
case 0xf0: |
246 |
|
/* |
247 |
|
* GXemul hack: |
248 |
* |
* |
249 |
* TODO |
* By jumping to this address (0x8c000080), a "boot from |
250 |
|
* CDROM" is simulated. Control is transfered to the license |
251 |
|
* code in the loaded IP.BIN file. |
252 |
*/ |
*/ |
253 |
fatal("[ Boot menu? TODO ]\n"); |
debug("[ dreamcast boot from CDROM ]\n"); |
254 |
goto bad; |
booting_from_cdrom = 1; |
255 |
|
cpu->pc = 0x8c008300; |
256 |
|
return 1; |
257 |
|
|
258 |
default:goto bad; |
default:goto bad; |
259 |
} |
} |
266 |
bad: |
bad: |
267 |
cpu_register_dump(cpu->machine, cpu, 1, 0); |
cpu_register_dump(cpu->machine, cpu, 1, 0); |
268 |
printf("\n"); |
printf("\n"); |
269 |
fatal("[ dreamcast_emul(): unimplemented dreamcast PROM call ]\n"); |
fatal("[ dreamcast_emul(): unimplemented dreamcast PROM call, " |
270 |
|
"pc=0x%08"PRIx32" ]\n", (uint32_t)cpu->pc); |
271 |
cpu->running = 0; |
cpu->running = 0; |
272 |
return 1; |
return 1; |
273 |
} |
} |