Commit 3f8eaee3 authored by David Skywalker's avatar David Skywalker
Browse files

[ev] autorun on events

[ui] new option to disable floppy sounds
[cap32] cleaned a bit.
parent eafe37b8
......@@ -162,8 +162,6 @@
May 29, 2004 - 18:09 reintroduced tape_eject, tape_insert and tape_insert_voc; added sound support via the native SDL audio routines
*/
#define AUTODELAY 50
/* forward declarations - some libretro port callbacks */
void retro_loop(void);
void doCleanUp (void);
......@@ -186,7 +184,6 @@ extern bool kbd_runcmd;
int autoboot_delay=0;
extern void kbd_buf_feed(char *s);
extern void kbd_buf_update();
extern void kbd_update_table(int lang);
extern char DISKA_NAME[512];
......@@ -2152,83 +2149,40 @@ int loadadsk (char *arv,int drive)
return 0;
}
void check_kbd_command()
{
if (autoboot_delay<AUTODELAY)
autoboot_delay++;
else if (autoboot_delay==AUTODELAY)
{
if (!autorun)
kbd_runcmd=false;
autoboot_delay++;
}
if(kbd_runcmd==true && autoboot_delay>AUTODELAY){
static int pair=-1;
pair=-pair;
if(pair==1)
return;
kbd_buf_update();
}
}
void retro_loop(void)
{
while(theloop());
check_kbd_command();
//printf("auto:%d run:%d cmd:%d\n",autoboot_delay,autorun,kbd_runcmd);
}
int theloop(void)
{
if ((CPC.limit_speed) && (iExitCondition == EC_CYCLE_COUNT))
while(1)
{
//int iTicksAdj = 0; // no adjustment necessary by default
if (CPC.snd_enabled)
if ((CPC.limit_speed) && (iExitCondition == EC_CYCLE_COUNT))
{
if (pbSndStream < CPC.snd_bufferptr)
dwSndDist = CPC.snd_bufferptr - pbSndStream; // determine distance between play and write cursors
else
dwSndDist = (pbSndBufferEnd - pbSndStream) + (CPC.snd_bufferptr - pbSndBuffer);
#if 0
if (dwSndDist < dwSndMinSafeDist)
iTicksAdj = -5; // speed emulation up to compensate
else if (dwSndDist > dwSndMaxSafeDist)
iTicksAdj = 5; // slow emulation down to compensate
#endif
if (CPC.snd_enabled)
{
if (pbSndStream < CPC.snd_bufferptr)
dwSndDist = CPC.snd_bufferptr - pbSndStream; // determine distance between play and write cursors
else
dwSndDist = (pbSndBufferEnd - pbSndStream) + (CPC.snd_bufferptr - pbSndBuffer);
}
}
}
uint32_t dwOffset = CPC.scr_pos - CPC.scr_base; // offset in current surface row
if (VDU.scrln > 0)
CPC.scr_base = retro_getScreenPtr() + (VDU.scrln * CPC.scr_line_offs); // determine current position
else
CPC.scr_base = retro_getScreenPtr(); // reset to surface start
CPC.scr_pos = CPC.scr_base + dwOffset; // update current rendering position
uint32_t dwOffset = CPC.scr_pos - CPC.scr_base; // offset in current surface row
if (VDU.scrln > 0)
CPC.scr_base = retro_getScreenPtr() + (VDU.scrln * CPC.scr_line_offs); // determine current position
else
CPC.scr_base = retro_getScreenPtr(); // reset to surface start
iExitCondition = z80_execute(); // run the emulation until an exit condition is met
CPC.scr_pos = CPC.scr_base + dwOffset; // update current rendering position
if (iExitCondition == EC_FRAME_COMPLETE)
{
/* emulation finished rendering a complete frame? */
return 0; /* exit retro_loop for retro_run */
iExitCondition = z80_execute(); // run the emulation until an exit condition is met
if (iExitCondition == EC_FRAME_COMPLETE)
{
/* emulation finished rendering a complete frame? */
break; /* exit retro_loop for retro_run */
}
else if (iExitCondition == EC_SOUND_BUFFER)
{
mixsnd();
}
}
else if (iExitCondition == EC_SOUND_BUFFER)
mixsnd();
return 1;
}
int capmain (int argc, char **argv)
......
......@@ -499,7 +499,6 @@ int cpc_get_key_from_ascii(char ascii)
char kbd_feedbuf[255];
int kbd_feedbuf_pos;
bool kbd_runcmd=false;
int kbd_mode = 0;
extern void play_tape();
......@@ -513,16 +512,14 @@ extern uint8_t keyboard_matrix[16];
void kbd_buf_feed(char *s) {
strcpy(kbd_feedbuf, s);
kbd_feedbuf_pos=0;
kbd_runcmd=true;
//printf("cmd:%s\n",s);
}
void kbd_buf_clean(){
kbd_runcmd=false;
memset(keyboard_matrix, 0xff, sizeof(keyboard_matrix));
}
void kbd_buf_update() {
bool kbd_buf_update() {
static int old=0;
......@@ -530,7 +527,7 @@ void kbd_buf_update() {
if( kbd_feedbuf[kbd_feedbuf_pos]=='^' ) {
kbd_feedbuf_pos++;
play_tape();
return;
return false;
}
if( (kbd_feedbuf[kbd_feedbuf_pos]!=0) && old==0) {
......@@ -561,8 +558,10 @@ void kbd_buf_update() {
else if(kbd_feedbuf[kbd_feedbuf_pos]=='\0')
{
kbd_buf_clean();
return true;
}
return false;
}
//FIXME VIRTULAL KBD HANDLE
......
......@@ -55,7 +55,6 @@ extern int tape_insert (char *pchFileName);
extern int cart_insert (char *pchFileName);
extern void enter_gui(void);
extern void kbd_buf_feed(char *s);
extern void kbd_buf_update();
extern int Retro_PollEvent();
extern void retro_loop(void);
extern int video_set_palette (void);
......@@ -425,6 +424,10 @@ void retro_set_environment(retro_environment_t cb)
"cap32_statusbar",
"Status Bar; onloading|enabled|disabled",
},
{
"cap32_floppy_sound",
"Floppy Sound; enabled|disabled",
},
{
"cap32_scr_tube",
"Monitor Type; color|green|white",
......@@ -491,8 +494,10 @@ static void update_variables(void)
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (strcmp(var.value, "enabled") == 0)
autorun = 1;
if (strcmp(var.value, "disabled") == 0)
ev_set(EV_JOY);
else
ev_set(EV_AUTO);
}
var.key = "cap32_combokey";
......@@ -546,6 +551,17 @@ static void update_variables(void)
}
}
var.key = "cap32_floppy_sound";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (strcmp(var.value, "disabled") == 0)
retro_computer_cfg.floppy_snd = 0;
else
retro_computer_cfg.floppy_snd = 1;
}
var.key = "cap32_statusbar";
var.value = NULL;
......@@ -1237,7 +1253,8 @@ void retro_set_video_refresh(retro_video_refresh_t cb)
void retro_audio_mix()
{
retro_snd_mixer();
if(retro_computer_cfg.floppy_snd)
retro_snd_mixer();
memcpy(audio_buffer, pbSndBuffer, audio_buffer_size);
audio_batch_cb((int16_t*) audio_buffer, audio_buffer_size);
}
......
......@@ -76,6 +76,7 @@ extern unsigned amstrad_devices[ PORTS_NUMBER ];
#endif
#define WINDOW_MAX_SIZE (TEX_MAX_WIDTH * TEX_MAX_HEIGHT)
#define EMULATION_INIT_AUTORUNDELAY 50
#ifdef LOWRES
#define SCREENMODE_STR " LO"
......@@ -119,22 +120,10 @@ typedef struct {
uint32_t statusbar;
uint32_t padcfg[PORTS_NUMBER];
bool is_dirty;
bool floppy_snd;
} computer_cfg_t;
extern computer_cfg_t retro_computer_cfg;
//VKBD
#define NPLGN 12
#define NLIGN 5
#define NLETT 5
typedef struct {
char norml[NLETT];
char shift[NLETT];
int val;
} Mvk;
extern Mvk MVk[NPLGN*NLIGN*2];
//STRUCTURES
typedef struct{
signed short x, y;
......
......@@ -44,6 +44,7 @@ extern retro_mouse_t mouse;
extern bool kbd_runcmd;
extern void kbd_buf_feed(char *s);
extern bool kbd_buf_update();
extern void save_bkg();
extern void play_tape();
extern void stop_tape(void);
......@@ -65,12 +66,6 @@ bool (*ev_events)(void);
bool (*process_events)(void);
unsigned char (*process_ev_key)(int key, bool pressed);
enum retro_event_call
{
EV_NONE = 0,
EV_JOY = 1,
EV_KBD = 2
};
int event_call = EV_JOY;
void ev_toggle_call();
......@@ -340,7 +335,8 @@ static void _process_joy(int playerID){
* ev_joysticks:
* function to unify event code, call joy events and get user pad data
**/
bool ev_joysticks() {
bool ev_joysticks()
{
// you cannot use key-remap on player two, force read it
_process_joy(ID_PLAYER2);
......@@ -356,6 +352,28 @@ bool ev_joysticks() {
return true;
}
bool ev_autorun()
{
static int delay = EMULATION_INIT_AUTORUNDELAY;
static int wait_computer = 1;
if(delay)
{
delay --;
return false;
}
// wait one loop for the key be pressed
wait_computer ^= 1;
if(wait_computer)
return false;
if(kbd_buf_update())
ev_set(EV_JOY);
return true;
}
//-----------------------------------------------------
#define MAX_KEY_EVENT 6
......@@ -405,9 +423,8 @@ static void ev_events_key(unsigned keycode, bool down)
/**
* _ev_key:
* process_ev_key:
* emulator keyboard handler
* BUG: ra call keyboard_cb incorrectly with release events
**/
unsigned char _ev_key(int key, bool pressed) {
uint8_t cpc_key = get_cpckey(key);
......@@ -423,7 +440,8 @@ unsigned char _ev_key(int key, bool pressed) {
/**
* _ev_key_null:
* FIXME: to try to avoid ghosting bug we set ev_key as null on KoS.
* Here we to try to avoid ghosting bug on old retroarch versions
* issue: https://github.com/libretro/RetroArch/issues/8838
**/
unsigned char _ev_key_null(int key, bool pressed) {
return CPC_KEY_NULL;
......@@ -433,16 +451,12 @@ unsigned char _ev_key_null(int key, bool pressed) {
* keyboard_cb:
* Is called by main retro_callback when user press/release a key
* just convert this event to an emulated event
* BUG: generates ghosting release events when "amstrad keyboard" is selected on controls
**/
static void keyboard_cb(bool down, unsigned keycode, uint32_t character, uint16_t mod)
{
//printf( "Down: %s, Code: %d, Char: %u, Mod: %u.\n",
// down ? "yes" : "no", keycode, character, mod);
if(kbd_runcmd) // FIXME -- send bug to libretro
return;
if(process_ev_key(keycode, down) != CPC_KEY_NULL)
return;
......@@ -597,21 +611,39 @@ void ev_init(){
ev_events = _events_null;
process_events = ev_joysticks;
process_ev_key = _ev_key;
process_ev_key = _ev_key_null;
}
void ev_toggle_call()
void ev_set(int type)
{
if (event_call == EV_JOY)
switch (type)
{
process_ev_key = _ev_key_null;
process_events = *ev_events;
event_call = EV_KBD;
} else {
process_ev_key = _ev_key;
process_events = ev_joysticks;
event_call = EV_JOY;
case EV_AUTO:
process_ev_key = _ev_key_null;
process_events = ev_autorun;
break;
case EV_JOY:
process_ev_key = _ev_key;
process_events = ev_joysticks;
break;
case EV_KBD:
process_ev_key = _ev_key_null;
process_events = *ev_events;
break;
}
//printf("[CPC] [EV] type %u\n", type);
event_call = type;
}
void ev_toggle_call()
{
if (event_call == EV_JOY)
ev_set(EV_KBD);
else
ev_set(EV_JOY);
}
void ev_combo_set(unsigned btn)
......@@ -718,15 +750,14 @@ void ev_mouse_motion_absolute()
mouse.status |= CURSOR_MOTION;
}
bool ev_cursor_click(unsigned int device, unsigned int event, int * ref_ptr, int value)
void ev_cursor_click(unsigned int device, unsigned int event, int * ref_ptr, int value)
{
int clicked = input_state_cb(0, device, 0, event);
if (clicked == *ref_ptr)
return false;
return;
*ref_ptr = clicked;
mouse.status |= value;
return true;
}
void ev_joy_motion()
......@@ -769,7 +800,6 @@ void ev_joy_motion()
{
mouse.status |= CURSOR_MOTION;
}
}
void ev_process_cursor()
......
......@@ -138,6 +138,14 @@ enum retro_events_action_type
EVENT_CURSOR_JOY,
};
enum retro_event_call_type
{
EV_NONE = 0,
EV_JOY = 1,
EV_KBD = 2,
EV_AUTO = 3,
};
typedef struct {
unsigned type;
const char * kbd_buf;
......@@ -151,9 +159,9 @@ typedef struct {
enum retro_cursor_status
{
CURSOR_NONE = 0,
CURSOR_CLICKED = 1,
CURSOR_MOTION = 2,
CURSOR_NONE = 0,
CURSOR_CLICKED = 1,
CURSOR_MOTION = 2,
CURSOR_CLICKED_JOY = 4,
};
......@@ -174,6 +182,7 @@ void ev_release_key(unsigned char cpc_key);
extern bool (*process_events)(void);
void ev_combo_set(unsigned btn);
void ev_set(int type);
void ev_init();
void Core_PollEvent(void);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment