Skip to content

Commit 8738293

Browse files
ejaquayejaquay
andauthored
Add a few comments to cartridge stuff (#473)
* Add a few comments to cartridge stuff * Fix comment to clarify cartridge detection logic --------- Co-authored-by: ejaquay <[email protected]>
1 parent 9e29a63 commit 8738293

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

libcommon/src/cartridges/capi_adapter_cartridge.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <vcc/cartridges/capi_adapter_cartridge.h>
1919
#include <stdexcept>
2020

21+
// C API hardware cartridge interface
2122

2223
namespace vcc::cartridges
2324
{

libcommon/src/cartridges/empty_cartridge.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
////////////////////////////////////////////////////////////////////////////////
1818
#include <vcc/cartridges/empty_cartridge.h>
1919

20+
// Interface for empty cartridge
2021

2122
namespace vcc::cartridges
2223
{

libcommon/src/cartridges/rom_cartridge.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
////////////////////////////////////////////////////////////////////////////////
1818
#include <vcc/cartridges/rom_cartridge.h>
1919

20+
// Interface for ROM cartridge
2021

2122
namespace vcc::cartridges
2223
{
@@ -63,6 +64,7 @@ namespace vcc::cartridges
6364
bank_offset_ = 0;
6465
}
6566

67+
// A write to port 0x40 of a bank switching cart (eg RoboCop) will set the bank offset
6668
void rom_cartridge::write_port(unsigned char port_id, unsigned char value)
6769
{
6870
if (enable_bank_switching_ && port_id == 0x40)
@@ -73,7 +75,7 @@ namespace vcc::cartridges
7375

7476
unsigned char rom_cartridge::read_memory_byte(unsigned short memory_address)
7577
{
76-
return buffer_[((memory_address & 32767) + bank_offset_) % buffer_.size()];
78+
return buffer_[((memory_address & 0x7fff) + bank_offset_) % buffer_.size()];
7779
}
7880

7981

libcommon/src/utils/cartridge_loader.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace vcc::utils
4444

4545
}
4646

47-
47+
// Look for magic "MZ" to detect DLL. Assume rom if not.
4848
cartridge_file_type determine_cartridge_type(const std::string& filename)
4949
{
5050
std::ifstream input(filename, std::ios::binary);
@@ -61,11 +61,12 @@ namespace vcc::utils
6161
return cartridge_file_type::rom_image;
6262
}
6363

64+
// Load rom cartridge
6465
cartridge_loader_result load_rom_cartridge(
6566
const std::string& filename,
6667
std::unique_ptr<::vcc::core::cartridge_context> context)
6768
{
68-
constexpr size_t PAK_MAX_MEM = 0x40000;
69+
constexpr size_t PAK_MAX_MEM = 0x40000; // 256KB
6970

7071
std::vector<uint8_t> romImage;
7172

@@ -91,7 +92,7 @@ namespace vcc::utils
9192
}
9293

9394
// Force enable bank switching since we don't have a way to detect if
94-
// it should be enabled.
95+
// it should be enabled. (CCC file > 16KB?)
9596
constexpr bool enable_bank_switching = true;
9697

9798
return {
@@ -106,6 +107,7 @@ namespace vcc::utils
106107
};
107108
}
108109

110+
// Load C API hardware cart
109111
cartridge_loader_result load_capi_cartridge(
110112
const std::string& filename,
111113
std::unique_ptr<::vcc::core::cartridge_context> cartridge_context,

0 commit comments

Comments
 (0)