mirror of
https://github.com/n64dev/cen64.git
synced 2024-06-22 22:12:45 -04:00
Add some preliminary input support.
This commit is contained in:
parent
ee44e46abb
commit
0d15bd9ddc
2
device.h
2
device.h
|
@ -24,6 +24,7 @@
|
|||
#define PIFROM_SIZE 2048
|
||||
|
||||
struct cen64_device {
|
||||
struct vr4300 vr4300;
|
||||
struct bus_controller bus;
|
||||
|
||||
struct ai_controller ai;
|
||||
|
@ -34,7 +35,6 @@ struct cen64_device {
|
|||
|
||||
struct rdp rdp;
|
||||
struct rsp rsp;
|
||||
struct vr4300 vr4300;
|
||||
|
||||
// Dynamic memory.
|
||||
uint8_t *ram;
|
||||
|
|
55
os/input.c
55
os/input.c
|
@ -7,14 +7,69 @@
|
|||
// 'LICENSE', which is part of this source code package.
|
||||
//
|
||||
|
||||
#include "bus/controller.h"
|
||||
#include "common.h"
|
||||
#include "os/input.h"
|
||||
#include "os/keycodes.h"
|
||||
#include "si/controller.h"
|
||||
|
||||
bool shift_down;
|
||||
|
||||
void keyboard_press_callback(struct bus_controller *bus, unsigned key) {
|
||||
struct si_controller *si = bus->si;
|
||||
|
||||
//fprintf(stderr, "os/input: Got keypress event: %u\n", key);
|
||||
|
||||
if (key == CEN64_KEY_LSHIFT || key == CEN64_KEY_RSHIFT) {
|
||||
shift_down = true;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (key) {
|
||||
// Analog stick.
|
||||
case CEN64_KEY_LEFT: si->input[2] = shift_down ? 114 : 38; break;
|
||||
case CEN64_KEY_RIGHT: si->input[2] = shift_down ? -114 : -38; break;
|
||||
case CEN64_KEY_UP: si->input[3] = shift_down ? 114 : 38; break;
|
||||
case CEN64_KEY_DOWN: si->input[3] = shift_down ? -114 : -38; break;
|
||||
|
||||
// L/R flippers.
|
||||
case CEN64_KEY_A: si->input[1] |= 1 << 5; break;
|
||||
case CEN64_KEY_S: si->input[1] |= 1 << 4; break;
|
||||
|
||||
// A/Z/B/S buttons.
|
||||
case CEN64_KEY_X: si->input[0] |= 1 << 7; break;
|
||||
case CEN64_KEY_C: si->input[0] |= 1 << 6; break;
|
||||
case CEN64_KEY_Z: si->input[0] |= 1 << 5; break;
|
||||
case CEN64_KEY_RETURN: si->input[0] |= 1 << 4; break;
|
||||
}
|
||||
}
|
||||
|
||||
void keyboard_release_callback(struct bus_controller *bus, unsigned key) {
|
||||
struct si_controller *si = bus->si;
|
||||
|
||||
//fprintf(stderr, "os/input: Got keyrelease event: %u\n", key);
|
||||
|
||||
if (key == CEN64_KEY_LSHIFT || key == CEN64_KEY_RSHIFT) {
|
||||
shift_down = false;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (key) {
|
||||
// Analog stick.
|
||||
case CEN64_KEY_LEFT: si->input[2] = 0; break;
|
||||
case CEN64_KEY_RIGHT: si->input[2] = 0; break;
|
||||
case CEN64_KEY_UP: si->input[3] = 0; break;
|
||||
case CEN64_KEY_DOWN: si->input[3] = 0; break;
|
||||
|
||||
// L/R flippers.
|
||||
case CEN64_KEY_A: si->input[1] &= ~(1 << 5); break;
|
||||
case CEN64_KEY_S: si->input[1] &= ~(1 << 4); break;
|
||||
|
||||
// A/Z/B/S buttons.
|
||||
case CEN64_KEY_X: si->input[0] &= ~(1 << 7); break;
|
||||
case CEN64_KEY_C: si->input[0] &= ~(1 << 6); break;
|
||||
case CEN64_KEY_Z: si->input[0] &= ~(1 << 5); break;
|
||||
case CEN64_KEY_RETURN: si->input[0] &= ~(1 << 4); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#ifndef __unix_keycodes_h__
|
||||
#define __unix_keycodes_h__
|
||||
#include <X11/keydefs.h>
|
||||
#include <X11/keysym.h>
|
||||
|
||||
// Letter keys.
|
||||
#define CEN64_KEY_A XK_a
|
||||
|
|
|
@ -86,7 +86,7 @@ int pif_perform_command(struct si_controller *si,
|
|||
case 0x01:
|
||||
switch(channel) {
|
||||
case 0:
|
||||
memset(recv_buf, 0, 4);
|
||||
memcpy(recv_buf, si->input, sizeof(si->input));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -33,6 +33,7 @@ struct si_controller {
|
|||
|
||||
uint32_t regs[NUM_SI_REGISTERS];
|
||||
uint32_t pif_status;
|
||||
uint8_t input[4];
|
||||
};
|
||||
|
||||
int si_init(struct si_controller *si,
|
||||
|
|
|
@ -410,6 +410,25 @@ int VR4300_CACHE(struct vr4300 *vr4300,
|
|||
vr4300_dcache_invalidate(line);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
if ((line = vr4300_dcache_probe(&vr4300->dcache, vaddr, paddr))) {
|
||||
uint32_t bus_address;
|
||||
uint32_t data[4];
|
||||
unsigned i;
|
||||
|
||||
if (line->metadata & 0x2) {
|
||||
bus_address = vr4300_dcache_get_tag(line);
|
||||
memcpy(data, line->data, sizeof(data));
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
bus_write_word(vr4300->bus, bus_address + i * 4, data[i], ~0);
|
||||
}
|
||||
|
||||
line->metadata &= ~0x1;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 6:
|
||||
if ((line = vr4300_dcache_probe(&vr4300->dcache, vaddr, paddr))) {
|
||||
uint32_t bus_address;
|
||||
|
|
|
@ -141,7 +141,7 @@ extern const char *vr4300_opcode_mnemonics[NUM_VR4300_OPCODES];
|
|||
#define SW VR4300_BUILD_OP(SW, STORE, INFO2(NEEDRS, NEEDRT))
|
||||
#define SWL VR4300_BUILD_OP(SWL, SWL_SWR, INFO2(NEEDRS, NEEDRT))
|
||||
#define SWR VR4300_BUILD_OP(SWR, SWL_SWR, INFO2(NEEDRS, NEEDRT))
|
||||
#define SYNC VR4300_BUILD_OP(SYNC, INV, INFO1(NONE))
|
||||
#define SYNC VR4300_BUILD_OP(SYNC, SLL, INFO1(NONE))
|
||||
#define SYSCALL VR4300_BUILD_OP(SYSCALL, INV, INFO1(NONE))
|
||||
#define TEQ VR4300_BUILD_OP(TEQ, INV, INFO1(NONE))
|
||||
#define TEQI VR4300_BUILD_OP(TEQI, INV, INFO1(NONE))
|
||||
|
|
Loading…
Reference in a new issue