X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fmemory.h;h=ae7ae50dad2ce115112f6314ac9da935f62e8268;hb=40d22a8e7610b2fdde5cfe6178605262ef0d61d7;hp=d43fe230d3dca866bb42788e16f524cf9a2d8bcc;hpb=bcf65fd674528896fe1bc233c8bab617f6b2c86e;p=picodrive.git diff --git a/pico/memory.h b/pico/memory.h index d43fe23..ae7ae50 100644 --- a/pico/memory.h +++ b/pico/memory.h @@ -20,6 +20,24 @@ extern uptr s68k_read16_map [0x1000000 >> M68K_MEM_SHIFT]; extern uptr s68k_write8_map [0x1000000 >> M68K_MEM_SHIFT]; extern uptr s68k_write16_map[0x1000000 >> M68K_MEM_SHIFT]; +// top-level handlers that cores can use +// (or alternatively build them into themselves) +// XXX: unhandled: *16 and *32 might cross the bank boundaries +typedef u32 (cpu68k_read_f)(u32 a); +typedef void (cpu68k_write_f)(u32 a, u32 d); + +extern u32 m68k_read8(u32 a); +extern u32 m68k_read16(u32 a); +extern void m68k_write8(u32 a, u8 d); +extern void m68k_write16(u32 a, u16 d); + +// z80 +#define Z80_MEM_SHIFT 13 +extern uptr z80_read_map [0x10000 >> Z80_MEM_SHIFT]; +extern uptr z80_write_map[0x10000 >> Z80_MEM_SHIFT]; +typedef unsigned char (z80_read_f)(unsigned short a); +typedef void (z80_write_f)(unsigned int a, unsigned char data); + void z80_map_set(uptr *map, int start_addr, int end_addr, const void *func_or_mh, int is_func); void cpu68k_map_set(uptr *map, int start_addr, int end_addr, @@ -27,11 +45,8 @@ void cpu68k_map_set(uptr *map, int start_addr, int end_addr, void cpu68k_map_all_ram(int start_addr, int end_addr, void *ptr, int is_sub); void m68k_map_unmap(int start_addr, int end_addr); -// top-level handlers that cores can use -// (or alternatively build them into themselves) -// XXX: unhandled: *16 and *32 might cross the bank boundaries -typedef u32 (cpu68k_read_f)(u32 a); -typedef void (cpu68k_write_f)(u32 a, u32 d); +#define MAP_FLAG ((uptr)1 << (sizeof(uptr) * 8 - 1)) +#define map_flag_set(x) ((x) & MAP_FLAG) #define MAKE_68K_READ8(name, map) \ u32 name(u32 a) \ @@ -39,7 +54,7 @@ u32 name(u32 a) \ uptr v; \ a &= 0x00ffffff; \ v = map[a >> M68K_MEM_SHIFT]; \ - if (v & 0x80000000) \ + if (map_flag_set(v)) \ return ((cpu68k_read_f *)(v << 1))(a); \ else \ return *(u8 *)((v << 1) + (a ^ 1)); \ @@ -51,7 +66,7 @@ u32 name(u32 a) \ uptr v; \ a &= 0x00fffffe; \ v = map[a >> M68K_MEM_SHIFT]; \ - if (v & 0x80000000) \ + if (map_flag_set(v)) \ return ((cpu68k_read_f *)(v << 1))(a); \ else \ return *(u16 *)((v << 1) + a); \ @@ -65,7 +80,7 @@ u32 name(u32 a) \ a &= 0x00fffffe; \ v = map[a >> M68K_MEM_SHIFT]; \ vs = v << 1; \ - if (v & 0x80000000) { \ + if (map_flag_set(v)) { \ d = ((cpu68k_read_f *)vs)(a) << 16; \ d |= ((cpu68k_read_f *)vs)(a + 2); \ } \ @@ -82,7 +97,7 @@ void name(u32 a, u8 d) \ uptr v; \ a &= 0x00ffffff; \ v = map[a >> M68K_MEM_SHIFT]; \ - if (v & 0x80000000) \ + if (map_flag_set(v)) \ ((cpu68k_write_f *)(v << 1))(a, d); \ else \ *(u8 *)((v << 1) + (a ^ 1)) = d; \ @@ -94,7 +109,7 @@ void name(u32 a, u16 d) \ uptr v; \ a &= 0x00fffffe; \ v = map[a >> M68K_MEM_SHIFT]; \ - if (v & 0x80000000) \ + if (map_flag_set(v)) \ ((cpu68k_write_f *)(v << 1))(a, d); \ else \ *(u16 *)((v << 1) + a) = d; \ @@ -107,7 +122,7 @@ void name(u32 a, u32 d) \ a &= 0x00fffffe; \ v = map[a >> M68K_MEM_SHIFT]; \ vs = v << 1; \ - if (v & 0x80000000) { \ + if (map_flag_set(v)) { \ ((cpu68k_write_f *)vs)(a, d >> 16); \ ((cpu68k_write_f *)vs)(a + 2, d); \ } \ @@ -118,3 +133,27 @@ void name(u32 a, u32 d) \ } \ } +#ifdef NEED_DMA_SOURCE // meh + +static __inline void *m68k_dma_source(u32 a) +{ + u8 *base; + uptr v; + v = m68k_read16_map[a >> M68K_MEM_SHIFT]; + if (map_flag_set(v)) { + if (a >= Pico.romsize) // Rom + return NULL; + base = Pico.rom; + } + else + base = (void *)(v << 1); + return base + (a & 0xfe0000); +} + +#endif + +// 32x +typedef struct { + uptr addr; // stores (membase >> 1) or ((handler >> 1) | (1<<31)) + u32 mask; +} sh2_memmap;