Start implementing Joypad
This commit is contained in:
parent
8731b45567
commit
a86523e03d
|
@ -24,6 +24,15 @@ GBTimers *gb_timers_open(RIO *io);
|
||||||
void gb_timers_close(RIO *io, GBTimers *timers);
|
void gb_timers_close(RIO *io, GBTimers *timers);
|
||||||
void gb_timers_update(GBTimers *timers, ut32 cycles);
|
void gb_timers_update(GBTimers *timers, ut32 cycles);
|
||||||
|
|
||||||
|
typedef struct gb_joypad_t {
|
||||||
|
ut8 *keys;
|
||||||
|
int fd;
|
||||||
|
ut8 data;
|
||||||
|
ut8 odata;
|
||||||
|
} GBJoypad;
|
||||||
|
|
||||||
|
GBJoypad *gb_joypad_open(RIO *io)
|
||||||
|
|
||||||
//int gb_mbc1_open(RIO *io, char *path);
|
//int gb_mbc1_open(RIO *io, char *path);
|
||||||
|
|
||||||
extern RIOPlugin r_io_plugin_gb_timers;
|
extern RIOPlugin r_io_plugin_gb_timers;
|
||||||
|
|
77
io/joypad.c
Normal file
77
io/joypad.c
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <gb.h>
|
||||||
|
#include <r_io.h>
|
||||||
|
#include <r_util.h>
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
|
static bool __check(RIO *io, const char *pathname, bool many) {
|
||||||
|
return r_str_startswith (pathname, "gb_joypad://");
|
||||||
|
}
|
||||||
|
|
||||||
|
static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
|
||||||
|
if (!r_str_startswith (pathname, "gb_joypad://")) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
GBJoypad *joypad = NULL;
|
||||||
|
sscanf (pathname, "gb_joybad://%p", &joypad);
|
||||||
|
RIODesc *desc = r_io_desc_new (io, &r_io_plugin_gb_joypad, pathname,
|
||||||
|
R_PERM_RWX, mode, timers);
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int __read(RIO *io, RIODesc *desc, ut8 *buf, int len) {
|
||||||
|
GBJoypad *joypad = (GBJoypad *)desc->data;
|
||||||
|
if (!len || (joypad->odata & 0x10)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
joypad->data = buf[0] & 0xf;
|
||||||
|
joypad->odata |= 0x10;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int __write(RIO *io, RIODesc *desc, const ut8 *buf, int len) {
|
||||||
|
GBJoypad *joypad = (GBJoypad *)desc->data;
|
||||||
|
if (!len || (joypad->odata & 0x10)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
joypad->odata |= 0x10;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool __close(RIODesc *desc) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
RIOPlugin r_io_plugin_gb_joypad = {
|
||||||
|
.meta = {
|
||||||
|
.name = "gb_joypad",
|
||||||
|
.desc = "gb_joypad",
|
||||||
|
.license = "LGPL",
|
||||||
|
},
|
||||||
|
.uris = "gb_joypad://",
|
||||||
|
.open = __open,
|
||||||
|
.close = __close,
|
||||||
|
.read = __read,
|
||||||
|
.check = __check,
|
||||||
|
.seek = __lseek,
|
||||||
|
.write = __write,
|
||||||
|
};
|
||||||
|
|
||||||
|
GBJoypad *gb_joypad_open (RIO *io) {
|
||||||
|
joypad = R_NEW0 (GBJoypad);
|
||||||
|
if (!joypad) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
char uri[64];
|
||||||
|
memset (uri, 0x00, sizeof (char) * 64);
|
||||||
|
sprintf (uri, "gb_joypad://%p", joypad);
|
||||||
|
RIODesc *desc = r_io_desc_open_plugin (io, &r_io_plugin_gb_joypad,
|
||||||
|
uri, R_PERM_RWX, 0);
|
||||||
|
if (!desc) {
|
||||||
|
free (joypad);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
joypad->fd = desc->fd;
|
||||||
|
joypad->keys = SDL_GetKeyboardState (NULL);
|
||||||
|
return joypad;
|
||||||
|
}
|
|
@ -38,9 +38,6 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
|
||||||
sscanf (pathname, "gb_timers://%p", &timers);
|
sscanf (pathname, "gb_timers://%p", &timers);
|
||||||
RIODesc *desc = r_io_desc_new (io, &r_io_plugin_gb_timers, pathname,
|
RIODesc *desc = r_io_desc_new (io, &r_io_plugin_gb_timers, pathname,
|
||||||
R_PERM_RWX, mode, timers);
|
R_PERM_RWX, mode, timers);
|
||||||
if (!desc) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user