naomi: Portability fixes, add posix support

- Replaced BYTE, WORD, DWORD w/ u8, u16 & u32
- mmap/munmap/open

I should wrap the mmap fns in the oslib methinks...
This commit is contained in:
Stefanos Kornilios Mitsis Poiitidis 2015-08-09 23:40:05 +02:00
parent 7feeec0ceb
commit b53b303c89
4 changed files with 92 additions and 54 deletions

View File

@ -8,8 +8,8 @@ RZDCY_SRC_DIR ?= $(call my-dir)
RZDCY_MODULES := cfg/ hw/arm7/ hw/aica/ hw/holly/ hw/ hw/gdrom/ hw/maple/ \
hw/mem/ hw/pvr/ hw/sh4/ hw/sh4/interpr/ hw/sh4/modules/ plugins/ profiler/ oslib/ \
hw/extdev/ hw/arm/ imgread/ linux/ ./ deps/coreio/ deps/zlib/ deps/chdr/ deps/crypto/ \
deps/libelf/ deps/chdpsr/ arm_emitter/ rend/ reios/ deps/libpng/
hw/extdev/ hw/arm/ hw/naomi/ imgread/ linux/ ./ deps/coreio/ deps/zlib/ deps/chdr/ deps/crypto/ \
deps/libelf/ deps/chdpsr/ arm_emitter/ rend/ reios/ deps/libpng/
ifdef WEBUI

View File

