Sync to 1.24.0

This commit is contained in:
negativeExponent 2019-12-24 13:57:24 +08:00
parent b31d656765
commit 12db71df06
17 changed files with 669 additions and 652 deletions

3
.gitignore vendored
View File

@ -3,4 +3,5 @@
*.dll *.dll
*.dylib *.dylib
/old /old
.vscode
.clang-format

View File

@ -19,7 +19,8 @@ SOURCES_CXX += \
$(CORE_EMU_DIR)/mikie.cpp \ $(CORE_EMU_DIR)/mikie.cpp \
$(CORE_EMU_DIR)/ram.cpp \ $(CORE_EMU_DIR)/ram.cpp \
$(CORE_EMU_DIR)/rom.cpp \ $(CORE_EMU_DIR)/rom.cpp \
$(CORE_EMU_DIR)/susie.cpp $(CORE_EMU_DIR)/susie.cpp \
$(CORE_EMU_DIR)/system.cpp
endif endif
ifeq ($(NEED_BLIP), 1) ifeq ($(NEED_BLIP), 1)

View File

@ -4,10 +4,10 @@
#include "mednafen/mempatcher.h" #include "mednafen/mempatcher.h"
#include "mednafen/git.h" #include "mednafen/git.h"
#include "mednafen/general.h" #include "mednafen/general.h"
#include "mednafen/md5.h"
#include <libretro.h> #include <libretro.h>
#include <streams/file_stream.h> #include <streams/file_stream.h>
#include <algorithm> #include <algorithm>
#include "mednafen/lynx/system.h"
#ifdef _MSC_VER #ifdef _MSC_VER
#include <compat/msvc.h> #include <compat/msvc.h>
@ -58,492 +58,6 @@ static void set_basename(const char *path)
retro_base_name = retro_base_name.substr(0, retro_base_name.find_last_of('.')); retro_base_name = retro_base_name.substr(0, retro_base_name.find_last_of('.'));
} }
//
// Copyright (c) 2004 K. Wilkins
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from
// the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
//////////////////////////////////////////////////////////////////////////////
// Handy - An Atari Lynx Emulator //
// Copyright (c) 1996,1997 //
// K. Wilkins //
//////////////////////////////////////////////////////////////////////////////
// System object class //
//////////////////////////////////////////////////////////////////////////////
// //
// This class provides the glue to bind of of the emulation objects //
// together via peek/poke handlers and pass thru interfaces to lower //
// objects, all control of the emulator is done via this class. Update() //
// does most of the work and each call emulates one CPU instruction and //
// updates all of the relevant hardware if required. It must be remembered //
// that if that instruction involves setting SPRGO then, it will cause a //
// sprite painting operation and then a corresponding update of all of the //
// hardware which will usually involve recursive calls to Update, see //
// Mikey SPRGO code for more details. //
// //
// K. Wilkins //
// August 1997 //
// //
//////////////////////////////////////////////////////////////////////////////
// Revision History: //
// ----------------- //
// //
// 01Aug1997 KW Document header added & class documented. //
// //
//////////////////////////////////////////////////////////////////////////////
#define SYSTEM_CPP
//#include <crtdbg.h>
//#define TRACE_SYSTEM
#include "mednafen/lynx/system.h"
#include "mednafen/general.h"
#include "mednafen/mempatcher.h"
CSystem::CSystem(const uint8 *filememory, int32 filesize)
:mCart(NULL),
mRom(NULL),
mMemMap(NULL),
mRam(NULL),
mCpu(NULL),
mMikie(NULL),
mSusie(NULL)
{
mFileType=HANDY_FILETYPE_ILLEGAL;
if(filesize < 11)
{
/* Lynx ROM image is too short. */
}
char clip[11];
memcpy(clip,filememory,11);
clip[4]=0;
clip[10]=0;
if(!strcmp(&clip[6],"BS93")) mFileType=HANDY_FILETYPE_HOMEBREW;
else if(!strcmp(&clip[0],"LYNX")) mFileType=HANDY_FILETYPE_LNX;
else if(filesize==128*1024 || filesize==256*1024 || filesize==512*1024)
{
/* Invalid Cart (type). but 128/256/512k size -> set to RAW and try to load raw rom image */
mFileType=HANDY_FILETYPE_RAW;
}
else
{
/* File format is unknown to module. This will then
* just load the core into an "Insert Game" screen */
}
MDFNMP_Init(65536, 1);
// Create the system objects that we'll use
// Attempt to load the cartridge errors caught above here...
mRom = new CRom(MDFN_MakeFName(MDFNMKF_FIRMWARE, 0, "lynxboot.img").c_str());
// An exception from this will be caught by the level above
switch(mFileType)
{
case HANDY_FILETYPE_RAW:
case HANDY_FILETYPE_LNX:
mCart = new CCart(filememory,filesize);
mRam = new CRam(0,0);
break;
case HANDY_FILETYPE_HOMEBREW:
mCart = new CCart(NULL, 0);
mRam = new CRam(filememory,filesize);
break;
case HANDY_FILETYPE_SNAPSHOT:
case HANDY_FILETYPE_ILLEGAL:
default:
mCart = new CCart(0,0);
mRam = new CRam(0,0);
break;
}
// These can generate exceptions
mMikie = new CMikie(*this);
mSusie = new CSusie(*this);
// Instantiate the memory map handler
mMemMap = new CMemMap(*this);
// Now the handlers are set we can instantiate the CPU as is will use handlers on reset
mCpu = new C65C02(*this);
// Now init is complete do a reset, this will cause many things to be reset twice
// but what the hell, who cares, I don't.....
Reset();
}
CSystem::~CSystem()
{
// Cleanup all our objects
if(mCart!=NULL) delete mCart;
if(mRom!=NULL) delete mRom;
if(mRam!=NULL) delete mRam;
if(mCpu!=NULL) delete mCpu;
if(mMikie!=NULL) delete mMikie;
if(mSusie!=NULL) delete mSusie;
if(mMemMap!=NULL) delete mMemMap;
}
void CSystem::Reset(void)
{
gSystemCycleCount=0;
gNextTimerEvent=0;
gCPUBootAddress=0;
gSystemIRQ=false;
gSystemNMI=false;
gSystemCPUSleep=false;
gSystemHalt=false;
gSuzieDoneTime = 0;
mMemMap->Reset();
mCart->Reset();
mRom->Reset();
mRam->Reset();
mMikie->Reset();
mSusie->Reset();
mCpu->Reset();
// Homebrew hashup
if(mFileType==HANDY_FILETYPE_HOMEBREW)
{
mMikie->PresetForHomebrew();
C6502_REGS regs;
mCpu->GetRegs(regs);
regs.PC=(uint16)gCPUBootAddress;
mCpu->SetRegs(regs);
}
}
// Somewhat of a hack to make sure undrawn lines are black.
bool LynxLineDrawn[256];
static CSystem *lynxie = NULL;
extern MDFNGI EmulatedLynx;
static bool TestMagic(const char *name, MDFNFILE *fp)
{
uint8 data[64];
uint64 rc;
rc = fp->size;
if(rc >= CCart::HEADER_RAW_SIZE && CCart::TestMagic(data, sizeof(data)))
return true;
if(rc >= CRam::HEADER_RAW_SIZE && CRam::TestMagic(data, sizeof(data)))
return true;
return false;
}
static int Load(const uint8_t *data, size_t size)
{
lynxie = new CSystem(data, size);
switch(lynxie->CartGetRotate())
{
case CART_ROTATE_LEFT:
MDFNGameInfo->rotated = MDFN_ROTATE270;
break;
case CART_ROTATE_RIGHT:
MDFNGameInfo->rotated = MDFN_ROTATE90;
break;
}
if(lynxie->mRam->InfoRAMSize)
{
memcpy(MDFNGameInfo->MD5, lynxie->mRam->MD5, 16);
MDFN_printf(_("RAM: %u bytes\n"), lynxie->mRam->InfoRAMSize);
MDFN_printf(_("CRC32: 0x%08x\n"), lynxie->mRam->CRC32());
MDFN_printf(_("RAM MD5: 0x%s\n"), md5_context::asciistr(MDFNGameInfo->MD5, 0).c_str());
}
else
{
memcpy(MDFNGameInfo->MD5, lynxie->mCart->MD5, 16);
MDFN_printf(_("ROM: %dKiB\n"), (lynxie->mCart->InfoROMSize + 1023) / 1024);
MDFN_printf(_("CRC32: 0x%08x\n"), lynxie->mCart->CRC32());
MDFN_printf(_("ROM MD5: 0x%s\n"), md5_context::asciistr(MDFNGameInfo->MD5, 0).c_str());
}
MDFNGameInfo->fps = (uint32)(59.8 * 65536 * 256);
if(MDFN_GetSettingB("lynx.lowpass"))
{
lynxie->mMikie->miksynth.treble_eq(-35);
}
else
{
lynxie->mMikie->miksynth.treble_eq(0);
}
return(1);
}
static void CloseGame(void)
{
if(lynxie)
{
delete lynxie;
lynxie = NULL;
}
}
static uint8 *chee;
static void Emulate(EmulateSpecStruct *espec)
{
espec->DisplayRect.x = 0;
espec->DisplayRect.y = 0;
espec->DisplayRect.w = 160;
espec->DisplayRect.h = 102;
if(espec->VideoFormatChanged)
lynxie->DisplaySetAttributes(espec->surface->format); // FIXME, pitch
if(espec->SoundFormatChanged)
{
lynxie->mMikie->mikbuf.set_sample_rate(espec->SoundRate ? espec->SoundRate : 44100, 60);
lynxie->mMikie->mikbuf.clock_rate((long int)(16000000 / 4));
lynxie->mMikie->mikbuf.bass_freq(60);
lynxie->mMikie->miksynth.volume(0.50);
}
uint16 butt_data = chee[0] | (chee[1] << 8);
lynxie->SetButtonData(butt_data);
MDFNMP_ApplyPeriodicCheats();
memset(LynxLineDrawn, 0, sizeof(LynxLineDrawn[0]) * 102);
lynxie->mMikie->mpSkipFrame = espec->skip;
lynxie->mMikie->mpDisplayCurrent = espec->surface;
lynxie->mMikie->mpDisplayCurrentLine = 0;
lynxie->mMikie->startTS = gSystemCycleCount;
while(lynxie->mMikie->mpDisplayCurrent && (gSystemCycleCount - lynxie->mMikie->startTS) < 700000)
{
lynxie->Update();
// printf("%d ", gSystemCycleCount - lynxie->mMikie->startTS);
}
{
// FIXME, we should integrate this into mikie.*
uint32 color_black = espec->surface->MakeColor(30, 30, 30);
for(int y = 0; y < 102; y++)
{
if(espec->surface->format.bpp == 16)
{
uint16 *row = espec->surface->pixels16 + y * espec->surface->pitchinpix;
if(!LynxLineDrawn[y])
{
for(int x = 0; x < 160; x++)
row[x] = color_black;
}
}
else
{
uint32 *row = espec->surface->pixels + y * espec->surface->pitchinpix;
if(!LynxLineDrawn[y])
{
for(int x = 0; x < 160; x++)
row[x] = color_black;
}
}
}
}
espec->MasterCycles = gSystemCycleCount - lynxie->mMikie->startTS;
if(espec->SoundBuf)
{
lynxie->mMikie->mikbuf.end_frame((gSystemCycleCount - lynxie->mMikie->startTS) >> 2);
espec->SoundBufSize = lynxie->mMikie->mikbuf.read_samples(espec->SoundBuf, espec->SoundBufMaxSize) / 2; // divide by nr audio chn
}
else
espec->SoundBufSize = 0;
}
static void SetInput(int port, const char *type, void *ptr)
{
chee = (uint8 *)ptr;
}
static void TransformInput(void)
{
if(MDFN_GetSettingB("lynx.rotateinput"))
{
static const unsigned bp[4] = { 4, 6, 5, 7 };
const unsigned offs = MDFNGameInfo->rotated;
uint16 butt_data = MDFN_de16lsb(chee);
butt_data = (butt_data & 0xFF0F) |
(((butt_data >> bp[0]) & 1) << bp[(0 + offs) & 3]) |
(((butt_data >> bp[1]) & 1) << bp[(1 + offs) & 3]) |
(((butt_data >> bp[2]) & 1) << bp[(2 + offs) & 3]) |
(((butt_data >> bp[3]) & 1) << bp[(3 + offs) & 3]);
//printf("%d, %04x\n", MDFNGameInfo->rotated, butt_data);
MDFN_en16lsb(chee, butt_data);
}
}
int StateAction(StateMem *sm, int load, int data_only)
{
SFORMAT SystemRegs[] =
{
SFVAR(gSuzieDoneTime),
SFVAR(gSystemCycleCount),
SFVAR(gNextTimerEvent),
SFVAR(gCPUBootAddress),
SFVAR(gSystemIRQ),
SFVAR(gSystemNMI),
SFVAR(gSystemCPUSleep),
SFVAR(gSystemHalt),
SFARRAYN(lynxie->GetRamPointer(), RAM_SIZE, "RAM"),
SFEND
};
MDFNSS_StateAction(sm, load, data_only, SystemRegs, "SYST", false);
if(!lynxie->mSusie->StateAction(sm, load, data_only))
return(0);
if(!lynxie->mMemMap->StateAction(sm, load, data_only))
return(0);
if(!lynxie->mCart->StateAction(sm, load, data_only))
return(0);
if(!lynxie->mMikie->StateAction(sm, load, data_only))
return(0);
if(!lynxie->mCpu->StateAction(sm, load, data_only))
return(0);
return(1);
}
static void SetLayerEnableMask(uint64 mask)
{
}
static void DoSimpleCommand(int cmd)
{
switch(cmd)
{
case MDFN_MSC_POWER:
case MDFN_MSC_RESET: lynxie->Reset(); break;
}
}
static MDFNSetting LynxSettings[] =
{
{ "lynx.rotateinput", MDFNSF_NOFLAGS, "Virtually rotate D-pad along with screen.", NULL, MDFNST_BOOL, "1" },
{ "lynx.lowpass", MDFNSF_CAT_SOUND, "Enable sound output lowpass filter.", NULL, MDFNST_BOOL, "1" },
{ NULL }
};
static const InputDeviceInputInfoStruct IDII[] =
{
{ "a", "A (outer)", 8, IDIT_BUTTON_CAN_RAPID, NULL },
{ "b", "B (inner)", 7, IDIT_BUTTON_CAN_RAPID, NULL },
{ "option_2", "Option 2 (lower)", 5, IDIT_BUTTON_CAN_RAPID, NULL },
{ "option_1", "Option 1 (upper)", 4, IDIT_BUTTON_CAN_RAPID, NULL },
{ "left", "LEFT ←", /*VIRTB_DPAD0_L,*/ 2, IDIT_BUTTON, "right", { "up", "right", "down" } },
{ "right", "RIGHT →", /*VIRTB_DPAD0_R,*/ 3, IDIT_BUTTON, "left", { "down", "left", "up" } },
{ "up", "UP ↑", /*VIRTB_DPAD0_U,*/ 0, IDIT_BUTTON, "down", { "right", "down", "left" } },
{ "down", "DOWN ↓", /*VIRTB_DPAD0_D,*/ 1, IDIT_BUTTON, "up", { "left", "up", "right" } },
{ "pause", "PAUSE", 6, IDIT_BUTTON, NULL },
};
static InputDeviceInfoStruct InputDeviceInfo[] =
{
{
"gamepad",
"Gamepad",
NULL,
NULL,
sizeof(IDII) / sizeof(InputDeviceInputInfoStruct),
IDII,
}
};
static const InputPortInfoStruct PortInfo[] =
{
{ "builtin", "Built-In", sizeof(InputDeviceInfo) / sizeof(InputDeviceInfoStruct), InputDeviceInfo, 0 }
};
static InputInfoStruct InputInfo =
{
sizeof(PortInfo) / sizeof(InputPortInfoStruct),
PortInfo
};
static const FileExtensionSpecStruct KnownExtensions[] =
{
{ ".lnx", "Atari Lynx ROM Image" },
{ NULL, NULL }
};
MDFNGI EmulatedLynx =
{
LynxSettings,
MDFN_MASTERCLOCK_FIXED(16000000),
0,
false, // Multires possible?
160, // lcm_width
102, // lcm_height
NULL, // Dummy
160, // Nominal width
102, // Nominal height
160, // Framebuffer width
102, // Framebuffer height
2, // Number of output sound channels
};
#define MEDNAFEN_CORE_NAME_MODULE "lynx" #define MEDNAFEN_CORE_NAME_MODULE "lynx"
#define MEDNAFEN_CORE_NAME "Beetle Lynx" #define MEDNAFEN_CORE_NAME "Beetle Lynx"
#define MEDNAFEN_CORE_VERSION "v0.9.47" #define MEDNAFEN_CORE_VERSION "v0.9.47"
@ -662,7 +176,7 @@ static void check_variables(void)
#define MAX_BUTTONS 9 #define MAX_BUTTONS 9
static uint8_t input_buf[2]; static uint8_t input_buf[2];
static MDFNGI *MDFNI_LoadGame(const uint8_t *, size_t); static MDFNGI *MDFNI_LoadGame(const uint8_t *data, size_t size);
bool retro_load_game(const struct retro_game_info *info) bool retro_load_game(const struct retro_game_info *info)
{ {
if (!info || failed_init) if (!info || failed_init)
@ -707,7 +221,7 @@ bool retro_load_game(const struct retro_game_info *info)
surf = new MDFN_Surface(NULL, FB_WIDTH, FB_HEIGHT, FB_WIDTH, pix_fmt); surf = new MDFN_Surface(NULL, FB_WIDTH, FB_HEIGHT, FB_WIDTH, pix_fmt);
SetInput(0, "gamepad", &input_buf); SetInput(0, "gamepad", (uint8_t*)&input_buf);
rot_screen = 0; rot_screen = 0;
select_pressed_last_frame = 0; select_pressed_last_frame = 0;
@ -776,7 +290,6 @@ static void update_input(void)
}, },
}; };
uint16_t input_state = 0; uint16_t input_state = 0;
for (unsigned i = 0; i < MAX_BUTTONS; i++) for (unsigned i = 0; i < MAX_BUTTONS; i++)
input_state |= input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, map[rot_screen][i]) ? (1 << i) : 0; input_state |= input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, map[rot_screen][i]) ? (1 << i) : 0;
@ -1128,11 +641,17 @@ void MDFN_ResetMessages(void)
static MDFNGI *MDFNI_LoadGame(const uint8_t *data, size_t size) static MDFNGI *MDFNI_LoadGame(const uint8_t *data, size_t size)
{ {
if (!data || !size) { if (!data || !size) {
MDFN_indent(2); MDFN_indent(-2);
goto error; MDFNGameInfo = NULL;
return NULL;
} }
MDFNGameInfo = &EmulatedLynx; MDFNFILE *GameFile = file_open_mem(data, size);
if (!GameFile)
return NULL;
MDFNGameInfo = &EmulatedLynx;
MDFN_indent(1); MDFN_indent(1);
@ -1146,8 +665,7 @@ static MDFNGI *MDFNI_LoadGame(const uint8_t *data, size_t size)
// End load per-game settings // End load per-game settings
// //
if(Load(data, size) <= 0) Load(GameFile);
goto error;
MDFN_LoadGameCheats(NULL); MDFN_LoadGameCheats(NULL);
MDFNMP_InstallReadPatches(); MDFNMP_InstallReadPatches();
@ -1158,9 +676,6 @@ static MDFNGI *MDFNI_LoadGame(const uint8_t *data, size_t size)
return(MDFNGameInfo); return(MDFNGameInfo);
error:
MDFN_indent(-2);
MDFNGameInfo = NULL;
return NULL; return NULL;
} }

