From f051c7ad170876a6510336d668d6e49b7c9ddfcd Mon Sep 17 00:00:00 2001 From: Tommy Thorn Date: Wed, 18 Mar 2009 17:07:23 -0700 Subject: [PATCH] wip --- Makefile | 18 +++- README | 2 +- nascom.c | 320 ++++++++++++++++++++++++++++++++++++------------------- simz80.c | 4 +- xvirtualnascom.c | 6 +- xvirtualnascom.h | 2 - 6 files changed, 230 insertions(+), 122 deletions(-) diff --git a/Makefile b/Makefile index c416ea0..f30f077 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,10 @@ CC =gcc # full speed or debugging to taste -OPTIMIZE =-O2 -#OPTIMIZE = -g -CFLAGS = $(OPTIMIZE) # $(CWARN) +#OPTIMIZE =-O2 +OPTIMIZE = -g +WARN = -Wmost -Werror +CFLAGS = $(OPTIMIZE) $(WARN) VIRTUALNASCOM_OBJS = simz80.o nascom.o xvirtualnascom.o @@ -16,7 +17,16 @@ LIBS =-lXpm -lXt -lX -lm CWARN = -ansi -pedantic -Wall -Wshadow \ -Wpointer-arith -Wnested-externs -Winline -all: +sdl-nascom: sdl-nascom.o simz80.o nascom.o + $(CC) $(shell sdl-config --libs) $^ -o $@ + +sdl-nascom.o: sdl-nascom.c + $(CC) $(CFLAGS) $(shell sdl-config --cflags) -c $< -o $@ + +ascii-nascom: ascii-nascom.o simz80.o nascom.o + $(CC) $(CFLAGS) $^ -o $@ + +all: -@echo Use \`make linux\' or \`make solaris\' linux: $(VIRTUALNASCOM_OBJS) diff --git a/README b/README index b90ab76..62333d8 100644 --- a/README +++ b/README @@ -4,7 +4,7 @@ This is a version 1.0.1, which although not finished is already very useful (runs every program I've tried). A very crucial part of VirtualNascom is the excellent z80 emulator -from Yaze, which is also copylefted. +from Yaze, which is also copylefted. INSTALLATION diff --git a/nascom.c b/nascom.c index 31d03a3..f3346f4 100644 --- a/nascom.c +++ b/nascom.c @@ -1,5 +1,5 @@ /* VirtualNascom, a Nascom II emulator. - + Copyright (C) 2000 Tommy Thorn Copyright (C) 1995,1998 Frank D. Cringle. @@ -40,95 +40,196 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include +#include +#include +#include +#include "simz80.h" +#include "nascom.h" + + +unsigned char keym[9] = { + 0, /* ? ? ? Shift ? ? ? ? */ + 0, /* ?!TXF5BH ! = Up*/ + 0, /* ?!YZD6NJ ! = Left*/ + 0, /* ?!USE7MK ! = Down */ + 0, /* ?!IAW8,L ! = Right */ + 0, /* ??OQ39.; */ + 0, /* ?[P120/: */ + 0, /* ?]R C4VG */ + 0 /* ? ? CR - Newline BS */ +}; -#include -#include -#include -#include -#include -#include +unsigned char keyp = 0; +unsigned char port0; -#define XK_MISCELLANY 1 -#include +static void +usage(void) +{ + fprintf(stderr, + "Usage: %s {flags} {commands}\n" + " -m use as monitor (default is nasysy3.nal)\n" + " -v verbose\n" + ,progname); + exit (1); +} -#include +void load_nascom(const char *file) +{ + FILE *f = fopen(file, "r"); + int a, b1, b2, b3, b4, b5, b6, b7, b8; + int count = 0; + int ch; + + if (!f) { + perror(file); + exit(1); + } -#include "simz80.h" -#include "xvirtualnascom.h" + if (vflag) + printf("Loading %s", file); + + for (; !feof(f) ;) { + if (fscanf(f, "%x %x %x %x %x %x %x %x %x", + &a, &b1, &b2, &b3, &b4, &b5, &b6, &b7, &b8) == 9) { + RAM(a) = b1; + RAM(a+1) = b2; + RAM(a+2) = b3; + RAM(a+3) = b4; + RAM(a+4) = b5; + RAM(a+5) = b6; + RAM(a+6) = b7; + RAM(a+7) = b8; + count += 8; + } + + do + ch = fgetc(f); + while (ch != -1 && ch != '\n'); + + if (ch == -1) + break; + } -#define INSCREEN(x) (((x) >> 10) == 2) + fclose(f); + if (vflag) + printf(". Successfully loaded %d bytes\n", count); +} -unsigned char keym[9] = +int main(int argc, char **argv) { - 0, /* ? ? ? Shift ? ? ? ? */ - 0, /* ?!TXF5BH ! = Up*/ - 0, /* ?!YZD6NJ ! = Left*/ - 0, /* ?!USE7MK ! = Down */ - 0, /* ?!IAW8,L ! = Right */ - 0, /* ??OQ39.; */ - 0, /* ?[P120/: */ - 0, /* ?]R C4VG */ - 0 /* ? ? CR - Newline BS */ -}; - -unsigned char keyp = 0; -unsigned char port0; + int c; + + setup(argc, argv); + + monitor = "nassys3.nal"; + progname = argv[0]; + + +#ifdef MMU + for (c=0; c +#include +#include +#include +#include +#include + +#define XK_MISCELLANY 1 +#include + void slow_write(unsigned int a, unsigned char v) { - if (INSCREEN(a)) - { - unsigned int y = (a-0x800) / 64; - unsigned int x = (a-0x800) % 64; - /* fprintf(stdout, "putbyte %04x %02x '%c'\n", a, v, v); */ - if (10 <= x && x < 58 && ' ' <= v) { - if (y == 15) - y = 0; - else - ++y; - - xputch(x-10, y, v); - } + if (INSCREEN(a)) { + unsigned int y = (a-0x800) / 64; + unsigned int x = (a-0x800) % 64; + /* fprintf(stdout, "putbyte %04x %02x '%c'\n", a, v, v); */ + if (10 <= x && x < 58 && ' ' <= v) { + if (y == 15) + y = 0; + else + ++y; + + xputch(x-10, y, v); + } } - if (0x800 <= a && a <= 0xE000) - RAM(a) = v; + if (0x800 <= a && a <= 0xE000) + RAM(a) = v; } static char * kbd_translation[] = { @@ -145,49 +246,48 @@ static char * kbd_translation[] = { void EventHandler(Widget w, caddr_t data, XEvent *ev) { - KeySym keysym; - int i = -1, bit = 0; - - if (ev->xany.type != KeyPress && ev->xany.type != KeyRelease) - return; - - keysym = XKeycodeToKeysym(dpy, ev->xkey.keycode, 0); - - if ((unsigned long) keysym < 128) { - int ch = toupper(keysym); - for (i = 0; i < 9; ++i) - for (bit = 0; bit < 8; ++bit) - if (kbd_translation[i][7-bit] == ch) - goto found; - i = -1; - found:; - } else - switch (keysym) { - case XK_Shift_L: - case XK_Shift_R: i = 0, bit = 4; break; - case XK_Up: i = 1, bit = 6; break; - case XK_Left: i = 2, bit = 6; break; - case XK_Down: i = 3, bit = 6; break; - case XK_Right: i = 4, bit = 6; break; - case XK_BackSpace: i = 8, bit = 0; break; - case XK_Return: i = 8, bit = 1; break; - case XK_End: - { - /* Undocumented hack */ - FILE *f; - f = fopen("screendump", "w"); - fwrite((const void *) (ram+0x800), 1, 1024, f); - fclose(f); - if (vflag) printf("Screen dumped\n"); - } - break; + KeySym keysym; + int i = -1, bit = 0; + + if (ev->xany.type != KeyPress && ev->xany.type != KeyRelease) + return; + + keysym = XKeycodeToKeysym(dpy, ev->xkey.keycode, 0); + + if ((unsigned long) keysym < 128) { + int ch = toupper(keysym); + for (i = 0; i < 9; ++i) + for (bit = 0; bit < 8; ++bit) + if (kbd_translation[i][7-bit] == ch) + goto found; + i = -1; + found:; + } else + switch (keysym) { + case XK_Shift_L: + case XK_Shift_R: i = 0, bit = 4; break; + case XK_Up: i = 1, bit = 6; break; + case XK_Left: i = 2, bit = 6; break; + case XK_Down: i = 3, bit = 6; break; + case XK_Right: i = 4, bit = 6; break; + case XK_BackSpace: i = 8, bit = 0; break; + case XK_Return: i = 8, bit = 1; break; + case XK_End: { + /* Undocumented hack */ + FILE *f; + f = fopen("screendump", "w"); + fwrite((const void *) (ram+0x800), 1, 1024, f); + fclose(f); + if (vflag) printf("Screen dumped\n"); + break; + }} + + if (i != -1) { + if (ev->xany.type == KeyPress) + keym[i] |= 1 << bit; + else + keym[i] &= ~(1 << bit); } - - if (i != -1) { - if (ev->xany.type == KeyPress) - keym[i] |= 1 << bit; - else - keym[i] &= ~(1 << bit); - } } +#endif diff --git a/simz80.c b/simz80.c index f975b79..d0ecd19 100644 --- a/simz80.c +++ b/simz80.c @@ -681,11 +681,11 @@ simz80(FASTREG PC, int count, void (*fnc)()) #else while (1) { #endif - if (--n == 0) { + if (fnc && --n == 0) { n = count; (*fnc)(); } - + switch(++PC,RAM(PC-1)) { case 0x00: /* NOP */ break; diff --git a/xvirtualnascom.c b/xvirtualnascom.c index 175d1a5..2d12cd2 100644 --- a/xvirtualnascom.c +++ b/xvirtualnascom.c @@ -1,5 +1,5 @@ /* VirtualNascom, a Nascom II emulator. - + Copyright (C) 2000 Tommy Thorn Copyright (C) 1995,1998 Frank D. Cringle. @@ -379,9 +379,9 @@ void RepaintCanvas(Widget w, caddr_t data, XEvent *ev) /* The Nascom screen memory has the top line be line 15 with line 0-14 just following it. Yes, stupid indeed */ - for (x = 0; x < 48; ++x) + for (x = 0; x < 48; ++x) xputch(x, 0, RAM(0x80a+64*15+x)); - + for (y = 0; y < 15; ++y) for (x = 0; x < 48; ++x) xputch(x, y+1, RAM(0x80a+y*64+x)); diff --git a/xvirtualnascom.h b/xvirtualnascom.h index 4104acf..c0f67f6 100644 --- a/xvirtualnascom.h +++ b/xvirtualnascom.h @@ -2,6 +2,4 @@ void xsetup(int, char **); void xhandleevent(void); void xputch(int x, int y, unsigned char v); -extern unsigned char keym[9]; Display *dpy; -int vflag; -- 2.11.4.GIT