@ -570,8 +570,8 @@ struct maple_sega_vmu: maple_base
lgLcdBitmap160x43x1 bmp;
bmp.hdr.Format = LGLCD_BMP_FORMAT_160x43x1;
const BYTE white=0x00;
const BYTE black=0xFF;
const u8 white=0x00;
const u8 black=0xFF;
//make it all black...
memset(bmp.pixels,black,sizeof(bmp.pixels));
@ -579,11 +579,11 @@ struct maple_sega_vmu: maple_base
//decode from the VMU
for(int y=0;y<32;++y)
{
BYTE *dst=bmp.pixels+5816+((-y)*(48+112)); //ugly way to make things look right :p
BYTE *src=dev->lcd.data+6*y+5;
u8 *dst=bmp.pixels+5816+((-y)*(48+112)); //ugly way to make things look right :p
u8 *src=dev->lcd.data+6*y+5;
for(int x=0;x<48/8;++x)
{
BYTE val=*src;
u8 val=*src;
for(int m=0;m<8;++m)
{
if(val&(1<<(m)))
@ -849,9 +849,9 @@ bool EEPROM_loaded = false;
struct _NaomiState
{
BYTE Cmd;
BYTE Mode;
BYTE Node;
u8 Cmd;
u8 Mode;
u8 Node;
};
_NaomiState State;
@ -969,7 +969,7 @@ struct maple_naomi_jamma : maple_sega_controller
case 0x10:
{
static char ID1[102] = "nullDC Team; I/O Plugin-1; ver0.2; for nullDC or other emus";
buffer_out_b[0x8 + 0x10] = (BYTE)strlen(ID1) + 3;
buffer_out_b[0x8 + 0x10] = (u8)strlen(ID1) + 3;
for (int i = 0; ID1[i] != 0; ++i)
{
buffer_out_b[0x8 + 0x13 + i] = ID1[i];
@ -1037,9 +1037,10 @@ struct maple_naomi_jamma : maple_sega_controller
static unsigned char LastKey[256];
static unsigned short coin1 = 0x0000;
static unsigned short coin2 = 0x0000;
unsigned char Key[256];
unsigned char Key[256] = { 0 };
#if HOST_OS == OS_WINDOWS
GetKeyboardState(Key);
#endif
if (keycode&NAOMI_SERVICE_KEY_1) //Service ?
glbl |= 0x80;
if (keycode&NAOMI_TEST_KEY_1) //Test

View File

@ -12,18 +12,16 @@
#include "naomi_regs.h"
u32 naomi_updates;
//For file memory mapping :p
#include <windows.h>
//#define NAOMI_COMM
u32 RomPioOffset=0;
DWORD DmaOffset;
DWORD DmaCount;
u32 DmaOffset;
u32 DmaCount;
DWORD BoardID=0x980055AA;
DWORD GSerialBuffer=0,BSerialBuffer=0;
u32 BoardID=0x980055AA;
u32 GSerialBuffer=0,BSerialBuffer=0;
int GBufPos=0,BBufPos=0;
int GState=0,BState=0;
int GOldClk=0,BOldClk=0;
@ -84,7 +82,7 @@ void NaomiInit()
DmaCount=0xffff;
DmaOffset=0;
WORD CRC;
u16 CRC;
CRC=CRCSerial(BSerial+2,0x2E);
BSerial[0]=(u8)(CRC>>8);
BSerial[1]=(u8)(CRC);
@ -150,7 +148,7 @@ u16 NaomiBoardIDRead()
return (BSerialBuffer&(1<<(31-BBufPos)))?8:0;
}
static DWORD AdaptByte(BYTE val)
static u32 AdaptByte(u8 val)
{
return val<<24;
}
@ -283,7 +281,7 @@ void NaomiGameIDProcessCmd()
}
void NaomiGameIDWrite(const WORD Data)
void NaomiGameIDWrite(const u16 Data)
{
int Dat=Data&0x01;
int Clk=Data&0x02;
@ -344,7 +342,7 @@ void NaomiGameIDWrite(const WORD Data)
}
WORD NaomiGameIDRead()
u16 NaomiGameIDRead()
{
return (GSerialBuffer&(1<<(31-GBufPos)))?1:0;
}
@ -459,7 +457,7 @@ u32 ReadMem_naomi(u32 Addr, u32 sz)
break;
case NAOMI_DMA_COUNT_addr&255:
return (WORD) DmaCount;
return (u16) DmaCount;
case NAOMI_BOARDID_READ_addr&255:
return NaomiGameIDRead()?0x8000:0x0000;

View File

@ -4,13 +4,22 @@
u8* RomPtr;
u32 RomSize;
HANDLE* RomCacheMap;
#if HOST_OS == OS_WINDOWS
typedef HANDLE fd_t;
#define INVALID_FD INVALID_HANDLE_VALUE
#else
typedef int fd_t;
#define INVALID_FD -1
#include <unistd.h>
#include <fcntl.h>
#endif
fd_t* RomCacheMap;
u32 RomCacheMapCount;
char SelectedFile[512];
OPENFILENAME ofn;
bool naomi_cart_LoadRom(char* file)
{
@ -80,14 +89,19 @@ bool naomi_cart_LoadRom(char* file)
}
RomCacheMapCount = (u32)files.size();
RomCacheMap = new HANDLE[files.size()];
RomCacheMap = new fd_t[files.size()];
strcpy(t, file);
t[folder_pos] = 0;
strcat(t, "ndcn-composed.cache");
//Allocate space for the ram, so we are sure we have a segment of continius ram
#if HOST_OS == OS_WINDOWS
RomPtr = (u8*)VirtualAlloc(0, RomSize, MEM_RESERVE, PAGE_NOACCESS);
#else
RomPtr = (u8*)mmap(0, RomSize, PROT_NONE, MAP_PRIVATE, 0, 0);
#endif
verify(RomPtr != 0);
strcpy(t, file);
@ -97,50 +111,71 @@ bool naomi_cart_LoadRom(char* file)
{
t[folder_pos] = 0;
strcat(t, files[i].c_str());
HANDLE RomCache;
fd_t RomCache;
if (strcmp(files[i].c_str(), "null") == 0)
{
RomCacheMap[i] = INVALID_HANDLE_VALUE;
RomCacheMap[i] = INVALID_FD;
continue;
}
#if HOST_OS == OS_WINDOWS
RomCache = CreateFile(t, FILE_READ_ACCESS, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (RomCache == INVALID_HANDLE_VALUE)
#else
RomCache = open(t, O_RDONLY);
#endif
if (RomCache == INVALID_FD)
{
wprintf(L"-Unable to read file %s\n", files[i].c_str());
RomCacheMap[i] = INVALID_HANDLE_VALUE;
RomCacheMap[i] = INVALID_FD;
continue;
}
#if HOST_OS == OS_WINDOWS
RomCacheMap[i] = CreateFileMapping(RomCache, 0, PAGE_READONLY, 0, fsize[i], 0);
verify(RomCacheMap[i] != INVALID_HANDLE_VALUE);
wprintf(L"-Preparing \"%s\" at 0x%08X, size 0x%08X\n", files[i].c_str(), fstart[i], fsize[i]);
verify(CloseHandle(RomCache));
#else
RomCacheMap[i] = RomCache;
#endif
verify(RomCacheMap[i] != INVALID_FD);
wprintf(L"-Preparing \"%s\" at 0x%08X, size 0x%08X\n", files[i].c_str(), fstart[i], fsize[i]);
}
//We have all file mapping objects, we start to map the ram
printf("+Mapping ROM\n");
//Release the segment we reserved so we can map the files there
#if HOST_OS == OS_WINDOWS
verify(VirtualFree(RomPtr, 0, MEM_RELEASE));
#else
munmap(RomPtr, RomSize);
#endif
//Map the files into the segment of the ram that was reserved
for (size_t i = 0; i<RomCacheMapCount; i++)
{
u8* RomDest = RomPtr + fstart[i];
if (RomCacheMap[i] == INVALID_HANDLE_VALUE)
if (RomCacheMap[i] == INVALID_FD)
{
wprintf(L"-Reserving ram at 0x%08X, size 0x%08X\n", fstart[i], fsize[i]);
verify(VirtualAlloc(RomDest, fsize[i], MEM_RESERVE, PAGE_NOACCESS));
#if HOST_OS == OS_WINDOWS
bool mapped = RomDest == VirtualAlloc(RomDest, fsize[i], MEM_RESERVE, PAGE_NOACCESS);
#else
bool mapped = RomDest == (u8*)mmap(RomDest, RomSize, PROT_NONE, MAP_PRIVATE, 0, 0);
#endif
verify(mapped);
}
else
{
wprintf(L"-Mapping \"%s\" at 0x%08X, size 0x%08X\n", files[i].c_str(), fstart[i], fsize[i]);
if (RomDest != MapViewOfFileEx(RomCacheMap[i], FILE_MAP_READ, 0, 0, fsize[i], RomDest))
#if HOST_OS == OS_WINDOWS
bool mapped = RomDest != MapViewOfFileEx(RomCacheMap[i], FILE_MAP_READ, 0, 0, fsize[i], RomDest);
#else
bool mapped = RomDest != mmap(RomDest, fsize[i], PROT_READ, MAP_PRIVATE, RomCacheMap[i], 0 );
#endif
if (!mapped)
{
printf("-Mapping ROM FAILED\n");
//unmap file
@ -158,20 +193,24 @@ bool naomi_cart_LoadRom(char* file)
bool naomi_cart_SelectFile(void* handle)
{
cfgLoadStr("config", "image", SelectedFile, "null");
#if HOST_OS == OS_WINDOWS
if (strcmp(SelectedFile, "null") == 0) {
OPENFILENAME ofn = { 0 };
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hInstance = (HINSTANCE)GetModuleHandle(0);
ofn.lpstrFile = SelectedFile;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = "*.lst\0*.lst\0\0";
ofn.nFilterIndex = 0;
ofn.hwndOwner = (HWND)handle;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hInstance = (HINSTANCE)GetModuleHandle(0);
ofn.lpstrFile = SelectedFile;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = "*.lst\0*.lst\0\0";
ofn.nFilterIndex = 0;
ofn.hwndOwner = (HWND)handle;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
if (GetOpenFileName(&ofn) <= 0)
return true;
if (GetOpenFileName(&ofn) <= 0)
return true;
}
#endif
if (!naomi_cart_LoadRom(SelectedFile))
{
cfgSaveStr("emu", "gamefile", "naomi_bios");