externalize emulator's keyboard functions in their own files
This commit is contained in:
parent
294d140082
commit
f2d9fc67b4
5 changed files with 82 additions and 74 deletions
1
Makefile
1
Makefile
|
@ -37,6 +37,7 @@ DOTOS = src/emu_serial.o \
|
|||
src/emu_emulate.o \
|
||||
src/emu_init.o \
|
||||
src/emu_actions.o \
|
||||
src/emu_keyboard.o \
|
||||
src/emu_memory.o \
|
||||
src/emu_register.o \
|
||||
src/emu_timer.o \
|
||||
|
|
|
@ -24,14 +24,13 @@ short conf_tab[] = { 1, 2, 2, 2, 2, 0 };
|
|||
|
||||
void do_in( void )
|
||||
{
|
||||
int i, in, out;
|
||||
int i, in = 0, out = 0;
|
||||
|
||||
out = 0;
|
||||
for ( i = 2; i >= 0; i-- ) {
|
||||
out <<= 4;
|
||||
out |= saturn.OUT[ i ];
|
||||
}
|
||||
in = 0;
|
||||
|
||||
for ( i = 0; i < 9; i++ )
|
||||
if ( out & ( 1 << i ) )
|
||||
in |= saturn.keybuf.rows[ i ];
|
||||
|
@ -497,55 +496,3 @@ void recall_n( unsigned char* reg, word_20 dat, int n )
|
|||
/************/
|
||||
/* keyboard */
|
||||
/************/
|
||||
void press_key( int hpkey )
|
||||
{
|
||||
// Check not already pressed (may be important: avoids a useless do_kbd_int)
|
||||
if ( keyboard[ hpkey ].pressed )
|
||||
return;
|
||||
|
||||
keyboard[ hpkey ].pressed = true;
|
||||
|
||||
int code = keyboard[ hpkey ].code;
|
||||
if ( code == 0x8000 ) { /* HPKEY_ON */
|
||||
for ( int i = 0; i < 9; i++ )
|
||||
saturn.keybuf.rows[ i ] |= 0x8000;
|
||||
do_kbd_int();
|
||||
} else {
|
||||
int r = code >> 4;
|
||||
int c = 1 << ( code & 0xf );
|
||||
if ( ( saturn.keybuf.rows[ r ] & c ) == 0 ) {
|
||||
if ( saturn.kbd_ien )
|
||||
do_kbd_int();
|
||||
if ( ( saturn.keybuf.rows[ r ] & c ) )
|
||||
fprintf( stderr, "bug\n" );
|
||||
|
||||
saturn.keybuf.rows[ r ] |= c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void release_key( int hpkey )
|
||||
{
|
||||
// Check not already released (not critical)
|
||||
if ( !keyboard[ hpkey ].pressed )
|
||||
return;
|
||||
|
||||
keyboard[ hpkey ].pressed = false;
|
||||
|
||||
int code = keyboard[ hpkey ].code;
|
||||
if ( code == 0x8000 ) {
|
||||
for ( int i = 0; i < 9; i++ )
|
||||
saturn.keybuf.rows[ i ] &= ~0x8000;
|
||||
} else {
|
||||
int r = code >> 4;
|
||||
int c = 1 << ( code & 0xf );
|
||||
saturn.keybuf.rows[ r ] &= ~c;
|
||||
}
|
||||
}
|
||||
|
||||
void release_all_keys( void )
|
||||
{
|
||||
for ( int hpkey = FIRST_HPKEY; hpkey <= LAST_HPKEY; hpkey++ )
|
||||
if ( keyboard[ hpkey ].pressed )
|
||||
release_key( hpkey );
|
||||
}
|
||||
|
|
|
@ -21,6 +21,19 @@
|
|||
#define IN_FIELD 16
|
||||
#define OUTS_FIELD 18
|
||||
|
||||
#define SrvcIoStart 0x3c0
|
||||
#define SrvcIoEnd 0x5ec
|
||||
|
||||
#define SCHED_INSTR_ROLLOVER 0x3fffffff
|
||||
#define SCHED_RECEIVE 0x7ff
|
||||
#define SCHED_ADJTIME 0x1ffe
|
||||
#define SCHED_TIMER1 0x1e00
|
||||
#define SCHED_TIMER2 0xf
|
||||
#define SCHED_STATISTICS 0x7ffff
|
||||
#define SCHED_NEVER 0x7fffffff
|
||||
|
||||
#define NB_SAMPLES 10
|
||||
|
||||
static long jumpaddr;
|
||||
|
||||
unsigned long instructions = 0;
|
||||
|
@ -38,19 +51,6 @@ long schedule_event = 0;
|
|||
long sched_timer1;
|
||||
long sched_timer2;
|
||||
|
||||
#define SrvcIoStart 0x3c0
|
||||
#define SrvcIoEnd 0x5ec
|
||||
|
||||
#define SCHED_INSTR_ROLLOVER 0x3fffffff
|
||||
#define SCHED_RECEIVE 0x7ff
|
||||
#define SCHED_ADJTIME 0x1ffe
|
||||
#define SCHED_TIMER1 0x1e00
|
||||
#define SCHED_TIMER2 0xf
|
||||
#define SCHED_STATISTICS 0x7ffff
|
||||
#define SCHED_NEVER 0x7fffffff
|
||||
|
||||
#define NB_SAMPLES 10
|
||||
|
||||
long sched_instr_rollover = SCHED_INSTR_ROLLOVER;
|
||||
long sched_receive = SCHED_RECEIVE;
|
||||
long sched_adjtime = SCHED_ADJTIME;
|
||||
|
|
56
src/emu_keyboard.c
Normal file
56
src/emu_keyboard.c
Normal file
|
@ -0,0 +1,56 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "emulator.h"
|
||||
|
||||
void press_key( int hpkey )
|
||||
{
|
||||
// Check not already pressed (may be important: avoids a useless do_kbd_int)
|
||||
if ( keyboard[ hpkey ].pressed )
|
||||
return;
|
||||
|
||||
keyboard[ hpkey ].pressed = true;
|
||||
|
||||
int code = keyboard[ hpkey ].code;
|
||||
if ( code == 0x8000 ) { /* HPKEY_ON */
|
||||
for ( int i = 0; i < 9; i++ )
|
||||
saturn.keybuf.rows[ i ] |= 0x8000;
|
||||
do_kbd_int();
|
||||
} else {
|
||||
int r = code >> 4;
|
||||
int c = 1 << ( code & 0xf );
|
||||
if ( ( saturn.keybuf.rows[ r ] & c ) == 0 ) {
|
||||
if ( saturn.kbd_ien )
|
||||
do_kbd_int();
|
||||
if ( ( saturn.keybuf.rows[ r ] & c ) )
|
||||
fprintf( stderr, "bug\n" );
|
||||
|
||||
saturn.keybuf.rows[ r ] |= c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void release_key( int hpkey )
|
||||
{
|
||||
// Check not already released (not critical)
|
||||
if ( !keyboard[ hpkey ].pressed )
|
||||
return;
|
||||
|
||||
keyboard[ hpkey ].pressed = false;
|
||||
|
||||
int code = keyboard[ hpkey ].code;
|
||||
if ( code == 0x8000 ) {
|
||||
for ( int i = 0; i < 9; i++ )
|
||||
saturn.keybuf.rows[ i ] &= ~0x8000;
|
||||
} else {
|
||||
int r = code >> 4;
|
||||
int c = 1 << ( code & 0xf );
|
||||
saturn.keybuf.rows[ r ] &= ~c;
|
||||
}
|
||||
}
|
||||
|
||||
void release_all_keys( void )
|
||||
{
|
||||
for ( int hpkey = FIRST_HPKEY; hpkey <= LAST_HPKEY; hpkey++ )
|
||||
if ( keyboard[ hpkey ].pressed )
|
||||
release_key( hpkey );
|
||||
}
|
|
@ -17,6 +17,9 @@
|
|||
/* LCD refresh rate is 64Hz according to https://www.hpcalc.org/hp48/docs/faq/48faq-6.html */
|
||||
#define USEC_PER_FRAME ( 1000000 / 64 )
|
||||
|
||||
#define NIBBLES_PER_ROW 0x22
|
||||
#define NIBBLES_NB_BITS 4
|
||||
|
||||
// Keys
|
||||
#define HPKEY_A 0
|
||||
#define HPKEY_B 1
|
||||
|
@ -291,9 +294,6 @@ typedef struct saturn_t {
|
|||
unsigned char* port2;
|
||||
} saturn_t;
|
||||
|
||||
#define NIBBLES_PER_ROW 0x22
|
||||
#define NIBBLES_NB_BITS 4
|
||||
|
||||
extern bool sigalarm_triggered;
|
||||
|
||||
extern int set_t1;
|
||||
|
@ -322,7 +322,7 @@ extern int annunciators_bits[ NB_ANNUNCIATORS ];
|
|||
/**************/
|
||||
/* emu_init.c */
|
||||
/**************/
|
||||
extern void init_display( void ); /* used in ui_*.c */
|
||||
extern void init_display( void ); /* used in main.c */
|
||||
extern int init_emulator( void ); /* used in main.c */
|
||||
extern void exit_emulator( void ); /* debugger.c; main.c; ui_*.c */
|
||||
extern int read_files( void ); /* debugger.c */
|
||||
|
@ -338,7 +338,7 @@ extern t1_t2_ticks get_t1_t2( void );
|
|||
extern void set_accesstime( void );
|
||||
|
||||
/********************/
|
||||
/* hp48emu_memory.c */
|
||||
/* emu_memory.c */
|
||||
/********************/
|
||||
extern int ( *read_nibble )( long addr );
|
||||
|
||||
|
@ -350,7 +350,12 @@ extern long read_nibbles( long addr, int len );
|
|||
/*****************/
|
||||
/* emu_actions.c */
|
||||
/*****************/
|
||||
extern void load_addr( word_20* dat, long addr, int n );
|
||||
extern void do_kbd_int( void );
|
||||
|
||||
/******************/
|
||||
/* emu_keyboard.c */
|
||||
/******************/
|
||||
extern void press_key( int hpkey );
|
||||
extern void release_key( int hpkey );
|
||||
extern void release_all_keys( void );
|
||||
|
@ -366,6 +371,5 @@ extern int init_serial( void );
|
|||
extern void emulate( void );
|
||||
extern int step_instruction( void );
|
||||
extern void schedule( void );
|
||||
extern void load_addr( word_20* dat, long addr, int n );
|
||||
|
||||
#endif /* !_EMULATOR_H */
|
||||
|
|
Loading…
Reference in a new issue