# HG changeset patch # User Shinji KONO # Date 1531064405 -32400 # Node ID e3b08716aa53de3a7864a7f487f769a6c1b04e95 # Parent 67046a9431a0d156f0f0b45065da7a0e8c5700e9 fix mmu diff -r 67046a9431a0 -r e3b08716aa53 engine.c --- a/engine.c Sun Jul 08 16:15:34 2018 +0900 +++ b/engine.c Mon Jul 09 00:40:05 2018 +0900 @@ -42,12 +42,13 @@ #ifdef USE_MMU Byte * mem0(Byte *iphymem, Word adr, Byte *immu) { + if ((adr&0xfe00)==(IOPAGE&0xfe00)) return &mem[adr]; int addr = (immu[ (adr) >> 13 ] <<13 ) + ((adr) & 0x1fff ); return & iphymem[ addr ]; -}; +} static Byte mem1(Byte *iphymem, Word adr, Byte *immu) { - if ((adr&0xff00)==(IOPAGE&0xff00)) return do_input(adr&0xff); + if ((adr&0xfe00)==(IOPAGE&0xfe00)) return do_input(adr&0x1ff); Byte *p = mem0(iphymem, adr, immu); if(!(p-phymem>=rommemsize)) { return *p; @@ -58,25 +59,29 @@ #define mem(a) mem1(iphymem,a,immu) -static void SETBYTE1(Byte n,Byte *iphymem, Word adr, Byte *immu) { - if ((adr&0xff00)==(IOPAGE&0xff00)) do_output(adr&0xff,n); - Byte *p = mem0(iphymem, adr, immu); - if(!(p-phymem>=romstart)) { - *p=n; - } -} +#define SETBYTE(a,n) { \ + Word adr = a; \ + if ((adr&0xfe00)==(IOPAGE&0xfe00)) { \ + do_output(adr&0x1ff,n); \ + immu = mmu; \ + } else {\ + Byte *p = mem0(iphymem, adr,immu); \ + if(!(p-phymem>=romstart)) { \ + *p=n; \ + } \ + } \ +} -#define SETBYTE(a,n) SETBYTE1(n,iphymem,a,immu); #else static Byte mem1(Word adr) { - if ((adr&0xff00)==(IOPAGE&0xff00)) return do_input(adr&0xff); + if ((adr&0xfe00)==(IOPAGE&0xfe00)) return do_input(adr&0x1ff); return mem[adr]; } static void SETBYTE1(Word a,Byte n) { - if ((a&0xff00)==(IOPAGE&0xff00)) do_output(a&0xff,n); + if ((a&0xfe00)==(IOPAGE&0xfe00)) do_output(a&0x1ff,n); if(!(a>=romstart))mem[a]=n; } #define mem(a) mem1(a) @@ -233,8 +238,8 @@ if(tracing && ipcreg>=tracelo && ipcreg<=tracehi) { SAVEREGS #ifdef USE_MMU - Byte *phyadr = mem0(phymem,pcreg,immu); - prog = (char *)(phyadr - pcreg); + Byte *phyadr = mem0(phymem,ipcreg,immu); + prog = (char *)(phyadr - ipcreg); #endif do_trace(tracefile); } diff -r 67046a9431a0 -r e3b08716aa53 io.c --- a/io.c Sun Jul 08 16:15:34 2018 +0900 +++ b/io.c Mon Jul 09 00:40:05 2018 +0900 @@ -49,7 +49,7 @@ * IOPAGE ~ IOPAGE+0x7f * for OS9 level2 * IOPAGE 0xff80 means ioport beging 0xff80 but IOPAGE itself starts 0xff00 - * 0xff00-0xff7f, 0xffe0-0xffff can be used as ROM in fixed area + * 0xfe00-0xff7f, 0xffe0-0xffff can be used as ROM in fixed area * * IOPAGE + 0x00 ACIA control * IOPAGE + 0x01 ACIA data @@ -187,13 +187,13 @@ int do_input(int a) { static int c, f = EOF; - if (a == 0+(IOPAGE&0xff)) { + if (a == 0+(IOPAGE&0x1ff)) { if (f == EOF) f = char_input(); if (f != EOF) c = f; return 2 + (f != EOF); - } else if (a == 1+(IOPAGE&0xff)) { /*data port*/ + } else if (a == 1+(IOPAGE&0x1ff)) { /*data port*/ if (f == EOF) f = char_input(); if (f != EOF) { @@ -202,12 +202,12 @@ } return c; } - return mem[(IOPAGE&0xff00) + a]; + return mem[(IOPAGE&0xfe00) + a]; } void do_output(int a, int c) { int i, sum; - if (a == 1+(IOPAGE&0xff)) { /* ACIA data port,ignore address */ + if (a == 1+(IOPAGE&0x1ff)) { /* ACIA data port,ignore address */ if (!xmstat) { if (logfile && c != 127 && (c >= ' ' || c == '\n')) putc(c, logfile); @@ -253,11 +253,11 @@ xidx = 0; } } - } else if (a >= 0x40+(IOPAGE&0xff)) { /* disk */ + } else if (a >= 0x40+(IOPAGE&0x1ff)) { /* disk */ do_disk(a,c); - } else if (a >= 0x30+(IOPAGE&0xff)) { /* timer */ + } else if (a >= 0x30+(IOPAGE&0x1ff)) { /* timer */ do_timer(a,c); - } else if (a >= 0x10+(IOPAGE&0xff)) { /* mmu */ + } else if (a >= 0x10+(IOPAGE&0x1ff)) { /* mmu */ do_mmu(a,c); } } @@ -275,17 +275,17 @@ void do_timer(int a, int c) { struct itimerval timercontrol; - if (a==0x30+(IOPAGE&0xff) && c==0x8f) { + if (a==0x30+(IOPAGE&0x1ff) && 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+(IOPAGE&0xff) && c==0x80) { + } else if (a==0x30+(IOPAGE&0x1ff) && c==0x80) { timercontrol.it_interval.tv_sec = 0; timercontrol.it_interval.tv_usec = 0; setitimer(ITIMER_REAL, &timercontrol, NULL); - } else if (a==0x30+(IOPAGE&0xff) && c==0x04) { + } else if (a==0x30+(IOPAGE&0x1ff) && c==0x04) { time_t tm = time(0); struct tm *t = localtime(&tm); mem[IOPAGE+0x31] = t->tm_year; @@ -295,13 +295,13 @@ mem[IOPAGE+0x35] = t->tm_min; mem[IOPAGE+0x36] = t->tm_sec; } else { - mem[(IOPAGE&0xff00)+a]=c; + mem[(IOPAGE&0xfe00)+a]=c; } } void do_disk(int a, int c) { - if (a!=0x40+(IOPAGE&0xff)) { - mem[(IOPAGE&0xff00)+a]=c; + if (a!=0x40+(IOPAGE&0x1ff)) { + mem[(IOPAGE&0xfe00)+a]=c; return; } int drv = mem[IOPAGE+0x41]; @@ -325,14 +325,14 @@ { #ifdef USE_MMU - if (a==0x11+(IOPAGE&0xff)) { + if (a==0x11+(IOPAGE&0x1ff)) { if (c&1) { mmu = phymem+memsize-0x10000+0xffa8; } else { mmu = phymem+memsize-0x10000+0xffa0; } } - mem[(IOPAGE&0xff00)+a] = c; // other register such as 0xffa0-0xffaf + mem[(IOPAGE&0xfe00)+a] = c; // other register such as 0xffa0-0xffaf #endif } diff -r 67046a9431a0 -r e3b08716aa53 v09.c --- a/v09.c Sun Jul 08 16:15:34 2018 +0900 +++ b/v09.c Mon Jul 09 00:40:05 2018 +0900 @@ -97,8 +97,8 @@ fread(mem+(romstart&0xffff),len,1,image); fclose(image); #ifdef USE_MMU - do_mmu(0x91,0); // set mmu - do_mmu(0xa7,0x3f); // initial mmu value + do_mmu(0xff91&0x1ff,0); // set mmu + do_mmu(0xffa7&0x1ff,0x3f); // initial mmu value #endif }