--- np2/i386c/memory.h 2003/12/08 00:55:31 1.1 +++ np2/i386c/memory.h 2012/01/29 14:53:54 1.20 @@ -1,23 +1,34 @@ +#ifndef NP2_I386C_MEMORY_H__ +#define NP2_I386C_MEMORY_H__ -#ifdef NP2_MEMORY_ASM // アセンブラ版は 必ずfastcallで +#ifdef NP2_MEMORY_ASM // アセンブラ版は 必ずfastcallで #undef MEMCALL #define MEMCALL FASTCALL #endif +#if !defined(MEMCALL) +#define MEMCALL +#endif // 000000-0fffff メインメモリ // 100000-10ffef HMA // 110000-193fff FONT-ROM/RAM -// 1a8000-1e7fff VRAM1 +// 1a8000-1bffff VRAM1 +// 1c0000-1c7fff ITF-ROM BAK +// 1c8000-1dffff EPSON RAM +// 1e0000-1e7fff VRAM1 // 1f8000-1fffff ITF-ROM +#define CPU_MEMREADMAX 0x0a4000 +#define CPU_MEMWRITEMAX 0x0a0000 + #define VRAM_STEP 0x100000 #define VRAM_B 0x0a8000 #define VRAM_R 0x0b0000 #define VRAM_G 0x0b8000 #define VRAM_E 0x0e0000 -#define VRAM_POS(a) ((a) & (VRAM_STEP | 0x7fff)) +#define VRAMADDRMASKEX(a) ((a) & (VRAM_STEP | 0x7fff)) #define VRAM0_B VRAM_B #define VRAM0_R VRAM_R @@ -31,126 +42,105 @@ #define FONT_ADRS 0x110000 #define ITF_ADRS 0x1f8000 -#if defined(CPU386) -#if 0 -#define LOWMEM 0x100000 -#else -#define LOWMEM 0x10fff0 -#endif -#endif /* CPU386 */ - - -#if defined(BYTESEX_LITTLE) - -#define MEM_SETB(pos, data) mem[pos] = data -#define MEM_ANDB(pos, data) mem[pos] &= data -#define MEM_XORB(pos, data) mem[pos] ^= data -#define MEM_ORB(pos, data) mem[pos] |= data -#define MEM_SETW(pos, data) *(WORD *)(mem + (pos)) = (data) -#define MEM_SETD(pos, data) *(DWORD *)(mem + (pos)) = (data) -#define MEM_GETB(pos) (mem[pos]) -#define MEM_GETW(pos) (*(WORD *)(mem + (pos))) -#define MEM_GETD(pos) (*(DWORD *)(mem + (pos))) - -#elif defined(BYTESEX_BIG) - -#define MEM_SETB(pos, data) mem[pos] = data -#define MEM_ANDB(pos, data) mem[pos] &= data -#define MEM_XORB(pos, data) mem[pos] ^= data -#define MEM_ORB(pos, data) mem[pos] |= data -#define MEM_SETW(pos, data) \ - mem[(pos)] = (BYTE)data; \ - mem[(pos) + 1] = (BYTE)(data >> 8); -#define MEM_SETD(pos, data) \ - mem[(pos)] = (BYTE)data; \ - mem[(pos) + 1] = (BYTE)(data >> 8); \ - mem[(pos) + 2] = (BYTE)(data >> 16); \ - mem[(pos) + 3] = (BYTE)(data >> 24); -#define MEM_GETB(pos) (mem[pos]) -#define MEM_GETW(pos) \ - (((WORD)mem[(pos) + 1] << 8) | mem[(pos)]) -#define MEM_GETD(pos) \ - (((DWORD)mem[(pos) + 3] << 24) | \ - ((DWORD)mem[(pos) + 2] << 16) | \ - ((WORD)mem[(pos) + 1] << 8) | mem[(pos)]) -#endif - +#define USE_HIMEM 0x110000 #ifdef __cplusplus extern "C" { #endif -extern BYTE mem[0x200000]; +extern UINT8 mem[0x200000]; -void MEMCALL i286_vram_dispatch(UINT operate); +void MEMCALL memm_arch(UINT type); +void MEMCALL memm_vram(UINT operate); -void MEMCALL __i286_memorywrite(UINT32 address, REG8 value); -void MEMCALL __i286_memorywrite_w(UINT32 address, REG16 value); -void MEMCALL __i286_memorywrite_d(UINT32 address, UINT32 value); -REG8 MEMCALL __i286_memoryread(UINT32 address); -REG16 MEMCALL __i286_memoryread_w(UINT32 address); -UINT32 MEMCALL __i286_memoryread_d(UINT32 address); - -#ifndef CPU386 -#define i286_memorywrite(a,v) __i286_memorywrite(a,v) -#define i286_memorywrite_w(a,v) __i286_memorywrite_w(a,v) -#define i286_memorywrite_d(a,v) __i286_memorywrite_d(a,v) -#define i286_memoryread(a) __i286_memoryread(a) -#define i286_memoryread_w(a) __i286_memoryread_w(a) -#define i286_memoryread_d(a) __i286_memoryread_d(a) -#else /* CPU386 */ -void MEMCALL cpu_memorywrite(DWORD address, BYTE value); -void MEMCALL cpu_memorywrite_w(DWORD address, WORD value); -void MEMCALL cpu_memorywrite_d(DWORD address, DWORD value); -BYTE MEMCALL cpu_memoryread(DWORD address); -WORD MEMCALL cpu_memoryread_w(DWORD address); -DWORD MEMCALL cpu_memoryread_d(DWORD address); -#define i286_memorywrite(a,v) cpu_memorywrite(a,v) -#define i286_memorywrite_w(a,v) cpu_memorywrite_w(a,v) -#define i286_memorywrite_d(a,v) cpu_memorywrite_d(a,v) -#define i286_memoryread(a) cpu_memoryread(a) -#define i286_memoryread_w(a) cpu_memoryread_w(a) -#define i286_memoryread_d(a) cpu_memoryread_d(a) -#endif - -#ifdef NP2_MEMORY_ASM -BYTE MEMCALL i286_membyte_read(WORD seg, WORD off); -WORD MEMCALL i286_memword_read(WORD seg, WORD off); -void MEMCALL i286_membyte_write(WORD seg, WORD off, BYTE dat); -void MEMCALL i286_memword_write(WORD seg, WORD off, WORD dat); -#else -#define i286_membyte_read(a, b) \ - i286_memoryread(((DWORD)(a) << 4) + (WORD)(b)) -#define i286_memword_read(a, b) \ - i286_memoryread_w(((DWORD)(a) << 4) + (WORD)(b)) - -#define i286_membyte_write(a, b, c) \ - i286_memorywrite(((DWORD)(a) << 4) + (WORD)(b), (c)) -#define i286_memword_write(a, b, c) \ - i286_memorywrite_w(((DWORD)(a) << 4) + (WORD)(b), (c)) -#endif - -void MEMCALL i286_memstr_read(UINT seg, UINT off, void *dat, UINT leng); -void MEMCALL i286_memstr_write(UINT seg, UINT off, - const void *dat, UINT leng); -void MEMCALL i286_memx_read(UINT32 address, void *dat, UINT leng); -void MEMCALL i286_memx_write(UINT32 address, const void *dat, UINT leng); +REG8 MEMCALL memp_read8(UINT32 address); +REG16 MEMCALL memp_read16(UINT32 address); +UINT32 MEMCALL memp_read32(UINT32 address); +void MEMCALL memp_write8(UINT32 address, REG8 value); +void MEMCALL memp_write16(UINT32 address, REG16 value); +void MEMCALL memp_write32(UINT32 address, UINT32 value); +void MEMCALL memp_reads(UINT32 address, void *dat, UINT leng); +void MEMCALL memp_writes(UINT32 address, const void *dat, UINT leng); + +REG8 MEMCALL meml_read8(UINT32 address); +REG16 MEMCALL meml_read16(UINT32 address); +UINT32 MEMCALL meml_read32(UINT32 address); +void MEMCALL meml_write8(UINT32 address, REG8 dat); +void MEMCALL meml_write16(UINT32 address, REG16 dat); +void MEMCALL meml_write32(UINT32 address, UINT32 dat); +void MEMCALL meml_reads(UINT32 address, void *dat, UINT leng); +void MEMCALL meml_writes(UINT32 address, const void *dat, UINT leng); + +REG8 MEMCALL memr_read8(UINT seg, UINT off); +REG16 MEMCALL memr_read16(UINT seg, UINT off); +UINT32 MEMCALL memr_read32(UINT seg, UINT off); +void MEMCALL memr_write8(UINT seg, UINT off, REG8 dat); +void MEMCALL memr_write16(UINT seg, UINT off, REG16 dat); +void MEMCALL memr_write32(UINT seg, UINT off, UINT32 dat); +void MEMCALL memr_reads(UINT seg, UINT off, void *dat, UINT leng); +void MEMCALL memr_writes(UINT seg, UINT off, const void *dat, UINT leng); #ifdef __cplusplus } #endif -// とりあえず -#define GETDWORD(a) (((UINT32)(a)[0]) | \ - ((UINT32)(a)[1] << 8) | \ - ((UINT32)(a)[2] << 16) | \ - ((UINT32)(a)[3] << 24)) -#define GETWORD(a) (((UINT16)(a)[0]) | ((UINT16)(a)[1] << 8)) -#define SETDWORD(a, b) *((a)+0) = (BYTE)((b)); \ - *((a)+1) = (BYTE)((b)>>8); \ - *((a)+2) = (BYTE)((b)>>16); \ - *((a)+3) = (BYTE)((b)>>24) -#define SETWORD(a, b) *((a)+0) = (BYTE)((b)); \ - *((a)+1) = (BYTE)((b)>>8) +// ---- Memory map + +#define MEMM_ARCH(t) memm_arch(t) +#define MEMM_VRAM(o) memm_vram(o) + + +// ---- Physical Space (DMA) + +#define MEMP_READ8(addr) \ + memp_read8((addr)) +#define MEMP_READ16(addr) \ + memp_read16((addr)) +#define MEMP_READ32(addr) \ + memp_read32((addr)) +#define MEMP_WRITE8(addr, dat) \ + memp_write8((addr), (dat)) +#define MEMP_WRITE16(addr, dat) \ + memp_write16((addr), (dat)) +#define MEMP_WRITE32(addr, dat) \ + memp_write32((addr), (dat)) +#define MEMP_READS(addr, dat, leng) \ + memp_reads((addr), (dat), (leng)) +#define MEMP_WRITES(addr, dat, leng) \ + memp_writes((addr), (dat), (leng)) + + +// ---- Logical Space (BIOS) + +#define MEML_READ8(addr) \ + meml_read8((addr)) +#define MEML_READ16(addr) \ + meml_read16((addr)) +#define MEML_READ32(addr) \ + meml_read32((addr)) +#define MEML_WRITE8(addr, dat) \ + meml_write8((addr), (dat)) +#define MEML_WRITE16(addr, dat) \ + meml_write16((addr), (dat)) +#define MEML_WRITE32(addr, dat) \ + meml_write32((addr), (dat)) +#define MEML_READS(addr, dat, leng) \ + meml_reads((addr), (dat), (leng)) +#define MEML_WRITES(addr, dat, leng) \ + meml_writes((addr), (dat), (leng)) + +#define MEMR_READ8(seg, off) \ + memr_read8((seg), (off)) +#define MEMR_READ16(seg, off) \ + memr_read16((seg), (off)) +#define MEMR_WRITE8(seg, off, dat) \ + memr_write8((seg), (off), (dat)) +#define MEMR_WRITE16(seg, off, dat) \ + memr_write16((seg), (off), (dat)) +#define MEMR_READS(seg, off, dat, leng) \ + memr_reads((seg), (off), (dat), (leng)) +#define MEMR_WRITES(seg, off, dat, leng) \ + memr_writes((seg), (off), (dat), (leng)) +#endif /* !NP2_I386C_MEMORY_H__ */