another big code-shuffling files-renaming moment

This commit is contained in:
Gwenhael Le Moine 2023-09-15 17:42:29 +02:00
parent 5bf401d8c9
commit de336e4821
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
19 changed files with 576 additions and 588 deletions

View file

@ -21,18 +21,18 @@ ifeq ($(FULL_WARNINGS), yes)
CFLAGS += -Wall -Wextra -Wpedantic -Wno-unused-parameter -Wno-unused-function -Wconversion -Wdouble-promotion -Wno-sign-conversion -fsanitize=undefined -fsanitize-trap
endif
DOTOS = src/main.o \
src/hp48_emulate.o \
src/hp48_init.o \
src/hp48_serial.o \
src/hp48emu_actions.o \
src/hp48emu_memory.o \
src/hp48emu_register.o \
DOTOS = src/emu_serial.o \
src/emu_emulate.o \
src/emu_init.o \
src/emu_actions.o \
src/emu_memory.o \
src/emu_register.o \
src/emu_timer.o \
src/options.o \
src/romio.o \
src/timer.o \
src/error_handling.o \
src/ui_sdl.o
src/ui_sdl.o \
src/main.o
### debugger
DOTOS += src/debugger.o \

View file

@ -8,10 +8,9 @@
#include <readline/readline.h>
#include "options.h"
#include "hp48.h"
#include "emulator.h"
#include "romio.h"
#include "timer.h"
#include "ui.h" /* init_display(); update_display(); */
#include "ui.h" /* ui__init_LCD(); ui__update_LCD(); */
#include "debugger.h"
#define MAX_ARGS 16
@ -56,23 +55,23 @@ bkpt_tbl[ MAX_BREAKPOINTS + 1 ];
/*
* command functions
*/
static void do_break( int, char** );
static void do_continue( int, char** );
static void do_delete( int, char** );
static void do_exit( int, char** );
static void do_go( int, char** );
static void do_help( int, char** );
static void do_load( int, char** );
static void do_mode( int, char** );
static void do_quit( int, char** );
static void do_regs( int, char** );
static void do_save( int, char** );
static void do_stack( int, char** );
static void do_stat( int, char** );
static void do_step( int, char** );
static void do_ram( int, char** );
static void do_reset( int, char** );
static void do_rstk( int, char** );
static void cmd_break( int, char** );
static void cmd_continue( int, char** );
static void cmd_delete( int, char** );
static void cmd_exit( int, char** );
static void cmd_go( int, char** );
static void cmd_help( int, char** );
static void cmd_load( int, char** );
static void cmd_mode( int, char** );
static void cmd_quit( int, char** );
static void cmd_regs( int, char** );
static void cmd_save( int, char** );
static void cmd_stack( int, char** );
static void cmd_stat( int, char** );
static void cmd_step( int, char** );
static void cmd_ram( int, char** );
static void cmd_reset( int, char** );
static void cmd_rstk( int, char** );
struct cmd {
const char* name;
@ -81,61 +80,61 @@ struct cmd {
}
cmd_tbl[] = {
{ "break", do_break,
{ "break", cmd_break,
"break [address] Set breakpoint at `address\' or show "
"breakpoints" },
{ "b", do_break, 0 },
{ "b", cmd_break, 0 },
{ "cont", do_continue, "cont Continue execution" },
{ "c", do_continue, 0 },
{ "cont", cmd_continue, "cont Continue execution" },
{ "c", cmd_continue, 0 },
{ "delete", do_delete,
{ "delete", cmd_delete,
"delete [all | n] Delete breakpoint or watchpoint number "
"`n\',\n all breakpoints, or current "
"breakpoint" },
{ "d", do_delete, 0 },
{ "d", cmd_delete, 0 },
{ "exit", do_exit,
{ "exit", cmd_exit,
"exit Exit the emulator without saving" },
{ "go", do_go, "go address Set PC to `address\'" },
{ "go", cmd_go, "go address Set PC to `address\'" },
{ "help", do_help, "help Display this information" },
{ "h", do_help, 0 },
{ "?", do_help, 0 },
{ "help", cmd_help, "help Display this information" },
{ "h", cmd_help, 0 },
{ "?", cmd_help, 0 },
{ "load", do_load,
{ "load", cmd_load,
"load Load emulator-state from files" },
{ "mode", do_mode,
{ "mode", cmd_mode,
"mode [hp | class] Show or set disassembler mode" },
{ "quit", do_quit,
{ "quit", cmd_quit,
"quit Exit the emulator after saving its state" },
{ "q", do_quit, 0 },
{ "q", cmd_quit, 0 },
{ "ram", do_ram, "ram Show RAM layout" },
{ "ram", cmd_ram, "ram Show RAM layout" },
{ "reg", do_regs,
{ "reg", cmd_regs,
"reg [register [hexvalue]] Display or set register value" },
{ "r", do_regs, 0 },
{ "r", cmd_regs, 0 },
{ "reset", do_reset,
{ "reset", cmd_reset,
"reset Set the HP48\'s PC to ZERO" },
{ "save", do_save,
{ "save", cmd_save,
"save Save emulator-state to files" },
{ "stack", do_stack, "stack Display RPL stack" },
{ "stack", cmd_stack, "stack Display RPL stack" },
{ "stat", do_stat,
{ "stat", cmd_stat,
"stat Display statistics for the emulator" },
{ "step", do_step,
{ "step", cmd_step,
"step [n] Step one or n Instruction(s)" },
{ "s", do_step, 0 },
{ "s", cmd_step, 0 },
{ "where", do_rstk, "where Show ML return stack" },
{ "where", cmd_rstk, "where Show ML return stack" },
{ 0, 0, 0 } };
@ -341,7 +340,7 @@ static int confirm( const char* prompt ) {
}
}
static void do_break( int argc, char** argv ) {
static void cmd_break( int argc, char** argv ) {
int i;
word_20 addr;
@ -379,9 +378,9 @@ static void do_break( int argc, char** argv ) {
}
}
static void do_continue( int argc, char** argv ) { continue_flag = 1; }
static void cmd_continue( int argc, char** argv ) { continue_flag = 1; }
static void do_delete( int argc, char** argv ) {
static void cmd_delete( int argc, char** argv ) {
int num;
if ( argc == 1 ) {
@ -440,14 +439,14 @@ static void do_delete( int argc, char** argv ) {
}
}
static void do_exit( int argc, char** argv ) {
static void cmd_exit( int argc, char** argv ) {
if ( confirm( "Exit the emulator WITHOUT saving its state?" ) ) {
printf( "Exit.\n" );
exit( 0 );
}
}
static void do_go( int argc, char** argv ) {
static void cmd_go( int argc, char** argv ) {
word_20 addr;
str_to_upper( argv[ 1 ] );
@ -457,7 +456,7 @@ static void do_go( int argc, char** argv ) {
}
}
static void do_help( int argc, char** argv ) {
static void cmd_help( int argc, char** argv ) {
int i;
for ( i = 0; cmd_tbl[ i ].name; i++ ) {
@ -467,52 +466,57 @@ static void do_help( int argc, char** argv ) {
}
}
static void do_load( int argc, char** argv ) {
static void cmd_load( int argc, char** argv ) {
saturn_t tmp_saturn;
device_t tmp_device;
if ( confirm( "Load emulator-state from files?" ) ) {
memcpy( &tmp_saturn, &saturn, sizeof( saturn ) );
memcpy( &tmp_device, &device, sizeof( device ) );
memset( &saturn, 0, sizeof( saturn ) );
if ( read_files() ) {
printf( "Loading done.\n" );
enter_debugger &= ~ILLEGAL_INSTRUCTION;
if ( tmp_saturn.rom ) {
free( tmp_saturn.rom );
}
if ( tmp_saturn.ram ) {
free( tmp_saturn.ram );
}
if ( tmp_saturn.port1 ) {
free( tmp_saturn.port1 );
}
if ( tmp_saturn.port2 ) {
free( tmp_saturn.port2 );
}
init_display();
update_display();
} else {
printf( "Loading emulator-state from files failed.\n" );
if ( saturn.rom ) {
free( saturn.rom );
}
if ( saturn.ram ) {
free( saturn.ram );
}
if ( saturn.port1 ) {
free( saturn.port1 );
}
if ( saturn.port2 ) {
free( saturn.port2 );
}
memcpy( &saturn, &tmp_saturn, sizeof( saturn ) );
memcpy( &device, &tmp_device, sizeof( device ) );
}
if ( !confirm( "Load emulator-state from files?" ) )
return;
memcpy( &tmp_saturn, &saturn, sizeof( saturn ) );
memcpy( &tmp_device, &device, sizeof( device ) );
memset( &saturn, 0, sizeof( saturn ) );
if ( read_files() ) {
printf( "Loading done.\n" );
enter_debugger &= ~ILLEGAL_INSTRUCTION;
if ( tmp_saturn.rom )
free( tmp_saturn.rom );
if ( tmp_saturn.ram )
free( tmp_saturn.ram );
if ( tmp_saturn.port1 )
free( tmp_saturn.port1 );
if ( tmp_saturn.port2 )
free( tmp_saturn.port2 );
/* After reloading state we need to refresh the UI's LCD */
ui__init_LCD();
ui__update_LCD();
} else {
printf( "Loading emulator-state from files failed.\n" );
if ( saturn.rom )
free( saturn.rom );
if ( saturn.ram )
free( saturn.ram );
if ( saturn.port1 )
free( saturn.port1 );
if ( saturn.port2 )
free( saturn.port2 );
memcpy( &saturn, &tmp_saturn, sizeof( saturn ) );
memcpy( &device, &tmp_device, sizeof( device ) );
}
}
static void do_mode( int argc, char** argv ) {
static void cmd_mode( int argc, char** argv ) {
if ( argc < 2 ) {
printf( "Disassembler uses %s mnemonics.\n",
mode_name[ disassembler_mode ] );
@ -529,7 +533,7 @@ static void do_mode( int argc, char** argv ) {
}
}
static void do_quit( int argc, char** argv ) {
static void cmd_quit( int argc, char** argv ) {
if ( confirm( "Quit the emulator and save its state?" ) ) {
printf( "Exit.\n" );
exit_emulator();
@ -625,7 +629,7 @@ static const char* mctl_str_gx[] = { "MMIO ", "SysRAM ",
static const char* mctl_str_sx[] = { "MMIO ", "SysRAM", "Port 1",
"Port 2", "Extra ", "SysROM" };
static void do_ram( int argc, char** argv ) {
static void cmd_ram( int argc, char** argv ) {
int i;
for ( i = 0; i < 5; i++ ) {
@ -646,7 +650,7 @@ static void do_ram( int argc, char** argv ) {
printf( "Port 2 switched to bank %d\n", saturn.bank_switch );
}
static void do_regs( int argc, char** argv ) {
static void cmd_regs( int argc, char** argv ) {
int i;
word_64 val;
@ -818,7 +822,7 @@ static void do_regs( int argc, char** argv ) {
}
}
static void do_save( int argc, char** argv ) {
static void cmd_save( int argc, char** argv ) {
if ( write_files() ) {
printf( "Saving done.\n" );
} else {
@ -881,7 +885,7 @@ char* get_stack( void ) {
return "";
}
static void do_stack( int argc, char** argv ) {
static void cmd_stack( int argc, char** argv ) {
word_20 dsktop, dskbot;
word_20 sp = 0, end = 0, ent = 0;
word_20 ram_base, ram_mask;
@ -951,13 +955,13 @@ static void do_stack( int argc, char** argv ) {
saturn.mem_cntl[ 1 ].config[ 1 ] = ram_mask;
}
static void do_stat( int argc, char** argv ) {
static void cmd_stat( int argc, char** argv ) {
printf( "Instructions/s: %ld\n", saturn.i_per_s );
printf( "Timer 1 I/TICK: %d\n", saturn.t1_tick );
printf( "Timer 2 I/TICK: %d\n", saturn.t2_tick );
}
static void do_step( int argc, char** argv ) {
static void cmd_step( int argc, char** argv ) {
word_20 next_instr;
word_32 n;
int leave;
@ -1020,14 +1024,14 @@ static void do_step( int argc, char** argv ) {
}
}
static void do_reset( int argc, char** argv ) {
static void cmd_reset( int argc, char** argv ) {
if ( confirm( "Do a RESET (PC = 00000)?" ) ) {
saturn.PC = 0;
enter_debugger &= ~ILLEGAL_INSTRUCTION;
}
}
static void do_rstk( int argc, char** argv ) {
static void cmd_rstk( int argc, char** argv ) {
int i, j;
disassemble( saturn.PC, instr );
@ -1085,7 +1089,7 @@ int debug( void ) {
*/
if ( device.display_touched ) {
device.display_touched = 0;
update_display();
ui__update_LCD();
}
/*

View file

@ -1,7 +1,7 @@
#ifndef _DEBUGGER_H
#define _DEBUGGER_H 1
#include "hp48.h"
#include "emulator.h"
#define USER_INTERRUPT 1
#define ILLEGAL_INSTRUCTION 2

View file

@ -2,7 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include "hp48.h"
#include "emulator.h"
#include "debugger.h"
#define TAB_SKIP 8

View file

@ -3,8 +3,7 @@
#include <string.h>
#include <unistd.h>
#include "hp48.h"
#include "hp48emu.h"
#include "emulator.h"
#include "romio.h"
#include "debugger.h"

View file

@ -2,11 +2,9 @@
#include <stdlib.h>
#include <unistd.h>
#include "hp48.h"
#include "hp48emu.h"
#include "emulator.h"
#include "romio.h"
#include "timer.h"
#include "ui.h" /* get_ui_event(); update_display(); */
#include "ui.h" /* ui__get_event(); ui__update_LCD(); */
#include "debugger.h" /* in_debugger, enter_debugger */
@ -253,12 +251,12 @@ int get_identification( void ) {
}
void do_shutdown( void ) {
int wake, alarms;
int wake;
t1_t2_ticks ticks;
if ( device.display_touched ) {
device.display_touched = 0;
update_display();
ui__update_LCD();
}
stop_timer( RUN_TIMER );
@ -274,8 +272,6 @@ void do_shutdown( void ) {
else
wake = 0;
alarms = 0;
do {
pause();
@ -291,7 +287,7 @@ void do_shutdown( void ) {
set_t1 = ticks.t1_ticks;
interrupt_called = 0;
if ( get_ui_event() && interrupt_called )
if ( ui__get_event() && interrupt_called )
wake = 1;
if ( saturn.timer2 <= 0 ) {
@ -323,8 +319,6 @@ void do_shutdown( void ) {
if ( interrupt_called )
wake = 1;
}
alarms++;
}
if ( enter_debugger )

View file

@ -4,10 +4,8 @@
#include <sys/time.h>
#include "options.h" /* throttle */
#include "hp48.h" /* word_20; register_to_address(); exchange_reg(); add_address(); store(); recall(); store_n(); recall_n(); */
#include "hp48emu.h"
#include "timer.h"
#include "ui.h" /* get_ui_event(); adjust_contrast(); update_display(); draw_annunc(); */
#include "emulator.h" /* word_20; register_to_address(); exchange_reg(); add_address(); store(); recall(); store_n(); recall_n(); */
#include "ui.h" /* ui__get_event(); ui__adjust_contrast(); ui__update_LCD(); ui__draw_annunc(); */
#include "debugger.h" /* enter_debugger, TRAP_INSTRUCTION, ILLEGAL_INSTRUCTION */
static long jumpaddr;
@ -2271,7 +2269,7 @@ inline void schedule( void ) {
/* UI */
if ( device.display_touched > 0 && device.display_touched-- == 1 ) {
device.display_touched = 0;
update_display();
ui__update_LCD();
}
if ( device.display_touched > 0 )
@ -2279,12 +2277,12 @@ inline void schedule( void ) {
if ( device.contrast_touched ) {
device.contrast_touched = 0;
adjust_contrast();
ui__adjust_contrast();
}
if ( device.ann_touched ) {
device.ann_touched = 0;
draw_annunc();
ui__draw_annunc();
}
/* serial */
@ -2432,7 +2430,7 @@ inline void schedule( void ) {
if ( got_alarm ) {
got_alarm = 0;
get_ui_event();
ui__get_event();
}
}

View file

@ -8,8 +8,7 @@
#include <sys/types.h>
#include "options.h"
#include "hp48.h"
#include "hp48emu.h" /* dev_memory_init(); */
#include "emulator.h"
#include "romio.h"
#define X48_MAGIC 0x48503438
@ -101,7 +100,7 @@ void init_saturn( void ) {
dev_memory_init();
}
int init_emulator( void ) {
int emulator__init( void ) {
if ( !initialize && read_files() ) {
if ( resetOnStartup )
saturn.PC = 0x00000;

View file

@ -4,10 +4,9 @@
#include <sys/time.h>
#include <unistd.h>
#include "hp48.h"
#include "hp48emu.h"
#include "emulator.h"
#include "romio.h"
#include "ui.h" /* disp; disp_draw_nibble(); menu_draw_nibble(); */
#include "ui.h" /* disp; ui__disp_draw_nibble(); ui__menu_draw_nibble(); */
#include "options.h"
#define MCTL_MMIO_SX 0
@ -495,12 +494,12 @@ void write_nibble_sx( long addr, int val ) {
if ( device.display_touched || !disp.mapped )
return;
if ( addr >= display.disp_start && addr < display.disp_end ) {
disp_draw_nibble( addr, val );
ui__disp_draw_nibble( addr, val );
}
if ( display.lines == 63 )
return;
if ( addr >= display.menu_start && addr < display.menu_end ) {
menu_draw_nibble( addr, val );
ui__menu_draw_nibble( addr, val );
}
}
@ -686,12 +685,12 @@ void write_nibble_gx( long addr, int val ) {
if ( device.display_touched || !disp.mapped )
return;
if ( addr >= display.disp_start && addr < display.disp_end ) {
disp_draw_nibble( addr, val );
ui__disp_draw_nibble( addr, val );
}
if ( display.lines == 63 )
return;
if ( addr >= display.menu_start && addr < display.menu_end ) {
menu_draw_nibble( addr, val );
ui__menu_draw_nibble( addr, val );
}
}

View file

@ -1,8 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "hp48.h"
#include "hp48emu.h"
#include "emulator.h"
extern long nibble_masks[ 16 ];

View file

@ -8,8 +8,7 @@
#include <unistd.h>
#include "options.h"
#include "hp48.h"
#include "hp48emu.h"
#include "emulator.h"
static int wire_fd;
static int ir_fd;
@ -33,7 +32,7 @@ void update_connection_display( void ) {
}
}
int serial_init( void ) {
int serial__init( void ) {
int c;
int n;
char tty_dev_name[ 128 ];

View file

@ -7,7 +7,7 @@
#include <sys/time.h>
#include "romio.h"
#include "timer.h"
#include "emulator.h"
#include "debugger.h" /* used for in_debugger */
typedef struct x48_timer_t {

387
src/emulator.h Normal file
View file

@ -0,0 +1,387 @@
#ifndef _HP48_H
#define _HP48_H 1
#include <stdint.h> /* int64_t */
#define NR_MCTL 6
#define P_FIELD 0 /* unused? */
#define WP_FIELD 1 /* unused? */
#define XS_FIELD 2 /* unused? */
#define X_FIELD 3 /* unused? */
#define S_FIELD 4 /* unused? */
#define M_FIELD 5 /* unused? */
#define B_FIELD 6 /* unused? */
#define W_FIELD 7
#define A_FIELD 15
#define IN_FIELD 16
#define OUT_FIELD 17
#define OUTS_FIELD 18
#define DEC 10
#define HEX 16
#define NR_RSTK 8
#define NR_PSTAT 16
#define NR_TIMERS 4
#define T1_TIMER 0
#define T2_TIMER 1 /* unused? */
#define RUN_TIMER 2
#define IDLE_TIMER 3
typedef struct t1_t2_ticks {
unsigned long t1_ticks;
unsigned long t2_ticks;
} t1_t2_ticks;
typedef struct device_t {
int display_touched;
char contrast_touched;
char disp_test_touched;
char crc_touched;
char power_status_touched;
char power_ctrl_touched;
char mode_touched;
char ann_touched;
char baud_touched;
char card_ctrl_touched;
char card_status_touched;
char ioc_touched;
char tcs_touched;
char rcs_touched;
char rbr_touched;
char tbr_touched;
char sreq_touched;
char ir_ctrl_touched;
char base_off_touched;
char lcr_touched;
char lbr_touched;
char scratch_touched;
char base_nibble_touched;
char unknown_touched;
char t1_ctrl_touched;
char t2_ctrl_touched;
char unknown2_touched;
char t1_touched;
char t2_touched;
} device_t;
typedef unsigned char word_1;
typedef unsigned char word_4;
typedef unsigned char word_8;
typedef unsigned short word_12;
typedef unsigned short word_16;
typedef long word_20;
typedef long word_32;
typedef int64_t word_64;
typedef struct keystate_t {
short rows[ 9 ];
} keystate_t;
typedef struct display_t {
int on;
long disp_start;
long disp_end;
int offset;
int lines;
int nibs_per_line;
int contrast;
long menu_start;
long menu_end;
int annunc;
} display_t;
typedef struct mem_cntl_t {
unsigned short unconfigured;
word_20 config[ 2 ];
} mem_cntl_t;
typedef struct saturn_t {
unsigned long magic;
char version[ 3 ];
unsigned char A[ 16 ], B[ 16 ], C[ 16 ], D[ 16 ];
word_20 d[ 2 ];
#define D0 d[ 0 ]
#define D1 d[ 1 ]
word_4 P;
word_20 PC;
unsigned char R0[ 16 ], R1[ 16 ], R2[ 16 ], R3[ 16 ], R4[ 16 ];
unsigned char IN[ 4 ];
unsigned char OUT[ 3 ];
word_1 CARRY;
unsigned char PSTAT[ NR_PSTAT ];
unsigned char XM, SB, SR, MP;
word_4 hexmode;
word_20 rstk[ NR_RSTK ];
short rstkp;
keystate_t keybuf;
unsigned char intenable;
unsigned char int_pending;
unsigned char kbd_ien;
word_4 disp_io;
word_4 contrast_ctrl;
word_8 disp_test;
word_16 crc;
word_4 power_status;
word_4 power_ctrl;
word_4 mode;
word_8 annunc;
word_4 baud;
word_4 card_ctrl;
word_4 card_status;
word_4 io_ctrl;
word_4 rcs;
word_4 tcs;
word_8 rbr;
word_8 tbr;
word_8 sreq;
word_4 ir_ctrl;
word_4 base_off;
word_4 lcr;
word_4 lbr;
word_4 scratch;
word_4 base_nibble;
word_20 disp_addr;
word_12 line_offset;
word_8 line_count;
word_16 unknown;
word_4 t1_ctrl;
word_4 t2_ctrl;
word_20 menu_addr;
word_8 unknown2;
char timer1; /* may NOT be unsigned !!! */
word_32 timer2;
long t1_instr;
long t2_instr;
short t1_tick;
short t2_tick;
long i_per_s;
word_16 bank_switch;
mem_cntl_t mem_cntl[ NR_MCTL ];
unsigned char* rom;
unsigned char* ram;
unsigned char* port1;
unsigned char* port2;
} saturn_t;
#define NIBBLES_PER_ROW 0x22
extern int got_alarm;
extern int set_t1;
extern long sched_timer1;
extern long sched_timer2;
extern int adj_time_pending;
extern long sched_adjtime;
extern long schedule_event;
extern char* wire_name;
extern char* ir_name;
extern device_t device;
extern display_t display;
extern saturn_t saturn;
/**************/
/* emu_init.c */
/**************/
extern int emulator__init( void );
void init_saturn( void );
int exit_emulator( void );
int read_rom( const char* fname );
int read_files( void );
int write_files( void );
/***************/
/* emu_timer.c */
/***************/
extern void reset_timer( int timer );
extern void start_timer( int timer );
extern void restart_timer( int timer );
extern void stop_timer( int timer );
extern word_64 get_timer( int timer );
extern t1_t2_ticks get_t1_t2( void );
extern void set_accesstime( void );
/********************/
/* hp48emu_memory.c */
/********************/
extern void ( *write_nibble )( long addr, int val );
extern int ( *read_nibble )( long addr );
extern int ( *read_nibble_crc )( long addr );
/****************/
/* emu_memory.c */
/****************/
extern long read_nibbles( long addr, int len );
void write_nibbles( long addr, long val, int len );
extern void dev_memory_init( void ); /* */
/*****************/
/* emu_actions.c */
/*****************/
void push_return_addr( long addr );
long pop_return_addr( void );
void register_to_status( unsigned char* r );
void status_to_register( unsigned char* r );
void swap_register_status( unsigned char* r );
void clear_status( void );
void set_program_stat( int n );
void clear_program_stat( int n );
int get_program_stat( int n );
void set_hardware_stat( int op );
void clear_hardware_stat( int op );
int is_zero_hardware_stat( int op );
void set_register_bit( unsigned char* reg, int n );
void clear_register_bit( unsigned char* reg, int n );
int get_register_bit( unsigned char* reg, int n );
void set_register_nibble( unsigned char* reg, int n, unsigned char val );
unsigned char get_register_nibble( unsigned char* reg, int n );
void register_to_address( unsigned char* reg, word_20* dat, int s );
void address_to_register( word_20 dat, unsigned char* reg, int s );
void add_address( word_20* dat, int add );
char* make_hexstr( long addr, int n );
void load_constant( unsigned char* reg, int n, long addr );
void load_address( unsigned char* reg, long addr, int n );
void store( word_20 dat, unsigned char* reg, int code );
void store_n( word_20 dat, unsigned char* reg, int n );
void recall( unsigned char* reg, word_20 dat, int code );
void recall_n( unsigned char* reg, word_20 dat, int n );
long dat_to_addr( unsigned char* dat );
void addr_to_dat( long addr, unsigned char* dat );
extern void do_kbd_int( void );
void do_interupt( void );
void do_in( void );
void do_reset( void );
void do_configure( void );
void do_unconfigure( void );
void do_inton( void );
void do_intoff( void );
void do_return_interupt( void );
void do_reset_interrupt_system( void );
void do_shutdown( void );
int get_identification( void );
/******************/
/* emu_register.c */
/******************/
void add_p_plus_one( unsigned char* r );
void add_register_constant( unsigned char* res, int code, int val );
void sub_register_constant( unsigned char* res, int code, int val );
void add_register( unsigned char* res, unsigned char* r1, unsigned char* r2,
int code );
void sub_register( unsigned char* res, unsigned char* r1, unsigned char* r2,
int code );
void complement_2_register( unsigned char* r, int code );
void complement_1_register( unsigned char* r, int code );
void inc_register( unsigned char* r, int code );
void dec_register( unsigned char* r, int code );
void zero_register( unsigned char* r, int code );
void or_register( unsigned char* res, unsigned char* r1, unsigned char* r2,
int code );
void and_register( unsigned char* res, unsigned char* r1, unsigned char* r2,
int code );
void copy_register( unsigned char* to, unsigned char* from, int code );
void exchange_register( unsigned char* r1, unsigned char* r2, int code );
void exchange_reg( unsigned char* r, word_20* d, int code );
void shift_left_register( unsigned char* r, int code );
void shift_left_circ_register( unsigned char* r, int code );
void shift_right_register( unsigned char* r, int code );
void shift_right_circ_register( unsigned char* r, int code );
void shift_right_bit_register( unsigned char* r, int code );
extern int is_zero_register( unsigned char* r, int code );
int is_not_zero_register( unsigned char* r, int code );
int is_equal_register( unsigned char* r1, unsigned char* r2, int code );
int is_not_equal_register( unsigned char* r1, unsigned char* r2, int code );
int is_less_register( unsigned char* r1, unsigned char* r2, int code );
int is_less_or_equal_register( unsigned char* r1, unsigned char* r2, int code );
int is_greater_register( unsigned char* r1, unsigned char* r2, int code );
int is_greater_or_equal_register( unsigned char* r1, unsigned char* r2,
int code );
/****************/
/* emu_serial.c */
/****************/
extern int serial__init( void );
extern void serial_baud( int baud );
extern void transmit_char( void );
extern void receive_char( void );
/*****************/
/* emu_emulate.c */
/*****************/
extern void emulate( void );
int step_instruction( void );
void schedule( void );
void load_addr( word_20* dat, long addr, int n );
#endif /* !_HP48_H */

View file

@ -1,274 +0,0 @@
#ifndef _HP48_H
#define _HP48_H 1
#include <stdint.h> /* int64_t */
#define NR_MCTL 6
#define P_FIELD 0 /* unused? */
#define WP_FIELD 1 /* unused? */
#define XS_FIELD 2 /* unused? */
#define X_FIELD 3 /* unused? */
#define S_FIELD 4 /* unused? */
#define M_FIELD 5 /* unused? */
#define B_FIELD 6 /* unused? */
#define W_FIELD 7
#define A_FIELD 15
#define IN_FIELD 16
#define OUT_FIELD 17
#define OUTS_FIELD 18
#define DEC 10
#define HEX 16
#define NR_RSTK 8
#define NR_PSTAT 16
typedef struct device_t {
int display_touched;
char contrast_touched;
char disp_test_touched;
char crc_touched;
char power_status_touched;
char power_ctrl_touched;
char mode_touched;
char ann_touched;
char baud_touched;
char card_ctrl_touched;
char card_status_touched;
char ioc_touched;
char tcs_touched;
char rcs_touched;
char rbr_touched;
char tbr_touched;
char sreq_touched;
char ir_ctrl_touched;
char base_off_touched;
char lcr_touched;
char lbr_touched;
char scratch_touched;
char base_nibble_touched;
char unknown_touched;
char t1_ctrl_touched;
char t2_ctrl_touched;
char unknown2_touched;
char t1_touched;
char t2_touched;
} device_t;
typedef unsigned char word_1;
typedef unsigned char word_4;
typedef unsigned char word_8;
typedef unsigned short word_12;
typedef unsigned short word_16;
typedef long word_20;
typedef long word_32;
typedef int64_t word_64;
typedef struct keystate_t {
short rows[ 9 ];
} keystate_t;
typedef struct display_t {
int on;
long disp_start;
long disp_end;
int offset;
int lines;
int nibs_per_line;
int contrast;
long menu_start;
long menu_end;
int annunc;
} display_t;
typedef struct mem_cntl_t {
unsigned short unconfigured;
word_20 config[ 2 ];
} mem_cntl_t;
typedef struct saturn_t {
unsigned long magic;
char version[ 3 ];
unsigned char A[ 16 ], B[ 16 ], C[ 16 ], D[ 16 ];
word_20 d[ 2 ];
#define D0 d[ 0 ]
#define D1 d[ 1 ]
word_4 P;
word_20 PC;
unsigned char R0[ 16 ], R1[ 16 ], R2[ 16 ], R3[ 16 ], R4[ 16 ];
unsigned char IN[ 4 ];
unsigned char OUT[ 3 ];
word_1 CARRY;
unsigned char PSTAT[ NR_PSTAT ];
unsigned char XM, SB, SR, MP;
word_4 hexmode;
word_20 rstk[ NR_RSTK ];
short rstkp;
keystate_t keybuf;
unsigned char intenable;
unsigned char int_pending;
unsigned char kbd_ien;
word_4 disp_io;
word_4 contrast_ctrl;
word_8 disp_test;
word_16 crc;
word_4 power_status;
word_4 power_ctrl;
word_4 mode;
word_8 annunc;
word_4 baud;
word_4 card_ctrl;
word_4 card_status;
word_4 io_ctrl;
word_4 rcs;
word_4 tcs;
word_8 rbr;
word_8 tbr;
word_8 sreq;
word_4 ir_ctrl;
word_4 base_off;
word_4 lcr;
word_4 lbr;
word_4 scratch;
word_4 base_nibble;
word_20 disp_addr;
word_12 line_offset;
word_8 line_count;
word_16 unknown;
word_4 t1_ctrl;
word_4 t2_ctrl;
word_20 menu_addr;
word_8 unknown2;
char timer1; /* may NOT be unsigned !!! */
word_32 timer2;
long t1_instr;
long t2_instr;
short t1_tick;
short t2_tick;
long i_per_s;
word_16 bank_switch;
mem_cntl_t mem_cntl[ NR_MCTL ];
unsigned char* rom;
unsigned char* ram;
unsigned char* port1;
unsigned char* port2;
} saturn_t;
#define NIBBLES_PER_ROW 0x22
extern int got_alarm;
extern int set_t1;
extern long sched_timer1;
extern long sched_timer2;
extern int adj_time_pending;
extern long sched_adjtime;
extern long schedule_event;
extern char* wire_name;
extern char* ir_name;
extern device_t device;
extern display_t display;
extern saturn_t saturn;
/***************/
/* hp48_init.c */
/***************/
void init_saturn( void );
extern int init_emulator( void );
int exit_emulator( void );
int read_rom( const char* fname );
int read_files( void );
int write_files( void );
/*****************/
/* hp48_serial.c */
/*****************/
extern int serial_init( void );
void serial_baud( int baud );
void transmit_char( void );
void receive_char( void );
/********************/
/* hp48emu_memory.c */
/********************/
extern void ( *write_nibble )( long addr, int val );
extern int ( *read_nibble )( long addr );
extern int ( *read_nibble_crc )( long addr );
/******************/
/* hp48_emulate.c */
/******************/
void emulate( void );
int step_instruction( void );
void schedule( void );
void load_addr( word_20* dat, long addr, int n );
#endif /* !_HP48_H */

View file

@ -1,95 +0,0 @@
#ifndef _HP48_EMU_H
#define _HP48_EMU_H 1
#include "hp48.h" /* word_20 */
/********************/
/* hp48emu_memory.c */
/********************/
long read_nibbles( long addr, int len );
void write_nibbles( long addr, long val, int len );
extern void dev_memory_init( void ); /* */
/*********************/
/* hp48emu_actions.c */
/*********************/
void push_return_addr( long addr );
long pop_return_addr( void );
void register_to_status( unsigned char* r );
void status_to_register( unsigned char* r );
void swap_register_status( unsigned char* r );
void clear_status( void );
void set_program_stat( int n );
void clear_program_stat( int n );
int get_program_stat( int n );
void set_hardware_stat( int op );
void clear_hardware_stat( int op );
int is_zero_hardware_stat( int op );
void set_register_bit( unsigned char* reg, int n );
void clear_register_bit( unsigned char* reg, int n );
int get_register_bit( unsigned char* reg, int n );
void set_register_nibble( unsigned char* reg, int n, unsigned char val );
unsigned char get_register_nibble( unsigned char* reg, int n );
void register_to_address( unsigned char* reg, word_20* dat, int s );
void address_to_register( word_20 dat, unsigned char* reg, int s );
void add_address( word_20* dat, int add );
char* make_hexstr( long addr, int n );
void load_constant( unsigned char* reg, int n, long addr );
void load_address( unsigned char* reg, long addr, int n );
void store( word_20 dat, unsigned char* reg, int code );
void store_n( word_20 dat, unsigned char* reg, int n );
void recall( unsigned char* reg, word_20 dat, int code );
void recall_n( unsigned char* reg, word_20 dat, int n );
long dat_to_addr( unsigned char* dat );
void addr_to_dat( long addr, unsigned char* dat );
extern void do_kbd_int( void );
void do_interupt( void );
void do_in( void );
void do_reset( void );
void do_configure( void );
void do_unconfigure( void );
void do_inton( void );
void do_intoff( void );
void do_return_interupt( void );
void do_reset_interrupt_system( void );
void do_shutdown( void );
int get_identification( void );
/**********************/
/* hp48emu_register.c */
/**********************/
void add_p_plus_one( unsigned char* r );
void add_register_constant( unsigned char* res, int code, int val );
void sub_register_constant( unsigned char* res, int code, int val );
void add_register( unsigned char* res, unsigned char* r1, unsigned char* r2,
int code );
void sub_register( unsigned char* res, unsigned char* r1, unsigned char* r2,
int code );
void complement_2_register( unsigned char* r, int code );
void complement_1_register( unsigned char* r, int code );
void inc_register( unsigned char* r, int code );
void dec_register( unsigned char* r, int code );
void zero_register( unsigned char* r, int code );
void or_register( unsigned char* res, unsigned char* r1, unsigned char* r2,
int code );
void and_register( unsigned char* res, unsigned char* r1, unsigned char* r2,
int code );
void copy_register( unsigned char* to, unsigned char* from, int code );
void exchange_register( unsigned char* r1, unsigned char* r2, int code );
void exchange_reg( unsigned char* r, word_20* d, int code );
void shift_left_register( unsigned char* r, int code );
void shift_left_circ_register( unsigned char* r, int code );
void shift_right_register( unsigned char* r, int code );
void shift_right_circ_register( unsigned char* r, int code );
void shift_right_bit_register( unsigned char* r, int code );
int is_zero_register( unsigned char* r, int code );
int is_not_zero_register( unsigned char* r, int code );
int is_equal_register( unsigned char* r1, unsigned char* r2, int code );
int is_not_equal_register( unsigned char* r1, unsigned char* r2, int code );
int is_less_register( unsigned char* r1, unsigned char* r2, int code );
int is_less_or_equal_register( unsigned char* r1, unsigned char* r2, int code );
int is_greater_register( unsigned char* r1, unsigned char* r2, int code );
int is_greater_or_equal_register( unsigned char* r1, unsigned char* r2,
int code );
#endif /* !_HP48_EMU_H */

View file

@ -10,9 +10,9 @@
#include <locale.h>
#include "options.h"
#include "hp48.h"
#include "ui.h" /* SDLInit(); SDLCreateHP(); init_display(); */
#include "emulator.h"
#include "debugger.h"
#include "ui.h" /* ui__init(); */
void signal_handler( int sig ) {
switch ( sig ) {
@ -90,22 +90,12 @@ int main( int argc, char** argv ) {
flags &= ~O_NONBLOCK;
fcntl( STDIN_FILENO, F_SETFL, flags );
/*
* initialize emulator stuff
*/
init_emulator();
serial_init();
// SDL Initialization
SDLInit();
/*
* Create the HP-48 window
*/
SDLCreateHP();
init_display();
/*****************************/
/* initialize emulator stuff */
/*****************************/
emulator__init();
serial__init();
ui__init();
/************************/
/* Start emulation loop */

View file

@ -1,27 +0,0 @@
#ifndef _TIMER_H
#define _TIMER_H 1
#include "hp48.h" /* word_64 */
#define NR_TIMERS 4
#define T1_TIMER 0
#define T2_TIMER 1 /* unused? */
#define RUN_TIMER 2
#define IDLE_TIMER 3
typedef struct t1_t2_ticks {
unsigned long t1_ticks;
unsigned long t2_ticks;
} t1_t2_ticks;
extern void reset_timer( int timer );
extern void start_timer( int timer );
extern void restart_timer( int timer );
extern void stop_timer( int timer );
extern word_64 get_timer( int timer );
extern t1_t2_ticks get_t1_t2( void );
extern void set_accesstime( void );
#endif /* !_TIMER_H */

View file

@ -1,7 +1,7 @@
#ifndef _X48_GUI_H
#define _X48_GUI_H 1
#include "hp48.h" /* word_4; word_20; */
#include "emulator.h" /* word_4; word_20; */
/**************/
/* public API */
@ -15,20 +15,23 @@ typedef struct disp_t {
} disp_t;
extern disp_t disp;
extern void disp_draw_nibble( word_20 addr, word_4 val );
extern void menu_draw_nibble( word_20 addr, word_4 val );
extern void ui__disp_draw_nibble( word_20 addr, word_4 val );
extern void ui__menu_draw_nibble( word_20 addr, word_4 val );
/* used in: hp48emu_actions.c, hp48_emulate.c */
extern int get_ui_event( void );
extern void update_display( void );
extern int ui__get_event( void );
/* used in: hp48emu_actions.c, hp48_emulate.c, debugger.c */
extern void ui__update_LCD( void );
/* used in: hp48_emulate.c */
extern void adjust_contrast();
extern void draw_annunc( void );
extern void ui__adjust_contrast();
extern void ui__draw_annunc( void );
/* used in: debugger.c, ui_sdl.c */
extern void ui__init_LCD( void );
/* used in: main.c */
extern void SDLInit( void );
extern void SDLCreateHP( void );
extern void init_display( void );
extern void ui__init( void );
#endif /* !_X48_GUI_H */

View file

@ -14,10 +14,8 @@
#include "options.h"
#include "error_handling.h"
#include "hp48.h"
#include "hp48emu.h" /* do_kbd_int(); */
#include "emulator.h"
#include "romio.h"
#include "timer.h"
#include "ui.h"
#include "ui_bitmaps.h"
@ -205,7 +203,7 @@ typedef struct SDLWINDOW {
/* Functions' prototypes */
/*************************/
void redraw_annunc( void );
void redraw_display( void );
void redraw_LCD( void );
void ShowConnections();
void SDLDrawAnnunc( char* annunc );
@ -244,6 +242,9 @@ void SDLMessageBox( int w, int h, const char* title, const char* text[],
void SDLEventWaitClickOrKey( void );
void SDLShowInformation( void );
void SDLInit( void );
void SDLCreateHP( void );
disp_t disp;
keypad_t keypad;
@ -1314,11 +1315,11 @@ int button_released( int b ) {
return 0;
}
void adjust_contrast() {
void ui__adjust_contrast() {
SDLCreateColors();
SDLCreateAnnunc();
redraw_display();
redraw_LCD();
redraw_annunc();
}
@ -2944,7 +2945,7 @@ void ShowConnections() {
stringColor( sdlwindow, 10, 240, text, 0xffffffff );
}
int get_ui_event( void ) {
int ui__get_event( void ) {
SDL_Event event;
int hpkey;
int rv;
@ -3172,7 +3173,7 @@ static inline void draw_row( long addr, int row ) {
}
}
void update_display( void ) {
void ui__update_LCD( void ) {
int i, j;
long addr;
static int old_offset = -1;
@ -3218,13 +3219,13 @@ void update_display( void ) {
}
}
void redraw_display( void ) {
void redraw_LCD( void ) {
memset( disp_buf, 0, sizeof( disp_buf ) );
memset( lcd_buffer, 0, sizeof( lcd_buffer ) );
update_display();
ui__update_LCD();
}
void disp_draw_nibble( word_20 addr, word_4 val ) {
void ui__disp_draw_nibble( word_20 addr, word_4 val ) {
long offset;
int x, y;
@ -3250,7 +3251,7 @@ void disp_draw_nibble( word_20 addr, word_4 val ) {
}
}
void menu_draw_nibble( word_20 addr, word_4 val ) {
void ui__menu_draw_nibble( word_20 addr, word_4 val ) {
long offset;
int x, y;
@ -3263,7 +3264,7 @@ void menu_draw_nibble( word_20 addr, word_4 val ) {
}
}
void draw_annunc( void ) {
void ui__draw_annunc( void ) {
int val;
val = display.annunc;
@ -3283,10 +3284,10 @@ void draw_annunc( void ) {
void redraw_annunc( void ) {
last_annunc_state = -1;
draw_annunc();
ui__draw_annunc();
}
void init_display( void ) {
void ui__init_LCD( void ) {
display.on = ( int )( saturn.disp_io & 0x8 ) >> 3;
display.disp_start = ( saturn.disp_addr & 0xffffe );
@ -3322,3 +3323,15 @@ void init_display( void ) {
memset( lcd_buffer, 0xf0, sizeof( lcd_buffer ) );
}
/* \ x48_lcd.c */
void ui__init( void ) {
// SDL Initialization
SDLInit();
/*
* Create the HP-48 window
*/
SDLCreateHP();
ui__init_LCD();
}