MSXHawk: Give DLL a C interface, start making core constructor

This commit is contained in:
alyosha-tas 2020-01-09 19:37:59 -05:00
parent 3e0fd4a2d9
commit 2fa22c2505
10 changed files with 94 additions and 137 deletions

View File

@ -406,7 +406,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
I_skip = true;
// for prefetched case, the PC stays on the BUS one cycle longer
if ((src_t == IXCBpre) || (src_t == IXCBpre)) { BUSRQ[0] = PCh; }
if ((src_t == IXCBpre) || (src_t == IYCBpre)) { BUSRQ[0] = PCh; }
break;
case ASGN:

View File

@ -0,0 +1,27 @@
#pragma once
#include <iostream>
#include <cstdint>
#include <iomanip>
#include <string>
#include "Z80A.h"
#include "PSG.h"
#include "VDP.h"
namespace MSXHawk
{
class MSXCore
{
public:
MSXCore()
{
};
VDP vdp;
Z80A cpu;
SN76489sms psg;
};
}

View File

@ -1,22 +1,15 @@
// MSXHawk.cpp : Defines the exported functions for the DLL.
//
#include "pch.h"
#include "framework.h"
#include "MSXHawk.h"
#include "Core.h"
using namespace MSXHawk;
// This is an example of an exported variable
MSXHAWK_API int nMSXHawk=0;
MSXHAWK_EXPORT int nMSXHawk=0;
// This is an example of an exported function.
MSXHAWK_API int fnMSXHawk(void)
{
return 0;
}
// This is the constructor of a class that has been exported.
CMSXHawk::CMSXHawk()
{
return;
}
MSXHAWK_EXPORT MSXCore* MSX_create() {
return new MSXCore();
}

View File

@ -1,22 +1,5 @@
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the MSXHAWK_EXPORTS
// symbol defined on the command line. This symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// MSXHAWK_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef MSXHAWK_EXPORTS
#define MSXHAWK_API __declspec(dllexport)
#else
#define MSXHAWK_API __declspec(dllimport)
#ifdef _WIN32
#define MSXHAWK_EXPORT extern "C" __declspec(dllexport)
#elif __linux__
#define MSXHAWK_EXPORT extern "C"
#endif
// This class is exported from the dll
class MSXHAWK_API CMSXHawk {
public:
CMSXHawk(void);
// TODO: add your methods here.
};
extern MSXHAWK_API int nMSXHawk;
MSXHAWK_API int fnMSXHawk(void);

View File

