1 /* VirtualNascom, a Nascom II emulator.
3 Copyright (C) 2000 Tommy Thorn
4 Copyright (C) 1995,1998 Frank D. Cringle.
6 NasEmu is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 - a bitmapped keyboard,
28 0000 - 07ff 2 KB ROM monitor,
29 0800 - 0bff 1 KB screen memory,
30 0c00 - 0fff 1 KB workspace
32 e000 - ffff 8 KB of MS Basic
34 With the Z80 emulator in place the first thing to get working is the
35 screen memory. The "correct" way to simulate screen memory is to
36 trap upon writes, but that would be slow. We do it any just to get
50 unsigned char keym
[9] = {
51 0, /* ? ? ? Shift ? ? ? ? */
52 0, /* ?!TXF5BH ! = Up*/
53 0, /* ?!YZD6NJ ! = Left*/
54 0, /* ?!USE7MK ! = Down */
55 0, /* ?!IAW8,L ! = Right */
59 0 /* ? ? CR - Newline BS */
62 unsigned char keyp
= 0;
69 "Usage: %s {flags} {commands}\n"
70 " -m <file> use <file> as monitor (default is nasysy3.nal)\n"
76 void load_nascom(const char *file
)
78 FILE *f
= fopen(file
, "r");
79 int a
, b1
, b2
, b3
, b4
, b5
, b6
, b7
, b8
;
89 printf("Loading %s", file
);
92 if (fscanf(f
, "%x %x %x %x %x %x %x %x %x",
93 &a
, &b1
, &b2
, &b3
, &b4
, &b5
, &b6
, &b7
, &b8
) == 9) {
107 while (ch
!= -1 && ch
!= '\n');
115 printf(". Successfully loaded %d bytes\n", count
);
118 int main(int argc
, char **argv
)
124 monitor
= "nassys3.nal";
129 for (c
=0; c
<MEMSIZE
/4; ++c
) pagetable
[c
]=ram
+(c
<<12);
132 while ((c
= getopt(argc
, argv
, "m:v")) != EOF
)
145 puts("VirtualNascom, a Nascom 2 emulator version " VERSION
"\n"
146 "Copyright 2000 Tommy Thorn. Based on\n"
147 "Yet Another Z80 Emulator version " YAZEVERSION
148 ", Copyright 1995,1998 Frank D. Cringle.\n"
149 "NasEmu comes with ABSOLUTELY NO WARRANTY; for details\n"
150 "see the file \"COPYING\" in the distribution directory.\n");
152 load_nascom(monitor
);
153 load_nascom("basic.nal");
155 for ( ; optind
< argc
; optind
++)
156 load_nascom(argv
[optind
]);
158 simz80(pc
, 20, NULL
/*xhandleevent*/);
160 fprintf(stderr
,"HALT\n\r");
161 fprintf(stderr
,"PC SP IR IX IY AF BC DE HL AF' BC' DE' HL'\n\r");
162 fprintf(stderr
,"%04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x\n\r",pc
,sp
,ir
,ix
,iy
,af
[af_sel
],regs
[regs_sel
].bc
,regs
[regs_sel
].de
,regs
[regs_sel
].hl
,af
[1-af_sel
],regs
[1-regs_sel
].bc
,regs
[1-regs_sel
].de
,regs
[1-regs_sel
].hl
);
166 void out(unsigned int port
, unsigned char value
)
168 unsigned int down_trans
;
170 if (0) fprintf(stdout
, "[%02x] <- %02x\n", port
, value
);
175 down_trans
= port0
& ~value
;
178 if ((1 & down_trans
) && keyp
< 9) keyp
++;
179 if (2 & down_trans
) keyp
= 0;
186 int in(unsigned int port
)
188 if (0) fprintf(stdout
, "<- [%02x]\n", port
);
193 /* printf("[%d]", keyp); */
196 /* Status port on the UART */
205 #include "xvirtualnascom.h"
206 #include <X11/Intrinsic.h>
207 #include <X11/StringDefs.h>
209 #include <X11/cursorfont.h>
210 #include <X11/Xutil.h>
213 #define XK_MISCELLANY 1
214 #include <X11/keysymdef.h>
216 void slow_write(unsigned int a
, unsigned char v
)
219 unsigned int y
= (a
-0x800) / 64;
220 unsigned int x
= (a
-0x800) % 64;
221 /* fprintf(stdout, "putbyte %04x %02x '%c'\n", a, v, v); */
222 if (10 <= x
&& x
< 58 && ' ' <= v
) {
231 if (0x800 <= a
&& a
<= 0xE000)
235 static char * kbd_translation
[] = {
244 /* 8 */ "x\rxxx-\n\007"
247 void EventHandler(Widget w
, caddr_t data
, XEvent
*ev
)
252 if (ev
->xany
.type
!= KeyPress
&& ev
->xany
.type
!= KeyRelease
)
255 keysym
= XKeycodeToKeysym(dpy
, ev
->xkey
.keycode
, 0);
257 if ((unsigned long) keysym
< 128) {
258 int ch
= toupper(keysym
);
259 for (i
= 0; i
< 9; ++i
)
260 for (bit
= 0; bit
< 8; ++bit
)
261 if (kbd_translation
[i
][7-bit
] == ch
)
268 case XK_Shift_R
: i
= 0, bit
= 4; break;
269 case XK_Up
: i
= 1, bit
= 6; break;
270 case XK_Left
: i
= 2, bit
= 6; break;
271 case XK_Down
: i
= 3, bit
= 6; break;
272 case XK_Right
: i
= 4, bit
= 6; break;
273 case XK_BackSpace
: i
= 8, bit
= 0; break;
274 case XK_Return
: i
= 8, bit
= 1; break;
276 /* Undocumented hack */
278 f
= fopen("screendump", "w");
279 fwrite((const void *) (ram
+0x800), 1, 1024, f
);
281 if (vflag
) printf("Screen dumped\n");
286 if (ev
->xany
.type
== KeyPress
)
289 keym
[i
] &= ~(1 << bit
);