58#define MAPLE_DMA_DEBUG 0
68#define MAPLE_IRQ_DEBUG 0
79#define MAPLE_BASE 0xa05f6c00
80#define MAPLE_DMAADDR (MAPLE_BASE+0x04)
81#define MAPLE_RESET2 (MAPLE_BASE+0x10)
82#define MAPLE_ENABLE (MAPLE_BASE+0x14)
83#define MAPLE_STATE (MAPLE_BASE+0x18)
84#define MAPLE_SPEED (MAPLE_BASE+0x80)
85#define MAPLE_RESET1 (MAPLE_BASE+0x8c)
97#define MAPLE_RESET2_MAGIC 0
98#define MAPLE_ENABLE_ENABLED 1
99#define MAPLE_ENABLE_DISABLED 0
100#define MAPLE_STATE_IDLE 0
101#define MAPLE_STATE_DMA 1
102#define MAPLE_SPEED_2MBPS 0
103#define MAPLE_SPEED_TIMEOUT(n) ((n) << 16)
105#ifndef _arch_sub_naomi
106#define MAPLE_RESET1_MAGIC 0x6155404f
108#define MAPLE_RESET1_MAGIC 0x6155405f
122#define MAPLE_RESPONSE_FILEERR -5
123#define MAPLE_RESPONSE_AGAIN -4
124#define MAPLE_RESPONSE_BADCMD -3
125#define MAPLE_RESPONSE_BADFUNC -2
126#define MAPLE_RESPONSE_NONE -1
127#define MAPLE_COMMAND_DEVINFO 1
128#define MAPLE_COMMAND_ALLINFO 2
129#define MAPLE_COMMAND_RESET 3
130#define MAPLE_COMMAND_KILL 4
131#define MAPLE_RESPONSE_DEVINFO 5
132#define MAPLE_RESPONSE_ALLINFO 6
133#define MAPLE_RESPONSE_OK 7
134#define MAPLE_RESPONSE_DATATRF 8
135#define MAPLE_COMMAND_GETCOND 9
136#define MAPLE_COMMAND_GETMINFO 10
137#define MAPLE_COMMAND_BREAD 11
138#define MAPLE_COMMAND_BWRITE 12
139#define MAPLE_COMMAND_BSYNC 13
140#define MAPLE_COMMAND_SETCOND 14
141#define MAPLE_COMMAND_MICCONTROL 15
142#define MAPLE_COMMAND_CAMCONTROL 17
159#define MAPLE_FUNC_PURUPURU 0x00010000
160#define MAPLE_FUNC_MOUSE 0x00020000
161#define MAPLE_FUNC_CAMERA 0x00080000
162#define MAPLE_FUNC_CONTROLLER 0x01000000
163#define MAPLE_FUNC_MEMCARD 0x02000000
164#define MAPLE_FUNC_LCD 0x04000000
165#define MAPLE_FUNC_CLOCK 0x08000000
166#define MAPLE_FUNC_MICROPHONE 0x10000000
167#define MAPLE_FUNC_ARGUN 0x20000000
168#define MAPLE_FUNC_KEYBOARD 0x40000000
169#define MAPLE_FUNC_LIGHTGUN 0x80000000
175TAILQ_HEAD(maple_frame_queue, maple_frame);
178LIST_HEAD(maple_driver_list, maple_driver);
180struct maple_state_str;
190typedef struct maple_frame {
206 void (*callback)(
struct maple_state_str *,
struct maple_frame *);
209 uint8 recv_buf_arr[1024 + 1024 + 32];
220#define MAPLE_FRAME_VACANT 0
221#define MAPLE_FRAME_UNSENT 1
222#define MAPLE_FRAME_SENT 2
223#define MAPLE_FRAME_RESPONDED 3
236typedef struct maple_devinfo {
241 char product_name[30];
242 char product_license[60];
255typedef struct maple_response {
271typedef struct maple_device {
290#define MAPLE_PORT_COUNT 4
291#define MAPLE_UNIT_COUNT 6
301typedef struct maple_port {
317typedef struct maple_driver {
335 void (*periodic)(
struct maple_driver *drv);
367typedef struct maple_state_str {
369 struct maple_driver_list driver_list;
372 struct maple_frame_queue frame_queue;
413#define MAPLE_DMA_SIZE 16384
420#define maple_read(A) ( *((vuint32*)(A)) )
425#define maple_write(A, V) ( *((vuint32*)(A)) = (V) )
433#define MAPLE_EFAIL -1
434#define MAPLE_EAGAIN -2
435#define MAPLE_EINVALID -3
436#define MAPLE_ENOTSUPP -4
437#define MAPLE_ETIMEOUT -5
599void maple_sentinel_setup(
void * buffer,
int bufsize);
608void maple_sentinel_verify(
const char * bufname,
void * buffer,
int bufsize);
883#define MAPLE_FOREACH_BEGIN(TYPE, VARTYPE, VAR) \
885 maple_device_t * __dev; \
890 while( (__dev = maple_enum_type(__i, TYPE)) ) { \
891 VAR = (VARTYPE *)maple_dev_status(__dev); \
900#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:746
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:725
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:290
#define MAPLE_UNIT_COUNT
Max number of units per port.
Definition maple.h:291
One maple device.
Definition maple.h:271
volatile uint8 status_valid
Have we got our first status update?
Definition maple.h:285
void * status
Status buffer (for pollable devices)
Definition maple.h:287
uint8 dev_mask
Device-present mask for unit 0's.
Definition maple.h:283
int unit
Unit number, off of the port.
Definition maple.h:275
maple_devinfo_t info
Device info struct.
Definition maple.h:276
maple_frame_t frame
One rx/tx frame.
Definition maple.h:279
int port
Maple bus port connected to.
Definition maple.h:274
uint8 probe_mask
Mask of sub-devices left to probe.
Definition maple.h:282
bool valid
Is this a valid device?
Definition maple.h:273
struct maple_driver * drv
Driver which handles this device.
Definition maple.h:280
Maple device info structure.
Definition maple.h:236
uint8 connector_direction
0: UP (most controllers), 1: DOWN (lightgun, microphones)
Definition maple.h:240
uint8 area_code
Region code.
Definition maple.h:239
uint16 max_power
Power consumption (max)
Definition maple.h:244
uint32 functions
Function codes supported.
Definition maple.h:237
uint16 standby_power
Power consumption (standby)
Definition maple.h:243
A maple device driver.
Definition maple.h:317
LIST_ENTRY(maple_driver) drv_list
Driver list handle.
const char * name
The driver name.
Definition maple.h:322
uint32 functions
One or more MAPLE_FUNCs ORed together.
Definition maple.h:321
size_t status_size
The size of the status buffer.
Definition maple.h:324
Maple frame to be queued for transport.
Definition maple.h:190
volatile int queued
Are we on the queue?
Definition maple.h:199
int cmd
Command (see Commands and Responses)
Definition maple.h:194
int dst_port
Destination port.
Definition maple.h:195
struct maple_device * dev
Does this belong to a device?
Definition maple.h:204
uint8 * recv_buf
Points into recv_buf_arr, but 32-byte aligned.
Definition maple.h:202
void * send_buf
The data which will be sent (if any)
Definition maple.h:201
int dst_unit
Destination unit.
Definition maple.h:196
TAILQ_ENTRY(maple_frame) frameq
Send queue handle.
int length
Data transfer length in 32-bit words.
Definition maple.h:197
volatile int state
Has this frame been sent / responded to?
Definition maple.h:198
Internal representation of a Maple port.
Definition maple.h:301
int port
Port ID.
Definition maple.h:302
Maple response frame structure.
Definition maple.h:255
uint8 data_len
Data length (in 32-bit words)
Definition maple.h:259
int8 response
Response.
Definition maple.h:256
uint8 dst_addr
Destination address.
Definition maple.h:257
uint8 src_addr
Source address.
Definition maple.h:258
Maple state structure.
Definition maple.h:367
uint8 * dma_buffer
DMA send buffer.
Definition maple.h:384
volatile int dma_in_progress
Is a DMA running now?
Definition maple.h:387
int vbl_handle
Our vblank handler handle.
Definition maple.h:396
volatile uint8 scan_ready_mask
Mask of ports that completed the initial scan.
Definition maple.h:393
volatile int dma_cntr
DMA interrupt counter.
Definition maple.h:378
volatile int vbl_cntr
VBlank interrupt counter.
Definition maple.h:381
int gun_x
The horizontal position of the lightgun signal.
Definition maple.h:402
uint8 detect_port_next
Next port that will be auto-detected.
Definition maple.h:390
int gun_y
The vertical position of the lightgun signal.
Definition maple.h:405
int gun_port
The port to read for lightgun status, if any.
Definition maple.h:399