diff io.c @ 9:cb7aa75418b8

mmu and io
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 05 Jul 2018 16:00:19 +0900
parents a6db579d8c11
children 2a1338b218bf
line wrap: on
line diff
--- a/io.c	Thu Jul 05 12:07:06 2018 +0900
+++ b/io.c	Thu Jul 05 16:00:19 2018 +0900
@@ -1,8 +1,8 @@
-/* 6808 Simulator V09.
-
-   created 1993,1994 by L.C. Benschop.
-   copyleft (c) 1994-2014 by the sbc09 team, see AUTHORS for more details.
-   license: GNU General Public License version 2, see LICENSE for more details.
+/* 6808 Simulator V092
+  created 1993,1994 by L.C. Benschop.  copyleft (c) 1994-2014
+by the sbc09 team, see AUTHORS for more details.  license: 
+GNU General Public License version 2, see LICENSE for more 
+details. 
 
    This program simulates a 6809 processor.
 
@@ -99,6 +99,11 @@
 
 extern void hexadump( unsigned char *b, int l, int loc, int w);
 extern void disasm(int,int);
+#ifdef USE_MMU
+extern char *prog ;   // for disass
+extern Byte * mem1(Byte *iphymem, Word adr, Byte *immu) ;
+#endif
+
 
 void do_timer(int,int);
 void do_disk(int,int);
@@ -180,7 +185,7 @@
         }
 }
 
-int do_input( a) {
+int do_input(int a) {
         static int c, f = EOF;
         if (a == 0+(IOPAGE&0xff)) {
                 if (f == EOF)
@@ -197,7 +202,7 @@
                 }
                 return c;
         }
-        return mem[IOPAGE + a];
+        return mem[(IOPAGE&0xff00) + a];
 }
 
 void do_output(int a, int c) {
@@ -270,17 +275,17 @@
 
 void do_timer(int a, int c) {
    struct itimerval timercontrol;
-   if (a==0x30 && c==0x8f) {
+   if (a==0x30+(IOPAGE&0xff) && c==0x8f) {
         timercontrol.it_interval.tv_sec = 0;
         timercontrol.it_interval.tv_usec = 20000;
         timercontrol.it_value.tv_sec = 0;
         timercontrol.it_value.tv_usec = 20000;
         setitimer(ITIMER_REAL, &timercontrol, NULL);
-   } else if (a==0x30 && c==0x80) {
+   } else if (a==0x30+(IOPAGE&0xff) && c==0x80) {
         timercontrol.it_interval.tv_sec = 0;
         timercontrol.it_interval.tv_usec = 0;
         setitimer(ITIMER_REAL, &timercontrol, NULL);
-   } else if (a==0x30 && c==0x04) {
+   } else if (a==0x30+(IOPAGE&0xff) && c==0x04) {
       time_t tm = time(0);
       struct tm *t = localtime(&tm);
       mem[IOPAGE+0x31] = t->tm_year;
@@ -290,13 +295,13 @@
       mem[IOPAGE+0x35] = t->tm_min;
       mem[IOPAGE+0x36] = t->tm_sec;
    } else {
-      mem[IOPAGE+a]=c;
+      mem[(IOPAGE&0xff00)+a]=c;
    }
 }
 
 void do_disk(int a, int c) {
-   if (a!=0x40) {
-      mem[IOPAGE+a]=c;
+   if (a!=0x40+(IOPAGE&0xff)) {
+      mem[(IOPAGE&0xff00)+a]=c;
       return;
    }
    int drv = mem[IOPAGE+0x41];
@@ -320,15 +325,15 @@
 {
 #ifdef USE_MMU
 
-   if (a==0x11) {
+   if (a==0x11+(IOPAGE&0xff)) {
        if (c&0) {
            mmu = phymem+memsize-0x10000+0xffa0;
        } else {
            mmu = phymem+memsize-0x10000+0xffa8;
        }
-       mem[IOPAGE+a] = c;
-   } if (0x20 <= a && a <= 0x2f) {
-       mem[IOPAGE+a] = c;
+       mem[(IOPAGE&0xff00)+a] = c;
+   } if (0x20+(IOPAGE&0xff) <= a && a <= 0x2f+(IOPAGE&0xff)) {
+       mem[(IOPAGE&0xff00)+a] = c;
    }
 
 #endif 
@@ -360,6 +365,9 @@
      "  d [n]      delte break point list\n"
      "  c  [count] continue;\n"
      "  x  [adr]   dump\n"
+#ifdef USE_MMU
+     "  xp [adr]   dump physical memory\n"
+#endif
      "  xi [adr]   disassemble\n"
      "  0  file    disk drive 0 image\n"
      "  1  file    disk drive 1 image\n"
@@ -395,6 +403,10 @@
 restart0:
         stkskip = 0;
         restore_term();
+#ifdef USE_MMU
+        Byte *phyadr = mem1(phymem,pcreg,mmu);
+        prog = (char*)phyadr - pcreg;
+#endif
         do_trace(stdout);
         if (trskip>1) { // show trace and step
             trskip--;
@@ -471,6 +483,7 @@
         case 'x':   // dump
                 skip = 1;
                 if (s[1]=='i') skip=2;
+                if (s[1]=='p') skip=2;
                 if (s[skip]) {
                    char *next;
                    int adr = getarg(s+skip,&next);
@@ -478,12 +491,31 @@
                    if (next[0]) {
                       len =  getarg(next,&next);
                    }
-                   if (skip==2) {
-                        disasm(adr,adr+len);
+                   if (skip==2 && s[1]=='i') {
+                     for(int i=0; len > 0 ; i+=16, len-=16) {
+#ifdef USE_MMU
+                        Byte *phyadr = mem1(phymem,adr+i,mmu);
+                        prog = (char*)phyadr - adr;
+#endif
+                        disasm(adr,adr+((i>len)?len:i));
+                      }
                    } else {
+#ifdef USE_MMU
+                     for(int i=0; len > 0 ; i+=16, len-=16) {
+                        if (skip==2 && s[1]=='p') {
+                            if (adr+i > memsize) goto restart;
+                            hexadump(phymem+adr+i,len>16?16:len,adr+i,16);
+                        } else {
+                            Byte *phyadr = mem1(phymem,adr+i,mmu);
+                            if (phyadr > phymem+memsize) goto restart;
+                            hexadump(phyadr,len>16?16:len,adr+i,16);
+                        }
+                     }
+#else
                      for(int i=0; len > 0 ; i+=16, len-=16) {
                         hexadump(mem+adr+i,len>16?16:len,adr+i,16);
                      }
+#endif
                    }
                 } else 
                    disasm(pcreg,pcreg+32);