66#include " system.h"
77
88namespace gui ::options {
9+
10+ char sjisToAscii (uint16_t sjis) {
11+ uint8_t l = sjis & 0xff ;
12+ uint8_t h = (sjis >> 8 ) & 0xff ;
13+ if (sjis == 0 ) return 0 ;
14+ if (l == 0x81 ) {
15+ // if (h == 0x14) return '-';
16+ if (h == 0x5b ) return ' -' ;
17+ if (h == 0x40 ) return ' ' ;
18+ if (h == 0x46 ) return ' :' ;
19+ if (h == 0x49 ) return ' !' ;
20+ if (h == 0x5e ) return ' /' ;
21+ if (h == 0x6d ) return ' [' ;
22+ if (h == 0x6e ) return ' ]' ;
23+ if (h == 0x69 ) return ' (' ;
24+ if (h == 0x6a ) return ' )' ;
25+ if (h == 0x7b ) return ' +' ;
26+ if (h == 0x7c ) return ' ,' ;
27+ if (h == 0x93 ) return ' %' ;
28+ // if (h >= 0x43 && h <= 0x97) return ' ' + (h-0x43);
29+ }
30+ if (l == 0x82 ) {
31+ if (h >= 0x4f && h <= 0x58 ) return ' 0' + (h - 0x4f );
32+ if (h >= 0x60 && h <= 0x79 ) return ' A' + (h - 0x60 );
33+ if (h >= 0x81 && h <= 0x9a ) return ' a' + (h - 0x81 );
34+ }
35+ // fmt::print("Unknown S-JIS: 0x{:02x} 0x{:02x}\n", l, h);
36+ return ' ?' ;
37+ }
38+
39+ void MemoryCard::parseAndDisplayCard (peripherals::MemoryCard* card) {
40+ auto data = card->data ;
41+ auto read32
42+ = [data](size_t pos) -> uint32_t { return data[pos] | (data[pos + 1 ] << 8 ) | (data[pos + 2 ] << 16 ) | (data[pos + 3 ] << 24 ); };
43+
44+ const int BLOCKS = 15 ;
45+ const auto FRAME_SIZE = 0x80 ;
46+ const auto BLOCK_SIZE = FRAME_SIZE * 64 ;
47+
48+ ImGui::Text (" Contents:" );
49+
50+ enum BlockNum { First = 1 , Middle = 2 , Last = 3 };
51+
52+ std::string names[BLOCKS];
53+ int links[BLOCKS];
54+
55+ for (size_t i = 1 ; i < BLOCKS + 1 ; i++) {
56+ size_t offset = 0x80 * i;
57+ uint32_t state = read32 (offset + 0 );
58+
59+ bool inUse = false ;
60+ if (state >= 0x51 && state <= 0x53 ) {
61+ if (state == 0x51 ) {
62+ links[i - 1 ] = -1 ;
63+ }
64+ inUse = true ;
65+ }
66+
67+ if (!inUse) {
68+ ImGui::Selectable (fmt::format (" {:2d}. ---" , i).c_str ());
69+ continue ;
70+ }
71+
72+ // state == 0x51 - block in use, first block
73+ // state == 0x52 - block in use, middle block
74+ // state == 0x53 - block in use, end block
75+
76+ if (state == 0x51 ) {
77+ uint32_t size = read32 (offset + 4 ) / 1024 ;
78+ std::string filename;
79+ for (int i = 0 ; i < 20 ; i++) {
80+ filename += data[offset + 0x0a + i];
81+ }
82+
83+ // Parse block
84+ std::string title;
85+
86+ for (int s = 0 ; s < 32 ; s++) {
87+ size_t offset = BLOCK_SIZE * i + 4 ;
88+ uint16_t sjis = data[offset + s * 2 ] | (data[offset + s * 2 + 1 ] << 8 );
89+
90+ char c = sjisToAscii (sjis);
91+ if (c == 0 ) break ;
92+ title += c;
93+ }
94+
95+ ImGui::Selectable (fmt::format (" {:2d}. {} ({})" , i, title, filename).c_str ());
96+ continue ;
97+ }
98+
99+ ImGui::Selectable (fmt::format (" {:2d}. USED" , i).c_str ());
100+ }
101+ }
9102void MemoryCard::memoryCardWindow (System* sys) {
10103 if (loadPaths) {
11104 for (size_t i = 0 ; i < cardPaths.size (); i++) {
@@ -26,9 +119,13 @@ void MemoryCard::memoryCardWindow(System* sys) {
26119
27120 bool inserted = sys->controller ->card [i]->inserted ;
28121 if (ImGui::Checkbox (" Inserted" , &inserted)) {
29- sys->controller ->card [0 ]->inserted = inserted;
122+ sys->controller ->card [i ]->inserted = inserted;
30123 }
31124
125+ // ImGui::BeginChild("Contents");
126+ parseAndDisplayCard (sys->controller ->card [i].get ());
127+ // ImGui::EndChild();
128+
32129 ImGui::EndTabItem ();
33130 }
34131 }
@@ -40,4 +137,4 @@ void MemoryCard::memoryCardWindow(System* sys) {
40137void MemoryCard::displayWindows (System* sys) {
41138 if (memoryCardWindowOpen) memoryCardWindow (sys);
42139}
43- } // namespace gui::options::memory_card
140+ } // namespace gui::options
0 commit comments