57#define MAPLE_DMA_DEBUG 0
67#define MAPLE_IRQ_DEBUG 0
78#define MAPLE_BASE 0xa05f6c00
79#define MAPLE_DMAADDR (MAPLE_BASE+0x04)
80#define MAPLE_RESET2 (MAPLE_BASE+0x10)
81#define MAPLE_ENABLE (MAPLE_BASE+0x14)
82#define MAPLE_STATE (MAPLE_BASE+0x18)
83#define MAPLE_SPEED (MAPLE_BASE+0x80)
84#define MAPLE_RESET1 (MAPLE_BASE+0x8c)
96#define MAPLE_RESET2_MAGIC 0
97#define MAPLE_ENABLE_ENABLED 1
98#define MAPLE_ENABLE_DISABLED 0
99#define MAPLE_STATE_IDLE 0
100#define MAPLE_STATE_DMA 1
101#define MAPLE_SPEED_2MBPS 0
102#define MAPLE_SPEED_TIMEOUT(n) ((n) << 16)
104#ifndef _arch_sub_naomi
105#define MAPLE_RESET1_MAGIC 0x6155404f
107#define MAPLE_RESET1_MAGIC 0x6155405f
121#define MAPLE_RESPONSE_FILEERR -5
122#define MAPLE_RESPONSE_AGAIN -4
123#define MAPLE_RESPONSE_BADCMD -3
124#define MAPLE_RESPONSE_BADFUNC -2
125#define MAPLE_RESPONSE_NONE -1
126#define MAPLE_COMMAND_DEVINFO 1
127#define MAPLE_COMMAND_ALLINFO 2
128#define MAPLE_COMMAND_RESET 3
129#define MAPLE_COMMAND_KILL 4
130#define MAPLE_RESPONSE_DEVINFO 5
131#define MAPLE_RESPONSE_ALLINFO 6
132#define MAPLE_RESPONSE_OK 7
133#define MAPLE_RESPONSE_DATATRF 8
134#define MAPLE_COMMAND_GETCOND 9
135#define MAPLE_COMMAND_GETMINFO 10
136#define MAPLE_COMMAND_BREAD 11
137#define MAPLE_COMMAND_BWRITE 12
138#define MAPLE_COMMAND_BSYNC 13
139#define MAPLE_COMMAND_SETCOND 14
140#define MAPLE_COMMAND_MICCONTROL 15
141#define MAPLE_COMMAND_CAMCONTROL 17
158#define MAPLE_FUNC_PURUPURU 0x00010000
159#define MAPLE_FUNC_MOUSE 0x00020000
160#define MAPLE_FUNC_CAMERA 0x00080000
161#define MAPLE_FUNC_CONTROLLER 0x01000000
162#define MAPLE_FUNC_MEMCARD 0x02000000
163#define MAPLE_FUNC_LCD 0x04000000
164#define MAPLE_FUNC_CLOCK 0x08000000
165#define MAPLE_FUNC_MICROPHONE 0x10000000
166#define MAPLE_FUNC_ARGUN 0x20000000
167#define MAPLE_FUNC_KEYBOARD 0x40000000
168#define MAPLE_FUNC_LIGHTGUN 0x80000000
174TAILQ_HEAD(maple_frame_queue, maple_frame);
177LIST_HEAD(maple_driver_list, maple_driver);
179struct maple_state_str;
189typedef struct maple_frame {
205 void (*callback)(
struct maple_state_str *,
struct maple_frame *);
208 uint8 recv_buf_arr[1024 + 1024 + 32];
219#define MAPLE_FRAME_VACANT 0
220#define MAPLE_FRAME_UNSENT 1
221#define MAPLE_FRAME_SENT 2
222#define MAPLE_FRAME_RESPONDED 3
235typedef struct maple_devinfo {
240 char product_name[30];
241 char product_license[60];
254typedef struct maple_response {
270typedef struct maple_device {
288#define MAPLE_PORT_COUNT 4
289#define MAPLE_UNIT_COUNT 6
299typedef struct maple_port {
315typedef struct maple_driver {
333 void (*periodic)(
struct maple_driver *drv);
365typedef struct maple_state_str {
367 struct maple_driver_list driver_list;
370 struct maple_frame_queue frame_queue;
411#define MAPLE_DMA_SIZE 16384
418#define maple_read(A) ( *((vuint32*)(A)) )
423#define maple_write(A, V) ( *((vuint32*)(A)) = (V) )
431#define MAPLE_EFAIL -1
432#define MAPLE_EAGAIN -2
433#define MAPLE_EINVALID -3
434#define MAPLE_ENOTSUPP -4
435#define MAPLE_ETIMEOUT -5
597void maple_sentinel_setup(
void * buffer,
int bufsize);
606void maple_sentinel_verify(
const char * bufname,
void * buffer,
int bufsize);
880#define MAPLE_FOREACH_BEGIN(TYPE, VARTYPE, VAR) \
882 maple_device_t * __dev; \
887 while( (__dev = maple_enum_type(__i, TYPE)) ) { \
888 VAR = (VARTYPE *)maple_dev_status(__dev); \
897#define MAPLE_FOREACH_END() \
int maple_driver_unreg(maple_driver_t *driver)
Unregister a maple device driver.
int maple_driver_attach(maple_frame_t *det)
Attach a maple device to a driver, if possible.
void(* maple_detach_callback_t)(maple_device_t *dev)
Maple detach callback type.
Definition maple.h:743
int maple_gun_enable(int port)
Enable light gun mode for this frame.
void maple_dma_start(void)
Start a Maple DMA.
void maple_dma_addr(void *ptr)
Set the Maple DMA address.
void maple_gun_read_pos(int *x, int *y)
Read the light gun position values.
void maple_dma_irq_hnd(uint32 code, void *data)
Called after a Maple DMA send / receive pair completes.
int maple_driver_detach(int p, int u)
Detach an attached maple device.
const char * maple_perror(int response)
Return a string representing the maple response code.
void maple_wait_scan(void)
Wait for the initial bus scan to complete.
void maple_frame_init(maple_frame_t *frame)
Initialize a new frame to prepare it to be placed on the queue.
void maple_shutdown(void)
Shutdown Maple.
int maple_frame_lock(maple_frame_t *frame)
Lock a frame so that someone else can't use it in the mean time.
int maple_driver_reg(maple_driver_t *driver)
Register a maple device driver.
maple_device_t * maple_enum_type_ex(int n, uint32 func, uint32 cap)
Return the Nth device that is of the requested type and supports the list of capabilities given.
int maple_dev_valid(int p, int u)
Determine if a given device is valid.
int maple_enum_count(void)
Return the number of connected devices.
void maple_init(void)
Initialize Maple.
void maple_raddr(uint8 addr, int *port, int *unit)
Decompose a "maple address" into a port, unit pair.
maple_device_t * maple_enum_type(int n, uint32 func)
Get the Nth device of the requested type (where N is zero-indexed).
void maple_attach_callback(uint32 functions, maple_attach_callback_t cb)
Set an automatic maple attach callback.
void(* maple_attach_callback_t)(maple_device_t *dev)
Maple attach callback type.
Definition maple.h:722
void maple_gun_disable(void)
Disable light gun mode.
void maple_bus_disable(void)
Disable the Maple bus.
int maple_queue_frame(maple_frame_t *frame)
Submit a frame for queueing.
void maple_dma_stop(void)
Stop a Maple DMA.
const char * maple_pcaps(uint32 functions)
Return a string with the capabilities of a given function code.
void maple_detach_callback(uint32 functions, maple_detach_callback_t cb)
Set an automatic maple detach callback.
void maple_frame_unlock(maple_frame_t *frame)
Unlock a frame.
void maple_bus_enable(void)
Enable the Maple bus.
void maple_queue_flush(void)
Send all queued frames.
maple_device_t * maple_enum_dev(int p, int u)
Get a raw device info struct for the given device.
void maple_vbl_irq_hnd(uint32 code, void *data)
Called on every VBL (~60fps).
int maple_dma_in_progress(void)
Is a Maple DMA in progress?
uint8 maple_addr(int port, int unit)
Return a "maple address" for a port, unit pair.
void * maple_dev_status(maple_device_t *dev)
Get the status struct for the requested maple device.
int maple_driver_foreach(maple_driver_t *drv, int(*callback)(maple_device_t *))
For each device which the given driver controls, call the callback.
int maple_queue_remove(maple_frame_t *frame)
Remove a used frame from the queue.
typedef LIST_HEAD(nmmgr_list, nmmgr_handler) nmmgr_list_t
Name handler list type.
unsigned short uint16
16-bit unsigned integer
Definition types.h:34
unsigned long uint32
32-bit unsigned integer
Definition types.h:33
unsigned char uint8
8-bit unsigned integer
Definition types.h:35
char int8
8-bit signed integer
Definition types.h:39
#define MAPLE_PORT_COUNT
Number of ports on the bus.
Definition maple.h:288
#define MAPLE_UNIT_COUNT
Max number of units per port.
Definition maple.h:289
One maple device.
Definition maple.h:270
volatile uint8 status_valid
Have we got our first status update?
Definition maple.h:283
uint8 dev_mask
Device-present mask for unit 0's.
Definition maple.h:281
int unit
Unit number, off of the port.
Definition maple.h:273
maple_devinfo_t info
Device info struct.
Definition maple.h:274
maple_frame_t frame
One rx/tx frame.
Definition maple.h:277
int port
Maple bus port connected to.
Definition maple.h:272
uint8 probe_mask
Mask of sub-devices left to probe.
Definition maple.h:280
struct maple_driver * drv
Driver which handles this device.
Definition maple.h:278
Maple device info structure.
Definition maple.h:235
uint8 connector_direction
0: UP (most controllers), 1: DOWN (lightgun, microphones)
Definition maple.h:239
uint8 area_code
Region code.
Definition maple.h:238
uint16 max_power
Power consumption (max)
Definition maple.h:243
uint32 functions
Function codes supported.
Definition maple.h:236
uint16 standby_power
Power consumption (standby)
Definition maple.h:242
A maple device driver.
Definition maple.h:315
LIST_ENTRY(maple_driver) drv_list
Driver list handle.
const char * name
The driver name.
Definition maple.h:320
uint32 functions
One or more MAPLE_FUNCs ORed together.
Definition maple.h:319
size_t status_size
The size of the status buffer.
Definition maple.h:322
Maple frame to be queued for transport.
Definition maple.h:189
volatile int queued
Are we on the queue?
Definition maple.h:198
int cmd
Command (see Commands and Responses)
Definition maple.h:193
int dst_port
Destination port.
Definition maple.h:194
struct maple_device * dev
Does this belong to a device?
Definition maple.h:203
uint8 * recv_buf
Points into recv_buf_arr, but 32-byte aligned.
Definition maple.h:201
void * send_buf
The data which will be sent (if any)
Definition maple.h:200
int dst_unit
Destination unit.
Definition maple.h:195
TAILQ_ENTRY(maple_frame) frameq
Send queue handle.
int length
Data transfer length in 32-bit words.
Definition maple.h:196
volatile int state
Has this frame been sent / responded to?
Definition maple.h:197
Internal representation of a Maple port.
Definition maple.h:299
int port
Port ID.
Definition maple.h:300
Maple response frame structure.
Definition maple.h:254
uint8 data_len
Data length (in 32-bit words)
Definition maple.h:258
int8 response
Response.
Definition maple.h:255
uint8 dst_addr
Destination address.
Definition maple.h:256
uint8 src_addr
Source address.
Definition maple.h:257
Maple state structure.
Definition maple.h:365
uint8 * dma_buffer
DMA send buffer.
Definition maple.h:382
volatile int dma_in_progress
Is a DMA running now?
Definition maple.h:385
int vbl_handle
Our vblank handler handle.
Definition maple.h:394
volatile uint8 scan_ready_mask
Mask of ports that completed the initial scan.
Definition maple.h:391
volatile int dma_cntr
DMA interrupt counter.
Definition maple.h:376
volatile int vbl_cntr
VBlank interrupt counter.
Definition maple.h:379
int gun_x
The horizontal position of the lightgun signal.
Definition maple.h:400
uint8 detect_port_next
Next port that will be auto-detected.
Definition maple.h:388
int gun_y
The vertical position of the lightgun signal.
Definition maple.h:403
int gun_port
The port to read for lightgun status, if any.
Definition maple.h:397