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.
# Build Instructions
==========================
See the /doc/ directory for "Developer-Quickstart" docs which cover building
for the various platforms.

View File

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

View File

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

View File

@ -119,6 +119,17 @@ extern int g_audio_enable;
extern int g_preferred_rate;
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();
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]);
// OG Added sim65816_initglobals()
void sim65816_initglobals()
{
void sim65816_initglobals() {
g_fcycles_stop = 0.0;
halt_sim = 0;
enter_debug = 0;
@ -305,9 +315,7 @@ void sim65816_initglobals()
g_mem_size_total = 256*1024; /* Total contiguous RAM from 0 */
}
void
show_pc_log()
{
void show_pc_log() {
FILE *pcfile;
Pc_log *log_pc_ptr;
Data_log *log_data_ptr;
@ -407,9 +415,7 @@ show_pc_log()
int g_toolbox_log_pos = 0;
word32 g_toolbox_log_array[TOOLBOX_LOG_LEN][8];
word32
toolbox_debug_4byte(word32 addr)
{
word32 toolbox_debug_4byte(word32 addr) {
word32 part1, part2;
/* If addr looks safe, use it */
@ -425,9 +431,7 @@ toolbox_debug_4byte(word32 addr)
return (part1 << 16) + part2;
}
void
toolbox_debug_c(word32 xreg, word32 stack, double *cyc_ptr)
{
void toolbox_debug_c(word32 xreg, word32 stack, double *cyc_ptr) {
int 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;
}
void
show_toolbox_log()
{
void show_toolbox_log() {
int pos;
int i;
@ -503,9 +505,7 @@ get_memory_c(word32 loc, int diff_cycles)
#endif
word32
get_memory_io(word32 loc, double *cyc_ptr)
{
word32 get_memory_io(word32 loc, double *cyc_ptr) {
int tmp;
if(loc > 0xffffff) {
@ -624,9 +624,7 @@ set_memory(word32 loc, int val, int diff_cycles)
}
#endif
void
set_memory_io(word32 loc, int val, double *cyc_ptr)
{
void set_memory_io(word32 loc, int val, double *cyc_ptr) {
word32 tmp;
tmp = loc & 0xfef000;
if(tmp == 0xc000 || tmp == 0xe0c000) {
@ -718,22 +716,17 @@ show_regs_act(Engine_reg *eptr)
dbank, g_cur_dcycs);
}
void
show_regs()
{
void show_regs() {
show_regs_act(&engine);
}
//OG for regular exit, use quitEmulator()
void quitEmulator()
{
void quitEmulator() {
printf("set_halt(HALT_WANTTOQUIT)\n");
set_halt(HALT_WANTTOQUIT);
}
//OG change exit to fatal_exit()
#ifndef ACTIVEGS
// use standard exit function
#define fatalExit exit
@ -741,8 +734,7 @@ void quitEmulator()
extern void fatalExit(int);
#endif
void my_exit(int ret)
{
void my_exit(int ret) {
end_screen();
imagewriter_close();
printer_close();
@ -751,9 +743,7 @@ void my_exit(int ret)
}
void
do_reset()
{
void do_reset() {
// OG Cleared remaining IRQS on RESET
extern int g_irq_pending;
@ -807,9 +797,7 @@ do_reset()
exit(5); \
}
void
check_engine_asm_defines()
{
void check_engine_asm_defines() {
Fplus fplus;
Fplus *fplusptr;
Pc_log pclog;
@ -850,9 +838,7 @@ check_engine_asm_defines()
CHECK(fplusptr, fplusptr->plus_x_minus_1, FPLUS_PLUS_X_M1, val1, val2);
}
byte *
memalloc_align(int size, int skip_amt, void **alloc_ptr)
{
byte * memalloc_align(int size, int skip_amt, void **alloc_ptr) {
byte *bptr;
word32 addr;
word32 offset;
@ -874,9 +860,7 @@ memalloc_align(int size, int skip_amt, void **alloc_ptr)
return (bptr + offset);
}
void
memory_ptr_init()
{
void memory_ptr_init() {
word32 mem_size;
/* This routine may be called several times--each time the ROM file */
@ -898,9 +882,7 @@ memory_ptr_init()
}
// OG Added memory_ptr_shut
void
memory_ptr_shut()
{
void memory_ptr_shut() {
if(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() {
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);
}
int
gsplusmain(int argc, char **argv)
{
void help_exit() {
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 skip_amt;
int tmp1;
int i;
char *final_arg = 0;
// just for fun
banner();
// OG Restoring globals
sim65816_initglobals();
moremem_init();
@ -952,7 +950,9 @@ gsplusmain(int argc, char **argv)
/* parse args */
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");
g_halt_on_bad_read = 2;
} else if(!strcmp("-noignbadacc", argv[i])) {
@ -1093,6 +1093,9 @@ gsplusmain(int argc, char **argv)
}
}
// just for fun
banner();
check_engine_asm_defines();
fixed_memory_ptrs_init();