clean headers and more dead code

This commit is contained in:
Gwenhael Le Moine 2023-10-03 16:20:40 +02:00
parent 080d4ef025
commit 493c6df450
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
23 changed files with 58 additions and 368 deletions

View file

@ -9,7 +9,6 @@ all: dist/hpemu
dist/hpemu: src/bus.o \ dist/hpemu: src/bus.o \
src/color.o \ src/color.o \
src/cpu.o \ src/cpu.o \
src/disasm.o \
src/display.o \ src/display.o \
src/emulator.o \ src/emulator.o \
src/gui.o \ src/gui.o \

View file

@ -57,17 +57,17 @@ extern word crc;
// FAST_PEEK_MAX must not be greater than the size of the hdw registers (64) // FAST_PEEK_MAX must not be greater than the size of the hdw registers (64)
#define FAST_PEEK_MAX 64 #define FAST_PEEK_MAX 64
void bus_init( void ); extern void bus_init( void );
void bus_exit( void ); extern void bus_exit( void );
void bus_read( byte* buf, address adr, address len ); extern void bus_read( byte* buf, address adr, address len );
void bus_write( byte* buf, address adr, address len ); extern void bus_write( byte* buf, address adr, address len );
byte* bus_fast_peek( byte* buf, address adr, address* len ); extern byte* bus_fast_peek( byte* buf, address adr, address* len );
void bus_remap( void ); extern void bus_remap( void );
void bus_configure( address adr ); extern void bus_configure( address adr );
void bus_unconfigure( address adr ); extern void bus_unconfigure( address adr );
void bus_reset( void ); extern void bus_reset( void );
address bus_get_id(); extern address bus_get_id();
#endif #endif

View file

