pizza: input
This commit is contained in:
parent
803190e6b4
commit
dd9d1b2018
|
@ -11,16 +11,31 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Gameboy
|
|||
public abstract class LibPizza
|
||||
{
|
||||
private const CallingConvention CC = CallingConvention.Cdecl;
|
||||
[Flags]
|
||||
public enum Buttons : ushort
|
||||
{
|
||||
A = 0x01,
|
||||
B = 0x02,
|
||||
SELECT = 0x04,
|
||||
START = 0x08,
|
||||
RIGHT = 0x10,
|
||||
LEFT = 0x20,
|
||||
UP = 0x40,
|
||||
DOWN = 0x80
|
||||
}
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public class FrameInfo
|
||||
{
|
||||
public IntPtr VideoBuffer;
|
||||
public int Clocks;
|
||||
public Buttons Keys;
|
||||
}
|
||||
|
||||
[BizImport(CC)]
|
||||
public abstract bool Init(byte[] rom, int romlen);
|
||||
[BizImport(CC)]
|
||||
public abstract void FrameAdvance([In,Out] FrameInfo frame);
|
||||
[BizImport(CC)]
|
||||
public abstract bool IsCGB();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,12 +35,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Gameboy
|
|||
MmapHeapSizeKB = 32 * 1024
|
||||
});
|
||||
_pizza = BizInvoker.GetInvoker<LibPizza>(_exe, _exe);
|
||||
using (_exe.EnterExit())
|
||||
if (!_pizza.Init(rom, rom.Length))
|
||||
{
|
||||
if (!_pizza.Init(rom, rom.Length))
|
||||
{
|
||||
throw new InvalidOperationException("Core rejected the rom!");
|
||||
}
|
||||
throw new InvalidOperationException("Core rejected the rom!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,6 +58,27 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Gameboy
|
|||
|
||||
private int _tickOverflow = 0;
|
||||
|
||||
private static LibPizza.Buttons GetButtons(IController c)
|
||||
{
|
||||
LibPizza.Buttons b = 0;
|
||||
if (c.IsPressed("Up"))
|
||||
b |= LibPizza.Buttons.UP;
|
||||
if (c.IsPressed("Down"))
|
||||
b |= LibPizza.Buttons.DOWN;
|
||||
if (c.IsPressed("Left"))
|
||||
b |= LibPizza.Buttons.LEFT;
|
||||
if (c.IsPressed("Right"))
|
||||
b |= LibPizza.Buttons.RIGHT;
|
||||
if (c.IsPressed("A"))
|
||||
b |= LibPizza.Buttons.A;
|
||||
if (c.IsPressed("B"))
|
||||
b |= LibPizza.Buttons.B;
|
||||
if (c.IsPressed("Select"))
|
||||
b |= LibPizza.Buttons.SELECT;
|
||||
if (c.IsPressed("Start"))
|
||||
b |= LibPizza.Buttons.START;
|
||||
return b;
|
||||
}
|
||||
|
||||
public unsafe void FrameAdvance(IController controller, bool render, bool rendersound = true)
|
||||
{
|
||||
|
@ -71,11 +89,13 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Gameboy
|
|||
var frame = new LibPizza.FrameInfo
|
||||
{
|
||||
VideoBuffer = (IntPtr)vp,
|
||||
Clocks = targetClocks
|
||||
Clocks = targetClocks,
|
||||
Keys = GetButtons(controller)
|
||||
};
|
||||
|
||||
_pizza.FrameAdvance(frame);
|
||||
_tickOverflow = frame.Clocks - targetClocks;
|
||||
Frame++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,8 +110,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Gameboy
|
|||
}
|
||||
}
|
||||
|
||||
public bool IsCGBMode() { return false; } // TODO
|
||||
public ControllerDefinition ControllerDefinition => NullController.Instance.Definition;
|
||||
public bool IsCGBMode() => _pizza.IsCGB();
|
||||
public ControllerDefinition ControllerDefinition => BizHawk.Emulation.Cores.Nintendo.Gameboy.Gameboy.GbController;
|
||||
public int Frame { get; private set; }
|
||||
public int LagCount { get; set; }
|
||||
public bool IsLagFrame { get; set; }
|
||||
|
|
|
@ -17,12 +17,10 @@
|
|||
|
||||
*/
|
||||
|
||||
#include <semaphore.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include "cartridge.h"
|
||||
#include "sound.h"
|
||||
#include "mmu.h"
|
||||
|
@ -36,9 +34,6 @@
|
|||
#include "z80_gameboy_regs.h"
|
||||
#include "z80_gameboy.h"
|
||||
|
||||
/* semaphore for pauses */
|
||||
sem_t gameboy_sem;
|
||||
|
||||
char gameboy_inited = 0;
|
||||
|
||||
|
||||
|
@ -53,9 +48,6 @@ void gameboy_init()
|
|||
/* init cycles syncronizer */
|
||||
cycles_init();
|
||||
|
||||
/* init input */
|
||||
input_init();
|
||||
|
||||
/* init timer */
|
||||
timer_init();
|
||||
|
||||
|
|
|
@ -23,27 +23,13 @@
|
|||
#include <stdint.h>
|
||||
|
||||
/* button states */
|
||||
char input_key_left;
|
||||
char input_key_right;
|
||||
char input_key_up;
|
||||
char input_key_down;
|
||||
char input_key_a;
|
||||
char input_key_b;
|
||||
char input_key_select;
|
||||
char input_key_start;
|
||||
static uint16_t input_keys;
|
||||
|
||||
uint8_t input_init()
|
||||
void input_set_keys(uint16_t keys)
|
||||
{
|
||||
input_key_left = 0;
|
||||
input_key_right = 0;
|
||||
input_key_up = 0;
|
||||
input_key_down = 0;
|
||||
input_key_a = 0;
|
||||
input_key_b = 0;
|
||||
input_key_select = 0;
|
||||
input_key_start = 0;
|
||||
|
||||
return 0;
|
||||
// 7......0
|
||||
// DULRSsBA
|
||||
input_keys = keys & 0xff;
|
||||
}
|
||||
|
||||
uint8_t input_get_keys(uint8_t line)
|
||||
|
@ -52,50 +38,13 @@ uint8_t input_get_keys(uint8_t line)
|
|||
|
||||
if ((line & 0x30) == 0x20)
|
||||
{
|
||||
/* RIGHT pressed? */
|
||||
if (input_key_right)
|
||||
v ^= 0x01;
|
||||
|
||||
/* LEFT pressed? */
|
||||
if (input_key_left)
|
||||
v ^= 0x02;
|
||||
|
||||
/* UP pressed? */
|
||||
if (input_key_up)
|
||||
v ^= 0x04;
|
||||
|
||||
/* DOWN pressed? */
|
||||
if (input_key_down)
|
||||
v ^= 0x08;
|
||||
v ^= input_keys >> 4;
|
||||
}
|
||||
|
||||
if ((line & 0x30) == 0x10)
|
||||
{
|
||||
/* A pressed? */
|
||||
if (input_key_a)
|
||||
v ^= 0x01;
|
||||
|
||||
/* B pressed? */
|
||||
if (input_key_b)
|
||||
v ^= 0x02;
|
||||
|
||||
/* SELECT pressed? */
|
||||
if (input_key_select)
|
||||
v ^= 0x04;
|
||||
|
||||
/* START pressed? */
|
||||
if (input_key_start)
|
||||
v ^= 0x08;
|
||||
v ^= input_keys & 0x0f;
|
||||
}
|
||||
|
||||
return (v | 0xc0);
|
||||
return v | 0xc0;
|
||||
}
|
||||
|
||||
void input_set_key_right(char state) { input_key_right = state; }
|
||||
void input_set_key_left(char state) { input_key_left = state; }
|
||||
void input_set_key_up(char state) { input_key_up = state; }
|
||||
void input_set_key_down(char state) { input_key_down = state; }
|
||||
void input_set_key_a(char state) { input_key_a = state; }
|
||||
void input_set_key_b(char state) { input_key_b = state; }
|
||||
void input_set_key_select(char state) { input_key_select = state; }
|
||||
void input_set_key_start(char state) { input_key_start = state; }
|
||||
|
|
|
@ -22,14 +22,6 @@
|
|||
|
||||
/* prototypes */
|
||||
uint8_t input_get_keys(uint8_t line);
|
||||
uint8_t input_init();
|
||||
void input_set_key_left(char state);
|
||||
void input_set_key_right(char state);
|
||||
void input_set_key_up(char state);
|
||||
void input_set_key_down(char state);
|
||||
void input_set_key_a(char state);
|
||||
void input_set_key_b(char state);
|
||||
void input_set_key_select(char state);
|
||||
void input_set_key_start(char state);
|
||||
void input_set_keys(uint16_t keys);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -88,69 +88,28 @@ EXPORT int Init(const void *rom, int romlen)
|
|||
|
||||
static uint32_t fb32[160 * 144];
|
||||
|
||||
//case (SDLK_d): global_debug ^= 0x01; break;
|
||||
//case (SDLK_s): global_slow_down = 1; break;
|
||||
//case (SDLK_w): global_window ^= 0x01; break;
|
||||
//case (SDLK_n): gameboy_set_pause(0);
|
||||
// global_next_frame = 1; break;
|
||||
|
||||
/* case (SDLK_p): gameboy_set_pause(global_pause ^ 0x01);
|
||||
break;
|
||||
case (SDLK_m): mmu_dump_all(); break;
|
||||
case (SDLK_SPACE): input_set_key_select(1); break;
|
||||
case (SDLK_RETURN): input_set_key_start(1); break;
|
||||
case (SDLK_UP): input_set_key_up(1); break;
|
||||
case (SDLK_DOWN): input_set_key_down(1); break;
|
||||
case (SDLK_RIGHT): input_set_key_right(1); break;
|
||||
case (SDLK_LEFT): input_set_key_left(1); break;
|
||||
case (SDLK_z): input_set_key_b(1); break;
|
||||
case (SDLK_x): input_set_key_a(1); break;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_KEYUP:
|
||||
switch (e.key.keysym.sym)
|
||||
{
|
||||
case (SDLK_SPACE): input_set_key_select(0); break;
|
||||
case (SDLK_RETURN): input_set_key_start(0); break;
|
||||
case (SDLK_UP): input_set_key_up(0); break;
|
||||
case (SDLK_DOWN): input_set_key_down(0); break;
|
||||
case (SDLK_RIGHT): input_set_key_right(0); break;
|
||||
case (SDLK_LEFT): input_set_key_left(0); break;
|
||||
case (SDLK_z): input_set_key_b(0); break;
|
||||
case (SDLK_x): input_set_key_a(0); break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// join emulation thread
|
||||
pthread_join(thread, NULL);
|
||||
|
||||
// stop network thread!
|
||||
network_stop();
|
||||
|
||||
utils_log("Total cycles %d\n", cycles.cnt);
|
||||
utils_log("Total running seconds %d\n", cycles.seconds);
|
||||
|
||||
return 0;
|
||||
}*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t* vbuff;
|
||||
int32_t clocks; // desired(in) actual(out) time to run; 2MHZ
|
||||
uint16_t keys; // keypad input
|
||||
} frameinfo_t;
|
||||
|
||||
|
||||
EXPORT void FrameAdvance(frameinfo_t* frame)
|
||||
{
|
||||
input_set_keys(frame->keys);
|
||||
uint64_t current = cycles.sampleclock;
|
||||
gameboy_run(current + frame->clocks);
|
||||
frame->clocks = cycles.sampleclock - current;
|
||||
memcpy(frame->vbuff, fb32, 160 * 144 * sizeof(uint32_t));
|
||||
}
|
||||
|
||||
EXPORT int IsCGB(void)
|
||||
{
|
||||
return global_cgb;
|
||||
}
|
||||
|
||||
void cb()
|
||||
{
|
||||
// frame received into fb
|
||||
|
|
Loading…
Reference in New Issue