OBJS += frontend/libpicofe/gp2x/soc_pollux.o
OBJS += frontend/libpicofe/linux/in_evdev.o
OBJS += frontend/plat_pollux.o frontend/in_tsbutton.o frontend/blit320.o
-libpcsxcore/new_dynarec/pcsxmem.o: CFLAGS += -DCUSTOM_MEMMAPS
frontend/main.o frontend/menu.o: CFLAGS += -include 320240/ui_gp2x.h
USE_PLUGIN_LIB = 1
USE_FRONTEND = 1
endif
ifeq "$(PLATFORM)" "libretro"
OBJS += frontend/libretro.o
-OBJS += frontend/linux/plat_mmap.o
endif
ifeq "$(USE_PLUGIN_LIB)" "1"
-Subproject commit 3e1124f989febba80ef582c1200153ed176226f0
+Subproject commit 14fa485ef29d946407fe79f8d7c65afa6ae1fb08
#include "../libpcsxcore/misc.h"
#include "../libpcsxcore/psxcounters.h"
+#include "../libpcsxcore/psxmem_map.h"
#include "../libpcsxcore/new_dynarec/new_dynarec.h"
#include "../plugins/dfsound/out.h"
#include "../plugins/gpulib/cspace.h"
-#include "linux/plat_mmap.h"
#include "main.h"
#include "plugin.h"
#include "plugin_lib.h"
static void *pl_mmap(unsigned int size)
{
- return plat_mmap(0, size, 0, 0);
+ return psxMap(0, size, 0, MAP_TAG_VRAM);
}
static void pl_munmap(void *ptr, unsigned int size)
{
- plat_munmap(ptr, size);
+ psxUnmap(ptr, size, MAP_TAG_VRAM);
}
struct rearmed_cbs pl_rearmed_cbs = {
+++ /dev/null
-/*
- * (C) Gražvydas "notaz" Ignotas, 2008-2010
- *
- * This work is licensed under the terms of any of these licenses
- * (at your option):
- * - GNU GPL, version 2 or later.
- * - GNU LGPL, version 2.1 or later.
- * See the COPYING file in the top-level directory.
- */
-
-#define _GNU_SOURCE 1
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <errno.h>
-
-// this is some dupe code to avoid libpicofe dep
-
-//#include "../libpicofe/plat.h"
-
-/* XXX: maybe unhardcode pagesize? */
-#define HUGETLB_PAGESIZE (2 * 1024 * 1024)
-#define HUGETLB_THRESHOLD (HUGETLB_PAGESIZE / 2)
-#ifndef MAP_HUGETLB
-#define MAP_HUGETLB 0x40000 /* arch specific */
-#endif
-
-void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed)
-{
- static int hugetlb_disabled;
- int prot = PROT_READ | PROT_WRITE;
- int flags = MAP_PRIVATE | MAP_ANONYMOUS;
- void *req, *ret;
-
- req = (void *)addr;
- if (need_exec)
- prot |= PROT_EXEC;
- if (is_fixed)
- flags |= MAP_FIXED;
- if (size >= HUGETLB_THRESHOLD && !hugetlb_disabled)
- flags |= MAP_HUGETLB;
-
- ret = mmap(req, size, prot, flags, -1, 0);
- if (ret == MAP_FAILED && (flags & MAP_HUGETLB)) {
- fprintf(stderr,
- "warning: failed to do hugetlb mmap (%p, %zu): %d\n",
- req, size, errno);
- hugetlb_disabled = 1;
- flags &= ~MAP_HUGETLB;
- ret = mmap(req, size, prot, flags, -1, 0);
- }
- if (ret == MAP_FAILED)
- return NULL;
-
- if (req != NULL && ret != req)
- fprintf(stderr,
- "warning: mmaped to %p, requested %p\n", ret, req);
-
- return ret;
-}
-
-void *plat_mremap(void *ptr, size_t oldsize, size_t newsize)
-{
- void *ret;
-
- ret = mremap(ptr, oldsize, newsize, MREMAP_MAYMOVE);
- if (ret == MAP_FAILED)
- return NULL;
- if (ret != ptr)
- printf("warning: mremap moved: %p -> %p\n", ptr, ret);
-
- return ret;
-}
-
-void plat_munmap(void *ptr, size_t size)
-{
- int ret;
-
- ret = munmap(ptr, size);
- if (ret != 0 && (size & (HUGETLB_PAGESIZE - 1))) {
- // prehaps an autorounded hugetlb mapping?
- size = (size + HUGETLB_PAGESIZE - 1) & ~(HUGETLB_PAGESIZE - 1);
- ret = munmap(ptr, size);
- }
- if (ret != 0) {
- fprintf(stderr,
- "munmap(%p, %zu) failed: %d\n", ptr, size, errno);
- }
-}
+++ /dev/null
-#include <stdlib.h>
-
-void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed);
-void *plat_mremap(void *ptr, size_t oldsize, size_t newsize);
-void plat_munmap(void *ptr, size_t size);
#include "libpicofe/input.h"
#include "libpicofe/plat.h"
#include "libpicofe/readpng.h"
+
+static void toggle_fast_forward(int force_off);
#endif
#ifndef BOOT_MSG
#define BOOT_MSG "Booting up..."
char hud_msg[64];
int hud_new_msg;
-static void toggle_fast_forward(int force_off);
-
static void make_path(char *buf, size_t size, const char *dir, const char *fname)
{
if (fname)
/*
- * (C) Gražvydas "notaz" Ignotas, 2009-2011
+ * (C) Gražvydas "notaz" Ignotas, 2009-2012
*
* This work is licensed under the terms of the GNU GPLv2 or later.
* See the COPYING file in the top-level directory.
+ *
+ * GPH claims:
+ * Main Memory : Wiz = 0 ~ 2A00000, Caanoo = 0 ~ 5600000 (86M)
+ * Frame Buffer : Wiz = 2A00000 ~ 2E00000 (4M), Caanoo = 5600000 ~ 5700000 (1M)
+ * Sound Buffer : Wiz = 2E00000 ~ 3000000 (2M), Caanoo = 5700000 ~ 5800000 (1M)
+ * YUV Buffer : Caanoo = 5800000 ~ 6000000 (8M)
+ * 3D Buffer : Wiz = 3000000 ~ 4000000 (16M),Caanoo = 6000000 ~ 8000000 (32M)
+ *
+ * Caanoo dram column (or row?) is 1024 bytes?
+ *
+ * pollux display array:
+ * 27:24 | 23:18 | 17:11 | 10:6 | 5:0
+ * seg | y[11:5] | x[11:6] | y[4:0] | x[5:0]
+ * | blk_index[12:0] | block[10:0]
*/
#include <stdio.h>
#include "main.h"
#include "menu.h"
#include "plat.h"
-#include "pcnt.h"
+#include "../libpcsxcore/psxmem_map.h"
#include "../plugins/gpulib/cspace.h"
static int fb_work_buf;
static int have_warm;
#define FB_VRAM_SIZE (320*240*2*2*2) // 2 buffers with space for 24bpp mode
+static unsigned int uppermem_pbase, vram_pbase;
static unsigned short *psx_vram;
-static unsigned int psx_vram_padds[512];
static int psx_step, psx_width, psx_height, psx_bpp;
static int psx_offset_x, psx_offset_y, psx_src_width, psx_src_height;
static int fb_offset_x, fb_offset_y;
{
}
-static void pl_vout_set_raw_vram(void *vram)
-{
- int i;
-
- psx_vram = vram;
-
- if (vram == NULL)
- return;
-
- if ((long)psx_vram & 0x7ff)
- fprintf(stderr, "GPU plugin did not align vram\n");
-
- for (i = 0; i < 512; i++) {
- psx_vram[i * 1024] = 0; // touch
- psx_vram_padds[i] = warm_virt2phys(&psx_vram[i * 1024]);
- }
-}
-
static void spend_cycles(int loops)
{
asm volatile (
#define DMA_REG(x) memregl[(DMA_BASE6 + x) >> 2]
/* this takes ~1.5ms, while ldm/stm ~1.95ms */
-static void raw_flip_dma(const void *vram, int stride, int bgr24, int w, int h)
+static void raw_blit_dma(int doffs, const void *vram, int w, int h,
+ int sstride, int bgr24)
{
- unsigned int pixel_offset = psx_vram - (unsigned short *)vram;
+ unsigned int pixel_offset = (unsigned short *)vram - psx_vram;
unsigned int dst = fb_paddrs[fb_work_buf] +
(fb_offset_y * 320 + fb_offset_x) * psx_bpp / 8;
int spsx_line = pixel_offset / 1024 + psx_offset_y;
int spsx_offset = (pixel_offset + psx_offset_x) & 0x3f8;
+ unsigned int vram_byte_pos, vram_byte_step;
int dst_stride = 320 * psx_bpp / 8;
int len = psx_src_width * psx_bpp / 8;
int i;
- warm_cache_op_all(WOP_D_CLEAN);
- pcnt_start(PCNT_BLIT);
+ //warm_cache_op_all(WOP_D_CLEAN);
dst &= ~7;
len &= ~7;
DMA_REG(0x24) = 1;
}
- for (i = psx_src_height; i > 0; i--, spsx_line += psx_step, dst += dst_stride) {
+ vram_byte_pos = vram_pbase;
+ vram_byte_pos += (spsx_line & 511) * 2 * 1024 + spsx_offset * 2;
+ vram_byte_step = psx_step * 2 * 1024;
+
+ for (i = psx_src_height; i > 0;
+ i--, vram_byte_pos += vram_byte_step, dst += dst_stride)
+ {
while ((DMA_REG(0x2c) & 0x0f) < 4)
spend_cycles(10);
// XXX: it seems we must always set all regs, what is autoincrement there for?
DMA_REG(0x20) = 1; // queue wait cmd
- DMA_REG(0x10) = psx_vram_padds[spsx_line & 511] + spsx_offset * 2; // DMA src
+ DMA_REG(0x10) = vram_byte_pos; // DMA src
DMA_REG(0x14) = dst; // DMA dst
DMA_REG(0x18) = len - 1; // len
DMA_REG(0x1c) = 0x80000; // go
}
-
- if (psx_bpp == 16) {
- pl_vout_buf = g_menuscreen_ptr;
- pl_print_hud(w, h, fb_offset_x);
- }
-
- g_menuscreen_ptr = fb_flip();
- pl_rearmed_cbs.flip_cnt++;
-
- pcnt_end(PCNT_BLIT);
}
#define make_flip_func(name, blitfunc) \
-static void name(const void *vram_, int stride, int bgr24, int w, int h) \
+static void name(int doffs, const void *vram_, int w, int h, int sstride, int bgr24) \
{ \
const unsigned short *vram = vram_; \
unsigned char *dst = (unsigned char *)g_menuscreen_ptr + \
int len = psx_src_width * psx_bpp / 8; \
int i; \
\
- pcnt_start(PCNT_BLIT); \
- \
vram += psx_offset_y * 1024 + psx_offset_x; \
for (i = psx_src_height; i > 0; i--, vram += psx_step * 1024, dst += dst_stride)\
blitfunc(dst, vram, len); \
- \
- if (psx_bpp == 16) { \
- pl_vout_buf = g_menuscreen_ptr; \
- pl_print_hud(w, h, fb_offset_x); \
- } \
- \
- g_menuscreen_ptr = fb_flip(); \
- pl_rearmed_cbs.flip_cnt++; \
- \
- pcnt_end(PCNT_BLIT); \
}
-make_flip_func(raw_flip_soft, memcpy)
-make_flip_func(raw_flip_soft_368, blit320_368)
-make_flip_func(raw_flip_soft_512, blit320_512)
-make_flip_func(raw_flip_soft_640, blit320_640)
+make_flip_func(raw_blit_soft, memcpy)
+make_flip_func(raw_blit_soft_368, blit320_368)
+make_flip_func(raw_blit_soft_512, blit320_512)
+make_flip_func(raw_blit_soft_640, blit320_640)
void *plat_gvideo_set_mode(int *w_, int *h_, int *bpp_)
{
switch (w + (bpp != 16) + !soft_scaling) {
case 640:
- pl_rearmed_cbs.pl_vout_flip = raw_flip_soft_640;
+ pl_plat_blit = raw_blit_soft_640;
w_max = 640;
break;
case 512:
- pl_rearmed_cbs.pl_vout_flip = raw_flip_soft_512;
+ pl_plat_blit = raw_blit_soft_512;
w_max = 512;
break;
case 384:
case 368:
- pl_rearmed_cbs.pl_vout_flip = raw_flip_soft_368;
+ pl_plat_blit = raw_blit_soft_368;
w_max = 368;
break;
default:
- pl_rearmed_cbs.pl_vout_flip = have_warm ? raw_flip_dma : raw_flip_soft;
+ pl_plat_blit = have_warm ? raw_blit_dma : raw_blit_soft;
w_max = 320;
break;
}
*w_ = 320;
*h_ = fb_offset_y + psx_src_height;
- return NULL;
+ return g_menuscreen_ptr;
}
/* not really used, we do raw_flip */
void *plat_gvideo_flip(void)
{
- return NULL;
+ g_menuscreen_ptr = fb_flip();
+ return g_menuscreen_ptr;
}
void plat_gvideo_close(void)
{
}
+static void *pl_emu_mmap(unsigned long addr, size_t size, int is_fixed,
+ enum psxMapTag tag)
+{
+ unsigned int pbase;
+ void *retval;
+ int ret;
+
+ if (!have_warm)
+ goto basic_map;
+
+ switch (tag) {
+ case MAP_TAG_RAM:
+ if (size > 0x400000) {
+ fprintf(stderr, "unexpected ram map request: %08lx %x\n",
+ addr, size);
+ exit(1);
+ }
+ pbase = (uppermem_pbase + 0xffffff) & ~0xffffff;
+ pbase += 0x400000;
+ retval = (void *)addr;
+ ret = warm_mmap_section(retval, pbase, size, WCB_C_BIT);
+ if (ret != 0) {
+ fprintf(stderr, "ram section map failed\n");
+ exit(1);
+ }
+ goto out;
+ case MAP_TAG_VRAM:
+ if (size > 0x400000) {
+ fprintf(stderr, "unexpected vram map request: %08lx %x\n",
+ addr, size);
+ exit(1);
+ }
+ if (addr == 0)
+ addr = 0x60000000;
+ vram_pbase = (uppermem_pbase + 0xffffff) & ~0xffffff;
+ retval = (void *)addr;
+
+ ret = warm_mmap_section(retval, vram_pbase, size, WCB_C_BIT);
+ if (ret != 0) {
+ fprintf(stderr, "vram section map failed\n");
+ exit(1);
+ }
+ goto out;
+ case MAP_TAG_LUTS:
+ // mostly for Wiz to not run out of RAM
+ if (size > 0x800000) {
+ fprintf(stderr, "unexpected LUT map request: %08lx %x\n",
+ addr, size);
+ exit(1);
+ }
+ pbase = (uppermem_pbase + 0xffffff) & ~0xffffff;
+ pbase += 0x800000;
+ retval = (void *)addr;
+ ret = warm_mmap_section(retval, pbase, size, WCB_C_BIT);
+ if (ret != 0) {
+ fprintf(stderr, "LUT section map failed\n");
+ exit(1);
+ }
+ goto out;
+ default:
+ break;
+ }
+
+basic_map:
+ retval = plat_mmap(addr, size, 0, is_fixed);
+
+out:
+ if (tag == MAP_TAG_VRAM)
+ psx_vram = retval;
+ return retval;
+}
+
+static void pl_emu_munmap(void *ptr, size_t size, enum psxMapTag tag)
+{
+ switch (tag) {
+ case MAP_TAG_RAM:
+ case MAP_TAG_VRAM:
+ case MAP_TAG_LUTS:
+ warm_munmap_section(ptr, size);
+ break;
+ default:
+ plat_munmap(ptr, size);
+ break;
+ }
+}
+
void plat_init(void)
{
const char *main_fb_name = "/dev/fb0";
perror("ioctl(fbdev) failed");
exit(1);
}
+ uppermem_pbase = fbfix.smem_start;
+
printf("framebuffer: \"%s\" @ %08lx\n", fbfix.id, fbfix.smem_start);
fb_paddrs[0] = fbfix.smem_start;
fb_paddrs[1] = fb_paddrs[0] + 320*240*4; // leave space for 24bpp
- fb_vaddrs[0] = mmap(0, FB_VRAM_SIZE, PROT_READ|PROT_WRITE,
+ ret = warm_init();
+ have_warm = (ret == 0);
+
+ if (have_warm) {
+ // map fb as write-through cached section
+ fb_vaddrs[0] = (void *)0x7fe00000;
+ ret = warm_mmap_section(fb_vaddrs[0], fb_paddrs[0],
+ FB_VRAM_SIZE, WCB_C_BIT);
+ if (ret != 0) {
+ fprintf(stderr, "fb section map failed\n");
+ fb_vaddrs[0] = NULL;
+
+ // we could continue but it would just get messy
+ exit(1);
+ }
+ }
+ if (fb_vaddrs[0] == NULL) {
+ fb_vaddrs[0] = mmap(0, FB_VRAM_SIZE, PROT_READ|PROT_WRITE,
MAP_SHARED, memdev, fb_paddrs[0]);
- if (fb_vaddrs[0] == MAP_FAILED) {
- perror("mmap(fb_vaddrs) failed");
- exit(1);
+ if (fb_vaddrs[0] == MAP_FAILED) {
+ perror("mmap(fb_vaddrs) failed");
+ exit(1);
+ }
+
+ memset(fb_vaddrs[0], 0, FB_VRAM_SIZE);
+ warm_change_cb_range(WCB_C_BIT, 1, fb_vaddrs[0], FB_VRAM_SIZE);
}
+ printf(" mapped @%p\n", fb_vaddrs[0]);
+
fb_vaddrs[1] = (char *)fb_vaddrs[0] + 320*240*4;
memset(fb_vaddrs[0], 0, FB_VRAM_SIZE);
g_menuscreen_h = 240;
g_menuscreen_ptr = fb_flip();
- ret = warm_init();
- have_warm = (ret == 0);
- warm_change_cb_upper(WCB_B_BIT, 1);
-
/* setup DMA */
DMA_REG(0x0c) = 0x20000; // pending IRQ clear
else
wiz_init();
- pl_rearmed_cbs.pl_vout_flip = have_warm ? raw_flip_dma : raw_flip_soft;
- pl_rearmed_cbs.pl_vout_set_raw_vram = pl_vout_set_raw_vram;
+ pl_plat_blit = have_warm ? raw_blit_dma : raw_blit_soft;
psx_src_width = 320;
psx_src_height = 240;
plat_target_setup_input();
plat_target.cpu_clock_set = cpu_clock_wrapper;
+
+ psxMapHook = pl_emu_mmap;
+ psxUnmapHook = pl_emu_munmap;
}
void plat_finish(void)
plat_target_finish();
}
-/* WIZ RAM lack workaround */
-void *memtab_mmap(void *addr, size_t size)
-{
- void *ret;
-
- if (gp2x_dev_id != GP2X_DEV_WIZ)
- return mmap(addr, size, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
-
- ret = mmap(addr, size, PROT_READ | PROT_WRITE,
- MAP_SHARED | MAP_FIXED, memdev, 0x03000000);
- if (ret != MAP_FAILED)
- warm_change_cb_range(WCB_C_BIT | WCB_B_BIT, 1, ret, size);
- return ret;
-}
-
/* Caanoo stuff, perhaps move later */
static const char * const caanoo_keys[KEY_MAX + 1] = {
[0 ... KEY_MAX] = NULL,
#include "pl_gun_ts.h"
#include "../libpcsxcore/new_dynarec/new_dynarec.h"
#include "../libpcsxcore/psemu_plugin_defs.h"
+#include "../libpcsxcore/psxmem_map.h"
#include "../plugins/gpulib/cspace.h"
#include "../plugins/dfinput/externals.h"
}
}
-void pl_print_hud(int w, int h, int xborder)
+static void print_hud(int w, int h, int xborder)
{
if (h < 16)
return;
- xborder += (pl_vout_w - w) / 2;
+ if (w < pl_vout_w)
+ xborder += (pl_vout_w - w) / 2;
+ if (h > pl_vout_h)
+ h = pl_vout_h;
if (g_opts & OPT_SHOWSPU)
draw_active_chans(w, h);
}
#endif
- if (pl_vout_buf != NULL && vout_w == pl_vout_w && vout_h == pl_vout_h
- && vout_bpp == pl_vout_bpp)
- return;
-
update_layer_size(vout_w, vout_h);
pl_vout_buf = plat_gvideo_set_mode(&vout_w, &vout_h, &vout_bpp);
}
out_hud:
- pl_print_hud(w * pl_vout_scale, h * pl_vout_scale, 0);
+ print_hud(w * pl_vout_scale, h * pl_vout_scale, 0);
out:
pcnt_end(PCNT_BLIT);
*h = g_layer_h;
}
-static void *pl_mmap(unsigned int size)
-{
- return plat_mmap(0, size, 0, 0);
-}
-
-static void pl_munmap(void *ptr, unsigned int size)
-{
- plat_munmap(ptr, size);
-}
+static void *pl_mmap(unsigned int size);
+static void pl_munmap(void *ptr, unsigned int size);
struct rearmed_cbs pl_rearmed_cbs = {
pl_get_layer_pos,
fprintf(stderr, "could not start watchdog: %d\n", ret);
}
+static void *pl_emu_mmap(unsigned long addr, size_t size, int is_fixed,
+ enum psxMapTag tag)
+{
+ return plat_mmap(addr, size, 0, is_fixed);
+}
+
+static void pl_emu_munmap(void *ptr, size_t size, enum psxMapTag tag)
+{
+ plat_munmap(ptr, size);
+}
+
+static void *pl_mmap(unsigned int size)
+{
+ return psxMapHook(0, size, 0, MAP_TAG_VRAM);
+}
+
+static void pl_munmap(void *ptr, unsigned int size)
+{
+ psxUnmapHook(ptr, size, MAP_TAG_VRAM);
+}
+
void pl_init(void)
{
extern unsigned int hSyncCount; // from psxcounters
pl_rearmed_cbs.gpu_hcnt = &hSyncCount;
pl_rearmed_cbs.gpu_frame_count = &frame_counter;
+
+ psxMapHook = pl_emu_mmap;
+ psxUnmapHook = pl_emu_munmap;
}
void pl_start_watchdog(void);
void *pl_prepare_screenshot(int *w, int *h, int *bpp);
void pl_init(void);
-void pl_print_hud(int width, int height, int xborder);
void pl_switch_dispmode(void);
void pl_timing_prepare(int is_pal);
-Subproject commit c682a397f4a09a7e9e29fee12ec5101a4284d452
+Subproject commit a6f015da3b10b82a476250793645c071340decbc
*/
#include <stdio.h>
-#include <sys/mman.h>
#include "../psxhw.h"
#include "../cdrom.h"
#include "../mdec.h"
#include "../gpu.h"
+#include "../psxmem_map.h"
#include "emu_if.h"
#include "pcsxmem.h"
{
int i;
-#ifdef CUSTOM_MEMMAPS
- // WIZ lack-of-RAM hack
- extern void *memtab_mmap(void *addr, size_t size);
- mem_readtab = memtab_mmap((void *)0x08000000, 0x200000 * 4);
-#else
// have to map these further to keep tcache close to .text
- mem_readtab = mmap((void *)0x08000000, 0x200000 * 4, PROT_READ | PROT_WRITE,
- MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-#endif
- if (mem_readtab == MAP_FAILED) {
+ mem_readtab = psxMap(0x08000000, 0x200000 * 4, 0, MAP_TAG_LUTS);
+ if (mem_readtab == NULL) {
fprintf(stderr, "failed to map mem tables\n");
exit(1);
}
// TODO: Implement caches & cycle penalty.
#include "psxmem.h"
+#include "psxmem_map.h"
#include "r3000a.h"
#include "psxhw.h"
#include "debug.h"
#define MAP_ANONYMOUS MAP_ANON
#endif
+void *(*psxMapHook)(unsigned long addr, size_t size, int is_fixed,
+ enum psxMapTag tag);
+void (*psxUnmapHook)(void *ptr, size_t size, enum psxMapTag tag);
+
+void *psxMap(unsigned long addr, size_t size, int is_fixed,
+ enum psxMapTag tag)
+{
+ int flags = MAP_PRIVATE | MAP_ANONYMOUS;
+ void *req, *ret;
+
+ if (psxMapHook != NULL)
+ return psxMapHook(addr, size, is_fixed, tag);
+
+ if (is_fixed)
+ flags |= MAP_FIXED;
+
+ req = (void *)addr;
+ ret = mmap(req, size, PROT_READ | PROT_WRITE, flags, -1, 0);
+ if (ret == MAP_FAILED)
+ return NULL;
+
+ if (ret != req)
+ SysMessage("psxMap: warning: wanted to map @%p, got %p\n",
+ req, ret);
+
+ return ret;
+}
+
+void psxUnmap(void *ptr, size_t size, enum psxMapTag tag)
+{
+ if (psxUnmapHook != NULL) {
+ psxUnmapHook(ptr, size, tag);
+ return;
+ }
+
+ munmap(ptr, size);
+}
+
s8 *psxM = NULL; // Kernel & User Memory (2 Meg)
s8 *psxP = NULL; // Parallel Port (64K)
s8 *psxR = NULL; // BIOS ROM (512K)
0xbfc0_0000-0xbfc7_ffff BIOS Mirror (512K) Uncached
*/
-#if 1
-void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed);
-void plat_munmap(void *ptr, size_t size);
-#else
-#define plat_mmap(addr, size, need_exec, is_fixed) \
- mmap((void *)addr, size, PROT_WRITE | PROT_READ, \
- MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0)
-#define plat_munmap munmap
-#endif
-
int psxMemInit() {
int i;
memset(psxMemRLUT, 0, 0x10000 * sizeof(void *));
memset(psxMemWLUT, 0, 0x10000 * sizeof(void *));
- psxM = plat_mmap(0x80000000, 0x00210000, 0, 1);
+ psxM = psxMap(0x80000000, 0x00210000, 1, MAP_TAG_RAM);
#ifndef RAM_FIXED
- if (psxM == MAP_FAILED)
- psxM = mmap((void *)0x70000000, 0x00210000,
- PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
+ if (psxM == NULL)
+ psxM = psxMap(0x70000000, 0x00210000, 0, MAP_TAG_RAM);
#endif
- if (psxM == MAP_FAILED) {
+ if (psxM == NULL) {
SysMessage(_("mapping main RAM failed"));
return -1;
}
psxP = &psxM[0x200000];
- psxH = mmap((void *)0x1f800000, 0x00010000,
- PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
-
- psxR = mmap((void *)0x1fc00000, 0x80000,
- PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ psxH = psxMap(0x1f800000, 0x10000, 1, MAP_TAG_OTHER);
+ psxR = psxMap(0x1fc00000, 0x80000, 0, MAP_TAG_OTHER);
if (psxMemRLUT == NULL || psxMemWLUT == NULL ||
- psxR == MAP_FAILED ||
- psxP == NULL || psxH != (void *)0x1f800000) {
+ psxR == NULL || psxP == NULL || psxH != (void *)0x1f800000) {
SysMessage(_("Error allocating memory!"));
return -1;
}
}
void psxMemShutdown() {
- plat_munmap(psxM, 0x00210000);
- munmap(psxH, 0x1f800000);
- munmap(psxR, 0x80000);
+ psxUnmap(psxM, 0x00210000, MAP_TAG_RAM);
+ psxUnmap(psxH, 0x1f800000, MAP_TAG_OTHER);
+ psxUnmap(psxR, 0x80000, MAP_TAG_OTHER);
free(psxMemRLUT);
free(psxMemWLUT);
--- /dev/null
+#ifndef __PSXMEM_MAP_H__
+#define __PSXMEM_MAP_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum psxMapTag {
+ MAP_TAG_OTHER = 0,
+ MAP_TAG_RAM,
+ MAP_TAG_VRAM,
+ MAP_TAG_LUTS,
+};
+
+extern void *(*psxMapHook)(unsigned long addr, size_t size, int is_fixed,
+ enum psxMapTag tag);
+extern void (*psxUnmapHook)(void *ptr, size_t size, enum psxMapTag tag);
+
+void *psxMap(unsigned long addr, size_t size, int is_fixed,
+ enum psxMapTag tag);
+void psxUnmap(void *ptr, size_t size, enum psxMapTag tag);
+
+#ifdef __cplusplus
+}
+#endif
+#endif