diff --git a/src/actions.c b/src/actions.c index 01a18c5..da29daa 100644 --- a/src/actions.c +++ b/src/actions.c @@ -83,21 +83,21 @@ #include #include +#include "debugger.h" +#include "device.h" #include "hp48.h" #include "hp48_emu.h" -#include "device.h" -#include "x48_x11.h" -#include "timer.h" -#include "debugger.h" #include "romio.h" +#include "timer.h" +#include "x48_x11.h" -static int interrupt_called = 0; -extern long nibble_masks[16]; +static int interrupt_called = 0; +extern long nibble_masks[16]; -int got_alarm; +int got_alarm; -int conf_bank1 = 0x00000; -int conf_bank2 = 0x00000; +int conf_bank1 = 0x00000; +int conf_bank2 = 0x00000; void do_in(void) { int i, in, out; @@ -121,17 +121,11 @@ void do_in(void) { } } -void clear_program_stat(int n) { - saturn.PSTAT[n] = 0; -} +void clear_program_stat(int n) { saturn.PSTAT[n] = 0; } -void set_program_stat(int n) { - saturn.PSTAT[n] = 1; -} +void set_program_stat(int n) { saturn.PSTAT[n] = 1; } -int get_program_stat(int n) { - return saturn.PSTAT[n]; -} +int get_program_stat(int n) { return saturn.PSTAT[n]; } void register_to_status(unsigned char *r) { int i; @@ -179,64 +173,55 @@ void set_register_nibble(unsigned char *reg, int n, unsigned char val) { reg[n] = val; } -unsigned char get_register_nibble(unsigned char *reg, int n) { - return reg[n]; -} +unsigned char get_register_nibble(unsigned char *reg, int n) { return reg[n]; } void set_register_bit(unsigned char *reg, int n) { - reg[n/4] |= (1 << (n%4)); + reg[n / 4] |= (1 << (n % 4)); } void clear_register_bit(unsigned char *reg, int n) { - reg[n/4] &= ~(1 << (n%4)); + reg[n / 4] &= ~(1 << (n % 4)); } int get_register_bit(unsigned char *reg, int n) { - return ((int)(reg[n/4] & (1 << (n%4))) > 0)?1:0; + return ((int)(reg[n / 4] & (1 << (n % 4))) > 0) ? 1 : 0; } -short conf_tab_sx[] = { 1, 2, 2, 2, 2, 0 }; -short conf_tab_gx[] = { 1, 2, 2, 2, 2, 0 }; +short conf_tab_sx[] = {1, 2, 2, 2, 2, 0}; +short conf_tab_gx[] = {1, 2, 2, 2, 2, 0}; void do_reset(void) { int i; - for (i = 0; i < 6; i++) - { - if (opt_gx) - saturn.mem_cntl[i].unconfigured = conf_tab_gx[i]; - else - saturn.mem_cntl[i].unconfigured = conf_tab_sx[i]; - saturn.mem_cntl[i].config[0] = 0x0; - saturn.mem_cntl[i].config[1] = 0x0; - } + for (i = 0; i < 6; i++) { + if (opt_gx) + saturn.mem_cntl[i].unconfigured = conf_tab_gx[i]; + else + saturn.mem_cntl[i].unconfigured = conf_tab_sx[i]; + saturn.mem_cntl[i].config[0] = 0x0; + saturn.mem_cntl[i].config[1] = 0x0; + } #ifdef DEBUG_CONFIG fprintf(stderr, "%.5lx: RESET\n", saturn.PC); - for (i = 0; i < 6; i++) - { - if (saturn.mem_cntl[i].unconfigured) - fprintf(stderr, "MEMORY CONTROLLER %d is unconfigured\n", i); - else - fprintf(stderr, "MEMORY CONTROLLER %d is configured to %.5lx, %.5lx\n", - i, saturn.mem_cntl[i].config[0], saturn.mem_cntl[i].config[1]); - } + for (i = 0; i < 6; i++) { + if (saturn.mem_cntl[i].unconfigured) + fprintf(stderr, "MEMORY CONTROLLER %d is unconfigured\n", i); + else + fprintf(stderr, "MEMORY CONTROLLER %d is configured to %.5lx, %.5lx\n", i, + saturn.mem_cntl[i].config[0], saturn.mem_cntl[i].config[1]); + } #endif } -void do_inton(void) { - saturn.kbd_ien = 1; -} +void do_inton(void) { saturn.kbd_ien = 1; } -void do_intoff(void) { - saturn.kbd_ien = 0; -} +void do_intoff(void) { saturn.kbd_ien = 0; } void do_return_interupt(void) { if (saturn.int_pending) { #ifdef DEBUG_INTERRUPT - fprintf(stderr, "PC = %.5lx: RTI SERVICE PENDING INTERRUPT\n", - saturn.PC); + fprintf(stderr, "PC = %.5lx: RTI SERVICE PENDING INTERRUPT\n", saturn.PC); #endif saturn.int_pending = 0; saturn.intenable = 0; @@ -255,7 +240,6 @@ void do_return_interupt(void) { schedule_event = 0; sched_adjtime = 0; } - } } @@ -314,30 +298,27 @@ void do_unconfigure(void) { conf |= saturn.C[i]; } - for (i = 0; i < 6; i++) - { - if (saturn.mem_cntl[i].config[0] == conf) - { - if (opt_gx) - saturn.mem_cntl[i].unconfigured = conf_tab_gx[i]; - else - saturn.mem_cntl[i].unconfigured = conf_tab_sx[i]; - saturn.mem_cntl[i].config[0] = 0x0; - saturn.mem_cntl[i].config[1] = 0x0; - break; - } + for (i = 0; i < 6; i++) { + if (saturn.mem_cntl[i].config[0] == conf) { + if (opt_gx) + saturn.mem_cntl[i].unconfigured = conf_tab_gx[i]; + else + saturn.mem_cntl[i].unconfigured = conf_tab_sx[i]; + saturn.mem_cntl[i].config[0] = 0x0; + saturn.mem_cntl[i].config[1] = 0x0; + break; } + } #ifdef DEBUG_CONFIG fprintf(stderr, "%.5lx: UNCNFG %.5x:\n", saturn.PC, conf); - for (i = 0; i < 6; i++) - { - if (saturn.mem_cntl[i].unconfigured) - fprintf(stderr, "MEMORY CONTROLLER %d is unconfigured\n", i); - else - fprintf(stderr, "MEMORY CONTROLLER %d is configured to %.5lx, %.5lx\n", - i, saturn.mem_cntl[i].config[0], saturn.mem_cntl[i].config[1]); - } + for (i = 0; i < 6; i++) { + if (saturn.mem_cntl[i].unconfigured) + fprintf(stderr, "MEMORY CONTROLLER %d is unconfigured\n", i); + else + fprintf(stderr, "MEMORY CONTROLLER %d is configured to %.5lx, %.5lx\n", i, + saturn.mem_cntl[i].config[0], saturn.mem_cntl[i].config[1]); + } #endif } @@ -351,40 +332,35 @@ void do_configure(void) { conf |= saturn.C[i]; } - for (i = 0; i < 6; i++) - { - if (saturn.mem_cntl[i].unconfigured) - { - saturn.mem_cntl[i].unconfigured--; - saturn.mem_cntl[i].config[saturn.mem_cntl[i].unconfigured] = conf; - break; - } + for (i = 0; i < 6; i++) { + if (saturn.mem_cntl[i].unconfigured) { + saturn.mem_cntl[i].unconfigured--; + saturn.mem_cntl[i].config[saturn.mem_cntl[i].unconfigured] = conf; + break; } + } #ifdef DEBUG_CONFIG fprintf(stderr, "%.5lx: CONFIG %.5lx:\n", saturn.PC, conf); - for (i = 0; i < 6; i++) - { - if (saturn.mem_cntl[i].unconfigured) - fprintf(stderr, "MEMORY CONTROLLER %d is unconfigured\n", i); - else - fprintf(stderr, "MEMORY CONTROLLER %d at %.5lx, %.5lx\n", - i, saturn.mem_cntl[i].config[0], saturn.mem_cntl[i].config[1]); - } + for (i = 0; i < 6; i++) { + if (saturn.mem_cntl[i].unconfigured) + fprintf(stderr, "MEMORY CONTROLLER %d is unconfigured\n", i); + else + fprintf(stderr, "MEMORY CONTROLLER %d at %.5lx, %.5lx\n", i, + saturn.mem_cntl[i].config[0], saturn.mem_cntl[i].config[1]); + } #endif } int get_identification(void) { int i; - static int chip_id[] - = { 0, 0, 0, 0, 0x05, 0xf6, 0x07, 0xf8, 0x01, 0xf2, 0, 0 }; + static int chip_id[] = {0, 0, 0, 0, 0x05, 0xf6, 0x07, 0xf8, 0x01, 0xf2, 0, 0}; int id; - for (i = 0; i < 6; i++) - { - if (saturn.mem_cntl[i].unconfigured) - break; - } + for (i = 0; i < 6; i++) { + if (saturn.mem_cntl[i].unconfigured) + break; + } if (i < 6) id = chip_id[2 * i + (2 - saturn.mem_cntl[i].unconfigured)]; else @@ -392,29 +368,25 @@ int get_identification(void) { #ifdef DEBUG_ID fprintf(stderr, "%.5lx: C=ID, returning: %x\n", saturn.PC, id); - for (i = 0; i < 6; i++) - { - if (saturn.mem_cntl[i].unconfigured == 2) - fprintf(stderr, "MEMORY CONTROLLER %d is unconfigured\n", i); - else if (saturn.mem_cntl[i].unconfigured == 1) - { - if (i == 0) - fprintf(stderr, "MEMORY CONTROLLER %d unconfigured\n", i); - else - fprintf(stderr, "MEMORY CONTROLLER %d configured to ????? %.5lx\n", - i, saturn.mem_cntl[i].config[1]); - } + for (i = 0; i < 6; i++) { + if (saturn.mem_cntl[i].unconfigured == 2) + fprintf(stderr, "MEMORY CONTROLLER %d is unconfigured\n", i); + else if (saturn.mem_cntl[i].unconfigured == 1) { + if (i == 0) + fprintf(stderr, "MEMORY CONTROLLER %d unconfigured\n", i); else - fprintf(stderr, "MEMORY CONTROLLER %d configured to %.5lx, %.5lx\n", - i, saturn.mem_cntl[i].config[0], saturn.mem_cntl[i].config[1]); - } + fprintf(stderr, "MEMORY CONTROLLER %d configured to ????? %.5lx\n", i, + saturn.mem_cntl[i].config[1]); + } else + fprintf(stderr, "MEMORY CONTROLLER %d configured to %.5lx, %.5lx\n", i, + saturn.mem_cntl[i].config[0], saturn.mem_cntl[i].config[1]); + } #endif - for (i = 0; i < 3; i++) - { - saturn.C[i] = id & 0x0f; - id >>= 4; - } + for (i = 0; i < 3; i++) { + saturn.C[i] = id & 0x0f; + id >>= 4; + } return 0; } @@ -426,7 +398,8 @@ void do_shutdown(void) { device.display_touched = 0; update_display(); #ifdef HAVE_XSHM - if (disp.display_update) refresh_display(); + if (disp.display_update) + refresh_display(); #endif } @@ -463,7 +436,8 @@ void do_shutdown(void) { got_alarm = 0; #ifdef HAVE_XSHM - if (disp.display_update) refresh_display(); + if (disp.display_update) + refresh_display(); #endif ticks = get_t1_t2(); @@ -479,34 +453,28 @@ void do_shutdown(void) { wake = 1; } - if (saturn.timer2 <= 0) - { - if (saturn.t2_ctrl & 0x04) - { - wake = 1; - } - if (saturn.t2_ctrl & 0x02) - { - wake = 1; - saturn.t2_ctrl |= 0x08; - do_interupt(); - } + if (saturn.timer2 <= 0) { + if (saturn.t2_ctrl & 0x04) { + wake = 1; } + if (saturn.t2_ctrl & 0x02) { + wake = 1; + saturn.t2_ctrl |= 0x08; + do_interupt(); + } + } - if (saturn.timer1 <= 0) - { - saturn.timer1 &= 0x0f; - if (saturn.t1_ctrl & 0x04) - { - wake = 1; - } - if (saturn.t1_ctrl & 0x03) - { - wake = 1; - saturn.t1_ctrl |= 0x08; - do_interupt(); - } + if (saturn.timer1 <= 0) { + saturn.timer1 &= 0x0f; + if (saturn.t1_ctrl & 0x04) { + wake = 1; } + if (saturn.t1_ctrl & 0x03) { + wake = 1; + saturn.t1_ctrl |= 0x08; + do_interupt(); + } + } if (wake == 0) { interrupt_called = 0; @@ -518,10 +486,9 @@ void do_shutdown(void) { alarms++; } - if (enter_debugger) - { - wake = 1; - } + if (enter_debugger) { + wake = 1; + } } while (wake == 0); stop_timer(IDLE_TIMER); @@ -529,24 +496,40 @@ void do_shutdown(void) { } void set_hardware_stat(int op) { - if (op & 1) saturn.XM = 1; - if (op & 2) saturn.SB = 1; - if (op & 4) saturn.SR = 1; - if (op & 8) saturn.MP = 1; + if (op & 1) + saturn.XM = 1; + if (op & 2) + saturn.SB = 1; + if (op & 4) + saturn.SR = 1; + if (op & 8) + saturn.MP = 1; } void clear_hardware_stat(int op) { - if (op & 1) saturn.XM = 0; - if (op & 2) saturn.SB = 0; - if (op & 4) saturn.SR = 0; - if (op & 8) saturn.MP = 0; + if (op & 1) + saturn.XM = 0; + if (op & 2) + saturn.SB = 0; + if (op & 4) + saturn.SR = 0; + if (op & 8) + saturn.MP = 0; } int is_zero_hardware_stat(int op) { - if (op & 1) if (saturn.XM != 0) return 0; - if (op & 2) if (saturn.SB != 0) return 0; - if (op & 4) if (saturn.SR != 0) return 0; - if (op & 8) if (saturn.MP != 0) return 0; + if (op & 1) + if (saturn.XM != 0) + return 0; + if (op & 2) + if (saturn.SB != 0) + return 0; + if (op & 4) + if (saturn.SR != 0) + return 0; + if (op & 8) + if (saturn.MP != 0) + return 0; return 1; } @@ -561,7 +544,7 @@ void push_return_addr(long addr) { } #endif for (i = 1; i < NR_RSTK; i++) - saturn.rstk[i-1] = saturn.rstk[i]; + saturn.rstk[i - 1] = saturn.rstk[i]; saturn.rstkp--; } saturn.rstk[saturn.rstkp] = addr; @@ -581,14 +564,14 @@ long pop_return_addr(void) { fprintf(stderr, "RSTK[%d] %.5x\n", i, saturn.rstk[i]); } fprintf(stderr, "POP %.5x:\n", - (saturn.rstkp >= 0) ? saturn.rstk[saturn.rstkp]:0); + (saturn.rstkp >= 0) ? saturn.rstk[saturn.rstkp] : 0); #endif if (saturn.rstkp < 0) return 0; return saturn.rstk[saturn.rstkp--]; } -char * make_hexstr(long addr, int n) { +char *make_hexstr(long addr, int n) { static char str[44]; int i, t, trunc; @@ -598,7 +581,7 @@ char * make_hexstr(long addr, int n) { trunc = 1; } for (i = 0; i < n; i++) { - t = read_nibble(addr+i); + t = read_nibble(addr + i); if (t <= 9) str[i] = '0' + t; else @@ -607,9 +590,9 @@ char * make_hexstr(long addr, int n) { str[n] = '\0'; if (trunc) { str[n] = '.'; - str[n+1] = '.'; - str[n+2] = '.'; - str[n+3] = '\0'; + str[n + 1] = '.'; + str[n + 2] = '.'; + str[n + 3] = '\0'; } return str; } @@ -698,17 +681,11 @@ void add_address(word_20 *dat, int add) { *dat &= 0xfffff; } -static int start_fields[] = { - -1, 0, 2, 0, 15, 3, 0, 0, - -1, 0, 2, 0, 15, 3, 0, 0, - 0, 0, 0 -}; +static int start_fields[] = {-1, 0, 2, 0, 15, 3, 0, 0, -1, 0, + 2, 0, 15, 3, 0, 0, 0, 0, 0}; -static int end_fields[] = { - -1, -1, 2, 2, 15, 14, 1, 15, - -1, -1, 2, 2, 15, 14, 1, 4, - 3, 2, 0 -}; +static int end_fields[] = {-1, -1, 2, 2, 15, 14, 1, 15, -1, -1, + 2, 2, 15, 14, 1, 4, 3, 2, 0}; static inline int get_start(int code) { int s; diff --git a/src/append.h b/src/append.h index a871d2c..f72bb6e 100644 --- a/src/append.h +++ b/src/append.h @@ -38,8 +38,8 @@ #include "global.h" -extern char * append_str __ProtoType__((char *buf, char *string)); -extern char * append_tab __ProtoType__((char *buf)); -extern char * append_tab_16 __ProtoType__((char *buf)); +extern char *append_str __ProtoType__((char *buf, char *string)); +extern char *append_tab __ProtoType__((char *buf)); +extern char *append_tab_16 __ProtoType__((char *buf)); #endif /* !_APPEND_H */ diff --git a/src/checkrom.c b/src/checkrom.c index 742967c..0d15b42 100644 --- a/src/checkrom.c +++ b/src/checkrom.c @@ -39,8 +39,8 @@ #include #include -#include #include +#include #include "global.h" #include "romio.h" @@ -48,7 +48,7 @@ unsigned char *rom; unsigned short rom_crc, crc; -int verbose = 0; +int verbose = 0; char *progname; #define calc_crc(n) (crc = ((crc >> 4) ^ (((crc ^ n) & 0xf) * 0x1081))) @@ -61,14 +61,13 @@ int main(int argc, char **argv) { if (argc < 2) { fprintf(stderr, "usage: %s rom-file\n", argv[0]); - exit (1); + exit(1); } - if (!read_rom_file(argv[1], &rom, &rom_size)) - { - fprintf(stderr, "%s: can\'t read ROM from %s\n", argv[0], argv[1]); - exit (1); - } + if (!read_rom_file(argv[1], &rom, &rom_size)) { + fprintf(stderr, "%s: can\'t read ROM from %s\n", argv[0], argv[1]); + exit(1); + } if (opt_gx != 0) ver_addr = 0x7ffbf; @@ -82,7 +81,6 @@ int main(int argc, char **argv) { version[6] = '\0'; printf("ROM Version is %s\n", version); - for (i = 0x100; i < 0x140; i++) { rom[i] = 0x0; } diff --git a/src/constants.h b/src/constants.h index bc84b07..c1ed0b5 100644 --- a/src/constants.h +++ b/src/constants.h @@ -40,9 +40,8 @@ /* * Color modes this program can cope with */ -#define COLOR_MODE_MONO 1 -#define COLOR_MODE_GRAY 2 +#define COLOR_MODE_MONO 1 +#define COLOR_MODE_GRAY 2 #define COLOR_MODE_COLOR 3 #endif /* !_CONSTANTS_H */ - diff --git a/src/debugger.c b/src/debugger.c index 582486b..2417771 100644 --- a/src/debugger.c +++ b/src/debugger.c @@ -53,28 +53,28 @@ #include #ifdef HAVE_READLINE -# include -# include +#include +#include #endif -#include -#include -#include #include #include +#include +#include +#include #ifdef SUNOS #include #endif #include -#include "hp48.h" +#include "debugger.h" #include "device.h" +#include "disasm.h" +#include "hp48.h" +#include "resources.h" +#include "romio.h" +#include "rpl.h" #include "timer.h" #include "x48_x11.h" -#include "debugger.h" -#include "disasm.h" -#include "rpl.h" -#include "romio.h" -#include "resources.h" #define MAX_ARGS 16 @@ -88,204 +88,120 @@ static char instr[100]; /* * Pointers in the HP48sx ROM */ -#define DSKTOP_SX 0x70579 -#define DSKBOT_SX 0x7057e +#define DSKTOP_SX 0x70579 +#define DSKBOT_SX 0x7057e /* * Pointers in the HP48gx ROM */ -#define DSKTOP_GX 0x806f8 -#define DSKBOT_GX 0x806fd +#define DSKTOP_GX 0x806f8 +#define DSKBOT_GX 0x806fd /* * Breakpoint related stuff */ -#define BP_EXEC 1 -#define BP_READ 2 -#define BP_WRITE 4 -#define BP_RANGE 8 +#define BP_EXEC 1 +#define BP_READ 2 +#define BP_WRITE 4 +#define BP_RANGE 8 -#define MAX_BREAKPOINTS 32 +#define MAX_BREAKPOINTS 32 int num_bkpts; -struct breakpoint - { - word_20 addr; - word_20 end_addr; - int flags; - } +struct breakpoint { + word_20 addr; + word_20 end_addr; + int flags; +} bkpt_tbl[MAX_BREAKPOINTS + 1]; /* * command functions */ -static void do_break __ProtoType__ ((int, char **)); -static void do_continue __ProtoType__ ((int, char **)); -static void do_delete __ProtoType__ ((int, char **)); -static void do_exit __ProtoType__ ((int, char **)); -static void do_go __ProtoType__ ((int, char **)); -static void do_help __ProtoType__ ((int, char **)); -static void do_load __ProtoType__ ((int, char **)); -static void do_mode __ProtoType__ ((int, char **)); -static void do_quit __ProtoType__ ((int, char **)); -static void do_regs __ProtoType__ ((int, char **)); -static void do_save __ProtoType__ ((int, char **)); -static void do_stack __ProtoType__ ((int, char **)); -static void do_stat __ProtoType__ ((int, char **)); -static void do_step __ProtoType__ ((int, char **)); -static void do_ram __ProtoType__ ((int, char **)); -static void do_reset __ProtoType__ ((int, char **)); -static void do_rstk __ProtoType__ ((int, char **)); +static void do_break __ProtoType__((int, char **)); +static void do_continue __ProtoType__((int, char **)); +static void do_delete __ProtoType__((int, char **)); +static void do_exit __ProtoType__((int, char **)); +static void do_go __ProtoType__((int, char **)); +static void do_help __ProtoType__((int, char **)); +static void do_load __ProtoType__((int, char **)); +static void do_mode __ProtoType__((int, char **)); +static void do_quit __ProtoType__((int, char **)); +static void do_regs __ProtoType__((int, char **)); +static void do_save __ProtoType__((int, char **)); +static void do_stack __ProtoType__((int, char **)); +static void do_stat __ProtoType__((int, char **)); +static void do_step __ProtoType__((int, char **)); +static void do_ram __ProtoType__((int, char **)); +static void do_reset __ProtoType__((int, char **)); +static void do_rstk __ProtoType__((int, char **)); -struct cmd - { - char *name; - void (*func) __ProtoType__ ((int, char **)); - char *help; - } +struct cmd { + char *name; + void(*func) __ProtoType__((int, char **)); + char *help; +} -cmd_tbl[] = -{ - { - "break", do_break, - "break [address] Set breakpoint at `address\' or show breakpoints" - } - , - { - "b", do_break, 0 - } - , +cmd_tbl[] = { + {"break", do_break, + "break [address] Set breakpoint at `address\' or show " + "breakpoints"}, + {"b", do_break, 0}, - { - "cont", do_continue, - "cont Continue execution" - } - , - { - "c", do_continue, 0 - } - , + {"cont", do_continue, "cont Continue execution"}, + {"c", do_continue, 0}, - { - "delete", do_delete, - "delete [all | n] Delete breakpoint or watchpoint number `n\',\n all breakpoints, or current breakpoint" - } - , - { - "d", do_delete, 0 - } - , + {"delete", do_delete, + "delete [all | n] Delete breakpoint or watchpoint number " + "`n\',\n all breakpoints, or current " + "breakpoint"}, + {"d", do_delete, 0}, - { - "exit", do_exit, - "exit Exit the emulator without saving" - } - , + {"exit", do_exit, + "exit Exit the emulator without saving"}, - { - "go", do_go, - "go address Set PC to `address\'" - } - , + {"go", do_go, "go address Set PC to `address\'"}, - { - "help", do_help, - "help Display this information" - } - , - { - "h", do_help, 0 - } - , - { - "?", do_help, 0 - } - , + {"help", do_help, "help Display this information"}, + {"h", do_help, 0}, + {"?", do_help, 0}, - { - "load", do_load, - "load Load emulator-state from files" - } - , + {"load", do_load, + "load Load emulator-state from files"}, - { - "mode", do_mode, - "mode [hp | class] Show or set disassembler mode" - } - , + {"mode", do_mode, + "mode [hp | class] Show or set disassembler mode"}, - { - "quit", do_quit, - "quit Exit the emulator after saving its state" - } - , - { - "q", do_quit, 0 - } - , + {"quit", do_quit, + "quit Exit the emulator after saving its state"}, + {"q", do_quit, 0}, - { - "ram", do_ram, - "ram Show RAM layout" - } - , + {"ram", do_ram, "ram Show RAM layout"}, - { - "reg", do_regs, - "reg [register [hexvalue]] Display or set register value" - } - , - { - "r", do_regs, 0 - } - , + {"reg", do_regs, + "reg [register [hexvalue]] Display or set register value"}, + {"r", do_regs, 0}, - { - "reset", do_reset, - "reset Set the HP48\'s PC to ZERO" - } - , + {"reset", do_reset, + "reset Set the HP48\'s PC to ZERO"}, - { - "save", do_save, - "save Save emulator-state to files" - } - , + {"save", do_save, + "save Save emulator-state to files"}, - { - "stack", do_stack, - "stack Display RPL stack" - } - , + {"stack", do_stack, "stack Display RPL stack"}, - { - "stat", do_stat, - "stat Display statistics for the emulator" - } - , + {"stat", do_stat, + "stat Display statistics for the emulator"}, - { - "step", do_step, - "step [n] Step one or n Instruction(s)" - } - , - { - "s", do_step, 0 - } - , + {"step", do_step, + "step [n] Step one or n Instruction(s)"}, + {"s", do_step, 0}, - { - "where", do_rstk, - "where Show ML return stack" - } - , + {"where", do_rstk, "where Show ML return stack"}, - { - 0, 0, 0 - } -}; + {0, 0, 0}}; -void init_debugger (void) { +void init_debugger(void) { int i; num_bkpts = 0; @@ -294,592 +210,472 @@ void init_debugger (void) { exec_flags = 0; } -int check_breakpoint (int type, word_20 addr) { +int check_breakpoint(int type, word_20 addr) { struct breakpoint *bp; int i, n; bp = bkpt_tbl; n = num_bkpts; i = 0; - for (; n > 0; bp++) - { - i++; - if (bp->flags == 0) - continue; - n--; - if (bp->flags & BP_RANGE && addr >= bp->addr && addr <= bp->end_addr) - { + for (; n > 0; bp++) { + i++; + if (bp->flags == 0) + continue; + n--; + if (bp->flags & BP_RANGE && addr >= bp->addr && addr <= bp->end_addr) { goto hit_it; } - if (bp->flags & type && addr == bp->addr) - { + if (bp->flags & type && addr == bp->addr) { hit_it: - if (type == BP_READ) - { - printf ("%.5lX: Read watchpoint %d hit at %.5lX\n", saturn.PC, - i, addr); - } - else if (type == BP_WRITE) - { - printf ("%.5lX: Write watchpoint %d hit at %.5lX\n", saturn.PC, - i, addr); - } - else - { - printf ("Breakpoint %d hit at %.5lX\n", i, addr); - } + if (type == BP_READ) { + printf("%.5lX: Read watchpoint %d hit at %.5lX\n", saturn.PC, i, addr); + } else if (type == BP_WRITE) { + printf("%.5lX: Write watchpoint %d hit at %.5lX\n", saturn.PC, i, addr); + } else { + printf("Breakpoint %d hit at %.5lX\n", i, addr); + } return 1; } - } + } return 0; } -char * read_str(char *str, int n, int fp) { +char *read_str(char *str, int n, int fp) { int cc; int flags; - while (1) - { - cc = read(fp, str, n); - if (cc > 0) - { + while (1) { + cc = read(fp, str, n); + if (cc > 0) { str[cc] = '\0'; - return str; + return str; } - if (cc == 0) - return NULL; - - if (errno == EINTR) - continue; - - if (errno == EAGAIN) - { - flags = fcntl(fp, F_GETFL, 0); - flags &= ~ O_NONBLOCK; - fcntl(fp, F_SETFL, flags); - continue; - } + if (cc == 0) return NULL; + + if (errno == EINTR) + continue; + + if (errno == EAGAIN) { + flags = fcntl(fp, F_GETFL, 0); + flags &= ~O_NONBLOCK; + fcntl(fp, F_SETFL, flags); + continue; } - /* not reached */ + return NULL; + } + /* not reached */ } #ifndef HAVE_READLINE -char * readline(char *prompt) -{ +char *readline(char *prompt) { char rl[81]; char *nrl; - if (prompt) - { - printf("%s", prompt); - fflush(stdout); - } + if (prompt) { + printf("%s", prompt); + fflush(stdout); + } nrl = read_str(rl, 80, 0); - if (nrl) - { - int len; - char *str; + if (nrl) { + int len; + char *str; - len = strlen(nrl); - str = malloc(len + 1); + len = strlen(nrl); + str = malloc(len + 1); - if (nrl[len-1] == '\n') - { - nrl[len-1] = '\0'; + if (nrl[len - 1] == '\n') { + nrl[len - 1] = '\0'; } - if (NULL == str) - { + if (NULL == str) { fprintf(stderr, "Out of memory\n"); exit(-1); - } - - strcpy(str, nrl); - nrl = str; } + + strcpy(str, nrl); + nrl = str; + } return nrl; } #endif -static inline void str_to_upper (char *arg) { +static inline void str_to_upper(char *arg) { int i; - for (i = 0; i < strlen (arg); i++) - { - if ('a' <= arg[i] && arg[i] <= 'z') - { - arg[i] = (char) ((int) arg[i] - (int) 'a' + (int) 'A'); - } + for (i = 0; i < strlen(arg); i++) { + if ('a' <= arg[i] && arg[i] <= 'z') { + arg[i] = (char)((int)arg[i] - (int)'a' + (int)'A'); } + } } -static int decode_dec (int *num, char *arg) { +static int decode_dec(int *num, char *arg) { int i; - if (arg == (char *) 0) - { - printf ("Command requires an argument.\n"); - return 0; - } + if (arg == (char *)0) { + printf("Command requires an argument.\n"); + return 0; + } *num = 0; - for (i = 0; i < strlen (arg); i++) - { - *num *= 10; - if ('0' <= arg[i] && arg[i] <= '9') - { - *num += ((int) arg[i] - (int) '0'); - } - else - { + for (i = 0; i < strlen(arg); i++) { + *num *= 10; + if ('0' <= arg[i] && arg[i] <= '9') { + *num += ((int)arg[i] - (int)'0'); + } else { *num = 0; - printf ("Not a number: %s.\n", arg); + printf("Not a number: %s.\n", arg); return 0; } - } + } return 1; } -static int decode_20 (word_20 * addr, char *arg) { +static int decode_20(word_20 *addr, char *arg) { int i; - if (arg == (char *) 0) - { - printf ("Command requires an argument.\n"); - return 0; - } + if (arg == (char *)0) { + printf("Command requires an argument.\n"); + return 0; + } *addr = 0; - for (i = 0; i < strlen (arg); i++) - { - *addr <<= 4; - if ('0' <= arg[i] && arg[i] <= '9') - { - *addr |= ((int) arg[i] - (int) '0'); - } - else if ('A' <= arg[i] && arg[i] <= 'F') - { - *addr |= ((int) arg[i] - (int) 'A' + 10); - } - else - { + for (i = 0; i < strlen(arg); i++) { + *addr <<= 4; + if ('0' <= arg[i] && arg[i] <= '9') { + *addr |= ((int)arg[i] - (int)'0'); + } else if ('A' <= arg[i] && arg[i] <= 'F') { + *addr |= ((int)arg[i] - (int)'A' + 10); + } else { *addr = 0; - printf ("Not a number: %s.\n", arg); + printf("Not a number: %s.\n", arg); return 0; } - *addr &= 0xfffff; - } + *addr &= 0xfffff; + } return 1; } -static int decode_32 (word_32 * addr, char *arg) { +static int decode_32(word_32 *addr, char *arg) { int i; - if (arg == (char *) 0) - { - printf ("Command requires an argument.\n"); - return 0; - } + if (arg == (char *)0) { + printf("Command requires an argument.\n"); + return 0; + } *addr = 0; - for (i = 0; i < strlen (arg); i++) - { - *addr <<= 4; - if ('0' <= arg[i] && arg[i] <= '9') - { - *addr |= ((int) arg[i] - (int) '0'); - } - else if ('A' <= arg[i] && arg[i] <= 'F') - { - *addr |= ((int) arg[i] - (int) 'A' + 10); - } - else - { + for (i = 0; i < strlen(arg); i++) { + *addr <<= 4; + if ('0' <= arg[i] && arg[i] <= '9') { + *addr |= ((int)arg[i] - (int)'0'); + } else if ('A' <= arg[i] && arg[i] <= 'F') { + *addr |= ((int)arg[i] - (int)'A' + 10); + } else { *addr = 0; - printf ("Not a number: %s.\n", arg); + printf("Not a number: %s.\n", arg); return 0; } - } + } return 1; } -static int decode_64 (word_64 * addr, char *arg) { +static int decode_64(word_64 *addr, char *arg) { int i; - if (arg == (char *) 0) - { - printf ("Command requires an argument.\n"); - return 0; - } + if (arg == (char *)0) { + printf("Command requires an argument.\n"); + return 0; + } #ifdef SIMPLE_64 *addr = 0; - for (i = 0; i < strlen (arg); i++) - { - *addr <<= 4; - if ('0' <= arg[i] && arg[i] <= '9') - { - *addr |= ((int) arg[i] - (int) '0'); - } - else if ('A' <= arg[i] && arg[i] <= 'F') - { - *addr |= ((int) arg[i] - (int) 'A' + 10); - } - else - { + for (i = 0; i < strlen(arg); i++) { + *addr <<= 4; + if ('0' <= arg[i] && arg[i] <= '9') { + *addr |= ((int)arg[i] - (int)'0'); + } else if ('A' <= arg[i] && arg[i] <= 'F') { + *addr |= ((int)arg[i] - (int)'A' + 10); + } else { *addr = 0; - printf ("Not a number: %s.\n", arg); + printf("Not a number: %s.\n", arg); return 0; } - } + } #else addr->lo = addr->hi = 0; - for (i = 0; i < strlen (arg); i++) - { - addr->hi <<= 4; - addr->hi |= ((addr->lo >> 28) & 0x0f); - addr->lo <<= 4; - if ('0' <= arg[i] && arg[i] <= '9') - { - addr->lo |= ((int) arg[i] - (int) '0'); - } - else if ('A' <= arg[i] && arg[i] <= 'F') - { - addr->lo |= ((int) arg[i] - (int) 'A' + 10); - } - else - { + for (i = 0; i < strlen(arg); i++) { + addr->hi <<= 4; + addr->hi |= ((addr->lo >> 28) & 0x0f); + addr->lo <<= 4; + if ('0' <= arg[i] && arg[i] <= '9') { + addr->lo |= ((int)arg[i] - (int)'0'); + } else if ('A' <= arg[i] && arg[i] <= 'F') { + addr->lo |= ((int)arg[i] - (int)'A' + 10); + } else { addr->hi = addr->lo = 0; - printf ("Not a number: %s.\n", arg); + printf("Not a number: %s.\n", arg); return 0; } - } + } #endif return 1; } -char * str_nibbles (word_20 addr, int n) { +char *str_nibbles(word_20 addr, int n) { static char str[1025]; char *cp; int i; - if (n > 1024) - { - str[0] = '\0'; - return str; - } + if (n > 1024) { + str[0] = '\0'; + return str; + } - for (cp = str, i = 0; i < n; i++) - { - sprintf (cp, "%.1X", read_nibble (addr + i)); - cp++; - } + for (cp = str, i = 0; i < n; i++) { + sprintf(cp, "%.1X", read_nibble(addr + i)); + cp++; + } *cp = '\0'; return str; } -static int confirm (const char *prompt) { +static int confirm(const char *prompt) { char ans[80]; - printf ("%s (y or n) ", prompt); - fflush (stdout); - read_str (ans, sizeof (ans), 0); - while (ans[0] != 'y' && ans[0] != 'Y' && ans[0] != 'n' && ans[0] != 'N') - { - printf ("Please answer y or n.\n"); - printf ("%s (y or n) ", prompt); - fflush (stdout); - read_str (ans, sizeof (ans), 0); - } - if (ans[0] == 'y' || ans[0] == 'Y') - { - return 1; - } - else - { - printf ("Not confirmed.\n"); - return 0; - } + printf("%s (y or n) ", prompt); + fflush(stdout); + read_str(ans, sizeof(ans), 0); + while (ans[0] != 'y' && ans[0] != 'Y' && ans[0] != 'n' && ans[0] != 'N') { + printf("Please answer y or n.\n"); + printf("%s (y or n) ", prompt); + fflush(stdout); + read_str(ans, sizeof(ans), 0); + } + if (ans[0] == 'y' || ans[0] == 'Y') { + return 1; + } else { + printf("Not confirmed.\n"); + return 0; + } } -static void do_break (int argc, char **argv) { +static void do_break(int argc, char **argv) { int i; word_20 addr; - if (argc == 1) - { - for (i = 0; i < MAX_BREAKPOINTS; i++) - { + if (argc == 1) { + for (i = 0; i < MAX_BREAKPOINTS; i++) { if (bkpt_tbl[i].flags == 0) continue; - if (bkpt_tbl[i].flags == BP_EXEC) - { - printf ("Breakpoint %d at 0x%.5lX\n", i + 1, bkpt_tbl[i].addr); - } - else if (bkpt_tbl[i].flags == BP_RANGE) - { - printf ("Range watchpoint %d at 0x%.5lX - 0x%.5lX\n", i + 1, - bkpt_tbl[i].addr, bkpt_tbl[i].end_addr); - } - else - { - printf ("Watchpoint %d at 0x%.5lX\n", i + 1, bkpt_tbl[i].addr); - } + if (bkpt_tbl[i].flags == BP_EXEC) { + printf("Breakpoint %d at 0x%.5lX\n", i + 1, bkpt_tbl[i].addr); + } else if (bkpt_tbl[i].flags == BP_RANGE) { + printf("Range watchpoint %d at 0x%.5lX - 0x%.5lX\n", i + 1, + bkpt_tbl[i].addr, bkpt_tbl[i].end_addr); + } else { + printf("Watchpoint %d at 0x%.5lX\n", i + 1, bkpt_tbl[i].addr); + } } - } - else - { - str_to_upper (argv[1]); - if (!decode_20 (&addr, argv[1])) - { + } else { + str_to_upper(argv[1]); + if (!decode_20(&addr, argv[1])) { return; } - for (i = 0; i < MAX_BREAKPOINTS; i++) - { - if (bkpt_tbl[i].flags == 0) - { - bkpt_tbl[i].flags = BP_EXEC; - bkpt_tbl[i].addr = addr; - printf ("Breakpoint %d at 0x%.5lX\n", i + 1, bkpt_tbl[i].addr); - num_bkpts++; - return; - } - } - printf ("Breakpoint table full\n"); + for (i = 0; i < MAX_BREAKPOINTS; i++) { + if (bkpt_tbl[i].flags == 0) { + bkpt_tbl[i].flags = BP_EXEC; + bkpt_tbl[i].addr = addr; + printf("Breakpoint %d at 0x%.5lX\n", i + 1, bkpt_tbl[i].addr); + num_bkpts++; + return; + } } + printf("Breakpoint table full\n"); + } } -static void do_continue (int argc, char **argv) { - continue_flag = 1; -} +static void do_continue(int argc, char **argv) { continue_flag = 1; } -static void do_delete (int argc, char **argv) { +static void do_delete(int argc, char **argv) { int num; - if (argc == 1) - { - for (num = 0; num < MAX_BREAKPOINTS; num++) - { - if (bkpt_tbl[num].addr == saturn.PC) - { - if (bkpt_tbl[num].flags == BP_EXEC) - { - printf ("Breakpoint %d at 0x%.5lX deleted.\n", - num + 1, bkpt_tbl[num].addr); + if (argc == 1) { + for (num = 0; num < MAX_BREAKPOINTS; num++) { + if (bkpt_tbl[num].addr == saturn.PC) { + if (bkpt_tbl[num].flags == BP_EXEC) { + printf("Breakpoint %d at 0x%.5lX deleted.\n", num + 1, + bkpt_tbl[num].addr); + } else if (bkpt_tbl[num].flags == BP_RANGE) { + printf("Range watchpoint %d at 0x%.5lX - 0x%.5lX deleted.\n", num + 1, + bkpt_tbl[num].addr, bkpt_tbl[num].end_addr); + } else if (bkpt_tbl[num].flags) { + printf("Watchpoint %d at 0x%.5lX deleted.\n", num + 1, + bkpt_tbl[num].addr); } - else if (bkpt_tbl[num].flags == BP_RANGE) - { - printf ("Range watchpoint %d at 0x%.5lX - 0x%.5lX deleted.\n", - num + 1, bkpt_tbl[num].addr, bkpt_tbl[num].end_addr); - } - else if (bkpt_tbl[num].flags) - { - printf ("Watchpoint %d at 0x%.5lX deleted.\n", - num + 1, bkpt_tbl[num].addr); - } - num_bkpts--; - bkpt_tbl[num].addr = 0; - bkpt_tbl[num].flags = 0; - } + num_bkpts--; + bkpt_tbl[num].addr = 0; + bkpt_tbl[num].flags = 0; + } } - } - else - { - str_to_upper (argv[1]); - if (!strcmp ("ALL", argv[1])) - { - for (num = 0; num < MAX_BREAKPOINTS; num++) - { - bkpt_tbl[num].addr = 0; - bkpt_tbl[num].flags = 0; - } + } else { + str_to_upper(argv[1]); + if (!strcmp("ALL", argv[1])) { + for (num = 0; num < MAX_BREAKPOINTS; num++) { + bkpt_tbl[num].addr = 0; + bkpt_tbl[num].flags = 0; + } num_bkpts = 0; - printf ("All breakpoints deleted.\n"); - } - else - { - if (decode_dec (&num, argv[1])) - { - if (num < 1 || num > MAX_BREAKPOINTS) - { - printf ("Breakpoint %d out of range.\n", num); + printf("All breakpoints deleted.\n"); + } else { + if (decode_dec(&num, argv[1])) { + if (num < 1 || num > MAX_BREAKPOINTS) { + printf("Breakpoint %d out of range.\n", num); return; } - num -= 1; - if (bkpt_tbl[num].flags == BP_EXEC) - { - printf ("Breakpoint %d at 0x%.5lX deleted.\n", - num + 1, bkpt_tbl[num].addr); - } - else if (bkpt_tbl[num].flags == BP_RANGE) - { - printf ("Range watchpoint %d at 0x%.5lX - 0x%.5lX deleted.\n", - num + 1, bkpt_tbl[num].addr, bkpt_tbl[num].end_addr); - } - else if (bkpt_tbl[num].flags) - { - printf ("Watchpoint %d at 0x%.5lX deleted.\n", - num + 1, bkpt_tbl[num].addr); - } - num_bkpts--; - bkpt_tbl[num].addr = 0; - bkpt_tbl[num].flags = 0; + num -= 1; + if (bkpt_tbl[num].flags == BP_EXEC) { + printf("Breakpoint %d at 0x%.5lX deleted.\n", num + 1, + bkpt_tbl[num].addr); + } else if (bkpt_tbl[num].flags == BP_RANGE) { + printf("Range watchpoint %d at 0x%.5lX - 0x%.5lX deleted.\n", num + 1, + bkpt_tbl[num].addr, bkpt_tbl[num].end_addr); + } else if (bkpt_tbl[num].flags) { + printf("Watchpoint %d at 0x%.5lX deleted.\n", num + 1, + bkpt_tbl[num].addr); } + num_bkpts--; + bkpt_tbl[num].addr = 0; + bkpt_tbl[num].flags = 0; + } } - } + } } -static void do_exit (int argc, char **argv) { - if (confirm ("Exit the emulator WITHOUT saving its state?")) - { - printf ("Exit.\n"); - XCloseDisplay(dpy); - exit (0); - } +static void do_exit(int argc, char **argv) { + if (confirm("Exit the emulator WITHOUT saving its state?")) { + printf("Exit.\n"); + XCloseDisplay(dpy); + exit(0); + } } -static void do_go (int argc, char **argv) { +static void do_go(int argc, char **argv) { word_20 addr; - str_to_upper (argv[1]); - if (decode_20 (&addr, argv[1])) - { - saturn.PC = addr; - enter_debugger &= ~ILLEGAL_INSTRUCTION; - } + str_to_upper(argv[1]); + if (decode_20(&addr, argv[1])) { + saturn.PC = addr; + enter_debugger &= ~ILLEGAL_INSTRUCTION; + } } -static void do_help (int argc, char **argv) { +static void do_help(int argc, char **argv) { int i; - for (i = 0; cmd_tbl[i].name; i++) - { - if (cmd_tbl[i].help) - { - printf ("%s.\n", cmd_tbl[i].help); - } + for (i = 0; cmd_tbl[i].name; i++) { + if (cmd_tbl[i].help) { + printf("%s.\n", cmd_tbl[i].help); } + } } -static void do_load (int argc, char **argv) { +static void do_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"); + 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 (); + 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(); #ifdef HAVE_XSHM if (disp.display_update) - refresh_display (); + refresh_display(); #endif + } 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)); } - 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) { - if (argc < 2) - { - printf ("Disassembler uses %s mnemonics.\n", mode_name[disassembler_mode]); - } - else - { - str_to_upper (argv[1]); - if (!strcmp ("HP", argv[1])) - { +static void do_mode(int argc, char **argv) { + if (argc < 2) { + printf("Disassembler uses %s mnemonics.\n", mode_name[disassembler_mode]); + } else { + str_to_upper(argv[1]); + if (!strcmp("HP", argv[1])) { disassembler_mode = HP_MNEMONICS; - } - else if (!strcmp ("CLASS", argv[1])) - { + } else if (!strcmp("CLASS", argv[1])) { disassembler_mode = CLASS_MNEMONICS; + } else { + printf("Unknown disassembler mode %s. Try \"help\".\n", argv[1]); } - else - { - printf ("Unknown disassembler mode %s. Try \"help\".\n", argv[1]); - } - } + } } -static void do_quit (int argc, char **argv) { - if (confirm ("Quit the emulator and save its state?")) - { - printf ("Exit.\n"); - exit_emulator (); - XCloseDisplay(dpy); - exit (0); - } +static void do_quit(int argc, char **argv) { + if (confirm("Quit the emulator and save its state?")) { + printf("Exit.\n"); + exit_emulator(); + XCloseDisplay(dpy); + exit(0); + } } -static void set_reg (word_64 val, int n, unsigned char *r){ +static void set_reg(word_64 val, int n, unsigned char *r) { int i; - for (i = 0; i < n; i++) - { + for (i = 0; i < n; i++) { #ifdef SIMPLE_64 - r[i] = (unsigned char) ((val & (0xf << (4 * i))) >> (4 * i)); + r[i] = (unsigned char)((val & (0xf << (4 * i))) >> (4 * i)); #else - r[i] = (unsigned char) (((i < 8?val.lo:val.hi) & (0xf << (4 * i))) >> (4 * i)); + r[i] = (unsigned char)(((i < 8 ? val.lo : val.hi) & (0xf << (4 * i))) >> + (4 * i)); #endif - } + } } -static void dump_reg (const char *reg, int n, unsigned char *r) { +static void dump_reg(const char *reg, int n, unsigned char *r) { int i; - printf ("%s:\t", reg); - for (i = n - 1; i >= 0; i--) - { - printf ("%.1X", r[i] & 0xf); - } - printf ("\n"); + printf("%s:\t", reg); + for (i = n - 1; i >= 0; i--) { + printf("%.1X", r[i] & 0xf); + } + printf("\n"); } - -static void set_st (word_64 val) { +static void set_st(word_64 val) { int i; for (i = 0; i < 16; i++) @@ -890,39 +686,31 @@ static void set_st (word_64 val) { #endif } -static void dump_st (void) { +static void dump_st(void) { int i; int val; val = 0; - for (i = NR_PSTAT - 1; i >= 0; i--) - { - val <<= 1; - val |= saturn.PSTAT[i] ? 1 : 0; - } - printf (" ST:\t%.4X (", val); - for (i = NR_PSTAT - 1; i > 0; i--) - { - if (saturn.PSTAT[i]) - { - printf ("%.1X ", i); - } - else - { - printf ("- "); - } - } - if (saturn.PSTAT[0]) - { - printf ("%.1X)\n", 0); - } - else - { - printf ("-)\n"); + for (i = NR_PSTAT - 1; i >= 0; i--) { + val <<= 1; + val |= saturn.PSTAT[i] ? 1 : 0; + } + printf(" ST:\t%.4X (", val); + for (i = NR_PSTAT - 1; i > 0; i--) { + if (saturn.PSTAT[i]) { + printf("%.1X ", i); + } else { + printf("- "); } + } + if (saturn.PSTAT[0]) { + printf("%.1X)\n", 0); + } else { + printf("-)\n"); + } } -static void set_hst (word_64 val) { +static void set_hst(word_64 val) { saturn.XM = 0; saturn.SB = 0; saturn.SR = 0; @@ -948,7 +736,7 @@ static void set_hst (word_64 val) { #endif } -static void dump_hst (void) { +static void dump_hst(void) { short hst = 0; if (saturn.XM != 0) hst |= 1; @@ -958,400 +746,287 @@ static void dump_hst (void) { hst |= 3; if (saturn.MP != 0) hst |= 4; - printf (" HST:\t%.1X (%s%s%s%s)\n", hst, - saturn.MP ? "MP " : "-- ", saturn.SR ? "SR " : "-- ", - saturn.SB ? "SB " : "-- ", saturn.XM ? "XM" : "--"); + printf(" HST:\t%.1X (%s%s%s%s)\n", hst, saturn.MP ? "MP " : "-- ", + saturn.SR ? "SR " : "-- ", saturn.SB ? "SB " : "-- ", + saturn.XM ? "XM" : "--"); } -static char *mctl_str_gx[] = { - "MMIO ", - "SysRAM ", - "Bank Switch", - "Port 1 ", - "Port 2 ", - "SysROM " -}; +static char *mctl_str_gx[] = {"MMIO ", "SysRAM ", "Bank Switch", + "Port 1 ", "Port 2 ", "SysROM "}; -static char *mctl_str_sx[] = { - "MMIO ", - "SysRAM", - "Port 1", - "Port 2", - "Extra ", - "SysROM" -}; +static char *mctl_str_sx[] = {"MMIO ", "SysRAM", "Port 1", + "Port 2", "Extra ", "SysROM"}; -static void do_ram (int argc, char **argv) { +static void do_ram(int argc, char **argv) { int i; - for (i = 0; i < 5; i++) - { - printf("%s ", opt_gx ? mctl_str_gx[i] : mctl_str_sx[i]); - if (saturn.mem_cntl[i].unconfigured) - printf("unconfigured\n"); - else - if (i == 0) - printf("configured to 0x%.5lx\n", saturn.mem_cntl[i].config[0]); - else - printf("configured to 0x%.5lX - 0x%.5lX\n", - saturn.mem_cntl[i].config[0], - (saturn.mem_cntl[i].config[0] | ~saturn.mem_cntl[i].config[1]) - & 0xfffff); - } + for (i = 0; i < 5; i++) { + printf("%s ", opt_gx ? mctl_str_gx[i] : mctl_str_sx[i]); + if (saturn.mem_cntl[i].unconfigured) + printf("unconfigured\n"); + else if (i == 0) + printf("configured to 0x%.5lx\n", saturn.mem_cntl[i].config[0]); + else + printf("configured to 0x%.5lX - 0x%.5lX\n", saturn.mem_cntl[i].config[0], + (saturn.mem_cntl[i].config[0] | ~saturn.mem_cntl[i].config[1]) & + 0xfffff); + } if (opt_gx) printf("Port 2 switched to bank %d\n", saturn.bank_switch); } -static void do_regs (int argc, char **argv) { +static void do_regs(int argc, char **argv) { int i; word_64 val; - if (argc < 2) - { - /* + if (argc < 2) { + /* * dump all registers */ - printf ("CPU is in %s mode. Registers:\n", - saturn.hexmode == HEX ? "HEX" : "DEC"); - dump_reg (" A", 16, saturn.A); - dump_reg (" B", 16, saturn.B); - dump_reg (" C", 16, saturn.C); - dump_reg (" D", 16, saturn.D); - printf (" D0:\t%.5lX ->", saturn.D0); - for (i = 0; i < 20; i += 5) - { - printf (" %s", str_nibbles (saturn.D0 + i, 5)); + printf("CPU is in %s mode. Registers:\n", + saturn.hexmode == HEX ? "HEX" : "DEC"); + dump_reg(" A", 16, saturn.A); + dump_reg(" B", 16, saturn.B); + dump_reg(" C", 16, saturn.C); + dump_reg(" D", 16, saturn.D); + printf(" D0:\t%.5lX ->", saturn.D0); + for (i = 0; i < 20; i += 5) { + printf(" %s", str_nibbles(saturn.D0 + i, 5)); } - printf ("\n"); - printf (" D1:\t%.5lX ->", saturn.D1); - for (i = 0; i < 20; i += 5) - { - printf (" %s", str_nibbles (saturn.D1 + i, 5)); + printf("\n"); + printf(" D1:\t%.5lX ->", saturn.D1); + for (i = 0; i < 20; i += 5) { + printf(" %s", str_nibbles(saturn.D1 + i, 5)); } - printf ("\n"); - printf (" P:\t%.1X\n", saturn.P); - disassemble (saturn.PC, instr); - printf (" PC:\t%.5lX -> %s\n", saturn.PC, instr); - dump_reg (" R0", 16, saturn.R0); - dump_reg (" R1", 16, saturn.R1); - dump_reg (" R2", 16, saturn.R2); - dump_reg (" R3", 16, saturn.R3); - dump_reg (" R4", 16, saturn.R4); - dump_reg (" IN", 4, saturn.IN); - dump_reg (" OUT", 3, saturn.OUT); - printf (" CARRY:\t%.1d\n", saturn.CARRY); - dump_st (); - dump_hst (); - } - else if (argc == 2) - { - /* + printf("\n"); + printf(" P:\t%.1X\n", saturn.P); + disassemble(saturn.PC, instr); + printf(" PC:\t%.5lX -> %s\n", saturn.PC, instr); + dump_reg(" R0", 16, saturn.R0); + dump_reg(" R1", 16, saturn.R1); + dump_reg(" R2", 16, saturn.R2); + dump_reg(" R3", 16, saturn.R3); + dump_reg(" R4", 16, saturn.R4); + dump_reg(" IN", 4, saturn.IN); + dump_reg(" OUT", 3, saturn.OUT); + printf(" CARRY:\t%.1d\n", saturn.CARRY); + dump_st(); + dump_hst(); + } else if (argc == 2) { + /* * dump specified register */ - str_to_upper (argv[1]); - if (!strcmp ("A", argv[1])) - { - dump_reg (" A", 16, saturn.A); - } - else if (!strcmp ("B", argv[1])) - { - dump_reg (" B", 16, saturn.B); - } - else if (!strcmp ("C", argv[1])) - { - dump_reg (" C", 16, saturn.C); - } - else if (!strcmp ("D", argv[1])) - { - dump_reg (" D", 16, saturn.D); + str_to_upper(argv[1]); + if (!strcmp("A", argv[1])) { + dump_reg(" A", 16, saturn.A); + } else if (!strcmp("B", argv[1])) { + dump_reg(" B", 16, saturn.B); + } else if (!strcmp("C", argv[1])) { + dump_reg(" C", 16, saturn.C); + } else if (!strcmp("D", argv[1])) { + dump_reg(" D", 16, saturn.D); + } else if (!strcmp("D0", argv[1])) { + printf(" D0:\t%.5lX ->", saturn.D0); + for (i = 0; i < 20; i += 5) { + printf(" %s", str_nibbles(saturn.D0 + i, 5)); + } + printf("\n"); + } else if (!strcmp("D1", argv[1])) { + printf(" D1:\t%.5lX ->", saturn.D1); + for (i = 0; i < 20; i += 5) { + printf(" %s", str_nibbles(saturn.D1 + i, 5)); + } + printf("\n"); + } else if (!strcmp("P", argv[1])) { + printf(" P:\t%.1X\n", saturn.P); + } else if (!strcmp("PC", argv[1])) { + disassemble(saturn.PC, instr); + printf(" PC:\t%.5lX -> %s\n", saturn.PC, instr); + } else if (!strcmp("R0", argv[1])) { + dump_reg(" R0", 16, saturn.R0); + } else if (!strcmp("R1", argv[1])) { + dump_reg(" R1", 16, saturn.R1); + } else if (!strcmp("R2", argv[1])) { + dump_reg(" R2", 16, saturn.R2); + } else if (!strcmp("R3", argv[1])) { + dump_reg(" R3", 16, saturn.R3); + } else if (!strcmp("R4", argv[1])) { + dump_reg(" R4", 16, saturn.R4); + } else if (!strcmp("IN", argv[1])) { + dump_reg(" IN", 4, saturn.IN); + } else if (!strcmp("OUT", argv[1])) { + dump_reg(" OUT", 3, saturn.OUT); + } else if (!strcmp("CARRY", argv[1])) { + printf(" CARRY:\t%.1d\n", saturn.CARRY); + } else if (!strcmp("CY", argv[1])) { + printf(" CARRY:\t%.1d\n", saturn.CARRY); + } else if (!strcmp("ST", argv[1])) { + dump_st(); + } else if (!strcmp("HST", argv[1])) { + dump_hst(); + } else { + printf("No Register %s in CPU.\n", argv[1]); } - else if (!strcmp ("D0", argv[1])) - { - printf (" D0:\t%.5lX ->", saturn.D0); - for (i = 0; i < 20; i += 5) - { - printf (" %s", str_nibbles (saturn.D0 + i, 5)); - } - printf ("\n"); - } - else if (!strcmp ("D1", argv[1])) - { - printf (" D1:\t%.5lX ->", saturn.D1); - for (i = 0; i < 20; i += 5) - { - printf (" %s", str_nibbles (saturn.D1 + i, 5)); - } - printf ("\n"); - } - else if (!strcmp ("P", argv[1])) - { - printf (" P:\t%.1X\n", saturn.P); - } - else if (!strcmp ("PC", argv[1])) - { - disassemble (saturn.PC, instr); - printf (" PC:\t%.5lX -> %s\n", saturn.PC, instr); - } - else if (!strcmp ("R0", argv[1])) - { - dump_reg (" R0", 16, saturn.R0); - } - else if (!strcmp ("R1", argv[1])) - { - dump_reg (" R1", 16, saturn.R1); - } - else if (!strcmp ("R2", argv[1])) - { - dump_reg (" R2", 16, saturn.R2); - } - else if (!strcmp ("R3", argv[1])) - { - dump_reg (" R3", 16, saturn.R3); - } - else if (!strcmp ("R4", argv[1])) - { - dump_reg (" R4", 16, saturn.R4); - } - else if (!strcmp ("IN", argv[1])) - { - dump_reg (" IN", 4, saturn.IN); - } - else if (!strcmp ("OUT", argv[1])) - { - dump_reg (" OUT", 3, saturn.OUT); - } - else if (!strcmp ("CARRY", argv[1])) - { - printf (" CARRY:\t%.1d\n", saturn.CARRY); - } - else if (!strcmp ("CY", argv[1])) - { - printf (" CARRY:\t%.1d\n", saturn.CARRY); - } - else if (!strcmp ("ST", argv[1])) - { - dump_st (); - } - else if (!strcmp ("HST", argv[1])) - { - dump_hst (); - } - else - { - printf ("No Register %s in CPU.\n", argv[1]); - } - } - else - { - /* + } else { + /* * set specified register */ - str_to_upper (argv[1]); - str_to_upper (argv[2]); - if (decode_64 (&val, argv[2])) - { - if (!strcmp ("A", argv[1])) - { - set_reg (val, 16, saturn.A); - dump_reg (" A", 16, saturn.A); - } - else if (!strcmp ("B", argv[1])) - { - set_reg (val, 16, saturn.B); - dump_reg (" B", 16, saturn.B); - } - else if (!strcmp ("C", argv[1])) - { - set_reg (val, 16, saturn.C); - dump_reg (" C", 16, saturn.C); - } - else if (!strcmp ("D", argv[1])) - { - set_reg (val, 16, saturn.D); - dump_reg (" D", 16, saturn.D); - } - else if (!strcmp ("D0", argv[1])) - { + str_to_upper(argv[1]); + str_to_upper(argv[2]); + if (decode_64(&val, argv[2])) { + if (!strcmp("A", argv[1])) { + set_reg(val, 16, saturn.A); + dump_reg(" A", 16, saturn.A); + } else if (!strcmp("B", argv[1])) { + set_reg(val, 16, saturn.B); + dump_reg(" B", 16, saturn.B); + } else if (!strcmp("C", argv[1])) { + set_reg(val, 16, saturn.C); + dump_reg(" C", 16, saturn.C); + } else if (!strcmp("D", argv[1])) { + set_reg(val, 16, saturn.D); + dump_reg(" D", 16, saturn.D); + } else if (!strcmp("D0", argv[1])) { #ifdef SIMPLE_64 - saturn.D0 = (word_20)(val & 0xfffff); + saturn.D0 = (word_20)(val & 0xfffff); #else - saturn.D0 = (word_20)(val.lo & 0xfffff); + saturn.D0 = (word_20)(val.lo & 0xfffff); #endif - printf (" D0:\t%.5lX ->", saturn.D0); - for (i = 0; i < 20; i += 5) - { - printf (" %s", str_nibbles (saturn.D0 + i, 5)); + printf(" D0:\t%.5lX ->", saturn.D0); + for (i = 0; i < 20; i += 5) { + printf(" %s", str_nibbles(saturn.D0 + i, 5)); } - printf ("\n"); - } - else if (!strcmp ("D1", argv[1])) - { + printf("\n"); + } else if (!strcmp("D1", argv[1])) { #ifdef SIMPLE_64 - saturn.D1 = (word_20)(val & 0xfffff); + saturn.D1 = (word_20)(val & 0xfffff); #else - saturn.D1 = (word_20)(val.lo & 0xfffff); + saturn.D1 = (word_20)(val.lo & 0xfffff); #endif - printf (" D1:\t%.5lX ->", saturn.D1); - for (i = 0; i < 20; i += 5) - { - printf (" %s", str_nibbles (saturn.D1 + i, 5)); + printf(" D1:\t%.5lX ->", saturn.D1); + for (i = 0; i < 20; i += 5) { + printf(" %s", str_nibbles(saturn.D1 + i, 5)); } - printf ("\n"); - } - else if (!strcmp ("P", argv[1])) - { + printf("\n"); + } else if (!strcmp("P", argv[1])) { #ifdef SIMPLE_64 - saturn.P = (word_4)(val & 0xf); + saturn.P = (word_4)(val & 0xf); #else - saturn.P = (word_4)(val.lo & 0xf); + saturn.P = (word_4)(val.lo & 0xf); #endif - printf (" P:\t%.1X\n", saturn.P); - } - else if (!strcmp ("PC", argv[1])) - { + printf(" P:\t%.1X\n", saturn.P); + } else if (!strcmp("PC", argv[1])) { #ifdef SIMPLE_64 - saturn.PC = (word_20)(val & 0xfffff); + saturn.PC = (word_20)(val & 0xfffff); #else - saturn.PC = (word_20)(val.lo & 0xfffff); + saturn.PC = (word_20)(val.lo & 0xfffff); #endif - disassemble (saturn.PC, instr); - printf (" PC:\t%.5lX -> %s\n", saturn.PC, instr); - } - else if (!strcmp ("R0", argv[1])) - { - set_reg (val, 16, saturn.R0); - dump_reg (" R0", 16, saturn.R0); - } - else if (!strcmp ("R1", argv[1])) - { - set_reg (val, 16, saturn.R1); - dump_reg (" R1", 16, saturn.R1); - } - else if (!strcmp ("R2", argv[1])) - { - set_reg (val, 16, saturn.R2); - dump_reg (" R2", 16, saturn.R2); - } - else if (!strcmp ("R3", argv[1])) - { - set_reg (val, 16, saturn.R3); - dump_reg (" R3", 16, saturn.R3); - } - else if (!strcmp ("R4", argv[1])) - { - set_reg (val, 16, saturn.R4); - dump_reg (" R4", 16, saturn.R4); - } - else if (!strcmp ("IN", argv[1])) - { - set_reg (val, 4, saturn.IN); - dump_reg (" IN", 4, saturn.IN); - } - else if (!strcmp ("OUT", argv[1])) - { - set_reg (val, 3, saturn.OUT); - dump_reg (" OUT", 3, saturn.OUT); - } - else if (!strcmp ("CARRY", argv[1])) - { + disassemble(saturn.PC, instr); + printf(" PC:\t%.5lX -> %s\n", saturn.PC, instr); + } else if (!strcmp("R0", argv[1])) { + set_reg(val, 16, saturn.R0); + dump_reg(" R0", 16, saturn.R0); + } else if (!strcmp("R1", argv[1])) { + set_reg(val, 16, saturn.R1); + dump_reg(" R1", 16, saturn.R1); + } else if (!strcmp("R2", argv[1])) { + set_reg(val, 16, saturn.R2); + dump_reg(" R2", 16, saturn.R2); + } else if (!strcmp("R3", argv[1])) { + set_reg(val, 16, saturn.R3); + dump_reg(" R3", 16, saturn.R3); + } else if (!strcmp("R4", argv[1])) { + set_reg(val, 16, saturn.R4); + dump_reg(" R4", 16, saturn.R4); + } else if (!strcmp("IN", argv[1])) { + set_reg(val, 4, saturn.IN); + dump_reg(" IN", 4, saturn.IN); + } else if (!strcmp("OUT", argv[1])) { + set_reg(val, 3, saturn.OUT); + dump_reg(" OUT", 3, saturn.OUT); + } else if (!strcmp("CARRY", argv[1])) { #ifdef SIMPLE_64 - saturn.CARRY = (word_1)(val & 0x1); + saturn.CARRY = (word_1)(val & 0x1); #else - saturn.CARRY = (word_1)(val.lo & 0x1); + saturn.CARRY = (word_1)(val.lo & 0x1); #endif - printf (" CARRY:\t%.1d\n", saturn.CARRY); - } - else if (!strcmp ("CY", argv[1])) - { + printf(" CARRY:\t%.1d\n", saturn.CARRY); + } else if (!strcmp("CY", argv[1])) { #ifdef SIMPLE_64 - saturn.CARRY = (word_1)(val & 0x1); + saturn.CARRY = (word_1)(val & 0x1); #else - saturn.CARRY = (word_1)(val.lo & 0x1); + saturn.CARRY = (word_1)(val.lo & 0x1); #endif - printf (" CARRY:\t%.1d\n", saturn.CARRY); - } - else if (!strcmp ("ST", argv[1])) - { - set_st (val); - dump_st (); - } - else if (!strcmp ("HST", argv[1])) - { - set_hst (val); - dump_hst (); - } - else - { - printf ("No Register %s in CPU.\n", argv[1]); - } - } + printf(" CARRY:\t%.1d\n", saturn.CARRY); + } else if (!strcmp("ST", argv[1])) { + set_st(val); + dump_st(); + } else if (!strcmp("HST", argv[1])) { + set_hst(val); + dump_hst(); + } else { + printf("No Register %s in CPU.\n", argv[1]); + } } + } } -static void do_save (int argc, char **argv) { - if (write_files ()) - { - printf ("Saving done.\n"); - } - else - { - printf ("Saving emulator-state failed.\n"); - } +static void do_save(int argc, char **argv) { + if (write_files()) { + printf("Saving done.\n"); + } else { + printf("Saving emulator-state failed.\n"); + } } struct se { - int se_n; - word_20 se_p; + int se_n; + word_20 se_p; struct se *se_next; }; -char * get_stack (void) { +char *get_stack(void) { word_20 dsktop, dskbot; word_20 sp = 0, end = 0, ent = 0; word_20 ram_base, ram_mask; - char dat[65536]; - char typ[256]; + char dat[65536]; + char typ[256]; int i, n; ram_base = saturn.mem_cntl[1].config[0]; ram_mask = saturn.mem_cntl[1].config[1]; - if (opt_gx) - { - saturn.mem_cntl[1].config[0] = 0x80000; - saturn.mem_cntl[1].config[1] = 0xc0000; - dsktop = DSKTOP_GX; - dskbot = DSKBOT_GX; - } - else - { - saturn.mem_cntl[1].config[0] = 0x70000; - saturn.mem_cntl[1].config[1] = 0xf0000; - dsktop = DSKTOP_SX; - dskbot = DSKBOT_SX; - } + if (opt_gx) { + saturn.mem_cntl[1].config[0] = 0x80000; + saturn.mem_cntl[1].config[1] = 0xc0000; + dsktop = DSKTOP_GX; + dskbot = DSKBOT_GX; + } else { + saturn.mem_cntl[1].config[0] = 0x70000; + saturn.mem_cntl[1].config[1] = 0xf0000; + dsktop = DSKTOP_SX; + dskbot = DSKBOT_SX; + } load_addr(&sp, dsktop, 5); load_addr(&end, dskbot, 5); - n = (end - sp) / 5 - 1; /* end never matches sp */ + n = (end - sp) / 5 - 1; /* end never matches sp */ printf("n = %d\n", n); - //TODO Get the top of the stack in the buffer. - //TODO create a window and put the complete stack into it! - if (n) - { - load_addr(&ent, sp, 5); - decode_rpl_obj_2(ent, typ, dat); - printf("%d %p -> [%s] %s\n", i, ent, typ, dat); - } + // TODO Get the top of the stack in the buffer. + // TODO create a window and put the complete stack into it! + if (n) { + load_addr(&ent, sp, 5); + decode_rpl_obj_2(ent, typ, dat); + printf("%d %p -> [%s] %s\n", i, ent, typ, dat); + } - for (i = 0; i < n; i++) - { - load_addr(&ent, sp + (5 * i), 5); - decode_rpl_obj_2(ent, typ, dat); - printf("%d %p -> [%s] %s\n", i, ent, typ, dat); - } + for (i = 0; i < n; i++) { + load_addr(&ent, sp + (5 * i), 5); + decode_rpl_obj_2(ent, typ, dat); + printf("%d %p -> [%s] %s\n", i, ent, typ, dat); + } saturn.mem_cntl[1].config[0] = ram_base; saturn.mem_cntl[1].config[1] = ram_mask; @@ -1359,364 +1034,321 @@ char * get_stack (void) { return; } -static void do_stack (int argc, char **argv) { +static void do_stack(int argc, char **argv) { word_20 dsktop, dskbot; word_20 sp = 0, end = 0, ent = 0; word_20 ram_base, ram_mask; - char buf[65536]; + char buf[65536]; struct se *stack, *se; int n; ram_base = saturn.mem_cntl[1].config[0]; ram_mask = saturn.mem_cntl[1].config[1]; - if (opt_gx) - { - saturn.mem_cntl[1].config[0] = 0x80000; - saturn.mem_cntl[1].config[1] = 0xc0000; - dsktop = DSKTOP_GX; - dskbot = DSKBOT_GX; - } - else - { - saturn.mem_cntl[1].config[0] = 0x70000; - saturn.mem_cntl[1].config[1] = 0xf0000; - dsktop = DSKTOP_SX; - dskbot = DSKBOT_SX; - } + if (opt_gx) { + saturn.mem_cntl[1].config[0] = 0x80000; + saturn.mem_cntl[1].config[1] = 0xc0000; + dsktop = DSKTOP_GX; + dskbot = DSKBOT_GX; + } else { + saturn.mem_cntl[1].config[0] = 0x70000; + saturn.mem_cntl[1].config[1] = 0xf0000; + dsktop = DSKTOP_SX; + dskbot = DSKBOT_SX; + } load_addr(&sp, dsktop, 5); load_addr(&end, dskbot, 5); stack = (struct se *)0; n = 0; - do - { - load_addr(&ent, sp, 5); - if (ent == 0) - break; - n++; - sp += 5; - se = (struct se *)malloc(sizeof(struct se)); - if (se == 0) - { - fprintf(stderr, "Out off memory.\n"); - break; - } - se->se_n = n; - se->se_p = ent; - se->se_next = stack; - stack = se; + do { + load_addr(&ent, sp, 5); + if (ent == 0) + break; + n++; + sp += 5; + se = (struct se *)malloc(sizeof(struct se)); + if (se == 0) { + fprintf(stderr, "Out off memory.\n"); + break; } - while (sp <= end); + se->se_n = n; + se->se_p = ent; + se->se_next = stack; + stack = se; + } while (sp <= end); if (n == 0) printf("Empty stack.\n"); se = stack; - while (se) - { - decode_rpl_obj(se->se_p, buf); - if (se->se_n != 1) - if (strlen(buf) > 63) - { - sprintf(&buf[60], "..."); - buf[63] = '\0'; - } - printf("%5d: %.5lX -> %s\n", se->se_n, se->se_p, buf); - se = se->se_next; - } + while (se) { + decode_rpl_obj(se->se_p, buf); + if (se->se_n != 1) + if (strlen(buf) > 63) { + sprintf(&buf[60], "..."); + buf[63] = '\0'; + } + printf("%5d: %.5lX -> %s\n", se->se_n, se->se_p, buf); + se = se->se_next; + } se = stack; - while (se) - { - stack = se; - se = se->se_next; - free(stack); - } + while (se) { + stack = se; + se = se->se_next; + free(stack); + } saturn.mem_cntl[1].config[0] = ram_base; saturn.mem_cntl[1].config[1] = ram_mask; } -static void do_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_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 do_step(int argc, char **argv) { word_20 next_instr; word_32 n; int leave; - if (enter_debugger & ILLEGAL_INSTRUCTION) - { - printf ("Can\'t step into an illegal instruction."); - return; - } + if (enter_debugger & ILLEGAL_INSTRUCTION) { + printf("Can\'t step into an illegal instruction."); + return; + } n = 1; if (argc > 1) - if (!decode_32 (&n, argv[1])) + if (!decode_32(&n, argv[1])) return; if (n <= 0) return; in_debugger = 1; - step_instruction (); + step_instruction(); - if (exec_flags & EXEC_BKPT) - { - if (check_breakpoint (BP_EXEC, saturn.PC)) - { + if (exec_flags & EXEC_BKPT) { + if (check_breakpoint(BP_EXEC, saturn.PC)) { enter_debugger |= BREAKPOINT_HIT; return; } - } + } next_instr = saturn.PC; sched_adjtime = 0; - schedule (); + schedule(); enter_debugger = 0; - while (1) - { - if (enter_debugger) - break; + while (1) { + if (enter_debugger) + break; - leave = 0; + leave = 0; - if (saturn.PC == next_instr) - { + if (saturn.PC == next_instr) { n--; leave = 1; if (n == 0) break; } - step_instruction (); + step_instruction(); - if (exec_flags & EXEC_BKPT) - { - if (check_breakpoint (BP_EXEC, saturn.PC)) - { - enter_debugger |= BREAKPOINT_HIT; - break; - } + if (exec_flags & EXEC_BKPT) { + if (check_breakpoint(BP_EXEC, saturn.PC)) { + enter_debugger |= BREAKPOINT_HIT; + break; + } } - if (leave) - next_instr = saturn.PC; + if (leave) + next_instr = saturn.PC; - schedule (); - } + schedule(); + } } -static void do_reset (int argc, char **argv) { - if (confirm ("Do a RESET (PC = 00000)?")) - { - saturn.PC = 0; - enter_debugger &= ~ILLEGAL_INSTRUCTION; - } +static void do_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 do_rstk(int argc, char **argv) { int i, j; - disassemble (saturn.PC, instr); - printf ("PC: %.5lX: %s\n", saturn.PC, instr); - if (saturn.rstkp < 0) - { - printf ("Empty return stack.\n"); - } - else - { - j = 0; - for (i = saturn.rstkp; i >= 0; i--) - { - disassemble (saturn.rstk[i], instr); - printf ("%2d: %.5lX: %s\n", j, saturn.rstk[i], instr); + disassemble(saturn.PC, instr); + printf("PC: %.5lX: %s\n", saturn.PC, instr); + if (saturn.rstkp < 0) { + printf("Empty return stack.\n"); + } else { + j = 0; + for (i = saturn.rstkp; i >= 0; i--) { + disassemble(saturn.rstk[i], instr); + printf("%2d: %.5lX: %s\n", j, saturn.rstk[i], instr); j++; } - } + } } -int debug (void) { +int debug(void) { t1_t2_ticks ticks; struct cmd *cmdp; char *cp; int argc; char *argv[MAX_ARGS]; char *rl = NULL; - static char *cl = (char *) 0; - static char *old_line = (char *) 0; + static char *cl = (char *)0; + static char *old_line = (char *)0; int i; /* * do we want to debug ??? */ - if (!useDebugger) - { - if (enter_debugger & ILLEGAL_INSTRUCTION) - { - if (!quiet) - fprintf (stderr, "%s: reset (illegal instruction at 0x%.5lX)\n", - progname, saturn.PC); - saturn.PC = 0; - } - if (enter_debugger & USER_INTERRUPT) - if (verbose) - printf ("%s: user interrupt (SIGINT) ignored\n", progname); - exit_x48(1); - if (enter_debugger & BREAKPOINT_HIT) - if (verbose) - printf ("%s: breakpoint hit at 0x%.5lX ignored\n", - progname, saturn.PC); - if (enter_debugger & TRAP_INSTRUCTION) - if (verbose) - printf ("%s: trap instruction at 0x%.5lX ignored\n", - progname, saturn.PC); - enter_debugger = 0; - return 0; + if (!useDebugger) { + if (enter_debugger & ILLEGAL_INSTRUCTION) { + if (!quiet) + fprintf(stderr, "%s: reset (illegal instruction at 0x%.5lX)\n", + progname, saturn.PC); + saturn.PC = 0; } + if (enter_debugger & USER_INTERRUPT) + if (verbose) + printf("%s: user interrupt (SIGINT) ignored\n", progname); + exit_x48(1); + if (enter_debugger & BREAKPOINT_HIT) + if (verbose) + printf("%s: breakpoint hit at 0x%.5lX ignored\n", progname, saturn.PC); + if (enter_debugger & TRAP_INSTRUCTION) + if (verbose) + printf("%s: trap instruction at 0x%.5lX ignored\n", progname, + saturn.PC); + enter_debugger = 0; + return 0; + } /* * update the lcd if necessary */ - if (device.display_touched) - { - device.display_touched = 0; - update_display (); + if (device.display_touched) { + device.display_touched = 0; + update_display(); #ifdef HAVE_XSHM - if (disp.display_update) - refresh_display (); + if (disp.display_update) + refresh_display(); #endif - } + } /* * debugging is counted as idle time */ - stop_timer (RUN_TIMER); - start_timer (IDLE_TIMER); + stop_timer(RUN_TIMER); + start_timer(IDLE_TIMER); continue_flag = 0; - if (enter_debugger & ILLEGAL_INSTRUCTION) - { - printf ("ILLEGAL INSTRUCTION at %.5lX : %s\n", - saturn.PC, str_nibbles (saturn.PC, 16)); - } + if (enter_debugger & ILLEGAL_INSTRUCTION) { + printf("ILLEGAL INSTRUCTION at %.5lX : %s\n", saturn.PC, + str_nibbles(saturn.PC, 16)); + } - if (enter_debugger & TRAP_INSTRUCTION) - { - printf ("TRAP at %.5lX : %s\n", - saturn.PC - 5, str_nibbles (saturn.PC - 5, 16)); - enter_debugger &= ~TRAP_INSTRUCTION; - } + if (enter_debugger & TRAP_INSTRUCTION) { + printf("TRAP at %.5lX : %s\n", saturn.PC - 5, + str_nibbles(saturn.PC - 5, 16)); + enter_debugger &= ~TRAP_INSTRUCTION; + } - do - { + do { - /* - * print current instruction - */ - disassemble (saturn.PC, instr); - printf ("%.5lX: %s\n", saturn.PC, instr); + /* + * print current instruction + */ + disassemble(saturn.PC, instr); + printf("%.5lX: %s\n", saturn.PC, instr); - /* - * read a command - */ - rl = readline ("x48-debug> "); + /* + * read a command + */ + rl = readline("x48-debug> "); - if (rl == (char *) 0) - { + if (rl == (char *)0) { continue_flag = 1; continue; } - if (*rl == '\0') - { - free (rl); - rl = (char *) 0; - if (cl) - { - free (cl); - cl = (char *) 0; - } - cl = strdup (old_line == NULL ? "(null)" : old_line); - } - else - { - if (cl) - { - free (cl); - cl = (char *) 0; - } - if (old_line) - { - free (old_line); - old_line = (char *) 0; - } - cl = strdup (rl); - old_line = strdup (rl); + if (*rl == '\0') { + free(rl); + rl = (char *)0; + if (cl) { + free(cl); + cl = (char *)0; + } + cl = strdup(old_line == NULL ? "(null)" : old_line); + } else { + if (cl) { + free(cl); + cl = (char *)0; + } + if (old_line) { + free(old_line); + old_line = (char *)0; + } + cl = strdup(rl); + old_line = strdup(rl); #ifdef HAVE_READLINE - add_history (rl); + add_history(rl); #endif - free (rl); - rl = (char *) 0; + free(rl); + rl = (char *)0; } - /* - * decode the commandline - */ - cp = strtok (cl, " \t"); - for (cmdp = cmd_tbl; cmdp->name; cmdp++) - { - if (strcmp (cp, cmdp->name) == 0) - { - break; - } + /* + * decode the commandline + */ + cp = strtok(cl, " \t"); + for (cmdp = cmd_tbl; cmdp->name; cmdp++) { + if (strcmp(cp, cmdp->name) == 0) { + break; + } } - argc = 0; - argv[argc++] = cp; - while ((cp = strtok ((char *) 0, " \t")) != (char *) 0) - { + argc = 0; + argv[argc++] = cp; + while ((cp = strtok((char *)0, " \t")) != (char *)0) { argv[argc++] = cp; if (argc == MAX_ARGS) break; } - for (i = argc; i < MAX_ARGS; i++) - argv[i] = (char *) NULL; + for (i = argc; i < MAX_ARGS; i++) + argv[i] = (char *)NULL; - /* - * execute the command, if valid - */ - if (cmdp->func) - { - (*cmdp->func) (argc, argv); + /* + * execute the command, if valid + */ + if (cmdp->func) { + (*cmdp->func)(argc, argv); + } else { + printf("Undefined command \"%s\". Try \"help\".\n", argv[0]); } - else - { - printf ("Undefined command \"%s\". Try \"help\".\n", argv[0]); - } - in_debugger = 0; + in_debugger = 0; - } - while (!continue_flag); + } while (!continue_flag); /* * adjust the hp48's timers */ in_debugger = 1; - ticks = get_t1_t2 (); + ticks = get_t1_t2(); in_debugger = 0; - if (saturn.t2_ctrl & 0x01) - { - saturn.timer2 = ticks.t2_ticks; - } + if (saturn.t2_ctrl & 0x01) { + saturn.timer2 = ticks.t2_ticks; + } saturn.timer1 = (set_t1 - ticks.t1_ticks) & 0xf; @@ -1725,20 +1357,17 @@ int debug (void) { /* * restart timers */ - stop_timer (IDLE_TIMER); - start_timer (RUN_TIMER); + stop_timer(IDLE_TIMER); + start_timer(RUN_TIMER); set_accesstime(); - if (enter_debugger & ILLEGAL_INSTRUCTION) - { - printf ("Reset (ILLEGAL INSTRUCTION)\n"); - saturn.PC = 0; - } - else - { - printf ("Continue.\n"); - } + if (enter_debugger & ILLEGAL_INSTRUCTION) { + printf("Reset (ILLEGAL INSTRUCTION)\n"); + saturn.PC = 0; + } else { + printf("Continue.\n"); + } enter_debugger = 0; @@ -1752,28 +1381,23 @@ int debug (void) { return 0; } -int emulate_debug (void) { - do - { +int emulate_debug(void) { + do { - step_instruction (); + step_instruction(); - if (exec_flags & EXEC_BKPT) - { - if (check_breakpoint (BP_EXEC, saturn.PC)) - { - enter_debugger |= BREAKPOINT_HIT; - break; - } + if (exec_flags & EXEC_BKPT) { + if (check_breakpoint(BP_EXEC, saturn.PC)) { + enter_debugger |= BREAKPOINT_HIT; + break; + } } - if (schedule_event-- == 0) - { - schedule (); + if (schedule_event-- == 0) { + schedule(); } - } - while (!enter_debugger); + } while (!enter_debugger); return 0; } diff --git a/src/debugger.h b/src/debugger.h index 1044543..84d236d 100644 --- a/src/debugger.h +++ b/src/debugger.h @@ -38,29 +38,29 @@ */ #ifndef _DEBUGGER_H -#define _DEBUGGER_H 1 +#define _DEBUGGER_H 1 #include "global.h" #include "hp48.h" -#define USER_INTERRUPT 1 -#define ILLEGAL_INSTRUCTION 2 -#define BREAKPOINT_HIT 4 -#define TRAP_INSTRUCTION 8 +#define USER_INTERRUPT 1 +#define ILLEGAL_INSTRUCTION 2 +#define BREAKPOINT_HIT 4 +#define TRAP_INSTRUCTION 8 /* * exec_flags values */ -#define EXEC_BKPT 1 +#define EXEC_BKPT 1 -extern int enter_debugger; -extern int in_debugger; -extern int exec_flags; +extern int enter_debugger; +extern int in_debugger; +extern int exec_flags; -extern void init_debugger __ProtoType__((void)); -extern int debug __ProtoType__((void)); -extern int emulate_debug __ProtoType__((void)); +extern void init_debugger __ProtoType__((void)); +extern int debug __ProtoType__((void)); +extern int emulate_debug __ProtoType__((void)); -extern char *str_nibbles __ProtoType__((word_20 addr, int n)); +extern char *str_nibbles __ProtoType__((word_20 addr, int n)); #endif /* !_DEBUGGER_H */ diff --git a/src/device.c b/src/device.c index a057f34..a6d394b 100644 --- a/src/device.c +++ b/src/device.c @@ -53,9 +53,9 @@ #include +#include "device.h" #include "hp48.h" #include "hp48_emu.h" -#include "device.h" #include "timer.h" #include "x48_x11.h" @@ -175,10 +175,10 @@ void check_devices(void) { #if 0 +#include #include #include #include -#include void check_out_register(void) { static int au = -2; diff --git a/src/device.h b/src/device.h index 34fa31d..0e51998 100644 --- a/src/device.h +++ b/src/device.h @@ -51,24 +51,25 @@ #define _DEVICE_H 1 #include "global.h" +#include "hp48.h" -#define DISP_INSTR_OFF 0x10 +#define DISP_INSTR_OFF 0x10 -#define ANN_LEFT 0x81 -#define ANN_RIGHT 0x82 -#define ANN_ALPHA 0x84 -#define ANN_BATTERY 0x88 -#define ANN_BUSY 0x90 -#define ANN_IO 0xa0 +#define ANN_LEFT 0x81 +#define ANN_RIGHT 0x82 +#define ANN_ALPHA 0x84 +#define ANN_BATTERY 0x88 +#define ANN_BUSY 0x90 +#define ANN_IO 0xa0 typedef struct device_t { - int display_touched; + int display_touched; char contrast_touched; char disp_test_touched; - + char crc_touched; char power_status_touched; @@ -77,7 +78,7 @@ typedef struct device_t { char mode_touched; char ann_touched; - + char baud_touched; char card_ctrl_touched; @@ -102,7 +103,7 @@ typedef struct device_t { char scratch_touched; char base_nibble_touched; - + char unknown_touched; char t1_ctrl_touched; @@ -116,16 +117,16 @@ typedef struct device_t { } device_t; extern device_t device; -extern void check_devices __ProtoType__((void)); +extern void check_devices __ProtoType__((void)); #if 0 extern void check_out_register __ProtoType__((void)); #endif -extern void update_display __ProtoType__((void)); -extern void redraw_display __ProtoType__((void)); -extern void disp_draw_nibble __ProtoType__((word_20 addr, word_4 val)); -extern void menu_draw_nibble __ProtoType__((word_20 addr, word_4 val)); -extern void draw_annunc __ProtoType__((void)); -extern void redraw_annunc __ProtoType__((void)); +extern void update_display __ProtoType__((void)); +extern void redraw_display __ProtoType__((void)); +extern void disp_draw_nibble __ProtoType__((word_20 addr, word_4 val)); +extern void menu_draw_nibble __ProtoType__((word_20 addr, word_4 val)); +extern void draw_annunc __ProtoType__((void)); +extern void redraw_annunc __ProtoType__((void)); #endif /* !_DEVICE_H */ diff --git a/src/disasm.c b/src/disasm.c index 5b6b216..7dccb76 100644 --- a/src/disasm.c +++ b/src/disasm.c @@ -45,306 +45,317 @@ #include "global.h" -#include #include +#include #include -#include "hp48.h" #include "disasm.h" +#include "hp48.h" -#define TAB_SKIP 8 +#define TAB_SKIP 8 int disassembler_mode = CLASS_MNEMONICS; -char *mode_name[] = -{ - "HP", - "class" +char *mode_name[] = {"HP", "class"}; + +static char *hex[] = { + "0123456789ABCDEF", + "0123456789abcdef", }; -static char *hex[] = -{ - "0123456789ABCDEF", - "0123456789abcdef", +static char *opcode_0_tbl[32] = { + /* + * HP Mnemonics + */ + "RTNSXM", "RTN", "RTNSC", "RTNCC", "SETHEX", "SETDEC", "RSTK=C", "C=RSTK", + "CLRST", "C=ST", "ST=C", "CSTEX", "P=P+1", "P=P-1", "(NULL)", "RTI", + /* + * Class Mnemonics + */ + "rtnsxm", "rtn", "rtnsc", "rtncc", "sethex", "setdec", "push", "pop", + "clr.3 st", "move.3 st, c", "move.3 c, st", "exg.3 c, st", + "inc.1 p", "dec.1 p", "(null)", "rti"}; + +static char *op_str_0[16] = { + /* + * HP Mnemonics + */ + "A=A%cB", "B=B%cC", "C=C%cA", "D=D%cC", "B=B%cA", "C=C%cB", "A=A%cC", + "C=C%cD", + /* + * Class Mnemonics + */ + "b, a", "c, b", "a, c", "c, d", "a, b", "b, c", "c, a", "d, c"}; + +static char *op_str_1[16] = { + /* + * HP Mnemonics + */ + "DAT0=A", "DAT1=A", "A=DAT0", "A=DAT1", "DAT0=C", "DAT1=C", "C=DAT0", + "C=DAT1", + /* + * Class Mnemonics + */ + "a, (d0)", "a, (d1)", "(d0), a", "(d1), a", "c, (d0)", "c, (d1)", "(d0), c", + "(d1), c"}; + +static char *in_str_80[32] = { + /* + * HP Mnemonics + */ + "OUT=CS", "OUT=C", "A=IN", "C=IN", "UNCNFG", "CONFIG", "C=ID", "SHUTDN", + NULL, "C+P+1", "RESET", "BUSCC", NULL, NULL, "SREQ?", NULL, + /* + * Class Mnemonics + */ + "move.s c, out", "move.3 c, out", "move.4 in, a", "move.4 in, c", + "uncnfg", "config", "c=id", "shutdn", NULL, "add.a p+1, c", "reset", + "buscc", NULL, NULL, "sreq?", NULL}; + +static char *in_str_808[32] = { + /* + * HP Mnemonics + */ + "INTON", NULL, NULL, "BUSCB", NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, "PC=(A)", "BUSCD", "PC=(C)", "INTOFF", + /* + * Class Mnemonics + */ + "inton", NULL, NULL, "buscb", NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, "jmp (a)", "buscd", "jmp (c)", "intoff"}; + +static char *op_str_81[8] = { + /* + * HP Mnemonics + */ + "A", + "B", + "C", + "D", + /* + * Class Mnemonics + */ + "a", + "b", + "c", + "d", }; -static char *opcode_0_tbl[32] = -{ -/* - * HP Mnemonics - */ - "RTNSXM", "RTN", "RTNSC", "RTNCC", - "SETHEX", "SETDEC", "RSTK=C", "C=RSTK", - "CLRST", "C=ST", "ST=C", "CSTEX", - "P=P+1", "P=P-1", "(NULL)", "RTI", -/* - * Class Mnemonics - */ - "rtnsxm", "rtn", "rtnsc", "rtncc", - "sethex", "setdec", "push", "pop", - "clr.3 st", "move.3 st, c", "move.3 c, st", "exg.3 c, st", - "inc.1 p", "dec.1 p", "(null)", "rti" +static char *in_str_81b[32] = { + /* + * HP Mnemonics + */ + NULL, + NULL, + "PC=A", + "PC=C", + "A=PC", + "C=PC", + "APCEX", + "CPCEX", + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + /* + * Class Mnemonics + */ + NULL, + NULL, + "jmp a", + "jmp c", + "move.a pc, a", + "move.a pc, c", + "exg.a a, pc", + "exg.a c, pc", + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, }; -static char *op_str_0[16] = -{ -/* - * HP Mnemonics - */ - "A=A%cB", "B=B%cC", "C=C%cA", "D=D%cC", - "B=B%cA", "C=C%cB", "A=A%cC", "C=C%cD", -/* - * Class Mnemonics - */ - "b, a", "c, b", "a, c", "c, d", - "a, b", "b, c", "c, a", "d, c" -}; +static char *in_str_9[16] = { + /* + * HP Mnemonics + */ + "=", "#", "=", "#", ">", "<", ">=", "<=", + /* + * Class Mnemonics + */ + "eq", "ne", "eq", "ne", "gt", "lt", "ge", "le"}; -static char *op_str_1[16] = -{ -/* - * HP Mnemonics - */ - "DAT0=A", "DAT1=A", "A=DAT0", "A=DAT1", - "DAT0=C", "DAT1=C", "C=DAT0", "C=DAT1", -/* - * Class Mnemonics - */ - "a, (d0)", "a, (d1)", "(d0), a", "(d1), a", - "c, (d0)", "c, (d1)", "(d0), c", "(d1), c" -}; +static char *op_str_9[16] = { + /* + * HP Mnemonics + */ + "?A%sB", "?B%sC", "?C%sA", "?D%sC", "?A%s0", "?B%s0", "?C%s0", "?D%s0", + /* + * Class Mnemonics + */ + "a, b", "b, c", "c, a", "d, c", "a, 0", "b, 0", "c, 0", "d, 0"}; -static char *in_str_80[32] = -{ -/* - * HP Mnemonics - */ - "OUT=CS", "OUT=C", "A=IN", "C=IN", - "UNCNFG", "CONFIG", "C=ID", "SHUTDN", - NULL, "C+P+1", "RESET", "BUSCC", - NULL, NULL, "SREQ?", NULL, -/* - * Class Mnemonics - */ - "move.s c, out", "move.3 c, out", "move.4 in, a", "move.4 in, c", - "uncnfg", "config", "c=id", "shutdn", - NULL, "add.a p+1, c", "reset", "buscc", - NULL, NULL, "sreq?", NULL -}; - -static char *in_str_808[32] = -{ -/* - * HP Mnemonics - */ - "INTON", NULL, NULL, "BUSCB", - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - "PC=(A)", "BUSCD", "PC=(C)", "INTOFF", -/* - * Class Mnemonics - */ - "inton", NULL, NULL, "buscb", - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - "jmp (a)", "buscd", "jmp (c)", "intoff" -}; - -static char *op_str_81[8] = -{ -/* - * HP Mnemonics - */ - "A", "B", "C", "D", -/* - * Class Mnemonics - */ - "a", "b", "c", "d", -}; - -static char *in_str_81b[32] = -{ -/* - * HP Mnemonics - */ - NULL, NULL, "PC=A", "PC=C", - "A=PC", "C=PC", "APCEX", "CPCEX", - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, -/* - * Class Mnemonics - */ - NULL, NULL, "jmp a", "jmp c", - "move.a pc, a", "move.a pc, c", "exg.a a, pc", "exg.a c, pc", - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, -}; - -static char *in_str_9[16] = -{ -/* - * HP Mnemonics - */ - "=", "#", "=", "#", - ">", "<", ">=", "<=", -/* - * Class Mnemonics - */ - "eq", "ne", "eq", "ne", - "gt", "lt", "ge", "le" -}; - -static char *op_str_9[16] = -{ -/* - * HP Mnemonics - */ - "?A%sB", "?B%sC", "?C%sA", "?D%sC", - "?A%s0", "?B%s0", "?C%s0", "?D%s0", -/* - * Class Mnemonics - */ - "a, b", "b, c", "c, a", "d, c", - "a, 0", "b, 0", "c, 0", "d, 0" -}; - -static char *op_str_af[32] = -{ -/* - * HP Mnemonics - */ - "A=A%sB", "B=B%sC", "C=C%sA", "D=D%sC", - "A=A%sA", "B=B%sB", "C=C%sC", "D=D%sD", - "B=B%sA", "C=C%sB", "A=A%sC", "C=C%sD", - "A=B%sA", "B=C%sB", "C=A%sC", "D=C%sD", -/* - * Class Mnemonics - */ - "b, a", "c, b", "a, c", "c, d", - "a, a", "b, b", "c, c", "d, d", - "a, b", "b, c", "c, a", "d, c", - "b, a", "c, b", "a, c", "c, d" -}; +static char *op_str_af[32] = { + /* + * HP Mnemonics + */ + "A=A%sB", "B=B%sC", "C=C%sA", "D=D%sC", "A=A%sA", "B=B%sB", "C=C%sC", + "D=D%sD", "B=B%sA", "C=C%sB", "A=A%sC", "C=C%sD", "A=B%sA", "B=C%sB", + "C=A%sC", "D=C%sD", + /* + * Class Mnemonics + */ + "b, a", "c, b", "a, c", "c, d", "a, a", "b, b", "c, c", "d, d", "a, b", + "b, c", "c, a", "d, c", "b, a", "c, b", "a, c", "c, d"}; static char hp_reg_1_af[] = "ABCDABCDBCACABAC"; static char hp_reg_2_af[] = "0000BCACABCDBCCD"; -static char *field_tbl[32] = -{ -/* - * HP Mnemonics - */ - "P", "WP", "XS", "X", - "S", "M", "B", "W", - "P", "WP", "XS", "X", - "S", "M", "B", "A", -/* - * Class Mnemonics - */ - ".p", ".wp", ".xs", ".x", - ".s", ".m", ".b", ".w", - ".p", ".wp", ".xs", ".x", - ".s", ".m", ".b", ".a", +static char *field_tbl[32] = { + /* + * HP Mnemonics + */ + "P", + "WP", + "XS", + "X", + "S", + "M", + "B", + "W", + "P", + "WP", + "XS", + "X", + "S", + "M", + "B", + "A", + /* + * Class Mnemonics + */ + ".p", + ".wp", + ".xs", + ".x", + ".s", + ".m", + ".b", + ".w", + ".p", + ".wp", + ".xs", + ".x", + ".s", + ".m", + ".b", + ".a", }; -static char *hst_bits[8] = -{ -/* - * HP Mnemonics - */ - "XM", "SB", "SR", "MP", -/* - * Class Mnemonics - */ - "xm", "sb", "sr", "mp", +static char *hst_bits[8] = { + /* + * HP Mnemonics + */ + "XM", + "SB", + "SR", + "MP", + /* + * Class Mnemonics + */ + "xm", + "sb", + "sr", + "mp", }; -int read_int (word_20 * addr, int n) { +int read_int(word_20 *addr, int n) { int i, t; for (i = 0, t = 0; i < n; i++) - t |= read_nibble ((*addr)++) << (i * 4); + t |= read_nibble((*addr)++) << (i * 4); return t; } -char * append_str (char *buf, char *str) { +char *append_str(char *buf, char *str) { while ((*buf = *str++)) buf++; return buf; } -char * append_tab_16 (char *buf) { +char *append_tab_16(char *buf) { int n; char *p; - n = 16 - (strlen (buf) % 16); - p = &buf[strlen (buf)]; + n = 16 - (strlen(buf) % 16); + p = &buf[strlen(buf)]; while (n--) *p++ = ' '; *p = '\0'; return p; } -char * append_tab (char *buf) { +char *append_tab(char *buf) { int n; char *p; - n = TAB_SKIP - (strlen (buf) % TAB_SKIP); - p = &buf[strlen (buf)]; + n = TAB_SKIP - (strlen(buf) % TAB_SKIP); + p = &buf[strlen(buf)]; while (n--) *p++ = ' '; *p = '\0'; return p; } -char * append_field (char *buf, word_4 fn) { - buf = append_str (buf, field_tbl[fn + 16 * disassembler_mode]); +char *append_field(char *buf, word_4 fn) { + buf = append_str(buf, field_tbl[fn + 16 * disassembler_mode]); return buf; } -char * append_imm_nibble (char *buf, word_20 * addr, int n) { +char *append_imm_nibble(char *buf, word_20 *addr, int n) { int i; char t[16]; - if (disassembler_mode == CLASS_MNEMONICS) - { - *buf++ = '#'; - if (n > 1) - *buf++ = '$'; - } - if (n > 1) - { - for (i = 0; i < n; i++) - t[i] = hex[disassembler_mode][read_nibble ((*addr)++)]; - for (i = n - 1; i >= 0; i--) - { + if (disassembler_mode == CLASS_MNEMONICS) { + *buf++ = '#'; + if (n > 1) + *buf++ = '$'; + } + if (n > 1) { + for (i = 0; i < n; i++) + t[i] = hex[disassembler_mode][read_nibble((*addr)++)]; + for (i = n - 1; i >= 0; i--) { *buf++ = t[i]; } - *buf = '\0'; - } - else - { - sprintf (t, "%d", read_nibble ((*addr)++)); - buf = append_str (buf, t); - } + *buf = '\0'; + } else { + sprintf(t, "%d", read_nibble((*addr)++)); + buf = append_str(buf, t); + } return buf; } -char * append_addr (char *buf, word_20 addr) { +char *append_addr(char *buf, word_20 addr) { int shift; long mask; - if (disassembler_mode == CLASS_MNEMONICS) - { - *buf++ = '$'; - } + if (disassembler_mode == CLASS_MNEMONICS) { + *buf++ = '$'; + } for (mask = 0xf0000, shift = 16; mask != 0; mask >>= 4, shift -= 4) *buf++ = hex[disassembler_mode][(addr & mask) >> shift]; *buf = '\0'; return buf; } -char * append_r_addr (char *buf, word_20 * pc, long disp, int n, int offset) { +char *append_r_addr(char *buf, word_20 *pc, long disp, int n, int offset) { long sign; sign = 1 << (n * 4 - 1); @@ -352,105 +363,93 @@ char * append_r_addr (char *buf, word_20 * pc, long disp, int n, int offset) { disp |= ~(sign - 1); *pc += disp; - switch (disassembler_mode) - { - case HP_MNEMONICS: - if (disp < 0) - { - buf = append_str (buf, "-"); + switch (disassembler_mode) { + case HP_MNEMONICS: + if (disp < 0) { + buf = append_str(buf, "-"); disp = -disp - offset; - } - else - { - buf = append_str (buf, "+"); + } else { + buf = append_str(buf, "+"); disp += offset; } - buf = append_addr (buf, disp); - break; - case CLASS_MNEMONICS: - if (disp < 0) - { - buf = append_str (buf, "-"); + buf = append_addr(buf, disp); + break; + case CLASS_MNEMONICS: + if (disp < 0) { + buf = append_str(buf, "-"); disp = -disp - offset; - } - else - { - buf = append_str (buf, "+"); + } else { + buf = append_str(buf, "+"); disp += offset; } - buf = append_addr (buf, disp); - break; - default: - buf = append_str (buf, "Unknown disassembler mode"); - break; - } + buf = append_addr(buf, disp); + break; + default: + buf = append_str(buf, "Unknown disassembler mode"); + break; + } return buf; } -char * append_pc_comment (char *buf, word_20 pc) { +char *append_pc_comment(char *buf, word_20 pc) { char *p = buf; - while (strlen (buf) < 4 * TAB_SKIP) - p = append_tab (buf); + while (strlen(buf) < 4 * TAB_SKIP) + p = append_tab(buf); - switch (disassembler_mode) - { - case HP_MNEMONICS: - p = append_str (p, "# Address: "); - p = append_addr (p, pc); - break; - case CLASS_MNEMONICS: - p = append_str (p, "; address: "); - p = append_addr (p, pc); - break; - default: - p = append_str (p, "Unknown disassembler mode"); - break; - } + switch (disassembler_mode) { + case HP_MNEMONICS: + p = append_str(p, "# Address: "); + p = append_addr(p, pc); + break; + case CLASS_MNEMONICS: + p = append_str(p, "; address: "); + p = append_addr(p, pc); + break; + default: + p = append_str(p, "Unknown disassembler mode"); + break; + } return p; } - -char * append_hst_bits (char *buf, int n) { +char *append_hst_bits(char *buf, int n) { int i; char *p = buf; - switch (disassembler_mode) - { - case HP_MNEMONICS: - for (i = 0; i < 4; i++) - if (n & (1 << i)) - { + switch (disassembler_mode) { + case HP_MNEMONICS: + for (i = 0; i < 4; i++) + if (n & (1 << i)) { if (p != buf) - p = append_str (p, "="); - p = append_str (p, hst_bits[i + 4 * disassembler_mode]); + p = append_str(p, "="); + p = append_str(p, hst_bits[i + 4 * disassembler_mode]); } - break; + break; - case CLASS_MNEMONICS: - while (strlen (buf) < 4 * TAB_SKIP) - p = append_tab (buf); - p = &buf[strlen (buf)]; - p = append_str (p, "; hst bits: "); + case CLASS_MNEMONICS: + while (strlen(buf) < 4 * TAB_SKIP) + p = append_tab(buf); + p = &buf[strlen(buf)]; + p = append_str(p, "; hst bits: "); - for (buf = p, i = 0; i < 4; i++) - if (n & (1 << i)) - { + for (buf = p, i = 0; i < 4; i++) + if (n & (1 << i)) { if (p != buf) - p = append_str (p, ", "); - p = append_str (p, hst_bits[i + 4 * disassembler_mode]); + p = append_str(p, ", "); + p = append_str(p, hst_bits[i + 4 * disassembler_mode]); } - break; + break; - default: - p = append_str (p, "Unknown disassembler mode"); - break; - } + default: + p = append_str(p, "Unknown disassembler mode"); + break; + } return p; } -char * disasm_1 (word_20 * addr, char *out) { +char *disasm_1(word_20 *addr, char *out) { word_4 n; word_4 fn; char *p; @@ -458,212 +457,184 @@ char * disasm_1 (word_20 * addr, char *out) { char c; p = out; - switch ((n = read_nibble ((*addr)++))) - { - case 0: - case 1: - fn = read_nibble ((*addr)++); - fn = (fn & 7); - if (fn > 4) - fn -= 4; - switch (disassembler_mode) - { + switch ((n = read_nibble((*addr)++))) { + case 0: + case 1: + fn = read_nibble((*addr)++); + fn = (fn & 7); + if (fn > 4) + fn -= 4; + switch (disassembler_mode) { case HP_MNEMONICS: - c = (char) ((fn < 8) ? 'A' : 'C'); + c = (char)((fn < 8) ? 'A' : 'C'); if (n == 0) - sprintf (buf, "R%d=%c", fn, c); + sprintf(buf, "R%d=%c", fn, c); else - sprintf (buf, "%c=R%d", c, fn); - p = append_str (out, buf); + sprintf(buf, "%c=R%d", c, fn); + p = append_str(out, buf); break; case CLASS_MNEMONICS: - p = append_str (out, "move.w"); - p = append_tab (out); - c = (char) ((fn < 8) ? 'a' : 'c'); + p = append_str(out, "move.w"); + p = append_tab(out); + c = (char)((fn < 8) ? 'a' : 'c'); if (n == 0) - sprintf (buf, "%c, r%d", c, fn); + sprintf(buf, "%c, r%d", c, fn); else - sprintf (buf, "r%d, %c", fn, c); - p = append_str (p, buf); + sprintf(buf, "r%d, %c", fn, c); + p = append_str(p, buf); break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - case 2: - fn = read_nibble ((*addr)++); - fn = (fn & 7); - if (fn > 4) - fn -= 4; - switch (disassembler_mode) - { + case 2: + fn = read_nibble((*addr)++); + fn = (fn & 7); + if (fn > 4) + fn -= 4; + switch (disassembler_mode) { case HP_MNEMONICS: - c = (char) ((fn < 8) ? 'A' : 'C'); - sprintf (buf, "%cR%dEX", c, fn); - p = append_str (out, buf); + c = (char)((fn < 8) ? 'A' : 'C'); + sprintf(buf, "%cR%dEX", c, fn); + p = append_str(out, buf); break; case CLASS_MNEMONICS: - p = append_str (out, "exg.w"); - p = append_tab (out); - c = (char) ((fn < 8) ? 'a' : 'c'); - sprintf (buf, "%c, r%d", c, fn); - p = append_str (p, buf); + p = append_str(out, "exg.w"); + p = append_tab(out); + c = (char)((fn < 8) ? 'a' : 'c'); + sprintf(buf, "%c, r%d", c, fn); + p = append_str(p, buf); break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - case 3: - n = read_nibble ((*addr)++); - switch (disassembler_mode) - { + case 3: + n = read_nibble((*addr)++); + switch (disassembler_mode) { case HP_MNEMONICS: c = (n & 4) ? 'C' : 'A'; - if (n & 2) - { - if (n < 8) - { - sprintf (buf, "%cD%dEX", c, (n & 1)); + if (n & 2) { + if (n < 8) { + sprintf(buf, "%cD%dEX", c, (n & 1)); + } else { + sprintf(buf, "%cD%dXS", c, (n & 1)); } - else - { - sprintf (buf, "%cD%dXS", c, (n & 1)); + } else { + if (n < 8) { + sprintf(buf, "D%d=%c", (n & 1), c); + } else { + sprintf(buf, "D%d=%cS", (n & 1), c); } - } - else - { - if (n < 8) - { - sprintf (buf, "D%d=%c", (n & 1), c); - } - else - { - sprintf (buf, "D%d=%cS", (n & 1), c); - } - } - p = append_str (out, buf); + } + p = append_str(out, buf); break; case CLASS_MNEMONICS: - p = append_str (out, (n & 2) ? "exg." : "move."); - p = append_str (p, (n < 8) ? "a" : "4"); - p = append_tab (out); + p = append_str(out, (n & 2) ? "exg." : "move."); + p = append_str(p, (n < 8) ? "a" : "4"); + p = append_tab(out); c = (n & 4) ? 'c' : 'a'; - sprintf (buf, "%c, d%d", c, (n & 1)); - p = append_str (p, buf); + sprintf(buf, "%c, d%d", c, (n & 1)); + p = append_str(p, buf); break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - case 4: - case 5: - fn = read_nibble ((*addr)++); - switch (disassembler_mode) - { + case 4: + case 5: + fn = read_nibble((*addr)++); + switch (disassembler_mode) { case HP_MNEMONICS: - p = append_str (out, op_str_1[(fn & 7) + 8 * disassembler_mode]); - p = append_tab (out); - if (n == 4) - { - p = append_str (p, (fn < 8) ? "A" : "B"); - } - else - { - n = read_nibble ((*addr)++); - if (fn < 8) - { - p = append_field (p, n); - } - else - { - sprintf (buf, "%d", n + 1); - p = append_str (p, buf); - } + p = append_str(out, op_str_1[(fn & 7) + 8 * disassembler_mode]); + p = append_tab(out); + if (n == 4) { + p = append_str(p, (fn < 8) ? "A" : "B"); + } else { + n = read_nibble((*addr)++); + if (fn < 8) { + p = append_field(p, n); + } else { + sprintf(buf, "%d", n + 1); + p = append_str(p, buf); } + } break; case CLASS_MNEMONICS: - p = append_str (out, "move"); - if (n == 4) - { - p = append_str (p, "."); - p = append_str (p, (fn < 8) ? "a" : "b"); + p = append_str(out, "move"); + if (n == 4) { + p = append_str(p, "."); + p = append_str(p, (fn < 8) ? "a" : "b"); + } else { + n = read_nibble((*addr)++); + if (fn < 8) { + p = append_field(p, n); + } else { + sprintf(buf, ".%d", n + 1); + p = append_str(p, buf); } - else - { - n = read_nibble ((*addr)++); - if (fn < 8) - { - p = append_field (p, n); - } - else - { - sprintf (buf, ".%d", n + 1); - p = append_str (p, buf); - } - } - p = append_tab (out); - p = append_str (p, op_str_1[(fn & 7) + 8 * disassembler_mode]); + } + p = append_tab(out); + p = append_str(p, op_str_1[(fn & 7) + 8 * disassembler_mode]); break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - case 6: - case 7: - case 8: - case 0xc: - fn = read_nibble (*addr++); - switch (disassembler_mode) - { + case 6: + case 7: + case 8: + case 0xc: + fn = read_nibble(*addr++); + switch (disassembler_mode) { case HP_MNEMONICS: if (n == 6 || n == 8) - p = append_str (out, "D0=D0"); + p = append_str(out, "D0=D0"); else - p = append_str (out, "D1=D1"); + p = append_str(out, "D1=D1"); if (n < 8) - p = append_str (p, "+"); + p = append_str(p, "+"); else - p = append_str (p, "-"); - p = append_tab (out); - sprintf (buf, "%d", fn + 1); - p = append_str (p, buf); + p = append_str(p, "-"); + p = append_tab(out); + sprintf(buf, "%d", fn + 1); + p = append_str(p, buf); break; case CLASS_MNEMONICS: if (n < 8) - p = append_str (out, "add.a"); + p = append_str(out, "add.a"); else - p = append_str (out, "sub.a"); - p = append_tab (out); - sprintf (buf, "#%d, ", fn + 1); - p = append_str (p, buf); + p = append_str(out, "sub.a"); + p = append_tab(out); + sprintf(buf, "#%d, ", fn + 1); + p = append_str(p, buf); if (n == 6 || n == 8) - p = append_str (p, "d0"); + p = append_str(p, "d0"); else - p = append_str (p, "d1"); + p = append_str(p, "d1"); break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - case 9: - case 0xa: - case 0xb: - case 0xd: - case 0xe: - case 0xf: - c = (char) ((n < 0xd) ? '0' : '1'); - switch (n & 3) - { + case 9: + case 0xa: + case 0xb: + case 0xd: + case 0xe: + case 0xf: + c = (char)((n < 0xd) ? '0' : '1'); + switch (n & 3) { case 1: n = 2; break; @@ -674,47 +645,40 @@ char * disasm_1 (word_20 * addr, char *out) { n = 5; break; } - switch (disassembler_mode) - { + switch (disassembler_mode) { case HP_MNEMONICS: - sprintf (buf, "D%c=(%d)", c, n); - p = append_str (out, buf); - p = append_tab (out); - p = append_imm_nibble (p, addr, n); + sprintf(buf, "D%c=(%d)", c, n); + p = append_str(out, buf); + p = append_tab(out); + p = append_imm_nibble(p, addr, n); break; case CLASS_MNEMONICS: - if (n == 5) - { - sprintf (buf, "move.a"); - } - else if (n == 4) - { - sprintf (buf, "move.as"); - } - else - { - sprintf (buf, "move.b"); - } - p = append_str (out, buf); - p = append_tab (out); - p = append_imm_nibble (p, addr, n); - sprintf (buf, ", d%c", c); - p = append_str (p, buf); + if (n == 5) { + sprintf(buf, "move.a"); + } else if (n == 4) { + sprintf(buf, "move.as"); + } else { + sprintf(buf, "move.b"); + } + p = append_str(out, buf); + p = append_tab(out); + p = append_imm_nibble(p, addr, n); + sprintf(buf, ", d%c", c); + p = append_str(p, buf); break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - default: - break; - } + default: + break; + } return p; } - -char * disasm_8 (word_20 * addr, char *out) { +char *disasm_8(word_20 *addr, char *out) { word_4 n; word_4 fn; char *p = out; @@ -722,607 +686,547 @@ char * disasm_8 (word_20 * addr, char *out) { char buf[20]; word_20 disp, pc; - fn = read_nibble ((*addr)++); - switch (fn) - { - case 0: - n = read_nibble ((*addr)++); - if (NULL != (p = in_str_80[n + 16 * disassembler_mode])) - { - p = append_str (out, p); + fn = read_nibble((*addr)++); + switch (fn) { + case 0: + n = read_nibble((*addr)++); + if (NULL != (p = in_str_80[n + 16 * disassembler_mode])) { + p = append_str(out, p); return p; } - switch (n) - { + switch (n) { case 8: - fn = read_nibble ((*addr)++); - if (NULL != (p = in_str_808[fn + 16 * disassembler_mode])) - { - p = append_str (out, p); - return p; + fn = read_nibble((*addr)++); + if (NULL != (p = in_str_808[fn + 16 * disassembler_mode])) { + p = append_str(out, p); + return p; + } + switch (fn) { + case 1: + n = read_nibble((*addr)++); + if (n == 0) { + switch (disassembler_mode) { + case HP_MNEMONICS: + p = append_str(out, "RSI"); + break; + case CLASS_MNEMONICS: + p = append_str(out, "rsi"); + break; + default: + p = append_str(out, "Unknown disassembler mode"); + break; + } } - switch (fn) - { - case 1: - n = read_nibble ((*addr)++); - if (n == 0) - { - switch (disassembler_mode) - { - case HP_MNEMONICS: - p = append_str (out, "RSI"); - break; - case CLASS_MNEMONICS: - p = append_str (out, "rsi"); - break; - default: - p = append_str (out, "Unknown disassembler mode"); - break; - } - } - break; - case 2: - n = read_nibble ((*addr)++); - switch (disassembler_mode) - { + break; + case 2: + n = read_nibble((*addr)++); + switch (disassembler_mode) { case HP_MNEMONICS: - if (n < 5) - { - sprintf (buf, "LA(%d)", n + 1); - } - else - { - sprintf (buf, "LAHEX"); - } - p = append_str (out, buf); - p = append_tab (out); - p = append_imm_nibble (p, addr, n + 1); + if (n < 5) { + sprintf(buf, "LA(%d)", n + 1); + } else { + sprintf(buf, "LAHEX"); + } + p = append_str(out, buf); + p = append_tab(out); + p = append_imm_nibble(p, addr, n + 1); break; case CLASS_MNEMONICS: - sprintf (buf, "move.%d", n + 1); - p = append_str (out, buf); - p = append_tab (out); - p = append_imm_nibble (p, addr, n + 1); - sprintf (buf, ", a.p"); - p = append_str (p, buf); + sprintf(buf, "move.%d", n + 1); + p = append_str(out, buf); + p = append_tab(out); + p = append_imm_nibble(p, addr, n + 1); + sprintf(buf, ", a.p"); + p = append_str(p, buf); break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - case 4: - case 5: - case 8: - case 9: + case 4: + case 5: + case 8: + case 9: - switch (disassembler_mode) - { + switch (disassembler_mode) { case HP_MNEMONICS: - sprintf (buf, "%cBIT=%d", (fn & 8) ? 'C' : 'A', - (fn & 1) ? 1 : 0); - p = append_str (out, buf); - p = append_tab (out); - p = append_imm_nibble (p, addr, 1); + sprintf(buf, "%cBIT=%d", (fn & 8) ? 'C' : 'A', (fn & 1) ? 1 : 0); + p = append_str(out, buf); + p = append_tab(out); + p = append_imm_nibble(p, addr, 1); break; case CLASS_MNEMONICS: - p = append_str (out, (fn & 1) ? "bset" : "bclr"); - p = append_tab (out); - p = append_imm_nibble (p, addr, 1); - p = append_str (p, (fn & 8) ? ", c" : ", a"); + p = append_str(out, (fn & 1) ? "bset" : "bclr"); + p = append_tab(out); + p = append_imm_nibble(p, addr, 1); + p = append_str(p, (fn & 8) ? ", c" : ", a"); break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - case 6: - case 7: - case 0xa: - case 0xb: + case 6: + case 7: + case 0xa: + case 0xb: - n = read_nibble ((*addr)++); - pc = *addr; - disp = read_int (addr, 2); + n = read_nibble((*addr)++); + pc = *addr; + disp = read_int(addr, 2); - switch (disassembler_mode) - { + switch (disassembler_mode) { case HP_MNEMONICS: - c = (char) ((fn < 0xa) ? 'A' : 'C'); - sprintf (buf, "?%cBIT=%d", c, (fn & 1) ? 1 : 0); - p = append_str (out, buf); - p = append_tab (out); - sprintf (buf, "%d", n); - p = append_str (p, buf); - if (disp != 0) - { - p = append_str (p, ", GOYES "); - p = append_r_addr (p, &pc, disp, 2, 5); - p = append_pc_comment (out, pc); - } - else - p = append_str (p, ", RTNYES"); + c = (char)((fn < 0xa) ? 'A' : 'C'); + sprintf(buf, "?%cBIT=%d", c, (fn & 1) ? 1 : 0); + p = append_str(out, buf); + p = append_tab(out); + sprintf(buf, "%d", n); + p = append_str(p, buf); + if (disp != 0) { + p = append_str(p, ", GOYES "); + p = append_r_addr(p, &pc, disp, 2, 5); + p = append_pc_comment(out, pc); + } else + p = append_str(p, ", RTNYES"); break; case CLASS_MNEMONICS: - c = (char) ((fn < 0xa) ? 'a' : 'c'); - p = append_str (out, (disp == 0) ? "rt" : "b"); - p = append_str (p, (fn & 1) ? "bs" : "bc"); - p = append_tab (out); - sprintf (buf, "#%d, %c", n, c); - p = append_str (p, buf); - if (disp != 0) - { - p = append_str (p, ", "); - p = append_r_addr (p, &pc, disp, 2, 5); - p = append_pc_comment (out, pc); - } + c = (char)((fn < 0xa) ? 'a' : 'c'); + p = append_str(out, (disp == 0) ? "rt" : "b"); + p = append_str(p, (fn & 1) ? "bs" : "bc"); + p = append_tab(out); + sprintf(buf, "#%d, %c", n, c); + p = append_str(p, buf); + if (disp != 0) { + p = append_str(p, ", "); + p = append_r_addr(p, &pc, disp, 2, 5); + p = append_pc_comment(out, pc); + } break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - default: - break; - } + default: + break; + } break; case 0xc: case 0xd: case 0xf: - fn = read_nibble ((*addr)++); - switch (disassembler_mode) - { - case HP_MNEMONICS: - sprintf (buf, (n == 0xf) ? "%c%cEX" : "%c=%c", - (n == 0xd) ? 'P' : 'C', (n == 0xd) ? 'C' : 'P'); - p = append_str (out, buf); - p = append_tab (out); - sprintf (buf, "%d", fn); - p = append_str (p, buf); - break; - case CLASS_MNEMONICS: - p = append_str (out, (n == 0xf) ? "exg.1" : "move.1"); - p = append_tab (out); - sprintf (buf, (n == 0xd) ? "p, c.%d" : "c.%d, p", fn); - p = append_str (p, buf); - break; - default: - p = append_str (out, "Unknown disassembler mode"); - break; - } + fn = read_nibble((*addr)++); + switch (disassembler_mode) { + case HP_MNEMONICS: + sprintf(buf, (n == 0xf) ? "%c%cEX" : "%c=%c", (n == 0xd) ? 'P' : 'C', + (n == 0xd) ? 'C' : 'P'); + p = append_str(out, buf); + p = append_tab(out); + sprintf(buf, "%d", fn); + p = append_str(p, buf); + break; + case CLASS_MNEMONICS: + p = append_str(out, (n == 0xf) ? "exg.1" : "move.1"); + p = append_tab(out); + sprintf(buf, (n == 0xd) ? "p, c.%d" : "c.%d, p", fn); + p = append_str(p, buf); + break; + default: + p = append_str(out, "Unknown disassembler mode"); + break; + } break; default: break; - } - break; + break; - case 1: - switch (n = read_nibble ((*addr)++)) - { + case 1: + switch (n = read_nibble((*addr)++)) { case 0: case 1: case 2: case 3: - switch (disassembler_mode) - { - case HP_MNEMONICS: - sprintf (buf, "%sSLC", op_str_81[(n & 3) + 4 * disassembler_mode]); - p = append_str (out, buf); - break; - case CLASS_MNEMONICS: - p = append_str (out, "rol.w"); - p = append_tab (out); - p = append_str (p, "#4, "); - p = append_str (p, op_str_81[(n & 3) + 4 * disassembler_mode]); - break; - default: - p = append_str (out, "Unknown disassembler mode"); - break; - } + switch (disassembler_mode) { + case HP_MNEMONICS: + sprintf(buf, "%sSLC", op_str_81[(n & 3) + 4 * disassembler_mode]); + p = append_str(out, buf); + break; + case CLASS_MNEMONICS: + p = append_str(out, "rol.w"); + p = append_tab(out); + p = append_str(p, "#4, "); + p = append_str(p, op_str_81[(n & 3) + 4 * disassembler_mode]); + break; + default: + p = append_str(out, "Unknown disassembler mode"); + break; + } break; case 4: case 5: case 6: case 7: - switch (disassembler_mode) - { - case HP_MNEMONICS: - sprintf (buf, "%sSRC", op_str_81[(n & 3) + 4 * disassembler_mode]); - p = append_str (out, buf); - break; - case CLASS_MNEMONICS: - p = append_str (out, "ror.w"); - p = append_tab (out); - p = append_str (p, "#4, "); - p = append_str (p, op_str_81[(n & 3) + 4 * disassembler_mode]); - break; - default: - p = append_str (out, "Unknown disassembler mode"); - break; - } + switch (disassembler_mode) { + case HP_MNEMONICS: + sprintf(buf, "%sSRC", op_str_81[(n & 3) + 4 * disassembler_mode]); + p = append_str(out, buf); + break; + case CLASS_MNEMONICS: + p = append_str(out, "ror.w"); + p = append_tab(out); + p = append_str(p, "#4, "); + p = append_str(p, op_str_81[(n & 3) + 4 * disassembler_mode]); + break; + default: + p = append_str(out, "Unknown disassembler mode"); + break; + } break; case 8: - fn = read_nibble ((*addr)++); - n = read_nibble ((*addr)++); - switch (disassembler_mode) - { - case HP_MNEMONICS: - sprintf (buf, "%s=%s%cCON", - op_str_81[(n & 3) + 4 * disassembler_mode], - op_str_81[(n & 3) + 4 * disassembler_mode], - (n < 8) ? '+' : '-'); - p = append_str (out, buf); - p = append_tab (out); - p = append_field (p, fn); - fn = read_nibble ((*addr)++); - sprintf (buf, ", %d", fn + 1); - p = append_str (p, buf); - break; - case CLASS_MNEMONICS: - p = append_str (out, (n < 8) ? "add" : "sub"); - p = append_field (p, fn); - p = append_tab (out); - fn = read_nibble ((*addr)++); - sprintf (buf, "#%d, ", fn + 1); - p = append_str (p, buf); - p = append_str (p, op_str_81[(n & 3) + 4 * disassembler_mode]); - break; - default: - p = append_str (out, "Unknown disassembler mode"); - break; - } + fn = read_nibble((*addr)++); + n = read_nibble((*addr)++); + switch (disassembler_mode) { + case HP_MNEMONICS: + sprintf(buf, "%s=%s%cCON", op_str_81[(n & 3) + 4 * disassembler_mode], + op_str_81[(n & 3) + 4 * disassembler_mode], + (n < 8) ? '+' : '-'); + p = append_str(out, buf); + p = append_tab(out); + p = append_field(p, fn); + fn = read_nibble((*addr)++); + sprintf(buf, ", %d", fn + 1); + p = append_str(p, buf); + break; + case CLASS_MNEMONICS: + p = append_str(out, (n < 8) ? "add" : "sub"); + p = append_field(p, fn); + p = append_tab(out); + fn = read_nibble((*addr)++); + sprintf(buf, "#%d, ", fn + 1); + p = append_str(p, buf); + p = append_str(p, op_str_81[(n & 3) + 4 * disassembler_mode]); + break; + default: + p = append_str(out, "Unknown disassembler mode"); + break; + } break; case 9: - switch (disassembler_mode) - { - case HP_MNEMONICS: - sprintf (buf, "%sSRB.F", - op_str_81[(n & 3) + 4 * disassembler_mode]); - p = append_str (out, buf); - p = append_tab (out); - p = append_field (p, read_nibble ((*addr)++)); - break; - case CLASS_MNEMONICS: - p = append_str (out, "lsr"); - p = append_field (p, read_nibble ((*addr)++)); - p = append_tab (out); - p = append_str (p, "#1, "); - p = append_str (p, op_str_81[(n & 3) + 4 * disassembler_mode]); - break; - default: - p = append_str (out, "Unknown disassembler mode"); - break; - } + switch (disassembler_mode) { + case HP_MNEMONICS: + sprintf(buf, "%sSRB.F", op_str_81[(n & 3) + 4 * disassembler_mode]); + p = append_str(out, buf); + p = append_tab(out); + p = append_field(p, read_nibble((*addr)++)); + break; + case CLASS_MNEMONICS: + p = append_str(out, "lsr"); + p = append_field(p, read_nibble((*addr)++)); + p = append_tab(out); + p = append_str(p, "#1, "); + p = append_str(p, op_str_81[(n & 3) + 4 * disassembler_mode]); + break; + default: + p = append_str(out, "Unknown disassembler mode"); + break; + } break; case 0xa: - fn = read_nibble ((*addr)++); - n = read_nibble ((*addr)++); + fn = read_nibble((*addr)++); + n = read_nibble((*addr)++); if (n > 2) break; - c = (char) read_nibble ((*addr)++); - if (((int) c & 7) > 4) + c = (char)read_nibble((*addr)++); + if (((int)c & 7) > 4) break; - switch (disassembler_mode) - { - case HP_MNEMONICS: - if (n == 2) - { - sprintf (buf, "%cR%dEX.F", ((int) c < 8) ? 'A' : 'C', - (int) c & 7); + switch (disassembler_mode) { + case HP_MNEMONICS: + if (n == 2) { + sprintf(buf, "%cR%dEX.F", ((int)c < 8) ? 'A' : 'C', (int)c & 7); + } else if (n == 1) { + sprintf(buf, "%c=R%d.F", ((int)c < 8) ? 'A' : 'C', (int)c & 7); + } else { + sprintf(buf, "R%d=%c.F", (int)c & 7, ((int)c < 8) ? 'A' : 'C'); } - else if (n == 1) - { - sprintf (buf, "%c=R%d.F", ((int) c < 8) ? 'A' : 'C', - (int) c & 7); - } - else - { - sprintf (buf, "R%d=%c.F", (int) c & 7, - ((int) c < 8) ? 'A' : 'C'); - } - p = append_str (out, buf); - p = append_tab (out); - p = append_field (p, fn); - break; - case CLASS_MNEMONICS: - p = append_str (out, (n == 2) ? "exg" : "move"); - p = append_field (p, fn); - p = append_tab (out); - if (n == 1) - { - sprintf (buf, "r%d", (int) c & 7); - p = append_str (p, buf); - } - else - p = append_str (p, ((int) c < 8) ? "a" : "c"); - p = append_str (p, ", "); - if (n == 1) - p = append_str (p, ((int) c < 8) ? "a" : "c"); - else - { - sprintf (buf, "r%d", (int) c & 7); - p = append_str (p, buf); - } - break; - default: - p = append_str (out, "Unknown disassembler mode"); - break; + p = append_str(out, buf); + p = append_tab(out); + p = append_field(p, fn); + break; + case CLASS_MNEMONICS: + p = append_str(out, (n == 2) ? "exg" : "move"); + p = append_field(p, fn); + p = append_tab(out); + if (n == 1) { + sprintf(buf, "r%d", (int)c & 7); + p = append_str(p, buf); + } else + p = append_str(p, ((int)c < 8) ? "a" : "c"); + p = append_str(p, ", "); + if (n == 1) + p = append_str(p, ((int)c < 8) ? "a" : "c"); + else { + sprintf(buf, "r%d", (int)c & 7); + p = append_str(p, buf); } + break; + default: + p = append_str(out, "Unknown disassembler mode"); + break; + } break; case 0xb: - n = read_nibble ((*addr)++); + n = read_nibble((*addr)++); if ((n < 2) || (n > 7)) break; - p = append_str (out, in_str_81b[n + 16 * disassembler_mode]); + p = append_str(out, in_str_81b[n + 16 * disassembler_mode]); break; case 0xc: case 0xd: case 0xe: case 0xf: - switch (disassembler_mode) - { - case HP_MNEMONICS: - sprintf (buf, "%sSRB", op_str_81[(n & 3) + 4 * disassembler_mode]); - p = append_str (out, buf); - break; - case CLASS_MNEMONICS: - p = append_str (out, "lsr.w"); - p = append_tab (out); - p = append_str (p, "#1, "); - p = append_str (p, op_str_81[(n & 3) + 4 * disassembler_mode]); - break; - default: - p = append_str (out, "Unknown disassembler mode"); - break; - } + switch (disassembler_mode) { + case HP_MNEMONICS: + sprintf(buf, "%sSRB", op_str_81[(n & 3) + 4 * disassembler_mode]); + p = append_str(out, buf); + break; + case CLASS_MNEMONICS: + p = append_str(out, "lsr.w"); + p = append_tab(out); + p = append_str(p, "#1, "); + p = append_str(p, op_str_81[(n & 3) + 4 * disassembler_mode]); + break; + default: + p = append_str(out, "Unknown disassembler mode"); + break; + } break; default: break; } - break; + break; - case 2: - n = read_nibble ((*addr)++); - switch (disassembler_mode) - { + case 2: + n = read_nibble((*addr)++); + switch (disassembler_mode) { case HP_MNEMONICS: - if (n == 0xf) - { - p = append_str (out, "CLRHST"); - } - else - { - p = append_hst_bits (out, n); - p = append_str (p, "=0"); - } + if (n == 0xf) { + p = append_str(out, "CLRHST"); + } else { + p = append_hst_bits(out, n); + p = append_str(p, "=0"); + } break; case CLASS_MNEMONICS: - p = append_str (out, "clr.1"); - p = append_tab (out); - sprintf (buf, "#%d, hst", n); - p = append_str (p, buf); - p = append_hst_bits (out, n); + p = append_str(out, "clr.1"); + p = append_tab(out); + sprintf(buf, "#%d, hst", n); + p = append_str(p, buf); + p = append_hst_bits(out, n); break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - case 3: - n = read_nibble ((*addr)++); - pc = *addr; - disp = read_int (addr, 2); - switch (disassembler_mode) - { + case 3: + n = read_nibble((*addr)++); + pc = *addr; + disp = read_int(addr, 2); + switch (disassembler_mode) { case HP_MNEMONICS: - p = append_str (out, "?"); - p = append_hst_bits (p, n); - p = append_str (p, "=0"); - p = append_tab (out); - if (disp != 0) - { - p = append_str (p, "GOYES "); - p = append_r_addr (p, &pc, disp, 2, 3); - p = append_pc_comment (out, pc); - } - else - p = append_str (p, "RTNYES"); + p = append_str(out, "?"); + p = append_hst_bits(p, n); + p = append_str(p, "=0"); + p = append_tab(out); + if (disp != 0) { + p = append_str(p, "GOYES "); + p = append_r_addr(p, &pc, disp, 2, 3); + p = append_pc_comment(out, pc); + } else + p = append_str(p, "RTNYES"); break; case CLASS_MNEMONICS: - p = append_str (out, (disp == 0) ? "rt" : "b"); - p = append_str (p, "eq.1"); - p = append_tab (out); - sprintf (buf, "#%d, hst", n); - p = append_str (p, buf); - if (disp != 0) - { - p = append_str (p, ", "); - p = append_r_addr (p, &pc, disp, 2, 3); - p = append_pc_comment (out, pc); - } - p = append_hst_bits (out, n); + p = append_str(out, (disp == 0) ? "rt" : "b"); + p = append_str(p, "eq.1"); + p = append_tab(out); + sprintf(buf, "#%d, hst", n); + p = append_str(p, buf); + if (disp != 0) { + p = append_str(p, ", "); + p = append_r_addr(p, &pc, disp, 2, 3); + p = append_pc_comment(out, pc); + } + p = append_hst_bits(out, n); break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - case 4: - case 5: - switch (disassembler_mode) - { + case 4: + case 5: + switch (disassembler_mode) { case HP_MNEMONICS: - sprintf (buf, "ST=%d", (fn == 4) ? 0 : 1); - p = append_str (out, buf); - p = append_tab (out); - p = append_imm_nibble (p, addr, 1); + sprintf(buf, "ST=%d", (fn == 4) ? 0 : 1); + p = append_str(out, buf); + p = append_tab(out); + p = append_imm_nibble(p, addr, 1); break; case CLASS_MNEMONICS: - p = append_str (out, (fn == 4) ? "bclr" : "bset"); - p = append_tab (out); - p = append_imm_nibble (p, addr, 1); - p = append_str (p, ", st"); + p = append_str(out, (fn == 4) ? "bclr" : "bset"); + p = append_tab(out); + p = append_imm_nibble(p, addr, 1); + p = append_str(p, ", st"); break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - case 6: - case 7: - n = read_nibble ((*addr)++); - pc = *addr; - disp = read_int (addr, 2); - switch (disassembler_mode) - { + case 6: + case 7: + n = read_nibble((*addr)++); + pc = *addr; + disp = read_int(addr, 2); + switch (disassembler_mode) { case HP_MNEMONICS: - sprintf (buf, "?ST=%d", (fn == 6) ? 0 : 1); - p = append_str (out, buf); - p = append_tab (out); - sprintf (buf, "%d", n); - p = append_str (p, buf); - if (disp != 0) - { - p = append_str (p, ", GOYES "); - p = append_r_addr (p, &pc, disp, 2, 3); - p = append_pc_comment (out, pc); - } - else - p = append_str (p, ", RTNYES"); + sprintf(buf, "?ST=%d", (fn == 6) ? 0 : 1); + p = append_str(out, buf); + p = append_tab(out); + sprintf(buf, "%d", n); + p = append_str(p, buf); + if (disp != 0) { + p = append_str(p, ", GOYES "); + p = append_r_addr(p, &pc, disp, 2, 3); + p = append_pc_comment(out, pc); + } else + p = append_str(p, ", RTNYES"); break; case CLASS_MNEMONICS: - p = append_str (out, (disp == 0) ? "rt" : "b"); - p = append_str (p, (fn == 6) ? "bc" : "bs"); - p = append_tab (out); - sprintf (buf, "#%d, st", n); - p = append_str (p, buf); - if (disp != 0) - { - p = append_str (p, ", "); - p = append_r_addr (p, &pc, disp, 2, 3); - p = append_pc_comment (out, pc); - } + p = append_str(out, (disp == 0) ? "rt" : "b"); + p = append_str(p, (fn == 6) ? "bc" : "bs"); + p = append_tab(out); + sprintf(buf, "#%d, st", n); + p = append_str(p, buf); + if (disp != 0) { + p = append_str(p, ", "); + p = append_r_addr(p, &pc, disp, 2, 3); + p = append_pc_comment(out, pc); + } break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - case 8: - case 9: - n = read_nibble ((*addr)++); - pc = *addr; - disp = read_int (addr, 2); - switch (disassembler_mode) - { + case 8: + case 9: + n = read_nibble((*addr)++); + pc = *addr; + disp = read_int(addr, 2); + switch (disassembler_mode) { case HP_MNEMONICS: - sprintf (buf, "?P%c", (fn == 8) ? '#' : '='); - p = append_str (out, buf); - p = append_tab (out); - sprintf (buf, "%d", n); - p = append_str (p, buf); - if (disp != 0) - { - p = append_str (p, ", GOYES "); - p = append_r_addr (p, &pc, disp, 2, 3); - p = append_pc_comment (out, pc); - } - else - p = append_str (p, ", RTNYES"); + sprintf(buf, "?P%c", (fn == 8) ? '#' : '='); + p = append_str(out, buf); + p = append_tab(out); + sprintf(buf, "%d", n); + p = append_str(p, buf); + if (disp != 0) { + p = append_str(p, ", GOYES "); + p = append_r_addr(p, &pc, disp, 2, 3); + p = append_pc_comment(out, pc); + } else + p = append_str(p, ", RTNYES"); break; case CLASS_MNEMONICS: - p = append_str (out, (disp == 0) ? "rt" : "b"); - p = append_str (p, (fn == 8) ? "ne.1" : "eq.1"); - p = append_tab (out); - sprintf (buf, "#%d, p", n); - p = append_str (p, buf); - if (disp != 0) - { - p = append_str (p, ", "); - p = append_r_addr (p, &pc, disp, 2, 3); - p = append_pc_comment (out, pc); - } + p = append_str(out, (disp == 0) ? "rt" : "b"); + p = append_str(p, (fn == 8) ? "ne.1" : "eq.1"); + p = append_tab(out); + sprintf(buf, "#%d, p", n); + p = append_str(p, buf); + if (disp != 0) { + p = append_str(p, ", "); + p = append_r_addr(p, &pc, disp, 2, 3); + p = append_pc_comment(out, pc); + } break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - case 0xc: - case 0xe: - pc = *addr; - if (fn == 0xe) - pc += 4; - disp = read_int (addr, 4); - switch (disassembler_mode) - { + case 0xc: + case 0xe: + pc = *addr; + if (fn == 0xe) + pc += 4; + disp = read_int(addr, 4); + switch (disassembler_mode) { case HP_MNEMONICS: - p = append_str (out, (fn == 0xc) ? "GOLONG" : "GOSUBL"); - p = append_tab (out); - p = append_r_addr (p, &pc, disp, 4, (fn == 0xc) ? 2 : 6); - p = append_pc_comment (out, pc); + p = append_str(out, (fn == 0xc) ? "GOLONG" : "GOSUBL"); + p = append_tab(out); + p = append_r_addr(p, &pc, disp, 4, (fn == 0xc) ? 2 : 6); + p = append_pc_comment(out, pc); break; case CLASS_MNEMONICS: - p = append_str (out, (fn == 0xc) ? "bra.4" : "bsr.4"); - p = append_tab (out); - p = append_r_addr (p, &pc, disp, 4, (fn == 0xc) ? 2 : 6); - p = append_pc_comment (out, pc); + p = append_str(out, (fn == 0xc) ? "bra.4" : "bsr.4"); + p = append_tab(out); + p = append_r_addr(p, &pc, disp, 4, (fn == 0xc) ? 2 : 6); + p = append_pc_comment(out, pc); break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - case 0xd: - case 0xf: - pc = read_int (addr, 5); - switch (disassembler_mode) - { + case 0xd: + case 0xf: + pc = read_int(addr, 5); + switch (disassembler_mode) { case HP_MNEMONICS: - p = append_str (out, (fn == 0xc) ? "GOVLNG" : "GOSBVL"); - p = append_tab (out); - p = append_addr (p, pc); + p = append_str(out, (fn == 0xc) ? "GOVLNG" : "GOSBVL"); + p = append_tab(out); + p = append_addr(p, pc); break; case CLASS_MNEMONICS: - p = append_str (out, (fn == 0xc) ? "jmp" : "jsr"); - p = append_tab (out); - p = append_addr (p, pc); + p = append_str(out, (fn == 0xc) ? "jmp" : "jsr"); + p = append_tab(out); + p = append_addr(p, pc); break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - default: - break; - - } + default: + break; + } return p; } - -word_20 disassemble (word_20 addr, char *out) { +word_20 disassemble(word_20 addr, char *out) { word_4 n; word_4 fn; char *p = out; @@ -1330,299 +1234,271 @@ word_20 disassemble (word_20 addr, char *out) { char buf[20]; word_20 disp, pc; - switch (n = read_nibble (addr++)) - { - case 0: - if ((n = read_nibble (addr++)) != 0xe) - { - p = append_str (out, opcode_0_tbl[n + 16 * disassembler_mode]); + switch (n = read_nibble(addr++)) { + case 0: + if ((n = read_nibble(addr++)) != 0xe) { + p = append_str(out, opcode_0_tbl[n + 16 * disassembler_mode]); break; } - fn = read_nibble (addr++); - n = read_nibble (addr++); - switch (disassembler_mode) - { + fn = read_nibble(addr++); + n = read_nibble(addr++); + switch (disassembler_mode) { case HP_MNEMONICS: - sprintf (buf, op_str_0[(n & 7) + 8 * HP_MNEMONICS], - (n < 8) ? '&' : '!'); - p = append_str (out, buf); - p = append_tab (out); - p = append_field (p, fn); + sprintf(buf, op_str_0[(n & 7) + 8 * HP_MNEMONICS], (n < 8) ? '&' : '!'); + p = append_str(out, buf); + p = append_tab(out); + p = append_field(p, fn); break; case CLASS_MNEMONICS: - p = append_str (out, (n < 8) ? "and" : "or"); - p = append_field (p, fn); - p = append_tab (out); - p = append_str (p, op_str_0[(n & 7) + 8 * CLASS_MNEMONICS]); + p = append_str(out, (n < 8) ? "and" : "or"); + p = append_field(p, fn); + p = append_tab(out); + p = append_str(p, op_str_0[(n & 7) + 8 * CLASS_MNEMONICS]); break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - case 1: - p = disasm_1 (&addr, out); - break; + case 1: + p = disasm_1(&addr, out); + break; - case 2: - n = read_nibble (addr++); - switch (disassembler_mode) - { + case 2: + n = read_nibble(addr++); + switch (disassembler_mode) { case HP_MNEMONICS: - sprintf (buf, "P=%d", n); - p = append_str (out, buf); + sprintf(buf, "P=%d", n); + p = append_str(out, buf); break; case CLASS_MNEMONICS: - sprintf (buf, "move.1 #%d, p", n); - p = append_str (out, buf); + sprintf(buf, "move.1 #%d, p", n); + p = append_str(out, buf); break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - case 3: - fn = read_nibble (addr++); - switch (disassembler_mode) - { + case 3: + fn = read_nibble(addr++); + switch (disassembler_mode) { case HP_MNEMONICS: - if (fn < 5) - { - sprintf (buf, "LC(%d)", fn + 1); - } - else - { - sprintf (buf, "LCHEX"); - } - p = append_str (out, buf); - p = append_tab (out); - p = append_imm_nibble (p, &addr, fn + 1); + if (fn < 5) { + sprintf(buf, "LC(%d)", fn + 1); + } else { + sprintf(buf, "LCHEX"); + } + p = append_str(out, buf); + p = append_tab(out); + p = append_imm_nibble(p, &addr, fn + 1); break; case CLASS_MNEMONICS: - sprintf (buf, "move.%d", fn + 1); - p = append_str (out, buf); - p = append_tab (out); - p = append_imm_nibble (p, &addr, fn + 1); - sprintf (buf, ", c.p"); - p = append_str (p, buf); + sprintf(buf, "move.%d", fn + 1); + p = append_str(out, buf); + p = append_tab(out); + p = append_imm_nibble(p, &addr, fn + 1); + sprintf(buf, ", c.p"); + p = append_str(p, buf); break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - case 4: - case 5: - pc = addr; - disp = read_int (&addr, 2); - switch (disassembler_mode) - { + case 4: + case 5: + pc = addr; + disp = read_int(&addr, 2); + switch (disassembler_mode) { case HP_MNEMONICS: - if (disp == 2) - { - p = append_str (out, "NOP3"); - break; - } - sprintf (buf, (disp == 0) ? "RTN%sC" : "GO%sC", (n == 4) ? "" : "N"); - p = append_str (out, buf); - if (disp != 0) - { - p = append_tab (out); - p = append_r_addr (p, &pc, disp, 2, 1); - p = append_pc_comment (out, pc); - } + if (disp == 2) { + p = append_str(out, "NOP3"); + break; + } + sprintf(buf, (disp == 0) ? "RTN%sC" : "GO%sC", (n == 4) ? "" : "N"); + p = append_str(out, buf); + if (disp != 0) { + p = append_tab(out); + p = append_r_addr(p, &pc, disp, 2, 1); + p = append_pc_comment(out, pc); + } break; case CLASS_MNEMONICS: - if (disp == 2) - { - p = append_str (out, "nop3"); - break; - } - p = append_str (out, (disp == 0) ? "rtc" : "bc"); - p = append_str (p, (n == 4) ? "s" : "c"); - if (disp != 0) - { - p = append_tab (out); - p = append_r_addr (p, &pc, disp, 2, 1); - p = append_pc_comment (out, pc); - } + if (disp == 2) { + p = append_str(out, "nop3"); + break; + } + p = append_str(out, (disp == 0) ? "rtc" : "bc"); + p = append_str(p, (n == 4) ? "s" : "c"); + if (disp != 0) { + p = append_tab(out); + p = append_r_addr(p, &pc, disp, 2, 1); + p = append_pc_comment(out, pc); + } break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - case 6: - pc = addr; - disp = read_int (&addr, 3); - switch (disassembler_mode) - { + case 6: + pc = addr; + disp = read_int(&addr, 3); + switch (disassembler_mode) { case HP_MNEMONICS: - if (disp == 3) - { - p = append_str (out, "NOP4"); - break; - } - if (disp == 4) - { - p = append_str (out, "NOP5"); - break; - } - p = append_str (out, "GOTO"); - p = append_tab (out); - p = append_r_addr (p, &pc, disp, 3, 1); - p = append_pc_comment (out, pc); + if (disp == 3) { + p = append_str(out, "NOP4"); + break; + } + if (disp == 4) { + p = append_str(out, "NOP5"); + break; + } + p = append_str(out, "GOTO"); + p = append_tab(out); + p = append_r_addr(p, &pc, disp, 3, 1); + p = append_pc_comment(out, pc); break; case CLASS_MNEMONICS: - if (disp == 3) - { - p = append_str (out, "nop4"); - break; - } - if (disp == 4) - { - p = append_str (out, "nop5"); - break; - } - p = append_str (out, "bra.3"); - p = append_tab (out); - p = append_r_addr (p, &pc, disp, 3, 1); - p = append_pc_comment (out, pc); + if (disp == 3) { + p = append_str(out, "nop4"); + break; + } + if (disp == 4) { + p = append_str(out, "nop5"); + break; + } + p = append_str(out, "bra.3"); + p = append_tab(out); + p = append_r_addr(p, &pc, disp, 3, 1); + p = append_pc_comment(out, pc); break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - case 7: - pc = addr + 3; - disp = read_int (&addr, 3); - switch (disassembler_mode) - { + case 7: + pc = addr + 3; + disp = read_int(&addr, 3); + switch (disassembler_mode) { case HP_MNEMONICS: - p = append_str (out, "GOSUB"); - p = append_tab (out); - p = append_r_addr (p, &pc, disp, 3, 4); - p = append_pc_comment (out, pc); + p = append_str(out, "GOSUB"); + p = append_tab(out); + p = append_r_addr(p, &pc, disp, 3, 4); + p = append_pc_comment(out, pc); break; case CLASS_MNEMONICS: - p = append_str (out, "bsr.3"); - p = append_tab (out); - p = append_r_addr (p, &pc, disp, 3, 4); - p = append_pc_comment (out, pc); + p = append_str(out, "bsr.3"); + p = append_tab(out); + p = append_r_addr(p, &pc, disp, 3, 4); + p = append_pc_comment(out, pc); break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - case 8: - fn = read_nibble (addr); /* PEEK */ - if (fn != 0xa && fn != 0xb) - { - p = disasm_8 (&addr, out); + case 8: + fn = read_nibble(addr); /* PEEK */ + if (fn != 0xa && fn != 0xb) { + p = disasm_8(&addr, out); break; } - /* Fall through */ + /* Fall through */ - case 9: - fn = read_nibble (addr++); - if (n == 8) - { - c = (char) ((fn == 0xa) ? 0 : 1); + case 9: + fn = read_nibble(addr++); + if (n == 8) { + c = (char)((fn == 0xa) ? 0 : 1); fn = 0xf; - } - else - { - c = (char) ((fn < 8) ? 0 : 1); + } else { + c = (char)((fn < 8) ? 0 : 1); fn &= 7; } - n = read_nibble (addr++); - pc = addr; - disp = read_int (&addr, 2); + n = read_nibble(addr++); + pc = addr; + disp = read_int(&addr, 2); - switch (disassembler_mode) - { + switch (disassembler_mode) { case HP_MNEMONICS: if ((c == 0) && (n >= 8)) - sprintf (buf, op_str_9[(n & 3) + 8 * HP_MNEMONICS + 4], - in_str_9[((n >> 2) & 3) + 4 * c + 8 * HP_MNEMONICS]); + sprintf(buf, op_str_9[(n & 3) + 8 * HP_MNEMONICS + 4], + in_str_9[((n >> 2) & 3) + 4 * c + 8 * HP_MNEMONICS]); else - sprintf (buf, op_str_9[(n & 3) + 8 * HP_MNEMONICS], - in_str_9[((n >> 2) & 3) + 4 * c + 8 * HP_MNEMONICS]); - p = append_str (out, buf); - p = append_tab (out); - p = append_field (p, fn); - p = append_str (p, ", "); - p = append_str (p, (disp == 0) ? "RTNYES" : "GOYES "); - if (disp != 0) - { - p = append_r_addr (p, &pc, disp, 2, 3); - p = append_pc_comment (out, pc); - } + sprintf(buf, op_str_9[(n & 3) + 8 * HP_MNEMONICS], + in_str_9[((n >> 2) & 3) + 4 * c + 8 * HP_MNEMONICS]); + p = append_str(out, buf); + p = append_tab(out); + p = append_field(p, fn); + p = append_str(p, ", "); + p = append_str(p, (disp == 0) ? "RTNYES" : "GOYES "); + if (disp != 0) { + p = append_r_addr(p, &pc, disp, 2, 3); + p = append_pc_comment(out, pc); + } break; case CLASS_MNEMONICS: - p = append_str (out, (disp == 0) ? "rt" : "b"); - p = append_str (p, in_str_9[((n >> 2) & 3) + 4 * c + 8 * CLASS_MNEMONICS]); - p = append_field (p, fn); - p = append_tab (out); + p = append_str(out, (disp == 0) ? "rt" : "b"); + p = append_str(p, in_str_9[((n >> 2) & 3) + 4 * c + 8 * CLASS_MNEMONICS]); + p = append_field(p, fn); + p = append_tab(out); if ((c == 0) && (n >= 8)) - p = append_str (p, op_str_9[(n & 3) + 8 * CLASS_MNEMONICS + 4]); + p = append_str(p, op_str_9[(n & 3) + 8 * CLASS_MNEMONICS + 4]); else - p = append_str (p, op_str_9[(n & 3) + 8 * CLASS_MNEMONICS]); - if (disp != 0) - { - p = append_str (p, ", "); - p = append_r_addr (p, &pc, disp, 2, 3); - p = append_pc_comment (out, pc); - } + p = append_str(p, op_str_9[(n & 3) + 8 * CLASS_MNEMONICS]); + if (disp != 0) { + p = append_str(p, ", "); + p = append_r_addr(p, &pc, disp, 2, 3); + p = append_pc_comment(out, pc); + } break; default: - p = append_str (out, "Unknown disassembler mode"); + p = append_str(out, "Unknown disassembler mode"); break; } - break; + break; - default: - switch (n) - { + default: + switch (n) { case 0xa: - fn = read_nibble (addr++); - c = (char) ((fn < 8) ? 0 : 1); + fn = read_nibble(addr++); + c = (char)((fn < 8) ? 0 : 1); fn &= 7; disp = 0xa; break; case 0xb: - fn = read_nibble (addr++); - c = (char) ((fn < 8) ? 0 : 1); + fn = read_nibble(addr++); + c = (char)((fn < 8) ? 0 : 1); fn &= 7; disp = 0xb; break; case 0xc: case 0xd: fn = 0xf; - c = (char) (n & 1); + c = (char)(n & 1); disp = 0xa; break; case 0xe: case 0xf: fn = 0xf; - c = (char) (n & 1); + c = (char)(n & 1); disp = 0xb; break; default: @@ -1632,228 +1508,161 @@ word_20 disassemble (word_20 addr, char *out) { break; } - n = read_nibble (addr++); - pc = 0; + n = read_nibble(addr++); + pc = 0; - switch (disp) - { + switch (disp) { case 0xa: - switch (disassembler_mode) - { - case HP_MNEMONICS: - if (c == 0) - { - if (n < 0xc) - { - p = "+"; - } - else - { - p = "%c=%c-1"; - pc = 2; - } + switch (disassembler_mode) { + case HP_MNEMONICS: + if (c == 0) { + if (n < 0xc) { + p = "+"; + } else { + p = "%c=%c-1"; + pc = 2; + } + } else { + if (n < 4) { + p = "%c=0"; + pc = 1; + } else if (n >= 0xc) { + p = "%c%cEX"; + pc = 3; + } else { + p = "%c=%c"; + pc = 3; + } } - else - { - if (n < 4) - { - p = "%c=0"; - pc = 1; - } - else if (n >= 0xc) - { - p = "%c%cEX"; - pc = 3; - } - else - { - p = "%c=%c"; - pc = 3; - } - } - break; + break; - case CLASS_MNEMONICS: - if (c == 0) - { - if (n < 0xc) - { - p = "add"; - } - else - { - p = "dec"; - pc = 1; - } + case CLASS_MNEMONICS: + if (c == 0) { + if (n < 0xc) { + p = "add"; + } else { + p = "dec"; + pc = 1; + } + } else { + if (n < 4) { + p = "clr"; + pc = 1; + } else if (n >= 0xc) { + p = "exg"; + } else { + p = "move"; + if (n < 8) + n -= 4; + } } - else - { - if (n < 4) - { - p = "clr"; - pc = 1; - } - else if (n >= 0xc) - { - p = "exg"; - } - else - { - p = "move"; - if (n < 8) - n -= 4; - } - } - break; + break; - default: - p = append_str (out, "Unknown disassembler mode"); - return addr; - } + default: + p = append_str(out, "Unknown disassembler mode"); + return addr; + } break; case 0xb: - switch (disassembler_mode) - { - case HP_MNEMONICS: - if (c == 0) - { - if (n >= 0xc) - { - p = "-"; - } - else if ((n >= 4) && (n <= 7)) - { - p = "%c=%c+1"; - pc = 2; - n -= 4; - } - else - { - p = "-"; - } + switch (disassembler_mode) { + case HP_MNEMONICS: + if (c == 0) { + if (n >= 0xc) { + p = "-"; + } else if ((n >= 4) && (n <= 7)) { + p = "%c=%c+1"; + pc = 2; + n -= 4; + } else { + p = "-"; + } + } else { + if (n < 4) { + p = "%cSL"; + pc = 1; + } else if (n < 8) { + p = "%cSR"; + pc = 1; + } else if (n < 0xc) { + p = "%c=%c-1"; + pc = 2; + } else { + p = "%c=-%c-1"; + pc = 2; + } } - else - { - if (n < 4) - { - p = "%cSL"; - pc = 1; - } - else if (n < 8) - { - p = "%cSR"; - pc = 1; - } - else if (n < 0xc) - { - p = "%c=%c-1"; - pc = 2; - } - else - { - p = "%c=-%c-1"; - pc = 2; - } - } - break; + break; - case CLASS_MNEMONICS: - if (c == 0) - { - if (n >= 0xc) - { - p = "subr"; - } - else if ((n >= 4) && (n <= 7)) - { - p = "inc"; - pc = 1; - n -= 4; - } - else - { - p = "sub"; - } - } - else - { + case CLASS_MNEMONICS: + if (c == 0) { + if (n >= 0xc) { + p = "subr"; + } else if ((n >= 4) && (n <= 7)) { + p = "inc"; + pc = 1; + n -= 4; + } else { + p = "sub"; + } + } else { pc = 1; - if (n < 4) - { - p = "lsl"; - } - else if (n < 8) - { - p = "lsr"; - } - else if (n < 0xc) - { - p = "neg"; - } - else - { - p = "not"; - } + if (n < 4) { + p = "lsl"; + } else if (n < 8) { + p = "lsr"; + } else if (n < 0xc) { + p = "neg"; + } else { + p = "not"; + } } - break; + break; - default: - p = append_str (out, "Unknown disassembler mode"); - return addr; - } + default: + p = append_str(out, "Unknown disassembler mode"); + return addr; + } break; - } - switch (disassembler_mode) - { + switch (disassembler_mode) { case HP_MNEMONICS: - if (pc == 0) - { - sprintf (buf, op_str_af[n + 16 * HP_MNEMONICS], p); - } - else if (pc == 1) - { - sprintf (buf, p, (n & 3) + 'A'); - } - else if (pc == 2) - { - sprintf (buf, p, (n & 3) + 'A', (n & 3) + 'A'); - } - else - { - sprintf (buf, p, hp_reg_1_af[n], hp_reg_2_af[n]); - } - p = append_str (out, buf); - p = append_tab (out); - p = append_field (p, fn); + if (pc == 0) { + sprintf(buf, op_str_af[n + 16 * HP_MNEMONICS], p); + } else if (pc == 1) { + sprintf(buf, p, (n & 3) + 'A'); + } else if (pc == 2) { + sprintf(buf, p, (n & 3) + 'A', (n & 3) + 'A'); + } else { + sprintf(buf, p, hp_reg_1_af[n], hp_reg_2_af[n]); + } + p = append_str(out, buf); + p = append_tab(out); + p = append_field(p, fn); break; case CLASS_MNEMONICS: - p = append_str (out, p); - p = append_field (p, fn); - p = append_tab (out); - if (pc == 1) - { - sprintf (buf, "%c", (n & 3) + 'a'); - p = append_str (p, buf); - } - else - { - p = append_str (p, op_str_af[n + 16 * CLASS_MNEMONICS]); - } + p = append_str(out, p); + p = append_field(p, fn); + p = append_tab(out); + if (pc == 1) { + sprintf(buf, "%c", (n & 3) + 'a'); + p = append_str(p, buf); + } else { + p = append_str(p, op_str_af[n + 16 * CLASS_MNEMONICS]); + } break; default: - p = append_str (p, "Unknown disassembler mode"); + p = append_str(p, "Unknown disassembler mode"); break; } - break; - } + break; + } *p = '\0'; return addr; } diff --git a/src/dump2rom.c b/src/dump2rom.c index 19bb0b5..8e87799 100644 --- a/src/dump2rom.c +++ b/src/dump2rom.c @@ -45,13 +45,12 @@ * $Id: dump2rom.c,v 1.7 1995/01/11 18:20:01 ecd Exp ecd $ */ - #include "global.h" #include #include -#include #include +#include #ifdef SUNOS #include #endif @@ -67,44 +66,36 @@ int write_mem_file(char *name, unsigned char *mem, int size) { unsigned char byte; int i, j; - if (NULL == (fp = fopen(name, "w"))) - { - fprintf(stderr, "can\'t open %s\n", name); + if (NULL == (fp = fopen(name, "w"))) { + fprintf(stderr, "can\'t open %s\n", name); + return 0; + } + + if (NULL == (tmp_mem = (unsigned char *)malloc((size_t)size / 2))) { + for (i = 0, j = 0; i < size / 2; i++) { + byte = (mem[j++] & 0x0f); + byte |= (mem[j++] << 4) & 0xf0; + if (1 != fwrite(&byte, 1, 1, fp)) { + fprintf(stderr, "can\'t write %s\n", name); + fclose(fp); + return 0; + } + } + } else { + for (i = 0, j = 0; i < size / 2; i++) { + tmp_mem[i] = (mem[j++] & 0x0f); + tmp_mem[i] |= (mem[j++] << 4) & 0xf0; + } + + if (fwrite(tmp_mem, 1, (size_t)size / 2, fp) != size / 2) { + fprintf(stderr, "can\'t write %s\n", name); + fclose(fp); + free(tmp_mem); return 0; } - if (NULL == (tmp_mem = (unsigned char *)malloc((size_t)size / 2))) - { - for (i = 0, j = 0; i < size / 2; i++) - { - byte = (mem[j++] & 0x0f); - byte |= (mem[j++] << 4) & 0xf0; - if (1 != fwrite(&byte, 1, 1, fp)) - { - fprintf(stderr, "can\'t write %s\n", name); - fclose(fp); - return 0; - } - } - } - else - { - for (i = 0, j = 0; i < size / 2; i++) - { - tmp_mem[i] = (mem[j++] & 0x0f); - tmp_mem[i] |= (mem[j++] << 4) & 0xf0; - } - - if (fwrite(tmp_mem, 1, (size_t)size / 2, fp) != size / 2) - { - fprintf(stderr, "can\'t write %s\n", name); - fclose(fp); - free(tmp_mem); - return 0; - } - - free(tmp_mem); - } + free(tmp_mem); + } fclose(fp); return 1; @@ -117,17 +108,17 @@ int main(int argc, char **argv) { if (argc < 2) { fprintf(stderr, "usage: %s hp48-dump-file\n", argv[0]); - exit (1); + exit(1); } if ((dump = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "%s: can\'t open %s\n", argv[0], argv[1]); - exit (1); + exit(1); } if ((core = (unsigned char *)malloc(0x100000)) == NULL) { fprintf(stderr, "%s: can\'t malloc %d bytes\n", argv[0], 0x100000); - exit (1); + exit(1); } memset(core, 0, 0x100000); @@ -160,8 +151,8 @@ int main(int argc, char **argv) { break; } if (ch != ':') { - fprintf(stderr, "%s: Illegal char %c, expected \':\' at %lx\n", - argv[0], ch, addr); + fprintf(stderr, "%s: Illegal char %c, expected \':\' at %lx\n", argv[0], + ch, addr); break; } for (i = 0; i < 16; i++) { @@ -185,8 +176,8 @@ int main(int argc, char **argv) { if ((ch = fgetc(dump)) < 0) break; if (ch != '\n') { - fprintf(stderr, "%s: Illegal char %c, expected \'\\n\' at %lx\n", - argv[0], ch, addr); + fprintf(stderr, "%s: Illegal char %c, expected \'\\n\' at %lx\n", argv[0], + ch, addr); break; } } @@ -198,11 +189,10 @@ int main(int argc, char **argv) { size = 0x100000; else size = 0x80000; - if (!write_mem_file(DEFAULT_ROM_FILE, core, size)) - { - fprintf(stderr, "%s: can\'t write to %s\n", argv[0], DEFAULT_ROM_FILE); - exit (1); - } + if (!write_mem_file(DEFAULT_ROM_FILE, core, size)) { + fprintf(stderr, "%s: can\'t write to %s\n", argv[0], DEFAULT_ROM_FILE); + exit(1); + } - exit (0); + exit(0); } diff --git a/src/emulate.c b/src/emulate.c index defe5cd..d05ff15 100644 --- a/src/emulate.c +++ b/src/emulate.c @@ -43,17 +43,16 @@ * $Id: emulate.c,v 1.16 1995/01/11 18:20:01 ecd Exp ecd $ */ - #include "global.h" #include +#include "debugger.h" +#include "device.h" #include "hp48.h" #include "hp48_emu.h" -#include "device.h" #include "timer.h" #include "x48_x11.h" -#include "debugger.h" extern int throttle; @@ -63,56 +62,54 @@ extern int throttle; #define DEBUG_DISP_SCHED #endif -static long jumpaddr; +static long jumpaddr; -unsigned long instructions = 0; -unsigned long old_instr = 0; +unsigned long instructions = 0; +unsigned long old_instr = 0; -int rece_instr = 0; -int device_check = 0; +int rece_instr = 0; +int device_check = 0; -int adj_time_pending = 0; +int adj_time_pending = 0; -int set_t1; +int set_t1; -long schedule_event = 0; +long schedule_event = 0; -#define SrvcIoStart 0x3c0 -#define SrvcIoEnd 0x5ec +#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 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 NR_SAMPLES 10 +#define NR_SAMPLES 10 -long sched_instr_rollover = SCHED_INSTR_ROLLOVER; -long sched_receive = SCHED_RECEIVE; -long sched_adjtime = SCHED_ADJTIME; -long sched_timer1 = SCHED_TIMER1; -long sched_timer2 = SCHED_TIMER2; -long sched_statistics = SCHED_STATISTICS; -long sched_display = SCHED_NEVER; +long sched_instr_rollover = SCHED_INSTR_ROLLOVER; +long sched_receive = SCHED_RECEIVE; +long sched_adjtime = SCHED_ADJTIME; +long sched_timer1 = SCHED_TIMER1; +long sched_timer2 = SCHED_TIMER2; +long sched_statistics = SCHED_STATISTICS; +long sched_display = SCHED_NEVER; -unsigned long t1_i_per_tick; -unsigned long t2_i_per_tick; -unsigned long s_1; -unsigned long s_16; -unsigned long old_s_1; -unsigned long old_s_16; -unsigned long delta_t_1; -unsigned long delta_t_16; -unsigned long delta_i; -word_64 run; +unsigned long t1_i_per_tick; +unsigned long t2_i_per_tick; +unsigned long s_1; +unsigned long s_16; +unsigned long old_s_1; +unsigned long old_s_16; +unsigned long delta_t_1; +unsigned long delta_t_16; +unsigned long delta_i; +word_64 run; -static word_20 jumpmasks[] = { - 0xffffffff, 0xfffffff0, 0xffffff00, 0xfffff000, - 0xffff0000, 0xfff00000, 0xff000000, 0xf0000000 -}; +static word_20 jumpmasks[] = {0xffffffff, 0xfffffff0, 0xffffff00, 0xfffff000, + 0xffff0000, 0xfff00000, 0xff000000, 0xf0000000}; int decode_group_80(void) { int t, op3, op4, op5, op6; @@ -120,169 +117,169 @@ int decode_group_80(void) { long addr; op3 = read_nibble(saturn.PC + 2); switch (op3) { - case 0: /* OUT=CS */ - saturn.PC += 3; - copy_register(saturn.OUT, saturn.C, OUTS_FIELD); + case 0: /* OUT=CS */ + saturn.PC += 3; + copy_register(saturn.OUT, saturn.C, OUTS_FIELD); #if 0 check_out_register(); #endif - return 0; - case 1: /* OUT=C */ - saturn.PC += 3; - copy_register(saturn.OUT, saturn.C, OUT_FIELD); + return 0; + case 1: /* OUT=C */ + saturn.PC += 3; + copy_register(saturn.OUT, saturn.C, OUT_FIELD); #if 0 check_out_register(); #endif + return 0; + case 2: /* A=IN */ + saturn.PC += 3; + do_in(); + copy_register(saturn.A, saturn.IN, IN_FIELD); + return 0; + case 3: /* C=IN */ + saturn.PC += 3; + do_in(); + copy_register(saturn.C, saturn.IN, IN_FIELD); + return 0; + case 4: /* UNCNFG */ + saturn.PC += 3; + do_unconfigure(); + return 0; + case 5: /* CONFIG */ + saturn.PC += 3; + do_configure(); + return 0; + case 6: /* C=ID */ + saturn.PC += 3; + return get_identification(); + case 7: /* SHUTDN */ + saturn.PC += 3; + do_shutdown(); + return 0; + case 8: + op4 = read_nibble(saturn.PC + 3); + switch (op4) { + case 0: /* INTON */ + saturn.PC += 4; + do_inton(); return 0; - case 2: /* A=IN */ - saturn.PC += 3; - do_in(); - copy_register(saturn.A, saturn.IN, IN_FIELD); + case 1: /* RSI... */ + op5 = read_nibble(saturn.PC + 4); + saturn.PC += 5; + do_reset_interrupt_system(); return 0; - case 3: /* C=IN */ - saturn.PC += 3; - do_in(); - copy_register(saturn.C, saturn.IN, IN_FIELD); + case 2: /* LA... */ + op5 = read_nibble(saturn.PC + 4); + load_constant(saturn.A, op5 + 1, saturn.PC + 5); + saturn.PC += 6 + op5; return 0; - case 4: /* UNCNFG */ - saturn.PC += 3; - do_unconfigure(); + case 3: /* BUSCB */ + saturn.PC += 4; return 0; - case 5: /* CONFIG */ - saturn.PC += 3; - do_configure(); + case 4: /* ABIT=0 */ + op5 = read_nibble(saturn.PC + 4); + saturn.PC += 5; + clear_register_bit(saturn.A, op5); return 0; - case 6: /* C=ID */ - saturn.PC += 3; - return get_identification(); - case 7: /* SHUTDN */ - saturn.PC += 3; - do_shutdown(); + case 5: /* ABIT=1 */ + op5 = read_nibble(saturn.PC + 4); + saturn.PC += 5; + set_register_bit(saturn.A, op5); return 0; - case 8: - op4 = read_nibble(saturn.PC + 3); - switch (op4) { - case 0: /* INTON */ - saturn.PC += 4; - do_inton(); + case 8: /* CBIT=0 */ + op5 = read_nibble(saturn.PC + 4); + saturn.PC += 5; + clear_register_bit(saturn.C, op5); return 0; - case 1: /* RSI... */ - op5 = read_nibble(saturn.PC + 4); - saturn.PC += 5; - do_reset_interrupt_system(); + case 9: /* CBIT=1 */ + op5 = read_nibble(saturn.PC + 4); + saturn.PC += 5; + set_register_bit(saturn.C, op5); return 0; - case 2: /* LA... */ - op5 = read_nibble(saturn.PC + 4); - load_constant(saturn.A, op5 + 1, saturn.PC + 5); - saturn.PC += 6 + op5; - return 0; - case 3: /* BUSCB */ - saturn.PC += 4; - return 0; - case 4: /* ABIT=0 */ - op5 = read_nibble(saturn.PC + 4); - saturn.PC += 5; - clear_register_bit(saturn.A, op5); - return 0; - case 5: /* ABIT=1 */ - op5 = read_nibble(saturn.PC + 4); - saturn.PC += 5; - set_register_bit(saturn.A, op5); - return 0; - case 8: /* CBIT=0 */ - op5 = read_nibble(saturn.PC + 4); - saturn.PC += 5; - clear_register_bit(saturn.C, op5); - return 0; - case 9: /* CBIT=1 */ - op5 = read_nibble(saturn.PC + 4); - saturn.PC += 5; - set_register_bit(saturn.C, op5); - return 0; - case 6: /* ?ABIT=0 */ - case 7: /* ?ABIT=1 */ - case 0xa: /* ?CBIT=0 */ - case 0xb: /* ?CBIT=1 */ - op5 = read_nibble(saturn.PC + 4); + case 6: /* ?ABIT=0 */ + case 7: /* ?ABIT=1 */ + case 0xa: /* ?CBIT=0 */ + case 0xb: /* ?CBIT=1 */ + op5 = read_nibble(saturn.PC + 4); if (op4 < 8) - REG = saturn.A; - else - REG = saturn.C; - if (op4 == 6 || op4 == 0xa) - t = 0; - else - t = 1; - saturn.CARRY = (get_register_bit(REG, op5) == t)?1:0; + REG = saturn.A; + else + REG = saturn.C; + if (op4 == 6 || op4 == 0xa) + t = 0; + else + t = 1; + saturn.CARRY = (get_register_bit(REG, op5) == t) ? 1 : 0; if (saturn.CARRY) { saturn.PC += 5; - op6 = read_nibbles(saturn.PC, 2); - if (op6) { - if (op6 & 0x80) - op6 |= jumpmasks[2]; - jumpaddr = (saturn.PC + op6) & 0xfffff; + op6 = read_nibbles(saturn.PC, 2); + if (op6) { + if (op6 & 0x80) + op6 |= jumpmasks[2]; + jumpaddr = (saturn.PC + op6) & 0xfffff; saturn.PC = jumpaddr; - } else { + } else { saturn.PC = pop_return_addr(); - } + } } else { - saturn.PC += 7; + saturn.PC += 7; } - return 0; - case 0xc: /* PC=(A) */ - addr = dat_to_addr(saturn.A); - jumpaddr = read_nibbles(addr, 5); - saturn.PC = jumpaddr; - return 0; - case 0xd: /* BUSCD */ - saturn.PC += 4; return 0; - case 0xe: /* PC=(C) */ - addr = dat_to_addr(saturn.C); - jumpaddr = read_nibbles(addr, 5); - saturn.PC = jumpaddr; - return 0; - case 0xf: /* INTOFF */ - saturn.PC += 4; - do_intoff(); + case 0xc: /* PC=(A) */ + addr = dat_to_addr(saturn.A); + jumpaddr = read_nibbles(addr, 5); + saturn.PC = jumpaddr; return 0; - default: - return 1; - } - case 9: /* C+P+1 */ - saturn.PC += 3; - add_p_plus_one(saturn.C); - return 0; - case 0xa: /* RESET */ - saturn.PC += 3; - do_reset(); - return 0; - case 0xb: /* BUSCC */ - saturn.PC += 3; - return 0; - case 0xc: /* C=P n */ - op4 = read_nibble(saturn.PC + 3); + case 0xd: /* BUSCD */ saturn.PC += 4; - set_register_nibble(saturn.C, op4, saturn.P); return 0; - case 0xd: /* P=C n */ - op4 = read_nibble(saturn.PC + 3); + case 0xe: /* PC=(C) */ + addr = dat_to_addr(saturn.C); + jumpaddr = read_nibbles(addr, 5); + saturn.PC = jumpaddr; + return 0; + case 0xf: /* INTOFF */ saturn.PC += 4; - saturn.P = get_register_nibble(saturn.C, op4); - return 0; - case 0xe: /* SREQ? */ - saturn.PC += 3; - saturn.C[0] = 0; - saturn.SR = 0; - return 0; - case 0xf: /* CPEX n */ - op4 = read_nibble(saturn.PC + 3); - saturn.PC += 4; - t = get_register_nibble(saturn.C, op4); - set_register_nibble(saturn.C, op4, saturn.P); - saturn.P = t; + do_intoff(); return 0; default: return 1; + } + case 9: /* C+P+1 */ + saturn.PC += 3; + add_p_plus_one(saturn.C); + return 0; + case 0xa: /* RESET */ + saturn.PC += 3; + do_reset(); + return 0; + case 0xb: /* BUSCC */ + saturn.PC += 3; + return 0; + case 0xc: /* C=P n */ + op4 = read_nibble(saturn.PC + 3); + saturn.PC += 4; + set_register_nibble(saturn.C, op4, saturn.P); + return 0; + case 0xd: /* P=C n */ + op4 = read_nibble(saturn.PC + 3); + saturn.PC += 4; + saturn.P = get_register_nibble(saturn.C, op4); + return 0; + case 0xe: /* SREQ? */ + saturn.PC += 3; + saturn.C[0] = 0; + saturn.SR = 0; + return 0; + case 0xf: /* CPEX n */ + op4 = read_nibble(saturn.PC + 3); + saturn.PC += 4; + t = get_register_nibble(saturn.C, op4); + set_register_nibble(saturn.C, op4, saturn.P); + saturn.P = t; + return 0; + default: + return 1; } } @@ -291,395 +288,395 @@ int decode_group_1(void) { op2 = read_nibble(saturn.PC + 1); switch (op2) { - case 0: - op3 = read_nibble(saturn.PC + 2); - switch (op3) { - case 0: /* saturn.R0=A */ - saturn.PC += 3; - copy_register(saturn.R0, saturn.A, W_FIELD); - return 0; - case 1: /* saturn.R1=A */ - case 5: - saturn.PC += 3; - copy_register(saturn.R1, saturn.A, W_FIELD); - return 0; - case 2: /* saturn.R2=A */ - case 6: - saturn.PC += 3; - copy_register(saturn.R2, saturn.A, W_FIELD); - return 0; - case 3: /* saturn.R3=A */ - case 7: - saturn.PC += 3; - copy_register(saturn.R3, saturn.A, W_FIELD); - return 0; - case 4: /* saturn.R4=A */ - saturn.PC += 3; - copy_register(saturn.R4, saturn.A, W_FIELD); - return 0; - case 8: /* saturn.R0=C */ - saturn.PC += 3; - copy_register(saturn.R0, saturn.C, W_FIELD); - return 0; - case 9: /* saturn.R1=C */ - case 0xd: - saturn.PC += 3; - copy_register(saturn.R1, saturn.C, W_FIELD); - return 0; - case 0xa: /* saturn.R2=C */ - case 0xe: - saturn.PC += 3; - copy_register(saturn.R2, saturn.C, W_FIELD); - return 0; - case 0xb: /* saturn.R3=C */ - case 0xf: - saturn.PC += 3; - copy_register(saturn.R3, saturn.C, W_FIELD); - return 0; - case 0xc: /* saturn.R4=C */ - saturn.PC += 3; - copy_register(saturn.R4, saturn.C, W_FIELD); - return 0; - default: - return 1; - } - case 1: - op3 = read_nibble(saturn.PC + 2); - switch (op3) { - case 0: /* A=R0 */ - saturn.PC += 3; - copy_register(saturn.A, saturn.R0, W_FIELD); - return 0; - case 1: /* A=R1 */ - case 5: - saturn.PC += 3; - copy_register(saturn.A, saturn.R1, W_FIELD); - return 0; - case 2: /* A=R2 */ - case 6: - saturn.PC += 3; - copy_register(saturn.A, saturn.R2, W_FIELD); - return 0; - case 3: /* A=R3 */ - case 7: - saturn.PC += 3; - copy_register(saturn.A, saturn.R3, W_FIELD); - return 0; - case 4: /* A=R4 */ - saturn.PC += 3; - copy_register(saturn.A, saturn.R4, W_FIELD); - return 0; - case 8: /* C=R0 */ - saturn.PC += 3; - copy_register(saturn.C, saturn.R0, W_FIELD); - return 0; - case 9: /* C=R1 */ - case 0xd: - saturn.PC += 3; - copy_register(saturn.C, saturn.R1, W_FIELD); - return 0; - case 0xa: /* C=R2 */ - case 0xe: - saturn.PC += 3; - copy_register(saturn.C, saturn.R2, W_FIELD); - return 0; - case 0xb: /* C=R3 */ - case 0xf: - saturn.PC += 3; - copy_register(saturn.C, saturn.R3, W_FIELD); - return 0; - case 0xc: /* C=R4 */ - saturn.PC += 3; - copy_register(saturn.C, saturn.R4, W_FIELD); - return 0; - default: - return 1; - } - case 2: - op3 = read_nibble(saturn.PC + 2); - switch (op3) { - case 0: /* AR0EX */ - saturn.PC += 3; - exchange_register(saturn.A, saturn.R0, W_FIELD); - return 0; - case 1: /* AR1EX */ - case 5: - saturn.PC += 3; - exchange_register(saturn.A, saturn.R1, W_FIELD); - return 0; - case 2: /* AR2EX */ - case 6: - saturn.PC += 3; - exchange_register(saturn.A, saturn.R2, W_FIELD); - return 0; - case 3: /* AR3EX */ - case 7: - saturn.PC += 3; - exchange_register(saturn.A, saturn.R3, W_FIELD); - return 0; - case 4: /* AR4EX */ - saturn.PC += 3; - exchange_register(saturn.A, saturn.R4, W_FIELD); - return 0; - case 8: /* CR0EX */ - saturn.PC += 3; - exchange_register(saturn.C, saturn.R0, W_FIELD); - return 0; - case 9: /* CR1EX */ - case 0xd: - saturn.PC += 3; - exchange_register(saturn.C, saturn.R1, W_FIELD); - return 0; - case 0xa: /* CR2EX */ - case 0xe: - saturn.PC += 3; - exchange_register(saturn.C, saturn.R2, W_FIELD); - return 0; - case 0xb: /* CR3EX */ - case 0xf: - saturn.PC += 3; - exchange_register(saturn.C, saturn.R3, W_FIELD); - return 0; - case 0xc: /* CR4EX */ - saturn.PC += 3; - exchange_register(saturn.C, saturn.R4, W_FIELD); - return 0; - default: - return 1; - } - case 3: - op3 = read_nibble(saturn.PC + 2); - switch (op3) { - case 0: /* D0=A */ - saturn.PC += 3; + case 0: + op3 = read_nibble(saturn.PC + 2); + switch (op3) { + case 0: /* saturn.R0=A */ + saturn.PC += 3; + copy_register(saturn.R0, saturn.A, W_FIELD); + return 0; + case 1: /* saturn.R1=A */ + case 5: + saturn.PC += 3; + copy_register(saturn.R1, saturn.A, W_FIELD); + return 0; + case 2: /* saturn.R2=A */ + case 6: + saturn.PC += 3; + copy_register(saturn.R2, saturn.A, W_FIELD); + return 0; + case 3: /* saturn.R3=A */ + case 7: + saturn.PC += 3; + copy_register(saturn.R3, saturn.A, W_FIELD); + return 0; + case 4: /* saturn.R4=A */ + saturn.PC += 3; + copy_register(saturn.R4, saturn.A, W_FIELD); + return 0; + case 8: /* saturn.R0=C */ + saturn.PC += 3; + copy_register(saturn.R0, saturn.C, W_FIELD); + return 0; + case 9: /* saturn.R1=C */ + case 0xd: + saturn.PC += 3; + copy_register(saturn.R1, saturn.C, W_FIELD); + return 0; + case 0xa: /* saturn.R2=C */ + case 0xe: + saturn.PC += 3; + copy_register(saturn.R2, saturn.C, W_FIELD); + return 0; + case 0xb: /* saturn.R3=C */ + case 0xf: + saturn.PC += 3; + copy_register(saturn.R3, saturn.C, W_FIELD); + return 0; + case 0xc: /* saturn.R4=C */ + saturn.PC += 3; + copy_register(saturn.R4, saturn.C, W_FIELD); + return 0; + default: + return 1; + } + case 1: + op3 = read_nibble(saturn.PC + 2); + switch (op3) { + case 0: /* A=R0 */ + saturn.PC += 3; + copy_register(saturn.A, saturn.R0, W_FIELD); + return 0; + case 1: /* A=R1 */ + case 5: + saturn.PC += 3; + copy_register(saturn.A, saturn.R1, W_FIELD); + return 0; + case 2: /* A=R2 */ + case 6: + saturn.PC += 3; + copy_register(saturn.A, saturn.R2, W_FIELD); + return 0; + case 3: /* A=R3 */ + case 7: + saturn.PC += 3; + copy_register(saturn.A, saturn.R3, W_FIELD); + return 0; + case 4: /* A=R4 */ + saturn.PC += 3; + copy_register(saturn.A, saturn.R4, W_FIELD); + return 0; + case 8: /* C=R0 */ + saturn.PC += 3; + copy_register(saturn.C, saturn.R0, W_FIELD); + return 0; + case 9: /* C=R1 */ + case 0xd: + saturn.PC += 3; + copy_register(saturn.C, saturn.R1, W_FIELD); + return 0; + case 0xa: /* C=R2 */ + case 0xe: + saturn.PC += 3; + copy_register(saturn.C, saturn.R2, W_FIELD); + return 0; + case 0xb: /* C=R3 */ + case 0xf: + saturn.PC += 3; + copy_register(saturn.C, saturn.R3, W_FIELD); + return 0; + case 0xc: /* C=R4 */ + saturn.PC += 3; + copy_register(saturn.C, saturn.R4, W_FIELD); + return 0; + default: + return 1; + } + case 2: + op3 = read_nibble(saturn.PC + 2); + switch (op3) { + case 0: /* AR0EX */ + saturn.PC += 3; + exchange_register(saturn.A, saturn.R0, W_FIELD); + return 0; + case 1: /* AR1EX */ + case 5: + saturn.PC += 3; + exchange_register(saturn.A, saturn.R1, W_FIELD); + return 0; + case 2: /* AR2EX */ + case 6: + saturn.PC += 3; + exchange_register(saturn.A, saturn.R2, W_FIELD); + return 0; + case 3: /* AR3EX */ + case 7: + saturn.PC += 3; + exchange_register(saturn.A, saturn.R3, W_FIELD); + return 0; + case 4: /* AR4EX */ + saturn.PC += 3; + exchange_register(saturn.A, saturn.R4, W_FIELD); + return 0; + case 8: /* CR0EX */ + saturn.PC += 3; + exchange_register(saturn.C, saturn.R0, W_FIELD); + return 0; + case 9: /* CR1EX */ + case 0xd: + saturn.PC += 3; + exchange_register(saturn.C, saturn.R1, W_FIELD); + return 0; + case 0xa: /* CR2EX */ + case 0xe: + saturn.PC += 3; + exchange_register(saturn.C, saturn.R2, W_FIELD); + return 0; + case 0xb: /* CR3EX */ + case 0xf: + saturn.PC += 3; + exchange_register(saturn.C, saturn.R3, W_FIELD); + return 0; + case 0xc: /* CR4EX */ + saturn.PC += 3; + exchange_register(saturn.C, saturn.R4, W_FIELD); + return 0; + default: + return 1; + } + case 3: + op3 = read_nibble(saturn.PC + 2); + switch (op3) { + case 0: /* D0=A */ + saturn.PC += 3; register_to_address(saturn.A, &saturn.D0, 0); - return 0; - case 1: /* D1=A */ - saturn.PC += 3; + return 0; + case 1: /* D1=A */ + saturn.PC += 3; register_to_address(saturn.A, &saturn.D1, 0); - return 0; - case 2: /* AD0EX */ + return 0; + case 2: /* AD0EX */ saturn.PC += 3; exchange_reg(saturn.A, &saturn.D0, A_FIELD); return 0; - case 3: /* AD1EX */ + case 3: /* AD1EX */ saturn.PC += 3; exchange_reg(saturn.A, &saturn.D1, A_FIELD); return 0; - case 4: /* D0=C */ - saturn.PC += 3; + case 4: /* D0=C */ + saturn.PC += 3; register_to_address(saturn.C, &saturn.D0, 0); - return 0; - case 5: /* D1=C */ - saturn.PC += 3; + return 0; + case 5: /* D1=C */ + saturn.PC += 3; register_to_address(saturn.C, &saturn.D1, 0); - return 0; - case 6: /* CD0EX */ + return 0; + case 6: /* CD0EX */ saturn.PC += 3; exchange_reg(saturn.C, &saturn.D0, A_FIELD); return 0; - case 7: /* CD1EX */ + case 7: /* CD1EX */ saturn.PC += 3; exchange_reg(saturn.C, &saturn.D1, A_FIELD); return 0; - case 8: /* D0=AS */ - saturn.PC += 3; + case 8: /* D0=AS */ + saturn.PC += 3; register_to_address(saturn.A, &saturn.D0, 1); - return 0; - case 9: /* saturn.D1=AS */ - saturn.PC += 3; + return 0; + case 9: /* saturn.D1=AS */ + saturn.PC += 3; register_to_address(saturn.A, &saturn.D1, 1); - return 0; - case 0xa: /* AD0XS */ + return 0; + case 0xa: /* AD0XS */ saturn.PC += 3; exchange_reg(saturn.A, &saturn.D0, IN_FIELD); - return 0; - case 0xb: /* AD1XS */ + return 0; + case 0xb: /* AD1XS */ saturn.PC += 3; exchange_reg(saturn.A, &saturn.D1, IN_FIELD); - return 0; - case 0xc: /* D0=CS */ - saturn.PC += 3; + return 0; + case 0xc: /* D0=CS */ + saturn.PC += 3; register_to_address(saturn.C, &saturn.D0, 1); - return 0; - case 0xd: /* D1=CS */ - saturn.PC += 3; + return 0; + case 0xd: /* D1=CS */ + saturn.PC += 3; register_to_address(saturn.C, &saturn.D1, 1); - return 0; - case 0xe: /* CD0XS */ + return 0; + case 0xe: /* CD0XS */ saturn.PC += 3; exchange_reg(saturn.C, &saturn.D0, IN_FIELD); - return 0; - case 0xf: /* CD1XS */ + return 0; + case 0xf: /* CD1XS */ saturn.PC += 3; exchange_reg(saturn.C, &saturn.D1, IN_FIELD); - return 0; - default: - return 1; - } - case 4: - op3 = read_nibble(saturn.PC + 2); - op = op3 < 8 ? 0xf : 6; - switch(op3 & 7) { - case 0: /* DAT0=A */ + return 0; + default: + return 1; + } + case 4: + op3 = read_nibble(saturn.PC + 2); + op = op3 < 8 ? 0xf : 6; + switch (op3 & 7) { + case 0: /* DAT0=A */ saturn.PC += 3; store(saturn.D0, saturn.A, op); - return 0; - case 1: /* DAT1=A */ + return 0; + case 1: /* DAT1=A */ saturn.PC += 3; store(saturn.D1, saturn.A, op); - return 0; - case 2: /* A=DAT0 */ + return 0; + case 2: /* A=DAT0 */ saturn.PC += 3; recall(saturn.A, saturn.D0, op); - return 0; - case 3: /* A=DAT1 */ + return 0; + case 3: /* A=DAT1 */ saturn.PC += 3; recall(saturn.A, saturn.D1, op); - return 0; - case 4: /* DAT0=C */ + return 0; + case 4: /* DAT0=C */ saturn.PC += 3; store(saturn.D0, saturn.C, op); - return 0; - case 5: /* DAT1=C */ + return 0; + case 5: /* DAT1=C */ saturn.PC += 3; store(saturn.D1, saturn.C, op); - return 0; - case 6: /* C=DAT0 */ + return 0; + case 6: /* C=DAT0 */ saturn.PC += 3; recall(saturn.C, saturn.D0, op); - return 0; - case 7: /* C=DAT1 */ + return 0; + case 7: /* C=DAT1 */ saturn.PC += 3; recall(saturn.C, saturn.D1, op); - return 0; + return 0; default: return 1; - } - case 5: - op3 = read_nibble(saturn.PC + 2); - op4 = read_nibble(saturn.PC + 3); - if (op3 >= 8) { - switch(op3 & 7) { - case 0: /* DAT0=A */ + } + case 5: + op3 = read_nibble(saturn.PC + 2); + op4 = read_nibble(saturn.PC + 3); + if (op3 >= 8) { + switch (op3 & 7) { + case 0: /* DAT0=A */ saturn.PC += 4; - store_n(saturn.D0, saturn.A, op4+1); - return 0; - case 1: /* DAT1=A */ + store_n(saturn.D0, saturn.A, op4 + 1); + return 0; + case 1: /* DAT1=A */ saturn.PC += 4; - store_n(saturn.D1, saturn.A, op4+1); - return 0; - case 2: /* A=DAT0 */ + store_n(saturn.D1, saturn.A, op4 + 1); + return 0; + case 2: /* A=DAT0 */ saturn.PC += 4; - recall_n(saturn.A, saturn.D0, op4+1); - return 0; - case 3: /* A=DAT1 */ + recall_n(saturn.A, saturn.D0, op4 + 1); + return 0; + case 3: /* A=DAT1 */ saturn.PC += 4; - recall_n(saturn.A, saturn.D1, op4+1); - return 0; - case 4: /* DAT0=C */ + recall_n(saturn.A, saturn.D1, op4 + 1); + return 0; + case 4: /* DAT0=C */ saturn.PC += 4; - store_n(saturn.D0, saturn.C, op4+1); - return 0; - case 5: /* DAT1=C */ + store_n(saturn.D0, saturn.C, op4 + 1); + return 0; + case 5: /* DAT1=C */ saturn.PC += 4; - store_n(saturn.D1, saturn.C, op4+1); - return 0; - case 6: /* C=DAT0 */ + store_n(saturn.D1, saturn.C, op4 + 1); + return 0; + case 6: /* C=DAT0 */ saturn.PC += 4; - recall_n(saturn.C, saturn.D0, op4+1); - return 0; - case 7: /* C=DAT1 */ + recall_n(saturn.C, saturn.D0, op4 + 1); + return 0; + case 7: /* C=DAT1 */ saturn.PC += 4; - recall_n(saturn.C, saturn.D1, op4+1); - return 0; + recall_n(saturn.C, saturn.D1, op4 + 1); + return 0; default: return 1; - } - } else { - switch(op3) { - case 0: /* DAT0=A */ + } + } else { + switch (op3) { + case 0: /* DAT0=A */ saturn.PC += 4; store(saturn.D0, saturn.A, op4); - return 0; - case 1: /* DAT1=A */ + return 0; + case 1: /* DAT1=A */ saturn.PC += 4; store(saturn.D1, saturn.A, op4); - return 0; - case 2: /* A=DAT0 */ + return 0; + case 2: /* A=DAT0 */ saturn.PC += 4; recall(saturn.A, saturn.D0, op4); - return 0; - case 3: /* A=DAT1 */ + return 0; + case 3: /* A=DAT1 */ saturn.PC += 4; recall(saturn.A, saturn.D1, op4); - return 0; - case 4: /* DAT0=C */ + return 0; + case 4: /* DAT0=C */ saturn.PC += 4; store(saturn.D0, saturn.C, op4); - return 0; - case 5: /* DAT1=C */ + return 0; + case 5: /* DAT1=C */ saturn.PC += 4; store(saturn.D1, saturn.C, op4); - return 0; - case 6: /* C=DAT0 */ + return 0; + case 6: /* C=DAT0 */ saturn.PC += 4; recall(saturn.C, saturn.D0, op4); - return 0; - case 7: /* C=DAT1 */ + return 0; + case 7: /* C=DAT1 */ saturn.PC += 4; recall(saturn.C, saturn.D1, op4); - return 0; + return 0; default: return 1; - } } - case 6: - op3 = read_nibble(saturn.PC + 2); - saturn.PC += 3; - add_address(&saturn.D0, op3+1); - return 0; - case 7: - op3 = read_nibble(saturn.PC + 2); - saturn.PC += 3; - add_address(&saturn.D1, op3+1); - return 0; - case 8: - op3 = read_nibble(saturn.PC + 2); - saturn.PC += 3; - add_address(&saturn.D0, -(op3+1)); - return 0; - case 9: - load_addr(&saturn.D0, saturn.PC+2, 2); - saturn.PC += 4; - return 0; - case 0xa: - load_addr(&saturn.D0, saturn.PC+2, 4); - saturn.PC += 6; - return 0; - case 0xb: - load_addr(&saturn.D0, saturn.PC+2, 5); - saturn.PC += 7; - return 0; - case 0xc: - op3 = read_nibble(saturn.PC + 2); - saturn.PC += 3; - add_address(&saturn.D1, -(op3+1)); - return 0; - case 0xd: - load_addr(&saturn.D1, saturn.PC+2, 2); - saturn.PC += 4; - return 0; - case 0xe: - load_addr(&saturn.D1, saturn.PC+2, 4); - saturn.PC += 6; - return 0; - case 0xf: - load_addr(&saturn.D1, saturn.PC+2, 5); - saturn.PC += 7; - return 0; - default: - return 1; + } + case 6: + op3 = read_nibble(saturn.PC + 2); + saturn.PC += 3; + add_address(&saturn.D0, op3 + 1); + return 0; + case 7: + op3 = read_nibble(saturn.PC + 2); + saturn.PC += 3; + add_address(&saturn.D1, op3 + 1); + return 0; + case 8: + op3 = read_nibble(saturn.PC + 2); + saturn.PC += 3; + add_address(&saturn.D0, -(op3 + 1)); + return 0; + case 9: + load_addr(&saturn.D0, saturn.PC + 2, 2); + saturn.PC += 4; + return 0; + case 0xa: + load_addr(&saturn.D0, saturn.PC + 2, 4); + saturn.PC += 6; + return 0; + case 0xb: + load_addr(&saturn.D0, saturn.PC + 2, 5); + saturn.PC += 7; + return 0; + case 0xc: + op3 = read_nibble(saturn.PC + 2); + saturn.PC += 3; + add_address(&saturn.D1, -(op3 + 1)); + return 0; + case 0xd: + load_addr(&saturn.D1, saturn.PC + 2, 2); + saturn.PC += 4; + return 0; + case 0xe: + load_addr(&saturn.D1, saturn.PC + 2, 4); + saturn.PC += 6; + return 0; + case 0xf: + load_addr(&saturn.D1, saturn.PC + 2, 5); + saturn.PC += 7; + return 0; + default: + return 1; } } @@ -688,694 +685,402 @@ static inline int decode_8_thru_f(int op1) { op2 = read_nibble(saturn.PC + 1); switch (op1) { - case 8: - switch (op2) { - case 0: - return decode_group_80(); - case 1: - op3 = read_nibble(saturn.PC + 2); - switch (op3) { - case 0: /* ASLC */ - saturn.PC += 3; - shift_left_circ_register(saturn.A, W_FIELD); - return 0; - case 1: /* BSLC */ - saturn.PC += 3; - shift_left_circ_register(saturn.B, W_FIELD); - return 0; - case 2: /* CSLC */ - saturn.PC += 3; - shift_left_circ_register(saturn.C, W_FIELD); - return 0; - case 3: /* DSLC */ - saturn.PC += 3; - shift_left_circ_register(saturn.D, W_FIELD); - return 0; - case 4: /* ASRC */ - saturn.PC += 3; - shift_right_circ_register(saturn.A, W_FIELD); - return 0; - case 5: /* BSRC */ - saturn.PC += 3; - shift_right_circ_register(saturn.B, W_FIELD); - return 0; - case 6: /* CSRC */ - saturn.PC += 3; - shift_right_circ_register(saturn.C, W_FIELD); - return 0; - case 7: /* DSRC */ - saturn.PC += 3; - shift_right_circ_register(saturn.D, W_FIELD); - return 0; - case 8: /* R = R +/- CON */ - op4 = read_nibble(saturn.PC + 3); - op5 = read_nibble(saturn.PC + 4); - op6 = read_nibble(saturn.PC + 5); - if (op5 < 8) { /* PLUS */ - switch (op5 & 3) { - case 0: /* A=A+CON */ - saturn.PC += 6; - add_register_constant(saturn.A, op4, op6+1); - return 0; - case 1: /* B=B+CON */ - saturn.PC += 6; - add_register_constant(saturn.B, op4, op6+1); - return 0; - case 2: /* C=C+CON */ - saturn.PC += 6; - add_register_constant(saturn.C, op4, op6+1); - return 0; - case 3: /* D=D+CON */ - saturn.PC += 6; - add_register_constant(saturn.D, op4, op6+1); - return 0; - default: - return 1; - } - } else { /* MINUS */ - switch (op5 & 3) { - case 0: /* A=A-CON */ - saturn.PC += 6; - sub_register_constant(saturn.A, op4, op6+1); - return 0; - case 1: /* B=B-CON */ - saturn.PC += 6; - sub_register_constant(saturn.B, op4, op6+1); - return 0; - case 2: /* C=C-CON */ - saturn.PC += 6; - sub_register_constant(saturn.C, op4, op6+1); - return 0; - case 3: /* D=D-CON */ - saturn.PC += 6; - sub_register_constant(saturn.D, op4, op6+1); - return 0; - default: - return 1; - } - } - case 9: /* R SRB FIELD */ - op4 = read_nibble(saturn.PC + 3); - op5 = read_nibble(saturn.PC + 4); - switch (op5 & 3) { - case 0: - saturn.PC += 5; - shift_right_bit_register(saturn.A, op4); - return 0; - case 1: - saturn.PC += 5; - shift_right_bit_register(saturn.B, op4); - return 0; - case 2: - saturn.PC += 5; - shift_right_bit_register(saturn.C, op4); - return 0; - case 3: - saturn.PC += 5; - shift_right_bit_register(saturn.D, op4); - return 0; - default: - return 1; - } - case 0xa: /* R = R FIELD, etc. */ - op4 = read_nibble(saturn.PC + 3); - op5 = read_nibble(saturn.PC + 4); - op6 = read_nibble(saturn.PC + 5); - switch (op5) { - case 0: - switch (op6) { - case 0: /* saturn.R0=A */ - saturn.PC += 6; - copy_register(saturn.R0, saturn.A, op4); - return 0; - case 1: /* saturn.R1=A */ - case 5: - saturn.PC += 6; - copy_register(saturn.R1, saturn.A, op4); - return 0; - case 2: /* saturn.R2=A */ - case 6: - saturn.PC += 6; - copy_register(saturn.R2, saturn.A, op4); - return 0; - case 3: /* saturn.R3=A */ - case 7: - saturn.PC += 6; - copy_register(saturn.R3, saturn.A, op4); - return 0; - case 4: /* saturn.R4=A */ - saturn.PC += 6; - copy_register(saturn.R4, saturn.A, op4); - return 0; - case 8: /* saturn.R0=C */ - saturn.PC += 6; - copy_register(saturn.R0, saturn.C, op4); - return 0; - case 9: /* saturn.R1=C */ - case 0xd: - saturn.PC += 6; - copy_register(saturn.R1, saturn.C, op4); - return 0; - case 0xa: /* saturn.R2=C */ - case 0xe: - saturn.PC += 6; - copy_register(saturn.R2, saturn.C, op4); - return 0; - case 0xb: /* saturn.R3=C */ - case 0xf: - saturn.PC += 6; - copy_register(saturn.R3, saturn.C, op4); - return 0; - case 0xc: /* saturn.R4=C */ - saturn.PC += 6; - copy_register(saturn.R4, saturn.C, op4); - return 0; - default: - return 1; - } - case 1: - switch (op6) { - case 0: /* A=R0 */ - saturn.PC += 6; - copy_register(saturn.A, saturn.R0, op4); - return 0; - case 1: /* A=R1 */ - case 5: - saturn.PC += 6; - copy_register(saturn.A, saturn.R1, op4); - return 0; - case 2: /* A=R2 */ - case 6: - saturn.PC += 6; - copy_register(saturn.A, saturn.R2, op4); - return 0; - case 3: /* A=R3 */ - case 7: - saturn.PC += 6; - copy_register(saturn.A, saturn.R3, op4); - return 0; - case 4: /* A=R4 */ - saturn.PC += 6; - copy_register(saturn.A, saturn.R4, op4); - return 0; - case 8: /* C=R0 */ - saturn.PC += 6; - copy_register(saturn.C, saturn.R0, op4); - return 0; - case 9: /* C=R1 */ - case 0xd: - saturn.PC += 6; - copy_register(saturn.C, saturn.R1, op4); - return 0; - case 0xa: /* C=R2 */ - case 0xe: - saturn.PC += 6; - copy_register(saturn.C, saturn.R2, op4); - return 0; - case 0xb: /* C=R3 */ - case 0xf: - saturn.PC += 6; - copy_register(saturn.C, saturn.R3, op4); - return 0; - case 0xc: /* C=R4 */ - saturn.PC += 6; - copy_register(saturn.C, saturn.R4, op4); - return 0; - default: - return 1; - } - case 2: - switch (op6) { - case 0: /* AR0EX */ - saturn.PC += 6; - exchange_register(saturn.A, saturn.R0, op4); - return 0; - case 1: /* AR1EX */ - case 5: - saturn.PC += 6; - exchange_register(saturn.A, saturn.R1, op4); - return 0; - case 2: /* AR2EX */ - case 6: - saturn.PC += 6; - exchange_register(saturn.A, saturn.R2, op4); - return 0; - case 3: /* AR3EX */ - case 7: - saturn.PC += 6; - exchange_register(saturn.A, saturn.R3, op4); - return 0; - case 4: /* AR4EX */ - saturn.PC += 6; - exchange_register(saturn.A, saturn.R4, op4); - return 0; - case 8: /* CR0EX */ - saturn.PC += 6; - exchange_register(saturn.C, saturn.R0, op4); - return 0; - case 9: /* CR1EX */ - case 0xd: - saturn.PC += 6; - exchange_register(saturn.C, saturn.R1, op4); - return 0; - case 0xa: /* CR2EX */ - case 0xe: - saturn.PC += 6; - exchange_register(saturn.C, saturn.R2, op4); - return 0; - case 0xb: /* CR3EX */ - case 0xf: - saturn.PC += 6; - exchange_register(saturn.C, saturn.R3, op4); - return 0; - case 0xc: /* CR4EX */ - saturn.PC += 6; - exchange_register(saturn.C, saturn.R4, op4); - return 0; - default: - return 1; - } - default: - return 1; - } - case 0xb: - op4 = read_nibble(saturn.PC + 3); - switch(op4) { - case 2: /* PC=A */ - jumpaddr = dat_to_addr(saturn.A); - saturn.PC = jumpaddr; - return 0; - case 3: /* PC=C */ - jumpaddr = dat_to_addr(saturn.C); - saturn.PC = jumpaddr; - return 0; - case 4: /* A=PC */ - saturn.PC += 4; - addr_to_dat(saturn.PC, saturn.A); - return 0; - case 5: /* C=PC */ - saturn.PC += 4; - addr_to_dat(saturn.PC, saturn.C); - return 0; - case 6: /* APCEX */ - saturn.PC += 4; - jumpaddr = dat_to_addr(saturn.A); - addr_to_dat(saturn.PC, saturn.A); - saturn.PC = jumpaddr; - return 0; - case 7: /* CPCEX */ - saturn.PC += 4; - jumpaddr = dat_to_addr(saturn.C); - addr_to_dat(saturn.PC, saturn.C); - saturn.PC = jumpaddr; - return 0; - default: - return 1; - } - case 0xc: /* ASRB */ - saturn.PC += 3; - shift_right_bit_register(saturn.A, W_FIELD); - return 0; - case 0xd: /* BSRB */ - saturn.PC += 3; - shift_right_bit_register(saturn.B, W_FIELD); - return 0; - case 0xe: /* CSRB */ - saturn.PC += 3; - shift_right_bit_register(saturn.C, W_FIELD); - return 0; - case 0xf: /* DSRB */ - saturn.PC += 3; - shift_right_bit_register(saturn.D, W_FIELD); - return 0; - default: - return 1; + case 8: + switch (op2) { + case 0: + return decode_group_80(); + case 1: + op3 = read_nibble(saturn.PC + 2); + switch (op3) { + case 0: /* ASLC */ + saturn.PC += 3; + shift_left_circ_register(saturn.A, W_FIELD); + return 0; + case 1: /* BSLC */ + saturn.PC += 3; + shift_left_circ_register(saturn.B, W_FIELD); + return 0; + case 2: /* CSLC */ + saturn.PC += 3; + shift_left_circ_register(saturn.C, W_FIELD); + return 0; + case 3: /* DSLC */ + saturn.PC += 3; + shift_left_circ_register(saturn.D, W_FIELD); + return 0; + case 4: /* ASRC */ + saturn.PC += 3; + shift_right_circ_register(saturn.A, W_FIELD); + return 0; + case 5: /* BSRC */ + saturn.PC += 3; + shift_right_circ_register(saturn.B, W_FIELD); + return 0; + case 6: /* CSRC */ + saturn.PC += 3; + shift_right_circ_register(saturn.C, W_FIELD); + return 0; + case 7: /* DSRC */ + saturn.PC += 3; + shift_right_circ_register(saturn.D, W_FIELD); + return 0; + case 8: /* R = R +/- CON */ + op4 = read_nibble(saturn.PC + 3); + op5 = read_nibble(saturn.PC + 4); + op6 = read_nibble(saturn.PC + 5); + if (op5 < 8) { /* PLUS */ + switch (op5 & 3) { + case 0: /* A=A+CON */ + saturn.PC += 6; + add_register_constant(saturn.A, op4, op6 + 1); + return 0; + case 1: /* B=B+CON */ + saturn.PC += 6; + add_register_constant(saturn.B, op4, op6 + 1); + return 0; + case 2: /* C=C+CON */ + saturn.PC += 6; + add_register_constant(saturn.C, op4, op6 + 1); + return 0; + case 3: /* D=D+CON */ + saturn.PC += 6; + add_register_constant(saturn.D, op4, op6 + 1); + return 0; + default: + return 1; } + } else { /* MINUS */ + switch (op5 & 3) { + case 0: /* A=A-CON */ + saturn.PC += 6; + sub_register_constant(saturn.A, op4, op6 + 1); + return 0; + case 1: /* B=B-CON */ + saturn.PC += 6; + sub_register_constant(saturn.B, op4, op6 + 1); + return 0; + case 2: /* C=C-CON */ + saturn.PC += 6; + sub_register_constant(saturn.C, op4, op6 + 1); + return 0; + case 3: /* D=D-CON */ + saturn.PC += 6; + sub_register_constant(saturn.D, op4, op6 + 1); + return 0; + default: + return 1; + } + } + case 9: /* R SRB FIELD */ + op4 = read_nibble(saturn.PC + 3); + op5 = read_nibble(saturn.PC + 4); + switch (op5 & 3) { + case 0: + saturn.PC += 5; + shift_right_bit_register(saturn.A, op4); + return 0; + case 1: + saturn.PC += 5; + shift_right_bit_register(saturn.B, op4); + return 0; case 2: - op3 = read_nibble(saturn.PC + 2); - saturn.PC += 3; - clear_hardware_stat(op3); + saturn.PC += 5; + shift_right_bit_register(saturn.C, op4); return 0; case 3: - op3 = read_nibble(saturn.PC + 2); - saturn.CARRY = is_zero_hardware_stat(op3); - if (saturn.CARRY) { - saturn.PC += 3; - op4 = read_nibbles(saturn.PC, 2); - if (op4) { - if (op4 & 0x80) - op4 |= jumpmasks[2]; - jumpaddr = (saturn.PC + op4) & 0xfffff; - saturn.PC = jumpaddr; - } else { - saturn.PC = pop_return_addr(); - } - } else { - saturn.PC += 5; - } + saturn.PC += 5; + shift_right_bit_register(saturn.D, op4); return 0; - case 4: - case 5: - op3 = read_nibble(saturn.PC + 2); - if (op2 == 4) { - saturn.PC += 3; - clear_program_stat(op3); - } else { - saturn.PC += 3; - set_program_stat(op3); - } - return 0; - case 6: - case 7: - op3 = read_nibble(saturn.PC + 2); - if (op2 == 6) - saturn.CARRY = (get_program_stat(op3) == 0)?1:0; - else - saturn.CARRY = (get_program_stat(op3) != 0)?1:0; - if (saturn.CARRY) { - saturn.PC += 3; - op4 = read_nibbles(saturn.PC, 2); - if (op4) { - if (op4 & 0x80) - op4 |= jumpmasks[2]; - jumpaddr = (saturn.PC + op4) & 0xfffff; - saturn.PC = jumpaddr; - } else { - saturn.PC = pop_return_addr(); - } - } else { - saturn.PC += 5; - } - return 0; - case 8: - case 9: - op3 = read_nibble(saturn.PC + 2); - if (op2 == 8) - saturn.CARRY = (saturn.P != op3)?1:0; - else - saturn.CARRY = (saturn.P == op3)?1:0; - if (saturn.CARRY) { - saturn.PC += 3; - op4 = read_nibbles(saturn.PC, 2); - if (op4) { - if (op4 & 0x80) - op4 |= jumpmasks[2]; - jumpaddr = (saturn.PC + op4) & 0xfffff; - saturn.PC = jumpaddr; - } else { - saturn.PC = pop_return_addr(); - } - } else { - saturn.PC += 5; - } - return 0; - case 0xa: - op3 = read_nibble(saturn.PC + 2); - switch(op3) { - case 0: /* ?A=B */ - saturn.CARRY = is_equal_register(saturn.A, saturn.B, A_FIELD); - break; - case 1: /* ?B=C */ - saturn.CARRY = is_equal_register(saturn.B, saturn.C, A_FIELD); - break; - case 2: /* ?A=C */ - saturn.CARRY = is_equal_register(saturn.A, saturn.C, A_FIELD); - break; - case 3: /* ?C=D */ - saturn.CARRY = is_equal_register(saturn.C, saturn.D, A_FIELD); - break; - case 4: /* ?A#B */ - saturn.CARRY = is_not_equal_register(saturn.A, saturn.B, A_FIELD); - break; - case 5: /* ?B#C */ - saturn.CARRY = is_not_equal_register(saturn.B, saturn.C, A_FIELD); - break; - case 6: /* ?A#C */ - saturn.CARRY = is_not_equal_register(saturn.A, saturn.C, A_FIELD); - break; - case 7: /* ?C#D */ - saturn.CARRY = is_not_equal_register(saturn.C, saturn.D, A_FIELD); - break; - case 8: /* ?A=0 */ - saturn.CARRY = is_zero_register(saturn.A, A_FIELD); - break; - case 9: /* ?B=0 */ - saturn.CARRY = is_zero_register(saturn.B, A_FIELD); - break; - case 0xa: /* ?C=0 */ - saturn.CARRY = is_zero_register(saturn.C, A_FIELD); - break; - case 0xb: /* ?D=0 */ - saturn.CARRY = is_zero_register(saturn.D, A_FIELD); - break; - case 0xc: /* ?A#0 */ - saturn.CARRY = is_not_zero_register(saturn.A, A_FIELD); - break; - case 0xd: /* ?B#0 */ - saturn.CARRY = is_not_zero_register(saturn.B, A_FIELD); - break; - case 0xe: /* ?C#0 */ - saturn.CARRY = is_not_zero_register(saturn.C, A_FIELD); - break; - case 0xf: /* ?D#0 */ - saturn.CARRY = is_not_zero_register(saturn.D, A_FIELD); - break; - default: - return 1; - } - if (saturn.CARRY) { - saturn.PC += 3; - op4 = read_nibbles(saturn.PC, 2); - if (op4) { - if (op4 & 0x80) - op4 |= jumpmasks[2]; - jumpaddr = (saturn.PC + op4) & 0xfffff; - saturn.PC = jumpaddr; - } else { - saturn.PC = pop_return_addr(); - } - } else { - saturn.PC += 5; - } - return 0; - case 0xb: - op3 = read_nibble(saturn.PC + 2); - switch (op3) { - case 0: /* ?A>B */ - saturn.CARRY = is_greater_register(saturn.A, saturn.B, A_FIELD); - break; - case 1: /* ?B>C */ - saturn.CARRY = is_greater_register(saturn.B, saturn.C, A_FIELD); - break; - case 2: /* ?C>A */ - saturn.CARRY = is_greater_register(saturn.C, saturn.A, A_FIELD); - break; - case 3: /* ?D>C */ - saturn.CARRY = is_greater_register(saturn.D, saturn.C, A_FIELD); - break; - case 4: /* ?A=B */ - saturn.CARRY = is_greater_or_equal_register(saturn.A, saturn.B, A_FIELD); - break; - case 9: /* ?B>=C */ - saturn.CARRY = is_greater_or_equal_register(saturn.B, saturn.C, A_FIELD); - break; - case 0xa: /* ?C>=A */ - saturn.CARRY = is_greater_or_equal_register(saturn.C, saturn.A, A_FIELD); - break; - case 0xb: /* ?D>=C */ - saturn.CARRY = is_greater_or_equal_register(saturn.D, saturn.C, A_FIELD); - break; - case 0xc: /* ?A<=B */ - saturn.CARRY = is_less_or_equal_register(saturn.A, saturn.B, A_FIELD); - break; - case 0xd: /* ?B<=C */ - saturn.CARRY = is_less_or_equal_register(saturn.B, saturn.C, A_FIELD); - break; - case 0xe: /* ?C<=A */ - saturn.CARRY = is_less_or_equal_register(saturn.C, saturn.A, A_FIELD); - break; - case 0xf: /* ?D<=C */ - saturn.CARRY = is_less_or_equal_register(saturn.D, saturn.C, A_FIELD); - break; - default: - return 1; - } - if (saturn.CARRY) { - saturn.PC += 3; - op4 = read_nibbles(saturn.PC, 2); - if (op4) { - if (op4 & 0x80) - op4 |= jumpmasks[2]; - jumpaddr = (saturn.PC + op4) & 0xfffff; - saturn.PC = jumpaddr; - } else { - saturn.PC = pop_return_addr(); - } - } else { - saturn.PC += 5; - } - return 0; - case 0xc: - op3 = read_nibbles(saturn.PC + 2, 4); - if (op3 & 0x8000) - op3 |= jumpmasks[4]; - jumpaddr = (saturn.PC + op3 + 2) & 0xfffff; - saturn.PC = jumpaddr; - return 0; - case 0xd: - op3 = read_nibbles(saturn.PC + 2, 5); - jumpaddr = op3; - saturn.PC = jumpaddr; - return 0; - case 0xe: - op3 = read_nibbles(saturn.PC + 2, 4); - if (op3 & 0x8000) - op3 |= jumpmasks[4]; - jumpaddr = (saturn.PC + op3 + 6) & 0xfffff; - push_return_addr(saturn.PC + 6); - saturn.PC = jumpaddr; - return 0; - case 0xf: - op3 = read_nibbles(saturn.PC + 2, 5); - jumpaddr = op3; - push_return_addr(saturn.PC + 7); - saturn.PC = jumpaddr; - return 0; default: return 1; + } + case 0xa: /* R = R FIELD, etc. */ + op4 = read_nibble(saturn.PC + 3); + op5 = read_nibble(saturn.PC + 4); + op6 = read_nibble(saturn.PC + 5); + switch (op5) { + case 0: + switch (op6) { + case 0: /* saturn.R0=A */ + saturn.PC += 6; + copy_register(saturn.R0, saturn.A, op4); + return 0; + case 1: /* saturn.R1=A */ + case 5: + saturn.PC += 6; + copy_register(saturn.R1, saturn.A, op4); + return 0; + case 2: /* saturn.R2=A */ + case 6: + saturn.PC += 6; + copy_register(saturn.R2, saturn.A, op4); + return 0; + case 3: /* saturn.R3=A */ + case 7: + saturn.PC += 6; + copy_register(saturn.R3, saturn.A, op4); + return 0; + case 4: /* saturn.R4=A */ + saturn.PC += 6; + copy_register(saturn.R4, saturn.A, op4); + return 0; + case 8: /* saturn.R0=C */ + saturn.PC += 6; + copy_register(saturn.R0, saturn.C, op4); + return 0; + case 9: /* saturn.R1=C */ + case 0xd: + saturn.PC += 6; + copy_register(saturn.R1, saturn.C, op4); + return 0; + case 0xa: /* saturn.R2=C */ + case 0xe: + saturn.PC += 6; + copy_register(saturn.R2, saturn.C, op4); + return 0; + case 0xb: /* saturn.R3=C */ + case 0xf: + saturn.PC += 6; + copy_register(saturn.R3, saturn.C, op4); + return 0; + case 0xc: /* saturn.R4=C */ + saturn.PC += 6; + copy_register(saturn.R4, saturn.C, op4); + return 0; + default: + return 1; + } + case 1: + switch (op6) { + case 0: /* A=R0 */ + saturn.PC += 6; + copy_register(saturn.A, saturn.R0, op4); + return 0; + case 1: /* A=R1 */ + case 5: + saturn.PC += 6; + copy_register(saturn.A, saturn.R1, op4); + return 0; + case 2: /* A=R2 */ + case 6: + saturn.PC += 6; + copy_register(saturn.A, saturn.R2, op4); + return 0; + case 3: /* A=R3 */ + case 7: + saturn.PC += 6; + copy_register(saturn.A, saturn.R3, op4); + return 0; + case 4: /* A=R4 */ + saturn.PC += 6; + copy_register(saturn.A, saturn.R4, op4); + return 0; + case 8: /* C=R0 */ + saturn.PC += 6; + copy_register(saturn.C, saturn.R0, op4); + return 0; + case 9: /* C=R1 */ + case 0xd: + saturn.PC += 6; + copy_register(saturn.C, saturn.R1, op4); + return 0; + case 0xa: /* C=R2 */ + case 0xe: + saturn.PC += 6; + copy_register(saturn.C, saturn.R2, op4); + return 0; + case 0xb: /* C=R3 */ + case 0xf: + saturn.PC += 6; + copy_register(saturn.C, saturn.R3, op4); + return 0; + case 0xc: /* C=R4 */ + saturn.PC += 6; + copy_register(saturn.C, saturn.R4, op4); + return 0; + default: + return 1; + } + case 2: + switch (op6) { + case 0: /* AR0EX */ + saturn.PC += 6; + exchange_register(saturn.A, saturn.R0, op4); + return 0; + case 1: /* AR1EX */ + case 5: + saturn.PC += 6; + exchange_register(saturn.A, saturn.R1, op4); + return 0; + case 2: /* AR2EX */ + case 6: + saturn.PC += 6; + exchange_register(saturn.A, saturn.R2, op4); + return 0; + case 3: /* AR3EX */ + case 7: + saturn.PC += 6; + exchange_register(saturn.A, saturn.R3, op4); + return 0; + case 4: /* AR4EX */ + saturn.PC += 6; + exchange_register(saturn.A, saturn.R4, op4); + return 0; + case 8: /* CR0EX */ + saturn.PC += 6; + exchange_register(saturn.C, saturn.R0, op4); + return 0; + case 9: /* CR1EX */ + case 0xd: + saturn.PC += 6; + exchange_register(saturn.C, saturn.R1, op4); + return 0; + case 0xa: /* CR2EX */ + case 0xe: + saturn.PC += 6; + exchange_register(saturn.C, saturn.R2, op4); + return 0; + case 0xb: /* CR3EX */ + case 0xf: + saturn.PC += 6; + exchange_register(saturn.C, saturn.R3, op4); + return 0; + case 0xc: /* CR4EX */ + saturn.PC += 6; + exchange_register(saturn.C, saturn.R4, op4); + return 0; + default: + return 1; + } + default: + return 1; + } + case 0xb: + op4 = read_nibble(saturn.PC + 3); + switch (op4) { + case 2: /* PC=A */ + jumpaddr = dat_to_addr(saturn.A); + saturn.PC = jumpaddr; + return 0; + case 3: /* PC=C */ + jumpaddr = dat_to_addr(saturn.C); + saturn.PC = jumpaddr; + return 0; + case 4: /* A=PC */ + saturn.PC += 4; + addr_to_dat(saturn.PC, saturn.A); + return 0; + case 5: /* C=PC */ + saturn.PC += 4; + addr_to_dat(saturn.PC, saturn.C); + return 0; + case 6: /* APCEX */ + saturn.PC += 4; + jumpaddr = dat_to_addr(saturn.A); + addr_to_dat(saturn.PC, saturn.A); + saturn.PC = jumpaddr; + return 0; + case 7: /* CPCEX */ + saturn.PC += 4; + jumpaddr = dat_to_addr(saturn.C); + addr_to_dat(saturn.PC, saturn.C); + saturn.PC = jumpaddr; + return 0; + default: + return 1; + } + case 0xc: /* ASRB */ + saturn.PC += 3; + shift_right_bit_register(saturn.A, W_FIELD); + return 0; + case 0xd: /* BSRB */ + saturn.PC += 3; + shift_right_bit_register(saturn.B, W_FIELD); + return 0; + case 0xe: /* CSRB */ + saturn.PC += 3; + shift_right_bit_register(saturn.C, W_FIELD); + return 0; + case 0xf: /* DSRB */ + saturn.PC += 3; + shift_right_bit_register(saturn.D, W_FIELD); + return 0; + default: + return 1; } - case 9: + case 2: op3 = read_nibble(saturn.PC + 2); - if (op2 < 8) { - switch(op3) { - case 0: /* ?A=B */ - saturn.CARRY = is_equal_register(saturn.A, saturn.B, op2); - break; - case 1: /* ?B=C */ - saturn.CARRY = is_equal_register(saturn.B, saturn.C, op2); - break; - case 2: /* ?A=C */ - saturn.CARRY = is_equal_register(saturn.A, saturn.C, op2); - break; - case 3: /* ?C=D */ - saturn.CARRY = is_equal_register(saturn.C, saturn.D, op2); - break; - case 4: /* ?A#B */ - saturn.CARRY = is_not_equal_register(saturn.A, saturn.B, op2); - break; - case 5: /* ?B#C */ - saturn.CARRY = is_not_equal_register(saturn.B, saturn.C, op2); - break; - case 6: /* ?A#C */ - saturn.CARRY = is_not_equal_register(saturn.A, saturn.C, op2); - break; - case 7: /* ?C#D */ - saturn.CARRY = is_not_equal_register(saturn.C, saturn.D, op2); - break; - case 8: /* ?A=0 */ - saturn.CARRY = is_zero_register(saturn.A, op2); - break; - case 9: /* ?B=0 */ - saturn.CARRY = is_zero_register(saturn.B, op2); - break; - case 0xa: /* ?C=0 */ - saturn.CARRY = is_zero_register(saturn.C, op2); - break; - case 0xb: /* ?D=0 */ - saturn.CARRY = is_zero_register(saturn.D, op2); - break; - case 0xc: /* ?A#0 */ - saturn.CARRY = is_not_zero_register(saturn.A, op2); - break; - case 0xd: /* ?B#0 */ - saturn.CARRY = is_not_zero_register(saturn.B, op2); - break; - case 0xe: /* ?C#0 */ - saturn.CARRY = is_not_zero_register(saturn.C, op2); - break; - case 0xf: /* ?D#0 */ - saturn.CARRY = is_not_zero_register(saturn.D, op2); - break; - default: - return 1; - } - } else { - op2 &= 7; - switch (op3) { - case 0: /* ?A>B */ - saturn.CARRY = is_greater_register(saturn.A, saturn.B, op2); - break; - case 1: /* ?B>C */ - saturn.CARRY = is_greater_register(saturn.B, saturn.C, op2); - break; - case 2: /* ?C>A */ - saturn.CARRY = is_greater_register(saturn.C, saturn.A, op2); - break; - case 3: /* ?D>C */ - saturn.CARRY = is_greater_register(saturn.D, saturn.C, op2); - break; - case 4: /* ?A=B */ - saturn.CARRY = is_greater_or_equal_register(saturn.A, saturn.B, op2); - break; - case 9: /* ?B>=C */ - saturn.CARRY = is_greater_or_equal_register(saturn.B, saturn.C, op2); - break; - case 0xa: /* ?C>=A */ - saturn.CARRY = is_greater_or_equal_register(saturn.C, saturn.A, op2); - break; - case 0xb: /* ?D>=C */ - saturn.CARRY = is_greater_or_equal_register(saturn.D, saturn.C, op2); - break; - case 0xc: /* ?A<=B */ - saturn.CARRY = is_less_or_equal_register(saturn.A, saturn.B, op2); - break; - case 0xd: /* ?B<=C */ - saturn.CARRY = is_less_or_equal_register(saturn.B, saturn.C, op2); - break; - case 0xe: /* ?C<=A */ - saturn.CARRY = is_less_or_equal_register(saturn.C, saturn.A, op2); - break; - case 0xf: /* ?D<=C */ - saturn.CARRY = is_less_or_equal_register(saturn.D, saturn.C, op2); - break; - default: - return 1; - } - } + saturn.PC += 3; + clear_hardware_stat(op3); + return 0; + case 3: + op3 = read_nibble(saturn.PC + 2); + saturn.CARRY = is_zero_hardware_stat(op3); if (saturn.CARRY) { - saturn.PC += 3; + saturn.PC += 3; op4 = read_nibbles(saturn.PC, 2); if (op4) { if (op4 & 0x80) op4 |= jumpmasks[2]; jumpaddr = (saturn.PC + op4) & 0xfffff; - saturn.PC = jumpaddr; + saturn.PC = jumpaddr; } else { - saturn.PC = pop_return_addr(); + saturn.PC = pop_return_addr(); + } + } else { + saturn.PC += 5; + } + return 0; + case 4: + case 5: + op3 = read_nibble(saturn.PC + 2); + if (op2 == 4) { + saturn.PC += 3; + clear_program_stat(op3); + } else { + saturn.PC += 3; + set_program_stat(op3); + } + return 0; + case 6: + case 7: + op3 = read_nibble(saturn.PC + 2); + if (op2 == 6) + saturn.CARRY = (get_program_stat(op3) == 0) ? 1 : 0; + else + saturn.CARRY = (get_program_stat(op3) != 0) ? 1 : 0; + if (saturn.CARRY) { + saturn.PC += 3; + op4 = read_nibbles(saturn.PC, 2); + if (op4) { + if (op4 & 0x80) + op4 |= jumpmasks[2]; + jumpaddr = (saturn.PC + op4) & 0xfffff; + saturn.PC = jumpaddr; + } else { + saturn.PC = pop_return_addr(); + } + } else { + saturn.PC += 5; + } + return 0; + case 8: + case 9: + op3 = read_nibble(saturn.PC + 2); + if (op2 == 8) + saturn.CARRY = (saturn.P != op3) ? 1 : 0; + else + saturn.CARRY = (saturn.P == op3) ? 1 : 0; + if (saturn.CARRY) { + saturn.PC += 3; + op4 = read_nibbles(saturn.PC, 2); + if (op4) { + if (op4 & 0x80) + op4 |= jumpmasks[2]; + jumpaddr = (saturn.PC + op4) & 0xfffff; + saturn.PC = jumpaddr; + } else { + saturn.PC = pop_return_addr(); } } else { saturn.PC += 5; @@ -1383,566 +1088,862 @@ static inline int decode_8_thru_f(int op1) { return 0; case 0xa: op3 = read_nibble(saturn.PC + 2); - if (op2 < 8) { - switch(op3) { - case 0: /* A=A+B */ + switch (op3) { + case 0: /* ?A=B */ + saturn.CARRY = is_equal_register(saturn.A, saturn.B, A_FIELD); + break; + case 1: /* ?B=C */ + saturn.CARRY = is_equal_register(saturn.B, saturn.C, A_FIELD); + break; + case 2: /* ?A=C */ + saturn.CARRY = is_equal_register(saturn.A, saturn.C, A_FIELD); + break; + case 3: /* ?C=D */ + saturn.CARRY = is_equal_register(saturn.C, saturn.D, A_FIELD); + break; + case 4: /* ?A#B */ + saturn.CARRY = is_not_equal_register(saturn.A, saturn.B, A_FIELD); + break; + case 5: /* ?B#C */ + saturn.CARRY = is_not_equal_register(saturn.B, saturn.C, A_FIELD); + break; + case 6: /* ?A#C */ + saturn.CARRY = is_not_equal_register(saturn.A, saturn.C, A_FIELD); + break; + case 7: /* ?C#D */ + saturn.CARRY = is_not_equal_register(saturn.C, saturn.D, A_FIELD); + break; + case 8: /* ?A=0 */ + saturn.CARRY = is_zero_register(saturn.A, A_FIELD); + break; + case 9: /* ?B=0 */ + saturn.CARRY = is_zero_register(saturn.B, A_FIELD); + break; + case 0xa: /* ?C=0 */ + saturn.CARRY = is_zero_register(saturn.C, A_FIELD); + break; + case 0xb: /* ?D=0 */ + saturn.CARRY = is_zero_register(saturn.D, A_FIELD); + break; + case 0xc: /* ?A#0 */ + saturn.CARRY = is_not_zero_register(saturn.A, A_FIELD); + break; + case 0xd: /* ?B#0 */ + saturn.CARRY = is_not_zero_register(saturn.B, A_FIELD); + break; + case 0xe: /* ?C#0 */ + saturn.CARRY = is_not_zero_register(saturn.C, A_FIELD); + break; + case 0xf: /* ?D#0 */ + saturn.CARRY = is_not_zero_register(saturn.D, A_FIELD); + break; + default: + return 1; + } + if (saturn.CARRY) { + saturn.PC += 3; + op4 = read_nibbles(saturn.PC, 2); + if (op4) { + if (op4 & 0x80) + op4 |= jumpmasks[2]; + jumpaddr = (saturn.PC + op4) & 0xfffff; + saturn.PC = jumpaddr; + } else { + saturn.PC = pop_return_addr(); + } + } else { + saturn.PC += 5; + } + return 0; + case 0xb: + op3 = read_nibble(saturn.PC + 2); + switch (op3) { + case 0: /* ?A>B */ + saturn.CARRY = is_greater_register(saturn.A, saturn.B, A_FIELD); + break; + case 1: /* ?B>C */ + saturn.CARRY = is_greater_register(saturn.B, saturn.C, A_FIELD); + break; + case 2: /* ?C>A */ + saturn.CARRY = is_greater_register(saturn.C, saturn.A, A_FIELD); + break; + case 3: /* ?D>C */ + saturn.CARRY = is_greater_register(saturn.D, saturn.C, A_FIELD); + break; + case 4: /* ?A=B */ + saturn.CARRY = + is_greater_or_equal_register(saturn.A, saturn.B, A_FIELD); + break; + case 9: /* ?B>=C */ + saturn.CARRY = + is_greater_or_equal_register(saturn.B, saturn.C, A_FIELD); + break; + case 0xa: /* ?C>=A */ + saturn.CARRY = + is_greater_or_equal_register(saturn.C, saturn.A, A_FIELD); + break; + case 0xb: /* ?D>=C */ + saturn.CARRY = + is_greater_or_equal_register(saturn.D, saturn.C, A_FIELD); + break; + case 0xc: /* ?A<=B */ + saturn.CARRY = is_less_or_equal_register(saturn.A, saturn.B, A_FIELD); + break; + case 0xd: /* ?B<=C */ + saturn.CARRY = is_less_or_equal_register(saturn.B, saturn.C, A_FIELD); + break; + case 0xe: /* ?C<=A */ + saturn.CARRY = is_less_or_equal_register(saturn.C, saturn.A, A_FIELD); + break; + case 0xf: /* ?D<=C */ + saturn.CARRY = is_less_or_equal_register(saturn.D, saturn.C, A_FIELD); + break; + default: + return 1; + } + if (saturn.CARRY) { + saturn.PC += 3; + op4 = read_nibbles(saturn.PC, 2); + if (op4) { + if (op4 & 0x80) + op4 |= jumpmasks[2]; + jumpaddr = (saturn.PC + op4) & 0xfffff; + saturn.PC = jumpaddr; + } else { + saturn.PC = pop_return_addr(); + } + } else { + saturn.PC += 5; + } + return 0; + case 0xc: + op3 = read_nibbles(saturn.PC + 2, 4); + if (op3 & 0x8000) + op3 |= jumpmasks[4]; + jumpaddr = (saturn.PC + op3 + 2) & 0xfffff; + saturn.PC = jumpaddr; + return 0; + case 0xd: + op3 = read_nibbles(saturn.PC + 2, 5); + jumpaddr = op3; + saturn.PC = jumpaddr; + return 0; + case 0xe: + op3 = read_nibbles(saturn.PC + 2, 4); + if (op3 & 0x8000) + op3 |= jumpmasks[4]; + jumpaddr = (saturn.PC + op3 + 6) & 0xfffff; + push_return_addr(saturn.PC + 6); + saturn.PC = jumpaddr; + return 0; + case 0xf: + op3 = read_nibbles(saturn.PC + 2, 5); + jumpaddr = op3; + push_return_addr(saturn.PC + 7); + saturn.PC = jumpaddr; + return 0; + default: + return 1; + } + case 9: + op3 = read_nibble(saturn.PC + 2); + if (op2 < 8) { + switch (op3) { + case 0: /* ?A=B */ + saturn.CARRY = is_equal_register(saturn.A, saturn.B, op2); + break; + case 1: /* ?B=C */ + saturn.CARRY = is_equal_register(saturn.B, saturn.C, op2); + break; + case 2: /* ?A=C */ + saturn.CARRY = is_equal_register(saturn.A, saturn.C, op2); + break; + case 3: /* ?C=D */ + saturn.CARRY = is_equal_register(saturn.C, saturn.D, op2); + break; + case 4: /* ?A#B */ + saturn.CARRY = is_not_equal_register(saturn.A, saturn.B, op2); + break; + case 5: /* ?B#C */ + saturn.CARRY = is_not_equal_register(saturn.B, saturn.C, op2); + break; + case 6: /* ?A#C */ + saturn.CARRY = is_not_equal_register(saturn.A, saturn.C, op2); + break; + case 7: /* ?C#D */ + saturn.CARRY = is_not_equal_register(saturn.C, saturn.D, op2); + break; + case 8: /* ?A=0 */ + saturn.CARRY = is_zero_register(saturn.A, op2); + break; + case 9: /* ?B=0 */ + saturn.CARRY = is_zero_register(saturn.B, op2); + break; + case 0xa: /* ?C=0 */ + saturn.CARRY = is_zero_register(saturn.C, op2); + break; + case 0xb: /* ?D=0 */ + saturn.CARRY = is_zero_register(saturn.D, op2); + break; + case 0xc: /* ?A#0 */ + saturn.CARRY = is_not_zero_register(saturn.A, op2); + break; + case 0xd: /* ?B#0 */ + saturn.CARRY = is_not_zero_register(saturn.B, op2); + break; + case 0xe: /* ?C#0 */ + saturn.CARRY = is_not_zero_register(saturn.C, op2); + break; + case 0xf: /* ?D#0 */ + saturn.CARRY = is_not_zero_register(saturn.D, op2); + break; + default: + return 1; + } + } else { + op2 &= 7; + switch (op3) { + case 0: /* ?A>B */ + saturn.CARRY = is_greater_register(saturn.A, saturn.B, op2); + break; + case 1: /* ?B>C */ + saturn.CARRY = is_greater_register(saturn.B, saturn.C, op2); + break; + case 2: /* ?C>A */ + saturn.CARRY = is_greater_register(saturn.C, saturn.A, op2); + break; + case 3: /* ?D>C */ + saturn.CARRY = is_greater_register(saturn.D, saturn.C, op2); + break; + case 4: /* ?A=B */ + saturn.CARRY = is_greater_or_equal_register(saturn.A, saturn.B, op2); + break; + case 9: /* ?B>=C */ + saturn.CARRY = is_greater_or_equal_register(saturn.B, saturn.C, op2); + break; + case 0xa: /* ?C>=A */ + saturn.CARRY = is_greater_or_equal_register(saturn.C, saturn.A, op2); + break; + case 0xb: /* ?D>=C */ + saturn.CARRY = is_greater_or_equal_register(saturn.D, saturn.C, op2); + break; + case 0xc: /* ?A<=B */ + saturn.CARRY = is_less_or_equal_register(saturn.A, saturn.B, op2); + break; + case 0xd: /* ?B<=C */ + saturn.CARRY = is_less_or_equal_register(saturn.B, saturn.C, op2); + break; + case 0xe: /* ?C<=A */ + saturn.CARRY = is_less_or_equal_register(saturn.C, saturn.A, op2); + break; + case 0xf: /* ?D<=C */ + saturn.CARRY = is_less_or_equal_register(saturn.D, saturn.C, op2); + break; + default: + return 1; + } + } + if (saturn.CARRY) { + saturn.PC += 3; + op4 = read_nibbles(saturn.PC, 2); + if (op4) { + if (op4 & 0x80) + op4 |= jumpmasks[2]; + jumpaddr = (saturn.PC + op4) & 0xfffff; + saturn.PC = jumpaddr; + } else { + saturn.PC = pop_return_addr(); + } + } else { + saturn.PC += 5; + } + return 0; + case 0xa: + op3 = read_nibble(saturn.PC + 2); + if (op2 < 8) { + switch (op3) { + case 0: /* A=A+B */ saturn.PC += 3; add_register(saturn.A, saturn.A, saturn.B, op2); return 0; - case 1: /* B=B+C */ + case 1: /* B=B+C */ saturn.PC += 3; add_register(saturn.B, saturn.B, saturn.C, op2); return 0; - case 2: /* C=C+A */ + case 2: /* C=C+A */ saturn.PC += 3; add_register(saturn.C, saturn.C, saturn.A, op2); return 0; - case 3: /* D=D+C */ + case 3: /* D=D+C */ saturn.PC += 3; add_register(saturn.D, saturn.D, saturn.C, op2); return 0; - case 4: /* A=A+A */ + case 4: /* A=A+A */ saturn.PC += 3; add_register(saturn.A, saturn.A, saturn.A, op2); return 0; - case 5: /* B=B+B */ + case 5: /* B=B+B */ saturn.PC += 3; add_register(saturn.B, saturn.B, saturn.B, op2); return 0; - case 6: /* C=C+C */ + case 6: /* C=C+C */ saturn.PC += 3; add_register(saturn.C, saturn.C, saturn.C, op2); return 0; - case 7: /* D=D+D */ + case 7: /* D=D+D */ saturn.PC += 3; add_register(saturn.D, saturn.D, saturn.D, op2); return 0; - case 8: /* B=B+A */ + case 8: /* B=B+A */ saturn.PC += 3; add_register(saturn.B, saturn.B, saturn.A, op2); return 0; - case 9: /* C=C+B */ + case 9: /* C=C+B */ saturn.PC += 3; add_register(saturn.C, saturn.C, saturn.B, op2); return 0; - case 0xa: /* A=A+C */ + case 0xa: /* A=A+C */ saturn.PC += 3; add_register(saturn.A, saturn.A, saturn.C, op2); return 0; - case 0xb: /* C=C+D */ + case 0xb: /* C=C+D */ saturn.PC += 3; add_register(saturn.C, saturn.C, saturn.D, op2); return 0; - case 0xc: /* A=A-1 */ + case 0xc: /* A=A-1 */ saturn.PC += 3; dec_register(saturn.A, op2); return 0; - case 0xd: /* B=B-1 */ + case 0xd: /* B=B-1 */ saturn.PC += 3; dec_register(saturn.B, op2); return 0; - case 0xe: /* C=C-1 */ + case 0xe: /* C=C-1 */ saturn.PC += 3; dec_register(saturn.C, op2); return 0; - case 0xf: /* D=D-1 */ + case 0xf: /* D=D-1 */ saturn.PC += 3; dec_register(saturn.D, op2); return 0; default: return 1; - } - } else { - op2 &= 7; - switch(op3) { - case 0: /* A=0 */ + } + } else { + op2 &= 7; + switch (op3) { + case 0: /* A=0 */ saturn.PC += 3; zero_register(saturn.A, op2); return 0; - case 1: /* B=0 */ + case 1: /* B=0 */ saturn.PC += 3; zero_register(saturn.B, op2); return 0; - case 2: /* C=0 */ + case 2: /* C=0 */ saturn.PC += 3; zero_register(saturn.C, op2); return 0; - case 3: /* D=0 */ + case 3: /* D=0 */ saturn.PC += 3; zero_register(saturn.D, op2); return 0; - case 4: /* A=B */ + case 4: /* A=B */ saturn.PC += 3; copy_register(saturn.A, saturn.B, op2); return 0; - case 5: /* B=C */ + case 5: /* B=C */ saturn.PC += 3; copy_register(saturn.B, saturn.C, op2); return 0; - case 6: /* C=A */ + case 6: /* C=A */ saturn.PC += 3; copy_register(saturn.C, saturn.A, op2); return 0; - case 7: /* D=C */ + case 7: /* D=C */ saturn.PC += 3; copy_register(saturn.D, saturn.C, op2); return 0; - case 8: /* B=A */ + case 8: /* B=A */ saturn.PC += 3; copy_register(saturn.B, saturn.A, op2); return 0; - case 9: /* C=B */ + case 9: /* C=B */ saturn.PC += 3; copy_register(saturn.C, saturn.B, op2); return 0; - case 0xa: /* A=C */ + case 0xa: /* A=C */ saturn.PC += 3; copy_register(saturn.A, saturn.C, op2); return 0; - case 0xb: /* C=D */ + case 0xb: /* C=D */ saturn.PC += 3; copy_register(saturn.C, saturn.D, op2); return 0; - case 0xc: /* ABEX */ + case 0xc: /* ABEX */ saturn.PC += 3; exchange_register(saturn.A, saturn.B, op2); return 0; - case 0xd: /* BCEX */ + case 0xd: /* BCEX */ saturn.PC += 3; exchange_register(saturn.B, saturn.C, op2); return 0; - case 0xe: /* ACEX */ + case 0xe: /* ACEX */ saturn.PC += 3; exchange_register(saturn.A, saturn.C, op2); return 0; - case 0xf: /* CDEX */ + case 0xf: /* CDEX */ saturn.PC += 3; exchange_register(saturn.C, saturn.D, op2); return 0; default: return 1; + } } - } - case 0xb: - op3 = read_nibble(saturn.PC + 2); - if (op2 < 8) { - switch (op3) { - case 0: /* A=A-B */ - saturn.PC += 3; - sub_register(saturn.A, saturn.A, saturn.B, op2); - return 0; - case 1: /* B=B-C */ - saturn.PC += 3; - sub_register(saturn.B, saturn.B, saturn.C, op2); - return 0; - case 2: /* C=C-A */ - saturn.PC += 3; - sub_register(saturn.C, saturn.C, saturn.A, op2); - return 0; - case 3: /* D=D-C */ - saturn.PC += 3; - sub_register(saturn.D, saturn.D, saturn.C, op2); - return 0; - case 4: /* A=A+1 */ - saturn.PC += 3; + case 0xb: + op3 = read_nibble(saturn.PC + 2); + if (op2 < 8) { + switch (op3) { + case 0: /* A=A-B */ + saturn.PC += 3; + sub_register(saturn.A, saturn.A, saturn.B, op2); + return 0; + case 1: /* B=B-C */ + saturn.PC += 3; + sub_register(saturn.B, saturn.B, saturn.C, op2); + return 0; + case 2: /* C=C-A */ + saturn.PC += 3; + sub_register(saturn.C, saturn.C, saturn.A, op2); + return 0; + case 3: /* D=D-C */ + saturn.PC += 3; + sub_register(saturn.D, saturn.D, saturn.C, op2); + return 0; + case 4: /* A=A+1 */ + saturn.PC += 3; inc_register(saturn.A, op2); - return 0; - case 5: /* B=B+1 */ - saturn.PC += 3; + return 0; + case 5: /* B=B+1 */ + saturn.PC += 3; inc_register(saturn.B, op2); - return 0; - case 6: /* C=C+1 */ - saturn.PC += 3; + return 0; + case 6: /* C=C+1 */ + saturn.PC += 3; inc_register(saturn.C, op2); - return 0; - case 7: /* D=D+1 */ - saturn.PC += 3; + return 0; + case 7: /* D=D+1 */ + saturn.PC += 3; inc_register(saturn.D, op2); - return 0; - case 8: /* B=B-A */ - saturn.PC += 3; - sub_register(saturn.B, saturn.B, saturn.A, op2); - return 0; - case 9: /* C=C-B */ - saturn.PC += 3; - sub_register(saturn.C, saturn.C, saturn.B, op2); - return 0; - case 0xa: /* A=A-C */ - saturn.PC += 3; - sub_register(saturn.A, saturn.A, saturn.C, op2); - return 0; - case 0xb: /* C=C-D */ - saturn.PC += 3; - sub_register(saturn.C, saturn.C, saturn.D, op2); - return 0; - case 0xc: /* A=B-A */ - saturn.PC += 3; - sub_register(saturn.A, saturn.B, saturn.A, op2); - return 0; - case 0xd: /* B=C-B */ - saturn.PC += 3; - sub_register(saturn.B, saturn.C, saturn.B, op2); - return 0; - case 0xe: /* C=A-C */ - saturn.PC += 3; - sub_register(saturn.C, saturn.A, saturn.C, op2); - return 0; - case 0xf: /* D=C-D */ - saturn.PC += 3; - sub_register(saturn.D, saturn.C, saturn.D, op2); - return 0; - default: - return 1; - } - } else { - op2 &= 7; - switch (op3) { - case 0: /* ASL */ - saturn.PC += 3; - shift_left_register(saturn.A, op2); - return 0; - case 1: /* BSL */ - saturn.PC += 3; - shift_left_register(saturn.B, op2); - return 0; - case 2: /* CSL */ - saturn.PC += 3; - shift_left_register(saturn.C, op2); - return 0; - case 3: /* DSL */ - saturn.PC += 3; - shift_left_register(saturn.D, op2); - return 0; - case 4: /* ASR */ - saturn.PC += 3; - shift_right_register(saturn.A, op2); - return 0; - case 5: /* BSR */ - saturn.PC += 3; - shift_right_register(saturn.B, op2); - return 0; - case 6: /* CSR */ - saturn.PC += 3; - shift_right_register(saturn.C, op2); - return 0; - case 7: /* DSR */ - saturn.PC += 3; - shift_right_register(saturn.D, op2); - return 0; - case 8: /* A=-A */ - saturn.PC += 3; - complement_2_register(saturn.A, op2); - return 0; - case 9: /* B=-B */ - saturn.PC += 3; - complement_2_register(saturn.B, op2); - return 0; - case 0xa: /* C=-C */ - saturn.PC += 3; - complement_2_register(saturn.C, op2); - return 0; - case 0xb: /* D=-D */ - saturn.PC += 3; - complement_2_register(saturn.D, op2); - return 0; - case 0xc: /* A=-A-1 */ - saturn.PC += 3; - complement_1_register(saturn.A, op2); - return 0; - case 0xd: /* B=-B-1 */ - saturn.PC += 3; - complement_1_register(saturn.B, op2); - return 0; - case 0xe: /* C=-C-1 */ - saturn.PC += 3; - complement_1_register(saturn.C, op2); - return 0; - case 0xf: /* D=-D-1 */ - saturn.PC += 3; - complement_1_register(saturn.D, op2); - return 0; - default: - return 1; - } + return 0; + case 8: /* B=B-A */ + saturn.PC += 3; + sub_register(saturn.B, saturn.B, saturn.A, op2); + return 0; + case 9: /* C=C-B */ + saturn.PC += 3; + sub_register(saturn.C, saturn.C, saturn.B, op2); + return 0; + case 0xa: /* A=A-C */ + saturn.PC += 3; + sub_register(saturn.A, saturn.A, saturn.C, op2); + return 0; + case 0xb: /* C=C-D */ + saturn.PC += 3; + sub_register(saturn.C, saturn.C, saturn.D, op2); + return 0; + case 0xc: /* A=B-A */ + saturn.PC += 3; + sub_register(saturn.A, saturn.B, saturn.A, op2); + return 0; + case 0xd: /* B=C-B */ + saturn.PC += 3; + sub_register(saturn.B, saturn.C, saturn.B, op2); + return 0; + case 0xe: /* C=A-C */ + saturn.PC += 3; + sub_register(saturn.C, saturn.A, saturn.C, op2); + return 0; + case 0xf: /* D=C-D */ + saturn.PC += 3; + sub_register(saturn.D, saturn.C, saturn.D, op2); + return 0; + default: + return 1; } - case 0xc: - switch(op2) { - case 0: /* A=A+B */ + } else { + op2 &= 7; + switch (op3) { + case 0: /* ASL */ + saturn.PC += 3; + shift_left_register(saturn.A, op2); + return 0; + case 1: /* BSL */ + saturn.PC += 3; + shift_left_register(saturn.B, op2); + return 0; + case 2: /* CSL */ + saturn.PC += 3; + shift_left_register(saturn.C, op2); + return 0; + case 3: /* DSL */ + saturn.PC += 3; + shift_left_register(saturn.D, op2); + return 0; + case 4: /* ASR */ + saturn.PC += 3; + shift_right_register(saturn.A, op2); + return 0; + case 5: /* BSR */ + saturn.PC += 3; + shift_right_register(saturn.B, op2); + return 0; + case 6: /* CSR */ + saturn.PC += 3; + shift_right_register(saturn.C, op2); + return 0; + case 7: /* DSR */ + saturn.PC += 3; + shift_right_register(saturn.D, op2); + return 0; + case 8: /* A=-A */ + saturn.PC += 3; + complement_2_register(saturn.A, op2); + return 0; + case 9: /* B=-B */ + saturn.PC += 3; + complement_2_register(saturn.B, op2); + return 0; + case 0xa: /* C=-C */ + saturn.PC += 3; + complement_2_register(saturn.C, op2); + return 0; + case 0xb: /* D=-D */ + saturn.PC += 3; + complement_2_register(saturn.D, op2); + return 0; + case 0xc: /* A=-A-1 */ + saturn.PC += 3; + complement_1_register(saturn.A, op2); + return 0; + case 0xd: /* B=-B-1 */ + saturn.PC += 3; + complement_1_register(saturn.B, op2); + return 0; + case 0xe: /* C=-C-1 */ + saturn.PC += 3; + complement_1_register(saturn.C, op2); + return 0; + case 0xf: /* D=-D-1 */ + saturn.PC += 3; + complement_1_register(saturn.D, op2); + return 0; + default: + return 1; + } + } + case 0xc: + switch (op2) { + case 0: /* A=A+B */ saturn.PC += 2; add_register(saturn.A, saturn.A, saturn.B, A_FIELD); - return 0; - case 1: /* B=B+C */ + return 0; + case 1: /* B=B+C */ saturn.PC += 2; add_register(saturn.B, saturn.B, saturn.C, A_FIELD); - return 0; - case 2: /* C=C+A */ + return 0; + case 2: /* C=C+A */ saturn.PC += 2; add_register(saturn.C, saturn.C, saturn.A, A_FIELD); - return 0; - case 3: /* D=D+C */ + return 0; + case 3: /* D=D+C */ saturn.PC += 2; add_register(saturn.D, saturn.D, saturn.C, A_FIELD); - return 0; - case 4: /* A=A+A */ + return 0; + case 4: /* A=A+A */ saturn.PC += 2; add_register(saturn.A, saturn.A, saturn.A, A_FIELD); - return 0; - case 5: /* B=B+B */ + return 0; + case 5: /* B=B+B */ saturn.PC += 2; add_register(saturn.B, saturn.B, saturn.B, A_FIELD); - return 0; - case 6: /* C=C+C */ + return 0; + case 6: /* C=C+C */ saturn.PC += 2; add_register(saturn.C, saturn.C, saturn.C, A_FIELD); - return 0; - case 7: /* D=D+D */ + return 0; + case 7: /* D=D+D */ saturn.PC += 2; add_register(saturn.D, saturn.D, saturn.D, A_FIELD); - return 0; - case 8: /* B=B+A */ + return 0; + case 8: /* B=B+A */ saturn.PC += 2; add_register(saturn.B, saturn.B, saturn.A, A_FIELD); - return 0; - case 9: /* C=C+B */ + return 0; + case 9: /* C=C+B */ saturn.PC += 2; add_register(saturn.C, saturn.C, saturn.B, A_FIELD); - return 0; - case 0xa: /* A=A+C */ + return 0; + case 0xa: /* A=A+C */ saturn.PC += 2; add_register(saturn.A, saturn.A, saturn.C, A_FIELD); - return 0; - case 0xb: /* C=C+D */ + return 0; + case 0xb: /* C=C+D */ saturn.PC += 2; add_register(saturn.C, saturn.C, saturn.D, A_FIELD); - return 0; - case 0xc: /* A=A-1 */ + return 0; + case 0xc: /* A=A-1 */ saturn.PC += 2; dec_register(saturn.A, A_FIELD); return 0; - case 0xd: /* B=B-1 */ + case 0xd: /* B=B-1 */ saturn.PC += 2; dec_register(saturn.B, A_FIELD); return 0; - case 0xe: /* C=C-1 */ + case 0xe: /* C=C-1 */ saturn.PC += 2; dec_register(saturn.C, A_FIELD); return 0; - case 0xf: /* D=D-1 */ + case 0xf: /* D=D-1 */ saturn.PC += 2; dec_register(saturn.D, A_FIELD); return 0; - default: - return 1; - } - case 0xd: - switch(op2) { - case 0: /* A=0 */ + default: + return 1; + } + case 0xd: + switch (op2) { + case 0: /* A=0 */ saturn.PC += 2; zero_register(saturn.A, A_FIELD); return 0; - case 1: /* B=0 */ + case 1: /* B=0 */ saturn.PC += 2; zero_register(saturn.B, A_FIELD); return 0; - case 2: /* C=0 */ + case 2: /* C=0 */ saturn.PC += 2; zero_register(saturn.C, A_FIELD); return 0; - case 3: /* D=0 */ + case 3: /* D=0 */ saturn.PC += 2; zero_register(saturn.D, A_FIELD); return 0; - case 4: /* A=B */ + case 4: /* A=B */ saturn.PC += 2; copy_register(saturn.A, saturn.B, A_FIELD); return 0; - case 5: /* B=C */ + case 5: /* B=C */ saturn.PC += 2; copy_register(saturn.B, saturn.C, A_FIELD); return 0; - case 6: /* C=A */ + case 6: /* C=A */ saturn.PC += 2; copy_register(saturn.C, saturn.A, A_FIELD); return 0; - case 7: /* D=C */ + case 7: /* D=C */ saturn.PC += 2; copy_register(saturn.D, saturn.C, A_FIELD); return 0; - case 8: /* B=A */ + case 8: /* B=A */ saturn.PC += 2; copy_register(saturn.B, saturn.A, A_FIELD); return 0; - case 9: /* C=B */ + case 9: /* C=B */ saturn.PC += 2; copy_register(saturn.C, saturn.B, A_FIELD); return 0; - case 0xa: /* A=C */ + case 0xa: /* A=C */ saturn.PC += 2; copy_register(saturn.A, saturn.C, A_FIELD); return 0; - case 0xb: /* C=D */ + case 0xb: /* C=D */ saturn.PC += 2; copy_register(saturn.C, saturn.D, A_FIELD); return 0; - case 0xc: /* ABEX */ + case 0xc: /* ABEX */ saturn.PC += 2; exchange_register(saturn.A, saturn.B, A_FIELD); return 0; - case 0xd: /* BCEX */ + case 0xd: /* BCEX */ saturn.PC += 2; exchange_register(saturn.B, saturn.C, A_FIELD); return 0; - case 0xe: /* ACEX */ + case 0xe: /* ACEX */ saturn.PC += 2; exchange_register(saturn.A, saturn.C, A_FIELD); return 0; - case 0xf: /* CDEX */ + case 0xf: /* CDEX */ saturn.PC += 2; exchange_register(saturn.C, saturn.D, A_FIELD); return 0; default: return 1; - } - case 0xe: - switch (op2) { - case 0: /* A=A-B */ - saturn.PC += 2; - sub_register(saturn.A, saturn.A, saturn.B, A_FIELD); - return 0; - case 1: /* B=B-C */ - saturn.PC += 2; - sub_register(saturn.B, saturn.B, saturn.C, A_FIELD); - return 0; - case 2: /* C=C-A */ - saturn.PC += 2; - sub_register(saturn.C, saturn.C, saturn.A, A_FIELD); - return 0; - case 3: /* D=D-C */ - saturn.PC += 2; - sub_register(saturn.D, saturn.D, saturn.C, A_FIELD); - return 0; - case 4: /* A=A+1 */ - saturn.PC += 2; + } + case 0xe: + switch (op2) { + case 0: /* A=A-B */ + saturn.PC += 2; + sub_register(saturn.A, saturn.A, saturn.B, A_FIELD); + return 0; + case 1: /* B=B-C */ + saturn.PC += 2; + sub_register(saturn.B, saturn.B, saturn.C, A_FIELD); + return 0; + case 2: /* C=C-A */ + saturn.PC += 2; + sub_register(saturn.C, saturn.C, saturn.A, A_FIELD); + return 0; + case 3: /* D=D-C */ + saturn.PC += 2; + sub_register(saturn.D, saturn.D, saturn.C, A_FIELD); + return 0; + case 4: /* A=A+1 */ + saturn.PC += 2; inc_register(saturn.A, A_FIELD); - return 0; - case 5: /* B=B+1 */ - saturn.PC += 2; + return 0; + case 5: /* B=B+1 */ + saturn.PC += 2; inc_register(saturn.B, A_FIELD); - return 0; - case 6: /* C=C+1 */ - saturn.PC += 2; + return 0; + case 6: /* C=C+1 */ + saturn.PC += 2; inc_register(saturn.C, A_FIELD); - return 0; - case 7: /* D=D+1 */ - saturn.PC += 2; + return 0; + case 7: /* D=D+1 */ + saturn.PC += 2; inc_register(saturn.D, A_FIELD); - return 0; - case 8: /* B=B-A */ - saturn.PC += 2; - sub_register(saturn.B, saturn.B, saturn.A, A_FIELD); - return 0; - case 9: /* C=C-B */ - saturn.PC += 2; - sub_register(saturn.C, saturn.C, saturn.B, A_FIELD); - return 0; - case 0xa: /* A=A-C */ - saturn.PC += 2; - sub_register(saturn.A, saturn.A, saturn.C, A_FIELD); - return 0; - case 0xb: /* C=C-D */ - saturn.PC += 2; - sub_register(saturn.C, saturn.C, saturn.D, A_FIELD); - return 0; - case 0xc: /* A=B-A */ - saturn.PC += 2; - sub_register(saturn.A, saturn.B, saturn.A, A_FIELD); - return 0; - case 0xd: /* B=C-B */ - saturn.PC += 2; - sub_register(saturn.B, saturn.C, saturn.B, A_FIELD); - return 0; - case 0xe: /* C=A-C */ - saturn.PC += 2; - sub_register(saturn.C, saturn.A, saturn.C, A_FIELD); - return 0; - case 0xf: /* D=C-D */ - saturn.PC += 2; - sub_register(saturn.D, saturn.C, saturn.D, A_FIELD); - return 0; - default: - return 1; - } - case 0xf: - switch (op2) { - case 0: /* ASL */ - saturn.PC += 2; - shift_left_register(saturn.A, A_FIELD); - return 0; - case 1: /* BSL */ - saturn.PC += 2; - shift_left_register(saturn.B, A_FIELD); - return 0; - case 2: /* CSL */ - saturn.PC += 2; - shift_left_register(saturn.C, A_FIELD); - return 0; - case 3: /* DSL */ - saturn.PC += 2; - shift_left_register(saturn.D, A_FIELD); - return 0; - case 4: /* ASR */ - saturn.PC += 2; - shift_right_register(saturn.A, A_FIELD); - return 0; - case 5: /* BSR */ - saturn.PC += 2; - shift_right_register(saturn.B, A_FIELD); - return 0; - case 6: /* CSR */ - saturn.PC += 2; - shift_right_register(saturn.C, A_FIELD); - return 0; - case 7: /* DSR */ - saturn.PC += 2; - shift_right_register(saturn.D, A_FIELD); - return 0; - case 8: /* A=-A */ - saturn.PC += 2; - complement_2_register(saturn.A, A_FIELD); - return 0; - case 9: /* B=-B */ - saturn.PC += 2; - complement_2_register(saturn.B, A_FIELD); - return 0; - case 0xa: /* C=-C */ - saturn.PC += 2; - complement_2_register(saturn.C, A_FIELD); - return 0; - case 0xb: /* D=-D */ - saturn.PC += 2; - complement_2_register(saturn.D, A_FIELD); - return 0; - case 0xc: /* A=-A-1 */ - saturn.PC += 2; - complement_1_register(saturn.A, A_FIELD); - return 0; - case 0xd: /* B=-B-1 */ - saturn.PC += 2; - complement_1_register(saturn.B, A_FIELD); - return 0; - case 0xe: /* C=-C-1 */ - saturn.PC += 2; - complement_1_register(saturn.C, A_FIELD); - return 0; - case 0xf: /* D=-D-1 */ - saturn.PC += 2; - complement_1_register(saturn.D, A_FIELD); - return 0; - default: - return 1; - } + return 0; + case 8: /* B=B-A */ + saturn.PC += 2; + sub_register(saturn.B, saturn.B, saturn.A, A_FIELD); + return 0; + case 9: /* C=C-B */ + saturn.PC += 2; + sub_register(saturn.C, saturn.C, saturn.B, A_FIELD); + return 0; + case 0xa: /* A=A-C */ + saturn.PC += 2; + sub_register(saturn.A, saturn.A, saturn.C, A_FIELD); + return 0; + case 0xb: /* C=C-D */ + saturn.PC += 2; + sub_register(saturn.C, saturn.C, saturn.D, A_FIELD); + return 0; + case 0xc: /* A=B-A */ + saturn.PC += 2; + sub_register(saturn.A, saturn.B, saturn.A, A_FIELD); + return 0; + case 0xd: /* B=C-B */ + saturn.PC += 2; + sub_register(saturn.B, saturn.C, saturn.B, A_FIELD); + return 0; + case 0xe: /* C=A-C */ + saturn.PC += 2; + sub_register(saturn.C, saturn.A, saturn.C, A_FIELD); + return 0; + case 0xf: /* D=C-D */ + saturn.PC += 2; + sub_register(saturn.D, saturn.C, saturn.D, A_FIELD); + return 0; default: return 1; + } + case 0xf: + switch (op2) { + case 0: /* ASL */ + saturn.PC += 2; + shift_left_register(saturn.A, A_FIELD); + return 0; + case 1: /* BSL */ + saturn.PC += 2; + shift_left_register(saturn.B, A_FIELD); + return 0; + case 2: /* CSL */ + saturn.PC += 2; + shift_left_register(saturn.C, A_FIELD); + return 0; + case 3: /* DSL */ + saturn.PC += 2; + shift_left_register(saturn.D, A_FIELD); + return 0; + case 4: /* ASR */ + saturn.PC += 2; + shift_right_register(saturn.A, A_FIELD); + return 0; + case 5: /* BSR */ + saturn.PC += 2; + shift_right_register(saturn.B, A_FIELD); + return 0; + case 6: /* CSR */ + saturn.PC += 2; + shift_right_register(saturn.C, A_FIELD); + return 0; + case 7: /* DSR */ + saturn.PC += 2; + shift_right_register(saturn.D, A_FIELD); + return 0; + case 8: /* A=-A */ + saturn.PC += 2; + complement_2_register(saturn.A, A_FIELD); + return 0; + case 9: /* B=-B */ + saturn.PC += 2; + complement_2_register(saturn.B, A_FIELD); + return 0; + case 0xa: /* C=-C */ + saturn.PC += 2; + complement_2_register(saturn.C, A_FIELD); + return 0; + case 0xb: /* D=-D */ + saturn.PC += 2; + complement_2_register(saturn.D, A_FIELD); + return 0; + case 0xc: /* A=-A-1 */ + saturn.PC += 2; + complement_1_register(saturn.A, A_FIELD); + return 0; + case 0xd: /* B=-B-1 */ + saturn.PC += 2; + complement_1_register(saturn.B, A_FIELD); + return 0; + case 0xe: /* C=-C-1 */ + saturn.PC += 2; + complement_1_register(saturn.C, A_FIELD); + return 0; + case 0xf: /* D=-D-1 */ + saturn.PC += 2; + complement_1_register(saturn.D, A_FIELD); + return 0; + default: + return 1; + } + default: + return 1; } } @@ -1954,233 +1955,233 @@ inline int step_instruction(void) { op0 = read_nibble(saturn.PC); switch (op0) { - case 0: - op1 = read_nibble(saturn.PC + 1); - switch (op1) { - case 0: /* RTNSXM */ - saturn.XM = 1; + case 0: + op1 = read_nibble(saturn.PC + 1); + switch (op1) { + case 0: /* RTNSXM */ + saturn.XM = 1; saturn.PC = pop_return_addr(); break; - case 1: /* RTN */ + case 1: /* RTN */ saturn.PC = pop_return_addr(); break; - case 2: /* RTNSC */ + case 2: /* RTNSC */ saturn.CARRY = 1; saturn.PC = pop_return_addr(); break; - case 3: /* RTNCC */ + case 3: /* RTNCC */ saturn.CARRY = 0; saturn.PC = pop_return_addr(); break; - case 4: /* SETHEX */ + case 4: /* SETHEX */ saturn.PC += 2; saturn.hexmode = HEX; break; - case 5: /* SETDEC */ + case 5: /* SETDEC */ saturn.PC += 2; saturn.hexmode = DEC; break; - case 6: /* RSTK=C */ - jumpaddr = dat_to_addr(saturn.C); - push_return_addr(jumpaddr); - saturn.PC += 2; + case 6: /* RSTK=C */ + jumpaddr = dat_to_addr(saturn.C); + push_return_addr(jumpaddr); + saturn.PC += 2; break; - case 7: /* C=RSTK */ - saturn.PC += 2; + case 7: /* C=RSTK */ + saturn.PC += 2; jumpaddr = pop_return_addr(); - addr_to_dat(jumpaddr, saturn.C); + addr_to_dat(jumpaddr, saturn.C); break; - case 8: /* CLRST */ - saturn.PC += 2; - clear_status(); - break; - case 9: /* C=ST */ - saturn.PC += 2; - status_to_register(saturn.C); - break; - case 0xa: /* ST=C */ - saturn.PC += 2; - register_to_status(saturn.C); - break; - case 0xb: /* CSTEX */ - saturn.PC += 2; - swap_register_status(saturn.C); - break; - case 0xc: /* P=P+1 */ + case 8: /* CLRST */ saturn.PC += 2; - if (saturn.P == 0xf) { - saturn.P = 0; - saturn.CARRY = 1; - } else { - saturn.P += 1; - saturn.CARRY = 0; - } + clear_status(); break; - case 0xd: /* P=P-1 */ + case 9: /* C=ST */ saturn.PC += 2; - if (saturn.P == 0) { - saturn.P = 0xf; - saturn.CARRY = 1; - } else { - saturn.P -= 1; - saturn.CARRY = 0; - } + status_to_register(saturn.C); break; - case 0xe: - op2 = read_nibble(saturn.PC + 2); - op3 = read_nibble(saturn.PC + 3); - switch(op3) { - case 0: /* A=A&B */ - saturn.PC += 4; - and_register(saturn.A, saturn.A, saturn.B, op2); - break; - case 1: /* B=B&C */ - saturn.PC += 4; - and_register(saturn.B, saturn.B, saturn.C, op2); - break; - case 2: /* C=C&A */ - saturn.PC += 4; - and_register(saturn.C, saturn.C, saturn.A, op2); - break; - case 3: /* D=D&C */ - saturn.PC += 4; - and_register(saturn.D, saturn.D, saturn.C, op2); - break; - case 4: /* B=B&A */ - saturn.PC += 4; - and_register(saturn.B, saturn.B, saturn.A, op2); - break; - case 5: /* C=C&B */ - saturn.PC += 4; - and_register(saturn.C, saturn.C, saturn.B, op2); - break; - case 6: /* A=A&C */ - saturn.PC += 4; - and_register(saturn.A, saturn.A, saturn.C, op2); - break; - case 7: /* C=C&D */ - saturn.PC += 4; - and_register(saturn.C, saturn.C, saturn.D, op2); - break; - case 8: /* A=A!B */ - saturn.PC += 4; - or_register(saturn.A, saturn.A, saturn.B, op2); - break; - case 9: /* B=B!C */ - saturn.PC += 4; - or_register(saturn.B, saturn.B, saturn.C, op2); - break; - case 0xa: /* C=C!A */ - saturn.PC += 4; - or_register(saturn.C, saturn.C, saturn.A, op2); - break; - case 0xb: /* D=D!C */ - saturn.PC += 4; - or_register(saturn.D, saturn.D, saturn.C, op2); - break; - case 0xc: /* B=B!A */ - saturn.PC += 4; - or_register(saturn.B, saturn.B, saturn.A, op2); - break; - case 0xd: /* C=C!B */ - saturn.PC += 4; - or_register(saturn.C, saturn.C, saturn.B, op2); - break; - case 0xe: /* A=A!C */ - saturn.PC += 4; - or_register(saturn.A, saturn.A, saturn.C, op2); - break; - case 0xf: /* C=C!D */ - saturn.PC += 4; - or_register(saturn.C, saturn.C, saturn.D, op2); - break; - default: - stop = 1; - break; - } - break; - case 0xf: /* RTI */ - do_return_interupt(); - break; - default: - stop = 1; - break; - } - break; - case 1: - stop = decode_group_1(); - break; - case 2: - op2 = read_nibble(saturn.PC + 1); + case 0xa: /* ST=C */ saturn.PC += 2; - saturn.P = op2; + register_to_status(saturn.C); break; - case 3: - op2 = read_nibble(saturn.PC + 1); - load_constant(saturn.C, op2 + 1, saturn.PC + 2); - saturn.PC += 3 + op2; + case 0xb: /* CSTEX */ + saturn.PC += 2; + swap_register_status(saturn.C); break; - case 4: - op2 = read_nibbles(saturn.PC + 1, 2); - if (op2 == 0x02) { - saturn.PC += 3; - } else if (saturn.CARRY != 0) { - if (op2) { - if (op2 & 0x80) - op2 |= jumpmasks[2]; - jumpaddr = (saturn.PC + op2 + 1) & 0xfffff; - saturn.PC = jumpaddr; - } else { - saturn.PC = pop_return_addr(); - } + case 0xc: /* P=P+1 */ + saturn.PC += 2; + if (saturn.P == 0xf) { + saturn.P = 0; + saturn.CARRY = 1; } else { - saturn.PC += 3; + saturn.P += 1; + saturn.CARRY = 0; } break; - case 5: - if (saturn.CARRY == 0) { - op2 = read_nibbles(saturn.PC + 1, 2); - if (op2) { - if (op2 & 0x80) - op2 |= jumpmasks[2]; - jumpaddr = (saturn.PC + op2 + 1) & 0xfffff; - saturn.PC = jumpaddr; - } else { - saturn.PC = pop_return_addr(); - } + case 0xd: /* P=P-1 */ + saturn.PC += 2; + if (saturn.P == 0) { + saturn.P = 0xf; + saturn.CARRY = 1; } else { - saturn.PC += 3; + saturn.P -= 1; + saturn.CARRY = 0; } break; - case 6: - op2 = read_nibbles(saturn.PC + 1, 3); - if (op2 == 0x003) { + case 0xe: + op2 = read_nibble(saturn.PC + 2); + op3 = read_nibble(saturn.PC + 3); + switch (op3) { + case 0: /* A=A&B */ saturn.PC += 4; - } else if(op2 == 0x004) { - op3 = read_nibbles(saturn.PC + 4, 1); - saturn.PC += 5; - if (op3 != 0) { - enter_debugger |= TRAP_INSTRUCTION; - return 1; - } - } else { - if (op2 & 0x800) - op2 |= jumpmasks[3]; - jumpaddr = (op2 + saturn.PC + 1) & 0xfffff; - saturn.PC = jumpaddr; + and_register(saturn.A, saturn.A, saturn.B, op2); + break; + case 1: /* B=B&C */ + saturn.PC += 4; + and_register(saturn.B, saturn.B, saturn.C, op2); + break; + case 2: /* C=C&A */ + saturn.PC += 4; + and_register(saturn.C, saturn.C, saturn.A, op2); + break; + case 3: /* D=D&C */ + saturn.PC += 4; + and_register(saturn.D, saturn.D, saturn.C, op2); + break; + case 4: /* B=B&A */ + saturn.PC += 4; + and_register(saturn.B, saturn.B, saturn.A, op2); + break; + case 5: /* C=C&B */ + saturn.PC += 4; + and_register(saturn.C, saturn.C, saturn.B, op2); + break; + case 6: /* A=A&C */ + saturn.PC += 4; + and_register(saturn.A, saturn.A, saturn.C, op2); + break; + case 7: /* C=C&D */ + saturn.PC += 4; + and_register(saturn.C, saturn.C, saturn.D, op2); + break; + case 8: /* A=A!B */ + saturn.PC += 4; + or_register(saturn.A, saturn.A, saturn.B, op2); + break; + case 9: /* B=B!C */ + saturn.PC += 4; + or_register(saturn.B, saturn.B, saturn.C, op2); + break; + case 0xa: /* C=C!A */ + saturn.PC += 4; + or_register(saturn.C, saturn.C, saturn.A, op2); + break; + case 0xb: /* D=D!C */ + saturn.PC += 4; + or_register(saturn.D, saturn.D, saturn.C, op2); + break; + case 0xc: /* B=B!A */ + saturn.PC += 4; + or_register(saturn.B, saturn.B, saturn.A, op2); + break; + case 0xd: /* C=C!B */ + saturn.PC += 4; + or_register(saturn.C, saturn.C, saturn.B, op2); + break; + case 0xe: /* A=A!C */ + saturn.PC += 4; + or_register(saturn.A, saturn.A, saturn.C, op2); + break; + case 0xf: /* C=C!D */ + saturn.PC += 4; + or_register(saturn.C, saturn.C, saturn.D, op2); + break; + default: + stop = 1; + break; } break; - case 7: - op2 = read_nibbles(saturn.PC + 1, 3); - if (op2 & 0x800) - op2 |= jumpmasks[3]; - jumpaddr = (op2 + saturn.PC + 4) & 0xfffff; - push_return_addr(saturn.PC+4); - saturn.PC = jumpaddr; + case 0xf: /* RTI */ + do_return_interupt(); break; default: - stop = decode_8_thru_f(op0); + stop = 1; break; + } + break; + case 1: + stop = decode_group_1(); + break; + case 2: + op2 = read_nibble(saturn.PC + 1); + saturn.PC += 2; + saturn.P = op2; + break; + case 3: + op2 = read_nibble(saturn.PC + 1); + load_constant(saturn.C, op2 + 1, saturn.PC + 2); + saturn.PC += 3 + op2; + break; + case 4: + op2 = read_nibbles(saturn.PC + 1, 2); + if (op2 == 0x02) { + saturn.PC += 3; + } else if (saturn.CARRY != 0) { + if (op2) { + if (op2 & 0x80) + op2 |= jumpmasks[2]; + jumpaddr = (saturn.PC + op2 + 1) & 0xfffff; + saturn.PC = jumpaddr; + } else { + saturn.PC = pop_return_addr(); + } + } else { + saturn.PC += 3; + } + break; + case 5: + if (saturn.CARRY == 0) { + op2 = read_nibbles(saturn.PC + 1, 2); + if (op2) { + if (op2 & 0x80) + op2 |= jumpmasks[2]; + jumpaddr = (saturn.PC + op2 + 1) & 0xfffff; + saturn.PC = jumpaddr; + } else { + saturn.PC = pop_return_addr(); + } + } else { + saturn.PC += 3; + } + break; + case 6: + op2 = read_nibbles(saturn.PC + 1, 3); + if (op2 == 0x003) { + saturn.PC += 4; + } else if (op2 == 0x004) { + op3 = read_nibbles(saturn.PC + 4, 1); + saturn.PC += 5; + if (op3 != 0) { + enter_debugger |= TRAP_INSTRUCTION; + return 1; + } + } else { + if (op2 & 0x800) + op2 |= jumpmasks[3]; + jumpaddr = (op2 + saturn.PC + 1) & 0xfffff; + saturn.PC = jumpaddr; + } + break; + case 7: + op2 = read_nibbles(saturn.PC + 1, 3); + if (op2 & 0x800) + op2 |= jumpmasks[3]; + jumpaddr = (op2 + saturn.PC + 4) & 0xfffff; + push_return_addr(saturn.PC + 4); + saturn.PC = jumpaddr; + break; + default: + stop = decode_8_thru_f(op0); + break; } instructions++; if (stop) { @@ -2190,10 +2191,10 @@ inline int step_instruction(void) { } inline void schedule(void) { - t1_t2_ticks ticks; - unsigned long steps; - static unsigned long old_stat_instr; - static unsigned long old_sched_instr; + t1_t2_ticks ticks; + unsigned long steps; + static unsigned long old_stat_instr; + static unsigned long old_sched_instr; steps = instructions - old_sched_instr; old_sched_instr = instructions; @@ -2220,15 +2221,17 @@ inline void schedule(void) { schedule_event = sched_timer2; #ifdef DEBUG_SCHED - fprintf(stderr, "next timer 2 step: %ld, event: %ld\n", - sched_timer2, schedule_event); + fprintf(stderr, "next timer 2 step: %ld, event: %ld\n", sched_timer2, + schedule_event); #endif if (device_check) { device_check = 0; if ((sched_display -= steps) <= 0) { - if (device.display_touched) device.display_touched -= steps; - if (device.display_touched < 0) device.display_touched = 1; + if (device.display_touched) + device.display_touched -= steps; + if (device.display_touched < 0) + device.display_touched = 1; #ifdef DEBUG_DISP_SCHED fprintf(stderr, "check_device: disp_when %d, disp_touched %d\n", sched_display, device.display_touched); @@ -2239,7 +2242,8 @@ inline void schedule(void) { if (device.display_touched) { if (device.display_touched < sched_display) sched_display = device.display_touched - 1; - if (sched_display < schedule_event) schedule_event = sched_display; + if (sched_display < schedule_event) + schedule_event = sched_display; } } @@ -2249,11 +2253,12 @@ inline void schedule(void) { receive_char(); } } - if (sched_receive < schedule_event) schedule_event = sched_receive; + if (sched_receive < schedule_event) + schedule_event = sched_receive; #ifdef DEBUG_SCHED - fprintf(stderr, "next receive: %ld, event: %ld\n", - sched_receive, schedule_event); + fprintf(stderr, "next receive: %ld, event: %ld\n", sched_receive, + schedule_event); #endif if ((sched_adjtime -= steps) <= 0) { @@ -2288,14 +2293,14 @@ inline void schedule(void) { } else { adj_time_pending = 1; - } } - if (sched_adjtime < schedule_event) schedule_event = sched_adjtime; + if (sched_adjtime < schedule_event) + schedule_event = sched_adjtime; #ifdef DEBUG_SCHED - fprintf(stderr, "next adjtime: %ld, event: %ld\n", - sched_adjtime, schedule_event); + fprintf(stderr, "next adjtime: %ld, event: %ld\n", sched_adjtime, + schedule_event); #endif if ((sched_timer1 -= steps) <= 0) { @@ -2311,11 +2316,12 @@ inline void schedule(void) { do_interupt(); } } - if (sched_timer1 < schedule_event) schedule_event = sched_timer1; + if (sched_timer1 < schedule_event) + schedule_event = sched_timer1; #ifdef DEBUG_SCHED - fprintf(stderr, "next timer 1 step: %ld, event: %ld\n", - sched_timer1, schedule_event); + fprintf(stderr, "next timer 1 step: %ld, event: %ld\n", sched_timer1, + schedule_event); #endif if ((sched_statistics -= steps) <= 0) { @@ -2332,11 +2338,13 @@ inline void schedule(void) { delta_i = instructions - old_stat_instr; old_stat_instr = instructions; if (delta_t_1 > 0) { - t1_i_per_tick = ((NR_SAMPLES - 1) * t1_i_per_tick + - (delta_i / delta_t_16)) / NR_SAMPLES; + t1_i_per_tick = + ((NR_SAMPLES - 1) * t1_i_per_tick + (delta_i / delta_t_16)) / + NR_SAMPLES; t2_i_per_tick = t1_i_per_tick / 512; - saturn.i_per_s = ((NR_SAMPLES - 1) * saturn.i_per_s + - (delta_i / delta_t_1)) / NR_SAMPLES; + saturn.i_per_s = + ((NR_SAMPLES - 1) * saturn.i_per_s + (delta_i / delta_t_1)) / + NR_SAMPLES; } else { t1_i_per_tick = 8192; t2_i_per_tick = 16; @@ -2361,8 +2369,8 @@ inline void schedule(void) { schedule_event = sched_statistics; #ifdef DEBUG_SCHED - fprintf(stderr, "next statistics: %ld, event: %ld\n", - sched_statistics, schedule_event); + fprintf(stderr, "next statistics: %ld, event: %ld\n", sched_statistics, + schedule_event); #endif if ((sched_instr_rollover -= steps) <= 0) { @@ -2386,15 +2394,16 @@ inline void schedule(void) { if (got_alarm) { got_alarm = 0; #ifdef HAVE_XSHM - if (disp.display_update) refresh_display(); + if (disp.display_update) + refresh_display(); #endif GetEvent(); } } int emulate(void) { - struct timeval tv; - struct timeval tv2; + struct timeval tv; + struct timeval tv2; #ifndef SOLARIS struct timezone tz; #endif @@ -2418,36 +2427,36 @@ int emulate(void) { { int i; - for (i=0; - i < sizeof(saturn.keybuf.rows)/sizeof(saturn.keybuf.rows[0]); - i++) { + for (i = 0; + i < sizeof(saturn.keybuf.rows) / sizeof(saturn.keybuf.rows[0]); + i++) { if (saturn.keybuf.rows[i] || throttle) { #ifdef SOLARIS gettimeofday(&tv); #else gettimeofday(&tv, &tz); #endif - while ((tv.tv_sec == tv2.tv_sec) && ((tv.tv_usec - tv2.tv_usec) < 2)) { - gettimeofday(&tv, &tz); + while ((tv.tv_sec == tv2.tv_sec) && + ((tv.tv_usec - tv2.tv_usec) < 2)) { + gettimeofday(&tv, &tz); } tv2.tv_usec = tv.tv_usec; tv2.tv_sec = tv.tv_sec; - break; - } + break; + } } } -/* We need to throttle the speed here. */ + /* We need to throttle the speed here. */ if (schedule_event < 0) { -//puts("bug"); -// schedule_event = 0; + // puts("bug"); + // schedule_event = 0; + } + if (schedule_event-- <= 0) { + schedule(); } - if (schedule_event-- <= 0) - { - schedule(); - } } while (!enter_debugger); return 0; diff --git a/src/errors.c b/src/errors.c index 4e76a64..291d7b1 100644 --- a/src/errors.c +++ b/src/errors.c @@ -31,23 +31,26 @@ #include "global.h" #include "resources.h" -char errbuf[1024] = { 0, }; -char fixbuf[1024] = { 0, }; +char errbuf[1024] = { + 0, +}; +char fixbuf[1024] = { + 0, +}; void fatal_exit(void) { if (quiet) - exit (1); + exit(1); - if (errbuf[0] == '\0') - { - fprintf(stderr, "%s: FATAL ERROR, exit.\n", progname); - exit (1); - } + if (errbuf[0] == '\0') { + fprintf(stderr, "%s: FATAL ERROR, exit.\n", progname); + exit(1); + } fprintf(stderr, "%s: FATAL ERROR, exit.\n - %s\n", progname, errbuf); if (fixbuf[0] != '\0') fprintf(stderr, " - %s\n", fixbuf); - exit (1); + exit(1); } diff --git a/src/errors.h b/src/errors.h index 77770ce..225e298 100644 --- a/src/errors.h +++ b/src/errors.h @@ -32,6 +32,6 @@ extern char errbuf[1024]; extern char fixbuf[1024]; -extern void fatal_exit __ProtoType__ ((void)); +extern void fatal_exit __ProtoType__((void)); #endif /* !_ERRORS_H */ diff --git a/src/global.h b/src/global.h index 504392b..a342341 100644 --- a/src/global.h +++ b/src/global.h @@ -60,41 +60,41 @@ #if defined(linux) #ifndef LINUX -#define LINUX 1 +#define LINUX 1 #endif #define SYSV_TIME 1 -#else /* Not Linux */ +#else /* Not Linux */ #if defined(sun) && defined(unix) #if defined(__svr4__) || defined(SVR4) || defined(SYSV) #ifndef SOLARIS -#define SOLARIS 1 +#define SOLARIS 1 #endif #define SYSV_TIME 1 -#else /* Not Solaris */ +#else /* Not Solaris */ #if defined(hpux) #ifndef HPUX -#define HPUX 1 +#define HPUX 1 #endif -#else /* Not HP-UX */ +#else /* Not HP-UX */ #ifndef SUNOS -#define SUNOS 1 +#define SUNOS 1 #endif -#endif /* Not HP-UX */ -#endif /* Not Solaris */ -#endif /* Sun && Unix */ -#endif /* Not Linux */ +#endif /* Not HP-UX */ +#endif /* Not Solaris */ +#endif /* Sun && Unix */ +#endif /* Not Linux */ #ifdef SYSV #ifndef SYSV_TIME @@ -112,28 +112,28 @@ #include #include #include -extern int printf __ProtoType__((char *, ...)); -extern int fprintf __ProtoType__((FILE *, char *, ...)); -extern int sscanf __ProtoType__((char *, char *, ...)); -extern void fflush __ProtoType__((FILE *)); -extern int fseek __ProtoType__((FILE *, long, int)); -extern int fread __ProtoType__((void *, int, int, FILE*)); -extern int fwrite __ProtoType__((void *, int, int, FILE*)); -extern void fclose __ProtoType__((FILE *)); -extern int fgetc __ProtoType__((FILE *)); -extern void bzero __ProtoType__((void *, int)); -extern time_t time __ProtoType__((time_t *)); -extern int select __ProtoType__((int, fd_set *, fd_set *, - fd_set *, struct timeval *)); -extern int setitimer __ProtoType__((int, struct itimerval *, - struct itimerval *)); -extern int gethostname __ProtoType__((char *, int)); +extern int printf __ProtoType__((char *, ...)); +extern int fprintf __ProtoType__((FILE *, char *, ...)); +extern int sscanf __ProtoType__((char *, char *, ...)); +extern void fflush __ProtoType__((FILE *)); +extern int fseek __ProtoType__((FILE *, long, int)); +extern int fread __ProtoType__((void *, int, int, FILE *)); +extern int fwrite __ProtoType__((void *, int, int, FILE *)); +extern void fclose __ProtoType__((FILE *)); +extern int fgetc __ProtoType__((FILE *)); +extern void bzero __ProtoType__((void *, int)); +extern time_t time __ProtoType__((time_t *)); +extern int select __ProtoType__((int, fd_set *, fd_set *, fd_set *, + struct timeval *)); +extern int setitimer __ProtoType__((int, struct itimerval *, + struct itimerval *)); +extern int gethostname __ProtoType__((char *, int)); #ifdef HAVE_XSHM #include #include -extern int shmget __ProtoType__((key_t, int, int)); -extern int shmat __ProtoType__((int, void *, int)); -extern int shmctl __ProtoType__((int, int, struct shmid_ds *)); +extern int shmget __ProtoType__((key_t, int, int)); +extern int shmat __ProtoType__((int, void *, int)); +extern int shmctl __ProtoType__((int, int, struct shmid_ds *)); #endif #endif diff --git a/src/hp48.h b/src/hp48.h index e2b89b9..20e5bff 100644 --- a/src/hp48.h +++ b/src/hp48.h @@ -68,41 +68,41 @@ #include #include "mmu.h" -#ifdef HAVE_STDINT_H -# include +#ifdef HAVE_STDINT_H +#include #endif #define RAM_SIZE_SX 0x10000 #define RAM_SIZE_GX 0x40000 -#define P_FIELD 0 -#define WP_FIELD 1 -#define XS_FIELD 2 -#define X_FIELD 3 -#define S_FIELD 4 -#define M_FIELD 5 -#define B_FIELD 6 -#define W_FIELD 7 -#define A_FIELD 15 -#define IN_FIELD 16 -#define OUT_FIELD 17 -#define OUTS_FIELD 18 +#define P_FIELD 0 +#define WP_FIELD 1 +#define XS_FIELD 2 +#define X_FIELD 3 +#define S_FIELD 4 +#define M_FIELD 5 +#define B_FIELD 6 +#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 DEC 10 +#define HEX 16 -#define NR_RSTK 8 -#define NR_PSTAT 16 +#define NR_RSTK 8 +#define NR_PSTAT 16 -typedef unsigned char word_1; -typedef unsigned char word_4; -typedef unsigned char word_8; +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 long word_20; +typedef long word_32; -#ifdef HAVE_STDINT_H +#ifdef HAVE_STDINT_H #define SIMPLE_64 typedef int64_t word_64; #else @@ -117,21 +117,21 @@ typedef struct keystate_t { typedef struct display_t { - int on; + int on; long disp_start; long disp_end; - int offset; - int lines; - int nibs_per_line; + int offset; + int lines; + int nibs_per_line; - int contrast; + int contrast; long menu_start; long menu_end; - int annunc; + int annunc; } display_t; @@ -143,102 +143,102 @@ typedef struct mem_cntl_t { typedef struct saturn_t { unsigned long magic; - char version[4]; + char version[4]; unsigned char A[16], B[16], C[16], D[16]; - word_20 d[2]; + word_20 d[2]; -#define D0 d[0] -#define D1 d[1] +#define D0 d[0] +#define D1 d[1] - word_4 P; - word_20 PC; + 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; + word_1 CARRY; unsigned char PSTAT[NR_PSTAT]; unsigned char XM, SB, SR, MP; - word_4 hexmode; + word_4 hexmode; - word_20 rstk[NR_RSTK]; - short rstkp; + word_20 rstk[NR_RSTK]; + short rstkp; - keystate_t keybuf; + keystate_t keybuf; unsigned char intenable; unsigned char int_pending; unsigned char kbd_ien; - word_4 disp_io; + word_4 disp_io; - word_4 contrast_ctrl; - word_8 disp_test; + word_4 contrast_ctrl; + word_8 disp_test; - word_16 crc; + word_16 crc; - word_4 power_status; - word_4 power_ctrl; + word_4 power_status; + word_4 power_ctrl; - word_4 mode; + word_4 mode; - word_8 annunc; + word_8 annunc; - word_4 baud; + word_4 baud; - word_4 card_ctrl; - word_4 card_status; + word_4 card_ctrl; + word_4 card_status; - word_4 io_ctrl; - word_4 rcs; - word_4 tcs; + word_4 io_ctrl; + word_4 rcs; + word_4 tcs; - word_8 rbr; - word_8 tbr; + word_8 rbr; + word_8 tbr; - word_8 sreq; + word_8 sreq; - word_4 ir_ctrl; + word_4 ir_ctrl; - word_4 base_off; + word_4 base_off; - word_4 lcr; - word_4 lbr; + word_4 lcr; + word_4 lbr; - word_4 scratch; + word_4 scratch; - word_4 base_nibble; + word_4 base_nibble; - word_20 disp_addr; - word_12 line_offset; - word_8 line_count; + word_20 disp_addr; + word_12 line_offset; + word_8 line_count; - word_16 unknown; + word_16 unknown; - word_4 t1_ctrl; - word_4 t2_ctrl; + word_4 t1_ctrl; + word_4 t2_ctrl; - word_20 menu_addr; + word_20 menu_addr; - word_8 unknown2; + word_8 unknown2; - char timer1; /* may NOT be unsigned !!! */ - word_32 timer2; + char timer1; /* may NOT be unsigned !!! */ + word_32 timer2; - long t1_instr; - long t2_instr; + long t1_instr; + long t2_instr; - short t1_tick; - short t2_tick; - long i_per_s; + short t1_tick; + short t2_tick; + long i_per_s; - short bank_switch; - mem_cntl_t mem_cntl[NR_MCTL]; + short bank_switch; + mem_cntl_t mem_cntl[NR_MCTL]; unsigned char *rom; unsigned char *ram; @@ -249,45 +249,44 @@ typedef struct saturn_t { #define NIBBLES_PER_ROW 0x22 -extern int got_alarm; +extern int got_alarm; -extern int set_t1; -extern long sched_timer1; -extern long sched_timer2; +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 int adj_time_pending; +extern long sched_adjtime; +extern long schedule_event; -extern display_t display; -extern void init_display __ProtoType__((void)); +extern display_t display; +extern void init_display __ProtoType__((void)); -extern saturn_t saturn; +extern saturn_t saturn; -extern int exit_emulator __ProtoType__((void)); -extern int init_emulator __ProtoType__((void)); -extern void init_active_stuff __ProtoType__((void)); +extern int exit_emulator __ProtoType__((void)); +extern int init_emulator __ProtoType__((void)); +extern void init_active_stuff __ProtoType__((void)); -extern int serial_init __ProtoType__((void)); -extern void serial_baud __ProtoType__((int baud)); -extern void transmit_char __ProtoType__((void)); -extern void receive_char __ProtoType__((void)); +extern int serial_init __ProtoType__((void)); +extern void serial_baud __ProtoType__((int baud)); +extern void transmit_char __ProtoType__((void)); +extern void receive_char __ProtoType__((void)); -extern void do_kbd_int __ProtoType__((void)); -extern void do_interupt __ProtoType__((void)); +extern void do_kbd_int __ProtoType__((void)); +extern void do_interupt __ProtoType__((void)); -extern void (*write_nibble) __ProtoType__((long addr, int val)); -extern int (*read_nibble) __ProtoType__((long addr)); -extern int (*read_nibble_crc) __ProtoType__((long addr)); +extern void(*write_nibble) __ProtoType__((long addr, int val)); +extern int(*read_nibble) __ProtoType__((long addr)); +extern int(*read_nibble_crc) __ProtoType__((long addr)); -extern int emulate __ProtoType__((void)); -extern int step_instruction __ProtoType__((void)); -extern void schedule __ProtoType__((void)); +extern int emulate __ProtoType__((void)); +extern int step_instruction __ProtoType__((void)); +extern void schedule __ProtoType__((void)); -extern int read_rom __ProtoType__((const char *fname)); -extern int read_files __ProtoType__((void)); -extern int write_files __ProtoType__((void)); +extern int read_rom __ProtoType__((const char *fname)); +extern int read_files __ProtoType__((void)); +extern int write_files __ProtoType__((void)); -extern void load_addr __ProtoType__((word_20 *dat, long addr, - int n)); +extern void load_addr __ProtoType__((word_20 * dat, long addr, int n)); #endif /* !_HP48_H */ diff --git a/src/hp48_emu.h b/src/hp48_emu.h index 1ad82bd..a77d355 100644 --- a/src/hp48_emu.h +++ b/src/hp48_emu.h @@ -68,135 +68,119 @@ extern Display *dpy; extern Window dispW; extern GC gc; -extern void push_return_addr __ProtoType__((long addr)); -extern long pop_return_addr __ProtoType__((void)); +extern void push_return_addr __ProtoType__((long addr)); +extern long pop_return_addr __ProtoType__((void)); -extern void init_annunc __ProtoType__((void)); +extern void init_annunc __ProtoType__((void)); -extern void init_saturn __ProtoType__((void)); +extern void init_saturn __ProtoType__((void)); -extern void check_timer __ProtoType__((void)); +extern void check_timer __ProtoType__((void)); -extern void register_to_status __ProtoType__((unsigned char *r)); -extern void status_to_register __ProtoType__((unsigned char *r)); -extern void swap_register_status __ProtoType__((unsigned char *r)); -extern void clear_status __ProtoType__((void)); +extern void register_to_status __ProtoType__((unsigned char *r)); +extern void status_to_register __ProtoType__((unsigned char *r)); +extern void swap_register_status __ProtoType__((unsigned char *r)); +extern void clear_status __ProtoType__((void)); -extern long read_nibbles __ProtoType__((long addr, int len)); -extern void write_nibbles __ProtoType__((long addr, long val, int len)); -extern void dev_memory_init __ProtoType__((void)); +extern long read_nibbles __ProtoType__((long addr, int len)); +extern void write_nibbles __ProtoType__((long addr, long val, int len)); +extern void dev_memory_init __ProtoType__((void)); -extern void set_program_stat __ProtoType__((int n)); -extern void clear_program_stat __ProtoType__((int n)); -extern int get_program_stat __ProtoType__((int n)); +extern void set_program_stat __ProtoType__((int n)); +extern void clear_program_stat __ProtoType__((int n)); +extern int get_program_stat __ProtoType__((int n)); -extern void set_hardware_stat __ProtoType__((int op)); -extern void clear_hardware_stat __ProtoType__((int op)); -extern int is_zero_hardware_stat __ProtoType__((int op)); +extern void set_hardware_stat __ProtoType__((int op)); +extern void clear_hardware_stat __ProtoType__((int op)); +extern int is_zero_hardware_stat __ProtoType__((int op)); -extern void set_register_bit __ProtoType__((unsigned char *reg, int n)); -extern void clear_register_bit __ProtoType__((unsigned char *reg, int n)); -extern int get_register_bit __ProtoType__((unsigned char *reg, int n)); +extern void set_register_bit __ProtoType__((unsigned char *reg, int n)); +extern void clear_register_bit __ProtoType__((unsigned char *reg, int n)); +extern int get_register_bit __ProtoType__((unsigned char *reg, int n)); -extern void set_register_nibble __ProtoType__((unsigned char *reg, int n, - unsigned char val)); -extern unsigned char get_register_nibble __ProtoType__((unsigned char *reg, int n)); +extern void set_register_nibble __ProtoType__((unsigned char *reg, int n, + unsigned char val)); +extern unsigned char get_register_nibble __ProtoType__((unsigned char *reg, + int n)); +extern void register_to_address __ProtoType__((unsigned char *reg, word_20 *dat, + int s)); +extern void address_to_register __ProtoType__((word_20 dat, unsigned char *reg, + int s)); +extern void add_address __ProtoType__((word_20 * dat, int add)); -extern void register_to_address __ProtoType__((unsigned char *reg, - word_20 *dat, int s)); -extern void address_to_register __ProtoType__((word_20 dat, - unsigned char *reg, int s)); -extern void add_address __ProtoType__((word_20 *dat, int add)); +extern char *make_hexstr __ProtoType__((long addr, int n)); +extern void load_constant __ProtoType__((unsigned char *reg, int n, long addr)); +extern void load_address __ProtoType__((unsigned char *reg, long addr, int n)); -extern char * make_hexstr __ProtoType__((long addr, int n)); -extern void load_constant __ProtoType__((unsigned char *reg, int n, - long addr)); -extern void load_address __ProtoType__((unsigned char *reg, long addr, - int n)); +extern void store __ProtoType__((word_20 dat, unsigned char *reg, int code)); +extern void store_n __ProtoType__((word_20 dat, unsigned char *reg, int n)); +extern void recall __ProtoType__((unsigned char *reg, word_20 dat, int code)); +extern void recall_n __ProtoType__((unsigned char *reg, word_20 dat, int n)); -extern void store __ProtoType__((word_20 dat, unsigned char *reg, - int code)); -extern void store_n __ProtoType__((word_20 dat, unsigned char *reg, - int n)); -extern void recall __ProtoType__((unsigned char *reg, word_20 dat, - int code)); -extern void recall_n __ProtoType__((unsigned char *reg, word_20 dat, - int n)); +extern long dat_to_addr __ProtoType__((unsigned char *dat)); +extern void addr_to_dat __ProtoType__((long addr, unsigned char *dat)); -extern long dat_to_addr __ProtoType__((unsigned char *dat)); -extern void addr_to_dat __ProtoType__((long addr, unsigned char *dat)); +extern void do_in __ProtoType__((void)); +extern void do_reset __ProtoType__((void)); +extern void do_configure __ProtoType__((void)); +extern void do_unconfigure __ProtoType__((void)); +extern void do_inton __ProtoType__((void)); +extern void do_intoff __ProtoType__((void)); +extern void do_return_interupt __ProtoType__((void)); +extern void do_reset_interrupt_system __ProtoType__((void)); +extern void do_shutdown __ProtoType__((void)); +extern int get_identification __ProtoType__((void)); -extern void do_in __ProtoType__((void)); -extern void do_reset __ProtoType__((void)); -extern void do_configure __ProtoType__((void)); -extern void do_unconfigure __ProtoType__((void)); -extern void do_inton __ProtoType__((void)); -extern void do_intoff __ProtoType__((void)); -extern void do_return_interupt __ProtoType__((void)); -extern void do_reset_interrupt_system __ProtoType__((void)); -extern void do_shutdown __ProtoType__((void)); -extern int get_identification __ProtoType__((void)); +extern void add_p_plus_one __ProtoType__((unsigned char *r)); +extern void add_register_constant __ProtoType__((unsigned char *res, int code, + int val)); +extern void sub_register_constant __ProtoType__((unsigned char *res, int code, + int val)); +extern void add_register __ProtoType__((unsigned char *res, unsigned char *r1, + unsigned char *r2, int code)); +extern void sub_register __ProtoType__((unsigned char *res, unsigned char *r1, + unsigned char *r2, int code)); +extern void complement_2_register __ProtoType__((unsigned char *r, int code)); +extern void complement_1_register __ProtoType__((unsigned char *r, int code)); +extern void inc_register __ProtoType__((unsigned char *r, int code)); +extern void dec_register __ProtoType__((unsigned char *r, int code)); +extern void zero_register __ProtoType__((unsigned char *r, int code)); +extern void or_register __ProtoType__((unsigned char *res, unsigned char *r1, + unsigned char *r2, int code)); +extern void and_register __ProtoType__((unsigned char *res, unsigned char *r1, + unsigned char *r2, int code)); +extern void copy_register __ProtoType__((unsigned char *to, unsigned char *from, + int code)); +extern void exchange_register __ProtoType__((unsigned char *r1, + unsigned char *r2, int code)); -extern void add_p_plus_one __ProtoType__((unsigned char *r)); -extern void add_register_constant __ProtoType__((unsigned char *res, - int code, int val)); -extern void sub_register_constant __ProtoType__((unsigned char *res, - int code, int val)); -extern void add_register __ProtoType__((unsigned char *res, unsigned char *r1, - unsigned char *r2, int code)); -extern void sub_register __ProtoType__((unsigned char *res, unsigned char *r1, - unsigned char *r2, int code)); -extern void complement_2_register __ProtoType__((unsigned char *r, int code)); -extern void complement_1_register __ProtoType__((unsigned char *r, int code)); -extern void inc_register __ProtoType__((unsigned char *r, int code)); -extern void dec_register __ProtoType__((unsigned char *r, int code)); -extern void zero_register __ProtoType__((unsigned char *r, int code)); -extern void or_register __ProtoType__((unsigned char *res, unsigned char *r1, - unsigned char *r2, int code)); -extern void and_register __ProtoType__((unsigned char *res, unsigned char *r1, - unsigned char *r2, int code)); -extern void copy_register __ProtoType__((unsigned char *to, unsigned char *from, - int code)); -extern void exchange_register __ProtoType__((unsigned char *r1, unsigned char *r2, - int code)); +extern void exchange_reg __ProtoType__((unsigned char *r, word_20 *d, + int code)); -extern void exchange_reg __ProtoType__((unsigned char *r, word_20 *d, int code)); - -extern void shift_left_register __ProtoType__((unsigned char *r, int code)); -extern void shift_left_circ_register __ProtoType__((unsigned char *r, int code)); -extern void shift_right_register __ProtoType__((unsigned char *r, int code)); -extern void shift_right_circ_register __ProtoType__((unsigned char *r, int code)); -extern void shift_right_bit_register __ProtoType__((unsigned char *r, int code)); -extern int is_zero_register __ProtoType__(( - unsigned char *r, - int code)); -extern int is_not_zero_register __ProtoType__(( - unsigned char *r, - int code)); -extern int is_equal_register __ProtoType__(( - unsigned char *r1, - unsigned char *r2, - int code)); -extern int is_not_equal_register __ProtoType__(( - unsigned char *r1, - unsigned char *r2, - int code)); -extern int is_less_register __ProtoType__(( - unsigned char *r1, - unsigned char *r2, - int code)); -extern int is_less_or_equal_register __ProtoType__(( - unsigned char *r1, - unsigned char *r2, - int code)); -extern int is_greater_register __ProtoType__(( - unsigned char *r1, - unsigned char *r2, - int code)); -extern int is_greater_or_equal_register __ProtoType__(( - unsigned char *r1, - unsigned char *r2, - int code)); +extern void shift_left_register __ProtoType__((unsigned char *r, int code)); +extern void shift_left_circ_register __ProtoType__((unsigned char *r, + int code)); +extern void shift_right_register __ProtoType__((unsigned char *r, int code)); +extern void shift_right_circ_register __ProtoType__((unsigned char *r, + int code)); +extern void shift_right_bit_register __ProtoType__((unsigned char *r, + int code)); +extern int is_zero_register __ProtoType__((unsigned char *r, int code)); +extern int is_not_zero_register __ProtoType__((unsigned char *r, int code)); +extern int is_equal_register __ProtoType__((unsigned char *r1, + unsigned char *r2, int code)); +extern int is_not_equal_register __ProtoType__((unsigned char *r1, + unsigned char *r2, int code)); +extern int is_less_register __ProtoType__((unsigned char *r1, unsigned char *r2, + int code)); +extern int is_less_or_equal_register __ProtoType__((unsigned char *r1, + unsigned char *r2, + int code)); +extern int is_greater_register __ProtoType__((unsigned char *r1, + unsigned char *r2, int code)); +extern int is_greater_or_equal_register __ProtoType__((unsigned char *r1, + unsigned char *r2, + int code)); #endif /* !_HP48_EMU_H */ diff --git a/src/hp48char.h b/src/hp48char.h index b3b5efb..fc8aebd 100644 --- a/src/hp48char.h +++ b/src/hp48char.h @@ -34,275 +34,81 @@ * $Id: hp48char.h,v 1.3 1995/01/11 18:20:01 ecd Exp ecd $ */ #ifndef _HP48CHAR_H -#define _HP48CHAR_H 1 +#define _HP48CHAR_H 1 typedef struct trans_tbl_t { - unsigned char hp48_char; - char *trans; + unsigned char hp48_char; + char *trans; } trans_tbl_t; #ifndef DEFINE_TRANS_TABLE extern trans_tbl_t hp48_trans_tbl[256]; #else -trans_tbl_t hp48_trans_tbl[256] = -{ - { 0, "\\0" }, - { 1, "\\001" }, - { 2, "\\002" }, - { 3, "\\003" }, - { 4, "\\004" }, - { 5, "\\005" }, - { 6, "\\006" }, - { 7, "\\007" }, - { 8, "\\b" }, - { 9, "\\t" }, - { 10, "\\n" }, - { 11, "\\011" }, - { 12, "\\f" }, - { 13, "\\r" }, - { 14, "\\014" }, - { 15, "\\015" }, - { 16, "\\016" }, - { 17, "\\017" }, - { 18, "\\018" }, - { 19, "\\019" }, - { 20, "\\020" }, - { 21, "\\021" }, - { 22, "\\022" }, - { 23, "\\023" }, - { 24, "\\024" }, - { 25, "\\025" }, - { 26, "\\026" }, - { 27, "\\027" }, - { 28, "\\028" }, - { 29, "\\029" }, - { 30, "\\030" }, - { 31, "\\031" }, - { ' ', 0 }, - { '!', 0 }, - { '"', 0 }, - { '#', 0 }, - { '$', 0 }, - { '%', 0 }, - { '&', 0 }, - { '\'', 0 }, - { '(', 0 }, - { ')', 0 }, - { '*', 0 }, - { '+', 0 }, - { ',', 0 }, - { '-', 0 }, - { '.', 0 }, - { '/', 0 }, - { '0', 0 }, - { '1', 0 }, - { '2', 0 }, - { '3', 0 }, - { '4', 0 }, - { '5', 0 }, - { '6', 0 }, - { '7', 0 }, - { '8', 0 }, - { '9', 0 }, - { ':', 0 }, - { ';', 0 }, - { '<', 0 }, - { '=', 0 }, - { '>', 0 }, - { '?', 0 }, - { '@', 0 }, - { 'A', 0 }, - { 'B', 0 }, - { 'C', 0 }, - { 'D', 0 }, - { 'E', 0 }, - { 'F', 0 }, - { 'G', 0 }, - { 'H', 0 }, - { 'I', 0 }, - { 'J', 0 }, - { 'K', 0 }, - { 'L', 0 }, - { 'M', 0 }, - { 'N', 0 }, - { 'O', 0 }, - { 'P', 0 }, - { 'Q', 0 }, - { 'R', 0 }, - { 'S', 0 }, - { 'T', 0 }, - { 'U', 0 }, - { 'V', 0 }, - { 'W', 0 }, - { 'X', 0 }, - { 'Y', 0 }, - { 'Z', 0 }, - { '[', 0 }, - { '\\', 0 }, - { ']', 0 }, - { '^', 0 }, - { '_', 0 }, - { '`', 0 }, - { 'a', 0 }, - { 'b', 0 }, - { 'c', 0 }, - { 'd', 0 }, - { 'e', 0 }, - { 'f', 0 }, - { 'g', 0 }, - { 'h', 0 }, - { 'i', 0 }, - { 'j', 0 }, - { 'k', 0 }, - { 'l', 0 }, - { 'm', 0 }, - { 'n', 0 }, - { 'o', 0 }, - { 'p', 0 }, - { 'q', 0 }, - { 'r', 0 }, - { 's', 0 }, - { 't', 0 }, - { 'u', 0 }, - { 'v', 0 }, - { 'w', 0 }, - { 'x', 0 }, - { 'y', 0 }, - { 'z', 0 }, - { '{', 0 }, - { '|', 0 }, - { '}', 0 }, - { '~', 0 }, - { 127, "\\127" }, - { 128, "\\<)" }, - { 129, "\\x-" }, - { 130, "\\.V" }, - { 131, "\\v/" }, - { 132, "\\.S" }, - { 133, "\\GS" }, - { 134, "\\|>" }, - { 135, "\\pi" }, - { 136, "\\.d" }, - { 137, "\\<=" }, - { 138, "\\>=" }, - { 139, "\\=/" }, - { 140, "\\Ga" }, - { 141, "\\->" }, - { 142, "\\<-" }, - { 143, "\\|v" }, - { 144, "\\|^" }, - { 145, "\\Gg" }, - { 146, "\\Gd" }, - { 147, "\\Ge" }, - { 148, "\\Gn" }, - { 149, "\\Gh" }, - { 150, "\\Gl" }, - { 151, "\\Gr" }, - { 152, "\\Gs" }, - { 153, "\\Gt" }, - { 154, "\\Gw" }, - { 155, "\\GD" }, - { 156, "\\PI" }, - { 157, "\\GW" }, - { 158, "\\[]" }, - { 159, "\\oo" }, - { 160, "\\160" }, - { 161, "\\161" }, - { 162, "\\162" }, - { 163, "\\163" }, - { 164, "\\164" }, - { 165, "\\165" }, - { 166, "\\166" }, - { 167, "\\167" }, - { 168, "\\168" }, - { 169, "\\169" }, - { 170, "\\170" }, - { 171, "\\<<" }, - { 172, "\\172" }, - { 173, "\\173" }, - { 174, "\\174" }, - { 175, "\\175" }, - { 176, "\\^o" }, - { 177, "\\177" }, - { 178, "\\178" }, - { 179, "\\179" }, - { 180, "\\180" }, - { 181, "\\Gm" }, - { 182, "\\182" }, - { 183, "\\183" }, - { 184, "\\184" }, - { 185, "\\185" }, - { 186, "\\186" }, - { 187, "\\>>" }, - { 188, "\\188" }, - { 189, "\\189" }, - { 190, "\\190" }, - { 191, "\\191" }, - { 192, "\\192" }, - { 193, "\\193" }, - { 194, "\\194" }, - { 195, "\\195" }, - { 196, "\\196" }, - { 197, "\\197" }, - { 198, "\\198" }, - { 199, "\\199" }, - { 200, "\\200" }, - { 201, "\\201" }, - { 202, "\\202" }, - { 203, "\\203" }, - { 204, "\\204" }, - { 205, "\\205" }, - { 206, "\\206" }, - { 207, "\\207" }, - { 208, "\\208" }, - { 209, "\\209" }, - { 210, "\\210" }, - { 211, "\\211" }, - { 212, "\\212" }, - { 213, "\\213" }, - { 214, "\\214" }, - { 215, "\\.x" }, - { 216, "\\O/" }, - { 217, "\\217" }, - { 218, "\\218" }, - { 219, "\\219" }, - { 220, "\\220" }, - { 221, "\\221" }, - { 222, "\\222" }, - { 223, "\\223" }, - { 224, "\\224" }, - { 225, "\\225" }, - { 226, "\\226" }, - { 227, "\\227" }, - { 228, "\\228" }, - { 229, "\\229" }, - { 230, "\\230" }, - { 231, "\\231" }, - { 232, "\\232" }, - { 233, "\\233" }, - { 234, "\\234" }, - { 235, "\\235" }, - { 236, "\\236" }, - { 237, "\\237" }, - { 238, "\\238" }, - { 239, "\\239" }, - { 240, "\\240" }, - { 241, "\\241" }, - { 242, "\\242" }, - { 243, "\\243" }, - { 244, "\\244" }, - { 245, "\\245" }, - { 246, "\\246" }, - { 247, "\\:-" }, - { 248, "\\248" }, - { 249, "\\249" }, - { 250, "\\250" }, - { 251, "\\251" }, - { 252, "\\252" }, - { 253, "\\253" }, - { 254, "\\254" }, - { 255, "\\255" } -}; +trans_tbl_t hp48_trans_tbl[256] = { + {0, "\\0"}, {1, "\\001"}, {2, "\\002"}, {3, "\\003"}, + {4, "\\004"}, {5, "\\005"}, {6, "\\006"}, {7, "\\007"}, + {8, "\\b"}, {9, "\\t"}, {10, "\\n"}, {11, "\\011"}, + {12, "\\f"}, {13, "\\r"}, {14, "\\014"}, {15, "\\015"}, + {16, "\\016"}, {17, "\\017"}, {18, "\\018"}, {19, "\\019"}, + {20, "\\020"}, {21, "\\021"}, {22, "\\022"}, {23, "\\023"}, + {24, "\\024"}, {25, "\\025"}, {26, "\\026"}, {27, "\\027"}, + {28, "\\028"}, {29, "\\029"}, {30, "\\030"}, {31, "\\031"}, + {' ', 0}, {'!', 0}, {'"', 0}, {'#', 0}, + {'$', 0}, {'%', 0}, {'&', 0}, {'\'', 0}, + {'(', 0}, {')', 0}, {'*', 0}, {'+', 0}, + {',', 0}, {'-', 0}, {'.', 0}, {'/', 0}, + {'0', 0}, {'1', 0}, {'2', 0}, {'3', 0}, + {'4', 0}, {'5', 0}, {'6', 0}, {'7', 0}, + {'8', 0}, {'9', 0}, {':', 0}, {';', 0}, + {'<', 0}, {'=', 0}, {'>', 0}, {'?', 0}, + {'@', 0}, {'A', 0}, {'B', 0}, {'C', 0}, + {'D', 0}, {'E', 0}, {'F', 0}, {'G', 0}, + {'H', 0}, {'I', 0}, {'J', 0}, {'K', 0}, + {'L', 0}, {'M', 0}, {'N', 0}, {'O', 0}, + {'P', 0}, {'Q', 0}, {'R', 0}, {'S', 0}, + {'T', 0}, {'U', 0}, {'V', 0}, {'W', 0}, + {'X', 0}, {'Y', 0}, {'Z', 0}, {'[', 0}, + {'\\', 0}, {']', 0}, {'^', 0}, {'_', 0}, + {'`', 0}, {'a', 0}, {'b', 0}, {'c', 0}, + {'d', 0}, {'e', 0}, {'f', 0}, {'g', 0}, + {'h', 0}, {'i', 0}, {'j', 0}, {'k', 0}, + {'l', 0}, {'m', 0}, {'n', 0}, {'o', 0}, + {'p', 0}, {'q', 0}, {'r', 0}, {'s', 0}, + {'t', 0}, {'u', 0}, {'v', 0}, {'w', 0}, + {'x', 0}, {'y', 0}, {'z', 0}, {'{', 0}, + {'|', 0}, {'}', 0}, {'~', 0}, {127, "\\127"}, + {128, "\\<)"}, {129, "\\x-"}, {130, "\\.V"}, {131, "\\v/"}, + {132, "\\.S"}, {133, "\\GS"}, {134, "\\|>"}, {135, "\\pi"}, + {136, "\\.d"}, {137, "\\<="}, {138, "\\>="}, {139, "\\=/"}, + {140, "\\Ga"}, {141, "\\->"}, {142, "\\<-"}, {143, "\\|v"}, + {144, "\\|^"}, {145, "\\Gg"}, {146, "\\Gd"}, {147, "\\Ge"}, + {148, "\\Gn"}, {149, "\\Gh"}, {150, "\\Gl"}, {151, "\\Gr"}, + {152, "\\Gs"}, {153, "\\Gt"}, {154, "\\Gw"}, {155, "\\GD"}, + {156, "\\PI"}, {157, "\\GW"}, {158, "\\[]"}, {159, "\\oo"}, + {160, "\\160"}, {161, "\\161"}, {162, "\\162"}, {163, "\\163"}, + {164, "\\164"}, {165, "\\165"}, {166, "\\166"}, {167, "\\167"}, + {168, "\\168"}, {169, "\\169"}, {170, "\\170"}, {171, "\\<<"}, + {172, "\\172"}, {173, "\\173"}, {174, "\\174"}, {175, "\\175"}, + {176, "\\^o"}, {177, "\\177"}, {178, "\\178"}, {179, "\\179"}, + {180, "\\180"}, {181, "\\Gm"}, {182, "\\182"}, {183, "\\183"}, + {184, "\\184"}, {185, "\\185"}, {186, "\\186"}, {187, "\\>>"}, + {188, "\\188"}, {189, "\\189"}, {190, "\\190"}, {191, "\\191"}, + {192, "\\192"}, {193, "\\193"}, {194, "\\194"}, {195, "\\195"}, + {196, "\\196"}, {197, "\\197"}, {198, "\\198"}, {199, "\\199"}, + {200, "\\200"}, {201, "\\201"}, {202, "\\202"}, {203, "\\203"}, + {204, "\\204"}, {205, "\\205"}, {206, "\\206"}, {207, "\\207"}, + {208, "\\208"}, {209, "\\209"}, {210, "\\210"}, {211, "\\211"}, + {212, "\\212"}, {213, "\\213"}, {214, "\\214"}, {215, "\\.x"}, + {216, "\\O/"}, {217, "\\217"}, {218, "\\218"}, {219, "\\219"}, + {220, "\\220"}, {221, "\\221"}, {222, "\\222"}, {223, "\\223"}, + {224, "\\224"}, {225, "\\225"}, {226, "\\226"}, {227, "\\227"}, + {228, "\\228"}, {229, "\\229"}, {230, "\\230"}, {231, "\\231"}, + {232, "\\232"}, {233, "\\233"}, {234, "\\234"}, {235, "\\235"}, + {236, "\\236"}, {237, "\\237"}, {238, "\\238"}, {239, "\\239"}, + {240, "\\240"}, {241, "\\241"}, {242, "\\242"}, {243, "\\243"}, + {244, "\\244"}, {245, "\\245"}, {246, "\\246"}, {247, "\\:-"}, + {248, "\\248"}, {249, "\\249"}, {250, "\\250"}, {251, "\\251"}, + {252, "\\252"}, {253, "\\253"}, {254, "\\254"}, {255, "\\255"}}; #endif /* DEFINE_TRANS_TABLE */ #endif /* !_HP48CHAR_H */ diff --git a/src/init.c b/src/init.c index 8bc6507..d96db02 100644 --- a/src/init.c +++ b/src/init.c @@ -65,21 +65,21 @@ * $Id: init.c,v 1.13 1995/01/11 18:20:01 ecd Exp ecd $ */ +#include +#include #include #include -#include -#include -#include #include -#include +#include #include +#include #ifdef SUNOS #include #endif +#include "device.h" #include "hp48.h" #include "hp48_emu.h" -#include "device.h" #include "resources.h" #include "romio.h" @@ -87,12 +87,12 @@ #define NR_CONFIG 8 short rom_is_new = 1; -long ram_size; -long port1_size; -long port1_mask; +long ram_size; +long port1_size; +long port1_mask; short port1_is_ram; -long port2_size; -long port2_mask; +long port2_size; +long port2_mask; short port2_is_ram; typedef struct old_keystate_t { @@ -101,30 +101,30 @@ typedef struct old_keystate_t { typedef struct old_saturn_t { unsigned char A[16], B[16], C[16], D[16]; - long d[2]; - int P; - long PC; + long d[2]; + int P; + long PC; unsigned char R0[16], R1[16], R2[16], R3[16], R4[16]; unsigned char IN[4]; unsigned char OUT[3]; - int CARRY; + int CARRY; unsigned char PSTAT[NR_PSTAT]; unsigned char XM, SB, SR, MP; unsigned char hexmode; - long rstk[NR_RSTK]; - short rstkp; + long rstk[NR_RSTK]; + short rstkp; old_keystate_t keybuf; unsigned char intenable; unsigned char int_pending; unsigned char kbd_ien; - long configs[NR_CONFIG]; - short daisy_state; - long ram32k; - long devices; + long configs[NR_CONFIG]; + short daisy_state; + long ram32k; + long devices; unsigned char disp_io; unsigned char contrast_ctrl; unsigned char disp_test; - unsigned int crc; + unsigned int crc; unsigned char power_status; unsigned char power_ctrl; unsigned char mode; @@ -144,18 +144,18 @@ typedef struct old_saturn_t { unsigned char lbr; unsigned char scratch; unsigned char base_nibble; - long disp_addr; - long line_offset; - long line_count; - long unknown; + long disp_addr; + long line_offset; + long line_count; + long unknown; unsigned char t1_ctrl; unsigned char t2_ctrl; - long menu_addr; - long unknown2; - int timer1; - long timer2; - long t1_instr; - long t2_instr; + long menu_addr; + long unknown2; + int timer1; + long timer2; + long t1_instr; + long t2_instr; unsigned char *rom; unsigned char *ram; unsigned char *port1; @@ -166,66 +166,66 @@ old_saturn_t old_saturn; typedef struct saturn_0_3_0_t { unsigned long magic; - char version[4]; + char version[4]; unsigned char A[16], B[16], C[16], D[16]; - word_20 d[2]; - word_4 P; - word_20 PC; + word_20 d[2]; + 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; + 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; + 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_20 configs[NR_CONFIG]; - word_16 daisy_state; - word_20 ram32k; - word_20 devices; - 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; - word_32 timer2; - long t1_instr; - long t2_instr; - short t1_tick; - short t2_tick; - long i_per_s; + word_20 configs[NR_CONFIG]; + word_16 daisy_state; + word_20 ram32k; + word_20 devices; + 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; + word_32 timer2; + long t1_instr; + long t2_instr; + short t1_tick; + short t2_tick; + long i_per_s; unsigned char *rom; unsigned char *ram; unsigned char *port1; @@ -272,17 +272,16 @@ void init_saturn(void) { saturn.timer1 = 0; saturn.timer2 = 0x2000; saturn.bank_switch = 0; - for (i = 0; i < NR_MCTL; i++) - { - if (i == 0) - saturn.mem_cntl[i].unconfigured = 1; - else if (i == 5) - saturn.mem_cntl[i].unconfigured = 0; - else - saturn.mem_cntl[i].unconfigured = 2; - saturn.mem_cntl[i].config[0] = 0; - saturn.mem_cntl[i].config[1] = 0; - } + for (i = 0; i < NR_MCTL; i++) { + if (i == 0) + saturn.mem_cntl[i].unconfigured = 1; + else if (i == 5) + saturn.mem_cntl[i].unconfigured = 0; + else + saturn.mem_cntl[i].unconfigured = 2; + saturn.mem_cntl[i].config[0] = 0; + saturn.mem_cntl[i].config[1] = 0; + } dev_memory_init(); } @@ -355,81 +354,66 @@ void copy_old_saturn(old_saturn_t *old, saturn_t *new) { new->t1_instr = old->t1_instr; new->t2_instr = old->t2_instr; new->bank_switch = 0; - if (opt_gx) - { + if (opt_gx) { + new->mem_cntl[0].unconfigured = 0; + new->mem_cntl[0].config[0] = 0x00100; + new->mem_cntl[1].unconfigured = 0; + new->mem_cntl[1].config[0] = 0x80000; + new->mem_cntl[1].config[1] = 0xc0000; + new->mem_cntl[2].unconfigured = 0; + new->mem_cntl[2].config[0] = 0x7f000; + new->mem_cntl[2].config[1] = 0xff000; + new->mem_cntl[3].unconfigured = 0; + new->mem_cntl[3].config[0] = 0xc0000; + new->mem_cntl[3].config[1] = 0xc0000; + new->mem_cntl[4].unconfigured = 0; + new->mem_cntl[4].config[0] = 0xc0000; + new->mem_cntl[4].config[1] = 0xc0000; + new->mem_cntl[5].unconfigured = 0; + new->mem_cntl[5].config[0] = 0x00000; + new->mem_cntl[5].config[1] = 0x00000; + } else { + if (old->devices == 0x100) { new->mem_cntl[0].unconfigured = 0; - new->mem_cntl[0].config[0] = 0x00100; + new->mem_cntl[0].config[0] = old->devices; + } else { + new->mem_cntl[0].unconfigured = 1; + new->mem_cntl[0].config[0] = 0x00000; + } + if (old->ram32k == 0x70000) { new->mem_cntl[1].unconfigured = 0; - new->mem_cntl[1].config[0] = 0x80000; - new->mem_cntl[1].config[1] = 0xc0000; - new->mem_cntl[2].unconfigured = 0; - new->mem_cntl[2].config[0] = 0x7f000; - new->mem_cntl[2].config[1] = 0xff000; - new->mem_cntl[3].unconfigured = 0; - new->mem_cntl[3].config[0] = 0xc0000; - new->mem_cntl[3].config[1] = 0xc0000; - new->mem_cntl[4].unconfigured = 0; - new->mem_cntl[4].config[0] = 0xc0000; - new->mem_cntl[4].config[1] = 0xc0000; - new->mem_cntl[5].unconfigured = 0; - new->mem_cntl[5].config[0] = 0x00000; - new->mem_cntl[5].config[1] = 0x00000; - } - else - { - if (old->devices == 0x100) - { - new->mem_cntl[0].unconfigured = 0; - new->mem_cntl[0].config[0] = old->devices; - } - else - { - new->mem_cntl[0].unconfigured = 1; - new->mem_cntl[0].config[0] = 0x00000; - } - if (old->ram32k == 0x70000) - { - new->mem_cntl[1].unconfigured = 0; - new->mem_cntl[1].config[0] = 0x70000; - new->mem_cntl[1].config[1] = 0xf0000; - } - else if (old->ram32k == 0xf0000) - { - new->mem_cntl[1].unconfigured = 0; - new->mem_cntl[1].config[0] = 0xf0000; - new->mem_cntl[1].config[1] = 0xf0000; - } - else if (old->ram32k == 0xfc000) - { - new->mem_cntl[1].unconfigured = 0; - new->mem_cntl[1].config[0] = 0x70000; - new->mem_cntl[1].config[1] = 0xfc000; - } - else if (old->ram32k == 0xfe000) - { - new->mem_cntl[1].unconfigured = 0; - new->mem_cntl[1].config[0] = 0x70000; - new->mem_cntl[1].config[1] = 0xfe000; - } - else - { - new->mem_cntl[1].unconfigured = 2; - new->mem_cntl[1].config[0] = 0x00000; - new->mem_cntl[1].config[1] = 0x00000; - } - new->mem_cntl[2].unconfigured = 0; - new->mem_cntl[2].config[0] = 0x80000; - new->mem_cntl[2].config[1] = 0xc0000; - new->mem_cntl[3].unconfigured = 0; - new->mem_cntl[3].config[0] = 0xc0000; - new->mem_cntl[3].config[1] = 0xc0000; - new->mem_cntl[4].unconfigured = 0; - new->mem_cntl[4].config[0] = 0xd0000; - new->mem_cntl[4].config[1] = 0xff000; - new->mem_cntl[5].unconfigured = 0; - new->mem_cntl[5].config[0] = 0x00000; - new->mem_cntl[5].config[1] = 0x80000; + new->mem_cntl[1].config[0] = 0x70000; + new->mem_cntl[1].config[1] = 0xf0000; + } else if (old->ram32k == 0xf0000) { + new->mem_cntl[1].unconfigured = 0; + new->mem_cntl[1].config[0] = 0xf0000; + new->mem_cntl[1].config[1] = 0xf0000; + } else if (old->ram32k == 0xfc000) { + new->mem_cntl[1].unconfigured = 0; + new->mem_cntl[1].config[0] = 0x70000; + new->mem_cntl[1].config[1] = 0xfc000; + } else if (old->ram32k == 0xfe000) { + new->mem_cntl[1].unconfigured = 0; + new->mem_cntl[1].config[0] = 0x70000; + new->mem_cntl[1].config[1] = 0xfe000; + } else { + new->mem_cntl[1].unconfigured = 2; + new->mem_cntl[1].config[0] = 0x00000; + new->mem_cntl[1].config[1] = 0x00000; } + new->mem_cntl[2].unconfigured = 0; + new->mem_cntl[2].config[0] = 0x80000; + new->mem_cntl[2].config[1] = 0xc0000; + new->mem_cntl[3].unconfigured = 0; + new->mem_cntl[3].config[0] = 0xc0000; + new->mem_cntl[3].config[1] = 0xc0000; + new->mem_cntl[4].unconfigured = 0; + new->mem_cntl[4].config[0] = 0xd0000; + new->mem_cntl[4].config[1] = 0xff000; + new->mem_cntl[5].unconfigured = 0; + new->mem_cntl[5].config[0] = 0x00000; + new->mem_cntl[5].config[1] = 0x80000; + } } void copy_0_3_0_saturn(saturn_0_3_0_t *old, saturn_t *new) { @@ -504,81 +488,66 @@ void copy_0_3_0_saturn(saturn_0_3_0_t *old, saturn_t *new) { new->t2_tick = old->t2_tick; new->i_per_s = old->i_per_s; new->bank_switch = 0; - if (opt_gx) - { + if (opt_gx) { + new->mem_cntl[0].unconfigured = 0; + new->mem_cntl[0].config[0] = 0x00100; + new->mem_cntl[1].unconfigured = 0; + new->mem_cntl[1].config[0] = 0x80000; + new->mem_cntl[1].config[1] = 0xc0000; + new->mem_cntl[2].unconfigured = 0; + new->mem_cntl[2].config[0] = 0x7f000; + new->mem_cntl[2].config[1] = 0xff000; + new->mem_cntl[3].unconfigured = 0; + new->mem_cntl[3].config[0] = 0xc0000; + new->mem_cntl[3].config[1] = 0xc0000; + new->mem_cntl[4].unconfigured = 0; + new->mem_cntl[4].config[0] = 0xc0000; + new->mem_cntl[4].config[1] = 0xc0000; + new->mem_cntl[5].unconfigured = 0; + new->mem_cntl[5].config[0] = 0x00000; + new->mem_cntl[5].config[1] = 0x00000; + } else { + if (old->devices == 0x100) { new->mem_cntl[0].unconfigured = 0; - new->mem_cntl[0].config[0] = 0x00100; + new->mem_cntl[0].config[0] = old->devices; + } else { + new->mem_cntl[0].unconfigured = 1; + new->mem_cntl[0].config[0] = 0x00000; + } + if (old->ram32k == 0x70000) { new->mem_cntl[1].unconfigured = 0; - new->mem_cntl[1].config[0] = 0x80000; - new->mem_cntl[1].config[1] = 0xc0000; - new->mem_cntl[2].unconfigured = 0; - new->mem_cntl[2].config[0] = 0x7f000; - new->mem_cntl[2].config[1] = 0xff000; - new->mem_cntl[3].unconfigured = 0; - new->mem_cntl[3].config[0] = 0xc0000; - new->mem_cntl[3].config[1] = 0xc0000; - new->mem_cntl[4].unconfigured = 0; - new->mem_cntl[4].config[0] = 0xc0000; - new->mem_cntl[4].config[1] = 0xc0000; - new->mem_cntl[5].unconfigured = 0; - new->mem_cntl[5].config[0] = 0x00000; - new->mem_cntl[5].config[1] = 0x00000; - } - else - { - if (old->devices == 0x100) - { - new->mem_cntl[0].unconfigured = 0; - new->mem_cntl[0].config[0] = old->devices; - } - else - { - new->mem_cntl[0].unconfigured = 1; - new->mem_cntl[0].config[0] = 0x00000; - } - if (old->ram32k == 0x70000) - { - new->mem_cntl[1].unconfigured = 0; - new->mem_cntl[1].config[0] = 0x70000; - new->mem_cntl[1].config[1] = 0xf0000; - } - else if (old->ram32k == 0xf0000) - { - new->mem_cntl[1].unconfigured = 0; - new->mem_cntl[1].config[0] = 0xf0000; - new->mem_cntl[1].config[1] = 0xf0000; - } - else if (old->ram32k == 0xfc000) - { - new->mem_cntl[1].unconfigured = 0; - new->mem_cntl[1].config[0] = 0x70000; - new->mem_cntl[1].config[1] = 0xfc000; - } - else if (old->ram32k == 0xfe000) - { - new->mem_cntl[1].unconfigured = 0; - new->mem_cntl[1].config[0] = 0x70000; - new->mem_cntl[1].config[1] = 0xfe000; - } - else - { - new->mem_cntl[1].unconfigured = 2; - new->mem_cntl[1].config[0] = 0x00000; - new->mem_cntl[1].config[1] = 0x00000; - } - new->mem_cntl[2].unconfigured = 0; - new->mem_cntl[2].config[0] = 0x80000; - new->mem_cntl[2].config[1] = 0xc0000; - new->mem_cntl[3].unconfigured = 0; - new->mem_cntl[3].config[0] = 0xc0000; - new->mem_cntl[3].config[1] = 0xc0000; - new->mem_cntl[4].unconfigured = 0; - new->mem_cntl[4].config[0] = 0xd0000; - new->mem_cntl[4].config[1] = 0xff000; - new->mem_cntl[5].unconfigured = 0; - new->mem_cntl[5].config[0] = 0x00000; - new->mem_cntl[5].config[1] = 0x80000; + new->mem_cntl[1].config[0] = 0x70000; + new->mem_cntl[1].config[1] = 0xf0000; + } else if (old->ram32k == 0xf0000) { + new->mem_cntl[1].unconfigured = 0; + new->mem_cntl[1].config[0] = 0xf0000; + new->mem_cntl[1].config[1] = 0xf0000; + } else if (old->ram32k == 0xfc000) { + new->mem_cntl[1].unconfigured = 0; + new->mem_cntl[1].config[0] = 0x70000; + new->mem_cntl[1].config[1] = 0xfc000; + } else if (old->ram32k == 0xfe000) { + new->mem_cntl[1].unconfigured = 0; + new->mem_cntl[1].config[0] = 0x70000; + new->mem_cntl[1].config[1] = 0xfe000; + } else { + new->mem_cntl[1].unconfigured = 2; + new->mem_cntl[1].config[0] = 0x00000; + new->mem_cntl[1].config[1] = 0x00000; } + new->mem_cntl[2].unconfigured = 0; + new->mem_cntl[2].config[0] = 0x80000; + new->mem_cntl[2].config[1] = 0xc0000; + new->mem_cntl[3].unconfigured = 0; + new->mem_cntl[3].config[0] = 0xc0000; + new->mem_cntl[3].config[1] = 0xc0000; + new->mem_cntl[4].unconfigured = 0; + new->mem_cntl[4].config[0] = 0xd0000; + new->mem_cntl[4].config[1] = 0xff000; + new->mem_cntl[5].unconfigured = 0; + new->mem_cntl[5].config[0] = 0x00000; + new->mem_cntl[5].config[1] = 0x80000; + } } int read_8(FILE *fp, word_8 *var) { @@ -655,7 +624,7 @@ int read_version_0_3_0_file(FILE *fp) { * version 0.3.x, read in the saturn_0_3_0_t struct */ for (i = 0; i < 16; i++) - if(!read_8(fp, &saturn_0_3_0.A[i])) + if (!read_8(fp, &saturn_0_3_0.A[i])) return 0; for (i = 0; i < 16; i++) if (!read_8(fp, &saturn_0_3_0.B[i])) @@ -666,10 +635,14 @@ int read_version_0_3_0_file(FILE *fp) { for (i = 0; i < 16; i++) if (!read_8(fp, &saturn_0_3_0.D[i])) return 0; - if (!read_32(fp, &saturn_0_3_0.d[0])) return 0; - if (!read_32(fp, &saturn_0_3_0.d[1])) return 0; - if (!read_8(fp, &saturn_0_3_0.P)) return 0; - if (!read_32(fp, &saturn_0_3_0.PC)) return 0; + if (!read_32(fp, &saturn_0_3_0.d[0])) + return 0; + if (!read_32(fp, &saturn_0_3_0.d[1])) + return 0; + if (!read_8(fp, &saturn_0_3_0.P)) + return 0; + if (!read_32(fp, &saturn_0_3_0.PC)) + return 0; for (i = 0; i < 16; i++) if (!read_8(fp, &saturn_0_3_0.R0[i])) return 0; @@ -692,69 +665,119 @@ int read_version_0_3_0_file(FILE *fp) { if (!read_8(fp, &saturn_0_3_0.OUT[i])) return 0; if (!read_8(fp, &saturn_0_3_0.CARRY)) - return 0; + return 0; for (i = 0; i < NR_PSTAT; i++) if (!read_8(fp, &saturn_0_3_0.PSTAT[i])) return 0; - if (!read_8(fp, &saturn_0_3_0.XM)) return 0; - if (!read_8(fp, &saturn_0_3_0.SB)) return 0; - if (!read_8(fp, &saturn_0_3_0.SR)) return 0; - if (!read_8(fp, &saturn_0_3_0.MP)) return 0; - if (!read_8(fp, &saturn_0_3_0.hexmode)) return 0; + if (!read_8(fp, &saturn_0_3_0.XM)) + return 0; + if (!read_8(fp, &saturn_0_3_0.SB)) + return 0; + if (!read_8(fp, &saturn_0_3_0.SR)) + return 0; + if (!read_8(fp, &saturn_0_3_0.MP)) + return 0; + if (!read_8(fp, &saturn_0_3_0.hexmode)) + return 0; for (i = 0; i < NR_RSTK; i++) if (!read_32(fp, &saturn_0_3_0.rstk[i])) return 0; - if (!read_16(fp, (word_16 *)&saturn_0_3_0.rstkp)) return 0; + if (!read_16(fp, (word_16 *)&saturn_0_3_0.rstkp)) + return 0; for (i = 0; i < 9; i++) if (!read_16(fp, (word_16 *)&saturn_0_3_0.keybuf.rows[i])) return 0; - if (!read_8(fp, &saturn_0_3_0.intenable)) return 0; - if (!read_8(fp, &saturn_0_3_0.int_pending)) return 0; - if (!read_8(fp, &saturn_0_3_0.kbd_ien)) return 0; + if (!read_8(fp, &saturn_0_3_0.intenable)) + return 0; + if (!read_8(fp, &saturn_0_3_0.int_pending)) + return 0; + if (!read_8(fp, &saturn_0_3_0.kbd_ien)) + return 0; for (i = 0; i < NR_CONFIG; i++) if (!read_32(fp, &saturn_0_3_0.configs[i])) return 0; - if (!read_16(fp, (word_16 *)&saturn_0_3_0.daisy_state)) return 0; - if (!read_32(fp, &saturn_0_3_0.ram32k)) return 0; - if (!read_32(fp, &saturn_0_3_0.devices)) return 0; - if (!read_8(fp, &saturn_0_3_0.disp_io)) return 0; - if (!read_8(fp, &saturn_0_3_0.contrast_ctrl)) return 0; - if (!read_8(fp, &saturn_0_3_0.disp_test)) return 0; - if (!read_16(fp, &saturn_0_3_0.crc)) return 0; - if (!read_8(fp, &saturn_0_3_0.power_status)) return 0; - if (!read_8(fp, &saturn_0_3_0.power_ctrl)) return 0; - if (!read_8(fp, &saturn_0_3_0.mode)) return 0; - if (!read_8(fp, &saturn_0_3_0.annunc)) return 0; - if (!read_8(fp, &saturn_0_3_0.baud)) return 0; - if (!read_8(fp, &saturn_0_3_0.card_ctrl)) return 0; - if (!read_8(fp, &saturn_0_3_0.card_status)) return 0; - if (!read_8(fp, &saturn_0_3_0.io_ctrl)) return 0; - if (!read_8(fp, &saturn_0_3_0.rcs)) return 0; - if (!read_8(fp, &saturn_0_3_0.tcs)) return 0; - if (!read_8(fp, &saturn_0_3_0.rbr)) return 0; - if (!read_8(fp, &saturn_0_3_0.tbr)) return 0; - if (!read_8(fp, &saturn_0_3_0.sreq)) return 0; - if (!read_8(fp, &saturn_0_3_0.ir_ctrl)) return 0; - if (!read_8(fp, &saturn_0_3_0.base_off)) return 0; - if (!read_8(fp, &saturn_0_3_0.lcr)) return 0; - if (!read_8(fp, &saturn_0_3_0.lbr)) return 0; - if (!read_8(fp, &saturn_0_3_0.scratch)) return 0; - if (!read_8(fp, &saturn_0_3_0.base_nibble)) return 0; - if (!read_32(fp, &saturn_0_3_0.disp_addr)) return 0; - if (!read_16(fp, &saturn_0_3_0.line_offset)) return 0; - if (!read_8(fp, &saturn_0_3_0.line_count)) return 0; - if (!read_16(fp, &saturn_0_3_0.unknown)) return 0; - if (!read_8(fp, &saturn_0_3_0.t1_ctrl)) return 0; - if (!read_8(fp, &saturn_0_3_0.t2_ctrl)) return 0; - if (!read_32(fp, &saturn_0_3_0.menu_addr)) return 0; - if (!read_8(fp, &saturn_0_3_0.unknown2)) return 0; - if (!read_char(fp, &saturn_0_3_0.timer1)) return 0; - if (!read_32(fp, &saturn_0_3_0.timer2)) return 0; - if (!read_32(fp, &saturn_0_3_0.t1_instr)) return 0; - if (!read_32(fp, &saturn_0_3_0.t2_instr)) return 0; - if (!read_16(fp, (word_16 *)&saturn_0_3_0.t1_tick)) return 0; - if (!read_16(fp, (word_16 *)&saturn_0_3_0.t2_tick)) return 0; - if (!read_32(fp, &saturn_0_3_0.i_per_s)) return 0; + if (!read_16(fp, (word_16 *)&saturn_0_3_0.daisy_state)) + return 0; + if (!read_32(fp, &saturn_0_3_0.ram32k)) + return 0; + if (!read_32(fp, &saturn_0_3_0.devices)) + return 0; + if (!read_8(fp, &saturn_0_3_0.disp_io)) + return 0; + if (!read_8(fp, &saturn_0_3_0.contrast_ctrl)) + return 0; + if (!read_8(fp, &saturn_0_3_0.disp_test)) + return 0; + if (!read_16(fp, &saturn_0_3_0.crc)) + return 0; + if (!read_8(fp, &saturn_0_3_0.power_status)) + return 0; + if (!read_8(fp, &saturn_0_3_0.power_ctrl)) + return 0; + if (!read_8(fp, &saturn_0_3_0.mode)) + return 0; + if (!read_8(fp, &saturn_0_3_0.annunc)) + return 0; + if (!read_8(fp, &saturn_0_3_0.baud)) + return 0; + if (!read_8(fp, &saturn_0_3_0.card_ctrl)) + return 0; + if (!read_8(fp, &saturn_0_3_0.card_status)) + return 0; + if (!read_8(fp, &saturn_0_3_0.io_ctrl)) + return 0; + if (!read_8(fp, &saturn_0_3_0.rcs)) + return 0; + if (!read_8(fp, &saturn_0_3_0.tcs)) + return 0; + if (!read_8(fp, &saturn_0_3_0.rbr)) + return 0; + if (!read_8(fp, &saturn_0_3_0.tbr)) + return 0; + if (!read_8(fp, &saturn_0_3_0.sreq)) + return 0; + if (!read_8(fp, &saturn_0_3_0.ir_ctrl)) + return 0; + if (!read_8(fp, &saturn_0_3_0.base_off)) + return 0; + if (!read_8(fp, &saturn_0_3_0.lcr)) + return 0; + if (!read_8(fp, &saturn_0_3_0.lbr)) + return 0; + if (!read_8(fp, &saturn_0_3_0.scratch)) + return 0; + if (!read_8(fp, &saturn_0_3_0.base_nibble)) + return 0; + if (!read_32(fp, &saturn_0_3_0.disp_addr)) + return 0; + if (!read_16(fp, &saturn_0_3_0.line_offset)) + return 0; + if (!read_8(fp, &saturn_0_3_0.line_count)) + return 0; + if (!read_16(fp, &saturn_0_3_0.unknown)) + return 0; + if (!read_8(fp, &saturn_0_3_0.t1_ctrl)) + return 0; + if (!read_8(fp, &saturn_0_3_0.t2_ctrl)) + return 0; + if (!read_32(fp, &saturn_0_3_0.menu_addr)) + return 0; + if (!read_8(fp, &saturn_0_3_0.unknown2)) + return 0; + if (!read_char(fp, &saturn_0_3_0.timer1)) + return 0; + if (!read_32(fp, &saturn_0_3_0.timer2)) + return 0; + if (!read_32(fp, &saturn_0_3_0.t1_instr)) + return 0; + if (!read_32(fp, &saturn_0_3_0.t2_instr)) + return 0; + if (!read_16(fp, (word_16 *)&saturn_0_3_0.t1_tick)) + return 0; + if (!read_16(fp, (word_16 *)&saturn_0_3_0.t2_tick)) + return 0; + if (!read_32(fp, &saturn_0_3_0.i_per_s)) + return 0; return 1; } @@ -765,7 +788,7 @@ int read_version_0_4_0_file(FILE *fp) { * version 0.4.x, read in the saturn_t struct */ for (i = 0; i < 16; i++) - if(!read_8(fp, &saturn.A[i])) + if (!read_8(fp, &saturn.A[i])) return 0; for (i = 0; i < 16; i++) if (!read_8(fp, &saturn.B[i])) @@ -776,10 +799,14 @@ int read_version_0_4_0_file(FILE *fp) { for (i = 0; i < 16; i++) if (!read_8(fp, &saturn.D[i])) return 0; - if (!read_32(fp, &saturn.d[0])) return 0; - if (!read_32(fp, &saturn.d[1])) return 0; - if (!read_8(fp, &saturn.P)) return 0; - if (!read_32(fp, &saturn.PC)) return 0; + if (!read_32(fp, &saturn.d[0])) + return 0; + if (!read_32(fp, &saturn.d[1])) + return 0; + if (!read_8(fp, &saturn.P)) + return 0; + if (!read_32(fp, &saturn.PC)) + return 0; for (i = 0; i < 16; i++) if (!read_8(fp, &saturn.R0[i])) return 0; @@ -802,70 +829,120 @@ int read_version_0_4_0_file(FILE *fp) { if (!read_8(fp, &saturn.OUT[i])) return 0; if (!read_8(fp, &saturn.CARRY)) - return 0; + return 0; for (i = 0; i < NR_PSTAT; i++) if (!read_8(fp, &saturn.PSTAT[i])) return 0; - if (!read_8(fp, &saturn.XM)) return 0; - if (!read_8(fp, &saturn.SB)) return 0; - if (!read_8(fp, &saturn.SR)) return 0; - if (!read_8(fp, &saturn.MP)) return 0; - if (!read_8(fp, &saturn.hexmode)) return 0; + if (!read_8(fp, &saturn.XM)) + return 0; + if (!read_8(fp, &saturn.SB)) + return 0; + if (!read_8(fp, &saturn.SR)) + return 0; + if (!read_8(fp, &saturn.MP)) + return 0; + if (!read_8(fp, &saturn.hexmode)) + return 0; for (i = 0; i < NR_RSTK; i++) if (!read_32(fp, &saturn.rstk[i])) return 0; - if (!read_16(fp, (word_16 *)&saturn.rstkp)) return 0; + if (!read_16(fp, (word_16 *)&saturn.rstkp)) + return 0; for (i = 0; i < 9; i++) if (!read_16(fp, (word_16 *)&saturn.keybuf.rows[i])) return 0; - if (!read_8(fp, &saturn.intenable)) return 0; - if (!read_8(fp, &saturn.int_pending)) return 0; - if (!read_8(fp, &saturn.kbd_ien)) return 0; - if (!read_8(fp, &saturn.disp_io)) return 0; - if (!read_8(fp, &saturn.contrast_ctrl)) return 0; - if (!read_8(fp, &saturn.disp_test)) return 0; - if (!read_16(fp, &saturn.crc)) return 0; - if (!read_8(fp, &saturn.power_status)) return 0; - if (!read_8(fp, &saturn.power_ctrl)) return 0; - if (!read_8(fp, &saturn.mode)) return 0; - if (!read_8(fp, &saturn.annunc)) return 0; - if (!read_8(fp, &saturn.baud)) return 0; - if (!read_8(fp, &saturn.card_ctrl)) return 0; - if (!read_8(fp, &saturn.card_status)) return 0; - if (!read_8(fp, &saturn.io_ctrl)) return 0; - if (!read_8(fp, &saturn.rcs)) return 0; - if (!read_8(fp, &saturn.tcs)) return 0; - if (!read_8(fp, &saturn.rbr)) return 0; - if (!read_8(fp, &saturn.tbr)) return 0; - if (!read_8(fp, &saturn.sreq)) return 0; - if (!read_8(fp, &saturn.ir_ctrl)) return 0; - if (!read_8(fp, &saturn.base_off)) return 0; - if (!read_8(fp, &saturn.lcr)) return 0; - if (!read_8(fp, &saturn.lbr)) return 0; - if (!read_8(fp, &saturn.scratch)) return 0; - if (!read_8(fp, &saturn.base_nibble)) return 0; - if (!read_32(fp, &saturn.disp_addr)) return 0; - if (!read_16(fp, &saturn.line_offset)) return 0; - if (!read_8(fp, &saturn.line_count)) return 0; - if (!read_16(fp, &saturn.unknown)) return 0; - if (!read_8(fp, &saturn.t1_ctrl)) return 0; - if (!read_8(fp, &saturn.t2_ctrl)) return 0; - if (!read_32(fp, &saturn.menu_addr)) return 0; - if (!read_8(fp, &saturn.unknown2)) return 0; - if (!read_char(fp, &saturn.timer1)) return 0; - if (!read_32(fp, &saturn.timer2)) return 0; - if (!read_32(fp, &saturn.t1_instr)) return 0; - if (!read_32(fp, &saturn.t2_instr)) return 0; - if (!read_16(fp, (word_16 *)&saturn.t1_tick)) return 0; - if (!read_16(fp, (word_16 *)&saturn.t2_tick)) return 0; - if (!read_32(fp, &saturn.i_per_s)) return 0; - if (!read_16(fp, (word_16 *)&saturn.bank_switch)) return 0; - for (i = 0; i < NR_MCTL; i++) - { - if (!read_16(fp, &saturn.mem_cntl[i].unconfigured)) return 0; - if (!read_32(fp, &saturn.mem_cntl[i].config[0])) return 0; - if (!read_32(fp, &saturn.mem_cntl[i].config[1])) return 0; - } + if (!read_8(fp, &saturn.intenable)) + return 0; + if (!read_8(fp, &saturn.int_pending)) + return 0; + if (!read_8(fp, &saturn.kbd_ien)) + return 0; + if (!read_8(fp, &saturn.disp_io)) + return 0; + if (!read_8(fp, &saturn.contrast_ctrl)) + return 0; + if (!read_8(fp, &saturn.disp_test)) + return 0; + if (!read_16(fp, &saturn.crc)) + return 0; + if (!read_8(fp, &saturn.power_status)) + return 0; + if (!read_8(fp, &saturn.power_ctrl)) + return 0; + if (!read_8(fp, &saturn.mode)) + return 0; + if (!read_8(fp, &saturn.annunc)) + return 0; + if (!read_8(fp, &saturn.baud)) + return 0; + if (!read_8(fp, &saturn.card_ctrl)) + return 0; + if (!read_8(fp, &saturn.card_status)) + return 0; + if (!read_8(fp, &saturn.io_ctrl)) + return 0; + if (!read_8(fp, &saturn.rcs)) + return 0; + if (!read_8(fp, &saturn.tcs)) + return 0; + if (!read_8(fp, &saturn.rbr)) + return 0; + if (!read_8(fp, &saturn.tbr)) + return 0; + if (!read_8(fp, &saturn.sreq)) + return 0; + if (!read_8(fp, &saturn.ir_ctrl)) + return 0; + if (!read_8(fp, &saturn.base_off)) + return 0; + if (!read_8(fp, &saturn.lcr)) + return 0; + if (!read_8(fp, &saturn.lbr)) + return 0; + if (!read_8(fp, &saturn.scratch)) + return 0; + if (!read_8(fp, &saturn.base_nibble)) + return 0; + if (!read_32(fp, &saturn.disp_addr)) + return 0; + if (!read_16(fp, &saturn.line_offset)) + return 0; + if (!read_8(fp, &saturn.line_count)) + return 0; + if (!read_16(fp, &saturn.unknown)) + return 0; + if (!read_8(fp, &saturn.t1_ctrl)) + return 0; + if (!read_8(fp, &saturn.t2_ctrl)) + return 0; + if (!read_32(fp, &saturn.menu_addr)) + return 0; + if (!read_8(fp, &saturn.unknown2)) + return 0; + if (!read_char(fp, &saturn.timer1)) + return 0; + if (!read_32(fp, &saturn.timer2)) + return 0; + if (!read_32(fp, &saturn.t1_instr)) + return 0; + if (!read_32(fp, &saturn.t2_instr)) + return 0; + if (!read_16(fp, (word_16 *)&saturn.t1_tick)) + return 0; + if (!read_16(fp, (word_16 *)&saturn.t2_tick)) + return 0; + if (!read_32(fp, &saturn.i_per_s)) + return 0; + if (!read_16(fp, (word_16 *)&saturn.bank_switch)) + return 0; + for (i = 0; i < NR_MCTL; i++) { + if (!read_16(fp, &saturn.mem_cntl[i].unconfigured)) + return 0; + if (!read_32(fp, &saturn.mem_cntl[i].config[0])) + return 0; + if (!read_32(fp, &saturn.mem_cntl[i].config[1])) + return 0; + } return 1; } @@ -876,83 +953,69 @@ int read_mem_file(char *name, word_4 *mem, int size) { word_8 byte; int i, j; - if (NULL == (fp = fopen(name, "r"))) - { + if (NULL == (fp = fopen(name, "r"))) { + if (!quiet) + fprintf(stderr, "%s: can\'t open %s\n", progname, name); + return 0; + } + + if (stat(name, &st) < 0) { + if (!quiet) + fprintf(stderr, "%s: can\'t stat %s\n", progname, name); + return 0; + } + + if (st.st_size == size) { + /* + * size is same as memory size, old version file + */ + if (fread(mem, 1, (size_t)size, fp) != size) { if (!quiet) - fprintf(stderr, "%s: can\'t open %s\n", progname, name); + fprintf(stderr, "%s: can\'t read %s\n", progname, name); + fclose(fp); + return 0; + } + } else { + /* + * size is different, check size and decompress memory + */ + + if (st.st_size != size / 2) { + if (!quiet) + fprintf(stderr, "%s: strange size %s, expected %d, found %ld\n", + progname, name, size / 2, st.st_size); + fclose(fp); return 0; } - if (stat(name, &st) < 0) - { - if (!quiet) - fprintf(stderr, "%s: can\'t stat %s\n", progname, name); - return 0; - } - - if (st.st_size == size) - { - /* - * size is same as memory size, old version file - */ - if (fread(mem, 1, (size_t)size, fp) != size) - { + if (NULL == (tmp_mem = (word_8 *)malloc((size_t)st.st_size))) { + for (i = 0, j = 0; i < size / 2; i++) { + if (1 != fread(&byte, 1, 1, fp)) { if (!quiet) fprintf(stderr, "%s: can\'t read %s\n", progname, name); fclose(fp); return 0; } + mem[j++] = (word_4)((int)byte & 0xf); + mem[j++] = (word_4)(((int)byte >> 4) & 0xf); + } + } else { + if (fread(tmp_mem, 1, (size_t)size / 2, fp) != size / 2) { + if (!quiet) + fprintf(stderr, "%s: can\'t read %s\n", progname, name); + fclose(fp); + free(tmp_mem); + return 0; + } + + for (i = 0, j = 0; i < size / 2; i++) { + mem[j++] = (word_4)((int)tmp_mem[i] & 0xf); + mem[j++] = (word_4)(((int)tmp_mem[i] >> 4) & 0xf); + } + + free(tmp_mem); } - else - { - /* - * size is different, check size and decompress memory - */ - - if (st.st_size != size / 2) - { - if (!quiet) - fprintf(stderr, "%s: strange size %s, expected %d, found %ld\n", - progname, name, size / 2, st.st_size); - fclose(fp); - return 0; - } - - if (NULL == (tmp_mem = (word_8 *)malloc((size_t)st.st_size))) - { - for (i = 0, j = 0; i < size / 2; i++) - { - if (1 != fread(&byte, 1, 1, fp)) - { - if (!quiet) - fprintf(stderr, "%s: can\'t read %s\n", progname, name); - fclose(fp); - return 0; - } - mem[j++] = (word_4)((int)byte & 0xf); - mem[j++] = (word_4)(((int)byte >> 4) & 0xf); - } - } - else - { - if (fread(tmp_mem, 1, (size_t)size / 2, fp) != size / 2) - { - if (!quiet) - fprintf(stderr, "%s: can\'t read %s\n", progname, name); - fclose(fp); - free(tmp_mem); - return 0; - } - - for (i = 0, j = 0; i < size / 2; i++) - { - mem[j++] = (word_4)((int)tmp_mem[i] & 0xf); - mem[j++] = (word_4)(((int)tmp_mem[i] >> 4) & 0xf); - } - - free(tmp_mem); - } - } + } fclose(fp); @@ -974,12 +1037,11 @@ int read_rom(const char *fname) { else ram_size = RAM_SIZE_SX; - if (NULL == (saturn.ram = (word_4 *)malloc(ram_size))) - { - if (!quiet) - fprintf(stderr, "%s: can\'t malloc RAM\n", progname); - return 0; - } + if (NULL == (saturn.ram = (word_4 *)malloc(ram_size))) { + if (!quiet) + fprintf(stderr, "%s: can\'t malloc RAM\n", progname); + return 0; + } memset(saturn.ram, 0, ram_size); @@ -999,50 +1061,41 @@ int read_rom(const char *fname) { } void get_home_directory(char *path) { - char *p; + char *p; struct passwd *pwd; - if (homeDirectory[0] == '/') - { - strcpy(path, homeDirectory); - } - else - { - p = getenv("HOME"); - if (p) - { - strcpy(path, p); - strcat(path, "/"); - } - else - { - pwd = getpwuid(getuid()); - if (pwd) - { - strcpy(path, pwd->pw_dir); - strcat(path, "/"); - } - else - { - if (!quiet) - fprintf(stderr, - "%s: can\'t figure out your home directory, trying /tmp\n", - progname); - strcpy(path, "/tmp"); - } - } - strcat(path, homeDirectory); + if (homeDirectory[0] == '/') { + strcpy(path, homeDirectory); + } else { + p = getenv("HOME"); + if (p) { + strcpy(path, p); + strcat(path, "/"); + } else { + pwd = getpwuid(getuid()); + if (pwd) { + strcpy(path, pwd->pw_dir); + strcat(path, "/"); + } else { + if (!quiet) + fprintf(stderr, + "%s: can\'t figure out your home directory, trying /tmp\n", + progname); + strcpy(path, "/tmp"); + } } + strcat(path, homeDirectory); + } } int read_files(void) { - char path[1024]; - char fnam[1024]; - unsigned long v1, v2; - int i, read_version; - int ram_size; - struct stat st; - FILE *fp; + char path[1024]; + char fnam[1024]; + unsigned long v1, v2; + int i, read_version; + int ram_size; + struct stat st; + FILE *fp; get_home_directory(path); strcat(path, "/"); @@ -1057,133 +1110,120 @@ int read_files(void) { strcpy(fnam, path); strcat(fnam, "hp48"); - if (NULL == (fp = fopen(fnam, "r"))) - { - if (!quiet) - fprintf(stderr, "%s: can\'t open %s\n", progname, fnam); - return 0; - } + if (NULL == (fp = fopen(fnam, "r"))) { + if (!quiet) + fprintf(stderr, "%s: can\'t open %s\n", progname, fnam); + return 0; + } /* * ok, file is open, try to read the MAGIC number */ read_u_long(fp, &saturn.magic); - if (X48_MAGIC != saturn.magic) - { + if (X48_MAGIC != saturn.magic) { + /* + * no MAGIC number, try to read old format file + */ + fseek(fp, 0, SEEK_SET); + if (fread((char *)&old_saturn, 1, sizeof(old_saturn), fp) == + sizeof(old_saturn)) { /* - * no MAGIC number, try to read old format file + * seems to work */ - fseek(fp, 0, SEEK_SET); - if (fread((char *)&old_saturn, 1, sizeof(old_saturn), fp) - == sizeof(old_saturn)) { - /* - * seems to work - */ - copy_old_saturn(&old_saturn, &saturn); - if (!quiet) - fprintf(stderr, "%s: %s seems to be an old version file\n", - progname, fnam); - saturn.magic = X48_MAGIC; - saturn.t1_tick = 8192; - saturn.t2_tick = 16; - saturn.i_per_s = 0; - saturn.version[0] = VERSION_MAJOR; - saturn.version[1] = VERSION_MINOR; - saturn.version[2] = PATCHLEVEL; - saturn.version[3] = COMPILE_VERSION; - } else { - /* - * no, initialize - */ - if (!quiet) - fprintf(stderr, "%s: can\'t handle %s\n", progname, fnam); - init_saturn(); - } + copy_old_saturn(&old_saturn, &saturn); + if (!quiet) + fprintf(stderr, "%s: %s seems to be an old version file\n", progname, + fnam); + saturn.magic = X48_MAGIC; + saturn.t1_tick = 8192; + saturn.t2_tick = 16; + saturn.i_per_s = 0; + saturn.version[0] = VERSION_MAJOR; + saturn.version[1] = VERSION_MINOR; + saturn.version[2] = PATCHLEVEL; + saturn.version[3] = COMPILE_VERSION; } else { /* - * MAGIC ok, read and compare the version + * no, initialize */ - read_version = 1; - for (i = 0; i < 4; i++) { - if (!read_char(fp, &saturn.version[i])) { - if (!quiet) - fprintf(stderr, "%s: can\'t read version\n", progname); - read_version = 0; - } + if (!quiet) + fprintf(stderr, "%s: can\'t handle %s\n", progname, fnam); + init_saturn(); + } + } else { + /* + * MAGIC ok, read and compare the version + */ + read_version = 1; + for (i = 0; i < 4; i++) { + if (!read_char(fp, &saturn.version[i])) { + if (!quiet) + fprintf(stderr, "%s: can\'t read version\n", progname); + read_version = 0; } + } if (read_version) { - v1 = ((int)saturn.version[0] & 0xff) << 24; - v1 |= ((int)saturn.version[1] & 0xff) << 16; - v1 |= ((int)saturn.version[2] & 0xff) << 8; - v1 |= ((int)saturn.version[3] & 0xff); - v2 = ((int)VERSION_MAJOR & 0xff) << 24; - v2 |= ((int)VERSION_MINOR & 0xff) << 16; - v2 |= ((int)PATCHLEVEL & 0xff) << 8; - v2 |= ((int)COMPILE_VERSION & 0xff); + v1 = ((int)saturn.version[0] & 0xff) << 24; + v1 |= ((int)saturn.version[1] & 0xff) << 16; + v1 |= ((int)saturn.version[2] & 0xff) << 8; + v1 |= ((int)saturn.version[3] & 0xff); + v2 = ((int)VERSION_MAJOR & 0xff) << 24; + v2 |= ((int)VERSION_MINOR & 0xff) << 16; + v2 |= ((int)PATCHLEVEL & 0xff) << 8; + v2 |= ((int)COMPILE_VERSION & 0xff); - if ((v1 & 0xffffff00) < (v2 & 0xffffff00)) { - if (!quiet) - fprintf(stderr, "%s: %s is a version %d.%d.%d file, converting\n", - progname, fnam, - saturn.version[0], saturn.version[1], saturn.version[2]); - } else if ((v2 & 0xffffff00) < (v1 & 0xffffff00)) { - if (!quiet) - fprintf(stderr, "%s: %s is a version %d.%d.%d file, trying ...\n", - progname, fnam, - saturn.version[0], saturn.version[1], saturn.version[2]); - } + if ((v1 & 0xffffff00) < (v2 & 0xffffff00)) { + if (!quiet) + fprintf(stderr, "%s: %s is a version %d.%d.%d file, converting\n", + progname, fnam, saturn.version[0], saturn.version[1], + saturn.version[2]); + } else if ((v2 & 0xffffff00) < (v1 & 0xffffff00)) { + if (!quiet) + fprintf(stderr, "%s: %s is a version %d.%d.%d file, trying ...\n", + progname, fnam, saturn.version[0], saturn.version[1], + saturn.version[2]); + } - if (v1 < 0x00040000) - { - /* - * read version < 0.4 file - */ - if (!read_version_0_3_0_file(fp)) - { - if (!quiet) - fprintf(stderr, "%s: can\'t handle %s\n", progname, fnam); - init_saturn(); - } - else - { - copy_0_3_0_saturn(&saturn_0_3_0, &saturn); - if (verbose) - printf("%s: read %s\n", progname, fnam); - } - } - else if (v1 <= v2) { - /* - * read latest version file - */ - if (!read_version_0_4_0_file(fp)) - { - if (!quiet) - fprintf(stderr, "%s: can\'t handle %s\n", progname, fnam); - init_saturn(); - } - else if (verbose) - { - printf("%s: read %s\n", progname, fnam); - } + if (v1 < 0x00040000) { + /* + * read version < 0.4 file + */ + if (!read_version_0_3_0_file(fp)) { + if (!quiet) + fprintf(stderr, "%s: can\'t handle %s\n", progname, fnam); + init_saturn(); } else { - /* - * try to read latest version file - */ - if (!read_version_0_4_0_file(fp)) - { - if (!quiet) - fprintf(stderr, "%s: can\'t handle %s\n", progname, fnam); - init_saturn(); - } - else if (verbose) - { - printf("%s: read %s\n", progname, fnam); - } + copy_0_3_0_saturn(&saturn_0_3_0, &saturn); + if (verbose) + printf("%s: read %s\n", progname, fnam); + } + } else if (v1 <= v2) { + /* + * read latest version file + */ + if (!read_version_0_4_0_file(fp)) { + if (!quiet) + fprintf(stderr, "%s: can\'t handle %s\n", progname, fnam); + init_saturn(); + } else if (verbose) { + printf("%s: read %s\n", progname, fnam); + } + } else { + /* + * try to read latest version file + */ + if (!read_version_0_4_0_file(fp)) { + if (!quiet) + fprintf(stderr, "%s: can\'t handle %s\n", progname, fnam); + init_saturn(); + } else if (verbose) { + printf("%s: read %s\n", progname, fnam); } } } + } fclose(fp); dev_memory_init(); @@ -1196,13 +1236,11 @@ int read_files(void) { ram_size = RAM_SIZE_SX; saturn.ram = (word_4 *)NULL; - if (NULL == (saturn.ram = (word_4 *)malloc(ram_size))) - { - if (!quiet) - fprintf(stderr, "%s: can\'t malloc RAM[%d]\n", - progname, ram_size); - exit (1); - } + if (NULL == (saturn.ram = (word_4 *)malloc(ram_size))) { + if (!quiet) + fprintf(stderr, "%s: can\'t malloc RAM[%d]\n", progname, ram_size); + exit(1); + } strcpy(fnam, path); strcat(fnam, "ram"); @@ -1223,40 +1261,30 @@ int read_files(void) { strcpy(fnam, path); strcat(fnam, "port1"); - if (stat(fnam, &st) >= 0) - { - port1_size = 2 * st.st_size; - if ((port1_size == 0x10000) || (port1_size == 0x40000)) - { - if (NULL == (saturn.port1 = (word_4 *)malloc(port1_size))) - { - if (!quiet) - fprintf(stderr, "%s: can\'t malloc PORT1[%ld]\n", - progname, port1_size); - } - else if (!read_mem_file(fnam, saturn.port1, port1_size)) - { - port1_size = 0; - port1_is_ram = 0; - } - else - { - port1_is_ram = (st.st_mode & S_IWUSR) ? 1 : 0; - port1_mask = port1_size - 1; - } - } + if (stat(fnam, &st) >= 0) { + port1_size = 2 * st.st_size; + if ((port1_size == 0x10000) || (port1_size == 0x40000)) { + if (NULL == (saturn.port1 = (word_4 *)malloc(port1_size))) { + if (!quiet) + fprintf(stderr, "%s: can\'t malloc PORT1[%ld]\n", progname, + port1_size); + } else if (!read_mem_file(fnam, saturn.port1, port1_size)) { + port1_size = 0; + port1_is_ram = 0; + } else { + port1_is_ram = (st.st_mode & S_IWUSR) ? 1 : 0; + port1_mask = port1_size - 1; + } } + } - if (opt_gx) - { - saturn.card_status |= (port1_size > 0) ? 2 : 0; - saturn.card_status |= port1_is_ram ? 8 : 0; - } - else - { - saturn.card_status |= (port1_size > 0) ? 1 : 0; - saturn.card_status |= port1_is_ram ? 4 : 0; - } + if (opt_gx) { + saturn.card_status |= (port1_size > 0) ? 2 : 0; + saturn.card_status |= port1_is_ram ? 8 : 0; + } else { + saturn.card_status |= (port1_size > 0) ? 1 : 0; + saturn.card_status |= port1_is_ram ? 4 : 0; + } port2_size = 0; port2_mask = 0; @@ -1265,41 +1293,31 @@ int read_files(void) { strcpy(fnam, path); strcat(fnam, "port2"); - if (stat(fnam, &st) >= 0) - { - port2_size = 2 * st.st_size; - if ((opt_gx && ((port2_size % 0x40000) == 0)) || - (!opt_gx && ((port2_size == 0x10000) || (port2_size == 0x40000)))) - { - if (NULL == (saturn.port2 = (word_4 *)malloc(port2_size))) - { - if (!quiet) - fprintf(stderr, "%s: can\'t malloc PORT2[%ld]\n", - progname, port2_size); - } - else if (!read_mem_file(fnam, saturn.port2, port2_size)) - { - port2_size = 0; - port2_is_ram = 0; - } - else - { - port2_is_ram = (st.st_mode & S_IWUSR) ? 1 : 0; - port2_mask = port2_size - 1; - } - } + if (stat(fnam, &st) >= 0) { + port2_size = 2 * st.st_size; + if ((opt_gx && ((port2_size % 0x40000) == 0)) || + (!opt_gx && ((port2_size == 0x10000) || (port2_size == 0x40000)))) { + if (NULL == (saturn.port2 = (word_4 *)malloc(port2_size))) { + if (!quiet) + fprintf(stderr, "%s: can\'t malloc PORT2[%ld]\n", progname, + port2_size); + } else if (!read_mem_file(fnam, saturn.port2, port2_size)) { + port2_size = 0; + port2_is_ram = 0; + } else { + port2_is_ram = (st.st_mode & S_IWUSR) ? 1 : 0; + port2_mask = port2_size - 1; + } } + } - if (opt_gx) - { - saturn.card_status |= (port2_size > 0) ? 1 : 0; - saturn.card_status |= port2_is_ram ? 4 : 0; - } - else - { - saturn.card_status |= (port2_size > 0) ? 2 : 0; - saturn.card_status |= port2_is_ram ? 8 : 0; - } + if (opt_gx) { + saturn.card_status |= (port2_size > 0) ? 1 : 0; + saturn.card_status |= port2_is_ram ? 4 : 0; + } else { + saturn.card_status |= (port2_size > 0) ? 2 : 0; + saturn.card_status |= port2_is_ram ? 8 : 0; + } return 1; } @@ -1377,47 +1395,39 @@ int write_mem_file(char *name, word_4 *mem, int size) { word_8 byte; int i, j; - if (NULL == (fp = fopen(name, "w"))) - { + if (NULL == (fp = fopen(name, "w"))) { + if (!quiet) + fprintf(stderr, "%s: can\'t open %s\n", progname, name); + return 0; + } + + if (NULL == (tmp_mem = (word_8 *)malloc((size_t)size / 2))) { + for (i = 0, j = 0; i < size / 2; i++) { + byte = (mem[j++] & 0x0f); + byte |= (mem[j++] << 4) & 0xf0; + if (1 != fwrite(&byte, 1, 1, fp)) { + if (!quiet) + fprintf(stderr, "%s: can\'t write %s\n", progname, name); + fclose(fp); + return 0; + } + } + } else { + for (i = 0, j = 0; i < size / 2; i++) { + tmp_mem[i] = (mem[j++] & 0x0f); + tmp_mem[i] |= (mem[j++] << 4) & 0xf0; + } + + if (fwrite(tmp_mem, 1, (size_t)size / 2, fp) != size / 2) { if (!quiet) - fprintf(stderr, "%s: can\'t open %s\n", progname, name); + fprintf(stderr, "%s: can\'t write %s\n", progname, name); + fclose(fp); + free(tmp_mem); return 0; } - if (NULL == (tmp_mem = (word_8 *)malloc((size_t)size / 2))) - { - for (i = 0, j = 0; i < size / 2; i++) - { - byte = (mem[j++] & 0x0f); - byte |= (mem[j++] << 4) & 0xf0; - if (1 != fwrite(&byte, 1, 1, fp)) - { - if (!quiet) - fprintf(stderr, "%s: can\'t write %s\n", progname, name); - fclose(fp); - return 0; - } - } - } - else - { - for (i = 0, j = 0; i < size / 2; i++) - { - tmp_mem[i] = (mem[j++] & 0x0f); - tmp_mem[i] |= (mem[j++] << 4) & 0xf0; - } - - if (fwrite(tmp_mem, 1, (size_t)size / 2, fp) != size / 2) - { - if (!quiet) - fprintf(stderr, "%s: can\'t write %s\n", progname, name); - fclose(fp); - free(tmp_mem); - return 0; - } - - free(tmp_mem); - } + free(tmp_mem); + } fclose(fp); @@ -1427,7 +1437,6 @@ int write_mem_file(char *name, word_4 *mem, int size) { return 1; } - int write_files(void) { char path[1024]; char fnam[1024]; @@ -1439,41 +1448,31 @@ int write_files(void) { make_dir = 0; get_home_directory(path); - if (stat(path, &st) == -1) - { - if (errno == ENOENT) - { - make_dir = 1; - } - else - { - if (!quiet) - fprintf(stderr, "%s: can\'t stat %s, saving to /tmp\n", - progname, path); - strcpy(path, "/tmp"); - } + if (stat(path, &st) == -1) { + if (errno == ENOENT) { + make_dir = 1; + } else { + if (!quiet) + fprintf(stderr, "%s: can\'t stat %s, saving to /tmp\n", progname, path); + strcpy(path, "/tmp"); } - else - { - if (!S_ISDIR(st.st_mode)) - { - if (!quiet) - fprintf(stderr, "%s: %s is no directory, saving to /tmp\n", - progname, path); - strcpy(path, "/tmp"); - } + } else { + if (!S_ISDIR(st.st_mode)) { + if (!quiet) + fprintf(stderr, "%s: %s is no directory, saving to /tmp\n", progname, + path); + strcpy(path, "/tmp"); } + } - if (make_dir) - { - if (mkdir(path, 0777) == -1) - { - if (!quiet) - fprintf(stderr, "%s: can\'t mkdir %s, saving to /tmp\n", - progname, path); - strcpy(path, "/tmp"); - } + if (make_dir) { + if (mkdir(path, 0777) == -1) { + if (!quiet) + fprintf(stderr, "%s: can\'t mkdir %s, saving to /tmp\n", progname, + path); + strcpy(path, "/tmp"); } + } strcat(path, "/"); @@ -1481,8 +1480,7 @@ int write_files(void) { strcat(fnam, "hp48"); if ((fp = fopen(fnam, "w")) == NULL) { if (!quiet) - fprintf(stderr, "%s: can\'t open %s, no saving done\n", - progname, fnam); + fprintf(stderr, "%s: can\'t open %s, no saving done\n", progname, fnam); return 0; } @@ -1490,32 +1488,47 @@ int write_files(void) { * write the hp48 config file */ write_32(fp, (word_32 *)&saturn.magic); - for (i = 0; i < 4; i++) write_char(fp, &saturn.version[i]); - for (i = 0; i < 16; i++) write_8(fp, &saturn.A[i]); - for (i = 0; i < 16; i++) write_8(fp, &saturn.B[i]); - for (i = 0; i < 16; i++) write_8(fp, &saturn.C[i]); - for (i = 0; i < 16; i++) write_8(fp, &saturn.D[i]); + for (i = 0; i < 4; i++) + write_char(fp, &saturn.version[i]); + for (i = 0; i < 16; i++) + write_8(fp, &saturn.A[i]); + for (i = 0; i < 16; i++) + write_8(fp, &saturn.B[i]); + for (i = 0; i < 16; i++) + write_8(fp, &saturn.C[i]); + for (i = 0; i < 16; i++) + write_8(fp, &saturn.D[i]); write_32(fp, &saturn.d[0]); write_32(fp, &saturn.d[1]); write_8(fp, &saturn.P); write_32(fp, &saturn.PC); - for (i = 0; i < 16; i++) write_8(fp, &saturn.R0[i]); - for (i = 0; i < 16; i++) write_8(fp, &saturn.R1[i]); - for (i = 0; i < 16; i++) write_8(fp, &saturn.R2[i]); - for (i = 0; i < 16; i++) write_8(fp, &saturn.R3[i]); - for (i = 0; i < 16; i++) write_8(fp, &saturn.R4[i]); - for (i = 0; i < 4; i++) write_8(fp, &saturn.IN[i]); - for (i = 0; i < 3; i++) write_8(fp, &saturn.OUT[i]); + for (i = 0; i < 16; i++) + write_8(fp, &saturn.R0[i]); + for (i = 0; i < 16; i++) + write_8(fp, &saturn.R1[i]); + for (i = 0; i < 16; i++) + write_8(fp, &saturn.R2[i]); + for (i = 0; i < 16; i++) + write_8(fp, &saturn.R3[i]); + for (i = 0; i < 16; i++) + write_8(fp, &saturn.R4[i]); + for (i = 0; i < 4; i++) + write_8(fp, &saturn.IN[i]); + for (i = 0; i < 3; i++) + write_8(fp, &saturn.OUT[i]); write_8(fp, &saturn.CARRY); - for (i = 0; i < NR_PSTAT; i++) write_8(fp, &saturn.PSTAT[i]); + for (i = 0; i < NR_PSTAT; i++) + write_8(fp, &saturn.PSTAT[i]); write_8(fp, &saturn.XM); write_8(fp, &saturn.SB); write_8(fp, &saturn.SR); write_8(fp, &saturn.MP); write_8(fp, &saturn.hexmode); - for (i = 0; i < NR_RSTK; i++) write_32(fp, &saturn.rstk[i]); + for (i = 0; i < NR_RSTK; i++) + write_32(fp, &saturn.rstk[i]); write_16(fp, (word_16 *)&saturn.rstkp); - for (i = 0; i < 9; i++) write_16(fp, (word_16 *)&saturn.keybuf.rows[i]); + for (i = 0; i < 9; i++) + write_16(fp, (word_16 *)&saturn.keybuf.rows[i]); write_8(fp, &saturn.intenable); write_8(fp, &saturn.int_pending); write_8(fp, &saturn.kbd_ien); @@ -1558,23 +1571,21 @@ int write_files(void) { write_16(fp, (word_16 *)&saturn.t2_tick); write_32(fp, &saturn.i_per_s); write_16(fp, &saturn.bank_switch); - for (i = 0; i < NR_MCTL; i++) - { - write_16(fp, &saturn.mem_cntl[i].unconfigured); - write_32(fp, &saturn.mem_cntl[i].config[0]); - write_32(fp, &saturn.mem_cntl[i].config[1]); - } + for (i = 0; i < NR_MCTL; i++) { + write_16(fp, &saturn.mem_cntl[i].unconfigured); + write_32(fp, &saturn.mem_cntl[i].config[0]); + write_32(fp, &saturn.mem_cntl[i].config[1]); + } fclose(fp); if (verbose) printf("%s: wrote %s\n", progname, fnam); - if (rom_is_new) - { - strcpy(fnam, path); - strcat(fnam, "rom"); - if (!write_mem_file(fnam, saturn.rom, rom_size)) - return 0; - } + if (rom_is_new) { + strcpy(fnam, path); + strcat(fnam, "rom"); + if (!write_mem_file(fnam, saturn.rom, rom_size)) + return 0; + } if (opt_gx) ram_size = RAM_SIZE_GX; @@ -1586,33 +1597,30 @@ int write_files(void) { if (!write_mem_file(fnam, saturn.ram, ram_size)) return 0; - if ((port1_size > 0) && port1_is_ram) - { - strcpy(fnam, path); - strcat(fnam, "port1"); - if (!write_mem_file(fnam, saturn.port1, port1_size)) - return 0; - } + if ((port1_size > 0) && port1_is_ram) { + strcpy(fnam, path); + strcat(fnam, "port1"); + if (!write_mem_file(fnam, saturn.port1, port1_size)) + return 0; + } - if ((port2_size > 0) && port2_is_ram) - { - strcpy(fnam, path); - strcat(fnam, "port2"); - if (!write_mem_file(fnam, saturn.port2, port2_size)) - return 0; - } + if ((port2_size > 0) && port2_is_ram) { + strcpy(fnam, path); + strcat(fnam, "port2"); + if (!write_mem_file(fnam, saturn.port2, port2_size)) + return 0; + } return 1; } -int init_emulator(void) { +int init_emulator(void) { if (!initialize) - if (read_files()) - { - if (resetOnStartup) - saturn.PC = 0x00000; - return 0; - } + if (read_files()) { + if (resetOnStartup) + saturn.PC = 0x00000; + return 0; + } init_saturn(); if (!read_rom(romFileName)) diff --git a/src/lcd.c b/src/lcd.c index b6d7df4..f9219db 100644 --- a/src/lcd.c +++ b/src/lcd.c @@ -60,55 +60,53 @@ * $Id: lcd.c,v 1.13 1995/01/11 18:20:01 ecd Exp ecd $ */ - #include "global.h" #include -#include #include +#include #ifdef SUNOS #include #endif #include #include +#include "annunc.h" +#include "device.h" #include "hp48.h" #include "hp48_emu.h" #include "x48_x11.h" -#include "annunc.h" -#include "device.h" static int last_annunc_state = -1; display_t display; -#define DISP_ROWS 64 +#define DISP_ROWS 64 -#define NIBS_PER_BUFFER_ROW (NIBBLES_PER_ROW + 2) +#define NIBS_PER_BUFFER_ROW (NIBBLES_PER_ROW + 2) unsigned char disp_buf[DISP_ROWS][NIBS_PER_BUFFER_ROW]; unsigned char lcd_buffer[DISP_ROWS][NIBS_PER_BUFFER_ROW]; Pixmap nibble_maps[16]; -unsigned char nibbles[16][2] = -{ - { 0x00, 0x00 }, /* ---- */ - { 0x03, 0x03 }, /* *--- */ - { 0x0c, 0x0c }, /* -*-- */ - { 0x0f, 0x0f }, /* **-- */ - { 0x30, 0x30 }, /* --*- */ - { 0x33, 0x33 }, /* *-*- */ - { 0x3c, 0x3c }, /* -**- */ - { 0x3f, 0x3f }, /* ***- */ - { 0xc0, 0xc0 }, /* ---* */ - { 0xc3, 0xc3 }, /* *--* */ - { 0xcc, 0xcc }, /* -*-* */ - { 0xcf, 0xcf }, /* **-* */ - { 0xf0, 0xf0 }, /* --** */ - { 0xf3, 0xf3 }, /* *-** */ - { 0xfc, 0xfc }, /* -*** */ - { 0xff, 0xff } /* **** */ +unsigned char nibbles[16][2] = { + {0x00, 0x00}, /* ---- */ + {0x03, 0x03}, /* *--- */ + {0x0c, 0x0c}, /* -*-- */ + {0x0f, 0x0f}, /* **-- */ + {0x30, 0x30}, /* --*- */ + {0x33, 0x33}, /* *-*- */ + {0x3c, 0x3c}, /* -**- */ + {0x3f, 0x3f}, /* ***- */ + {0xc0, 0xc0}, /* ---* */ + {0xc3, 0xc3}, /* *--* */ + {0xcc, 0xcc}, /* -*-* */ + {0xcf, 0xcf}, /* **-* */ + {0xf0, 0xf0}, /* --** */ + {0xf3, 0xf3}, /* *-** */ + {0xfc, 0xfc}, /* -*** */ + {0xff, 0xff} /* **** */ }; static unsigned char nibble_bits[16]; @@ -117,45 +115,45 @@ void init_nibble_maps(void) { int i; for (i = 0; i < 16; i++) { - nibble_maps[i] = XCreateBitmapFromData(dpy, disp.win, - (char *)nibbles[i], 8, 2); + nibble_maps[i] = + XCreateBitmapFromData(dpy, disp.win, (char *)nibbles[i], 8, 2); } #ifdef HAVE_XSHM if (shm_flag) { if (disp.disp_image->bitmap_bit_order == MSBFirst) { - nibble_bits[0x0] = 0x00; /* ---- */ - nibble_bits[0x1] = 0xc0; /* *--- */ - nibble_bits[0x2] = 0x30; /* -*-- */ - nibble_bits[0x3] = 0xf0; /* **-- */ - nibble_bits[0x4] = 0x0c; /* --*- */ - nibble_bits[0x5] = 0xcc; /* *-*- */ - nibble_bits[0x6] = 0x3c; /* -**- */ - nibble_bits[0x7] = 0xfc; /* ***- */ - nibble_bits[0x8] = 0x03; /* ---* */ - nibble_bits[0x9] = 0xc3; /* *--* */ - nibble_bits[0xa] = 0x33; /* -*-* */ - nibble_bits[0xb] = 0xf3; /* **-* */ - nibble_bits[0xc] = 0x0f; /* --** */ - nibble_bits[0xd] = 0xcf; /* *-** */ - nibble_bits[0xe] = 0x3f; /* -*** */ - nibble_bits[0xf] = 0xff; /* **** */ + nibble_bits[0x0] = 0x00; /* ---- */ + nibble_bits[0x1] = 0xc0; /* *--- */ + nibble_bits[0x2] = 0x30; /* -*-- */ + nibble_bits[0x3] = 0xf0; /* **-- */ + nibble_bits[0x4] = 0x0c; /* --*- */ + nibble_bits[0x5] = 0xcc; /* *-*- */ + nibble_bits[0x6] = 0x3c; /* -**- */ + nibble_bits[0x7] = 0xfc; /* ***- */ + nibble_bits[0x8] = 0x03; /* ---* */ + nibble_bits[0x9] = 0xc3; /* *--* */ + nibble_bits[0xa] = 0x33; /* -*-* */ + nibble_bits[0xb] = 0xf3; /* **-* */ + nibble_bits[0xc] = 0x0f; /* --** */ + nibble_bits[0xd] = 0xcf; /* *-** */ + nibble_bits[0xe] = 0x3f; /* -*** */ + nibble_bits[0xf] = 0xff; /* **** */ } else { - nibble_bits[0x0] = 0x00; /* ---- */ - nibble_bits[0x1] = 0x03; /* *--- */ - nibble_bits[0x2] = 0x0c; /* -*-- */ - nibble_bits[0x3] = 0x0f; /* **-- */ - nibble_bits[0x4] = 0x30; /* --*- */ - nibble_bits[0x5] = 0x33; /* *-*- */ - nibble_bits[0x6] = 0x3c; /* -**- */ - nibble_bits[0x7] = 0x3f; /* ***- */ - nibble_bits[0x8] = 0xc0; /* ---* */ - nibble_bits[0x9] = 0xc3; /* *--* */ - nibble_bits[0xa] = 0xcc; /* -*-* */ - nibble_bits[0xb] = 0xcf; /* **-* */ - nibble_bits[0xc] = 0xf0; /* --** */ - nibble_bits[0xd] = 0xf3; /* *-** */ - nibble_bits[0xe] = 0xfc; /* -*** */ - nibble_bits[0xf] = 0xff; /* **** */ + nibble_bits[0x0] = 0x00; /* ---- */ + nibble_bits[0x1] = 0x03; /* *--- */ + nibble_bits[0x2] = 0x0c; /* -*-- */ + nibble_bits[0x3] = 0x0f; /* **-- */ + nibble_bits[0x4] = 0x30; /* --*- */ + nibble_bits[0x5] = 0x33; /* *-*- */ + nibble_bits[0x6] = 0x3c; /* -**- */ + nibble_bits[0x7] = 0x3f; /* ***- */ + nibble_bits[0x8] = 0xc0; /* ---* */ + nibble_bits[0x9] = 0xc3; /* *--* */ + nibble_bits[0xa] = 0xcc; /* -*-* */ + nibble_bits[0xb] = 0xcf; /* **-* */ + nibble_bits[0xc] = 0xf0; /* --** */ + nibble_bits[0xd] = 0xf3; /* *-** */ + nibble_bits[0xe] = 0xfc; /* -*** */ + nibble_bits[0xf] = 0xff; /* **** */ } } #endif @@ -176,12 +174,12 @@ void init_display(void) { disp.lines = 110; if (display.offset > 3) - display.nibs_per_line = (NIBBLES_PER_ROW+saturn.line_offset+2) & 0xfff; + display.nibs_per_line = (NIBBLES_PER_ROW + saturn.line_offset + 2) & 0xfff; else - display.nibs_per_line = (NIBBLES_PER_ROW+saturn.line_offset) & 0xfff; + display.nibs_per_line = (NIBBLES_PER_ROW + saturn.line_offset) & 0xfff; - display.disp_end = display.disp_start + - (display.nibs_per_line * (display.lines + 1)); + display.disp_end = + display.disp_start + (display.nibs_per_line * (display.lines + 1)); display.menu_start = saturn.menu_addr; display.menu_end = saturn.menu_addr + 0x110; @@ -238,11 +236,10 @@ void update_display(void) { word_20 data_addr, data_addr_2; #endif - if (!disp.mapped) - { - refresh_icon(); - return; - } + if (!disp.mapped) { + refresh_icon(); + return; + } if (display.on) { addr = display.disp_start; #ifdef HAVE_XSHM @@ -269,9 +266,9 @@ void update_display(void) { #endif if (display.offset != old_offset) { memset(disp_buf, 0xf0, - (size_t)((display.lines+1) * NIBS_PER_BUFFER_ROW)); + (size_t)((display.lines + 1) * NIBS_PER_BUFFER_ROW)); memset(lcd_buffer, 0xf0, - (size_t)((display.lines+1) * NIBS_PER_BUFFER_ROW)); + (size_t)((display.lines + 1) * NIBS_PER_BUFFER_ROW)); old_offset = display.offset; } if (display.lines != old_lines) { @@ -316,9 +313,11 @@ void update_display(void) { } else { #ifdef HAVE_XSHM if (shm_flag) { - memset(disp.disp_image->data, 0, + memset( + disp.disp_image->data, 0, (size_t)(disp.disp_image->bytes_per_line * disp.disp_image->height)); - memset(disp.menu_image->data, 0, + memset( + disp.menu_image->data, 0, (size_t)(disp.menu_image->bytes_per_line * disp.menu_image->height)); disp.display_update = UPDATE_DISP | UPDATE_MENU; } else { @@ -361,8 +360,8 @@ void disp_draw_nibble(word_20 addr, word_4 val) { if (shm_flag) { shm_addr = (2 * y * disp.disp_image->bytes_per_line) + x; disp.disp_image->data[shm_addr] = nibble_bits[val]; - disp.disp_image->data[shm_addr+disp.disp_image->bytes_per_line] = - nibble_bits[val]; + disp.disp_image->data[shm_addr + disp.disp_image->bytes_per_line] = + nibble_bits[val]; disp.display_update |= UPDATE_DISP; } else { #endif @@ -380,8 +379,7 @@ void disp_draw_nibble(word_20 addr, word_4 val) { for (y = 0; y < display.lines; y++) { disp.disp_image->data[shm_addr] = nibble_bits[val]; shm_addr += disp.disp_image->bytes_per_line; - disp.disp_image->data[shm_addr] - = nibble_bits[val]; + disp.disp_image->data[shm_addr] = nibble_bits[val]; shm_addr += disp.disp_image->bytes_per_line; } disp.display_update |= UPDATE_DISP; @@ -409,11 +407,12 @@ void menu_draw_nibble(word_20 addr, word_4 val) { offset = (addr - display.menu_start); #ifdef HAVE_XSHM if (shm_flag) { - shm_addr = 2 * (offset / NIBBLES_PER_ROW) * disp.menu_image->bytes_per_line - + (offset % NIBBLES_PER_ROW); + shm_addr = + 2 * (offset / NIBBLES_PER_ROW) * disp.menu_image->bytes_per_line + + (offset % NIBBLES_PER_ROW); disp.menu_image->data[shm_addr] = nibble_bits[val]; - disp.menu_image->data[shm_addr+disp.menu_image->bytes_per_line] = - nibble_bits[val]; + disp.menu_image->data[shm_addr + disp.menu_image->bytes_per_line] = + nibble_bits[val]; disp.display_update |= UPDATE_MENU; } else { #endif @@ -428,25 +427,23 @@ void menu_draw_nibble(word_20 addr, word_4 val) { #endif } - struct ann_struct { - int bit; - int x; - int y; - unsigned int width; - unsigned int height; + int bit; + int x; + int y; + unsigned int width; + unsigned int height; unsigned char *bits; - Pixmap pixmap; + Pixmap pixmap; } ann_tbl[] = { - { ANN_LEFT, 16, 4, ann_left_width, ann_left_height, ann_left_bits }, - { ANN_RIGHT, 61, 4, ann_right_width, ann_right_height, ann_right_bits }, - { ANN_ALPHA, 106, 4, ann_alpha_width, ann_alpha_height, ann_alpha_bits }, - { ANN_BATTERY, 151, 4, ann_battery_width, ann_battery_height, - ann_battery_bits }, - { ANN_BUSY, 196, 4, ann_busy_width, ann_busy_height, ann_busy_bits }, - { ANN_IO, 241, 4, ann_io_width, ann_io_height, ann_io_bits }, - { 0 } -}; + {ANN_LEFT, 16, 4, ann_left_width, ann_left_height, ann_left_bits}, + {ANN_RIGHT, 61, 4, ann_right_width, ann_right_height, ann_right_bits}, + {ANN_ALPHA, 106, 4, ann_alpha_width, ann_alpha_height, ann_alpha_bits}, + {ANN_BATTERY, 151, 4, ann_battery_width, ann_battery_height, + ann_battery_bits}, + {ANN_BUSY, 196, 4, ann_busy_width, ann_busy_height, ann_busy_bits}, + {ANN_IO, 241, 4, ann_io_width, ann_io_height, ann_io_bits}, + {0}}; void draw_annunc(void) { int val; @@ -457,20 +454,16 @@ void draw_annunc(void) { if (val == last_annunc_state) return; last_annunc_state = val; - for (i = 0; ann_tbl[i].bit; i++) - { - if ((ann_tbl[i].bit & val) == ann_tbl[i].bit) - { - XCopyPlane(dpy, ann_tbl[i].pixmap, disp.win, disp.gc, 0, 0, - ann_tbl[i].width, ann_tbl[i].height, - ann_tbl[i].x, ann_tbl[i].y, 1); - } - else - { - XClearArea(dpy, disp.win, ann_tbl[i].x, ann_tbl[i].y, - ann_tbl[i].width, ann_tbl[i].height, False); - } + for (i = 0; ann_tbl[i].bit; i++) { + if ((ann_tbl[i].bit & val) == ann_tbl[i].bit) { + XCopyPlane(dpy, ann_tbl[i].pixmap, disp.win, disp.gc, 0, 0, + ann_tbl[i].width, ann_tbl[i].height, ann_tbl[i].x, + ann_tbl[i].y, 1); + } else { + XClearArea(dpy, disp.win, ann_tbl[i].x, ann_tbl[i].y, ann_tbl[i].width, + ann_tbl[i].height, False); } + } refresh_icon(); } @@ -483,9 +476,8 @@ void init_annunc(void) { int i; for (i = 0; ann_tbl[i].bit; i++) { - ann_tbl[i].pixmap = XCreateBitmapFromData(dpy, disp.win, - (char *)ann_tbl[i].bits, - ann_tbl[i].width, - ann_tbl[i].height); + ann_tbl[i].pixmap = + XCreateBitmapFromData(dpy, disp.win, (char *)ann_tbl[i].bits, + ann_tbl[i].width, ann_tbl[i].height); } } diff --git a/src/main.c b/src/main.c index ed918aa..9e7cdb6 100644 --- a/src/main.c +++ b/src/main.c @@ -57,45 +57,44 @@ * $Id: main.c,v 1.11 1995/01/11 18:20:01 ecd Exp ecd $ */ - +#include +#include +#include #include #include -#include -#include #include -#include #include -#include +#include -#include "x48_x11.h" -#include "hp48.h" #include "debugger.h" +#include "hp48.h" +#include "x48_x11.h" #include #include -char *progname; -char *res_name; -char *res_class; +char *progname; +char *res_name; +char *res_class; -int saved_argc; +int saved_argc; char **saved_argv; saturn_t saturn; void signal_handler(int sig) { switch (sig) { - case SIGINT: - enter_debugger |= USER_INTERRUPT; - break; - case SIGALRM: - got_alarm = 1; - break; - case SIGPIPE: - exit_x48(0); - exit (0); - default: - break; + case SIGINT: + enter_debugger |= USER_INTERRUPT; + break; + case SIGALRM: + got_alarm = 1; + break; + case SIGPIPE: + exit_x48(0); + exit(0); + default: + break; } } @@ -104,24 +103,20 @@ void save_options(int argc, char **argv) { saved_argc = argc; saved_argv = (char **)malloc((argc + 2) * sizeof(char *)); - if (saved_argv == (char **)0) - { - fprintf(stderr, "%s: malloc failed in save_options(), exit\n", progname); - exit (1); - } + if (saved_argv == (char **)0) { + fprintf(stderr, "%s: malloc failed in save_options(), exit\n", progname); + exit(1); + } saved_argv[argc] = (char *)0; - while (argc--) - { - l = strlen(argv[argc]) + 1; - saved_argv[argc] = (char *)malloc(l); - if (saved_argv[argc] == (char *)0) - { - fprintf(stderr, "%s: malloc failed in save_options(), exit\n", - progname); - exit (1); - } - memcpy(saved_argv[argc], argv[argc], l); + while (argc--) { + l = strlen(argv[argc]) + 1; + saved_argv[argc] = (char *)malloc(l); + if (saved_argv[argc] == (char *)0) { + fprintf(stderr, "%s: malloc failed in save_options(), exit\n", progname); + exit(1); } + memcpy(saved_argv[argc], argv[argc], l); + } } int main(int argc, char **argv) { @@ -152,7 +147,7 @@ int main(int argc, char **argv) { * Open up the display */ if (InitDisplay(argc, argv) < 0) { - exit (1); + exit(1); } /* @@ -165,7 +160,7 @@ int main(int argc, char **argv) { */ if (CreateWindows(saved_argc, saved_argv) < 0) { fprintf(stderr, "%s: can\'t create window\n", progname); - exit (1); + exit(1); } /* @@ -229,9 +224,9 @@ int main(int argc, char **argv) { do { if (!exec_flags) - emulate (); + emulate(); else - emulate_debug (); + emulate_debug(); debug(); diff --git a/src/memory.c b/src/memory.c index 5bd1ac9..436891f 100644 --- a/src/memory.c +++ b/src/memory.c @@ -71,26 +71,26 @@ #include #include +#include #include #include -#include #ifdef SUNOS #include #endif -#include "hp48.h" #include "device.h" +#include "hp48.h" #include "hp48_emu.h" -#include "x48_x11.h" -#include "romio.h" -#include "resources.h" #include "mmu.h" +#include "resources.h" +#include "romio.h" +#include "x48_x11.h" -extern int device_check; +extern int device_check; extern short port1_is_ram; -extern long port1_mask; +extern long port1_mask; extern short port2_is_ram; -extern long port2_mask; +extern long port2_mask; #define DEBUG_UNKNOWN 1 /* #define DEBUG_SERIAL 1 */ @@ -103,28 +103,14 @@ extern long port2_mask; /* #define DEBUG_BASE_NIBBLE 1 */ /* #define DEBUG_BANK_SWITCH 1 */ -long nibble_masks[16] = { - 0x0000000f, - 0x000000f0, - 0x00000f00, - 0x0000f000, - 0x000f0000, - 0x00f00000, - 0x0f000000, - 0xf0000000, - 0x0000000f, - 0x000000f0, - 0x00000f00, - 0x0000f000, - 0x000f0000, - 0x00f00000, - 0x0f000000, - 0xf0000000 -}; +long nibble_masks[16] = {0x0000000f, 0x000000f0, 0x00000f00, 0x0000f000, + 0x000f0000, 0x00f00000, 0x0f000000, 0xf0000000, + 0x0000000f, 0x000000f0, 0x00000f00, 0x0000f000, + 0x000f0000, 0x00f00000, 0x0f000000, 0xf0000000}; -void (*write_nibble) __ProtoType__((long addr, int val)); -int (*read_nibble) __ProtoType__((long addr)); -int (*read_nibble_crc) __ProtoType__((long addr)); +void(*write_nibble) __ProtoType__((long addr, int val)); +int(*read_nibble) __ProtoType__((long addr)); +int(*read_nibble_crc) __ProtoType__((long addr)); static int line_counter = -1; @@ -139,396 +125,448 @@ void write_dev_mem(long addr, int val) { device_check = 1; schedule_event = 0; switch ((int)addr) { - case 0x100: /* DISPIO */ - if (val != saturn.disp_io) { - saturn.disp_io = val; - display.on = (val & 0x8) >> 3; - display.offset = val & 0x7; - disp.offset = 2 * display.offset; - if (display.offset > 3) - display.nibs_per_line = - (NIBBLES_PER_ROW+saturn.line_offset+2) & 0xfff; - else - display.nibs_per_line = - (NIBBLES_PER_ROW+saturn.line_offset) & 0xfff; - display.disp_end = display.disp_start + - (display.nibs_per_line * (display.lines + 1)); - device.display_touched = DISP_INSTR_OFF; - } + case 0x100: /* DISPIO */ + if (val != saturn.disp_io) { + saturn.disp_io = val; + display.on = (val & 0x8) >> 3; + display.offset = val & 0x7; + disp.offset = 2 * display.offset; + if (display.offset > 3) + display.nibs_per_line = + (NIBBLES_PER_ROW + saturn.line_offset + 2) & 0xfff; + else + display.nibs_per_line = (NIBBLES_PER_ROW + saturn.line_offset) & 0xfff; + display.disp_end = + display.disp_start + (display.nibs_per_line * (display.lines + 1)); + device.display_touched = DISP_INSTR_OFF; + } #ifdef DEBUG_DISPLAY - fprintf(stderr, "%.5lx: DISP ON: %x\n", saturn.PC, display.on); + fprintf(stderr, "%.5lx: DISP ON: %x\n", saturn.PC, display.on); #endif - return; - case 0x101: /* CONTRAST CONTROL */ - saturn.contrast_ctrl = val; - display.contrast &= ~0x0f; - display.contrast |= val; + return; + case 0x101: /* CONTRAST CONTROL */ + saturn.contrast_ctrl = val; + display.contrast &= ~0x0f; + display.contrast |= val; #ifdef DEBUG_CONTRAST - fprintf(stderr, "%.5lx: Contrast: 0x%x\n", saturn.PC, display.contrast); + fprintf(stderr, "%.5lx: Contrast: 0x%x\n", saturn.PC, display.contrast); #endif - device.contrast_touched = 1; - return; - case 0x102: /* DISPLAY TEST */ - display.contrast &= ~0xf0; - display.contrast |= ((val & 0x1) << 4); + device.contrast_touched = 1; + return; + case 0x102: /* DISPLAY TEST */ + display.contrast &= ~0xf0; + display.contrast |= ((val & 0x1) << 4); #ifdef DEBUG_CONTRAST - fprintf(stderr, "%.5lx: Contrast: 0x%x\n", saturn.PC, display.contrast); + fprintf(stderr, "%.5lx: Contrast: 0x%x\n", saturn.PC, display.contrast); #endif - device.contrast_touched = 1; - /* Fall through */ - case 0x103: /* DISPLAY TEST */ - saturn.disp_test &= ~nibble_masks[addr - 0x102]; - saturn.disp_test |= val << ((addr - 0x102) * 4); + device.contrast_touched = 1; + /* Fall through */ + case 0x103: /* DISPLAY TEST */ + saturn.disp_test &= ~nibble_masks[addr - 0x102]; + saturn.disp_test |= val << ((addr - 0x102) * 4); #ifdef DEBUG_DISPLAY - fprintf(stderr, "%.5lx: DISP TEST: %x\n", saturn.PC, saturn.disp_test); + fprintf(stderr, "%.5lx: DISP TEST: %x\n", saturn.PC, saturn.disp_test); #endif - device.disp_test_touched = 1; - return; - case 0x104: case 0x105: case 0x106: case 0x107: /* CRC */ - saturn.crc &= ~nibble_masks[addr - 0x104]; - saturn.crc |= val << ((addr - 0x104) * 4); - return; - case 0x108: /* POWER STATUS */ - saturn.power_status = val; - device.power_status_touched = 1; - return; - case 0x109: /* POWER CONTROL */ - saturn.power_ctrl = val; - device.power_ctrl_touched = 1; - return; - case 0x10a: /* MODE */ - saturn.mode = val; - device.mode_touched = 1; - return; - case 0x10b: case 0x10c: /* ANNUNC */ - saturn.annunc &= ~nibble_masks[addr - 0x10b]; - saturn.annunc |= val << ((addr - 0x10b) * 4); - display.annunc = saturn.annunc; - device.ann_touched = 1; - return; - case 0x10d: /* BAUD */ - saturn.baud = val; - device.baud_touched = 1; + device.disp_test_touched = 1; + return; + case 0x104: + case 0x105: + case 0x106: + case 0x107: /* CRC */ + saturn.crc &= ~nibble_masks[addr - 0x104]; + saturn.crc |= val << ((addr - 0x104) * 4); + return; + case 0x108: /* POWER STATUS */ + saturn.power_status = val; + device.power_status_touched = 1; + return; + case 0x109: /* POWER CONTROL */ + saturn.power_ctrl = val; + device.power_ctrl_touched = 1; + return; + case 0x10a: /* MODE */ + saturn.mode = val; + device.mode_touched = 1; + return; + case 0x10b: + case 0x10c: /* ANNUNC */ + saturn.annunc &= ~nibble_masks[addr - 0x10b]; + saturn.annunc |= val << ((addr - 0x10b) * 4); + display.annunc = saturn.annunc; + device.ann_touched = 1; + return; + case 0x10d: /* BAUD */ + saturn.baud = val; + device.baud_touched = 1; #ifdef DEBUG_SERIALb - fprintf(stderr, "%.5lx: BAUD write: %x\n", saturn.PC, saturn.baud); + fprintf(stderr, "%.5lx: BAUD write: %x\n", saturn.PC, saturn.baud); #endif - return; - case 0x10e: /* CARD CONTROL */ - saturn.card_ctrl = val; - if (saturn.card_ctrl & 0x02) - saturn.MP = 1; - if (saturn.card_ctrl & 0x01) - do_interupt(); - device.card_ctrl_touched = 1; + return; + case 0x10e: /* CARD CONTROL */ + saturn.card_ctrl = val; + if (saturn.card_ctrl & 0x02) + saturn.MP = 1; + if (saturn.card_ctrl & 0x01) + do_interupt(); + device.card_ctrl_touched = 1; #ifdef DEBUG_CARDS - fprintf(stderr, "%.5lx: CardControl write: %x\n", - saturn.PC, saturn.card_ctrl); + fprintf(stderr, "%.5lx: CardControl write: %x\n", saturn.PC, + saturn.card_ctrl); #endif - return; - case 0x10f: /* CARD STATUS */ + return; + case 0x10f: /* CARD STATUS */ #ifdef DEBUG_CARDS - fprintf(stderr, "%.5lx: CardStatus write: %x\n", - saturn.PC, saturn.card_status); + fprintf(stderr, "%.5lx: CardStatus write: %x\n", saturn.PC, + saturn.card_status); #endif - return; - case 0x110: /* IO CONTROL */ - saturn.io_ctrl = val; - device.ioc_touched = 1; + return; + case 0x110: /* IO CONTROL */ + saturn.io_ctrl = val; + device.ioc_touched = 1; #ifdef DEBUG_SERIAL - fprintf(stderr, "%.5lx: IOC write: %x\n", saturn.PC, saturn.io_ctrl); + fprintf(stderr, "%.5lx: IOC write: %x\n", saturn.PC, saturn.io_ctrl); #endif - return; - case 0x111: /* RCS */ - saturn.rcs = val; + return; + case 0x111: /* RCS */ + saturn.rcs = val; #ifdef DEBUG_SERIAL - fprintf(stderr, "%.5lx: RCS: %x\n", saturn.PC, saturn.rcs); + fprintf(stderr, "%.5lx: RCS: %x\n", saturn.PC, saturn.rcs); #endif - return; - case 0x112: /* TCS */ - saturn.tcs = val; + return; + case 0x112: /* TCS */ + saturn.tcs = val; #ifdef DEBUG_SERIAL - fprintf(stderr, "%.5lx: TCS: %x\n", saturn.PC, saturn.tcs); + fprintf(stderr, "%.5lx: TCS: %x\n", saturn.PC, saturn.tcs); #endif - return; - case 0x113: /* CRER */ - saturn.rcs &= 0x0b; + return; + case 0x113: /* CRER */ + saturn.rcs &= 0x0b; #ifdef DEBUG_SERIAL - fprintf(stderr, "%.5lx: CRER, RCS: %x\n", saturn.PC, saturn.rcs); + fprintf(stderr, "%.5lx: CRER, RCS: %x\n", saturn.PC, saturn.rcs); #endif - return; - case 0x114: case 0x115: /* RBR */ - return; - case 0x116: case 0x117: /* TBR */ - saturn.tbr &= ~nibble_masks[addr - 0x116]; - saturn.tbr |= val << ((addr - 0x116) * 4); - saturn.tcs |= 0x01; - device.tbr_touched = 1; - return; - case 0x118: case 0x119: /* SERVICE REQ */ - saturn.sreq &= ~nibble_masks[addr - 0x118]; - saturn.sreq |= val << ((addr - 0x118) * 4); - device.sreq_touched = 1; + return; + case 0x114: + case 0x115: /* RBR */ + return; + case 0x116: + case 0x117: /* TBR */ + saturn.tbr &= ~nibble_masks[addr - 0x116]; + saturn.tbr |= val << ((addr - 0x116) * 4); + saturn.tcs |= 0x01; + device.tbr_touched = 1; + return; + case 0x118: + case 0x119: /* SERVICE REQ */ + saturn.sreq &= ~nibble_masks[addr - 0x118]; + saturn.sreq |= val << ((addr - 0x118) * 4); + device.sreq_touched = 1; #ifdef DEBUG_SERIAL - fprintf(stderr, "%.5lx: SREQ? write: %x\n", saturn.PC, saturn.sreq); + fprintf(stderr, "%.5lx: SREQ? write: %x\n", saturn.PC, saturn.sreq); #endif - return; - case 0x11a: /* IR CONTROL */ - saturn.ir_ctrl = val; - device.ir_ctrl_touched = 1; + return; + case 0x11a: /* IR CONTROL */ + saturn.ir_ctrl = val; + device.ir_ctrl_touched = 1; #ifdef DEBUG_IR - fprintf(stderr, "%.5lx: IRC write: %x\n", saturn.PC, saturn.ir_ctrl); + fprintf(stderr, "%.5lx: IRC write: %x\n", saturn.PC, saturn.ir_ctrl); #endif - return; - case 0x11b: /* BASE NIB OFFSET */ - saturn.base_off = val; - device.base_off_touched = 1; - return; - case 0x11c: /* LED CONTROL */ - saturn.lcr = val; - device.lcr_touched = 1; + return; + case 0x11b: /* BASE NIB OFFSET */ + saturn.base_off = val; + device.base_off_touched = 1; + return; + case 0x11c: /* LED CONTROL */ + saturn.lcr = val; + device.lcr_touched = 1; #ifdef DEBUG_IR - fprintf(stderr, "%.5lx: LCR write: %x\n", saturn.PC, saturn.lcr); + fprintf(stderr, "%.5lx: LCR write: %x\n", saturn.PC, saturn.lcr); #endif - return; - case 0x11d: /* LED BUFFER */ - saturn.lbr = val; - device.lbr_touched = 1; + return; + case 0x11d: /* LED BUFFER */ + saturn.lbr = val; + device.lbr_touched = 1; #ifdef DEBUG_IR - fprintf(stderr, "%.5lx: LBR write: %x\n", saturn.PC, saturn.lbr); + fprintf(stderr, "%.5lx: LBR write: %x\n", saturn.PC, saturn.lbr); #endif - return; - case 0x11e: /* SCRATCH PAD */ - saturn.scratch = val; - device.scratch_touched = 1; - return; - case 0x11f: /* BASENIBBLE */ - saturn.base_nibble = val; - device.base_nibble_touched = 1; + return; + case 0x11e: /* SCRATCH PAD */ + saturn.scratch = val; + device.scratch_touched = 1; + return; + case 0x11f: /* BASENIBBLE */ + saturn.base_nibble = val; + device.base_nibble_touched = 1; #ifdef DEBUG_BASE_NIBBLE - if (opt_gx) + if (opt_gx) fprintf(stderr, "%.5lx: BASENIB: %x\n", saturn.PC, saturn.base_nibble); #endif - return; - case 0x120: case 0x121: case 0x122: case 0x123: /* DISP_ADDR */ - case 0x124: - saturn.disp_addr &= ~nibble_masks[addr - 0x120]; - saturn.disp_addr |= val << ((addr - 0x120) * 4); - if (display.disp_start != (saturn.disp_addr & 0xffffe)) { - display.disp_start = saturn.disp_addr & 0xffffe; - display.disp_end = display.disp_start + - (display.nibs_per_line * (display.lines + 1)); - device.display_touched = DISP_INSTR_OFF; - } + return; + case 0x120: + case 0x121: + case 0x122: + case 0x123: /* DISP_ADDR */ + case 0x124: + saturn.disp_addr &= ~nibble_masks[addr - 0x120]; + saturn.disp_addr |= val << ((addr - 0x120) * 4); + if (display.disp_start != (saturn.disp_addr & 0xffffe)) { + display.disp_start = saturn.disp_addr & 0xffffe; + display.disp_end = + display.disp_start + (display.nibs_per_line * (display.lines + 1)); + device.display_touched = DISP_INSTR_OFF; + } #ifdef DEBUG_DISPLAY - fprintf(stderr, "%.5lx: DISPLAY: %lx\n", saturn.PC, display.disp_start); - fprintf(stderr, "%.5lx: DISP END: %lx\n", saturn.PC, display.disp_end); + fprintf(stderr, "%.5lx: DISPLAY: %lx\n", saturn.PC, display.disp_start); + fprintf(stderr, "%.5lx: DISP END: %lx\n", saturn.PC, display.disp_end); #endif - return; - case 0x125: case 0x126: case 0x127: /* LINE_OFFSET */ - saturn.line_offset &= ~nibble_masks[addr - 0x125]; - saturn.line_offset |= val << ((addr - 0x125) * 4); - if (saturn.line_offset != old_line_offset) { - old_line_offset = saturn.line_offset; - if (display.offset > 3) - display.nibs_per_line = - (NIBBLES_PER_ROW+saturn.line_offset+2) & 0xfff; - else - display.nibs_per_line = - (NIBBLES_PER_ROW+saturn.line_offset) & 0xfff; - display.disp_end = display.disp_start + - (display.nibs_per_line * (display.lines + 1)); - device.display_touched = DISP_INSTR_OFF; - } + return; + case 0x125: + case 0x126: + case 0x127: /* LINE_OFFSET */ + saturn.line_offset &= ~nibble_masks[addr - 0x125]; + saturn.line_offset |= val << ((addr - 0x125) * 4); + if (saturn.line_offset != old_line_offset) { + old_line_offset = saturn.line_offset; + if (display.offset > 3) + display.nibs_per_line = + (NIBBLES_PER_ROW + saturn.line_offset + 2) & 0xfff; + else + display.nibs_per_line = (NIBBLES_PER_ROW + saturn.line_offset) & 0xfff; + display.disp_end = + display.disp_start + (display.nibs_per_line * (display.lines + 1)); + device.display_touched = DISP_INSTR_OFF; + } #ifdef DEBUG_DISPLAY - fprintf(stderr, "%.5lx: DISP LINE SIZE: %x\n", - saturn.PC, display.nibs_per_line); - fprintf(stderr, "%.5lx: DISP END: %lx\n", saturn.PC, display.disp_end); + fprintf(stderr, "%.5lx: DISP LINE SIZE: %x\n", saturn.PC, + display.nibs_per_line); + fprintf(stderr, "%.5lx: DISP END: %lx\n", saturn.PC, display.disp_end); #endif - return; - case 0x128: case 0x129: /* LINE_COUNT */ - saturn.line_count &= ~nibble_masks[addr - 0x128]; - saturn.line_count |= val << ((addr - 0x128) * 4); - line_counter = -1; - if (display.lines != (saturn.line_count & 0x3f)) { - display.lines = saturn.line_count & 0x3f; - if (display.lines == 0) - display.lines = 63; - disp.lines = 2 * display.lines; - display.disp_end = display.disp_start + - (display.nibs_per_line * (display.lines + 1)); - device.display_touched = DISP_INSTR_OFF; - } + return; + case 0x128: + case 0x129: /* LINE_COUNT */ + saturn.line_count &= ~nibble_masks[addr - 0x128]; + saturn.line_count |= val << ((addr - 0x128) * 4); + line_counter = -1; + if (display.lines != (saturn.line_count & 0x3f)) { + display.lines = saturn.line_count & 0x3f; + if (display.lines == 0) + display.lines = 63; + disp.lines = 2 * display.lines; + display.disp_end = + display.disp_start + (display.nibs_per_line * (display.lines + 1)); + device.display_touched = DISP_INSTR_OFF; + } #ifdef DEBUG_DISPLAY - fprintf(stderr, "%.5lx: DISP LINES: %x\n", saturn.PC, display.lines); - fprintf(stderr, "%.5lx: DISP END: %lx\n", saturn.PC, display.disp_end); + fprintf(stderr, "%.5lx: DISP LINES: %x\n", saturn.PC, display.lines); + fprintf(stderr, "%.5lx: DISP END: %lx\n", saturn.PC, display.disp_end); #endif - return; - case 0x12a: case 0x12b: case 0x12c: case 0x12d: /* Dont know yet */ - saturn.unknown &= ~nibble_masks[addr - 0x12a]; - saturn.unknown |= val << ((addr - 0x12a) * 4); + return; + case 0x12a: + case 0x12b: + case 0x12c: + case 0x12d: /* Dont know yet */ + saturn.unknown &= ~nibble_masks[addr - 0x12a]; + saturn.unknown |= val << ((addr - 0x12a) * 4); #ifdef DEBUG_UNKNOWN - fprintf(stderr, "Unknown device @0x%ld: %.4x\n", addr, saturn.unknown); + fprintf(stderr, "Unknown device @0x%ld: %.4x\n", addr, saturn.unknown); #endif - device.unknown_touched = 1; - return; - case 0x12e: /* TIMER 1 CONTROL */ - saturn.t1_ctrl = val; - device.t1_ctrl_touched = 1; - return; - case 0x12f: /* TIMER 2 CONTROL */ - saturn.t2_ctrl = val; - device.t2_ctrl_touched = 1; - return; - case 0x130: case 0x131: case 0x132: case 0x133: /* MENU_ADDR */ - case 0x134: - saturn.menu_addr &= ~nibble_masks[addr - 0x130]; - saturn.menu_addr |= val << ((addr - 0x130) * 4); - if (display.menu_start != saturn.menu_addr) { - display.menu_start = saturn.menu_addr; - display.menu_end = display.menu_start + 0x110; - device.display_touched = DISP_INSTR_OFF; - } - return; - case 0x135: case 0x136: /* Dont know yet 2 */ - saturn.unknown2 &= ~nibble_masks[addr - 0x135]; - saturn.unknown2 |= val << ((addr - 0x135) * 4); + device.unknown_touched = 1; + return; + case 0x12e: /* TIMER 1 CONTROL */ + saturn.t1_ctrl = val; + device.t1_ctrl_touched = 1; + return; + case 0x12f: /* TIMER 2 CONTROL */ + saturn.t2_ctrl = val; + device.t2_ctrl_touched = 1; + return; + case 0x130: + case 0x131: + case 0x132: + case 0x133: /* MENU_ADDR */ + case 0x134: + saturn.menu_addr &= ~nibble_masks[addr - 0x130]; + saturn.menu_addr |= val << ((addr - 0x130) * 4); + if (display.menu_start != saturn.menu_addr) { + display.menu_start = saturn.menu_addr; + display.menu_end = display.menu_start + 0x110; + device.display_touched = DISP_INSTR_OFF; + } + return; + case 0x135: + case 0x136: /* Dont know yet 2 */ + saturn.unknown2 &= ~nibble_masks[addr - 0x135]; + saturn.unknown2 |= val << ((addr - 0x135) * 4); #ifdef DEBUG_UNKNOWN - fprintf(stderr, "Unknown device @0x%ld: %.2x\n", addr, saturn.unknown2); + fprintf(stderr, "Unknown device @0x%ld: %.2x\n", addr, saturn.unknown2); #endif - device.unknown2_touched = 1; - return; - case 0x137: /* TIMER1 */ - saturn.timer1 = val; - device.t1_touched = 1; - return; - case 0x138: case 0x139: case 0x13a: case 0x13b: - case 0x13c: case 0x13d: case 0x13e: case 0x13f: /* TIMER2 */ - saturn.timer2 &= ~nibble_masks[addr - 0x138]; - saturn.timer2 |= val << ((addr - 0x138) * 4); - device.t2_touched = 1; - return; - default: - if (!quiet) - fprintf(stderr, "%.5lx: UNKNOWN DEVICE WRITE AT 0x%lx !!!\n", - saturn.PC, addr); - return; + device.unknown2_touched = 1; + return; + case 0x137: /* TIMER1 */ + saturn.timer1 = val; + device.t1_touched = 1; + return; + case 0x138: + case 0x139: + case 0x13a: + case 0x13b: + case 0x13c: + case 0x13d: + case 0x13e: + case 0x13f: /* TIMER2 */ + saturn.timer2 &= ~nibble_masks[addr - 0x138]; + saturn.timer2 |= val << ((addr - 0x138) * 4); + device.t2_touched = 1; + return; + default: + if (!quiet) + fprintf(stderr, "%.5lx: UNKNOWN DEVICE WRITE AT 0x%lx !!!\n", saturn.PC, + addr); + return; } } int read_dev_mem(long addr) { switch ((int)addr) { - case 0x100: /* DISPLAY IO */ - return saturn.disp_io & 0x0f; - case 0x101: /* CONTRAST CONTROL */ - return saturn.contrast_ctrl & 0x0f; - case 0x102: case 0x103: /* DISPLAY TEST */ - return (saturn.disp_test >> ((addr - 0x102) * 4)) & 0x0f; - case 0x104: case 0x105: case 0x106: case 0x107: /* CRC */ - return (saturn.crc >> ((addr - 0x104) * 4)) & 0x0f; - case 0x108: /* POWER STATUS */ - return saturn.power_status & 0x0f; - case 0x109: /* POWER CONTROL */ - return saturn.power_ctrl & 0x0f; - case 0x10a: /* MODE */ - return saturn.mode & 0x0f; - case 0x10b: case 0x10c: /* ANNUNC */ - return (saturn.annunc >> ((addr - 0x10b) * 4)) & 0x0f; - case 0x10d: /* BAUD */ + case 0x100: /* DISPLAY IO */ + return saturn.disp_io & 0x0f; + case 0x101: /* CONTRAST CONTROL */ + return saturn.contrast_ctrl & 0x0f; + case 0x102: + case 0x103: /* DISPLAY TEST */ + return (saturn.disp_test >> ((addr - 0x102) * 4)) & 0x0f; + case 0x104: + case 0x105: + case 0x106: + case 0x107: /* CRC */ + return (saturn.crc >> ((addr - 0x104) * 4)) & 0x0f; + case 0x108: /* POWER STATUS */ + return saturn.power_status & 0x0f; + case 0x109: /* POWER CONTROL */ + return saturn.power_ctrl & 0x0f; + case 0x10a: /* MODE */ + return saturn.mode & 0x0f; + case 0x10b: + case 0x10c: /* ANNUNC */ + return (saturn.annunc >> ((addr - 0x10b) * 4)) & 0x0f; + case 0x10d: /* BAUD */ #ifdef DEBUG_SERIALb - fprintf(stderr, "%.5lx: BAUD read: %x\n", saturn.PC, saturn.baud); + fprintf(stderr, "%.5lx: BAUD read: %x\n", saturn.PC, saturn.baud); #endif - return saturn.baud & 0x0f; - case 0x10e: /* CARD CONTROL */ - return saturn.card_ctrl & 0x0f; - case 0x10f: /* CARD STATUS */ - return saturn.card_status & 0x0f; - case 0x110: /* IO CONTROL */ + return saturn.baud & 0x0f; + case 0x10e: /* CARD CONTROL */ + return saturn.card_ctrl & 0x0f; + case 0x10f: /* CARD STATUS */ + return saturn.card_status & 0x0f; + case 0x110: /* IO CONTROL */ #ifdef DEBUG_SERIAL - fprintf(stderr, "%.5lx: IOC read: %x\n", saturn.PC, saturn.io_ctrl); + fprintf(stderr, "%.5lx: IOC read: %x\n", saturn.PC, saturn.io_ctrl); #endif - return saturn.io_ctrl & 0x0f; - case 0x111: /* RCS */ + return saturn.io_ctrl & 0x0f; + case 0x111: /* RCS */ #ifdef DEBUG_SERIAL - fprintf(stderr, "%.5lx: RCS read: %x\n", saturn.PC, saturn.rcs); + fprintf(stderr, "%.5lx: RCS read: %x\n", saturn.PC, saturn.rcs); #endif - return saturn.rcs & 0x0f; - case 0x112: /* TCS */ + return saturn.rcs & 0x0f; + case 0x112: /* TCS */ #ifdef DEBUG_SERIAL - fprintf(stderr, "%.5lx: TCS read: %x\n", saturn.PC, saturn.tcs); + fprintf(stderr, "%.5lx: TCS read: %x\n", saturn.PC, saturn.tcs); #endif - return saturn.tcs & 0x0f; - case 0x113: /* CRER */ - return 0x00; - case 0x114: case 0x115: /* RBR */ - saturn.rcs &= 0x0e; - device.rbr_touched = 1; - device_check = 1; - schedule_event = 0; - return (saturn.rbr >> ((addr - 0x114) * 4)) & 0x0f; - case 0x116: case 0x117: /* TBR */ - return 0x00; - case 0x118: case 0x119: /* SERVICE REQ */ + return saturn.tcs & 0x0f; + case 0x113: /* CRER */ + return 0x00; + case 0x114: + case 0x115: /* RBR */ + saturn.rcs &= 0x0e; + device.rbr_touched = 1; + device_check = 1; + schedule_event = 0; + return (saturn.rbr >> ((addr - 0x114) * 4)) & 0x0f; + case 0x116: + case 0x117: /* TBR */ + return 0x00; + case 0x118: + case 0x119: /* SERVICE REQ */ #ifdef DEBUG_SERIAL - fprintf(stderr, "%.5lx: SREQ? read: %x\n", saturn.PC, saturn.sreq); + fprintf(stderr, "%.5lx: SREQ? read: %x\n", saturn.PC, saturn.sreq); #endif - return (saturn.sreq >> ((addr - 0x118) * 4)) & 0x0f; - case 0x11a: /* IR CONTROL */ + return (saturn.sreq >> ((addr - 0x118) * 4)) & 0x0f; + case 0x11a: /* IR CONTROL */ #ifdef DEBUG_IR - fprintf(stderr, "%.5lx: IRC read: %x\n", saturn.PC, saturn.ir_ctrl); + fprintf(stderr, "%.5lx: IRC read: %x\n", saturn.PC, saturn.ir_ctrl); #endif - return saturn.ir_ctrl & 0x0f; - case 0x11b: /* BASE NIB OFFSET */ - return saturn.base_off & 0x0f; - case 0x11c: /* LED CONTROL */ + return saturn.ir_ctrl & 0x0f; + case 0x11b: /* BASE NIB OFFSET */ + return saturn.base_off & 0x0f; + case 0x11c: /* LED CONTROL */ #if 0 #ifdef DEBUG_IR fprintf(stderr, "%.5lx: LCR read: %x\n", saturn.PC, saturn.lcr); #endif #endif - return saturn.lcr & 0x0f; - case 0x11d: /* LED BUFFER */ + return saturn.lcr & 0x0f; + case 0x11d: /* LED BUFFER */ #if 0 #ifdef DEBUG_IR fprintf(stderr, "%.5lx: LBR read: %x\n", saturn.PC, saturn.lbr); #endif #endif - return saturn.lbr & 0x0f; - case 0x11e: /* SCRATCH PAD */ - return saturn.scratch & 0x0f; - case 0x11f: /* BASENIBBLE */ - return saturn.base_nibble & 0x0f; - case 0x120: case 0x121: case 0x122: case 0x123: /* DISP_ADDR */ - case 0x124: - return (saturn.disp_addr >> ((addr - 0x120) * 4)) & 0x0f; - case 0x125: case 0x126: case 0x127: /* LINE_OFFSET */ - return (saturn.line_offset >> ((addr - 0x125) * 4)) & 0x0f; - case 0x128: case 0x129: /* LINE_COUNT */ - line_counter++; - if (line_counter > 0x3f) - line_counter = -1; - return (((saturn.line_count & 0xc0) | (line_counter & 0x3f)) >> - ((addr - 0x128) * 4)) & 0x0f; - case 0x12a: case 0x12b: case 0x12c: case 0x12d: /* Dont know yet */ - return (saturn.unknown >> ((addr - 0x12a) * 4)) & 0x0f; - case 0x12e: /* TIMER 1 CONTROL */ - return saturn.t1_ctrl & 0x0f; - case 0x12f: /* TIMER 2 CONTROL */ - return saturn.t2_ctrl & 0x0f; - case 0x130: case 0x131: case 0x132: case 0x133: /* MENU_ADDR */ - case 0x134: - return (saturn.menu_addr >> ((addr - 0x130) * 4)) & 0x0f; - case 0x135: case 0x136: /* Dont know yet 2 */ - return (saturn.unknown2 >> ((addr - 0x135) * 4)) & 0x0f; - case 0x137: - return saturn.timer1 & 0xf; - case 0x138: case 0x139: case 0x13a: case 0x13b: - case 0x13c: case 0x13d: case 0x13e: case 0x13f: - return (saturn.timer2 >> ((addr - 0x138) * 4)) & 0xf; - default: - if (!quiet) - fprintf(stderr, "%.5lx: UNKNOWN DEVICE READ AT 0x%lx !!!\n", - saturn.PC, addr); - return 0x00; + return saturn.lbr & 0x0f; + case 0x11e: /* SCRATCH PAD */ + return saturn.scratch & 0x0f; + case 0x11f: /* BASENIBBLE */ + return saturn.base_nibble & 0x0f; + case 0x120: + case 0x121: + case 0x122: + case 0x123: /* DISP_ADDR */ + case 0x124: + return (saturn.disp_addr >> ((addr - 0x120) * 4)) & 0x0f; + case 0x125: + case 0x126: + case 0x127: /* LINE_OFFSET */ + return (saturn.line_offset >> ((addr - 0x125) * 4)) & 0x0f; + case 0x128: + case 0x129: /* LINE_COUNT */ + line_counter++; + if (line_counter > 0x3f) + line_counter = -1; + return (((saturn.line_count & 0xc0) | (line_counter & 0x3f)) >> + ((addr - 0x128) * 4)) & + 0x0f; + case 0x12a: + case 0x12b: + case 0x12c: + case 0x12d: /* Dont know yet */ + return (saturn.unknown >> ((addr - 0x12a) * 4)) & 0x0f; + case 0x12e: /* TIMER 1 CONTROL */ + return saturn.t1_ctrl & 0x0f; + case 0x12f: /* TIMER 2 CONTROL */ + return saturn.t2_ctrl & 0x0f; + case 0x130: + case 0x131: + case 0x132: + case 0x133: /* MENU_ADDR */ + case 0x134: + return (saturn.menu_addr >> ((addr - 0x130) * 4)) & 0x0f; + case 0x135: + case 0x136: /* Dont know yet 2 */ + return (saturn.unknown2 >> ((addr - 0x135) * 4)) & 0x0f; + case 0x137: + return saturn.timer1 & 0xf; + case 0x138: + case 0x139: + case 0x13a: + case 0x13b: + case 0x13c: + case 0x13d: + case 0x13e: + case 0x13f: + return (saturn.timer2 >> ((addr - 0x138) * 4)) & 0xf; + default: + if (!quiet) + fprintf(stderr, "%.5lx: UNKNOWN DEVICE READ AT 0x%lx !!!\n", saturn.PC, + addr); + return 0x00; } } @@ -536,878 +574,811 @@ void write_nibble_sx(long addr, int val) { addr &= 0xfffff; val &= 0x0f; switch ((int)(addr >> 16) & 0x0f) { - case 0: - if (addr < 0x140 && addr >= 0x100 && - saturn.mem_cntl[MCTL_MMIO_SX].config[0] == 0x100) - { - write_dev_mem(addr, val); - return; - } -#ifdef DEBUG_BAD_MEM - fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", - saturn.PC, addr); -#endif + case 0: + if (addr < 0x140 && addr >= 0x100 && + saturn.mem_cntl[MCTL_MMIO_SX].config[0] == 0x100) { + write_dev_mem(addr, val); return; - case 1: case 2: case 3: case 4: case 5: case 6: + } #ifdef DEBUG_BAD_MEM - fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", - saturn.PC, addr); + fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", saturn.PC, addr); #endif - return; - case 7: - if (saturn.mem_cntl[MCTL_SysRAM_SX].config[0] == 0x70000) - { - if (saturn.mem_cntl[MCTL_SysRAM_SX].config[1] == 0xfc000 - && addr < 0x74000) - { - saturn.ram[addr - 0x70000] = val; - break; - } - if (saturn.mem_cntl[MCTL_SysRAM_SX].config[1] == 0xfe000 - && addr < 0x72000) - { - saturn.ram[addr - 0x70000] = val; - break; - } - if (saturn.mem_cntl[MCTL_SysRAM_SX].config[1] == 0xf0000) - { - saturn.ram[addr - 0x70000] = val; - break; - } - } + return; + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: #ifdef DEBUG_BAD_MEM - fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", - saturn.PC, addr); + fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", saturn.PC, addr); #endif - return; - case 8: case 9: case 0xa: case 0xb: - if (saturn.mem_cntl[MCTL_PORT1_SX].config[0] == 0x80000) - { - if (port1_is_ram) - saturn.port1[(addr - 0x80000) & port1_mask] = val; - return; - } - if (saturn.mem_cntl[MCTL_PORT2_SX].config[0] == 0x80000) - { - if (port2_is_ram) - saturn.port2[(addr - 0x80000) & port2_mask] = val; - return; - } + return; + case 7: + if (saturn.mem_cntl[MCTL_SysRAM_SX].config[0] == 0x70000) { + if (saturn.mem_cntl[MCTL_SysRAM_SX].config[1] == 0xfc000 && + addr < 0x74000) { + saturn.ram[addr - 0x70000] = val; + break; + } + if (saturn.mem_cntl[MCTL_SysRAM_SX].config[1] == 0xfe000 && + addr < 0x72000) { + saturn.ram[addr - 0x70000] = val; + break; + } + if (saturn.mem_cntl[MCTL_SysRAM_SX].config[1] == 0xf0000) { + saturn.ram[addr - 0x70000] = val; + break; + } + } #ifdef DEBUG_BAD_MEM - fprintf(stderr, "%.5lx: write to NULL at %.5lx\n", - saturn.PC, addr); + fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", saturn.PC, addr); #endif + return; + case 8: + case 9: + case 0xa: + case 0xb: + if (saturn.mem_cntl[MCTL_PORT1_SX].config[0] == 0x80000) { + if (port1_is_ram) + saturn.port1[(addr - 0x80000) & port1_mask] = val; return; - case 0xc: case 0xd: case 0xe: - if (saturn.mem_cntl[MCTL_PORT1_SX].config[0] == 0xc0000) - { - if (port1_is_ram) - saturn.port1[(addr - 0xc0000) & port1_mask] = val; - return; - } - if (saturn.mem_cntl[MCTL_PORT2_SX].config[0] == 0xc0000) - { - if (port2_is_ram) - saturn.port2[(addr - 0xc0000) & port2_mask] = val; - return; - } + } + if (saturn.mem_cntl[MCTL_PORT2_SX].config[0] == 0x80000) { + if (port2_is_ram) + saturn.port2[(addr - 0x80000) & port2_mask] = val; + return; + } #ifdef DEBUG_BAD_MEM - fprintf(stderr, "%.5lx: write to NULL at %.5lx\n", - saturn.PC, addr); + fprintf(stderr, "%.5lx: write to NULL at %.5lx\n", saturn.PC, addr); #endif + return; + case 0xc: + case 0xd: + case 0xe: + if (saturn.mem_cntl[MCTL_PORT1_SX].config[0] == 0xc0000) { + if (port1_is_ram) + saturn.port1[(addr - 0xc0000) & port1_mask] = val; return; - case 0xf: - if (saturn.mem_cntl[MCTL_SysRAM_SX].config[0] == 0xf0000) - { - saturn.ram[addr - 0xf0000] = val; - break; - } - if (saturn.mem_cntl[MCTL_PORT1_SX].config[0] == 0xc0000) - { - if (port1_is_ram) - saturn.port1[(addr - 0xc0000) & port1_mask] = val; - return; - } - if (saturn.mem_cntl[MCTL_PORT2_SX].config[0] == 0xc0000) - { - if (port2_is_ram) - saturn.port2[(addr - 0xc0000) & port2_mask] = val; - return; - } + } + if (saturn.mem_cntl[MCTL_PORT2_SX].config[0] == 0xc0000) { + if (port2_is_ram) + saturn.port2[(addr - 0xc0000) & port2_mask] = val; + return; + } #ifdef DEBUG_BAD_MEM - fprintf(stderr, "%.5lx: write to NULL at %.5lx\n", - saturn.PC, addr); + fprintf(stderr, "%.5lx: write to NULL at %.5lx\n", saturn.PC, addr); #endif + return; + case 0xf: + if (saturn.mem_cntl[MCTL_SysRAM_SX].config[0] == 0xf0000) { + saturn.ram[addr - 0xf0000] = val; + break; + } + if (saturn.mem_cntl[MCTL_PORT1_SX].config[0] == 0xc0000) { + if (port1_is_ram) + saturn.port1[(addr - 0xc0000) & port1_mask] = val; return; + } + if (saturn.mem_cntl[MCTL_PORT2_SX].config[0] == 0xc0000) { + if (port2_is_ram) + saturn.port2[(addr - 0xc0000) & port2_mask] = val; + return; + } +#ifdef DEBUG_BAD_MEM + fprintf(stderr, "%.5lx: write to NULL at %.5lx\n", saturn.PC, addr); +#endif + return; } if (device.display_touched || !disp.mapped) return; - if (addr >= display.disp_start && addr < display.disp_end) - { - disp_draw_nibble(addr, val); - } + if (addr >= display.disp_start && addr < display.disp_end) { + disp_draw_nibble(addr, val); + } if (display.lines == 63) return; - if (addr >= display.menu_start && addr < display.menu_end) - { - menu_draw_nibble(addr, val); - } + if (addr >= display.menu_start && addr < display.menu_end) { + menu_draw_nibble(addr, val); + } } void write_nibble_gx(long addr, int val) { addr &= 0xfffff; val &= 0x0f; - switch ((int)(addr >> 16) & 0x0f) - { - case 0: - if (addr < 0x140 && addr >= 0x100 && - saturn.mem_cntl[MCTL_MMIO_GX].config[0] == 0x100) - { - write_dev_mem(addr, val); - return; - } -#ifdef DEBUG_BAD_MEM - fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", - saturn.PC, addr); -#endif - return; - case 1: case 2: case 3: case 5: case 6: -#ifdef DEBUG_BAD_MEM - fprintf(stderr, "%.5lx: BAD WRITE TO ROM AT ADDRESS %.5lx\n", - saturn.PC, addr); -#endif - return; - case 4: - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x40000) - { - saturn.ram[addr - 0x40000] = val; - break; - } -#ifdef DEBUG_BAD_MEM - fprintf(stderr, "%.5lx: BAD WRITE TO ROM AT ADDRESS %.5lx\n", - saturn.PC, addr); -#endif - return; - case 7: - if (addr >= 0x7f000 && - saturn.mem_cntl[MCTL_BANK_GX].config[0] == 0x7f000) - { -#ifdef DEBUG_BANK_SWITCH - fprintf(stderr, "%.5lx: write to bank switch at %.5lx\n", - saturn.PC, addr); -#endif - return; - } - if (addr >= 0x7e000 && addr < 0x7f000 && - saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0x7e000) - { -#ifdef DEBUG_PORTS - fprintf(stderr, "%.5lx: write to port 1 at %.5lx\n", - saturn.PC, addr); -#endif - return; - } - if (addr >= 0x7e000 && addr < 0x7f000 && - saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0x7e000) - { -#ifdef DEBUG_PORTS - fprintf(stderr, "%.5lx: write to port 2 at %.5lx\n", - saturn.PC, addr); -#endif - return; - } -#ifdef DEBUG_BAD_MEM - fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", - saturn.PC, addr); -#endif - return; - case 8: - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) - { - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfc000 - && addr < 0x84000) - { - saturn.ram[addr - 0x80000] = val; - break; - } - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfe000 - && addr < 0x82000) - { - saturn.ram[addr - 0x80000] = val; - break; - } - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xf0000) - { - saturn.ram[addr - 0x80000] = val; - break; - } - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) - { - saturn.ram[addr - 0x80000] = val; - break; - } - } -#ifdef DEBUG_BAD_MEM - fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", - saturn.PC, addr); -#endif - return; - case 9: - if (saturn.mem_cntl[MCTL_BANK_GX].config[0] == 0x90000) - { - if (addr < 0x91000) - { -#ifdef DEBUG_BANK_SWITCH - fprintf(stderr, "%.5lx: write to bank switch at %.5lx\n", - saturn.PC, addr); -#endif - return; - } - } - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) - { - saturn.ram[addr - 0x80000] = val; - break; - } -#ifdef DEBUG_BAD_MEM - fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", - saturn.PC, addr); -#endif - return; - case 0xa: - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) - { - saturn.ram[addr - 0x80000] = val; - break; - } - if (saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0xa0000) - { - if (port1_is_ram) - saturn.port1[(addr - 0xa0000) & port1_mask] = val; - return; - } -#ifdef DEBUG_BAD_MEM - fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", - saturn.PC, addr); -#endif - return; - case 0xb: - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) - { - saturn.ram[addr - 0x80000] = val; - break; - } - if (saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0xb0000) - { - if (port2_is_ram) - saturn.port2[((saturn.bank_switch << 18) + (addr - 0xb0000)) - & port2_mask] = val; -/* - if (port2_size > (saturn.bank_switch << 18)) - { - if (port2_is_ram) - saturn.port2[(saturn.bank_switch << 18) - + (addr - 0xb0000)] = val; - } -*/ - return; - } -#ifdef DEBUG_BAD_MEM - fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", - saturn.PC, addr); -#endif - return; - case 0xc: - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0xc0000) - { - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfc000 - && addr < 0xc4000) - { - saturn.ram[addr - 0xc0000] = val; - break; - } - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfe000 - && addr < 0xc2000) - { - saturn.ram[addr - 0xc0000] = val; - break; - } - saturn.ram[addr - 0xc0000] = val; - break; - } - if (saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0xc0000) - { - if (port1_is_ram) - saturn.port1[(addr - 0xc0000) & port1_mask] = val; - return; - } - if (saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0xc0000) - { - if (port2_is_ram) - saturn.port2[((saturn.bank_switch << 18) + (addr - 0xc0000)) - & port2_mask] = val; -/* - if (port2_size > (saturn.bank_switch << 18)) - { - if (port2_is_ram) - saturn.port2[(saturn.bank_switch << 18) - + (addr - 0xc0000)] = val; - } -*/ - return; - } -#ifdef DEBUG_BAD_MEM - fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", - saturn.PC, addr); -#endif - return; - case 0xd: case 0xe: case 0xf: - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0xc0000) - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) - { - saturn.ram[addr - 0xc0000] = val; - break; - } - if (saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0xc0000) - if (saturn.mem_cntl[MCTL_PORT1_GX].config[1] == 0xc0000) - { - if (port1_is_ram) - saturn.port1[(addr - 0xc0000) & port1_mask] = val; - return; - } - if (saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0xc0000) - if (saturn.mem_cntl[MCTL_PORT2_GX].config[1] == 0xc0000) - { - if (port2_is_ram) - saturn.port2[((saturn.bank_switch << 18) + (addr - 0xc0000)) - & port2_mask] = val; -/* - if (port2_size > (saturn.bank_switch << 18)) - { - if (port2_is_ram) - saturn.port2[(saturn.bank_switch << 18) - + (addr - 0xc0000)] = val; - } -*/ - return; - } -#ifdef DEBUG_BAD_MEM - fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", - saturn.PC, addr); -#endif - return; + switch ((int)(addr >> 16) & 0x0f) { + case 0: + if (addr < 0x140 && addr >= 0x100 && + saturn.mem_cntl[MCTL_MMIO_GX].config[0] == 0x100) { + write_dev_mem(addr, val); + return; } +#ifdef DEBUG_BAD_MEM + fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", saturn.PC, addr); +#endif + return; + case 1: + case 2: + case 3: + case 5: + case 6: +#ifdef DEBUG_BAD_MEM + fprintf(stderr, "%.5lx: BAD WRITE TO ROM AT ADDRESS %.5lx\n", saturn.PC, + addr); +#endif + return; + case 4: + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x40000) { + saturn.ram[addr - 0x40000] = val; + break; + } +#ifdef DEBUG_BAD_MEM + fprintf(stderr, "%.5lx: BAD WRITE TO ROM AT ADDRESS %.5lx\n", saturn.PC, + addr); +#endif + return; + case 7: + if (addr >= 0x7f000 && saturn.mem_cntl[MCTL_BANK_GX].config[0] == 0x7f000) { +#ifdef DEBUG_BANK_SWITCH + fprintf(stderr, "%.5lx: write to bank switch at %.5lx\n", saturn.PC, + addr); +#endif + return; + } + if (addr >= 0x7e000 && addr < 0x7f000 && + saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0x7e000) { +#ifdef DEBUG_PORTS + fprintf(stderr, "%.5lx: write to port 1 at %.5lx\n", saturn.PC, addr); +#endif + return; + } + if (addr >= 0x7e000 && addr < 0x7f000 && + saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0x7e000) { +#ifdef DEBUG_PORTS + fprintf(stderr, "%.5lx: write to port 2 at %.5lx\n", saturn.PC, addr); +#endif + return; + } +#ifdef DEBUG_BAD_MEM + fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", saturn.PC, addr); +#endif + return; + case 8: + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) { + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfc000 && + addr < 0x84000) { + saturn.ram[addr - 0x80000] = val; + break; + } + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfe000 && + addr < 0x82000) { + saturn.ram[addr - 0x80000] = val; + break; + } + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xf0000) { + saturn.ram[addr - 0x80000] = val; + break; + } + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) { + saturn.ram[addr - 0x80000] = val; + break; + } + } +#ifdef DEBUG_BAD_MEM + fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", saturn.PC, addr); +#endif + return; + case 9: + if (saturn.mem_cntl[MCTL_BANK_GX].config[0] == 0x90000) { + if (addr < 0x91000) { +#ifdef DEBUG_BANK_SWITCH + fprintf(stderr, "%.5lx: write to bank switch at %.5lx\n", saturn.PC, + addr); +#endif + return; + } + } + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) { + saturn.ram[addr - 0x80000] = val; + break; + } +#ifdef DEBUG_BAD_MEM + fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", saturn.PC, addr); +#endif + return; + case 0xa: + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) { + saturn.ram[addr - 0x80000] = val; + break; + } + if (saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0xa0000) { + if (port1_is_ram) + saturn.port1[(addr - 0xa0000) & port1_mask] = val; + return; + } +#ifdef DEBUG_BAD_MEM + fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", saturn.PC, addr); +#endif + return; + case 0xb: + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) { + saturn.ram[addr - 0x80000] = val; + break; + } + if (saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0xb0000) { + if (port2_is_ram) + saturn.port2[((saturn.bank_switch << 18) + (addr - 0xb0000)) & + port2_mask] = val; + /* + if (port2_size > (saturn.bank_switch << 18)) + { + if (port2_is_ram) + saturn.port2[(saturn.bank_switch << 18) + + (addr - 0xb0000)] = val; + } + */ + return; + } +#ifdef DEBUG_BAD_MEM + fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", saturn.PC, addr); +#endif + return; + case 0xc: + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0xc0000) { + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfc000 && + addr < 0xc4000) { + saturn.ram[addr - 0xc0000] = val; + break; + } + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfe000 && + addr < 0xc2000) { + saturn.ram[addr - 0xc0000] = val; + break; + } + saturn.ram[addr - 0xc0000] = val; + break; + } + if (saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0xc0000) { + if (port1_is_ram) + saturn.port1[(addr - 0xc0000) & port1_mask] = val; + return; + } + if (saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0xc0000) { + if (port2_is_ram) + saturn.port2[((saturn.bank_switch << 18) + (addr - 0xc0000)) & + port2_mask] = val; + /* + if (port2_size > (saturn.bank_switch << 18)) + { + if (port2_is_ram) + saturn.port2[(saturn.bank_switch << 18) + + (addr - 0xc0000)] = val; + } + */ + return; + } +#ifdef DEBUG_BAD_MEM + fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", saturn.PC, addr); +#endif + return; + case 0xd: + case 0xe: + case 0xf: + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0xc0000) + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) { + saturn.ram[addr - 0xc0000] = val; + break; + } + if (saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0xc0000) + if (saturn.mem_cntl[MCTL_PORT1_GX].config[1] == 0xc0000) { + if (port1_is_ram) + saturn.port1[(addr - 0xc0000) & port1_mask] = val; + return; + } + if (saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0xc0000) + if (saturn.mem_cntl[MCTL_PORT2_GX].config[1] == 0xc0000) { + if (port2_is_ram) + saturn.port2[((saturn.bank_switch << 18) + (addr - 0xc0000)) & + port2_mask] = val; + /* + if (port2_size > (saturn.bank_switch << 18)) + { + if (port2_is_ram) + saturn.port2[(saturn.bank_switch << 18) + + (addr - 0xc0000)] = val; + } + */ + return; + } +#ifdef DEBUG_BAD_MEM + fprintf(stderr, "%.5lx: write to ROM at %.5lx\n", saturn.PC, addr); +#endif + return; + } if (device.display_touched || !disp.mapped) return; - if (addr >= display.disp_start && addr < display.disp_end) - { - disp_draw_nibble(addr, val); - } + if (addr >= display.disp_start && addr < display.disp_end) { + disp_draw_nibble(addr, val); + } if (display.lines == 63) return; - if (addr >= display.menu_start && addr < display.menu_end) - { - menu_draw_nibble(addr, val); - } + if (addr >= display.menu_start && addr < display.menu_end) { + menu_draw_nibble(addr, val); + } return; } int read_nibble_sx(long addr) { addr &= 0xfffff; switch ((int)(addr >> 16) & 0x0f) { - case 0: - if (addr < 0x140 && addr >= 0x100) - { - if (saturn.mem_cntl[MCTL_MMIO_SX].config[0] == 0x100) - return read_dev_mem(addr); - else - return 0x00; - } - return saturn.rom[addr]; - case 1: case 2: case 3: case 4: case 5: case 6: - return saturn.rom[addr]; - case 7: - if (saturn.mem_cntl[MCTL_SysRAM_SX].config[0] == 0x70000) - { - if (saturn.mem_cntl[MCTL_SysRAM_SX].config[1] == 0xfc000 - && addr < 0x74000) - return saturn.ram[addr - 0x70000]; - if (saturn.mem_cntl[MCTL_SysRAM_SX].config[1] == 0xfe000 - && addr < 0x72000) - return saturn.ram[addr - 0x70000]; - if (saturn.mem_cntl[MCTL_SysRAM_SX].config[1] == 0xf0000) - return saturn.ram[addr - 0x70000]; - } - return saturn.rom[addr]; - case 8: case 9: case 0xa: case 0xb: - if (saturn.mem_cntl[MCTL_PORT1_SX].config[0] == 0x80000) - { - return saturn.port1[(addr - 0x80000) & port1_mask]; - } - if (saturn.mem_cntl[MCTL_PORT2_SX].config[0] == 0x80000) - { - return saturn.port2[(addr - 0x80000) & port2_mask]; - } - return 0x00; - case 0xc: case 0xd: case 0xe: - if (saturn.mem_cntl[MCTL_PORT1_SX].config[0] == 0xc0000) - { - return saturn.port1[(addr - 0xc0000) & port1_mask]; - } - if (saturn.mem_cntl[MCTL_PORT2_SX].config[0] == 0xc0000) - { - return saturn.port2[(addr - 0xc0000) & port2_mask]; - } - return 0x00; - case 0xf: - if (saturn.mem_cntl[MCTL_SysRAM_SX].config[0] == 0xf0000) - return saturn.ram[addr - 0xf0000]; - if (saturn.mem_cntl[MCTL_PORT1_SX].config[0] == 0xc0000) - { - return saturn.port1[(addr - 0xc0000) & port1_mask]; - } - if (saturn.mem_cntl[MCTL_PORT2_SX].config[0] == 0xc0000) - { - return saturn.port2[(addr - 0xc0000) & port2_mask]; - } - return 0x00; + case 0: + if (addr < 0x140 && addr >= 0x100) { + if (saturn.mem_cntl[MCTL_MMIO_SX].config[0] == 0x100) + return read_dev_mem(addr); + else + return 0x00; + } + return saturn.rom[addr]; + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + return saturn.rom[addr]; + case 7: + if (saturn.mem_cntl[MCTL_SysRAM_SX].config[0] == 0x70000) { + if (saturn.mem_cntl[MCTL_SysRAM_SX].config[1] == 0xfc000 && + addr < 0x74000) + return saturn.ram[addr - 0x70000]; + if (saturn.mem_cntl[MCTL_SysRAM_SX].config[1] == 0xfe000 && + addr < 0x72000) + return saturn.ram[addr - 0x70000]; + if (saturn.mem_cntl[MCTL_SysRAM_SX].config[1] == 0xf0000) + return saturn.ram[addr - 0x70000]; + } + return saturn.rom[addr]; + case 8: + case 9: + case 0xa: + case 0xb: + if (saturn.mem_cntl[MCTL_PORT1_SX].config[0] == 0x80000) { + return saturn.port1[(addr - 0x80000) & port1_mask]; + } + if (saturn.mem_cntl[MCTL_PORT2_SX].config[0] == 0x80000) { + return saturn.port2[(addr - 0x80000) & port2_mask]; + } + return 0x00; + case 0xc: + case 0xd: + case 0xe: + if (saturn.mem_cntl[MCTL_PORT1_SX].config[0] == 0xc0000) { + return saturn.port1[(addr - 0xc0000) & port1_mask]; + } + if (saturn.mem_cntl[MCTL_PORT2_SX].config[0] == 0xc0000) { + return saturn.port2[(addr - 0xc0000) & port2_mask]; + } + return 0x00; + case 0xf: + if (saturn.mem_cntl[MCTL_SysRAM_SX].config[0] == 0xf0000) + return saturn.ram[addr - 0xf0000]; + if (saturn.mem_cntl[MCTL_PORT1_SX].config[0] == 0xc0000) { + return saturn.port1[(addr - 0xc0000) & port1_mask]; + } + if (saturn.mem_cntl[MCTL_PORT2_SX].config[0] == 0xc0000) { + return saturn.port2[(addr - 0xc0000) & port2_mask]; + } + return 0x00; } return 0x00; } int read_nibble_gx(long addr) { addr &= 0xfffff; - switch ((int)(addr >> 16) & 0x0f) - { - case 0: - if (addr < 0x140 && addr >= 0x100) - { - if (saturn.mem_cntl[0].config[0] == 0x100) - return read_dev_mem(addr); - else - return 0x00; - } - return saturn.rom[addr]; - case 1: case 2: case 3: case 5: case 6: - return saturn.rom[addr]; - case 4: - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x40000) - return saturn.ram[addr - 0x40000]; - return saturn.rom[addr]; - case 7: - if (addr >= 0x7f000 && - saturn.mem_cntl[MCTL_BANK_GX].config[0] == 0x7f000) - { - if (addr == 0x7f000) - { - saturn.bank_switch = 0; -#ifdef DEBUG_BANK_SWITCH - fprintf(stderr, "%.5lx: disable bank switch\n", saturn.PC); -#endif - } - if (addr >= 0x7f040 && addr < 0x7f080) - { - saturn.bank_switch = (addr - 0x7f040) / 2; -#ifdef DEBUG_BANK_SWITCH - fprintf(stderr, "%.5lx: switch to bank %d\n", - saturn.PC, saturn.bank_switch); -#endif - } - return 0x7; - } - if (addr >= 0x7e000 && addr < 0x7f000 && - saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0x7e000) - { -#ifdef DEBUG_PORTS - fprintf(stderr, "%.5lx: read from port 1 at %.5lx\n", - saturn.PC, addr); -#endif - return 0x7; - } - if (addr >= 0x7e000 && addr < 0x7f000 && - saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0x7e000) - { -#ifdef DEBUG_PORTS - fprintf(stderr, "%.5lx: read from port 2 at %.5lx\n", - saturn.PC, addr); -#endif - return 0x7; - } - return saturn.rom[addr]; - case 8: - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) - { - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfc000 - && addr < 0x84000) - return saturn.ram[addr - 0x80000]; - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfe000 - && addr < 0x82000) - return saturn.ram[addr - 0x80000]; - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xf0000) - return saturn.ram[addr - 0x80000]; - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) - return saturn.ram[addr - 0x80000]; - } - return saturn.rom[addr]; - case 9: - if (saturn.mem_cntl[0].config[0] == 0x90000) - { - if (addr < 0x91000) - { - if (addr == 0x90000) - { - saturn.bank_switch = 0; -#ifdef DEBUG_BANK_SWITCH - fprintf(stderr, "%.5lx: disable bank switch\n", saturn.PC); -#endif - } - if (addr >= 0x90040 && addr < 0x90080) - { - saturn.bank_switch = (addr - 0x90040) / 2; -#ifdef DEBUG_BANK_SWITCH - fprintf(stderr, "%.5lx: switch to bank %d\n", - saturn.PC, saturn.bank_switch); -#endif - } - return 0x7; - } - } - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) - return saturn.ram[addr - 0x80000]; - return saturn.rom[addr]; - case 0xa: - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) - return saturn.ram[addr - 0x80000]; - if (saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0xa0000) - { - return saturn.port1[(addr - 0xa0000) & port1_mask]; - } - return saturn.rom[addr]; - case 0xb: - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) - return saturn.ram[addr - 0x80000]; - if (saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0xb0000) - { - return saturn.port2[((saturn.bank_switch << 18) + (addr - 0xb0000)) - & port2_mask]; -/* - if (port2_size > (saturn.bank_switch << 18)) - { - return saturn.port2[(saturn.bank_switch << 18) - + (addr - 0xb0000)]; - } - return 0x00; -*/ - } - return saturn.rom[addr]; - case 0xc: - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0xc0000) - { - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfc000 - && addr < 0xc4000) - return saturn.ram[addr - 0xc0000]; - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfe000 - && addr < 0xc2000) - return saturn.ram[addr - 0xc0000]; - return saturn.ram[addr - 0xc0000]; - } - if (saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0xc0000) - { - return saturn.port1[(addr - 0xc0000) & port1_mask]; - } - if (saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0xc0000) - { - return saturn.port2[((saturn.bank_switch << 18) + (addr - 0xc0000)) - & port2_mask]; -/* - if (port2_size > (saturn.bank_switch << 18)) - { - return saturn.port2[(saturn.bank_switch << 18) - + (addr - 0xc0000)]; - } - return 0x00; -*/ - } - return saturn.rom[addr]; - case 0xd: case 0xe: case 0xf: - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0xc0000) - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) - return saturn.ram[addr - 0xc0000]; - if (saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0xc0000) - if (saturn.mem_cntl[MCTL_PORT1_GX].config[1] == 0xc0000) - { - return saturn.port1[(addr - 0xc0000) & port1_mask]; - } - if (saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0xc0000) - if (saturn.mem_cntl[MCTL_PORT2_GX].config[1] == 0xc0000) - { - return saturn.port2[((saturn.bank_switch << 18) + - (addr - 0xc0000)) & port2_mask]; -/* - if (port2_size > (saturn.bank_switch << 18)) - { - return saturn.port2[(saturn.bank_switch << 18) - + (addr - 0xc0000)]; - } - return 0x00; -*/ - } - return saturn.rom[addr]; + switch ((int)(addr >> 16) & 0x0f) { + case 0: + if (addr < 0x140 && addr >= 0x100) { + if (saturn.mem_cntl[0].config[0] == 0x100) + return read_dev_mem(addr); + else + return 0x00; } + return saturn.rom[addr]; + case 1: + case 2: + case 3: + case 5: + case 6: + return saturn.rom[addr]; + case 4: + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x40000) + return saturn.ram[addr - 0x40000]; + return saturn.rom[addr]; + case 7: + if (addr >= 0x7f000 && saturn.mem_cntl[MCTL_BANK_GX].config[0] == 0x7f000) { + if (addr == 0x7f000) { + saturn.bank_switch = 0; +#ifdef DEBUG_BANK_SWITCH + fprintf(stderr, "%.5lx: disable bank switch\n", saturn.PC); +#endif + } + if (addr >= 0x7f040 && addr < 0x7f080) { + saturn.bank_switch = (addr - 0x7f040) / 2; +#ifdef DEBUG_BANK_SWITCH + fprintf(stderr, "%.5lx: switch to bank %d\n", saturn.PC, + saturn.bank_switch); +#endif + } + return 0x7; + } + if (addr >= 0x7e000 && addr < 0x7f000 && + saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0x7e000) { +#ifdef DEBUG_PORTS + fprintf(stderr, "%.5lx: read from port 1 at %.5lx\n", saturn.PC, addr); +#endif + return 0x7; + } + if (addr >= 0x7e000 && addr < 0x7f000 && + saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0x7e000) { +#ifdef DEBUG_PORTS + fprintf(stderr, "%.5lx: read from port 2 at %.5lx\n", saturn.PC, addr); +#endif + return 0x7; + } + return saturn.rom[addr]; + case 8: + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) { + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfc000 && + addr < 0x84000) + return saturn.ram[addr - 0x80000]; + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfe000 && + addr < 0x82000) + return saturn.ram[addr - 0x80000]; + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xf0000) + return saturn.ram[addr - 0x80000]; + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) + return saturn.ram[addr - 0x80000]; + } + return saturn.rom[addr]; + case 9: + if (saturn.mem_cntl[0].config[0] == 0x90000) { + if (addr < 0x91000) { + if (addr == 0x90000) { + saturn.bank_switch = 0; +#ifdef DEBUG_BANK_SWITCH + fprintf(stderr, "%.5lx: disable bank switch\n", saturn.PC); +#endif + } + if (addr >= 0x90040 && addr < 0x90080) { + saturn.bank_switch = (addr - 0x90040) / 2; +#ifdef DEBUG_BANK_SWITCH + fprintf(stderr, "%.5lx: switch to bank %d\n", saturn.PC, + saturn.bank_switch); +#endif + } + return 0x7; + } + } + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) + return saturn.ram[addr - 0x80000]; + return saturn.rom[addr]; + case 0xa: + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) + return saturn.ram[addr - 0x80000]; + if (saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0xa0000) { + return saturn.port1[(addr - 0xa0000) & port1_mask]; + } + return saturn.rom[addr]; + case 0xb: + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) + return saturn.ram[addr - 0x80000]; + if (saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0xb0000) { + return saturn + .port2[((saturn.bank_switch << 18) + (addr - 0xb0000)) & port2_mask]; + /* + if (port2_size > (saturn.bank_switch << 18)) + { + return saturn.port2[(saturn.bank_switch << 18) + + (addr - 0xb0000)]; + } + return 0x00; + */ + } + return saturn.rom[addr]; + case 0xc: + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0xc0000) { + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfc000 && + addr < 0xc4000) + return saturn.ram[addr - 0xc0000]; + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfe000 && + addr < 0xc2000) + return saturn.ram[addr - 0xc0000]; + return saturn.ram[addr - 0xc0000]; + } + if (saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0xc0000) { + return saturn.port1[(addr - 0xc0000) & port1_mask]; + } + if (saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0xc0000) { + return saturn + .port2[((saturn.bank_switch << 18) + (addr - 0xc0000)) & port2_mask]; + /* + if (port2_size > (saturn.bank_switch << 18)) + { + return saturn.port2[(saturn.bank_switch << 18) + + (addr - 0xc0000)]; + } + return 0x00; + */ + } + return saturn.rom[addr]; + case 0xd: + case 0xe: + case 0xf: + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0xc0000) + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) + return saturn.ram[addr - 0xc0000]; + if (saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0xc0000) + if (saturn.mem_cntl[MCTL_PORT1_GX].config[1] == 0xc0000) { + return saturn.port1[(addr - 0xc0000) & port1_mask]; + } + if (saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0xc0000) + if (saturn.mem_cntl[MCTL_PORT2_GX].config[1] == 0xc0000) { + return saturn.port2[((saturn.bank_switch << 18) + (addr - 0xc0000)) & + port2_mask]; + /* + if (port2_size > (saturn.bank_switch << 18)) + { + return saturn.port2[(saturn.bank_switch << 18) + + (addr - 0xc0000)]; + } + return 0x00; + */ + } + return saturn.rom[addr]; + } return 0x00; } int read_nibble_crc_sx(long addr) { addr &= 0xfffff; switch ((int)(addr >> 16) & 0x0f) { - case 0: - if (addr < 0x140 && addr >= 0x100) - { - if (saturn.mem_cntl[MCTL_MMIO_SX].config[0] == 0x100) - return read_dev_mem(addr); - else - return calc_crc(0x00); - } - return calc_crc(saturn.rom[addr]); - case 1: case 2: case 3: case 4: case 5: case 6: - return calc_crc(saturn.rom[addr]); - case 7: - if (saturn.mem_cntl[MCTL_SysRAM_SX].config[0] == 0x70000) - { - if (saturn.mem_cntl[MCTL_SysRAM_SX].config[1] == 0xfc000 - && addr < 0x74000) - return calc_crc(saturn.ram[addr - 0x70000]); - if (saturn.mem_cntl[MCTL_SysRAM_SX].config[1] == 0xfe000 - && addr < 0x72000) - return calc_crc(saturn.ram[addr - 0x70000]); - if (saturn.mem_cntl[MCTL_SysRAM_SX].config[1] == 0xf0000) - return calc_crc(saturn.ram[addr - 0x70000]); - } - return calc_crc(saturn.rom[addr]); - case 8: case 9: case 0xa: case 0xb: - if (saturn.mem_cntl[MCTL_PORT1_SX].config[0] == 0x80000) - { - return calc_crc(saturn.port1[(addr - 0x80000) & port1_mask]); - } - if (saturn.mem_cntl[MCTL_PORT2_SX].config[0] == 0x80000) - { - return calc_crc(saturn.port2[(addr - 0x80000) & port2_mask]); - } - return 0x00; - case 0xc: case 0xd: case 0xe: - if (saturn.mem_cntl[MCTL_PORT1_SX].config[0] == 0xc0000) - { - return calc_crc(saturn.port1[(addr - 0xc0000) & port1_mask]); - } - if (saturn.mem_cntl[MCTL_PORT2_SX].config[0] == 0xc0000) - { - return calc_crc(saturn.port2[(addr - 0xc0000) & port2_mask]); - } - return 0x00; - case 0xf: - if (saturn.mem_cntl[MCTL_SysRAM_SX].config[0] == 0xf0000) - return calc_crc(saturn.ram[addr - 0xf0000]); - if (saturn.mem_cntl[MCTL_PORT1_SX].config[0] == 0xc0000) - { - return calc_crc(saturn.port1[(addr - 0xc0000) & port1_mask]); - } - if (saturn.mem_cntl[MCTL_PORT2_SX].config[0] == 0xc0000) - { - return calc_crc(saturn.port2[(addr - 0xc0000) & port2_mask]); - } - return 0x00; + case 0: + if (addr < 0x140 && addr >= 0x100) { + if (saturn.mem_cntl[MCTL_MMIO_SX].config[0] == 0x100) + return read_dev_mem(addr); + else + return calc_crc(0x00); + } + return calc_crc(saturn.rom[addr]); + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + return calc_crc(saturn.rom[addr]); + case 7: + if (saturn.mem_cntl[MCTL_SysRAM_SX].config[0] == 0x70000) { + if (saturn.mem_cntl[MCTL_SysRAM_SX].config[1] == 0xfc000 && + addr < 0x74000) + return calc_crc(saturn.ram[addr - 0x70000]); + if (saturn.mem_cntl[MCTL_SysRAM_SX].config[1] == 0xfe000 && + addr < 0x72000) + return calc_crc(saturn.ram[addr - 0x70000]); + if (saturn.mem_cntl[MCTL_SysRAM_SX].config[1] == 0xf0000) + return calc_crc(saturn.ram[addr - 0x70000]); + } + return calc_crc(saturn.rom[addr]); + case 8: + case 9: + case 0xa: + case 0xb: + if (saturn.mem_cntl[MCTL_PORT1_SX].config[0] == 0x80000) { + return calc_crc(saturn.port1[(addr - 0x80000) & port1_mask]); + } + if (saturn.mem_cntl[MCTL_PORT2_SX].config[0] == 0x80000) { + return calc_crc(saturn.port2[(addr - 0x80000) & port2_mask]); + } + return 0x00; + case 0xc: + case 0xd: + case 0xe: + if (saturn.mem_cntl[MCTL_PORT1_SX].config[0] == 0xc0000) { + return calc_crc(saturn.port1[(addr - 0xc0000) & port1_mask]); + } + if (saturn.mem_cntl[MCTL_PORT2_SX].config[0] == 0xc0000) { + return calc_crc(saturn.port2[(addr - 0xc0000) & port2_mask]); + } + return 0x00; + case 0xf: + if (saturn.mem_cntl[MCTL_SysRAM_SX].config[0] == 0xf0000) + return calc_crc(saturn.ram[addr - 0xf0000]); + if (saturn.mem_cntl[MCTL_PORT1_SX].config[0] == 0xc0000) { + return calc_crc(saturn.port1[(addr - 0xc0000) & port1_mask]); + } + if (saturn.mem_cntl[MCTL_PORT2_SX].config[0] == 0xc0000) { + return calc_crc(saturn.port2[(addr - 0xc0000) & port2_mask]); + } + return 0x00; } return 0x00; } int read_nibble_crc_gx(long addr) { addr &= 0xfffff; - switch ((int)(addr >> 16) & 0x0f) - { - case 0: - if (addr < 0x140 && addr >= 0x100) - { - if (saturn.mem_cntl[MCTL_MMIO_GX].config[0] == 0x100) - return read_dev_mem(addr); - else - return calc_crc(0x00); - } - return calc_crc(saturn.rom[addr]); - case 1: case 2: case 3: case 5: case 6: - return calc_crc(saturn.rom[addr]); - case 4: - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x40000) - return calc_crc(saturn.ram[addr - 0x40000]); - return calc_crc(saturn.rom[addr]); - case 7: - if (addr >= 0x7f000 && - saturn.mem_cntl[MCTL_BANK_GX].config[0] == 0x7f000) - { - if (addr == 0x7f000) - { - saturn.bank_switch = 0; -#ifdef DEBUG_BANK_SWITCH - fprintf(stderr, "%.5lx: disable bank switch\n", saturn.PC); -#endif - } - if (addr >= 0x7f040 && addr < 0x7f080) - { - saturn.bank_switch = (addr - 0x7f040) / 2; -#ifdef DEBUG_BANK_SWITCH - fprintf(stderr, "%.5lx: switch to bank %d\n", - saturn.PC, saturn.bank_switch); -#endif - } - return 0x7; - } - if (addr >= 0x7e000 && addr < 0x7f000 && - saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0x7e000) - { -#ifdef DEBUG_PORTS - fprintf(stderr, "%.5lx: read from port 1 at %.5lx\n", - saturn.PC, addr); -#endif - return 0x7; - } - if (addr >= 0x7e000 && addr < 0x7f000 && - saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0x7e000) - { -#ifdef DEBUG_PORTS - fprintf(stderr, "%.5lx: read from port 2 at %.5lx\n", - saturn.PC, addr); -#endif - return 0x7; - } - return calc_crc(saturn.rom[addr]); - case 8: - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) - { - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfc000 - && addr < 0x84000) - return calc_crc(saturn.ram[addr - 0x80000]); - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfe000 - && addr < 0x82000) - return calc_crc(saturn.ram[addr - 0x80000]); - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xf0000) - return calc_crc(saturn.ram[addr - 0x80000]); - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) - return calc_crc(saturn.ram[addr - 0x80000]); - } - return calc_crc(saturn.rom[addr]); - case 9: - if (saturn.mem_cntl[0].config[0] == 0x90000) - { - if (addr < 0x91000) - { - if (addr == 0x90000) - { - saturn.bank_switch = 0; -#ifdef DEBUG_BANK_SWITCH - fprintf(stderr, "%.5lx: disable bank switch\n", saturn.PC); -#endif - } - if (addr >= 0x90040 && addr < 0x90080) - { - saturn.bank_switch = (addr - 0x90040) / 2; -#ifdef DEBUG_BANK_SWITCH - fprintf(stderr, "%.5lx: switch to bank %d\n", - saturn.PC, saturn.bank_switch); -#endif - } - return 0x7; - } - } - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) - return calc_crc(saturn.ram[addr - 0x80000]); - return calc_crc(saturn.rom[addr]); - case 0xa: - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) - return calc_crc(saturn.ram[addr - 0x80000]); - if (saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0xa0000) - { - return calc_crc(saturn.port1[(addr - 0xa0000) & port1_mask]); - } - return calc_crc(saturn.rom[addr]); - case 0xb: - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) - return calc_crc(saturn.ram[addr - 0x80000]); - if (saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0xb0000) - { - return calc_crc(saturn.port2[((saturn.bank_switch << 18) + - (addr - 0xb0000)) & port2_mask]); -/* - if (port2_size > (saturn.bank_switch << 18)) - { - return calc_crc(saturn.port2[(saturn.bank_switch << 18) - + (addr - 0xb0000)]); - } - return 0x00; -*/ - } - return calc_crc(saturn.rom[addr]); - case 0xc: - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0xc0000) - { - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfc000 - && addr < 0xc4000) - return calc_crc(saturn.ram[addr - 0xc0000]); - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfe000 - && addr < 0xc2000) - return calc_crc(saturn.ram[addr - 0xc0000]); - return calc_crc(saturn.ram[addr - 0xc0000]); - } - if (saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0xc0000) - { - return calc_crc(saturn.port1[(addr - 0xc0000) & port1_mask]); - } - if (saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0xc0000) - { - return calc_crc(saturn.port2[((saturn.bank_switch << 18) + - (addr - 0xc0000)) & port2_mask]); -/* - if (port2_size > (saturn.bank_switch << 18)) - { - return calc_crc(saturn.port2[(saturn.bank_switch << 18) - + (addr - 0xc0000)]); - } - return 0x00; -*/ - } - return calc_crc(saturn.rom[addr]); - case 0xd: case 0xe: case 0xf: - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0xc0000) - if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) - return calc_crc(saturn.ram[addr - 0xc0000]); - if (saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0xc0000) - if (saturn.mem_cntl[MCTL_PORT1_GX].config[1] == 0xc0000) - { - return calc_crc(saturn.port1[(addr - 0xc0000) & port1_mask]); - } - if (saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0xc0000) - if (saturn.mem_cntl[MCTL_PORT2_GX].config[1] == 0xc0000) - { - return calc_crc(saturn.port2[((saturn.bank_switch << 18) + - (addr - 0xc0000)) & port2_mask]); -/* - if (port2_size > (saturn.bank_switch << 18)) - { - return calc_crc(saturn.port2[(saturn.bank_switch << 18) - + (addr - 0xc0000)]); - } - return 0x00; -*/ - } - return calc_crc(saturn.rom[addr]); + switch ((int)(addr >> 16) & 0x0f) { + case 0: + if (addr < 0x140 && addr >= 0x100) { + if (saturn.mem_cntl[MCTL_MMIO_GX].config[0] == 0x100) + return read_dev_mem(addr); + else + return calc_crc(0x00); } + return calc_crc(saturn.rom[addr]); + case 1: + case 2: + case 3: + case 5: + case 6: + return calc_crc(saturn.rom[addr]); + case 4: + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x40000) + return calc_crc(saturn.ram[addr - 0x40000]); + return calc_crc(saturn.rom[addr]); + case 7: + if (addr >= 0x7f000 && saturn.mem_cntl[MCTL_BANK_GX].config[0] == 0x7f000) { + if (addr == 0x7f000) { + saturn.bank_switch = 0; +#ifdef DEBUG_BANK_SWITCH + fprintf(stderr, "%.5lx: disable bank switch\n", saturn.PC); +#endif + } + if (addr >= 0x7f040 && addr < 0x7f080) { + saturn.bank_switch = (addr - 0x7f040) / 2; +#ifdef DEBUG_BANK_SWITCH + fprintf(stderr, "%.5lx: switch to bank %d\n", saturn.PC, + saturn.bank_switch); +#endif + } + return 0x7; + } + if (addr >= 0x7e000 && addr < 0x7f000 && + saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0x7e000) { +#ifdef DEBUG_PORTS + fprintf(stderr, "%.5lx: read from port 1 at %.5lx\n", saturn.PC, addr); +#endif + return 0x7; + } + if (addr >= 0x7e000 && addr < 0x7f000 && + saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0x7e000) { +#ifdef DEBUG_PORTS + fprintf(stderr, "%.5lx: read from port 2 at %.5lx\n", saturn.PC, addr); +#endif + return 0x7; + } + return calc_crc(saturn.rom[addr]); + case 8: + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) { + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfc000 && + addr < 0x84000) + return calc_crc(saturn.ram[addr - 0x80000]); + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfe000 && + addr < 0x82000) + return calc_crc(saturn.ram[addr - 0x80000]); + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xf0000) + return calc_crc(saturn.ram[addr - 0x80000]); + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) + return calc_crc(saturn.ram[addr - 0x80000]); + } + return calc_crc(saturn.rom[addr]); + case 9: + if (saturn.mem_cntl[0].config[0] == 0x90000) { + if (addr < 0x91000) { + if (addr == 0x90000) { + saturn.bank_switch = 0; +#ifdef DEBUG_BANK_SWITCH + fprintf(stderr, "%.5lx: disable bank switch\n", saturn.PC); +#endif + } + if (addr >= 0x90040 && addr < 0x90080) { + saturn.bank_switch = (addr - 0x90040) / 2; +#ifdef DEBUG_BANK_SWITCH + fprintf(stderr, "%.5lx: switch to bank %d\n", saturn.PC, + saturn.bank_switch); +#endif + } + return 0x7; + } + } + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) + return calc_crc(saturn.ram[addr - 0x80000]); + return calc_crc(saturn.rom[addr]); + case 0xa: + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) + return calc_crc(saturn.ram[addr - 0x80000]); + if (saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0xa0000) { + return calc_crc(saturn.port1[(addr - 0xa0000) & port1_mask]); + } + return calc_crc(saturn.rom[addr]); + case 0xb: + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0x80000) + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) + return calc_crc(saturn.ram[addr - 0x80000]); + if (saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0xb0000) { + return calc_crc( + saturn.port2[((saturn.bank_switch << 18) + (addr - 0xb0000)) & + port2_mask]); + /* + if (port2_size > (saturn.bank_switch << 18)) + { + return calc_crc(saturn.port2[(saturn.bank_switch << 18) + + (addr - 0xb0000)]); + } + return 0x00; + */ + } + return calc_crc(saturn.rom[addr]); + case 0xc: + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0xc0000) { + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfc000 && + addr < 0xc4000) + return calc_crc(saturn.ram[addr - 0xc0000]); + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xfe000 && + addr < 0xc2000) + return calc_crc(saturn.ram[addr - 0xc0000]); + return calc_crc(saturn.ram[addr - 0xc0000]); + } + if (saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0xc0000) { + return calc_crc(saturn.port1[(addr - 0xc0000) & port1_mask]); + } + if (saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0xc0000) { + return calc_crc( + saturn.port2[((saturn.bank_switch << 18) + (addr - 0xc0000)) & + port2_mask]); + /* + if (port2_size > (saturn.bank_switch << 18)) + { + return calc_crc(saturn.port2[(saturn.bank_switch << 18) + + (addr - 0xc0000)]); + } + return 0x00; + */ + } + return calc_crc(saturn.rom[addr]); + case 0xd: + case 0xe: + case 0xf: + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[0] == 0xc0000) + if (saturn.mem_cntl[MCTL_SysRAM_GX].config[1] == 0xc0000) + return calc_crc(saturn.ram[addr - 0xc0000]); + if (saturn.mem_cntl[MCTL_PORT1_GX].config[0] == 0xc0000) + if (saturn.mem_cntl[MCTL_PORT1_GX].config[1] == 0xc0000) { + return calc_crc(saturn.port1[(addr - 0xc0000) & port1_mask]); + } + if (saturn.mem_cntl[MCTL_PORT2_GX].config[0] == 0xc0000) + if (saturn.mem_cntl[MCTL_PORT2_GX].config[1] == 0xc0000) { + return calc_crc( + saturn.port2[((saturn.bank_switch << 18) + (addr - 0xc0000)) & + port2_mask]); + /* + if (port2_size > (saturn.bank_switch << 18)) + { + return calc_crc(saturn.port2[(saturn.bank_switch << + 18) + + (addr - 0xc0000)]); + } + return 0x00; + */ + } + return calc_crc(saturn.rom[addr]); + } return 0x00; } @@ -1429,17 +1400,14 @@ void write_nibbles(long addr, long val, int len) { } void dev_memory_init(void) { - if (opt_gx) - { - read_nibble = read_nibble_gx; - read_nibble_crc = read_nibble_crc_gx; - write_nibble = write_nibble_gx; - } - else - { - read_nibble = read_nibble_sx; - read_nibble_crc = read_nibble_crc_sx; - write_nibble = write_nibble_sx; - } + if (opt_gx) { + read_nibble = read_nibble_gx; + read_nibble_crc = read_nibble_crc_gx; + write_nibble = write_nibble_gx; + } else { + read_nibble = read_nibble_sx; + read_nibble_crc = read_nibble_crc_sx; + write_nibble = write_nibble_sx; + } memset(&device, 0, sizeof(device)); } diff --git a/src/mkcard.c b/src/mkcard.c index 192be7f..47006f2 100644 --- a/src/mkcard.c +++ b/src/mkcard.c @@ -25,13 +25,12 @@ * $Id: mkcard.c,v 1.1 1995/01/11 18:11:25 ecd Exp ecd $ */ - #include "global.h" #include #include -#include #include +#include #ifdef SUNOS #include #endif @@ -42,18 +41,16 @@ unsigned char *mem; int write_mem_file(char *name, unsigned char *mem, int size) { FILE *fp; - if (NULL == (fp = fopen(name, "w"))) - { - fprintf(stderr, "can\'t open %s\n", name); - return 0; - } + if (NULL == (fp = fopen(name, "w"))) { + fprintf(stderr, "can\'t open %s\n", name); + return 0; + } - if (fwrite(mem, 1, (size_t)size, fp) != size) - { - fprintf(stderr, "can\'t write %s\n", name); - fclose(fp); - return 0; - } + if (fwrite(mem, 1, (size_t)size, fp) != size) { + fprintf(stderr, "can\'t write %s\n", name); + fclose(fp); + return 0; + } fclose(fp); return 1; @@ -65,12 +62,11 @@ int main(int argc, char **argv) { char *asize; unsigned char *core; - if (argc < 2) - { - fprintf(stderr, "usage: %s [32K | 128K | 1M | 2M | 4M] file-name\n", - argv[0]); - exit (1); - } + if (argc < 2) { + fprintf(stderr, "usage: %s [32K | 128K | 1M | 2M | 4M] file-name\n", + argv[0]); + exit(1); + } name = argv[2]; asize = argv[1]; @@ -88,25 +84,23 @@ int main(int argc, char **argv) { size = 0x200000; else if (!strcmp(asize, "4M")) size = 0x400000; - else - { - fprintf(stderr, - "%s: size must be one of 32K, 128K, 256K, 512K, 1M, 2M, or 4M\n", - argv[0]); - exit (1); - } + else { + fprintf(stderr, + "%s: size must be one of 32K, 128K, 256K, 512K, 1M, 2M, or 4M\n", + argv[0]); + exit(1); + } if ((core = (unsigned char *)malloc(size)) == NULL) { fprintf(stderr, "%s: can\'t malloc %ld bytes\n", argv[0], size); - exit (1); + exit(1); } memset(core, 0, size); - if (!write_mem_file(name, core, size)) - { - fprintf(stderr, "%s: can\'t write to %s\n", argv[0], name); - exit (1); - } + if (!write_mem_file(name, core, size)) { + fprintf(stderr, "%s: can\'t write to %s\n", argv[0], name); + exit(1); + } - exit (0); + exit(0); } diff --git a/src/mmu.h b/src/mmu.h index 6d54564..b1797c1 100644 --- a/src/mmu.h +++ b/src/mmu.h @@ -27,23 +27,21 @@ #ifndef _MMU_H #define _MMU_H 1 +#define NR_MCTL 6 -#define NR_MCTL 6 - -#define MCTL_MMIO_SX 0 -#define MCTL_SysRAM_SX 1 -#define MCTL_PORT1_SX 2 -#define MCTL_PORT2_SX 3 -#define MCTL_EXTRA_SX 4 -#define MCTL_SysROM_SX 5 - -#define MCTL_MMIO_GX 0 -#define MCTL_SysRAM_GX 1 -#define MCTL_BANK_GX 2 -#define MCTL_PORT1_GX 3 -#define MCTL_PORT2_GX 4 -#define MCTL_SysROM_GX 5 +#define MCTL_MMIO_SX 0 +#define MCTL_SysRAM_SX 1 +#define MCTL_PORT1_SX 2 +#define MCTL_PORT2_SX 3 +#define MCTL_EXTRA_SX 4 +#define MCTL_SysROM_SX 5 +#define MCTL_MMIO_GX 0 +#define MCTL_SysRAM_GX 1 +#define MCTL_BANK_GX 2 +#define MCTL_PORT1_GX 3 +#define MCTL_PORT2_GX 4 +#define MCTL_SysROM_GX 5 #if 0 extern void init_mmu __ProtoType__((void)); diff --git a/src/options.c b/src/options.c index f27f20c..10367e7 100644 --- a/src/options.c +++ b/src/options.c @@ -44,8 +44,8 @@ #include #include -#include #include +#include #include "constants.h" #include "resources.h" @@ -90,18 +90,19 @@ where options include:\n\ -xrm set Xresource \n\ -/+throttle turn off/on speed emulation\n\ -/+netbook turn off/on netbook layout\n\ -\n", VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL, progname); +\n", + VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL, progname); fflush(stdout); - exit (1); + exit(1); } void show_version(void) { fprintf(stdout, "\n\ %s Version %d.%d.%d, x48 is Copyright (c) 1994-2005 by Eddie C. Dost .\n\ Compiled on %s by <%s> #%d\n\n", - progname, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL, - COMPILE_TIME, COMPILE_BY, COMPILE_VERSION); + progname, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL, COMPILE_TIME, + COMPILE_BY, COMPILE_VERSION); } void show_copyright(void) { diff --git a/src/options.h b/src/options.h index efbbb21..3051329 100644 --- a/src/options.h +++ b/src/options.h @@ -49,72 +49,72 @@ #include static XrmOptionDescRec options[] = { - { "-display", ".display", XrmoptionSepArg, (void *) 0 }, - { "-geometry", "*geometry", XrmoptionSepArg, (void *) 0 }, - { "-iconGeom", "*iconGeom", XrmoptionSepArg, (void *) 0 }, - { "-iconName", "*iconName", XrmoptionSepArg, (void *) 0 }, - { "-iconic", "*iconic", XrmoptionNoArg, (void *) "True" }, - { "-name", (char *) 0, XrmoptionSepArg, (void *) 0 }, - { "-title", "*title", XrmoptionSepArg, (void *) 0 }, + {"-display", ".display", XrmoptionSepArg, (void *)0}, + {"-geometry", "*geometry", XrmoptionSepArg, (void *)0}, + {"-iconGeom", "*iconGeom", XrmoptionSepArg, (void *)0}, + {"-iconName", "*iconName", XrmoptionSepArg, (void *)0}, + {"-iconic", "*iconic", XrmoptionNoArg, (void *)"True"}, + {"-name", (char *)0, XrmoptionSepArg, (void *)0}, + {"-title", "*title", XrmoptionSepArg, (void *)0}, - { "-xshm", "*useXShm", XrmoptionNoArg, (void *) "True" }, - { "+xshm", "*useXShm", XrmoptionNoArg, (void *)"False" }, + {"-xshm", "*useXShm", XrmoptionNoArg, (void *)"True"}, + {"+xshm", "*useXShm", XrmoptionNoArg, (void *)"False"}, - { "-visual", "*visual", XrmoptionSepArg, (void *) 0 }, - { "-mono", "*mono", XrmoptionNoArg, (void *) "True" }, - { "-gray", "*gray", XrmoptionNoArg, (void *) "True" }, - { "-monoIcon", "*monoIcon", XrmoptionNoArg, (void *) "True" }, + {"-visual", "*visual", XrmoptionSepArg, (void *)0}, + {"-mono", "*mono", XrmoptionNoArg, (void *)"True"}, + {"-gray", "*gray", XrmoptionNoArg, (void *)"True"}, + {"-monoIcon", "*monoIcon", XrmoptionNoArg, (void *)"True"}, - { "-version", "*printVersion", XrmoptionNoArg, (void *) "True" }, - { "-copyright", "*printCopyright",XrmoptionNoArg, (void *) "True" }, - { "-warranty", "*printWarranty", XrmoptionNoArg, (void *) "True" }, + {"-version", "*printVersion", XrmoptionNoArg, (void *)"True"}, + {"-copyright", "*printCopyright", XrmoptionNoArg, (void *)"True"}, + {"-warranty", "*printWarranty", XrmoptionNoArg, (void *)"True"}, - { "-smallFont", "*smallLabelFont",XrmoptionSepArg, (void *) 0 }, - { "-mediumFont", "*mediumLabelFont",XrmoptionSepArg, (void *) 0 }, - { "-largeFont", "*largeLabelFont",XrmoptionSepArg, (void *) 0 }, - { "-connFont", "*connectionFont",XrmoptionSepArg, (void *) 0 }, + {"-smallFont", "*smallLabelFont", XrmoptionSepArg, (void *)0}, + {"-mediumFont", "*mediumLabelFont", XrmoptionSepArg, (void *)0}, + {"-largeFont", "*largeLabelFont", XrmoptionSepArg, (void *)0}, + {"-connFont", "*connectionFont", XrmoptionSepArg, (void *)0}, - { "-verbose", "*verbose", XrmoptionNoArg, (void *) "True" }, - { "-quiet", "*quiet", XrmoptionNoArg, (void *) "True" }, + {"-verbose", "*verbose", XrmoptionNoArg, (void *)"True"}, + {"-quiet", "*quiet", XrmoptionNoArg, (void *)"True"}, - { "-terminal", "*useTerminal", XrmoptionNoArg, (void *) "True" }, - { "+terminal", "*useTerminal", XrmoptionNoArg, (void *)"False" }, - { "-serial", "*useSerial", XrmoptionNoArg, (void *) "True" }, - { "+serial", "*useSerial", XrmoptionNoArg, (void *)"False" }, - { "-line", "*serialLine", XrmoptionSepArg, (void *) 0 }, + {"-terminal", "*useTerminal", XrmoptionNoArg, (void *)"True"}, + {"+terminal", "*useTerminal", XrmoptionNoArg, (void *)"False"}, + {"-serial", "*useSerial", XrmoptionNoArg, (void *)"True"}, + {"+serial", "*useSerial", XrmoptionNoArg, (void *)"False"}, + {"-line", "*serialLine", XrmoptionSepArg, (void *)0}, - { "-initialize", "*completeInitialize",XrmoptionNoArg,(void *) "True" }, - { "-reset", "*resetOnStartup",XrmoptionNoArg, (void *) "True" }, - { "-rom", "*romFileName", XrmoptionSepArg, (void *) 0 }, - { "-home", "*homeDirectory", XrmoptionSepArg, (void *) 0 }, + {"-initialize", "*completeInitialize", XrmoptionNoArg, (void *)"True"}, + {"-reset", "*resetOnStartup", XrmoptionNoArg, (void *)"True"}, + {"-rom", "*romFileName", XrmoptionSepArg, (void *)0}, + {"-home", "*homeDirectory", XrmoptionSepArg, (void *)0}, - { "-debug", "*useDebugger", XrmoptionNoArg, (void *)"False" }, - { "+debug", "*useDebugger", XrmoptionNoArg, (void *) "True" }, - { "-disasm", "*disassemblerMnemonics",XrmoptionSepArg,(void *) 0 }, + {"-debug", "*useDebugger", XrmoptionNoArg, (void *)"False"}, + {"+debug", "*useDebugger", XrmoptionNoArg, (void *)"True"}, + {"-disasm", "*disassemblerMnemonics", XrmoptionSepArg, (void *)0}, - { "-xrm", (char *) 0, XrmoptionResArg, (void *) 0 }, - { "-netbook", "*netbook", XrmoptionNoArg, (void *)"False" }, - { "+netbook", "*netbook", XrmoptionNoArg, (void *) "True" }, + {"-xrm", (char *)0, XrmoptionResArg, (void *)0}, + {"-netbook", "*netbook", XrmoptionNoArg, (void *)"False"}, + {"+netbook", "*netbook", XrmoptionNoArg, (void *)"True"}, - { "-throttle", "*throttle", XrmoptionNoArg, (void *)"False" }, - { "+throttle", "*throttle", XrmoptionNoArg, (void *) "True" }, + {"-throttle", "*throttle", XrmoptionNoArg, (void *)"False"}, + {"+throttle", "*throttle", XrmoptionNoArg, (void *)"True"}, - /* - * these are parsed for compatibility, but not used yet. - */ - { "-bg", "*background", XrmoptionSepArg, (void *) 0 }, - { "-background", "*background", XrmoptionSepArg, (void *) 0 }, - { "-bd", "*borderColor", XrmoptionSepArg, (void *) 0 }, - { "-bordercolor", "*borderColor", XrmoptionSepArg, (void *) 0 }, - { "-bw", "*borderWidth", XrmoptionSepArg, (void *) 0 }, - { "-borderwidth", "*borderWidth", XrmoptionSepArg, (void *) 0 }, - { "-fg", "*foreground", XrmoptionSepArg, (void *) 0 }, - { "-foreground", "*foreground", XrmoptionSepArg, (void *) 0 }, - { "-fn", "*fontName", XrmoptionSepArg, (void *) 0 }, - { "-font", "*fontName", XrmoptionSepArg, (void *) 0 }, - { "-rv", "*reverseVideo", XrmoptionNoArg, (void *) "True" }, - { "+rv", "*reverseVideo", XrmoptionNoArg, (void *)"False" }, - { "-reverse", "*reverseVideo", XrmoptionNoArg, (void *) "True" }, + /* + * these are parsed for compatibility, but not used yet. + */ + {"-bg", "*background", XrmoptionSepArg, (void *)0}, + {"-background", "*background", XrmoptionSepArg, (void *)0}, + {"-bd", "*borderColor", XrmoptionSepArg, (void *)0}, + {"-bordercolor", "*borderColor", XrmoptionSepArg, (void *)0}, + {"-bw", "*borderWidth", XrmoptionSepArg, (void *)0}, + {"-borderwidth", "*borderWidth", XrmoptionSepArg, (void *)0}, + {"-fg", "*foreground", XrmoptionSepArg, (void *)0}, + {"-foreground", "*foreground", XrmoptionSepArg, (void *)0}, + {"-fn", "*fontName", XrmoptionSepArg, (void *)0}, + {"-font", "*fontName", XrmoptionSepArg, (void *)0}, + {"-rv", "*reverseVideo", XrmoptionNoArg, (void *)"True"}, + {"+rv", "*reverseVideo", XrmoptionNoArg, (void *)"False"}, + {"-reverse", "*reverseVideo", XrmoptionNoArg, (void *)"True"}, }; diff --git a/src/register.c b/src/register.c index 2733d4a..43e96f5 100644 --- a/src/register.c +++ b/src/register.c @@ -42,28 +42,21 @@ * $Id: register.c,v 1.6 1995/01/11 18:20:01 ecd Exp ecd $ */ - #include "global.h" -#include #include +#include #include "hp48.h" #include "hp48_emu.h" extern long nibble_masks[16]; -static int start_fields[] = { - -1, 0, 2, 0, 15, 3, 0, 0, - -1, 0, 2, 0, 15, 3, 0, 0, - 0, 0, 0 -}; +static int start_fields[] = {-1, 0, 2, 0, 15, 3, 0, 0, -1, 0, + 2, 0, 15, 3, 0, 0, 0, 0, 0}; -static int end_fields[] = { - -1, -1, 2, 2, 15, 14, 1, 15, - -1, -1, 2, 2, 15, 14, 1, 4, - 3, 2, 0 -}; +static int end_fields[] = {-1, -1, 2, 2, 15, 14, 1, 15, -1, -1, + 2, 2, 15, 14, 1, 4, 3, 2, 0}; static inline int get_start(int code) { int s; @@ -83,8 +76,8 @@ static inline int get_end(int code) { return e; } -void add_register(unsigned char *res, unsigned char *r1, - unsigned char *r2, int code) { +void add_register(unsigned char *res, unsigned char *r1, unsigned char *r2, + int code) { int t, c, i, s, e; s = get_start(code); @@ -128,8 +121,8 @@ void add_p_plus_one(unsigned char *r) { saturn.CARRY = 0; } -void sub_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) { int t, c, i, s, e; s = get_start(code); @@ -288,8 +281,8 @@ void zero_register(unsigned char *r, int code) { r[i] = 0; } -void or_register(unsigned char *res, unsigned char *r1, - unsigned char *r2, int code) { +void or_register(unsigned char *res, unsigned char *r1, unsigned char *r2, + int code) { int i, s, e; s = get_start(code); @@ -299,8 +292,8 @@ void or_register(unsigned char *res, unsigned char *r1, } } -void and_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) { int i, s, e; s = get_start(code); @@ -350,7 +343,7 @@ void shift_left_register(unsigned char *r, int code) { s = get_start(code); e = get_end(code); for (i = e; i > s; i--) { - r[i] = r[i-1] & 0x0f; + r[i] = r[i - 1] & 0x0f; } r[s] = 0; } @@ -362,7 +355,7 @@ void shift_left_circ_register(unsigned char *r, int code) { e = get_end(code); t = r[e] & 0x0f; for (i = e; i > s; i--) { - r[i] = r[i-1] & 0x0f; + r[i] = r[i - 1] & 0x0f; } r[s] = t; } @@ -375,7 +368,7 @@ void shift_right_register(unsigned char *r, int code) { if (r[s] & 0x0f) saturn.SB = 1; for (i = s; i < e; i++) { - r[i] = r[i+1] & 0x0f; + r[i] = r[i + 1] & 0x0f; } r[e] = 0; } @@ -387,7 +380,7 @@ void shift_right_circ_register(unsigned char *r, int code) { e = get_end(code); t = r[s] & 0x0f; for (i = s; i < e; i++) { - r[i] = r[i+1] & 0x0f; + r[i] = r[i + 1] & 0x0f; } r[e] = t; if (t) @@ -522,7 +515,8 @@ int is_greater_register(unsigned char *r1, unsigned char *r2, int code) { return z; } -int is_greater_or_equal_register(unsigned char *r1, unsigned char *r2, int code) { +int is_greater_or_equal_register(unsigned char *r1, unsigned char *r2, + int code) { int z, i, s, e; s = get_start(code); diff --git a/src/resources.c b/src/resources.c index 91dabee..2b17e9c 100644 --- a/src/resources.c +++ b/src/resources.c @@ -50,30 +50,30 @@ #include #include -#include #include -#include #include +#include +#include -#include "resources.h" #include "disasm.h" #include "errors.h" +#include "resources.h" XrmDatabase rdb = (XrmDatabase)0; -int verbose; -int quiet; -int useTerminal; -int useSerial; -char *serialLine; -int useXShm; -int useDebugger; -int netbook; -int throttle; -int initialize; -int resetOnStartup; -char *romFileName; -char *homeDirectory; +int verbose; +int quiet; +int useTerminal; +int useSerial; +char *serialLine; +int useXShm; +int useDebugger; +int netbook; +int throttle; +int initialize; +int resetOnStartup; +char *romFileName; +char *homeDirectory; void get_resources(void) { if (get_boolean_resource("printVersion", "PrintVersion")) @@ -92,216 +92,217 @@ void get_resources(void) { useSerial = get_boolean_resource("useSerial", "UseSerial"); serialLine = get_string_resource("serialLine", "SerialLine"); - initialize = get_boolean_resource("completeInitialize", - "CompleteInitialize"); - resetOnStartup = get_boolean_resource("resetOnStartup", - "ResetOnStartup"); + initialize = get_boolean_resource("completeInitialize", "CompleteInitialize"); + resetOnStartup = get_boolean_resource("resetOnStartup", "ResetOnStartup"); romFileName = get_string_resource("romFileName", "RomFileName"); homeDirectory = get_string_resource("homeDirectory", "HomeDirectory"); useDebugger = get_boolean_resource("useDebugger", "UseDebugger"); - disassembler_mode = get_mnemonic_resource("disassemblerMnemonics", - "DisassemblerMnemonics"); + disassembler_mode = + get_mnemonic_resource("disassemblerMnemonics", "DisassemblerMnemonics"); netbook = get_boolean_resource("netbook", "Netbook"); throttle = get_boolean_resource("throttle", "Throttle"); } -char * get_string_resource_from_db (XrmDatabase db, char *name, char *class) { +char *get_string_resource_from_db(XrmDatabase db, char *name, char *class) { XrmValue value; - char *type; - char full_name [1024], full_class [1024]; + char *type; + char full_name[1024], full_class[1024]; - strcpy (full_name, res_name); - strcat (full_name, "."); - strcat (full_name, name); - strcpy (full_class, res_class); - strcat (full_class, "."); - strcat (full_class, class); - if (XrmGetResource (db, full_name, full_class, &type, &value)) - { - char *str = (char *) malloc (value.size + 1); - strncpy (str, (char *) value.addr, value.size); - str [value.size] = 0; - return str; - } + strcpy(full_name, res_name); + strcat(full_name, "."); + strcat(full_name, name); + strcpy(full_class, res_class); + strcat(full_class, "."); + strcat(full_class, class); + if (XrmGetResource(db, full_name, full_class, &type, &value)) { + char *str = (char *)malloc(value.size + 1); + strncpy(str, (char *)value.addr, value.size); + str[value.size] = 0; + return str; + } return (char *)0; } -char * get_string_resource (char *name, char *class) { +char *get_string_resource(char *name, char *class) { return get_string_resource_from_db(rdb, name, class); } -int get_mnemonic_resource (char *name, char *class) { - char *tmp, buf [100]; - char *s = get_string_resource (name, class); +int get_mnemonic_resource(char *name, char *class) { + char *tmp, buf[100]; + char *s = get_string_resource(name, class); char *os = s; - if (! s) return CLASS_MNEMONICS; - for (tmp = buf; *s; s++) - *tmp++ = isupper (*s) ? _tolower (*s) : *s; - *tmp = 0; - free (os); - - if (!strcmp (buf, "hp")) - return HP_MNEMONICS; - if (!strcmp (buf, "class")) + if (!s) return CLASS_MNEMONICS; - fprintf (stderr, "%s: %s must be one of \'HP\' or \'class\', not %s.\n", - progname, name, buf); + for (tmp = buf; *s; s++) + *tmp++ = isupper(*s) ? _tolower(*s) : *s; + *tmp = 0; + free(os); + + if (!strcmp(buf, "hp")) + return HP_MNEMONICS; + if (!strcmp(buf, "class")) + return CLASS_MNEMONICS; + fprintf(stderr, "%s: %s must be one of \'HP\' or \'class\', not %s.\n", + progname, name, buf); return CLASS_MNEMONICS; } -int get_boolean_resource (char *name, char *class) { - char *tmp, buf [100]; - char *s = get_string_resource (name, class); +int get_boolean_resource(char *name, char *class) { + char *tmp, buf[100]; + char *s = get_string_resource(name, class); char *os = s; - if (! s) return 0; - for (tmp = buf; *s; s++) - *tmp++ = isupper (*s) ? _tolower (*s) : *s; - *tmp = 0; - free (os); - - if (!strcmp (buf, "on") || !strcmp (buf, "true") || !strcmp (buf, "yes")) - return 1; - if (!strcmp (buf, "off") || !strcmp (buf, "false") || !strcmp (buf, "no")) + if (!s) return 0; - fprintf (stderr, "%s: %s must be boolean, not %s.\n", - progname, name, buf); + for (tmp = buf; *s; s++) + *tmp++ = isupper(*s) ? _tolower(*s) : *s; + *tmp = 0; + free(os); + + if (!strcmp(buf, "on") || !strcmp(buf, "true") || !strcmp(buf, "yes")) + return 1; + if (!strcmp(buf, "off") || !strcmp(buf, "false") || !strcmp(buf, "no")) + return 0; + fprintf(stderr, "%s: %s must be boolean, not %s.\n", progname, name, buf); return 0; } -int get_integer_resource (char *name, char *class) { +int get_integer_resource(char *name, char *class) { int val; - char c, *s = get_string_resource (name, class); - if (!s) return 0; - if (1 == sscanf (s, " %d %c", &val, &c)) - { - free (s); - return val; - } - fprintf (stderr, "%s: %s must be an integer, not %s.\n", - progname, name, s); - free (s); + char c, *s = get_string_resource(name, class); + if (!s) + return 0; + if (1 == sscanf(s, " %d %c", &val, &c)) { + free(s); + return val; + } + fprintf(stderr, "%s: %s must be an integer, not %s.\n", progname, name, s); + free(s); return 0; } -unsigned int get_pixel_resource (char *name, char *class, Display *dpy, - Colormap cmap) { +unsigned int get_pixel_resource(char *name, char *class, Display *dpy, + Colormap cmap) { XColor color; - char *s = get_string_resource (name, class); - if (!s) goto DEFAULT; + char *s = get_string_resource(name, class); + if (!s) + goto DEFAULT; - if (! XParseColor (dpy, cmap, s, &color)) - { - fprintf (stderr, "%s: can't parse color %s\n", progname, s); - goto DEFAULT; - } - if (! XAllocColor (dpy, cmap, &color)) - { - fprintf (stderr, "%s: couldn't allocate color %s\n", progname, s); - goto DEFAULT; - } - free (s); + if (!XParseColor(dpy, cmap, s, &color)) { + fprintf(stderr, "%s: can't parse color %s\n", progname, s); + goto DEFAULT; + } + if (!XAllocColor(dpy, cmap, &color)) { + fprintf(stderr, "%s: couldn't allocate color %s\n", progname, s); + goto DEFAULT; + } + free(s); return color.pixel; - DEFAULT: - if (s) free (s); - return (strcmp (class, "Background") - ? WhitePixel (dpy, DefaultScreen (dpy)) - : BlackPixel (dpy, DefaultScreen (dpy))); +DEFAULT: + if (s) + free(s); + return (strcmp(class, "Background") ? WhitePixel(dpy, DefaultScreen(dpy)) + : BlackPixel(dpy, DefaultScreen(dpy))); } -static Visual * pick_visual_of_class (Display *dpy, int visual_class, unsigned int *depth) { +static Visual *pick_visual_of_class(Display *dpy, int visual_class, + unsigned int *depth) { XVisualInfo vi_in, *vi_out; int out_count; vi_in.class = visual_class; vi_in.screen = DefaultScreen(dpy); - vi_out = XGetVisualInfo(dpy, VisualClassMask|VisualScreenMask, - &vi_in, &out_count); - if (vi_out) - { /* choose the 'best' one, if multiple */ - int i, best; - Visual *visual; - for (i = 0, best = 0; i < out_count; i++) - if (vi_out[i].depth > vi_out[best].depth) - best = i; - visual = vi_out[best].visual; - *depth = vi_out[best].depth; - XFree ((char *)vi_out); - return visual; - } - else - { - *depth = DefaultDepth(dpy, DefaultScreen(dpy)); - return DefaultVisual(dpy, DefaultScreen(dpy)); - } + vi_out = XGetVisualInfo(dpy, VisualClassMask | VisualScreenMask, &vi_in, + &out_count); + if (vi_out) { /* choose the 'best' one, if multiple */ + int i, best; + Visual *visual; + for (i = 0, best = 0; i < out_count; i++) + if (vi_out[i].depth > vi_out[best].depth) + best = i; + visual = vi_out[best].visual; + *depth = vi_out[best].depth; + XFree((char *)vi_out); + return visual; + } else { + *depth = DefaultDepth(dpy, DefaultScreen(dpy)); + return DefaultVisual(dpy, DefaultScreen(dpy)); + } } -static Visual * id_to_visual (Display *dpy, int id, unsigned int *depth) { +static Visual *id_to_visual(Display *dpy, int id, unsigned int *depth) { XVisualInfo vi_in, *vi_out; int out_count; vi_in.screen = DefaultScreen(dpy); vi_in.visualid = id; - vi_out = XGetVisualInfo(dpy, VisualScreenMask|VisualIDMask, - &vi_in, &out_count); - if (vi_out) - { - Visual *v = vi_out[0].visual; - *depth = vi_out[0].depth; - XFree((char *)vi_out); - return v; - } + vi_out = + XGetVisualInfo(dpy, VisualScreenMask | VisualIDMask, &vi_in, &out_count); + if (vi_out) { + Visual *v = vi_out[0].visual; + *depth = vi_out[0].depth; + XFree((char *)vi_out); + return v; + } return 0; } -Visual * get_visual_resource(Display *dpy, char *name, char *class, unsigned int *depth) { - char c; +Visual *get_visual_resource(Display *dpy, char *name, char *class, + unsigned int *depth) { + char c; char *tmp, *s; - int vclass; - int id; + int vclass; + int id; s = get_string_resource(name, class); if (s) for (tmp = s; *tmp; tmp++) - if (isupper(*tmp)) *tmp = _tolower(*tmp); + if (isupper(*tmp)) + *tmp = _tolower(*tmp); - if (!s || !strcmp(s, "default")) vclass = -1; - else if (!strcmp (s, "staticgray")) vclass = StaticGray; - else if (!strcmp (s, "staticcolor")) vclass = StaticColor; - else if (!strcmp (s, "truecolor")) vclass = TrueColor; - else if (!strcmp (s, "grayscale")) vclass = GrayScale; - else if (!strcmp (s, "pseudocolor")) vclass = PseudoColor; - else if (!strcmp (s, "directcolor")) vclass = DirectColor; - else if (1 == sscanf (s, " %d %c", &id, &c)) vclass = -2; - else if (1 == sscanf (s, " 0x%x %c", &id, &c)) vclass = -2; - else - { - fprintf (stderr, "%s: unrecognized visual \"%s\".\n", progname, s); - vclass = -1; - } - if (s) free (s); + if (!s || !strcmp(s, "default")) + vclass = -1; + else if (!strcmp(s, "staticgray")) + vclass = StaticGray; + else if (!strcmp(s, "staticcolor")) + vclass = StaticColor; + else if (!strcmp(s, "truecolor")) + vclass = TrueColor; + else if (!strcmp(s, "grayscale")) + vclass = GrayScale; + else if (!strcmp(s, "pseudocolor")) + vclass = PseudoColor; + else if (!strcmp(s, "directcolor")) + vclass = DirectColor; + else if (1 == sscanf(s, " %d %c", &id, &c)) + vclass = -2; + else if (1 == sscanf(s, " 0x%x %c", &id, &c)) + vclass = -2; + else { + fprintf(stderr, "%s: unrecognized visual \"%s\".\n", progname, s); + vclass = -1; + } + if (s) + free(s); - if (vclass == -1) - { - *depth = DefaultDepth(dpy, DefaultScreen(dpy)); - return DefaultVisual(dpy, DefaultScreen(dpy)); - } - else if (vclass == -2) - { - Visual *v = id_to_visual (dpy, id, depth); - if (v) return v; - fprintf (stderr, "%s: no visual with id 0x%x.\n", progname, id); - *depth = DefaultDepth(dpy, DefaultScreen(dpy)); - return DefaultVisual(dpy, DefaultScreen(dpy)); - } - else + if (vclass == -1) { + *depth = DefaultDepth(dpy, DefaultScreen(dpy)); + return DefaultVisual(dpy, DefaultScreen(dpy)); + } else if (vclass == -2) { + Visual *v = id_to_visual(dpy, id, depth); + if (v) + return v; + fprintf(stderr, "%s: no visual with id 0x%x.\n", progname, id); + *depth = DefaultDepth(dpy, DefaultScreen(dpy)); + return DefaultVisual(dpy, DefaultScreen(dpy)); + } else return pick_visual_of_class(dpy, vclass, depth); } -XFontStruct * get_font_resource(Display *dpy, char *name, char *class) { +XFontStruct *get_font_resource(Display *dpy, char *name, char *class) { char *s; XFontStruct *f = (XFontStruct *)0; @@ -309,16 +310,14 @@ XFontStruct * get_font_resource(Display *dpy, char *name, char *class) { if (s) f = XLoadQueryFont(dpy, s); - else - { - sprintf(errbuf, "can\'t get resource \'%s\'", name); - fatal_exit(); - } - if (f == (XFontStruct *)0) - { - sprintf(errbuf, "can\'t load font \'%s\'", s); - sprintf(fixbuf, "Please change resource \'%s\'", name); - fatal_exit(); - } + else { + sprintf(errbuf, "can\'t get resource \'%s\'", name); + fatal_exit(); + } + if (f == (XFontStruct *)0) { + sprintf(errbuf, "can\'t load font \'%s\'", s); + sprintf(fixbuf, "Please change resource \'%s\'", name); + fatal_exit(); + } return f; } diff --git a/src/resources.h b/src/resources.h index d7f18bd..4e440e2 100644 --- a/src/resources.h +++ b/src/resources.h @@ -41,59 +41,55 @@ #include #include -extern int verbose; -extern int quiet; -extern int useTerminal; -extern int useSerial; -extern int useXShm; -extern int useDebugger; -extern int netbook; -extern int throttle; -extern char *serialLine; -extern int initialize; -extern int resetOnStartup; -extern char *romFileName; -extern char *homeDirectory; +extern int verbose; +extern int quiet; +extern int useTerminal; +extern int useSerial; +extern int useXShm; +extern int useDebugger; +extern int netbook; +extern int throttle; +extern char *serialLine; +extern int initialize; +extern int resetOnStartup; +extern char *romFileName; +extern char *homeDirectory; -extern char *progname; -extern char *res_name; -extern char *res_class; +extern char *progname; +extern char *res_name; +extern char *res_class; -extern XrmDatabase rdb; +extern XrmDatabase rdb; -extern void usage __ProtoType__ ((void)); -extern void show_version __ProtoType__ ((void)); -extern void show_copyright __ProtoType__ ((void)); -extern void show_warranty __ProtoType__ ((void)); -extern void get_resources __ProtoType__ ((void)); -extern char * get_string_resource_from_db __ProtoType__ ((XrmDatabase db, - char *name, - char *class)); -extern char * get_string_resource __ProtoType__ ((char *name, - char *class)); -extern int get_boolean_resource __ProtoType__ ((char *name, - char *class)); -extern int get_mnemonic_resource __ProtoType__ ((char *name, - char *class)); -extern Visual * get_visual_resource __ProtoType__ ((Display *dpy, - char *name, - char *class, - unsigned int *depth)); -extern XFontStruct * get_font_resource __ProtoType__ ((Display *dpy, - char *res_name, - char *res_class)); +extern void usage __ProtoType__((void)); +extern void show_version __ProtoType__((void)); +extern void show_copyright __ProtoType__((void)); +extern void show_warranty __ProtoType__((void)); +extern void get_resources __ProtoType__((void)); +extern char *get_string_resource_from_db __ProtoType__((XrmDatabase db, + char *name, + char *class)); +extern char *get_string_resource __ProtoType__((char *name, char *class)); +extern int get_boolean_resource __ProtoType__((char *name, char *class)); +extern int get_mnemonic_resource __ProtoType__((char *name, char *class)); +extern Visual *get_visual_resource __ProtoType__((Display * dpy, char *name, + char *class, + unsigned int *depth)); +extern XFontStruct *get_font_resource __ProtoType__((Display * dpy, + char *res_name, + char *res_class)); #ifndef isupper -# define isupper(c) ((c) >= 'A' && (c) <= 'Z') +#define isupper(c) ((c) >= 'A' && (c) <= 'Z') #endif #ifndef islower -# define islower(c) ((c) >= 'a' && (c) <= 'z') +#define islower(c) ((c) >= 'a' && (c) <= 'z') #endif #ifndef _tolower -# define _tolower(c) ((c) - 'A' + 'a') +#define _tolower(c) ((c) - 'A' + 'a') #endif #ifndef _toupper -# define _toupper(c) ((c) - 'a' + 'A') +#define _toupper(c) ((c) - 'a' + 'A') #endif #endif /* !_RESOURCES_H */ diff --git a/src/romio.c b/src/romio.c index d2b34ba..f775974 100644 --- a/src/romio.c +++ b/src/romio.c @@ -27,8 +27,8 @@ #include #include -#include #include +#include #include "global.h" #include "resources.h" @@ -47,70 +47,80 @@ int read_rom_file(char *name, unsigned char **mem, int *size) { *mem = NULL; *size = 0; - if (NULL == (fp = fopen(name, "r"))) - { - fprintf(stderr, "can\'t open %s\n", name); - return 0; - } + if (NULL == (fp = fopen(name, "r"))) { + fprintf(stderr, "can\'t open %s\n", name); + return 0; + } - if (stat(name, &st) < 0) - { - fprintf(stderr, "can\'t stat %s\n", name); + if (stat(name, &st) < 0) { + fprintf(stderr, "can\'t stat %s\n", name); + fclose(fp); + return 0; + } + + if (fread(four, 1, 4, fp) != 4) { + fprintf(stderr, "can\'t read first 4 bytes of %s\n", name); + fclose(fp); + return 0; + } + + if (four[0] == 0x02 && four[1] == 0x03 && four[2] == 0x06 && + four[3] == 0x09) { + *size = st.st_size; + } else if (four[0] == 0x32 && four[1] == 0x96 && four[2] == 0x1b && + four[3] == 0x80) { + *size = 2 * st.st_size; + } else if (four[1] = 0x49) { + fprintf(stderr, "%s is an HP49 ROM\n", name); + *size = 2 * st.st_size; + } else if (four[0]) { + printf("%d\n", st.st_size); + *size = st.st_size; + } else { + fprintf(stderr, "%s is not a HP48 ROM\n", name); + fclose(fp); + return 0; + } + + if (fseek(fp, 0, 0) < 0) { + fprintf(stderr, "can\'t fseek to position 0 in %s\n", name); + *size = 0; + fclose(fp); + return 0; + } + + *mem = (unsigned char *)malloc(*size); + + if (st.st_size == *size) { + /* + * size is same as memory size, old version file + */ + if (fread(*mem, 1, (size_t)*size, fp) != *size) { + fprintf(stderr, "can\'t read %s\n", name); + free(*mem); + *mem = NULL; + *size = 0; fclose(fp); return 0; } + } else { + /* + * size is different, check size and decompress memory + */ - if (fread(four, 1, 4, fp) != 4) - { - fprintf(stderr, "can\'t read first 4 bytes of %s\n", name); - fclose(fp); - return 0; - } - - if (four[0] == 0x02 && four[1] == 0x03 && - four[2] == 0x06 && four[3] == 0x09) - { - *size = st.st_size; - } - else if (four[0] == 0x32 && four[1] == 0x96 && - four[2] == 0x1b && four[3] == 0x80) - { - *size = 2 * st.st_size; - } - else if (four[1] = 0x49) - { - fprintf(stderr, "%s is an HP49 ROM\n", name); - *size = 2 * st.st_size; - } - else if (four[0]) - { - printf("%d\n", st.st_size); - *size = st.st_size; - } - else - { - fprintf(stderr, "%s is not a HP48 ROM\n", name); - fclose(fp); - return 0; - } - - if (fseek(fp, 0, 0) < 0) - { - fprintf(stderr, "can\'t fseek to position 0 in %s\n", name); + if (st.st_size != *size / 2) { + fprintf(stderr, "strange size %s, expected %d, found %ld\n", name, + *size / 2, st.st_size); + free(*mem); + *mem = NULL; *size = 0; fclose(fp); return 0; } - *mem = (unsigned char *)malloc(*size); - - if (st.st_size == *size) - { - /* - * size is same as memory size, old version file - */ - if (fread(*mem, 1, (size_t)*size, fp) != *size) - { + if (NULL == (tmp_mem = (unsigned char *)malloc((size_t)st.st_size))) { + for (i = 0, j = 0; i < *size / 2; i++) { + if (1 != fread(&byte, 1, 1, fp)) { fprintf(stderr, "can\'t read %s\n", name); free(*mem); *mem = NULL; @@ -118,112 +128,62 @@ int read_rom_file(char *name, unsigned char **mem, int *size) { fclose(fp); return 0; } + (*mem)[j++] = byte & 0xf; + (*mem)[j++] = (byte >> 4) & 0xf; + } + } else { + if (fread(tmp_mem, 1, (size_t)*size / 2, fp) != *size / 2) { + fprintf(stderr, "can\'t read %s\n", name); + free(*mem); + *mem = NULL; + *size = 0; + fclose(fp); + free(tmp_mem); + return 0; + } + + for (i = 0, j = 0; i < *size / 2; i++) { + (*mem)[j++] = tmp_mem[i] & 0xf; + (*mem)[j++] = (tmp_mem[i] >> 4) & 0xf; + } + + free(tmp_mem); } - else - { - /* - * size is different, check size and decompress memory - */ - - if (st.st_size != *size / 2) - { - fprintf(stderr, "strange size %s, expected %d, found %ld\n", - name, *size / 2, st.st_size); - free(*mem); - *mem = NULL; - *size = 0; - fclose(fp); - return 0; - } - - if (NULL == (tmp_mem = (unsigned char *)malloc((size_t)st.st_size))) - { - for (i = 0, j = 0; i < *size / 2; i++) - { - if (1 != fread(&byte, 1, 1, fp)) - { - fprintf(stderr, "can\'t read %s\n", name); - free(*mem); - *mem = NULL; - *size = 0; - fclose(fp); - return 0; - } - (*mem)[j++] = byte & 0xf; - (*mem)[j++] = (byte >> 4) & 0xf; - } - } - else - { - if (fread(tmp_mem, 1, (size_t)*size / 2, fp) != *size / 2) - { - fprintf(stderr, "can\'t read %s\n", name); - free(*mem); - *mem = NULL; - *size = 0; - fclose(fp); - free(tmp_mem); - return 0; - } - - for (i = 0, j = 0; i < *size / 2; i++) - { - (*mem)[j++] = tmp_mem[i] & 0xf; - (*mem)[j++] = (tmp_mem[i] >> 4) & 0xf; - } - - free(tmp_mem); - } - } + } fclose(fp); - if ((*mem)[0x29] == 0x00) - { - if (*size == ROM_SIZE_GX) - { - opt_gx = 1; - } - else - if (*size == 4 * ROM_SIZE_GX) - { - fprintf(stderr, "%s seems to be HP49 ROM, but size is 0x%x\n", - name, *size); - opt_gx = 2; - } - else - if (*size == 8 * ROM_SIZE_GX) - { - fprintf(stderr, "%s seems to be HP49 ROM, but size is 0x%x\n", - name, *size); - opt_gx = 2; - } - else - { - fprintf(stderr, "%s seems to be G/GX ROM, but size is 0x%x\n", - name, *size); - free(*mem); - *mem = NULL; - *size = 0; - return 0; - } + if ((*mem)[0x29] == 0x00) { + if (*size == ROM_SIZE_GX) { + opt_gx = 1; + } else if (*size == 4 * ROM_SIZE_GX) { + fprintf(stderr, "%s seems to be HP49 ROM, but size is 0x%x\n", name, + *size); + opt_gx = 2; + } else if (*size == 8 * ROM_SIZE_GX) { + fprintf(stderr, "%s seems to be HP49 ROM, but size is 0x%x\n", name, + *size); + opt_gx = 2; + } else { + fprintf(stderr, "%s seems to be G/GX ROM, but size is 0x%x\n", name, + *size); + free(*mem); + *mem = NULL; + *size = 0; + return 0; } - else - { - if (*size == ROM_SIZE_SX) - { - opt_gx = 0; - } - else - { - fprintf(stderr, "%s seems to be S/SX ROM, but size is 0x%x\n", - name, *size); - free(*mem); - *mem = NULL; - *size = 0; - return 0; - } + } else { + if (*size == ROM_SIZE_SX) { + opt_gx = 0; + } else { + fprintf(stderr, "%s seems to be S/SX ROM, but size is 0x%x\n", name, + *size); + free(*mem); + *mem = NULL; + *size = 0; + return 0; } + } if (verbose) printf("%s: read %s\n", progname, name); diff --git a/src/rpl.c b/src/rpl.c index 7f0fb7e..f14ec85 100644 --- a/src/rpl.c +++ b/src/rpl.c @@ -38,79 +38,75 @@ #include #include -#include #include +#include +#include "append.h" +#include "debugger.h" +#include "disasm.h" #include "hp48.h" #include "hp48_emu.h" -#include "rpl.h" -#include "debugger.h" -#include "append.h" -#include "disasm.h" #include "romio.h" +#include "rpl.h" #define DEFINE_TRANS_TABLE 1 #include "hp48char.h" #undef DEFINE_TRANS_TABLE struct objfunc { - char *name; - short length; - word_20 prolog; - char *(*func) __ProtoType__((word_20 *addr, char *string)); -} objects[] = { - { "System Binary", 0, DOBINT, dec_bin_int }, - { "Real", 0, DOREAL, dec_real }, - { "Long Real", 0, DOEREL, dec_long_real }, - { "Complex", 0, DOCMP, dec_complex }, - { "Long Complex", 0, DOECMP, dec_long_complex }, - { "Character", 0, DOCHAR, dec_char }, - { "Array", 0, DOARRY, dec_array }, - { "Linked Array", 0, DOLNKARRY, dec_lnk_array }, - { "String", 2, DOCSTR, dec_string }, - { "Hex String", 1, DOHSTR, dec_hex_string }, - { "List", 0, DOLIST, dec_list }, - { "Directory", 0, DORRP, skip_ob }, - { "Symbolic", 0, DOSYMB, dec_symb }, - { "Unit", 0, DOEXT, dec_unit }, - { "Tagged", 0, DOTAG, skip_ob }, - { "Graphic", 0, DOGROB, skip_ob }, - { "Library", 0, DOLIB, dec_library }, - { "Backup", 0, DOBAK, skip_ob }, - { "Library Data", 0, DOEXT0, dec_library_data }, - { "ACPTR", 0, DOACPTR, dec_acptr }, - { "External 2", 0, DOEXT2, skip_ob }, - { "External 3", 0, DOEXT3, skip_ob }, - { "External 4", 0, DOEXT4, skip_ob }, - { "Program", 0, DOCOL, dec_prog }, - { "Code", 1, DOCODE, dec_code }, - { "Global Ident", 0, DOIDNT, dec_global_ident }, - { "Local Ident", 0, DOLAM, dec_local_ident }, - { "XLib Name", 0, DOROMP, dec_xlib_name }, - { "*", 0, UM_MUL, dec_unit_op }, - { "/", 0, UM_DIV, dec_unit_op }, - { "^", 0, UM_POW, dec_unit_op }, - { " ", 0, UM_PRE, dec_unit_op }, - { "_", 0, UM_END, dec_unit_op }, - { 0, 0, 0 } -}; + char *name; + short length; + word_20 prolog; + char *(*func)__ProtoType__((word_20 * addr, char *string)); +} objects[] = {{"System Binary", 0, DOBINT, dec_bin_int}, + {"Real", 0, DOREAL, dec_real}, + {"Long Real", 0, DOEREL, dec_long_real}, + {"Complex", 0, DOCMP, dec_complex}, + {"Long Complex", 0, DOECMP, dec_long_complex}, + {"Character", 0, DOCHAR, dec_char}, + {"Array", 0, DOARRY, dec_array}, + {"Linked Array", 0, DOLNKARRY, dec_lnk_array}, + {"String", 2, DOCSTR, dec_string}, + {"Hex String", 1, DOHSTR, dec_hex_string}, + {"List", 0, DOLIST, dec_list}, + {"Directory", 0, DORRP, skip_ob}, + {"Symbolic", 0, DOSYMB, dec_symb}, + {"Unit", 0, DOEXT, dec_unit}, + {"Tagged", 0, DOTAG, skip_ob}, + {"Graphic", 0, DOGROB, skip_ob}, + {"Library", 0, DOLIB, dec_library}, + {"Backup", 0, DOBAK, skip_ob}, + {"Library Data", 0, DOEXT0, dec_library_data}, + {"ACPTR", 0, DOACPTR, dec_acptr}, + {"External 2", 0, DOEXT2, skip_ob}, + {"External 3", 0, DOEXT3, skip_ob}, + {"External 4", 0, DOEXT4, skip_ob}, + {"Program", 0, DOCOL, dec_prog}, + {"Code", 1, DOCODE, dec_code}, + {"Global Ident", 0, DOIDNT, dec_global_ident}, + {"Local Ident", 0, DOLAM, dec_local_ident}, + {"XLib Name", 0, DOROMP, dec_xlib_name}, + {"*", 0, UM_MUL, dec_unit_op}, + {"/", 0, UM_DIV, dec_unit_op}, + {"^", 0, UM_POW, dec_unit_op}, + {" ", 0, UM_PRE, dec_unit_op}, + {"_", 0, UM_END, dec_unit_op}, + {0, 0, 0}}; -char * skip_ob(word_20 *addr, char *string) { - word_20 size, type; - char *p = string; +char *skip_ob(word_20 *addr, char *string) { + word_20 size, type; + char *p = string; struct objfunc *op; type = read_nibbles(*addr - 5, 5); - for (op = objects; op->prolog != 0; op++) - { - if (op->prolog == type) - break; - } + for (op = objects; op->prolog != 0; op++) { + if (op->prolog == type) + break; + } - if (op->prolog) - { - sprintf(p, "%s", op->name); - p += strlen(p); - } + if (op->prolog) { + sprintf(p, "%s", op->name); + p += strlen(p); + } size = read_nibbles(*addr, 5); *addr += size; @@ -122,18 +118,17 @@ char * skip_ob(word_20 *addr, char *string) { long hxs2real(long hxs) { int n = 0, c = 1; - while (hxs) - { - n += (hxs & 0xf) * c; - c *= 10; - hxs >>= 4; - } + while (hxs) { + n += (hxs & 0xf) * c; + c *= 10; + hxs >>= 4; + } return n; } -char * dec_bin_int(word_20 *addr, char *string) { - char *p = string; - word_20 n = 0; +char *dec_bin_int(word_20 *addr, char *string) { + char *p = string; + word_20 n = 0; n = read_nibbles(*addr, 5); *addr += 5; @@ -142,13 +137,13 @@ char * dec_bin_int(word_20 *addr, char *string) { return p; } -char * real_number(word_20 *addr, char *string, int ml, int xl) { +char *real_number(word_20 *addr, char *string, int ml, int xl) { hp_real r; - long re, xs; - int i; - char fmt[20]; - char m[16]; - char *p = string; + long re, xs; + int i; + char fmt[20]; + char m[16]; + char *p = string; /* * Read the number @@ -168,87 +163,88 @@ char * real_number(word_20 *addr, char *string, int ml, int xl) { * Figure out the exponent */ xs = 5; - while (--xl) xs *= 10; + while (--xl) + xs *= 10; re = hxs2real(r.x); if (re >= xs) re = re - 2 * xs; + if ((re >= 0) && (re < ml + 1)) { + if (r.s >= 5) + *p++ = '-'; - if ((re >= 0) && (re < ml + 1)) - { + sprintf(fmt, "%%.1X%%.8lX%%.%dlX", ml - 8); + sprintf(m, fmt, r.m, r.mh, r.ml); + + for (i = 0; i <= re; i++) + *p++ = m[i]; + *p++ = '.'; + for (; i < ml + 1; i++) + *p++ = m[i]; + p--; + while (*p == '0') + p--; + if (*p == '.') + p--; + *++p = '\0'; + + return p; + } + + if ((re < 0) && (re >= -ml - 1)) { + sprintf(fmt, "%%.1X%%.8lX%%.%dlX", ml - 8); + sprintf(m, fmt, r.m, r.mh, r.ml); + + for (i = ml; m[i] == '0'; i--) + ; + + if (-re <= ml - i + 1) { if (r.s >= 5) *p++ = '-'; - sprintf(fmt, "%%.1X%%.8lX%%.%dlX", ml - 8); - sprintf(m, fmt, r.m, r.mh, r.ml); - - for (i = 0; i <= re; i++) - *p++ = m[i]; *p++ = '.'; - for ( ; i < ml + 1; i++) + + for (i = 1; i < -re; i++) + *p++ = '0'; + + for (i = 0; i < ml + 1; i++) *p++ = m[i]; p--; - while(*p == '0') p--; - if (*p == '.') p--; + while (*p == '0') + p--; *++p = '\0'; return p; } - - if ((re < 0) && (re >= -ml - 1)) - { - sprintf(fmt, "%%.1X%%.8lX%%.%dlX", ml - 8); - sprintf(m, fmt, r.m, r.mh, r.ml); - - for (i = ml; m[i] == '0'; i--) ; - - if (-re <= ml - i + 1) - { - if (r.s >= 5) - *p++ = '-'; - - *p++ = '.'; - - for (i = 1; i < -re; i++) - *p++ = '0'; - - for (i = 0; i < ml + 1; i++) - *p++ = m[i]; - p--; - while(*p == '0') p--; - *++p = '\0'; - - return p; - } - } + } sprintf(fmt, "%%s%%X.%%.8lX%%.%dlX", ml - 8); sprintf(p, fmt, (r.s >= 5) ? "-" : "", r.m, r.mh, r.ml); p += strlen(p) - 1; - while(*p == '0') p--; + while (*p == '0') + p--; *++p = '\0'; - if (re) - { - sprintf(p, "E%ld", re); - p += strlen(p); - *p = '\0'; - } + if (re) { + sprintf(p, "E%ld", re); + p += strlen(p); + *p = '\0'; + } return p; } -char * dec_real(word_20 *addr, char *string) { +char *dec_real(word_20 *addr, char *string) { return real_number(addr, string, 11, 3); } -char * dec_long_real(word_20 *addr, char *string) { +char *dec_long_real(word_20 *addr, char *string) { return real_number(addr, string, 14, 5); } -char * dec_complex(word_20 *addr, char *string) { +char *dec_complex(word_20 *addr, char *string) { char *p = string; *p++ = '('; @@ -260,7 +256,7 @@ char * dec_complex(word_20 *addr, char *string) { return p; } -char * dec_long_complex(word_20 *addr, char *string) { +char *dec_long_complex(word_20 *addr, char *string) { char *p = string; *p++ = '('; @@ -272,11 +268,11 @@ char * dec_long_complex(word_20 *addr, char *string) { return p; } -char * dec_string(word_20 *addr, char *string) { - word_20 len; - unsigned char c; - char *p = string; - int i, n; +char *dec_string(word_20 *addr, char *string) { + word_20 len; + unsigned char c; + char *p = string; + int i, n; len = read_nibbles(*addr, 5); *addr += 5; @@ -288,33 +284,29 @@ char * dec_string(word_20 *addr, char *string) { n = 1000; *p++ = '\"'; - for (i = 0; i < n; i++) - { - c = read_nibbles(*addr, 2); - *addr += 2; - if (hp48_trans_tbl[c].trans) - { - sprintf(p, hp48_trans_tbl[c].trans); - p += strlen(p); - } - else - *p++ = c; - } + for (i = 0; i < n; i++) { + c = read_nibbles(*addr, 2); + *addr += 2; + if (hp48_trans_tbl[c].trans) { + sprintf(p, hp48_trans_tbl[c].trans); + p += strlen(p); + } else + *p++ = c; + } - if (n != len) - { - *p++ = '.'; - *p++ = '.'; - *p++ = '.'; - } + if (n != len) { + *p++ = '.'; + *p++ = '.'; + *p++ = '.'; + } *p++ = '\"'; *p = '\0'; return p; } -char * dec_hex_string(word_20 *addr, char *string) { - int len, lead, i, n; +char *dec_hex_string(word_20 *addr, char *string) { + int len, lead, i, n; static char hex[] = "0123456789ABCDEF"; char *p = string; @@ -322,49 +314,44 @@ char * dec_hex_string(word_20 *addr, char *string) { *addr += 5; len -= 5; - if (len <= 16) - { - *p++ = '#'; - *p++ = ' '; - lead = 1; - for (i = len - 1; i >= 0; i--) - { - *p = hex[read_nibble(*addr + i)]; - if (lead) - if ((i != 0) && (*p == '0')) - p--; - else - lead = 0; - p++; - } - - *p++ = 'h'; + if (len <= 16) { + *p++ = '#'; + *p++ = ' '; + lead = 1; + for (i = len - 1; i >= 0; i--) { + *p = hex[read_nibble(*addr + i)]; + if (lead) + if ((i != 0) && (*p == '0')) + p--; + else + lead = 0; + p++; } - else - { - *p++ = 'C'; - *p++ = '#'; - *p++ = ' '; - sprintf(p, "%d", len); - p += strlen(p); + *p++ = 'h'; + } else { + *p++ = 'C'; + *p++ = '#'; + *p++ = ' '; - *p++ = ' '; + sprintf(p, "%d", len); + p += strlen(p); - n = len; - if (len > 1000) - n = 1000; + *p++ = ' '; - for (i = 0; i < n; i++) - *p++ = hex[read_nibble(*addr + i)]; + n = len; + if (len > 1000) + n = 1000; - if (n != len) - { - *p++ = '.'; - *p++ = '.'; - *p++ = '.'; - } + for (i = 0; i < n; i++) + *p++ = hex[read_nibble(*addr + i)]; + + if (n != len) { + *p++ = '.'; + *p++ = '.'; + *p++ = '.'; } + } *addr += len; @@ -372,23 +359,21 @@ char * dec_hex_string(word_20 *addr, char *string) { return p; } -char * dec_list(word_20 *addr, char *string) { - word_20 semi; - char *p = string; +char *dec_list(word_20 *addr, char *string) { + word_20 semi; + char *p = string; *p++ = '{'; *p++ = ' '; semi = read_nibbles(*addr, 5); - while (semi != SEMI) - { - p = dec_rpl_obj(addr, p); - semi = read_nibbles(*addr, 5); - if (semi != SEMI) - { - *p++ = ' '; - *p = '\0'; - } + while (semi != SEMI) { + p = dec_rpl_obj(addr, p); + semi = read_nibbles(*addr, 5); + if (semi != SEMI) { + *p++ = ' '; + *p = '\0'; } + } *p++ = ' '; *p++ = '}'; *p = '\0'; @@ -397,22 +382,20 @@ char * dec_list(word_20 *addr, char *string) { return p; } -char * dec_symb(word_20 *addr, char *string) { - word_20 semi; - char *p = string; +char *dec_symb(word_20 *addr, char *string) { + word_20 semi; + char *p = string; semi = read_nibbles(*addr, 5); *p++ = '\''; - while (semi != SEMI) - { - p = dec_rpl_obj(addr, p); - semi = read_nibbles(*addr, 5); - if (semi != SEMI) - { - *p++ = ' '; - *p = '\0'; - } + while (semi != SEMI) { + p = dec_rpl_obj(addr, p); + semi = read_nibbles(*addr, 5); + if (semi != SEMI) { + *p++ = ' '; + *p = '\0'; } + } *addr += 5; *p++ = '\''; @@ -420,63 +403,60 @@ char * dec_symb(word_20 *addr, char *string) { return p; } -char * dec_unit(word_20 *addr, char *string) { - word_20 semi; - char *p = string; +char *dec_unit(word_20 *addr, char *string) { + word_20 semi; + char *p = string; semi = read_nibbles(*addr, 5); - while (semi != SEMI) - { - p = dec_rpl_obj(addr, p); - semi = read_nibbles(*addr, 5); - if (semi != SEMI) - { - *p++ = ' '; - *p = '\0'; - } + while (semi != SEMI) { + p = dec_rpl_obj(addr, p); + semi = read_nibbles(*addr, 5); + if (semi != SEMI) { + *p++ = ' '; + *p = '\0'; } + } *addr += 5; return p; } -char * dec_unit_op(word_20 *addr, char *string) { +char *dec_unit_op(word_20 *addr, char *string) { word_20 op; char *p = string; op = read_nibbles(*addr - 5, 5); - switch (op) - { - case UM_MUL: - *p++ = '*'; - break; - case UM_DIV: - *p++ = '/'; - break; - case UM_POW: - *p++ = '^'; - break; - case UM_END: - *p++ = '_'; - break; - case UM_PRE: - p--; - break; - default: - break; + switch (op) { + case UM_MUL: + *p++ = '*'; + break; + case UM_DIV: + *p++ = '/'; + break; + case UM_POW: + *p++ = '^'; + break; + case UM_END: + *p++ = '_'; + break; + case UM_PRE: + p--; + break; + default: + break; } *p = '\0'; return p; } -char * dec_library(word_20 *addr, char *string) { - word_20 libsize, libidsize; -/* - word_20 hashoff, mesgoff, linkoff, cfgoff; - word_20 mesgloc, cfgloc; -*/ - int i, libnum; - unsigned char c; - char *p = string; +char *dec_library(word_20 *addr, char *string) { + word_20 libsize, libidsize; + /* + word_20 hashoff, mesgoff, linkoff, cfgoff; + word_20 mesgloc, cfgloc; + */ + int i, libnum; + unsigned char c; + char *p = string; libsize = read_nibbles(*addr, 5); libidsize = read_nibbles(*addr + 5, 2); @@ -485,17 +465,14 @@ char * dec_library(word_20 *addr, char *string) { sprintf(p, "Library %d: ", libnum); p += strlen(p); - for (i = 0; i < libidsize; i++) - { - c = read_nibbles(*addr + 2 * i + 7, 2); - if (hp48_trans_tbl[c].trans) - { - sprintf(p, hp48_trans_tbl[c].trans); - p += strlen(p); - } - else - *p++ = c; - } + for (i = 0; i < libidsize; i++) { + c = read_nibbles(*addr + 2 * i + 7, 2); + if (hp48_trans_tbl[c].trans) { + sprintf(p, hp48_trans_tbl[c].trans); + p += strlen(p); + } else + *p++ = c; + } *addr += libsize; @@ -503,9 +480,9 @@ char * dec_library(word_20 *addr, char *string) { return p; } -char * dec_library_data(word_20 *addr, char *string) { - word_20 size; - char *p = string; +char *dec_library_data(word_20 *addr, char *string) { + word_20 size; + char *p = string; size = read_nibbles(*addr, 5); @@ -518,29 +495,26 @@ char * dec_library_data(word_20 *addr, char *string) { return p; } -char * dec_acptr(word_20 *addr, char *string) { - word_20 size; - char *p = string; - int i; +char *dec_acptr(word_20 *addr, char *string) { + word_20 size; + char *p = string; + int i; static char hex[] = "0123456789ABCDEF"; - if (opt_gx) - { - size = 10; - sprintf(p, "ACPTR "); - p += strlen(p); - for (i = 0; i < 5; i++) - *p++ = hex[read_nibble(*addr + i)]; - *p++ = ' '; - for (i = 5; i < 10; i++) - *p++ = hex[read_nibble(*addr + i)]; - } - else - { - size = read_nibbles(*addr, 5); - sprintf(p, "Ext 1"); - p += strlen(p); - } + if (opt_gx) { + size = 10; + sprintf(p, "ACPTR "); + p += strlen(p); + for (i = 0; i < 5; i++) + *p++ = hex[read_nibble(*addr + i)]; + *p++ = ' '; + for (i = 5; i < 10; i++) + *p++ = hex[read_nibble(*addr + i)]; + } else { + size = read_nibbles(*addr, 5); + sprintf(p, "Ext 1"); + p += strlen(p); + } *addr += size; @@ -548,49 +522,46 @@ char * dec_acptr(word_20 *addr, char *string) { return p; } -char * dec_prog(word_20 *addr, char *string) { - word_20 semi; - char *p = string; +char *dec_prog(word_20 *addr, char *string) { + word_20 semi; + char *p = string; semi = read_nibbles(*addr, 5); - while (semi != SEMI) - { - p = dec_rpl_obj(addr, p); - semi = read_nibbles(*addr, 5); - if (semi != SEMI) - { - *p++ = ' '; - *p = '\0'; - } + while (semi != SEMI) { + p = dec_rpl_obj(addr, p); + semi = read_nibbles(*addr, 5); + if (semi != SEMI) { + *p++ = ' '; + *p = '\0'; } + } *addr += 5; return p; } -char * dec_code(word_20 *addr, char *string) { - char *p = string; - word_20 n, len; +char *dec_code(word_20 *addr, char *string) { + char *p = string; + word_20 n, len; len = read_nibbles(*addr, 5); sprintf(p, "Code"); p += strlen(p); n = 0; - while (n < len) - { -/* - *addr = disassemble(*addr, p); -*/ - n += len; - } + while (n < len) { + /* + *addr = disassemble(*addr, p); + */ + n += len; + } *addr += len; return p; } -char * dec_local_ident(word_20 *addr, char *string) { - int len, i, n; - char *p = string; +char *dec_local_ident(word_20 *addr, char *string) { + int len, i, n; + char *p = string; unsigned char c; len = read_nibbles(*addr, 2); @@ -600,33 +571,29 @@ char * dec_local_ident(word_20 *addr, char *string) { if (len > 1000) n = 1000; - for (i = 0; i < n; i++) - { - c = read_nibbles(*addr, 2); - *addr += 2; - if (hp48_trans_tbl[c].trans) - { - sprintf(p, hp48_trans_tbl[c].trans); - p += strlen(p); - } - else - *p++ = c; - } + for (i = 0; i < n; i++) { + c = read_nibbles(*addr, 2); + *addr += 2; + if (hp48_trans_tbl[c].trans) { + sprintf(p, hp48_trans_tbl[c].trans); + p += strlen(p); + } else + *p++ = c; + } - if (n != len) - { - *p++ = '.'; - *p++ = '.'; - *p++ = '.'; - } + if (n != len) { + *p++ = '.'; + *p++ = '.'; + *p++ = '.'; + } *p = '\0'; return p; } -char * dec_global_ident(word_20 *addr, char *string) { - int len, i, n; - char *p = string; +char *dec_global_ident(word_20 *addr, char *string) { + int len, i, n; + char *p = string; unsigned char c; len = read_nibbles(*addr, 2); @@ -636,58 +603,51 @@ char * dec_global_ident(word_20 *addr, char *string) { if (len > 1000) n = 1000; - for (i = 0; i < n; i++) - { - c = read_nibbles(*addr, 2); - *addr += 2; - if (hp48_trans_tbl[c].trans) - { - sprintf(p, hp48_trans_tbl[c].trans); - p += strlen(p); - } - else - *p++ = c; - } + for (i = 0; i < n; i++) { + c = read_nibbles(*addr, 2); + *addr += 2; + if (hp48_trans_tbl[c].trans) { + sprintf(p, hp48_trans_tbl[c].trans); + p += strlen(p); + } else + *p++ = c; + } - if (n != len) - { - *p++ = '.'; - *p++ = '.'; - *p++ = '.'; - } + if (n != len) { + *p++ = '.'; + *p++ = '.'; + *p++ = '.'; + } *p = '\0'; return p; } -char * xlib_name(int lib, int command, char *string) { - int n, len; - int i, lib_n = 0; +char *xlib_name(int lib, int command, char *string) { + int n, len; + int i, lib_n = 0; unsigned char c; - word_20 romptab, acptr; - word_20 offset, hash_end; - word_20 lib_addr, name_addr; - word_20 type, ram_base, ram_mask; - short present = 0; - char *p = string; + word_20 romptab, acptr; + word_20 offset, hash_end; + word_20 lib_addr, name_addr; + word_20 type, ram_base, ram_mask; + short present = 0; + char *p = string; /* * Configure RAM to address 0x70000 */ ram_base = saturn.mem_cntl[1].config[0]; ram_mask = saturn.mem_cntl[1].config[1]; - if (opt_gx) - { - saturn.mem_cntl[1].config[0] = 0x80000; - saturn.mem_cntl[1].config[1] = 0xc0000; - romptab = ROMPTAB_GX; - } - else - { - saturn.mem_cntl[1].config[0] = 0x70000; - saturn.mem_cntl[1].config[1] = 0xf0000; - romptab = ROMPTAB_SX; - } + if (opt_gx) { + saturn.mem_cntl[1].config[0] = 0x80000; + saturn.mem_cntl[1].config[1] = 0xc0000; + romptab = ROMPTAB_GX; + } else { + saturn.mem_cntl[1].config[0] = 0x70000; + saturn.mem_cntl[1].config[1] = 0xf0000; + romptab = ROMPTAB_SX; + } /* * look up number of installed libs in romptab @@ -695,133 +655,118 @@ char * xlib_name(int lib, int command, char *string) { n = read_nibbles(romptab, 3); romptab += 3; - if (n > 0) - { - /* - * look up lib number in romptab - */ - while (n--) - { - lib_n = read_nibbles(romptab, 3); - romptab += 3; - if (lib_n == lib) - break; - romptab += 5; - if (opt_gx) - romptab += 8; - } + if (n > 0) { + /* + * look up lib number in romptab + */ + while (n--) { + lib_n = read_nibbles(romptab, 3); + romptab += 3; if (lib_n == lib) - { - /* - * look at hash table pointer - */ - lib_addr = read_nibbles(romptab, 5); - if (opt_gx) - { - romptab += 5; - acptr = read_nibbles(romptab, 5); - if (acptr != 0x00000) - { - saturn.mem_cntl[1].config[0] = ram_base; - saturn.mem_cntl[1].config[1] = ram_mask; - sprintf(p, "XLIB %d %d", lib, command); - p += strlen(p); - return p; - } - } - lib_addr += 3; - offset = read_nibbles(lib_addr, 5); - if (offset > 0) - { - /* - * look at the hash table - */ - lib_addr += offset; - - /* - * check if library is in ROM - */ - if (!opt_gx) - if (lib_addr < 0x70000) - saturn.mem_cntl[1].config[0] = 0xf0000; - - /* - * check pointer type - */ - type = read_nibbles(lib_addr, 5); - if (type == DOBINT) - { - /* - * follow pointer to real address - */ - lib_addr += 5; - lib_addr = read_nibbles(lib_addr, 5); - } - else if (type == DOACPTR) - { - /* - * follow pointer to real address - */ - lib_addr += 5; - acptr = lib_addr + 5; - lib_addr = read_nibbles(lib_addr, 5); - acptr = read_nibbles(acptr, 5); - if (acptr != 0x00000) - { - saturn.mem_cntl[1].config[0] = ram_base; - saturn.mem_cntl[1].config[1] = ram_mask; - sprintf(p, "XLIB %d %d", lib, command); - p += strlen(p); - return p; - } - } - - /* - * get length of hash table - */ - lib_addr += 5; - hash_end = read_nibbles(lib_addr, 5); - hash_end += lib_addr; - - /* - * go into real name table - */ - lib_addr += 85; - offset = read_nibbles(lib_addr, 5); - lib_addr += offset; - - /* - * look at library name number 'command' - */ - offset = 5 * command; - lib_addr += offset; - if (lib_addr < hash_end) - { - offset = read_nibbles(lib_addr, 5); - if (offset > 0) - { - name_addr = lib_addr - offset; - len = read_nibbles(name_addr, 2); - name_addr += 2; - present = 1; - for (i = 0; i < len; i++) - { - c = read_nibbles(name_addr, 2); - name_addr += 2; - if (hp48_trans_tbl[c].trans) - { - sprintf(p, hp48_trans_tbl[c].trans); - p += strlen(p); - } - else - *p++ = c; - } - *p = '\0'; - } - } - } - } + break; + romptab += 5; + if (opt_gx) + romptab += 8; } + if (lib_n == lib) { + /* + * look at hash table pointer + */ + lib_addr = read_nibbles(romptab, 5); + if (opt_gx) { + romptab += 5; + acptr = read_nibbles(romptab, 5); + if (acptr != 0x00000) { + saturn.mem_cntl[1].config[0] = ram_base; + saturn.mem_cntl[1].config[1] = ram_mask; + sprintf(p, "XLIB %d %d", lib, command); + p += strlen(p); + return p; + } + } + lib_addr += 3; + offset = read_nibbles(lib_addr, 5); + if (offset > 0) { + /* + * look at the hash table + */ + lib_addr += offset; + + /* + * check if library is in ROM + */ + if (!opt_gx) + if (lib_addr < 0x70000) + saturn.mem_cntl[1].config[0] = 0xf0000; + + /* + * check pointer type + */ + type = read_nibbles(lib_addr, 5); + if (type == DOBINT) { + /* + * follow pointer to real address + */ + lib_addr += 5; + lib_addr = read_nibbles(lib_addr, 5); + } else if (type == DOACPTR) { + /* + * follow pointer to real address + */ + lib_addr += 5; + acptr = lib_addr + 5; + lib_addr = read_nibbles(lib_addr, 5); + acptr = read_nibbles(acptr, 5); + if (acptr != 0x00000) { + saturn.mem_cntl[1].config[0] = ram_base; + saturn.mem_cntl[1].config[1] = ram_mask; + sprintf(p, "XLIB %d %d", lib, command); + p += strlen(p); + return p; + } + } + + /* + * get length of hash table + */ + lib_addr += 5; + hash_end = read_nibbles(lib_addr, 5); + hash_end += lib_addr; + + /* + * go into real name table + */ + lib_addr += 85; + offset = read_nibbles(lib_addr, 5); + lib_addr += offset; + + /* + * look at library name number 'command' + */ + offset = 5 * command; + lib_addr += offset; + if (lib_addr < hash_end) { + offset = read_nibbles(lib_addr, 5); + if (offset > 0) { + name_addr = lib_addr - offset; + len = read_nibbles(name_addr, 2); + name_addr += 2; + present = 1; + for (i = 0; i < len; i++) { + c = read_nibbles(name_addr, 2); + name_addr += 2; + if (hp48_trans_tbl[c].trans) { + sprintf(p, hp48_trans_tbl[c].trans); + p += strlen(p); + } else + *p++ = c; + } + *p = '\0'; + } + } + } + } + } /* * Reconfigure RAM @@ -829,16 +774,15 @@ char * xlib_name(int lib, int command, char *string) { saturn.mem_cntl[1].config[0] = ram_base; saturn.mem_cntl[1].config[1] = ram_mask; - if (!present) - { - sprintf(p, "XLIB %d %d", lib, command); - p += strlen(p); - } + if (!present) { + sprintf(p, "XLIB %d %d", lib, command); + p += strlen(p); + } return p; } -char * dec_xlib_name(word_20 *addr, char *string) { - int lib, command; +char *dec_xlib_name(word_20 *addr, char *string) { + int lib, command; lib = read_nibbles(*addr, 3); *addr += 3; @@ -848,13 +792,13 @@ char * dec_xlib_name(word_20 *addr, char *string) { return xlib_name(lib, command, string); } -char * any_array(word_20 *addr, char *string, short lnk_flag) { - word_20 len, type, dim; +char *any_array(word_20 *addr, char *string, short lnk_flag) { + word_20 len, type, dim; word_20 *dim_lens, *dims; - word_20 array_addr, elem_addr; - long elems; - int d, i; - char *p = string; + word_20 array_addr, elem_addr; + long elems; + int d, i; + char *p = string; struct objfunc *op; array_addr = *addr; @@ -865,76 +809,65 @@ char * any_array(word_20 *addr, char *string, short lnk_flag) { dim = read_nibbles(*addr, 5); *addr += 5; - for (op = objects; op->prolog != 0; op++) - { - if (op->prolog == type) - break; - } + for (op = objects; op->prolog != 0; op++) { + if (op->prolog == type) + break; + } dim_lens = (word_20 *)malloc(dim * sizeof(word_20)); dims = (word_20 *)malloc(dim * sizeof(word_20)); elems = 1; - for (i = 0; i < dim; i++) - { - dim_lens[i] = read_nibbles(*addr, 5); - dims[i] = dim_lens[i]; - elems *= dim_lens[i]; - *addr += 5; - } + for (i = 0; i < dim; i++) { + dim_lens[i] = read_nibbles(*addr, 5); + dims[i] = dim_lens[i]; + elems *= dim_lens[i]; + *addr += 5; + } - if (op->prolog == 0) - { - sprintf(p, "of Type %.5lX, Dim %ld, Size ", type, (long)dim); + if (op->prolog == 0) { + sprintf(p, "of Type %.5lX, Dim %ld, Size ", type, (long)dim); + p += strlen(p); + for (i = 0; i < dim; i++) { + sprintf(p, "%ld", (long)dim_lens[i]); p += strlen(p); - for (i = 0; i < dim; i++) - { - sprintf(p, "%ld", (long)dim_lens[i]); - p += strlen(p); - if (i < dim - 1) - { - sprintf(p, " x "); - p += strlen(p); - } - } - *p = '\0'; - *addr = array_addr + len; - free(dim_lens); - free(dims); - return p; + if (i < dim - 1) { + sprintf(p, " x "); + p += strlen(p); + } } + *p = '\0'; + *addr = array_addr + len; + free(dim_lens); + free(dims); + return p; + } d = -1; - while (elems--) - { - if (d < dim - 1) - { - for ( ; d < dim - 1; d++) - { - *p++ = '['; - } - d = dim - 1; - } - if (lnk_flag) - { - elem_addr = read_nibbles(*addr, 5); - elem_addr += *addr; - *addr += 5; - p = (*op->func)(&elem_addr, p); - } - else - p = (*op->func)(addr, p); - *p = '\0'; - dims[d]--; - if (dims[d]) - *p++ = ' '; - while (dims[d] == 0) - { - dims[d] = dim_lens[d]; - d--; - dims[d]--; - *p++ = ']'; - } + while (elems--) { + if (d < dim - 1) { + for (; d < dim - 1; d++) { + *p++ = '['; + } + d = dim - 1; } + if (lnk_flag) { + elem_addr = read_nibbles(*addr, 5); + elem_addr += *addr; + *addr += 5; + p = (*op->func)(&elem_addr, p); + } else + p = (*op->func)(addr, p); + *p = '\0'; + dims[d]--; + if (dims[d]) + *p++ = ' '; + while (dims[d] == 0) { + dims[d] = dim_lens[d]; + d--; + dims[d]--; + *p++ = ']'; + } + } free(dim_lens); free(dims); @@ -944,15 +877,15 @@ char * any_array(word_20 *addr, char *string, short lnk_flag) { return p; } -char * dec_array(word_20 *addr, char *string) { +char *dec_array(word_20 *addr, char *string) { return any_array(addr, string, 0); } -char * dec_lnk_array(word_20 *addr, char *string) { +char *dec_lnk_array(word_20 *addr, char *string) { return any_array(addr, string, 1); } -char * dec_char(word_20 *addr, char *string) { +char *dec_char(word_20 *addr, char *string) { char *p = string; unsigned char c; @@ -960,12 +893,10 @@ char * dec_char(word_20 *addr, char *string) { *addr += 2; *p++ = '\''; - if (hp48_trans_tbl[c].trans) - { - sprintf(p, hp48_trans_tbl[c].trans); - p += strlen(p); - } - else + if (hp48_trans_tbl[c].trans) { + sprintf(p, hp48_trans_tbl[c].trans); + p += strlen(p); + } else *p++ = c; *p++ = '\''; @@ -974,31 +905,28 @@ char * dec_char(word_20 *addr, char *string) { } short check_xlib(word_20 addr, char *string) { - int n, lib, command; - word_20 romptab; - word_20 offset, link_end; - word_20 acptr; - word_20 lib_addr; - word_20 type, ram_base, ram_mask; - char *p = string; + int n, lib, command; + word_20 romptab; + word_20 offset, link_end; + word_20 acptr; + word_20 lib_addr; + word_20 type, ram_base, ram_mask; + char *p = string; /* * Configure RAM to address 0x70000 */ ram_base = saturn.mem_cntl[1].config[0]; ram_mask = saturn.mem_cntl[1].config[1]; - if (opt_gx) - { - saturn.mem_cntl[1].config[0] = 0x80000; - saturn.mem_cntl[1].config[1] = 0xc0000; - romptab = ROMPTAB_GX; - } - else - { - saturn.mem_cntl[1].config[0] = 0x70000; - saturn.mem_cntl[1].config[1] = 0xf0000; - romptab = ROMPTAB_SX; - } + if (opt_gx) { + saturn.mem_cntl[1].config[0] = 0x80000; + saturn.mem_cntl[1].config[1] = 0xc0000; + romptab = ROMPTAB_GX; + } else { + saturn.mem_cntl[1].config[0] = 0x70000; + saturn.mem_cntl[1].config[1] = 0xf0000; + romptab = ROMPTAB_SX; + } /* * look up number of installed libs in romptab @@ -1006,115 +934,107 @@ short check_xlib(word_20 addr, char *string) { n = read_nibbles(romptab, 3); romptab += 3; -/* -fprintf(stderr, "Number of Libraries = %d\n", n); -fflush(stderr); -*/ + /* + fprintf(stderr, "Number of Libraries = %d\n", n); + fflush(stderr); + */ - if (n > 0) - { + if (n > 0) { + /* + * look up lib number in romptab + */ + while (n--) { + lib = read_nibbles(romptab, 3); + romptab += 3; /* - * look up lib number in romptab + fprintf(stderr, "Library num = %d\n", lib); + fflush(stderr); + */ + /* + * look at link table pointer */ - while (n--) - { - lib = read_nibbles(romptab, 3); - romptab += 3; -/* -fprintf(stderr, "Library num = %d\n", lib); -fflush(stderr); -*/ - /* - * look at link table pointer - */ - lib_addr = read_nibbles(romptab, 5); -/* -fprintf(stderr, "Library addr = %.5lx\n", lib_addr); -fflush(stderr); -*/ - romptab += 5; + lib_addr = read_nibbles(romptab, 5); + /* + fprintf(stderr, "Library addr = %.5lx\n", lib_addr); + fflush(stderr); + */ + romptab += 5; - if (opt_gx) - { - acptr = read_nibbles(romptab, 5); - romptab += 8; - if (acptr != 0x00000) - continue; - } + if (opt_gx) { + acptr = read_nibbles(romptab, 5); + romptab += 8; + if (acptr != 0x00000) + continue; + } - lib_addr += 13; - offset = read_nibbles(lib_addr, 5); - if (offset > 0) - { - /* - * look at the link table - */ - lib_addr += offset; -/* -fprintf(stderr, "Link table addr = %.5lx\n", lib_addr); -fflush(stderr); -*/ - /* - * check if library is in ROM - */ - if (!opt_gx) - if (lib_addr < 0x70000) - saturn.mem_cntl[1].config[0] = 0xf0000; + lib_addr += 13; + offset = read_nibbles(lib_addr, 5); + if (offset > 0) { + /* + * look at the link table + */ + lib_addr += offset; + /* + fprintf(stderr, "Link table addr = %.5lx\n", lib_addr); + fflush(stderr); + */ + /* + * check if library is in ROM + */ + if (!opt_gx) + if (lib_addr < 0x70000) + saturn.mem_cntl[1].config[0] = 0xf0000; - /* - * check pointer type - */ - type = read_nibbles(lib_addr, 5); - if (type == DOBINT) - { + /* + * check pointer type + */ + type = read_nibbles(lib_addr, 5); + if (type == DOBINT) { /* * follow pointer to real address - */ - lib_addr += 5; - lib_addr = read_nibbles(lib_addr, 5); - } -/* -fprintf(stderr, "Link table addr (2) = %.5lx\n", lib_addr); -fflush(stderr); -*/ - /* - * get length of link table - */ - lib_addr += 5; - link_end = read_nibbles(lib_addr, 5); - link_end += lib_addr; -/* -fprintf(stderr, "Link table end = %.5lx\n", link_end); -fflush(stderr); -*/ - /* - * look at library commands - */ - lib_addr += 5; - command = 0; - while (lib_addr < link_end) - { - offset = read_nibbles(lib_addr, 5); - if (offset > 0) - { - if (addr == ((lib_addr + offset) & 0xfffff)) - { - p = xlib_name(lib, command, p); - saturn.mem_cntl[1].config[0] = ram_base; - saturn.mem_cntl[1].config[1] = ram_mask; - return 1; - } - } - lib_addr += 5; - command++; - } - if (opt_gx) - saturn.mem_cntl[1].config[0] = 0x80000; - else - saturn.mem_cntl[1].config[0] = 0x70000; - } + */ + lib_addr += 5; + lib_addr = read_nibbles(lib_addr, 5); } + /* + fprintf(stderr, "Link table addr (2) = %.5lx\n", lib_addr); + fflush(stderr); + */ + /* + * get length of link table + */ + lib_addr += 5; + link_end = read_nibbles(lib_addr, 5); + link_end += lib_addr; + /* + fprintf(stderr, "Link table end = %.5lx\n", link_end); + fflush(stderr); + */ + /* + * look at library commands + */ + lib_addr += 5; + command = 0; + while (lib_addr < link_end) { + offset = read_nibbles(lib_addr, 5); + if (offset > 0) { + if (addr == ((lib_addr + offset) & 0xfffff)) { + p = xlib_name(lib, command, p); + saturn.mem_cntl[1].config[0] = ram_base; + saturn.mem_cntl[1].config[1] = ram_mask; + return 1; + } + } + lib_addr += 5; + command++; + } + if (opt_gx) + saturn.mem_cntl[1].config[0] = 0x80000; + else + saturn.mem_cntl[1].config[0] = 0x70000; + } } + } /* * Reconfigure RAM @@ -1125,44 +1045,37 @@ fflush(stderr); return 0; } - -char * dec_rpl_obj(word_20 *addr, char *string) { - word_20 prolog = 0; - word_20 prolog_2; - char *p = string; - char tmp_str[80]; +char *dec_rpl_obj(word_20 *addr, char *string) { + word_20 prolog = 0; + word_20 prolog_2; + char *p = string; + char tmp_str[80]; struct objfunc *op; prolog = read_nibbles(*addr, 5); - for (op = objects; op->prolog != 0; op++) - { - if (op->prolog == prolog) - break; - } + for (op = objects; op->prolog != 0; op++) { + if (op->prolog == prolog) + break; + } - if (op->prolog == 0) - { - if (check_xlib(prolog, tmp_str)) - { - p = append_str(p, tmp_str); - } + if (op->prolog == 0) { + if (check_xlib(prolog, tmp_str)) { + p = append_str(p, tmp_str); + } else { + prolog_2 = read_nibbles(prolog, 5); + for (op = objects; op->prolog != 0; op++) { + if (op->prolog == prolog_2) + break; + } + if (op->prolog) + p = dec_rpl_obj(&prolog, p); else - { - prolog_2 = read_nibbles(prolog, 5); - for (op = objects; op->prolog != 0; op++) - { - if (op->prolog == prolog_2) - break; - } - if (op->prolog) - p = dec_rpl_obj(&prolog, p); - else - p = append_str(p, "External"); - } - *addr += 5; - return p; + p = append_str(p, "External"); } + *addr += 5; + return p; + } *addr += 5; p = (*op->func)(addr, p); @@ -1171,9 +1084,9 @@ char * dec_rpl_obj(word_20 *addr, char *string) { } void decode_rpl_obj_2(word_20 addr, char *typ, char *dat) { - word_20 prolog = 0; - int len; - char tmp_str[80]; + word_20 prolog = 0; + int len; + char tmp_str[80]; struct objfunc *op; typ[0] = '\0'; @@ -1181,51 +1094,39 @@ void decode_rpl_obj_2(word_20 addr, char *typ, char *dat) { prolog = read_nibbles(addr, 5); - for (op = objects; op->prolog != 0; op++) - { - if (op->prolog == prolog) - break; - } + for (op = objects; op->prolog != 0; op++) { + if (op->prolog == prolog) + break; + } - if (op->prolog == 0) - { - if (addr == SEMI) - { - append_str(typ, "Primitive Code"); - append_str(dat, "SEMI"); - } - else if (addr + 5 == prolog) - { - append_str(typ, "Primitive Code"); - sprintf(dat, "at %.5lX", prolog); - } - else - { - append_str(typ, "PTR"); - sprintf(dat, "%.5lX", prolog); - } + if (op->prolog == 0) { + if (addr == SEMI) { + append_str(typ, "Primitive Code"); + append_str(dat, "SEMI"); + } else if (addr + 5 == prolog) { + append_str(typ, "Primitive Code"); + sprintf(dat, "at %.5lX", prolog); + } else { + append_str(typ, "PTR"); + sprintf(dat, "%.5lX", prolog); + } + return; + } + + if (op->prolog == DOCOL) { + if (check_xlib(addr, tmp_str)) { + append_str(typ, "XLib Call"); + append_str(dat, tmp_str); return; } + } - if (op->prolog == DOCOL) - { - if (check_xlib(addr, tmp_str)) - { - append_str(typ, "XLib Call"); - append_str(dat, tmp_str); - return; - } - } - - if (op->length) - { - len = (read_nibbles(addr + 5, 5) - 5) / op->length; - sprintf(typ, "%s %d", op->name, len); - } - else - { - append_str(typ, op->name); - } + if (op->length) { + len = (read_nibbles(addr + 5, 5) - 5) / op->length; + sprintf(typ, "%s %d", op->name, len); + } else { + append_str(typ, op->name); + } addr += 5; (*op->func)(&addr, dat); @@ -1233,67 +1134,57 @@ void decode_rpl_obj_2(word_20 addr, char *typ, char *dat) { return; } -char * decode_rpl_obj(word_20 addr, char *buf) { - word_20 prolog = 0; - int len; - char *p = buf; - char tmp_str[80]; +char *decode_rpl_obj(word_20 addr, char *buf) { + word_20 prolog = 0; + int len; + char *p = buf; + char tmp_str[80]; struct objfunc *op; prolog = read_nibbles(addr, 5); - for (op = objects; op->prolog != 0; op++) - { - if (op->prolog == prolog) - break; - } + for (op = objects; op->prolog != 0; op++) { + if (op->prolog == prolog) + break; + } - if (op->prolog == 0) - { - if (addr == SEMI) - { - p = append_str(buf, "Primitive Code"); - p = append_tab_16(buf); - p = append_str(p, "SEMI"); - } - else if (addr + 5 == prolog) - { - p = append_str(buf, "Primitive Code"); - p = append_tab_16(buf); - sprintf(p, "at %.5lX", prolog); - p += strlen(p); - *p = '\0'; - } - else - { - p = append_str(buf, "PTR"); - p = append_tab_16(buf); - sprintf(p, "%.5lX", prolog); - p += strlen(p); - *p = '\0'; - } + if (op->prolog == 0) { + if (addr == SEMI) { + p = append_str(buf, "Primitive Code"); + p = append_tab_16(buf); + p = append_str(p, "SEMI"); + } else if (addr + 5 == prolog) { + p = append_str(buf, "Primitive Code"); + p = append_tab_16(buf); + sprintf(p, "at %.5lX", prolog); + p += strlen(p); + *p = '\0'; + } else { + p = append_str(buf, "PTR"); + p = append_tab_16(buf); + sprintf(p, "%.5lX", prolog); + p += strlen(p); + *p = '\0'; + } + return p; + } + + if (op->prolog == DOCOL) { + if (check_xlib(addr, tmp_str)) { + p = append_str(buf, "XLib Call"); + p = append_tab_16(buf); + p = append_str(p, tmp_str); return p; } - - if (op->prolog == DOCOL) - { - if (check_xlib(addr, tmp_str)) - { - p = append_str(buf, "XLib Call"); - p = append_tab_16(buf); - p = append_str(p, tmp_str); - return p; - } - } + } p = append_str(buf, op->name); - if (op->length) - { - len = (read_nibbles(addr + 5, 5) - 5) / op->length; - sprintf(p, " %d", len); - p += strlen(p); - } + if (op->length) { + len = (read_nibbles(addr + 5, 5) - 5) / op->length; + sprintf(p, " %d", len); + p += strlen(p); + } p = append_tab_16(buf); addr += 5; diff --git a/src/rpl.h b/src/rpl.h index dd6a9b3..8542350 100644 --- a/src/rpl.h +++ b/src/rpl.h @@ -43,90 +43,90 @@ /* * Addresses in SX ROM */ -#define ROMPTAB_SX 0x707d9 -#define ROMPTAB_GX 0x809a3 - +#define ROMPTAB_SX 0x707d9 +#define ROMPTAB_GX 0x809a3 /* * Object Prologs */ -#define DOBINT 0x02911 /* System Binary */ -#define DOREAL 0x02933 /* Real */ -#define DOEREL 0x02955 /* Extended Real */ -#define DOCMP 0x02977 /* Complex */ -#define DOECMP 0x0299d /* Extended Complex */ -#define DOCHAR 0x029bf /* Character */ -#define DOARRY 0x029e8 /* Array */ -#define DOLNKARRY 0x02a0a /* Linked Array */ -#define DOCSTR 0x02a2c /* String */ -#define DOHSTR 0x02a4e /* Binary Integer */ -#define DOLIST 0x02a74 /* List */ -#define DORRP 0x02a96 /* Directory */ -#define DOSYMB 0x02ab8 /* Algebraic */ -#define DOEXT 0x02ada /* Unit */ -#define DOTAG 0x02afc /* Tagged */ -#define DOGROB 0x02b1e /* Graphic Object */ -#define DOLIB 0x02b40 /* Library */ -#define DOBAK 0x02b62 /* Backup */ -#define DOEXT0 0x02b88 /* Library Data */ -#define DOACPTR 0x02baa /* */ -#define DOEXT2 0x02bcc /* */ -#define DOEXT3 0x02bee /* */ -#define DOEXT4 0x02c10 /* */ -#define DOCOL 0x02d9d /* Program */ -#define DOCODE 0x02dcc /* Code */ -#define DOIDNT 0x02e48 /* Global Name */ -#define DOLAM 0x02e6d /* Local Name */ -#define DOROMP 0x02e92 /* XLib Name */ +#define DOBINT 0x02911 /* System Binary */ +#define DOREAL 0x02933 /* Real */ +#define DOEREL 0x02955 /* Extended Real */ +#define DOCMP 0x02977 /* Complex */ +#define DOECMP 0x0299d /* Extended Complex */ +#define DOCHAR 0x029bf /* Character */ +#define DOARRY 0x029e8 /* Array */ +#define DOLNKARRY 0x02a0a /* Linked Array */ +#define DOCSTR 0x02a2c /* String */ +#define DOHSTR 0x02a4e /* Binary Integer */ +#define DOLIST 0x02a74 /* List */ +#define DORRP 0x02a96 /* Directory */ +#define DOSYMB 0x02ab8 /* Algebraic */ +#define DOEXT 0x02ada /* Unit */ +#define DOTAG 0x02afc /* Tagged */ +#define DOGROB 0x02b1e /* Graphic Object */ +#define DOLIB 0x02b40 /* Library */ +#define DOBAK 0x02b62 /* Backup */ +#define DOEXT0 0x02b88 /* Library Data */ +#define DOACPTR 0x02baa /* */ +#define DOEXT2 0x02bcc /* */ +#define DOEXT3 0x02bee /* */ +#define DOEXT4 0x02c10 /* */ +#define DOCOL 0x02d9d /* Program */ +#define DOCODE 0x02dcc /* Code */ +#define DOIDNT 0x02e48 /* Global Name */ +#define DOLAM 0x02e6d /* Local Name */ +#define DOROMP 0x02e92 /* XLib Name */ /* * Terminates composite objects */ -#define SEMI 0x0312b /* Semi */ +#define SEMI 0x0312b /* Semi */ /* * Unit Operators */ -#define UM_MUL 0x10b5e /* Unit Operator * */ -#define UM_DIV 0x10b68 /* Unit Operator / */ -#define UM_POW 0x10b72 /* Unit Operator ^ */ -#define UM_PRE 0x10b7c /* Unit Operator prefix */ -#define UM_END 0x10b86 /* Unit Operator _ */ +#define UM_MUL 0x10b5e /* Unit Operator * */ +#define UM_DIV 0x10b68 /* Unit Operator / */ +#define UM_POW 0x10b72 /* Unit Operator ^ */ +#define UM_PRE 0x10b7c /* Unit Operator prefix */ +#define UM_END 0x10b86 /* Unit Operator _ */ typedef struct hp_real { - word_20 x; - word_32 ml; - word_32 mh; - word_4 m; - word_1 s; + word_20 x; + word_32 ml; + word_32 mh; + word_4 m; + word_1 s; } hp_real; -extern char *decode_rpl_obj __ProtoType__((word_20 addr, char *buf)); -extern void decode_rpl_obj_2 __ProtoType__((word_20 addr, char *typ, char *dat)); +extern char *decode_rpl_obj __ProtoType__((word_20 addr, char *buf)); +extern void decode_rpl_obj_2 __ProtoType__((word_20 addr, char *typ, + char *dat)); -extern char *skip_ob __ProtoType__((word_20 *addr, char *string)); -extern char *dec_rpl_obj __ProtoType__((word_20 *addr, char *string)); -extern char *dec_bin_int __ProtoType__((word_20 *addr, char *string)); -extern char *dec_real __ProtoType__((word_20 *addr, char *string)); -extern char *dec_long_real __ProtoType__((word_20 *addr, char *string)); -extern char *dec_complex __ProtoType__((word_20 *addr, char *string)); -extern char *dec_long_complex __ProtoType__((word_20 *addr, char *string)); -extern char *dec_char __ProtoType__((word_20 *addr, char *string)); -extern char *dec_array __ProtoType__((word_20 *addr, char *string)); -extern char *dec_lnk_array __ProtoType__((word_20 *addr, char *string)); -extern char *dec_string __ProtoType__((word_20 *addr, char *string)); -extern char *dec_hex_string __ProtoType__((word_20 *addr, char *string)); -extern char *dec_list __ProtoType__((word_20 *addr, char *string)); -extern char *dec_symb __ProtoType__((word_20 *addr, char *string)); -extern char *dec_unit __ProtoType__((word_20 *addr, char *string)); -extern char *dec_library __ProtoType__((word_20 *addr, char *string)); -extern char *dec_library_data __ProtoType__((word_20 *addr, char *string)); -extern char *dec_acptr __ProtoType__((word_20 *addr, char *string)); -extern char *dec_prog __ProtoType__((word_20 *addr, char *string)); -extern char *dec_code __ProtoType__((word_20 *addr, char *string)); -extern char *dec_global_ident __ProtoType__((word_20 *addr, char *string)); -extern char *dec_local_ident __ProtoType__((word_20 *addr, char *string)); -extern char *dec_xlib_name __ProtoType__((word_20 *addr, char *string)); -extern char *dec_unit_op __ProtoType__((word_20 *addr, char *string)); +extern char *skip_ob __ProtoType__((word_20 * addr, char *string)); +extern char *dec_rpl_obj __ProtoType__((word_20 * addr, char *string)); +extern char *dec_bin_int __ProtoType__((word_20 * addr, char *string)); +extern char *dec_real __ProtoType__((word_20 * addr, char *string)); +extern char *dec_long_real __ProtoType__((word_20 * addr, char *string)); +extern char *dec_complex __ProtoType__((word_20 * addr, char *string)); +extern char *dec_long_complex __ProtoType__((word_20 * addr, char *string)); +extern char *dec_char __ProtoType__((word_20 * addr, char *string)); +extern char *dec_array __ProtoType__((word_20 * addr, char *string)); +extern char *dec_lnk_array __ProtoType__((word_20 * addr, char *string)); +extern char *dec_string __ProtoType__((word_20 * addr, char *string)); +extern char *dec_hex_string __ProtoType__((word_20 * addr, char *string)); +extern char *dec_list __ProtoType__((word_20 * addr, char *string)); +extern char *dec_symb __ProtoType__((word_20 * addr, char *string)); +extern char *dec_unit __ProtoType__((word_20 * addr, char *string)); +extern char *dec_library __ProtoType__((word_20 * addr, char *string)); +extern char *dec_library_data __ProtoType__((word_20 * addr, char *string)); +extern char *dec_acptr __ProtoType__((word_20 * addr, char *string)); +extern char *dec_prog __ProtoType__((word_20 * addr, char *string)); +extern char *dec_code __ProtoType__((word_20 * addr, char *string)); +extern char *dec_global_ident __ProtoType__((word_20 * addr, char *string)); +extern char *dec_local_ident __ProtoType__((word_20 * addr, char *string)); +extern char *dec_xlib_name __ProtoType__((word_20 * addr, char *string)); +extern char *dec_unit_op __ProtoType__((word_20 * addr, char *string)); #endif /* !_RPL_H */ diff --git a/src/serial.c b/src/serial.c index 6e81201..16b448f 100644 --- a/src/serial.c +++ b/src/serial.c @@ -60,28 +60,27 @@ * $Id: serial.c,v 1.11 1995/01/11 18:20:01 ecd Exp ecd $ */ - #include "global.h" +#include +#include #include #include #include -#include -#include #include #if defined(HPUX) || defined(CSRG_BASED) -# include +#include #endif -#include #include +#include #ifdef SOLARIS -# include -# include -# include +#include +#include +#include #endif -#include "hp48.h" #include "device.h" +#include "hp48.h" #include "hp48_emu.h" #include "resources.h" #include "x48_x11.h" @@ -98,161 +97,133 @@ static char *ir_name = (char *)0; /* #define DEBUG_SERIAL */ void update_connection_display(void) { - if (wire_fd == -1) - { - if (wire_name) free(wire_name); - wire_name = (char *)0; - } - if (ir_fd == -1) - { - if (ir_name) free(ir_name); - ir_name = (char *)0; - } + if (wire_fd == -1) { + if (wire_name) + free(wire_name); + wire_name = (char *)0; + } + if (ir_fd == -1) { + if (ir_name) + free(ir_name); + ir_name = (char *)0; + } ShowConnections(wire_name, ir_name); } int serial_init(void) { char *p; - int c; - int n; - char tty_dev_name[128]; + int c; + int n; + char tty_dev_name[128]; struct termios ttybuf; wire_fd = -1; ttyp = -1; - if (useTerminal) - { + if (useTerminal) { #if defined(IRIX) - if ((p = _getpty(&wire_fd, O_RDWR | O_EXCL | O_NDELAY, 0666, 0)) == NULL) - { - wire_fd = -1; - ttyp = -1; - } - else - { - if ((ttyp = open(p, O_RDWR | O_NDELAY, 0666)) < 0) - { - close(wire_fd); - wire_fd = -1; - ttyp = -1; - } - else - { - if (verbose) - printf("%s: wire connection on %s\n", progname, p); - wire_name = strdup(p); - } - } -#elif defined(SOLARIS) - if ((wire_fd = open("/dev/ptmx", O_RDWR | O_NONBLOCK, 0666)) >= 0) - { - grantpt(wire_fd); - unlockpt(wire_fd); - p = ptsname(wire_fd); - strcpy(tty_dev_name, p); - if ((ttyp = open(tty_dev_name, O_RDWR | O_NDELAY, 0666)) >= 0) - { - ioctl(ttyp, I_PUSH, "ptem"); - ioctl(ttyp, I_PUSH, "ldterm"); - if (verbose) - printf("%s: wire connection on %s\n", progname, - tty_dev_name); - wire_name = strdup(tty_dev_name); - } - } -#elif defined(LINUX) - /* Unix98 PTY (Preferred) */ - if ((wire_fd = open("/dev/ptmx", O_RDWR | O_NONBLOCK, 0666)) >= 0) - { - grantpt(wire_fd); - unlockpt(wire_fd); - if (ptsname_r(wire_fd, tty_dev_name, 128)) { - perror("Could not get the name of the wire device."); - exit(-1); + if ((p = _getpty(&wire_fd, O_RDWR | O_EXCL | O_NDELAY, 0666, 0)) == NULL) { + wire_fd = -1; + ttyp = -1; + } else { + if ((ttyp = open(p, O_RDWR | O_NDELAY, 0666)) < 0) { + close(wire_fd); + wire_fd = -1; + ttyp = -1; + } else { + if (verbose) + printf("%s: wire connection on %s\n", progname, p); + wire_name = strdup(p); } - if ((ttyp = open(tty_dev_name, O_RDWR | O_NDELAY, 0666)) >= 0) - { - if (verbose) - printf("%s: wire connection on %s\n", progname, - tty_dev_name); - wire_name = strdup(tty_dev_name); - } - } - /* BSD PTY (Legacy) */ - else - { - c = 'p'; - do - { - for (n = 0; n < 16; n++) - { - sprintf(tty_dev_name, "/dev/pty%c%x", c, n); - if ((wire_fd = open(tty_dev_name, - O_RDWR | O_EXCL | O_NDELAY, 0666)) >= 0) - { - ttyp = wire_fd; - sprintf(tty_dev_name, "/dev/tty%c%x", c, n); - if (verbose) - printf("%s: wire connection on %s\n", progname, - tty_dev_name); - wire_name = strdup(tty_dev_name); - break; - } - } - c++; - } - while ((wire_fd < 0) && (errno != ENOENT)); } -#else - /* - * Here we go for SUNOS, HPUX - */ +#elif defined(SOLARIS) + if ((wire_fd = open("/dev/ptmx", O_RDWR | O_NONBLOCK, 0666)) >= 0) { + grantpt(wire_fd); + unlockpt(wire_fd); + p = ptsname(wire_fd); + strcpy(tty_dev_name, p); + if ((ttyp = open(tty_dev_name, O_RDWR | O_NDELAY, 0666)) >= 0) { + ioctl(ttyp, I_PUSH, "ptem"); + ioctl(ttyp, I_PUSH, "ldterm"); + if (verbose) + printf("%s: wire connection on %s\n", progname, tty_dev_name); + wire_name = strdup(tty_dev_name); + } + } +#elif defined(LINUX) + /* Unix98 PTY (Preferred) */ + if ((wire_fd = open("/dev/ptmx", O_RDWR | O_NONBLOCK, 0666)) >= 0) { + grantpt(wire_fd); + unlockpt(wire_fd); + if (ptsname_r(wire_fd, tty_dev_name, 128)) { + perror("Could not get the name of the wire device."); + exit(-1); + } + if ((ttyp = open(tty_dev_name, O_RDWR | O_NDELAY, 0666)) >= 0) { + if (verbose) + printf("%s: wire connection on %s\n", progname, tty_dev_name); + wire_name = strdup(tty_dev_name); + } + } + /* BSD PTY (Legacy) */ + else { c = 'p'; - do - { - for (n = 0; n < 16; n++) - { - sprintf(tty_dev_name, "/dev/ptyp%x", n); - if ((wire_fd = open(tty_dev_name, - O_RDWR | O_EXCL | O_NDELAY, 0666)) >= 0) - { - sprintf(tty_dev_name, "/dev/tty%c%x", c, n); - if ((ttyp = open(tty_dev_name, O_RDWR | O_NDELAY, 0666)) < 0) - { - wire_fd = -1; - ttyp = -1; - } - else - { - if (verbose) - printf("%s: wire connection on %s\n", progname, - tty_dev_name); - wire_name = strdup(tty_dev_name); - break; - } - } - } - c++; + do { + for (n = 0; n < 16; n++) { + sprintf(tty_dev_name, "/dev/pty%c%x", c, n); + if ((wire_fd = + open(tty_dev_name, O_RDWR | O_EXCL | O_NDELAY, 0666)) >= 0) { + ttyp = wire_fd; + sprintf(tty_dev_name, "/dev/tty%c%x", c, n); + if (verbose) + printf("%s: wire connection on %s\n", progname, tty_dev_name); + wire_name = strdup(tty_dev_name); + break; + } } - while ((wire_fd < 0) && (errno != ENOENT)); -#endif + c++; + } while ((wire_fd < 0) && (errno != ENOENT)); } - - if (ttyp >= 0) - { -#if defined(TCSANOW) - if (tcgetattr(ttyp, &ttybuf) < 0) #else - if (ioctl(ttyp, TCGETS, (char *)&ttybuf) < 0) -#endif - { - if (!quiet) - fprintf(stderr, "%s: ioctl(wire, TCGETS) failed, errno = %d\n", - progname, errno); - wire_fd = -1; - ttyp = -1; + /* + * Here we go for SUNOS, HPUX + */ + c = 'p'; + do { + for (n = 0; n < 16; n++) { + sprintf(tty_dev_name, "/dev/ptyp%x", n); + if ((wire_fd = open(tty_dev_name, O_RDWR | O_EXCL | O_NDELAY, 0666)) >= + 0) { + sprintf(tty_dev_name, "/dev/tty%c%x", c, n); + if ((ttyp = open(tty_dev_name, O_RDWR | O_NDELAY, 0666)) < 0) { + wire_fd = -1; + ttyp = -1; + } else { + if (verbose) + printf("%s: wire connection on %s\n", progname, tty_dev_name); + wire_name = strdup(tty_dev_name); + break; + } } + } + c++; + } while ((wire_fd < 0) && (errno != ENOENT)); +#endif + } + + if (ttyp >= 0) { +#if defined(TCSANOW) + if (tcgetattr(ttyp, &ttybuf) < 0) +#else + if (ioctl(ttyp, TCGETS, (char *)&ttybuf) < 0) +#endif + { + if (!quiet) + fprintf(stderr, "%s: ioctl(wire, TCGETS) failed, errno = %d\n", + progname, errno); + wire_fd = -1; + ttyp = -1; } + } ttybuf.c_lflag = 0; ttybuf.c_iflag = 0; @@ -263,48 +234,44 @@ int serial_init(void) { ttybuf.c_cc[VTIME] = 0; ttybuf.c_cc[VMIN] = 1; - if (ttyp >= 0) - { + if (ttyp >= 0) { #if defined(TCSANOW) - if (tcsetattr(ttyp, TCSANOW, &ttybuf) < 0) + if (tcsetattr(ttyp, TCSANOW, &ttybuf) < 0) #else - if (ioctl(ttyp, TCSETS, (char *)&ttybuf) < 0) + if (ioctl(ttyp, TCSETS, (char *)&ttybuf) < 0) #endif - { - if (!quiet) - fprintf(stderr, "%s: ioctl(wire, TCSETS) failed, errno = %d\n", - progname, errno); - wire_fd = -1; - ttyp = -1; - } + { + if (!quiet) + fprintf(stderr, "%s: ioctl(wire, TCSETS) failed, errno = %d\n", + progname, errno); + wire_fd = -1; + ttyp = -1; } + } ir_fd = -1; - if (useSerial) - { - sprintf(tty_dev_name, serialLine); - if ((ir_fd = open(tty_dev_name, O_RDWR | O_NDELAY)) >= 0) - { - if (verbose) - printf("%s: IR connection on %s\n", progname, tty_dev_name); - ir_name = strdup(tty_dev_name); - } + if (useSerial) { + sprintf(tty_dev_name, serialLine); + if ((ir_fd = open(tty_dev_name, O_RDWR | O_NDELAY)) >= 0) { + if (verbose) + printf("%s: IR connection on %s\n", progname, tty_dev_name); + ir_name = strdup(tty_dev_name); } + } - if (ir_fd >= 0) - { + if (ir_fd >= 0) { #if defined(TCSANOW) - if (tcgetattr(ir_fd, &ttybuf) < 0) + if (tcgetattr(ir_fd, &ttybuf) < 0) #else - if (ioctl(ir_fd, TCGETS, (char *)&ttybuf) < 0) + if (ioctl(ir_fd, TCGETS, (char *)&ttybuf) < 0) #endif - { - if (!quiet) - fprintf(stderr, "%s: ioctl(IR, TCGETS) failed, errno = %d\n", - progname, errno); - ir_fd = -1; - } + { + if (!quiet) + fprintf(stderr, "%s: ioctl(IR, TCGETS) failed, errno = %d\n", progname, + errno); + ir_fd = -1; } + } ttybuf.c_lflag = 0; ttybuf.c_iflag = 0; @@ -315,20 +282,19 @@ int serial_init(void) { ttybuf.c_cc[VTIME] = 0; ttybuf.c_cc[VMIN] = 1; - if (ir_fd >= 0) - { + if (ir_fd >= 0) { #if defined(TCSANOW) - if (tcsetattr(ir_fd, TCSANOW, &ttybuf) < 0) + if (tcsetattr(ir_fd, TCSANOW, &ttybuf) < 0) #else - if (ioctl(ir_fd, TCSETS, (char *)&ttybuf) < 0) + if (ioctl(ir_fd, TCSETS, (char *)&ttybuf) < 0) #endif - { - if (!quiet) - fprintf(stderr, "%s: ioctl(IR, TCSETS) failed, errno = %d\n", - progname, errno); - ir_fd = -1; - } + { + if (!quiet) + fprintf(stderr, "%s: ioctl(IR, TCSETS) failed, errno = %d\n", progname, + errno); + ir_fd = -1; } + } update_connection_display(); return 1; } @@ -337,215 +303,204 @@ void serial_baud(int baud) { int error = 0; struct termios ttybuf; - if (ir_fd >= 0) - { + if (ir_fd >= 0) { #if defined(TCSANOW) - if (tcgetattr(ir_fd, &ttybuf) < 0) + if (tcgetattr(ir_fd, &ttybuf) < 0) #else - if (ioctl(ir_fd, TCGETS, (char *)&ttybuf) < 0) + if (ioctl(ir_fd, TCGETS, (char *)&ttybuf) < 0) #endif - { - if (!quiet) - fprintf(stderr, "%s: ioctl(IR, TCGETS) failed, errno = %d\n", - progname, errno); - ir_fd = -1; - error = 1; - } + { + if (!quiet) + fprintf(stderr, "%s: ioctl(IR, TCGETS) failed, errno = %d\n", progname, + errno); + ir_fd = -1; + error = 1; } + } #if defined(__APPLE__) baud &= 0x7; - switch (baud) - { - case 0: /* 1200 */ - ttybuf.c_cflag |= B1200; - break; - case 1: /* 1920 */ -# ifdef B1920 - ttybuf.c_cflag |= B1920; -# endif - break; - case 2: /* 2400 */ - ttybuf.c_cflag |= B2400; - break; - case 3: /* 3840 */ -# ifdef B3840 - ttybuf.c_cflag |= B3840; -# endif - break; - case 4: /* 4800 */ - ttybuf.c_cflag |= B4800; - break; - case 5: /* 7680 */ -# ifdef B7680 - ttybuf.c_cflag |= B7680; -# endif - break; - case 6: /* 9600 */ - ttybuf.c_cflag |= B9600; - break; - case 7: /* 15360 */ -# ifdef B15360 - ttybuf.c_cflag |= B15360; -# endif - break; - } + switch (baud) { + case 0: /* 1200 */ + ttybuf.c_cflag |= B1200; + break; + case 1: /* 1920 */ +#ifdef B1920 + ttybuf.c_cflag |= B1920; +#endif + break; + case 2: /* 2400 */ + ttybuf.c_cflag |= B2400; + break; + case 3: /* 3840 */ +#ifdef B3840 + ttybuf.c_cflag |= B3840; +#endif + break; + case 4: /* 4800 */ + ttybuf.c_cflag |= B4800; + break; + case 5: /* 7680 */ +#ifdef B7680 + ttybuf.c_cflag |= B7680; +#endif + break; + case 6: /* 9600 */ + ttybuf.c_cflag |= B9600; + break; + case 7: /* 15360 */ +#ifdef B15360 + ttybuf.c_cflag |= B15360; +#endif + break; + } - if ((ir_fd >= 0) && ((ttybuf.c_ospeed) == 0)) - { - if (!quiet) - fprintf(stderr, "%s: can\'t set baud rate, using 9600\n", progname); - ttybuf.c_cflag |= B9600; - } + if ((ir_fd >= 0) && ((ttybuf.c_ospeed) == 0)) { + if (!quiet) + fprintf(stderr, "%s: can\'t set baud rate, using 9600\n", progname); + ttybuf.c_cflag |= B9600; + } #else ttybuf.c_cflag &= ~CBAUD; baud &= 0x7; - switch (baud) - { - case 0: /* 1200 */ - ttybuf.c_cflag |= B1200; - break; - case 1: /* 1920 */ -# ifdef B1920 - ttybuf.c_cflag |= B1920; -# endif - break; - case 2: /* 2400 */ - ttybuf.c_cflag |= B2400; - break; - case 3: /* 3840 */ -# ifdef B3840 - ttybuf.c_cflag |= B3840; -# endif - break; - case 4: /* 4800 */ - ttybuf.c_cflag |= B4800; - break; - case 5: /* 7680 */ -# ifdef B7680 - ttybuf.c_cflag |= B7680; -# endif - break; - case 6: /* 9600 */ - ttybuf.c_cflag |= B9600; - break; - case 7: /* 15360 */ -# ifdef B15360 - ttybuf.c_cflag |= B15360; -# endif - break; - } + switch (baud) { + case 0: /* 1200 */ + ttybuf.c_cflag |= B1200; + break; + case 1: /* 1920 */ +#ifdef B1920 + ttybuf.c_cflag |= B1920; +#endif + break; + case 2: /* 2400 */ + ttybuf.c_cflag |= B2400; + break; + case 3: /* 3840 */ +#ifdef B3840 + ttybuf.c_cflag |= B3840; +#endif + break; + case 4: /* 4800 */ + ttybuf.c_cflag |= B4800; + break; + case 5: /* 7680 */ +#ifdef B7680 + ttybuf.c_cflag |= B7680; +#endif + break; + case 6: /* 9600 */ + ttybuf.c_cflag |= B9600; + break; + case 7: /* 15360 */ +#ifdef B15360 + ttybuf.c_cflag |= B15360; +#endif + break; + } - if ((ir_fd >= 0) && ((ttybuf.c_cflag & CBAUD) == 0)) + if ((ir_fd >= 0) && ((ttybuf.c_cflag & CBAUD) == 0)) { + if (!quiet) + fprintf(stderr, "%s: can\'t set baud rate, using 9600\n", progname); + ttybuf.c_cflag |= B9600; + } +#endif + if (ir_fd >= 0) { +#if defined(TCSANOW) + if (tcsetattr(ir_fd, TCSANOW, &ttybuf) < 0) +#else + if (ioctl(ir_fd, TCSETS, (char *)&ttybuf) < 0) +#endif { if (!quiet) - fprintf(stderr, "%s: can\'t set baud rate, using 9600\n", progname); - ttybuf.c_cflag |= B9600; - } -#endif - if (ir_fd >= 0) - { -#if defined(TCSANOW) - if (tcsetattr(ir_fd, TCSANOW, &ttybuf) < 0) -#else - if (ioctl(ir_fd, TCSETS, (char *)&ttybuf) < 0) -#endif - { - if (!quiet) - fprintf(stderr, "%s: ioctl(IR, TCSETS) failed, errno = %d\n", - progname, errno); - ir_fd = -1; - error = 1; - } + fprintf(stderr, "%s: ioctl(IR, TCSETS) failed, errno = %d\n", progname, + errno); + ir_fd = -1; + error = 1; } + } - if (ttyp >= 0) - { + if (ttyp >= 0) { #if defined(TCSANOW) - if (tcgetattr(ttyp, &ttybuf) < 0) + if (tcgetattr(ttyp, &ttybuf) < 0) #else - if (ioctl(ttyp, TCGETS, (char *)&ttybuf) < 0) + if (ioctl(ttyp, TCGETS, (char *)&ttybuf) < 0) #endif - { - if (!quiet) - fprintf(stderr, "%s: ioctl(wire, TCGETS) failed, errno = %d\n", - progname, errno); - wire_fd = -1; - ttyp = -1; - error = 1; - } + { + if (!quiet) + fprintf(stderr, "%s: ioctl(wire, TCGETS) failed, errno = %d\n", + progname, errno); + wire_fd = -1; + ttyp = -1; + error = 1; } + } #if defined(__APPLE__) #else ttybuf.c_cflag &= ~CBAUD; baud &= 0x7; - switch (baud) - { - case 0: /* 1200 */ - ttybuf.c_cflag |= B1200; - break; - case 1: /* 1920 */ -# ifdef B1920 - ttybuf.c_cflag |= B1920; -# endif - break; - case 2: /* 2400 */ - ttybuf.c_cflag |= B2400; - break; - case 3: /* 3840 */ -# ifdef B3840 - ttybuf.c_cflag |= B3840; -# endif - break; - case 4: /* 4800 */ - ttybuf.c_cflag |= B4800; - break; - case 5: /* 7680 */ -# ifdef B7680 - ttybuf.c_cflag |= B7680; -# endif - break; - case 6: /* 9600 */ - ttybuf.c_cflag |= B9600; - break; - case 7: /* 15360 */ -# ifdef B15360 - ttybuf.c_cflag |= B15360; -# endif - break; - } + switch (baud) { + case 0: /* 1200 */ + ttybuf.c_cflag |= B1200; + break; + case 1: /* 1920 */ +#ifdef B1920 + ttybuf.c_cflag |= B1920; +#endif + break; + case 2: /* 2400 */ + ttybuf.c_cflag |= B2400; + break; + case 3: /* 3840 */ +#ifdef B3840 + ttybuf.c_cflag |= B3840; +#endif + break; + case 4: /* 4800 */ + ttybuf.c_cflag |= B4800; + break; + case 5: /* 7680 */ +#ifdef B7680 + ttybuf.c_cflag |= B7680; +#endif + break; + case 6: /* 9600 */ + ttybuf.c_cflag |= B9600; + break; + case 7: /* 15360 */ +#ifdef B15360 + ttybuf.c_cflag |= B15360; +#endif + break; + } - if ((ttyp >= 0) && ((ttybuf.c_cflag & CBAUD) == 0)) + if ((ttyp >= 0) && ((ttybuf.c_cflag & CBAUD) == 0)) { + if (!quiet) + fprintf(stderr, "%s: can\'t set baud rate, using 9600\n", progname); + ttybuf.c_cflag |= B9600; + } +#endif + if (ttyp >= 0) { +#if defined(TCSANOW) + if (tcsetattr(ttyp, TCSANOW, &ttybuf) < 0) +#else + if (ioctl(ttyp, TCSETS, (char *)&ttybuf) < 0) +#endif { if (!quiet) - fprintf(stderr, "%s: can\'t set baud rate, using 9600\n", progname); - ttybuf.c_cflag |= B9600; - } -#endif - if (ttyp >= 0) - { -#if defined(TCSANOW) - if (tcsetattr(ttyp, TCSANOW, &ttybuf) < 0) -#else - if (ioctl(ttyp, TCSETS, (char *)&ttybuf) < 0) -#endif - { - if (!quiet) - fprintf(stderr, "%s: ioctl(wire, TCSETS) failed, errno = %d\n", - progname, errno); - wire_fd = -1; - ttyp = -1; - error = 1; - } + fprintf(stderr, "%s: ioctl(wire, TCSETS) failed, errno = %d\n", + progname, errno); + wire_fd = -1; + ttyp = -1; + error = 1; } + } if (error) update_connection_display(); } - void transmit_char(void) { #ifdef DEBUG_SERIALx fprintf(stderr, "XMT %s\n", (saturn.ir_ctrl & 0x04) ? "IR" : "wire"); diff --git a/src/small.h b/src/small.h index 22dce44..fb39607 100644 --- a/src/small.h +++ b/src/small.h @@ -191,139 +191,138 @@ #include "bitmaps/equal_gx.h" typedef struct letter_t { - unsigned int w, h; + unsigned int w, h; unsigned char *bits; } letter_t; letter_t small_font[] = { - { 0, 0, 0 }, - { nl_gx_width, nl_gx_height, nl_gx_bits }, /* \001 == \n gx */ - { comma_gx_width, comma_gx_height, comma_gx_bits }, /* \002 == comma gx */ - { arrow_gx_width, arrow_gx_height, arrow_gx_bits }, /* \003 == \-> gx */ - { equal_gx_width, equal_gx_height, equal_gx_bits }, /* \004 == equal gx */ - { pi_gx_width, pi_gx_height, pi_gx_bits }, /* \005 == pi gx */ - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, /* # 16 */ - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { blank_width, blank_height, blank_bits }, /* # 32 */ - { 0, 0, 0 }, - { 0, 0, 0 }, - { hash_width, hash_height, hash_bits }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { lbrace_width, lbrace_height, lbrace_bits }, - { rbrace_width, rbrace_height, rbrace_bits }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { comma_width, comma_height, comma_bits }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { slash_width, slash_height, slash_bits }, - { 0, 0, 0 }, /* # 48 */ - { 0, 0, 0 }, - { two_width, two_height, two_bits }, - { three_width, three_height, three_bits }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { small_colon_width, small_colon_height, small_colon_bits }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { equal_width, equal_height, equal_bits }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, /* # 64 */ - { A_width, A_height, A_bits }, - { B_width, B_height, B_bits }, - { C_width, C_height, C_bits }, - { D_width, D_height, D_bits }, - { E_width, E_height, E_bits }, - { F_width, F_height, F_bits }, - { G_width, G_height, G_bits }, - { H_width, H_height, H_bits }, - { I_width, I_height, I_bits }, - { J_width, J_height, J_bits }, - { K_width, K_height, K_bits }, - { L_width, L_height, L_bits }, - { M_width, M_height, M_bits }, - { N_width, N_height, N_bits }, - { O_width, O_height, O_bits }, - { P_width, P_height, P_bits }, /* # 80 */ - { Q_width, Q_height, Q_bits }, - { R_width, R_height, R_bits }, - { S_width, S_height, S_bits }, - { T_width, T_height, T_bits }, - { U_width, U_height, U_bits }, - { V_width, V_height, V_bits }, - { W_width, W_height, W_bits }, - { X_width, X_height, X_bits }, - { Y_width, Y_height, Y_bits }, - { Z_width, Z_height, Z_bits }, - { lbracket_width, lbracket_height, lbracket_bits }, - { 0, 0, 0 }, - { rbracket_width, rbracket_height, rbracket_bits }, - { 0, 0, 0 }, - { under_width, under_height, under_bits }, - { 0, 0, 0 }, /* # 96 */ - { arrow_width, arrow_height, arrow_bits }, /* a == left arrow */ - { diff_width, diff_height, diff_bits }, /* b == differential */ - { integral_width, integral_height, integral_bits }, /* c == integral */ - { sigma_width, sigma_height, sigma_bits }, /* d == sigma */ - { sqr_width, sqr_height, sqr_bits }, /* e == sqr */ - { root_width, root_height, root_bits }, /* f == root */ - { pow10_width, pow10_height, pow10_bits }, /* g == pow10 */ - { exp_width, exp_height, exp_bits }, /* h == exp */ - { prog_width, prog_height, prog_bits }, /* i == << >> */ - { string_width, string_height, string_bits }, /* j == " " */ - { nl_width, nl_height, nl_bits }, /* k == New Line */ - { pi_width, pi_height, pi_bits }, /* l == pi */ - { angle_width, angle_height, angle_bits }, /* m == angle */ - { sqr_gx_width, sqr_gx_height, sqr_gx_bits }, /* n == sqr gx */ - { root_gx_width, root_gx_height, root_gx_bits }, /* o == root gx */ - { pow10_gx_width, pow10_gx_height, pow10_gx_bits }, /* p == pow10 gx */ - { exp_gx_width, exp_gx_height, exp_gx_bits }, /* q == exp gx */ - { parens_gx_width, parens_gx_height, parens_gx_bits },/* r == ( ) gx */ - { hash_gx_width, hash_gx_height, hash_gx_bits }, /* s == # gx */ - { bracket_gx_width, bracket_gx_height, bracket_gx_bits }, /* t == [] gx */ - { under_gx_width, under_gx_height, under_gx_bits }, /* u == _ gx */ - { prog_gx_width, prog_gx_height, prog_gx_bits }, /* v == << >> gx */ - { quote_gx_width, quote_gx_height, quote_gx_bits }, /* w == " " gx */ - { curly_gx_width, curly_gx_height, curly_gx_bits }, /* x == {} gx */ - { colon_gx_width, colon_gx_height, colon_gx_bits }, /* y == :: gx */ - { angle_gx_width, angle_gx_height, angle_gx_bits }, /* z == angle gx */ - { lcurly_width, lcurly_height, lcurly_bits }, - { 0, 0, 0 }, - { rcurly_width, rcurly_height, rcurly_bits }, - { 0, 0, 0 }, - { 0, 0, 0 } -}; + {0, 0, 0}, + {nl_gx_width, nl_gx_height, nl_gx_bits}, /* \001 == \n gx */ + {comma_gx_width, comma_gx_height, comma_gx_bits}, /* \002 == comma gx */ + {arrow_gx_width, arrow_gx_height, arrow_gx_bits}, /* \003 == \-> gx */ + {equal_gx_width, equal_gx_height, equal_gx_bits}, /* \004 == equal gx */ + {pi_gx_width, pi_gx_height, pi_gx_bits}, /* \005 == pi gx */ + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, /* # 16 */ + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {blank_width, blank_height, blank_bits}, /* # 32 */ + {0, 0, 0}, + {0, 0, 0}, + {hash_width, hash_height, hash_bits}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {lbrace_width, lbrace_height, lbrace_bits}, + {rbrace_width, rbrace_height, rbrace_bits}, + {0, 0, 0}, + {0, 0, 0}, + {comma_width, comma_height, comma_bits}, + {0, 0, 0}, + {0, 0, 0}, + {slash_width, slash_height, slash_bits}, + {0, 0, 0}, /* # 48 */ + {0, 0, 0}, + {two_width, two_height, two_bits}, + {three_width, three_height, three_bits}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {small_colon_width, small_colon_height, small_colon_bits}, + {0, 0, 0}, + {0, 0, 0}, + {equal_width, equal_height, equal_bits}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, /* # 64 */ + {A_width, A_height, A_bits}, + {B_width, B_height, B_bits}, + {C_width, C_height, C_bits}, + {D_width, D_height, D_bits}, + {E_width, E_height, E_bits}, + {F_width, F_height, F_bits}, + {G_width, G_height, G_bits}, + {H_width, H_height, H_bits}, + {I_width, I_height, I_bits}, + {J_width, J_height, J_bits}, + {K_width, K_height, K_bits}, + {L_width, L_height, L_bits}, + {M_width, M_height, M_bits}, + {N_width, N_height, N_bits}, + {O_width, O_height, O_bits}, + {P_width, P_height, P_bits}, /* # 80 */ + {Q_width, Q_height, Q_bits}, + {R_width, R_height, R_bits}, + {S_width, S_height, S_bits}, + {T_width, T_height, T_bits}, + {U_width, U_height, U_bits}, + {V_width, V_height, V_bits}, + {W_width, W_height, W_bits}, + {X_width, X_height, X_bits}, + {Y_width, Y_height, Y_bits}, + {Z_width, Z_height, Z_bits}, + {lbracket_width, lbracket_height, lbracket_bits}, + {0, 0, 0}, + {rbracket_width, rbracket_height, rbracket_bits}, + {0, 0, 0}, + {under_width, under_height, under_bits}, + {0, 0, 0}, /* # 96 */ + {arrow_width, arrow_height, arrow_bits}, /* a == left arrow */ + {diff_width, diff_height, diff_bits}, /* b == differential */ + {integral_width, integral_height, integral_bits}, /* c == integral */ + {sigma_width, sigma_height, sigma_bits}, /* d == sigma */ + {sqr_width, sqr_height, sqr_bits}, /* e == sqr */ + {root_width, root_height, root_bits}, /* f == root */ + {pow10_width, pow10_height, pow10_bits}, /* g == pow10 */ + {exp_width, exp_height, exp_bits}, /* h == exp */ + {prog_width, prog_height, prog_bits}, /* i == << >> */ + {string_width, string_height, string_bits}, /* j == " " */ + {nl_width, nl_height, nl_bits}, /* k == New Line */ + {pi_width, pi_height, pi_bits}, /* l == pi */ + {angle_width, angle_height, angle_bits}, /* m == angle */ + {sqr_gx_width, sqr_gx_height, sqr_gx_bits}, /* n == sqr gx */ + {root_gx_width, root_gx_height, root_gx_bits}, /* o == root gx */ + {pow10_gx_width, pow10_gx_height, pow10_gx_bits}, /* p == pow10 gx */ + {exp_gx_width, exp_gx_height, exp_gx_bits}, /* q == exp gx */ + {parens_gx_width, parens_gx_height, parens_gx_bits}, /* r == ( ) gx */ + {hash_gx_width, hash_gx_height, hash_gx_bits}, /* s == # gx */ + {bracket_gx_width, bracket_gx_height, bracket_gx_bits}, /* t == [] gx */ + {under_gx_width, under_gx_height, under_gx_bits}, /* u == _ gx */ + {prog_gx_width, prog_gx_height, prog_gx_bits}, /* v == << >> gx */ + {quote_gx_width, quote_gx_height, quote_gx_bits}, /* w == " " gx */ + {curly_gx_width, curly_gx_height, curly_gx_bits}, /* x == {} gx */ + {colon_gx_width, colon_gx_height, colon_gx_bits}, /* y == :: gx */ + {angle_gx_width, angle_gx_height, angle_gx_bits}, /* z == angle gx */ + {lcurly_width, lcurly_height, lcurly_bits}, + {0, 0, 0}, + {rcurly_width, rcurly_height, rcurly_bits}, + {0, 0, 0}, + {0, 0, 0}}; #endif /* !_SMALL_H */ diff --git a/src/timer.c b/src/timer.c index 80af657..1bdca1b 100644 --- a/src/timer.c +++ b/src/timer.c @@ -40,14 +40,14 @@ #include "global.h" -#include #include -#include +#include #include +#include -#include "timer.h" #include "debugger.h" #include "romio.h" +#include "timer.h" #include @@ -55,14 +55,14 @@ /* #define DEBUG_TIMER_ADJUST 1 */ #ifdef SOLARIS -extern int gettimeofday __ProtoType__((struct timeval *tp)); +extern int gettimeofday __ProtoType__((struct timeval * tp)); #endif #ifdef SUNOS extern int gettimeofday __ProtoType__((struct timeval *, struct timezone *)); #endif typedef struct x48_timer_t { - word_1 run; + word_1 run; word_64 start; word_64 stop; word_64 value; @@ -75,7 +75,7 @@ static long systime_offset = 0; /* * Ticks for THU 01.01.1970 00:00:00 */ -word_64 unix_0_time = 0x1CF2E8F800000L; +word_64 unix_0_time = 0x1CF2E8F800000L; word_64 ticks_10_min = 0x00b40000L; /* @@ -88,17 +88,17 @@ word_64 set_0_time = 0x0; */ word_64 time_offset = 0x0; -#define RAM_BASE_SX 0x70000 -#define ACCESSTIME_SX (0x70052 - RAM_BASE_SX) -#define ACCESSCRC_SX (0x7005F - RAM_BASE_SX) -#define TIMEOUT_SX (0x70063 - RAM_BASE_SX) -#define TIMEOUTCLK_SX (0x70070 - RAM_BASE_SX) +#define RAM_BASE_SX 0x70000 +#define ACCESSTIME_SX (0x70052 - RAM_BASE_SX) +#define ACCESSCRC_SX (0x7005F - RAM_BASE_SX) +#define TIMEOUT_SX (0x70063 - RAM_BASE_SX) +#define TIMEOUTCLK_SX (0x70070 - RAM_BASE_SX) -#define RAM_BASE_GX 0x80000 -#define ACCESSTIME_GX (0x80058 - RAM_BASE_GX) -#define ACCESSCRC_GX (0x80065 - RAM_BASE_GX) -#define TIMEOUT_GX (0x80069 - RAM_BASE_GX) -#define TIMEOUTCLK_GX (0x80076 - RAM_BASE_GX) +#define RAM_BASE_GX 0x80000 +#define ACCESSTIME_GX (0x80058 - RAM_BASE_GX) +#define ACCESSCRC_GX (0x80065 - RAM_BASE_GX) +#define TIMEOUT_GX (0x80069 - RAM_BASE_GX) +#define TIMEOUTCLK_GX (0x80076 - RAM_BASE_GX) #define calc_crc(nib) (crc = (crc >> 4) ^ (((crc ^ (nib)) & 0xf) * 0x1081)) @@ -116,18 +116,18 @@ word_64 time_offset = 0x0; * */ void set_accesstime(void) { - struct timeval tv; + struct timeval tv; #ifndef SOLARIS struct timezone tz; #endif - word_64 ticks, timeout, timer2; - word_20 accesstime_loc, timeout_loc; - word_20 accesscrc_loc, timeoutclk_loc; - word_16 crc; - word_4 val; - int i; - time_t gmt; - struct tm *ltm; + word_64 ticks, timeout, timer2; + word_20 accesstime_loc, timeout_loc; + word_20 accesscrc_loc, timeoutclk_loc; + word_16 crc; + word_4 val; + int i; + time_t gmt; + struct tm *ltm; /* * This is done to set the variable 'timezone' on SYSV systems @@ -136,7 +136,7 @@ void set_accesstime(void) { ltm = localtime(&gmt); #if defined(SYSV_TIME) || defined(__sgi) systime_offset = timezone; - if( ltm->tm_isdst ) + if (ltm->tm_isdst) systime_offset -= 3600; #else systime_offset = -ltm->tm_gmtoff; @@ -157,10 +157,9 @@ void set_accesstime(void) { ticks += time_offset; timer2 = saturn.timer2; - if (saturn.timer2 & 0x80000000) - { - assert(timer2 < 0); - } + if (saturn.timer2 & 0x80000000) { + assert(timer2 < 0); + } ticks += timer2; @@ -168,50 +167,44 @@ void set_accesstime(void) { crc = 0x0; - if (opt_gx) - { - accesstime_loc = ACCESSTIME_GX; - accesscrc_loc = ACCESSCRC_GX; - timeout_loc = TIMEOUT_GX; - timeoutclk_loc = TIMEOUTCLK_GX; - } - else - { - accesstime_loc = ACCESSTIME_SX; - accesscrc_loc = ACCESSCRC_SX; - timeout_loc = TIMEOUT_SX; - timeoutclk_loc = TIMEOUTCLK_SX; - } + if (opt_gx) { + accesstime_loc = ACCESSTIME_GX; + accesscrc_loc = ACCESSCRC_GX; + timeout_loc = TIMEOUT_GX; + timeoutclk_loc = TIMEOUTCLK_GX; + } else { + accesstime_loc = ACCESSTIME_SX; + accesscrc_loc = ACCESSCRC_SX; + timeout_loc = TIMEOUT_SX; + timeoutclk_loc = TIMEOUTCLK_SX; + } - for (i = 0; i < 13; i++) - { - val = ticks & 0xf; - calc_crc(val); - saturn.ram[accesstime_loc + i] = val; - ticks >>= 4; - } + for (i = 0; i < 13; i++) { + val = ticks & 0xf; + calc_crc(val); + saturn.ram[accesstime_loc + i] = val; + ticks >>= 4; + } - for (i = 0; i < 4; i++) - { - saturn.ram[accesscrc_loc + i] = crc & 0xf; - crc >>= 4; - } + for (i = 0; i < 4; i++) { + saturn.ram[accesscrc_loc + i] = crc & 0xf; + crc >>= 4; + } timeout += ticks_10_min; - for (i = 0; i < 13; i++) - { - val = timeout & 0xf; - calc_crc(val); - saturn.ram[timeout_loc + i] = val; - timeout >>= 4; - } + for (i = 0; i < 13; i++) { + val = timeout & 0xf; + calc_crc(val); + saturn.ram[timeout_loc + i] = val; + timeout >>= 4; + } saturn.ram[timeoutclk_loc] = 0xf; } void start_timer(int timer) { - struct timeval tv; + struct timeval tv; #ifndef SOLARIS struct timezone tz; #endif @@ -237,12 +230,13 @@ void start_timer(int timer) { timers[timer].start += (tv.tv_usec << 7) / 15625; } #ifdef DEBUG_TIMER - fprintf(stderr, "Timer%c[%d] start at 0x%lx\n", timer == T1_TIMER?'*':' ', timer, timers[timer].start); + fprintf(stderr, "Timer%c[%d] start at 0x%lx\n", timer == T1_TIMER ? '*' : ' ', + timer, timers[timer].start); #endif } void restart_timer(int timer) { - struct timeval tv; + struct timeval tv; #ifndef SOLARIS struct timezone tz; #endif @@ -271,13 +265,12 @@ void restart_timer(int timer) { timers[timer].start += (tv.tv_usec << 7) / 15625; } #ifdef DEBUG_TIMER - fprintf(stderr, "Timer[%d] restart at 0x%lx\n", timer, - timers[timer].start); + fprintf(stderr, "Timer[%d] restart at 0x%lx\n", timer, timers[timer].start); #endif } void stop_timer(int timer) { - struct timeval tv; + struct timeval tv; #ifndef SOLARIS struct timezone tz; #endif @@ -306,11 +299,12 @@ void stop_timer(int timer) { } timers[timer].value += timers[timer].stop - timers[timer].start; -// add_sub_64(&timers[timer].stop, &timers[timer].start, &timers[timer].value); + // add_sub_64(&timers[timer].stop, &timers[timer].start, + // &timers[timer].value); #ifdef DEBUG_TIMER - fprintf(stderr, "Timer[%d] stop at 0x%llx, value 0x%llx\n", - timer, timers[timer].stop, timers[timer].value); + fprintf(stderr, "Timer[%d] stop at 0x%llx, value 0x%llx\n", timer, + timers[timer].stop, timers[timer].value); #endif } @@ -329,11 +323,11 @@ void reset_timer(int timer) { static word_64 zero = 0; word_64 get_timer(int timer) { - struct timeval tv; + struct timeval tv; #ifndef SOLARIS struct timezone tz; #endif - word_64 stop; + word_64 stop; if (timer > NR_TIMERS) return zero; @@ -373,18 +367,18 @@ word_64 get_timer(int timer) { */ t1_t2_ticks get_t1_t2(void) { - struct timeval tv; + struct timeval tv; #ifndef SOLARIS struct timezone tz; #endif - word_64 stop; - t1_t2_ticks ticks; - word_64 access_time; - word_64 adj_time; - word_64 diff_time; - word_64 delta; - word_20 accesstime_loc; - int i; + word_64 stop; + t1_t2_ticks ticks; + word_64 access_time; + word_64 adj_time; + word_64 diff_time; + word_64 delta; + word_20 accesstime_loc; + int i; #ifdef SOLARIS gettimeofday(&tv); @@ -393,17 +387,15 @@ t1_t2_ticks get_t1_t2(void) { #endif tv.tv_sec -= systime_offset; - if (timers[T1_TIMER].run) - { - stop = (tv.tv_sec << 9); - stop += (tv.tv_usec / 15625) >> 3; - if (timers[T1_TIMER].start <= stop) - { - timers[T1_TIMER].value += stop - timers[T1_TIMER].start; - } else { + if (timers[T1_TIMER].run) { + stop = (tv.tv_sec << 9); + stop += (tv.tv_usec / 15625) >> 3; + if (timers[T1_TIMER].start <= stop) { + timers[T1_TIMER].value += stop - timers[T1_TIMER].start; + } else { fprintf(stderr, "clock running backwards\n"); } - } + } ticks.t1_ticks = timers[T1_TIMER].value; stop = tv.tv_sec; @@ -416,73 +408,27 @@ t1_t2_ticks get_t1_t2(void) { access_time = 0x0; - for (i = 13 - 1; i >= 0; i--) - { - access_time <<= 4; - access_time |= ((int)saturn.ram[accesstime_loc + i] & 0xf); - } + for (i = 13 - 1; i >= 0; i--) { + access_time <<= 4; + access_time |= ((int)saturn.ram[accesstime_loc + i] & 0xf); + } access_time -= stop; - if (adj_time_pending || in_debugger) - { - /* - * We have been inside an interrupt for very long, maybe - * or we are sleeping in the debugger. - * Don't adjust the time, can't come from user, anyhow. - */ + if (adj_time_pending || in_debugger) { + /* + * We have been inside an interrupt for very long, maybe + * or we are sleeping in the debugger. + * Don't adjust the time, can't come from user, anyhow. + */ - if ((saturn.timer2 >= 0 && access_time < 0) - || ((unsigned long)saturn.timer2 > access_time)) - { - /* - * check OK, return calculated time - */ - ticks.t2_ticks = access_time; - } - else - { - /* - * Don't increment timer2, return old value and - * slow down timer2. - */ - ticks.t2_ticks = saturn.timer2; - saturn.t2_tick++; - } - - return ticks; - } - - diff_time = saturn.timer2; - - adj_time = access_time - diff_time; - delta = abs(adj_time); - - if (delta > 0x3c000) /* Half a minute */ - { - set_0_time += adj_time; - time_offset += adj_time; - access_time -= adj_time; - -#ifdef DEBUG_TIMER_ADJUST - fprintf(stderr, "Time adjusted by "); - fprintf(stderr, "%lX", adj_time); - fprintf(stderr, " TICKS, Total offset "); - fprintf(stderr, "%lX", set_0_time); - fprintf(stderr, " TICKS\n"); -#endif - } - - if ((saturn.timer2 >= 0 && (access_time < 0)) - || ((unsigned long)saturn.timer2 > access_time)) - { + if ((saturn.timer2 >= 0 && access_time < 0) || + ((unsigned long)saturn.timer2 > access_time)) { /* * check OK, return calculated time */ ticks.t2_ticks = access_time; - } - else - { + } else { /* * Don't increment timer2, return old value and * slow down timer2. @@ -491,5 +437,43 @@ t1_t2_ticks get_t1_t2(void) { saturn.t2_tick++; } + return ticks; + } + + diff_time = saturn.timer2; + + adj_time = access_time - diff_time; + delta = abs(adj_time); + + if (delta > 0x3c000) /* Half a minute */ + { + set_0_time += adj_time; + time_offset += adj_time; + access_time -= adj_time; + +#ifdef DEBUG_TIMER_ADJUST + fprintf(stderr, "Time adjusted by "); + fprintf(stderr, "%lX", adj_time); + fprintf(stderr, " TICKS, Total offset "); + fprintf(stderr, "%lX", set_0_time); + fprintf(stderr, " TICKS\n"); +#endif + } + + if ((saturn.timer2 >= 0 && (access_time < 0)) || + ((unsigned long)saturn.timer2 > access_time)) { + /* + * check OK, return calculated time + */ + ticks.t2_ticks = access_time; + } else { + /* + * Don't increment timer2, return old value and + * slow down timer2. + */ + ticks.t2_ticks = saturn.timer2; + saturn.t2_tick++; + } + return ticks; } diff --git a/src/timer.h b/src/timer.h index b487daa..a906e2a 100644 --- a/src/timer.h +++ b/src/timer.h @@ -37,26 +37,26 @@ #include "global.h" #include "hp48.h" -#define NR_TIMERS 4 +#define NR_TIMERS 4 -#define T1_TIMER 0 -#define T2_TIMER 1 -#define RUN_TIMER 2 -#define IDLE_TIMER 3 +#define T1_TIMER 0 +#define T2_TIMER 1 +#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 __ProtoType__((int timer)); -extern void start_timer __ProtoType__((int timer)); -extern void restart_timer __ProtoType__((int timer)); -extern void stop_timer __ProtoType__((int timer)); -extern word_64 get_timer __ProtoType__((int timer)); -extern long diff_timer __ProtoType__((word_64 *t1, word_64 *t2)); +extern void reset_timer __ProtoType__((int timer)); +extern void start_timer __ProtoType__((int timer)); +extern void restart_timer __ProtoType__((int timer)); +extern void stop_timer __ProtoType__((int timer)); +extern word_64 get_timer __ProtoType__((int timer)); +extern long diff_timer __ProtoType__((word_64 * t1, word_64 *t2)); -extern t1_t2_ticks get_t1_t2 __ProtoType__((void)); -extern void set_accesstime __ProtoType__((void)); +extern t1_t2_ticks get_t1_t2 __ProtoType__((void)); +extern void set_accesstime __ProtoType__((void)); #endif /* !_TIMER_H */ diff --git a/src/version.h b/src/version.h index db6d47f..3f0c290 100644 --- a/src/version.h +++ b/src/version.h @@ -34,10 +34,10 @@ #ifndef _VERSION_H #define _VERSION_H 1 -extern int VERSION_MAJOR; -extern int VERSION_MINOR; -extern int PATCHLEVEL; -extern int COMPILE_VERSION; +extern int VERSION_MAJOR; +extern int VERSION_MINOR; +extern int PATCHLEVEL; +extern int COMPILE_VERSION; extern char *COMPILE_TIME; extern char *COMPILE_BY; diff --git a/src/x48_x11.c b/src/x48_x11.c index 3093b8d..2c25a9d 100644 --- a/src/x48_x11.c +++ b/src/x48_x11.c @@ -71,17 +71,16 @@ * $Id: x48_x11.c,v 1.13 1995/01/11 18:20:01 ecd Exp ecd $ */ - #include "global.h" -#include -#include -#include -#include -#include #include #include +#include +#include +#include +#include #include +#include #ifdef SYSV #include #endif @@ -90,588 +89,845 @@ #endif #include -#include -#include #include +#include +#include -#include "x48_x11.h" -#include "icon.h" -#include "small.h" #include "buttons.h" #include "hp.h" +#include "icon.h" +#include "small.h" +#include "x48_x11.h" -#include "hp48.h" -#include "device.h" #include "constants.h" +#include "device.h" +#include "errors.h" +#include "hp48.h" #include "options.h" #include "resources.h" -#include "errors.h" #include "romio.h" static char *defaults[] = { #include "X48.ad.h" - 0 -}; + 0}; #ifdef HAVE_XSHM extern int XShmQueryExtension __ProtoType__((Display *)); -extern int XShmGetEventBase __ProtoType__((Display *)); +extern int XShmGetEventBase __ProtoType__((Display *)); static int CompletionType = -1; #endif -extern int saved_argc; -extern char **saved_argv; +extern int saved_argc; +extern char **saved_argv; -Display *dpy; -int screen; -unsigned int depth; -Colormap cmap; -GC gc; -Window mainW; -Window iconW = 0; -disp_t disp; -Atom wm_delete_window, wm_save_yourself, wm_protocols; -Atom ol_decor_del, ol_decor_icon_name; -Atom atom_type; -Visual *visual; -Pixmap icon_pix; -Pixmap icon_text_pix; -Pixmap icon_disp_pix; -static int last_icon_state = -1; +Display *dpy; +int screen; +unsigned int depth; +Colormap cmap; +GC gc; +Window mainW; +Window iconW = 0; +disp_t disp; +Atom wm_delete_window, wm_save_yourself, wm_protocols; +Atom ol_decor_del, ol_decor_icon_name; +Atom atom_type; +Visual *visual; +Pixmap icon_pix; +Pixmap icon_text_pix; +Pixmap icon_disp_pix; +static int last_icon_state = -1; #ifdef HAVE_XSHM -int shm_flag; -int xerror_flag; +int shm_flag; +int xerror_flag; #endif -int dynamic_color; -int direct_color; -int does_backing_store; -int color_mode; -int icon_color_mode; +int dynamic_color; +int direct_color; +int does_backing_store; +int color_mode; +int icon_color_mode; #if 0 -# define DEBUG_XEVENT 1 -# define DEBUG_BUTTONS 1 -# define DEBUG_FOCUS 1 -# define DEBUG_BACKING_STORE 1 -# define DEBUG_SHM 1 +#define DEBUG_XEVENT 1 +#define DEBUG_BUTTONS 1 +#define DEBUG_FOCUS 1 +#define DEBUG_BACKING_STORE 1 +#define DEBUG_SHM 1 #endif typedef struct keypad_t { - unsigned int width; - unsigned int height; - Pixmap pixmap; + unsigned int width; + unsigned int height; + Pixmap pixmap; } keypad_t; -keypad_t keypad; -color_t *colors; +keypad_t keypad; +color_t *colors; color_t colors_sx[] = { - { "white", 255, 255, 255, 255, 255, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "left", 255, 166, 0, 255, 230, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "right", 0, 210, 255, 255, 169, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "but_top", 109, 93, 93, 0, 91, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "button", 90, 77, 77, 0, 81, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "but_bot", 76, 65, 65, 0, 69, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "lcd_col", 202, 221, 92, 255, 205, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "pix_col", 0, 0, 128, 0, 20, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "pad_top", 109, 78, 78, 0, 88, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "pad", 90, 64, 64, 0, 73, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "pad_bot", 76, 54, 54, 0, 60, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "disp_pad_top", 155, 118, 84, 0, 124, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "disp_pad", 124, 94, 67, 0, 99, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "disp_pad_bot", 100, 75, 53, 0, 79, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "logo", 204, 169, 107, 255, 172, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "logo_back", 64, 64, 64, 0, 65, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "label", 202, 184, 144, 255, 185, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "frame", 0, 0, 0, 255, 0, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "underlay", 60, 42, 42, 0, 48, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "black", 0, 0, 0, 0, 0, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { 0 } -}; + {"white", + 255, + 255, + 255, + 255, + 255, + {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"left", 255, 166, 0, 255, 230, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"right", 0, 210, 255, 255, 169, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"but_top", 109, 93, 93, 0, 91, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"button", 90, 77, 77, 0, 81, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"but_bot", 76, 65, 65, 0, 69, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"lcd_col", + 202, + 221, + 92, + 255, + 205, + {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"pix_col", 0, 0, 128, 0, 20, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"pad_top", 109, 78, 78, 0, 88, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"pad", 90, 64, 64, 0, 73, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"pad_bot", 76, 54, 54, 0, 60, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"disp_pad_top", + 155, + 118, + 84, + 0, + 124, + {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"disp_pad", 124, 94, 67, 0, 99, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"disp_pad_bot", + 100, + 75, + 53, + 0, + 79, + {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"logo", + 204, + 169, + 107, + 255, + 172, + {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"logo_back", 64, 64, 64, 0, 65, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"label", + 202, + 184, + 144, + 255, + 185, + {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"frame", 0, 0, 0, 255, 0, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"underlay", 60, 42, 42, 0, 48, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"black", 0, 0, 0, 0, 0, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {0}}; color_t colors_gx[] = { - { "white", 255, 255, 255, 255, 255, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "left", 255, 186, 255, 255, 220, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "right", 0, 255, 204, 255, 169, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "but_top", 104, 104, 104, 0, 104, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "button", 88, 88, 88, 0, 88, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "but_bot", 74, 74, 74, 0, 74, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "lcd_col", 202, 221, 92, 255, 205, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "pix_col", 0, 0, 128, 0, 20, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "pad_top", 88, 88, 88, 0, 88, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "pad", 74, 74, 74, 0, 74, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "pad_bot", 64, 64, 64, 0, 64, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "disp_pad_top", 128, 128, 138, 0, 128, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "disp_pad", 104, 104, 110, 0, 104, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "disp_pad_bot", 84, 84, 90, 0, 84, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "logo", 176, 176, 184, 255, 176, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "logo_back", 104, 104, 110, 0, 104, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "label", 240, 240, 240, 255, 240, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "frame", 0, 0, 0, 255, 0, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "underlay", 104, 104, 110, 0, 104, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { "black", 0, 0, 0, 0, 0, - { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } }, - { 0 } -}; + {"white", + 255, + 255, + 255, + 255, + 255, + {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"left", + 255, + 186, + 255, + 255, + 220, + {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"right", 0, 255, 204, 255, 169, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"but_top", + 104, + 104, + 104, + 0, + 104, + {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"button", 88, 88, 88, 0, 88, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"but_bot", 74, 74, 74, 0, 74, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"lcd_col", + 202, + 221, + 92, + 255, + 205, + {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"pix_col", 0, 0, 128, 0, 20, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"pad_top", 88, 88, 88, 0, 88, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"pad", 74, 74, 74, 0, 74, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"pad_bot", 64, 64, 64, 0, 64, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"disp_pad_top", + 128, + 128, + 138, + 0, + 128, + {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"disp_pad", + 104, + 104, + 110, + 0, + 104, + {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"disp_pad_bot", + 84, + 84, + 90, + 0, + 84, + {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"logo", + 176, + 176, + 184, + 255, + 176, + {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"logo_back", + 104, + 104, + 110, + 0, + 104, + {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"label", + 240, + 240, + 240, + 255, + 240, + {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"frame", 0, 0, 0, 255, 0, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"underlay", + 104, + 104, + 110, + 0, + 104, + {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {"black", 0, 0, 0, 0, 0, {0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0}}, + {0}}; typedef struct button_t { - char *name; - short pressed; - short extra; + char *name; + short pressed; + short extra; - int code; - int x, y; - unsigned int w, h; + int code; + int x, y; + unsigned int w, h; - int lc; - char *label; - short font_size; - unsigned int lw, lh; + int lc; + char *label; + short font_size; + unsigned int lw, lh; unsigned char *lb; - char *letter; + char *letter; - char *left; - short is_menu; - char *right; - char *sub; + char *left; + short is_menu; + char *right; + char *sub; - Pixmap map; - Pixmap down; - Window xwin; + Pixmap map; + Pixmap down; + Window xwin; } button_t; -#define BUTTON_A 0 -#define BUTTON_B 1 -#define BUTTON_C 2 -#define BUTTON_D 3 -#define BUTTON_E 4 -#define BUTTON_F 5 +#define BUTTON_A 0 +#define BUTTON_B 1 +#define BUTTON_C 2 +#define BUTTON_D 3 +#define BUTTON_E 4 +#define BUTTON_F 5 -#define BUTTON_MTH 6 -#define BUTTON_PRG 7 -#define BUTTON_CST 8 -#define BUTTON_VAR 9 -#define BUTTON_UP 10 -#define BUTTON_NXT 11 +#define BUTTON_MTH 6 +#define BUTTON_PRG 7 +#define BUTTON_CST 8 +#define BUTTON_VAR 9 +#define BUTTON_UP 10 +#define BUTTON_NXT 11 -#define BUTTON_COLON 12 -#define BUTTON_STO 13 -#define BUTTON_EVAL 14 -#define BUTTON_LEFT 15 -#define BUTTON_DOWN 16 -#define BUTTON_RIGHT 17 +#define BUTTON_COLON 12 +#define BUTTON_STO 13 +#define BUTTON_EVAL 14 +#define BUTTON_LEFT 15 +#define BUTTON_DOWN 16 +#define BUTTON_RIGHT 17 -#define BUTTON_SIN 18 -#define BUTTON_COS 19 -#define BUTTON_TAN 20 -#define BUTTON_SQRT 21 -#define BUTTON_POWER 22 -#define BUTTON_INV 23 +#define BUTTON_SIN 18 +#define BUTTON_COS 19 +#define BUTTON_TAN 20 +#define BUTTON_SQRT 21 +#define BUTTON_POWER 22 +#define BUTTON_INV 23 -#define BUTTON_ENTER 24 -#define BUTTON_NEG 25 -#define BUTTON_EEX 26 -#define BUTTON_DEL 27 -#define BUTTON_BS 28 +#define BUTTON_ENTER 24 +#define BUTTON_NEG 25 +#define BUTTON_EEX 26 +#define BUTTON_DEL 27 +#define BUTTON_BS 28 -#define BUTTON_ALPHA 29 -#define BUTTON_7 30 -#define BUTTON_8 31 -#define BUTTON_9 32 -#define BUTTON_DIV 33 +#define BUTTON_ALPHA 29 +#define BUTTON_7 30 +#define BUTTON_8 31 +#define BUTTON_9 32 +#define BUTTON_DIV 33 -#define BUTTON_SHL 34 -#define BUTTON_4 35 -#define BUTTON_5 36 -#define BUTTON_6 37 -#define BUTTON_MUL 38 +#define BUTTON_SHL 34 +#define BUTTON_4 35 +#define BUTTON_5 36 +#define BUTTON_6 37 +#define BUTTON_MUL 38 -#define BUTTON_SHR 39 -#define BUTTON_1 40 -#define BUTTON_2 41 -#define BUTTON_3 42 -#define BUTTON_MINUS 43 +#define BUTTON_SHR 39 +#define BUTTON_1 40 +#define BUTTON_2 41 +#define BUTTON_3 42 +#define BUTTON_MINUS 43 -#define BUTTON_ON 44 -#define BUTTON_0 45 -#define BUTTON_PERIOD 46 -#define BUTTON_SPC 47 -#define BUTTON_PLUS 48 +#define BUTTON_ON 44 +#define BUTTON_0 45 +#define BUTTON_PERIOD 46 +#define BUTTON_SPC 47 +#define BUTTON_PLUS 48 -#define LAST_BUTTON 48 +#define LAST_BUTTON 48 button_t *buttons; button_t buttons_sx[] = { - { "A", 0, 0, 0x14, 0, 0, 36, 23, WHITE, - 0, 0, menu_label_width, menu_label_height, menu_label_bits, - "A", 0, 0, 0, 0, 0 }, - { "B", 0, 0, 0x84, 50, 0, 36, 23, WHITE, - 0, 0, menu_label_width, menu_label_height, menu_label_bits, - "B", 0, 0, 0, 0, 0 }, - { "C", 0, 0, 0x83, 100, 0, 36, 23, WHITE, - 0, 0, menu_label_width, menu_label_height, menu_label_bits, - "C", 0, 0, 0, 0, 0 }, - { "D", 0, 0, 0x82, 150, 0, 36, 23, WHITE, - 0, 0, menu_label_width, menu_label_height, menu_label_bits, - "D", 0, 0, 0, 0, 0 }, - { "E", 0, 0, 0x81, 200, 0, 36, 23, WHITE, - 0, 0, menu_label_width, menu_label_height, menu_label_bits, - "E", 0, 0, 0, 0, 0 }, - { "F", 0, 0, 0x80, 250, 0, 36, 23, WHITE, - 0, 0, menu_label_width, menu_label_height, menu_label_bits, - "F", 0, 0, 0, 0, 0 }, + {"A", + 0, + 0, + 0x14, + 0, + 0, + 36, + 23, + WHITE, + 0, + 0, + menu_label_width, + menu_label_height, + menu_label_bits, + "A", + 0, + 0, + 0, + 0, + 0}, + {"B", + 0, + 0, + 0x84, + 50, + 0, + 36, + 23, + WHITE, + 0, + 0, + menu_label_width, + menu_label_height, + menu_label_bits, + "B", + 0, + 0, + 0, + 0, + 0}, + {"C", + 0, + 0, + 0x83, + 100, + 0, + 36, + 23, + WHITE, + 0, + 0, + menu_label_width, + menu_label_height, + menu_label_bits, + "C", + 0, + 0, + 0, + 0, + 0}, + {"D", + 0, + 0, + 0x82, + 150, + 0, + 36, + 23, + WHITE, + 0, + 0, + menu_label_width, + menu_label_height, + menu_label_bits, + "D", + 0, + 0, + 0, + 0, + 0}, + {"E", + 0, + 0, + 0x81, + 200, + 0, + 36, + 23, + WHITE, + 0, + 0, + menu_label_width, + menu_label_height, + menu_label_bits, + "E", + 0, + 0, + 0, + 0, + 0}, + {"F", + 0, + 0, + 0x80, + 250, + 0, + 36, + 23, + WHITE, + 0, + 0, + menu_label_width, + menu_label_height, + menu_label_bits, + "F", + 0, + 0, + 0, + 0, + 0}, - { "MTH", 0, 0, 0x24, 0, 50, 36, 26, WHITE, "MTH", 0, 0, 0, 0, - "G", "PRINT", 1, 0, 0, 0 }, - { "PRG", 0, 0, 0x74, 50, 50, 36, 26, WHITE, "PRG", 0, 0, 0, 0, - "H", "I/O", 1, 0, 0, 0 }, - { "CST", 0, 0, 0x73, 100, 50, 36, 26, WHITE, "CST", 0, 0, 0, 0, - "I", "MODES", 1, 0, 0, 0 }, - { "VAR", 0, 0, 0x72, 150, 50, 36, 26, WHITE, "VAR", 0, 0, 0, 0, - "J", "MEMORY", 1, 0, 0, 0 }, - { "UP", 0, 0, 0x71, 200, 50, 36, 26, WHITE, - 0, 0, up_width, up_height, up_bits, - "K", "LIBRARY", 1, 0, 0, 0 }, - { "NXT", 0, 0, 0x70, 250, 50, 36, 26, WHITE, "NXT", 0, 0, 0, 0, - "L", "PREV", 0, 0, 0, 0 }, + {"MTH", 0, 0, 0x24, 0, 50, 36, 26, WHITE, "MTH", + 0, 0, 0, 0, "G", "PRINT", 1, 0, 0, 0}, + {"PRG", 0, 0, 0x74, 50, 50, 36, 26, WHITE, "PRG", + 0, 0, 0, 0, "H", "I/O", 1, 0, 0, 0}, + {"CST", 0, 0, 0x73, 100, 50, 36, 26, WHITE, "CST", + 0, 0, 0, 0, "I", "MODES", 1, 0, 0, 0}, + {"VAR", 0, 0, 0x72, 150, 50, 36, 26, WHITE, "VAR", + 0, 0, 0, 0, "J", "MEMORY", 1, 0, 0, 0}, + {"UP", 0, 0, 0x71, 200, 50, 36, 26, WHITE, 0, + 0, up_width, up_height, up_bits, "K", "LIBRARY", 1, 0, 0, 0}, + {"NXT", 0, 0, 0x70, 250, 50, 36, 26, WHITE, "NXT", + 0, 0, 0, 0, "L", "PREV", 0, 0, 0, 0}, - { "COLON", 0, 0, 0x04, 0, 100, 36, 26, WHITE, - 0, 0, colon_width, colon_height, colon_bits, - "M", "UP", 0, "HOME", 0, 0 }, - { "STO", 0, 0, 0x64, 50, 100, 36, 26, WHITE, "STO", 0, 0, 0, 0, - "N", "DEF", 0, "RCL", 0, 0 }, - { "EVAL", 0, 0, 0x63, 100, 100, 36, 26, WHITE, "EVAL", 0, 0, 0, 0, - "O", "aQ", 0, "aNUM", 0, 0 }, - { "LEFT", 0, 0, 0x62, 150, 100, 36, 26, WHITE, - 0, 0, left_width, left_height, left_bits, - "P", "GRAPH", 0, 0, 0, 0 }, - { "DOWN", 0, 0, 0x61, 200, 100, 36, 26, WHITE, - 0, 0, down_width, down_height, down_bits, - "Q", "REVIEW", 0, 0, 0, 0 }, - { "RIGHT", 0, 0, 0x60, 250, 100, 36, 26, WHITE, - 0, 0, right_width, right_height, right_bits, - "R", "SWAP", 0, 0, 0, 0 }, + {"COLON", 0, 0, 0x04, 0, 100, 36, 26, WHITE, + 0, 0, colon_width, colon_height, colon_bits, "M", "UP", 0, "HOME", + 0, 0}, + {"STO", 0, 0, 0x64, 50, 100, 36, 26, WHITE, "STO", + 0, 0, 0, 0, "N", "DEF", 0, "RCL", 0, 0}, + {"EVAL", 0, 0, 0x63, 100, 100, 36, 26, WHITE, "EVAL", + 0, 0, 0, 0, "O", "aQ", 0, "aNUM", 0, 0}, + {"LEFT", 0, 0, 0x62, 150, 100, 36, 26, + WHITE, 0, 0, left_width, left_height, left_bits, "P", "GRAPH", + 0, 0, 0, 0}, + {"DOWN", 0, 0, 0x61, 200, 100, 36, 26, + WHITE, 0, 0, down_width, down_height, down_bits, "Q", "REVIEW", + 0, 0, 0, 0}, + {"RIGHT", 0, 0, 0x60, 250, 100, 36, 26, WHITE, + 0, 0, right_width, right_height, right_bits, "R", "SWAP", 0, 0, + 0, 0}, - { "SIN", 0, 0, 0x34, 0, 150, 36, 26, WHITE, "SIN", 0, 0, 0, 0, - "S", "ASIN", 0, "b", 0, 0 }, - { "COS", 0, 0, 0x54, 50, 150, 36, 26, WHITE, "COS", 0, 0, 0, 0, - "T", "ACOS", 0, "c", 0, 0 }, - { "TAN", 0, 0, 0x53, 100, 150, 36, 26, WHITE, "TAN", 0, 0, 0, 0, - "U", "ATAN", 0, "d", 0, 0 }, - { "SQRT", 0, 0, 0x52, 150, 150, 36, 26, WHITE, - 0, 0, sqrt_width, sqrt_height, sqrt_bits, - "V", "e", 0, "f", 0, 0 }, - { "POWER", 0, 0, 0x51, 200, 150, 36, 26, WHITE, - 0, 0, power_width, power_height, power_bits, - "W", "g", 0, "LOG", 0, 0 }, - { "INV", 0, 0, 0x50, 250, 150, 36, 26, WHITE, - 0, 0, inv_width, inv_height, inv_bits, - "X", "h", 0, "LN", 0, 0 }, + {"SIN", 0, 0, 0x34, 0, 150, 36, 26, WHITE, "SIN", + 0, 0, 0, 0, "S", "ASIN", 0, "b", 0, 0}, + {"COS", 0, 0, 0x54, 50, 150, 36, 26, WHITE, "COS", + 0, 0, 0, 0, "T", "ACOS", 0, "c", 0, 0}, + {"TAN", 0, 0, 0x53, 100, 150, 36, 26, WHITE, "TAN", + 0, 0, 0, 0, "U", "ATAN", 0, "d", 0, 0}, + {"SQRT", 0, 0, 0x52, 150, 150, 36, 26, WHITE, 0, + 0, sqrt_width, sqrt_height, sqrt_bits, "V", "e", 0, "f", 0, 0}, + {"POWER", 0, 0, 0x51, 200, 150, 36, 26, WHITE, + 0, 0, power_width, power_height, power_bits, "W", "g", 0, "LOG", + 0, 0}, + {"INV", 0, 0, 0x50, 250, 150, 36, 26, WHITE, 0, + 0, inv_width, inv_height, inv_bits, "X", "h", 0, "LN", 0, 0}, - { "ENTER", 0, 0, 0x44, 0, 200, 86, 26, WHITE, "ENTER", 2, 0, 0, 0, - 0, "EQUATION", 0, "MATRIX", 0, 0 }, - { "NEG", 0, 0, 0x43, 100, 200, 36, 26, WHITE, - 0, 0, neg_width, neg_height, neg_bits, - "Y", "EDIT", 0, "VISIT", 0, 0 }, - { "EEX", 0, 0, 0x42, 150, 200, 36, 26, WHITE, "EEX", 0, 0, 0, 0, - "Z", "2D", 0, "3D", 0, 0 }, - { "DEL", 0, 0, 0x41, 200, 200, 36, 26, WHITE, "DEL", 0, 0, 0, 0, - 0, "PURGE", 0, 0, 0, 0 }, - { "BS", 0, 0, 0x40, 250, 200, 36, 26, WHITE, - 0, 0, bs_width, bs_height, bs_bits, - 0, "DROP", 0, "CLR", 0, 0 }, + {"ENTER", 0, 0, 0x44, 0, 200, 86, 26, WHITE, "ENTER", + 2, 0, 0, 0, 0, "EQUATION", 0, "MATRIX", 0, 0}, + {"NEG", 0, 0, 0x43, 100, 200, 36, + 26, WHITE, 0, 0, neg_width, neg_height, neg_bits, + "Y", "EDIT", 0, "VISIT", 0, 0}, + {"EEX", 0, 0, 0x42, 150, 200, 36, 26, WHITE, "EEX", + 0, 0, 0, 0, "Z", "2D", 0, "3D", 0, 0}, + {"DEL", 0, 0, 0x41, 200, 200, 36, 26, WHITE, "DEL", + 0, 0, 0, 0, 0, "PURGE", 0, 0, 0, 0}, + {"BS", 0, 0, 0x40, 250, 200, 36, 26, WHITE, 0, + 0, bs_width, bs_height, bs_bits, 0, "DROP", 0, "CLR", 0, 0}, - { "ALPHA", 0, 0, 0x35, 0, 250, 36, 26, WHITE, - 0, 0, alpha_width, alpha_height, alpha_bits, - 0, "USR", 0, "ENTRY", 0, 0 }, - { "7", 0, 0, 0x33, 60, 250, 46, 26, WHITE, "7", 1, 0, 0, 0, - 0, "SOLVE", 1, 0, 0, 0 }, - { "8", 0, 0, 0x32, 120, 250, 46, 26, WHITE, "8", 1, 0, 0, 0, - 0, "PLOT", 1, 0, 0, 0 }, - { "9", 0, 0, 0x31, 180, 250, 46, 26, WHITE, "9", 1, 0, 0, 0, - 0, "ALGEBRA", 1, 0, 0, 0 }, - { "DIV", 0, 0, 0x30, 240, 250, 46, 26, WHITE, - 0, 0, div_width, div_height, div_bits, - 0, "( )", 0, "#", 0, 0 }, + {"ALPHA", 0, 0, 0x35, 0, 250, 36, 26, WHITE, + 0, 0, alpha_width, alpha_height, alpha_bits, 0, "USR", 0, "ENTRY", + 0, 0}, + {"7", 0, 0, 0x33, 60, 250, 46, 26, WHITE, "7", + 1, 0, 0, 0, 0, "SOLVE", 1, 0, 0, 0}, + {"8", 0, 0, 0x32, 120, 250, 46, 26, WHITE, "8", + 1, 0, 0, 0, 0, "PLOT", 1, 0, 0, 0}, + {"9", 0, 0, 0x31, 180, 250, 46, 26, WHITE, "9", + 1, 0, 0, 0, 0, "ALGEBRA", 1, 0, 0, 0}, + {"DIV", 0, 0, 0x30, 240, 250, 46, 26, WHITE, 0, + 0, div_width, div_height, div_bits, 0, "( )", 0, "#", 0, 0}, - { "SHL", 0, 0, 0x25, 0, 300, 36, 26, LEFT, - 0, 0, shl_width, shl_height, shl_bits, - 0, 0, 0, 0, 0, 0 }, - { "4", 0, 0, 0x23, 60, 300, 46, 26, WHITE, "4", 1, 0, 0, 0, - 0, "TIME", 1, 0, 0, 0 }, - { "5", 0, 0, 0x22, 120, 300, 46, 26, WHITE, "5", 1, 0, 0, 0, - 0, "STAT", 1, 0, 0, 0 }, - { "6", 0, 0, 0x21, 180, 300, 46, 26, WHITE, "6", 1, 0, 0, 0, - 0, "UNITS", 1, 0, 0, 0 }, - { "MUL", 0, 0, 0x20, 240, 300, 46, 26, WHITE, - 0, 0, mul_width, mul_height, mul_bits, - 0, "[ ]", 0, "_", 0, 0 }, + {"SHL", 0, 0, 0x25, 0, 300, 36, 26, LEFT, 0, + 0, shl_width, shl_height, shl_bits, 0, 0, 0, 0, 0, 0}, + {"4", 0, 0, 0x23, 60, 300, 46, 26, WHITE, "4", + 1, 0, 0, 0, 0, "TIME", 1, 0, 0, 0}, + {"5", 0, 0, 0x22, 120, 300, 46, 26, WHITE, "5", + 1, 0, 0, 0, 0, "STAT", 1, 0, 0, 0}, + {"6", 0, 0, 0x21, 180, 300, 46, 26, WHITE, "6", + 1, 0, 0, 0, 0, "UNITS", 1, 0, 0, 0}, + {"MUL", 0, 0, 0x20, 240, 300, 46, 26, WHITE, 0, + 0, mul_width, mul_height, mul_bits, 0, "[ ]", 0, "_", 0, 0}, - { "SHR", 0, 0, 0x15, 0, 350, 36, 26, RIGHT, - 0, 0, shr_width, shr_height, shr_bits, - 0, 0, 0, 0, 0, 0 }, - { "1", 0, 0, 0x13, 60, 350, 46, 26, WHITE, "1", 1, 0, 0, 0, - 0, "RAD", 0, "POLAR", 0, 0 }, - { "2", 0, 0, 0x12, 120, 350, 46, 26, WHITE, "2", 1, 0, 0, 0, - 0, "STACK", 0, "ARG", 0, 0 }, - { "3", 0, 0, 0x11, 180, 350, 46, 26, WHITE, "3", 1, 0, 0, 0, - 0, "CMD", 0, "MENU", 0, 0 }, - { "MINUS", 0, 0, 0x10, 240, 350, 46, 26, WHITE, - 0, 0, minus_width, minus_height, minus_bits, - 0, "i", 0, "j", 0, 0 }, + {"SHR", 0, 0, 0x15, 0, 350, 36, 26, RIGHT, 0, + 0, shr_width, shr_height, shr_bits, 0, 0, 0, 0, 0, 0}, + {"1", 0, 0, 0x13, 60, 350, 46, 26, WHITE, "1", + 1, 0, 0, 0, 0, "RAD", 0, "POLAR", 0, 0}, + {"2", 0, 0, 0x12, 120, 350, 46, 26, WHITE, "2", + 1, 0, 0, 0, 0, "STACK", 0, "ARG", 0, 0}, + {"3", 0, 0, 0x11, 180, 350, 46, 26, WHITE, "3", + 1, 0, 0, 0, 0, "CMD", 0, "MENU", 0, 0}, + {"MINUS", 0, 0, 0x10, 240, 350, 46, 26, WHITE, + 0, 0, minus_width, minus_height, minus_bits, 0, "i", 0, "j", + 0, 0}, - { "ON", 0, 0, 0x8000, 0, 400, 36, 26, WHITE, "ON", 0, 0, 0, 0, - 0, "CONT", 0, "OFF", "ATTN", 0 }, - { "0", 0, 0, 0x03, 60, 400, 46, 26, WHITE, "0", 1, 0, 0, 0, - 0, "= ", 0, " a", 0, 0 }, - { "PERIOD", 0, 0, 0x02, 120, 400, 46, 26, WHITE, ".", 1, 0, 0, 0, - 0, ", ", 0, " k", 0, 0 }, - { "SPC", 0, 0, 0x01, 180, 400, 46, 26, WHITE, "SPC", 0, 0, 0, 0, - 0, "l ", 0, " m", 0, 0 }, - { "PLUS", 0, 0, 0x00, 240, 400, 46, 26, WHITE, - 0, 0, plus_width, plus_height, plus_bits, - 0, "{ }", 0, ": :", 0, 0 }, + {"ON", 0, 0, 0x8000, 0, 400, 36, 26, WHITE, "ON", + 0, 0, 0, 0, 0, "CONT", 0, "OFF", "ATTN", 0}, + {"0", 0, 0, 0x03, 60, 400, 46, 26, WHITE, "0", + 1, 0, 0, 0, 0, "= ", 0, " a", 0, 0}, + {"PERIOD", 0, 0, 0x02, 120, 400, 46, 26, WHITE, ".", + 1, 0, 0, 0, 0, ", ", 0, " k", 0, 0}, + {"SPC", 0, 0, 0x01, 180, 400, 46, 26, WHITE, "SPC", + 0, 0, 0, 0, 0, "l ", 0, " m", 0, 0}, + {"PLUS", 0, 0, 0x00, 240, 400, 46, 26, + WHITE, 0, 0, plus_width, plus_height, plus_bits, 0, "{ }", + 0, ": :", 0, 0}, - { 0 } -}; + {0}}; button_t buttons_gx[] = { - { "A", 0, 0, 0x14, 0, 0, 36, 23, WHITE, - 0, 0, menu_label_width, menu_label_height, menu_label_bits, - "A", 0, 0, 0, 0, 0 }, - { "B", 0, 0, 0x84, 50, 0, 36, 23, WHITE, - 0, 0, menu_label_width, menu_label_height, menu_label_bits, - "B", 0, 0, 0, 0, 0 }, - { "C", 0, 0, 0x83, 100, 0, 36, 23, WHITE, - 0, 0, menu_label_width, menu_label_height, menu_label_bits, - "C", 0, 0, 0, 0, 0 }, - { "D", 0, 0, 0x82, 150, 0, 36, 23, WHITE, - 0, 0, menu_label_width, menu_label_height, menu_label_bits, - "D", 0, 0, 0, 0, 0 }, - { "E", 0, 0, 0x81, 200, 0, 36, 23, WHITE, - 0, 0, menu_label_width, menu_label_height, menu_label_bits, - "E", 0, 0, 0, 0, 0 }, - { "F", 0, 0, 0x80, 250, 0, 36, 23, WHITE, - 0, 0, menu_label_width, menu_label_height, menu_label_bits, - "F", 0, 0, 0, 0, 0 }, + {"A", + 0, + 0, + 0x14, + 0, + 0, + 36, + 23, + WHITE, + 0, + 0, + menu_label_width, + menu_label_height, + menu_label_bits, + "A", + 0, + 0, + 0, + 0, + 0}, + {"B", + 0, + 0, + 0x84, + 50, + 0, + 36, + 23, + WHITE, + 0, + 0, + menu_label_width, + menu_label_height, + menu_label_bits, + "B", + 0, + 0, + 0, + 0, + 0}, + {"C", + 0, + 0, + 0x83, + 100, + 0, + 36, + 23, + WHITE, + 0, + 0, + menu_label_width, + menu_label_height, + menu_label_bits, + "C", + 0, + 0, + 0, + 0, + 0}, + {"D", + 0, + 0, + 0x82, + 150, + 0, + 36, + 23, + WHITE, + 0, + 0, + menu_label_width, + menu_label_height, + menu_label_bits, + "D", + 0, + 0, + 0, + 0, + 0}, + {"E", + 0, + 0, + 0x81, + 200, + 0, + 36, + 23, + WHITE, + 0, + 0, + menu_label_width, + menu_label_height, + menu_label_bits, + "E", + 0, + 0, + 0, + 0, + 0}, + {"F", + 0, + 0, + 0x80, + 250, + 0, + 36, + 23, + WHITE, + 0, + 0, + menu_label_width, + menu_label_height, + menu_label_bits, + "F", + 0, + 0, + 0, + 0, + 0}, - { "MTH", 0, 0, 0x24, 0, 50, 36, 26, WHITE, "MTH", 0, 0, 0, 0, - "G", "RAD", 0, "POLAR", 0, 0 }, - { "PRG", 0, 0, 0x74, 50, 50, 36, 26, WHITE, "PRG", 0, 0, 0, 0, - "H", 0, 0, "CHARS", 0, 0 }, - { "CST", 0, 0, 0x73, 100, 50, 36, 26, WHITE, "CST", 0, 0, 0, 0, - "I", 0, 0, "MODES", 0, 0 }, - { "VAR", 0, 0, 0x72, 150, 50, 36, 26, WHITE, "VAR", 0, 0, 0, 0, - "J", 0, 0, "MEMORY", 0, 0 }, - { "UP", 0, 0, 0x71, 200, 50, 36, 26, WHITE, - 0, 0, up_width, up_height, up_bits, - "K", 0, 0, "STACK", 0, 0 }, - { "NXT", 0, 0, 0x70, 250, 50, 36, 26, WHITE, "NXT", 0, 0, 0, 0, - "L", "PREV", 0, "MENU", 0, 0 }, + {"MTH", 0, 0, 0x24, 0, 50, 36, 26, WHITE, "MTH", + 0, 0, 0, 0, "G", "RAD", 0, "POLAR", 0, 0}, + {"PRG", 0, 0, 0x74, 50, 50, 36, 26, WHITE, "PRG", + 0, 0, 0, 0, "H", 0, 0, "CHARS", 0, 0}, + {"CST", 0, 0, 0x73, 100, 50, 36, 26, WHITE, "CST", + 0, 0, 0, 0, "I", 0, 0, "MODES", 0, 0}, + {"VAR", 0, 0, 0x72, 150, 50, 36, 26, WHITE, "VAR", + 0, 0, 0, 0, "J", 0, 0, "MEMORY", 0, 0}, + {"UP", 0, 0, 0x71, 200, 50, 36, 26, WHITE, 0, + 0, up_width, up_height, up_bits, "K", 0, 0, "STACK", 0, 0}, + {"NXT", 0, 0, 0x70, 250, 50, 36, 26, WHITE, "NXT", + 0, 0, 0, 0, "L", "PREV", 0, "MENU", 0, 0}, - { "COLON", 0, 0, 0x04, 0, 100, 36, 26, WHITE, - 0, 0, colon_width, colon_height, colon_bits, - "M", "UP", 0, "HOME", 0, 0 }, - { "STO", 0, 0, 0x64, 50, 100, 36, 26, WHITE, "STO", 0, 0, 0, 0, - "N", "DEF", 0, "RCL", 0, 0 }, - { "EVAL", 0, 0, 0x63, 100, 100, 36, 26, WHITE, "EVAL", 0, 0, 0, 0, - "O", "aNUM", 0, "UNDO", 0, 0 }, - { "LEFT", 0, 0, 0x62, 150, 100, 36, 26, WHITE, - 0, 0, left_width, left_height, left_bits, - "P", "PICTURE", 0, 0, 0, 0 }, - { "DOWN", 0, 0, 0x61, 200, 100, 36, 26, WHITE, - 0, 0, down_width, down_height, down_bits, - "Q", "VIEW", 0, 0, 0, 0 }, - { "RIGHT", 0, 0, 0x60, 250, 100, 36, 26, WHITE, - 0, 0, right_width, right_height, right_bits, - "R", "SWAP", 0, 0, 0, 0 }, + {"COLON", 0, 0, 0x04, 0, 100, 36, 26, WHITE, + 0, 0, colon_width, colon_height, colon_bits, "M", "UP", 0, "HOME", + 0, 0}, + {"STO", 0, 0, 0x64, 50, 100, 36, 26, WHITE, "STO", + 0, 0, 0, 0, "N", "DEF", 0, "RCL", 0, 0}, + {"EVAL", 0, 0, 0x63, 100, 100, 36, 26, WHITE, "EVAL", + 0, 0, 0, 0, "O", "aNUM", 0, "UNDO", 0, 0}, + {"LEFT", 0, 0, 0x62, 150, 100, 36, 26, + WHITE, 0, 0, left_width, left_height, left_bits, "P", "PICTURE", + 0, 0, 0, 0}, + {"DOWN", 0, 0, 0x61, 200, 100, 36, 26, WHITE, 0, + 0, down_width, down_height, down_bits, "Q", "VIEW", 0, 0, 0, 0}, + {"RIGHT", 0, 0, 0x60, 250, 100, 36, 26, WHITE, + 0, 0, right_width, right_height, right_bits, "R", "SWAP", 0, 0, + 0, 0}, - { "SIN", 0, 0, 0x34, 0, 150, 36, 26, WHITE, "SIN", 0, 0, 0, 0, - "S", "ASIN", 0, "b", 0, 0 }, - { "COS", 0, 0, 0x54, 50, 150, 36, 26, WHITE, "COS", 0, 0, 0, 0, - "T", "ACOS", 0, "c", 0, 0 }, - { "TAN", 0, 0, 0x53, 100, 150, 36, 26, WHITE, "TAN", 0, 0, 0, 0, - "U", "ATAN", 0, "d", 0, 0 }, - { "SQRT", 0, 0, 0x52, 150, 150, 36, 26, WHITE, - 0, 0, sqrt_width, sqrt_height, sqrt_bits, - "V", "n", 0, "o", 0, 0 }, - { "POWER", 0, 0, 0x51, 200, 150, 36, 26, WHITE, - 0, 0, power_width, power_height, power_bits, - "W", "p", 0, "LOG", 0, 0 }, - { "INV", 0, 0, 0x50, 250, 150, 36, 26, WHITE, - 0, 0, inv_width, inv_height, inv_bits, - "X", "q", 0, "LN", 0, 0 }, + {"SIN", 0, 0, 0x34, 0, 150, 36, 26, WHITE, "SIN", + 0, 0, 0, 0, "S", "ASIN", 0, "b", 0, 0}, + {"COS", 0, 0, 0x54, 50, 150, 36, 26, WHITE, "COS", + 0, 0, 0, 0, "T", "ACOS", 0, "c", 0, 0}, + {"TAN", 0, 0, 0x53, 100, 150, 36, 26, WHITE, "TAN", + 0, 0, 0, 0, "U", "ATAN", 0, "d", 0, 0}, + {"SQRT", 0, 0, 0x52, 150, 150, 36, 26, WHITE, 0, + 0, sqrt_width, sqrt_height, sqrt_bits, "V", "n", 0, "o", 0, 0}, + {"POWER", 0, 0, 0x51, 200, 150, 36, 26, WHITE, + 0, 0, power_width, power_height, power_bits, "W", "p", 0, "LOG", + 0, 0}, + {"INV", 0, 0, 0x50, 250, 150, 36, 26, WHITE, 0, + 0, inv_width, inv_height, inv_bits, "X", "q", 0, "LN", 0, 0}, - { "ENTER", 0, 0, 0x44, 0, 200, 86, 26, WHITE, "ENTER", 2, 0, 0, 0, - 0, "EQUATION", 0, "MATRIX", 0, 0 }, - { "NEG", 0, 0, 0x43, 100, 200, 36, 26, WHITE, - 0, 0, neg_width, neg_height, neg_bits, - "Y", "EDIT", 0, "CMD", 0, 0 }, - { "EEX", 0, 0, 0x42, 150, 200, 36, 26, WHITE, "EEX", 0, 0, 0, 0, - "Z", "PURG", 0, "ARG", 0, 0 }, - { "DEL", 0, 0, 0x41, 200, 200, 36, 26, WHITE, "DEL", 0, 0, 0, 0, - 0, "CLEAR", 0, 0, 0, 0 }, - { "BS", 0, 0, 0x40, 250, 200, 36, 26, WHITE, - 0, 0, bs_width, bs_height, bs_bits, - 0, "DROP", 0, 0, 0, 0 }, + {"ENTER", 0, 0, 0x44, 0, 200, 86, 26, WHITE, "ENTER", + 2, 0, 0, 0, 0, "EQUATION", 0, "MATRIX", 0, 0}, + {"NEG", 0, 0, 0x43, 100, 200, 36, 26, WHITE, 0, + 0, neg_width, neg_height, neg_bits, "Y", "EDIT", 0, "CMD", 0, 0}, + {"EEX", 0, 0, 0x42, 150, 200, 36, 26, WHITE, "EEX", + 0, 0, 0, 0, "Z", "PURG", 0, "ARG", 0, 0}, + {"DEL", 0, 0, 0x41, 200, 200, 36, 26, WHITE, "DEL", + 0, 0, 0, 0, 0, "CLEAR", 0, 0, 0, 0}, + {"BS", 0, 0, 0x40, 250, 200, 36, 26, WHITE, 0, + 0, bs_width, bs_height, bs_bits, 0, "DROP", 0, 0, 0, 0}, - { "ALPHA", 0, 0, 0x35, 0, 250, 36, 26, WHITE, - 0, 0, alpha_width, alpha_height, alpha_bits, - 0, "USER", 0, "ENTRY", 0, 0 }, - { "7", 0, 0, 0x33, 60, 250, 46, 26, WHITE, "7", 1, 0, 0, 0, - 0, 0, 1, "SOLVE", 0, 0 }, - { "8", 0, 0, 0x32, 120, 250, 46, 26, WHITE, "8", 1, 0, 0, 0, - 0, 0, 1, "PLOT", 0, 0 }, - { "9", 0, 0, 0x31, 180, 250, 46, 26, WHITE, "9", 1, 0, 0, 0, - 0, 0, 1, "SYMBOLIC", 0, 0 }, - { "DIV", 0, 0, 0x30, 240, 250, 46, 26, WHITE, - 0, 0, div_width, div_height, div_bits, - 0, "r ", 0, "s", 0, 0 }, + {"ALPHA", + 0, + 0, + 0x35, + 0, + 250, + 36, + 26, + WHITE, + 0, + 0, + alpha_width, + alpha_height, + alpha_bits, + 0, + "USER", + 0, + "ENTRY", + 0, + 0}, + {"7", 0, 0, 0x33, 60, 250, 46, 26, WHITE, "7", + 1, 0, 0, 0, 0, 0, 1, "SOLVE", 0, 0}, + {"8", 0, 0, 0x32, 120, 250, 46, 26, WHITE, "8", + 1, 0, 0, 0, 0, 0, 1, "PLOT", 0, 0}, + {"9", 0, 0, 0x31, 180, 250, 46, 26, WHITE, "9", + 1, 0, 0, 0, 0, 0, 1, "SYMBOLIC", 0, 0}, + {"DIV", 0, 0, 0x30, 240, 250, 46, 26, WHITE, 0, + 0, div_width, div_height, div_bits, 0, "r ", 0, "s", 0, 0}, - { "SHL", 0, 0, 0x25, 0, 300, 36, 26, LEFT, - 0, 0, shl_width, shl_height, shl_bits, - 0, 0, 0, 0, 0, 0 }, - { "4", 0, 0, 0x23, 60, 300, 46, 26, WHITE, "4", 1, 0, 0, 0, - 0, 0, 1, "TIME", 0, 0 }, - { "5", 0, 0, 0x22, 120, 300, 46, 26, WHITE, "5", 1, 0, 0, 0, - 0, 0, 1, "STAT", 0, 0 }, - { "6", 0, 0, 0x21, 180, 300, 46, 26, WHITE, "6", 1, 0, 0, 0, - 0, 0, 1, "UNITS", 0, 0 }, - { "MUL", 0, 0, 0x20, 240, 300, 46, 26, WHITE, - 0, 0, mul_width, mul_height, mul_bits, - 0, "t ", 0, "u", 0, 0 }, + {"SHL", 0, 0, 0x25, 0, 300, 36, 26, LEFT, 0, + 0, shl_width, shl_height, shl_bits, 0, 0, 0, 0, 0, 0}, + {"4", 0, 0, 0x23, 60, 300, 46, 26, WHITE, "4", + 1, 0, 0, 0, 0, 0, 1, "TIME", 0, 0}, + {"5", 0, 0, 0x22, 120, 300, 46, 26, WHITE, "5", + 1, 0, 0, 0, 0, 0, 1, "STAT", 0, 0}, + {"6", 0, 0, 0x21, 180, 300, 46, 26, WHITE, "6", + 1, 0, 0, 0, 0, 0, 1, "UNITS", 0, 0}, + {"MUL", 0, 0, 0x20, 240, 300, 46, 26, WHITE, 0, + 0, mul_width, mul_height, mul_bits, 0, "t ", 0, "u", 0, 0}, - { "SHR", 0, 0, 0x15, 0, 350, 36, 26, RIGHT, - 0, 0, shr_width, shr_height, shr_bits, - 0, 0, 1, " ", 0, 0 }, - { "1", 0, 0, 0x13, 60, 350, 46, 26, WHITE, "1", 1, 0, 0, 0, - 0, 0, 1, "I/O", 0, 0 }, - { "2", 0, 0, 0x12, 120, 350, 46, 26, WHITE, "2", 1, 0, 0, 0, - 0, 0, 1, "LIBRARY", 0, 0 }, - { "3", 0, 0, 0x11, 180, 350, 46, 26, WHITE, "3", 1, 0, 0, 0, - 0, 0, 1, "EQ LIB", 0, 0 }, - { "MINUS", 0, 0, 0x10, 240, 350, 46, 26, WHITE, - 0, 0, minus_width, minus_height, minus_bits, - 0, "v ", 0, "w", 0, 0 }, + {"SHR", 0, 0, 0x15, 0, 350, 36, 26, RIGHT, 0, + 0, shr_width, shr_height, shr_bits, 0, 0, 1, " ", 0, 0}, + {"1", 0, 0, 0x13, 60, 350, 46, 26, WHITE, "1", + 1, 0, 0, 0, 0, 0, 1, "I/O", 0, 0}, + {"2", 0, 0, 0x12, 120, 350, 46, 26, WHITE, "2", + 1, 0, 0, 0, 0, 0, 1, "LIBRARY", 0, 0}, + {"3", 0, 0, 0x11, 180, 350, 46, 26, WHITE, "3", + 1, 0, 0, 0, 0, 0, 1, "EQ LIB", 0, 0}, + {"MINUS", 0, 0, 0x10, 240, 350, 46, 26, WHITE, + 0, 0, minus_width, minus_height, minus_bits, 0, "v ", 0, "w", + 0, 0}, - { "ON", 0, 0, 0x8000, 0, 400, 36, 26, WHITE, "ON", 0, 0, 0, 0, - 0, "CONT", 0, "OFF", "CANCEL", 0 }, - { "0", 0, 0, 0x03, 60, 400, 46, 26, WHITE, "0", 1, 0, 0, 0, - 0, "\004 ", 0, "\003", 0, 0 }, - { "PERIOD", 0, 0, 0x02, 120, 400, 46, 26, WHITE, ".", 1, 0, 0, 0, - 0, "\002 ", 0, "\001", 0, 0 }, - { "SPC", 0, 0, 0x01, 180, 400, 46, 26, WHITE, "SPC", 0, 0, 0, 0, - 0, "\005 ", 0, "z", 0, 0 }, - { "PLUS", 0, 0, 0x00, 240, 400, 46, 26, WHITE, - 0, 0, plus_width, plus_height, plus_bits, - 0, "x ", 0, "y", 0, 0 }, + {"ON", 0, 0, 0x8000, 0, 400, 36, 26, WHITE, "ON", + 0, 0, 0, 0, 0, "CONT", 0, "OFF", "CANCEL", 0}, + {"0", 0, 0, 0x03, 60, 400, 46, 26, WHITE, "0", + 1, 0, 0, 0, 0, "\004 ", 0, "\003", 0, 0}, + {"PERIOD", 0, 0, 0x02, 120, 400, 46, 26, WHITE, ".", + 1, 0, 0, 0, 0, "\002 ", 0, "\001", 0, 0}, + {"SPC", 0, 0, 0x01, 180, 400, 46, 26, WHITE, "SPC", + 0, 0, 0, 0, 0, "\005 ", 0, "z", 0, 0}, + {"PLUS", 0, 0, 0x00, 240, 400, 46, 26, WHITE, 0, + 0, plus_width, plus_height, plus_bits, 0, "x ", 0, "y", 0, 0}, - { 0 } -}; + {0}}; typedef struct icon_t { - unsigned int w; - unsigned int h; - int c; + unsigned int w; + unsigned int h; + int c; unsigned char *bits; } icon_map_t; -#define ICON_MAP 0 -#define ON_MAP 1 -#define DISP_MAP 2 +#define ICON_MAP 0 +#define ON_MAP 1 +#define DISP_MAP 2 #define FIRST_MAP 3 -#define LAST_MAP 9 +#define LAST_MAP 9 icon_map_t *icon_maps; icon_map_t icon_maps_sx[] = { - { hp48_icon_width, hp48_icon_height, BLACK, hp48_icon_bits }, - { hp48_on_width, hp48_on_height, PIXEL, hp48_on_bits }, - { hp48_disp_width, hp48_disp_height, LCD, hp48_disp_bits }, - { hp48_top_width, hp48_top_height, DISP_PAD, hp48_top_bits }, - { hp48_bottom_width, hp48_bottom_height, PAD, hp48_bottom_bits }, - { hp48_logo_width, hp48_logo_height, LOGO, hp48_logo_bits }, - { hp48_text_width, hp48_text_height, LABEL, hp48_text_bits }, - { hp48_keys_width, hp48_keys_height, BLACK, hp48_keys_bits }, - { hp48_orange_width, hp48_orange_height, LEFT, hp48_orange_bits }, - { hp48_blue_width, hp48_blue_height, RIGHT, hp48_blue_bits } -}; + {hp48_icon_width, hp48_icon_height, BLACK, hp48_icon_bits}, + {hp48_on_width, hp48_on_height, PIXEL, hp48_on_bits}, + {hp48_disp_width, hp48_disp_height, LCD, hp48_disp_bits}, + {hp48_top_width, hp48_top_height, DISP_PAD, hp48_top_bits}, + {hp48_bottom_width, hp48_bottom_height, PAD, hp48_bottom_bits}, + {hp48_logo_width, hp48_logo_height, LOGO, hp48_logo_bits}, + {hp48_text_width, hp48_text_height, LABEL, hp48_text_bits}, + {hp48_keys_width, hp48_keys_height, BLACK, hp48_keys_bits}, + {hp48_orange_width, hp48_orange_height, LEFT, hp48_orange_bits}, + {hp48_blue_width, hp48_blue_height, RIGHT, hp48_blue_bits}}; icon_map_t icon_maps_gx[] = { - { hp48_icon_width, hp48_icon_height, BLACK, hp48_icon_bits }, - { hp48_on_width, hp48_on_height, PIXEL, hp48_on_bits }, - { hp48_disp_width, hp48_disp_height, LCD, hp48_disp_bits }, - { hp48_top_gx_width, hp48_top_gx_height, DISP_PAD, hp48_top_gx_bits }, - { hp48_bottom_width, hp48_bottom_height, PAD, hp48_bottom_bits }, - { hp48_logo_gx_width, hp48_logo_gx_height, LOGO, hp48_logo_gx_bits }, - { hp48_text_gx_width, hp48_text_gx_height, LABEL, hp48_text_gx_bits }, - { hp48_keys_width, hp48_keys_height, BLACK, hp48_keys_bits }, - { hp48_orange_width, hp48_orange_height, LEFT, hp48_orange_bits }, - { hp48_green_gx_width, hp48_green_gx_height, RIGHT, hp48_green_gx_bits } -}; + {hp48_icon_width, hp48_icon_height, BLACK, hp48_icon_bits}, + {hp48_on_width, hp48_on_height, PIXEL, hp48_on_bits}, + {hp48_disp_width, hp48_disp_height, LCD, hp48_disp_bits}, + {hp48_top_gx_width, hp48_top_gx_height, DISP_PAD, hp48_top_gx_bits}, + {hp48_bottom_width, hp48_bottom_height, PAD, hp48_bottom_bits}, + {hp48_logo_gx_width, hp48_logo_gx_height, LOGO, hp48_logo_gx_bits}, + {hp48_text_gx_width, hp48_text_gx_height, LABEL, hp48_text_gx_bits}, + {hp48_keys_width, hp48_keys_height, BLACK, hp48_keys_bits}, + {hp48_orange_width, hp48_orange_height, LEFT, hp48_orange_bits}, + {hp48_green_gx_width, hp48_green_gx_height, RIGHT, hp48_green_gx_bits}}; -#define KEYBOARD_HEIGHT (buttons[LAST_BUTTON].y + buttons[LAST_BUTTON].h) -#define KEYBOARD_WIDTH (buttons[LAST_BUTTON].x + buttons[LAST_BUTTON].w) +#define KEYBOARD_HEIGHT (buttons[LAST_BUTTON].y + buttons[LAST_BUTTON].h) +#define KEYBOARD_WIDTH (buttons[LAST_BUTTON].x + buttons[LAST_BUTTON].w) -#define TOP_SKIP 65 -#define SIDE_SKIP 20 -#define BOTTOM_SKIP 25 -#define DISP_KBD_SKIP 65 +#define TOP_SKIP 65 +#define SIDE_SKIP 20 +#define BOTTOM_SKIP 25 +#define DISP_KBD_SKIP 65 -#define DISPLAY_WIDTH (264 + 8) -#define DISPLAY_HEIGHT (128 + 16 + 8) -#define DISPLAY_OFFSET_X (SIDE_SKIP+(286-DISPLAY_WIDTH)/2) -#define DISPLAY_OFFSET_Y TOP_SKIP +#define DISPLAY_WIDTH (264 + 8) +#define DISPLAY_HEIGHT (128 + 16 + 8) +#define DISPLAY_OFFSET_X (SIDE_SKIP + (286 - DISPLAY_WIDTH) / 2) +#define DISPLAY_OFFSET_Y TOP_SKIP -#define DISP_FRAME 8 +#define DISP_FRAME 8 -#define KEYBOARD_OFFSET_X SIDE_SKIP -#define KEYBOARD_OFFSET_Y (TOP_SKIP + DISPLAY_HEIGHT + DISP_KBD_SKIP) +#define KEYBOARD_OFFSET_X SIDE_SKIP +#define KEYBOARD_OFFSET_Y (TOP_SKIP + DISPLAY_HEIGHT + DISP_KBD_SKIP) int AllocColors(void) { int c, error, dyn; @@ -681,28 +937,114 @@ int AllocColors(void) { error = -1; dyn = dynamic_color; - if (direct_color) - { - while (!(visual->red_mask & (1 << r_shift))) - r_shift++; - while (visual->red_mask & (1 << r_shift)) - r_shift++; - r_shift = 16 - r_shift; - while (!(visual->green_mask & (1 << g_shift))) - g_shift++; - while ((visual->green_mask & (1 << g_shift))) - g_shift++; - g_shift = 16 - g_shift; - while (!(visual->blue_mask & (1 << b_shift))) - b_shift++; - while ((visual->blue_mask & (1 << b_shift))) - b_shift++; - b_shift = 16 - b_shift; - } + if (direct_color) { + while (!(visual->red_mask & (1 << r_shift))) + r_shift++; + while (visual->red_mask & (1 << r_shift)) + r_shift++; + r_shift = 16 - r_shift; + while (!(visual->green_mask & (1 << g_shift))) + g_shift++; + while ((visual->green_mask & (1 << g_shift))) + g_shift++; + g_shift = 16 - g_shift; + while (!(visual->blue_mask & (1 << b_shift))) + b_shift++; + while ((visual->blue_mask & (1 << b_shift))) + b_shift++; + b_shift = 16 - b_shift; + } for (c = WHITE; c <= BLACK; c++) { - switch (color_mode) - { + switch (color_mode) { + case COLOR_MODE_MONO: + colors[c].xcolor.red = colors[c].mono_rgb << 8; + colors[c].xcolor.green = colors[c].mono_rgb << 8; + colors[c].xcolor.blue = colors[c].mono_rgb << 8; + break; + case COLOR_MODE_GRAY: + colors[c].xcolor.red = colors[c].gray_rgb << 8; + colors[c].xcolor.green = colors[c].gray_rgb << 8; + colors[c].xcolor.blue = colors[c].gray_rgb << 8; + break; + default: + colors[c].xcolor.red = colors[c].r << 8; + colors[c].xcolor.green = colors[c].g << 8; + colors[c].xcolor.blue = colors[c].b << 8; + break; + } + if (direct_color) { + colors[c].xcolor.pixel = + ((colors[c].xcolor.red >> r_shift) & visual->red_mask) | + ((colors[c].xcolor.green >> g_shift) & visual->green_mask) | + ((colors[c].xcolor.blue >> b_shift) & visual->blue_mask); + XStoreColor(dpy, cmap, &colors[c].xcolor); + } else { + if (dynamic_color && c == PIXEL) { + if (XAllocColorCells(dpy, cmap, True, (unsigned long *)0, 0, + &colors[c].xcolor.pixel, 1) == 0) { + dyn = 0; + if (XAllocColor(dpy, cmap, &colors[c].xcolor) == 0) { + if (!quiet) + fprintf(stderr, "%s: XAllocColor failed.\n", progname); + error = c; + break; + } + } else if (colors[c].xcolor.pixel >= visual->map_entries) { + dyn = 0; + if (XAllocColor(dpy, cmap, &colors[c].xcolor) == 0) { + if (!quiet) + fprintf(stderr, "%s: XAllocColor failed.\n", progname); + error = c; + break; + } + } else { + XStoreColor(dpy, cmap, &colors[c].xcolor); + } + } else { + if (XAllocColor(dpy, cmap, &colors[c].xcolor) == 0) { + if (!quiet) + fprintf(stderr, "%s: XAllocColor failed.\n", progname); + error = c; + break; + } + } + } + } + + /* + * Can't be reached when visual->class == DirectColor + */ + + if (error != -1) { + if (!quiet) + fprintf(stderr, "%s: Using own Colormap.\n", progname); + /* + * free colors so far allocated + */ + for (c = WHITE; c < error; c++) { + XFreeColors(dpy, cmap, &colors[c].xcolor.pixel, 1, 0); + } + + /* + * Create my own Colormap + */ + cmap = XCreateColormap(dpy, mainW, visual, AllocNone); + if (cmap == (Colormap)0) { + sprintf(errbuf, "can\'t alloc Colormap.\n"); + fatal_exit(); + } + xswa.colormap = cmap; + XChangeWindowAttributes(dpy, mainW, CWColormap, &xswa); + if (iconW) + XChangeWindowAttributes(dpy, iconW, CWColormap, &xswa); + + /* + * Try to allocate colors again + */ + dyn = dynamic_color; + for (c = WHITE; c <= BLACK; c++) { + switch (color_mode) { case COLOR_MODE_MONO: colors[c].xcolor.red = colors[c].mono_rgb << 8; colors[c].xcolor.green = colors[c].mono_rgb << 8; @@ -718,185 +1060,92 @@ int AllocColors(void) { colors[c].xcolor.green = colors[c].g << 8; colors[c].xcolor.blue = colors[c].b << 8; break; - } - if (direct_color) - { - colors[c].xcolor.pixel = - ((colors[c].xcolor.red >> r_shift) & visual->red_mask) | - ((colors[c].xcolor.green >> g_shift) & visual->green_mask) | - ((colors[c].xcolor.blue >> b_shift) & visual->blue_mask); - XStoreColor(dpy, cmap, &colors[c].xcolor); } - else - { - if (dynamic_color && c == PIXEL) - { - if (XAllocColorCells(dpy, cmap, True, (unsigned long *)0, 0, - &colors[c].xcolor.pixel, 1) == 0) - { - dyn = 0; - if (XAllocColor(dpy, cmap, &colors[c].xcolor) == 0) - { - if (!quiet) - fprintf(stderr, "%s: XAllocColor failed.\n", progname); - error = c; - break; - } - } - else if (colors[c].xcolor.pixel >= visual->map_entries) - { - dyn = 0; - if (XAllocColor(dpy, cmap, &colors[c].xcolor) == 0) - { - if (!quiet) - fprintf(stderr, "%s: XAllocColor failed.\n", progname); - error = c; - break; - } - } - else - { - XStoreColor(dpy, cmap, &colors[c].xcolor); - } + if (dynamic_color && c == PIXEL) { + if (XAllocColorCells(dpy, cmap, True, (unsigned long *)0, 0, + &colors[c].xcolor.pixel, 1) == 0) { + dyn = 0; + if (XAllocColor(dpy, cmap, &colors[c].xcolor) == 0) { + sprintf(errbuf, "can\'t alloc Color.\n"); + fatal_exit(); } - else { - if (XAllocColor(dpy, cmap, &colors[c].xcolor) == 0) - { - if (!quiet) - fprintf(stderr, "%s: XAllocColor failed.\n", progname); - error = c; - break; - } + } else if (colors[c].xcolor.pixel >= visual->map_entries) { + dyn = 0; + if (XAllocColor(dpy, cmap, &colors[c].xcolor) == 0) { + sprintf(errbuf, "can\'t alloc Color.\n"); + fatal_exit(); + } + } else { + XStoreColor(dpy, cmap, &colors[c].xcolor); } - } - } - - /* - * Can't be reached when visual->class == DirectColor - */ - - if (error != -1) - { - if (!quiet) - fprintf(stderr, "%s: Using own Colormap.\n", progname); - /* - * free colors so far allocated - */ - for (c = WHITE; c < error; c++) - { - XFreeColors(dpy, cmap, &colors[c].xcolor.pixel, 1, 0); - } - - /* - * Create my own Colormap - */ - cmap = XCreateColormap(dpy, mainW, visual, AllocNone); - if (cmap == (Colormap)0) - { - sprintf(errbuf, "can\'t alloc Colormap.\n"); + } else { + if (XAllocColor(dpy, cmap, &colors[c].xcolor) == 0) { + sprintf(errbuf, "can\'t alloc Color.\n"); fatal_exit(); } - xswa.colormap = cmap; - XChangeWindowAttributes(dpy, mainW, CWColormap, &xswa); - if (iconW) - XChangeWindowAttributes(dpy, iconW, CWColormap, &xswa); - - /* - * Try to allocate colors again - */ - dyn = dynamic_color; - for (c = WHITE; c <= BLACK; c++) { - switch (color_mode) - { - case COLOR_MODE_MONO: - colors[c].xcolor.red = colors[c].mono_rgb << 8; - colors[c].xcolor.green = colors[c].mono_rgb << 8; - colors[c].xcolor.blue = colors[c].mono_rgb << 8; - break; - case COLOR_MODE_GRAY: - colors[c].xcolor.red = colors[c].gray_rgb << 8; - colors[c].xcolor.green = colors[c].gray_rgb << 8; - colors[c].xcolor.blue = colors[c].gray_rgb << 8; - break; - default: - colors[c].xcolor.red = colors[c].r << 8; - colors[c].xcolor.green = colors[c].g << 8; - colors[c].xcolor.blue = colors[c].b << 8; - break; - } - if (dynamic_color && c == PIXEL) { - if (XAllocColorCells(dpy, cmap, True, (unsigned long *)0, 0, - &colors[c].xcolor.pixel, 1) == 0) - { - dyn = 0; - if (XAllocColor(dpy, cmap, &colors[c].xcolor) == 0) - { - sprintf(errbuf, "can\'t alloc Color.\n"); - fatal_exit(); - } - } - else if (colors[c].xcolor.pixel >= visual->map_entries) - { - dyn = 0; - if (XAllocColor(dpy, cmap, &colors[c].xcolor) == 0) - { - sprintf(errbuf, "can\'t alloc Color.\n"); - fatal_exit(); - } - } - else - { - XStoreColor(dpy, cmap, &colors[c].xcolor); - } - } else { - if (XAllocColor(dpy, cmap, &colors[c].xcolor) == 0) - { - sprintf(errbuf, "can\'t alloc Color.\n"); - fatal_exit(); - } - } } } + } dynamic_color = dyn; return 0; } void adjust_contrast(int contrast) { - int gray = 0; - int r = 0, g = 0, b = 0; + int gray = 0; + int r = 0, g = 0, b = 0; unsigned long old; - if (contrast < 0x3) contrast = 0x3; - if (contrast > 0x13) contrast = 0x13; + if (contrast < 0x3) + contrast = 0x3; + if (contrast > 0x13) + contrast = 0x13; old = colors[PIXEL].xcolor.pixel; - switch (color_mode) - { - case COLOR_MODE_MONO: - return; - case COLOR_MODE_GRAY: - gray = (0x13 - contrast) * (colors[LCD].gray_rgb / 0x10); - colors[PIXEL].xcolor.red = gray << 8; - colors[PIXEL].xcolor.green = gray << 8; - colors[PIXEL].xcolor.blue = gray << 8; - break; - default: - r = (0x13 - contrast) * (colors[LCD].r / 0x10); - g = (0x13 - contrast) * (colors[LCD].g / 0x10); - b = 128 - ((0x13 - contrast) * ((128 - colors[LCD].b) / 0x10)); - colors[PIXEL].xcolor.red = r << 8; - colors[PIXEL].xcolor.green = g << 8; - colors[PIXEL].xcolor.blue = b << 8; - break; + switch (color_mode) { + case COLOR_MODE_MONO: + return; + case COLOR_MODE_GRAY: + gray = (0x13 - contrast) * (colors[LCD].gray_rgb / 0x10); + colors[PIXEL].xcolor.red = gray << 8; + colors[PIXEL].xcolor.green = gray << 8; + colors[PIXEL].xcolor.blue = gray << 8; + break; + default: + r = (0x13 - contrast) * (colors[LCD].r / 0x10); + g = (0x13 - contrast) * (colors[LCD].g / 0x10); + b = 128 - ((0x13 - contrast) * ((128 - colors[LCD].b) / 0x10)); + colors[PIXEL].xcolor.red = r << 8; + colors[PIXEL].xcolor.green = g << 8; + colors[PIXEL].xcolor.blue = b << 8; + break; } - if (direct_color) - { - colors[PIXEL].gray_rgb = gray; - colors[PIXEL].r = r; - colors[PIXEL].g = g; - colors[PIXEL].b = b; - AllocColors(); + if (direct_color) { + colors[PIXEL].gray_rgb = gray; + colors[PIXEL].r = r; + colors[PIXEL].g = g; + colors[PIXEL].b = b; + AllocColors(); + XSetForeground(dpy, disp.gc, COLOR(PIXEL)); +#ifdef HAVE_XSHM + disp.display_update = UPDATE_DISP | UPDATE_MENU; + refresh_display(); +#else + redraw_display(); +#endif + redraw_annunc(); + last_icon_state = -1; + refresh_icon(); + } else if (dynamic_color) { + XStoreColor(dpy, cmap, &colors[PIXEL].xcolor); + } else { + if (XAllocColor(dpy, cmap, &colors[PIXEL].xcolor) == 0) { + colors[PIXEL].xcolor.pixel = old; + if (!quiet) + fprintf(stderr, "%s: warning: can\'t alloc new pixel color.\n", + progname); + } else { + XFreeColors(dpy, cmap, &old, 1, 0); XSetForeground(dpy, disp.gc, COLOR(PIXEL)); #ifdef HAVE_XSHM disp.display_update = UPDATE_DISP | UPDATE_MENU; @@ -908,38 +1157,11 @@ void adjust_contrast(int contrast) { last_icon_state = -1; refresh_icon(); } - else if (dynamic_color) - { - XStoreColor(dpy, cmap, &colors[PIXEL].xcolor); - } - else - { - if (XAllocColor(dpy, cmap, &colors[PIXEL].xcolor) == 0) - { - colors[PIXEL].xcolor.pixel = old; - if (!quiet) - fprintf(stderr, "%s: warning: can\'t alloc new pixel color.\n", - progname); - } - else - { - XFreeColors(dpy, cmap, &old, 1, 0); - XSetForeground(dpy, disp.gc, COLOR(PIXEL)); -#ifdef HAVE_XSHM - disp.display_update = UPDATE_DISP | UPDATE_MENU; - refresh_display(); -#else - redraw_display(); -#endif - redraw_annunc(); - last_icon_state = -1; - refresh_icon(); - } - } + } } int merge_app_defaults(char *path, XrmDatabase *db) { - char file[1024]; + char file[1024]; XrmDatabase tmp; if (path == (char *)0) @@ -957,32 +1179,31 @@ int merge_app_defaults(char *path, XrmDatabase *db) { } int InitDisplay(int argc, char **argv) { - XrmDatabase cmd = NULL, tmp = NULL; - char *res, *s; - char buf[1024], home[1024]; - int def, i; + XrmDatabase cmd = NULL, tmp = NULL; + char *res, *s; + char buf[1024], home[1024]; + int def, i; struct passwd *pwd; #ifdef SYSV struct utsname uts; #else - char hostname[128]; + char hostname[128]; #endif /* * Parse the command line */ XrmInitialize(); - XrmParseCommand(&cmd, options, sizeof(options)/sizeof(*options), - progname, &argc, argv); + XrmParseCommand(&cmd, options, sizeof(options) / sizeof(*options), progname, + &argc, argv); if ((argc == 2) && !strcmp(argv[1], "-help")) usage(); - else if (argc > 1) - { - fprintf(stderr, "%s: unknown option %s or missing argument\n", - progname, argv[1]); - usage(); - } + else if (argc > 1) { + fprintf(stderr, "%s: unknown option %s or missing argument\n", progname, + argv[1]); + usage(); + } res_name = progname; res_class = strdup(res_name); @@ -992,56 +1213,49 @@ int InitDisplay(int argc, char **argv) { * look for argument -name */ res = get_string_resource_from_db(cmd, "name", "Name"); - if (res) - { - if (!(res_name = strdup(res))) - { - sprintf(errbuf, "out of memory in InitDisplay()\n"); - fatal_exit(); - } - - for (s = res_name; *s; s++) - *s = isupper(*s) ? _tolower(*s) : *s; - - free(res_class); - res_class = strdup(res_name); - *res_class = islower(*res_class) ? _toupper(*res_class) : *res_class; - - argc = saved_argc; - argv = (char **)malloc((argc + 1) * sizeof(char *)); - if (argv == (char **)0) - { - sprintf(errbuf, "out of memory in InitDisplay()\n"); - fatal_exit(); - } - argv[argc] = (char *)0; - for (i = 0; i < argc; i++) - argv[i] = saved_argv[i]; - - XrmParseCommand(&cmd, options, sizeof(options)/sizeof(*options), - res_name, &argc, argv); + if (res) { + if (!(res_name = strdup(res))) { + sprintf(errbuf, "out of memory in InitDisplay()\n"); + fatal_exit(); } + for (s = res_name; *s; s++) + *s = isupper(*s) ? _tolower(*s) : *s; + + free(res_class); + res_class = strdup(res_name); + *res_class = islower(*res_class) ? _toupper(*res_class) : *res_class; + + argc = saved_argc; + argv = (char **)malloc((argc + 1) * sizeof(char *)); + if (argv == (char **)0) { + sprintf(errbuf, "out of memory in InitDisplay()\n"); + fatal_exit(); + } + argv[argc] = (char *)0; + for (i = 0; i < argc; i++) + argv[i] = saved_argv[i]; + + XrmParseCommand(&cmd, options, sizeof(options) / sizeof(*options), res_name, + &argc, argv); + } + /* * Open the display */ res = get_string_resource_from_db(cmd, "display", "Display"); dpy = XOpenDisplay(res); - if (dpy == (Display *)0) - { - if (res) - { - if (!quiet) - fprintf(stderr, "%s: can\'t open display %s\n", progname, res); - } - else - { - if (!quiet) - fprintf(stderr, "%s: can\'t open display\n", progname); - } - return -1; + if (dpy == (Display *)0) { + if (res) { + if (!quiet) + fprintf(stderr, "%s: can\'t open display %s\n", progname, res); + } else { + if (!quiet) + fprintf(stderr, "%s: can\'t open display\n", progname); } + return -1; + } /* * Load all those Resources. @@ -1064,11 +1278,10 @@ int InitDisplay(int argc, char **argv) { /* 1. Hardcoded Defaults */ - for (def = 0; defaults[def]; def++) - { - if ((tmp = XrmGetStringDatabase(defaults[def]))) - XrmMergeDatabases(tmp, &rdb); - } + for (def = 0; defaults[def]; def++) { + if ((tmp = XrmGetStringDatabase(defaults[def]))) + XrmMergeDatabases(tmp, &rdb); + } /* 2. /usr/lib/X11/app-defaults/X48 */ @@ -1082,63 +1295,53 @@ int InitDisplay(int argc, char **argv) { /* 4. Values from XResourceManagerString() or ~/.Xdefaults */ res = XResourceManagerString(dpy); - if (res) - { - if ((tmp = XrmGetStringDatabase(res))) - XrmMergeDatabases(tmp, &rdb); - } - else - { - res = getenv("HOME"); - if (res) - strcpy(home, res); - else - { - pwd = getpwuid(getuid()); - if (pwd) - strcpy(home, pwd->pw_dir); - } - sprintf(buf, "%s/.Xdefaults", home); - if ((tmp = XrmGetFileDatabase(buf))) - XrmMergeDatabases(tmp, &rdb); + if (res) { + if ((tmp = XrmGetStringDatabase(res))) + XrmMergeDatabases(tmp, &rdb); + } else { + res = getenv("HOME"); + if (res) + strcpy(home, res); + else { + pwd = getpwuid(getuid()); + if (pwd) + strcpy(home, pwd->pw_dir); } + sprintf(buf, "%s/.Xdefaults", home); + if ((tmp = XrmGetFileDatabase(buf))) + XrmMergeDatabases(tmp, &rdb); + } /* 5. Values in $XENVIRONMENT or ~/.Xdefaults-hostname */ res = getenv("XENVIRONMENT"); - if (res) - { - if ((tmp = XrmGetFileDatabase(res))) - XrmMergeDatabases(tmp, &rdb); + if (res) { + if ((tmp = XrmGetFileDatabase(res))) + XrmMergeDatabases(tmp, &rdb); + } else { + res = getenv("HOME"); + if (res) + strcpy(home, res); + else { + pwd = getpwuid(getuid()); + if (pwd) + strcpy(home, pwd->pw_dir); } - else - { - res = getenv("HOME"); - if (res) - strcpy(home, res); - else - { - pwd = getpwuid(getuid()); - if (pwd) - strcpy(home, pwd->pw_dir); - } - tmp = (XrmDatabase)0; + tmp = (XrmDatabase)0; #ifdef SYSV - if (uname(&uts) >= 0) - { - sprintf(buf, "%s/.Xdefaults-%s", home, uts.nodename); - tmp = XrmGetFileDatabase(buf); - } -#else - if (gethostname(hostname, 128) >= 0) - { - sprintf(buf, "%s/.Xdefaults-%s", home, hostname); - tmp = XrmGetFileDatabase(buf); - } -#endif - if (tmp) - XrmMergeDatabases(tmp, &rdb); + if (uname(&uts) >= 0) { + sprintf(buf, "%s/.Xdefaults-%s", home, uts.nodename); + tmp = XrmGetFileDatabase(buf); } +#else + if (gethostname(hostname, 128) >= 0) { + sprintf(buf, "%s/.Xdefaults-%s", home, hostname); + tmp = XrmGetFileDatabase(buf); + } +#endif + if (tmp) + XrmMergeDatabases(tmp, &rdb); + } /* 6. Command line arguments */ @@ -1174,14 +1377,12 @@ int InitDisplay(int argc, char **argv) { progname); } if (shm_flag) - fprintf(stderr, "%s: using XShm extension.\n", progname); + fprintf(stderr, "%s: using XShm extension.\n", progname); #else - if (useXShm) - { - if (!quiet) - fprintf(stderr, "%s: not compiled to use XShm extension.\n", - progname); - } + if (useXShm) { + if (!quiet) + fprintf(stderr, "%s: not compiled to use XShm extension.\n", progname); + } #endif return 0; @@ -1203,19 +1404,19 @@ int SmallTextWidth(const char *string, unsigned int length) { return w; } -int DrawSmallString(Display *the_dpy, Drawable d, GC the_gc, - int x, int y, const char *string, unsigned int length) { +int DrawSmallString(Display *the_dpy, Drawable d, GC the_gc, int x, int y, + const char *string, unsigned int length) { int i; Pixmap pix; for (i = 0; i < length; i++) { if (small_font[(int)string[i]].h != 0) { - pix = XCreateBitmapFromData(the_dpy, d, - (char *)small_font[(int)string[i]].bits, - small_font[(int)string[i]].w, small_font[(int)string[i]].h); + pix = XCreateBitmapFromData( + the_dpy, d, (char *)small_font[(int)string[i]].bits, + small_font[(int)string[i]].w, small_font[(int)string[i]].h); XCopyPlane(the_dpy, pix, d, the_gc, 0, 0, small_font[(int)string[i]].w, small_font[(int)string[i]].h, x, - (int)(y - small_font[(int)string[i]].h), 1); + (int)(y - small_font[(int)string[i]].h), 1); XFreePixmap(the_dpy, pix); } x += SmallTextWidth(&string[i], 1); @@ -1225,7 +1426,8 @@ int DrawSmallString(Display *the_dpy, Drawable d, GC the_gc, #include -void CreateButton(int i, int off_x, int off_y, XFontStruct *f_small, XFontStruct *f_med, XFontStruct *f_big ) { +void CreateButton(int i, int off_x, int off_y, XFontStruct *f_small, + XFontStruct *f_med, XFontStruct *f_big) { int x, y; XSetWindowAttributes xswa; XFontStruct *finfo; @@ -1239,40 +1441,36 @@ void CreateButton(int i, int off_x, int off_y, XFontStruct *f_small, XFontStruct { if (i < BUTTON_MTH) pixel = COLOR(DISP_PAD); - else - { - if (opt_gx && buttons[i].is_menu) - pixel = COLOR(UNDERLAY); - else - pixel = COLOR(PAD); - } + else { + if (opt_gx && buttons[i].is_menu) + pixel = COLOR(UNDERLAY); + else + pixel = COLOR(PAD); + } /* * create the buttons subwindows */ - buttons[i].xwin = XCreateSimpleWindow(dpy, mainW, - off_x + buttons[i].x, - off_y + buttons[i].y, - buttons[i].w, buttons[i].h, 0, - COLOR(BLACK), pixel); + buttons[i].xwin = XCreateSimpleWindow(dpy, mainW, off_x + buttons[i].x, + off_y + buttons[i].y, buttons[i].w, + buttons[i].h, 0, COLOR(BLACK), pixel); XDefineCursor(dpy, buttons[i].xwin, XCreateFontCursor(dpy, XC_hand1)); xswa.event_mask = LeaveWindowMask | ExposureMask | StructureNotifyMask; xswa.backing_store = Always; - XChangeWindowAttributes(dpy, buttons[i].xwin, - CWEventMask|CWBackingStore, &xswa); + XChangeWindowAttributes(dpy, buttons[i].xwin, CWEventMask | CWBackingStore, + &xswa); /* * draw the released button */ - buttons[i].map = XCreatePixmap(dpy, buttons[i].xwin, buttons[i].w, - buttons[i].h, depth); + buttons[i].map = + XCreatePixmap(dpy, buttons[i].xwin, buttons[i].w, buttons[i].h, depth); XSetForeground(dpy, gc, pixel); - XFillRectangle(dpy, buttons[i].map, gc, 0, 0, buttons[i].w, - buttons[i].h); + XFillRectangle(dpy, buttons[i].map, gc, 0, 0, buttons[i].w, buttons[i].h); XSetForeground(dpy, gc, COLOR(BUTTON)); XFillRectangle(dpy, buttons[i].map, gc, 1, 1, buttons[i].w - 2, @@ -1284,18 +1482,18 @@ void CreateButton(int i, int off_x, int off_y, XFontStruct *f_small, XFontStruct * set font size in gc */ switch (buttons[i].font_size) { - case 0: - finfo = f_small; - break; - case 1: - finfo = f_big; - break; - case 2: - finfo = f_med; - break; - default: - finfo = f_small; - break; + case 0: + finfo = f_small; + break; + case 1: + finfo = f_big; + break; + case 2: + finfo = f_med; + break; + default: + finfo = f_small; + break; } val.font = finfo->fid; gc_mask = GCFont; @@ -1307,13 +1505,13 @@ void CreateButton(int i, int off_x, int off_y, XFontStruct *f_small, XFontStruct XSetBackground(dpy, gc, COLOR(BUTTON)); XSetForeground(dpy, gc, COLOR(buttons[i].lc)); - XTextExtents(finfo, buttons[i].label, (int)strlen(buttons[i].label), - &dir, &fa, &fd, &xchar); + XTextExtents(finfo, buttons[i].label, (int)strlen(buttons[i].label), &dir, + &fa, &fd, &xchar); x = (buttons[i].w - xchar.width) / 2; - y = (1 + buttons[i].h - - (xchar.ascent + xchar.descent)) / 2 + xchar.ascent + 1; - XDrawImageString(dpy, buttons[i].map, gc, x, y, - buttons[i].label, (int)strlen(buttons[i].label)); + y = (1 + buttons[i].h - (xchar.ascent + xchar.descent)) / 2 + + xchar.ascent + 1; + XDrawImageString(dpy, buttons[i].map, gc, x, y, buttons[i].label, + (int)strlen(buttons[i].label)); XSetBackground(dpy, gc, COLOR(BLACK)); @@ -1326,18 +1524,17 @@ void CreateButton(int i, int off_x, int off_y, XFontStruct *f_small, XFontStruct XSetForeground(dpy, gc, COLOR(buttons[i].lc)); pix = XCreateBitmapFromData(dpy, buttons[i].xwin, (char *)buttons[i].lb, - buttons[i].lw, buttons[i].lh); + buttons[i].lw, buttons[i].lh); x = (1 + buttons[i].w - buttons[i].lw) / 2; y = (1 + buttons[i].h - buttons[i].lh) / 2 + 1; XCopyPlane(dpy, pix, buttons[i].map, gc, 0, 0, buttons[i].lw, - buttons[i].lh, x, y, 1); + buttons[i].lh, x, y, 1); XFreePixmap(dpy, pix); XSetBackground(dpy, gc, COLOR(BLACK)); - } /* @@ -1385,17 +1582,14 @@ void CreateButton(int i, int off_x, int off_y, XFontStruct *f_small, XFontStruct XDrawLine(dpy, buttons[i].map, gc, (int)(buttons[i].w - 1), (int)(buttons[i].h - 3), (int)(buttons[i].w - 1), 2); - if (i == BUTTON_ON) - { - XDrawLine(dpy, buttons[i].map, gc, 1, 1, (int)(buttons[i].w - 2), 1); - XDrawPoint(dpy, buttons[i].map, gc, 1, 2); - XDrawPoint(dpy, buttons[i].map, gc, (int)(buttons[i].w - 2), 2); - } - else - { - XDrawPoint(dpy, buttons[i].map, gc, 1, 1); - XDrawPoint(dpy, buttons[i].map, gc, (int)(buttons[i].w - 2), 1); - } + if (i == BUTTON_ON) { + XDrawLine(dpy, buttons[i].map, gc, 1, 1, (int)(buttons[i].w - 2), 1); + XDrawPoint(dpy, buttons[i].map, gc, 1, 2); + XDrawPoint(dpy, buttons[i].map, gc, (int)(buttons[i].w - 2), 2); + } else { + XDrawPoint(dpy, buttons[i].map, gc, 1, 1); + XDrawPoint(dpy, buttons[i].map, gc, (int)(buttons[i].w - 2), 1); + } XDrawPoint(dpy, buttons[i].map, gc, 1, (int)(buttons[i].h - 2)); XDrawPoint(dpy, buttons[i].map, gc, (int)(buttons[i].w - 2), (int)(buttons[i].h - 2)); @@ -1403,12 +1597,11 @@ void CreateButton(int i, int off_x, int off_y, XFontStruct *f_small, XFontStruct /* * draw the depressed button */ - buttons[i].down = XCreatePixmap(dpy, buttons[i].xwin, buttons[i].w, - buttons[i].h, depth); + buttons[i].down = + XCreatePixmap(dpy, buttons[i].xwin, buttons[i].w, buttons[i].h, depth); XSetForeground(dpy, gc, pixel); - XFillRectangle(dpy, buttons[i].down, gc, 0, 0, buttons[i].w, - buttons[i].h); + XFillRectangle(dpy, buttons[i].down, gc, 0, 0, buttons[i].w, buttons[i].h); XSetForeground(dpy, gc, COLOR(BUTTON)); XFillRectangle(dpy, buttons[i].down, gc, 1, 1, buttons[i].w - 2, @@ -1420,18 +1613,18 @@ void CreateButton(int i, int off_x, int off_y, XFontStruct *f_small, XFontStruct * set small or big font in gc */ switch (buttons[i].font_size) { - case 0: - finfo = f_small; - break; - case 1: - finfo = f_big; - break; - case 2: - finfo = f_med; - break; - default: - finfo = f_small; - break; + case 0: + finfo = f_small; + break; + case 1: + finfo = f_big; + break; + case 2: + finfo = f_med; + break; + default: + finfo = f_small; + break; } val.font = finfo->fid; gc_mask = GCFont; @@ -1443,13 +1636,13 @@ void CreateButton(int i, int off_x, int off_y, XFontStruct *f_small, XFontStruct XSetBackground(dpy, gc, COLOR(BUTTON)); XSetForeground(dpy, gc, COLOR(buttons[i].lc)); - XTextExtents(finfo, buttons[i].label, (int)strlen(buttons[i].label), - &dir, &fa, &fd, &xchar); + XTextExtents(finfo, buttons[i].label, (int)strlen(buttons[i].label), &dir, + &fa, &fd, &xchar); x = (buttons[i].w - xchar.width) / 2; - y = (1 + buttons[i].h - - (xchar.ascent + xchar.descent)) / 2 + xchar.ascent; - XDrawImageString(dpy, buttons[i].down, gc, x, y, - buttons[i].label, (int)strlen(buttons[i].label)); + y = (1 + buttons[i].h - (xchar.ascent + xchar.descent)) / 2 + + xchar.ascent; + XDrawImageString(dpy, buttons[i].down, gc, x, y, buttons[i].label, + (int)strlen(buttons[i].label)); XSetBackground(dpy, gc, COLOR(BLACK)); @@ -1462,18 +1655,17 @@ void CreateButton(int i, int off_x, int off_y, XFontStruct *f_small, XFontStruct XSetForeground(dpy, gc, COLOR(buttons[i].lc)); pix = XCreateBitmapFromData(dpy, buttons[i].xwin, (char *)buttons[i].lb, - buttons[i].lw, buttons[i].lh); + buttons[i].lw, buttons[i].lh); x = (1 + buttons[i].w - buttons[i].lw) / 2; y = (1 + buttons[i].h - buttons[i].lh) / 2; XCopyPlane(dpy, pix, buttons[i].down, gc, 0, 0, buttons[i].lw, - buttons[i].lh, x, y, 1); + buttons[i].lh, x, y, 1); XFreePixmap(dpy, pix); XSetBackground(dpy, gc, COLOR(BLACK)); - } /* @@ -1516,39 +1708,32 @@ void CreateButton(int i, int off_x, int off_y, XFontStruct *f_small, XFontStruct XDrawLine(dpy, buttons[i].down, gc, (int)(buttons[i].w - 1), (int)(buttons[i].h - 3), (int)(buttons[i].w - 1), 2); - if (i == BUTTON_ON) - { - XDrawLine(dpy, buttons[i].down, gc, 1, 1, (int)(buttons[i].w - 2), 1); - XDrawPoint(dpy, buttons[i].down, gc, 1, 2); - XDrawPoint(dpy, buttons[i].down, gc, (int)(buttons[i].w - 2), 2); - } - else - { - XDrawPoint(dpy, buttons[i].down, gc, 1, 1); - XDrawPoint(dpy, buttons[i].down, gc, (int)(buttons[i].w - 2), 1); - } + if (i == BUTTON_ON) { + XDrawLine(dpy, buttons[i].down, gc, 1, 1, (int)(buttons[i].w - 2), 1); + XDrawPoint(dpy, buttons[i].down, gc, 1, 2); + XDrawPoint(dpy, buttons[i].down, gc, (int)(buttons[i].w - 2), 2); + } else { + XDrawPoint(dpy, buttons[i].down, gc, 1, 1); + XDrawPoint(dpy, buttons[i].down, gc, (int)(buttons[i].w - 2), 1); + } XDrawPoint(dpy, buttons[i].down, gc, 1, (int)(buttons[i].h - 2)); XDrawPoint(dpy, buttons[i].down, gc, (int)(buttons[i].w - 2), (int)(buttons[i].h - 2)); - if (i == BUTTON_ON) - { - XDrawRectangle(dpy, buttons[i].down, gc, 1, 2, buttons[i].w - 3, - buttons[i].h - 4); - XDrawPoint(dpy, buttons[i].down, gc, 2, 3); - XDrawPoint(dpy, buttons[i].down, gc, (int)(buttons[i].w - 3), 3); - } - else - { - XDrawRectangle(dpy, buttons[i].down, gc, 1, 1, buttons[i].w - 3, - buttons[i].h - 3); - XDrawPoint(dpy, buttons[i].down, gc, 2, 2); - XDrawPoint(dpy, buttons[i].down, gc, (int)(buttons[i].w - 3), 2); - } + if (i == BUTTON_ON) { + XDrawRectangle(dpy, buttons[i].down, gc, 1, 2, buttons[i].w - 3, + buttons[i].h - 4); + XDrawPoint(dpy, buttons[i].down, gc, 2, 3); + XDrawPoint(dpy, buttons[i].down, gc, (int)(buttons[i].w - 3), 3); + } else { + XDrawRectangle(dpy, buttons[i].down, gc, 1, 1, buttons[i].w - 3, + buttons[i].h - 3); + XDrawPoint(dpy, buttons[i].down, gc, 2, 2); + XDrawPoint(dpy, buttons[i].down, gc, (int)(buttons[i].w - 3), 2); + } XDrawPoint(dpy, buttons[i].down, gc, 2, (int)(buttons[i].h - 3)); XDrawPoint(dpy, buttons[i].down, gc, (int)(buttons[i].w - 3), (int)(buttons[i].h - 3)); - } return; @@ -1580,8 +1765,8 @@ int DrawButton(int i) { return 0; } -void CreateBackground(int width, int height, int w_top, int h_top, keypad_t *keypad) -{ +void CreateBackground(int width, int height, int w_top, int h_top, + keypad_t *keypad) { XSetBackground(dpy, gc, COLOR(PAD)); XSetForeground(dpy, gc, COLOR(PAD)); @@ -1595,15 +1780,15 @@ void CreateBackground(int width, int height, int w_top, int h_top, keypad_t *key return; } -void CreateKeypad(unsigned int w, unsigned int h, unsigned int offset_y, unsigned int offset_x, keypad_t *keypad) { +void CreateKeypad(unsigned int w, unsigned int h, unsigned int offset_y, + unsigned int offset_x, keypad_t *keypad) { int i, x, y; int wl, wr, ws; Pixmap pix; unsigned long pixel; - unsigned int pw, ph; + unsigned int pw, ph; XFontStruct *f_small, *f_med, *f_big; - f_small = get_font_resource(dpy, "smallLabelFont", "SmallLabelFont"); f_med = get_font_resource(dpy, "mediumLabelFont", "MediumLabelFont"); f_big = get_font_resource(dpy, "largeLabelFont", "LargeLabelFont"); @@ -1625,20 +1810,16 @@ void CreateKeypad(unsigned int w, unsigned int h, unsigned int offset_y, unsigne XSetBackground(dpy, gc, pixel); XSetForeground(dpy, gc, COLOR(WHITE)); - if (opt_gx) - { - x = offset_x + buttons[i].x + buttons[i].w + 3; - y = offset_y + buttons[i].y + buttons[i].h + 1; - } - else - { - x = offset_x + buttons[i].x + buttons[i].w - - SmallTextWidth(buttons[i].letter, 1) / 2 + 5; - y = offset_y + buttons[i].y + buttons[i].h - 2; - } + if (opt_gx) { + x = offset_x + buttons[i].x + buttons[i].w + 3; + y = offset_y + buttons[i].y + buttons[i].h + 1; + } else { + x = offset_x + buttons[i].x + buttons[i].w - + SmallTextWidth(buttons[i].letter, 1) / 2 + 5; + y = offset_y + buttons[i].y + buttons[i].h - 2; + } - DrawSmallString(dpy, keypad->pixmap, gc, x, y, - buttons[i].letter, 1); + DrawSmallString(dpy, keypad->pixmap, gc, x, y, buttons[i].letter, 1); } } @@ -1656,12 +1837,14 @@ void CreateKeypad(unsigned int w, unsigned int h, unsigned int offset_y, unsigne XSetBackground(dpy, gc, pixel); XSetForeground(dpy, gc, COLOR(WHITE)); - x = offset_x + buttons[i].x + (1 + buttons[i].w - - SmallTextWidth(buttons[i].sub, strlen(buttons[i].sub))) / 2; + x = offset_x + buttons[i].x + + (1 + buttons[i].w - + SmallTextWidth(buttons[i].sub, strlen(buttons[i].sub))) / + 2; y = offset_y + buttons[i].y + buttons[i].h + small_ascent + 2; - DrawSmallString(dpy, keypad->pixmap, gc, x, y, - buttons[i].sub, strlen(buttons[i].sub)); + DrawSmallString(dpy, keypad->pixmap, gc, x, y, buttons[i].sub, + strlen(buttons[i].sub)); } } @@ -1677,89 +1860,80 @@ void CreateKeypad(unsigned int w, unsigned int h, unsigned int offset_y, unsigne /* * draw the dark shade under the label */ - if (opt_gx) - { - pw = 58; - ph = 48; - } - else - { - pw = 46; - ph = 11; - } + if (opt_gx) { + pw = 58; + ph = 48; + } else { + pw = 46; + ph = 11; + } - pix = XCreatePixmap(dpy, keypad->pixmap, pw, ph, depth); + pix = XCreatePixmap(dpy, keypad->pixmap, pw, ph, depth); XSetForeground(dpy, gc, COLOR(UNDERLAY)); - XFillRectangle(dpy, pix, gc, 0, 0, pw, ph); + XFillRectangle(dpy, pix, gc, 0, 0, pw, ph); XSetBackground(dpy, gc, COLOR(UNDERLAY)); - XSetForeground(dpy, gc, COLOR(LEFT)); + XSetForeground(dpy, gc, COLOR(LEFT)); - x = (pw + 1 - SmallTextWidth(buttons[i].left, - strlen(buttons[i].left))) / 2; + x = (pw + 1 - + SmallTextWidth(buttons[i].left, strlen(buttons[i].left))) / + 2; if (opt_gx) y = 14; else y = 9; - DrawSmallString(dpy, pix, gc, x, y, - buttons[i].left, strlen(buttons[i].left)); + DrawSmallString(dpy, pix, gc, x, y, buttons[i].left, + strlen(buttons[i].left)); XSetForeground(dpy, gc, pixel); - if (!opt_gx) - { - XDrawPoint(dpy, pix, gc, 0, 0); - XDrawPoint(dpy, pix, gc, 0, ph - 1); - XDrawPoint(dpy, pix, gc, pw - 1, 0); - XDrawPoint(dpy, pix, gc, pw - 1, ph - 1); - } + if (!opt_gx) { + XDrawPoint(dpy, pix, gc, 0, 0); + XDrawPoint(dpy, pix, gc, 0, ph - 1); + XDrawPoint(dpy, pix, gc, pw - 1, 0); + XDrawPoint(dpy, pix, gc, pw - 1, ph - 1); + } - if (opt_gx) - { - x = offset_x + buttons[i].x - 6; - y = offset_y + buttons[i].y - - small_ascent - small_descent - 6; - } - else - { - x = offset_x + buttons[i].x + (buttons[i].w - pw) / 2; - y = offset_y + buttons[i].y - - small_ascent - small_descent; - } + if (opt_gx) { + x = offset_x + buttons[i].x - 6; + y = offset_y + buttons[i].y - small_ascent - small_descent - 6; + } else { + x = offset_x + buttons[i].x + (buttons[i].w - pw) / 2; + y = offset_y + buttons[i].y - small_ascent - small_descent; + } XCopyArea(dpy, pix, keypad->pixmap, gc, 0, 0, pw, ph, x, y); - XFreePixmap(dpy, pix); + XFreePixmap(dpy, pix); } else { XSetBackground(dpy, gc, pixel); XSetForeground(dpy, gc, COLOR(LEFT)); - if (buttons[i].right == (char *)0) { /* centered label */ + if (buttons[i].right == (char *)0) { /* centered label */ - x = offset_x + buttons[i].x + (1 + buttons[i].w - - SmallTextWidth(buttons[i].left, - strlen(buttons[i].left))) / 2; + x = offset_x + buttons[i].x + + (1 + buttons[i].w - + SmallTextWidth(buttons[i].left, strlen(buttons[i].left))) / + 2; - } else { /* label to the left */ + } else { /* label to the left */ - wl = SmallTextWidth(buttons[i].left, strlen(buttons[i].left)); - wr = SmallTextWidth(buttons[i].right, strlen(buttons[i].right)); - ws = SmallTextWidth(" ", 1); - - x = offset_x + buttons[i].x + (1 + buttons[i].w - - (wl + wr + ws)) / 2; + wl = SmallTextWidth(buttons[i].left, strlen(buttons[i].left)); + wr = SmallTextWidth(buttons[i].right, strlen(buttons[i].right)); + ws = SmallTextWidth(" ", 1); + x = offset_x + buttons[i].x + (1 + buttons[i].w - (wl + wr + ws)) / 2; } y = offset_y + buttons[i].y - small_descent; - DrawSmallString(dpy, keypad->pixmap, gc, x, y, - buttons[i].left, strlen(buttons[i].left)); + DrawSmallString(dpy, keypad->pixmap, gc, x, y, buttons[i].left, + strlen(buttons[i].left)); } } } @@ -1781,89 +1955,81 @@ void CreateKeypad(unsigned int w, unsigned int h, unsigned int offset_y, unsigne /* * draw the dark shade under the label */ - if (opt_gx) - { - pw = 58; - ph = 48; - } - else - { - pw = 44; - ph = 9; - } + if (opt_gx) { + pw = 58; + ph = 48; + } else { + pw = 44; + ph = 9; + } pix = XCreatePixmap(dpy, keypad->pixmap, pw, ph, depth); XSetForeground(dpy, gc, COLOR(UNDERLAY)); - XFillRectangle(dpy, pix, gc, 0, 0, pw, ph); + XFillRectangle(dpy, pix, gc, 0, 0, pw, ph); XSetBackground(dpy, gc, COLOR(UNDERLAY)); - XSetForeground(dpy, gc, COLOR(RIGHT)); + XSetForeground(dpy, gc, COLOR(RIGHT)); - x = (pw + 1 - SmallTextWidth(buttons[i].right, - strlen(buttons[i].right))) / 2; + x = (pw + 1 - + SmallTextWidth(buttons[i].right, strlen(buttons[i].right))) / + 2; if (opt_gx) y = 14; else y = 8; - DrawSmallString(dpy, pix, gc, x, y, - buttons[i].right, strlen(buttons[i].right)); + DrawSmallString(dpy, pix, gc, x, y, buttons[i].right, + strlen(buttons[i].right)); XSetForeground(dpy, gc, pixel); - if (!opt_gx) - { - XDrawPoint(dpy, pix, gc, 0, 0); - XDrawPoint(dpy, pix, gc, 0, ph - 1); - XDrawPoint(dpy, pix, gc, pw - 1, 0); - XDrawPoint(dpy, pix, gc, pw - 1, ph - 1); - } + if (!opt_gx) { + XDrawPoint(dpy, pix, gc, 0, 0); + XDrawPoint(dpy, pix, gc, 0, ph - 1); + XDrawPoint(dpy, pix, gc, pw - 1, 0); + XDrawPoint(dpy, pix, gc, pw - 1, ph - 1); + } - if (opt_gx) - { - x = offset_x + buttons[i].x - 6; - y = offset_y + buttons[i].y - - small_ascent - small_descent - 6; - } - else - { - x = offset_x + buttons[i].x + (buttons[i].w - pw) / 2; - y = offset_y + buttons[i].y - - small_ascent - small_descent; - } + if (opt_gx) { + x = offset_x + buttons[i].x - 6; + y = offset_y + buttons[i].y - small_ascent - small_descent - 6; + } else { + x = offset_x + buttons[i].x + (buttons[i].w - pw) / 2; + y = offset_y + buttons[i].y - small_ascent - small_descent; + } XCopyArea(dpy, pix, keypad->pixmap, gc, 0, 0, pw, ph, x, y); - XFreePixmap(dpy, pix); + XFreePixmap(dpy, pix); } else { XSetBackground(dpy, gc, pixel); XSetForeground(dpy, gc, COLOR(RIGHT)); - if (buttons[i].left == (char *)0) { /* centered label */ + if (buttons[i].left == (char *)0) { /* centered label */ - x = offset_x + buttons[i].x + (1 + buttons[i].w - - SmallTextWidth(buttons[i].right, - strlen(buttons[i].right))) / 2; + x = offset_x + buttons[i].x + + (1 + buttons[i].w - + SmallTextWidth(buttons[i].right, strlen(buttons[i].right))) / + 2; - } else { /* label to the right */ + } else { /* label to the right */ - wl = SmallTextWidth(buttons[i].left, strlen(buttons[i].left)); - wr = SmallTextWidth(buttons[i].right, strlen(buttons[i].right)); - ws = SmallTextWidth(" ", 1); - - x = offset_x + buttons[i].x + (1 + buttons[i].w - - (wl + wr + ws)) / 2 + wl + ws; + wl = SmallTextWidth(buttons[i].left, strlen(buttons[i].left)); + wr = SmallTextWidth(buttons[i].right, strlen(buttons[i].right)); + ws = SmallTextWidth(" ", 1); + x = offset_x + buttons[i].x + + (1 + buttons[i].w - (wl + wr + ws)) / 2 + wl + ws; } y = offset_y + buttons[i].y - small_descent; - DrawSmallString(dpy, keypad->pixmap, gc, x, y, - buttons[i].right, strlen(buttons[i].right)); + DrawSmallString(dpy, keypad->pixmap, gc, x, y, buttons[i].right, + strlen(buttons[i].right)); } } } @@ -1872,34 +2038,32 @@ void CreateKeypad(unsigned int w, unsigned int h, unsigned int offset_y, unsigne * at last draw the v--- LAST ---v thing */ - if (!opt_gx) - { - XSetBackground(dpy, gc, COLOR(PAD)); - XSetForeground(dpy, gc, COLOR(WHITE)); + if (!opt_gx) { + XSetBackground(dpy, gc, COLOR(PAD)); + XSetForeground(dpy, gc, COLOR(WHITE)); - pix = XCreateBitmapFromData(dpy, keypad->pixmap, (char *)last_bits, - last_width, last_height); + pix = XCreateBitmapFromData(dpy, keypad->pixmap, (char *)last_bits, + last_width, last_height); - x = offset_x + buttons[BUTTON_1].x + buttons[BUTTON_1].w + - (buttons[BUTTON_2].x - buttons[BUTTON_1].x - buttons[BUTTON_1].w) / 2; - y = offset_y + buttons[BUTTON_5].y + buttons[BUTTON_5].h + 2; + x = offset_x + buttons[BUTTON_1].x + buttons[BUTTON_1].w + + (buttons[BUTTON_2].x - buttons[BUTTON_1].x - buttons[BUTTON_1].w) / 2; + y = offset_y + buttons[BUTTON_5].y + buttons[BUTTON_5].h + 2; - XCopyPlane(dpy, pix, keypad->pixmap, gc, 0, 0, last_width, last_height, - x, y, 1); + XCopyPlane(dpy, pix, keypad->pixmap, gc, 0, 0, last_width, last_height, x, + y, 1); - XFreePixmap(dpy, pix); - } + XFreePixmap(dpy, pix); + } return; } -void -CreateBezel(unsigned int width, unsigned int height, unsigned int offset_y, unsigned int offset_x, keypad_t *keypad) -{ +void CreateBezel(unsigned int width, unsigned int height, unsigned int offset_y, + unsigned int offset_x, keypad_t *keypad) { int i, x, y; Pixmap pix; int display_height = DISPLAY_HEIGHT; - int display_width = DISPLAY_WIDTH; + int display_width = DISPLAY_WIDTH; /* * draw the frame around the display @@ -1907,36 +2071,31 @@ CreateBezel(unsigned int width, unsigned int height, unsigned int offset_y, unsi XSetForeground(dpy, gc, COLOR(DISP_PAD_TOP)); for (i = 0; i < DISP_FRAME; i++) { - XDrawLine(dpy, keypad->pixmap, gc, - (int)(DISPLAY_OFFSET_X - i), + XDrawLine(dpy, keypad->pixmap, gc, (int)(DISPLAY_OFFSET_X - i), (int)(DISPLAY_OFFSET_Y + display_height + 2 * i), (int)(DISPLAY_OFFSET_X + display_width + i), (int)(DISPLAY_OFFSET_Y + display_height + 2 * i)); - XDrawLine(dpy, keypad->pixmap, gc, - (int)(DISPLAY_OFFSET_X - i), + XDrawLine(dpy, keypad->pixmap, gc, (int)(DISPLAY_OFFSET_X - i), (int)(DISPLAY_OFFSET_Y + display_height + 2 * i + 1), (int)(DISPLAY_OFFSET_X + display_width + i), (int)(DISPLAY_OFFSET_Y + display_height + 2 * i + 1)); XDrawLine(dpy, keypad->pixmap, gc, - (int)(DISPLAY_OFFSET_X + display_width + i), - (int)(DISPLAY_OFFSET_Y - i), - (int)(DISPLAY_OFFSET_X + display_width + i), - (int)(DISPLAY_OFFSET_Y + display_height + 2 * i)); + (int)(DISPLAY_OFFSET_X + display_width + i), + (int)(DISPLAY_OFFSET_Y - i), + (int)(DISPLAY_OFFSET_X + display_width + i), + (int)(DISPLAY_OFFSET_Y + display_height + 2 * i)); } XSetForeground(dpy, gc, COLOR(DISP_PAD_BOT)); for (i = 0; i < DISP_FRAME; i++) { - XDrawLine(dpy, keypad->pixmap, gc, - (int)(DISPLAY_OFFSET_X - i - 1), + XDrawLine(dpy, keypad->pixmap, gc, (int)(DISPLAY_OFFSET_X - i - 1), (int)(DISPLAY_OFFSET_Y - i - 1), (int)(DISPLAY_OFFSET_X + display_width + i - 1), (int)(DISPLAY_OFFSET_Y - i - 1)); - XDrawLine(dpy, keypad->pixmap, gc, - (int)(DISPLAY_OFFSET_X - i - 1), - (int)(DISPLAY_OFFSET_Y - i - 1), - (int)(DISPLAY_OFFSET_X - i - 1), - (int)(DISPLAY_OFFSET_Y + display_height + 2 * i - 1)); + XDrawLine(dpy, keypad->pixmap, gc, (int)(DISPLAY_OFFSET_X - i - 1), + (int)(DISPLAY_OFFSET_Y - i - 1), (int)(DISPLAY_OFFSET_X - i - 1), + (int)(DISPLAY_OFFSET_Y + display_height + 2 * i - 1)); } /* @@ -1944,100 +2103,88 @@ CreateBezel(unsigned int width, unsigned int height, unsigned int offset_y, unsi */ XSetForeground(dpy, gc, COLOR(DISP_PAD)); - XDrawLine(dpy, keypad->pixmap, gc, + XDrawLine(dpy, keypad->pixmap, gc, (int)(DISPLAY_OFFSET_X - DISP_FRAME), + (int)(DISPLAY_OFFSET_Y - DISP_FRAME), + (int)(DISPLAY_OFFSET_X - DISP_FRAME + 3), + (int)(DISPLAY_OFFSET_Y - DISP_FRAME)); + XDrawLine(dpy, keypad->pixmap, gc, (int)(DISPLAY_OFFSET_X - DISP_FRAME), + (int)(DISPLAY_OFFSET_Y - DISP_FRAME), (int)(DISPLAY_OFFSET_X - DISP_FRAME), - (int)(DISPLAY_OFFSET_Y - DISP_FRAME), - (int)(DISPLAY_OFFSET_X - DISP_FRAME + 3), - (int)(DISPLAY_OFFSET_Y - DISP_FRAME)); - XDrawLine(dpy, keypad->pixmap, gc, - (int)(DISPLAY_OFFSET_X - DISP_FRAME), - (int)(DISPLAY_OFFSET_Y - DISP_FRAME), - (int)(DISPLAY_OFFSET_X - DISP_FRAME), - (int)(DISPLAY_OFFSET_Y - DISP_FRAME + 3)); - XDrawPoint(dpy, keypad->pixmap, gc, - (int)(DISPLAY_OFFSET_X - DISP_FRAME + 1), - (int)(DISPLAY_OFFSET_Y - DISP_FRAME + 1)); + (int)(DISPLAY_OFFSET_Y - DISP_FRAME + 3)); + XDrawPoint(dpy, keypad->pixmap, gc, (int)(DISPLAY_OFFSET_X - DISP_FRAME + 1), + (int)(DISPLAY_OFFSET_Y - DISP_FRAME + 1)); XDrawLine(dpy, keypad->pixmap, gc, (int)(DISPLAY_OFFSET_X + display_width + DISP_FRAME - 4), - (int)(DISPLAY_OFFSET_Y - DISP_FRAME), - (int)(DISPLAY_OFFSET_X + display_width + DISP_FRAME - 1), - (int)(DISPLAY_OFFSET_Y - DISP_FRAME)); + (int)(DISPLAY_OFFSET_Y - DISP_FRAME), + (int)(DISPLAY_OFFSET_X + display_width + DISP_FRAME - 1), + (int)(DISPLAY_OFFSET_Y - DISP_FRAME)); XDrawLine(dpy, keypad->pixmap, gc, - (int)(DISPLAY_OFFSET_X + display_width + DISP_FRAME - 1), - (int)(DISPLAY_OFFSET_Y - DISP_FRAME), - (int)(DISPLAY_OFFSET_X + display_width + DISP_FRAME - 1), - (int)(DISPLAY_OFFSET_Y - DISP_FRAME + 3)); + (int)(DISPLAY_OFFSET_X + display_width + DISP_FRAME - 1), + (int)(DISPLAY_OFFSET_Y - DISP_FRAME), + (int)(DISPLAY_OFFSET_X + display_width + DISP_FRAME - 1), + (int)(DISPLAY_OFFSET_Y - DISP_FRAME + 3)); XDrawPoint(dpy, keypad->pixmap, gc, - (int)(DISPLAY_OFFSET_X + display_width + DISP_FRAME - 2), - (int)(DISPLAY_OFFSET_Y - DISP_FRAME + 1)); + (int)(DISPLAY_OFFSET_X + display_width + DISP_FRAME - 2), + (int)(DISPLAY_OFFSET_Y - DISP_FRAME + 1)); + + XDrawLine(dpy, keypad->pixmap, gc, (int)(DISPLAY_OFFSET_X - DISP_FRAME), + (int)(DISPLAY_OFFSET_Y + display_height + 2 * DISP_FRAME - 4), + (int)(DISPLAY_OFFSET_X - DISP_FRAME), + (int)(DISPLAY_OFFSET_Y + display_height + 2 * DISP_FRAME - 1)); + XDrawLine(dpy, keypad->pixmap, gc, (int)(DISPLAY_OFFSET_X - DISP_FRAME), + (int)(DISPLAY_OFFSET_Y + display_height + 2 * DISP_FRAME - 1), + (int)(DISPLAY_OFFSET_X - DISP_FRAME + 3), + (int)(DISPLAY_OFFSET_Y + display_height + 2 * DISP_FRAME - 1)); + XDrawPoint(dpy, keypad->pixmap, gc, (int)(DISPLAY_OFFSET_X - DISP_FRAME + 1), + (int)(DISPLAY_OFFSET_Y + display_height + 2 * DISP_FRAME - 2)); XDrawLine(dpy, keypad->pixmap, gc, - (int)(DISPLAY_OFFSET_X - DISP_FRAME), - (int)(DISPLAY_OFFSET_Y + display_height + 2 * DISP_FRAME - 4), - (int)(DISPLAY_OFFSET_X - DISP_FRAME), - (int)(DISPLAY_OFFSET_Y + display_height + 2 * DISP_FRAME - 1)); + (int)(DISPLAY_OFFSET_X + display_width + DISP_FRAME - 1), + (int)(DISPLAY_OFFSET_Y + display_height + 2 * DISP_FRAME - 4), + (int)(DISPLAY_OFFSET_X + display_width + DISP_FRAME - 1), + (int)(DISPLAY_OFFSET_Y + display_height + 2 * DISP_FRAME - 1)); XDrawLine(dpy, keypad->pixmap, gc, - (int)(DISPLAY_OFFSET_X - DISP_FRAME), - (int)(DISPLAY_OFFSET_Y + display_height + 2 * DISP_FRAME - 1), - (int)(DISPLAY_OFFSET_X - DISP_FRAME + 3), - (int)(DISPLAY_OFFSET_Y + display_height + 2 * DISP_FRAME - 1)); + (int)(DISPLAY_OFFSET_X + display_width + DISP_FRAME - 4), + (int)(DISPLAY_OFFSET_Y + display_height + 2 * DISP_FRAME - 1), + (int)(DISPLAY_OFFSET_X + display_width + DISP_FRAME - 1), + (int)(DISPLAY_OFFSET_Y + display_height + 2 * DISP_FRAME - 1)); XDrawPoint(dpy, keypad->pixmap, gc, - (int)(DISPLAY_OFFSET_X - DISP_FRAME + 1), - (int)(DISPLAY_OFFSET_Y + display_height + 2 * DISP_FRAME - 2)); - - XDrawLine(dpy, keypad->pixmap, gc, - (int)(DISPLAY_OFFSET_X + display_width + DISP_FRAME - 1), - (int)(DISPLAY_OFFSET_Y + display_height + 2 * DISP_FRAME - 4), - (int)(DISPLAY_OFFSET_X + display_width + DISP_FRAME - 1), - (int)(DISPLAY_OFFSET_Y + display_height + 2 * DISP_FRAME - 1)); - XDrawLine(dpy, keypad->pixmap, gc, - (int)(DISPLAY_OFFSET_X + display_width + DISP_FRAME - 4), - (int)(DISPLAY_OFFSET_Y + display_height + 2 * DISP_FRAME - 1), - (int)(DISPLAY_OFFSET_X + display_width + DISP_FRAME - 1), - (int)(DISPLAY_OFFSET_Y + display_height + 2 * DISP_FRAME - 1)); - XDrawPoint(dpy, keypad->pixmap, gc, - (int)(DISPLAY_OFFSET_X + display_width + DISP_FRAME - 2), - (int)(DISPLAY_OFFSET_Y + display_height + 2 * DISP_FRAME - 2)); + (int)(DISPLAY_OFFSET_X + display_width + DISP_FRAME - 2), + (int)(DISPLAY_OFFSET_Y + display_height + 2 * DISP_FRAME - 2)); /* * simulate rounded lcd corners */ XSetForeground(dpy, gc, COLOR(LCD)); - XDrawLine(dpy, keypad->pixmap, gc, - (int)(DISPLAY_OFFSET_X - 1), - (int)(DISPLAY_OFFSET_Y + 1), - (int)(DISPLAY_OFFSET_X - 1), + XDrawLine(dpy, keypad->pixmap, gc, (int)(DISPLAY_OFFSET_X - 1), + (int)(DISPLAY_OFFSET_Y + 1), (int)(DISPLAY_OFFSET_X - 1), (int)(DISPLAY_OFFSET_Y + display_height - 2)); - XDrawLine(dpy, keypad->pixmap, gc, - (int)(DISPLAY_OFFSET_X + 1), - (int)(DISPLAY_OFFSET_Y - 1), + XDrawLine(dpy, keypad->pixmap, gc, (int)(DISPLAY_OFFSET_X + 1), + (int)(DISPLAY_OFFSET_Y - 1), (int)(DISPLAY_OFFSET_X + display_width - 2), (int)(DISPLAY_OFFSET_Y - 1)); - XDrawLine(dpy, keypad->pixmap, gc, - (int)(DISPLAY_OFFSET_X + 1), - (int)(DISPLAY_OFFSET_Y + display_height), - (int)(DISPLAY_OFFSET_X + display_width - 2), - (int)(DISPLAY_OFFSET_Y + display_height)); - XDrawLine(dpy, keypad->pixmap, gc, + XDrawLine(dpy, keypad->pixmap, gc, (int)(DISPLAY_OFFSET_X + 1), + (int)(DISPLAY_OFFSET_Y + display_height), + (int)(DISPLAY_OFFSET_X + display_width - 2), + (int)(DISPLAY_OFFSET_Y + display_height)); + XDrawLine(dpy, keypad->pixmap, gc, (int)(DISPLAY_OFFSET_X + display_width), + (int)(DISPLAY_OFFSET_Y + 1), (int)(DISPLAY_OFFSET_X + display_width), - (int)(DISPLAY_OFFSET_Y + 1), - (int)(DISPLAY_OFFSET_X + display_width), - (int)(DISPLAY_OFFSET_Y + display_height - 2)); + (int)(DISPLAY_OFFSET_Y + display_height - 2)); return; } -void -DrawMore(unsigned int w, unsigned int h, unsigned int offset_y, unsigned int offset_x, keypad_t *keypad) -{ +void DrawMore(unsigned int w, unsigned int h, unsigned int offset_y, + unsigned int offset_x, keypad_t *keypad) { Pixmap pix; int cut; int x, y; int display_height = DISPLAY_HEIGHT; - int display_width = DISPLAY_WIDTH; + int display_width = DISPLAY_WIDTH; /* * lower the whole thing */ @@ -2046,23 +2193,23 @@ DrawMore(unsigned int w, unsigned int h, unsigned int offset_y, unsigned int off /* bottom lines */ int keypad_width = keypad->width; XDrawLine(dpy, keypad->pixmap, gc, 1, (int)(keypad->height - 1), - (int)(keypad_width - 1), (int)(keypad->height - 1)); + (int)(keypad_width - 1), (int)(keypad->height - 1)); XDrawLine(dpy, keypad->pixmap, gc, 2, (int)(keypad->height - 2), - (int)(keypad_width - 2), (int)(keypad->height - 2)); + (int)(keypad_width - 2), (int)(keypad->height - 2)); /* right lines */ XDrawLine(dpy, keypad->pixmap, gc, (int)(keypad->width - 1), - (int)(keypad->height - 1), (int)(keypad->width - 1), cut); + (int)(keypad->height - 1), (int)(keypad->width - 1), cut); XDrawLine(dpy, keypad->pixmap, gc, (int)(keypad->width - 2), - (int)(keypad->height - 2), (int)(keypad->width - 2), cut); + (int)(keypad->height - 2), (int)(keypad->width - 2), cut); XSetForeground(dpy, gc, COLOR(DISP_PAD_TOP)); /* right lines */ - XDrawLine(dpy, keypad->pixmap, gc, (int)(keypad->width - 1), - cut - 1, (int)(keypad->width - 1), 1); - XDrawLine(dpy, keypad->pixmap, gc, (int)(keypad->width - 2), - cut - 1, (int)(keypad->width - 2), 2); + XDrawLine(dpy, keypad->pixmap, gc, (int)(keypad->width - 1), cut - 1, + (int)(keypad->width - 1), 1); + XDrawLine(dpy, keypad->pixmap, gc, (int)(keypad->width - 2), cut - 1, + (int)(keypad->width - 2), 2); XSetForeground(dpy, gc, COLOR(DISP_PAD_BOT)); @@ -2087,31 +2234,31 @@ DrawMore(unsigned int w, unsigned int h, unsigned int offset_y, unsigned int off /* bottom lines */ XDrawLine(dpy, keypad->pixmap, gc, 3, (int)(keypad->height - 3), - (int)(keypad->width - 3), (int)(keypad->height - 3)); + (int)(keypad->width - 3), (int)(keypad->height - 3)); XDrawLine(dpy, keypad->pixmap, gc, 4, (int)(keypad->height - 4), - (int)(keypad->width - 4), (int)(keypad->height - 4)); + (int)(keypad->width - 4), (int)(keypad->height - 4)); /* right lines */ XDrawLine(dpy, keypad->pixmap, gc, (int)(keypad->width - 3), - (int)(keypad->height - 3), (int)(keypad->width - 3), cut); + (int)(keypad->height - 3), (int)(keypad->width - 3), cut); XDrawLine(dpy, keypad->pixmap, gc, (int)(keypad->width - 4), - (int)(keypad->height - 4), (int)(keypad->width - 4), cut); + (int)(keypad->height - 4), (int)(keypad->width - 4), cut); XSetForeground(dpy, gc, COLOR(DISP_PAD_TOP)); /* right lines */ - XDrawLine(dpy, keypad->pixmap, gc, (int)(keypad->width - 3), - cut - 1, (int)(keypad->width - 3), offset_y - 24); - XDrawLine(dpy, keypad->pixmap, gc, (int)(keypad->width - 4), - cut - 1, (int)(keypad->width - 4), offset_y - 23); + XDrawLine(dpy, keypad->pixmap, gc, (int)(keypad->width - 3), cut - 1, + (int)(keypad->width - 3), offset_y - 24); + XDrawLine(dpy, keypad->pixmap, gc, (int)(keypad->width - 4), cut - 1, + (int)(keypad->width - 4), offset_y - 23); XSetForeground(dpy, gc, COLOR(DISP_PAD_BOT)); /* top lines */ - XDrawLine(dpy, keypad->pixmap, gc, 2, offset_y - 25, - (int)(keypad->width - 4), offset_y - 25); - XDrawLine(dpy, keypad->pixmap, gc, 3, offset_y - 24, - (int)(keypad->width - 5), offset_y - 24); + XDrawLine(dpy, keypad->pixmap, gc, 2, offset_y - 25, (int)(keypad->width - 4), + offset_y - 25); + XDrawLine(dpy, keypad->pixmap, gc, 3, offset_y - 24, (int)(keypad->width - 5), + offset_y - 24); /* left lines */ XDrawLine(dpy, keypad->pixmap, gc, 2, cut - 1, 2, offset_y - 24); @@ -2130,23 +2277,22 @@ DrawMore(unsigned int w, unsigned int h, unsigned int offset_y, unsigned int off /* bottom lines */ XDrawLine(dpy, keypad->pixmap, gc, 5, (int)(keypad->height - 5), - (int)(keypad->width - 3), (int)(keypad->height - 5)); + (int)(keypad->width - 3), (int)(keypad->height - 5)); XDrawLine(dpy, keypad->pixmap, gc, 6, (int)(keypad->height - 6), - (int)(keypad->width - 4), (int)(keypad->height - 6)); + (int)(keypad->width - 4), (int)(keypad->height - 6)); /* right lines */ XDrawLine(dpy, keypad->pixmap, gc, (int)(keypad->width - 5), - (int)(keypad->height - 5), (int)(keypad->width - 5), cut + 1); + (int)(keypad->height - 5), (int)(keypad->width - 5), cut + 1); XDrawLine(dpy, keypad->pixmap, gc, (int)(keypad->width - 6), - (int)(keypad->height - 6), (int)(keypad->width - 6), cut + 2); + (int)(keypad->height - 6), (int)(keypad->width - 6), cut + 2); XSetForeground(dpy, gc, COLOR(DISP_PAD_BOT)); /* top lines */ - XDrawLine(dpy, keypad->pixmap, gc, 4, cut, - (int)(keypad->width - 6), cut); - XDrawLine(dpy, keypad->pixmap, gc, 5, cut + 1, - (int)(keypad->width - 7), cut + 1); + XDrawLine(dpy, keypad->pixmap, gc, 4, cut, (int)(keypad->width - 6), cut); + XDrawLine(dpy, keypad->pixmap, gc, 5, cut + 1, (int)(keypad->width - 7), + cut + 1); XSetForeground(dpy, gc, COLOR(PAD_BOT)); @@ -2171,8 +2317,8 @@ DrawMore(unsigned int w, unsigned int h, unsigned int offset_y, unsigned int off XDrawLine(dpy, keypad->pixmap, gc, (int)(keypad->width - 7), (int)(keypad->height - 8), (int)(keypad->width - 11), (int)(keypad->height - 8)); - XDrawPoint(dpy, keypad->pixmap, gc, - (int)(keypad->width - 9), (int)(keypad->height - 9)); + XDrawPoint(dpy, keypad->pixmap, gc, (int)(keypad->width - 9), + (int)(keypad->height - 9)); XDrawLine(dpy, keypad->pixmap, gc, 7, (int)(keypad->height - 7), 13, (int)(keypad->height - 7)); @@ -2191,32 +2337,30 @@ DrawMore(unsigned int w, unsigned int h, unsigned int offset_y, unsigned int off XSetBackground(dpy, gc, COLOR(LOGO_BACK)); XSetForeground(dpy, gc, COLOR(LOGO)); - pix = XCreateBitmapFromData(dpy, keypad->pixmap, (char *)hp_bits, - hp_width, hp_height); + pix = XCreateBitmapFromData(dpy, keypad->pixmap, (char *)hp_bits, hp_width, + hp_height); if (opt_gx) x = DISPLAY_OFFSET_X - 6; else x = DISPLAY_OFFSET_X; - XCopyPlane(dpy, pix, keypad->pixmap, gc, 0, 0, hp_width, hp_height, - x, 10, 1); + XCopyPlane(dpy, pix, keypad->pixmap, gc, 0, 0, hp_width, hp_height, x, 10, 1); XFreePixmap(dpy, pix); - if (!opt_gx) - { - XSetForeground(dpy, gc, COLOR(FRAME)); + if (!opt_gx) { + XSetForeground(dpy, gc, COLOR(FRAME)); - XDrawLine(dpy, keypad->pixmap, gc, (int)DISPLAY_OFFSET_X, 9, - (int)(DISPLAY_OFFSET_X + hp_width - 1), 9); - XDrawLine(dpy, keypad->pixmap, gc, (int)(DISPLAY_OFFSET_X - 1), 10, - (int)(DISPLAY_OFFSET_X - 1), 10 + hp_height - 1); - XDrawLine(dpy, keypad->pixmap, gc, (int)DISPLAY_OFFSET_X, 10 + hp_height, - (int)(DISPLAY_OFFSET_X + hp_width - 1), 10 + hp_height); - XDrawLine(dpy, keypad->pixmap, gc, (int)(DISPLAY_OFFSET_X + hp_width), 10, - (int)(DISPLAY_OFFSET_X + hp_width), 10 + hp_height - 1); - } + XDrawLine(dpy, keypad->pixmap, gc, (int)DISPLAY_OFFSET_X, 9, + (int)(DISPLAY_OFFSET_X + hp_width - 1), 9); + XDrawLine(dpy, keypad->pixmap, gc, (int)(DISPLAY_OFFSET_X - 1), 10, + (int)(DISPLAY_OFFSET_X - 1), 10 + hp_height - 1); + XDrawLine(dpy, keypad->pixmap, gc, (int)DISPLAY_OFFSET_X, 10 + hp_height, + (int)(DISPLAY_OFFSET_X + hp_width - 1), 10 + hp_height); + XDrawLine(dpy, keypad->pixmap, gc, (int)(DISPLAY_OFFSET_X + hp_width), 10, + (int)(DISPLAY_OFFSET_X + hp_width), 10 + hp_height - 1); + } /* * write the name of it @@ -2224,75 +2368,72 @@ DrawMore(unsigned int w, unsigned int h, unsigned int offset_y, unsigned int off XSetBackground(dpy, gc, COLOR(DISP_PAD)); XSetForeground(dpy, gc, COLOR(LABEL)); - if (opt_gx) - { - x = DISPLAY_OFFSET_X + display_width - gx_128K_ram_width - + gx_128K_ram_x_hot + 2; - y = 10 + gx_128K_ram_y_hot; - pix = XCreateBitmapFromData(dpy, keypad->pixmap, (char *)gx_128K_ram_bits, - gx_128K_ram_width, gx_128K_ram_height); - XCopyPlane(dpy, pix, keypad->pixmap, gc, 0, 0, gx_128K_ram_width, - gx_128K_ram_height, x, y, 1); - XFreePixmap(dpy, pix); + if (opt_gx) { + x = DISPLAY_OFFSET_X + display_width - gx_128K_ram_width + + gx_128K_ram_x_hot + 2; + y = 10 + gx_128K_ram_y_hot; + pix = XCreateBitmapFromData(dpy, keypad->pixmap, (char *)gx_128K_ram_bits, + gx_128K_ram_width, gx_128K_ram_height); + XCopyPlane(dpy, pix, keypad->pixmap, gc, 0, 0, gx_128K_ram_width, + gx_128K_ram_height, x, y, 1); + XFreePixmap(dpy, pix); - XSetForeground(dpy, gc, COLOR(LOGO)); - x = DISPLAY_OFFSET_X + hp_width; - y = hp_height + 8 - hp48gx_height; - pix = XCreateBitmapFromData(dpy, keypad->pixmap, (char *)hp48gx_bits, - hp48gx_width, hp48gx_height); - XCopyPlane(dpy, pix, keypad->pixmap, gc, 0, 0, hp48gx_width, - hp48gx_height, x, y, 1); - XFreePixmap(dpy, pix); + XSetForeground(dpy, gc, COLOR(LOGO)); + x = DISPLAY_OFFSET_X + hp_width; + y = hp_height + 8 - hp48gx_height; + pix = XCreateBitmapFromData(dpy, keypad->pixmap, (char *)hp48gx_bits, + hp48gx_width, hp48gx_height); + XCopyPlane(dpy, pix, keypad->pixmap, gc, 0, 0, hp48gx_width, hp48gx_height, + x, y, 1); + XFreePixmap(dpy, pix); - XSetFillStyle(dpy, gc, FillStippled); - x = DISPLAY_OFFSET_X + DISPLAY_WIDTH - gx_128K_ram_width - + gx_silver_x_hot + 2; - y = 10 + gx_silver_y_hot; - pix = XCreateBitmapFromData(dpy, keypad->pixmap, (char *)gx_silver_bits, - gx_silver_width, gx_silver_height); - XSetStipple(dpy, gc, pix); - XSetTSOrigin(dpy, gc, x, y); - XFillRectangle(dpy, keypad->pixmap, gc, x, y, gx_silver_width, - gx_silver_height); - XFreePixmap(dpy, pix); + XSetFillStyle(dpy, gc, FillStippled); + x = DISPLAY_OFFSET_X + DISPLAY_WIDTH - gx_128K_ram_width + gx_silver_x_hot + + 2; + y = 10 + gx_silver_y_hot; + pix = XCreateBitmapFromData(dpy, keypad->pixmap, (char *)gx_silver_bits, + gx_silver_width, gx_silver_height); + XSetStipple(dpy, gc, pix); + XSetTSOrigin(dpy, gc, x, y); + XFillRectangle(dpy, keypad->pixmap, gc, x, y, gx_silver_width, + gx_silver_height); + XFreePixmap(dpy, pix); - XSetForeground(dpy, gc, COLOR(RIGHT)); - x = DISPLAY_OFFSET_X + display_width - gx_128K_ram_width - + gx_green_x_hot + 2; - y = 10 + gx_green_y_hot; - pix = XCreateBitmapFromData(dpy, keypad->pixmap, (char *)gx_green_bits, - gx_green_width, gx_green_height); - XSetStipple(dpy, gc, pix); - XSetTSOrigin(dpy, gc, x, y); - XFillRectangle(dpy, keypad->pixmap, gc, x, y, gx_green_width, - gx_green_height); - XFreePixmap(dpy, pix); + XSetForeground(dpy, gc, COLOR(RIGHT)); + x = DISPLAY_OFFSET_X + display_width - gx_128K_ram_width + gx_green_x_hot + + 2; + y = 10 + gx_green_y_hot; + pix = XCreateBitmapFromData(dpy, keypad->pixmap, (char *)gx_green_bits, + gx_green_width, gx_green_height); + XSetStipple(dpy, gc, pix); + XSetTSOrigin(dpy, gc, x, y); + XFillRectangle(dpy, keypad->pixmap, gc, x, y, gx_green_width, + gx_green_height); + XFreePixmap(dpy, pix); - XSetTSOrigin(dpy, gc, 0, 0); - XSetFillStyle(dpy, gc, FillSolid); - } - else - { - x = DISPLAY_OFFSET_X; - y = TOP_SKIP - DISP_FRAME - hp48sx_height - 3; + XSetTSOrigin(dpy, gc, 0, 0); + XSetFillStyle(dpy, gc, FillSolid); + } else { + x = DISPLAY_OFFSET_X; + y = TOP_SKIP - DISP_FRAME - hp48sx_height - 3; - pix = XCreateBitmapFromData(dpy, keypad->pixmap, (char *)hp48sx_bits, - hp48sx_width, hp48sx_height); + pix = XCreateBitmapFromData(dpy, keypad->pixmap, (char *)hp48sx_bits, + hp48sx_width, hp48sx_height); - XCopyPlane(dpy, pix, keypad->pixmap, gc, 0, 0, hp48sx_width, - hp48sx_height, x, y, 1); + XCopyPlane(dpy, pix, keypad->pixmap, gc, 0, 0, hp48sx_width, hp48sx_height, + x, y, 1); - XFreePixmap(dpy, pix); + XFreePixmap(dpy, pix); - x = DISPLAY_OFFSET_X + display_width - 1 - science_width; - y = TOP_SKIP - DISP_FRAME - science_height - 4; + x = DISPLAY_OFFSET_X + display_width - 1 - science_width; + y = TOP_SKIP - DISP_FRAME - science_height - 4; - pix = XCreateBitmapFromData(dpy, keypad->pixmap, (char *)science_bits, - science_width, science_height); + pix = XCreateBitmapFromData(dpy, keypad->pixmap, (char *)science_bits, + science_width, science_height); - XCopyPlane(dpy, pix, keypad->pixmap, gc, 0, 0, science_width, - science_height, x, y, 1); - } + XCopyPlane(dpy, pix, keypad->pixmap, gc, 0, 0, science_width, + science_height, x, y, 1); + } /* * that's it. Ooph. @@ -2301,95 +2442,85 @@ DrawMore(unsigned int w, unsigned int h, unsigned int offset_y, unsigned int off } void DrawKeypad(keypad_t *keypad) { - XCopyArea(dpy, keypad->pixmap, mainW, gc, 0, 0, keypad->width, - keypad->height, 0, 0); + XCopyArea(dpy, keypad->pixmap, mainW, gc, 0, 0, keypad->width, keypad->height, + 0, 0); return; } void CreateIcon(void) { XSetWindowAttributes xswa; - XWindowAttributes xwa; - Pixmap tmp_pix; - int p; + XWindowAttributes xwa; + Pixmap tmp_pix; + int p; XGetWindowAttributes(dpy, iconW, &xwa); xswa.event_mask = xwa.your_event_mask | ExposureMask; xswa.backing_store = Always; - XChangeWindowAttributes(dpy, iconW, CWEventMask|CWBackingStore, &xswa); + XChangeWindowAttributes(dpy, iconW, CWEventMask | CWBackingStore, &xswa); - icon_pix = XCreatePixmap(dpy, iconW, hp48_icon_width, - hp48_icon_height, depth); + icon_pix = + XCreatePixmap(dpy, iconW, hp48_icon_width, hp48_icon_height, depth); /* * draw the icon pixmap */ - if (icon_color_mode == COLOR_MODE_MONO) - { - tmp_pix = XCreateBitmapFromData(dpy, iconW, - (char *)icon_maps[ICON_MAP].bits, - icon_maps[ICON_MAP].w, - icon_maps[ICON_MAP].h); - XSetForeground(dpy, gc, COLOR(BLACK)); - XSetBackground(dpy, gc, COLOR(WHITE)); - XCopyPlane(dpy, tmp_pix, icon_pix, gc, 0, 0, - icon_maps[ICON_MAP].w, icon_maps[ICON_MAP].h, 0, 0, 1); + if (icon_color_mode == COLOR_MODE_MONO) { + tmp_pix = + XCreateBitmapFromData(dpy, iconW, (char *)icon_maps[ICON_MAP].bits, + icon_maps[ICON_MAP].w, icon_maps[ICON_MAP].h); + XSetForeground(dpy, gc, COLOR(BLACK)); + XSetBackground(dpy, gc, COLOR(WHITE)); + XCopyPlane(dpy, tmp_pix, icon_pix, gc, 0, 0, icon_maps[ICON_MAP].w, + icon_maps[ICON_MAP].h, 0, 0, 1); + XFreePixmap(dpy, tmp_pix); + } else { + XSetFillStyle(dpy, gc, FillStippled); + for (p = FIRST_MAP; p <= LAST_MAP; p++) { + tmp_pix = XCreateBitmapFromData(dpy, iconW, (char *)icon_maps[p].bits, + icon_maps[p].w, icon_maps[p].h); + XSetStipple(dpy, gc, tmp_pix); + XSetForeground(dpy, gc, COLOR(icon_maps[p].c)); + XFillRectangle(dpy, icon_pix, gc, 0, 0, icon_maps[p].w, icon_maps[p].h); XFreePixmap(dpy, tmp_pix); } - else - { - XSetFillStyle(dpy, gc, FillStippled); - for (p = FIRST_MAP; p <= LAST_MAP; p++) - { - tmp_pix = XCreateBitmapFromData(dpy, iconW, - (char *)icon_maps[p].bits, - icon_maps[p].w, - icon_maps[p].h); - XSetStipple(dpy, gc, tmp_pix); - XSetForeground(dpy, gc, COLOR(icon_maps[p].c)); - XFillRectangle(dpy, icon_pix, gc, 0, 0, - icon_maps[p].w, icon_maps[p].h); - XFreePixmap(dpy, tmp_pix); - } - XSetFillStyle(dpy, gc, FillSolid); + XSetFillStyle(dpy, gc, FillSolid); - /* - * draw frame around icon - */ - XSetForeground(dpy, gc, COLOR(BLACK)); - XDrawRectangle(dpy, icon_pix, gc, 0, 0, icon_maps[ICON_MAP].w - 1, - icon_maps[ICON_MAP].h - 1); - } + /* + * draw frame around icon + */ + XSetForeground(dpy, gc, COLOR(BLACK)); + XDrawRectangle(dpy, icon_pix, gc, 0, 0, icon_maps[ICON_MAP].w - 1, + icon_maps[ICON_MAP].h - 1); + } /* * draw the display */ XSetFillStyle(dpy, gc, FillStippled); - icon_disp_pix = XCreateBitmapFromData(dpy, iconW, - (char *)icon_maps[DISP_MAP].bits, - icon_maps[DISP_MAP].w, - icon_maps[DISP_MAP].h); + icon_disp_pix = + XCreateBitmapFromData(dpy, iconW, (char *)icon_maps[DISP_MAP].bits, + icon_maps[DISP_MAP].w, icon_maps[DISP_MAP].h); XSetStipple(dpy, gc, icon_disp_pix); if (icon_color_mode == COLOR_MODE_MONO) XSetForeground(dpy, gc, COLOR(WHITE)); else XSetForeground(dpy, gc, COLOR(icon_maps[DISP_MAP].c)); - XFillRectangle(dpy, icon_pix, gc, 0, 0, - icon_maps[DISP_MAP].w, icon_maps[DISP_MAP].h); + XFillRectangle(dpy, icon_pix, gc, 0, 0, icon_maps[DISP_MAP].w, + icon_maps[DISP_MAP].h); /* * draw the 'x48' string */ - icon_text_pix = XCreateBitmapFromData(dpy, iconW, - (char *)icon_maps[ON_MAP].bits, - icon_maps[ON_MAP].w, - icon_maps[ON_MAP].h); + icon_text_pix = + XCreateBitmapFromData(dpy, iconW, (char *)icon_maps[ON_MAP].bits, + icon_maps[ON_MAP].w, icon_maps[ON_MAP].h); XSetStipple(dpy, gc, icon_text_pix); if (icon_color_mode == COLOR_MODE_MONO) XSetForeground(dpy, gc, COLOR(BLACK)); else XSetForeground(dpy, gc, COLOR(icon_maps[ON_MAP].c)); - XFillRectangle(dpy, icon_pix, gc, 0, 0, - icon_maps[ON_MAP].w, icon_maps[ON_MAP].h); + XFillRectangle(dpy, icon_pix, gc, 0, 0, icon_maps[ON_MAP].w, + icon_maps[ON_MAP].h); XSetFillStyle(dpy, gc, FillSolid); return; @@ -2399,50 +2530,46 @@ void refresh_icon(void) { int icon_state; icon_state = ((display.on && !((ANN_IO & display.annunc) == ANN_IO)) || - (display.on && !((ANN_ALPHA & display.annunc) == ANN_ALPHA))); + (display.on && !((ANN_ALPHA & display.annunc) == ANN_ALPHA))); if (icon_state == last_icon_state) return; last_icon_state = icon_state; XSetFillStyle(dpy, gc, FillStippled); - if (icon_state) - { - /* - * draw the 'x48' string - */ - XSetStipple(dpy, gc, icon_text_pix); - if (icon_color_mode == COLOR_MODE_MONO) - XSetForeground(dpy, gc, COLOR(BLACK)); - else - XSetForeground(dpy, gc, COLOR(icon_maps[ON_MAP].c)); - XFillRectangle(dpy, icon_pix, gc, 0, 0, - icon_maps[ON_MAP].w, icon_maps[ON_MAP].h); - } - else - { - /* - * clear the display - */ - XSetFillStyle(dpy, gc, FillStippled); - XSetStipple(dpy, gc, icon_disp_pix); - if (icon_color_mode == COLOR_MODE_MONO) - XSetForeground(dpy, gc, COLOR(WHITE)); - else - XSetForeground(dpy, gc, COLOR(icon_maps[DISP_MAP].c)); - XFillRectangle(dpy, icon_pix, gc, 0, 0, - icon_maps[DISP_MAP].w, icon_maps[DISP_MAP].h); - } + if (icon_state) { + /* + * draw the 'x48' string + */ + XSetStipple(dpy, gc, icon_text_pix); + if (icon_color_mode == COLOR_MODE_MONO) + XSetForeground(dpy, gc, COLOR(BLACK)); + else + XSetForeground(dpy, gc, COLOR(icon_maps[ON_MAP].c)); + XFillRectangle(dpy, icon_pix, gc, 0, 0, icon_maps[ON_MAP].w, + icon_maps[ON_MAP].h); + } else { + /* + * clear the display + */ + XSetFillStyle(dpy, gc, FillStippled); + XSetStipple(dpy, gc, icon_disp_pix); + if (icon_color_mode == COLOR_MODE_MONO) + XSetForeground(dpy, gc, COLOR(WHITE)); + else + XSetForeground(dpy, gc, COLOR(icon_maps[DISP_MAP].c)); + XFillRectangle(dpy, icon_pix, gc, 0, 0, icon_maps[DISP_MAP].w, + icon_maps[DISP_MAP].h); + } XSetFillStyle(dpy, gc, FillSolid); - if (iconW) - { - XCopyArea(dpy, icon_pix, iconW, gc, 0, 0, - hp48_icon_width, hp48_icon_height, 0, 0); - } + if (iconW) { + XCopyArea(dpy, icon_pix, iconW, gc, 0, 0, hp48_icon_width, hp48_icon_height, + 0, 0); + } } void DrawIcon(void) { - XCopyArea(dpy, icon_pix, iconW, gc, 0, 0, - hp48_icon_width, hp48_icon_height, 0, 0); + XCopyArea(dpy, icon_pix, iconW, gc, 0, 0, hp48_icon_width, hp48_icon_height, + 0, 0); return; } @@ -2465,17 +2592,16 @@ void CreateDispWindow(void) { disp.w = DISPLAY_WIDTH; disp.h = DISPLAY_HEIGHT; - disp.win = XCreateSimpleWindow(dpy, mainW, - (int)DISPLAY_OFFSET_X, (int)DISPLAY_OFFSET_Y, - disp.w, disp.h, 0, - COLOR(BLACK), COLOR(LCD)); + disp.win = XCreateSimpleWindow(dpy, mainW, (int)DISPLAY_OFFSET_X, + (int)DISPLAY_OFFSET_Y, disp.w, disp.h, 0, + COLOR(BLACK), COLOR(LCD)); disp.mapped = 1; xswa.event_mask = ExposureMask | StructureNotifyMask; xswa.backing_store = Always; - XChangeWindowAttributes(dpy, disp.win, CWEventMask|CWBackingStore, &xswa); + XChangeWindowAttributes(dpy, disp.win, CWEventMask | CWBackingStore, &xswa); /* * set up the gc @@ -2516,9 +2642,10 @@ void CreateDispWindow(void) { /* * get ID of shared memory block for DISP */ - disp.disp_info.shmid = shmget(IPC_PRIVATE, - (disp.disp_image->bytes_per_line * disp.disp_image->height), - IPC_CREAT | 0777); + disp.disp_info.shmid = + shmget(IPC_PRIVATE, + (disp.disp_image->bytes_per_line * disp.disp_image->height), + IPC_CREAT | 0777); if (disp.disp_info.shmid < 0) { XDestroyImage(disp.disp_image); disp.disp_image = NULL; @@ -2564,9 +2691,10 @@ void CreateDispWindow(void) { /* * get ID of shared memory block for MENU */ - disp.menu_info.shmid = shmget(IPC_PRIVATE, - (disp.menu_image->bytes_per_line * disp.menu_image->height), - IPC_CREAT | 0777); + disp.menu_info.shmid = + shmget(IPC_PRIVATE, + (disp.menu_image->bytes_per_line * disp.menu_image->height), + IPC_CREAT | 0777); if (disp.menu_info.shmid < 0) { XDestroyImage(disp.disp_image); disp.disp_image = NULL; @@ -2627,7 +2755,7 @@ void CreateDispWindow(void) { CompletionType = XShmGetEventBase(dpy) + ShmCompletion; } - shm_error: +shm_error: XSetErrorHandler(NULL); XFlush(dpy); @@ -2647,72 +2775,66 @@ void CreateDispWindow(void) { } int CreateWindows(int argc, char **argv) { - XSizeHints hint, ih; - XWMHints wmh; - XClassHint clh; - unsigned int class; - XGCValues val; + XSizeHints hint, ih; + XWMHints wmh; + XClassHint clh; + unsigned int class; + XGCValues val; unsigned long gc_mask; - unsigned int mask; + unsigned int mask; XSetWindowAttributes xswa; - XTextProperty wname, iname; - Atom protocols[2]; - char *name, *user_geom, def_geom[40]; - int info, x, y, w, h; - unsigned int width, height; + XTextProperty wname, iname; + Atom protocols[2]; + char *name, *user_geom, def_geom[40]; + int info, x, y, w, h; + unsigned int width, height; - if (opt_gx) - { - buttons = buttons_gx; - colors = colors_gx; - icon_maps = icon_maps_gx; - } - else - { - buttons = buttons_sx; - colors = colors_sx; - icon_maps = icon_maps_sx; - } + if (opt_gx) { + buttons = buttons_gx; + colors = colors_gx; + icon_maps = icon_maps_gx; + } else { + buttons = buttons_sx; + colors = colors_sx; + icon_maps = icon_maps_sx; + } if (netbook) { - int i; - for (i = 0; i < 6; i++) { - buttons[i].x -= 3; - buttons[i].y += 300; - } - for (; i <= LAST_BUTTON; i++) { - buttons[i].x += 317; - buttons[i].y -= 3; - } + int i; + for (i = 0; i < 6; i++) { + buttons[i].x -= 3; + buttons[i].y += 300; + } + for (; i <= LAST_BUTTON; i++) { + buttons[i].x += 317; + buttons[i].y -= 3; + } } class = InputOutput; visual = get_visual_resource(dpy, "visual", "Visual", &depth); - if (visual != DefaultVisual(dpy, screen)) - { - if (visual->class == DirectColor) - cmap = XCreateColormap(dpy, RootWindow(dpy, screen), visual, AllocAll); - else - cmap = XCreateColormap(dpy, RootWindow(dpy, screen), visual, AllocNone); - } - else + if (visual != DefaultVisual(dpy, screen)) { + if (visual->class == DirectColor) + cmap = XCreateColormap(dpy, RootWindow(dpy, screen), visual, AllocAll); + else + cmap = XCreateColormap(dpy, RootWindow(dpy, screen), visual, AllocNone); + } else cmap = DefaultColormap(dpy, screen); direct_color = 0; - switch (visual->class) - { - case DirectColor: - direct_color = 1; - case GrayScale: - case PseudoColor: - dynamic_color = 1; - break; - case StaticGray: - case StaticColor: - case TrueColor: - default: - dynamic_color = 0; - break; + switch (visual->class) { + case DirectColor: + direct_color = 1; + case GrayScale: + case PseudoColor: + dynamic_color = 1; + break; + case StaticGray: + case StaticColor: + case TrueColor: + default: + dynamic_color = 0; + break; } if ((visual->class == StaticGray) || (visual->class == GrayScale)) @@ -2731,24 +2853,22 @@ int CreateWindows(int argc, char **argv) { if (get_boolean_resource("monoIcon", "Mono")) icon_color_mode = COLOR_MODE_MONO; - clh.res_name = res_name; clh.res_class = res_class; - if(!XStringListToTextProperty(&progname, 1, &iname)) + if (!XStringListToTextProperty(&progname, 1, &iname)) return -1; - if ((name = get_string_resource("title", "Title")) == (char *)0) - { - name = (char *)malloc(128); - if (name == (char *)0) { - sprintf(errbuf, "malloc failed.\n"); - fatal_exit(); - } - sprintf(name, "%s-%d.%d.%d", progname, saturn.version[0], - saturn.version[1], saturn.version[2]); + if ((name = get_string_resource("title", "Title")) == (char *)0) { + name = (char *)malloc(128); + if (name == (char *)0) { + sprintf(errbuf, "malloc failed.\n"); + fatal_exit(); } + sprintf(name, "%s-%d.%d.%d", progname, saturn.version[0], saturn.version[1], + saturn.version[2]); + } - if(!XStringListToTextProperty(&name, 1, &wname)) + if (!XStringListToTextProperty(&name, 1, &wname)) return -1; /* @@ -2762,15 +2882,14 @@ int CreateWindows(int argc, char **argv) { */ width = KEYBOARD_WIDTH + 2 * SIDE_SKIP; if (netbook) { - height = KEYBOARD_HEIGHT; + height = KEYBOARD_HEIGHT; } else { - height = DISPLAY_OFFSET_Y + DISPLAY_HEIGHT + DISP_KBD_SKIP + KEYBOARD_HEIGHT + BOTTOM_SKIP; + height = DISPLAY_OFFSET_Y + DISPLAY_HEIGHT + DISP_KBD_SKIP + + KEYBOARD_HEIGHT + BOTTOM_SKIP; } - mainW = XCreateWindow(dpy, RootWindow(dpy, screen), - 0, 0, width, height, - 0, (int)depth, class, - visual, mask, &xswa); + mainW = XCreateWindow(dpy, RootWindow(dpy, screen), 0, 0, width, height, 0, + (int)depth, class, visual, mask, &xswa); if (mainW == 0) return -1; @@ -2792,17 +2911,16 @@ int CreateWindows(int argc, char **argv) { sprintf(def_geom, "%ux%u", width, height); user_geom = get_string_resource("geometry", "Geometry"); - info = XWMGeometry(dpy, screen, user_geom, def_geom, 0, &hint, - &x, &y, &w, &h, &hint.win_gravity); + info = XWMGeometry(dpy, screen, user_geom, def_geom, 0, &hint, &x, &y, &w, &h, + &hint.win_gravity); - if (info & (XValue | YValue)) - { - if (info & XValue) - hint.x = x; - if (info & YValue) - hint.y = y; - hint.flags |= USPosition; - } + if (info & (XValue | YValue)) { + if (info & XValue) + hint.x = x; + if (info & YValue) + hint.y = y; + hint.flags |= USPosition; + } /* * check if we start iconic @@ -2835,10 +2953,9 @@ int CreateWindows(int argc, char **argv) { */ xswa.colormap = cmap; mask = CWColormap; - iconW = XCreateWindow(dpy, RootWindow(dpy, screen), - 0, 0, hp48_icon_width, hp48_icon_height, - 0, (int)depth, class, - visual, mask, &xswa); + iconW = XCreateWindow(dpy, RootWindow(dpy, screen), 0, 0, hp48_icon_width, + hp48_icon_height, 0, (int)depth, class, visual, mask, + &xswa); if (iconW == 0) return -1; @@ -2857,15 +2974,14 @@ int CreateWindows(int argc, char **argv) { ih.flags = PSize | PMinSize | PMaxSize | PBaseSize | PWinGravity; user_geom = get_string_resource("iconGeom", "IconGeom"); - info = XWMGeometry(dpy, screen, user_geom, (char *)0, 0, &ih, - &x, &y, &w, &h, &ih.win_gravity); + info = XWMGeometry(dpy, screen, user_geom, (char *)0, 0, &ih, &x, &y, &w, &h, + &ih.win_gravity); - if ((info & XValue) && (info & YValue)) - { - wmh.icon_x = x; - wmh.icon_y = y; - wmh.flags |= IconPositionHint; - } + if ((info & XValue) && (info & YValue)) { + wmh.icon_x = x; + wmh.icon_y = y; + wmh.flags |= IconPositionHint; + } /* * set some more attributes of icon window @@ -2933,19 +3049,19 @@ int CreateWindows(int argc, char **argv) { keypad.pixmap = XCreatePixmap(dpy, mainW, width, height, depth); - if (netbook) { - int cut = buttons[BUTTON_MTH].y - (small_ascent + small_descent + 6 + 4); - CreateBackground(width/2, height, width, height, &keypad); - DrawMore(width, height, KEYBOARD_OFFSET_Y, KEYBOARD_OFFSET_X, &keypad); - CreateBezel(width/2, height, KEYBOARD_OFFSET_Y, KEYBOARD_OFFSET_X, &keypad); - CreateKeypad(width, height, -cut, KEYBOARD_OFFSET_X, &keypad); + int cut = buttons[BUTTON_MTH].y - (small_ascent + small_descent + 6 + 4); + CreateBackground(width / 2, height, width, height, &keypad); + DrawMore(width, height, KEYBOARD_OFFSET_Y, KEYBOARD_OFFSET_X, &keypad); + CreateBezel(width / 2, height, KEYBOARD_OFFSET_Y, KEYBOARD_OFFSET_X, + &keypad); + CreateKeypad(width, height, -cut, KEYBOARD_OFFSET_X, &keypad); } else { - int cut = buttons[BUTTON_MTH].y + KEYBOARD_OFFSET_Y - 19; - CreateBackground(width, cut, width, height, &keypad); - DrawMore(width, height, KEYBOARD_OFFSET_Y, KEYBOARD_OFFSET_X, &keypad); - CreateBezel(width, cut, KEYBOARD_OFFSET_Y, KEYBOARD_OFFSET_X, &keypad); - CreateKeypad(width, height, KEYBOARD_OFFSET_Y, KEYBOARD_OFFSET_X, &keypad); + int cut = buttons[BUTTON_MTH].y + KEYBOARD_OFFSET_Y - 19; + CreateBackground(width, cut, width, height, &keypad); + DrawMore(width, height, KEYBOARD_OFFSET_Y, KEYBOARD_OFFSET_X, &keypad); + CreateBezel(width, cut, KEYBOARD_OFFSET_Y, KEYBOARD_OFFSET_X, &keypad); + CreateKeypad(width, height, KEYBOARD_OFFSET_Y, KEYBOARD_OFFSET_X, &keypad); } /* @@ -2969,15 +3085,15 @@ int CreateWindows(int argc, char **argv) { } void ShowConnections(char *wire, char *ir) { - int x, y, w, h; - int conn_top; - XFontStruct *finfo; - char name[128]; - XGCValues val; + int x, y, w, h; + int conn_top; + XFontStruct *finfo; + char name[128]; + XGCValues val; unsigned long gc_mask; - XCharStruct xchar; - int dir, fa, fd; - Pixmap pix; + XCharStruct xchar; + int dir, fa, fd; + Pixmap pix; finfo = get_font_resource(dpy, "connectionFont", "ConnectionFont"); val.font = finfo->fid; @@ -2990,7 +3106,7 @@ void ShowConnections(char *wire, char *ir) { w = DISPLAY_WIDTH; h = fa + fd; - pix = XCreatePixmap(dpy, keypad.pixmap, w, h, depth); /* FIXME keypad? */ + pix = XCreatePixmap(dpy, keypad.pixmap, w, h, depth); /* FIXME keypad? */ XSetForeground(dpy, gc, COLOR(DISP_PAD)); XFillRectangle(dpy, pix, gc, 0, 0, w, h); @@ -3011,7 +3127,7 @@ void ShowConnections(char *wire, char *ir) { x = DISPLAY_OFFSET_X; y = conn_top; - XCopyArea(dpy, pix, keypad.pixmap, gc, 0, 0, w, h, x, y); /* FIXME keypad? */ + XCopyArea(dpy, pix, keypad.pixmap, gc, 0, 0, w, h, x, y); /* FIXME keypad? */ DrawKeypad(&keypad); @@ -3037,14 +3153,14 @@ int button_pressed(int b) { do_kbd_int(); } if ((saturn.keybuf.rows[r] & c)) { -fprintf(stderr, "bug\n"); + fprintf(stderr, "bug\n"); } saturn.keybuf.rows[r] |= c; } } #ifdef DEBUG_BUTTONS - fprintf(stderr, "Button pressed %d (%s)\n", - buttons[b].code, buttons[b].name); + fprintf(stderr, "Button pressed %d (%s)\n", buttons[b].code, + buttons[b].name); #endif return 0; } @@ -3065,43 +3181,39 @@ int button_released(int b) { saturn.keybuf.rows[r] &= ~c; } #ifdef DEBUG_BUTTONS - fprintf(stderr, "Button released %d (%s)\n", - buttons[b].code, buttons[b].name); + fprintf(stderr, "Button released %d (%s)\n", buttons[b].code, + buttons[b].name); #endif return 0; } -static -int button_release_all(void) { +static int button_release_all(void) { int code; int b; #ifdef DEBUG_BUTTONS fprintf(stderr, "Buttons released "); #endif - for (b = BUTTON_A; b <= LAST_BUTTON; b++) - { - if (buttons[b].pressed) - { + for (b = BUTTON_A; b <= LAST_BUTTON; b++) { + if (buttons[b].pressed) { #ifdef DEBUG_BUTTONS - fprintf(stderr, "%d (%s) ", - buttons[b].code, buttons[b].name); + fprintf(stderr, "%d (%s) ", buttons[b].code, buttons[b].name); #endif - code = buttons[b].code; - if (code == 0x8000) { - int i; - for (i = 0; i < 9; i++) - saturn.keybuf.rows[i] &= ~0x8000; - } else { - int r, c; - r = code >> 4; - c = 1 << (code & 0xf); - saturn.keybuf.rows[r] &= ~c; - } - buttons[b].pressed = 0; - DrawButton(b); + code = buttons[b].code; + if (code == 0x8000) { + int i; + for (i = 0; i < 9; i++) + saturn.keybuf.rows[i] &= ~0x8000; + } else { + int r, c; + r = code >> 4; + c = 1 << (code & 0xf); + saturn.keybuf.rows[r] &= ~c; } + buttons[b].pressed = 0; + DrawButton(b); } + } #ifdef DEBUG_BUTTONS fprintf(stderr, "\n"); #endif @@ -3132,24 +3244,24 @@ int key_event(int b, XEvent *xev) { } } #ifdef DEBUG_BUTTONS - fprintf(stderr, "Key pressed %d (%s) %x\n", - buttons[b].code, buttons[b].name), c; + fprintf(stderr, "Key pressed %d (%s) %x\n", buttons[b].code, + buttons[b].name), + c; #endif } else { - if (code == 0x8000) { - for (i = 0; i < 9; i++) - saturn.keybuf.rows[i] &= ~0x8000; - memset (&saturn.keybuf, 0, sizeof (saturn.keybuf)); - } else { - r = code >> 4; - c = 1 << (code & 0xf); - saturn.keybuf.rows[r] &= ~c; - } - buttons[b].pressed = 0; - DrawButton(b); + if (code == 0x8000) { + for (i = 0; i < 9; i++) + saturn.keybuf.rows[i] &= ~0x8000; + memset(&saturn.keybuf, 0, sizeof(saturn.keybuf)); + } else { + r = code >> 4; + c = 1 << (code & 0xf); + saturn.keybuf.rows[r] &= ~c; + } + buttons[b].pressed = 0; + DrawButton(b); #ifdef DEBUG_BUTTONS - fprintf(stderr, "Key released %d (%s)\n", - buttons[b].code, buttons[b].name); + fprintf(stderr, "Key released %d (%s)\n", buttons[b].code, buttons[b].name); #endif } return 0; @@ -3159,13 +3271,13 @@ int key_event(int b, XEvent *xev) { void refresh_display(void) { if (shm_flag) { if (disp.display_update & UPDATE_DISP) { - XShmPutImage(dpy, disp.win, disp.gc, disp.disp_image, disp.offset, 0, - 5, 20, 262, (unsigned int)(disp.lines + 2), 0); + XShmPutImage(dpy, disp.win, disp.gc, disp.disp_image, disp.offset, 0, 5, + 20, 262, (unsigned int)(disp.lines + 2), 0); } if ((disp.lines < 126) && (disp.display_update & UPDATE_MENU)) { - XShmPutImage(dpy, disp.win, disp.gc, disp.menu_image, - 0, 0, 5, (int)(disp.lines + 22), - 262, (unsigned int)(126 - disp.lines), 0); + XShmPutImage(dpy, disp.win, disp.gc, disp.menu_image, 0, 0, 5, + (int)(disp.lines + 22), 262, + (unsigned int)(126 - disp.lines), 0); } disp.display_update = 0; } @@ -3175,12 +3287,12 @@ void refresh_display(void) { void DrawDisp(void) { #ifdef HAVE_XSHM if (shm_flag) { - XShmPutImage(dpy, disp.win, disp.gc, disp.disp_image, disp.offset, 0, - 5, 20, 262, (unsigned int)(disp.lines + 2), 0); + XShmPutImage(dpy, disp.win, disp.gc, disp.disp_image, disp.offset, 0, 5, 20, + 262, (unsigned int)(disp.lines + 2), 0); if (display.lines < 63) { - XShmPutImage(dpy, disp.win, disp.gc, disp.menu_image, - 0, disp.lines - 110, 5, 22 + disp.lines, - 262, (unsigned int)(126 - disp.lines), 0); + XShmPutImage(dpy, disp.win, disp.gc, disp.menu_image, 0, disp.lines - 110, + 5, 22 + disp.lines, 262, (unsigned int)(126 - disp.lines), + 0); } disp.display_update = 0; } else { @@ -3193,93 +3305,86 @@ void DrawDisp(void) { } void get_geometry_string(Window win, char *s, int allow_off_screen) { - XWindowAttributes xwa; - Window root, parent, window; - Window *children = (Window *)0; - unsigned int rw, rh, rbw, rd; - unsigned int w, h, bw, d; - unsigned int nc; - int rx, ry, x, y; - int x_pos, x_neg, x_s, y_pos, y_neg, y_s; + XWindowAttributes xwa; + Window root, parent, window; + Window *children = (Window *)0; + unsigned int rw, rh, rbw, rd; + unsigned int w, h, bw, d; + unsigned int nc; + int rx, ry, x, y; + int x_pos, x_neg, x_s, y_pos, y_neg, y_s; window = win; nc = 0; XQueryTree(dpy, window, &root, &parent, &children, &nc); XFree((char *)children); - while (parent != root) - { - window = parent; - nc = 0; - XQueryTree(dpy, window, &root, &parent, &children, &nc); - XFree((char *)children); - } + while (parent != root) { + window = parent; + nc = 0; + XQueryTree(dpy, window, &root, &parent, &children, &nc); + XFree((char *)children); + } XGetGeometry(dpy, window, &root, &x, &y, &w, &h, &bw, &d); XGetGeometry(dpy, root, &root, &rx, &ry, &rw, &rh, &rbw, &rd); x_s = 1; x_pos = x; x_neg = rw - (x + w); - if (abs(x_pos) > abs(x_neg)) - { - x = x_neg; - x_s = -1; - } + if (abs(x_pos) > abs(x_neg)) { + x = x_neg; + x_s = -1; + } y_s = 1; y_pos = y; y_neg = rh - (y + h); - if (abs(y_pos) > abs(y_neg)) - { - y = y_neg; - y_s = -1; - } + if (abs(y_pos) > abs(y_neg)) { + y = y_neg; + y_s = -1; + } - if (!allow_off_screen) - { - if (x < 0) x = 0; - if (y < 0) y = 0; - } + if (!allow_off_screen) { + if (x < 0) + x = 0; + if (y < 0) + y = 0; + } XGetWindowAttributes(dpy, win, &xwa); - sprintf(s, "%ux%u%s%d%s%d", xwa.width, xwa.height, - (x_s > 0) ? "+" : "-", x, (y_s > 0) ? "+" : "-", y); + sprintf(s, "%ux%u%s%d%s%d", xwa.width, xwa.height, (x_s > 0) ? "+" : "-", x, + (y_s > 0) ? "+" : "-", y); } void save_command_line(void) { - XWindowAttributes xwa; - int wm_argc, ac; - char **wm_argv, geom[128], icon_geom[128]; + XWindowAttributes xwa; + int wm_argc, ac; + char **wm_argv, geom[128], icon_geom[128]; ac = wm_argc = 0; wm_argv = (char **)malloc((saved_argc + 5) * sizeof(char *)); - if (wm_argv == (char **)0) - { - if (!quiet) - fprintf(stderr, "%s: warning: malloc failed in wm_save_yourself.\n", - progname); - XSetCommand(dpy, mainW, saved_argv, saved_argc); - return; - } + if (wm_argv == (char **)0) { + if (!quiet) + fprintf(stderr, "%s: warning: malloc failed in wm_save_yourself.\n", + progname); + XSetCommand(dpy, mainW, saved_argv, saved_argc); + return; + } - while (saved_argv[ac]) - { - if (!strcmp(saved_argv[ac], "-geometry")) - { - ac += 2; - continue; - } - if (!strcmp(saved_argv[ac], "-iconGeom")) - { - ac += 2; - continue; - } - if (!strcmp(saved_argv[ac], "-iconic")) - { - ac++; - continue; - } - wm_argv[wm_argc++] = saved_argv[ac++]; + while (saved_argv[ac]) { + if (!strcmp(saved_argv[ac], "-geometry")) { + ac += 2; + continue; } + if (!strcmp(saved_argv[ac], "-iconGeom")) { + ac += 2; + continue; + } + if (!strcmp(saved_argv[ac], "-iconic")) { + ac++; + continue; + } + wm_argv[wm_argc++] = saved_argv[ac++]; + } wm_argv[wm_argc++] = "-geometry"; get_geometry_string(mainW, geom, 1); @@ -3290,10 +3395,9 @@ void save_command_line(void) { wm_argv[wm_argc++] = icon_geom; XGetWindowAttributes(dpy, mainW, &xwa); - if (xwa.map_state == IsUnmapped) - { - wm_argv[wm_argc++] = "-iconic"; - } + if (xwa.map_state == IsUnmapped) { + wm_argv[wm_argc++] = "-iconic"; + } wm_argv[wm_argc] = (char *)0; XSetCommand(dpy, mainW, wm_argv, wm_argc); @@ -3303,7 +3407,7 @@ void exit_x48(int tell_x11) { exit_emulator(); if (tell_x11) XCloseDisplay(dpy); - exit (0); + exit(0); } int decode_key(XEvent *xev, KeySym sym, char *buf, int buflen) { @@ -3312,314 +3416,314 @@ int decode_key(XEvent *xev, KeySym sym, char *buf, int buflen) { wake = 0; if (buflen == 1) switch (buf[0]) { - case '0': - sym = XK_0; - break; - case '1': - sym = XK_1; - break; - case '2': - sym = XK_2; - break; - case '3': - sym = XK_3; - break; - case '4': - sym = XK_4; - break; - case '5': - sym = XK_5; - break; - case '6': - sym = XK_6; - break; - case '7': - sym = XK_7; - break; - case '8': - sym = XK_8; - break; - case '9': - sym = XK_9; - break; - default: - break; - } - - switch ((int)sym) { - case XK_KP_0: - case XK_0: - key_event(BUTTON_0, xev); - wake = 1; + case '0': + sym = XK_0; break; - case XK_KP_1: - case XK_1: - key_event(BUTTON_1, xev); - wake = 1; + case '1': + sym = XK_1; break; - case XK_KP_2: - case XK_2: - key_event(BUTTON_2, xev); - wake = 1; + case '2': + sym = XK_2; break; - case XK_KP_3: - case XK_3: - key_event(BUTTON_3, xev); - wake = 1; + case '3': + sym = XK_3; break; - case XK_KP_4: - case XK_4: - key_event(BUTTON_4, xev); - wake = 1; + case '4': + sym = XK_4; break; - case XK_KP_5: - case XK_5: - key_event(BUTTON_5, xev); - wake = 1; + case '5': + sym = XK_5; break; - case XK_KP_6: - case XK_6: - key_event(BUTTON_6, xev); - wake = 1; + case '6': + sym = XK_6; break; - case XK_KP_7: - case XK_7: - key_event(BUTTON_7, xev); - wake = 1; - break; - case XK_KP_8: - case XK_8: - key_event(BUTTON_8, xev); - wake = 1; + case '7': + sym = XK_7; break; - case XK_KP_9: - case XK_9: - key_event(BUTTON_9, xev); - wake = 1; + case '8': + sym = XK_8; break; - case XK_KP_Add: - case XK_plus: - case XK_equal: - key_event(BUTTON_PLUS, xev); - wake = 1; - break; - case XK_KP_Subtract: - case XK_minus: - key_event(BUTTON_MINUS, xev); - wake = 1; - break; -#ifdef XK_F25 - case XK_F25: -#endif - case XK_KP_Divide: - case XK_slash: - key_event(BUTTON_DIV, xev); - wake = 1; - break; -#ifdef XK_F26 - case XK_F26: -#endif - case XK_KP_Multiply: - case XK_asterisk: - case XK_comma: - key_event(BUTTON_MUL, xev); - wake = 1; - break; - case XK_KP_Enter: - case XK_Return: - key_event(BUTTON_ENTER, xev); - wake = 1; - break; - case XK_KP_Decimal: - case XK_KP_Separator: - case XK_period: - key_event(BUTTON_PERIOD, xev); - wake = 1; - break; - case XK_space: - key_event(BUTTON_SPC, xev); - wake = 1; - break; - case XK_Delete: - key_event(BUTTON_DEL, xev); - wake = 1; - break; - case XK_BackSpace: - key_event(BUTTON_BS, xev); - wake = 1; - break; - case XK_Escape: - key_event(BUTTON_ON, xev); - wake = 1; - break; - case XK_Shift_L: - case XK_Control_R: - key_event(BUTTON_SHL, xev); - wake = 1; - break; - case XK_Shift_R: - case XK_Control_L: - key_event(BUTTON_SHR, xev); - wake = 1; - break; - case XK_Alt_L: - case XK_Alt_R: - case XK_Meta_L: - case XK_Meta_R: - key_event(BUTTON_ALPHA, xev); - wake = 1; - break; - case XK_a: - case XK_A: - case XK_F1: - key_event(BUTTON_A, xev); - wake = 1; - break; - case XK_b: - case XK_B: - case XK_F2: - key_event(BUTTON_B, xev); - wake = 1; - break; - case XK_c: - case XK_C: - case XK_F3: - key_event(BUTTON_C, xev); - wake = 1; - break; - case XK_d: - case XK_D: - case XK_F4: - key_event(BUTTON_D, xev); - wake = 1; - break; - case XK_e: - case XK_E: - case XK_F5: - key_event(BUTTON_E, xev); - wake = 1; - break; - case XK_f: - case XK_F: - case XK_F6: - key_event(BUTTON_F, xev); - wake = 1; - break; - case XK_g: - case XK_G: - key_event(BUTTON_MTH, xev); - wake = 1; - break; - case XK_h: - case XK_H: - key_event(BUTTON_PRG, xev); - wake = 1; - break; - case XK_i: - case XK_I: - key_event(BUTTON_CST, xev); - wake = 1; - break; - case XK_j: - case XK_J: - key_event(BUTTON_VAR, xev); - wake = 1; - break; - case XK_k: - case XK_K: - case XK_Up: - key_event(BUTTON_UP, xev); - wake = 1; - break; - case XK_l: - case XK_L: - key_event(BUTTON_NXT, xev); - wake = 1; - break; - case XK_m: - case XK_M: - key_event(BUTTON_COLON, xev); - wake = 1; - break; - case XK_n: - case XK_N: - key_event(BUTTON_STO, xev); - wake = 1; - break; - case XK_o: - case XK_O: - key_event(BUTTON_EVAL, xev); - wake = 1; - break; - case XK_p: - case XK_P: - case XK_Left: - key_event(BUTTON_LEFT, xev); - wake = 1; - break; - case XK_q: - case XK_Q: - case XK_Down: - key_event(BUTTON_DOWN, xev); - wake = 1; - break; - case XK_r: - case XK_R: - case XK_Right: - key_event(BUTTON_RIGHT, xev); - wake = 1; - break; - case XK_s: - case XK_S: - key_event(BUTTON_SIN, xev); - wake = 1; - break; - case XK_t: - case XK_T: - key_event(BUTTON_COS, xev); - wake = 1; - break; - case XK_u: - case XK_U: - key_event(BUTTON_TAN, xev); - wake = 1; - break; - case XK_v: - case XK_V: - key_event(BUTTON_SQRT, xev); - wake = 1; - break; - case XK_w: - case XK_W: - key_event(BUTTON_POWER, xev); - wake = 1; - break; - case XK_x: - case XK_X: - key_event(BUTTON_INV, xev); - wake = 1; - break; - case XK_y: - case XK_Y: - key_event(BUTTON_NEG, xev); - wake = 1; - break; - case XK_z: - case XK_Z: - key_event(BUTTON_EEX, xev); - wake = 1; + case '9': + sym = XK_9; break; default: break; + } + + switch ((int)sym) { + case XK_KP_0: + case XK_0: + key_event(BUTTON_0, xev); + wake = 1; + break; + case XK_KP_1: + case XK_1: + key_event(BUTTON_1, xev); + wake = 1; + break; + case XK_KP_2: + case XK_2: + key_event(BUTTON_2, xev); + wake = 1; + break; + case XK_KP_3: + case XK_3: + key_event(BUTTON_3, xev); + wake = 1; + break; + case XK_KP_4: + case XK_4: + key_event(BUTTON_4, xev); + wake = 1; + break; + case XK_KP_5: + case XK_5: + key_event(BUTTON_5, xev); + wake = 1; + break; + case XK_KP_6: + case XK_6: + key_event(BUTTON_6, xev); + wake = 1; + break; + case XK_KP_7: + case XK_7: + key_event(BUTTON_7, xev); + wake = 1; + break; + case XK_KP_8: + case XK_8: + key_event(BUTTON_8, xev); + wake = 1; + break; + case XK_KP_9: + case XK_9: + key_event(BUTTON_9, xev); + wake = 1; + break; + case XK_KP_Add: + case XK_plus: + case XK_equal: + key_event(BUTTON_PLUS, xev); + wake = 1; + break; + case XK_KP_Subtract: + case XK_minus: + key_event(BUTTON_MINUS, xev); + wake = 1; + break; +#ifdef XK_F25 + case XK_F25: +#endif + case XK_KP_Divide: + case XK_slash: + key_event(BUTTON_DIV, xev); + wake = 1; + break; +#ifdef XK_F26 + case XK_F26: +#endif + case XK_KP_Multiply: + case XK_asterisk: + case XK_comma: + key_event(BUTTON_MUL, xev); + wake = 1; + break; + case XK_KP_Enter: + case XK_Return: + key_event(BUTTON_ENTER, xev); + wake = 1; + break; + case XK_KP_Decimal: + case XK_KP_Separator: + case XK_period: + key_event(BUTTON_PERIOD, xev); + wake = 1; + break; + case XK_space: + key_event(BUTTON_SPC, xev); + wake = 1; + break; + case XK_Delete: + key_event(BUTTON_DEL, xev); + wake = 1; + break; + case XK_BackSpace: + key_event(BUTTON_BS, xev); + wake = 1; + break; + case XK_Escape: + key_event(BUTTON_ON, xev); + wake = 1; + break; + case XK_Shift_L: + case XK_Control_R: + key_event(BUTTON_SHL, xev); + wake = 1; + break; + case XK_Shift_R: + case XK_Control_L: + key_event(BUTTON_SHR, xev); + wake = 1; + break; + case XK_Alt_L: + case XK_Alt_R: + case XK_Meta_L: + case XK_Meta_R: + key_event(BUTTON_ALPHA, xev); + wake = 1; + break; + case XK_a: + case XK_A: + case XK_F1: + key_event(BUTTON_A, xev); + wake = 1; + break; + case XK_b: + case XK_B: + case XK_F2: + key_event(BUTTON_B, xev); + wake = 1; + break; + case XK_c: + case XK_C: + case XK_F3: + key_event(BUTTON_C, xev); + wake = 1; + break; + case XK_d: + case XK_D: + case XK_F4: + key_event(BUTTON_D, xev); + wake = 1; + break; + case XK_e: + case XK_E: + case XK_F5: + key_event(BUTTON_E, xev); + wake = 1; + break; + case XK_f: + case XK_F: + case XK_F6: + key_event(BUTTON_F, xev); + wake = 1; + break; + case XK_g: + case XK_G: + key_event(BUTTON_MTH, xev); + wake = 1; + break; + case XK_h: + case XK_H: + key_event(BUTTON_PRG, xev); + wake = 1; + break; + case XK_i: + case XK_I: + key_event(BUTTON_CST, xev); + wake = 1; + break; + case XK_j: + case XK_J: + key_event(BUTTON_VAR, xev); + wake = 1; + break; + case XK_k: + case XK_K: + case XK_Up: + key_event(BUTTON_UP, xev); + wake = 1; + break; + case XK_l: + case XK_L: + key_event(BUTTON_NXT, xev); + wake = 1; + break; + case XK_m: + case XK_M: + key_event(BUTTON_COLON, xev); + wake = 1; + break; + case XK_n: + case XK_N: + key_event(BUTTON_STO, xev); + wake = 1; + break; + case XK_o: + case XK_O: + key_event(BUTTON_EVAL, xev); + wake = 1; + break; + case XK_p: + case XK_P: + case XK_Left: + key_event(BUTTON_LEFT, xev); + wake = 1; + break; + case XK_q: + case XK_Q: + case XK_Down: + key_event(BUTTON_DOWN, xev); + wake = 1; + break; + case XK_r: + case XK_R: + case XK_Right: + key_event(BUTTON_RIGHT, xev); + wake = 1; + break; + case XK_s: + case XK_S: + key_event(BUTTON_SIN, xev); + wake = 1; + break; + case XK_t: + case XK_T: + key_event(BUTTON_COS, xev); + wake = 1; + break; + case XK_u: + case XK_U: + key_event(BUTTON_TAN, xev); + wake = 1; + break; + case XK_v: + case XK_V: + key_event(BUTTON_SQRT, xev); + wake = 1; + break; + case XK_w: + case XK_W: + key_event(BUTTON_POWER, xev); + wake = 1; + break; + case XK_x: + case XK_X: + key_event(BUTTON_INV, xev); + wake = 1; + break; + case XK_y: + case XK_Y: + key_event(BUTTON_NEG, xev); + wake = 1; + break; + case XK_z: + case XK_Z: + key_event(BUTTON_EEX, xev); + wake = 1; + break; + default: + break; } return wake; } #define MAX_PASTE 128 -int paste[MAX_PASTE*3]; -int paste_count = 0; -int paste_size = 0; -int paste_last_key = 0; +int paste[MAX_PASTE * 3]; +int paste_count = 0; +int paste_size = 0; +int paste_last_key = 0; int first_key = 0; @@ -3640,137 +3744,111 @@ int GetEvent(void) { static Time last_release_time = 0; wake = 0; - if (paste_last_key) - { - button_released (paste[paste_count - 1]); - paste_last_key = 0; - return 1; - } - else if (paste_count < paste_size) - { - button_pressed (paste[paste_count]); - paste_last_key = 1; - paste_count++; - return 1; - } + if (paste_last_key) { + button_released(paste[paste_count - 1]); + paste_last_key = 0; + return 1; + } else if (paste_count < paste_size) { + button_pressed(paste[paste_count]); + paste_last_key = 1; + paste_count++; + return 1; + } - if (release_pending) - { - i = XLookupString (&release_event, buf, bufs, &sym, NULL); - wake = decode_key ((XEvent *) & release_event, sym, buf, i); - release_pending = 0; - return wake; - } + if (release_pending) { + i = XLookupString(&release_event, buf, bufs, &sym, NULL); + wake = decode_key((XEvent *)&release_event, sym, buf, i); + release_pending = 0; + return wake; + } - do - { - while (XPending (dpy) > 0) - { + do { + while (XPending(dpy) > 0) { - XNextEvent (dpy, &xev); + XNextEvent(dpy, &xev); - switch ((int) xev.type) - { + switch ((int)xev.type) { - case KeyPress: + case KeyPress: - if (0 && release_pending) - { - printf ("xxx release_pending\n"); + if (0 && release_pending) { + printf("xxx release_pending\n"); } - release_pending = 0; - if ((xev.xkey.time - last_release_time) <= 1) - { + release_pending = 0; + if ((xev.xkey.time - last_release_time) <= 1) { release_pending = 0; break; } - i = XLookupString (&xev.xkey, buf, bufs, &sym, NULL); - wake = decode_key (&xev, sym, buf, i); - first_key = 1; - break; + i = XLookupString(&xev.xkey, buf, bufs, &sym, NULL); + wake = decode_key(&xev, sym, buf, i); + first_key = 1; + break; - case KeyRelease: + case KeyRelease: - i = XLookupString (&xev.xkey, buf, bufs, &sym, NULL); - first_key = 0; - release_pending = 1; - last_release_time = xev.xkey.time; - memcpy (&release_event, &xev, sizeof (XKeyEvent)); - break; + i = XLookupString(&xev.xkey, buf, bufs, &sym, NULL); + first_key = 0; + release_pending = 1; + last_release_time = xev.xkey.time; + memcpy(&release_event, &xev, sizeof(XKeyEvent)); + break; - case NoExpose: + case NoExpose: - break; + break; - case Expose: + case Expose: - if (xev.xexpose.count == 0) - { - if (xev.xexpose.window == disp.win) - { - DrawDisp (); - } - else if (xev.xexpose.window == iconW) - { - DrawIcon (); - } - else if (xev.xexpose.window == mainW) - { - DrawKeypad(&keypad); - } - else - for (i = BUTTON_A; i <= LAST_BUTTON; i++) - { - if (xev.xexpose.window == buttons[i].xwin) - { - DrawButton (i); + if (xev.xexpose.count == 0) { + if (xev.xexpose.window == disp.win) { + DrawDisp(); + } else if (xev.xexpose.window == iconW) { + DrawIcon(); + } else if (xev.xexpose.window == mainW) { + DrawKeypad(&keypad); + } else + for (i = BUTTON_A; i <= LAST_BUTTON; i++) { + if (xev.xexpose.window == buttons[i].xwin) { + DrawButton(i); break; } - } + } } - break; - case UnmapNotify: + break; + case UnmapNotify: - disp.mapped = 0; - break; + disp.mapped = 0; + break; - case MapNotify: + case MapNotify: - if (!disp.mapped) - { + if (!disp.mapped) { disp.mapped = 1; - update_display (); - redraw_annunc (); + update_display(); + redraw_annunc(); } - break; + break; - case ButtonPress: + case ButtonPress: - if (xev.xbutton.subwindow == disp.win) - { - if (xev.xbutton.button == Button2) - { - if (xev.xbutton.subwindow == disp.win) - { + if (xev.xbutton.subwindow == disp.win) { + if (xev.xbutton.button == Button2) { + if (xev.xbutton.subwindow == disp.win) { int x; int flag = 0; - char *paste_in = XFetchBuffer (dpy, &x, 0); + char *paste_in = XFetchBuffer(dpy, &x, 0); char *p = paste_in; - if (x > MAX_PASTE) - { - x = 0; - printf ("input too long. limit is %d characters\n", - MAX_PASTE); - } + if (x > MAX_PASTE) { + x = 0; + printf("input too long. limit is %d characters\n", MAX_PASTE); + } paste_count = 0; paste_size = 0; - while (x--) - { - char c = *p++; - switch (c) - { + while (x--) { + char c = *p++; + switch (c) { case '.': paste[paste_size++] = BUTTON_PERIOD; break; @@ -3841,19 +3919,16 @@ int GetEvent(void) { paste[paste_size++] = BUTTON_MUL; break; case '<': - if (x > 1 && *p == '<') - { - paste[paste_size++] = BUTTON_SHL; - paste[paste_size++] = BUTTON_MINUS; - x--; - p++; - } - else - { - paste[paste_size++] = BUTTON_ALPHA; - paste[paste_size++] = BUTTON_SHL; - paste[paste_size++] = BUTTON_2; - } + if (x > 1 && *p == '<') { + paste[paste_size++] = BUTTON_SHL; + paste[paste_size++] = BUTTON_MINUS; + x--; + p++; + } else { + paste[paste_size++] = BUTTON_ALPHA; + paste[paste_size++] = BUTTON_SHL; + paste[paste_size++] = BUTTON_2; + } break; case '{': paste[paste_size++] = BUTTON_SHL; @@ -3865,20 +3940,17 @@ int GetEvent(void) { paste[paste_size++] = BUTTON_RIGHT; break; case '>': - if (x > 1 && *p == '>') - { - paste[paste_size++] = BUTTON_RIGHT; - paste[paste_size++] = BUTTON_RIGHT; - paste[paste_size++] = BUTTON_RIGHT; - x--; - p++; - } - else - { - paste[paste_size++] = BUTTON_ALPHA; - paste[paste_size++] = BUTTON_SHR; - paste[paste_size++] = BUTTON_2; - } + if (x > 1 && *p == '>') { + paste[paste_size++] = BUTTON_RIGHT; + paste[paste_size++] = BUTTON_RIGHT; + paste[paste_size++] = BUTTON_RIGHT; + x--; + p++; + } else { + paste[paste_size++] = BUTTON_ALPHA; + paste[paste_size++] = BUTTON_SHR; + paste[paste_size++] = BUTTON_2; + } break; case '#': paste[paste_size++] = BUTTON_SHR; @@ -3889,124 +3961,115 @@ int GetEvent(void) { paste[paste_size++] = BUTTON_MUL; break; case '"': - if (flag & 1) - { - flag &= ~1; - paste[paste_size++] = BUTTON_RIGHT; - } - else - { - flag |= 1; - paste[paste_size++] = BUTTON_SHR; - paste[paste_size++] = BUTTON_MINUS; - } + if (flag & 1) { + flag &= ~1; + paste[paste_size++] = BUTTON_RIGHT; + } else { + flag |= 1; + paste[paste_size++] = BUTTON_SHR; + paste[paste_size++] = BUTTON_MINUS; + } break; case ':': - if (flag & 2) - { - flag &= ~2; - paste[paste_size++] = BUTTON_RIGHT; - } - else - { - flag |= 2; - paste[paste_size++] = BUTTON_SHR; - paste[paste_size++] = BUTTON_PLUS; - } + if (flag & 2) { + flag &= ~2; + paste[paste_size++] = BUTTON_RIGHT; + } else { + flag |= 2; + paste[paste_size++] = BUTTON_SHR; + paste[paste_size++] = BUTTON_PLUS; + } break; case '\'': - if (flag & 4) - { - flag &= ~4; - paste[paste_size++] = BUTTON_RIGHT; - } - else - { - flag |= 4; - paste[paste_size++] = BUTTON_COLON; - } + if (flag & 4) { + flag &= ~4; + paste[paste_size++] = BUTTON_RIGHT; + } else { + flag |= 4; + paste[paste_size++] = BUTTON_COLON; + } break; case 'a': case 'A': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_A; break; case 'b': case 'B': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_B; break; case 'c': case 'C': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_C; break; case 'd': case 'D': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_D; break; case 'e': case 'E': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_E; break; case 'f': case 'F': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_F; break; case 'g': case 'G': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_MTH; break; case 'h': case 'H': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_PRG; break; case 'i': case 'I': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_CST; break; case 'j': case 'J': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_VAR; break; case 'k': case 'K': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_UP; break; case 'l': case 'L': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_NXT; break; @@ -4014,240 +4077,213 @@ int GetEvent(void) { case 'm': case 'M': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_COLON; break; case 'n': case 'N': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_STO; break; case 'o': case 'O': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_EVAL; break; case 'p': case 'P': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_LEFT; break; case 'q': case 'Q': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_DOWN; break; case 'r': case 'R': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_RIGHT; break; case 's': case 'S': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_SIN; break; case 't': case 'T': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_COS; break; case 'u': case 'U': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_TAN; break; case 'v': case 'V': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_SQRT; break; case 'w': case 'W': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_POWER; break; case 'x': case 'X': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_INV; break; case 'y': case 'Y': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_NEG; break; case 'z': case 'Z': paste[paste_size++] = BUTTON_ALPHA; - if (islower (c)) + if (islower(c)) paste[paste_size++] = BUTTON_SHL; paste[paste_size++] = BUTTON_EEX; break; default: - printf ("unknown %c %d\n", c, *p); + printf("unknown %c %d\n", c, *p); break; } - } + } if (paste_in) - XFree (paste_in); - if (paste_size) - { - return 1; - } + XFree(paste_in); + if (paste_size) { + return 1; + } } - } - else if (xev.xbutton.button == Button3) - { - /* TODO Make cut from the screen work. */ - get_stack(); - } - else - { -/* printf("In display %d\n", xev.xbutton.button); */ - } - } - else - { - if (xev.xbutton.button == Button1 - || xev.xbutton.button == Button2 - || xev.xbutton.button == Button3 - ) - { - for (i = BUTTON_A; i <= LAST_BUTTON; i++) - { - if (xev.xbutton.subwindow == buttons[i].xwin) - { - if (buttons[i].pressed) - { - if (xev.xbutton.button == Button3 - ) - { - button_released (i); - DrawButton (i); - } - } - else - { + } else if (xev.xbutton.button == Button3) { + /* TODO Make cut from the screen work. */ + get_stack(); + } else { + /* printf("In display %d\n", xev.xbutton.button); */ + } + } else { + if (xev.xbutton.button == Button1 || xev.xbutton.button == Button2 || + xev.xbutton.button == Button3) { + for (i = BUTTON_A; i <= LAST_BUTTON; i++) { + if (xev.xbutton.subwindow == buttons[i].xwin) { + if (buttons[i].pressed) { + if (xev.xbutton.button == Button3) { + button_released(i); + DrawButton(i); + } + } else { last_button = i; - button_pressed (i); + button_pressed(i); wake = 1; first_key = 1; - DrawButton (i); - } - break; + DrawButton(i); } + break; + } } - } - } - break; - - case ButtonRelease: - - first_key = 0; - if (xev.xbutton.button == Button1) - { - button_release_all (); + } } - if (xev.xbutton.button == Button2) - { - if (last_button >= 0) - { - button_released (last_button); - DrawButton (last_button); - } - last_button = -1; - } - break; + break; - case FocusOut: - first_key = 0; + case ButtonRelease: + + first_key = 0; + if (xev.xbutton.button == Button1) { button_release_all(); - break; + } + if (xev.xbutton.button == Button2) { + if (last_button >= 0) { + button_released(last_button); + DrawButton(last_button); + } + last_button = -1; + } + break; - case MappingNotify: + case FocusOut: + first_key = 0; + button_release_all(); + break; - switch (xev.xmapping.request) - { + case MappingNotify: + + switch (xev.xmapping.request) { case MappingModifier: case MappingKeyboard: - XRefreshKeyboardMapping (&xev.xmapping); + XRefreshKeyboardMapping(&xev.xmapping); break; case MappingPointer: default: break; } - break; + break; - case EnterNotify: - case LeaveNotify: + case EnterNotify: + case LeaveNotify: - break; + break; - case ClientMessage: + case ClientMessage: - cm = (XClientMessageEvent *) & xev; + cm = (XClientMessageEvent *)&xev; - if (cm->message_type == wm_protocols) - { - if (cm->data.l[0] == wm_delete_window) - { - /* - * Quit selected from window managers menu - */ - exit_x48 (1); - } + if (cm->message_type == wm_protocols) { + if (cm->data.l[0] == wm_delete_window) { + /* + * Quit selected from window managers menu + */ + exit_x48(1); + } - if (cm->data.l[0] == wm_save_yourself) - { - save_command_line (); - } + if (cm->data.l[0] == wm_save_yourself) { + save_command_line(); + } } - break; + break; - default: + default: #ifdef DEBUG_XEVENT - printf ("Event: %d\n", xev.type); + printf("Event: %d\n", xev.type); #endif - case KeymapNotify: - case ConfigureNotify: - case ReparentNotify: - break; - - } - } - } - while (first_key > 1); - if (first_key) - { - first_key++; + case KeymapNotify: + case ConfigureNotify: + case ReparentNotify: + break; + } } + } while (first_key > 1); + if (first_key) { + first_key++; + } return wake; } diff --git a/src/x48_x11.h b/src/x48_x11.h index b14a0fb..7846677 100644 --- a/src/x48_x11.h +++ b/src/x48_x11.h @@ -65,31 +65,31 @@ #include #ifdef HAVE_XSHM +#include #include #include -#include #endif -#define WHITE 0 -#define LEFT 1 -#define RIGHT 2 -#define BUT_TOP 3 -#define BUTTON 4 -#define BUT_BOT 5 -#define LCD 6 -#define PIXEL 7 -#define PAD_TOP 8 -#define PAD 9 -#define PAD_BOT 10 -#define DISP_PAD_TOP 11 -#define DISP_PAD 12 -#define DISP_PAD_BOT 13 -#define LOGO 14 -#define LOGO_BACK 15 -#define LABEL 16 -#define FRAME 17 -#define UNDERLAY 18 -#define BLACK 19 +#define WHITE 0 +#define LEFT 1 +#define RIGHT 2 +#define BUT_TOP 3 +#define BUTTON 4 +#define BUT_BOT 5 +#define LCD 6 +#define PIXEL 7 +#define PAD_TOP 8 +#define PAD 9 +#define PAD_BOT 10 +#define DISP_PAD_TOP 11 +#define DISP_PAD 12 +#define DISP_PAD_BOT 13 +#define LOGO 14 +#define LOGO_BACK 15 +#define LABEL 16 +#define FRAME 17 +#define UNDERLAY 18 +#define BLACK 19 typedef struct color_t { char *name; @@ -101,49 +101,49 @@ typedef struct color_t { extern color_t *colors; -#define COLOR(c) (colors[(c)].xcolor.pixel) +#define COLOR(c) (colors[(c)].xcolor.pixel) -#define UPDATE_MENU 1 -#define UPDATE_DISP 2 +#define UPDATE_MENU 1 +#define UPDATE_DISP 2 typedef struct disp_t { - unsigned int w, h; - Window win; - GC gc; - short mapped; - int offset; - int lines; + unsigned int w, h; + Window win; + GC gc; + short mapped; + int offset; + int lines; #ifdef HAVE_XSHM - int display_update; - XShmSegmentInfo disp_info; - XImage *disp_image; - XShmSegmentInfo menu_info; - XImage *menu_image; + int display_update; + XShmSegmentInfo disp_info; + XImage *disp_image; + XShmSegmentInfo menu_info; + XImage *menu_image; #endif } disp_t; -extern disp_t disp; +extern disp_t disp; #ifdef HAVE_XSHM extern int shm_flag; #endif extern Display *dpy; -extern int screen; +extern int screen; -extern int InitDisplay __ProtoType__((int argc, char **argv)); -extern int CreateWindows __ProtoType__((int argc, char **argv)); -extern int GetEvent __ProtoType__((void)); +extern int InitDisplay __ProtoType__((int argc, char **argv)); +extern int CreateWindows __ProtoType__((int argc, char **argv)); +extern int GetEvent __ProtoType__((void)); -extern void adjust_contrast __ProtoType__((int contrast)); -extern void refresh_icon __ProtoType__((void)); +extern void adjust_contrast __ProtoType__((int contrast)); +extern void refresh_icon __ProtoType__((void)); -extern void ShowConnections __ProtoType__((char *w, char *i)); +extern void ShowConnections __ProtoType__((char *w, char *i)); -extern void exit_x48 __ProtoType__((int tell_x11)); +extern void exit_x48 __ProtoType__((int tell_x11)); #ifdef HAVE_XSHM -extern void refresh_display __ProtoType__((void)); +extern void refresh_display __ProtoType__((void)); #endif #endif /* !_X48_X11_H */