Mercurial > hg > Members > kono > os9 > sbc09
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/v09.c Mon Jul 02 02:12:31 2018 +0900 @@ -0,0 +1,146 @@ +/* 6809 Simulator V09. + + Copyright 1994, L.C. Benschop, Eidnhoven The Netherlands. + This version of the program is distributed under the terms and conditions + of the GNU General Public License version 2. See the file COPYING. + THERE IS NO WARRANTY ON THIS PROGRAM!!! + + This program simulates a 6809 processor. + + System dependencies: short must be 16 bits. + char must be 8 bits. + long must be more than 16 bits. + arrays up to 65536 bytes must be supported. + machine must be twos complement. + Most Unix machines will work. For MSODS you need long pointers + and you may have to malloc() the mem array of 65536 bytes. + + Define BIG_ENDIAN if you have a big-endian machine (680x0 etc) + + Special instructions: + SWI2 writes char to stdout from register B. + SWI3 reads char from stdout to register B, sets carry at EOF. + (or when no key available when using term control). + SWI retains its normal function. + CWAI and SYNC stop simulator. + +*/ + + +#include <stdio.h> +#include <stdlib.h> +#include <strings.h> +#include <sys/stat.h> + +#define engine extern + +#include "v09.h" + +FILE *tracefile; + +extern FILE *fp; +extern char *prog; +extern void disasm(int,int); + +void do_trace(FILE *tracefile) +{ + Word pc=pcreg; + Byte ir; + // fprintf(tracefile,"pc=%04x ",pc); + // ir=mem[pc++]; + // fprintf(tracefile,"i=%02x ",ir); if((ir&0xfe)==0x10) fprintf(tracefile,"%02x ",mem[pc]);else + // fprintf(tracefile," "); + fprintf(tracefile,"x=%04x y=%04x u=%04x s=%04x a=%02x b=%02x cc=%02x pc=", + xreg,yreg,ureg,sreg,*areg,*breg,ccreg); + fp = tracefile; + prog = (char*)mem; + disasm(pc,pc); +} + +char *romfile = "v09.rom"; +int romstart = 0x8000; + +long +filesize(FILE *image) +{ + struct stat buf; + fstat(fileno(image),&buf); + return buf.st_size; +} + + +void +read_image() +{ + FILE *image; + if((image=fopen(romfile,"rb"))==NULL) + if((image=fopen("../v09.rom","rb"))==NULL) + if((image=fopen("..\\v09.rom","rb"))==NULL) { + perror("v09, image file"); + exit(2); + } + long len = filesize(image); + fread(mem+romstart,len,1,image); + fclose(image); +} + +void usage(void) +{ + fprintf(stderr,"Usage: v09 [-l romstart] [-rom rom-image] [-t tracefile [-tl addr] [-nt]" + "[-th addr] ]\n[-e escchar] \n"); + exit(1); +} + + +#define CHECKARG if(i==argc)usage();else i++; + +int +main(int argc,char *argv[]) +{ + Word loadaddr=0x100; + char *imagename=0; + int i; + int setterm = 1; + escchar='\x1d'; + tracelo=0;tracehi=0xffff; + for(i=1;i<argc;i++) { + if (strcmp(argv[i],"-t")==0) { + i++; + if((tracefile=fopen(argv[i],"w"))==NULL) { + perror("v09, tracefile"); + exit(2); + } + tracing=1;attention=1; + } else if (strcmp(argv[i],"-rom")==0) { + i++; + romfile = argv[i]; + } else if (strcmp(argv[i],"-tl")==0) { + i++; + tracelo=strtol(argv[i],(char**)0,0); + } else if (strcmp(argv[i],"-th")==0) { + i++; + tracehi=strtol(argv[i],(char**)0,0); + } else if (strcmp(argv[i],"-e")==0) { + i++; + escchar=strtol(argv[i],(char**)0,0); + } else if (strcmp(argv[i],"-l")==0) { + i++; + romstart=strtol(argv[i],(char**)0,0); + } else if (strcmp(argv[i],"-nt")==0) { + attention = escape = 1; + timer = 0; + } else usage(); + } + #ifdef MSDOS + if((mem=farmalloc(65535))==0) { + fprintf(stderr,"Not enough memory\n"); + exit(2); + } + #endif + read_image(); + if (setterm) set_term(escchar); + pcreg=(mem[0xfffe]<<8)+mem[0xffff]; + interpr(); + return 0; +} +