Some cleanups for moviecart code.

- Compiles in Linux now, and without any warnings or errors
 - Converted some code to use that already in Stella
 - Formatting cleanups to match Stella style
This commit is contained in:
Stephen Anthony 2021-04-21 22:13:38 -02:30
parent 8873ffd0b7
commit 9f12d5c16c
6 changed files with 1036 additions and 1163 deletions

View File

@ -704,7 +704,7 @@ bool CartDetector::isProbablyMVC(const ByteBuffer& image, size_t size)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
size_t CartDetector::isProbablyMVC(std::istream &in, size_t maxSize) size_t CartDetector::isProbablyMVC(std::istream &in, size_t maxSize)
{ {
const size_t frameSize = 2 * MVC_FIELD_PAD_SIZE; const size_t frameSize = 2 * CartridgeMVC::MVC_FIELD_PAD_SIZE;
bool found = false; bool found = false;
// Returns size of field if stream is probably an MVC movie cartridge // Returns size of field if stream is probably an MVC movie cartridge

467
src/emucore/CartMVC.cxx Executable file → Normal file
View File

@ -15,10 +15,10 @@
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================ //============================================================================
#include "Serializer.hxx"
#include "System.hxx" #include "System.hxx"
#include "CartMVC.hxx" #include "CartMVC.hxx"
/** /**
Implementation of MovieCart. Implementation of MovieCart.
1K of memory is presented on the bus, but is repeated to fill the 4K image space. 1K of memory is presented on the bus, but is repeated to fill the 4K image space.
@ -29,16 +29,11 @@
@author Rob Bairos @author Rob Bairos
*/ */
#include <string.h>
#include <stdint.h>
#include <fstream>
#include <string>
#define LO_JUMP_BYTE(X) ((X) & 0xff) #define LO_JUMP_BYTE(X) ((X) & 0xff)
#define HI_JUMP_BYTE(X) ((((X) & 0xff00) >> 8) | 0x10) #define HI_JUMP_BYTE(X) ((((X) & 0xff00) >> 8) | 0x10)
#define COLOR_BLUE 0x9A #define COLOR_BLUE 0x9A
#define COLOR_WHITE 0x0E // #define COLOR_WHITE 0x0E
#define OSD_FRAMES 180 #define OSD_FRAMES 180
#define BACK_SECONDS 10 #define BACK_SECONDS 10
@ -46,142 +41,24 @@
#define TITLE_CYCLES 1000000 #define TITLE_CYCLES 1000000
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/** /**
Simulate retrieval 512 byte chunks from a serial source Simulate retrieval 512 byte chunks from a serial source
*/ */
class StreamReader class StreamReader
{ {
public: public:
StreamReader() = default;
StreamReader() bool open(const string& path) {
{ myFile = Serializer(path, Serializer::Mode::ReadOnly);
if(myFile)
myFileSize = myFile.size();
return bool(myFile);
} }
~StreamReader() void swapField(bool index) {
{ if(index)
close();
}
bool open(const std::string& path);
void close();
void swapField(bool index);
bool readField(uint32_t fnum, bool index);
uint8_t
readVersion()
{
return *myVersion++;
}
uint8_t
readFrame()
{
return *myFrame++;
}
uint8_t
readColor()
{
return *myColor++;
}
uint8_t
readGraph()
{
uint8_t v;
if (myGraphOverride)
v = *myGraphOverride++;
else
v = *myGraph++;
return v;
}
void
overrideGraph(const uint8_t* p)
{
myGraphOverride = p;
}
uint8_t
readAudio()
{
return *myAudio++;
}
uint8_t
peekAudio()
{
return *myAudio;
}
void
startTimeCode()
{
myGraph = myTimecode;
}
private:
static int constexpr VERSION_DATA_OFFSET = 0;
static int constexpr FRAME_DATA_OFFSET = 4;
static int constexpr AUDIO_DATA_OFFSET = 7;
static int constexpr GRAPH_DATA_OFFSET = 269;
static int constexpr TIMECODE_DATA_OFFSET = 1229;
static int constexpr COLOR_DATA_OFFSET = 1289;
static int constexpr END_DATA_OFFSET = 2249;
const uint8_t* myAudio{nullptr};
const uint8_t* myGraph{nullptr};
const uint8_t* myGraphOverride{nullptr};
const uint8_t* myTimecode{nullptr};
const uint8_t* myColor{nullptr};
const uint8_t* myVersion{nullptr};
const uint8_t* myFrame{nullptr};
uint8_t myBuffer1[MVC_FIELD_SIZE];
uint8_t myBuffer2[MVC_FIELD_SIZE];
std::ifstream* myFile{nullptr};
size_t myFileSize{0};
};
bool
StreamReader::open(const std::string& path)
{
close();
myFile = new std::ifstream(path, std::ios::binary);
if (!myFile || !*myFile)
close();
myFile->seekg(0, std::ios::end);
myFileSize = static_cast<size_t>(myFile->tellg());
myFile->seekg(0, std::ios::beg);
return myFile ? true:false;
}
void
StreamReader::close()
{
delete myFile;
myFile = nullptr;
}
void
StreamReader::swapField(bool index)
{
if (index == true)
{ {
myVersion = myBuffer1 + VERSION_DATA_OFFSET; myVersion = myBuffer1 + VERSION_DATA_OFFSET;
myFrame = myBuffer1 + FRAME_DATA_OFFSET; myFrame = myBuffer1 + FRAME_DATA_OFFSET;
@ -201,80 +78,95 @@ StreamReader::swapField(bool index)
} }
} }
bool bool readField(uInt32 fnum, bool index) {
StreamReader::readField(uint32_t fnum, bool index)
{
bool read = false;
if(myFile) if(myFile)
{ {
size_t offset = ((fnum + 0) * MVC_FIELD_PAD_SIZE); size_t offset = ((fnum + 0) * CartridgeMVC::MVC_FIELD_PAD_SIZE);
if (offset + MVC_FIELD_PAD_SIZE < myFileSize) if(offset + CartridgeMVC::MVC_FIELD_PAD_SIZE < myFileSize)
{ {
myFile->seekg(offset); myFile.setPosition(offset);
if (index == true) if(index)
myFile->read((char*)myBuffer1, MVC_FIELD_SIZE); myFile.getByteArray(myBuffer1, CartridgeMVC::MVC_FIELD_SIZE);
else else
myFile->read((char*)myBuffer2, MVC_FIELD_SIZE); myFile.getByteArray(myBuffer2, CartridgeMVC::MVC_FIELD_SIZE);
read = true; return true;
} }
} }
return false;
}
return read; uInt8 readVersion() { return *myVersion++; }
uInt8 readFrame() { return *myFrame++; }
uInt8 readColor() { return *myColor++; }
uInt8 readGraph() {
return myGraphOverride ? *myGraphOverride++ : *myGraph++;
} }
void overrideGraph(const uInt8* p) {
myGraphOverride = p;
}
uInt8 readAudio() { return *myAudio++; }
uInt8 peekAudio() const { return *myAudio; }
void startTimeCode() { myGraph = myTimecode; }
private:
static constexpr int
VERSION_DATA_OFFSET = 0,
FRAME_DATA_OFFSET = 4,
AUDIO_DATA_OFFSET = 7,
GRAPH_DATA_OFFSET = 269,
TIMECODE_DATA_OFFSET = 1229,
COLOR_DATA_OFFSET = 1289,
END_DATA_OFFSET = 2249;
const uInt8* myAudio{nullptr};
const uInt8* myGraph{nullptr};
const uInt8* myGraphOverride{nullptr};
const uInt8* myTimecode{nullptr};
const uInt8* myColor{nullptr};
const uInt8* myVersion{nullptr};
const uInt8* myFrame{nullptr};
uInt8 myBuffer1[CartridgeMVC::MVC_FIELD_SIZE];
uInt8 myBuffer2[CartridgeMVC::MVC_FIELD_SIZE];
Serializer myFile;
size_t myFileSize{0};
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/** /**
State of current switches and joystick positions to control MovieCart State of current switches and joystick positions to control MovieCart
*/ */
class MovieInputs class MovieInputs
{ {
public: public:
MovieInputs() = default;
MovieInputs() void init() {
{ bw = fire = select = reset = false;
init(); right = left = up = down = false;
} }
void bool bw{false}, fire{false}, select{false}, reset{false};
init() bool right{false}, left{false}, up{false}, down{false};
{
bw = false;
fire = false;
select = false;
reset = false;
right = false; void updateDirection(uInt8 val) {
left = false;
up = false;
down = false;
}
bool bw;
bool fire;
bool select;
bool reset;
bool right;
bool left;
bool up;
bool down;
void
updateDirection(uint8_t val)
{
right = val & TRANSPORT_RIGHT; right = val & TRANSPORT_RIGHT;
left = val & TRANSPORT_LEFT; left = val & TRANSPORT_LEFT;
up = val & TRANSPORT_UP; up = val & TRANSPORT_UP;
down = val & TRANSPORT_DOWN; down = val & TRANSPORT_DOWN;
} }
void updateTransport(uint8_t val) void updateTransport(uInt8 val) {
{
bw = val & TRANSPORT_BW; bw = val & TRANSPORT_BW;
fire = val & TRANSPORT_BUTTON; fire = val & TRANSPORT_BUTTON;
select = val & TRANSPORT_SELECT; select = val & TRANSPORT_SELECT;
@ -282,82 +174,106 @@ public:
} }
private: private:
static constexpr uInt8
TRANSPORT_RIGHT = 0x10,
TRANSPORT_LEFT = 0x08,
TRANSPORT_DOWN = 0x04,
TRANSPORT_UP = 0x02,
TRANSPORT_UNUSED1 = 0x01; // Right-2
static int constexpr TRANSPORT_RIGHT = 0x10; static constexpr uInt8
static int constexpr TRANSPORT_LEFT = 0x08; TRANSPORT_BW = 0x10,
static int constexpr TRANSPORT_DOWN = 0x04; TRANSPORT_UNUSED2 = 0x08,
static int constexpr TRANSPORT_UP = 0x02; TRANSPORT_SELECT = 0x04,
static int constexpr TRANSPORT_UNUSED1 = 0x01; // Right-2 TRANSPORT_RESET = 0x02,
TRANSPORT_BUTTON = 0x01;
static int constexpr TRANSPORT_BW = 0x10;
static int constexpr TRANSPORT_UNUSED2 = 0x08;
static int constexpr TRANSPORT_SELECT = 0x04;
static int constexpr TRANSPORT_RESET = 0x02;
static int constexpr TRANSPORT_BUTTON = 0x01;
}; };
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/** /**
Various kernel, OSD and scale definitions Various kernel, OSD and scale definitions
@author Rob Bairos @author Rob Bairos
*/ */
#define TIMECODE_HEIGHT 12 #define TIMECODE_HEIGHT 12
#define MAX_LEVEL 11 #define MAX_LEVEL 11
#define DEFAULT_LEVEL 6 #define DEFAULT_LEVEL 6
#define BLANK_LINE_SIZE (28+3+37) // 68 #define BLANK_LINE_SIZE (28+3+37) // 68
#define addr_kernel_48 0x800 // #define addr_kernel_48 0x800
#define addr_transport_buttons 0x880 #define addr_transport_buttons 0x880
#define addr_transport_direction 0x897 #define addr_transport_direction 0x897
#define addr_right_line 0x94c #define addr_right_line 0x94c
#define addr_left_line 0x980 #define addr_left_line 0x980
#define addr_pick_continue 0x9c2 #define addr_pick_continue 0x9c2
#define addr_main_start 0xa00 // #define addr_main_start 0xa00
#define addr_aud_bank_setup 0xa0c // #define addr_aud_bank_setup 0xa0c
#define addr_tg0 0xa24 // #define addr_tg0 0xa24
#define addr_title_again 0xa3b // #define addr_title_again 0xa3b
#define addr_end_lines 0xa80 #define addr_end_lines 0xa80
#define addr_end_lines_audio 0xaa1 #define addr_end_lines_audio 0xaa1
#define addr_set_overscan_size 0xaad #define addr_set_overscan_size 0xaad
#define addr_set_vblank_size 0xac3 #define addr_set_vblank_size 0xac3
#define addr_pick_transport 0xacc #define addr_pick_transport 0xacc
#define addr_last_audio 0xacf #define addr_last_audio 0xacf
#define addr_wait_lines 0xad4 // #define addr_wait_lines 0xad4
#define addr_transport_done1 0xae7 // #define addr_transport_done1 0xae7
#define addr_draw_title 0xb00 // #define addr_draw_title 0xb00
#define addr_title_loop 0xb50 #define addr_title_loop 0xb50
#define addr_black_bar 0xb52 // #define addr_black_bar 0xb52
#define addr_animate_bar1 0xb58 // #define addr_animate_bar1 0xb58
#define addr_animate_bar_again1 0xb5a // #define addr_animate_bar_again1 0xb5a
#define addr_animate_dex1 0xb65 // #define addr_animate_dex1 0xb65
#define addr_audio_bank 0xb80 #define addr_audio_bank 0xb80
#define addr_reset_loop 0xbfa // #define addr_reset_loop 0xbfa
// scale adjustments, automatically generated // scale adjustments, automatically generated
const uint8_t scale0[16] = { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8}; /* 0.0000 */ static constexpr uInt8 scale0[16] = {
const uint8_t scale1[16] = { 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9}; /* 0.1667 */ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 /* 0.0000 */
const uint8_t scale2[16] = { 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10}; /* 0.3333 */ };
const uint8_t scale3[16] = { 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11}; /* 0.5000 */ static constexpr uInt8 scale1[16] = {
const uint8_t scale4[16] = { 3, 3, 4, 5, 5, 6, 7, 7, 8, 9, 9, 10, 11, 11, 12, 13}; /* 0.6667 */ 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9 /* 0.1667 */
const uint8_t scale5[16] = { 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14}; /* 0.8333 */ };
const uint8_t scale6[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; /* 1.0000 */ static constexpr uInt8 scale2[16] = {
const uint8_t scale7[16] = { 0, 0, 0, 1, 3, 4, 5, 7, 8, 10, 11, 12, 14, 15, 15, 15}; /* 1.3611 */ 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10 /* 0.3333 */
const uint8_t scale8[16] = { 0, 0, 0, 0, 1, 3, 5, 7, 8, 10, 12, 14, 15, 15, 15, 15}; /* 1.7778 */ };
const uint8_t scale9[16] = { 0, 0, 0, 0, 0, 2, 4, 6, 9, 11, 13, 15, 15, 15, 15, 15}; /* 2.2500 */ static constexpr uInt8 scale3[16] = {
const uint8_t scale10[16] = { 0, 0, 0, 0, 0, 1, 3, 6, 9, 12, 14, 15, 15, 15, 15, 15}; /* 2.7778 */ 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11 /* 0.5000 */
const uint8_t *scales[11] = {scale0, scale1, scale2, scale3, scale4, scale5, scale6, scale7, scale8, scale9, scale10}; };
static constexpr uInt8 scale4[16] = {
3, 3, 4, 5, 5, 6, 7, 7, 8, 9, 9, 10, 11, 11, 12, 13 /* 0.6667 */
};
static constexpr uInt8 scale5[16] = {
1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14 /* 0.8333 */
};
static constexpr uInt8 scale6[16] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 /* 1.0000 */
};
static constexpr uInt8 scale7[16] = {
0, 0, 0, 1, 3, 4, 5, 7, 8, 10, 11, 12, 14, 15, 15, 15 /* 1.3611 */
};
static constexpr uInt8 scale8[16] = {
0, 0, 0, 0, 1, 3, 5, 7, 8, 10, 12, 14, 15, 15, 15, 15 /* 1.7778 */
};
static constexpr uInt8 scale9[16] = {
0, 0, 0, 0, 0, 2, 4, 6, 9, 11, 13, 15, 15, 15, 15, 15 /* 2.2500 */
};
static constexpr uInt8 scale10[16] = {
0, 0, 0, 0, 0, 1, 3, 6, 9, 12, 14, 15, 15, 15, 15, 15 /* 2.7778 */
};
static const uInt8* scales[11] = {
scale0, scale1, scale2, scale3, scale4, scale5,
scale6, scale7, scale8, scale9, scale10
};
// lower bit is ignored anyways // lower bit is ignored anyways
const uint8_t shiftBright[16 + MAX_LEVEL - 1] = { 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 15, 15, 15, 15}; static constexpr uInt8 shiftBright[16 + MAX_LEVEL - 1] = {
0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 15, 15, 15, 15
};
// Compiled kernel // Compiled kernel
const unsigned char kernelROM[] = static constexpr unsigned char kernelROM[] = {
{
133, 2, 185, 50, 248, 133, 27, 185, 62, 248, 133, 28, 185, 74, 248, 133, 133, 2, 185, 50, 248, 133, 27, 185, 62, 248, 133, 28, 185, 74, 248, 133,
27, 185, 86, 248, 133, 135, 185, 98, 248, 190, 110, 248, 132, 136, 164, 135, 27, 185, 86, 248, 133, 135, 185, 98, 248, 190, 110, 248, 132, 136, 164, 135,
132, 28, 133, 27, 134, 28, 134, 27, 164, 136, 102, 137, 176, 210, 136, 16, 132, 28, 133, 27, 134, 28, 134, 27, 164, 136, 102, 137, 176, 210, 136, 16,
@ -425,9 +341,7 @@ const unsigned char kernelROM[] =
}; };
// OSD labels // OSD labels
static constexpr uInt8 brightLabelEven[] = {
const uint8_t brightLabelEven[] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -442,8 +356,7 @@ const uint8_t brightLabelEven[] =
0, 225, 48, 12, 96, 0, 225, 48, 12, 96,
}; };
const uint8_t brightLabelOdd[] = static constexpr uInt8 brightLabelOdd[] = {
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7, 252, 126, 99, 0, 7, 252, 126, 99, 0,
@ -458,8 +371,7 @@ const uint8_t brightLabelOdd[] =
0, 0, 0, 0, 0 0, 0, 0, 0, 0
}; };
const uint8_t volumeLabelEven[] = static constexpr uInt8 volumeLabelEven[] = {
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -474,8 +386,7 @@ const uint8_t volumeLabelEven[] =
0, 7, 252, 12, 254, 0, 7, 252, 12, 254,
}; };
const uint8_t volumeLabelOdd[] = static constexpr uInt8 volumeLabelOdd[] = {
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
97, 224, 99, 112, 0, 97, 224, 99, 112, 0,
@ -492,9 +403,7 @@ const uint8_t volumeLabelOdd[] =
// Level bars // Level bars
// 8 rows * 5 columns = 40 // 8 rows * 5 columns = 40
static constexpr uInt8 levelBarsEvenData[] = {
const uint8_t levelBarsEvenData[] =
{
/**/ /**/
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3, 239, 191, 253, 247, 3, 239, 191, 253, 247,
@ -594,11 +503,9 @@ const uint8_t levelBarsEvenData[] =
3, 239, 191, 253, 247, 3, 239, 191, 253, 247,
247, 223, 126, 251, 224, 247, 223, 126, 251, 224,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
}; };
const uint8_t levelBarsOddData[] = static constexpr uInt8 levelBarsOddData[] = {
{
/**/ /**/
247, 223, 126, 251, 224, 247, 223, 126, 251, 224,
3, 239, 191, 253, 247, 3, 239, 191, 253, 247,
@ -701,11 +608,8 @@ const uint8_t levelBarsOddData[] =
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
class MovieCart class MovieCart
{ {
public: public:
MovieCart(); MovieCart();
@ -714,14 +618,14 @@ public:
bool init(const std::string& path); bool init(const std::string& path);
bool process(uint16_t address); bool process(uint16_t address);
uint8_t uInt8
readROM(uint16_t address) readROM(uint16_t address)
{ {
return myROM[address & 1023]; return myROM[address & 1023];
} }
void void
writeROM(uint16_t address, uint8_t data) writeROM(uint16_t address, uInt8 data)
{ {
myROM[address & 1023] = data; myROM[address & 1023] = data;
} }
@ -747,7 +651,7 @@ private:
void stopTitleScreen(); void stopTitleScreen();
void writeColor(uint16_t address); void writeColor(uint16_t address);
void writeAudioData(uint16_t address, uint8_t val); void writeAudioData(uint16_t address, uInt8 val);
void writeAudio(uint16_t address); void writeAudio(uint16_t address);
void writeGraph(uint16_t address); void writeGraph(uint16_t address);
@ -765,49 +669,49 @@ private:
// data // data
uint8_t myROM[1024]; uInt8 myROM[1024];
// title screen state // title screen state
int myTitleCycles; int myTitleCycles;
uint8_t myTitleState; uInt8 myTitleState;
// address info // address info
bool myA7; bool myA7;
bool myA10; bool myA10;
uint8_t myA10_Count; uInt8 myA10_Count;
// state machine info // state machine info
uint8_t myState; uInt8 myState;
bool myPlaying; bool myPlaying;
bool myOdd; bool myOdd;
bool myBufferIndex; bool myBufferIndex;
uint8_t myLines; uInt8 myLines;
int32_t myFrameNumber; // signed int32_t myFrameNumber; // signed
uint8_t myMode; uInt8 myMode;
uint8_t myBright; uInt8 myBright;
uint8_t myForceColor; uInt8 myForceColor;
// expressed in frames // expressed in frames
uint8_t myDrawLevelBars; uInt8 myDrawLevelBars;
uint8_t myDrawTimeCode; uInt8 myDrawTimeCode;
MovieInputs myInputs; MovieInputs myInputs;
MovieInputs myLastInputs; MovieInputs myLastInputs;
int8_t mySpeed; // signed int8_t mySpeed; // signed
uint8_t myJoyRepeat; uInt8 myJoyRepeat;
uint8_t myDirectionValue; uInt8 myDirectionValue;
uint8_t myButtonsValue; uInt8 myButtonsValue;
uint8_t myVolume; uInt8 myVolume;
const uint8_t* myVolumeScale; const uInt8* myVolumeScale;
uint8_t myFirstAudioVal; uInt8 myFirstAudioVal;
}; };
@ -874,7 +778,7 @@ MovieCart::stopTitleScreen()
void void
MovieCart::writeColor(uint16_t address) MovieCart::writeColor(uint16_t address)
{ {
uint8_t v = myStream.readColor(); uInt8 v = myStream.readColor();
v = (v & 0xf0) | shiftBright[(v & 0x0f) + myBright]; v = (v & 0xf0) | shiftBright[(v & 0x0f) + myBright];
if (myForceColor) if (myForceColor)
@ -886,9 +790,9 @@ MovieCart::writeColor(uint16_t address)
} }
void void
MovieCart::writeAudioData(uint16_t address, uint8_t val) MovieCart::writeAudioData(uint16_t address, uInt8 val)
{ {
uint8_t v; uInt8 v;
v = myVolumeScale[val]; v = myVolumeScale[val];
writeROM(address, v); writeROM(address, v);
} }
@ -896,14 +800,14 @@ MovieCart::writeAudioData(uint16_t address, uint8_t val)
void void
MovieCart::writeAudio(uint16_t address) MovieCart::writeAudio(uint16_t address)
{ {
uint8_t v = myStream.readAudio(); uInt8 v = myStream.readAudio();
writeAudioData(address, v); writeAudioData(address, v);
} }
void void
MovieCart::writeGraph(uint16_t address) MovieCart::writeGraph(uint16_t address)
{ {
uint8_t v = myStream.readGraph(); uInt8 v = myStream.readGraph();
writeROM(address, v); writeROM(address, v);
} }
@ -917,7 +821,7 @@ MovieCart::updateTransport()
{ {
if (myBufferIndex == true) if (myBufferIndex == true)
{ {
uint8_t temp = ~(myA10_Count & 0x1e) & 0x1e; uInt8 temp = ~(myA10_Count & 0x1e) & 0x1e;
if (temp == myDirectionValue) if (temp == myDirectionValue)
myInputs.updateDirection(temp); myInputs.updateDirection(temp);
@ -926,7 +830,7 @@ MovieCart::updateTransport()
} }
else else
{ {
uint8_t temp = ~(myA10_Count & 0x17) & 0x17; uInt8 temp = ~(myA10_Count & 0x17) & 0x17;
if (temp == myButtonsValue) if (temp == myButtonsValue)
myInputs.updateTransport(temp); myInputs.updateTransport(temp);
@ -943,10 +847,12 @@ MovieCart::updateTransport()
myPlaying = true; myPlaying = true;
myDrawTimeCode = OSD_FRAMES; myDrawTimeCode = OSD_FRAMES;
goto update_stream; // goto update_stream;
myLastInputs = myInputs;
return;
} }
uint8_t lastMainMode = myMode; uInt8 lastMainMode = myMode;
if (myInputs.up && !myLastInputs.up) if (myInputs.up && !myLastInputs.up)
{ {
@ -1025,7 +931,9 @@ MovieCart::updateTransport()
{ {
myDrawTimeCode = OSD_FRAMES; myDrawTimeCode = OSD_FRAMES;
myFrameNumber -= 60 * BACK_SECONDS + 1; myFrameNumber -= 60 * BACK_SECONDS + 1;
goto update_stream; //goto update_stream;
myLastInputs = myInputs;
return;
} }
if (myInputs.fire && !myLastInputs.fire) if (myInputs.fire && !myLastInputs.fire)
@ -1099,10 +1007,7 @@ MovieCart::updateTransport()
mySpeed = 1; mySpeed = 1;
} }
update_stream:
myLastInputs = myInputs; myLastInputs = myInputs;
} }
void void
@ -1191,8 +1096,8 @@ MovieCart::fill_addr_end_lines()
void void
MovieCart::fill_addr_blank_lines() MovieCart::fill_addr_blank_lines()
{ {
uint8_t i; uInt8 i;
uint8_t v; uInt8 v;
// version number // version number
myStream.readVersion(); myStream.readVersion();
@ -1281,7 +1186,7 @@ MovieCart::runStateMachine()
{ {
if (myDrawLevelBars) if (myDrawLevelBars)
{ {
uint8_t levelValue; uInt8 levelValue;
switch (myMode) switch (myMode)
{ {
@ -1407,16 +1312,20 @@ MovieCart::process(uint16_t address)
CartridgeMVC::CartridgeMVC(const string& path, size_t size, CartridgeMVC::CartridgeMVC(const string& path, size_t size,
const string& md5, const Settings& settings, const string& md5, const Settings& settings,
size_t bsSize) size_t bsSize)
: Cartridge(settings, md5) : Cartridge(settings, md5),
mySize{bsSize}
{ {
myPath = path; myPath = path;
myMovie = make_unique<MovieCart>(); myMovie = make_unique<MovieCart>();
// not used // not used
mySize = 1024;
myImage = make_unique<uInt8[]>(mySize); myImage = make_unique<uInt8[]>(mySize);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CartridgeMVC::~CartridgeMVC()
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CartridgeMVC::install(System& system) void CartridgeMVC::install(System& system)
@ -1433,7 +1342,6 @@ void CartridgeMVC::install(System& system)
mySystem->setPageAccess(addr, access); mySystem->setPageAccess(addr, access);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CartridgeMVC::reset() void CartridgeMVC::reset()
{ {
@ -1467,4 +1375,3 @@ bool CartridgeMVC::poke(uInt16 address, uInt8 value)
{ {
return myMovie->process(address); return myMovie->process(address);
} }

69
src/emucore/CartMVC.hxx Executable file → Normal file
View File

@ -33,26 +33,26 @@ class MovieCart;
@author Rob Bairos @author Rob Bairos
*/ */
#define MVC_FIELD_SIZE 2560 // round field to nearest 512 byte boundary
#define MVC_FIELD_PAD_SIZE 4096 // round to nearest 4K
class CartridgeMVC : public Cartridge class CartridgeMVC : public Cartridge
{ {
public:
static constexpr uInt32
MVC_FIELD_SIZE = 2560, // round field to nearest 512 byte boundary
MVC_FIELD_PAD_SIZE = 4096; // round to nearest 4K
public: public:
/** /**
Create a new cartridge using the specified image Create a new cartridge using the specified image
@param image Pointer to the ROM image @param path Path to the ROM image file
@param size The size of the ROM image (<= 2048 bytes) @param size The size of the ROM image (<= 2048 bytes)
@param md5 The md5sum of the ROM image @param md5 The md5sum of the ROM image
@param settings A reference to the various settings (read-only) @param settings A reference to the various settings (read-only)
@param bsSize The size specified by the bankswitching scheme @param bsSize The size specified by the bankswitching scheme
*/ */
CartridgeMVC(const string& path, size_t size, const string& md5, CartridgeMVC(const string& path, size_t size, const string& md5,
const Settings& settings, size_t bsSize = 2_KB); const Settings& settings, size_t bsSize = 1_KB);
~CartridgeMVC() override = default; ~CartridgeMVC() override;
/** /**
Reset device to its power-on state Reset device to its power-on state
@ -73,7 +73,7 @@ class CartridgeMVC : public Cartridge
@param size Set to the size of the internal ROM image data @param size Set to the size of the internal ROM image data
@return A reference to the internal ROM image data @return A reference to the internal ROM image data
*/ */
virtual const ByteBuffer& getImage(size_t& size) const; const ByteBuffer& getImage(size_t& size) const override;
/** /**
Patch the cartridge ROM. Patch the cartridge ROM.
@ -82,7 +82,7 @@ class CartridgeMVC : public Cartridge
@param value The value to place into the address @param value The value to place into the address
@return Success or failure of the patch operation @return Success or failure of the patch operation
*/ */
virtual bool patch(uInt16 address, uInt8 value); bool patch(uInt16 address, uInt8 value) override;
/** /**
Get the byte at the specified address. Get the byte at the specified address.
@ -113,10 +113,7 @@ class CartridgeMVC : public Cartridge
@param out The Serializer object to use @param out The Serializer object to use
@return False on any errors, else true @return False on any errors, else true
*/ */
bool save(Serializer& out) const override bool save(Serializer& out) const override { return false; }
{
return false;
}
/** /**
Load the current state of this cart from the given Serializer. Load the current state of this cart from the given Serializer.
@ -124,49 +121,17 @@ class CartridgeMVC : public Cartridge
@param in The Serializer object to use @param in The Serializer object to use
@return False on any errors, else true @return False on any errors, else true
*/ */
bool load(Serializer& in) override bool load(Serializer& in) override { return false; }
{
return false;
}
/**
Install pages for the specified bank in the system.
@param bank The bank that should be installed in the system
@param segment The segment the bank should be using
@return true, if bank has changed
*/
bool bank(uInt16 bank, uInt16 segment = 0) override
{
return false;
}
/**
Get the current bank.
@param address The address to use when querying the bank
*/
uInt16 getBank(uInt16 address = 0) const override
{
return 0;
}
/**
Query the number of banks supported by the cartridge.
*/
uInt16 romBankCount() const override
{
return 1;
}
private: private:
// Currently not used: // Currently not used:
// Pointer to a dynamically allocated ROM image of the cartridge // Pointer to a dynamically allocated ROM image of the cartridge
ByteBuffer myImage{nullptr}; ByteBuffer myImage{nullptr};
size_t mySize{0}; size_t mySize{0};
unique_ptr<MovieCart> myMovie;
string myPath;
private: private:
// Following constructors and assignment operators not supported // Following constructors and assignment operators not supported
CartridgeMVC() = delete; CartridgeMVC() = delete;
@ -174,12 +139,6 @@ class CartridgeMVC : public Cartridge
CartridgeMVC(CartridgeMVC&&) = delete; CartridgeMVC(CartridgeMVC&&) = delete;
CartridgeMVC& operator=(const CartridgeMVC&) = delete; CartridgeMVC& operator=(const CartridgeMVC&) = delete;
CartridgeMVC& operator=(CartridgeMVC&&) = delete; CartridgeMVC& operator=(CartridgeMVC&&) = delete;
private:
unique_ptr<MovieCart> myMovie;
string myPath;
}; };
#endif #endif

View File

@ -77,6 +77,14 @@ Serializer::Serializer()
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Serializer::setPosition(size_t pos)
{
myStream->clear();
myStream->seekg(pos);
myStream->seekp(pos);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Serializer::rewind() void Serializer::rewind()
{ {

View File

@ -59,6 +59,11 @@ class Serializer
*/ */
explicit operator bool() const { return myStream != nullptr; } explicit operator bool() const { return myStream != nullptr; }
/**
Sets the read/write location to the given offset in the stream.
*/
void setPosition(size_t pos);
/** /**
Resets the read/write location to the beginning of the stream. Resets the read/write location to the beginning of the stream.
*/ */
@ -220,13 +225,6 @@ class Serializer
unique_ptr<iostream> myStream; unique_ptr<iostream> myStream;
static constexpr uInt8 TruePattern = 0xfe, FalsePattern = 0x01; static constexpr uInt8 TruePattern = 0xfe, FalsePattern = 0x01;
private:
// Following constructors and assignment operators not supported
Serializer(const Serializer&) = delete;
Serializer(Serializer&&) = delete;
Serializer& operator=(const Serializer&) = delete;
Serializer& operator=(Serializer&&) = delete;
}; };
#endif #endif

View File

@ -47,6 +47,7 @@ MODULE_OBJS := \
src/emucore/CartFC.o \ src/emucore/CartFC.o \
src/emucore/CartFE.o \ src/emucore/CartFE.o \
src/emucore/CartMDM.o \ src/emucore/CartMDM.o \
src/emucore/CartMVC.o \
src/emucore/CartSB.o \ src/emucore/CartSB.o \
src/emucore/CartTVBoy.o \ src/emucore/CartTVBoy.o \
src/emucore/CartUA.o \ src/emucore/CartUA.o \