Search
lxdream.org :: lxdream/src/maple/maple.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/maple/maple.h
changeset 1072:d82e04e6d497
prev1034:7044e01148f0
author nkeynes
date Fri May 29 18:47:05 2015 +1000 (7 years ago)
permissions -rw-r--r--
last change Fix test case
view annotate diff log raw
     1 /**
     2  * $Id$
     3  *
     4  * Maple bus definitions
     5  *
     6  * Copyright (c) 2005 Nathan Keynes.
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License as published by
    10  * the Free Software Foundation; either version 2 of the License, or
    11  * (at your option) any later version.
    12  *
    13  * This program is distributed in the hope that it will be useful,
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  * GNU General Public License for more details.
    17  */
    19 #ifndef lxdream_maple_H
    20 #define lxdream_maple_H 1
    22 #ifdef __cplusplus
    23 extern "C" {
    24 #endif
    26 #include <stdint.h>
    27 #include "config.h"
    29 #define MAPLE_PORTS 4
    30 #define MAPLE_MAX_DEVICES 24 /* 1 Primary + 5 secondary per port */
    31 #define MAPLE_USER_SLOTS 2   /* Number of slots to show in configuration */
    33 /* Map devices to a single id from 0..MAPLE_MAX_DEVICES, to simplify
    34  * configuration. Port is 0..3 (A..D) representing the primary ports, and
    35  * slot is 0 for the primary, or 1..5 for for one the secondary slots.
    36  */
    37 #define MAPLE_DEVID(port,slot) ( (port)|((slot)<<2) )
    38 #define MAPLE_DEVID_PORT(id)   ((id)&0x03)
    39 #define MAPLE_DEVID_SLOT(id)   ((id)>>2)
    41 #define MAPLE_CMD_INFO        1  /* Request device information */
    42 #define MAPLE_CMD_EXT_INFO    2  /* Request extended information */
    43 #define MAPLE_CMD_RESET       3  /* Reset device */
    44 #define MAPLE_CMD_SHUTDOWN    4  /* Shutdown device */
    45 #define MAPLE_CMD_GET_COND    9  /* Get condition */
    46 #define MAPLE_CMD_MEM_INFO    10 /* Get memory information */
    47 #define MAPLE_CMD_READ_BLOCK  11 /* Block read */
    48 #define MAPLE_CMD_WRITE_BLOCK 12 /* Block write */
    49 #define MAPLE_CMD_SYNC_BLOCK  13 /* Block sync */
    50 #define MAPLE_CMD_SET_COND    14 /* Set condition */
    51 #define MAPLE_RESP_INFO       5  /* Device information response */
    52 #define MAPLE_RESP_EXT_INFO   6  /* Extended device information response */
    53 #define MAPLE_RESP_ACK        7  /* Acknowledge command */
    54 #define MAPLE_RESP_DATA       8  /* Bytes read */
    55 #define MAPLE_ERR_NO_RESPONSE -1 /* Device did not respond */
    56 #define MAPLE_ERR_FUNC_UNSUP  -2 /* Function code unsupported */
    57 #define MAPLE_ERR_CMD_UNKNOWN -3 /* Command code unknown */
    58 #define MAPLE_ERR_RETRY       -4 /* Retry command */
    59 #define MAPLE_ERR_FILE        -5 /* File error? */
    61 #define MAPLE_FUNC_CONTROLLER 0x01000000
    62 #define MAPLE_FUNC_MEMORY     0x02000000
    63 #define MAPLE_FUNC_LCD        0x04000000
    64 #define MAPLE_FUNC_CLOCK      0x08000000
    65 #define MAPLE_FUNC_MICROPHONE 0x10000000
    66 #define MAPLE_FUNC_AR_GUN     0x20000000
    67 #define MAPLE_FUNC_KEYBOARD   0x40000000
    68 #define MAPLE_FUNC_LIGHT_GUN  0x80000000
    69 #define MAPLE_FUNC_PURU_PURU  0x00010000
    70 #define MAPLE_FUNC_MOUSE      0x00020000
    72 /* Internal flags, mainly for UI consumption */
    73 #define MAPLE_GRAB_DONTCARE   0x00
    74 #define MAPLE_GRAB_YES        0x01
    75 #define MAPLE_GRAB_NO         0x02
    76 #define MAPLE_GRAB_MASK       0x03
    77 #define MAPLE_TYPE_PRIMARY    0x08  /* attaches directly to maple port */
    78 #define MAPLE_SLOTS_MASK      0xF0  /* number of slots on device (primaries only) */
    79 #define MAPLE_SLOTS_1         0x10
    80 #define MAPLE_SLOTS_2         0x20
    81 #define MAPLE_SLOTS(x)        ((((x)->flags)&MAPLE_SLOTS_MASK)>>4)
    83 #define MAPLE_DEVICE_TAG 0x4D41504C
    84 #define MAPLE_DEVICE(x) ((maple_device_t)x)
    86 /* Some convenience methods for VMU handling */
    87 #define MAPLE_IS_VMU(dev)  ((dev)->device_class == &vmu_class)
    88 #define MAPLE_IS_VMU_CLASS(clz)  ((clz) == &vmu_class)
    89 #define MAPLE_VMU_NAME(dev) (((dev)->get_config(dev))->params[0].value)
    90 #define MAPLE_SET_VMU_NAME(dev,name) lxdream_set_config_value( (dev)->get_config(dev), 0 ,(name) )
    91 #define MAPLE_VMU_HAS_NAME(d1,name) (MAPLE_VMU_NAME(d1) == NULL ? name == NULL : \
    92     name != NULL && strcmp(MAPLE_VMU_NAME(d1),name) == 0)
    93 #define MAPLE_IS_SAME_VMU(d1,d2) (MAPLE_VMU_NAME(d1) == NULL ? MAPLE_VMU_NAME(d2) == NULL : \
    94     MAPLE_VMU_NAME(d2) != NULL && strcmp(MAPLE_VMU_NAME(d1),MAPLE_VMU_NAME(d2)) == 0)
    96 typedef const struct maple_device_class *maple_device_class_t;
    97 typedef struct maple_device *maple_device_t;
    99 struct maple_device_class {
   100     const char *name;
   101     int flags;
   103     maple_device_t (*new_device)();
   104 };
   106 /**
   107  * Table of functions to be implemented by any maple device.
   108  */
   109 struct maple_device {
   110     uint32_t _tag;
   111     maple_device_class_t device_class;
   112     unsigned char ident[112];
   113     unsigned char version[80];
   114     lxdream_config_group_t (*get_config)(struct maple_device *dev);
   115     void (*attach)(struct maple_device *dev);
   116     void (*detach)(struct maple_device *dev);
   117     void (*destroy)(struct maple_device *dev);
   118     struct maple_device * (*clone)(struct maple_device *dev);
   119     int (*reset)(struct maple_device *dev);
   120     int (*shutdown)(struct maple_device *dev);
   121     int (*get_condition)(struct maple_device *dev,
   122                          int function, unsigned char *outbuf, unsigned int *buflen);
   123     int (*set_condition)(struct maple_device *dev,
   124                          int function, unsigned char *inbuf, unsigned int buflen);
   125     int (*get_memory_info)(struct maple_device *dev, int function, unsigned int partition,
   126                            unsigned char *outbuf, unsigned int *buflen);
   127     int (*read_block)(struct maple_device *dev, int function, unsigned int partition,
   128             uint32_t block, unsigned int phase, unsigned char *outbuf, unsigned int *buflen);
   129     int (*write_block)(struct maple_device *dev, int function, unsigned int partition,
   130             uint32_t block, unsigned int phase, unsigned char *inbuf, unsigned int buflen);
   131     void (*start_gun)(struct maple_device *dev);
   132     void (*stop_gun)(struct maple_device *dev);
   133 };
   135 extern struct maple_device_class controller_class;
   136 extern struct maple_device_class keyboard_class;
   137 extern struct maple_device_class lightgun_class;
   138 extern struct maple_device_class mouse_class;
   139 extern struct maple_device_class vmu_class;
   141 maple_device_t maple_new_device( const gchar *name );
   142 maple_device_t maple_get_device( unsigned int port, unsigned int periph );
   143 const struct maple_device_class *maple_get_device_class( const gchar *name );
   144 const struct maple_device_class **maple_get_device_classes();
   145 lxdream_config_group_t maple_get_device_config( maple_device_t dev );
   147 void maple_handle_buffer( uint32_t buffer );
   148 void maple_attach_device( maple_device_t dev, unsigned int port, unsigned int periph );
   149 void maple_detach_device( unsigned int port, unsigned int periph );
   150 void maple_detach_all( );
   151 void maple_reattach_all( );
   152 gboolean maple_should_grab();
   155 /**
   156  * Default destroy implementation that just frees the dev memory.
   157  */
   158 void maple_default_destroy( maple_device_t dev );
   160 #ifdef __cplusplus
   161 }
   162 #endif
   164 #endif /* !lxdream_maple_H */
.