1 //============================================================================
2 //
3 // SSSS tt lll lll
4 // SS SS tt ll ll
5 // SS tttttt eeee ll ll aaaa
6 // SSSS tt ee ee ll ll aa
7 // SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
8 // SS SS tt ee ll ll aa aa
9 // SSSS ttt eeeee llll llll aaaaa
10 //
11 // Copyright (c) 1995-2021 by Bradford W. Mott, Stephen Anthony
12 // and the Stella Team
13 //
14 // See the file "License.txt" for information on usage and redistribution of
15 // this file, and for a DISCLAIMER OF ALL WARRANTIES.
16 //============================================================================
17
18 #include "System.hxx"
19 #include "CartTVBoy.hxx"
20
21 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CartridgeTVBoy(const ByteBuffer & image,size_t size,const string & md5,const Settings & settings,size_t bsSize)22 CartridgeTVBoy::CartridgeTVBoy(const ByteBuffer& image, size_t size,
23 const string& md5, const Settings& settings,
24 size_t bsSize)
25 : CartridgeEnhanced(image, size, md5, settings, bsSize)
26 {
27 }
28
29 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
checkSwitchBank(uInt16 address,uInt8)30 bool CartridgeTVBoy::checkSwitchBank(uInt16 address, uInt8)
31 {
32 // Switch banks if necessary
33 if((address & ADDR_MASK) >= 0x1800 && (address & ADDR_MASK) <= 0x187F)
34 {
35 bank(address & (romBankCount() - 1));
36 return true;
37 }
38 return false;
39 }
40
41 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bank(uInt16 bank,uInt16)42 bool CartridgeTVBoy::bank(uInt16 bank, uInt16)
43 {
44 if(myBankingDisabled) return false;
45
46 bool banked = CartridgeEnhanced::bank(bank);
47
48 // Any bankswitching locks further bankswitching, we check for bank 0
49 // to avoid locking on cart init.
50 if (banked && bank != 0)
51 myBankingDisabled = true;
52
53 return banked;
54 }
55
56 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
save(Serializer & out) const57 bool CartridgeTVBoy::save(Serializer& out) const
58 {
59 CartridgeEnhanced::save(out);
60 try
61 {
62 out.putBool(myBankingDisabled);
63 }
64 catch(...)
65 {
66 cerr << "ERROR: CartridgeTVBoy::save" << endl;
67 return false;
68 }
69
70 return true;
71 }
72
73 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
load(Serializer & in)74 bool CartridgeTVBoy::load(Serializer& in)
75 {
76 CartridgeEnhanced::load(in);
77 try
78 {
79 myBankingDisabled = in.getBool();
80 }
81 catch(...)
82 {
83 cerr << "ERROR: CartridgeTVBoy::load" << endl;
84 return false;
85 }
86
87 return true;
88 }
89