View File

@ -25,6 +25,24 @@
#include "file.h" #include "file.h"
struct MDFNFILE *file_open_mem(const uint8_t *data, int64_t size)
{
struct MDFNFILE *file = (struct MDFNFILE*)calloc(1, sizeof(*file));
if (!file)
return NULL;
if (!data || !size)
return NULL;
file->data = (uint8_t*)data;
file->size = size;
file->ext = 0;
file->location = 0;
return file;
}
struct MDFNFILE *file_open(const char *path) struct MDFNFILE *file_open(const char *path)
{ {
int64_t size = 0; int64_t size = 0;

View File

@ -15,6 +15,7 @@ struct MDFNFILE
int64_t location; int64_t location;
}; };
struct MDFNFILE *file_open_mem(const uint8_t *data, int64_t size);
struct MDFNFILE *file_open(const char *path); struct MDFNFILE *file_open(const char *path);
int file_close(struct MDFNFILE *file); int file_close(struct MDFNFILE *file);

View File

@ -50,13 +50,9 @@
#include <string.h> #include <string.h>
#include "cart.h" #include "cart.h"
#include "../state.h" #include "../state.h"
#include <../md5.h> #include "../md5.h"
#include "../../scrc32.h" #include "../../scrc32.h"
#include "../mednafen-endian.h"
static inline uint16_t MDFN_de16lsb(const uint8_t *morp)
{
return(morp[0] | (morp[1] << 8));
}
LYNX_HEADER CCart::DecodeHeader(const uint8 *data) LYNX_HEADER CCart::DecodeHeader(const uint8 *data)
{ {
@ -100,39 +96,38 @@ bool CCart::TestMagic(const uint8 *data, uint32 size)
return(true); return(true);
} }
CCart::CCart(const uint8 *gamedata, uint32 gamesize) CCart::CCart(MDFNFILE *fp)
{ {
LYNX_HEADER header; uint64 gamesize;
uint8 raw_header[HEADER_RAW_SIZE]; uint8 raw_header[HEADER_RAW_SIZE];
LYNX_HEADER header;
uint32 loop; uint32 loop;
md5_context md5;
md5.starts();
mWriteEnableBank0=false; mWriteEnableBank0=false;
mWriteEnableBank1=false; mWriteEnableBank1=false;
mCartRAM=false; mCartRAM=false;
if (gamesize) { if(fp)
{
gamesize = GET_FSIZE_PTR(fp);
// Checkout the header bytes // Checkout the header bytes
memcpy(&raw_header, gamedata, sizeof(LYNX_HEADER)); file_read(fp, raw_header, sizeof(LYNX_HEADER), 1);
header = DecodeHeader(raw_header); header = DecodeHeader(raw_header);
// Sanity checks on the header // Sanity checks on the header
if(header.magic[0]!= 'L' || header.magic[1]!='Y' || header.magic[2]!='N' || header.magic[3]!='X' || header.version!=1) if(header.magic[0]!= 'L' || header.magic[1]!='Y' || header.magic[2]!='N' || header.magic[3]!='X' || header.version!=1)
{ {
MDFN_printf("Invalid cart, no header?\n"); file_seek(fp, 0, SEEK_SET);
MDFN_printf("Trying to guess ROM layout\n"); memset(&header, 0, HEADER_RAW_SIZE);
memset(&header, 0, sizeof(LYNX_HEADER));
strncpy((char*)&header.cartname, "NO HEADER", 32); strncpy((char*)&header.cartname, "NO HEADER", 32);
strncpy((char*)&header.manufname, "HANDY", 16); strncpy((char*)&header.manufname, "HANDY", 16);
header.page_size_bank0 = gamesize >> 8; // Hard workaround... header.page_size_bank0 = gamesize >> 8; // Hard workaround...
} }
else else
{ {
gamedata += HEADER_RAW_SIZE;
gamesize -= HEADER_RAW_SIZE; gamesize -= HEADER_RAW_SIZE;
MDFN_printf("Found LYNX header!\n");
} }
} }
else else
@ -145,6 +140,8 @@ CCart::CCart(const uint8 *gamedata, uint32 gamesize)
// Setup rotation // Setup rotation
header.rotation = 0; header.rotation = 0;
gamesize = HEADER_RAW_SIZE;
} }
InfoROMSize = gamesize; InfoROMSize = gamesize;
@ -153,6 +150,9 @@ CCart::CCart(const uint8 *gamedata, uint32 gamesize)
strncpy(mName,(char*)&header.cartname, 32); strncpy(mName,(char*)&header.cartname, 32);
strncpy(mManufacturer,(char*)&header.manufname, 16); strncpy(mManufacturer,(char*)&header.manufname, 16);
MDFN_printf("Name: %s\n", mName);
MDFN_printf("Manufacturer: %s\n", mManufacturer);
// Setup rotation // Setup rotation
mRotation=header.rotation; mRotation=header.rotation;
if(mRotation!=CART_NO_ROTATE && mRotation!=CART_ROTATE_LEFT && mRotation!=CART_ROTATE_RIGHT) mRotation=CART_NO_ROTATE; if(mRotation!=CART_NO_ROTATE && mRotation!=CART_ROTATE_LEFT && mRotation!=CART_ROTATE_RIGHT) mRotation=CART_NO_ROTATE;
@ -161,7 +161,7 @@ CCart::CCart(const uint8 *gamedata, uint32 gamesize)
CTYPE banktype0,banktype1; CTYPE banktype0,banktype1;
switch(header.page_size_bank0) switch(header.page_size_bank0)
{ {
case 0x000: case 0x000:
banktype0=UNUSED; banktype0=UNUSED;
@ -233,7 +233,7 @@ CCart::CCart(const uint8 *gamedata, uint32 gamesize)
break; break;
} }
// Make some space for the new carts // Make some space for the new carts
mCartBank0 = new uint8[mMaskBank0+1]; mCartBank0 = new uint8[mMaskBank0+1];
mCartBank1 = new uint8[mMaskBank1+1]; mCartBank1 = new uint8[mMaskBank1+1];
@ -244,28 +244,34 @@ CCart::CCart(const uint8 *gamedata, uint32 gamesize)
// Initialiase // Initialiase
int bank0size = std::min((int)gamesize, (int)(mMaskBank0 + 1)); for(loop=0;loop<mMaskBank0+1;loop++)
int bank1size = std::min((int)gamesize, (int)(mMaskBank1 + 1));
for (loop = 0; loop < bank0size; loop++)
mCartBank0[loop] = DEFAULT_CART_CONTENTS; mCartBank0[loop] = DEFAULT_CART_CONTENTS;
for (loop = 0; loop < bank1size; loop++) for(loop=0;loop<mMaskBank1+1;loop++)
mCartBank1[loop] = DEFAULT_CART_CONTENTS; mCartBank1[loop] = DEFAULT_CART_CONTENTS;
mCRC32 = 0;
// Read in the BANK0 bytes // Read in the BANK0 bytes
if (mMaskBank0) {
memcpy(mCartBank0, gamedata, bank0size); mCRC32 = 0;
mCRC32 = crc32(0, mCartBank0, bank0size); md5_context md5;
md5.update(mCartBank0, bank0size); md5.starts();
if (mMaskBank0)
{
uint64 size = std::min<uint64>(gamesize, mMaskBank0 + 1);
file_read(fp, mCartBank0, size, 1);
mCRC32 = crc32(0, mCartBank0, size);
md5.update(mCartBank0, size);
gamesize -= size;
} }
// Read in the BANK1 bytes // Read in the BANK1 bytes
if (mMaskBank1) { if (mMaskBank1)
memcpy(mCartBank1, gamedata + bank0size, bank1size); {
mCRC32 = crc32(mCRC32, mCartBank1, bank1size); uint64 size = std::min<uint64>(gamesize, mMaskBank0 + 1);
md5.update(mCartBank1, bank1size); file_read(fp, mCartBank1, size, 1);
mCRC32 = crc32(mCRC32, mCartBank1, size);
md5.update(mCartBank1, size);
} }
md5.finish(MD5); md5.finish(MD5);
@ -422,17 +428,17 @@ int CCart::StateAction(StateMem *sm, int load, int data_only)
{ {
SFORMAT CartRegs[] = SFORMAT CartRegs[] =
{ {
SFVAR(mCounter), SFVAR(mCounter),
SFVAR(mShifter), SFVAR(mShifter),
SFVAR(mAddrData), SFVAR(mAddrData),
SFVAR(mStrobe), SFVAR(mStrobe),
SFVAR(mShiftCount0), SFVAR(mShiftCount0),
SFVAR(mCountMask0), SFVAR(mCountMask0),
SFVAR(mShiftCount1), SFVAR(mShiftCount1),
SFVAR(mCountMask1), SFVAR(mCountMask1),
SFVAR(mBank), SFVAR(mBank),
SFVAR(mWriteEnableBank0), SFVAR(mWriteEnableBank0),
SFVAR(mWriteEnableBank1), SFVAR(mWriteEnableBank1),
SFVAR(last_strobe), SFVAR(last_strobe),
SFARRAYN(mCartBank1, mCartRAM ? mMaskBank1 + 1 : 0, "mCartBank1"), SFARRAYN(mCartBank1, mCartRAM ? mMaskBank1 + 1 : 0, "mCartBank1"),
SFEND SFEND

View File

@ -71,7 +71,7 @@ class CCart : public CLynxBase
// Function members // Function members
public: public:
CCart(const uint8 *gamedata, uint32 gamesize) MDFN_COLD; CCart(MDFNFILE *fp) MDFN_COLD;
~CCart() MDFN_COLD; ~CCart() MDFN_COLD;
public: public:
@ -113,8 +113,8 @@ class CCart : public CLynxBase
uint32 mWriteEnableBank1; uint32 mWriteEnableBank1;
uint32 mCartRAM; uint32 mCartRAM;
uint8 MD5[16];
uint32 InfoROMSize; uint32 InfoROMSize;
uint8 MD5[16];
private: private:
EMMODE mBank; EMMODE mBank;
uint32 mMaskBank0; uint32 mMaskBank0;

View File

@ -48,6 +48,24 @@
#include "../mednafen.h" #include "../mednafen.h"
typedef struct
{
union
{
struct
{
#ifdef MSB_FIRST
uint8 High;
uint8 Low;
#else
uint8 Low;
uint8 High;
#endif
} Union8;
uint16 Val16;
};
} Uuint16;
// Read/Write Cycle definitions // Read/Write Cycle definitions
#define CPU_RDWR_CYC 5 #define CPU_RDWR_CYC 5
#define DMA_RDWR_CYC 4 #define DMA_RDWR_CYC 4

View File

@ -390,46 +390,18 @@ void CMikie::DisplaySetAttributes(const MDFN_PixelFormat &format)
for(Spot.Index=0;Spot.Index<4096;Spot.Index++) for(Spot.Index=0;Spot.Index<4096;Spot.Index++)
{ {
mColourMap[Spot.Index]= format.MakeColor(((Spot.Colours.Red * 15) + 30), ((Spot.Colours.Green * 15) + 30), uint8 r = ((Spot.Colours.Red * 15) + 30);
((Spot.Colours.Blue * 15) + 30)); uint8 g = ((Spot.Colours.Green * 15) + 30);
uint8 b = ((Spot.Colours.Blue * 15) + 30);
mColourMap[Spot.Index]= format.MakeColor(r, g, b);
} }
} }
void CMikie::CopyLineSurface32(void) template<typename T>
void CMikie::CopyLineSurface(void)
{ {
uint32_t* bitmap_tmp = mpDisplayCurrent->pixels + mpDisplayCurrentLine * mpDisplayCurrent->pitchinpix; T* bitmap_tmp = mpDisplayCurrent->pix<T>() + mpDisplayCurrentLine * mpDisplayCurrent->pitchinpix;
if(mpDisplayCurrentLine > 102)
{
printf("Lynx Line Overflow: %d\n", mpDisplayCurrentLine);
return;
}
for(uint32 loop = 0; loop < SCREEN_WIDTH / 2; loop++)
{
uint32 source = mpRamPointer[(uint16)mLynxAddr];
if(mDISPCTL_Flip)
{
mLynxAddr--;
*bitmap_tmp=mColourMap[mPalette[source&0x0f].Index];
bitmap_tmp++;
*bitmap_tmp=mColourMap[mPalette[source>>4].Index];
bitmap_tmp++;
}
else
{
mLynxAddr++;
*bitmap_tmp = mColourMap[mPalette[source>>4].Index];
bitmap_tmp++;
*bitmap_tmp = mColourMap[mPalette[source&0x0f].Index];
bitmap_tmp++;
}
}
}
void CMikie::CopyLineSurface16(void)
{
uint16_t* bitmap_tmp = mpDisplayCurrent->pixels16 + mpDisplayCurrentLine * mpDisplayCurrent->pitchinpix;
if(mpDisplayCurrentLine > 102) if(mpDisplayCurrentLine > 102)
{ {
@ -475,7 +447,7 @@ uint32 CMikie::DisplayRenderLine(void)
} }
// Logic says it should be 101 but testing on an actual lynx shows the rest // Logic says it should be 101 but testing on an actual lynx shows the rest
// persiod is between lines 102,101,100 with the new line being latched at // period is between lines 102,101,100 with the new line being latched at
// the beginning of count==99 hence the code below !! // the beginning of count==99 hence the code below !!
// Emulate REST signal // Emulate REST signal
@ -517,11 +489,11 @@ uint32 CMikie::DisplayRenderLine(void)
switch(mpDisplayCurrent->format.bpp) switch(mpDisplayCurrent->format.bpp)
{ {
case 16: case 16:
CopyLineSurface16(); CopyLineSurface<uint16>();
break; break;
case 32: case 32:
CopyLineSurface32(); CopyLineSurface<uint32>();
break; break;
} }
@ -928,7 +900,7 @@ void CMikie::Poke(uint32 addr,uint8 data)
{ {
C6502_REGS regs; C6502_REGS regs;
mSystem.GetRegs(regs); mSystem.GetRegs(regs);
MDFN_printf("Runtime Alert - System Halted\nCMikie::Poke(SYSCTL1) - Lynx power down occured at PC=$%04x.\nResetting system.\n",regs.PC); MDFN_printf("Runtime Alert - System Halted\nCMikie::Poke(SYSCTL1) - Lynx power down occurred at PC=$%04x.\nResetting system.\n",regs.PC);
mSystem.Reset(); mSystem.Reset();
gSystemHalt=true; gSystemHalt=true;
} }

View File

@ -395,8 +395,7 @@ class CMikie : public CLynxBase
uint32 mLynxLineDMACounter; uint32 mLynxLineDMACounter;
uint32 mLynxAddr; uint32 mLynxAddr;
void CopyLineSurface16(void); template<typename T> void CopyLineSurface(void);
void CopyLineSurface32(void);
}; };

View File

@ -67,16 +67,18 @@ bool CRam::TestMagic(const uint8* data, uint64 test_size)
return true; return true;
} }
CRam::CRam(const uint8 *filememory,uint32 filesize) CRam::CRam(MDFNFILE *fp)
:mRamXORData(NULL)
{ {
mFileSize=filesize; if(fp)
InfoRAMSize = 0;
if(filesize)
{ {
uint8 raw_header[HEADER_RAW_SIZE]; uint8 raw_header[HEADER_RAW_SIZE];
md5_context md5;
md5.starts();
mCRC32 = 0;
memcpy(&raw_header, filememory, sizeof(raw_header)); file_read(fp, raw_header, sizeof(raw_header), 1);
file_seek(fp, 0, SEEK_SET);
if(memcmp(&raw_header[6], "BS93", 4)) if(memcmp(&raw_header[6], "BS93", 4))
{ {
@ -93,14 +95,10 @@ CRam::CRam(const uint8 *filememory,uint32 filesize)
//printf("load_addr=%04x, size=%04x, rc0=%04x, rc1=%04x\n", load_address, size, rc0, rc1); //printf("load_addr=%04x, size=%04x, rc0=%04x, rc1=%04x\n", load_address, size, rc0, rc1);
md5_context md5; file_read(fp, &mRamXORData[load_address], rc0, 1);
md5.starts();
mCRC32 = 0;
memcpy(&mRamXORData[load_address], filememory, rc0);
md5.update(&mRamXORData[load_address], rc0); md5.update(&mRamXORData[load_address], rc0);
mCRC32 = crc32(mCRC32, &mRamXORData[load_address], rc0); mCRC32 = crc32(mCRC32, &mRamXORData[load_address], rc0);
memcpy(&mRamXORData[0x0000], filememory + rc0, rc1); file_read(fp, &mRamXORData[0x0000], rc1, 1);
md5.update(&mRamXORData[0x0000], rc1); md5.update(&mRamXORData[0x0000], rc1);
mCRC32 = crc32(mCRC32, &mRamXORData[0x0000], rc1); mCRC32 = crc32(mCRC32, &mRamXORData[0x0000], rc1);
@ -112,6 +110,8 @@ CRam::CRam(const uint8 *filememory,uint32 filesize)
boot_addr = load_address; boot_addr = load_address;
} }
else
InfoRAMSize = 0;
// Reset will cause the loadup // Reset will cause the loadup
Reset(); Reset();
@ -119,20 +119,18 @@ CRam::CRam(const uint8 *filememory,uint32 filesize)
CRam::~CRam() CRam::~CRam()
{ {
if(mFileSize) if (mRamXORData != NULL)
{ delete[] mRamXORData;
delete[] mRamXORData;
}
} }
void CRam::Reset(void) void CRam::Reset(void)
{ {
MDFNMP_AddRAM(65536, 0x0000, mRamData); MDFNMP_AddRAM(65536, 0x0000, mRamData);
for(int loop=0;loop<RAM_SIZE;loop++) for(unsigned i = 0; i < RAM_SIZE; i++)
mRamData[loop]=DEFAULT_RAM_CONTENTS; mRamData[i] = DEFAULT_RAM_CONTENTS;
if(mFileSize) if(mRamXORData)
{ {
for(unsigned i = 0; i < RAM_SIZE; i++) for(unsigned i = 0; i < RAM_SIZE; i++)
mRamData[i] ^= mRamXORData[i]; mRamData[i] ^= mRamXORData[i];

View File

@ -57,7 +57,7 @@ class CRam : public CLynxBase
public: public:
enum { HEADER_RAW_SIZE = 10 }; enum { HEADER_RAW_SIZE = 10 };
CRam(const uint8 *filememory,uint32 filesize) MDFN_COLD; CRam(MDFNFILE *fp) MDFN_COLD;
~CRam() MDFN_COLD; ~CRam() MDFN_COLD;
static bool TestMagic(const uint8* data, uint64 test_size) MDFN_COLD; static bool TestMagic(const uint8* data, uint64 test_size) MDFN_COLD;
@ -65,8 +65,8 @@ class CRam : public CLynxBase
void Reset(void) MDFN_COLD; void Reset(void) MDFN_COLD;
void Poke(uint32 addr, uint8 data){ mRamData[addr]=data;}; void Poke(uint32 addr, uint8 data){ mRamData[(uint16)addr]=data;};
uint8 Peek(uint32 addr){ return(mRamData[addr]);}; uint8 Peek(uint32 addr){ return(mRamData[(uint16)addr]);};
uint32 ReadCycle(void) {return 5;}; uint32 ReadCycle(void) {return 5;};
uint32 WriteCycle(void) {return 5;}; uint32 WriteCycle(void) {return 5;};
uint32 ObjectSize(void) {return RAM_SIZE;}; uint32 ObjectSize(void) {return RAM_SIZE;};
@ -81,7 +81,6 @@ class CRam : public CLynxBase
uint8 mRamData[RAM_SIZE]; uint8 mRamData[RAM_SIZE];
uint8 *mRamXORData; uint8 *mRamXORData;
uint16 boot_addr; uint16 boot_addr;
uint32 mFileSize;
uint32 mCRC32; uint32 mCRC32;
}; };

View File

@ -54,33 +54,34 @@
CRom::CRom(const char *romfile) CRom::CRom(const char *romfile)
{ {
unsigned loop; mWriteEnable=false;
mWriteEnable=false; Reset();
Reset();
// Initialise ROM // Initialise ROM
for(loop = 0;loop < ROM_SIZE;loop++) for(int loop=0;loop<ROM_SIZE;loop++) mRomData[loop]=DEFAULT_ROM_CONTENTS;
mRomData[loop]=DEFAULT_ROM_CONTENTS;
// Load up the file // Load up the file
MDFNFILE *BIOSFile = file_open(romfile);
if(!BIOSFile)
{ {
MDFNFILE *BIOSFile = file_open(romfile);
if(!BIOSFile)
{
/* Could not open Lynx boot ROM. */ /* Could not open Lynx boot ROM. */
return; return;
} }
if(BIOSFile->size < 512) if(BIOSFile->size < 512)
{ {
/* Lynx Boot ROM image is of an incorrect size. */ /* Lynx Boot ROM image is of an incorrect size. */
return; return;
}
// memcpy(mRomData, BIOSFile->data, 512);
file_read(BIOSFile, mRomData, 512, 1);
file_close(BIOSFile);
} }
memcpy(mRomData, BIOSFile->data, 512);
file_close(BIOSFile);
} }
void CRom::Reset(void) void CRom::Reset(void)

View File

@ -98,26 +98,6 @@ enum {sprite_background_shadow=0,
sprite_xor_shadow, sprite_xor_shadow,
sprite_shadow}; sprite_shadow};
/* Define register typedefs */
typedef struct
{
union
{
struct
{
#ifdef MSB_FIRST
uint8 High;
uint8 Low;
#else
uint8 Low;
uint8 High;
#endif
} Union8;
uint16 Val16;
};
} Uuint16;
typedef struct typedef struct
{ {
union union

478
mednafen/lynx/system.cpp Normal file
View File

@ -0,0 +1,478 @@
//
// Copyright (c) 2004 K. Wilkins
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from
// the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
//////////////////////////////////////////////////////////////////////////////
// Handy - An Atari Lynx Emulator //
// Copyright (c) 1996,1997 //
// K. Wilkins //
//////////////////////////////////////////////////////////////////////////////
// System object class //
//////////////////////////////////////////////////////////////////////////////
// //
// This class provides the glue to bind of of the emulation objects //
// together via peek/poke handlers and pass thru interfaces to lower //
// objects, all control of the emulator is done via this class. Update() //
// does most of the work and each call emulates one CPU instruction and //
// updates all of the relevant hardware if required. It must be remembered //
// that if that instruction involves setting SPRGO then, it will cause a //
// sprite painting operation and then a corresponding update of all of the //
// hardware which will usually involve recursive calls to Update, see //
// Mikey SPRGO code for more details. //
// //
// K. Wilkins //
// August 1997 //
// //
//////////////////////////////////////////////////////////////////////////////
// Revision History: //
// ----------------- //
// //
// 01Aug1997 KW Document header added & class documented. //
// //
//////////////////////////////////////////////////////////////////////////////
#define SYSTEM_CPP
//#include <crtdbg.h>
//#define TRACE_SYSTEM
#include "mednafen/lynx/system.h"
#include "mednafen/mednafen-endian.h"
#include "mednafen/general.h"
#include "mednafen/mempatcher.h"
#include "mednafen/md5.h"
CSystem::CSystem(MDFNFILE *fp)
:mCart(NULL),
mRom(NULL),
mMemMap(NULL),
mRam(NULL),
mCpu(NULL),
mMikie(NULL),
mSusie(NULL)
{
mFileType=HANDY_FILETYPE_ILLEGAL;
char clip[11];
file_read(fp, clip, 11, 1);
file_seek(fp, 0, SEEK_SET);
clip[4]=0;
clip[10]=0;
if(!strcmp(&clip[6],"BS93"))
mFileType=HANDY_FILETYPE_HOMEBREW;
else if(!strcmp(&clip[0],"LYNX"))
mFileType=HANDY_FILETYPE_LNX;
else if(GET_FSIZE_PTR(fp)==128*1024 || GET_FSIZE_PTR(fp)==256*1024 || GET_FSIZE_PTR(fp)==512*1024)
/* Invalid Cart (type). but 128/256/512k size -> set to RAW and try to load raw rom image */
mFileType=HANDY_FILETYPE_RAW;
else
{
/* File format is unknown to module. This will then
* just load the core into an "Insert Game" screen */
}
MDFNMP_Init(65536, 1);
// Create the system objects that we'll use
// Attempt to load the cartridge errors caught above here...
mRom = new CRom(MDFN_MakeFName(MDFNMKF_FIRMWARE, 0, "lynxboot.img").c_str());
// An exception from this will be caught by the level above
switch(mFileType)
{
case HANDY_FILETYPE_RAW:
case HANDY_FILETYPE_LNX:
mCart = new CCart(fp);
mRam = new CRam(NULL);
break;
case HANDY_FILETYPE_HOMEBREW:
mCart = new CCart(NULL);
mRam = new CRam(fp);
break;
case HANDY_FILETYPE_SNAPSHOT:
case HANDY_FILETYPE_ILLEGAL:
default:
mCart = new CCart(NULL);
mRam = new CRam(NULL);
break;
}
// These can generate exceptions
mMikie = new CMikie(*this);
mSusie = new CSusie(*this);
// Instantiate the memory map handler
mMemMap = new CMemMap(*this);
// Now the handlers are set we can instantiate the CPU as is will use handlers on reset
mCpu = new C65C02(*this);
// Now init is complete do a reset, this will cause many things to be reset twice
// but what the hell, who cares, I don't.....
Reset();
}
CSystem::~CSystem()
{
// Cleanup all our objects
if(mCart!=NULL) delete mCart;
if(mRom!=NULL) delete mRom;
if(mRam!=NULL) delete mRam;
if(mCpu!=NULL) delete mCpu;
if(mMikie!=NULL) delete mMikie;
if(mSusie!=NULL) delete mSusie;
if(mMemMap!=NULL) delete mMemMap;
}
void CSystem::Reset(void)
{
mMikie->startTS -= gSystemCycleCount;
gSystemCycleCount=0;
gNextTimerEvent=0;
gCPUBootAddress=0;
gSystemIRQ=false;
gSystemNMI=false;
gSystemCPUSleep=false;
gSystemHalt=false;
gSuzieDoneTime = 0;
mMemMap->Reset();
mCart->Reset();
mRom->Reset();
mRam->Reset();
mMikie->Reset();
mSusie->Reset();
mCpu->Reset();
// Homebrew hashup
if(mFileType==HANDY_FILETYPE_HOMEBREW)
{
mMikie->PresetForHomebrew();
C6502_REGS regs;
mCpu->GetRegs(regs);
regs.PC=(uint16)gCPUBootAddress;
mCpu->SetRegs(regs);
}
}
// Somewhat of a hack to make sure undrawn lines are black.
bool LynxLineDrawn[256];
CSystem *lynxie = NULL;
static bool TestMagic(const char *name, MDFNFILE *fp)
{
uint8 data[64];
uint64 rc;
rc = fp->size;
if(rc >= CCart::HEADER_RAW_SIZE && CCart::TestMagic(data, sizeof(data)))
return true;
if(rc >= CRam::HEADER_RAW_SIZE && CRam::TestMagic(data, sizeof(data)))
return true;
return false;
}
static void Cleanup(void)
{
if(lynxie)
{
delete lynxie;
lynxie = NULL;
}
}
void Load(MDFNFILE *fp)
{
lynxie = new CSystem(fp);
switch(lynxie->CartGetRotate())
{
case CART_ROTATE_LEFT:
MDFNGameInfo->rotated = MDFN_ROTATE270;
break;
case CART_ROTATE_RIGHT:
MDFNGameInfo->rotated = MDFN_ROTATE90;
break;
}
if(lynxie->mRam->InfoRAMSize)
{
memcpy(MDFNGameInfo->MD5, lynxie->mRam->MD5, 16);
MDFN_printf(_("RAM: %u bytes\n"), lynxie->mRam->InfoRAMSize);
MDFN_printf(_("CRC32: 0x%08x\n"), lynxie->mRam->CRC32());
MDFN_printf(_("RAM MD5: 0x%s\n"), md5_context::asciistr(MDFNGameInfo->MD5, 0).c_str());
}
else
{
memcpy(MDFNGameInfo->MD5, lynxie->mCart->MD5, 16);
MDFN_printf(_("ROM: %dKiB\n"), (lynxie->mCart->InfoROMSize + 1023) / 1024);
MDFN_printf(_("CRC32: 0x%08x\n"), lynxie->mCart->CRC32());
MDFN_printf(_("ROM MD5: 0x%s\n"), md5_context::asciistr(MDFNGameInfo->MD5, 0).c_str());
}
MDFNGameInfo->fps = (uint32)(59.8 * 65536 * 256);
if(MDFN_GetSettingB("lynx.lowpass"))
{
lynxie->mMikie->miksynth.treble_eq(-35);
}
else
{
lynxie->mMikie->miksynth.treble_eq(0);
}
}
void CloseGame(void)
{
Cleanup();
}
static uint8 *chee;
void Emulate(EmulateSpecStruct *espec)
{
espec->DisplayRect.x = 0;
espec->DisplayRect.y = 0;
espec->DisplayRect.w = 160;
espec->DisplayRect.h = 102;
if(espec->VideoFormatChanged)
lynxie->DisplaySetAttributes(espec->surface->format); // FIXME, pitch
if(espec->SoundFormatChanged)
{
lynxie->mMikie->mikbuf.set_sample_rate(espec->SoundRate ? espec->SoundRate : 44100, 60);
lynxie->mMikie->mikbuf.clock_rate((long int)(16000000 / 4));
lynxie->mMikie->mikbuf.bass_freq(60);
lynxie->mMikie->miksynth.volume(0.50);
}
uint16 butt_data = chee[0] | (chee[1] << 8);
lynxie->SetButtonData(butt_data);
MDFNMP_ApplyPeriodicCheats();
memset(LynxLineDrawn, 0, sizeof(LynxLineDrawn[0]) * 102);
lynxie->mMikie->mpSkipFrame = espec->skip;
lynxie->mMikie->mpDisplayCurrent = espec->surface;
lynxie->mMikie->mpDisplayCurrentLine = 0;
lynxie->mMikie->startTS = gSystemCycleCount;
while(lynxie->mMikie->mpDisplayCurrent && (gSystemCycleCount - lynxie->mMikie->startTS) < 700000)
{
lynxie->Update();
// printf("%d ", gSystemCycleCount - lynxie->mMikie->startTS);
}
{
// FIXME, we should integrate this into mikie.*
uint32 color_black = espec->surface->MakeColor(30, 30, 30);
for(int y = 0; y < 102; y++)
{
if(espec->surface->format.bpp == 16)
{
uint16 *row = espec->surface->pixels16 + y * espec->surface->pitchinpix;
if(!LynxLineDrawn[y])
{
for(int x = 0; x < 160; x++)
row[x] = color_black;
}
}
else
{
uint32 *row = espec->surface->pixels + y * espec->surface->pitchinpix;
if(!LynxLineDrawn[y])
{
for(int x = 0; x < 160; x++)
row[x] = color_black;
}
}
}
}
espec->MasterCycles = gSystemCycleCount - lynxie->mMikie->startTS;
if(espec->SoundBuf)
{
lynxie->mMikie->mikbuf.end_frame((gSystemCycleCount - lynxie->mMikie->startTS) >> 2);
espec->SoundBufSize = lynxie->mMikie->mikbuf.read_samples(espec->SoundBuf, espec->SoundBufMaxSize) / 2; // divide by nr audio chn
}
else
espec->SoundBufSize = 0;
}
void SetInput(unsigned port, const char *type, uint8 *ptr)
{
chee = (uint8 *)ptr;
}
static void TransformInput(void)
{
if(MDFN_GetSettingB("lynx.rotateinput"))
{
static const unsigned bp[4] = { 4, 6, 5, 7 };
const unsigned offs = MDFNGameInfo->rotated;
uint16 butt_data = MDFN_de16lsb(chee);
butt_data = (butt_data & 0xFF0F) |
(((butt_data >> bp[0]) & 1) << bp[(0 + offs) & 3]) |
(((butt_data >> bp[1]) & 1) << bp[(1 + offs) & 3]) |
(((butt_data >> bp[2]) & 1) << bp[(2 + offs) & 3]) |
(((butt_data >> bp[3]) & 1) << bp[(3 + offs) & 3]);
//printf("%d, %04x\n", MDFNGameInfo->rotated, butt_data);
MDFN_en16lsb(chee, butt_data);
}
}
int StateAction(StateMem *sm, int load, int data_only)
{
SFORMAT SystemRegs[] =
{
SFVAR(gSuzieDoneTime),
SFVAR(gSystemCycleCount),
SFVAR(gNextTimerEvent),
SFVAR(gCPUBootAddress),
SFVAR(gSystemIRQ),
SFVAR(gSystemNMI),
SFVAR(gSystemCPUSleep),
SFVAR(gSystemHalt),
SFARRAYN(lynxie->GetRamPointer(), RAM_SIZE, "RAM"),
SFEND
};
int ret = MDFNSS_StateAction(sm, load, data_only, SystemRegs, "SYST", false);
ret &= lynxie->mSusie->StateAction(sm, load, data_only);
ret &= lynxie->mMemMap->StateAction(sm, load, data_only);
ret &= lynxie->mCart->StateAction(sm, load, data_only);
ret &= lynxie->mMikie->StateAction(sm, load, data_only);
ret &= lynxie->mCpu->StateAction(sm, load, data_only);
return ret;
}
static void SetLayerEnableMask(uint64 mask)
{
}
void DoSimpleCommand(int cmd)
{
switch(cmd)
{
case MDFN_MSC_POWER:
case MDFN_MSC_RESET: lynxie->Reset(); break;
}
}
static MDFNSetting LynxSettings[] =
{
{ "lynx.rotateinput", MDFNSF_NOFLAGS, "Virtually rotate D-pad along with screen.", NULL, MDFNST_BOOL, "1" },
{ "lynx.lowpass", MDFNSF_CAT_SOUND, "Enable sound output lowpass filter.", NULL, MDFNST_BOOL, "1" },
{ NULL }
};
static const InputDeviceInputInfoStruct IDII[] =
{
{ "a", "A (outer)", 8, IDIT_BUTTON_CAN_RAPID, NULL },
{ "b", "B (inner)", 7, IDIT_BUTTON_CAN_RAPID, NULL },
{ "option_2", "Option 2 (lower)", 5, IDIT_BUTTON_CAN_RAPID, NULL },
{ "option_1", "Option 1 (upper)", 4, IDIT_BUTTON_CAN_RAPID, NULL },
{ "left", "LEFT ←", /*VIRTB_DPAD0_L,*/ 2, IDIT_BUTTON, "right", { "up", "right", "down" } },
{ "right", "RIGHT →", /*VIRTB_DPAD0_R,*/ 3, IDIT_BUTTON, "left", { "down", "left", "up" } },
{ "up", "UP ↑", /*VIRTB_DPAD0_U,*/ 0, IDIT_BUTTON, "down", { "right", "down", "left" } },
{ "down", "DOWN ↓", /*VIRTB_DPAD0_D,*/ 1, IDIT_BUTTON, "up", { "left", "up", "right" } },
{ "pause", "PAUSE", 6, IDIT_BUTTON, NULL },
};
static InputDeviceInfoStruct InputDeviceInfo[] =
{
{
"gamepad",
"Gamepad",
NULL,
NULL,
sizeof(IDII) / sizeof(InputDeviceInputInfoStruct),
IDII,
}
};
static const InputPortInfoStruct PortInfo[] =
{
{ "builtin", "Built-In", sizeof(InputDeviceInfo) / sizeof(InputDeviceInfoStruct), InputDeviceInfo, 0 }
};
static InputInfoStruct InputInfo =
{
sizeof(PortInfo) / sizeof(InputPortInfoStruct),
PortInfo
};
static const FileExtensionSpecStruct KnownExtensions[] =
{
{ ".lnx", "Atari Lynx ROM Image" },
{ NULL, NULL }
};
MDFNGI EmulatedLynx =
{
LynxSettings,
MDFN_MASTERCLOCK_FIXED(16000000),
0,
false, // Multires possible?
160, // lcm_width
102, // lcm_height
NULL, // Dummy
160, // Nominal width
102, // Nominal height
160, // Framebuffer width
102, // Framebuffer height
2, // Number of output sound channels
};

View File

@ -114,7 +114,7 @@ class CSystem;
class CSystem : public CSystemBase class CSystem : public CSystemBase
{ {
public: public:
CSystem(const uint8 *, int32) MDFN_COLD; CSystem(MDFNFILE *fp) MDFN_COLD;
~CSystem() MDFN_COLD; ~CSystem() MDFN_COLD;
public: public:
@ -220,4 +220,13 @@ class CSystem : public CSystemBase
extern bool LynxLineDrawn[256]; extern bool LynxLineDrawn[256];
void Load(MDFNFILE *fp);
void CloseGame(void);
void Emulate(EmulateSpecStruct *espec);
void SetInput(unsigned port, const char *type, uint8 *ptr);
int StateAction(StateMem *sm, const unsigned load, const bool data_only);
void DoSimpleCommand(int cmd);
extern CSystem *lynxie;
#endif #endif

View File

@ -121,6 +121,27 @@ class MDFN_Surface //typedef struct
uint16 *pixels16; uint16 *pixels16;
uint32 *pixels; uint32 *pixels;
private:
INLINE void pix_(uint16*& z) const { z = pixels16; }
INLINE void pix_(uint32*& z) const { z = pixels; }
public:
template<typename T>
INLINE const T* pix(void) const
{
T* ret;
pix_(ret);
return (const T*)ret;
}
template<typename T>
INLINE T* pix(void)
{
T* ret;
pix_(ret);
return ret;
}
// w, h, and pitch32 should always be > 0 // w, h, and pitch32 should always be > 0
int32 w; int32 w;
int32 h; int32 h;