From 38dce5194e808d93e91595c489099a6a6edc6567 Mon Sep 17 00:00:00 2001 From: stephena Date: Sun, 9 Aug 2015 18:07:04 +0000 Subject: [PATCH] Some minor improvements, self-documentation, etc. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@3191 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- src/common/FrameBufferSDL2.cxx | 2 +- src/common/SoundSDL2.cxx | 54 ++++++++++++++-------------------- src/emucore/AtariVox.cxx | 9 ++---- src/emucore/Cart.cxx | 36 +++++++++++------------ src/emucore/MT24LC256.cxx | 6 ---- src/emucore/MT24LC256.hxx | 2 +- src/emucore/System.cxx | 33 --------------------- src/emucore/System.hxx | 16 +++++++--- src/emucore/TIASnd.cxx | 40 +++++++++---------------- 9 files changed, 70 insertions(+), 128 deletions(-) diff --git a/src/common/FrameBufferSDL2.cxx b/src/common/FrameBufferSDL2.cxx index c9e539aae..e89d87a67 100644 --- a/src/common/FrameBufferSDL2.cxx +++ b/src/common/FrameBufferSDL2.cxx @@ -86,7 +86,7 @@ void FrameBufferSDL2::queryHardware(vector& displays, for(int i = 0; i < maxDisplays; ++i) { SDL_GetDesktopDisplayMode(i, &display); - displays.push_back(GUI::Size(display.w, display.h)); + displays.emplace_back(display.w, display.h); } // For now, supported render types are hardcoded; eventually, SDL may diff --git a/src/common/SoundSDL2.cxx b/src/common/SoundSDL2.cxx index 485d933b0..68a2545a0 100644 --- a/src/common/SoundSDL2.cxx +++ b/src/common/SoundSDL2.cxx @@ -25,6 +25,7 @@ #include #include "TIASnd.hxx" +#include "TIATables.hxx" #include "FrameBuffer.hxx" #include "Settings.hxx" #include "System.hxx" @@ -376,25 +377,19 @@ bool SoundSDL2::save(Serializer& out) const { out.putString(name()); - uInt8 reg1 = 0, reg2 = 0, reg3 = 0, reg4 = 0, reg5 = 0, reg6 = 0; - // Only get the TIA sound registers if sound is enabled if(myIsInitializedFlag) { - reg1 = myTIASound.get(0x15); - reg2 = myTIASound.get(0x16); - reg3 = myTIASound.get(0x17); - reg4 = myTIASound.get(0x18); - reg5 = myTIASound.get(0x19); - reg6 = myTIASound.get(0x1a); + out.putByte(myTIASound.get(TIARegister::AUDC0)); + out.putByte(myTIASound.get(TIARegister::AUDC1)); + out.putByte(myTIASound.get(TIARegister::AUDF0)); + out.putByte(myTIASound.get(TIARegister::AUDF1)); + out.putByte(myTIASound.get(TIARegister::AUDV0)); + out.putByte(myTIASound.get(TIARegister::AUDV1)); } - - out.putByte(reg1); - out.putByte(reg2); - out.putByte(reg3); - out.putByte(reg4); - out.putByte(reg5); - out.putByte(reg6); + else + for(int i = 0; i < 6; ++i) + out.putByte(0); out.putInt(myLastRegisterSetCycle); } @@ -415,29 +410,25 @@ bool SoundSDL2::load(Serializer& in) if(in.getString() != name()) return false; - uInt8 reg1 = in.getByte(), - reg2 = in.getByte(), - reg3 = in.getByte(), - reg4 = in.getByte(), - reg5 = in.getByte(), - reg6 = in.getByte(); - - myLastRegisterSetCycle = (Int32) in.getInt(); - // Only update the TIA sound registers if sound is enabled // Make sure to empty the queue of previous sound fragments if(myIsInitializedFlag) { SDL_PauseAudio(1); myRegWriteQueue.clear(); - myTIASound.set(0x15, reg1); - myTIASound.set(0x16, reg2); - myTIASound.set(0x17, reg3); - myTIASound.set(0x18, reg4); - myTIASound.set(0x19, reg5); - myTIASound.set(0x1a, reg6); + myTIASound.set(TIARegister::AUDC0, in.getByte()); + myTIASound.set(TIARegister::AUDC1, in.getByte()); + myTIASound.set(TIARegister::AUDF0, in.getByte()); + myTIASound.set(TIARegister::AUDF1, in.getByte()); + myTIASound.set(TIARegister::AUDV0, in.getByte()); + myTIASound.set(TIARegister::AUDV1, in.getByte()); if(!myIsMuted) SDL_PauseAudio(0); } + else + for(int i = 0; i < 6; ++i) + in.getByte(); + + myLastRegisterSetCycle = (Int32) in.getInt(); } catch(...) { @@ -450,13 +441,12 @@ bool SoundSDL2::load(Serializer& in) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SoundSDL2::RegWriteQueue::RegWriteQueue(uInt32 capacity) - : myBuffer(nullptr), + : myBuffer(make_ptr(capacity)), myCapacity(capacity), mySize(0), myHead(0), myTail(0) { - myBuffer = make_ptr(myCapacity); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/AtariVox.cxx b/src/emucore/AtariVox.cxx index 58d574e59..ff92ef0f2 100644 --- a/src/emucore/AtariVox.cxx +++ b/src/emucore/AtariVox.cxx @@ -115,12 +115,7 @@ void AtariVox::clockDataIn(bool value) // If this is the first write this frame, or if it's been a long time // since the last write, start a new data byte. - if(cycle < myLastDataWriteCycle) - { - myShiftRegister = 0; - myShiftCount = 0; - } - else if(cycle > myLastDataWriteCycle + 1000) + if((cycle < myLastDataWriteCycle) || (cycle > myLastDataWriteCycle + 1000)) { myShiftRegister = 0; myShiftCount = 0; @@ -128,7 +123,7 @@ void AtariVox::clockDataIn(bool value) // If this is the first write this frame, or if it's been 62 cycles // since the last write, shift this bit into the current byte. - if(cycle < myLastDataWriteCycle || cycle >= myLastDataWriteCycle + 62) + if((cycle < myLastDataWriteCycle) || (cycle >= myLastDataWriteCycle + 62)) { myShiftRegister >>= 1; myShiftRegister |= (value << 15); diff --git a/src/emucore/Cart.cxx b/src/emucore/Cart.cxx index 6a92339e6..12206f057 100644 --- a/src/emucore/Cart.cxx +++ b/src/emucore/Cart.cxx @@ -525,7 +525,7 @@ string Cartridge::autodetectType(const uInt8* image, uInt32 size) type = "4K"; // Most common bankswitching type } - // Variable sized ROM formats are independent of image size and comes last + // Variable sized ROM formats are independent of image size and come last if(isProbablyDASH(image, size)) type = "DASH"; else if(isProbablyMDM(image, size)) @@ -724,14 +724,14 @@ bool Cartridge::isProbablyE0(const uInt8* image, uInt32 size) // Thanks to "stella@casperkitty.com" for this advice // These signatures are attributed to the MESS project uInt8 signature[8][3] = { - { 0x8D, 0xE0, 0x1F }, // STA $1FE0 - { 0x8D, 0xE0, 0x5F }, // STA $5FE0 - { 0x8D, 0xE9, 0xFF }, // STA $FFE9 - { 0x0C, 0xE0, 0x1F }, // NOP $1FE0 - { 0xAD, 0xE0, 0x1F }, // LDA $1FE0 - { 0xAD, 0xE9, 0xFF }, // LDA $FFE9 - { 0xAD, 0xED, 0xFF }, // LDA $FFED - { 0xAD, 0xF3, 0xBF } // LDA $BFF3 + { 0x8D, 0xE0, 0x1F }, // STA $1FE0 + { 0x8D, 0xE0, 0x5F }, // STA $5FE0 + { 0x8D, 0xE9, 0xFF }, // STA $FFE9 + { 0x0C, 0xE0, 0x1F }, // NOP $1FE0 + { 0xAD, 0xE0, 0x1F }, // LDA $1FE0 + { 0xAD, 0xE9, 0xFF }, // LDA $FFE9 + { 0xAD, 0xED, 0xFF }, // LDA $FFED + { 0xAD, 0xF3, 0xBF } // LDA $BFF3 }; for(uInt32 i = 0; i < 8; ++i) if(searchForBytes(image, size, signature[i], 3, 1)) @@ -750,13 +750,13 @@ bool Cartridge::isProbablyE7(const uInt8* image, uInt32 size) // Thanks to "stella@casperkitty.com" for this advice // These signatures are attributed to the MESS project uInt8 signature[7][3] = { - { 0xAD, 0xE2, 0xFF }, // LDA $FFE2 - { 0xAD, 0xE5, 0xFF }, // LDA $FFE5 - { 0xAD, 0xE5, 0x1F }, // LDA $1FE5 - { 0xAD, 0xE7, 0x1F }, // LDA $1FE7 - { 0x0C, 0xE7, 0x1F }, // NOP $1FE7 - { 0x8D, 0xE7, 0xFF }, // STA $FFE7 - { 0x8D, 0xE7, 0x1F } // STA $1FE7 + { 0xAD, 0xE2, 0xFF }, // LDA $FFE2 + { 0xAD, 0xE5, 0xFF }, // LDA $FFE5 + { 0xAD, 0xE5, 0x1F }, // LDA $1FE5 + { 0xAD, 0xE7, 0x1F }, // LDA $1FE7 + { 0x0C, 0xE7, 0x1F }, // NOP $1FE7 + { 0x8D, 0xE7, 0xFF }, // STA $FFE7 + { 0x8D, 0xE7, 0x1F } // STA $1FE7 }; for(uInt32 i = 0; i < 7; ++i) if(searchForBytes(image, size, signature[i], 3, 1)) @@ -818,7 +818,7 @@ bool Cartridge::isProbablyBF(const uInt8* image, uInt32 size, const char*& type) { // BF carts store strings 'BFBF' and 'BFSC' starting at address $FFF8 // This signature is attributed to "RevEng" of AtariAge - uInt8 bf[] = { 'B', 'F', 'B', 'F' }; + uInt8 bf[] = { 'B', 'F', 'B', 'F' }; uInt8 bfsc[] = { 'B', 'F', 'S', 'C' }; if(searchForBytes(image+size-8, 8, bf, 4, 1)) { @@ -840,7 +840,7 @@ bool Cartridge::isProbablyDF(const uInt8* image, uInt32 size, const char*& type) // BF carts store strings 'DFDF' and 'DFSC' starting at address $FFF8 // This signature is attributed to "RevEng" of AtariAge - uInt8 df[] = { 'D', 'F', 'D', 'F' }; + uInt8 df[] = { 'D', 'F', 'D', 'F' }; uInt8 dfsc[] = { 'D', 'F', 'S', 'C' }; if(searchForBytes(image+size-8, 8, df, 4, 1)) { diff --git a/src/emucore/MT24LC256.cxx b/src/emucore/MT24LC256.cxx index 00a9e1715..f47b5f9a9 100644 --- a/src/emucore/MT24LC256.cxx +++ b/src/emucore/MT24LC256.cxx @@ -104,12 +104,6 @@ MT24LC256::~MT24LC256() } } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool MT24LC256::readSDA() const -{ - return jpee_mdat && jpee_sdat; -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void MT24LC256::writeSDA(bool state) { diff --git a/src/emucore/MT24LC256.hxx b/src/emucore/MT24LC256.hxx index 4dcd75594..29774cf60 100644 --- a/src/emucore/MT24LC256.hxx +++ b/src/emucore/MT24LC256.hxx @@ -51,7 +51,7 @@ class MT24LC256 public: /** Read boolean data from the SDA line */ - bool readSDA() const; + bool readSDA() const { return jpee_mdat && jpee_sdat; } /** Write boolean data to the SDA and SCL lines */ void writeSDA(bool state); diff --git a/src/emucore/System.cxx b/src/emucore/System.cxx index 4d7e1a32d..52d25a91c 100644 --- a/src/emucore/System.cxx +++ b/src/emucore/System.cxx @@ -101,39 +101,6 @@ void System::resetCycles() myCycles = 0; } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void System::setPageAccess(uInt16 page, const PageAccess& access) -{ - // Make sure the page is within range - assert(page < NUM_PAGES); - - // Make sure the access methods make sense - assert(access.device != 0); - - myPageAccessTable[page] = access; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -const System::PageAccess& System::getPageAccess(uInt16 page) const -{ - // Make sure the page is within range - assert(page < NUM_PAGES); - - return myPageAccessTable[page]; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -System::PageAccessType System::getPageAccessType(uInt16 addr) const -{ - return myPageAccessTable[(addr & ADDRESS_MASK) >> PAGE_SHIFT].type; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void System::setDirtyPage(uInt16 addr) -{ - myPageIsDirtyTable[(addr & ADDRESS_MASK) >> PAGE_SHIFT] = true; -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool System::isPageDirty(uInt16 start_addr, uInt16 end_addr) const { diff --git a/src/emucore/System.hxx b/src/emucore/System.hxx index c953f69b5..4f0a51c5a 100644 --- a/src/emucore/System.hxx +++ b/src/emucore/System.hxx @@ -313,7 +313,9 @@ class System : public Serializable @param page The page accessing methods should be set for @param access The accessing methods to be used by the page */ - void setPageAccess(uInt16 page, const PageAccess& access); + void setPageAccess(uInt16 page, const PageAccess& access) { + myPageAccessTable[page] = access; + } /** Get the page accessing method for the specified page. @@ -321,7 +323,9 @@ class System : public Serializable @param page The page to get accessing methods for @return The accessing methods used by the page */ - const PageAccess& getPageAccess(uInt16 page) const; + const PageAccess& getPageAccess(uInt16 page) const { + return myPageAccessTable[page]; + } /** Get the page type for the given address. @@ -329,14 +333,18 @@ class System : public Serializable @param addr The address contained in the page in questions @return The type of page that contains the given address */ - System::PageAccessType getPageAccessType(uInt16 addr) const; + System::PageAccessType getPageAccessType(uInt16 addr) const { + return myPageAccessTable[(addr & ADDRESS_MASK) >> PAGE_SHIFT].type; + } /** Mark the page containing this address as being dirty. @param addr Determines the page that is dirty */ - void setDirtyPage(uInt16 addr); + void setDirtyPage(uInt16 addr) { + myPageIsDirtyTable[(addr & ADDRESS_MASK) >> PAGE_SHIFT] = true; + } /** Answer whether any pages in given range of addresses have been diff --git a/src/emucore/TIASnd.cxx b/src/emucore/TIASnd.cxx index c9cc939e9..dc8355520 100644 --- a/src/emucore/TIASnd.cxx +++ b/src/emucore/TIASnd.cxx @@ -18,6 +18,7 @@ //============================================================================ #include "System.hxx" +#include "TIATables.hxx" #include "TIASnd.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -85,18 +86,18 @@ void TIASound::set(uInt16 address, uInt8 value) int chan = ~address & 0x1; switch(address) { - case 0x15: // AUDC0 - case 0x16: // AUDC1 + case TIARegister::AUDC0: + case TIARegister::AUDC1: myAUDC[chan] = value & 0x0f; break; - case 0x17: // AUDF0 - case 0x18: // AUDF1 + case TIARegister::AUDF0: + case TIARegister::AUDF1: myAUDF[chan] = value & 0x1f; break; - case 0x19: // AUDV0 - case 0x1a: // AUDV1 + case TIARegister::AUDV0: + case TIARegister::AUDV1: myAUDV[chan] = (value & 0x0f) << AUDV_SHIFT; break; @@ -142,26 +143,13 @@ uInt8 TIASound::get(uInt16 address) const { switch(address) { - case 0x15: // AUDC0 - return myAUDC[0]; - - case 0x16: // AUDC1 - return myAUDC[1]; - - case 0x17: // AUDF0 - return myAUDF[0]; - - case 0x18: // AUDF1 - return myAUDF[1]; - - case 0x19: // AUDV0 - return myAUDV[0] >> AUDV_SHIFT; - - case 0x1a: // AUDV1 - return myAUDV[1] >> AUDV_SHIFT; - - default: - return 0; + case TIARegister::AUDC0: return myAUDC[0]; + case TIARegister::AUDC1: return myAUDC[1]; + case TIARegister::AUDF0: return myAUDF[0]; + case TIARegister::AUDF1: return myAUDF[1]; + case TIARegister::AUDV0: return myAUDV[0] >> AUDV_SHIFT; + case TIARegister::AUDV1: return myAUDV[1] >> AUDV_SHIFT; + default: return 0; } }