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: dev_dreamcast_maple.c,v 1.9 2006/10/31 08:27:26 debug Exp $ |
* $Id: dev_dreamcast_maple.c,v 1.14 2007/03/08 19:04:09 debug Exp $ |
29 |
* |
* |
30 |
* Dreamcast "Maple" bus controller. |
* Dreamcast "Maple" bus controller. |
31 |
* |
* |
41 |
* |
* |
42 |
* TODO: |
* TODO: |
43 |
* Unit numbers / IDs for real Maple devices. |
* Unit numbers / IDs for real Maple devices. |
44 |
|
* The Controller (up/down/left/right, buttons, etc). |
45 |
*/ |
*/ |
46 |
|
|
47 |
#include <stdio.h> |
#include <stdio.h> |
52 |
#include "console.h" |
#include "console.h" |
53 |
#include "cpu.h" |
#include "cpu.h" |
54 |
#include "device.h" |
#include "device.h" |
|
#include "devices.h" |
|
55 |
#include "machine.h" |
#include "machine.h" |
56 |
#include "memory.h" |
#include "memory.h" |
57 |
#include "misc.h" |
#include "misc.h" |
96 |
* |
* |
97 |
* TODO: Figure out strings and numbers of _real_ Maple devices. |
* TODO: Figure out strings and numbers of _real_ Maple devices. |
98 |
*/ |
*/ |
99 |
|
#if 0 |
100 |
static struct maple_device maple_device_controller = { |
static struct maple_device maple_device_controller = { |
101 |
{ |
{ |
102 |
BE32_TO_HOST(MAPLE_FUNC(MAPLE_FN_CONTROLLER)), /* di_func */ |
BE32_TO_HOST(MAPLE_FUNC(MAPLE_FN_CONTROLLER)), /* di_func */ |
109 |
LE16_TO_HOST(100) /* di_max_power */ |
LE16_TO_HOST(100) /* di_max_power */ |
110 |
} |
} |
111 |
}; |
}; |
112 |
|
#endif |
113 |
static struct maple_device maple_device_keyboard = { |
static struct maple_device maple_device_keyboard = { |
114 |
{ |
{ |
115 |
BE32_TO_HOST(MAPLE_FUNC(MAPLE_FN_KEYBOARD)),/* di_func */ |
BE32_TO_HOST(MAPLE_FUNC(MAPLE_FN_KEYBOARD)),/* di_func */ |
141 |
DEVICE_TICK(maple) |
DEVICE_TICK(maple) |
142 |
{ |
{ |
143 |
struct dreamcast_maple_data *d = (struct dreamcast_maple_data *) extra; |
struct dreamcast_maple_data *d = (struct dreamcast_maple_data *) extra; |
144 |
int control_bits, key = console_readchar(d->console_handle); |
int key; |
145 |
|
|
146 |
if (key < 0) |
while ((key = console_readchar(d->console_handle)) >= 0) { |
147 |
return; |
/* Add to the keyboard queue: */ |
148 |
|
d->char_queue[d->char_queue_head] = key; |
149 |
|
d->char_queue_head = (d->char_queue_head + 1) % MAX_CHARS; |
150 |
|
if (d->char_queue_head == d->char_queue_tail) |
151 |
|
fatal("[ dreamcast_maple: KEYBOARD QUEUE OVERRUN! ]\n"); |
152 |
|
} |
153 |
|
|
154 |
/* Add to the keyboard queue: */ |
#if 0 |
155 |
d->char_queue[d->char_queue_head] = key; |
/* |
156 |
d->char_queue_head = (d->char_queue_head + 1) % MAX_CHARS; |
* NOTE/TODO: |
157 |
if (d->char_queue_head == d->char_queue_tail) |
* |
158 |
fatal("[ dreamcast_maple: KEYBOARD QUEUE OVERRUN! ]\n"); |
* Implement the controller in a reasonable way! |
159 |
|
*/ |
160 |
|
|
161 |
control_bits = 0; |
control_bits = 0; |
162 |
switch (key) { |
switch (key) { |
214 |
fatal("[ dreamcast_maple: CONTROLLER QUEUE " |
fatal("[ dreamcast_maple: CONTROLLER QUEUE " |
215 |
"OVERRUN! ]\n"); |
"OVERRUN! ]\n"); |
216 |
} |
} |
217 |
|
#endif |
218 |
} |
} |
219 |
|
|
220 |
|
|
320 |
key = get_key(d); |
key = get_key(d); |
321 |
|
|
322 |
/* |
/* |
323 |
* buf[0] = shift keys (1 = ctrl, 2 = shift) |
* buf[0] = shift keys (1 = left ctrl, 2 = shift, 0x10 = right ctrl) |
324 |
* buf[1] = led state |
* buf[1] = led state |
325 |
* buf[2] = key |
* buf[2] = key |
326 |
*/ |
*/ |
637 |
0x5f6c00, 0x100, dev_dreamcast_maple_access, d, DM_DEFAULT, NULL); |
0x5f6c00, 0x100, dev_dreamcast_maple_access, d, DM_DEFAULT, NULL); |
638 |
|
|
639 |
/* Devices connected to port A..D: */ |
/* Devices connected to port A..D: */ |
640 |
d->device[0] = &maple_device_controller; |
d->device[0] = NULL; /* &maple_device_controller; */ |
641 |
d->device[1] = NULL; |
d->device[1] = NULL; |
642 |
d->device[2] = &maple_device_keyboard; |
d->device[2] = &maple_device_keyboard; |
643 |
d->device[3] = NULL; /* TODO: &maple_device_mouse; */ |
d->device[3] = NULL; /* TODO: &maple_device_mouse; */ |