Skip to content

Commit

Permalink
Moved external FDC DLL code to Ext1770.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisn committed Dec 31, 2023
1 parent 8c7b08a commit a5254bf
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 74 deletions.
1 change: 1 addition & 0 deletions Src/BeebEm.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
<ClCompile Include="AviWriter.cpp" />
<ClCompile Include="Bcd.cpp" />
<ClCompile Include="BeebMem.cpp" />
<ClCompile Include="Ext1770.cpp" />
<ClCompile Include="Sound.cpp" />
<ClCompile Include="BeebWin.cpp" />
<ClCompile Include="BeebWinDx.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions Src/BeebEm.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@
<ClCompile Include="ExportFileDialog.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Ext1770.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="FileDialog.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
7 changes: 2 additions & 5 deletions Src/BeebWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,6 @@ LEDType LEDs;

LEDColour DiscLedColour = LEDColour::Red;

// FDC Board extension DLL variables
HMODULE hFDCBoard;
EDCB ExtBoard={0,0,NULL};
char FDCDLL[256]={0};

const char *WindowTitle = "BeebEm - BBC Model B / Master 128 Emulator";

/****************************************************************************/
Expand Down Expand Up @@ -3744,8 +3739,10 @@ void BeebWin::HandleCommand(UINT MenuID)
case ID_8271:
KillDLLs();
NativeFDC = true;

CheckMenuItem(ID_8271, true);
CheckMenuItem(ID_FDC_DLL, false);

if (MachineType != Model::Master128)
{
char CfgName[20];
Expand Down
9 changes: 4 additions & 5 deletions Src/BeebWinDx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ Boston, MA 02110-1301, USA.

typedef HRESULT (WINAPI* LPDIRECTDRAWCREATE)(GUID FAR *lpGUID, LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter);

extern HMODULE hFDCBoard;
extern EDCB ExtBoard;

/****************************************************************************/
void BeebWin::InitDX()
{
Expand Down Expand Up @@ -855,11 +852,13 @@ void BeebWin::DisplayClientAreaText(HDC hdc)
/****************************************************************************/
void BeebWin::DisplayFDCBoardInfo(HDC hDC, int x, int y)
{
if (DisplayCycles > 0 && hFDCBoard != NULL)
if (DisplayCycles > 0 && HasFDCBoard())
{
const char* BoardName = GetFDCBoardName();

SetBkMode(hDC, TRANSPARENT);
SetTextColor(hDC, 0x808080);
TextOut(hDC, x, y, ExtBoard.BoardName, (int)strlen(ExtBoard.BoardName));
TextOut(hDC, x, y, BoardName, (int)strlen(BoardName));
}
}

Expand Down
92 changes: 38 additions & 54 deletions Src/BeebWinIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,6 @@ using std::max;

using namespace Gdiplus;

extern EDCB ExtBoard;
extern char FDCDLL[256];
extern HMODULE hFDCBoard;

typedef void (*lGetBoardProperties)(struct DriveControlBlock *);
typedef unsigned char (*lSetDriveControl)(unsigned char);
typedef unsigned char (*lGetDriveControl)(unsigned char);
lGetBoardProperties PGetBoardProperties;
lSetDriveControl PSetDriveControl;
lGetDriveControl PGetDriveControl;

/****************************************************************************/

void BeebWin::SetImageName(const char *DiscName, int Drive, DiscType Type)
Expand Down Expand Up @@ -468,8 +457,9 @@ void BeebWin::SelectFDC()
}
else
{
strcpy(FDCDLL,FileName);
strcpy(FDCDLL, FileName);
}

LoadFDC(FDCDLL, true);
}
}
Expand Down Expand Up @@ -1103,80 +1093,74 @@ void BeebWin::LoadFDC(char *DLLName, bool save)
char CfgName[20];
sprintf(CfgName, "FDCDLL%d", static_cast<int>(MachineType));

