63 #define N_MAPLE_PORTS 4 65 #define MAX_CHARS 8192 66 #define MAX_CONTROLLER_DATA 4096 68 #define MAPLE_TICK_SHIFT 17 103 "Dreamcast Controller",
104 "di_product_license",
116 "di_product_license",
128 "di_product_license",
145 fatal(
"[ dreamcast_maple: KEYBOARD QUEUE OVERRUN! ]\n");
156 int control_bits = 0;
160 control_bits = 0x0004;
164 control_bits = 0x0002;
168 control_bits = 0x0001;
172 control_bits = 0x0800;
177 control_bits = 0x0400;
181 control_bits = 0x0200;
185 control_bits = 0x0100;
190 control_bits = 0x0008;
194 control_bits = 0x0010;
198 control_bits = 0x0020;
202 control_bits = 0x0040;
206 control_bits = 0x0080;
210 if (control_bits != 0) {
216 fatal(
"[ dreamcast_maple: CONTROLLER QUEUE " 253 struct cpu *
cpu,
int port, uint32_t receive_addr)
256 uint32_t response_code, transfer_code;
260 (((port << 6) | 0x20) << 16) |
264 cpu->
memory_rw(cpu, cpu->
mem, receive_addr, (
unsigned char *) (
void *) &transfer_code,
269 cpu->
memory_rw(cpu, cpu->
mem, receive_addr, (
unsigned char *) (
void *) &response_code,
274 c = ~get_controller(d);
289 buf[4] = buf[5] = buf[6] = buf[7] = 128;
291 cpu->
memory_rw(cpu, cpu->
mem, receive_addr, (
unsigned char *) (
void *) &buf, 8,
303 struct cpu *cpu,
int port, uint32_t receive_addr)
307 uint32_t response_code, transfer_code;
310 (((port << 6) | 0x20) << 16) |
314 cpu->
memory_rw(cpu, cpu->
mem, receive_addr, (
unsigned char *) (
void *) &transfer_code,
319 cpu->
memory_rw(cpu, cpu->
mem, receive_addr, (
unsigned char *) (
void *) &response_code,
332 if (key >=
'a' && key <=
'z') buf[2] = 4 + key -
'a';
333 if (key >=
'A' && key <=
'Z') buf[0] = 2, buf[2] = 4 + key -
'A';
334 if (key >= 1 && key <= 26) buf[0] = 1, buf[2] = 4 + key - 1;
335 if (key >=
'1' && key <=
'9') buf[2] = 0x1e + key -
'1';
336 if (key ==
'!') buf[0] = 2, buf[2] = 0x1e;
337 if (key ==
'"') buf[0] = 2, buf[2] = 0x1f;
338 if (key ==
'#') buf[0] = 2, buf[2] = 0x20;
339 if (key ==
'$') buf[0] = 2, buf[2] = 0x21;
340 if (key ==
'%') buf[0] = 2, buf[2] = 0x22;
341 if (key ==
'^') buf[0] = 2, buf[2] = 0x23;
342 if (key ==
'&') buf[0] = 2, buf[2] = 0x24;
343 if (key ==
'*') buf[0] = 2, buf[2] = 0x25;
344 if (key ==
'(') buf[0] = 2, buf[2] = 0x26;
345 if (key ==
'@') buf[0] = 2, buf[2] = 0x1f;
346 if (key ==
'\n' || key ==
'\r') buf[0] = 0, buf[2] = 0x28;
347 if (key ==
')') buf[0] = 2, buf[2] = 0x27;
348 if (key ==
'\b') buf[0] = 0, buf[2] = 0x2a;
349 if (key ==
'\t') buf[0] = 0, buf[2] = 0x2b;
350 if (key ==
' ') buf[0] = 0, buf[2] = 0x2c;
351 if (key ==
'0') buf[2] = 0x27;
352 if (key == 27) buf[2] = 0x29;
353 if (key ==
'-') buf[2] = 0x2d;
354 if (key ==
'=') buf[2] = 0x2e;
355 if (key ==
'[') buf[2] = 0x2f;
356 if (key ==
'\\') buf[2] = 0x31;
357 if (key ==
'|') buf[2] = 0x31, buf[0] = 2;
358 if (key ==
']') buf[2] = 0x32;
359 if (key ==
';') buf[2] = 0x33;
360 if (key ==
':') buf[2] = 0x34;
361 if (key ==
',') buf[2] = 0x36;
362 if (key ==
'.') buf[2] = 0x37;
363 if (key ==
'/') buf[2] = 0x38;
364 if (key ==
'<') buf[2] = 0x36, buf[0] = 2;
365 if (key ==
'>') buf[2] = 0x37, buf[0] = 2;
366 if (key ==
'?') buf[2] = 0x38, buf[0] = 2;
367 if (key ==
'+') buf[2] = 0x57;
369 cpu->
memory_rw(cpu, cpu->
mem, receive_addr, (
unsigned char *) (
void *) &buf, 8,
385 debug(
"[ maple_do_dma_xfer: not enabled? ]\n");
397 fatal(
"[ dreamcast_maple: dmaaddr 0x%08" PRIx32
" is NOT" 398 " 32-byte aligned; aborting ]\n", addr);
410 uint32_t receive_addr, response_code,
cond;
411 int datalen, port, last_message,
cmd, to, from, datalen_cmd;
420 datalen = buf[0] *
sizeof(uint32_t);
422 fatal(
"[ dreamcast_maple: TODO: GUN bit. ]\n");
429 last_message = buf[3] & 0x80;
430 receive_addr = buf[4] + (buf[5] << 8) + (buf[6] << 16)
433 if (receive_addr & 0xe000001f)
434 fatal(
"[ dreamcast_maple: WARNING! receive address 0x" 435 "%08" PRIx32
" isn't valid! ]\n", receive_addr);
445 datalen_cmd = buf[3];
451 case 0x20: unit = 0;
break;
452 case 0x01: unit = 1;
break;
453 case 0x02: unit = 2;
break;
454 case 0x04: unit = 3;
break;
455 case 0x08: unit = 4;
break;
456 case 0x10: unit = 5;
break;
457 default:
fatal(
"[ dreamcast_maple: ERROR! multiple " 458 "units? Not yet implemented. to = 0x%02x ]\n", to);
472 if (d->
device[port] == NULL || unit != 0) {
476 response_code = (uint32_t) -1;
479 (
unsigned char *) (
void *) &response_code, 4,
MEM_WRITE,
489 (((port << 6) | 0x20) << 8) |
490 ((port << 6) << 16) |
492 sizeof(uint32_t)) << 24);
495 (
unsigned char *) (
void *) &response_code, 4,
MEM_WRITE,
499 receive_addr + 4 + i, (
unsigned 506 cpu->
memory_rw(cpu, cpu->
mem, addr, (
unsigned char *) (
void *) &buf, 4,
508 cond = buf[3] + (buf[2] << 8) + (buf[1] << 16)
511 maple_getcond_controller_response(
512 d, cpu, port, receive_addr);
514 maple_getcond_keyboard_response(
515 d, cpu, port, receive_addr);
517 fatal(
"[ dreamcast_maple: WARNING: GETCOND: " 518 "UNIMPLEMENTED 0x%08" PRIx32
" ]\n", cond);
524 fatal(
"[ dreamcast_maple: BWRITE: TODO ]\n");
527 default:
fatal(
"[ dreamcast_maple: command %i: TODO ]\n", cmd);
531 addr += datalen_cmd * 4;
549 uint64_t idata = 0, odata = 0;
554 switch (relative_addr) {
562 fatal(
"[ dreamcast_maple: TODO: read from dmaaddr ]\n");
569 if (writeflag ==
MEM_WRITE && idata != 0)
570 fatal(
"[ dreamcast_maple: UNIMPLEMENTED reset2 value" 571 " 0x%08x ]\n", (
int)idata);
587 default:
fatal(
"[ dreamcast_maple: UNIMPLEMENTED " 588 "state value %i ]\n", (
int)idata);
598 d->
timeout = (idata >> 16) & 0xffff;
601 debug(
"[ dreamcast_maple: timeout set to %i ]\n",
610 if (idata != 0x6155404f && idata != 0x61557f00)
611 fatal(
"[ dreamcast_maple: UNIMPLEMENTED reset " 612 "value 0x%08x ]\n", (
int)idata);
621 fatal(
"[ dreamcast_maple: UNIMPLEMENTED 0xe8 " 622 "value 0x%08x ]\n", (
int)idata);
627 default:
if (writeflag ==
MEM_READ) {
628 fatal(
"[ dreamcast_maple: UNIMPLEMENTED read from " 629 "addr 0x%x ]\n", (
int)relative_addr);
631 fatal(
"[ dreamcast_maple: UNIMPLEMENTED write to addr " 632 "0x%x: 0x%x ]\n", (
int)relative_addr, (
int)idata);
651 0x5f6c00, 0x100, dev_dreamcast_maple_access, d,
DM_DEFAULT, NULL);
#define MAPLE_FN_KEYBOARD
uint64_t memory_readmax64(struct cpu *cpu, unsigned char *buf, int len)
void fatal(const char *fmt,...)
int console_start_slave_inputonly(struct machine *machine, const char *consolename, int use_for_input)
void maple_do_dma_xfer(struct cpu *cpu, struct dreamcast_maple_data *d)
#define MAPLE_RESPONSE_DATATRF
#define SYSASIC_EVENT_MAPLE_DMADONE
int console_readchar(int handle)
#define SYSASIC_TRIGGER_EVENT(e)
#define MAX_CONTROLLER_DATA
struct maple_device maple_device_mouse
#define CHECK_ALLOCATION(ptr)
uint8_t char_queue[MAX_CHARS]
int(* memory_rw)(struct cpu *cpu, struct memory *mem, uint64_t vaddr, unsigned char *data, size_t len, int writeflag, int cache_flags)
DEVICE_ACCESS(dreamcast_maple)
struct maple_device maple_device_keyboard
int controller_queue_head
#define MAPLE_COMMAND_BWRITE
int controller_queue_tail
void memory_writemax64(struct cpu *cpu, unsigned char *buf, int len, uint64_t data)
struct maple_device * device[N_MAPLE_PORTS]
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)
#define MAPLE_COMMAND_DEVINFO
uint16_t controller_queue[MAX_CONTROLLER_DATA]
#define MAPLE_FN_CONTROLLER
void machine_add_tickfunction(struct machine *machine, void(*func)(struct cpu *, void *), void *extra, int clockshift)
struct maple_device maple_device_controller
struct maple_devinfo devinfo
#define MAPLE_RESPONSE_DEVINFO
#define MAPLE_COMMAND_GETCOND