--- np2/i386c/memory.c 2004/03/04 15:20:13 1.13 +++ np2/i386c/memory.c 2004/03/04 17:36:05 1.16 @@ -796,12 +796,11 @@ REG8 MEMCALL i286_memoryread(UINT32 addr UINT32 pos; - addr &= CPU_ADRSMASK; if (addr < I286_MEMREADMAX) { return(mem[addr]); } else if (addr >= USE_HIMEM) { - pos = addr - 0x100000; + pos = (addr & CPU_ADRSMASK) - 0x100000; if (pos < CPU_EXTMEMSIZE) { return(CPU_EXTMEM[pos]); } @@ -827,13 +826,12 @@ REG16 MEMCALL i286_memoryread_w(UINT32 a UINT32 pos; REG16 ret; - addr &= CPU_ADRSMASK; if (addr < (I286_MEMREADMAX - 1)) { return(LOADINTELWORD(mem + addr)); } else if ((addr + 1) & 0x7fff) { // non 32kb boundary if (addr >= USE_HIMEM) { - pos = addr - 0x100000; + pos = (addr & CPU_ADRSMASK) - 0x100000; if (pos < CPU_EXTMEMSIZE) { return(LOADINTELWORD(CPU_EXTMEM + pos)); } @@ -863,12 +861,11 @@ UINT32 MEMCALL i286_memoryread_d(UINT32 UINT32 pos; UINT32 ret; - addr &= CPU_ADRSMASK; if (addr < (I286_MEMREADMAX - 3)) { return(LOADINTELDWORD(mem + addr)); } else if (addr >= USE_HIMEM) { - pos = addr - 0x100000; + pos = (addr & CPU_ADRSMASK) - 0x100000; if ((pos + 3) < CPU_EXTMEMSIZE) { return(LOADINTELDWORD(CPU_EXTMEM + pos)); } @@ -889,12 +886,11 @@ void MEMCALL i286_memorywrite(UINT32 add UINT32 pos; - addr &= CPU_ADRSMASK; if (addr < I286_MEMWRITEMAX) { mem[addr] = (BYTE)value; } else if (addr >= USE_HIMEM) { - pos = addr - 0x100000; + pos = (addr & CPU_ADRSMASK) - 0x100000; if (pos < CPU_EXTMEMSIZE) { CPU_EXTMEM[pos] = (BYTE)value; } @@ -906,9 +902,6 @@ void MEMCALL i286_memorywrite(UINT32 add mem9821_w(addr, value); } #endif - else { - TRACEOUT(("mem_w %x %x", addr, value)); - } } else { memfn.wr8[(addr >> 15) & 0x1f](addr, value); @@ -919,13 +912,12 @@ void MEMCALL i286_memorywrite_w(UINT32 a UINT32 pos; - addr &= CPU_ADRSMASK; if (addr < (I286_MEMWRITEMAX - 1)) { STOREINTELWORD(mem + addr, value); } else if ((addr + 1) & 0x7fff) { // non 32kb boundary if (addr >= USE_HIMEM) { - pos = addr - 0x100000; + pos = (addr & CPU_ADRSMASK) - 0x100000; if (pos < CPU_EXTMEMSIZE) { STOREINTELWORD(CPU_EXTMEM + pos, value); } @@ -952,13 +944,12 @@ void MEMCALL i286_memorywrite_d(UINT32 a UINT32 pos; - addr &= CPU_ADRSMASK; if (addr < (I286_MEMWRITEMAX - 3)) { STOREINTELDWORD(mem + addr, value); return; } else if (addr >= USE_HIMEM) { - pos = addr - 0x100000; + pos = (addr & CPU_ADRSMASK) - 0x100000; if ((pos + 3) < CPU_EXTMEMSIZE) { STOREINTELDWORD(CPU_EXTMEM + pos, value); return; @@ -975,7 +966,7 @@ void MEMCALL i286_memorywrite_d(UINT32 a } } -#ifdef NP2_MEMORY_ASM +#if 0 REG8 MEMCALL i286_membyte_read(UINT seg, UINT off) { UINT32 address; @@ -1027,53 +1018,74 @@ void MEMCALL i286_memword_write(UINT seg i286_memorywrite_w(address, value); } } -#endif /* NP2_MEMORY_ASM */ +#endif + +void MEMCALL memp_read(UINT32 address, void *dat, UINT leng) { -void MEMCALL i286_memx_read(UINT32 address, void *dat, UINT leng) { + BYTE *out = (BYTE *)dat; + UINT pos; + UINT diff; - if ((address + leng) < I286_MEMREADMAX) { + /* fast memory access */ + if (address + leng < I286_MEMREADMAX) { CopyMemory(dat, mem + address, leng); - } - else { - BYTE *out = (BYTE *)dat; - if (address < I286_MEMREADMAX) { - CopyMemory(out, mem + address, I286_MEMREADMAX - address); - out += I286_MEMREADMAX - address; - leng -= I286_MEMREADMAX - address; - address = I286_MEMREADMAX; + return; + } else if (address >= USE_HIMEM) { + pos = (address & CPU_ADRSMASK) - 0x100000; + if (pos + leng < CPU_EXTMEMSIZE) { + CopyMemory(dat, CPU_EXTMEM + pos, leng); + return; } - while(leng--) { - *out++ = i286_memoryread(address++); + if (pos < CPU_EXTMEMSIZE) { + diff = CPU_EXTMEMSIZE - pos; + CopyMemory(out, CPU_EXTMEM + pos, diff); + out += diff; + leng -= diff; + address += diff; } } + + /* slow memory access */ + while (leng-- > 0) { + *out++ = i286_memoryread(address++); + } } -void MEMCALL i286_memx_write(UINT32 address, const void *dat, UINT leng) { +void MEMCALL memp_write(UINT32 address, const void *dat, UINT leng) { -const BYTE *out; + const BYTE *out = (BYTE *)dat; + UINT pos; + UINT diff; - if ((address + leng) < I286_MEMWRITEMAX) { + /* fast memory access */ + if (address + leng < I286_MEMREADMAX) { CopyMemory(mem + address, dat, leng); - } - else { - out = (BYTE *)dat; - if (address < I286_MEMWRITEMAX) { - CopyMemory(mem + address, out, I286_MEMWRITEMAX - address); - out += I286_MEMWRITEMAX - address; - leng -= I286_MEMWRITEMAX - address; - address = I286_MEMWRITEMAX; + return; + } else if (address >= USE_HIMEM) { + pos = (address & CPU_ADRSMASK) - 0x100000; + if (pos + leng < CPU_EXTMEMSIZE) { + CopyMemory(CPU_EXTMEM + pos, dat, leng); + return; } - while(leng--) { - i286_memorywrite(address++, *out++); + if (pos < CPU_EXTMEMSIZE) { + diff = CPU_EXTMEMSIZE - pos; + CopyMemory(CPU_EXTMEM + pos, dat, diff); + out += diff; + leng -= diff; + address += diff; } } + + /* slow memory access */ + while (leng-- > 0) { + i286_memorywrite(address++, *out++); + } } -#endif -// ---- +// ---- Logical Space (BIOS) -static UINT32 realaddr(UINT32 addr) { +static UINT32 physicaladdr(UINT32 addr) { UINT32 pde; UINT32 pte; @@ -1083,9 +1095,7 @@ static UINT32 realaddr(UINT32 addr) { if (!(pde & CPU_PDE_PRESENT)) { goto retdummy; } - // ページサイズ 4KB固定(ぉ - pte = cpu_memoryread_d((pde & CPU_PDE_BASEADDR_MASK) - + ((addr >> 10) & 0xffc)); + pte = cpu_memoryread_d((pde & CPU_PDE_BASEADDR_MASK) + ((addr >> 10) & 0xffc)); if (!(pte & CPU_PTE_PRESENT)) { goto retdummy; } @@ -1097,7 +1107,7 @@ retdummy: return(0x01000000); // てきとーにメモリが存在しない場所 } -void MEMCALL i286_memstr_read(UINT seg, UINT off, void *dat, UINT leng) { +void MEMCALL meml_readstr(UINT seg, UINT off, void *dat, UINT leng) { UINT32 adrs; UINT size; @@ -1108,14 +1118,15 @@ void MEMCALL i286_memstr_read(UINT seg, size = 0x1000 - (adrs & 0xfff); size = min(size, leng); size = min(size, 0x10000 - off); - i286_memx_read(realaddr(adrs), dat, size); + memp_read(physicaladdr(adrs), dat, size); off += size; dat = ((BYTE *)dat) + size; leng -= size; } } -void MEMCALL i286_memstr_write(UINT seg, UINT off, const void *dat, UINT leng) { +void MEMCALL meml_writestr(UINT seg, UINT off, const void *dat, UINT leng) { + UINT32 adrs; UINT size; @@ -1125,27 +1136,40 @@ void MEMCALL i286_memstr_write(UINT seg, size = 0x1000 - (adrs & 0xfff); size = min(size, leng); size = min(size, 0x10000 - off); - i286_memx_write(realaddr(adrs), dat, size); + memp_write(physicaladdr(adrs), dat, size); off += size; dat = ((BYTE *)dat) + size; leng -= size; } } +void MEMCALL meml_read(UINT32 address, void *dat, UINT leng) { -#if 0 // テスト -void MEMCALL cpumem_strread(UINT32 adrs, void *dat, UINT leng) { + UINT size; + + while(leng) { + size = 0x1000 - (address & 0xfff); + size = min(size, leng); + memp_read(physicaladdr(address), dat, size); + address += size; + dat = ((BYTE *)dat) + size; + leng -= size; + } +} + +void MEMCALL meml_write(UINT32 address, const void *dat, UINT leng) { UINT size; while(leng) { - size = 0x1000 - (adrs & 0xfff); + size = 0x1000 - (address & 0xfff); size = min(size, leng); - i286_memx_read(realaddr(adrs), dat, size); - adrs += size; + memp_write(physicaladdr(address), dat, size); + address += size; dat = ((BYTE *)dat) + size; leng -= size; } } + #endif