if (hFDCBoard != nullptr)
{
FreeLibrary(hFDCBoard);
hFDCBoard = nullptr;
}
Ext1770Reset();

NativeFDC = true;

if (DLLName == NULL) {
if (DLLName == nullptr)
{
if (!m_Preferences.GetStringValue(CfgName, FDCDLL))
strcpy(FDCDLL,"None");
strcpy(FDCDLL, "None");
DLLName = FDCDLL;
}

if (strcmp(DLLName, "None")) {
if (strcmp(DLLName, "None") != 0)
{
char path[_MAX_PATH];
strcpy(path, DLLName);
GetDataPath(m_AppPath, path);

hFDCBoard=LoadLibrary(path);
if (hFDCBoard==NULL) {
Ext1770Result Result = Ext1770Init(path);

if (Result == Ext1770Result::Success)
{
NativeFDC = false; // at last, a working DLL!
}
else if (Result == Ext1770Result::LoadFailed)
{
Report(MessageType::Error, "Unable to load FDD Extension Board DLL\nReverting to native 8271");
strcpy(DLLName, "None");
}
else {
PGetBoardProperties=(lGetBoardProperties) GetProcAddress(hFDCBoard,"GetBoardProperties");
PSetDriveControl=(lSetDriveControl) GetProcAddress(hFDCBoard,"SetDriveControl");
PGetDriveControl=(lGetDriveControl) GetProcAddress(hFDCBoard,"GetDriveControl");
if ((PGetBoardProperties==NULL) || (PSetDriveControl==NULL) || (PGetDriveControl==NULL)) {
Report(MessageType::Error, "Invalid FDD Extension Board DLL\nReverting to native 8271");
strcpy(DLLName, "None");
}
else {
PGetBoardProperties(&ExtBoard);
EFDCAddr=ExtBoard.FDCAddress;
EDCAddr=ExtBoard.DCAddress;
NativeFDC = false; // at last, a working DLL!
InvertTR00=ExtBoard.TR00_ActiveHigh;
}
}
else // if (Result == InvalidDLL)
{
Report(MessageType::Error, "Invalid FDD Extension Board DLL\nReverting to native 8271");
strcpy(DLLName, "None");
}
}

if (save)
{
m_Preferences.SetStringValue(CfgName, DLLName);
}

// Set menu options
CheckMenuItem(ID_8271, NativeFDC);
CheckMenuItem(ID_FDC_DLL, !NativeFDC);

DisplayCycles=7000000;
DisplayCycles = 7000000;

if (NativeFDC || MachineType == Model::Master128)
DisplayCycles=0;
DisplayCycles = 0;
}

void BeebWin::KillDLLs()
{
if (hFDCBoard != nullptr)
{
FreeLibrary(hFDCBoard);
hFDCBoard = nullptr;
}
Ext1770Reset();
}

void BeebWin::SetDriveControl(unsigned char value) {
// This takes a value from the mem/io decoder, as written by the cpu, runs it through the
// DLL's translator, then sends it on to the 1770 FDC in master 128 form.
WriteFDCControlReg(PSetDriveControl(value));
void BeebWin::SetDriveControl(unsigned char Value)
{
// This takes a value from the mem/io decoder, as written by the CPU,
// runs it through the DLL's translator, then sends it on to the
// 1770 FDC in Master 128 form.
WriteFDCControlReg(::SetDriveControl(Value));
}

unsigned char BeebWin::GetDriveControl(void) {
// Same as above, but in reverse, i.e. reading
unsigned char temp=ReadFDCControlReg();
unsigned char temp2=PGetDriveControl(temp);
return(temp2);
unsigned char BeebWin::GetDriveControl()
{
// Same as above, but in reverse, i.e., reading.
unsigned char temp = ReadFDCControlReg();
return ::GetDriveControl(temp);
}

/****************************************************************************/
Expand Down
3 changes: 1 addition & 2 deletions Src/Disc1770.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Written by Richard Gellman - Feb 2001
#include "Disc1770.h"
#include "6502core.h"
#include "DiscInfo.h"
#include "Ext1770.h"
#include "FileUtils.h"
#include "Log.h"
#include "Main.h"
Expand Down Expand Up @@ -1265,7 +1266,6 @@ bool CreateADFSImage(const char *FileName, int Tracks) {

void Save1770UEF(FILE *SUEF)
{
extern char FDCDLL[256];
char blank[256];
memset(blank,0,256);

Expand Down Expand Up @@ -1341,7 +1341,6 @@ void Save1770UEF(FILE *SUEF)

void Load1770UEF(FILE *SUEF, int Version)
{
extern char FDCDLL[256];
char FileName[256];
bool Loaded = false;
bool LoadFailed = false;
Expand Down
125 changes: 125 additions & 0 deletions Src/Ext1770.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/****************************************************************
BeebEm - BBC Micro and Master 128 Emulator
Copyright (C) 2001 Richard Gellman
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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
****************************************************************/

#include <windows.h>

#include "Ext1770.h"
#include "BeebMem.h"
#include "Disc1770.h"

/*--------------------------------------------------------------------------*/

struct DriveControlBlock
{
int FDCAddress; // 1770 FDC chip address
int DCAddress; // Drive Control Register Address
const char *BoardName; // FDC Board name
bool TR00_ActiveHigh; // Set true if the TR00 input is Active High
};

// FDC Board extension DLL variables
char FDCDLL[256] = { 0 };

static HMODULE hFDCBoard = nullptr;
static DriveControlBlock ExtBoard = { 0, 0, nullptr };

typedef void (*GetBoardPropertiesFunc)(struct DriveControlBlock *);
typedef unsigned char (*SetDriveControlFunc)(unsigned char);
typedef unsigned char (*GetDriveControlFunc)(unsigned char);

GetBoardPropertiesFunc PGetBoardProperties;
SetDriveControlFunc PSetDriveControl;
GetDriveControlFunc PGetDriveControl;

/*--------------------------------------------------------------------------*/

void Ext1770Reset()
{
if (hFDCBoard != nullptr)
{
FreeLibrary(hFDCBoard);
hFDCBoard = nullptr;
}

PGetBoardProperties = nullptr;
PSetDriveControl = nullptr;
PGetDriveControl = nullptr;
}

/*--------------------------------------------------------------------------*/

Ext1770Result Ext1770Init(const char *FileName)
{
hFDCBoard = LoadLibrary(FileName);

if (hFDCBoard == nullptr)
{
return Ext1770Result::LoadFailed;
}

PGetBoardProperties = (GetBoardPropertiesFunc)GetProcAddress(hFDCBoard, "GetBoardProperties");
PSetDriveControl = (SetDriveControlFunc)GetProcAddress(hFDCBoard, "SetDriveControl");
PGetDriveControl = (GetDriveControlFunc)GetProcAddress(hFDCBoard, "GetDriveControl");

if (PGetBoardProperties == nullptr ||
PSetDriveControl == nullptr ||
PGetDriveControl == nullptr)
{
Ext1770Reset();

return Ext1770Result::InvalidDLL;
}

PGetBoardProperties(&ExtBoard);

EFDCAddr = ExtBoard.FDCAddress;
EDCAddr = ExtBoard.DCAddress;
InvertTR00 = ExtBoard.TR00_ActiveHigh;

return Ext1770Result::Success;
}

/*--------------------------------------------------------------------------*/

bool HasFDCBoard()
{
return hFDCBoard != nullptr;
}

/*--------------------------------------------------------------------------*/

const char* GetFDCBoardName()
{
return ExtBoard.BoardName;
}

/*--------------------------------------------------------------------------*/

unsigned char GetDriveControl(unsigned char Value)
{
return PGetDriveControl(Value);
}

/*--------------------------------------------------------------------------*/

unsigned char SetDriveControl(unsigned char Value)
{
return PSetDriveControl(Value);
}
Loading

0 comments on commit a5254bf

Please sign in to comment.