Disabled PlusROM for now, until we find more time to work on it.

This commit is contained in:
Stephen Anthony 2020-12-19 18:35:16 -03:30
parent a891f5cb33
commit e837e1f94c
3 changed files with 63 additions and 26 deletions

View File

@ -56,10 +56,12 @@ CartridgeEnhanced::CartridgeEnhanced(const ByteBuffer& image, size_t size,
// space will be filled with 0's from above // space will be filled with 0's from above
std::copy_n(image.get(), std::min(mySize, size), myImage.get()); std::copy_n(image.get(), std::min(mySize, size), myImage.get());
#if 0
// Determine whether we have a PlusROM cart // Determine whether we have a PlusROM cart
// PlusROM needs to call peek() method, so disable direct peeks // PlusROM needs to call peek() method, so disable direct peeks
if(myPlusROM.initialize(myImage, mySize)) if(myPlusROM.initialize(myImage, mySize))
myDirectPeek = false; myDirectPeek = false;
#endif
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -147,6 +149,7 @@ uInt8 CartridgeEnhanced::peek(uInt16 address)
{ {
const uInt16 peekAddress = address; const uInt16 peekAddress = address;
#if 0
// Is this a PlusROM? // Is this a PlusROM?
if(myPlusROM.isValid()) if(myPlusROM.isValid())
{ {
@ -154,6 +157,7 @@ uInt8 CartridgeEnhanced::peek(uInt16 address)
if(myPlusROM.peekHotspot(address, value)) if(myPlusROM.peekHotspot(address, value))
return value; return value;
} }
#endif
// hotspots in TIA range are reacting to pokes only // hotspots in TIA range are reacting to pokes only
if (hotspot() >= 0x80) if (hotspot() >= 0x80)
@ -184,9 +188,11 @@ uInt8 CartridgeEnhanced::peek(uInt16 address)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool CartridgeEnhanced::poke(uInt16 address, uInt8 value) bool CartridgeEnhanced::poke(uInt16 address, uInt8 value)
{ {
#if 0
// Is this a PlusROM? // Is this a PlusROM?
if(myPlusROM.isValid() && myPlusROM.pokeHotspot(address, value)) if(myPlusROM.isValid() && myPlusROM.pokeHotspot(address, value))
return true; return true;
#endif
// Switch banks if necessary // Switch banks if necessary
if (checkSwitchBank(address & ADDR_MASK, value)) if (checkSwitchBank(address & ADDR_MASK, value))
@ -380,8 +386,10 @@ bool CartridgeEnhanced::save(Serializer& out) const
out.putIntArray(myCurrentSegOffset.get(), myBankSegs); out.putIntArray(myCurrentSegOffset.get(), myBankSegs);
if(myRamSize > 0) if(myRamSize > 0)
out.putByteArray(myRAM.get(), myRamSize); out.putByteArray(myRAM.get(), myRamSize);
if(myPlusROM.isValid()) #if 0
if(!myPlusROM.save(out)) return false; if(myPlusROM.isValid() && !myPlusROM.save(out))
return false;
#endif
} }
catch(...) catch(...)
{ {
@ -400,8 +408,10 @@ bool CartridgeEnhanced::load(Serializer& in)
in.getIntArray(myCurrentSegOffset.get(), myBankSegs); in.getIntArray(myCurrentSegOffset.get(), myBankSegs);
if(myRamSize > 0) if(myRamSize > 0)
in.getByteArray(myRAM.get(), myRamSize); in.getByteArray(myRAM.get(), myRamSize);
if(myPlusROM.isValid()) #if 0
if(!myPlusROM.load(in)) return false; if(myPlusROM.isValid() && !myPlusROM.load(in))
return false;
#endif
} }
catch(...) catch(...)
{ {

View File

@ -15,6 +15,9 @@
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================ //============================================================================
#include <regex>
#include "bspf.hxx"
#include "PlusROM.hxx" #include "PlusROM.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -25,36 +28,28 @@ bool PlusROM::initialize(const ByteBuffer& image, size_t size)
if(i >= size) if(i >= size)
return myIsPlusROM = false; // Invalid NMI return myIsPlusROM = false; // Invalid NMI
// Convenience functions to detect valid path and host characters
auto isValidPathChar = [](uInt8 c) {
return ((c > 44 && c < 58) || (c > 64 && c < 91) || (c > 96 && c < 122));
};
auto isValidHostChar = [](uInt8 c) {
return (c == 45 || c == 46 || (c > 47 && c < 58) ||
(c > 64 && c < 91) || (c > 96 && c < 122));
};
// Path stored first, 0-terminated // Path stored first, 0-terminated
while(i < size && isValidPathChar(image[i])) string path;
myPath += static_cast<char>(image[i++]); while(i < size && image[i] != 0)
path += static_cast<char>(image[i++]);
// Did we get a 0-terminated path? // Did we get a valid, 0-terminated path?
if(i >= size || image[i] != 0) if(i >= size || image[i] != 0 || !isValidPath(path))
return myIsPlusROM = false; // Wrong delimiter return myIsPlusROM = false; // Invalid path
i++; // advance past 0 terminator i++; // advance past 0 terminator
// Host stored next, 0-terminated // Host stored next, 0-terminated
while(i < size && isValidHostChar(image[i])) string host;
myHost += static_cast<char>(image[i++]); while(i < size && image[i] != 0)
host += static_cast<char>(image[i++]);
// Did we get a valid, 0-terminated host? // Did we get a valid, 0-terminated host?
if(i >= size || image[i] != 0 || myHost.size() < 3 || myHost.find(".") == string::npos) if(i >= size || image[i] != 0 || !isValidHost(host))
return myIsPlusROM = false; // Wrong delimiter or dotless IP return myIsPlusROM = false; // Invalid host
cerr << "Path: " << myPath << endl;
cerr << "Host: " << myHost << endl;
myURL = "http://" + host + "/" + path;
cerr << "URL: " << myURL << endl;
return myIsPlusROM = true; return myIsPlusROM = true;
} }
@ -120,3 +115,28 @@ bool PlusROM::load(Serializer& in)
return true; return true;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool PlusROM::isValidHost(const string& host) const
{
// TODO: This isn't 100% either, as we're supposed to check for the length
// of each part between '.' in the range 1 .. 63
// Perhaps a better function will be included with whatever network
// library we decide to use
static std::regex rgx(R"(^(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])$)", std::regex_constants::icase);
return std::regex_match(host, rgx);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool PlusROM::isValidPath(const string& path) const
{
// TODO: This isn't 100%
// Perhaps a better function will be included with whatever network
// library we decide to use
for(auto c: path)
if(!((c > 44 && c < 58) || (c > 64 && c < 91) || (c > 96 && c < 122)))
return false;
return true;
}

View File

@ -108,9 +108,16 @@ class PlusROM : public Serializable
*/ */
bool load(Serializer& in) override; bool load(Serializer& in) override;
private:
//////////////////////////////////////////////////////
// These probably belong in the networking library
bool isValidHost(const string& host) const;
bool isValidPath(const string& path) const;
//////////////////////////////////////////////////////
private: private:
bool myIsPlusROM{false}; bool myIsPlusROM{false};
string myPath, myHost; string myURL;
std::array<uInt8, 256> myRxBuffer, myTxBuffer; std::array<uInt8, 256> myRxBuffer, myTxBuffer;