comparison v09.c @ 0:9a224bd9b45f

os9 emulation
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 02 Jul 2018 02:12:31 +0900
parents
children 3c736a81b886
comparison
equal deleted inserted replaced
-1:000000000000 0:9a224bd9b45f
1 /* 6809 Simulator V09.
2
3 Copyright 1994, L.C. Benschop, Eidnhoven The Netherlands.
4 This version of the program is distributed under the terms and conditions
5 of the GNU General Public License version 2. See the file COPYING.
6 THERE IS NO WARRANTY ON THIS PROGRAM!!!
7
8 This program simulates a 6809 processor.
9
10 System dependencies: short must be 16 bits.
11 char must be 8 bits.
12 long must be more than 16 bits.
13 arrays up to 65536 bytes must be supported.
14 machine must be twos complement.
15 Most Unix machines will work. For MSODS you need long pointers
16 and you may have to malloc() the mem array of 65536 bytes.
17
18 Define BIG_ENDIAN if you have a big-endian machine (680x0 etc)
19
20 Special instructions:
21 SWI2 writes char to stdout from register B.
22 SWI3 reads char from stdout to register B, sets carry at EOF.
23 (or when no key available when using term control).
24 SWI retains its normal function.
25 CWAI and SYNC stop simulator.
26
27 */
28
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <strings.h>
33 #include <sys/stat.h>
34
35 #define engine extern
36
37 #include "v09.h"
38
39 FILE *tracefile;
40
41 extern FILE *fp;
42 extern char *prog;
43 extern void disasm(int,int);
44
45 void do_trace(FILE *tracefile)
46 {
47 Word pc=pcreg;
48 Byte ir;
49 // fprintf(tracefile,"pc=%04x ",pc);
50 // ir=mem[pc++];
51 // fprintf(tracefile,"i=%02x ",ir); if((ir&0xfe)==0x10) fprintf(tracefile,"%02x ",mem[pc]);else
52 // fprintf(tracefile," ");
53 fprintf(tracefile,"x=%04x y=%04x u=%04x s=%04x a=%02x b=%02x cc=%02x pc=",
54 xreg,yreg,ureg,sreg,*areg,*breg,ccreg);
55 fp = tracefile;
56 prog = (char*)mem;
57 disasm(pc,pc);
58 }
59
60 char *romfile = "v09.rom";
61 int romstart = 0x8000;
62
63 long
64 filesize(FILE *image)
65 {
66 struct stat buf;
67 fstat(fileno(image),&buf);
68 return buf.st_size;
69 }
70
71
72 void
73 read_image()
74 {
75 FILE *image;
76 if((image=fopen(romfile,"rb"))==NULL)
77 if((image=fopen("../v09.rom","rb"))==NULL)
78 if((image=fopen("..\\v09.rom","rb"))==NULL) {
79 perror("v09, image file");
80 exit(2);
81 }
82 long len = filesize(image);
83 fread(mem+romstart,len,1,image);
84 fclose(image);
85 }
86
87 void usage(void)
88 {
89 fprintf(stderr,"Usage: v09 [-l romstart] [-rom rom-image] [-t tracefile [-tl addr] [-nt]"
90 "[-th addr] ]\n[-e escchar] \n");
91 exit(1);
92 }
93
94
95 #define CHECKARG if(i==argc)usage();else i++;
96
97 int
98 main(int argc,char *argv[])
99 {
100 Word loadaddr=0x100;
101 char *imagename=0;
102 int i;
103 int setterm = 1;
104 escchar='\x1d';
105 tracelo=0;tracehi=0xffff;
106 for(i=1;i<argc;i++) {
107 if (strcmp(argv[i],"-t")==0) {
108 i++;
109 if((tracefile=fopen(argv[i],"w"))==NULL) {
110 perror("v09, tracefile");
111 exit(2);
112 }
113 tracing=1;attention=1;
114 } else if (strcmp(argv[i],"-rom")==0) {
115 i++;
116 romfile = argv[i];
117 } else if (strcmp(argv[i],"-tl")==0) {
118 i++;
119 tracelo=strtol(argv[i],(char**)0,0);
120 } else if (strcmp(argv[i],"-th")==0) {
121 i++;
122 tracehi=strtol(argv[i],(char**)0,0);
123 } else if (strcmp(argv[i],"-e")==0) {
124 i++;
125 escchar=strtol(argv[i],(char**)0,0);
126 } else if (strcmp(argv[i],"-l")==0) {
127 i++;
128 romstart=strtol(argv[i],(char**)0,0);
129 } else if (strcmp(argv[i],"-nt")==0) {
130 attention = escape = 1;
131 timer = 0;
132 } else usage();
133 }
134 #ifdef MSDOS
135 if((mem=farmalloc(65535))==0) {
136 fprintf(stderr,"Not enough memory\n");
137 exit(2);
138 }
139 #endif
140 read_image();
141 if (setterm) set_term(escchar);
142 pcreg=(mem[0xfffe]<<8)+mem[0xffff];
143 interpr();
144 return 0;
145 }
146