formatting cleanup, add help option, fix quit behavior to ignore command-Q

This commit is contained in:
Dagen Brock 2017-01-22 12:33:43 -06:00
parent 2c368598e1
commit cb8a7a1d62
4 changed files with 98 additions and 114 deletions

View File

@ -18,6 +18,5 @@ from there.
See the doc/gsplusmanual.pdf file for much more complete documentation. See the doc/gsplusmanual.pdf file for much more complete documentation.
# Build Instructions # Build Instructions
==========================
See the /doc/ directory for "Developer-Quickstart" docs which cover building See the /doc/ directory for "Developer-Quickstart" docs which cover building
for the various platforms. for the various platforms.

View File

@ -957,15 +957,12 @@ void debug_server_poll()
/***********************************************************/ /***********************************************************/
/* Call poll() and wait for it to complete/timeout. */ /* Call poll() and wait for it to complete/timeout. */
/***********************************************************/ /***********************************************************/
//printf("Waiting on poll()...\n");
//printf("Waiting on debugger connection\n");
rc = poll(fds, nfds, timeout); rc = poll(fds, nfds, timeout);
/***********************************************************/ /***********************************************************/
/* Check to see if the poll call failed. */ /* Check to see if the poll call failed. */
/***********************************************************/ /***********************************************************/
if (rc < 0) if (rc < 0) {
{
perror(" poll() failed"); perror(" poll() failed");
return; // @todo: break/exit? return; // @todo: break/exit?
} }
@ -973,10 +970,7 @@ void debug_server_poll()
/***********************************************************/ /***********************************************************/
/* Check to see if the 3 minute time out expired. */ /* Check to see if the 3 minute time out expired. */
/***********************************************************/ /***********************************************************/
if (rc == 0) if (rc == 0) {
{
//printf(" poll() timed out. End program.\n");
//printf("~");
return; // @todo: break/exit? return; // @todo: break/exit?
} }
@ -986,29 +980,27 @@ void debug_server_poll()
/* determine which ones they are. */ /* determine which ones they are. */
/***********************************************************/ /***********************************************************/
current_size = nfds; current_size = nfds;
for (i = 0; i < current_size; i++) for (i = 0; i < current_size; i++) {
{
/*********************************************************/ /*********************************************************/
/* Loop through to find the descriptors that returned */ /* Loop through to find the descriptors that returned */
/* POLLIN and determine whether it's the listening */ /* POLLIN and determine whether it's the listening */
/* or the active connection. */ /* or the active connection. */
/*********************************************************/ /*********************************************************/
if(fds[i].revents == 0) if(fds[i].revents == 0) {
continue; continue;
}
/*********************************************************/ /*********************************************************/
/* If revents is not POLLIN, it's an unexpected result, */ /* If revents is not POLLIN, it's an unexpected result, */
/* log and end the server. */ /* log and end the server. */
/*********************************************************/ /*********************************************************/
if(fds[i].revents != POLLIN) if(fds[i].revents != POLLIN) {
{
printf(" Error! revents = %d\n", fds[i].revents); printf(" Error! revents = %d\n", fds[i].revents);
end_server = TRUE; end_server = TRUE;
break; break;
} }
if (fds[i].fd == listen_sd)
{ if (fds[i].fd == listen_sd) {
/*******************************************************/ /*******************************************************/
/* Listening descriptor is readable. */ /* Listening descriptor is readable. */
/*******************************************************/ /*******************************************************/
@ -1019,8 +1011,7 @@ void debug_server_poll()
/* queued up on the listening socket before we */ /* queued up on the listening socket before we */
/* loop back and call poll again. */ /* loop back and call poll again. */
/*******************************************************/ /*******************************************************/
do do {
{
/*****************************************************/ /*****************************************************/
/* Accept each incoming connection. If */ /* Accept each incoming connection. If */
/* accept fails with EWOULDBLOCK, then we */ /* accept fails with EWOULDBLOCK, then we */
@ -1029,10 +1020,8 @@ void debug_server_poll()
/* server. */ /* server. */
/*****************************************************/ /*****************************************************/
new_sd = accept(listen_sd, NULL, NULL); new_sd = accept(listen_sd, NULL, NULL);
if (new_sd < 0) if (new_sd < 0) {
{ if (errno != EWOULDBLOCK) {
if (errno != EWOULDBLOCK)
{
perror(" accept() failed"); perror(" accept() failed");
end_server = TRUE; end_server = TRUE;
} }
@ -1043,7 +1032,7 @@ void debug_server_poll()
/* Add the new incoming connection to the */ /* Add the new incoming connection to the */
/* pollfd structure */ /* pollfd structure */
/*****************************************************/ /*****************************************************/
printf(" New incoming connection - %d\n", new_sd); glogf(" New incoming connection - %d\n", new_sd);
fds[nfds].fd = new_sd; fds[nfds].fd = new_sd;
fds[nfds].events = POLLIN; fds[nfds].events = POLLIN;
nfds++; nfds++;
@ -1064,8 +1053,7 @@ void debug_server_poll()
/* existing connection must be readable */ /* existing connection must be readable */
/*********************************************************/ /*********************************************************/
else else {
{
//printf(" Descriptor %d is readable\n", fds[i].fd); //printf(" Descriptor %d is readable\n", fds[i].fd);
close_conn = FALSE; close_conn = FALSE;
/*******************************************************/ /*******************************************************/
@ -1073,8 +1061,7 @@ void debug_server_poll()
/* before we loop back and call poll again. */ /* before we loop back and call poll again. */
/*******************************************************/ /*******************************************************/
do do {
{
/*****************************************************/ /*****************************************************/
/* Receive data on this connection until the */ /* Receive data on this connection until the */
/* recv fails with EWOULDBLOCK. If any other */ /* recv fails with EWOULDBLOCK. If any other */
@ -1097,7 +1084,7 @@ void debug_server_poll()
/* closed by the client */ /* closed by the client */
/*****************************************************/ /*****************************************************/
if (rc == 0) { if (rc == 0) {
printf(" Connection closed\n"); glog("Connection closed\n");
close_conn = TRUE; close_conn = TRUE;
end_server = TRUE; end_server = TRUE;
break; break;
@ -1107,15 +1094,12 @@ void debug_server_poll()
/* Data was received */ /* Data was received */
/*****************************************************/ /*****************************************************/
len = rc; len = rc;
//printf("\n\n === debug_server_poll() %d bytes received \n", len);
//printf(" ==== current queue len: %d\n", dbg_cmd_queue_len);
char *mesg_ptr = buffer; char *mesg_ptr = buffer;
char *split_ptr = strchr(mesg_ptr, '\n'); char *split_ptr = strchr(mesg_ptr, '\n');
int mesg_len = len-1; // stripping that first char int mesg_len = len-1; // stripping that first char
if(split_ptr) { if(split_ptr) {
int index = split_ptr - buffer; int index = split_ptr - buffer;
//printf("Found: %d\n", index);
mesg_len = index - 1; // stripping that first char mesg_len = index - 1; // stripping that first char
} }
int debug_echo = FALSE; int debug_echo = FALSE;
@ -1182,11 +1166,9 @@ void debug_server_poll()
} }
mesg_ptr += mesg_len + 2; // +1 for command char and +1 for '\n' mesg_ptr += mesg_len + 2; // +1 for command char and +1 for '\n'
// printf(mesg_ptr);
split_ptr = strchr(mesg_ptr, '\n'); split_ptr = strchr(mesg_ptr, '\n');
if(split_ptr) { if(split_ptr) {
int index = split_ptr - mesg_ptr; int index = split_ptr - mesg_ptr;
// printf("Found: %d\n", index);
mesg_len = index - 1; // stripping that first char mesg_len = index - 1; // stripping that first char
} }
} }
@ -1195,8 +1177,7 @@ void debug_server_poll()
/*****************************************************/ /*****************************************************/
if (debug_echo) { if (debug_echo) {
rc = send(fds[i].fd, buffer, len, 0); rc = send(fds[i].fd, buffer, len, 0);
if (rc < 0) if (rc < 0) {
{
perror(" send() failed"); perror(" send() failed");
close_conn = TRUE; close_conn = TRUE;
break; break;
@ -1214,14 +1195,12 @@ void debug_server_poll()
/* clean up process includes removing the */ /* clean up process includes removing the */
/* descriptor. */ /* descriptor. */
/*******************************************************/ /*******************************************************/
if (close_conn) if (close_conn) {
{
close(fds[i].fd); close(fds[i].fd);
fds[i].fd = -1; fds[i].fd = -1;
compress_array = TRUE; compress_array = TRUE;
} }
} /* End of existing connection is readable */ } /* End of existing connection is readable */
} /* End of loop through pollable descriptors */ } /* End of loop through pollable descriptors */
@ -1257,9 +1236,7 @@ void debug_server_poll()
} }
int do_dis_json(char *buf, word32 kpc, int accsize, int xsize, int do_dis_json(char *buf, word32 kpc, int accsize, int xsize, int op_provided, word32 instr, int chain) {
int op_provided, word32 instr, int chain)
{
char buf_instructions[5*5]; // '["12","DE","AB"]' char buf_instructions[5*5]; // '["12","DE","AB"]'
char buf_disasm[50]; char buf_disasm[50];
@ -1532,13 +1509,11 @@ int do_dis_json(char *buf, word32 kpc, int accsize, int xsize,
// BASE 64 ENCODER (FOR MEMORY DUMPS) // BASE 64 ENCODER (FOR MEMORY DUMPS)
static const char b64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static const char b64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int b64encode_len(int len) int b64encode_len(int len) {
{
return ((len + 2) / 3 * 4) + 1; return ((len + 2) / 3 * 4) + 1;
} }
int b64encode(char *encoded, const char *string, int len) int b64encode(char *encoded, const char *string, int len) {
{
int i; int i;
char *p; char *p;

View File

@ -439,12 +439,19 @@ void check_input_events_sdl() {
motion |= handle_sdl_mouse_motion_event(event); motion |= handle_sdl_mouse_motion_event(event);
break; break;
case SDL_QUIT: case SDL_QUIT:
//quit = 1; /* SDL_QUIT event (window close) */ {
SDL_DestroyWindow(window); const Uint8 *state = SDL_GetKeyboardState(NULL);
iwm_shut(); if (state[SDL_SCANCODE_Q]) {
// Clean up glog("Skipping keyboard quit event. Not allowed.");
SDL_Quit(); } else {
my_exit(1); //quit = 1; /* SDL_QUIT event (window close) */
SDL_DestroyWindow(window);
iwm_shut();
// Clean up
SDL_Quit();
my_exit(1);
}
}
break; break;
case SDL_DROPFILE: case SDL_DROPFILE:
{ {

View File

@ -119,6 +119,17 @@ extern int g_audio_enable;
extern int g_preferred_rate; extern int g_preferred_rate;
extern int g_dbg_enable_port; extern int g_dbg_enable_port;
/* display parameters */
char g_display_env[512];
int g_force_depth = -1;
int g_screen_depth = 8;
int g_scanline_simulator = 0;
extern int g_screen_redraw_skip_amt;
extern int g_use_shmem;
extern int g_use_dhr140;
extern int g_use_bw_hires;
void U_STACK_TRACE(); void U_STACK_TRACE();
double g_fcycles_stop = 0.0; double g_fcycles_stop = 0.0;
@ -244,8 +255,7 @@ Data_log *g_log_data_start_ptr = &(g_data_log_array[0]);
Data_log *g_log_data_end_ptr = &(g_data_log_array[PC_LOG_LEN]); Data_log *g_log_data_end_ptr = &(g_data_log_array[PC_LOG_LEN]);
// OG Added sim65816_initglobals() // OG Added sim65816_initglobals()
void sim65816_initglobals() void sim65816_initglobals() {
{
g_fcycles_stop = 0.0; g_fcycles_stop = 0.0;
halt_sim = 0; halt_sim = 0;
enter_debug = 0; enter_debug = 0;
@ -305,9 +315,7 @@ void sim65816_initglobals()
g_mem_size_total = 256*1024; /* Total contiguous RAM from 0 */ g_mem_size_total = 256*1024; /* Total contiguous RAM from 0 */
} }
void void show_pc_log() {
show_pc_log()
{
FILE *pcfile; FILE *pcfile;
Pc_log *log_pc_ptr; Pc_log *log_pc_ptr;
Data_log *log_data_ptr; Data_log *log_data_ptr;
@ -407,9 +415,7 @@ show_pc_log()
int g_toolbox_log_pos = 0; int g_toolbox_log_pos = 0;
word32 g_toolbox_log_array[TOOLBOX_LOG_LEN][8]; word32 g_toolbox_log_array[TOOLBOX_LOG_LEN][8];
word32 word32 toolbox_debug_4byte(word32 addr) {
toolbox_debug_4byte(word32 addr)
{
word32 part1, part2; word32 part1, part2;
/* If addr looks safe, use it */ /* If addr looks safe, use it */
@ -425,9 +431,7 @@ toolbox_debug_4byte(word32 addr)
return (part1 << 16) + part2; return (part1 << 16) + part2;
} }
void void toolbox_debug_c(word32 xreg, word32 stack, double *cyc_ptr) {
toolbox_debug_c(word32 xreg, word32 stack, double *cyc_ptr)
{
int pos; int pos;
pos = g_toolbox_log_pos; pos = g_toolbox_log_pos;
@ -450,9 +454,7 @@ toolbox_debug_c(word32 xreg, word32 stack, double *cyc_ptr)
g_toolbox_log_pos = pos; g_toolbox_log_pos = pos;
} }
void void show_toolbox_log() {
show_toolbox_log()
{
int pos; int pos;
int i; int i;
@ -503,9 +505,7 @@ get_memory_c(word32 loc, int diff_cycles)
#endif #endif
word32 word32 get_memory_io(word32 loc, double *cyc_ptr) {
get_memory_io(word32 loc, double *cyc_ptr)
{
int tmp; int tmp;
if(loc > 0xffffff) { if(loc > 0xffffff) {
@ -624,9 +624,7 @@ set_memory(word32 loc, int val, int diff_cycles)
} }
#endif #endif
void void set_memory_io(word32 loc, int val, double *cyc_ptr) {
set_memory_io(word32 loc, int val, double *cyc_ptr)
{
word32 tmp; word32 tmp;
tmp = loc & 0xfef000; tmp = loc & 0xfef000;
if(tmp == 0xc000 || tmp == 0xe0c000) { if(tmp == 0xc000 || tmp == 0xe0c000) {
@ -718,22 +716,17 @@ show_regs_act(Engine_reg *eptr)
dbank, g_cur_dcycs); dbank, g_cur_dcycs);
} }
void void show_regs() {
show_regs()
{
show_regs_act(&engine); show_regs_act(&engine);
} }
//OG for regular exit, use quitEmulator() //OG for regular exit, use quitEmulator()
void quitEmulator() {
void quitEmulator()
{
printf("set_halt(HALT_WANTTOQUIT)\n"); printf("set_halt(HALT_WANTTOQUIT)\n");
set_halt(HALT_WANTTOQUIT); set_halt(HALT_WANTTOQUIT);
} }
//OG change exit to fatal_exit() //OG change exit to fatal_exit()
#ifndef ACTIVEGS #ifndef ACTIVEGS
// use standard exit function // use standard exit function
#define fatalExit exit #define fatalExit exit
@ -741,8 +734,7 @@ void quitEmulator()
extern void fatalExit(int); extern void fatalExit(int);
#endif #endif
void my_exit(int ret) void my_exit(int ret) {
{
end_screen(); end_screen();
imagewriter_close(); imagewriter_close();
printer_close(); printer_close();
@ -751,9 +743,7 @@ void my_exit(int ret)
} }
void void do_reset() {
do_reset()
{
// OG Cleared remaining IRQS on RESET // OG Cleared remaining IRQS on RESET
extern int g_irq_pending; extern int g_irq_pending;
@ -807,9 +797,7 @@ do_reset()
exit(5); \ exit(5); \
} }
void void check_engine_asm_defines() {
check_engine_asm_defines()
{
Fplus fplus; Fplus fplus;
Fplus *fplusptr; Fplus *fplusptr;
Pc_log pclog; Pc_log pclog;
@ -850,9 +838,7 @@ check_engine_asm_defines()
CHECK(fplusptr, fplusptr->plus_x_minus_1, FPLUS_PLUS_X_M1, val1, val2); CHECK(fplusptr, fplusptr->plus_x_minus_1, FPLUS_PLUS_X_M1, val1, val2);
} }
byte * byte * memalloc_align(int size, int skip_amt, void **alloc_ptr) {
memalloc_align(int size, int skip_amt, void **alloc_ptr)
{
byte *bptr; byte *bptr;
word32 addr; word32 addr;
word32 offset; word32 offset;
@ -874,9 +860,7 @@ memalloc_align(int size, int skip_amt, void **alloc_ptr)
return (bptr + offset); return (bptr + offset);
} }
void void memory_ptr_init() {
memory_ptr_init()
{
word32 mem_size; word32 mem_size;
/* This routine may be called several times--each time the ROM file */ /* This routine may be called several times--each time the ROM file */
@ -898,9 +882,7 @@ memory_ptr_init()
} }
// OG Added memory_ptr_shut // OG Added memory_ptr_shut
void void memory_ptr_shut() {
memory_ptr_shut()
{
if(g_memory_alloc_ptr) if(g_memory_alloc_ptr)
{ {
free(g_memory_alloc_ptr); free(g_memory_alloc_ptr);
@ -910,17 +892,6 @@ memory_ptr_shut()
} }
extern int g_screen_redraw_skip_amt;
extern int g_use_shmem;
extern int g_use_dhr140;
extern int g_use_bw_hires;
/* display parameters */
char g_display_env[512];
int g_force_depth = -1;
int g_screen_depth = 8;
int g_scanline_simulator = 0;
void banner() { void banner() {
printf("\x1b[32m _______ _______ _ \x1b[0m \n"); printf("\x1b[32m _______ _______ _ \x1b[0m \n");
@ -932,17 +903,44 @@ void banner() {
printf("\x1b[37m GSplus v%s \x1b[0m \n\n", g_gsplus_version_str); printf("\x1b[37m GSplus v%s \x1b[0m \n\n", g_gsplus_version_str);
} }
int void help_exit() {
gsplusmain(int argc, char **argv) printf(" USAGE: \n\n");
{ printf(" ./gsplus # simple - uses default config.txt\n");
printf(" ./gsplus -config games_hds.gsp # set custom config file\n\n");
printf(" You need to supply your own Apple IIgs Firmware ROM image.\n");
printf(" Press F4 when running gsplus to enter config menu and select ROM image location.\n");
printf(" Or copy the ROM image to the gsplus directory.\n");
printf(" It will search for: \"ROM\", \"ROM.01\", \"ROM.03\" \n\n\n");
printf(" Other command line options: \n\n");
printf(" -badrd Halt on bad reads\n");
printf(" -noignbadacc Dont ignore bad memory accesses\n");
printf(" -noignhalt Dont ignore code red halts\n");
printf(" -test Allow testing\n");
printf(" -joystick Ignore joystick option\n");
printf(" -bw Force B/W modes\n");
printf(" -dhr140 Use simple double-hires color map\n");
printf(" -mem value Set memory size to value\n");
printf(" -skip value Set skip_amt to value\n");
printf(" -audio value Set audio enable to value\n");
printf(" -arate value Set preferred audio rate to value\n");
printf(" -enet value Set ethernet to value\n");
printf(" -config value Set config file to value\n");
printf(" -debugport value Set debugport to value\n");
printf(" -ssdir value Set screenshot save directory to value\n");
printf(" -scanline Enable scanline simulator\n");
printf(" -noscanline Disable scanline simulator (default)\n");
printf(" -v value Set verbose flags to value\n\n");
printf(" Note: The final argument, if not a flag, will be tried as a mountable device.\n\n");
exit(1);
}
int gsplusmain(int argc, char **argv) {
int diff; int diff;
int skip_amt; int skip_amt;
int tmp1; int tmp1;
int i; int i;
char *final_arg = 0; char *final_arg = 0;
// just for fun
banner();
// OG Restoring globals // OG Restoring globals
sim65816_initglobals(); sim65816_initglobals();
moremem_init(); moremem_init();
@ -952,7 +950,9 @@ gsplusmain(int argc, char **argv)
/* parse args */ /* parse args */
for(i = 1; i < argc; i++) { for(i = 1; i < argc; i++) {
if(!strcmp("-badrd", argv[i])) { if( (!strcmp("-?", argv[i])) || (!strcmp("-h", argv[i])) || (!strcmp("-help", argv[i]))) {
help_exit();
} else if(!strcmp("-badrd", argv[i])) {
printf("Halting on bad reads\n"); printf("Halting on bad reads\n");
g_halt_on_bad_read = 2; g_halt_on_bad_read = 2;
} else if(!strcmp("-noignbadacc", argv[i])) { } else if(!strcmp("-noignbadacc", argv[i])) {
@ -1093,6 +1093,9 @@ gsplusmain(int argc, char **argv)
} }
} }
// just for fun
banner();
check_engine_asm_defines(); check_engine_asm_defines();
fixed_memory_ptrs_init(); fixed_memory_ptrs_init();