diff options
| author | Xavier ASUS <xavi92psx@gmail.com> | 2019-10-18 00:31:54 +0200 |
|---|---|---|
| committer | Xavier ASUS <xavi92psx@gmail.com> | 2019-10-18 00:31:54 +0200 |
| commit | 268a53de823a6750d6256ee1fb1e7707b4b45740 (patch) | |
| tree | 42c1799a9a82b2f7d9790ee9fe181d72a7274751 /sim/ucsim/gui.src/serio.src | |
| download | sdcc-gas-268a53de823a6750d6256ee1fb1e7707b4b45740.tar.gz | |
sdcc-3.9.0 fork implementing GNU assembler syntax
This fork aims to provide better support for stm8-binutils
Diffstat (limited to 'sim/ucsim/gui.src/serio.src')
| -rw-r--r-- | sim/ucsim/gui.src/serio.src/Makefile | 114 | ||||
| -rw-r--r-- | sim/ucsim/gui.src/serio.src/Makefile.in | 114 | ||||
| -rw-r--r-- | sim/ucsim/gui.src/serio.src/USAGE | 9 | ||||
| -rw-r--r-- | sim/ucsim/gui.src/serio.src/clean.mk | 28 | ||||
| -rw-r--r-- | sim/ucsim/gui.src/serio.src/conf.mk | 12 | ||||
| -rw-r--r-- | sim/ucsim/gui.src/serio.src/config.h | 20 | ||||
| -rw-r--r-- | sim/ucsim/gui.src/serio.src/fileio.cc | 143 | ||||
| -rw-r--r-- | sim/ucsim/gui.src/serio.src/fileio.hh | 29 | ||||
| -rw-r--r-- | sim/ucsim/gui.src/serio.src/frontend.cc | 292 | ||||
| -rw-r--r-- | sim/ucsim/gui.src/serio.src/frontend.hh | 64 | ||||
| -rw-r--r-- | sim/ucsim/gui.src/serio.src/main.cc | 439 | ||||
| -rw-r--r-- | sim/ucsim/gui.src/serio.src/posix_signal.cc | 106 | ||||
| -rw-r--r-- | sim/ucsim/gui.src/serio.src/posix_signal.hh | 22 |
13 files changed, 1392 insertions, 0 deletions
diff --git a/sim/ucsim/gui.src/serio.src/Makefile b/sim/ucsim/gui.src/serio.src/Makefile new file mode 100644 index 0000000..f92f471 --- /dev/null +++ b/sim/ucsim/gui.src/serio.src/Makefile @@ -0,0 +1,114 @@ +# Makefile for kano-networks talker + +SHELL = /bin/sh +CXX = g++ +CXXCPP = g++ -E +INSTALL = /usr/bin/install -c +STRIP = strip +CP = /bin/cp +MAKEDEP = g++ -MM + +top_builddir = ../.. +top_srcdir = ../.. + +DEFS = $(subs -DHAVE_CONFIG_H,,-DHAVE_CONFIG_H) +CPPFLAGS = -I. -I$(top_builddir) +# -I$(top_builddir)/cmd.src -I$(top_builddir)/sim.src +CFLAGS = -g -O2 -Wall +CXXFLAGS = -g -O2 -g -Wall + +LIBS = -lpanel -lcurses -lrt -lnsl + +EXEEXT = + +curses_ok = yes + +prefix = /usr/local +exec_prefix = ${prefix} +bindir = ${exec_prefix}/bin +libdir = ${exec_prefix}/lib +datadir = ${datarootdir} +datarootdir = ${prefix}/share +includedir = ${prefix}/include +mandir = ${datarootdir}/man +man1dir = $(mandir)/man1 +man2dir = $(mandir)/man2 +infodir = ${datarootdir}/info +srcdir = . + + +OBJECTS = main.o fileio.o frontend.o posix_signal.o + + +# Compiling entire program or any subproject +# ------------------------------------------ +all: serio.src + +ifeq ($(curses_ok),yes) +serio.src: checkconf serialview$(EXEEXT) +else +serio.src: checkconf +endif + + +# Compiling and installing everything and runing test +# --------------------------------------------------- +install: all installdirs + $(INSTALL) serialview$(EXEEXT) $(DESTDIR)$(bindir)/serialview$(EXEEXT) + $(STRIP) $(DESTDIR)$(bindir)/serialview$(EXEEXT) + + +# Deleting all the installed files +# -------------------------------- +uninstall: + rm -f $(DESTDIR)$(bindir)/serialview$(EXEEXT) + + +# Performing self-test +# -------------------- +check: + +test: + + +# Performing installation test +# ---------------------------- +installcheck: + + +# Creating installation directories +# --------------------------------- +installdirs: + test -d $(DESTDIR)$(bindir) || $(INSTALL) -d $(DESTDIR)$(bindir) + + +# Creating dependencies +# --------------------- +dep: Makefile.dep + +Makefile.dep: $(srcdir)/*.cc $(srcdir)/*.h $(srcdir)/*.hh + $(MAKEDEP) $(CPPFLAGS) $(filter %.cc,$^) >Makefile.dep + +ifeq "$(findstring $(MAKECMDGOALS),uninstall installcheck installdirs checkconf \ + clean distclean mostlyclean realclean)" "" + -include Makefile.dep +endif +include $(srcdir)/clean.mk + + +# My rules +# -------- +serialview$(EXEEXT): $(OBJECTS) + $(CXX) -o $@ $(LDFLAGS) $(OBJECTS) $(LIBS) + +.cc.o: + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@ + +# Remaking configuration +# ---------------------- +checkconf: + @if [ -f $(top_builddir)/devel ]; then\ + $(MAKE) -f conf.mk srcdir="$(srcdir)" top_builddir="$(top_builddir)" top_srcdir=$(top_srcdir) freshconf;\ + fi + +# End of gui.src/serio.src/Makefile.in diff --git a/sim/ucsim/gui.src/serio.src/Makefile.in b/sim/ucsim/gui.src/serio.src/Makefile.in new file mode 100644 index 0000000..78a7790 --- /dev/null +++ b/sim/ucsim/gui.src/serio.src/Makefile.in @@ -0,0 +1,114 @@ +# Makefile for kano-networks talker + +SHELL = /bin/sh +CXX = @CXX@ +CXXCPP = @CXXCPP@ +INSTALL = @INSTALL@ +STRIP = @STRIP@ +CP = /bin/cp +MAKEDEP = @MAKEDEP@ + +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ + +DEFS = $(subs -DHAVE_CONFIG_H,,@DEFS@) +CPPFLAGS = @CPPFLAGS@ -I. -I$(top_builddir) +# -I$(top_builddir)/cmd.src -I$(top_builddir)/sim.src +CFLAGS = @CFLAGS@ @WALL_FLAG@ +CXXFLAGS = @CXXFLAGS@ @WALL_FLAG@ + +LIBS = @CURSES_LIBS@ @LIBS@ + +EXEEXT = @EXEEXT@ + +curses_ok = @curses_ok@ + +prefix = @prefix@ +exec_prefix = @exec_prefix@ +bindir = @bindir@ +libdir = @libdir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +includedir = @includedir@ +mandir = @mandir@ +man1dir = $(mandir)/man1 +man2dir = $(mandir)/man2 +infodir = @infodir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +OBJECTS = main.o fileio.o frontend.o posix_signal.o + + +# Compiling entire program or any subproject +# ------------------------------------------ +all: serio.src + +ifeq ($(curses_ok),yes) +serio.src: checkconf serialview$(EXEEXT) +else +serio.src: checkconf +endif + + +# Compiling and installing everything and runing test +# --------------------------------------------------- +install: all installdirs + $(INSTALL) serialview$(EXEEXT) $(DESTDIR)$(bindir)/serialview$(EXEEXT) + $(STRIP) $(DESTDIR)$(bindir)/serialview$(EXEEXT) + + +# Deleting all the installed files +# -------------------------------- +uninstall: + rm -f $(DESTDIR)$(bindir)/serialview$(EXEEXT) + + +# Performing self-test +# -------------------- +check: + +test: + + +# Performing installation test +# ---------------------------- +installcheck: + + +# Creating installation directories +# --------------------------------- +installdirs: + test -d $(DESTDIR)$(bindir) || $(INSTALL) -d $(DESTDIR)$(bindir) + + +# Creating dependencies +# --------------------- +dep: Makefile.dep + +Makefile.dep: $(srcdir)/*.cc $(srcdir)/*.h $(srcdir)/*.hh + $(MAKEDEP) $(CPPFLAGS) $(filter %.cc,$^) >Makefile.dep + +ifeq "$(findstring $(MAKECMDGOALS),uninstall installcheck installdirs checkconf \ + clean distclean mostlyclean realclean)" "" + -include Makefile.dep +endif +include $(srcdir)/clean.mk + + +# My rules +# -------- +serialview$(EXEEXT): $(OBJECTS) + $(CXX) -o $@ $(LDFLAGS) $(OBJECTS) $(LIBS) + +.cc.o: + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@ + +# Remaking configuration +# ---------------------- +checkconf: + @if [ -f $(top_builddir)/devel ]; then\ + $(MAKE) -f conf.mk srcdir="$(srcdir)" top_builddir="$(top_builddir)" top_srcdir=$(top_srcdir) freshconf;\ + fi + +# End of gui.src/serio.src/Makefile.in diff --git a/sim/ucsim/gui.src/serio.src/USAGE b/sim/ucsim/gui.src/serio.src/USAGE new file mode 100644 index 0000000..a76e65e --- /dev/null +++ b/sim/ucsim/gui.src/serio.src/USAGE @@ -0,0 +1,9 @@ +*note: tested on: +Solaris 7 using gcc version 2.95.1 19990816 (release) +with ncurses +should work with curses although not guranteed + +Start serialview +Start the s51 simulator with the following command line options: +-S out=/tmp/out,in=/tmp/in +or whatever pipes you wish to use diff --git a/sim/ucsim/gui.src/serio.src/clean.mk b/sim/ucsim/gui.src/serio.src/clean.mk new file mode 100644 index 0000000..f50d8c6 --- /dev/null +++ b/sim/ucsim/gui.src/serio.src/clean.mk @@ -0,0 +1,28 @@ +# uCsim gui.src/serio.src/clean.mk + +# Deleting all files created by building the program +# -------------------------------------------------- +clean: + rm -f *core *[%~] *.[oa] + rm -f .[a-z]*~ + rm -f serialview$(EXEEXT) + + +# Deleting all files created by configuring or building the program +# ----------------------------------------------------------------- +distclean: clean + rm -f config.cache config.log config.status + rm -f Makefile *.dep + + +# Like clean but some files may still exist +# ----------------------------------------- +mostlyclean: clean + + +# Deleting everything that can reconstructed by this Makefile. It deletes +# everything deleted by distclean plus files created by bison, etc. +# ----------------------------------------------------------------------- +realclean: distclean + +# End of gui.src/serio.src/clean.mk diff --git a/sim/ucsim/gui.src/serio.src/conf.mk b/sim/ucsim/gui.src/serio.src/conf.mk new file mode 100644 index 0000000..25e3b04 --- /dev/null +++ b/sim/ucsim/gui.src/serio.src/conf.mk @@ -0,0 +1,12 @@ +# uCsim gui.src/serio.src/conf.mk + +# +# Makefile targets to remake configuration +# + +freshconf: Makefile + +Makefile: $(srcdir)/Makefile.in $(top_srcdir)/configure.ac + cd $(top_builddir) && $(SHELL) ./config.status + +# End of gui.src/serio.src/conf.mk diff --git a/sim/ucsim/gui.src/serio.src/config.h b/sim/ucsim/gui.src/serio.src/config.h new file mode 100644 index 0000000..3fef045 --- /dev/null +++ b/sim/ucsim/gui.src/serio.src/config.h @@ -0,0 +1,20 @@ +/****************************************************************************** + * to emulate the serial input and output of an 8051 controller * + * config.h - general defintions * + ******************************************************************************/ +#ifndef CONFIG_HEADER +#define CONFIG_HEADER + +#ifndef DEF_INFILE +// the processors serial output +#define DEF_INFILE "/tmp/out" +#endif + +#ifndef DEF_OUTFILE +// the processors serial input +#define DEF_OUTFILE "/tmp/in" +#endif + +#define MAX_SIZ 1024 + +#endif diff --git a/sim/ucsim/gui.src/serio.src/fileio.cc b/sim/ucsim/gui.src/serio.src/fileio.cc new file mode 100644 index 0000000..5f7e6fa --- /dev/null +++ b/sim/ucsim/gui.src/serio.src/fileio.cc @@ -0,0 +1,143 @@ +/****************************************************************************** + * to emulate the serial input and output of an 8051 controller * + * fileio.cc - file input and output * + ******************************************************************************/ +#include <sys/types.h> +#include <iostream> +#include <stdlib.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> +#include <string.h> +#include <unistd.h> +#include "fileio.hh" + +FileIO::FileIO() +{ + + // make the input fifo + if(mkfifo(DEF_INFILE, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) == -1) { + if(errno != EEXIST) { + std::cerr << "mkfifo(): Error number " << errno << " occourred: " << strerror(errno) << "\n"; + exit(-1); + } + } + + // the input fifo - non blocking + if ((fdin = open(DEF_INFILE, O_RDONLY|O_NONBLOCK)) == -1) { + std::cerr << "open(): Error number " << errno << " occourred: " << strerror(errno) << "\n"; + exit(-1); + } + + // make the output fifo + if(mkfifo(DEF_OUTFILE, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) == -1) { + if(errno != EEXIST) { + std::cerr << "mkfifo(): Error number " << errno << " occourred: " << strerror(errno) << "\n"; + exit(-1); + } + } + + // the output fifo + if ((fdout = open(DEF_OUTFILE, O_RDWR|O_NONBLOCK)) == -1) { + std::cerr << "open(): Error number " << errno << " occourred: " << strerror(errno) << "\n"; + exit(-1); + } +} + +FileIO::FileIO(const char *infile, const char *outfile) +{ + // make the input fifo + if(mkfifo(infile, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) == -1) { + if(errno != EEXIST) { + std::cerr << "mkfifo(): Error number " << errno << " occourred: " << strerror(errno); + exit(-1); + } + } + + // the input fifo - non blocking + if ((fdin = open(infile, O_RDONLY|O_NONBLOCK)) == -1) { + std::cerr << "open(): Error number " << errno << " occourred: " << strerror(errno); + exit(-1); + } + + // make the output fifo + if(mkfifo(outfile, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) == -1) { + if(errno != EEXIST) { + std::cerr << "mkfifo(): Error number " << errno << " occourred: " << strerror(errno); + exit(-1); + } + } + + // the output fifo + if ((fdout = open(outfile, O_RDWR|O_NONBLOCK)) == -1) { + std::cerr << "open(): Error number " << errno << " occourred: " << strerror(errno); + exit(-1); + } +} + + +FileIO::~FileIO() +{ + close(fdin); + close(fdout); +} + +int FileIO::SendByte(char b) +{ + int ret; + + if((ret = write(fdout, &b, 1)) != 1) + { + std::cerr << "write(): Error number " << errno << " occourred: " << strerror(errno); + exit(-1); + } + + return(ret); +} + + +int FileIO::RecvByte(char *b) +{ + int ret; + + ret = read(fdin, b, 1); + + if((ret == -1) && (errno != EAGAIN)) + { + std::cerr << "read(): Error number " << errno << " occourred: " << strerror(errno); + exit(-1); + } + + return(ret); +} + +// send a string +int FileIO::SendStr(char *str) +{ + int ret; + + if((ret = write(fdout, str, strlen(str))) != (int)strlen(str)) + { + std::cerr << "write(): Error number " << errno << " occourred: " << strerror(errno); + exit(-1); + } + + return(ret); +} + + +int FileIO::RecvStr(char *str) +{ + int ret; + + ret = read(fdin, str, MAX_SIZ-1); + str[MAX_SIZ] = 0; + + if((ret == -1) && (errno != EAGAIN)) + { + std::cerr << "read(): Error number " << errno << " occourred: " << strerror(errno); + exit(-1); + } + + return(ret); +} diff --git a/sim/ucsim/gui.src/serio.src/fileio.hh b/sim/ucsim/gui.src/serio.src/fileio.hh new file mode 100644 index 0000000..0e986ff --- /dev/null +++ b/sim/ucsim/gui.src/serio.src/fileio.hh @@ -0,0 +1,29 @@ +/****************************************************************************** + * to emulate the serial input and output of an 8051 controller * + * fileio.hh - file input and output * + ******************************************************************************/ +#ifndef FILEIO_HEADER +#define FILEIO_HEADER + +#include "config.h" + +class FileIO +{ +public: + FileIO(); + FileIO(const char *infile, const char *outfile); + virtual ~FileIO(); + + virtual int SendByte(char b); + virtual int RecvByte(char *b); + virtual int SendStr(char *str); + virtual int RecvStr(char *str); + + virtual int infile_id() { return fdin; } + +private: + int fdin; + int fdout; +}; + +#endif diff --git a/sim/ucsim/gui.src/serio.src/frontend.cc b/sim/ucsim/gui.src/serio.src/frontend.cc new file mode 100644 index 0000000..98472a2 --- /dev/null +++ b/sim/ucsim/gui.src/serio.src/frontend.cc @@ -0,0 +1,292 @@ +/****************************************************************************** + * to emulate the serial input and output of an 8051 controller * + * frontend.cc - the ncurses frontend * + ******************************************************************************/ +#include <sys/types.h> +#include <iostream> +#include <stdlib.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <curses.h> +#include <errno.h> +#include <string.h> +#include <unistd.h> +#include "frontend.hh" + +char * +flt_name(enum filter_t f) +{ + switch (f) + { + case flt_none : return (char*)"none"; + case flt_hex : return (char*)"hex"; + } + return (char*)"unknown"; +} + +Viewer::Viewer() +{ + /* initalise the output screen */ + initscr(); + cbreak(); + noecho(); + nl(); + intrflush(stdscr,FALSE); + keypad(stdscr, TRUE); + + flt_in= flt_none; + flt_out= flt_none; + ohex_ptr= 0; + ocnt= icnt= 0; + line_length= 8; + + /* clear the screen and off you go */ + refresh(); + + // get the coordinates for the box + /* create the subwindow */ + win_c.min_x = win_c.min_y = 0; + getmaxyx(stdscr, win_c.max_y, win_c.max_x); + + /* define the boxed size */ + topleft.x = win_c.min_x + 1; + bottomright.x = win_c.max_x - 2; + topleft.y = win_c.min_y + 1; + bottomright.y = win_c.max_y - 2; + middle_y = (int)((bottomright.y-topleft.y)/2)+1; + middle_x = (int)((bottomright.x-topleft.x)/2)+1; + + // draw the two subwindows + inp_c.min_x = outp_c.min_x = topleft.x; + inp_c.max_x = outp_c.max_x = bottomright.x; + inp_c.min_y = topleft.y; + inp_c.max_y = middle_y-topleft.y; + outp_c.min_y = middle_y+1; + outp_c.max_y = bottomright.y-middle_y; + inp = subwin(stdscr, inp_c.max_y, inp_c.max_x, inp_c.min_y, inp_c.min_x); + outp = subwin(stdscr, outp_c.max_y, outp_c.max_x, outp_c.min_y,outp_c.min_x); + + // initalise the windows + touchwin(inp); + werase(inp); + wrefresh(inp); + scrollok(inp, TRUE); + + touchwin(outp); + werase(outp); + wrefresh(outp); + scrollok(outp, TRUE); + refresh(); + + nodelay(inp, TRUE); + + // flush the input buffers + flushinp(); + + move(topleft.x,topleft.y); + DrawBox(); +} + +Viewer::~Viewer() +{ + delwin(inp); + delwin(outp); + erase(); + refresh(); + endwin(); +} + +void +Viewer::iflt_mode(enum filter_t iflt) +{ + char s[100]; + flt_in= iflt; + sprintf(s, "Input filter: %s\n", flt_name(flt_in)); + waddstr(inp, s); + wrefresh(inp); + ihex_high= 1; + ihex_ptr= 0; +} + +void +Viewer::oflt_mode(enum filter_t oflt) +{ + char s[100]; + flt_out= oflt; + sprintf(s, "Otput filter: %s\n", flt_name(flt_out)); + waddstr(outp, s); + wrefresh(outp); + wrefresh(inp); + ohex_ptr= 0; +} + +void +Viewer::set_length(int l) +{ + if (l > (bottomright.x-2-7) / 4) + l= ((bottomright.x-2-7)/4) - 1; + line_length= l; +} + +void Viewer::DrawBox(void) +{ + int height, width; + COORDINATES current; + + // save the current position + getyx(stdscr, current.y, current.x); + + height = (bottomright.y - topleft.y)+1; + width = (bottomright.x - topleft.y)+1; + + mvaddch(topleft.y-1, topleft.x-1, ACS_ULCORNER); + mvaddch(topleft.y-1, bottomright.x+1, ACS_URCORNER); + mvaddch(bottomright.y+1, bottomright.x+1, ACS_LRCORNER); + mvaddch(bottomright.y+1, topleft.x-1, ACS_LLCORNER); + + /* wmove (screen, y, x) */ + /* top */ + move(topleft.y-1, topleft.x); + hline(ACS_HLINE, width); + /* bottom */ + move(bottomright.y+1, topleft.x); + hline(ACS_HLINE, width); + move(bottomright.y+1, topleft.x); + hline(ACS_HLINE, width); + + /* left */ + move(topleft.y, topleft.x-1); + vline(ACS_VLINE, height); + + /* right */ + move(topleft.y, bottomright.x+1); + vline(ACS_VLINE, height); + + /* the divider */ + mvaddch(middle_y, bottomright.x+1, ACS_RTEE); + mvaddch(middle_y, topleft.x-1, ACS_LTEE); + hline(ACS_HLINE, width); + + // the window titles + mvaddstr(inp_c.min_y-1, middle_x-(strlen("Input")/2), "Input"); + mvaddstr(middle_y, middle_x-(strlen("Output")/2), "Output"); + move(current.y, current.x); + refresh(); +} + +void Viewer::AddStrOutWin(char *string) +{ + waddstr(outp, string); + wrefresh(outp); + wrefresh(inp); +} + +void Viewer::GetStrInWin(char *string) +{ + if(wgetstr(inp, string) == ERR) { + string[0] = 0; + } else { + waddstr(inp, string); + wrefresh(inp); + } +} + +void Viewer::AddChOutWin(char b) +{ + switch (flt_out) + { + case flt_none: + waddch(outp, b); + break; + case flt_hex: + { + char s[10]; + unsigned int u= b&0xff; + int i; + ohex_buf[ohex_ptr++]= b; + sprintf(s, "%02x ", u); + waddstr(outp, s); + if (ohex_ptr >= line_length) + { + for (i= 0; i < line_length; i++) + { + u= ohex_buf[i]; + waddch(outp, isprint(u)?u:'.'); + } + waddch(outp, '\n'); + ohex_ptr= 0; + sprintf(s, "%06x ", ocnt); + waddstr(outp, s); + } + break; + } + } + ocnt++; + wrefresh(outp); + wrefresh(inp); +} + +int Viewer::GetChInWin(char *res) +{ + int b = wgetch(inp); + int ret= 1; + char c= b; + + if (b==ERR) + { + return 0; + } + else + { + b= b & 0xff; + if (b == 4) + return -2; + switch (flt_in) + { + case flt_none: + { + char c= b; + if (!isprint(b) && + (b != '\n') && + (b != '\r')) + c= ' '; + waddch(inp, c); + wrefresh(inp); + break; + } + case flt_hex: + { + char s[10]; + s[0]= c; + s[1]= 0; + if (!isxdigit(b)) + return 0; + if (ihex_high) + { + ihex_val= strtol(s, NULL, 16); + ihex_high= 0; + waddch(inp, c); + wrefresh(inp); + return 0; + } + else + { + ihex_val*= 16; + ihex_val+= strtol(s, NULL, 16); + waddch(inp, c); + waddch(inp, ' '); + wrefresh(inp); + ihex_high= 1; + b= ihex_val; + ret= 1; + } + break; + } + } + } + + if (res) + *res= b; + + return ret; +} diff --git a/sim/ucsim/gui.src/serio.src/frontend.hh b/sim/ucsim/gui.src/serio.src/frontend.hh new file mode 100644 index 0000000..c7330ff --- /dev/null +++ b/sim/ucsim/gui.src/serio.src/frontend.hh @@ -0,0 +1,64 @@ +/****************************************************************************** + * to emulate the serial input and output of an 8051 controller * + * frontend.hh - ncurses frontend * + ******************************************************************************/ +#ifndef FRONTEND_HEADER +#define FRONTEND_HEADER + +#include <sys/types.h> +#include <curses.h> +#include <stdint.h> + +#include "config.h" + +struct COORDS_S +{ + int min_x; + int max_x; + int min_y; + int max_y; +}; +typedef struct COORDS_S COORDS; + +struct COORDINATES_S +{ + int x; + int y; +}; +typedef struct COORDINATES_S COORDINATES; + +enum filter_t + { + flt_none, + flt_hex + }; + +class Viewer +{ +public: + Viewer(); + virtual ~Viewer(); + virtual void DrawBox(void); + virtual void AddStrOutWin(char *string); + virtual void GetStrInWin(char *string); + virtual void AddChOutWin(char b); + virtual int GetChInWin(char *res); + + virtual void iflt_mode(enum filter_t iflt); + virtual void oflt_mode(enum filter_t oflt); + virtual void set_length(int l); + +private: + WINDOW *inp, *outp; + COORDS win_c, inp_c, outp_c; + COORDINATES topleft, bottomright, current; + int middle_y, middle_x; + enum filter_t flt_in, flt_out; + unsigned int ocnt, icnt; + int line_length; + + uint8_t ohex_buf[16], ihex_buf[16]; + int ohex_ptr, ihex_ptr, ihex_high, ihex_val; +}; + +#endif diff --git a/sim/ucsim/gui.src/serio.src/main.cc b/sim/ucsim/gui.src/serio.src/main.cc new file mode 100644 index 0000000..cd55540 --- /dev/null +++ b/sim/ucsim/gui.src/serio.src/main.cc @@ -0,0 +1,439 @@ +/****************************************************************************** + * to emulate the serial input and output of an 8051 controller * + * main.cc - the main stuff * + ******************************************************************************/ +#include "ddconfig.h" + +#include <sys/types.h> +#include <iostream> +#include <stdlib.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> +#include <string.h> +#include <unistd.h> +#include <signal.h> + +#if defined(HAVE_GETOPT_H) +# include <getopt.h> +#endif + +#include "fileio.hh" +#include "frontend.hh" +#include "posix_signal.hh" + +Viewer *view; +FileIO *fobj; + +struct auto_answer_t { + char *pattern; + int p_len; + char *answer; + int a_len; +}; + +enum + { + aa_len= 100 + }; + + +struct auto_answer_t aa[aa_len]; +int max_pattern_len= 0; +int aa_p_num= 0; +int aa_a_num= 0; +char *aa_queue; +int aa_q_len= 0; + + +void +init_aa() +{ + int i; + for (i= 0; i < aa_len; i++) + { + aa[i].pattern= 0; + aa[i].p_len= 0; + aa[i].answer= 0; + aa[i].a_len= 0; + } +} + +void +start_aa() +{ + if (max_pattern_len > 0) + { + aa_queue= (char*)malloc(max_pattern_len); + aa_queue[0]= 0; + } + else + aa_queue= NULL; +} + +void +new_aa_pattern(char *s, int len) +{ + if (aa_p_num < aa_len) + { + aa[aa_p_num].pattern= s; + aa[aa_p_num].p_len= len; + aa_p_num++; + if (len > max_pattern_len) + max_pattern_len= len; + } +} + +void +new_aa_answer(char *s, int len) +{ + if (aa_a_num < aa_len) + { + aa[aa_a_num].answer= s; + aa[aa_a_num].a_len= len; + aa_a_num++; + } +} + +// 0: no match +// 1: partial match +// 2: full match +int +check_pattern(char *p, int pl, char *q, int ql) +{ + int m= pl, i; + if (ql < m) + m= ql; + if (m == 0) + return 0; + for (i= 0; i<m; i++) + { + if (p[i] != q[i]) + break; + } + if (i != m) + return 0; + if (pl == ql) + return 2; + return 1; +} + +struct auto_answer_t * +get_aa(int *partial) +{ + + return 0; +} + +void +shift_queue() +{ + int i; + if (aa_queue) + { + for (i= 1; i<aa_q_len; i++) + aa_queue[i-1]= aa_queue[i]; + aa_queue[--aa_q_len]= 0; + } +} + +void +aa_proc(char c) +{ + int i, p; + // add to queue + if (!aa_queue) + return; + if (aa_q_len >= max_pattern_len) + shift_queue(); + aa_queue[aa_q_len++]= c; + // search + for (i=p= 0; i < aa_p_num; i++) + { + int m= check_pattern(aa[i].pattern, aa[i].p_len, aa_queue, aa_q_len); + if (m == 2) + { + // found a full match + int j; + for (j=0; j < aa[i].a_len; j++) + { + fobj->SendByte(aa[i].answer[j]); + } + shift_queue(); + return; + } + if (m == 1) + p++; + } + if (!p) + shift_queue(); +} + +// globals +int doloop = 1; + +// the signal handler +void HandleSig(int info) +{ + doloop = 0; +} + +int +hex2bin(char h) +{ + int cv= 0; + if ((h >= '0') && (h <= '9')) + cv= h-'0'; + else if ((h >= 'A') && (h <= 'F')) + cv= 10 + h-'A'; + else if ((h >= 'a') && (h <= 'f')) + cv= 10 + h-'a'; + return cv; +} + +/* Convert C escapes into bin chars */ + +char * +unesc_cstr(char *s, int *len) +{ + char *d= (char*)malloc(strlen(s)); + int i, j; + d[j= 0]= 0; + for (i= 0; s[i]!=0; i++) + { + if (s[i]=='\\') + { + if (s[++i]==0) + break; + switch (s[i]) + { + case 'a': d[j++]= '\a'; d[j]= 0; break; + case 'b': d[j++]= '\b'; d[j]= 0; break; + case 'e': d[j++]= 27; d[j]= 0; break; + case 'f': d[j++]= '\f'; d[j]= 0; break; + case 'n': d[j++]= '\n'; d[j]= 0; break; + case 'r': d[j++]= '\r'; d[j]= 0; break; + case 't': d[j++]= '\t'; d[j]= 0; break; + case 'v': d[j++]= '\v'; d[j]= 0; break; + case '\\': d[j++]= '\\'; d[j]= 0; break; + case '\'': d[j++]= '\''; d[j]= 0; break; + case '\"': d[j++]= '\"'; d[j]= 0; break; + case '?': d[j++]= '?'; d[j]= 0; break; + case 'x': + { + if (s[++i]==0) + break; + int n= 0, l= strspn(&s[i], "0123456789abcdefABCDEF"), v= 0, cv; + do + { + cv= hex2bin(s[i]); + v= (v*16) + cv; + if (s[++i]==0) + break; + } + while (++n < l); + d[j++]= v&0xff; + d[j]= 0; + i--; + break; + } + case 'u': + { + if (s[++i]==0) + break; + int n= 0, l= 4, v= 0, cv; + do + { + cv= hex2bin(s[i]); + v= (v*16) + cv; + if (s[++i]==0) + break; + } + while (++n < l); + d[j++]= v&0xff; + d[j]= 0; + i--; + break; + } + case 'U': + { + if (s[++i]==0) + break; + int n= 0, l= 8, v= 0, cv; + do + { + cv= hex2bin(s[i]); + v= (v*16) + cv; + if (s[++i]==0) + break; + } + while (++n < l); + d[j++]= v&0xff; + d[j]= 0; + i--; + break; + } + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + { + int n= 0, l= strspn(&s[i], "01234567"), v= 0; + if (l>3) + l= 3; + do + { + v= (v*8) + (s[i]-'0'); + if (s[++i]==0) + break; + } + while (++n < l); + d[j++]= v&0xff; + d[j]= 0; + i--; + break; + } + default: + d[j++]= s[i]; + d[j]= 0; + break; + } + if (s[i]==0) + break; + } + else + { + d[j++]= s[i]; + d[j]= 0; + } + } + if (len) + *len= j; + return d; +} + +// usage +void PrintUsage(char *progname) +{ + std::cout << "Usage: " << progname << " [-i <filename>] [-o <filename>] [-hIO]\n"; + std::cout << "-i <filename>\t<filename> is the pipe to the controllers' serial input\n"; + std::cout << "-o <filename>\t<filename> is the pipe to the controllers' serial output\n"; + std::cout << "-I \t\thexa filter on input\n"; + std::cout << "-O \t\thexa filter on output\n"; + std::cout << "-L n\t\tSet line length of hex dump in output panel (def=8)\n"; + std::cout << "-a string\tPattern for autoanswer\n"; + std::cout << "-A string\tAnswer for autoanswer\n"; + std::cout << "-h\t\tshow the help\n"; + std::cout << "\nTim Hurman - t.hurman@virgin.net\n"; + exit(0); +} + + +// the main function +int main(int argc, char **argv) +{ + char *string = new char[MAX_SIZ]; + extern char *optarg; + int errflg=0; + int c, l= 8; + enum filter_t fi= flt_none, fo= flt_none; + const char *infile = DEF_INFILE; + const char *outfile = DEF_OUTFILE; + + // sort out any command line params + while ((c = getopt(argc, argv, "i:o:hOIL:a:A:")) != EOF) + switch(c) { + case 'i': + infile = optarg; + break; + case 'o': + outfile = optarg; + break; + case 'I': + fi= flt_hex; + break; + case 'O': + fo= flt_hex; + break; + case 'L': + l= strtol(optarg, 0, 0); + break; + case 'h': + errflg++; + break; + case 'a': + { + int l; + char *s= unesc_cstr(optarg, &l); + new_aa_pattern(s, l); + break; + } + case 'A': + { + int l; + char *s= unesc_cstr(optarg, &l); + new_aa_answer(s, l); + break; + } + default: + std::cerr << "Invalid or unknown switch\n"; + errflg++; + break; + } + + // was there a problem + if(errflg) + PrintUsage(argv[0]); + + // the main objects needed + view = new Viewer(); + fobj = new FileIO(infile, outfile); + SigHandler *sig = new SigHandler(); + + view->iflt_mode(fi); + view->oflt_mode(fo); + view->set_length(l); + + // add a signal handler for ^C + sig->SetSignal(SIGINT, HandleSig); + + start_aa(); + // set the timeout for waiting for a char + fd_set s; + while(doloop) + { + int ret, i; + FD_ZERO(&s); + FD_SET(fileno(stdin), &s); + FD_SET(fobj->infile_id(), &s); + + i= select(FD_SETSIZE, &s, NULL, NULL, NULL); + if (i >= 0) + { + if (FD_ISSET(fileno(stdin), &s)) + { + ret= view->GetChInWin(&string[0]); + if (ret > 0) + { + fobj->SendByte(string[0]); + } + else if (ret < 0) + break; + } + + if (FD_ISSET(fobj->infile_id(), &s)) + { + if (fobj->RecvByte(string) > 0) + { + aa_proc(string[0]); + view->AddChOutWin(string[0]); + } + } + } + //usleep(5000); + } + + delete fobj; + delete view; + delete sig; + delete string; + return(0); +} diff --git a/sim/ucsim/gui.src/serio.src/posix_signal.cc b/sim/ucsim/gui.src/serio.src/posix_signal.cc new file mode 100644 index 0000000..8183f57 --- /dev/null +++ b/sim/ucsim/gui.src/serio.src/posix_signal.cc @@ -0,0 +1,106 @@ +/****************************************************************************** + * posix_signal.cc - A signal handleing class for linux + solaris * + * to convert posix into somthing easier to use * + * Tim Hurman - t.hurman@virgin.net * + * Last edited on 01th Oct 19999 * + ******************************************************************************/ +/* + * A quick note, fscking linux, none of this would be neccessary if + * linux contained support for sighold, sigrelse, sigignore and sigpause. + * + */ + +#include <sys/types.h> +#include <iostream> +#include <sys/wait.h> /* header for waitpid() and various macros */ +#include <signal.h> /* header for signal functions */ +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <strings.h> +#include <errno.h> + +#include "posix_signal.hh" + +// constructor +SigHandler::SigHandler() +{ +} + +// destructor +SigHandler::~SigHandler() +{ +} + +/* set a signal */ +int SigHandler::SetSignal(int SIGNAL, SIG_PF ACTION) +{ + struct sigaction act; + + /* declare what is going to be called when */ + act.sa_handler = ACTION; + + /* clear the structure's mask */ + sigemptyset(&act.sa_mask); + + /* set up some flags */ + if(SIGNAL == SIGCHLD) { + act.sa_flags = SA_NOCLDSTOP; + } + + /* set the signal handler */ + if(sigaction(SIGNAL, &act, NULL) < 0) + { + std::cerr << "sigaction(): " << strerror(errno) << "\n"; + exit(-1); + } + + /* all ok */ + return(0); +} + + +/* block a signal */ +int SigHandler::BlockSignal(int SIGNAL) +{ + sigset_t set; + + /* initalise */ + sigemptyset(&set); + + /* add the SIGNAL to the set */ + sigaddset(&set, SIGNAL); + + /* block it */ + if(sigprocmask(SIG_BLOCK, &set, NULL) < 0) + { + std::cerr << "sigprocmask(): " << strerror(errno) << "\n"; + exit(-1); + } + + /* done */ + return(0); +} + + +/* unblock a signal */ +int SigHandler::UnBlockSignal(int SIGNAL) +{ + sigset_t set; + + /* initalise */ + sigemptyset(&set); + + /* add the SIGNAL to the set */ + sigaddset(&set, SIGNAL); + + /* block it */ + if(sigprocmask(SIG_UNBLOCK, &set, NULL) < 0) + { + std::cerr << "sigprocmask(): " << strerror(errno) << "\n"; + exit(-1); + } + + /* done */ + return(0); +} diff --git a/sim/ucsim/gui.src/serio.src/posix_signal.hh b/sim/ucsim/gui.src/serio.src/posix_signal.hh new file mode 100644 index 0000000..50935ad --- /dev/null +++ b/sim/ucsim/gui.src/serio.src/posix_signal.hh @@ -0,0 +1,22 @@ +/****************************************************************************** + * posix_signal.hh - A signal handleing class for linux + solaris * + * to convert posix into somthing easier to use * + * Tim Hurman - t.hurman@virgin.net * + * Last edited on 01th Oct 1999 * + ******************************************************************************/ +#ifndef POSIX_SIGNAL_HEADER +#define POSIX_SIGNAL_HEADER + +typedef void(*SIG_PF)(int); +class SigHandler +{ +public: + SigHandler(); + virtual ~SigHandler(); + + virtual int SetSignal(int SIGNAL, SIG_PF ACTION); + virtual int BlockSignal(int SIGNAL); + virtual int UnBlockSignal(int SIGNAL); +}; + +#endif |
