diff -rupN gnusim8085/src/8085-asm.c gnusim8085_new/src/8085-asm.c --- gnusim8085/src/8085-asm.c 2010-10-16 16:15:25.000000000 -0400 +++ gnusim8085_new/src/8085-asm.c 2010-10-16 15:33:48.000000000 -0400 @@ -30,13 +30,17 @@ #include "gui-app.h" #include "file-op.h" #include "asm-err-comm.h" +#include "mode.h" + +extern Mode mode; /* call this when you are prepraring to assemble */ void eef_asm_init (void) { /* clear msg */ - gui_list_message_clear(); + if(mode == MODE_GUI) + gui_list_message_clear(); //TODO data, stack /* Initialize symtab */ @@ -61,8 +65,9 @@ eef_asm_assemble (const char *text, gint AsmSource *src; EefMemBlock *block; - file_op_editor_save(); - + if(mode == MODE_GUI) + file_op_editor_save(); + src = asm_source_new (text); g_return_val_if_fail (src, FALSE); diff -rupN gnusim8085/src/Makefile.am gnusim8085_new/src/Makefile.am --- gnusim8085/src/Makefile.am 2010-10-16 16:15:25.000000000 -0400 +++ gnusim8085_new/src/Makefile.am 2010-10-16 15:26:06.000000000 -0400 @@ -85,7 +85,11 @@ gnusim8085_SOURCES = \ gui-input-symbol.h\ gui-input-symbol.c\ asm-id-info.h\ - asm-id-info.c + asm-id-info.c\ + mode.h\ + mode.c\ + cli-reg-test.h\ + cli-reg-test.c gnusim8085_LDFLAGS = @@ -109,4 +113,4 @@ gnusim8085_SOURCES += \ file-op.c endif -LDADD = @LIBINTL@ +LDADD = @LIBINTL@ \ No newline at end of file diff -rupN gnusim8085/src/asm-err-comm.c gnusim8085_new/src/asm-err-comm.c --- gnusim8085/src/asm-err-comm.c 2010-10-16 16:15:25.000000000 -0400 +++ gnusim8085_new/src/asm-err-comm.c 2010-10-16 15:40:06.000000000 -0400 @@ -21,13 +21,33 @@ #include "asm-err-comm.h" #include "gui-list-message.h" +#include "mode.h" + +extern Mode mode; + +//prints to stderr, redirect to log if needed. +static void +_asm_err_print_err_msg (gint line_no, gchar * err_msg, AsmErrType type) +{ + if (type == ASM_ERR_MESSAGE) + g_printerr("Message "); + else if (type == ASM_ERR_WARNING) + g_printerr("Warning "); + else + g_printerr("Error "); + + g_printerr("at line %d:\n", line_no); + g_printerr("%s\n", err_msg); +} void asm_err_comm_send (gint line_no, gchar * err_msg, AsmErrType type) { g_assert (err_msg); - - /* send message */ - gui_list_message_add (err_msg, line_no, type); + /* send message */ + if (mode == MODE_GUI) + gui_list_message_add (err_msg, line_no, type); + else + _asm_err_print_err_msg(line_no, err_msg, type); } diff -rupN gnusim8085/src/cli-reg-test.c gnusim8085_new/src/cli-reg-test.c --- gnusim8085/src/cli-reg-test.c 1969-12-31 19:00:00.000000000 -0500 +++ gnusim8085_new/src/cli-reg-test.c 2010-10-16 15:38:29.000000000 -0400 @@ -0,0 +1,120 @@ +/* + Copyright (C) 2003 Sridhar Ratnakumar + + This file is part of GNUSim8085. + + GNUSim8085 is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + GNUSim8085 is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUSim8085; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#include "cli-reg-test.h" + +static AsmSource *cli_source = NULL; +static EefMemBlock *cli_memblock = NULL; + +static void +_cli_clean_up() +{ + if(cli_memblock) + eef_mem_block_delete(cli_memblock, TRUE); + cli_memblock = NULL; + + if(cli_source) + asm_source_destroy(cli_source); + cli_source = NULL; +} + +static void +_cli_assemble_and_run(char *text, guint16 start_addr) +{ + guint16 executed_bytes = 0; + + _cli_clean_up(); + asm_sym_clear(); + eef_asm_init(); + + sys.reg.sph = 0xff; + sys.reg.spl = 0xff; + + eef_asm_assemble(text, start_addr, &cli_source, &cli_memblock); + + eef_execute_from(start_addr, &executed_bytes, -1); +} + +/* + The format for this print (optimized for machine reading by strtok) is: + A,B,C,D,E,H,L,SPH,SPL,PCH,PCL + ZERO,SIGN,PARITY,CARRY,AUXCARRY +*/ +static void +_cli_print_registers() +{ + printf("%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x\n", + sys.reg.a, sys.reg.b, sys.reg.c, sys.reg.d, sys.reg.e, sys.reg.h,\ + sys.reg.l, sys.reg.sph, sys.reg.spl, sys.reg.pch, sys.reg.pcl); + printf("%d,%d,%d,%d,%d\n",\ + sys.flag.z, sys.flag.s, sys.flag.p, sys.flag.c, sys.flag.ac); +} + +static GString* +_cli_text_from_file(char* filename) +{ + g_assert(filename); + char* ret; + GString* gstr = g_string_new(""); + FILE* infile = fopen(filename, "r"); + + if(!infile) + { + g_printerr("Failed to read file: %s\n", filename); + return NULL; + } + + while(!feof(infile)) + { + gchar buf[300] = {0}; + ret = fgets(buf, 100, infile); + g_string_append(gstr, buf); + } + + return gstr; +} + +static void +_cli_process_file(char* filename) +{ + g_assert(filename); + GString* text = _cli_text_from_file(filename); + if(!text) + return; + _cli_assemble_and_run(text -> str, START_OF_MEM); + _cli_print_registers(); + g_string_free(text, TRUE); +} + +gint +cli_regression_test (int argc, char *argv[]) +{ + g_assert(argc > 1); + g_assert(argv); + int i; + asm_sym_init(); + for(i = 2; i < argc; i++) + { + g_assert(argv[i]); + _cli_process_file(argv[i]); + } + return 0; +} diff -rupN gnusim8085/src/cli-reg-test.h gnusim8085_new/src/cli-reg-test.h --- gnusim8085/src/cli-reg-test.h 1969-12-31 19:00:00.000000000 -0500 +++ gnusim8085_new/src/cli-reg-test.h 2010-10-16 15:25:30.000000000 -0400 @@ -0,0 +1,45 @@ +/* + Copyright (C) 2003 Sridhar Ratnakumar + + This file is part of GNUSim8085. + + GNUSim8085 is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + GNUSim8085 is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUSim8085; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +/* + Provides a framework for regression testing and a rudimentary + command line interface. +*/ + +#ifndef __CLI_REG_TEST_H__ +#define __CLI_REG_TEST_H__ + +#define START_OF_MEM 0x0000 + +#include +#include "asm-source.h" +#include "8085.h" +#include "8085-asm.h" +#include "8085-link.h" + +G_BEGIN_DECLS + +gint cli_regression_test(int argc, char *argv[]); + +G_END_DECLS + +#endif /* __CLI_REG_TEST_H__ */ + diff -rupN gnusim8085/src/cmd-regression.c gnusim8085_new/src/cmd-regression.c --- gnusim8085/src/cmd-regression.c 1969-12-31 19:00:00.000000000 -0500 +++ gnusim8085_new/src/cmd-regression.c 2010-10-16 01:33:39.000000000 -0400 @@ -0,0 +1,87 @@ +/* + Copyright (C) 2003 Sridhar Ratnakumar + + This file is part of GNUSim8085. + + GNUSim8085 is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + GNUSim8085 is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUSim8085; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#include "cmd-regression.h" + +static AsmSource *ds_source = NULL; +static EefMemBlock *ds_memblock = NULL; + +static void +ds_clean_up (void) +{ + if (ds_memblock) + eef_mem_block_delete (ds_memblock, TRUE); + ds_memblock = NULL; + + if (ds_source) + asm_source_destroy (ds_source); + ds_source = NULL; +} + +gboolean +assemble_and_run (char *text, guint16 start_addr) +{ + guint16 executed_bytes = 0; + + ds_clean_up (); + asm_sym_clear(); + eef_asm_init (); + + sys.reg.sph = 0xff; + sys.reg.spl = 0xff; + + eef_asm_assemble (text, start_addr, &ds_source, &ds_memblock); + + eef_execute_from (start_addr, &executed_bytes, -1); + + return TRUE; +} + +void reg_dump(){ + printf("A = %x, B = %x, C = %x, D = %x, E = %x, H = %x, L = %x," + "SPH = %x, SPL = %x, PCH = %x, PCL = %x\n", sys.reg.a, sys.reg.b,\ + sys.reg.c, sys.reg.d, sys.reg.e, sys.reg.h, sys.reg.l,\ + sys.reg.sph, sys.reg.spl, sys.reg.pch, sys.reg.pcl); + printf("FLAGS: ZERO = %d, SIGN = %d, PARITY = %d, CARRY = %d, AUXCARRY = %d\n",\ + sys.flag.z, sys.flag.s, sys.flag.p, sys.flag.c, sys.flag.ac); +} + +GString* get_text_from_file(char* infilename){ + FILE* infile = fopen(infilename, "r"); + GString* gstr = g_string_new(""); + + while(!feof(infile)){ + char * ret; + gchar buf[300] = {0}; + ret = fgets(buf, 100, infile); + g_string_append(gstr, buf); + } + + return gstr; +} + +int register_dump(char* filename){ + GString* text = get_text_from_file(filename); + assemble_and_run(text->str, 0x0000); + reg_dump(); + g_string_free(text, TRUE); + return 0; +} diff -rupN gnusim8085/src/cmd-regression.h gnusim8085_new/src/cmd-regression.h --- gnusim8085/src/cmd-regression.h 1969-12-31 19:00:00.000000000 -0500 +++ gnusim8085_new/src/cmd-regression.h 2010-10-15 23:24:01.000000000 -0400 @@ -0,0 +1,28 @@ +/* + Copyright (C) 2003 Sridhar Ratnakumar + + This file is part of GNUSim8085. + + GNUSim8085 is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + GNUSim8085 is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUSim8085; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#include +#include "asm-source.h" +#include "8085.h" +#include "8085-asm.h" +#include "8085-link.h" + +int register_dump(char *filename); diff -rupN gnusim8085/src/main.c gnusim8085_new/src/main.c --- gnusim8085/src/main.c 2010-10-16 16:15:25.000000000 -0400 +++ gnusim8085_new/src/main.c 2010-10-16 15:22:56.000000000 -0400 @@ -1,6 +1,6 @@ /* Copyright (C) 2003 Sridhar Ratnakumar - + This file is part of GNUSim8085. GNUSim8085 is free software; you can redistribute it and/or modify @@ -36,10 +36,15 @@ #include "bridge.h" #include "callbacks.h" #include "file-op.h" +#include "mode.h" +#include "cli-reg-test.h" int main (int argc, char *argv[]) { + if(mode_check(argc, argv) == MODE_CLI) + return cli_regression_test(argc, argv); + GtkWidget *statusbar; gchar *localedir = LOCALEDIR; #ifdef WINDOWS diff -rupN gnusim8085/src/mode-check.c gnusim8085_new/src/mode-check.c --- gnusim8085/src/mode-check.c 1969-12-31 19:00:00.000000000 -0500 +++ gnusim8085_new/src/mode-check.c 2010-10-15 23:48:59.000000000 -0400 @@ -0,0 +1,41 @@ +/* + Copyright (C) 2003 Sridhar Ratnakumar + + This file is part of GNUSim8085. + + GNUSim8085 is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + GNUSim8085 is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUSim8085; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#include "mode-check.h" + +int mode; + +int mode_check(int argc, char *argv[]){ + int i = 2; + if(argc > 1 && strcmp(argv[1], "-r") == 0){ + mode = CMD_LINE_MODE; + asm_sym_init(); + for(i = 2; i < argc; i++){ + register_dump(argv[i]); + } + return CMD_LINE_MODE; + } + else{ + mode = GUI_MODE; + return GUI_MODE; + } + +} diff -rupN gnusim8085/src/mode-check.h gnusim8085_new/src/mode-check.h --- gnusim8085/src/mode-check.h 1969-12-31 19:00:00.000000000 -0500 +++ gnusim8085_new/src/mode-check.h 2010-10-15 23:48:54.000000000 -0400 @@ -0,0 +1,30 @@ +/* + Copyright (C) 2003 Sridhar Ratnakumar + + This file is part of GNUSim8085. + + GNUSim8085 is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + GNUSim8085 is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUSim8085; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA + 02110-1301, USA. +*/ +#include +#include +#include "cmd-regression.h" +#include "asm-ds-symtable.h" + + +#define GUI_MODE 0 +#define CMD_LINE_MODE 1 + +int mode_check(int argc, char *argv[]); diff -rupN gnusim8085/src/mode.c gnusim8085_new/src/mode.c --- gnusim8085/src/mode.c 1969-12-31 19:00:00.000000000 -0500 +++ gnusim8085_new/src/mode.c 2010-10-16 15:25:30.000000000 -0400 @@ -0,0 +1,34 @@ +/* + Copyright (C) 2003 Sridhar Ratnakumar + + This file is part of GNUSim8085. + + GNUSim8085 is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + GNUSim8085 is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUSim8085; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#include "mode.h" + +Mode mode; + +Mode +mode_check (int argc, char *argv[]) +{ + if (argc > 1 && strcmp(argv[1], "-r") == 0) + mode = MODE_CLI; + else + mode = MODE_GUI; + return mode; +} \ No newline at end of file diff -rupN gnusim8085/src/mode.h gnusim8085_new/src/mode.h --- gnusim8085/src/mode.h 1969-12-31 19:00:00.000000000 -0500 +++ gnusim8085_new/src/mode.h 2010-10-16 15:25:30.000000000 -0400 @@ -0,0 +1,46 @@ +/* + Copyright (C) 2003 Sridhar Ratnakumar + + This file is part of GNUSim8085. + + GNUSim8085 is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + GNUSim8085 is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUSim8085; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +/* + Responsible for determining whether the applicaiton should run + in GUI mode or CLI mode (for testing). +*/ + +#ifndef __MODE_H__ +#define __MODE_H__ + +#include +#include +#include +#include "cli-reg-test.h" + +G_BEGIN_DECLS + +typedef enum +{ + MODE_GUI, + MODE_CLI +}Mode; + +Mode mode_check(int argc, char *argv[]); + +G_END_DECLS +#endif /* __MODE_H__ */ \ No newline at end of file