mirror of
https://github.com/libretro/beetle-lynx-libretro.git
synced 2024-11-23 08:10:55 +00:00
Cleanups
This commit is contained in:
parent
ccadc59f61
commit
0cd74c1f84
@ -14,8 +14,7 @@ SOURCES_CXX += \
|
||||
$(CORE_EMU_DIR)/mikie.cpp \
|
||||
$(CORE_EMU_DIR)/ram.cpp \
|
||||
$(CORE_EMU_DIR)/rom.cpp \
|
||||
$(CORE_EMU_DIR)/susie.cpp \
|
||||
$(CORE_EMU_DIR)/system.cpp
|
||||
$(CORE_EMU_DIR)/susie.cpp
|
||||
endif
|
||||
|
||||
ifeq ($(NEED_BLIP), 1)
|
||||
@ -81,6 +80,5 @@ SOURCES_CXX += \
|
||||
$(CORE_DIR)/libretro.cpp
|
||||
|
||||
SOURCES_C += \
|
||||
$(MEDNAFEN_DIR)/file.c \
|
||||
$(MEDNAFEN_DIR)/general.c
|
||||
$(MEDNAFEN_DIR)/file.c
|
||||
endif
|
||||
|
683
libretro.cpp
683
libretro.cpp
@ -1,3 +1,4 @@
|
||||
#include <stdarg.h>
|
||||
#include "mednafen/mednafen.h"
|
||||
#include "mednafen/mempatcher.h"
|
||||
#include "mednafen/git.h"
|
||||
@ -49,6 +50,462 @@ static void set_basename(const char *path)
|
||||
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_LNX;
|
||||
|
||||
if(filesize < 11)
|
||||
{
|
||||
/* Lynx ROM image is too short. */
|
||||
return;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
/* File format is unknown to module. */
|
||||
return;
|
||||
}
|
||||
|
||||
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_LNX:
|
||||
mCart = new CCart(filememory,filesize);
|
||||
mRam = new CRam(0,0);
|
||||
break;
|
||||
case HANDY_FILETYPE_HOMEBREW:
|
||||
{
|
||||
#if 0
|
||||
static uint8 dummy_cart[CCart::HEADER_RAW_SIZE + 65536] =
|
||||
{
|
||||
'L', 'Y', 'N', 'X', 0x00, 0x01, 0x00, 0x00,
|
||||
0x01, 0x00,
|
||||
};
|
||||
mCart = new CCart(dummy_cart, sizeof(dummy_cart));
|
||||
#else
|
||||
mCart = new CCart(NULL, 0);
|
||||
#endif
|
||||
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)
|
||||
{
|
||||
return(CCart::TestMagic(fp->data, fp->size));
|
||||
}
|
||||
|
||||
static int Load(const char *name, MDFNFILE *fp)
|
||||
{
|
||||
lynxie = new CSystem(GET_FDATA_PTR(fp), GET_FSIZE_PTR(fp));
|
||||
|
||||
int rot = lynxie->CartGetRotate();
|
||||
if(rot == CART_ROTATE_LEFT) MDFNGameInfo->rotated = MDFN_ROTATE270;
|
||||
else if(rot == CART_ROTATE_RIGHT) MDFNGameInfo->rotated = MDFN_ROTATE90;
|
||||
|
||||
gAudioEnabled = 1;
|
||||
|
||||
MDFN_printf(_("ROM: %dKiB\n"), (lynxie->mCart->InfoROMSize + 1023) / 1024);
|
||||
MDFN_printf(_("ROM CRC32: 0x%08x\n"), lynxie->mCart->CRC32());
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
std::vector <SSDescriptor> love;
|
||||
|
||||
love.push_back(SSDescriptor(SystemRegs, "SYST"));
|
||||
MDFNSS_StateAction(sm, load, data_only, love);
|
||||
|
||||
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, gettext_noop("Virtually rotate D-pad along with screen."), NULL, MDFNST_BOOL, "1" },
|
||||
{ "lynx.lowpass", MDFNSF_CAT_SOUND, gettext_noop("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", gettext_noop("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
|
||||
};
|
||||
|
||||
|
||||
#ifdef NEED_DEINTERLACER
|
||||
static bool PrevInterlaced;
|
||||
static Deinterlacer deint;
|
||||
@ -145,7 +602,7 @@ void retro_init(void)
|
||||
|
||||
void retro_reset(void)
|
||||
{
|
||||
game->DoSimpleCommand(MDFN_MSC_RESET);
|
||||
DoSimpleCommand(MDFN_MSC_RESET);
|
||||
}
|
||||
|
||||
bool retro_load_game_special(unsigned, const struct retro_game_info *, size_t)
|
||||
@ -175,12 +632,10 @@ static uint8_t input_buf[MAX_PLAYERS][2] = {0};
|
||||
|
||||
static void hookup_ports(bool force)
|
||||
{
|
||||
MDFNGI *currgame = game;
|
||||
|
||||
if (initial_ports_hookup && !force)
|
||||
return;
|
||||
|
||||
currgame->SetInput(0, "gamepad", &input_buf);
|
||||
SetInput(0, "gamepad", &input_buf);
|
||||
|
||||
initial_ports_hookup = true;
|
||||
}
|
||||
@ -240,7 +695,6 @@ void retro_unload_game()
|
||||
// See mednafen/psx/input/gamepad.cpp
|
||||
static void update_input(void)
|
||||
{
|
||||
MDFNGI *currgame = (MDFNGI*)game;
|
||||
static unsigned map[] = {
|
||||
RETRO_DEVICE_ID_JOYPAD_A,
|
||||
RETRO_DEVICE_ID_JOYPAD_B,
|
||||
@ -270,8 +724,6 @@ static uint64_t video_frames, audio_frames;
|
||||
|
||||
void retro_run()
|
||||
{
|
||||
MDFNGI *curgame = game;
|
||||
|
||||
input_poll_cb();
|
||||
|
||||
update_input();
|
||||
@ -305,7 +757,7 @@ void retro_run()
|
||||
last_sound_rate = spec.SoundRate;
|
||||
}
|
||||
|
||||
curgame->Emulate(&spec);
|
||||
Emulate(&spec);
|
||||
|
||||
#ifdef NEED_DEINTERLACER
|
||||
if (spec.InterlaceOn)
|
||||
@ -324,7 +776,7 @@ void retro_run()
|
||||
PrevInterlaced = false;
|
||||
#endif
|
||||
|
||||
int16 *const SoundBuf = spec.SoundBuf + spec.SoundBufSizeALMS * curgame->soundchan;
|
||||
int16 *const SoundBuf = spec.SoundBuf + spec.SoundBufSizeALMS * 2;
|
||||
int32 SoundBufSize = spec.SoundBufSize - spec.SoundBufSizeALMS;
|
||||
const int32 SoundBufMaxSize = spec.SoundBufMaxSize - spec.SoundBufSizeALMS;
|
||||
|
||||
@ -399,10 +851,6 @@ unsigned retro_api_version(void)
|
||||
|
||||
void retro_set_controller_port_device(unsigned in_port, unsigned device)
|
||||
{
|
||||
MDFNGI *currgame = (MDFNGI*)game;
|
||||
|
||||
if (!currgame)
|
||||
return;
|
||||
}
|
||||
|
||||
void retro_set_environment(retro_environment_t cb)
|
||||
@ -440,24 +888,13 @@ static size_t serialize_size;
|
||||
|
||||
size_t retro_serialize_size(void)
|
||||
{
|
||||
MDFNGI *curgame = (MDFNGI*)game;
|
||||
//if (serialize_size)
|
||||
// return serialize_size;
|
||||
|
||||
if (!curgame->StateAction)
|
||||
{
|
||||
if (log_cb)
|
||||
log_cb(RETRO_LOG_WARN, "[mednafen]: Module %s doesn't support save states.\n", curgame->shortname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
StateMem st;
|
||||
memset(&st, 0, sizeof(st));
|
||||
|
||||
if (!MDFNSS_SaveSM(&st, 0, 0, NULL, NULL, NULL))
|
||||
{
|
||||
if (log_cb)
|
||||
log_cb(RETRO_LOG_WARN, "[mednafen]: Module %s doesn't support save states.\n", curgame->shortname);
|
||||
log_cb(RETRO_LOG_WARN, "[mednafen]: Module lynx doesn't support save states.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -567,3 +1004,199 @@ void MDFND_PrintError(const char* err)
|
||||
if (log_cb)
|
||||
log_cb(RETRO_LOG_ERROR, "%s\n", err);
|
||||
}
|
||||
|
||||
extern MDFNGI EmulatedLynx;
|
||||
MDFNGI *MDFNGameInfo = &EmulatedLynx;
|
||||
|
||||
/* forward declarations */
|
||||
extern void MDFND_DispMessage(unsigned char *str);
|
||||
|
||||
void MDFN_DispMessage(const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap,format);
|
||||
char *msg = new char[4096];
|
||||
|
||||
vsnprintf(msg, 4096, format,ap);
|
||||
va_end(ap);
|
||||
|
||||
MDFND_DispMessage((UTF8*)msg);
|
||||
}
|
||||
|
||||
void MDFN_ResetMessages(void)
|
||||
{
|
||||
MDFND_DispMessage(NULL);
|
||||
}
|
||||
|
||||
|
||||
MDFNGI *MDFNI_LoadGame(const char *force_module, const char *name)
|
||||
{
|
||||
std::vector<FileExtensionSpecStruct> valid_iae;
|
||||
MDFNGameInfo = &EmulatedLynx;
|
||||
MDFNFILE *GameFile = NULL;
|
||||
|
||||
MDFN_printf(_("Loading %s...\n"),name);
|
||||
|
||||
MDFN_indent(1);
|
||||
|
||||
// Construct a NULL-delimited list of known file extensions for MDFN_fopen()
|
||||
const FileExtensionSpecStruct *curexts = KnownExtensions;
|
||||
|
||||
while(curexts->extension && curexts->description)
|
||||
{
|
||||
valid_iae.push_back(*curexts);
|
||||
curexts++;
|
||||
}
|
||||
|
||||
GameFile = file_open(name);
|
||||
|
||||
if(!GameFile)
|
||||
goto error;
|
||||
|
||||
MDFN_printf(_("Using module: lynx\n\n"));
|
||||
MDFN_indent(1);
|
||||
|
||||
//
|
||||
// Load per-game settings
|
||||
//
|
||||
// Maybe we should make a "pgcfg" subdir, and automatically load all files in it?
|
||||
// End load per-game settings
|
||||
//
|
||||
|
||||
if(Load(name, GameFile) <= 0)
|
||||
goto error;
|
||||
|
||||
MDFN_LoadGameCheats(NULL);
|
||||
MDFNMP_InstallReadPatches();
|
||||
|
||||
MDFN_ResetMessages(); // Save state, status messages, etc.
|
||||
|
||||
MDFN_indent(-2);
|
||||
|
||||
return(MDFNGameInfo);
|
||||
|
||||
error:
|
||||
if (GameFile)
|
||||
file_close(GameFile);
|
||||
MDFN_indent(-2);
|
||||
MDFNGameInfo = NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void MDFNI_CloseGame(void)
|
||||
{
|
||||
if(!MDFNGameInfo)
|
||||
return;
|
||||
|
||||
MDFN_FlushGameCheats(0);
|
||||
|
||||
CloseGame();
|
||||
|
||||
MDFNMP_Kill();
|
||||
|
||||
MDFNGameInfo = NULL;
|
||||
}
|
||||
|
||||
bool MDFNI_InitializeModule(void)
|
||||
{
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
int MDFNI_Initialize(const char *basedir)
|
||||
{
|
||||
return(1);
|
||||
}
|
||||
|
||||
static int curindent = 0;
|
||||
|
||||
void MDFN_indent(int indent)
|
||||
{
|
||||
curindent += indent;
|
||||
}
|
||||
|
||||
static uint8 lastchar = 0;
|
||||
|
||||
void MDFN_printf(const char *format, ...)
|
||||
{
|
||||
char *format_temp;
|
||||
char *temp;
|
||||
unsigned int x, newlen;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap,format);
|
||||
|
||||
|
||||
// First, determine how large our format_temp buffer needs to be.
|
||||
uint8 lastchar_backup = lastchar; // Save lastchar!
|
||||
for(newlen=x=0;x<strlen(format);x++)
|
||||
{
|
||||
if(lastchar == '\n' && format[x] != '\n')
|
||||
{
|
||||
int y;
|
||||
for(y=0;y<curindent;y++)
|
||||
newlen++;
|
||||
}
|
||||
newlen++;
|
||||
lastchar = format[x];
|
||||
}
|
||||
|
||||
format_temp = (char *)malloc(newlen + 1); // Length + NULL character, duh
|
||||
|
||||
// Now, construct our format_temp string
|
||||
lastchar = lastchar_backup; // Restore lastchar
|
||||
for(newlen=x=0;x<strlen(format);x++)
|
||||
{
|
||||
if(lastchar == '\n' && format[x] != '\n')
|
||||
{
|
||||
int y;
|
||||
for(y=0;y<curindent;y++)
|
||||
format_temp[newlen++] = ' ';
|
||||
}
|
||||
format_temp[newlen++] = format[x];
|
||||
lastchar = format[x];
|
||||
}
|
||||
|
||||
format_temp[newlen] = 0;
|
||||
|
||||
temp = new char[4096];
|
||||
vsnprintf(temp, 4096, format_temp, ap);
|
||||
free(format_temp);
|
||||
|
||||
MDFND_Message(temp);
|
||||
free(temp);
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void MDFN_PrintError(const char *format, ...)
|
||||
{
|
||||
char *temp;
|
||||
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
|
||||
temp = new char[4096];
|
||||
vsnprintf(temp, 4096, format, ap);
|
||||
MDFND_PrintError(temp);
|
||||
free(temp);
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void MDFN_DebugPrintReal(const char *file, const int line, const char *format, ...)
|
||||
{
|
||||
char *temp;
|
||||
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
|
||||
temp = new char[4096];
|
||||
vsnprintf(temp, 4096, format, ap);
|
||||
fprintf(stderr, "%s:%d %s\n", file, line, temp);
|
||||
free(temp);
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
@ -1,41 +0,0 @@
|
||||
/* Mednafen - Multi-system Emulator
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
const char * GetFNComponent(const char *str)
|
||||
{
|
||||
const char *tp1;
|
||||
|
||||
#ifdef _WIN32
|
||||
tp1 = ((char *)strrchr(str,'\\'));
|
||||
|
||||
const char *tp3;
|
||||
|
||||
tp3 = ((char *)strrchr(str,'/'));
|
||||
|
||||
if (tp1<tp3)
|
||||
tp1 = tp3;
|
||||
#else
|
||||
tp1 = ((char *)strrchr(str,'/'));
|
||||
#endif
|
||||
|
||||
if (tp1)
|
||||
return (tp1+1);
|
||||
return (str);
|
||||
}
|
@ -24,14 +24,4 @@ typedef enum
|
||||
|
||||
std::string MDFN_MakeFName(MakeFName_Type type, int id1, const char *cd1);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
const char * GetFNComponent(const char *str);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -276,70 +276,13 @@ typedef enum
|
||||
|
||||
class CDIF;
|
||||
|
||||
#define MDFN_MASTERCLOCK_FIXED(n) ((int64)((double)(n) * (1LL << 32)))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* Private functions to Mednafen. Do not call directly
|
||||
from the driver code, or else bad things shall happen. Maybe. Probably not, but don't
|
||||
do it(yet)!
|
||||
*/
|
||||
// Short system name, lowercase a-z, 0-9, and _ are the only allowable characters!
|
||||
const char *shortname;
|
||||
|
||||
// Full system name. Preferably English letters, but can be UTF8
|
||||
const char *fullname;
|
||||
|
||||
// Pointer to an array of FileExtensionSpecStruct, with the last entry being { NULL, NULL } to terminate the list.
|
||||
// This list is used to make best-guess choices, when calling the TestMagic*() functions would be unreasonable, such
|
||||
// as when scanning a ZIP archive for a file to load. The list may also be used in the future for GUI file open windows.
|
||||
const FileExtensionSpecStruct *FileExtensions;
|
||||
|
||||
ModPrio ModulePriority;
|
||||
|
||||
void *Debugger;
|
||||
InputInfoStruct *InputInfo;
|
||||
|
||||
// Returns 1 on successful load, 0 on fatal error(deprecated: -1 on unrecognized format)
|
||||
int (*Load)(const char *name, MDFNFILE *fp);
|
||||
|
||||
// Return TRUE if the file is a recognized type, FALSE if not.
|
||||
bool (*TestMagic)(const char *name, MDFNFILE *fp);
|
||||
|
||||
//
|
||||
// (*CDInterfaces).size() is guaranteed to be >= 1.
|
||||
int (*LoadCD)(std::vector<CDIF *> *CDInterfaces);
|
||||
bool (*TestMagicCD)(std::vector<CDIF *> *CDInterfaces);
|
||||
|
||||
void (*CloseGame)(void);
|
||||
|
||||
void (*SetLayerEnableMask)(uint64 mask); // Video
|
||||
const char *LayerNames;
|
||||
|
||||
void (*SetChanEnableMask)(uint64 mask); // Audio(TODO, placeholder)
|
||||
const char *ChanNames;
|
||||
|
||||
void (*InstallReadPatch)(uint32 address);
|
||||
void (*RemoveReadPatches)(void);
|
||||
uint8 (*MemRead)(uint32 addr);
|
||||
|
||||
#ifdef WANT_NEW_API
|
||||
CheatFormatInfoStruct *CheatFormatInfo;
|
||||
#endif
|
||||
|
||||
bool SaveStateAltersState; // true for bsnes and some libco-style emulators, false otherwise.
|
||||
// Main save state routine, called by the save state code in state.cpp.
|
||||
// When saving, load is set to 0. When loading, load is set to the version field of the save state being loaded.
|
||||
// data_only is true when the save state data is temporary, such as being saved into memory for state rewinding.
|
||||
int (*StateAction)(StateMem *sm, int load, int data_only);
|
||||
|
||||
void (*Emulate)(EmulateSpecStruct *espec);
|
||||
void (*SetInput)(int port, const char *type, void *ptr);
|
||||
|
||||
void (*DoSimpleCommand)(int cmd);
|
||||
|
||||
const MDFNSetting *Settings;
|
||||
|
||||
// Time base for EmulateSpecStruct::MasterCycles
|
||||
#define MDFN_MASTERCLOCK_FIXED(n) ((int64)((double)(n) * (1LL << 32)))
|
||||
int64 MasterClock;
|
||||
|
||||
uint32 fps; // frames per second * 65536 * 256, truncated
|
||||
@ -374,8 +317,6 @@ typedef struct
|
||||
|
||||
int rotated;
|
||||
|
||||
uint8 *name; /* Game name, UTF8 encoding */
|
||||
|
||||
int soundrate; /* For Ogg Vorbis expansion sound wacky support. 0 for default. */
|
||||
|
||||
VideoSystems VideoSystem;
|
||||
@ -390,4 +331,7 @@ typedef struct
|
||||
|
||||
double mouse_sensitivity;
|
||||
} MDFNGI;
|
||||
|
||||
int StateAction(StateMem *sm, int load, int data_only);
|
||||
|
||||
#endif
|
||||
|
@ -1,478 +0,0 @@
|
||||
//
|
||||
// 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 "system.h"
|
||||
|
||||
#include "../general.h"
|
||||
#include "../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_LNX;
|
||||
|
||||
if(filesize < 11)
|
||||
{
|
||||
/* Lynx ROM image is too short. */
|
||||
return;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
/* File format is unknown to module. */
|
||||
return;
|
||||
}
|
||||
|
||||
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_LNX:
|
||||
mCart = new CCart(filememory,filesize);
|
||||
mRam = new CRam(0,0);
|
||||
break;
|
||||
case HANDY_FILETYPE_HOMEBREW:
|
||||
{
|
||||
#if 0
|
||||
static uint8 dummy_cart[CCart::HEADER_RAW_SIZE + 65536] =
|
||||
{
|
||||
'L', 'Y', 'N', 'X', 0x00, 0x01, 0x00, 0x00,
|
||||
0x01, 0x00,
|
||||
};
|
||||
mCart = new CCart(dummy_cart, sizeof(dummy_cart));
|
||||
#else
|
||||
mCart = new CCart(NULL, 0);
|
||||
#endif
|
||||
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)
|
||||
{
|
||||
return(CCart::TestMagic(fp->data, fp->size));
|
||||
}
|
||||
|
||||
static int Load(const char *name, MDFNFILE *fp)
|
||||
{
|
||||
lynxie = new CSystem(GET_FDATA_PTR(fp), GET_FSIZE_PTR(fp));
|
||||
|
||||
int rot = lynxie->CartGetRotate();
|
||||
if(rot == CART_ROTATE_LEFT) MDFNGameInfo->rotated = MDFN_ROTATE270;
|
||||
else if(rot == CART_ROTATE_RIGHT) MDFNGameInfo->rotated = MDFN_ROTATE90;
|
||||
|
||||
gAudioEnabled = 1;
|
||||
|
||||
MDFN_printf(_("ROM: %dKiB\n"), (lynxie->mCart->InfoROMSize + 1023) / 1024);
|
||||
MDFN_printf(_("ROM CRC32: 0x%08x\n"), lynxie->mCart->CRC32());
|
||||
|
||||
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 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
|
||||
};
|
||||
std::vector <SSDescriptor> love;
|
||||
|
||||
love.push_back(SSDescriptor(SystemRegs, "SYST"));
|
||||
MDFNSS_StateAction(sm, load, data_only, love);
|
||||
|
||||
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, gettext_noop("Virtually rotate D-pad along with screen."), NULL, MDFNST_BOOL, "1" },
|
||||
{ "lynx.lowpass", MDFNSF_CAT_SOUND, gettext_noop("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", gettext_noop("Atari Lynx ROM Image") },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
MDFNGI EmulatedLynx =
|
||||
{
|
||||
"lynx",
|
||||
"Atari Lynx",
|
||||
KnownExtensions,
|
||||
MODPRIO_INTERNAL_HIGH,
|
||||
NULL,
|
||||
&InputInfo,
|
||||
Load,
|
||||
TestMagic,
|
||||
NULL,
|
||||
NULL,
|
||||
CloseGame,
|
||||
SetLayerEnableMask,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
false,
|
||||
StateAction,
|
||||
Emulate,
|
||||
SetInput,
|
||||
DoSimpleCommand,
|
||||
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
|
||||
};
|
||||
|
@ -34,219 +34,3 @@
|
||||
#ifdef _MSC_VER
|
||||
#include "msvc_compat.h"
|
||||
#endif
|
||||
|
||||
extern MDFNGI EmulatedLynx;
|
||||
MDFNGI *MDFNGameInfo = &EmulatedLynx;
|
||||
|
||||
/* forward declarations */
|
||||
extern void MDFND_DispMessage(unsigned char *str);
|
||||
|
||||
void MDFN_DispMessage(const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap,format);
|
||||
char *msg = new char[4096];
|
||||
|
||||
vsnprintf(msg, 4096, format,ap);
|
||||
va_end(ap);
|
||||
|
||||
MDFND_DispMessage((UTF8*)msg);
|
||||
}
|
||||
|
||||
void MDFN_ResetMessages(void)
|
||||
{
|
||||
MDFND_DispMessage(NULL);
|
||||
}
|
||||
|
||||
|
||||
MDFNGI *MDFNI_LoadGame(const char *force_module, const char *name)
|
||||
{
|
||||
std::vector<FileExtensionSpecStruct> valid_iae;
|
||||
MDFNGameInfo = &EmulatedLynx;
|
||||
MDFNFILE *GameFile = NULL;
|
||||
|
||||
MDFN_printf(_("Loading %s...\n"),name);
|
||||
|
||||
MDFN_indent(1);
|
||||
|
||||
// Construct a NULL-delimited list of known file extensions for MDFN_fopen()
|
||||
const FileExtensionSpecStruct *curexts = MDFNGameInfo->FileExtensions;
|
||||
|
||||
while(curexts->extension && curexts->description)
|
||||
{
|
||||
valid_iae.push_back(*curexts);
|
||||
curexts++;
|
||||
}
|
||||
|
||||
GameFile = file_open(name);
|
||||
|
||||
if(!GameFile)
|
||||
goto error;
|
||||
|
||||
MDFN_printf(_("Using module: %s(%s)\n\n"), MDFNGameInfo->shortname, MDFNGameInfo->fullname);
|
||||
MDFN_indent(1);
|
||||
|
||||
//
|
||||
// Load per-game settings
|
||||
//
|
||||
// Maybe we should make a "pgcfg" subdir, and automatically load all files in it?
|
||||
// End load per-game settings
|
||||
//
|
||||
|
||||
if(MDFNGameInfo->Load(name, GameFile) <= 0)
|
||||
goto error;
|
||||
|
||||
MDFN_LoadGameCheats(NULL);
|
||||
MDFNMP_InstallReadPatches();
|
||||
|
||||
MDFN_ResetMessages(); // Save state, status messages, etc.
|
||||
|
||||
MDFN_indent(-2);
|
||||
|
||||
if(!MDFNGameInfo->name)
|
||||
{
|
||||
unsigned int x;
|
||||
char *tmp;
|
||||
|
||||
MDFNGameInfo->name = (UTF8 *)strdup(GetFNComponent(name));
|
||||
|
||||
for(x=0;x<strlen((char *)MDFNGameInfo->name);x++)
|
||||
{
|
||||
if(MDFNGameInfo->name[x] == '_')
|
||||
MDFNGameInfo->name[x] = ' ';
|
||||
}
|
||||
if((tmp = strrchr((char *)MDFNGameInfo->name, '.')))
|
||||
*tmp = 0;
|
||||
}
|
||||
|
||||
return(MDFNGameInfo);
|
||||
|
||||
error:
|
||||
if (GameFile)
|
||||
file_close(GameFile);
|
||||
MDFN_indent(-2);
|
||||
MDFNGameInfo = NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void MDFNI_CloseGame(void)
|
||||
{
|
||||
if(!MDFNGameInfo)
|
||||
return;
|
||||
|
||||
MDFN_FlushGameCheats(0);
|
||||
|
||||
MDFNGameInfo->CloseGame();
|
||||
|
||||
if(MDFNGameInfo->name)
|
||||
free(MDFNGameInfo->name);
|
||||
MDFNGameInfo->name = NULL;
|
||||
|
||||
MDFNMP_Kill();
|
||||
|
||||
MDFNGameInfo = NULL;
|
||||
}
|
||||
|
||||
bool MDFNI_InitializeModule(void)
|
||||
{
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
int MDFNI_Initialize(const char *basedir)
|
||||
{
|
||||
return(1);
|
||||
}
|
||||
|
||||
static int curindent = 0;
|
||||
|
||||
void MDFN_indent(int indent)
|
||||
{
|
||||
curindent += indent;
|
||||
}
|
||||
|
||||
static uint8 lastchar = 0;
|
||||
|
||||
void MDFN_printf(const char *format, ...)
|
||||
{
|
||||
char *format_temp;
|
||||
char *temp;
|
||||
unsigned int x, newlen;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap,format);
|
||||
|
||||
|
||||
// First, determine how large our format_temp buffer needs to be.
|
||||
uint8 lastchar_backup = lastchar; // Save lastchar!
|
||||
for(newlen=x=0;x<strlen(format);x++)
|
||||
{
|
||||
if(lastchar == '\n' && format[x] != '\n')
|
||||
{
|
||||
int y;
|
||||
for(y=0;y<curindent;y++)
|
||||
newlen++;
|
||||
}
|
||||
newlen++;
|
||||
lastchar = format[x];
|
||||
}
|
||||
|
||||
format_temp = (char *)malloc(newlen + 1); // Length + NULL character, duh
|
||||
|
||||
// Now, construct our format_temp string
|
||||
lastchar = lastchar_backup; // Restore lastchar
|
||||
for(newlen=x=0;x<strlen(format);x++)
|
||||
{
|
||||
if(lastchar == '\n' && format[x] != '\n')
|
||||
{
|
||||
int y;
|
||||
for(y=0;y<curindent;y++)
|
||||
format_temp[newlen++] = ' ';
|
||||
}
|
||||
format_temp[newlen++] = format[x];
|
||||
lastchar = format[x];
|
||||
}
|
||||
|
||||
format_temp[newlen] = 0;
|
||||
|
||||
temp = new char[4096];
|
||||
vsnprintf(temp, 4096, format_temp, ap);
|
||||
free(format_temp);
|
||||
|
||||
MDFND_Message(temp);
|
||||
free(temp);
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void MDFN_PrintError(const char *format, ...)
|
||||
{
|
||||
char *temp;
|
||||
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
|
||||
temp = new char[4096];
|
||||
vsnprintf(temp, 4096, format, ap);
|
||||
MDFND_PrintError(temp);
|
||||
free(temp);
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void MDFN_DebugPrintReal(const char *file, const int line, const char *format, ...)
|
||||
{
|
||||
char *temp;
|
||||
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
|
||||
temp = new char[4096];
|
||||
vsnprintf(temp, 4096, format, ap);
|
||||
fprintf(stderr, "%s:%d %s\n", file, line, temp);
|
||||
free(temp);
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
@ -142,18 +142,22 @@ void MDFNMP_InstallReadPatches(void)
|
||||
|
||||
std::vector<SUBCHEAT>::iterator chit;
|
||||
|
||||
#if 0
|
||||
for(unsigned int x = 0; x < 8; x++)
|
||||
for(chit = SubCheats[x].begin(); chit != SubCheats[x].end(); chit++)
|
||||
{
|
||||
if(MDFNGameInfo->InstallReadPatch)
|
||||
MDFNGameInfo->InstallReadPatch(chit->addr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void MDFNMP_RemoveReadPatches(void)
|
||||
{
|
||||
#if 0
|
||||
if(MDFNGameInfo->RemoveReadPatches)
|
||||
MDFNGameInfo->RemoveReadPatches();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* This function doesn't allocate any memory for "name" */
|
||||
@ -291,6 +295,8 @@ static bool TestConditions(const char *string)
|
||||
v_value = strtoull(value, NULL, 0);
|
||||
|
||||
value_at_address = 0;
|
||||
|
||||
#if 0
|
||||
for(unsigned int x = 0; x < bytelen; x++)
|
||||
{
|
||||
unsigned int shiftie;
|
||||
@ -301,6 +307,7 @@ static bool TestConditions(const char *string)
|
||||
shiftie = x * 8;
|
||||
value_at_address |= MDFNGameInfo->MemRead(v_address + x) << shiftie;
|
||||
}
|
||||
#endif
|
||||
|
||||
//printf("A: %08x, V: %08llx, VA: %08llx, OP: %s\n", v_address, v_value, value_at_address, operation);
|
||||
if(!strcmp(operation, ">="))
|
||||
|
@ -466,7 +466,7 @@ int MDFNSS_SaveSM(void *st_p, int, int, const void*, const void*, const void*)
|
||||
MDFN_en32lsb(header + 28, neoheight);
|
||||
smem_write(st, header, 32);
|
||||
|
||||
if(!MDFNGameInfo->StateAction(st, 0, 0))
|
||||
if(!StateAction(st, 0, 0))
|
||||
return(0);
|
||||
|
||||
uint32_t sizy = st->loc;
|
||||
@ -489,5 +489,5 @@ int MDFNSS_LoadSM(void *st_p, int, int)
|
||||
|
||||
stateversion = MDFN_de32lsb(header + 16);
|
||||
|
||||
return(MDFNGameInfo->StateAction(st, stateversion, 0));
|
||||
return StateAction(st, stateversion, 0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user