Search
lxdream.org :: lxdream/src/maple/maple.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/maple/maple.h
changeset 850:28782ebbd01d
prev838:9abb2fa58934
next1034:7044e01148f0
author nkeynes
date Mon Sep 08 07:56:33 2008 +0000 (11 years ago)
permissions -rw-r--r--
last change Add lightgun support
file annotate diff log raw
nkeynes@1
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@31
     3
 *
nkeynes@31
     4
 * Maple bus definitions
nkeynes@31
     5
 *
nkeynes@31
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@31
     7
 *
nkeynes@31
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@31
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@31
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@31
    11
 * (at your option) any later version.
nkeynes@31
    12
 *
nkeynes@31
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@31
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@31
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@31
    16
 * GNU General Public License for more details.
nkeynes@1
    17
 */
nkeynes@31
    18
nkeynes@450
    19
#ifndef lxdream_maple_H
nkeynes@450
    20
#define lxdream_maple_H 1
nkeynes@1
    21
nkeynes@736
    22
#ifdef __cplusplus
nkeynes@736
    23
extern "C" {
nkeynes@736
    24
#endif
nkeynes@736
    25
nkeynes@450
    26
#include <stdint.h>
nkeynes@450
    27
#include "config.h"
nkeynes@144
    28
nkeynes@1
    29
#define MAPLE_CMD_INFO        1  /* Request device information */
nkeynes@1
    30
#define MAPLE_CMD_EXT_INFO    2  /* Request extended information */
nkeynes@1
    31
#define MAPLE_CMD_RESET       3  /* Reset device */
nkeynes@1
    32
#define MAPLE_CMD_SHUTDOWN    4  /* Shutdown device */
nkeynes@1
    33
#define MAPLE_CMD_GET_COND    9  /* Get condition */
nkeynes@1
    34
#define MAPLE_CMD_MEM_INFO    10 /* Get memory information */
nkeynes@2
    35
#define MAPLE_CMD_READ_BLOCK  11 /* Block read */
nkeynes@2
    36
#define MAPLE_CMD_WRITE_BLOCK 12 /* Block write */
nkeynes@1
    37
#define MAPLE_CMD_SET_COND    14 /* Set condition */
nkeynes@1
    38
#define MAPLE_RESP_INFO       5  /* Device information response */
nkeynes@1
    39
#define MAPLE_RESP_EXT_INFO   6  /* Extended device information response */
nkeynes@1
    40
#define MAPLE_RESP_ACK        7  /* Acknowledge command */
nkeynes@1
    41
#define MAPLE_RESP_DATA       8  /* Bytes read */
nkeynes@1
    42
#define MAPLE_ERR_NO_RESPONSE -1 /* Device did not respond */
nkeynes@1
    43
#define MAPLE_ERR_FUNC_UNSUP  -2 /* Function code unsupported */
nkeynes@1
    44
#define MAPLE_ERR_CMD_UNKNOWN -3 /* Command code unknown */
nkeynes@1
    45
#define MAPLE_ERR_RETRY       -4 /* Retry command */
nkeynes@1
    46
#define MAPLE_ERR_FILE        -5 /* File error? */
nkeynes@1
    47
nkeynes@2
    48
#define MAPLE_FUNC_CONTROLLER 0x01000000
nkeynes@2
    49
#define MAPLE_FUNC_MEMORY     0x02000000
nkeynes@2
    50
#define MAPLE_FUNC_LCD        0x04000000
nkeynes@2
    51
#define MAPLE_FUNC_CLOCK      0x08000000
nkeynes@2
    52
#define MAPLE_FUNC_MICROPHONE 0x10000000
nkeynes@2
    53
#define MAPLE_FUNC_AR_GUN     0x20000000
nkeynes@2
    54
#define MAPLE_FUNC_KEYBOARD   0x40000000
nkeynes@2
    55
#define MAPLE_FUNC_LIGHT_GUN  0x80000000
nkeynes@2
    56
#define MAPLE_FUNC_PURU_PURU  0x00010000
nkeynes@2
    57
#define MAPLE_FUNC_MOUSE      0x00020000
nkeynes@2
    58
nkeynes@838
    59
#define MAPLE_GRAB_DONTCARE   0
nkeynes@838
    60
#define MAPLE_GRAB_YES        1
nkeynes@838
    61
#define MAPLE_GRAB_NO         2
nkeynes@838
    62
    
nkeynes@2
    63
#define MAPLE_DEVICE_TAG 0x4D41504C
nkeynes@2
    64
#define MAPLE_DEVICE(x) ((maple_device_t)x)
nkeynes@2
    65
nkeynes@480
    66
typedef const struct maple_device_class *maple_device_class_t;
nkeynes@144
    67
typedef struct maple_device *maple_device_t;
nkeynes@144
    68
nkeynes@144
    69
struct maple_device_class {
nkeynes@144
    70
    const char *name;
nkeynes@144
    71
    maple_device_t (*new_device)();
nkeynes@144
    72
};
nkeynes@144
    73
nkeynes@31
    74
/**
nkeynes@31
    75
 * Table of functions to be implemented by any maple device.
nkeynes@31
    76
 */
nkeynes@144
    77
struct maple_device {
nkeynes@2
    78
    uint32_t _tag;
nkeynes@144
    79
    maple_device_class_t device_class;
nkeynes@838
    80
    int grab_mode;
nkeynes@2
    81
    unsigned char ident[112];
nkeynes@2
    82
    unsigned char version[80];
nkeynes@450
    83
    lxdream_config_entry_t (*get_config)(struct maple_device *dev);
nkeynes@770
    84
    void (*set_config_value)(struct maple_device *dev, unsigned int key, const gchar *value);
nkeynes@144
    85
    void (*attach)(struct maple_device *dev);
nkeynes@144
    86
    void (*detach)(struct maple_device *dev);
nkeynes@144
    87
    void (*destroy)(struct maple_device *dev);
nkeynes@460
    88
    struct maple_device * (*clone)(struct maple_device *dev);
nkeynes@2
    89
    int (*reset)(struct maple_device *dev);
nkeynes@2
    90
    int (*shutdown)(struct maple_device *dev);
nkeynes@2
    91
    int (*get_condition)(struct maple_device *dev,
nkeynes@502
    92
                         int function, unsigned char *outbuf, unsigned int *buflen);
nkeynes@2
    93
    int (*set_condition)(struct maple_device *dev,
nkeynes@502
    94
                         int function, unsigned char *inbuf, unsigned int buflen);
nkeynes@2
    95
    int (*read_block)(struct maple_device *dev,
nkeynes@502
    96
                      int function, uint32_t block, unsigned char *outbuf, unsigned int *buflen);
nkeynes@2
    97
    int (*write_block)(struct maple_device *dev,
nkeynes@502
    98
                       int function, uint32_t block, unsigned char *inbuf, unsigned int buflen);
nkeynes@850
    99
    void (*start_gun)(struct maple_device *dev);
nkeynes@850
   100
    void (*stop_gun)(struct maple_device *dev);
nkeynes@144
   101
};
nkeynes@2
   102
nkeynes@144
   103
extern struct maple_device_class controller_class;
nkeynes@608
   104
extern struct maple_device_class keyboard_class;
nkeynes@850
   105
extern struct maple_device_class lightgun_class;
nkeynes@608
   106
extern struct maple_device_class mouse_class;
nkeynes@144
   107
nkeynes@447
   108
maple_device_t maple_new_device( const gchar *name );
nkeynes@144
   109
maple_device_t maple_get_device( unsigned int port, unsigned int periph );
nkeynes@480
   110
const struct maple_device_class *maple_get_device_class( const gchar *name );
nkeynes@447
   111
const struct maple_device_class **maple_get_device_classes();
nkeynes@450
   112
lxdream_config_entry_t maple_get_device_config( maple_device_t dev );
nkeynes@770
   113
void maple_set_device_config_value( maple_device_t dev, unsigned int key, const gchar *value );
nkeynes@1
   114
nkeynes@1
   115
void maple_handle_buffer( uint32_t buffer );
nkeynes@2
   116
void maple_attach_device( maple_device_t dev, unsigned int port, unsigned int periph );
nkeynes@2
   117
void maple_detach_device( unsigned int port, unsigned int periph );
nkeynes@144
   118
void maple_detach_all( );
nkeynes@144
   119
void maple_reattach_all( );
nkeynes@838
   120
gboolean maple_should_grab();
nkeynes@1
   121
nkeynes@608
   122
/**
nkeynes@608
   123
 * Default destroy implementation that just frees the dev memory.
nkeynes@608
   124
 */
nkeynes@608
   125
void maple_default_destroy( maple_device_t dev );
nkeynes@608
   126
nkeynes@736
   127
#ifdef __cplusplus
nkeynes@736
   128
}
nkeynes@736
   129
#endif
nkeynes@736
   130
nkeynes@450
   131
#endif /* !lxdream_maple_H */
.