@ -137,7 +137,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
@ -158,22 +158,14 @@
<None Include="cpp.hint" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="framework.h" />
<ClInclude Include="Core.h" />
<ClInclude Include="VDP.h" />
<ClInclude Include="PSG.h" />
<ClInclude Include="Z80A.h" />
<ClInclude Include="MSXHawk.h" />
<ClInclude Include="pch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="MSXHawk.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -57,23 +57,23 @@ namespace MSXHawk
int FrameHeight = 192;
int ScanLine;
uint8_t HCounter = 0x90;
int FrameBuffer[256 * 240];
int FrameBuffer[256 * 244];
int GameGearFrameBuffer[160 * 144];
int OverscanFrameBuffer[1];
bool Mode1Bit() { return (Registers[1] & 16) > 0; }
bool Mode2Bit() {return (Registers[0] & 2) > 0; }
bool Mode3Bit() {return (Registers[1] & 8) > 0; }
bool Mode4Bit() {return (Registers[0] & 4) > 0; }
bool ShiftSpritesLeft8Pixels() { return (Registers[0] & 8) > 0; }
bool EnableLineInterrupts() { return (Registers[0] & 16) > 0; }
bool LeftBlanking() { return (Registers[0] & 32) > 0; }
bool HorizScrollLock() { return (Registers[0] & 64) > 0; }
bool VerticalScrollLock() { return (Registers[0] & 128) > 0; }
bool EnableDoubledSprites() { return (Registers[1] & 1) > 0; }
bool EnableLargeSprites() { return (Registers[1] & 2) > 0; }
bool EnableFrameInterrupts() { return (Registers[1] & 32) > 0; }
bool DisplayOn() { return (Registers[1] & 64) > 0; }
inline bool Mode1Bit() { return (Registers[1] & 16) > 0; }
inline bool Mode2Bit() {return (Registers[0] & 2) > 0; }
inline bool Mode3Bit() {return (Registers[1] & 8) > 0; }
inline bool Mode4Bit() {return (Registers[0] & 4) > 0; }
inline bool ShiftSpritesLeft8Pixels() { return (Registers[0] & 8) > 0; }
inline bool EnableLineInterrupts() { return (Registers[0] & 16) > 0; }
inline bool LeftBlanking() { return (Registers[0] & 32) > 0; }
inline bool HorizScrollLock() { return (Registers[0] & 64) > 0; }
inline bool VerticalScrollLock() { return (Registers[0] & 128) > 0; }
inline bool EnableDoubledSprites() { return (Registers[1] & 1) > 0; }
inline bool EnableLargeSprites() { return (Registers[1] & 2) > 0; }
inline bool EnableFrameInterrupts() { return (Registers[1] & 32) > 0; }
inline bool DisplayOn() { return (Registers[1] & 64) > 0; }
int SpriteAttributeTableBase() { return ((Registers[5] >> 1) << 8) & 0x3FFF; }
int SpriteTileBase() { return (Registers[6] & 4) > 0 ? 256 : 0; }
uint8_t BackdropColor() { return (uint8_t)(16 + (Registers[7] & 15)); }
@ -95,11 +95,11 @@ namespace MSXHawk
const uint8_t SMSPalXlatTable[4] = { 0, 85, 170, 255 };
const uint8_t GGPalXlatTable[16] = { 0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255 };
VDP(int vdp_mode, int displayType)
VDP()
{
mode = vdp_mode;
mode = MODE_GG;
DisplayType = displayType;
DisplayType = DISP_TYPE_NTSC;
NameTableBase = CalcNameTableBase();
}
@ -172,8 +172,7 @@ namespace MSXHawk
break;
case 0x80: // VDP register write
VdpCommand = Command_RegisterWrite;
int reg = value & 0x0F;
WriteRegister(reg, VdpLatch);
WriteRegister(value & 0x0F, VdpLatch);
break;
case 0xC0: // write CRAM / modify palette
VdpCommand = Command_CramWrite;
@ -241,15 +240,15 @@ namespace MSXHawk
void CheckVideoMode()
{
if (Mode4Bit == false) // check old TMS modes
if (Mode4Bit() == false) // check old TMS modes
{
if (Mode1Bit) TmsMode = 1;
else if (Mode2Bit) TmsMode = 2;
else if (Mode3Bit) TmsMode = 3;
if (Mode1Bit()) TmsMode = 1;
else if (Mode2Bit()) TmsMode = 2;
else if (Mode3Bit()) TmsMode = 3;
else TmsMode = 0;
}
else if (Mode4Bit && Mode2Bit) // if Mode4 and Mode2 set, then check extension modes
else if (Mode4Bit() && Mode2Bit()) // if Mode4 and Mode2 set, then check extension modes
{
TmsMode = 4;
switch (Registers[1] & 0x18)
@ -298,13 +297,13 @@ namespace MSXHawk
{
case 0: // Mode Control Register 1
CheckVideoMode();
INT_FLAG[0] = (EnableLineInterrupts && HIntPending);
INT_FLAG[0] |= (EnableFrameInterrupts && VIntPending);
INT_FLAG[0] = (EnableLineInterrupts() && HIntPending);
INT_FLAG[0] |= (EnableFrameInterrupts() && VIntPending);
break;
case 1: // Mode Control Register 2
CheckVideoMode();
INT_FLAG[0] = (EnableFrameInterrupts && VIntPending);
INT_FLAG[0] |= (EnableLineInterrupts && HIntPending);
INT_FLAG[0] = (EnableFrameInterrupts() && VIntPending);
INT_FLAG[0] |= (EnableLineInterrupts() && HIntPending);
break;
case 2: // Name Table Base Address
NameTableBase = CalcNameTableBase();
@ -352,7 +351,7 @@ namespace MSXHawk
VIntPending = true;
}
if (VIntPending && EnableFrameInterrupts)
if (VIntPending && EnableFrameInterrupts())
{
INT_FLAG[0] = true;
}
@ -366,7 +365,7 @@ namespace MSXHawk
if (lineIntLinesRemaining-- <= 0)
{
HIntPending = true;
if (EnableLineInterrupts)
if (EnableLineInterrupts())
{
INT_FLAG[0] = true;
}
@ -386,7 +385,7 @@ namespace MSXHawk
if (render)
RenderBackgroundCurrentLine(SHOW_BG);
if (EnableDoubledSprites)
if (EnableDoubledSprites())
RenderSpritesCurrentLineDoubleSize(SHOW_SPRITES & render);
else
RenderSpritesCurrentLine(SHOW_SPRITES & render);
@ -454,7 +453,7 @@ namespace MSXHawk
if (ScanLine >= FrameHeight)
return;
if (DisplayOn == false)
if (DisplayOn() == false)
{
for (int x = 0; x < 256; x++)
FrameBuffer[(ScanLine * 256) + x] = Palette[BackdropColor()];
@ -480,13 +479,13 @@ namespace MSXHawk
if (vertOffset >= 256)
vertOffset -= 256;
}
uint8_t horzOffset = (HorizScrollLock && ScanLine < 16) ? (uint8_t)0 : Registers[8];
uint8_t horzOffset = (HorizScrollLock() && ScanLine < 16) ? (uint8_t)0 : Registers[8];
int yTile = vertOffset / 8;
for (int xTile = 0; xTile < 32; xTile++)
{
if (xTile == 24 && VerticalScrollLock)
if (xTile == 24 && VerticalScrollLock())
{
vertOffset = ScanLine;
yTile = vertOffset / 8;
@ -558,7 +557,7 @@ namespace MSXHawk
bool collisionHappens = true;
bool renderHappens = show;
if (!DisplayOn)
if (!DisplayOn())
{
renderHappens = false;
collisionHappens = false;
@ -570,7 +569,7 @@ namespace MSXHawk
}
int SpriteBase = SpriteAttributeTableBase();
int SpriteHeight = EnableLargeSprites ? 16 : 8;
int SpriteHeight = EnableLargeSprites() ? 16 : 8;
// Clear the sprite collision buffer for this scanline
for (int i = 0; i < 256; i++)
@ -583,13 +582,13 @@ namespace MSXHawk
for (int i = 0; i < 64; i++)
{
int x = VRAM[SpriteBase + 0x80 + (i * 2)];
if (ShiftSpritesLeft8Pixels)
if (ShiftSpritesLeft8Pixels())
x -= 8;
int y = VRAM[SpriteBase + i] + 1;
if (y == 209 && FrameHeight == 192)
break; // 208 is special terminator sprite (in 192-line mode)
if (y >= (EnableLargeSprites ? 240 : 248))
if (y >= (EnableLargeSprites() ? 240 : 248))
y -= 256;
if (y + SpriteHeight <= ScanLine || y > ScanLine)
@ -605,7 +604,7 @@ namespace MSXHawk
}
int tileNo = VRAM[SpriteBase + 0x80 + (i * 2) + 1];
if (EnableLargeSprites)
if (EnableLargeSprites())
tileNo &= 0xFE;
tileNo += SpriteTileBase();
@ -638,7 +637,7 @@ namespace MSXHawk
bool collisionHappens = true;
bool renderHappens = show;
if (!DisplayOn)
if (!DisplayOn())
{
renderHappens = false;
collisionHappens = false;
@ -650,7 +649,7 @@ namespace MSXHawk
}
int SpriteBase = SpriteAttributeTableBase();
int SpriteHeight = EnableLargeSprites ? 16 : 8;
int SpriteHeight = EnableLargeSprites() ? 16 : 8;
// Clear the sprite collision buffer for this scanline
for (int i = 0; i < 256; i++)
@ -663,13 +662,13 @@ namespace MSXHawk
for (int i = 0; i < 64; i++)
{
int x = VRAM[SpriteBase + 0x80 + (i * 2)];
if (ShiftSpritesLeft8Pixels)
if (ShiftSpritesLeft8Pixels())
x -= 8;
int y = VRAM[SpriteBase + i] + 1;
if (y == 209 && FrameHeight == 192)
break; // terminator sprite
if (y >= (EnableLargeSprites ? 240 : 248))
if (y >= (EnableLargeSprites() ? 240 : 248))
y -= 256;
if (y + (SpriteHeight * 2) <= ScanLine || y > ScanLine)
@ -685,7 +684,7 @@ namespace MSXHawk
}
int tileNo = VRAM[SpriteBase + 0x80 + (i * 2) + 1];
if (EnableLargeSprites)
if (EnableLargeSprites())
tileNo &= 0xFE;
tileNo += SpriteTileBase();
@ -715,7 +714,7 @@ namespace MSXHawk
// Renders left-blanking. Should be done per scanline, not per-frame.
void RenderLineBlanking(bool render)
{
if (!LeftBlanking || ScanLine >= FrameHeight || !render)
if (!LeftBlanking() || ScanLine >= FrameHeight || !render)
return;
int ofs = ScanLine * 256;
@ -870,7 +869,7 @@ namespace MSXHawk
if (ScanLine >= FrameHeight)
return;
if (DisplayOn == false)
if (DisplayOn() == false)
{
for (int i = ScanLine * 256; i < (ScanLine * 256 + 256); i++)
{
@ -911,7 +910,7 @@ namespace MSXHawk
if (ScanLine >= FrameHeight)
return;
if (DisplayOn == false)
if (DisplayOn() == false)
{
for (int i = ScanLine * 256; i < (ScanLine * 256 + 256); i++)
{
@ -951,10 +950,10 @@ namespace MSXHawk
void RenderTmsSprites(bool show)
{
if (ScanLine >= FrameHeight || DisplayOn == false)
if (ScanLine >= FrameHeight || DisplayOn() == false)
return;
if (EnableDoubledSprites == false)
if (EnableDoubledSprites() == false)
RenderTmsSpritesStandard(show);
else
RenderTmsSpritesDouble(show);
@ -971,7 +970,7 @@ namespace MSXHawk
SpriteCollisionBuffer[i] = 0;
}
bool LargeSprites = EnableLargeSprites;
bool LargeSprites = EnableLargeSprites();
int SpriteSize = 8;
if (LargeSprites) SpriteSize *= 2;
@ -1043,7 +1042,7 @@ namespace MSXHawk
SpriteCollisionBuffer[i] = 0;
}
bool LargeSprites = EnableLargeSprites;
bool LargeSprites = EnableLargeSprites();
int SpriteSize = 8;
if (LargeSprites) SpriteSize *= 2;

View File

@ -47,7 +47,7 @@ namespace MSXHawk
// non-state variables
int Ztemp1, Ztemp2, Ztemp3, Ztemp4;
int Reg16_d, Reg16_s, ans, temp, carry;
int Reg16_d, Reg16_s, ans, temp, carry, dest_t, src_t;
inline bool FlagCget() { return (Regs[5] & 0x01) != 0; };
@ -489,7 +489,7 @@ namespace MSXHawk
EXCH_16_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++], cur_instr[instr_pntr++], cur_instr[instr_pntr++]);
break;
case PREFIX:
int src_t = PRE_SRC;
src_t = PRE_SRC;
NO_prefix = false;
if (PRE_SRC == CBpre) { CB_prefix = true; }
@ -515,7 +515,7 @@ namespace MSXHawk
I_skip = true;
// for prefetched case, the PC stays on the BUS one cycle longer
if ((src_t == IXCBpre) || (src_t == IXCBpre)) { BUSRQ[0] = PCh; }
if ((src_t == IXCBpre) || (src_t == IYCBpre)) { BUSRQ[0] = PCh; }
break;
case ASGN:
@ -618,7 +618,7 @@ namespace MSXHawk
}
break;
case SET_FL_IR:
int dest_t = cur_instr[instr_pntr++];
dest_t = cur_instr[instr_pntr++];
TR_Func(dest_t, cur_instr[instr_pntr++]);
SET_FL_IR_Func(dest_t);
break;

View File

@ -1,19 +0,0 @@
// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}

View File

@ -1,5 +0,0 @@
#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files
#include <windows.h>

View File

@ -1,13 +0,0 @@
// pch.h: This is a precompiled header file.
// Files listed below are compiled only once, improving build performance for future builds.
// This also affects IntelliSense performance, including code completion and many code browsing features.
// However, files listed here are ALL re-compiled if any one of them is updated between builds.
// Do not add files here that you will be updating frequently as this negates the performance advantage.
#ifndef PCH_H
#define PCH_H
// add headers that you want to pre-compile here
#include "framework.h"
#endif //PCH_H