@ -3,6 +3,8 @@
#define RESERVED_LCD 128 #define RESERVED_LCD 128
enum LCD_Modes { LCD_MODE_SIMPLE, LCD_MODE_GRAY4, LCD_MODE_GRAY8, LCD_MODE_EXP };
int color[ C_COUNT ]; int color[ C_COUNT ];
typedef struct RGB { typedef struct RGB {

View file

@ -1,8 +1,6 @@
#ifndef __COLOR_H #ifndef __COLOR_H
#define __COLOR_H #define __COLOR_H
enum LCD_Modes { LCD_MODE_SIMPLE, LCD_MODE_GRAY4, LCD_MODE_GRAY8, LCD_MODE_EXP };
enum Colors { enum Colors {
C_BACKGROUND, C_BACKGROUND,
C_PANEL_BACK, C_PANEL_BACK,
@ -19,9 +17,6 @@ enum Colors {
extern int color[ C_COUNT ]; extern int color[ C_COUNT ];
void color_lcd( int r0, int g0, int b0, int r1, int g1, int b1 ); extern void color_init( void );
void color_lcd_mode( int mode );
void color_set_emu( int i, int r, int g, int b );
void color_init( void );
#endif #endif

View file

@ -34,7 +34,7 @@ enum RegisterNames { A, B, C, D };
extern Cpu cpu; extern Cpu cpu;
void cpu_interrupt( void ); extern void cpu_interrupt( void );
void execute_instruction( void ); extern void execute_instruction( void );
#endif #endif

View file

@ -1,283 +0,0 @@
#include <stdio.h>
#include "types.h"
#include "opcodes.h"
#include "opinline.h"
#include "disasm.h"
static const char hex_tab[ 16 ] = "0123456789ABCDEF";
static const char r_tab[ 11 ][ 16 ] = {
"ABCDABCDBCACBCAC", // p
"BCAC1111ABCDABCD", // q
"ABCDBCACABCDBCAC", // r
"BCACABCDBCACABCD", // s
"ABCDABCDBCACABCD", // t
"ABCDABCDABCDABCD", // u (different than in opcodes.c)
"BCACBCACBCACBCAC", // v (different than in opcodes.c)
"BCACABCDABCD1111", // w
"ABCDABCDBCACABAC", // x
"0000BCACABCDBCCD", // y
"BCACBCAC00000000", // z
};
static const char* f_tab[ 8 ] = { "P", "WP", "XS", "X", "S", "M", "B", "W" };
#define HEX( x ) ( hex_tab[ x ] )
#define ADD_OFFSET( x, s ) \
do { \
if ( *( s ) == '+' ) { \
( s )++; \
( x ) += *( s )++ - '0'; \
} \
} while ( 0 )
static void expand( char* dest, char* src, byte* ptr )
{
int i, n;
int x;
while ( *src ) {
if ( *src != '%' ) {
*dest++ = *src++;
} else {
src++;
switch ( *src++ ) {
case 'I': // One digit integer
i = *src++ - '0';
x = ptr[ i ];
ADD_OFFSET( x, src );
if ( x >= 10 ) {
*dest++ = '0' + x / 10;
*dest++ = '0' + x % 10;
} else {
*dest++ = '0' + x;
}
break;
case 'X': // Hexadecimal number
i = *src++ - '0';
n = *src++ - '0';
while ( n-- ) {
*dest++ = HEX( ptr[ i + n ] );
}
break;
case 'N': // Variable length hexadecimal number
i = *src++ - '0';
n = ptr[ i ] + 1;
while ( n ) {
*dest++ = HEX( ptr[ i + n ] );
n--;
}
break;
case 'R': // Relative address
i = *src++ - '0';
n = *src++ - '0';
x = nib_to_signed( ptr + i, n );
ADD_OFFSET( x, src );
if ( x < 0 ) {
*dest++ = '-';
x = -x;
} else {
*dest++ = '+';
}
while ( n-- ) {
*dest++ = HEX( ( x >> ( n * 4 ) ) & 0xF );
}
break;
case 'T': // Relative address for tests
i = *src++ - '0';
n = *src++ - '0';
x = nib_to_signed( ptr + i, n );
if ( x == 0 ) {
ADD_OFFSET( x, src ); // skip over the optional "+i"
break;
}
ADD_OFFSET( x, src );
if ( x < 0 ) {
*dest++ = '-';
x = -x;
} else {
*dest++ = '+';
}
while ( n-- ) {
*dest++ = HEX( ( x >> ( n * 4 ) ) & 0xF );
}
break;
case 'G': // "GO" or "RTN" for tests
i = *src++ - '0';
n = *src++ - '0';
x = nib_to_signed( ptr + i, n );
if ( x == 0 ) {
*dest++ = 'R';
*dest++ = 'T';
*dest++ = 'N';
} else {
*dest++ = 'G';
*dest++ = 'O';
}
break;
case 'F': // Field name
i = *src++ - '0';
if ( *src == 'A' ) {
src++;
if ( ptr[ i ] == 0xF ) {
*dest++ = 'A';
break;
}
}
*dest++ = f_tab[ ptr[ i ] & 7 ][ 0 ];
if ( f_tab[ ptr[ i ] & 7 ][ 1 ] )
*dest++ = f_tab[ ptr[ i ] & 7 ][ 1 ];
break;
case 'B': // Field A or B
i = *src++ - '0';
*dest++ = ( ptr[ i ] & 8 ) ? 'B' : 'A';
break;
case 'p': // Subtraction source 1
case 'q': // Subtraction source 2
case 'r': // Logic destination & source 1
case 's': // Logic source 2
case 't': // Arithmethic destination & addition source 1
case 'u': // Compare source 1
case 'v': // Compare source 2 for <, >, <= and >=
case 'w': // Addition source 2
case 'x': // Assignment destination
case 'y': // Assignment source
case 'z': // Compare source 2 for = and #
i = *src++ - '0';
*dest++ = r_tab[ src[ -2 ] - 'p' ][ ptr[ i ] ];
break;
case 'a': // "A" or "C"
i = *src++ - '0';
*dest++ = ( ptr[ i ] & 8 ) ? 'C' : 'A';
break;
case 'i': // R-register number
i = *src++ - '0';
*dest++ = '0' + ( ( ptr[ i ] & 7 ) > 4 ? ptr[ i ] & 3 : ptr[ i ] & 7 );
break;
case '#': // "#" or "=" for comparisons
i = *src++ - '0';
*dest++ = ( ptr[ i ] & 4 ) ? '#' : '=';
break;
case '>': // ">", "<", ">=" or "<=" for comparisons
i = *src++ - '0';
*dest++ = ( ptr[ i ] & 4 ) ? '<' : '>';
if ( ptr[ i ] & 8 )
*dest++ = '=';
break;
case '=': // Conditional "=" for assignments
i = *src++ - '0';
if ( ptr[ i ] < 0xC )
*dest++ = '=';
break;
case 'E': // Conditionsl "EX" for assignments
i = *src++ - '0';
if ( ptr[ i ] >= 0xC ) {
*dest++ = 'E';
*dest++ = 'X';
}
break;
case '+': // "+" or "-" for add / dec
i = *src++ - '0';
*dest++ = ( ptr[ i ] < 0xC ) ? '+' : '-';
break;
case '-': // "-" or "+" for sub / inc
i = *src++ - '0';
*dest++ = ( ( ptr[ i ] & 0xC ) != 0x4 ) ? '-' : '+';
break;
case '~': // "+" or "-" for +con and -con
i = *src++ - '0';
*dest++ = ( ptr[ i ] & 8 ) ? '-' : '+';
break;
case '&': // "&" or "!" for and / or
i = *src++ - '0';
*dest++ = ( ptr[ i ] & 8 ) ? '!' : '&';
break;
case 'D': // DATi=r or r=DATi
i = *src++ - '0';
if ( !( ptr[ i ] & 2 ) ) {
*dest++ = 'D';
*dest++ = 'A';
*dest++ = 'T';
*dest++ = '0' + ( ptr[ i ] & 1 );
*dest++ = '=';
*dest++ = 'A' + ( ( ptr[ i ] & 4 ) >> 1 );
} else {
*dest++ = 'A' + ( ( ptr[ i ] & 4 ) >> 1 );
*dest++ = '=';
*dest++ = 'D';
*dest++ = 'A';
*dest++ = 'T';
*dest++ = '0' + ( ptr[ i ] & 1 );
}
break;
case '%': // Litteral %
*( dest++ ) = '%';
break;
}
}
}
*dest = '\0';
}
char* disassemble( byte* ptr )
{
static char buffer[ 64 ];
Opcode* op = opcodes;
int i = 0;
while ( op[ ptr[ i ] ].next ) {
op = op[ ptr[ i ] ].next;
i++;
}
if ( op[ ptr[ i ] ].dissasm ) {
expand( buffer, op[ ptr[ i ] ].dissasm, ptr );
} else {
sprintf( buffer, "Unknown (%s)", nib_to_hex( ptr, i + 1 ) );
}
return buffer;
}
char* nib_to_hex( byte* nib, int n )
{
static char buffer[ 17 ];
buffer[ n ] = '\0';
while ( n-- ) {
buffer[ n ] = HEX( nib[ n ] );
}
return buffer;
}
char* nib_to_hex_rev( byte* nib, int n )
{
static char buffer[ 17 ];
buffer[ n ] = '\0';
while ( n-- ) {
buffer[ n ] = HEX( *nib++ );
}
return buffer;
}

View file

@ -1,10 +0,0 @@
#ifndef __DISASM_H
#define __DISASM_H
#include "types.h"
char* disassemble( byte* ptr );
char* nib_to_hex( byte* nib, int n );
char* nib_to_hex_rev( byte* nib, int n );
#endif

View file

@ -1,8 +1,9 @@
#ifndef __DISPLAY_H #ifndef __DISPLAY_H
#define __DISPLAY_H #define __DISPLAY_H
#include <SDL2/SDL.h>
#include <stdlib.h> #include <stdlib.h>
#include <SDL2/SDL.h>
#include "types.h" #include "types.h"
extern address menu_base; extern address menu_base;
@ -13,9 +14,9 @@ extern byte display_height;
extern byte display_offset; extern byte display_offset;
extern bool display_enable; extern bool display_enable;
void display_init( void ); extern void display_init( void );
void display_exit( void ); extern void display_exit( void );
void display_update( void ); extern void display_update( void );
void display_show(); extern void display_show( void );
#endif #endif

View file

@ -41,8 +41,6 @@ static int emulator_state = EMULATOR_RUN;
void emulator_set_state( int state ) { emulator_state = state; } void emulator_set_state( int state ) { emulator_state = state; }
int emulator_get_state( void ) { return emulator_state; }
void emulator_init( void ) void emulator_init( void )
{ {
static bool locked = false; static bool locked = false;

View file

@ -5,16 +5,13 @@
enum EmulatorStates { EMULATOR_STOP, EMULATOR_STEP, EMULATOR_RUN }; enum EmulatorStates { EMULATOR_STOP, EMULATOR_STEP, EMULATOR_RUN };
void true_speed_proc( void );
extern volatile bool please_exit; extern volatile bool please_exit;
extern dword emulator_speed; extern dword emulator_speed;
void emulator_init( void ); extern void emulator_init( void );
void emulator_exit( void ); extern void emulator_exit( void );
bool emulator_run( void ); extern bool emulator_run( void );
void emulator_set_state( int state ); extern void emulator_set_state( int state );
int emulator_get_state( void );
#endif #endif

View file

@ -4,6 +4,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "color.h" #include "color.h"
#include "pcalc.h" #include "pcalc.h"
#include "pfiles.h" #include "pfiles.h"

View file

@ -29,10 +29,10 @@ typedef struct {
#define BUTTON_B2TOGGLE 0x08 // Mouse button 2 toggles this button #define BUTTON_B2TOGGLE 0x08 // Mouse button 2 toggles this button
#define BUTTON_B1RELEASE 0x10 // Releaseing mouse button 1 anywhere unpushes the button #define BUTTON_B1RELEASE 0x10 // Releaseing mouse button 1 anywhere unpushes the button
void gui_initKeyboard( Button* calcbuttons ); extern void gui_initKeyboard( Button* calcbuttons );
void button_draw_all( /*BITMAP *bmp,*/ Button* buttons ); extern void button_draw_all( /*BITMAP *bmp,*/ Button* buttons );
int button_mouse_down( /*BITMAP *bmp,*/ Button* butons, int mx, int my, int mb ); extern int button_mouse_down( /*BITMAP *bmp,*/ Button* butons, int mx, int my, int mb );
int button_mouse_up( /*BITMAP *bmp,*/ Button* buttons, int mx, int my, int mb ); extern int button_mouse_up( /*BITMAP *bmp,*/ Button* buttons, int mx, int my, int mb );
#endif #endif

View file

@ -3,10 +3,10 @@
#include "types.h" #include "types.h"
void hdw_init( void ); extern void hdw_init( void );
void hdw_exit( void ); extern void hdw_exit( void );
byte hdw_read_nibble( address adr ); extern byte hdw_read_nibble( address adr );
void hdw_write_nibble( byte data, address adr ); extern void hdw_write_nibble( byte data, address adr );
#endif #endif

View file

@ -5,10 +5,10 @@
extern bool kbd_on; extern bool kbd_on;
void kbd_out_changed( void ); extern void kbd_out_changed( void );
void kbd_key_pressed( int row, int col ); extern void kbd_key_pressed( int row, int col );
void kbd_key_released( int row, int col ); extern void kbd_key_released( int row, int col );
void kbd_on_pressed( void ); extern void kbd_on_pressed( void );
void kbd_on_released( void ); extern void kbd_on_released( void );
#endif #endif

View file

@ -257,11 +257,6 @@ void pcalc_show()
button_draw_all( calc_buttons ); button_draw_all( calc_buttons );
} }
void pcalc_hide( void )
{
// calc_bmp = NULL;
}
void pcalc_down( int mx, int my, int mb ) { button_mouse_down( calc_buttons, mx, my, mb ); } void pcalc_down( int mx, int my, int mb ) { button_mouse_down( calc_buttons, mx, my, mb ); }
void pcalc_up( int mx, int my, int mb ) { button_mouse_up( calc_buttons, mx, my, mb ); } void pcalc_up( int mx, int my, int mb ) { button_mouse_up( calc_buttons, mx, my, mb ); }

View file

@ -2,6 +2,7 @@
#define __PCALC_H #define __PCALC_H
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "types.h" #include "types.h"
typedef struct { typedef struct {
@ -10,12 +11,11 @@ typedef struct {
void ( *up )( bool action ); void ( *up )( bool action );
} KBMapping; } KBMapping;
void pcalc_init(); extern void pcalc_init();
void pcalc_show(); extern void pcalc_show();
void pcalc_hide( void ); extern void pcalc_down( int mx, int my, int mb );
void pcalc_down( int mx, int my, int mb ); extern void pcalc_up( int mx, int my, int mb );
void pcalc_up( int mx, int my, int mb ); extern void pcalc_kb_down( SDL_Keycode sdl_event );
void pcalc_kb_down( SDL_Keycode sdl_event ); extern void pcalc_kb_up( SDL_Keycode sdl_event );
void pcalc_kb_up( SDL_Keycode sdl_event );
#endif #endif

View file

@ -5,7 +5,6 @@
extern char WorkingPath[ 512 ]; extern char WorkingPath[ 512 ];
extern void getExePath();
extern int file_size( char* name ); extern int file_size( char* name );
extern void load_file( char* name ); extern void load_file( char* name );

View file

@ -6,9 +6,9 @@
#define PORT1_SIZE ( 256 * 1024 ) /* 128Kio in nibbles */ #define PORT1_SIZE ( 256 * 1024 ) /* 128Kio in nibbles */
#define PORT2_SIZE ( 256 * 1024 ) /* 128Kio in nibbles */ #define PORT2_SIZE ( 256 * 1024 ) /* 128Kio in nibbles */
void ports_init( void ); extern void ports_init( void );
void ports_exit( void ); extern void ports_exit( void );
void ports_switch_bank( address adr ); extern void ports_switch_bank( address adr );
byte ports_card_detect( void ); extern byte ports_card_detect( void );
#endif #endif

View file

@ -1,7 +1,7 @@
#ifndef __RAM_H #ifndef __RAM_H
#define __RAM_H #define __RAM_H
void ram_init( void ); extern void ram_init( void );
void ram_exit( void ); extern void ram_exit( void );
#endif #endif

View file

@ -12,11 +12,9 @@
void rom_init( void ) void rom_init( void )
{ {
printf( "rom_init..\n" );
int size; int size;
char* name = "hpemu.rom"; char* name = "hpemu.rom";
byte *buf, *ptr1, *ptr2; byte *buf, *ptr1, *ptr2;
// PACKFILE *f;
FILE* f; FILE* f;
size = file_size( name ); size = file_size( name );

View file

@ -1,7 +1,7 @@
#ifndef __ROM_H #ifndef __ROM_H
#define __ROM_H #define __ROM_H
void rom_init( void ); extern void rom_init( void );
void rom_exit( void ); extern void rom_exit( void );
#endif #endif

View file

@ -3,9 +3,7 @@
#include "types.h" #include "types.h"
int rpl_object_size( byte* obj ); extern int rpl_object_size( byte* obj );
address rpl_make_temp( address size ); extern int rpl_push_object( byte* obj, address size );
void rpl_push( address adr );
int rpl_push_object( byte* obj, address size );
#endif #endif

View file

@ -8,7 +8,7 @@ extern byte timer2_control;
extern byte timer1_value; extern byte timer1_value;
extern dword timer2_value; extern dword timer2_value;
void timer1_update( void ); extern void timer1_update( void );
void timer2_update( void ); extern void timer2_update( void );
#endif #endif