2019-09-01 14:36:53 +02:00
|
|
|
//******************************************
|
|
|
|
// NES MODULE
|
|
|
|
//******************************************
|
2019-09-05 00:48:39 +02:00
|
|
|
// mostly copy&pasted from "Famicom Dumper" 2019-08-31 by skaman
|
|
|
|
// also based on "CoolArduino" by HardWareMan
|
|
|
|
// Pinout changes: LED and CIRAM_A10
|
|
|
|
|
2024-03-02 17:26:35 +01:00
|
|
|
#ifdef ENABLE_NES
|
2020-07-04 17:07:14 +02:00
|
|
|
|
2019-09-05 00:48:39 +02:00
|
|
|
//Line Content
|
2021-02-08 05:34:39 +01:00
|
|
|
//28 Supported Mappers
|
2022-09-25 11:09:54 +02:00
|
|
|
//106 Defines
|
|
|
|
//136 Variables
|
|
|
|
//197 Menus
|
|
|
|
//383 Setup
|
|
|
|
//412 No-Intro SD Database Functions
|
|
|
|
//1125 Low Level Functions
|
|
|
|
//1372 CRC Functions
|
|
|
|
//1426 File Functions
|
|
|
|
//1527 NES 2.0 Header Functions
|
|
|
|
//1957 Config Functions
|
|
|
|
//2760 ROM Functions
|
|
|
|
//3951 RAM Functions
|
|
|
|
//4384 Eeprom Functions
|
|
|
|
//4574 NESmaker Flash Cart Functions
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2019-09-01 14:36:53 +02:00
|
|
|
/******************************************
|
2019-09-05 00:48:39 +02:00
|
|
|
Supported Mappers
|
2019-09-01 14:36:53 +02:00
|
|
|
*****************************************/
|
2019-09-05 00:48:39 +02:00
|
|
|
// Supported Mapper Array (iNES Mapper #s)
|
|
|
|
// Format = {mapper,prglo,prghi,chrlo,chrhi,ramlo,ramhi}
|
2023-06-27 09:43:40 +02:00
|
|
|
static const uint8_t PROGMEM mapsize[] = {
|
2022-12-20 10:31:35 +01:00
|
|
|
0, 0, 1, 0, 1, 0, 2, // nrom [sram r/w]
|
|
|
|
1, 1, 5, 0, 5, 0, 3, // mmc1 [sram r/w]
|
|
|
|
2, 2, 4, 0, 0, 0, 0, // uxrom
|
|
|
|
3, 0, 1, 0, 3, 0, 0, // cnrom
|
|
|
|
4, 1, 5, 0, 6, 0, 1, // mmc3/mmc6 [sram/prgram r/w]
|
|
|
|
5, 3, 5, 5, 7, 0, 3, // mmc5 [sram r/w]
|
|
|
|
7, 2, 4, 0, 0, 0, 0, // axrom
|
|
|
|
9, 3, 3, 5, 5, 0, 0, // mmc2 (punch out)
|
|
|
|
10, 3, 4, 4, 5, 1, 1, // mmc4 [sram r/w]
|
|
|
|
11, 1, 3, 1, 5, 0, 0, // Color Dreams [UNLICENSED]
|
|
|
|
13, 1, 1, 0, 0, 0, 0, // cprom (videomation)
|
|
|
|
15, 6, 6, 0, 0, 0, 0, // K-1029/K-1030P [UNLICENSED]
|
|
|
|
16, 3, 4, 5, 6, 0, 1, // bandai x24c02 [eep r/w]
|
|
|
|
18, 3, 4, 5, 6, 0, 1, // jaleco ss8806 [sram r/w]
|
|
|
|
19, 3, 4, 5, 6, 0, 1, // namco 106/163 [sram/prgram r/w]
|
2022-12-14 13:15:32 +01:00
|
|
|
// 20 - bad mapper, not used
|
2022-12-20 10:31:35 +01:00
|
|
|
21, 4, 4, 5, 6, 0, 1, // vrc4a/vrc4c [sram r/w]
|
|
|
|
22, 3, 3, 5, 5, 0, 0, // vrc2a
|
|
|
|
23, 3, 3, 5, 6, 0, 0, // vrc2b/vrc4e
|
|
|
|
24, 4, 4, 5, 5, 0, 0, // vrc6a (akumajou densetsu)
|
|
|
|
25, 3, 4, 5, 6, 0, 1, // vrc2c/vrc4b/vrc4d [sram r/w]
|
|
|
|
26, 4, 4, 5, 6, 1, 1, // vrc6b [sram r/w]
|
|
|
|
28, 5, 7, 0, 0, 0, 0, // Action 53 [UNLICENSED]
|
|
|
|
30, 4, 5, 0, 0, 0, 0, // unrom 512 (NESmaker) [UNLICENSED]
|
2022-12-22 21:55:00 +01:00
|
|
|
31, 6, 6, 0, 0, 0, 0, // NSF music compilations [UNLICENSED]
|
2022-12-20 10:31:35 +01:00
|
|
|
32, 3, 4, 5, 5, 0, 0, // irem g-101
|
|
|
|
33, 3, 4, 5, 6, 0, 0, // taito tc0190
|
2023-04-10 10:35:17 +02:00
|
|
|
34, 1, 8, 0, 4, 0, 0, // BxROM & NINA
|
2022-12-20 10:31:35 +01:00
|
|
|
35, 0, 7, 1, 8, 0, 0, // J.Y. Company ASIC [UNLICENSED]
|
|
|
|
36, 0, 3, 1, 5, 0, 0, // TXC 01-22000-400 Board [UNLICENSED]
|
|
|
|
37, 4, 4, 6, 6, 0, 0, // (super mario bros + tetris + world cup)
|
2023-04-15 16:12:41 +02:00
|
|
|
38, 1, 3, 0, 3, 0, 0, // Crime Busters [UNLICENSED]
|
2022-12-20 10:31:35 +01:00
|
|
|
42, 0, 3, 0, 5, 0, 0, // hacked FDS games converted to cartridge [UNLICENSED]
|
|
|
|
45, 3, 6, 0, 8, 0, 0, // ga23c asic multicart [UNLICENSED]
|
|
|
|
46, 1, 6, 0, 8, 0, 0, // Rumble Station [UNLICENSED]
|
|
|
|
47, 4, 4, 6, 6, 0, 0, // (super spike vball + world cup)
|
|
|
|
48, 3, 4, 6, 6, 0, 0, // taito tc0690
|
|
|
|
52, 0, 3, 0, 3, 0, 0, // Realtec 8213 [UNLICENSED]
|
2022-12-30 08:24:54 +01:00
|
|
|
56, 0, 7, 0, 6, 0, 0, // KS202 [UNLICENSED]
|
2022-12-22 21:55:00 +01:00
|
|
|
57, 0, 3, 0, 5, 0, 0, // BMC-GKA [UNLICENSED]
|
2022-12-20 10:31:35 +01:00
|
|
|
58, 1, 6, 1, 6, 0, 0, // BMC-GKB (C)NROM-based multicarts, duplicate of mapper 213 [UNLICENSED]
|
|
|
|
59, 0, 3, 0, 4, 0, 0, // BMC-T3H53 & BMC-D1038 [UNLICENSED]
|
|
|
|
60, 2, 2, 3, 3, 0, 0, // Reset-based NROM-128 4-in-1 multicarts [UNLICENSED]
|
|
|
|
62, 7, 7, 8, 8, 0, 0, // K-1017P [UNLICENSED]
|
|
|
|
63, 8, 8, 0, 0, 0, 0, // NTDEC "Powerful" multicart, 3072K [UNLICENSED]
|
|
|
|
64, 2, 3, 4, 5, 0, 0, // tengen rambo-1 [UNLICENSED]
|
|
|
|
65, 3, 4, 5, 6, 0, 0, // irem h-3001
|
|
|
|
66, 2, 3, 2, 3, 0, 0, // gxrom/mhrom
|
|
|
|
67, 3, 3, 5, 5, 0, 0, // sunsoft 3
|
|
|
|
68, 3, 3, 5, 6, 0, 1, // sunsoft 4 [sram r/w]
|
|
|
|
69, 3, 4, 5, 6, 0, 1, // sunsoft fme-7/5a/5b [sram r/w]
|
|
|
|
70, 3, 3, 5, 5, 0, 0, // bandai
|
|
|
|
71, 2, 4, 0, 0, 0, 0, // camerica/codemasters [UNLICENSED]
|
|
|
|
72, 3, 3, 5, 5, 0, 0, // jaleco jf-17
|
|
|
|
73, 3, 3, 0, 0, 0, 0, // vrc3 (salamander)
|
|
|
|
75, 3, 3, 5, 5, 0, 0, // vrc1
|
|
|
|
76, 3, 3, 5, 5, 0, 0, // namco 109 variant (megami tensei: digital devil story)
|
|
|
|
77, 3, 3, 3, 3, 0, 0, // (napoleon senki)
|
|
|
|
78, 3, 3, 5, 5, 0, 0, // irem 74hc161/32
|
|
|
|
79, 1, 2, 2, 3, 0, 0, // NINA-03/06 by AVE [UNLICENSED]
|
|
|
|
80, 3, 3, 5, 6, 0, 1, // taito x1-005 [prgram r/w]
|
|
|
|
82, 3, 3, 5, 6, 0, 1, // taito x1-017 [prgram r/w]
|
2022-12-14 13:15:32 +01:00
|
|
|
// 84 - bad mapper, not used
|
2022-12-20 10:31:35 +01:00
|
|
|
85, 3, 5, 0, 5, 0, 1, // vrc7 [sram r/w]
|
|
|
|
86, 3, 3, 4, 4, 0, 0, // jaleco jf-13 (moero pro yakyuu)
|
|
|
|
87, 0, 1, 2, 3, 0, 0, // Jaleco/Konami CNROM (DIS_74X139X74)
|
|
|
|
88, 3, 3, 5, 5, 0, 0, // namco (dxrom variant)
|
|
|
|
89, 3, 3, 5, 5, 0, 0, // sunsoft 2 variant (tenka no goikenban: mito koumon)
|
|
|
|
90, 0, 7, 1, 8, 0, 0, // J.Y. Company ASIC [UNLICENSED]
|
|
|
|
91, 3, 5, 7, 8, 0, 0, // JY830623C/YY840238C boards [UNLICENSED]
|
|
|
|
92, 4, 4, 5, 5, 0, 0, // jaleco jf-19/jf-21
|
|
|
|
93, 3, 3, 0, 0, 0, 0, // sunsoft 2
|
|
|
|
94, 3, 3, 0, 0, 0, 0, // hvc-un1rom (senjou no ookami)
|
|
|
|
95, 3, 3, 3, 3, 0, 0, // namcot-3425 (dragon buster)
|
|
|
|
96, 3, 3, 0, 0, 0, 0, // (oeka kids)
|
|
|
|
97, 4, 4, 0, 0, 0, 0, // irem tam-s1 (kaiketsu yanchamaru)
|
2022-12-14 13:15:32 +01:00
|
|
|
// 100 - bad mapper, not used
|
|
|
|
// 101 - bad mapper, not used
|
2022-10-13 09:49:03 +02:00
|
|
|
105, 4, 4, 0, 0, 0, 0, // (nintendo world Championships 1990) [UNTESTED]
|
2022-11-02 12:27:08 +01:00
|
|
|
111, 5, 5, 0, 0, 0, 0, // GTROM [UNLICENSED]
|
2023-05-11 20:41:19 +02:00
|
|
|
113, 1, 4, 0, 5, 0, 0, // NINA-03/06 [UNLICENSED]
|
|
|
|
114, 3, 4, 5, 6, 0, 0, // SuperGame MMC3-clone [UNLICENSED]
|
2022-10-13 09:49:03 +02:00
|
|
|
118, 3, 4, 5, 5, 0, 1, // txsrom/mmc3 [sram r/w]
|
|
|
|
119, 3, 3, 4, 4, 0, 0, // tqrom/mmc3
|
2022-12-08 16:10:05 +01:00
|
|
|
126, 1, 8, 0, 8, 0, 0, // MMC3-based multicart (PJ-008, AT-207) [UNLICENSED]
|
|
|
|
134, 1, 8, 0, 8, 0, 0, // T4A54A, WX-KB4K, or BS-5652 [UNLICENSED]
|
2022-10-13 09:49:03 +02:00
|
|
|
140, 3, 3, 3, 5, 0, 0, // jaleco jf-11/jf-14
|
2022-12-05 20:35:51 +01:00
|
|
|
142, 1, 3, 0, 0, 0, 0, // UNL-KS7032 [UNLICENSED]
|
2022-10-13 09:49:03 +02:00
|
|
|
146, 1, 2, 2, 3, 0, 0, // Sachen 3015 [UNLICENSED]
|
2023-04-30 13:42:16 +02:00
|
|
|
148, 1, 2, 0, 4, 0, 0, // Sachen SA-0037 & Tengen 800008 [UNLICENSED]
|
2022-12-14 13:15:32 +01:00
|
|
|
// 151 - bad mapper, not used
|
2022-10-25 09:33:22 +02:00
|
|
|
152, 2, 3, 5, 5, 0, 0, // BANDAI-74*161/161/32
|
2022-10-13 09:49:03 +02:00
|
|
|
153, 5, 5, 0, 0, 1, 1, // (famicom jump ii) [sram r/w]
|
|
|
|
154, 3, 3, 5, 5, 0, 0, // namcot-3453 (devil man)
|
|
|
|
155, 3, 3, 3, 5, 0, 1, // mmc1 variant [sram r/w]
|
2022-12-05 20:35:51 +01:00
|
|
|
157, 4, 4, 0, 0, 0, 0, // Datach
|
2022-10-13 09:49:03 +02:00
|
|
|
158, 3, 3, 5, 5, 0, 0, // tengen rambo-1 variant (alien syndrome (u)) [UNLICENSED]
|
|
|
|
159, 3, 4, 5, 6, 1, 1, // bandai x24c01 [eep r/w]
|
2022-12-05 20:35:51 +01:00
|
|
|
162, 6, 7, 0, 0, 0, 0, // Waixing FS304 [UNLICENSED]
|
|
|
|
163, 6, 7, 0, 0, 0, 0, // Nanjing FC-001 [UNLICENSED]
|
2022-12-08 16:10:05 +01:00
|
|
|
174, 3, 3, 4, 4, 0, 0, // NTDEC 5-in-1 [UNLICENSED]
|
2022-11-24 22:18:46 +01:00
|
|
|
176, 4, 4, 5, 5, 0, 0, // 8025 enhanced MMC3 [UNLICENSED]
|
2022-12-05 20:35:51 +01:00
|
|
|
177, 1, 7, 0, 0, 0, 0, // Henggedianzi Super Rich PCB [UNLICENSED]
|
2022-12-04 08:45:49 +01:00
|
|
|
178, 5, 5, 0, 0, 0, 0, // some Waixing PCBs [UNLICENSED]
|
2022-10-13 09:49:03 +02:00
|
|
|
180, 3, 3, 0, 0, 0, 0, // unrom variant (crazy climber)
|
|
|
|
184, 1, 1, 2, 3, 0, 0, // sunsoft 1
|
|
|
|
185, 0, 1, 1, 1, 0, 0, // cnrom lockout
|
2022-12-14 13:15:32 +01:00
|
|
|
// 186 - bad mapper, not used
|
2022-10-23 20:57:34 +02:00
|
|
|
200, 1, 4, 1, 4, 0, 0, // HN-02 multicarts [UNLICENSED]
|
|
|
|
201, 1, 8, 1, 9, 0, 0, // NROM-256 multicarts [UNLICENSED]
|
2022-10-24 14:50:33 +02:00
|
|
|
202, 0, 3, 1, 4, 0, 0, // BMC-150IN1 multicarts [UNLICENSED]
|
2022-10-23 20:57:34 +02:00
|
|
|
203, 1, 4, 1, 4, 0, 0, // various NROM-128 multicarts [UNLICENSED]
|
2022-10-13 09:49:03 +02:00
|
|
|
206, 1, 3, 2, 4, 0, 0, // dxrom
|
|
|
|
207, 4, 4, 5, 5, 0, 0, // taito x1-005 variant (fudou myouou den)
|
2022-12-14 04:47:53 +01:00
|
|
|
209, 0, 7, 1, 8, 0, 0, // J.Y. Company ASIC [UNLICENSED]
|
2022-10-13 09:49:03 +02:00
|
|
|
210, 3, 5, 5, 6, 0, 0, // namco 175/340
|
2022-12-14 13:15:32 +01:00
|
|
|
211, 0, 7, 1, 8, 0, 0, // J.Y. Company ASIC [UNLICENSED]
|
2022-12-06 16:48:53 +01:00
|
|
|
212, 0, 3, 0, 4, 0, 0, // BMC Super HiK 300-in-1 [UNLICENSED]
|
2022-10-23 20:57:34 +02:00
|
|
|
213, 1, 6, 1, 6, 0, 0, // BMC-GKB (C)NROM-based multicarts, duplicate of mapper 58 [UNLICENSED]
|
2022-12-22 21:55:00 +01:00
|
|
|
214, 0, 3, 0, 4, 0, 0, // BMC-SUPERGUN-20IN1, BMC-190IN1 [UNLICENSED]
|
2022-11-11 12:08:17 +01:00
|
|
|
225, 4, 7, 5, 8, 0, 0, // ET-4310 (FC) + K-1010 (NES) [UNLICENSED]
|
2022-11-10 23:20:23 +01:00
|
|
|
226, 6, 7, 0, 0, 0, 0, // BMC-76IN1, BMC-SUPER42IN1, BMC-GHOSTBUSTERS63IN1 [UNLICENSED]
|
2022-12-04 08:45:49 +01:00
|
|
|
227, 1, 5, 0, 0, 0, 0, // 810449-C-A1 / FW-01 [UNLICENSED]
|
2022-11-08 12:49:42 +01:00
|
|
|
228, 4, 7, 5, 7, 0, 0, // Action 52 + Cheetahmen II [UNLICENSED]
|
2022-10-24 14:50:33 +02:00
|
|
|
229, 5, 5, 6, 6, 0, 0, // BMC 31-IN-1 [UNLICENSED]
|
2022-10-23 20:57:34 +02:00
|
|
|
232, 4, 4, 0, 0, 0, 0, // Camerica/Codemasters "Quattro" cartridges [UNLICENSED]
|
2022-10-20 14:01:23 +02:00
|
|
|
235, 6, 8, 0, 0, 0, 0, // "Golden Game" multicarts [UNLICENSED]
|
2022-12-30 08:24:54 +01:00
|
|
|
236, 0, 6, 0, 5, 0, 0, // Realtec 8031, 8099, 8106, 8155 [UNLICENSED]
|
2022-10-27 16:56:46 +02:00
|
|
|
240, 1, 5, 1, 5, 0, 3, // C&E Bootleg Board (Sheng Huo Lie Zhuan, Jing Ke Xin Zhuan) [UNLICENSED]
|
2022-12-04 08:45:49 +01:00
|
|
|
241, 3, 5, 0, 0, 0, 0, // BxROM with WRAM [UNLICENSED]
|
2022-10-21 00:43:45 +02:00
|
|
|
242, 5, 5, 0, 0, 0, 0, // ET-113 [UNLICENSED]
|
2022-10-27 16:56:46 +02:00
|
|
|
246, 5, 5, 7, 7, 0, 0, // C&E Feng Shen Bang [UNLICENSED]
|
2022-12-14 13:15:32 +01:00
|
|
|
// 248 - bad mapper, not used
|
2022-11-11 12:08:17 +01:00
|
|
|
255, 4, 7, 5, 8, 0, 0, // 110-in-1 multicart (same as 225) [UNLICENSED]
|
2019-09-05 00:48:39 +02:00
|
|
|
};
|
2019-09-01 14:36:53 +02:00
|
|
|
|
2022-10-29 02:55:32 +02:00
|
|
|
const char _file_name_no_number_fmt[] PROGMEM = "%s.%s";
|
|
|
|
const char _file_name_with_number_fmt[] PROGMEM = "%s.%02d.%s";
|
|
|
|
|
2019-09-01 14:36:53 +02:00
|
|
|
/******************************************
|
2019-09-05 00:48:39 +02:00
|
|
|
Defines
|
2019-09-01 14:36:53 +02:00
|
|
|
*****************************************/
|
2022-10-13 09:49:03 +02:00
|
|
|
#define ROMSEL_HI PORTF |= (1 << 1)
|
|
|
|
#define ROMSEL_LOW PORTF &= ~(1 << 1)
|
|
|
|
#define PHI2_HI PORTF |= (1 << 0)
|
|
|
|
#define PHI2_LOW PORTF &= ~(1 << 0)
|
|
|
|
#define PRG_READ PORTF |= (1 << 7)
|
|
|
|
#define PRG_WRITE PORTF &= ~(1 << 7)
|
|
|
|
#define CHR_READ_HI PORTF |= (1 << 5)
|
|
|
|
#define CHR_READ_LOW PORTF &= ~(1 << 5)
|
|
|
|
#define CHR_WRITE_HI PORTF |= (1 << 2)
|
|
|
|
#define CHR_WRITE_LOW PORTF &= ~(1 << 2)
|
2019-09-05 00:48:39 +02:00
|
|
|
|
|
|
|
// RGB LED COMMON ANODE
|
2022-02-27 13:19:35 +01:00
|
|
|
#define LED_RED_OFF setColor_RGB(0, 0, 0)
|
|
|
|
#define LED_RED_ON setColor_RGB(255, 0, 0)
|
|
|
|
#define LED_GREEN_OFF setColor_RGB(0, 0, 0)
|
|
|
|
#define LED_GREEN_ON setColor_RGB(0, 255, 0)
|
|
|
|
#define LED_BLUE_OFF setColor_RGB(0, 0, 0)
|
|
|
|
#define LED_BLUE_ON setColor_RGB(0, 0, 255)
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
#define MODE_READ \
|
|
|
|
{ \
|
|
|
|
PORTK = 0xFF; \
|
|
|
|
DDRK = 0; \
|
|
|
|
}
|
2019-09-05 00:48:39 +02:00
|
|
|
#define MODE_WRITE DDRK = 0xFF
|
|
|
|
|
|
|
|
#define press 1
|
|
|
|
#define doubleclick 2
|
|
|
|
#define hold 3
|
|
|
|
#define longhold 4
|
|
|
|
|
|
|
|
/******************************************
|
|
|
|
Variables
|
|
|
|
*****************************************/
|
|
|
|
// Mapper
|
2023-06-27 09:43:40 +02:00
|
|
|
uint8_t mapcount = (sizeof(mapsize) / sizeof(mapsize[0])) / 7;
|
|
|
|
uint8_t mapselect;
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2023-06-27 09:43:40 +02:00
|
|
|
const uint16_t PRG[] PROGMEM = { 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 };
|
|
|
|
uint8_t prglo = 0; // Lowest Entry
|
|
|
|
uint8_t prghi = 11; // Highest Entry
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2023-06-27 09:43:40 +02:00
|
|
|
const uint16_t CHR[] PROGMEM = { 0, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 };
|
|
|
|
uint8_t chrlo = 0; // Lowest Entry
|
|
|
|
uint8_t chrhi = 10; // Highest Entry
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2023-06-27 09:43:40 +02:00
|
|
|
const uint8_t RAM[] PROGMEM = { 0, 8, 16, 32 };
|
|
|
|
uint8_t ramlo = 0; // Lowest Entry
|
|
|
|
uint8_t ramhi = 3; // Highest Entry
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2023-06-27 09:43:40 +02:00
|
|
|
uint16_t banks;
|
|
|
|
uint16_t prg;
|
|
|
|
uint16_t chr;
|
|
|
|
uint8_t ram;
|
2023-04-30 13:42:16 +02:00
|
|
|
bool vrc4e = false;
|
2023-06-27 09:43:40 +02:00
|
|
|
uint8_t prgchk0;
|
|
|
|
uint8_t prgchk1;
|
2023-04-30 13:42:16 +02:00
|
|
|
bool mmc6 = false;
|
2023-06-27 09:43:40 +02:00
|
|
|
uint8_t prgchk2;
|
|
|
|
uint8_t prgchk3;
|
2022-10-22 10:25:37 +02:00
|
|
|
word eepsize;
|
2023-06-27 09:43:40 +02:00
|
|
|
uint8_t bytecheck;
|
|
|
|
uint8_t firstbyte;
|
2023-04-30 13:42:16 +02:00
|
|
|
bool flashfound = false; // NESmaker 39SF040 Flash Cart
|
2019-09-05 00:48:39 +02:00
|
|
|
|
|
|
|
// Cartridge Config
|
2023-06-27 09:43:40 +02:00
|
|
|
uint8_t mapper;
|
|
|
|
uint8_t prgsize;
|
|
|
|
uint8_t chrsize;
|
|
|
|
uint8_t ramsize;
|
2019-09-05 00:48:39 +02:00
|
|
|
|
|
|
|
/******************************************
|
2022-09-25 11:09:54 +02:00
|
|
|
Menus
|
2019-09-05 00:48:39 +02:00
|
|
|
*****************************************/
|
2022-03-08 20:44:14 +01:00
|
|
|
// NES start menu
|
2022-10-07 10:15:18 +02:00
|
|
|
static const char nesMenuItem1[] PROGMEM = "Read iNES Rom";
|
|
|
|
static const char nesMenuItem2[] PROGMEM = "Read PRG/CHR";
|
|
|
|
static const char nesMenuItem5[] PROGMEM = "Change Mapper";
|
2022-07-07 00:15:13 +02:00
|
|
|
static const char nesMenuItem6[] PROGMEM = "Flash NESMaker";
|
2024-03-02 17:26:35 +01:00
|
|
|
static const char* const menuOptionsNES[] PROGMEM = { nesMenuItem1, nesMenuItem2, FSTRING_READ_SAVE, FSTRING_WRITE_SAVE, nesMenuItem5, nesMenuItem6, FSTRING_RESET };
|
2022-03-08 20:44:14 +01:00
|
|
|
|
|
|
|
// NES chips menu
|
2022-10-13 09:49:03 +02:00
|
|
|
static const char nesChipsMenuItem1[] PROGMEM = "Combined PRG+CHR";
|
|
|
|
static const char nesChipsMenuItem2[] PROGMEM = "Read only PRG";
|
|
|
|
static const char nesChipsMenuItem3[] PROGMEM = "Read only CHR";
|
|
|
|
static const char nesChipsMenuItem4[] PROGMEM = "Back";
|
|
|
|
static const char* const menuOptionsNESChips[] PROGMEM = { nesChipsMenuItem1, nesChipsMenuItem2, nesChipsMenuItem3, nesChipsMenuItem4 };
|
2022-03-08 21:01:38 +01:00
|
|
|
|
2019-09-05 00:48:39 +02:00
|
|
|
// NES start menu
|
2019-09-01 14:36:53 +02:00
|
|
|
void nesMenu() {
|
2022-10-23 12:01:09 +02:00
|
|
|
unsigned char answer;
|
|
|
|
|
2022-08-03 12:14:32 +02:00
|
|
|
// create menu with title "NES CART READER" and 7 options to choose from
|
2022-07-07 00:15:13 +02:00
|
|
|
convertPgm(menuOptionsNES, 7);
|
2022-10-23 12:01:09 +02:00
|
|
|
answer = question_box(F("NES CART READER"), menuOptions, 7, 0);
|
2019-09-05 00:48:39 +02:00
|
|
|
|
|
|
|
// wait for user choice to come back from the question box menu
|
|
|
|
switch (answer) {
|
2022-07-07 00:15:13 +02:00
|
|
|
// Read Rom
|
2022-10-07 10:15:18 +02:00
|
|
|
case 0:
|
2022-07-07 00:15:13 +02:00
|
|
|
display_Clear();
|
|
|
|
// Change working dir to root
|
|
|
|
sd.chdir("/");
|
|
|
|
readRom_NES();
|
2024-03-02 17:26:35 +01:00
|
|
|
println_Msg(FS(FSTRING_EMPTY));
|
2022-10-21 15:59:06 +02:00
|
|
|
// Prints string out of the common strings array either with or without newline
|
|
|
|
print_STR(press_button_STR, 1);
|
2024-03-02 17:26:35 +01:00
|
|
|
#ifdef ENABLE_GLOBAL_LOG
|
2022-06-16 15:15:43 +02:00
|
|
|
save_log();
|
2022-07-07 00:15:13 +02:00
|
|
|
#endif
|
|
|
|
display_Update();
|
|
|
|
wait();
|
2019-09-05 00:48:39 +02:00
|
|
|
break;
|
|
|
|
|
2022-08-03 12:14:32 +02:00
|
|
|
// Read single chip
|
2022-10-07 10:15:18 +02:00
|
|
|
case 1:
|
2022-08-03 12:14:32 +02:00
|
|
|
nesChipMenu();
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Read RAM
|
2022-10-07 10:15:18 +02:00
|
|
|
case 2:
|
2023-06-26 17:05:10 +02:00
|
|
|
sd.chdir();
|
|
|
|
sprintf(folder, "NES/SAVE");
|
|
|
|
sd.mkdir(folder, true);
|
|
|
|
sd.chdir(folder);
|
2022-07-07 00:15:13 +02:00
|
|
|
readRAM();
|
2019-09-05 00:48:39 +02:00
|
|
|
resetROM();
|
2024-03-02 17:26:35 +01:00
|
|
|
println_Msg(FS(FSTRING_EMPTY));
|
2022-10-21 15:59:06 +02:00
|
|
|
// Prints string out of the common strings array either with or without newline
|
|
|
|
print_STR(press_button_STR, 1);
|
2022-03-08 20:44:14 +01:00
|
|
|
display_Update();
|
2019-09-05 00:48:39 +02:00
|
|
|
wait();
|
|
|
|
break;
|
2019-11-25 11:53:45 +01:00
|
|
|
|
2022-07-07 00:15:13 +02:00
|
|
|
// Write RAM
|
2022-10-07 10:15:18 +02:00
|
|
|
case 3:
|
2022-07-07 00:15:13 +02:00
|
|
|
writeRAM();
|
2019-11-25 11:53:45 +01:00
|
|
|
resetROM();
|
2024-03-02 17:26:35 +01:00
|
|
|
println_Msg(FS(FSTRING_EMPTY));
|
2022-10-21 15:59:06 +02:00
|
|
|
// Prints string out of the common strings array either with or without newline
|
|
|
|
print_STR(press_button_STR, 1);
|
2022-03-08 20:44:14 +01:00
|
|
|
display_Update();
|
2019-11-25 11:53:45 +01:00
|
|
|
wait();
|
|
|
|
break;
|
|
|
|
|
2022-10-07 10:15:18 +02:00
|
|
|
// Change Mapper
|
|
|
|
case 4:
|
2022-10-23 12:01:09 +02:00
|
|
|
setDefaultRomName();
|
2022-10-07 10:15:18 +02:00
|
|
|
setMapper();
|
|
|
|
checkMapperSize();
|
|
|
|
setPRGSize();
|
|
|
|
setCHRSize();
|
|
|
|
setRAMSize();
|
|
|
|
checkStatus_NES();
|
|
|
|
break;
|
|
|
|
|
2022-07-07 00:15:13 +02:00
|
|
|
// Write FLASH
|
|
|
|
case 5:
|
|
|
|
if (mapper == 30) {
|
|
|
|
writeFLASH();
|
|
|
|
resetROM();
|
2022-10-13 09:49:03 +02:00
|
|
|
} else {
|
2022-07-07 00:15:13 +02:00
|
|
|
display_Clear();
|
2024-05-03 21:56:22 +02:00
|
|
|
println_Msg(FS(string_error5));
|
2022-07-07 00:15:13 +02:00
|
|
|
println_Msg(F("Can't write to this cartridge"));
|
2024-03-02 17:26:35 +01:00
|
|
|
println_Msg(FS(FSTRING_EMPTY));
|
2022-10-21 15:59:06 +02:00
|
|
|
// Prints string out of the common strings array either with or without newline
|
|
|
|
print_STR(press_button_STR, 1);
|
2022-07-07 00:15:13 +02:00
|
|
|
display_Update();
|
|
|
|
}
|
2019-11-25 11:53:45 +01:00
|
|
|
wait();
|
|
|
|
break;
|
2022-07-07 00:15:13 +02:00
|
|
|
|
|
|
|
// Reset
|
|
|
|
case 6:
|
|
|
|
resetArduino();
|
|
|
|
break;
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2019-09-01 14:36:53 +02:00
|
|
|
}
|
|
|
|
|
2022-07-07 00:15:13 +02:00
|
|
|
void nesChipMenu() {
|
|
|
|
// create menu with title "Select NES Chip" and 4 options to choose from
|
2022-08-03 12:14:32 +02:00
|
|
|
convertPgm(menuOptionsNESChips, 4);
|
|
|
|
unsigned char answer = question_box(F("Select NES Chip"), menuOptions, 4, 0);
|
2022-03-08 21:01:38 +01:00
|
|
|
|
|
|
|
// wait for user choice to come back from the question box menu
|
|
|
|
switch (answer) {
|
2022-08-03 12:14:32 +02:00
|
|
|
// Read combined PRG/CHR
|
2022-03-08 21:01:38 +01:00
|
|
|
case 0:
|
2022-08-03 12:14:32 +02:00
|
|
|
display_Clear();
|
|
|
|
// Change working dir to root
|
|
|
|
sd.chdir("/");
|
|
|
|
readRaw_NES();
|
2024-03-02 17:26:35 +01:00
|
|
|
println_Msg(FS(FSTRING_EMPTY));
|
2022-10-21 15:59:06 +02:00
|
|
|
// Prints string out of the common strings array either with or without newline
|
|
|
|
print_STR(press_button_STR, 1);
|
2024-03-02 17:26:35 +01:00
|
|
|
#ifdef ENABLE_GLOBAL_LOG
|
2022-08-03 12:14:32 +02:00
|
|
|
save_log();
|
|
|
|
#endif
|
2022-03-08 21:01:38 +01:00
|
|
|
display_Update();
|
|
|
|
wait();
|
|
|
|
break;
|
|
|
|
|
2022-08-03 12:14:32 +02:00
|
|
|
// Read PRG
|
2022-03-08 21:01:38 +01:00
|
|
|
case 1:
|
2022-08-03 12:14:32 +02:00
|
|
|
CreateROMFolderInSD();
|
|
|
|
readPRG(false);
|
|
|
|
resetROM();
|
2024-03-02 17:26:35 +01:00
|
|
|
println_Msg(FS(FSTRING_EMPTY));
|
2022-10-21 15:59:06 +02:00
|
|
|
// Prints string out of the common strings array either with or without newline
|
|
|
|
print_STR(press_button_STR, 1);
|
2022-08-03 12:14:32 +02:00
|
|
|
display_Update();
|
|
|
|
wait();
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Read CHR
|
|
|
|
case 2:
|
2022-07-07 00:15:13 +02:00
|
|
|
CreateROMFolderInSD();
|
2022-07-07 00:51:44 +02:00
|
|
|
readCHR(false);
|
2022-07-07 00:15:13 +02:00
|
|
|
resetROM();
|
2024-03-02 17:26:35 +01:00
|
|
|
println_Msg(FS(FSTRING_EMPTY));
|
2022-10-21 15:59:06 +02:00
|
|
|
// Prints string out of the common strings array either with or without newline
|
|
|
|
print_STR(press_button_STR, 1);
|
2022-07-07 00:15:13 +02:00
|
|
|
display_Update();
|
2022-03-08 21:01:38 +01:00
|
|
|
wait();
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Return to Main Menu
|
2022-08-03 12:14:32 +02:00
|
|
|
case 3:
|
2022-03-08 21:01:38 +01:00
|
|
|
nesMenu();
|
|
|
|
wait();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-01 14:36:53 +02:00
|
|
|
/******************************************
|
|
|
|
Setup
|
|
|
|
*****************************************/
|
2019-09-05 00:48:39 +02:00
|
|
|
void setup_NES() {
|
2023-06-26 21:25:54 +02:00
|
|
|
// Request 5V
|
2023-06-26 12:04:00 +02:00
|
|
|
setVoltage(VOLTS_SET_5V);
|
|
|
|
|
2019-09-05 00:48:39 +02:00
|
|
|
// CPU R/W, IRQ, PPU /RD, PPU /A13, CIRAM /CE, PPU /WR, /ROMSEL, PHI2
|
|
|
|
DDRF = 0b10110111;
|
|
|
|
// CPU R/W, IRQ, PPU /RD, PPU /A13, CIRAM /CE, PPU /WR, /ROMSEL, PHI2
|
|
|
|
PORTF = 0b11111111;
|
|
|
|
|
|
|
|
// A0-A7 to Output
|
|
|
|
DDRL = 0xFF;
|
|
|
|
// A8-A14 to Output
|
|
|
|
DDRA = 0xFF;
|
|
|
|
|
|
|
|
// Set CIRAM A10 to Input
|
|
|
|
DDRC &= ~(1 << 2);
|
|
|
|
// Activate Internal Pullup Resistors
|
|
|
|
PORTC |= (1 << 2);
|
|
|
|
|
|
|
|
// Set D0-D7 to Input
|
|
|
|
PORTK = 0xFF;
|
|
|
|
DDRK = 0;
|
|
|
|
|
|
|
|
set_address(0);
|
|
|
|
LED_RED_OFF;
|
|
|
|
LED_GREEN_OFF;
|
|
|
|
LED_BLUE_OFF;
|
|
|
|
}
|
2019-09-01 14:36:53 +02:00
|
|
|
|
2022-07-07 00:15:13 +02:00
|
|
|
/******************************************
|
2023-06-26 17:05:10 +02:00
|
|
|
Get Mapping from SD database
|
2022-07-07 00:15:13 +02:00
|
|
|
*****************************************/
|
|
|
|
uint32_t uppow2(uint32_t n) {
|
2023-06-27 09:43:40 +02:00
|
|
|
for (int8_t x = 31; x >= 0; x--)
|
2022-10-13 09:49:03 +02:00
|
|
|
if (n & (1u << x)) {
|
2022-07-07 00:15:13 +02:00
|
|
|
if ((1u << x) != n)
|
|
|
|
return (1u << (x + 1));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2022-10-23 12:01:09 +02:00
|
|
|
struct database_entry {
|
|
|
|
char filename[128];
|
|
|
|
char crc_str[8 + 1 + 8 + 1 + 32 + 1];
|
|
|
|
uint32_t crc;
|
2022-10-28 15:02:51 +02:00
|
|
|
char* crc512_str;
|
2022-10-23 12:01:09 +02:00
|
|
|
uint32_t crc512;
|
2022-10-28 15:02:51 +02:00
|
|
|
char* iNES_str;
|
2022-10-23 12:01:09 +02:00
|
|
|
};
|
|
|
|
|
2022-10-07 10:15:18 +02:00
|
|
|
void printPRG(unsigned long myOffset) {
|
2022-10-04 15:48:11 +02:00
|
|
|
display_Clear();
|
2022-10-07 10:15:18 +02:00
|
|
|
print_Msg(F("Printing PRG at "));
|
|
|
|
println_Msg(myOffset);
|
2022-10-04 15:48:11 +02:00
|
|
|
|
|
|
|
char myBuffer[3];
|
|
|
|
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t currLine = 0; currLine < 512; currLine += 16) {
|
|
|
|
for (uint8_t currByte = 0; currByte < 16; currByte++) {
|
2022-10-13 09:49:03 +02:00
|
|
|
itoa(read_prg_byte(myOffset + currLine + currByte), myBuffer, 16);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < 2 - strlen(myBuffer); i++) {
|
2022-10-04 15:48:11 +02:00
|
|
|
print_Msg(F("0"));
|
|
|
|
}
|
|
|
|
// Now print the significant bits
|
|
|
|
print_Msg(myBuffer);
|
|
|
|
print_Msg(" ");
|
|
|
|
}
|
|
|
|
println_Msg("");
|
|
|
|
}
|
|
|
|
display_Update();
|
|
|
|
}
|
|
|
|
|
2022-10-23 12:01:09 +02:00
|
|
|
void setDefaultRomName() {
|
|
|
|
romName[0] = 'C';
|
|
|
|
romName[1] = 'A';
|
|
|
|
romName[2] = 'R';
|
|
|
|
romName[3] = 'T';
|
|
|
|
romName[4] = '\0';
|
|
|
|
}
|
2022-07-07 00:15:13 +02:00
|
|
|
|
2022-10-28 15:02:51 +02:00
|
|
|
void setRomnameFromString(const char* input) {
|
2023-06-27 09:43:40 +02:00
|
|
|
uint8_t myLength = 0;
|
|
|
|
for (uint8_t i = 0; i < 20 && myLength < 15; i++) {
|
2022-10-23 12:01:09 +02:00
|
|
|
// Stop at first "(" to remove "(Country)"
|
|
|
|
if (input[i] == '(') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (
|
2022-10-28 15:02:51 +02:00
|
|
|
(input[i] >= '0' && input[i] <= '9') || (input[i] >= 'A' && input[i] <= 'Z') || (input[i] >= 'a' && input[i] <= 'z')) {
|
2022-10-23 12:01:09 +02:00
|
|
|
romName[myLength++] = input[i];
|
|
|
|
}
|
2022-07-07 00:15:13 +02:00
|
|
|
}
|
|
|
|
|
2022-10-23 12:01:09 +02:00
|
|
|
// If name consists out of all japanese characters use CART as name
|
|
|
|
if (myLength == 0) {
|
|
|
|
setDefaultRomName();
|
2022-07-07 00:15:13 +02:00
|
|
|
}
|
2022-10-23 12:01:09 +02:00
|
|
|
}
|
|
|
|
|
2024-05-03 19:12:48 +02:00
|
|
|
void printDataLine_NES(void* entry) {
|
|
|
|
struct database_entry* castEntry = (struct database_entry*) entry;
|
2024-04-28 13:35:21 +02:00
|
|
|
uint8_t iNES[16];
|
|
|
|
uint8_t* output;
|
|
|
|
char* input;
|
|
|
|
|
2024-05-03 19:12:48 +02:00
|
|
|
input = castEntry->iNES_str;
|
2024-04-28 13:35:21 +02:00
|
|
|
output = iNES;
|
|
|
|
for (uint8_t i = 0; i < sizeof(iNES); i++) {
|
|
|
|
unsigned int buf;
|
|
|
|
|
|
|
|
sscanf(input, "%2X", &buf);
|
|
|
|
*(output++) = buf;
|
|
|
|
input += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
mapper = (iNES[6] >> 4) | (iNES[7] & 0xF0) | (iNES[8] & 0x0F);
|
|
|
|
|
|
|
|
if ((iNES[9] & 0x0F) != 0x0F) {
|
|
|
|
// simple notation
|
|
|
|
prgsize = (iNES[4] | ((iNES[9] & 0x0F) << 8)); //*16
|
|
|
|
} else {
|
|
|
|
// exponent-multiplier notation
|
|
|
|
prgsize = (((1 << (iNES[4] >> 2)) * ((iNES[4] & 0b11) * 2 + 1)) >> 14); //*16
|
|
|
|
}
|
|
|
|
if (prgsize != 0)
|
|
|
|
prgsize = (int(log(prgsize) / log(2)));
|
|
|
|
|
|
|
|
if ((iNES[9] & 0xF0) != 0xF0) {
|
|
|
|
// simple notation
|
|
|
|
chrsize = (uppow2(iNES[5] | ((iNES[9] & 0xF0) << 4))) * 2; //*4
|
|
|
|
} else {
|
|
|
|
// exponent-multiplier notation
|
|
|
|
chrsize = (((1 << (iNES[5] >> 2)) * ((iNES[5] & 0b11) * 2 + 1)) >> 13) * 2; //*4
|
|
|
|
}
|
|
|
|
if (chrsize != 0)
|
|
|
|
chrsize = (int(log(chrsize) / log(2)));
|
|
|
|
|
|
|
|
ramsize = ((iNES[10] & 0xF0) ? (64 << ((iNES[10] & 0xF0) >> 4)) : 0) / 4096; //*4
|
|
|
|
if (ramsize != 0)
|
|
|
|
ramsize = (int(log(ramsize) / log(2)));
|
|
|
|
|
|
|
|
prg = (int_pow(2, prgsize)) * 16;
|
|
|
|
if (chrsize == 0)
|
|
|
|
chr = 0; // 0K
|
|
|
|
else
|
|
|
|
chr = (int_pow(2, chrsize)) * 4;
|
|
|
|
if (ramsize == 0)
|
|
|
|
ram = 0; // 0K
|
|
|
|
else if (mapper == 82)
|
|
|
|
ram = 5; // 5K
|
|
|
|
else
|
|
|
|
ram = (int_pow(2, ramsize)) * 4;
|
|
|
|
|
|
|
|
// Mapper Variants
|
|
|
|
// Identify variant for use across multiple functions
|
|
|
|
if (mapper == 4) { // Check for MMC6/MMC3
|
|
|
|
checkMMC6();
|
|
|
|
if (mmc6)
|
|
|
|
ram = 1; // 1K
|
|
|
|
}
|
|
|
|
printNESSettings();
|
|
|
|
}
|
|
|
|
|
2022-10-23 12:01:09 +02:00
|
|
|
void getMapping() {
|
|
|
|
FsFile database;
|
|
|
|
uint32_t oldcrc32 = 0xFFFFFFFF;
|
|
|
|
uint32_t oldcrc32MMC3 = 0xFFFFFFFF;
|
2022-07-07 00:15:13 +02:00
|
|
|
char crcStr[9];
|
|
|
|
|
2022-10-23 12:01:09 +02:00
|
|
|
display_Clear();
|
|
|
|
|
|
|
|
sd.chdir();
|
|
|
|
if (!database.open("nes.txt", O_READ)) {
|
2024-05-01 09:06:23 +02:00
|
|
|
print_FatalError(FS(FSTRING_DATABASE_FILE_NOT_FOUND));
|
2022-10-23 12:01:09 +02:00
|
|
|
// never reached
|
2022-10-06 19:58:04 +02:00
|
|
|
}
|
|
|
|
|
2022-10-23 12:01:09 +02:00
|
|
|
// Read first 512 bytes of first and last block of PRG ROM and compute CRC32
|
|
|
|
// MMC3 maps the last 8KB block of PRG ROM to 0xE000 while 0x8000 can contain random data after bootup
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t c = 0; c < 512; c++) {
|
2022-10-23 14:26:40 +02:00
|
|
|
UPDATE_CRC(oldcrc32, read_prg_byte(0x8000 + c));
|
|
|
|
UPDATE_CRC(oldcrc32MMC3, read_prg_byte(0xE000 + c));
|
2022-10-06 19:58:04 +02:00
|
|
|
}
|
2022-10-23 12:01:09 +02:00
|
|
|
oldcrc32 = ~oldcrc32;
|
|
|
|
oldcrc32MMC3 = ~oldcrc32MMC3;
|
2023-04-30 13:42:16 +02:00
|
|
|
bool browseDatabase;
|
2022-09-28 10:13:48 +02:00
|
|
|
|
2022-10-07 10:15:18 +02:00
|
|
|
// Filter out all 0xFF checksums at 0x8000 and 0xE000
|
2022-10-23 12:01:09 +02:00
|
|
|
if (oldcrc32 == 0xBD7BC39F && oldcrc32MMC3 == 0xBD7BC39F) {
|
2022-10-07 10:15:18 +02:00
|
|
|
println_Msg(F("No data found."));
|
2022-09-28 10:13:48 +02:00
|
|
|
println_Msg(F("Using manual selection"));
|
|
|
|
display_Update();
|
2023-05-01 11:57:04 +02:00
|
|
|
delay(500);
|
2022-10-23 12:01:09 +02:00
|
|
|
setDefaultRomName();
|
2022-11-02 00:32:54 +01:00
|
|
|
browseDatabase = selectMapping(database);
|
2022-10-13 09:49:03 +02:00
|
|
|
} else {
|
2022-10-23 12:01:09 +02:00
|
|
|
println_Msg(F("Searching database"));
|
|
|
|
print_Msg(F("for "));
|
|
|
|
sprintf(crcStr, "%08lX", oldcrc32);
|
|
|
|
print_Msg(crcStr);
|
|
|
|
if (oldcrc32 != oldcrc32MMC3) {
|
|
|
|
char crcStrMMC3[9];
|
|
|
|
print_Msg(F(" or "));
|
|
|
|
sprintf(crcStrMMC3, "%08lX", oldcrc32MMC3);
|
|
|
|
print_Msg(crcStrMMC3);
|
|
|
|
}
|
|
|
|
println_Msg(F("..."));
|
|
|
|
display_Update();
|
|
|
|
while (database.available()) {
|
|
|
|
struct database_entry entry;
|
|
|
|
|
|
|
|
readDatabaseEntry(database, &entry);
|
|
|
|
//if checksum search was successful set mapper and end search, also filter out 0xFF checksum
|
|
|
|
if (
|
2022-10-28 15:02:51 +02:00
|
|
|
entry.crc512 != 0xBD7BC39F && (entry.crc512 == oldcrc32 || entry.crc512 == oldcrc32MMC3)) {
|
2022-10-23 12:01:09 +02:00
|
|
|
// Rewind to start of entry
|
|
|
|
rewind_line(database, 3);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-11-05 01:37:44 +01:00
|
|
|
if (database.available()) {
|
2022-11-18 10:46:13 +01:00
|
|
|
browseDatabase = true;
|
2022-11-05 01:37:44 +01:00
|
|
|
} else {
|
2022-10-23 12:01:09 +02:00
|
|
|
// File searched until end but nothing found
|
2024-03-02 17:26:35 +01:00
|
|
|
println_Msg(FS(FSTRING_EMPTY));
|
2022-10-23 12:01:09 +02:00
|
|
|
println_Msg(F("CRC not found in database"));
|
|
|
|
println_Msg(F("Using manual selection"));
|
|
|
|
display_Update();
|
|
|
|
delay(500);
|
2023-04-12 09:54:24 +02:00
|
|
|
// Print content of PRG for debugging
|
|
|
|
//printPRG(0x8000);
|
|
|
|
//printPRG(0xE000);
|
2022-07-07 00:15:13 +02:00
|
|
|
|
2022-10-23 12:01:09 +02:00
|
|
|
// Change ROM name to CART
|
|
|
|
setDefaultRomName();
|
2022-11-02 00:32:54 +01:00
|
|
|
browseDatabase = selectMapping(database);
|
2022-10-23 12:01:09 +02:00
|
|
|
}
|
|
|
|
}
|
2022-11-02 00:32:54 +01:00
|
|
|
if (browseDatabase) {
|
2024-04-28 13:35:21 +02:00
|
|
|
struct database_entry entry;
|
2022-09-18 19:26:43 +02:00
|
|
|
|
2024-04-28 13:35:21 +02:00
|
|
|
if(checkCartSelection(database, &readDataLine_NES, &entry, &printDataLine_NES, &setRomnameFromString)) {
|
2022-11-02 00:32:54 +01:00
|
|
|
// anything else: select current record
|
|
|
|
// Save Mapper
|
|
|
|
EEPROM_writeAnything(7, mapper);
|
|
|
|
EEPROM_writeAnything(8, prgsize);
|
|
|
|
EEPROM_writeAnything(9, chrsize);
|
|
|
|
EEPROM_writeAnything(10, ramsize);
|
2022-07-07 00:15:13 +02:00
|
|
|
}
|
2022-10-23 12:01:09 +02:00
|
|
|
}
|
|
|
|
database.close();
|
2022-07-07 00:15:13 +02:00
|
|
|
}
|
|
|
|
|
2022-10-28 15:02:51 +02:00
|
|
|
static void readDatabaseEntry(FsFile& database, struct database_entry* entry) {
|
2022-10-23 12:01:09 +02:00
|
|
|
get_line(entry->filename, &database, sizeof(entry->filename));
|
2024-04-28 13:35:21 +02:00
|
|
|
readDataLine_NES(database, entry);
|
2022-10-23 12:01:09 +02:00
|
|
|
skip_line(&database);
|
2024-04-28 13:35:21 +02:00
|
|
|
}
|
|
|
|
|
2024-05-03 19:12:48 +02:00
|
|
|
void readDataLine_NES(FsFile& database, void* e) {
|
|
|
|
struct database_entry* entry = (database_entry*)e;
|
2024-04-28 13:35:21 +02:00
|
|
|
get_line(entry->crc_str, &database, sizeof(entry->crc_str));
|
2022-08-06 14:50:40 +02:00
|
|
|
|
2022-10-23 12:01:09 +02:00
|
|
|
entry->crc_str[8] = 0;
|
|
|
|
entry->crc512_str = &entry->crc_str[8 + 1];
|
|
|
|
entry->crc512_str[8] = 0;
|
|
|
|
entry->iNES_str = &entry->crc_str[8 + 1 + 8 + 1];
|
2023-06-26 19:34:55 +02:00
|
|
|
|
|
|
|
// Convert "4E4553" to (0x4E, 0x45, 0x53)
|
|
|
|
unsigned int iNES_BUF;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (uint8_t j = 0; j < 16; j++) {
|
2023-06-26 19:34:55 +02:00
|
|
|
sscanf(entry->iNES_str + j * 2, "%2X", &iNES_BUF);
|
|
|
|
iNES_HEADER[j] = iNES_BUF;
|
|
|
|
}
|
|
|
|
|
2022-10-23 12:01:09 +02:00
|
|
|
entry->crc = strtoul(entry->crc_str, NULL, 16);
|
|
|
|
entry->crc512 = strtoul(entry->crc512_str, NULL, 16);
|
|
|
|
}
|
|
|
|
|
2023-04-30 13:42:16 +02:00
|
|
|
bool selectMapping(FsFile& database) {
|
2022-08-06 14:50:40 +02:00
|
|
|
// Select starting letter
|
2024-04-24 19:55:43 +02:00
|
|
|
byte myLetter = starting_letter();
|
2022-08-06 14:50:40 +02:00
|
|
|
|
2022-10-07 10:15:18 +02:00
|
|
|
if (myLetter == 27) {
|
|
|
|
// Change Mapper
|
|
|
|
setMapper();
|
|
|
|
checkMapperSize();
|
|
|
|
setPRGSize();
|
|
|
|
setCHRSize();
|
|
|
|
setRAMSize();
|
2022-11-02 00:32:54 +01:00
|
|
|
return 0;
|
2022-10-13 09:49:03 +02:00
|
|
|
} else {
|
2024-04-24 19:55:43 +02:00
|
|
|
seek_first_letter_in_database(database, myLetter);
|
2022-08-06 14:50:40 +02:00
|
|
|
}
|
2022-11-02 00:32:54 +01:00
|
|
|
return 1;
|
2022-08-06 14:50:40 +02:00
|
|
|
}
|
|
|
|
|
2024-05-03 21:56:22 +02:00
|
|
|
void read_NES(const char* fileSuffix, const byte* header, const uint8_t headersize, const boolean renamerom) {
|
2024-05-12 15:37:11 +02:00
|
|
|
// Get name, add extension and convert to char array for sd lib
|
|
|
|
createFolder("NES", "ROM", romName, fileSuffix);
|
2022-07-07 00:15:13 +02:00
|
|
|
|
|
|
|
display_Clear();
|
2022-10-21 15:59:06 +02:00
|
|
|
print_STR(saving_to_STR, 0);
|
2022-07-07 00:15:13 +02:00
|
|
|
print_Msg(folder);
|
|
|
|
println_Msg(F("/..."));
|
|
|
|
display_Update();
|
|
|
|
|
|
|
|
// write new folder number back to eeprom
|
|
|
|
foldern = foldern + 1;
|
|
|
|
EEPROM_writeAnything(0, foldern);
|
|
|
|
|
|
|
|
// Open file on sd card
|
|
|
|
if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
|
2022-10-30 03:21:01 +01:00
|
|
|
print_FatalError(sd_error_STR);
|
2022-07-07 00:15:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Initialize progress bar
|
|
|
|
uint32_t processedProgressBar = 0;
|
2024-05-03 21:56:22 +02:00
|
|
|
uint32_t totalProgressBar = (uint32_t)(headersize + prgsize * 16 * 1024 + chrsize * 4 * 1024);
|
2022-07-07 00:15:13 +02:00
|
|
|
draw_progressbar(0, totalProgressBar);
|
|
|
|
|
2024-05-03 21:56:22 +02:00
|
|
|
//Write header
|
|
|
|
if(headersize > 0) {
|
|
|
|
myFile.write(header, headersize);
|
2022-07-07 00:15:13 +02:00
|
|
|
|
2024-05-03 21:56:22 +02:00
|
|
|
// update progress bar
|
|
|
|
processedProgressBar += headersize;
|
|
|
|
draw_progressbar(processedProgressBar, totalProgressBar);
|
|
|
|
}
|
2022-07-07 00:15:13 +02:00
|
|
|
|
|
|
|
//Write PRG
|
2022-07-07 00:51:44 +02:00
|
|
|
readPRG(true);
|
2022-07-07 00:15:13 +02:00
|
|
|
|
|
|
|
// update progress bar
|
|
|
|
processedProgressBar += prgsize * 16 * 1024;
|
|
|
|
draw_progressbar(processedProgressBar, totalProgressBar);
|
|
|
|
|
|
|
|
//Write CHR
|
2022-07-07 00:51:44 +02:00
|
|
|
readCHR(true);
|
2022-07-07 00:15:13 +02:00
|
|
|
|
|
|
|
// update progress bar
|
|
|
|
processedProgressBar += chrsize * 4 * 1024;
|
|
|
|
draw_progressbar(processedProgressBar, totalProgressBar);
|
|
|
|
|
|
|
|
// Close the file:
|
|
|
|
myFile.close();
|
|
|
|
|
|
|
|
// Compare CRC32 with database
|
2024-05-03 21:56:22 +02:00
|
|
|
compareCRC("nes.txt", 0, renamerom, headersize);
|
2022-08-03 12:14:32 +02:00
|
|
|
}
|
|
|
|
|
2024-05-03 21:56:22 +02:00
|
|
|
void readRom_NES() {
|
2024-05-12 15:37:11 +02:00
|
|
|
read_NES("nes", iNES_HEADER, 16, true);
|
2024-05-03 21:56:22 +02:00
|
|
|
}
|
2022-08-03 12:14:32 +02:00
|
|
|
|
2024-05-03 21:56:22 +02:00
|
|
|
void readRaw_NES() {
|
2024-05-12 15:37:11 +02:00
|
|
|
read_NES("bin", NULL, 0, false);
|
2022-07-07 00:15:13 +02:00
|
|
|
}
|
|
|
|
|
2019-09-01 14:36:53 +02:00
|
|
|
/******************************************
|
2019-09-05 00:48:39 +02:00
|
|
|
Low Level Functions
|
|
|
|
*****************************************/
|
|
|
|
static void set_address(unsigned int address) {
|
|
|
|
unsigned char l = address & 0xFF;
|
|
|
|
unsigned char h = address >> 8;
|
|
|
|
PORTL = l;
|
|
|
|
PORTA = h;
|
|
|
|
|
|
|
|
// PPU /A13
|
|
|
|
if ((address >> 13) & 1)
|
|
|
|
PORTF &= ~(1 << 4);
|
|
|
|
else
|
|
|
|
PORTF |= 1 << 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_romsel(unsigned int address) {
|
|
|
|
if (address & 0x8000) {
|
|
|
|
ROMSEL_LOW;
|
|
|
|
} else {
|
|
|
|
ROMSEL_HI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned char read_prg_byte(unsigned int address) {
|
|
|
|
MODE_READ;
|
|
|
|
PRG_READ;
|
|
|
|
set_address(address);
|
|
|
|
PHI2_HI;
|
|
|
|
set_romsel(address);
|
|
|
|
_delay_us(1);
|
|
|
|
return PINK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned char read_chr_byte(unsigned int address) {
|
|
|
|
MODE_READ;
|
|
|
|
PHI2_HI;
|
|
|
|
ROMSEL_HI;
|
|
|
|
set_address(address);
|
|
|
|
CHR_READ_LOW;
|
|
|
|
_delay_us(1);
|
|
|
|
uint8_t result = PINK;
|
|
|
|
CHR_READ_HI;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_prg_byte(unsigned int address, uint8_t data) {
|
|
|
|
PHI2_LOW;
|
|
|
|
ROMSEL_HI;
|
|
|
|
MODE_WRITE;
|
|
|
|
PRG_WRITE;
|
|
|
|
PORTK = data;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
set_address(address); // PHI2 low, ROMSEL always HIGH
|
2019-09-05 00:48:39 +02:00
|
|
|
// _delay_us(1);
|
|
|
|
PHI2_HI;
|
|
|
|
//_delay_us(10);
|
2022-10-13 09:49:03 +02:00
|
|
|
set_romsel(address); // ROMSEL is low if need, PHI2 high
|
|
|
|
_delay_us(1); // WRITING
|
2019-09-05 00:48:39 +02:00
|
|
|
//_delay_ms(1); // WRITING
|
|
|
|
// PHI2 low, ROMSEL high
|
|
|
|
PHI2_LOW;
|
|
|
|
_delay_us(1);
|
|
|
|
ROMSEL_HI;
|
|
|
|
// Back to read mode
|
|
|
|
// _delay_us(1);
|
|
|
|
PRG_READ;
|
|
|
|
MODE_READ;
|
|
|
|
set_address(0);
|
|
|
|
// Set phi2 to high state to keep cartridge unreseted
|
|
|
|
// _delay_us(1);
|
|
|
|
PHI2_HI;
|
|
|
|
// _delay_us(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void resetROM() {
|
|
|
|
set_address(0);
|
|
|
|
PHI2_HI;
|
|
|
|
ROMSEL_HI;
|
|
|
|
}
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
void write_mmc1_byte(unsigned int address, uint8_t data) { // write loop for 5 bit register
|
2019-09-05 00:48:39 +02:00
|
|
|
if (address >= 0xE000) {
|
2023-06-27 09:43:40 +02:00
|
|
|
for (uint8_t i = 0; i < 5; i++) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_reg_byte(address, data >> i); // shift 1 bit into temp register [WRITE RAM SAFE]
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
} else {
|
2023-06-27 09:43:40 +02:00
|
|
|
for (uint8_t j = 0; j < 5; j++) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(address, data >> j); // shift 1 bit into temp register
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// REFERENCE FOR REGISTER WRITE TO 0xE000/0xF000
|
|
|
|
// PORTF 7 = CPU R/W = 0
|
|
|
|
// PORTF 6 = /IRQ = 1
|
|
|
|
// PORTF 5 = PPU /RD = 1
|
|
|
|
// PORTF 4 = PPU /A13 = 1
|
|
|
|
// PORTF 3 = CIRAM /CE = 1
|
|
|
|
// PORTF 2 = PPU /WR = 1
|
|
|
|
// PORTF 1 = /ROMSEL
|
|
|
|
// PORTF 0 = PHI2 (M2)
|
|
|
|
|
|
|
|
// WRITE RAM SAFE TO REGISTERS 0xE000/0xF000
|
2022-10-13 09:49:03 +02:00
|
|
|
static void write_reg_byte(unsigned int address, uint8_t data) { // FIX FOR MMC1 RAM CORRUPTION
|
2019-09-05 00:48:39 +02:00
|
|
|
PHI2_LOW;
|
2022-10-13 09:49:03 +02:00
|
|
|
ROMSEL_HI; // A15 HI = E000
|
2019-09-05 00:48:39 +02:00
|
|
|
MODE_WRITE;
|
2022-10-13 09:49:03 +02:00
|
|
|
PRG_WRITE; // CPU R/W LO
|
2019-09-05 00:48:39 +02:00
|
|
|
PORTK = data;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
set_address(address); // PHI2 low, ROMSEL always HIGH
|
2019-09-05 00:48:39 +02:00
|
|
|
// DIRECT PIN TO PREVENT RAM CORRUPTION
|
|
|
|
// DIFFERENCE BETWEEN M2 LO AND ROMSEL HI MUST BE AROUND 33ns
|
|
|
|
// IF TIME IS GREATER THAN 33ns THEN WRITES TO 0xE000/0xF000 WILL CORRUPT RAM AT 0x6000/0x7000
|
2022-10-13 09:49:03 +02:00
|
|
|
PORTF = 0b01111101; // ROMSEL LO/M2 HI
|
|
|
|
PORTF = 0b01111110; // ROMSEL HI/M2 LO
|
2019-09-05 00:48:39 +02:00
|
|
|
_delay_us(1);
|
|
|
|
// Back to read mode
|
|
|
|
PRG_READ;
|
|
|
|
MODE_READ;
|
|
|
|
set_address(0);
|
|
|
|
// Set phi2 to high state to keep cartridge unreseted
|
|
|
|
PHI2_HI;
|
|
|
|
}
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
static void write_ram_byte(unsigned int address, uint8_t data) { // Mapper 19 (Namco 106/163) WRITE RAM SAFE ($E000-$FFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
PHI2_LOW;
|
|
|
|
ROMSEL_HI;
|
|
|
|
MODE_WRITE;
|
|
|
|
PRG_WRITE;
|
|
|
|
PORTK = data;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
set_address(address); // PHI2 low, ROMSEL always HIGH
|
2019-09-05 00:48:39 +02:00
|
|
|
PHI2_HI;
|
2022-10-13 09:49:03 +02:00
|
|
|
ROMSEL_LOW; // SET /ROMSEL LOW OTHERWISE CORRUPTS RAM
|
|
|
|
_delay_us(1); // WRITING
|
2019-09-05 00:48:39 +02:00
|
|
|
// PHI2 low, ROMSEL high
|
|
|
|
PHI2_LOW;
|
|
|
|
_delay_us(1);
|
|
|
|
ROMSEL_HI;
|
|
|
|
// Back to read mode
|
|
|
|
PRG_READ;
|
|
|
|
MODE_READ;
|
|
|
|
set_address(0);
|
|
|
|
// Set phi2 to high state to keep cartridge unreseted
|
|
|
|
PHI2_HI;
|
|
|
|
}
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
static void write_wram_byte(unsigned int address, uint8_t data) { // Mapper 5 (MMC5) RAM
|
2019-09-05 00:48:39 +02:00
|
|
|
PHI2_LOW;
|
|
|
|
ROMSEL_HI;
|
|
|
|
set_address(address);
|
|
|
|
PORTK = data;
|
|
|
|
|
|
|
|
_delay_us(1);
|
|
|
|
MODE_WRITE;
|
|
|
|
PRG_WRITE;
|
|
|
|
PHI2_HI;
|
2022-10-13 09:49:03 +02:00
|
|
|
_delay_us(1); // WRITING
|
2019-09-05 00:48:39 +02:00
|
|
|
PHI2_LOW;
|
|
|
|
ROMSEL_HI;
|
|
|
|
// Back to read mode
|
|
|
|
PRG_READ;
|
|
|
|
MODE_READ;
|
|
|
|
set_address(0);
|
|
|
|
// Set phi2 to high state to keep cartridge unreseted
|
|
|
|
PHI2_HI;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************
|
|
|
|
File Functions
|
|
|
|
*****************************************/
|
|
|
|
void CreateROMFolderInSD() {
|
|
|
|
sd.chdir();
|
|
|
|
sprintf(folder, "NES/ROM");
|
|
|
|
sd.mkdir(folder, true);
|
|
|
|
sd.chdir(folder);
|
|
|
|
}
|
|
|
|
|
2022-10-31 15:41:29 +01:00
|
|
|
FsFile createNewFile(const char* prefix, const char* extension) {
|
2022-10-29 02:55:32 +02:00
|
|
|
char filename[FILENAME_LENGTH];
|
|
|
|
snprintf_P(filename, sizeof(filename), _file_name_no_number_fmt, prefix, extension);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (uint8_t i = 0; i < 100; i++) {
|
2022-10-29 02:55:32 +02:00
|
|
|
if (!sd.exists(filename)) {
|
|
|
|
return sd.open(fileName, O_RDWR | O_CREAT);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2022-10-29 02:55:32 +02:00
|
|
|
snprintf_P(filename, sizeof(filename), _file_name_with_number_fmt, prefix, i, extension);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2022-10-29 02:55:32 +02:00
|
|
|
// Could not find an available name, recompose the original name and error out.
|
|
|
|
snprintf_P(filename, sizeof(filename), _file_name_no_number_fmt, prefix, extension);
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-10-29 02:55:32 +02:00
|
|
|
LED_RED_ON;
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-10-29 02:55:32 +02:00
|
|
|
display_Clear();
|
|
|
|
print_Msg(filename);
|
|
|
|
println_Msg(F(": no available name"));
|
|
|
|
display_Update();
|
|
|
|
print_FatalError(sd_error_STR);
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-10-29 02:55:32 +02:00
|
|
|
LED_RED_OFF;
|
|
|
|
}
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-10-29 02:55:32 +02:00
|
|
|
void CreatePRGFileInSD() {
|
|
|
|
myFile = createNewFile("PRG", "bin");
|
|
|
|
}
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-10-29 02:55:32 +02:00
|
|
|
void CreateCHRFileInSD() {
|
|
|
|
myFile = createNewFile("CHR", "bin");
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
2023-06-26 15:46:47 +02:00
|
|
|
//createNewFile fails to dump RAM if ROM isn't dumped first
|
|
|
|
//void CreateRAMFileInSD() {
|
|
|
|
//myFile = createNewFile("RAM", "bin");
|
|
|
|
//}
|
|
|
|
//Temporary fix
|
2019-09-05 00:48:39 +02:00
|
|
|
void CreateRAMFileInSD() {
|
2023-06-26 15:46:47 +02:00
|
|
|
char fileCount[3];
|
|
|
|
strcpy(fileName, "RAM");
|
|
|
|
strcat(fileName, ".bin");
|
2023-06-27 09:43:40 +02:00
|
|
|
for (uint8_t i = 0; i < 100; i++) {
|
2023-06-26 15:46:47 +02:00
|
|
|
if (!sd.exists(fileName)) {
|
|
|
|
myFile = sd.open(fileName, O_RDWR | O_CREAT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sprintf(fileCount, "%02d", i);
|
|
|
|
strcpy(fileName, "RAM.");
|
|
|
|
strcat(fileName, fileCount);
|
|
|
|
strcat(fileName, ".bin");
|
|
|
|
}
|
|
|
|
if (!myFile) {
|
|
|
|
LED_RED_ON;
|
|
|
|
|
|
|
|
display_Clear();
|
|
|
|
println_Msg(F("RAM FILE FAILED!"));
|
|
|
|
display_Update();
|
|
|
|
//print_Error(F("SD Error"), true);
|
|
|
|
|
|
|
|
LED_RED_OFF;
|
|
|
|
}
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************
|
|
|
|
Config Functions
|
|
|
|
*****************************************/
|
2024-05-01 21:27:45 +02:00
|
|
|
|
|
|
|
#if defined(ENABLE_LCD)
|
|
|
|
void printMapperSelection_NES(int index) {
|
|
|
|
display_Clear();
|
|
|
|
mapselect = pgm_read_byte(mapsize + index * 7);
|
|
|
|
print_Msg(F("Mapper: "));
|
|
|
|
println_Msg(mapselect);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-09-05 00:48:39 +02:00
|
|
|
void setMapper() {
|
2023-06-27 09:43:40 +02:00
|
|
|
uint8_t newmapper;
|
2024-03-02 17:26:35 +01:00
|
|
|
#ifdef ENABLE_GLOBAL_LOG
|
2022-10-04 21:11:13 +02:00
|
|
|
// Disable log to prevent unnecessary logging
|
2022-10-08 18:19:31 +02:00
|
|
|
println_Log(F("Set Mapper manually"));
|
2022-10-04 21:11:13 +02:00
|
|
|
dont_log = true;
|
|
|
|
#endif
|
|
|
|
|
2021-11-29 13:10:04 +01:00
|
|
|
// OLED
|
2024-03-02 17:26:35 +01:00
|
|
|
#if defined(ENABLE_OLED)
|
2019-09-05 00:48:39 +02:00
|
|
|
chooseMapper:
|
|
|
|
// Read stored mapper
|
|
|
|
EEPROM_readAnything(7, newmapper);
|
2022-10-22 10:25:37 +02:00
|
|
|
if (newmapper > 220)
|
2019-09-05 00:48:39 +02:00
|
|
|
newmapper = 0;
|
|
|
|
// Split into digits
|
2023-06-27 09:43:40 +02:00
|
|
|
uint8_t hundreds = newmapper / 100;
|
|
|
|
uint8_t tens = newmapper / 10 - hundreds * 10;
|
|
|
|
uint8_t units = newmapper - hundreds * 100 - tens * 10;
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-10-08 18:19:31 +02:00
|
|
|
// Cycle through all 3 digits
|
2023-06-27 09:43:40 +02:00
|
|
|
uint8_t digit = 0;
|
2022-10-08 18:19:31 +02:00
|
|
|
while (digit < 3) {
|
|
|
|
display_Clear();
|
|
|
|
println_Msg(F("Select Mapper:"));
|
|
|
|
display.setCursor(23, 20);
|
|
|
|
println_Msg(hundreds);
|
|
|
|
display.setCursor(43, 20);
|
|
|
|
println_Msg(tens);
|
|
|
|
display.setCursor(63, 20);
|
|
|
|
println_Msg(units);
|
|
|
|
println_Msg("");
|
|
|
|
println_Msg("");
|
|
|
|
println_Msg("");
|
2022-10-21 15:59:06 +02:00
|
|
|
print_STR(press_to_change_STR, 1);
|
2022-10-08 18:19:31 +02:00
|
|
|
println_Msg(F("Press right to select"));
|
|
|
|
|
|
|
|
if (digit == 0) {
|
|
|
|
display.setDrawColor(1);
|
|
|
|
display.drawLine(20, 30, 30, 30);
|
|
|
|
display.setDrawColor(0);
|
|
|
|
display.drawLine(40, 30, 50, 30);
|
|
|
|
display.drawLine(60, 30, 70, 30);
|
|
|
|
display.setDrawColor(1);
|
2022-10-13 09:49:03 +02:00
|
|
|
} else if (digit == 1) {
|
2022-10-08 18:19:31 +02:00
|
|
|
display.setDrawColor(0);
|
|
|
|
display.drawLine(20, 30, 30, 30);
|
|
|
|
display.setDrawColor(1);
|
|
|
|
display.drawLine(40, 30, 50, 30);
|
|
|
|
display.setDrawColor(0);
|
|
|
|
display.drawLine(60, 30, 70, 30);
|
|
|
|
display.setDrawColor(1);
|
2022-10-13 09:49:03 +02:00
|
|
|
} else if (digit == 2) {
|
2022-10-08 18:19:31 +02:00
|
|
|
display.setDrawColor(0);
|
|
|
|
display.drawLine(20, 30, 30, 30);
|
|
|
|
display.drawLine(40, 30, 50, 30);
|
|
|
|
display.setDrawColor(1);
|
|
|
|
display.drawLine(60, 30, 70, 30);
|
|
|
|
}
|
|
|
|
display.updateDisplay();
|
2021-11-29 13:10:04 +01:00
|
|
|
|
2022-10-08 18:19:31 +02:00
|
|
|
while (1) {
|
2019-09-05 00:48:39 +02:00
|
|
|
/* Check Button
|
|
|
|
1 click
|
|
|
|
2 doubleClick
|
|
|
|
3 hold
|
|
|
|
4 longHold */
|
2024-03-02 17:26:35 +01:00
|
|
|
uint8_t b = checkButton();
|
2019-09-05 00:48:39 +02:00
|
|
|
|
|
|
|
if (b == 1) {
|
|
|
|
if (digit == 0) {
|
|
|
|
if (hundreds < 2)
|
|
|
|
hundreds++;
|
|
|
|
else
|
|
|
|
hundreds = 0;
|
2022-10-13 09:49:03 +02:00
|
|
|
} else if (digit == 1) {
|
2019-09-05 00:48:39 +02:00
|
|
|
if (hundreds == 2) {
|
|
|
|
if (tens < 1)
|
|
|
|
tens++;
|
|
|
|
else
|
|
|
|
tens = 0;
|
2022-10-13 09:49:03 +02:00
|
|
|
} else {
|
2019-09-05 00:48:39 +02:00
|
|
|
if (tens < 9)
|
|
|
|
tens++;
|
|
|
|
else
|
|
|
|
tens = 0;
|
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
} else if (digit == 2) {
|
2019-09-05 00:48:39 +02:00
|
|
|
if (units < 9)
|
|
|
|
units++;
|
|
|
|
else
|
|
|
|
units = 0;
|
|
|
|
}
|
2022-10-08 18:19:31 +02:00
|
|
|
break;
|
2022-10-13 09:49:03 +02:00
|
|
|
} else if (b == 2) {
|
2019-09-05 00:48:39 +02:00
|
|
|
if (digit == 0) {
|
|
|
|
if (hundreds > 0)
|
|
|
|
hundreds--;
|
|
|
|
else
|
|
|
|
hundreds = 2;
|
2022-10-13 09:49:03 +02:00
|
|
|
} else if (digit == 1) {
|
2019-09-05 00:48:39 +02:00
|
|
|
if (hundreds == 2) {
|
|
|
|
if (tens > 0)
|
|
|
|
tens--;
|
|
|
|
else
|
|
|
|
tens = 1;
|
2022-10-13 09:49:03 +02:00
|
|
|
} else {
|
2019-09-05 00:48:39 +02:00
|
|
|
if (tens > 0)
|
|
|
|
tens--;
|
|
|
|
else
|
|
|
|
tens = 9;
|
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
} else if (digit == 2) {
|
2019-09-05 00:48:39 +02:00
|
|
|
if (units > 0)
|
|
|
|
units--;
|
|
|
|
else
|
|
|
|
units = 9;
|
|
|
|
}
|
2022-10-08 18:19:31 +02:00
|
|
|
break;
|
2022-10-13 09:49:03 +02:00
|
|
|
} else if (b == 3) {
|
2022-10-08 18:19:31 +02:00
|
|
|
digit++;
|
2019-09-05 00:48:39 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-29 13:10:04 +01:00
|
|
|
display_Clear();
|
2019-09-05 00:48:39 +02:00
|
|
|
|
|
|
|
newmapper = hundreds * 100 + tens * 10 + units;
|
|
|
|
|
|
|
|
// Check if valid
|
2023-04-30 13:42:16 +02:00
|
|
|
bool validMapper = 0;
|
2023-06-27 09:43:40 +02:00
|
|
|
uint8_t mapcount = (sizeof(mapsize) / sizeof(mapsize[0])) / 7;
|
|
|
|
for (uint8_t currMaplist = 0; currMaplist < mapcount; currMaplist++) {
|
2019-09-05 00:48:39 +02:00
|
|
|
if (pgm_read_byte(mapsize + currMaplist * 7) == newmapper)
|
|
|
|
validMapper = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validMapper) {
|
|
|
|
errorLvl = 1;
|
2022-07-07 00:15:13 +02:00
|
|
|
display.println(F("Mapper not supported"));
|
2022-10-08 18:19:31 +02:00
|
|
|
display.updateDisplay();
|
2021-10-24 00:41:18 +02:00
|
|
|
wait();
|
2019-09-05 00:48:39 +02:00
|
|
|
goto chooseMapper;
|
|
|
|
}
|
2021-11-29 13:10:04 +01:00
|
|
|
|
|
|
|
// LCD
|
2024-03-02 17:26:35 +01:00
|
|
|
#elif defined(ENABLE_LCD)
|
2024-05-01 21:27:45 +02:00
|
|
|
navigateMenu(0, mapcount - 1, &printMapperSelection_NES);
|
|
|
|
newmapper = mapselect;
|
|
|
|
|
2021-11-29 13:10:04 +01:00
|
|
|
display.setCursor(0, 56 + 8);
|
|
|
|
print_Msg(F("MAPPER "));
|
|
|
|
print_Msg(newmapper);
|
|
|
|
println_Msg(F(" SELECTED"));
|
|
|
|
display_Update();
|
2023-05-01 11:57:04 +02:00
|
|
|
delay(500);
|
2021-11-29 13:10:04 +01:00
|
|
|
|
|
|
|
// Serial Monitor
|
2024-03-02 17:26:35 +01:00
|
|
|
#elif defined(ENABLE_SERIAL)
|
2019-09-05 00:48:39 +02:00
|
|
|
setmapper:
|
|
|
|
String newmap;
|
2023-04-30 13:42:16 +02:00
|
|
|
bool mapfound = false;
|
2019-09-05 00:48:39 +02:00
|
|
|
Serial.println(F("SUPPORTED MAPPERS:"));
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < mapcount; i++) {
|
2020-07-11 13:39:12 +02:00
|
|
|
int index = i * 7;
|
2019-09-05 00:48:39 +02:00
|
|
|
mapselect = pgm_read_byte(mapsize + index);
|
2019-10-17 17:14:08 +02:00
|
|
|
Serial.print("[");
|
2019-09-05 00:48:39 +02:00
|
|
|
Serial.print(mapselect);
|
2019-10-17 17:14:08 +02:00
|
|
|
Serial.print("]");
|
2019-09-05 00:48:39 +02:00
|
|
|
if (i < mapcount - 1) {
|
|
|
|
if ((i != 0) && ((i + 1) % 10 == 0))
|
2024-03-02 17:30:44 +01:00
|
|
|
Serial.println(FS(FSTRING_EMPTY));
|
2019-09-05 00:48:39 +02:00
|
|
|
else
|
|
|
|
Serial.print(F("\t"));
|
2022-10-13 09:49:03 +02:00
|
|
|
} else
|
2024-03-02 17:30:44 +01:00
|
|
|
Serial.println(FS(FSTRING_EMPTY));
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
Serial.print(F("Enter Mapper: "));
|
|
|
|
while (Serial.available() == 0) {}
|
|
|
|
newmap = Serial.readStringUntil('\n');
|
|
|
|
Serial.println(newmap);
|
|
|
|
newmapper = newmap.toInt();
|
2023-06-27 09:43:40 +02:00
|
|
|
for (uint8_t i = 0; i < mapcount; i++) {
|
2020-07-11 13:39:12 +02:00
|
|
|
int index = i * 7;
|
2019-09-05 00:48:39 +02:00
|
|
|
mapselect = pgm_read_byte(mapsize + index);
|
|
|
|
if (newmapper == mapselect)
|
|
|
|
mapfound = true;
|
|
|
|
}
|
|
|
|
if (mapfound == false) {
|
|
|
|
Serial.println(F("MAPPER NOT SUPPORTED!"));
|
2024-03-02 17:30:44 +01:00
|
|
|
Serial.println(FS(FSTRING_EMPTY));
|
2019-09-05 00:48:39 +02:00
|
|
|
newmapper = 0;
|
|
|
|
goto setmapper;
|
|
|
|
}
|
|
|
|
#endif
|
2022-10-08 18:19:31 +02:00
|
|
|
|
2019-09-05 00:48:39 +02:00
|
|
|
EEPROM_writeAnything(7, newmapper);
|
|
|
|
mapper = newmapper;
|
2022-10-04 21:11:13 +02:00
|
|
|
|
2024-03-02 17:26:35 +01:00
|
|
|
#ifdef ENABLE_GLOBAL_LOG
|
2022-10-04 21:11:13 +02:00
|
|
|
// Enable log again
|
|
|
|
dont_log = false;
|
|
|
|
#endif
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void checkMapperSize() {
|
2023-06-27 09:43:40 +02:00
|
|
|
for (uint8_t i = 0; i < mapcount; i++) {
|
2020-07-11 13:39:12 +02:00
|
|
|
int index = i * 7;
|
2023-06-27 09:43:40 +02:00
|
|
|
uint8_t mapcheck = pgm_read_byte(mapsize + index);
|
2019-09-05 00:48:39 +02:00
|
|
|
if (mapcheck == mapper) {
|
|
|
|
prglo = pgm_read_byte(mapsize + index + 1);
|
|
|
|
prghi = pgm_read_byte(mapsize + index + 2);
|
|
|
|
chrlo = pgm_read_byte(mapsize + index + 3);
|
|
|
|
chrhi = pgm_read_byte(mapsize + index + 4);
|
|
|
|
ramlo = pgm_read_byte(mapsize + index + 5);
|
|
|
|
ramhi = pgm_read_byte(mapsize + index + 6);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-01 21:27:45 +02:00
|
|
|
#if (defined(ENABLE_LCD) || defined(ENABLE_OLED))
|
|
|
|
void printPrgSize_NES(int index) {
|
|
|
|
display_Clear();
|
|
|
|
print_Msg(F("PRG Size: "));
|
|
|
|
println_Msg(pgm_read_word(&(PRG[index])));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-09-05 00:48:39 +02:00
|
|
|
void setPRGSize() {
|
2024-05-01 21:27:45 +02:00
|
|
|
uint8_t newprgsize;
|
|
|
|
|
2024-03-02 17:26:35 +01:00
|
|
|
#ifdef ENABLE_GLOBAL_LOG
|
2022-10-04 21:11:13 +02:00
|
|
|
// Disable log to prevent unnecessary logging
|
2022-10-08 18:19:31 +02:00
|
|
|
println_Log(F("Set PRG Size"));
|
2022-10-04 21:11:13 +02:00
|
|
|
dont_log = true;
|
|
|
|
#endif
|
|
|
|
|
2024-03-02 17:26:35 +01:00
|
|
|
#if (defined(ENABLE_LCD) || defined(ENABLE_OLED))
|
2019-09-05 00:48:39 +02:00
|
|
|
display_Clear();
|
|
|
|
if (prglo == prghi)
|
|
|
|
newprgsize = prglo;
|
|
|
|
else {
|
2024-05-01 21:27:45 +02:00
|
|
|
newprgsize = navigateMenu(prglo, prghi, &printPrgSize_NES);
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
display.setCursor(0, 56); // Display selection at bottom
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
print_Msg(F("PRG SIZE "));
|
2022-10-29 01:49:41 +02:00
|
|
|
print_Msg(pgm_read_word(&(PRG[newprgsize])));
|
2019-09-05 00:48:39 +02:00
|
|
|
println_Msg(F("K"));
|
|
|
|
display_Update();
|
2023-05-01 11:57:04 +02:00
|
|
|
delay(500);
|
2021-11-29 13:10:04 +01:00
|
|
|
|
2024-03-02 17:26:35 +01:00
|
|
|
#elif defined(ENABLE_SERIAL)
|
2019-09-05 00:48:39 +02:00
|
|
|
if (prglo == prghi)
|
|
|
|
newprgsize = prglo;
|
|
|
|
else {
|
|
|
|
setprg:
|
|
|
|
String sizePRG;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < (prghi - prglo + 1); i++) {
|
2019-09-05 00:48:39 +02:00
|
|
|
Serial.print(F("Select PRG Size: "));
|
|
|
|
Serial.print(i);
|
|
|
|
Serial.print(F(" = "));
|
2022-10-29 01:49:41 +02:00
|
|
|
Serial.print(pgm_read_word(&(PRG[i + prglo])));
|
2019-09-05 00:48:39 +02:00
|
|
|
Serial.println(F("K"));
|
|
|
|
}
|
|
|
|
Serial.print(F("Enter PRG Size: "));
|
|
|
|
while (Serial.available() == 0) {}
|
|
|
|
sizePRG = Serial.readStringUntil('\n');
|
|
|
|
Serial.println(sizePRG);
|
|
|
|
newprgsize = sizePRG.toInt() + prglo;
|
|
|
|
if (newprgsize > prghi) {
|
|
|
|
Serial.println(F("SIZE NOT SUPPORTED"));
|
2024-03-02 17:30:44 +01:00
|
|
|
Serial.println(FS(FSTRING_EMPTY));
|
2019-09-05 00:48:39 +02:00
|
|
|
goto setprg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Serial.print(F("PRG Size = "));
|
2022-10-29 01:49:41 +02:00
|
|
|
Serial.print(pgm_read_word(&(PRG[newprgsize])));
|
2019-09-05 00:48:39 +02:00
|
|
|
Serial.println(F("K"));
|
|
|
|
#endif
|
|
|
|
EEPROM_writeAnything(8, newprgsize);
|
|
|
|
prgsize = newprgsize;
|
2022-10-04 21:11:13 +02:00
|
|
|
|
2024-03-02 17:26:35 +01:00
|
|
|
#ifdef ENABLE_GLOBAL_LOG
|
2022-10-04 21:11:13 +02:00
|
|
|
// Enable log again
|
|
|
|
dont_log = false;
|
|
|
|
#endif
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
2024-05-01 21:27:45 +02:00
|
|
|
#if (defined(ENABLE_LCD) || defined(ENABLE_OLED))
|
|
|
|
void printChrSize_NES(int index) {
|
|
|
|
display_Clear();
|
|
|
|
print_Msg(F("CHR Size: "));
|
|
|
|
println_Msg(pgm_read_word(&(CHR[index])));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-09-05 00:48:39 +02:00
|
|
|
void setCHRSize() {
|
2024-05-01 21:27:45 +02:00
|
|
|
uint8_t newchrsize;
|
2024-03-02 17:26:35 +01:00
|
|
|
#ifdef ENABLE_GLOBAL_LOG
|
2022-10-04 21:11:13 +02:00
|
|
|
// Disable log to prevent unnecessary logging
|
2022-10-08 18:19:31 +02:00
|
|
|
println_Log(F("Set CHR Size"));
|
2022-10-04 21:11:13 +02:00
|
|
|
dont_log = true;
|
|
|
|
#endif
|
|
|
|
|
2024-03-02 17:26:35 +01:00
|
|
|
#if (defined(ENABLE_LCD) || defined(ENABLE_OLED))
|
2019-09-05 00:48:39 +02:00
|
|
|
display_Clear();
|
|
|
|
if (chrlo == chrhi)
|
|
|
|
newchrsize = chrlo;
|
|
|
|
else {
|
2024-05-01 21:27:45 +02:00
|
|
|
newchrsize = navigateMenu(chrlo, chrhi, &printChrSize_NES);
|
2021-11-29 13:10:04 +01:00
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
display.setCursor(0, 56); // Display selection at bottom
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
print_Msg(F("CHR SIZE "));
|
2022-10-29 01:49:41 +02:00
|
|
|
print_Msg(pgm_read_word(&(CHR[newchrsize])));
|
2019-09-05 00:48:39 +02:00
|
|
|
println_Msg(F("K"));
|
|
|
|
display_Update();
|
2023-05-01 11:57:04 +02:00
|
|
|
delay(500);
|
2021-11-29 13:10:04 +01:00
|
|
|
|
2024-03-02 17:26:35 +01:00
|
|
|
#elif defined(ENABLE_SERIAL)
|
2019-09-05 00:48:39 +02:00
|
|
|
if (chrlo == chrhi)
|
|
|
|
newchrsize = chrlo;
|
|
|
|
else {
|
|
|
|
setchr:
|
|
|
|
String sizeCHR;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < (chrhi - chrlo + 1); i++) {
|
2019-09-05 00:48:39 +02:00
|
|
|
Serial.print(F("Select CHR Size: "));
|
|
|
|
Serial.print(i);
|
|
|
|
Serial.print(F(" = "));
|
2022-10-29 01:49:41 +02:00
|
|
|
Serial.print(pgm_read_word(&(CHR[i + chrlo])));
|
2019-09-05 00:48:39 +02:00
|
|
|
Serial.println(F("K"));
|
|
|
|
}
|
|
|
|
Serial.print(F("Enter CHR Size: "));
|
|
|
|
while (Serial.available() == 0) {}
|
|
|
|
sizeCHR = Serial.readStringUntil('\n');
|
|
|
|
Serial.println(sizeCHR);
|
|
|
|
newchrsize = sizeCHR.toInt() + chrlo;
|
|
|
|
if (newchrsize > chrhi) {
|
|
|
|
Serial.println(F("SIZE NOT SUPPORTED"));
|
2024-03-02 17:30:44 +01:00
|
|
|
Serial.println(FS(FSTRING_EMPTY));
|
2019-09-05 00:48:39 +02:00
|
|
|
goto setchr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Serial.print(F("CHR Size = "));
|
2022-10-29 01:49:41 +02:00
|
|
|
Serial.print(pgm_read_word(&(CHR[newchrsize])));
|
2019-09-05 00:48:39 +02:00
|
|
|
Serial.println(F("K"));
|
|
|
|
#endif
|
|
|
|
EEPROM_writeAnything(9, newchrsize);
|
|
|
|
chrsize = newchrsize;
|
2022-10-04 21:11:13 +02:00
|
|
|
|
2024-03-02 17:26:35 +01:00
|
|
|
#ifdef ENABLE_GLOBAL_LOG
|
2022-10-04 21:11:13 +02:00
|
|
|
// Enable log again
|
|
|
|
dont_log = false;
|
|
|
|
#endif
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
2024-05-01 21:27:45 +02:00
|
|
|
#if (defined(ENABLE_LCD) || defined(ENABLE_OLED))
|
|
|
|
void printRamSize_NES(int index) {
|
|
|
|
display_Clear();
|
|
|
|
print_Msg(F("RAM Size: "));
|
|
|
|
if (mapper == 0)
|
|
|
|
println_Msg(pgm_read_byte(&(RAM[index])) / 4);
|
|
|
|
else if (mapper == 16)
|
|
|
|
println_Msg(pgm_read_byte(&(RAM[index])) * 32);
|
|
|
|
else if (mapper == 19) {
|
|
|
|
if (index == 2)
|
|
|
|
println_Msg(F("128"));
|
|
|
|
else
|
|
|
|
println_Msg(pgm_read_byte(&(RAM[index])));
|
|
|
|
} else if ((mapper == 159) || (mapper == 80))
|
|
|
|
println_Msg(pgm_read_byte(&(RAM[index])) * 16);
|
|
|
|
else if (mapper == 82)
|
|
|
|
println_Msg(index * 5);
|
|
|
|
else
|
|
|
|
println_Msg(pgm_read_byte(&(RAM[index])));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-09-05 00:48:39 +02:00
|
|
|
void setRAMSize() {
|
2024-05-01 21:27:45 +02:00
|
|
|
uint8_t newramsize;
|
2024-03-02 17:26:35 +01:00
|
|
|
#ifdef ENABLE_GLOBAL_LOG
|
2022-10-04 21:11:13 +02:00
|
|
|
// Disable log to prevent unnecessary logging
|
2022-10-08 18:19:31 +02:00
|
|
|
println_Log(F("Set RAM Size"));
|
2022-10-04 21:11:13 +02:00
|
|
|
dont_log = true;
|
|
|
|
#endif
|
|
|
|
|
2024-03-02 17:26:35 +01:00
|
|
|
#if (defined(ENABLE_LCD) || defined(ENABLE_OLED))
|
2019-09-05 00:48:39 +02:00
|
|
|
display_Clear();
|
|
|
|
if (ramlo == ramhi)
|
|
|
|
newramsize = ramlo;
|
|
|
|
else {
|
2024-05-01 21:27:45 +02:00
|
|
|
newramsize = navigateMenu(0, ramhi, &printRamSize_NES);
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
display.setCursor(0, 56); // Display selection at bottom
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
if ((mapper == 16) || (mapper == 159)) {
|
|
|
|
int sizeEEP = 0;
|
|
|
|
print_Msg(F("EEPROM SIZE "));
|
|
|
|
if (mapper == 16)
|
2022-10-29 01:49:41 +02:00
|
|
|
sizeEEP = pgm_read_byte(&(RAM[newramsize])) * 32;
|
2019-09-05 00:48:39 +02:00
|
|
|
else
|
2022-10-29 01:49:41 +02:00
|
|
|
sizeEEP = pgm_read_byte(&(RAM[newramsize])) * 16;
|
2019-09-05 00:48:39 +02:00
|
|
|
print_Msg(sizeEEP);
|
|
|
|
println_Msg(F("B"));
|
2022-10-13 09:49:03 +02:00
|
|
|
} else if (mapper == 19) {
|
2019-11-25 11:53:45 +01:00
|
|
|
print_Msg(F("RAM SIZE "));
|
|
|
|
if (newramsize == 2)
|
|
|
|
println_Msg(F("128B"));
|
|
|
|
else {
|
2022-10-29 01:49:41 +02:00
|
|
|
print_Msg(pgm_read_byte(&(RAM[newramsize])));
|
2019-11-25 11:53:45 +01:00
|
|
|
println_Msg(F("K"));
|
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
} else if (mapper == 80) {
|
2019-11-25 11:53:45 +01:00
|
|
|
print_Msg(F("RAM SIZE "));
|
2022-10-29 01:49:41 +02:00
|
|
|
print_Msg(pgm_read_byte(&(RAM[newramsize])) * 16);
|
2019-11-25 11:53:45 +01:00
|
|
|
println_Msg(F("B"));
|
2022-10-13 09:49:03 +02:00
|
|
|
} else {
|
2019-09-05 00:48:39 +02:00
|
|
|
print_Msg(F("RAM SIZE "));
|
2019-11-25 11:53:45 +01:00
|
|
|
if (mapper == 0)
|
|
|
|
print_Msg(newramsize * 2);
|
|
|
|
else if (mapper == 82)
|
|
|
|
print_Msg(newramsize * 5);
|
|
|
|
else
|
2022-10-29 01:49:41 +02:00
|
|
|
print_Msg(pgm_read_byte(&(RAM[newramsize])));
|
2019-09-05 00:48:39 +02:00
|
|
|
println_Msg(F("K"));
|
|
|
|
}
|
|
|
|
display_Update();
|
2023-05-01 11:57:04 +02:00
|
|
|
delay(500);
|
2021-11-29 13:10:04 +01:00
|
|
|
|
2024-03-02 17:26:35 +01:00
|
|
|
#elif defined(ENABLE_SERIAL)
|
2019-09-05 00:48:39 +02:00
|
|
|
if (ramlo == ramhi)
|
|
|
|
newramsize = ramlo;
|
|
|
|
else {
|
|
|
|
setram:
|
|
|
|
String sizeRAM;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < (ramhi - ramlo + 1); i++) {
|
2019-09-05 00:48:39 +02:00
|
|
|
Serial.print(F("Select RAM Size: "));
|
|
|
|
Serial.print(i);
|
|
|
|
Serial.print(F(" = "));
|
2019-11-25 11:53:45 +01:00
|
|
|
if (mapper == 0) {
|
2022-10-29 01:49:41 +02:00
|
|
|
Serial.print(pgm_read_byte(&(RAM[i])) / 4);
|
2019-11-25 11:53:45 +01:00
|
|
|
Serial.println(F("K"));
|
2022-10-13 09:49:03 +02:00
|
|
|
} else if ((mapper == 16) || (mapper == 159)) {
|
2019-09-05 00:48:39 +02:00
|
|
|
if (mapper == 16)
|
2022-10-29 01:49:41 +02:00
|
|
|
Serial.print(pgm_read_byte(&(RAM[i + ramlo])) * 32);
|
2019-09-05 00:48:39 +02:00
|
|
|
else
|
2022-10-29 01:49:41 +02:00
|
|
|
Serial.print(pgm_read_byte(&(RAM[i + ramlo])) * 16);
|
2019-09-05 00:48:39 +02:00
|
|
|
Serial.println(F("B"));
|
2022-10-13 09:49:03 +02:00
|
|
|
} else if (mapper == 19) {
|
2019-11-25 11:53:45 +01:00
|
|
|
if (i == 2)
|
|
|
|
Serial.println(F("128B"));
|
|
|
|
else {
|
2022-10-29 01:49:41 +02:00
|
|
|
Serial.print(pgm_read_byte(&(RAM[i + ramlo])));
|
2019-11-25 11:53:45 +01:00
|
|
|
Serial.println(F("K"));
|
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
} else {
|
2022-10-29 01:49:41 +02:00
|
|
|
Serial.print(pgm_read_byte(&(RAM[i + ramlo])));
|
2019-09-05 00:48:39 +02:00
|
|
|
Serial.println(F("K"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Serial.print(F("Enter RAM Size: "));
|
|
|
|
while (Serial.available() == 0) {}
|
|
|
|
sizeRAM = Serial.readStringUntil('\n');
|
|
|
|
Serial.println(sizeRAM);
|
|
|
|
newramsize = sizeRAM.toInt() + ramlo;
|
|
|
|
if (newramsize > ramhi) {
|
|
|
|
Serial.println(F("SIZE NOT SUPPORTED"));
|
2024-03-02 17:30:44 +01:00
|
|
|
Serial.println(FS(FSTRING_EMPTY));
|
2019-09-05 00:48:39 +02:00
|
|
|
goto setram;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((mapper == 16) || (mapper == 159)) {
|
|
|
|
int sizeEEP = 0;
|
|
|
|
Serial.print(F("EEPROM Size = "));
|
|
|
|
if (mapper == 16)
|
2022-10-29 01:49:41 +02:00
|
|
|
sizeEEP = pgm_read_byte(&(RAM[newramsize])) * 32;
|
2019-09-05 00:48:39 +02:00
|
|
|
else
|
2022-10-29 01:49:41 +02:00
|
|
|
sizeEEP = pgm_read_byte(&(RAM[newramsize])) * 16;
|
2019-09-05 00:48:39 +02:00
|
|
|
Serial.print(sizeEEP);
|
|
|
|
Serial.println(F("B"));
|
2024-03-02 17:30:44 +01:00
|
|
|
Serial.println(FS(FSTRING_EMPTY));
|
2022-10-13 09:49:03 +02:00
|
|
|
} else if (mapper == 19) {
|
2019-11-25 11:53:45 +01:00
|
|
|
Serial.print(F("RAM Size = "));
|
|
|
|
if (newramsize == 2)
|
|
|
|
Serial.println(F("128B"));
|
|
|
|
else {
|
2022-10-29 01:49:41 +02:00
|
|
|
Serial.print(pgm_read_byte(&(RAM[newramsize])));
|
2019-11-25 11:53:45 +01:00
|
|
|
Serial.println(F("K"));
|
|
|
|
}
|
2024-03-02 17:30:44 +01:00
|
|
|
Serial.println(FS(FSTRING_EMPTY));
|
2022-10-13 09:49:03 +02:00
|
|
|
} else if (mapper == 80) {
|
2019-11-25 11:53:45 +01:00
|
|
|
Serial.print(F("RAM Size = "));
|
2022-10-29 01:49:41 +02:00
|
|
|
Serial.print(pgm_read_byte(&(RAM[newramsize])) * 16);
|
2019-11-25 11:53:45 +01:00
|
|
|
Serial.println(F("B"));
|
2024-03-02 17:30:44 +01:00
|
|
|
Serial.println(FS(FSTRING_EMPTY));
|
2022-10-13 09:49:03 +02:00
|
|
|
} else {
|
2019-09-05 00:48:39 +02:00
|
|
|
Serial.print(F("RAM Size = "));
|
2019-11-25 11:53:45 +01:00
|
|
|
if (mapper == 0)
|
|
|
|
Serial.print(newramsize * 2);
|
|
|
|
else if (mapper == 82)
|
|
|
|
Serial.print(newramsize * 5);
|
|
|
|
else
|
2022-10-29 01:49:41 +02:00
|
|
|
Serial.print(pgm_read_byte(&(RAM[newramsize])));
|
2019-09-05 00:48:39 +02:00
|
|
|
Serial.println(F("K"));
|
2024-03-02 17:30:44 +01:00
|
|
|
Serial.println(FS(FSTRING_EMPTY));
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
EEPROM_writeAnything(10, newramsize);
|
|
|
|
ramsize = newramsize;
|
2022-10-04 21:11:13 +02:00
|
|
|
|
2024-03-02 17:26:35 +01:00
|
|
|
#ifdef ENABLE_GLOBAL_LOG
|
2022-10-04 21:11:13 +02:00
|
|
|
// Enable log again
|
|
|
|
dont_log = false;
|
|
|
|
#endif
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
2019-11-25 11:53:45 +01:00
|
|
|
// MMC6 Detection
|
|
|
|
// Mapper 4 includes both MMC3 AND MMC6
|
|
|
|
// RAM is mapped differently between MMC3 and MMC6
|
2022-10-13 09:49:03 +02:00
|
|
|
void checkMMC6() { // Detect MMC6 Carts - read PRG 0x3E00A ("STARTROPICS")
|
|
|
|
write_prg_byte(0x8000, 6); // PRG Bank 0 ($8000-$9FFF)
|
|
|
|
write_prg_byte(0x8001, 0x1F); // 0x3E000
|
2019-11-27 09:54:48 +01:00
|
|
|
prgchk0 = read_prg_byte(0x800A);
|
|
|
|
prgchk1 = read_prg_byte(0x800B);
|
|
|
|
prgchk2 = read_prg_byte(0x800C);
|
|
|
|
prgchk3 = read_prg_byte(0x800D);
|
|
|
|
if ((prgchk0 == 0x53) && (prgchk1 == 0x54) && (prgchk2 == 0x41) && (prgchk3 == 0x52))
|
2022-10-13 09:49:03 +02:00
|
|
|
mmc6 = true; // MMC6 Cart
|
2019-11-25 11:53:45 +01:00
|
|
|
}
|
|
|
|
|
2022-09-18 19:26:43 +02:00
|
|
|
void checkStatus_NES() {
|
2019-09-05 00:48:39 +02:00
|
|
|
EEPROM_readAnything(7, mapper);
|
|
|
|
EEPROM_readAnything(8, prgsize);
|
|
|
|
EEPROM_readAnything(9, chrsize);
|
|
|
|
EEPROM_readAnything(10, ramsize);
|
|
|
|
prg = (int_pow(2, prgsize)) * 16;
|
|
|
|
if (chrsize == 0)
|
2022-10-13 09:49:03 +02:00
|
|
|
chr = 0; // 0K
|
2019-09-05 00:48:39 +02:00
|
|
|
else
|
|
|
|
chr = (int_pow(2, chrsize)) * 4;
|
|
|
|
if (ramsize == 0)
|
2022-10-13 09:49:03 +02:00
|
|
|
ram = 0; // 0K
|
2019-11-25 11:53:45 +01:00
|
|
|
else if (mapper == 82)
|
2022-10-13 09:49:03 +02:00
|
|
|
ram = 5; // 5K
|
2019-09-05 00:48:39 +02:00
|
|
|
else
|
|
|
|
ram = (int_pow(2, ramsize)) * 4;
|
|
|
|
|
2019-11-25 11:53:45 +01:00
|
|
|
// Mapper Variants
|
|
|
|
// Identify variant for use across multiple functions
|
2022-10-13 09:49:03 +02:00
|
|
|
if (mapper == 4) { // Check for MMC6/MMC3
|
2019-11-25 11:53:45 +01:00
|
|
|
checkMMC6();
|
|
|
|
if (mmc6)
|
2022-10-13 09:49:03 +02:00
|
|
|
ram = 1; // 1K
|
|
|
|
} else if (mapper == 30) // Check for Flashable/Non-Flashable
|
|
|
|
NESmaker_ID(); // Flash ID
|
2019-11-25 11:53:45 +01:00
|
|
|
|
2022-09-18 19:26:43 +02:00
|
|
|
display_Clear();
|
|
|
|
println_Msg(F("NES CART READER"));
|
2024-03-02 17:26:35 +01:00
|
|
|
println_Msg(FS(FSTRING_EMPTY));
|
2024-04-22 18:51:01 +02:00
|
|
|
println_Msg(FS(FSTRING_CURRENT_SETTINGS));
|
2024-03-02 17:26:35 +01:00
|
|
|
println_Msg(FS(FSTRING_EMPTY));
|
2022-10-23 12:01:09 +02:00
|
|
|
printNESSettings();
|
2024-03-02 17:26:35 +01:00
|
|
|
println_Msg(FS(FSTRING_EMPTY));
|
2022-10-23 12:01:09 +02:00
|
|
|
// Prints string out of the common strings array either with or without newline
|
|
|
|
print_STR(press_button_STR, 1);
|
|
|
|
display_Update();
|
|
|
|
wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printNESSettings(void) {
|
2019-09-05 00:48:39 +02:00
|
|
|
print_Msg(F("MAPPER: "));
|
|
|
|
println_Msg(mapper);
|
|
|
|
print_Msg(F("PRG SIZE: "));
|
|
|
|
print_Msg(prg);
|
|
|
|
println_Msg(F("K"));
|
|
|
|
print_Msg(F("CHR SIZE: "));
|
|
|
|
print_Msg(chr);
|
|
|
|
println_Msg(F("K"));
|
|
|
|
print_Msg(F("RAM SIZE: "));
|
2019-11-25 11:53:45 +01:00
|
|
|
if (mapper == 0) {
|
|
|
|
print_Msg(ram / 4);
|
|
|
|
println_Msg(F("K"));
|
2022-10-13 09:49:03 +02:00
|
|
|
} else if ((mapper == 16) || (mapper == 80) || (mapper == 159)) {
|
2019-09-05 00:48:39 +02:00
|
|
|
if (mapper == 16)
|
|
|
|
print_Msg(ram * 32);
|
|
|
|
else
|
|
|
|
print_Msg(ram * 16);
|
|
|
|
println_Msg(F("B"));
|
2022-10-13 09:49:03 +02:00
|
|
|
} else if (mapper == 19) {
|
2019-11-25 11:53:45 +01:00
|
|
|
if (ramsize == 2)
|
|
|
|
println_Msg(F("128B"));
|
|
|
|
else {
|
|
|
|
print_Msg(ram);
|
|
|
|
println_Msg(F("K"));
|
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
} else {
|
2019-09-05 00:48:39 +02:00
|
|
|
print_Msg(ram);
|
|
|
|
println_Msg(F("K"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************
|
|
|
|
ROM Functions
|
|
|
|
*****************************************/
|
|
|
|
void dumpPRG(word base, word address) {
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t x = 0; x < 512; x++) {
|
2019-09-05 00:48:39 +02:00
|
|
|
sdBuffer[x] = read_prg_byte(base + address + x);
|
|
|
|
}
|
2022-07-07 00:15:13 +02:00
|
|
|
myFile.write(sdBuffer, 512);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void dumpCHR(word address) {
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t x = 0; x < 512; x++) {
|
2019-09-05 00:48:39 +02:00
|
|
|
sdBuffer[x] = read_chr_byte(address + x);
|
|
|
|
}
|
2022-07-07 00:15:13 +02:00
|
|
|
myFile.write(sdBuffer, 512);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
void dumpCHR_M2(word address) { // MAPPER 45 - PULSE M2 LO/HI
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t x = 0; x < 512; x++) {
|
2022-09-25 11:09:54 +02:00
|
|
|
PHI2_LOW;
|
|
|
|
sdBuffer[x] = read_chr_byte(address + x);
|
|
|
|
}
|
|
|
|
myFile.write(sdBuffer, 512);
|
|
|
|
}
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
void dumpMMC5RAM(word base, word address) { // MMC5 SRAM DUMP - PULSE M2 LO/HI
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t x = 0; x < 512; x++) {
|
2019-09-05 00:48:39 +02:00
|
|
|
PHI2_LOW;
|
|
|
|
sdBuffer[x] = read_prg_byte(base + address + x);
|
|
|
|
}
|
2022-07-07 00:15:13 +02:00
|
|
|
myFile.write(sdBuffer, 512);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
void writeMMC5RAM(word base, word address) { // MMC5 SRAM WRITE
|
2022-07-07 00:15:13 +02:00
|
|
|
myFile.read(sdBuffer, 512);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t x = 0; x < 512; x++) {
|
2019-09-05 00:48:39 +02:00
|
|
|
do {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x5102, 2); // PRG RAM PROTECT1
|
|
|
|
write_prg_byte(0x5103, 1); // PRG RAM PROTECT2
|
2019-09-05 00:48:39 +02:00
|
|
|
write_wram_byte(base + address + x, sdBuffer[x]);
|
|
|
|
bytecheck = read_prg_byte(base + address + x);
|
2022-10-13 09:49:03 +02:00
|
|
|
} while (bytecheck != sdBuffer[x]); // CHECK WRITTEN BYTE
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x5102, 0); // PRG RAM PROTECT1
|
|
|
|
write_prg_byte(0x5103, 0); // PRG RAM PROTECT2
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
2024-05-03 23:42:06 +02:00
|
|
|
void dumpBankPRG(const size_t from, const size_t to, const size_t base) {
|
|
|
|
for (size_t address = from; address < to; address += 512) {
|
|
|
|
dumpPRG(base, address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void dumpBankCHR(const size_t from, const size_t to) {
|
|
|
|
for (size_t address = from; address < to; address += 512) {
|
|
|
|
dumpCHR(address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-30 13:42:16 +02:00
|
|
|
void readPRG(bool readrom) {
|
2022-07-07 00:51:44 +02:00
|
|
|
if (!readrom) {
|
|
|
|
display_Clear();
|
|
|
|
display_Update();
|
|
|
|
|
|
|
|
LED_BLUE_ON;
|
|
|
|
set_address(0);
|
|
|
|
_delay_us(1);
|
|
|
|
CreatePRGFileInSD();
|
2022-10-13 09:49:03 +02:00
|
|
|
} else {
|
2022-07-07 00:51:44 +02:00
|
|
|
set_address(0);
|
|
|
|
_delay_us(1);
|
|
|
|
}
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-07-07 00:15:13 +02:00
|
|
|
word base = 0x8000;
|
2022-12-10 15:05:16 +01:00
|
|
|
bool busConflict = false;
|
2022-07-07 00:15:13 +02:00
|
|
|
|
|
|
|
if (myFile) {
|
2019-09-05 00:48:39 +02:00
|
|
|
switch (mapper) {
|
|
|
|
case 0:
|
|
|
|
case 3:
|
|
|
|
case 13:
|
2024-05-03 23:42:06 +02:00
|
|
|
case 87: // 16K/32K
|
|
|
|
case 184: // 32K
|
|
|
|
case 185: // 16K/32K
|
|
|
|
dumpBankPRG(0, (((word)prgsize) * 0x4000) + 0x4000, base); // 16K or 32K
|
2019-09-05 00:48:39 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2022-10-13 09:49:03 +02:00
|
|
|
case 155: // 32K/64K/128K/256K/512K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize) - 1;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 16K Banks ($8000-$BFFF)
|
|
|
|
write_prg_byte(0x8000, 0x80); // Clear Register
|
|
|
|
write_mmc1_byte(0x8000, 0x0C); // Switch 16K Bank ($8000-$BFFF) + Fixed Last Bank ($C000-$FFFF)
|
|
|
|
if (prgsize > 4) // 512K
|
|
|
|
write_mmc1_byte(0xA000, 0x00); // Reset 512K Flag for Lower 256K
|
|
|
|
if (i > 15) // Switch Upper 256K
|
|
|
|
write_mmc1_byte(0xA000, 0x10); // Set 512K Flag
|
2019-09-05 00:48:39 +02:00
|
|
|
write_mmc1_byte(0xE000, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x4000, 0x8000, base); // Final Bank ($C000-$FFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
break;
|
|
|
|
|
2023-06-26 12:04:00 +02:00
|
|
|
case 2: // bus conflicts - fixed last bank
|
|
|
|
case 30: // bus conflicts in non-flashable configuration
|
2022-12-10 15:05:16 +01:00
|
|
|
banks = int_pow(2, prgsize);
|
|
|
|
busConflict = true;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks - 1; i++) {
|
|
|
|
for (size_t x = 0; x < 0x4000; x++) {
|
2022-12-10 15:05:16 +01:00
|
|
|
if (read_prg_byte(0xC000 + x) == i) {
|
|
|
|
write_prg_byte(0xC000 + x, i);
|
|
|
|
busConflict = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (busConflict) {
|
2022-12-11 00:00:57 +01:00
|
|
|
write_prg_byte(0xC000 + i, i);
|
2022-12-10 15:05:16 +01:00
|
|
|
}
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-12-10 15:05:16 +01:00
|
|
|
}
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x4000, 0x8000, base);
|
2019-09-05 00:48:39 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
case 47:
|
2022-07-23 11:04:17 +02:00
|
|
|
case 64:
|
2019-09-05 00:48:39 +02:00
|
|
|
case 118:
|
|
|
|
case 119:
|
2022-07-23 11:04:17 +02:00
|
|
|
case 158:
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = ((int_pow(2, prgsize) * 2)) - 2; // Set Number of Banks
|
|
|
|
if (mapper == 47)
|
2023-06-27 09:43:40 +02:00
|
|
|
write_prg_byte(0xA001, 0x80); // Block Register - PRG RAM Chip Enable, Writable
|
|
|
|
for (size_t i = 0; i < banks; i += 2) { // 32K/64K/128K/256K/512K
|
2019-09-05 00:48:39 +02:00
|
|
|
if (mapper == 47) {
|
|
|
|
if (i == 0)
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x6000, 0); // Switch to Lower Block
|
2019-09-05 00:48:39 +02:00
|
|
|
else if (i == 16)
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x6000, 1); // Switch to Upper Block
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x8000, 6); // PRG Bank 0 ($8000-$9FFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x8001, i);
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x8000, 7); // PRG Bank 1 ($A000-$BFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x8001, i + 1);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2022-07-23 11:04:17 +02:00
|
|
|
if ((mapper == 64) || (mapper == 158)) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x8000, 15); // PRG Bank 2 ($C000-$DFFF)
|
2022-07-23 11:04:17 +02:00
|
|
|
write_prg_byte(0x8001, banks);
|
|
|
|
}
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x4000, 0x8000, base); // Final 2 Banks ($C000-$FFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 5: // 128K/256K/512K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize) * 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
write_prg_byte(0x5100, 3); // 8K PRG Banks
|
|
|
|
for (size_t i = 0; i < banks; i += 2) { // 128K/256K/512K
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x5114, i | 0x80);
|
|
|
|
write_prg_byte(0x5115, (i + 1) | 0x80);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 7: // 128K/256K
|
2019-09-05 00:48:39 +02:00
|
|
|
case 77:
|
2022-12-20 10:31:35 +01:00
|
|
|
case 96: // 128K
|
2022-12-05 20:35:51 +01:00
|
|
|
case 177: // up to 1024K
|
2022-12-04 08:45:49 +01:00
|
|
|
case 241:
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 32K Banks
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x8000, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base); // 32K Banks ($8000-$FFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2024-05-03 23:42:06 +02:00
|
|
|
case 9: // 128K
|
|
|
|
for (size_t i = 0; i < 13; i++) { // 16-3 = 13 = 128K
|
|
|
|
write_prg_byte(0xA000, i); // $8000-$9FFF
|
|
|
|
dumpBankPRG(0x0, 0x2000, base); // Switch Bank ($8000-$9FFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x2000, 0x8000, base); // Final 3 Banks ($A000-$FFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 10: // 128K/256K
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < (unsigned)(((prgsize - 3) * 8) + 7); i++) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0xA000, i); // $8000-$BFFF
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base); // Switch Bank ($8000-$BFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x4000, 0x8000, base); // Final Bank ($C000-$FFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
break;
|
2022-10-13 09:49:03 +02:00
|
|
|
|
2022-10-12 23:07:43 +02:00
|
|
|
case 11:
|
|
|
|
banks = int_pow(2, prgsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0xFFB0 + i, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-10-12 23:07:43 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-10-27 23:43:46 +02:00
|
|
|
|
2022-10-19 11:08:13 +02:00
|
|
|
case 15:
|
|
|
|
banks = int_pow(2, prgsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) {
|
2022-10-19 11:08:13 +02:00
|
|
|
write_prg_byte(0x8000, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-10-19 11:08:13 +02:00
|
|
|
}
|
2022-10-27 23:43:46 +02:00
|
|
|
break;
|
2022-10-13 09:49:03 +02:00
|
|
|
|
2019-09-05 00:48:39 +02:00
|
|
|
case 16:
|
2022-10-13 09:49:03 +02:00
|
|
|
case 159: // 128K/256K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2024-05-03 23:42:06 +02:00
|
|
|
write_prg_byte(0x6008, i); // Submapper 4
|
|
|
|
write_prg_byte(0x8008, i); // Submapper 5
|
|
|
|
dumpBankPRG(0x0, 0x4000, base); // 16K Banks ($8000-$BFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 18: // 128K/256K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize) * 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) {
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x8000, i & 0xF);
|
|
|
|
write_prg_byte(0x8001, (i >> 4) & 0xF);
|
|
|
|
write_prg_byte(0x8002, (i + 1) & 0xF);
|
|
|
|
write_prg_byte(0x8003, ((i + 1) >> 4) & 0xF);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 19: // 128K/256K
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t j = 0; j < 64; j++) { // Init Register
|
2022-10-13 09:49:03 +02:00
|
|
|
write_ram_byte(0xE000, 0); // PRG Bank 0 ($8000-$9FFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
banks = int_pow(2, prgsize) * 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_ram_byte(0xE000, i); // PRG Bank 0 ($8000-$9FFF)
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x2000, base);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-05-25 07:34:18 +02:00
|
|
|
case 21: // 256K
|
|
|
|
banks = int_pow(2, prgsize) * 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2020-05-25 07:34:18 +02:00
|
|
|
write_prg_byte(0xA000, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x2000, 0x4000, base);
|
2020-05-25 07:34:18 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-09-05 00:48:39 +02:00
|
|
|
case 22:
|
|
|
|
case 25:
|
|
|
|
case 65:
|
2022-10-13 09:49:03 +02:00
|
|
|
case 75: // 128K/256K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize) * 2;
|
2022-12-24 18:22:13 +01:00
|
|
|
|
|
|
|
// set vrc4 swap setting for TMNT2
|
|
|
|
if (mapper == 25)
|
|
|
|
write_prg_byte(0x9005, 0x00);
|
|
|
|
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) {
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x8000, i);
|
|
|
|
write_prg_byte(0xA000, i + 1);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-20 10:31:35 +01:00
|
|
|
|
|
|
|
case 23:
|
2022-12-14 21:46:39 +01:00
|
|
|
banks = int_pow(2, prgsize) * 2;
|
|
|
|
write_prg_byte(0x9002, 0);
|
|
|
|
write_prg_byte(0x9008, 0);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-14 21:46:39 +01:00
|
|
|
write_prg_byte(0x8000, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x2000, base);
|
2022-12-14 21:46:39 +01:00
|
|
|
}
|
|
|
|
break;
|
2019-09-05 00:48:39 +02:00
|
|
|
|
|
|
|
case 24:
|
2022-10-13 09:49:03 +02:00
|
|
|
case 26: // 256K
|
|
|
|
case 78: // 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x8000, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x2000, 0x4000, base); // 16K Banks ($8000-$BFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-20 10:31:35 +01:00
|
|
|
|
2022-11-19 09:04:06 +01:00
|
|
|
case 28: // using 32k mode for inner and outer banks, switching only with outer
|
|
|
|
banks = int_pow(2, prgsize) / 2;
|
|
|
|
write_prg_byte(0x5000, 0x81);
|
|
|
|
write_prg_byte(0x8000, 0);
|
|
|
|
write_prg_byte(0x5000, 0x80);
|
|
|
|
write_prg_byte(0x8000, 0);
|
|
|
|
write_prg_byte(0x5000, 0x01);
|
|
|
|
write_prg_byte(0x8000, 0);
|
|
|
|
write_prg_byte(0x5000, 0x00);
|
|
|
|
write_prg_byte(0x8000, 0);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-11-19 09:04:06 +01:00
|
|
|
write_prg_byte(0x5000, 0x81);
|
|
|
|
write_prg_byte(0x8000, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2019-11-25 11:53:45 +01:00
|
|
|
}
|
|
|
|
break;
|
2023-01-03 19:33:34 +01:00
|
|
|
|
2022-12-22 21:55:00 +01:00
|
|
|
case 31:
|
|
|
|
banks = int_pow(2, prgsize) * 4;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 8) {
|
2022-12-22 21:55:00 +01:00
|
|
|
write_prg_byte(0x5FF8, i);
|
|
|
|
write_prg_byte(0x5FF9, i + 1);
|
|
|
|
write_prg_byte(0x5FFA, i + 2);
|
|
|
|
write_prg_byte(0x5FFB, i + 3);
|
|
|
|
write_prg_byte(0x5FFC, i + 4);
|
|
|
|
write_prg_byte(0x5FFD, i + 5);
|
|
|
|
write_prg_byte(0x5FFE, i + 6);
|
|
|
|
write_prg_byte(0x5FFF, i + 7);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-12-22 21:55:00 +01:00
|
|
|
}
|
|
|
|
break;
|
2019-11-25 11:53:45 +01:00
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 32: // 128K/256K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize) * 2;
|
2024-05-03 23:42:06 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 128K/256K
|
|
|
|
write_prg_byte(0x9000, 1); // PRG Mode 0 - Read $A000-$BFFF to avoid difference between Modes 0 and 1
|
|
|
|
write_prg_byte(0xA000, i); // PRG Bank
|
|
|
|
dumpBankPRG(0x2000, 0x4000, base); // 8K Banks ($A000-$BFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 33:
|
2022-10-13 09:49:03 +02:00
|
|
|
case 48: // 128K/256K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize) * 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) {
|
2024-05-03 23:42:06 +02:00
|
|
|
write_prg_byte(0x8000, i); // PRG Bank 0 ($8000-$9FFF)
|
|
|
|
write_prg_byte(0x8001, i + 1); // PRG Bank 1 ($A000-$BFFF)
|
|
|
|
dumpBankPRG(0x0, 0x4000, base); // 8K Banks ($A000-$BFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2023-06-26 12:04:00 +02:00
|
|
|
|
2023-04-10 10:35:17 +02:00
|
|
|
case 34: // BxROM/NINA
|
|
|
|
banks = int_pow(2, prgsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2024-05-03 23:42:06 +02:00
|
|
|
write_prg_byte(0x7FFD, i); // NINA Bank select
|
|
|
|
write_prg_byte(0x8000, i); // BxROM bank select
|
|
|
|
delay(200); // NINA seems slow to switch banks
|
|
|
|
dumpBankPRG(0x0, 0x8000, base); // 32K Banks ($8000-$FFFF)
|
2023-04-10 10:35:17 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-20 10:31:35 +01:00
|
|
|
|
2022-12-14 13:15:32 +01:00
|
|
|
case 35:
|
|
|
|
case 90:
|
|
|
|
case 209:
|
|
|
|
case 211:
|
|
|
|
banks = int_pow(2, prgsize) * 2;
|
|
|
|
write_prg_byte(0xD000, 0x02);
|
|
|
|
|
2023-06-27 09:43:40 +02:00
|
|
|
for (uint8_t i = 0; i < banks; i++) {
|
2022-12-14 13:15:32 +01:00
|
|
|
write_prg_byte(0xD003, (((i >> 5) & 0x06) | 0x20));
|
|
|
|
write_prg_byte(0x8000, (i & 0x3f));
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x2000, base);
|
2022-12-14 13:15:32 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-10-28 15:02:51 +02:00
|
|
|
|
2022-10-28 10:29:54 +02:00
|
|
|
case 36:
|
|
|
|
banks = int_pow(2, prgsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-28 15:02:51 +02:00
|
|
|
write_prg_byte(0xFFA0 + i, (i << 4));
|
2022-10-28 10:29:54 +02:00
|
|
|
write_prg_byte(0x4101, 0);
|
2022-10-28 15:02:51 +02:00
|
|
|
write_prg_byte(0x4102, (i << 4));
|
2022-10-28 10:29:54 +02:00
|
|
|
write_prg_byte(0x4103, 0);
|
|
|
|
write_prg_byte(0x4100, 0);
|
|
|
|
write_prg_byte(0x4103, 0xFF);
|
|
|
|
write_prg_byte(0xFFFF, 0xFF);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-10-28 10:29:54 +02:00
|
|
|
}
|
|
|
|
break;
|
2019-09-05 00:48:39 +02:00
|
|
|
|
|
|
|
case 37:
|
|
|
|
banks = ((int_pow(2, prgsize) * 2)) - 2; // Set Number of Banks
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0xA001, 0x80); // Block Register - PRG RAM Chip Enable, Writable
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) { // 256K
|
2019-09-05 00:48:39 +02:00
|
|
|
if (i == 0)
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x6000, 0); // Switch to Lower Block ($0000-$FFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
else if (i == 8)
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x6000, 3); // Switch to 2nd 64K Block ($10000-$1FFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
else if (i == 16)
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x6000, 4); // Switch to 128K Block ($20000-$3FFFF)
|
|
|
|
write_prg_byte(0x8000, 6); // PRG Bank 0 ($8000-$9FFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x8001, i);
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x8000, 7); // PRG Bank 1 ($A000-$BFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x8001, i + 1);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x4000, 0x8000, base); // Final 2 Banks ($C000-$FFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
break;
|
2023-06-26 12:04:00 +02:00
|
|
|
|
2023-04-15 16:12:41 +02:00
|
|
|
case 38:
|
|
|
|
banks = int_pow(2, prgsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2023-04-15 16:12:41 +02:00
|
|
|
write_prg_byte(0x7000, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2023-04-15 16:12:41 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-10 15:05:16 +01:00
|
|
|
|
2022-12-05 20:35:51 +01:00
|
|
|
case 42:
|
|
|
|
banks = int_pow(2, prgsize) * 2;
|
|
|
|
base = 0x6000; // 8k switchable PRG ROM bank at $6000-$7FFF
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks - 4; i++) {
|
2022-12-05 20:35:51 +01:00
|
|
|
write_prg_byte(0xE000, i & 0x0F);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x2000, base);
|
2022-12-05 20:35:51 +01:00
|
|
|
}
|
|
|
|
base = 0x8000; // last 32k fixed to $8000-$FFFF
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-12-05 20:35:51 +01:00
|
|
|
break;
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 45: // MMC3 Clone with Outer Registers
|
2022-09-25 11:09:54 +02:00
|
|
|
banks = ((int_pow(2, prgsize) * 2)) - 2; // Set Number of Banks
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) { // 128K/256K/512K/1024K
|
2022-09-25 11:09:54 +02:00
|
|
|
// set outer bank registers
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x6000, 0x00); // CHR-OR
|
|
|
|
write_prg_byte(0x6000, (i & 0xC0)); // PRG-OR
|
|
|
|
write_prg_byte(0x6000, ((i >> 2) & 0xC0)); // CHR-AND,CHR-OR/PRG-OR
|
|
|
|
write_prg_byte(0x6000, 0x80); // PRG-AND
|
2022-09-25 11:09:54 +02:00
|
|
|
// set inner bank registers
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x8000, 6); // PRG Bank 0 ($8000-$9FFF)
|
2022-09-25 11:09:54 +02:00
|
|
|
write_prg_byte(0x8001, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x2000, base);
|
2022-09-25 11:09:54 +02:00
|
|
|
// set outer bank registers
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x6000, 0x00); // CHR-OR
|
|
|
|
write_prg_byte(0x6000, ((i + 1) & 0xC0)); // PRG-OR
|
|
|
|
write_prg_byte(0x6000, (((i + 1) >> 2) & 0xC0)); // CHR-AND,CHR-OR/PRG-OR
|
|
|
|
write_prg_byte(0x6000, 0x80); // PRG-AND
|
2022-09-25 11:09:54 +02:00
|
|
|
// set inner bank registers
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x8000, 7); // PRG Bank 1 ($A000-$BFFF)
|
2022-09-25 11:09:54 +02:00
|
|
|
write_prg_byte(0x8001, i + 1);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x2000, 0x4000, base);
|
2022-09-25 11:09:54 +02:00
|
|
|
}
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x4000, 0x8000, base); // Final 2 Banks ($C000-$FFFF)
|
2022-09-25 11:09:54 +02:00
|
|
|
break;
|
2022-12-10 15:05:16 +01:00
|
|
|
|
2022-12-06 16:48:53 +01:00
|
|
|
case 46:
|
|
|
|
banks = int_pow(2, prgsize) / 2; // 32k banks
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-06 16:48:53 +01:00
|
|
|
write_prg_byte(0x6000, (i & 0x1E) >> 1); // high bits
|
2022-12-20 10:31:35 +01:00
|
|
|
write_prg_byte(0x8000, i & 0x01); // low bit
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-10-19 14:43:42 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-10-27 23:43:46 +02:00
|
|
|
|
2022-12-06 16:48:53 +01:00
|
|
|
case 52:
|
2022-12-20 10:31:35 +01:00
|
|
|
banks = int_pow(2, prgsize);
|
2022-12-06 16:48:53 +01:00
|
|
|
write_prg_byte(0xA001, 0x80); // enable WRAM write
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-06 16:48:53 +01:00
|
|
|
write_prg_byte(0x6000, (i & 0x07) | 0x08);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-12-06 16:48:53 +01:00
|
|
|
}
|
|
|
|
break;
|
2023-01-03 19:33:34 +01:00
|
|
|
|
2022-12-30 08:24:54 +01:00
|
|
|
case 56:
|
|
|
|
banks = int_pow(2, prgsize) * 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-30 08:24:54 +01:00
|
|
|
write_prg_byte(0xE000, 1);
|
|
|
|
write_prg_byte(0xF000, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x2000, base);
|
2022-12-30 08:24:54 +01:00
|
|
|
}
|
|
|
|
break;
|
2023-01-03 19:33:34 +01:00
|
|
|
|
2022-12-22 21:55:00 +01:00
|
|
|
case 57:
|
|
|
|
banks = int_pow(2, prgsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-22 21:55:00 +01:00
|
|
|
write_prg_byte(0x8800, (i & 0x07) << 5);
|
|
|
|
write_prg_byte(0x8000, 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-12-22 21:55:00 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-12-06 16:48:53 +01:00
|
|
|
|
2022-10-23 20:57:34 +02:00
|
|
|
case 58:
|
|
|
|
case 213:
|
|
|
|
banks = int_pow(2, prgsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-23 20:57:34 +02:00
|
|
|
write_prg_byte(0x8000 + (i & 0x07), 0x00);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-10-23 20:57:34 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-10 15:05:16 +01:00
|
|
|
|
2022-12-08 16:10:05 +01:00
|
|
|
case 59:
|
2022-12-20 10:31:35 +01:00
|
|
|
banks = int_pow(2, prgsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2023-03-30 03:05:01 +02:00
|
|
|
write_prg_byte((0x8000 + (i & 0x07)) << 4 | 0x80, 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-12-08 16:10:05 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-10-27 23:43:46 +02:00
|
|
|
|
2022-10-22 09:01:18 +02:00
|
|
|
case 60:
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < 3; i++) {
|
2022-10-22 09:01:18 +02:00
|
|
|
write_prg_byte(0x8D8D, i);
|
|
|
|
delay(500);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-10-22 09:01:18 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-10 15:05:16 +01:00
|
|
|
|
2022-12-06 16:48:53 +01:00
|
|
|
case 62:
|
|
|
|
banks = int_pow(2, prgsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-06 16:48:53 +01:00
|
|
|
write_prg_byte(0x8000 + (i * 512) + ((i & 32) << 1), 0x00);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-12-06 16:48:53 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-10-27 23:43:46 +02:00
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 66: // 64K/128K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize) / 2;
|
2024-05-03 23:42:06 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 64K/128K
|
|
|
|
write_prg_byte(0x8000, i << 4); // bits 4-5
|
|
|
|
dumpBankPRG(0x0, 0x8000, base); // 32K Banks ($8000-$FFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-10 15:05:16 +01:00
|
|
|
|
2022-12-13 19:11:55 +01:00
|
|
|
case 63: // 3072K total
|
2022-12-08 16:10:05 +01:00
|
|
|
banks = int_pow(2, prgsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < 192; i++) {
|
2022-12-20 10:31:35 +01:00
|
|
|
write_prg_byte(0x8000 + (i << 2), 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-12-08 16:10:05 +01:00
|
|
|
}
|
|
|
|
break;
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 67: // 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize);
|
2024-05-03 23:42:06 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 128K
|
|
|
|
write_reg_byte(0xF800, i); // [WRITE RAM SAFE]
|
|
|
|
dumpBankPRG(0x0, 0x4000, base); // 16K Banks ($8000-$BFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 68:
|
2022-10-13 09:49:03 +02:00
|
|
|
case 73: // 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 128K
|
2022-12-22 21:55:00 +01:00
|
|
|
write_prg_byte(0xF000, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base); // 16K Banks ($8000-$BFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 69: // 128K/256K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize) * 2;
|
2024-05-03 23:42:06 +02:00
|
|
|
write_prg_byte(0x8000, 8); // Command Register - PRG Bank 0
|
|
|
|
write_prg_byte(0xA000, 0); // Parameter Register - PRG RAM Disabled, PRG ROM, Bank 0 to $6000-$7FFF
|
|
|
|
for (size_t i = 0; i < banks; i++) { // 128K/256K
|
|
|
|
write_prg_byte(0x8000, 9); // Command Register - PRG Bank 1
|
|
|
|
write_prg_byte(0xA000, i); // Parameter Register - ($8000-$9FFF)
|
|
|
|
dumpBankPRG(0x0, 0x2000, base); // 8K Banks ($8000-$9FFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 70:
|
|
|
|
case 89:
|
2022-10-13 09:49:03 +02:00
|
|
|
case 152: // 64K/128K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x8000, i << 4);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base); // 16K Banks ($8000-$BFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 71: // 64K/128K/256K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0xC000, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base); // 16K Banks ($8000-$BFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 72: // 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize);
|
2024-05-03 23:42:06 +02:00
|
|
|
write_prg_byte(0x8000, 0); // Reset Register
|
|
|
|
for (size_t i = 0; i < banks; i++) { // 128K
|
|
|
|
write_prg_byte(0x8000, i | 0x80); // PRG Command + Bank
|
|
|
|
write_prg_byte(0x8000, i); // PRG Bank
|
|
|
|
dumpBankPRG(0x0, 0x4000, base); // 16K Banks ($8000-$BFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 76:
|
|
|
|
case 88:
|
|
|
|
case 95:
|
2022-10-13 09:49:03 +02:00
|
|
|
case 154: // 128K
|
2022-11-02 07:44:25 +01:00
|
|
|
case 206: // 32/64/128K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize) * 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks - 2; i += 2) {
|
2022-11-02 07:44:25 +01:00
|
|
|
write_prg_byte(0x8000, 6);
|
|
|
|
write_prg_byte(0x8001, i);
|
|
|
|
write_prg_byte(0x8000, 7);
|
|
|
|
write_prg_byte(0x8001, i | 1);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-11-18 10:46:13 +01:00
|
|
|
}
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x4000, 0x8000, base);
|
2019-09-05 00:48:39 +02:00
|
|
|
break;
|
|
|
|
|
2022-10-12 19:49:32 +02:00
|
|
|
case 79:
|
2022-10-12 22:11:35 +02:00
|
|
|
case 146:
|
2022-10-12 19:49:32 +02:00
|
|
|
banks = int_pow(2, prgsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-12 19:49:32 +02:00
|
|
|
write_prg_byte(0x4100, i << 3);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-10-12 19:49:32 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-10-13 09:49:03 +02:00
|
|
|
|
|
|
|
case 80: // 128K
|
|
|
|
case 207: // 256K [CART SOMETIMES NEEDS POWERCYCLE]
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize) * 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x7EFA, i); // PRG Bank 0 ($8000-$9FFF)
|
|
|
|
write_prg_byte(0x7EFC, i + 1); // PRG Bank 1 ($A000-$BFFF)
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 82: // 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize) * 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) {
|
2024-05-03 23:42:06 +02:00
|
|
|
write_prg_byte(0x7EFA, i << 2); // PRG Bank 0 ($8000-$9FFF)
|
|
|
|
write_prg_byte(0x7EFB, (i + 1) << 2); // PRG Bank 1 ($A000-$BFFF)
|
|
|
|
dumpBankPRG(0x0, 0x4000, base); // 8K Banks ($8000-$BFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 85: // 128K/512K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize) * 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2024-05-03 23:42:06 +02:00
|
|
|
write_prg_byte(0x8000, i); // PRG Bank 0 ($8000-$9FFF)
|
|
|
|
dumpBankPRG(0x0, 0x2000, base); // 8K Banks ($8000-$9FFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 86:
|
2022-10-13 09:49:03 +02:00
|
|
|
case 140: // 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize) / 2;
|
2024-05-03 23:42:06 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 128K
|
|
|
|
write_prg_byte(0x6000, i << 4); // bits 4-5
|
|
|
|
dumpBankPRG(0x0, 0x8000, base); // 32K Banks ($8000-$FFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-10-28 15:02:51 +02:00
|
|
|
|
2022-10-28 11:49:55 +02:00
|
|
|
case 91:
|
|
|
|
banks = int_pow(2, prgsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < (banks - 2); i += 2) {
|
2022-10-28 11:49:55 +02:00
|
|
|
write_prg_byte(0x7000, (i | 0));
|
|
|
|
write_prg_byte(0x7001, (i | 1));
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-10-28 15:02:51 +02:00
|
|
|
}
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x4000, 0x8000, base);
|
2022-10-28 11:49:55 +02:00
|
|
|
break;
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 92: // 256K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize);
|
2024-05-03 23:42:06 +02:00
|
|
|
write_prg_byte(0x8000, 0); // Reset Register
|
|
|
|
for (size_t i = 0; i < banks; i++) { // 256K
|
|
|
|
write_prg_byte(0x8000, i | 0x80); // PRG Command + Bank
|
|
|
|
write_prg_byte(0x8000, i); // PRG Bank
|
|
|
|
dumpBankPRG(0x4000, 0x8000, base); // 16K Banks ($C000-$FFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-10-04 15:48:11 +02:00
|
|
|
|
2022-10-01 14:41:47 +02:00
|
|
|
case 93:
|
|
|
|
banks = int_pow(2, prgsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-01 14:41:47 +02:00
|
|
|
write_prg_byte(0x6000, i);
|
|
|
|
write_prg_byte(0x8000, i << 4 | 0x01);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-10-01 14:41:47 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-10-04 15:48:11 +02:00
|
|
|
|
2022-12-22 21:55:00 +01:00
|
|
|
case 94: // bus conflicts - fixed last bank
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize);
|
2022-12-22 21:55:00 +01:00
|
|
|
busConflict = true;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks - 1; i++) {
|
|
|
|
for (size_t x = 0; x < 0x4000; x++) {
|
2022-12-22 21:55:00 +01:00
|
|
|
if (read_prg_byte(0xC000 + x) == (i << 2)) {
|
|
|
|
write_prg_byte(0xC000 + x, i << 2);
|
|
|
|
busConflict = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (busConflict) {
|
|
|
|
write_prg_byte(0x8000 + i, i << 2);
|
|
|
|
}
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-12-22 21:55:00 +01:00
|
|
|
}
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x4000, 0x8000, base);
|
2019-09-05 00:48:39 +02:00
|
|
|
break;
|
|
|
|
|
2023-01-03 19:33:34 +01:00
|
|
|
case 97: // fixed first bank
|
2022-12-22 21:55:00 +01:00
|
|
|
case 180: // bus conflicts - fixed fist bank
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize);
|
2022-12-22 21:55:00 +01:00
|
|
|
busConflict = true;
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 1; i < banks; i++) {
|
|
|
|
for (size_t x = 0; x < 0x4000; x++) {
|
2022-12-22 21:55:00 +01:00
|
|
|
if (read_prg_byte(0x8000 + x) == i) {
|
|
|
|
write_prg_byte(0x8000 + x, i);
|
|
|
|
busConflict = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (busConflict) {
|
|
|
|
write_prg_byte(0x8000 + i, i);
|
|
|
|
}
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x4000, 0x8000, base);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-06-27 09:43:40 +02:00
|
|
|
case 105: // 256K
|
|
|
|
write_mmc1_byte(0xA000, 0x00); // Clear PRG Init/IRQ (Bit 4)
|
|
|
|
write_mmc1_byte(0xA000, 0x10); // Set PRG Init/IRQ (Bit 4) to enable bank swapping
|
|
|
|
for (size_t i = 0; i < 4; i++) { // PRG CHIP 1 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
write_mmc1_byte(0xA000, i << 1);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);// 32K Banks ($8000-$FFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
write_mmc1_byte(0x8000, 0x0C); // Switch 16K Bank ($8000-$BFFF) + Fixed Last Bank ($C000-$FFFF)
|
|
|
|
write_mmc1_byte(0xA000, 0x08); // Select PRG CHIP 2 (Bit 3)
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t j = 0; j < 8; j++) { // PRG CHIP 2 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
write_mmc1_byte(0xE000, j);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base); // 16K Banks ($8000-$BFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-11-18 10:46:13 +01:00
|
|
|
|
2022-11-02 12:27:08 +01:00
|
|
|
case 111:
|
|
|
|
banks = int_pow(2, prgsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-11-02 12:27:08 +01:00
|
|
|
write_prg_byte(0x5000, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-11-02 12:27:08 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-12-10 15:05:16 +01:00
|
|
|
|
2022-12-08 16:10:05 +01:00
|
|
|
case 113:
|
|
|
|
banks = int_pow(2, prgsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-20 10:31:35 +01:00
|
|
|
write_prg_byte(0x4100, (i & 0x07) << 3);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-12-08 16:10:05 +01:00
|
|
|
}
|
|
|
|
break;
|
2023-06-26 12:04:00 +02:00
|
|
|
|
2023-05-11 20:41:19 +02:00
|
|
|
case 114: // Submapper 0
|
|
|
|
banks = int_pow(2, prgsize) * 2;
|
|
|
|
write_prg_byte(0x6000, 0);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2023-05-11 20:41:19 +02:00
|
|
|
write_prg_byte(0xA000, 4);
|
|
|
|
write_prg_byte(0xC000, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x2000, base);
|
2023-05-11 20:41:19 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-10 15:05:16 +01:00
|
|
|
|
2022-12-08 16:10:05 +01:00
|
|
|
case 126:
|
|
|
|
banks = int_pow(2, prgsize) * 2;
|
|
|
|
write_prg_byte(0xA001, 0x80); // enable WRAM
|
|
|
|
write_prg_byte(0x6003, 0x00); // set MMC3 banking mode
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) {
|
2022-12-08 16:10:05 +01:00
|
|
|
write_prg_byte(0x6000, (i & 0x180) >> 3 | (i & 0x70) >> 4); // select outer bank
|
2022-12-20 10:31:35 +01:00
|
|
|
write_prg_byte(0x8000, 6); // 8k bank 0 at $8000
|
2022-12-08 16:10:05 +01:00
|
|
|
write_prg_byte(0x8001, i);
|
|
|
|
write_prg_byte(0x8000, 7); // 8k bank 1 at $A000
|
|
|
|
write_prg_byte(0x8001, i + 1);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-12-08 16:10:05 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-12-20 10:31:35 +01:00
|
|
|
case 134:
|
|
|
|
banks = int_pow(2, prgsize) * 2;
|
|
|
|
write_prg_byte(0x6000, 0x00); // set MMC3 banking mode
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) {
|
2022-12-20 10:31:35 +01:00
|
|
|
write_prg_byte(0x6001, (i & 0x30) >> 4); // select outer bank
|
|
|
|
write_prg_byte(0x8000, 6); // 8k bank 0 at $8000
|
|
|
|
write_prg_byte(0x8001, i);
|
|
|
|
write_prg_byte(0x8000, 7); // 8k bank 1 at $A000
|
|
|
|
write_prg_byte(0x8001, i + 1);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-12-20 10:31:35 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-12-10 15:05:16 +01:00
|
|
|
|
2022-12-05 20:35:51 +01:00
|
|
|
case 142:
|
|
|
|
banks = int_pow(2, prgsize) * 2;
|
|
|
|
base = 0x6000; // 4x 8k switchable PRG ROM banks at $6000-$DFFF
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 4) {
|
2022-12-05 20:35:51 +01:00
|
|
|
write_prg_byte(0xE000, 4); // Select 8 KB PRG bank at CPU $6000-$7FFF
|
|
|
|
write_prg_byte(0xF000, i);
|
|
|
|
write_prg_byte(0xE000, 1); // Select 8 KB PRG bank at CPU $8000-$9FFF
|
|
|
|
write_prg_byte(0xF000, i + 1);
|
|
|
|
write_prg_byte(0xE000, 2); // Select 8 KB PRG bank at CPU $A000-$BFFF
|
|
|
|
write_prg_byte(0xF000, i + 2);
|
|
|
|
write_prg_byte(0xE000, 3); // Select 8 KB PRG bank at CPU $C000-$DFFF
|
|
|
|
write_prg_byte(0xF000, i + 3);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-12-05 20:35:51 +01:00
|
|
|
}
|
|
|
|
break;
|
2023-06-26 12:04:00 +02:00
|
|
|
|
2023-04-30 13:42:16 +02:00
|
|
|
case 148: // Sachen SA-008-A and Tengen 800008 -- Bus conflicts
|
|
|
|
banks = int_pow(2, prgsize) / 2;
|
|
|
|
busConflict = true;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
|
|
|
for (size_t x = 0; x < 0x8000; x++) {
|
2023-04-30 13:42:16 +02:00
|
|
|
if (read_prg_byte(0x8000 + x) == i) {
|
|
|
|
write_prg_byte(0x8000 + x, i << 3);
|
|
|
|
busConflict = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (busConflict) {
|
|
|
|
write_prg_byte(0x8000 + i, i << 3);
|
|
|
|
}
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2023-04-30 13:42:16 +02:00
|
|
|
}
|
|
|
|
break;
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 153: // 512K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize);
|
2024-05-03 23:42:06 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 512K
|
|
|
|
write_prg_byte(0x8000, i >> 4); // PRG Outer Bank (Documentation says duplicate over $8000-$8003 registers)
|
|
|
|
write_prg_byte(0x8001, i >> 4); // PRG Outer Bank
|
|
|
|
write_prg_byte(0x8002, i >> 4); // PRG Outer Bank
|
|
|
|
write_prg_byte(0x8003, i >> 4); // PRG Outer Bank
|
|
|
|
write_prg_byte(0x8008, i & 0xF); // PRG Inner Bank
|
|
|
|
dumpBankPRG(0x0, 0x4000, base); // 16K Banks ($8000-$BFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-10 15:05:16 +01:00
|
|
|
|
2022-12-05 20:35:51 +01:00
|
|
|
case 157:
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < 15; i++) {
|
2022-12-05 20:35:51 +01:00
|
|
|
write_prg_byte(0x8008, i); // select 16k bank at $8000-$BFFF
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-12-05 20:35:51 +01:00
|
|
|
}
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x4000, 0x8000, base); // last 16k bank fixed at $C000-$FFFF
|
2022-12-05 20:35:51 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 162:
|
|
|
|
banks = int_pow(2, prgsize) / 2;
|
|
|
|
write_prg_byte(0x5300, 0x07); // A16-A15 controlled by $5000
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-05 20:35:51 +01:00
|
|
|
write_prg_byte(0x5200, (i & 0x30) >> 4); // A20-A19
|
2022-12-20 10:31:35 +01:00
|
|
|
write_prg_byte(0x5000, i & 0x0F); // A18-A15
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-12-05 20:35:51 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-12-20 10:31:35 +01:00
|
|
|
|
2022-12-05 20:35:51 +01:00
|
|
|
case 163:
|
|
|
|
banks = int_pow(2, prgsize) / 2;
|
|
|
|
write_prg_byte(0x5300, 0x04); // disable bit swap on writes to $5000-$5200
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-05 20:35:51 +01:00
|
|
|
write_prg_byte(0x5200, (i & 0x30) >> 4); // A20-A19
|
2022-12-20 10:31:35 +01:00
|
|
|
write_prg_byte(0x5000, i & 0x0F); // A18-A15
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-12-05 20:35:51 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-12-10 15:05:16 +01:00
|
|
|
|
2022-12-08 16:10:05 +01:00
|
|
|
case 174: // 128k
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < 8; i++) {
|
2022-12-20 10:31:35 +01:00
|
|
|
write_prg_byte(0xFF00 + (i << 4), 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-12-20 10:31:35 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-12-10 15:05:16 +01:00
|
|
|
|
2022-11-24 22:18:46 +01:00
|
|
|
case 176:
|
|
|
|
banks = int_pow(2, prgsize) * 2;
|
|
|
|
write_prg_byte(0x5FF3, 0); // extended MMC3 mode: disabled
|
|
|
|
write_prg_byte(0x5FF0, 1); // 256K outer bank mode
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks - 3; i += 2) {
|
2022-11-24 22:18:46 +01:00
|
|
|
write_prg_byte(0x5FF1, (i & 0xE0) >> 1); // outer bank select
|
|
|
|
write_prg_byte(0x8000, 6);
|
|
|
|
write_prg_byte(0x8001, i);
|
|
|
|
write_prg_byte(0x8000, 7);
|
|
|
|
write_prg_byte(0x8001, i + 1);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-11-24 22:18:46 +01:00
|
|
|
}
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x4000, 0x8000, base);
|
2022-11-24 22:18:46 +01:00
|
|
|
break;
|
2022-12-10 15:05:16 +01:00
|
|
|
|
2022-12-04 08:45:49 +01:00
|
|
|
case 178:
|
|
|
|
banks = int_pow(2, prgsize);
|
2022-12-20 10:31:35 +01:00
|
|
|
write_prg_byte(0x4800, 0); // NROM-256 mode
|
|
|
|
write_prg_byte(0x4803, 0); // set PRG-RAM
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) {
|
2022-12-20 10:31:35 +01:00
|
|
|
write_prg_byte(0x4802, i >> 3); // high PRG (up to 8 bits?!)
|
2022-12-10 15:05:16 +01:00
|
|
|
write_prg_byte(0x4801, i & 0x07); // low PRG (3 bits)
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-12-04 08:45:49 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-10-27 23:43:46 +02:00
|
|
|
|
2022-10-23 20:57:34 +02:00
|
|
|
case 200:
|
2022-12-22 21:55:00 +01:00
|
|
|
case 212:
|
2022-10-23 20:57:34 +02:00
|
|
|
banks = int_pow(2, prgsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-25 12:28:38 +02:00
|
|
|
write_prg_byte(0x8000 + (i & 0x07), 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-10-23 20:57:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 201:
|
|
|
|
banks = int_pow(2, prgsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-23 20:57:34 +02:00
|
|
|
write_prg_byte(0x8000 + (i & 0xFF), 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-10-23 20:57:34 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-10-27 23:43:46 +02:00
|
|
|
|
2022-10-24 14:50:33 +02:00
|
|
|
case 202:
|
|
|
|
banks = int_pow(2, prgsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-24 14:50:33 +02:00
|
|
|
write_prg_byte(0x8000 | (i << 1), 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-10-24 14:50:33 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-10-23 20:57:34 +02:00
|
|
|
|
|
|
|
case 203:
|
2022-10-24 15:04:51 +02:00
|
|
|
banks = int_pow(2, prgsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-23 20:57:34 +02:00
|
|
|
write_prg_byte(0x8000, (i & 0x1F) << 2);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-10-23 20:57:34 +02:00
|
|
|
}
|
|
|
|
break;
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 210: // 128K/256K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, prgsize) * 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0xE000, i); // PRG Bank 0 ($8000-$9FFF) [WRITE NO RAM]
|
|
|
|
write_prg_byte(0xE800, i + 1); // PRG Bank 1 ($A000-$BFFF) [WRITE NO RAM]
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2023-01-03 19:33:34 +01:00
|
|
|
|
2022-12-22 21:55:00 +01:00
|
|
|
case 214:
|
2022-12-06 16:48:53 +01:00
|
|
|
banks = int_pow(2, prgsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-22 21:55:00 +01:00
|
|
|
write_prg_byte(0x8000 | (i << 2), 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-12-06 16:48:53 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-10-27 23:43:46 +02:00
|
|
|
|
2022-10-23 20:57:34 +02:00
|
|
|
case 225:
|
2022-10-27 16:56:46 +02:00
|
|
|
case 255:
|
2022-11-11 12:08:17 +01:00
|
|
|
banks = int_pow(2, prgsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) {
|
2022-11-11 12:08:17 +01:00
|
|
|
write_prg_byte(0x8000 + (((i & 0x40) << 8) | ((i & 0x3F) << 6)), 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-10-23 20:57:34 +02:00
|
|
|
}
|
2022-10-27 23:43:46 +02:00
|
|
|
break;
|
2022-11-18 10:46:13 +01:00
|
|
|
|
2022-11-10 23:20:23 +01:00
|
|
|
case 226:
|
|
|
|
banks = int_pow(2, prgsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) {
|
2022-11-11 10:53:13 +01:00
|
|
|
write_prg_byte(0x8001, (i & 0x40) >> 6);
|
2022-11-10 23:20:23 +01:00
|
|
|
write_prg_byte(0x8000, ((i & 0x20) << 2) | (i & 0x1F));
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-11-10 23:20:23 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-12-20 10:31:35 +01:00
|
|
|
|
2022-12-04 08:45:49 +01:00
|
|
|
case 227:
|
|
|
|
banks = int_pow(2, prgsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-04 08:45:49 +01:00
|
|
|
write_prg_byte(0x8083 + ((i & 0xF) << 3), 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-12-04 08:45:49 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-11-18 10:46:13 +01:00
|
|
|
|
2022-11-08 12:49:42 +01:00
|
|
|
case 228:
|
|
|
|
banks = int_pow(2, prgsize);
|
2023-05-11 21:01:12 +02:00
|
|
|
write_prg_byte(0x8000, 0);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) { // up to 1024k PRG
|
2022-11-08 12:49:42 +01:00
|
|
|
write_prg_byte(0x8000 + ((i & 0x3F) << 6), 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-11-08 12:49:42 +01:00
|
|
|
}
|
2023-05-11 21:01:12 +02:00
|
|
|
if (prgsize > 5) { // reading the 3rd 512k PRG chip (Action 52)
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < 32; i += 2) {
|
2022-11-08 12:49:42 +01:00
|
|
|
write_prg_byte(0x9800 + ((i & 0x1F) << 6), 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-11-08 12:49:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2022-10-23 20:57:34 +02:00
|
|
|
|
|
|
|
case 229:
|
|
|
|
write_prg_byte(0x8000, 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 2; i < 32; i++) {
|
2022-10-27 23:43:46 +02:00
|
|
|
write_prg_byte(0x8000 + i, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-10-23 20:57:34 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-10-27 23:43:46 +02:00
|
|
|
|
2022-10-23 20:57:34 +02:00
|
|
|
case 232:
|
|
|
|
banks = int_pow(2, prgsize) / 4;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t outerbank = 0; outerbank < 4; outerbank++) {
|
2022-10-23 20:57:34 +02:00
|
|
|
write_prg_byte(0x8000, outerbank << 3);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-23 20:57:34 +02:00
|
|
|
write_prg_byte(0xC000, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-10-23 20:57:34 +02:00
|
|
|
}
|
|
|
|
}
|
2022-10-27 23:43:46 +02:00
|
|
|
break;
|
|
|
|
|
2022-10-20 14:01:23 +02:00
|
|
|
case 235:
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < 32; i++) {
|
2022-10-27 23:43:46 +02:00
|
|
|
write_prg_byte(0x8000 + i, 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-10-20 14:01:23 +02:00
|
|
|
}
|
|
|
|
if (prgsize > 6) {
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 32; i < 64; i++) {
|
2022-10-27 23:43:46 +02:00
|
|
|
write_prg_byte(0x80E0 + i, 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-10-20 14:01:23 +02:00
|
|
|
}
|
|
|
|
if (prgsize > 7) {
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 64; i < 96; i++) {
|
2022-10-27 23:43:46 +02:00
|
|
|
write_prg_byte(0x81E0 + i, 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-10-20 14:01:23 +02:00
|
|
|
}
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 96; i < 128; i++) {
|
2022-10-27 23:43:46 +02:00
|
|
|
write_prg_byte(0x82E0 + i, 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-10-20 14:01:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-27 23:43:46 +02:00
|
|
|
break;
|
2023-01-03 19:33:34 +01:00
|
|
|
|
2022-12-30 08:24:54 +01:00
|
|
|
case 236:
|
|
|
|
banks = int_pow(2, prgsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-30 08:24:54 +01:00
|
|
|
write_prg_byte(0x8000 | ((i & 0x38) >> 3), 0); // A19-A17
|
2023-01-03 19:33:34 +01:00
|
|
|
write_prg_byte(0xC030 | (i & 0x0F), 0); // A17-A14
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-12-30 08:24:54 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-10-27 23:43:46 +02:00
|
|
|
|
2022-10-27 16:17:49 +02:00
|
|
|
case 240:
|
|
|
|
banks = int_pow(2, prgsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-27 16:17:49 +02:00
|
|
|
write_prg_byte(0x5FFF, (i & 0xF) << 4);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-10-27 16:17:49 +02:00
|
|
|
}
|
2022-10-27 23:43:46 +02:00
|
|
|
break;
|
|
|
|
|
2023-06-27 09:43:40 +02:00
|
|
|
case 242: // total size is 640k THIS IS NORMAL
|
|
|
|
for (size_t i = 0; i < 32; i++) { // dump 1st chip of 512k
|
2022-10-21 00:43:45 +02:00
|
|
|
write_prg_byte(0x8400 + (i * 4), 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-10-21 00:43:45 +02:00
|
|
|
}
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < 8; i++) { // dump 2nd chip of 128k
|
2022-10-21 00:43:45 +02:00
|
|
|
write_prg_byte(0x8000 + (i * 4), 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x4000, base);
|
2022-10-21 00:43:45 +02:00
|
|
|
}
|
2022-10-27 23:43:46 +02:00
|
|
|
break;
|
|
|
|
|
2022-10-27 16:17:49 +02:00
|
|
|
case 246:
|
|
|
|
banks = int_pow(2, prgsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 4) {
|
2022-10-27 23:43:46 +02:00
|
|
|
write_prg_byte(0x6000, (i | 0));
|
|
|
|
write_prg_byte(0x6001, (i | 1));
|
|
|
|
write_prg_byte(0x6002, (i | 2));
|
|
|
|
write_prg_byte(0x6003, (i | 3));
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x8000, base);
|
2022-10-27 16:17:49 +02:00
|
|
|
}
|
|
|
|
break;
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2022-07-07 00:51:44 +02:00
|
|
|
if (!readrom) {
|
|
|
|
myFile.flush();
|
|
|
|
myFile.close();
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-07-07 00:51:44 +02:00
|
|
|
println_Msg(F("PRG FILE DUMPED!"));
|
2024-03-02 17:26:35 +01:00
|
|
|
println_Msg(FS(FSTRING_EMPTY));
|
2022-07-07 00:51:44 +02:00
|
|
|
display_Update();
|
|
|
|
}
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
set_address(0);
|
|
|
|
PHI2_HI;
|
|
|
|
ROMSEL_HI;
|
|
|
|
LED_BLUE_OFF;
|
|
|
|
}
|
|
|
|
|
2023-04-30 13:42:16 +02:00
|
|
|
void readCHR(bool readrom) {
|
2022-07-07 00:51:44 +02:00
|
|
|
if (!readrom) {
|
|
|
|
display_Clear();
|
|
|
|
display_Update();
|
|
|
|
}
|
2019-09-05 00:48:39 +02:00
|
|
|
|
|
|
|
LED_GREEN_ON;
|
|
|
|
set_address(0);
|
|
|
|
_delay_us(1);
|
|
|
|
if (chrsize == 0) {
|
|
|
|
println_Msg(F("CHR SIZE 0K"));
|
|
|
|
display_Update();
|
2022-10-13 09:49:03 +02:00
|
|
|
} else {
|
2022-07-07 00:51:44 +02:00
|
|
|
if (!readrom) {
|
|
|
|
CreateCHRFileInSD();
|
|
|
|
}
|
2022-07-07 00:15:13 +02:00
|
|
|
if (myFile) {
|
2019-09-05 00:48:39 +02:00
|
|
|
switch (mapper) {
|
2022-10-13 09:49:03 +02:00
|
|
|
case 0: // 8K
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2019-09-05 00:48:39 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
case 155:
|
|
|
|
banks = int_pow(2, chrsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) { // 8K/16K/32K/64K/128K (Bank #s are based on 4K Banks)
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x8000, 0x80); // Clear Register
|
2019-09-05 00:48:39 +02:00
|
|
|
write_mmc1_byte(0xA000, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-06-26 12:04:00 +02:00
|
|
|
case 3: // 8K/16K/32K - bus conflicts
|
2023-07-18 07:17:17 +02:00
|
|
|
case 148: // Sachen SA-008-A and Tengen 800008 - Bus conflicts
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2023-07-18 07:17:17 +02:00
|
|
|
for (size_t x = 0; x < 0x8000; x++) {
|
2023-04-15 11:42:35 +02:00
|
|
|
if (read_prg_byte(0x8000 + x) == i) {
|
|
|
|
write_prg_byte(0x8000 + x, i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
case 47:
|
2022-07-23 11:04:17 +02:00
|
|
|
case 64:
|
2019-09-05 00:48:39 +02:00
|
|
|
case 118:
|
|
|
|
case 119:
|
2022-07-23 11:04:17 +02:00
|
|
|
case 158:
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) * 4;
|
|
|
|
if (mapper == 47)
|
2023-06-27 09:43:40 +02:00
|
|
|
write_prg_byte(0xA001, 0x80); // Block Register - PRG RAM Chip Enable, Writable
|
|
|
|
for (size_t i = 0; i < banks; i += 4) { // 8K/16K/32K/64K/128K/256K
|
2019-09-05 00:48:39 +02:00
|
|
|
if (mapper == 47) {
|
|
|
|
if (i == 0)
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x6000, 0); // Switch to Lower Block
|
2019-09-05 00:48:39 +02:00
|
|
|
else if (i == 128)
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x6000, 1); // Switch to Upper Block
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x8000, 0); // CHR Bank 0 ($0000-$07FF)
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x8001, i);
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x8000, 1); // CHR Bank 1 ($0800-$0FFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x8001, i + 2);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x1000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 5: // 128K/256K/512K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x5101, 0); // 8K CHR Banks
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2019-09-05 00:48:39 +02:00
|
|
|
if (i == 0)
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x5130, 0); // Set Upper 2 bits
|
2019-09-05 00:48:39 +02:00
|
|
|
else if (i == 8)
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x5130, 1); // Set Upper 2 bits
|
2019-09-05 00:48:39 +02:00
|
|
|
else if (i == 16)
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x5130, 2); // Set Upper 2 bits
|
2019-09-05 00:48:39 +02:00
|
|
|
else if (i == 24)
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x5130, 3); // Set Upper 2 bits
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x5127, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 9:
|
2022-10-13 09:49:03 +02:00
|
|
|
case 10: // Mapper 9: 128K, Mapper 10: 64K/128K
|
2019-09-05 00:48:39 +02:00
|
|
|
if (mapper == 9)
|
|
|
|
banks = 32;
|
2022-10-13 09:49:03 +02:00
|
|
|
else // Mapper 10
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 64K/128K
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0xB000, i);
|
|
|
|
write_prg_byte(0xC000, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x1000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-10-13 09:49:03 +02:00
|
|
|
|
2022-10-12 23:07:43 +02:00
|
|
|
case 11:
|
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0xFFB0 + i, i << 4);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-10-12 23:07:43 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-10-13 09:49:03 +02:00
|
|
|
|
2019-09-05 00:48:39 +02:00
|
|
|
case 16:
|
2022-10-13 09:49:03 +02:00
|
|
|
case 159: // 128K/256K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) * 4;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x6000, i); // Submapper 4
|
|
|
|
write_prg_byte(0x8000, i); // Submapper 5
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x400);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 18: // 128K/256K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) * 4;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0xA000, i & 0xF); // CHR Bank Lower 4 bits
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0xA001, (i >> 4) & 0xF); // CHR Bank Upper 4 bits
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x400);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 19: // 128K/256K
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t j = 0; j < 64; j++) { // Init Register
|
2022-10-13 09:49:03 +02:00
|
|
|
write_ram_byte(0xE800, 0xC0); // CHR RAM High/Low Disable (ROM Enable)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
banks = int_pow(2, chrsize) * 4;
|
2022-10-13 09:49:03 +02:00
|
|
|
write_ram_byte(0xE800, 0xC0); // CHR RAM High/Low Disable (ROM Enable)
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 8) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x8000, i); // CHR Bank 0
|
|
|
|
write_prg_byte(0x8800, i + 1); // CHR Bank 1
|
|
|
|
write_prg_byte(0x9000, i + 2); // CHR Bank 2
|
|
|
|
write_prg_byte(0x9800, i + 3); // CHR Bank 3
|
|
|
|
write_prg_byte(0xA000, i + 4); // CHR Bank 4
|
|
|
|
write_prg_byte(0xA800, i + 5); // CHR Bank 5
|
|
|
|
write_prg_byte(0xB000, i + 6); // CHR Bank 6
|
|
|
|
write_prg_byte(0xB800, i + 7); // CHR Bank 7
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 21: // 128K/256K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) * 4;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0xB000, i & 0xF); // CHR Bank Lower 4 bits
|
|
|
|
if (chrsize == 5) // Check CHR Size to determine VRC4a (128K) or VRC4c (256K)
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0xB002, (i >> 4) & 0xF); // CHR Bank Upper 4 bits VRC4a (Wai Wai World 2)
|
2022-10-13 09:49:03 +02:00
|
|
|
else // banks == 256
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0xB040, (i >> 4) & 0xF); // CHR Bank Upper 4 bits VRC4c (Ganbare Goemon Gaiden 2)
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x400);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 22: // 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) * 4;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0xB000, (i << 1) & 0xF); // CHR Bank Lower 4 bits
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0xB002, (i >> 3) & 0xF); // CHR Bank Upper 4 bits
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x400);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 23: // 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
// Detect VRC4e Carts - read PRG 0x1FFF6 (DATE)
|
|
|
|
// Boku Dracula-kun = 890810, Tiny Toon = 910809
|
2020-03-03 11:16:27 +01:00
|
|
|
// Crisis Force = 910701, Parodius Da! = 900916
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x8000, 15);
|
|
|
|
prgchk0 = read_prg_byte(0x9FF6);
|
2022-10-13 09:49:03 +02:00
|
|
|
if (prgchk0 == 0x30) { // Check for "0" in middle of date
|
|
|
|
vrc4e = true; // VRC4e Cart
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
banks = int_pow(2, chrsize) * 4;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0xB000, i & 0xF); // CHR Bank Lower 4 bits
|
2019-09-05 00:48:39 +02:00
|
|
|
if (vrc4e == true)
|
2020-03-03 11:16:27 +01:00
|
|
|
write_prg_byte(0xB004, (i >> 4) & 0xF); // CHR Bank Upper 4 bits VRC4e
|
2019-09-05 00:48:39 +02:00
|
|
|
else
|
|
|
|
write_prg_byte(0xB001, (i >> 4) & 0xF); // CHR Bank Upper 4 bits VRC2b/VRC4f
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x400);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 24: // 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) * 4;
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0xB003, 0); // PPU Banking Mode 0
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 8) {
|
2024-05-03 23:42:06 +02:00
|
|
|
write_prg_byte(0xD000, i); // CHR Bank 0
|
|
|
|
write_prg_byte(0xD001, i + 1); // CHR Bank 1
|
|
|
|
write_prg_byte(0xD002, i + 2); // CHR Bank 2
|
|
|
|
write_prg_byte(0xD003, i + 3); // CHR Bank 3
|
|
|
|
write_prg_byte(0xE000, i + 4); // CHR Bank 4 [WRITE NO RAM]
|
|
|
|
write_prg_byte(0xE001, i + 5); // CHR Bank 5 [WRITE NO RAM]
|
|
|
|
write_prg_byte(0xE002, i + 6); // CHR Bank 6 [WRITE NO RAM]
|
|
|
|
write_prg_byte(0xE003, i + 7); // CHR Bank 7 [WRITE NO RAM]
|
|
|
|
dumpBankCHR(0x0, 0x2000); // 1K Banks
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 25: // 128K/256K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) * 4;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2023-01-03 19:33:34 +01:00
|
|
|
write_prg_byte(0xB000, i & 0xF); // CHR Bank Lower 4 bits
|
|
|
|
write_prg_byte(0xB00A, (i >> 4) & 0xF); // Combine VRC2c and VRC4b, VRC4d reg
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x400);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 26: // 128K/256K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) * 4;
|
2020-07-03 19:01:35 +02:00
|
|
|
write_prg_byte(0xB003, 0x00);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 4) {
|
2024-05-03 23:42:06 +02:00
|
|
|
write_prg_byte(0xD000, i + 0); // CHR Bank 0
|
|
|
|
write_prg_byte(0xD002, i + 1); // CHR Bank 1
|
|
|
|
write_prg_byte(0xD001, i + 2); // CHR Bank 2
|
|
|
|
write_prg_byte(0xD003, i + 3); // CHR Bank 3
|
|
|
|
dumpBankCHR(0x0, 0x1000); // 1K Banks
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 32: // 128K
|
|
|
|
case 65: // 128K/256K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) * 4;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 8) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0xB000, i); // CHR Bank 0
|
|
|
|
write_prg_byte(0xB001, i + 1); // CHR Bank 1
|
|
|
|
write_prg_byte(0xB002, i + 2); // CHR Bank 2
|
|
|
|
write_prg_byte(0xB003, i + 3); // CHR Bank 3
|
|
|
|
write_prg_byte(0xB004, i + 4); // CHR Bank 4
|
|
|
|
write_prg_byte(0xB005, i + 5); // CHR Bank 5
|
|
|
|
write_prg_byte(0xB006, i + 6); // CHR Bank 6
|
|
|
|
write_prg_byte(0xB007, i + 7); // CHR Bank 7
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 33: // 128K/256K
|
|
|
|
case 48: // 256K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) * 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) { // 2K Banks
|
|
|
|
write_prg_byte(0x8002, i); // CHR Bank 0
|
|
|
|
write_prg_byte(0x8003, i + 1); // CHR Bank 1
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x1000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2023-06-26 12:04:00 +02:00
|
|
|
|
2023-04-10 10:35:17 +02:00
|
|
|
case 34: // NINA
|
|
|
|
banks = int_pow(2, chrsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) {
|
2023-06-26 12:04:00 +02:00
|
|
|
write_prg_byte(0x7FFE, i); // Select 4 KB CHR bank at $0000
|
|
|
|
write_prg_byte(0x7FFF, i + 1); // Select 4 KB CHR bank at $1000
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2023-04-10 10:35:17 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-20 10:31:35 +01:00
|
|
|
|
2022-12-14 13:15:32 +01:00
|
|
|
case 35:
|
|
|
|
case 90:
|
|
|
|
case 209:
|
|
|
|
case 211:
|
|
|
|
banks = int_pow(2, chrsize) / 2;
|
|
|
|
write_prg_byte(0xD000, 0x02);
|
|
|
|
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-14 13:15:32 +01:00
|
|
|
write_prg_byte(0xD003, (((i >> 3) & 0x18) | 0x20));
|
|
|
|
write_prg_byte(0x9000, (i & 0x3f));
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-12-14 13:15:32 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-10-28 15:02:51 +02:00
|
|
|
|
2022-10-28 10:29:54 +02:00
|
|
|
case 36:
|
2023-02-06 21:28:51 +01:00
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-28 10:29:54 +02:00
|
|
|
write_prg_byte(0x4200, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-10-28 10:29:54 +02:00
|
|
|
}
|
|
|
|
break;
|
2019-09-05 00:48:39 +02:00
|
|
|
|
|
|
|
case 37:
|
|
|
|
banks = int_pow(2, chrsize) * 4;
|
2023-06-27 09:43:40 +02:00
|
|
|
write_prg_byte(0xA001, 0x80); // Block Register - PRG RAM Chip Enable, Writable
|
|
|
|
for (size_t i = 0; i < banks; i += 4) { // 256K
|
2019-09-05 00:48:39 +02:00
|
|
|
if (i == 0)
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x6000, 0); // Switch to Lower Block ($00000-$1FFFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
else if (i == 128)
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x6000, 4); // Switch to Upper Block ($20000-$3FFFF)
|
|
|
|
write_prg_byte(0x8000, 0); // CHR Bank 0 ($0000-$07FF)
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x8001, i);
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x8000, 1); // CHR Bank 1 ($0800-$0FFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x8001, i + 2);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x1000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2023-06-26 12:04:00 +02:00
|
|
|
|
2023-04-15 16:12:41 +02:00
|
|
|
case 38:
|
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2023-04-15 16:12:41 +02:00
|
|
|
write_prg_byte(0x7000, i << 2);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2023-04-15 16:12:41 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-10 15:05:16 +01:00
|
|
|
|
|
|
|
case 42:
|
2022-12-05 20:35:51 +01:00
|
|
|
banks = int_pow(2, chrsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-05 20:35:51 +01:00
|
|
|
write_prg_byte(0x8000, i & 0x0F);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x1000);
|
2022-12-05 20:35:51 +01:00
|
|
|
}
|
|
|
|
break;
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 45: // 128K/256K/512K/1024K
|
2022-09-25 11:09:54 +02:00
|
|
|
banks = int_pow(2, chrsize) * 4;
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0xA001, 0x80); // Unlock Write Protection - not used by some carts
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-09-25 11:09:54 +02:00
|
|
|
// set outer bank registers
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x6000, 0x00); // CHR-OR
|
|
|
|
write_prg_byte(0x6000, 0x00); // PRG-OR
|
|
|
|
write_prg_byte(0x6000, (((i / 256) << 4) | 0x0F)); // CHR-AND,CHR-OR/PRG-OR
|
|
|
|
write_prg_byte(0x6000, 0x80); // PRG-AND
|
2022-09-25 11:09:54 +02:00
|
|
|
// set inner bank registers
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x8000, 0x2); // CHR Bank 2 ($1000-$13FF)
|
2022-09-25 11:09:54 +02:00
|
|
|
write_prg_byte(0x8001, i);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t address = 0x1000; address < 0x1200; address += 512) {
|
2022-10-13 09:49:03 +02:00
|
|
|
dumpCHR_M2(address); // Read CHR with M2 Pulse
|
2022-09-25 11:09:54 +02:00
|
|
|
}
|
|
|
|
// set outer bank registers
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x6000, 0x00); // CHR-OR
|
|
|
|
write_prg_byte(0x6000, 0x00); // PRG-OR
|
|
|
|
write_prg_byte(0x6000, (((i / 256) << 4) | 0x0F)); // CHR-AND,CHR-OR/PRG-OR
|
|
|
|
write_prg_byte(0x6000, 0x80); // PRG-AND
|
2022-09-25 11:09:54 +02:00
|
|
|
// set inner bank registers
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x8000, 0x2); // CHR Bank 2 ($1000-$13FF)
|
2022-09-25 11:09:54 +02:00
|
|
|
write_prg_byte(0x8001, i);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t address = 0x1200; address < 0x1400; address += 512) {
|
2022-10-13 09:49:03 +02:00
|
|
|
dumpCHR_M2(address); // Read CHR with M2 Pulse
|
2022-09-25 11:09:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2022-12-10 15:05:16 +01:00
|
|
|
|
|
|
|
case 46:
|
2022-12-06 16:48:53 +01:00
|
|
|
banks = int_pow(2, chrsize); // 8k banks
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-06 16:48:53 +01:00
|
|
|
write_prg_byte(0x6000, (i & 0x78) << 1); // high bits
|
2022-12-10 15:05:16 +01:00
|
|
|
write_prg_byte(0x8000, (i & 0x07) << 4); // low bits
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-12-06 16:48:53 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 52:
|
|
|
|
banks = int_pow(2, chrsize);
|
2022-12-10 15:05:16 +01:00
|
|
|
write_prg_byte(0xA001, 0x80); // enable WRAM write
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-06 16:48:53 +01:00
|
|
|
write_prg_byte(0x6000, (i & 0x04) << 2 | (i & 0x03) << 4 | 0x40);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x1000);
|
2022-12-06 16:48:53 +01:00
|
|
|
}
|
|
|
|
break;
|
2023-01-03 19:33:34 +01:00
|
|
|
|
2022-12-30 08:24:54 +01:00
|
|
|
case 56:
|
|
|
|
banks = int_pow(2, chrsize) * 4;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-30 08:24:54 +01:00
|
|
|
write_prg_byte(0xFC00, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x400);
|
2022-12-30 08:24:54 +01:00
|
|
|
}
|
|
|
|
break;
|
2023-01-03 19:33:34 +01:00
|
|
|
|
2022-12-22 21:55:00 +01:00
|
|
|
case 57:
|
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2023-01-03 19:33:34 +01:00
|
|
|
write_prg_byte(0x8800, i & 0x07); // A15-A13
|
2022-12-22 21:55:00 +01:00
|
|
|
write_prg_byte(0x8000, 0x80 | ((i & 0x08) << 3)); // A16
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-12-22 21:55:00 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-10-27 23:43:46 +02:00
|
|
|
|
2022-10-23 20:57:34 +02:00
|
|
|
case 58:
|
|
|
|
case 213:
|
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-23 20:57:34 +02:00
|
|
|
write_prg_byte(0x8000 + ((i & 0x07) << 3), 0x00);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-10-23 20:57:34 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-10 15:05:16 +01:00
|
|
|
|
|
|
|
case 59:
|
2022-12-08 16:10:05 +01:00
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-08 16:10:05 +01:00
|
|
|
write_prg_byte(0x8000 + (i & 0x07), 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-12-08 16:10:05 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-10-27 23:43:46 +02:00
|
|
|
|
2022-10-22 09:01:18 +02:00
|
|
|
case 60:
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < 4; i++) {
|
2022-10-22 09:01:18 +02:00
|
|
|
write_prg_byte(0x8D8D, i);
|
|
|
|
delay(500);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-10-22 09:01:18 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-10-27 23:43:46 +02:00
|
|
|
|
2022-10-19 14:43:42 +02:00
|
|
|
case 62:
|
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-19 14:43:42 +02:00
|
|
|
write_prg_byte(0x8000 + (i / 4), i & 3);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-10-19 14:43:42 +02:00
|
|
|
}
|
2022-10-27 23:43:46 +02:00
|
|
|
break;
|
2023-06-26 12:04:00 +02:00
|
|
|
|
2023-04-15 11:42:35 +02:00
|
|
|
case 66: // 16K/32K
|
|
|
|
case 70:
|
|
|
|
case 152: // 128K
|
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 8K Banks
|
|
|
|
write_prg_byte(0x8000, i); // CHR Bank 0
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2023-04-15 11:42:35 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-09-25 11:09:54 +02:00
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 67: // 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) * 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 4) { // 2K Banks
|
|
|
|
write_prg_byte(0x8800, i); // CHR Bank 0
|
|
|
|
write_prg_byte(0x9800, i + 1); // CHR Bank 1
|
|
|
|
write_prg_byte(0xA800, i + 2); // CHR Bank 2
|
|
|
|
write_prg_byte(0xB800, i + 3); // CHR Bank 3
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 68: // 128K/256K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) * 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 4) { // 2K Banks
|
|
|
|
write_prg_byte(0x8000, i); // CHR Bank 0
|
|
|
|
write_prg_byte(0x9000, i + 1); // CHR Bank 1
|
|
|
|
write_prg_byte(0xA000, i + 2); // CHR Bank 2
|
|
|
|
write_prg_byte(0xB000, i + 3); // CHR Bank 3
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 69: // 128K/256K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) * 4;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2024-05-03 23:42:06 +02:00
|
|
|
write_prg_byte(0x8000, 0); // Command Register - CHR Bank 0
|
|
|
|
write_prg_byte(0xA000, i); // Parameter Register - ($0000-$03FF)
|
|
|
|
dumpBankCHR(0x0, 0x400); // 1K Banks
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 72: // 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x8000, 0); // Reset Register
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 8K Banks
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x8000, i | 0x40); // CHR Command + Bank
|
|
|
|
write_prg_byte(0x8000, i); // CHR Bank
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 75: // 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 4K Banks
|
2022-10-13 09:49:03 +02:00
|
|
|
write_reg_byte(0xE000, i); // CHR Bank Low Bits [WRITE RAM SAFE]
|
|
|
|
write_prg_byte(0x9000, (i & 0x10) >> 3); // High Bit
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x1000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 76: // 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) * 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) { // 2K Banks
|
|
|
|
write_prg_byte(0x8000, 2); // CHR Command ($0000-$07FF) 2K Bank
|
|
|
|
write_prg_byte(0x8001, i); // CHR Bank
|
|
|
|
write_prg_byte(0x8000, 3); // CHR Command ($0800-$0FFF) 2K Bank
|
|
|
|
write_prg_byte(0x8001, i + 1); // CHR Bank
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x1000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 77: // 32K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) * 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 2K Banks
|
|
|
|
write_prg_byte(0x8000, i << 4); // CHR Bank 0
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x800);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 78: // 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2024-05-03 23:42:06 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 8K Banks
|
|
|
|
write_prg_byte(0x8000, i << 4); // CHR Bank 0
|
|
|
|
dumpBankCHR(0x0, 0x2000); // 8K Banks ($0000-$1FFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-10-13 09:49:03 +02:00
|
|
|
|
2022-10-12 19:49:32 +02:00
|
|
|
case 79:
|
2022-10-12 22:11:35 +02:00
|
|
|
case 146:
|
2022-10-12 19:49:32 +02:00
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-12 19:49:32 +02:00
|
|
|
write_prg_byte(0x4100, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-10-12 19:49:32 +02:00
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
break;
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 80: // 128K/256K
|
|
|
|
case 82: // 128K/256K
|
|
|
|
case 207: // 128K [CART SOMETIMES NEEDS POWERCYCLE]
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) * 4;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 4) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x7EF2, i); // CHR Bank 2 [REGISTERS 0x7EF0/0x7EF1 WON'T WORK]
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x7EF3, i + 1); // CHR Bank 3
|
|
|
|
write_prg_byte(0x7EF4, i + 2); // CHR Bank 4
|
|
|
|
write_prg_byte(0x7EF5, i + 3); // CHR Bank 5
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 85: // 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) * 4;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 8) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0xA000, i); // CHR Bank 0
|
|
|
|
write_prg_byte(0xA008, i + 1); // CHR Bank 1
|
|
|
|
write_prg_byte(0xB000, i + 2); // CHR Bank 2
|
|
|
|
write_prg_byte(0xB008, i + 3); // CHR Bank 3
|
|
|
|
write_prg_byte(0xC000, i + 4); // CHR Bank 4
|
|
|
|
write_prg_byte(0xC008, i + 5); // CHR Bank 5
|
|
|
|
write_prg_byte(0xD000, i + 6); // CHR Bank 6
|
|
|
|
write_prg_byte(0xD008, i + 7); // CHR Bank 7
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 86: // 64K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 8K Banks
|
2019-09-05 00:48:39 +02:00
|
|
|
if (i < 4)
|
|
|
|
write_prg_byte(0x6000, i & 0x3);
|
|
|
|
else
|
|
|
|
write_prg_byte(0x6000, (i | 0x40) & 0x43);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 87: // 16K/32K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 16K/32K
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x6000, (((i & 0x1) << 1) | ((i & 0x2) >> 1)));
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 88: // 128K
|
|
|
|
case 95: // 32K
|
|
|
|
case 154: // 128K
|
|
|
|
case 206: // 16K/32K/64K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) * 4;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) { // 1K Banks
|
2019-09-05 00:48:39 +02:00
|
|
|
if (i < 64) {
|
2023-06-27 09:43:40 +02:00
|
|
|
write_prg_byte(0x8000, 0); // CHR Command ($0000-$07FF) 2K Bank
|
|
|
|
write_prg_byte(0x8001, i & 0x3F); // CHR Bank
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x800);
|
2022-10-13 09:49:03 +02:00
|
|
|
} else {
|
|
|
|
write_prg_byte(0x8000, 2); // CHR Command ($1000-$13FF) 1K Bank
|
|
|
|
write_prg_byte(0x8001, i); // CHR Bank
|
|
|
|
write_prg_byte(0x8000, 3); // CHR Command ($1400-$17FF) 1K Bank
|
|
|
|
write_prg_byte(0x8001, i + 1); // CHR Bank
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x1000, 0x1800);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 89: // 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 8K Banks
|
2019-09-05 00:48:39 +02:00
|
|
|
if (i < 8)
|
|
|
|
write_prg_byte(0x8000, i & 0x7);
|
|
|
|
else
|
|
|
|
write_prg_byte(0x8000, (i | 0x80) & 0x87);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-10-28 15:02:51 +02:00
|
|
|
|
2022-10-28 11:49:55 +02:00
|
|
|
case 91:
|
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 8) {
|
2022-10-28 15:02:51 +02:00
|
|
|
write_prg_byte(0x6000, (i / 2) | 0);
|
|
|
|
write_prg_byte(0x6001, (i / 2) | 1);
|
|
|
|
write_prg_byte(0x6002, (i / 2) | 2);
|
|
|
|
write_prg_byte(0x6003, (i / 2) | 3);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-10-28 11:49:55 +02:00
|
|
|
}
|
|
|
|
break;
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 92: // 128K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x8000, 0); // Reset Register
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 8K Banks
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x8000, i | 0x40); // CHR Command + Bank
|
|
|
|
write_prg_byte(0x8000, i); // CHR Bank
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-10 15:05:16 +01:00
|
|
|
|
|
|
|
case 113:
|
2022-12-08 16:10:05 +01:00
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-20 10:31:35 +01:00
|
|
|
write_prg_byte(0x4100, (i & 0x08) << 3 | (i & 0x07));
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-12-08 16:10:05 +01:00
|
|
|
}
|
|
|
|
break;
|
2023-06-26 12:04:00 +02:00
|
|
|
|
2023-05-11 20:41:19 +02:00
|
|
|
case 114: // Submapper 0
|
|
|
|
banks = int_pow(2, chrsize) * 4;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2023-05-11 20:41:19 +02:00
|
|
|
write_prg_byte(0x6000, (i & 0x80) >> 7);
|
|
|
|
write_prg_byte(0xA000, 6);
|
|
|
|
write_prg_byte(0xC000, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x1000, 0x1400);
|
2023-05-11 20:41:19 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-10 15:05:16 +01:00
|
|
|
|
|
|
|
case 126:
|
2022-12-08 16:10:05 +01:00
|
|
|
banks = int_pow(2, chrsize) * 2;
|
|
|
|
write_prg_byte(0xA001, 0x80); // enable WRAM
|
|
|
|
write_prg_byte(0x6003, 0x00); // set MMC3 banking mode
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) {
|
2022-12-08 16:10:05 +01:00
|
|
|
write_prg_byte(0x6000, (i & 0x200) >> 5 | (i & 0x100) >> 3); // select outer bank
|
2022-12-20 10:31:35 +01:00
|
|
|
write_prg_byte(0x8000, 0); // 2k bank 0 at $0000
|
2022-12-08 16:10:05 +01:00
|
|
|
write_prg_byte(0x8001, i);
|
|
|
|
write_prg_byte(0x8000, 1); // 2k bank 1 at $0800
|
|
|
|
write_prg_byte(0x8001, i + 2);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x1000);
|
2022-12-08 16:10:05 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-12-10 15:05:16 +01:00
|
|
|
|
|
|
|
case 134:
|
|
|
|
banks = int_pow(2, chrsize) * 2;
|
|
|
|
write_prg_byte(0x6000, 0x00); // set MMC3 banking mode
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 2) {
|
2022-12-10 15:05:16 +01:00
|
|
|
write_prg_byte(0x6001, (i & 0x180) >> 3); // select outer bank
|
2022-12-20 10:31:35 +01:00
|
|
|
write_prg_byte(0x8000, 0); // 2k bank 0 at $0000
|
2022-12-10 15:05:16 +01:00
|
|
|
write_prg_byte(0x8001, i);
|
|
|
|
write_prg_byte(0x8000, 1); // 2k bank 1 at $0800
|
|
|
|
write_prg_byte(0x8001, i + 2);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x1000);
|
2022-12-10 15:05:16 +01:00
|
|
|
}
|
|
|
|
break;
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 140: // 32K/128K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 8K Banks
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x6000, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2023-06-26 12:04:00 +02:00
|
|
|
|
2022-12-20 10:31:35 +01:00
|
|
|
case 174: // 64k
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < 8; i++) {
|
2022-12-20 10:31:35 +01:00
|
|
|
write_prg_byte(0xFF00 + (i << 1), 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-12-20 10:31:35 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-11-24 22:18:46 +01:00
|
|
|
case 176:
|
|
|
|
banks = int_pow(2, chrsize) * 4;
|
|
|
|
write_prg_byte(0x5FF3, 0); // extended MMC3 mode: disabled
|
|
|
|
write_prg_byte(0x5FF0, 1); // 256K outer bank mode
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 8) {
|
2022-11-24 22:18:46 +01:00
|
|
|
write_prg_byte(0x5FF2, (i & 0x700) >> 3); // outer 256k bank
|
|
|
|
write_prg_byte(0x8000, 0);
|
|
|
|
write_prg_byte(0x8001, i);
|
|
|
|
write_prg_byte(0x8000, 0x0A);
|
|
|
|
write_prg_byte(0x8001, i + 1);
|
|
|
|
write_prg_byte(0x8000, 1);
|
|
|
|
write_prg_byte(0x8001, i + 2);
|
|
|
|
write_prg_byte(0x8000, 0x0B);
|
|
|
|
write_prg_byte(0x8001, i + 3);
|
|
|
|
write_prg_byte(0x8000, 2);
|
|
|
|
write_prg_byte(0x8001, i + 4);
|
|
|
|
write_prg_byte(0x8000, 3);
|
|
|
|
write_prg_byte(0x8001, i + 5);
|
|
|
|
write_prg_byte(0x8000, 4);
|
|
|
|
write_prg_byte(0x8001, i + 6);
|
|
|
|
write_prg_byte(0x8000, 5);
|
|
|
|
write_prg_byte(0x8001, i + 7);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-11-24 22:18:46 +01:00
|
|
|
}
|
|
|
|
break;
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 184: // 16K/32K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize);
|
2024-05-03 23:42:06 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 4K Banks
|
|
|
|
write_prg_byte(0x6000, i); // CHR LOW (Bits 0-2) ($0000-$0FFF)
|
|
|
|
dumpBankCHR(0x0, 0x1000); // 4K Banks ($0000-$0FFF)
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-06-27 09:43:40 +02:00
|
|
|
case 185: // 8K [READ 32K TO OVERRIDE LOCKOUT]
|
|
|
|
for (size_t i = 0; i < 4; i++) { // Read 32K to locate valid 8K
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x8000, i);
|
2023-06-27 09:43:40 +02:00
|
|
|
uint8_t chrcheck = read_chr_byte(0);
|
|
|
|
for (size_t address = 0x0; address < 0x2000; address += 512) {
|
|
|
|
for (size_t x = 0; x < 512; x++) {
|
2019-09-05 00:48:39 +02:00
|
|
|
sdBuffer[x] = read_chr_byte(address + x);
|
|
|
|
}
|
|
|
|
if (chrcheck != 0xFF)
|
2022-07-07 00:15:13 +02:00
|
|
|
myFile.write(sdBuffer, 512);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2022-10-27 23:43:46 +02:00
|
|
|
|
2022-10-23 20:57:34 +02:00
|
|
|
case 200:
|
2022-12-22 21:55:00 +01:00
|
|
|
case 212:
|
2022-10-23 20:57:34 +02:00
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-25 12:28:38 +02:00
|
|
|
write_prg_byte(0x8000 + (i & 0x07), 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-10-23 20:57:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 201:
|
2022-10-27 23:43:46 +02:00
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-27 23:43:46 +02:00
|
|
|
write_prg_byte(0x8000 + (i & 0xFF), 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-10-23 20:57:34 +02:00
|
|
|
}
|
2022-10-27 23:43:46 +02:00
|
|
|
break;
|
|
|
|
|
2022-10-24 14:50:33 +02:00
|
|
|
case 202:
|
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-24 14:50:33 +02:00
|
|
|
write_prg_byte(0x8000 | (i << 1), 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-10-24 14:50:33 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-10-23 20:57:34 +02:00
|
|
|
|
|
|
|
case 203:
|
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-23 20:57:34 +02:00
|
|
|
write_prg_byte(0x8000, (i & 0x03));
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-10-23 20:57:34 +02:00
|
|
|
}
|
2022-10-27 23:43:46 +02:00
|
|
|
break;
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 210: // 128K/256K
|
2019-09-05 00:48:39 +02:00
|
|
|
banks = int_pow(2, chrsize) * 4;
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0xE800, 0xC0); // CHR RAM DISABLE (Bit 6 and 7) [WRITE NO RAM]
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 8) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x8000, i); // CHR Bank 0
|
|
|
|
write_prg_byte(0x8800, i + 1); // CHR Bank 1
|
|
|
|
write_prg_byte(0x9000, i + 2); // CHR Bank 2
|
|
|
|
write_prg_byte(0x9800, i + 3); // CHR Bank 3
|
|
|
|
write_prg_byte(0xA000, i + 4); // CHR Bank 4
|
|
|
|
write_prg_byte(0xA800, i + 5); // CHR Bank 5
|
|
|
|
write_prg_byte(0xB000, i + 6); // CHR Bank 6
|
|
|
|
write_prg_byte(0xB800, i + 7); // CHR Bank 7
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2023-01-03 19:33:34 +01:00
|
|
|
|
2022-12-22 21:55:00 +01:00
|
|
|
case 214:
|
2022-12-06 16:48:53 +01:00
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-22 21:55:00 +01:00
|
|
|
write_prg_byte(0x8000 | (i << 2), 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-12-06 16:48:53 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-10-27 23:43:46 +02:00
|
|
|
|
|
|
|
case 225:
|
|
|
|
case 255:
|
2022-10-23 20:57:34 +02:00
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-11-11 12:08:17 +01:00
|
|
|
write_prg_byte(0x8000 + (((i & 0x40) << 8) | (i & 0x3F)), 0);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-10-23 20:57:34 +02:00
|
|
|
}
|
2022-10-27 23:43:46 +02:00
|
|
|
break;
|
2022-11-18 10:46:13 +01:00
|
|
|
|
2022-11-08 12:49:42 +01:00
|
|
|
case 228:
|
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-05-11 21:01:12 +02:00
|
|
|
write_prg_byte(0x8000, 0);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2023-05-11 21:01:12 +02:00
|
|
|
write_prg_byte(0x8000 + ((i & 0x3C) >> 2), i & 0x03);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-11-08 12:49:42 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-10-23 20:57:34 +02:00
|
|
|
|
2022-11-08 12:49:42 +01:00
|
|
|
case 229:
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < 32; i++) {
|
2022-10-27 23:43:46 +02:00
|
|
|
write_prg_byte(0x8000 + i, i);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-10-23 20:57:34 +02:00
|
|
|
}
|
|
|
|
break;
|
2023-01-03 19:33:34 +01:00
|
|
|
|
2022-12-30 08:24:54 +01:00
|
|
|
case 236:
|
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-12-30 08:24:54 +01:00
|
|
|
write_prg_byte(0x8000 | (i & 0x0F), 0); // A16-A13
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-12-30 08:24:54 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-10-27 23:43:46 +02:00
|
|
|
|
2022-10-27 16:17:49 +02:00
|
|
|
case 240:
|
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) {
|
2022-10-27 23:43:46 +02:00
|
|
|
write_prg_byte(0x5FFF, (i & 0xF));
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-10-27 16:17:49 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 246:
|
|
|
|
banks = int_pow(2, chrsize) / 2;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i += 4) {
|
2022-10-27 16:17:49 +02:00
|
|
|
write_prg_byte(0x6004, (i | 0));
|
|
|
|
write_prg_byte(0x6005, (i | 1));
|
|
|
|
write_prg_byte(0x6006, (i | 2));
|
|
|
|
write_prg_byte(0x6007, (i | 3));
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankCHR(0x0, 0x2000);
|
2022-10-27 16:17:49 +02:00
|
|
|
}
|
|
|
|
break;
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2022-07-07 00:51:44 +02:00
|
|
|
if (!readrom) {
|
|
|
|
myFile.flush();
|
|
|
|
myFile.close();
|
2019-09-05 00:48:39 +02:00
|
|
|
|
2022-07-07 00:51:44 +02:00
|
|
|
println_Msg(F("CHR FILE DUMPED!"));
|
2024-03-02 17:26:35 +01:00
|
|
|
println_Msg(FS(FSTRING_EMPTY));
|
2022-07-07 00:51:44 +02:00
|
|
|
display_Update();
|
|
|
|
}
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
set_address(0);
|
|
|
|
PHI2_HI;
|
|
|
|
ROMSEL_HI;
|
|
|
|
LED_GREEN_OFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************
|
|
|
|
RAM Functions
|
|
|
|
*****************************************/
|
|
|
|
void readRAM() {
|
|
|
|
display_Clear();
|
|
|
|
display_Update();
|
|
|
|
|
|
|
|
LED_BLUE_ON;
|
|
|
|
LED_GREEN_ON;
|
|
|
|
set_address(0);
|
|
|
|
_delay_us(1);
|
|
|
|
if (ramsize == 0) {
|
|
|
|
|
|
|
|
println_Msg(F("RAM SIZE 0K"));
|
|
|
|
display_Update();
|
2022-10-13 09:49:03 +02:00
|
|
|
} else {
|
2019-09-05 00:48:39 +02:00
|
|
|
CreateRAMFileInSD();
|
|
|
|
word base = 0x6000;
|
2022-07-07 00:15:13 +02:00
|
|
|
if (myFile) {
|
2019-09-05 00:48:39 +02:00
|
|
|
switch (mapper) {
|
2024-05-03 23:42:06 +02:00
|
|
|
case 0: // 2K/4K
|
|
|
|
dumpBankPRG(0x0, (0x800 * ramsize), base); // 2K/4K
|
|
|
|
break; // SWITCH MUST BE IN OFF POSITION
|
2019-11-25 11:53:45 +01:00
|
|
|
|
2019-09-05 00:48:39 +02:00
|
|
|
case 1:
|
2023-06-27 09:43:40 +02:00
|
|
|
case 155: // 8K/16K/32K
|
|
|
|
banks = int_pow(2, ramsize) / 2; // banks = 1,2,4
|
|
|
|
for (size_t i = 0; i < banks; i++) { // 8K Banks ($6000-$7FFF)
|
|
|
|
write_prg_byte(0x8000, 0x80); // Clear Register
|
2019-09-05 00:48:39 +02:00
|
|
|
write_mmc1_byte(0x8000, 1 << 3);
|
|
|
|
write_mmc1_byte(0xE000, 0);
|
2022-10-13 09:49:03 +02:00
|
|
|
if (banks == 4) // 32K
|
2019-09-05 00:48:39 +02:00
|
|
|
write_mmc1_byte(0xA000, i << 2);
|
|
|
|
else
|
|
|
|
write_mmc1_byte(0xA000, i << 3);
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x2000, base); // 8K
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 4: // 1K/8K (MMC6/MMC3)
|
|
|
|
if (mmc6) { // MMC6 1K
|
|
|
|
write_prg_byte(0x8000, 0x20); // PRG RAM ENABLE
|
|
|
|
write_prg_byte(0xA001, 0x20); // PRG RAM PROTECT - Enable reading RAM at $7000-$71FF
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t address = 0x1000; address < 0x1200; address += 512) { // 512B
|
2019-11-25 11:53:45 +01:00
|
|
|
dumpMMC5RAM(base, address);
|
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x8000, 0x20); // PRG RAM ENABLE
|
|
|
|
write_prg_byte(0xA001, 0x80); // PRG RAM PROTECT - Enable reading RAM at $7200-$73FF
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t address = 0x1200; address < 0x1400; address += 512) { // 512B
|
2019-11-25 11:53:45 +01:00
|
|
|
dumpMMC5RAM(base, address);
|
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x8000, 6); // PRG RAM DISABLE
|
|
|
|
} else { // MMC3 8K
|
|
|
|
write_prg_byte(0xA001, 0xC0); // PRG RAM CHIP ENABLE - Chip Enable, Write Protect
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x2000, base); // 8K
|
2019-11-25 11:53:45 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-06-27 09:43:40 +02:00
|
|
|
case 5: // 8K/16K/32K
|
|
|
|
write_prg_byte(0x5100, 3); // 8K PRG Banks
|
|
|
|
banks = int_pow(2, ramsize) / 2; // banks = 1,2,4
|
|
|
|
if (banks == 2) { // 16K - Split SRAM Chips 8K/8K
|
|
|
|
for (size_t i = 0; i < (banks / 2); i++) { // Chip 1
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x5113, i);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t address = 0; address < 0x2000; address += 512) { // 8K
|
2019-09-05 00:48:39 +02:00
|
|
|
dumpMMC5RAM(base, address);
|
|
|
|
}
|
|
|
|
}
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t j = 4; j < (banks / 2) + 4; j++) { // Chip 2
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x5113, j);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t address = 0; address < 0x2000; address += 512) { // 8K
|
2019-09-05 00:48:39 +02:00
|
|
|
dumpMMC5RAM(base, address);
|
|
|
|
}
|
|
|
|
}
|
2023-06-27 09:43:40 +02:00
|
|
|
} else { // 8K/32K Single SRAM Chip
|
|
|
|
for (size_t i = 0; i < banks; i++) { // banks = 1 or 4
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x5113, i);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t address = 0; address < 0x2000; address += 512) { // 8K
|
2019-09-05 00:48:39 +02:00
|
|
|
dumpMMC5RAM(base, address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 16: // 256-byte EEPROM 24C02
|
|
|
|
case 159: // 128-byte EEPROM 24C01 [Little Endian]
|
2019-09-05 00:48:39 +02:00
|
|
|
if (mapper == 159)
|
|
|
|
eepsize = 128;
|
|
|
|
else
|
|
|
|
eepsize = 256;
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t address = 0; address < eepsize; address++) {
|
2019-09-05 00:48:39 +02:00
|
|
|
EepromREAD(address);
|
|
|
|
}
|
2022-07-07 00:15:13 +02:00
|
|
|
myFile.write(sdBuffer, eepsize);
|
2019-09-05 00:48:39 +02:00
|
|
|
// display_Clear(); // TEST PURPOSES - DISPLAY EEPROM DATA
|
|
|
|
break;
|
|
|
|
|
2019-11-25 11:53:45 +01:00
|
|
|
case 19:
|
2022-10-13 09:49:03 +02:00
|
|
|
if (ramsize == 2) { // PRG RAM 128B
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t x = 0; x < 128; x++) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_ram_byte(0xF800, x); // PRG RAM ENABLE
|
|
|
|
sdBuffer[x] = read_prg_byte(0x4800); // DATA PORT
|
2019-11-25 11:53:45 +01:00
|
|
|
}
|
2022-07-07 00:15:13 +02:00
|
|
|
myFile.write(sdBuffer, 128);
|
2023-06-27 09:43:40 +02:00
|
|
|
} else { // SRAM 8K
|
|
|
|
for (size_t i = 0; i < 64; i++) { // Init Register
|
2019-11-25 11:53:45 +01:00
|
|
|
write_ram_byte(0xE000, 0);
|
|
|
|
}
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x2000, base); // 8K
|
2019-11-25 11:53:45 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 80: // 1K
|
|
|
|
write_prg_byte(0x7EF8, 0xA3); // PRG RAM ENABLE 0
|
|
|
|
write_prg_byte(0x7EF9, 0xA3); // PRG RAM ENABLE 1
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t x = 0; x < 128; x++) { // PRG RAM 1K ($7F00-$7FFF) MIRRORED ONCE
|
2019-11-25 11:53:45 +01:00
|
|
|
sdBuffer[x] = read_prg_byte(0x7F00 + x);
|
|
|
|
}
|
2022-07-07 00:15:13 +02:00
|
|
|
myFile.write(sdBuffer, 128);
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x7EF8, 0xFF); // PRG RAM DISABLE 0
|
|
|
|
write_prg_byte(0x7EF9, 0xFF); // PRG RAM DISABLE 1
|
2019-11-25 11:53:45 +01:00
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 82: // 5K
|
|
|
|
write_prg_byte(0x7EF7, 0xCA); // PRG RAM ENABLE 0 ($6000-$67FF)
|
|
|
|
write_prg_byte(0x7EF8, 0x69); // PRG RAM ENABLE 1 ($6800-$6FFF)
|
|
|
|
write_prg_byte(0x7EF9, 0x84); // PRG RAM ENABLE 2 ($7000-$73FF)
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t address = 0x0; address < 0x1400; address += 512) { // PRG RAM 5K ($6000-$73FF)
|
2019-11-25 11:53:45 +01:00
|
|
|
dumpMMC5RAM(base, address);
|
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x7EF7, 0xFF); // PRG RAM DISABLE 0 ($6000-$67FF)
|
|
|
|
write_prg_byte(0x7EF8, 0xFF); // PRG RAM DISABLE 1 ($6800-$6FFF)
|
|
|
|
write_prg_byte(0x7EF9, 0xFF); // PRG RAM DISABLE 2 ($7000-$73FF)
|
2019-11-25 11:53:45 +01:00
|
|
|
break;
|
|
|
|
|
2019-09-05 00:48:39 +02:00
|
|
|
default:
|
2022-10-13 09:49:03 +02:00
|
|
|
if (mapper == 118) // 8K
|
|
|
|
write_prg_byte(0xA001, 0xC0); // PRG RAM CHIP ENABLE - Chip Enable, Write Protect
|
2019-09-05 00:48:39 +02:00
|
|
|
else if (mapper == 19) {
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < 64; i++) { // Init Register
|
2019-09-05 00:48:39 +02:00
|
|
|
write_ram_byte(0xE000, 0);
|
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
} else if ((mapper == 21) || (mapper == 25)) // 8K
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x8000, 0);
|
2022-10-13 09:49:03 +02:00
|
|
|
else if (mapper == 26) // 8K
|
|
|
|
write_prg_byte(0xB003, 0x80); // PRG RAM ENABLE
|
|
|
|
else if (mapper == 68) // 8K
|
|
|
|
write_reg_byte(0xF000, 0x10); // PRG RAM ENABLE [WRITE RAM SAFE]
|
|
|
|
else if (mapper == 69) { // 8K
|
|
|
|
write_prg_byte(0x8000, 8); // Command Register - PRG Bank 0
|
|
|
|
write_prg_byte(0xA000, 0xC0); // Parameter Register - PRG RAM Enabled, PRG RAM, Bank 0 to $6000-$7FFF
|
|
|
|
} else if (mapper == 85) // 8K
|
|
|
|
write_ram_byte(0xE000, 0x80); // PRG RAM ENABLE
|
|
|
|
else if (mapper == 153) // 8K
|
|
|
|
write_prg_byte(0x800D, 0x20); // PRG RAM Chip Enable
|
2024-05-03 23:42:06 +02:00
|
|
|
dumpBankPRG(0x0, 0x2000, base); // 8K
|
2022-10-13 09:49:03 +02:00
|
|
|
if (mapper == 85) // 8K
|
|
|
|
write_reg_byte(0xE000, 0); // PRG RAM DISABLE [WRITE RAM SAFE]
|
2019-09-05 00:48:39 +02:00
|
|
|
break;
|
|
|
|
}
|
2022-07-07 00:15:13 +02:00
|
|
|
myFile.flush();
|
|
|
|
myFile.close();
|
2019-09-05 00:48:39 +02:00
|
|
|
|
|
|
|
println_Msg(F("RAM FILE DUMPED!"));
|
2024-03-02 17:26:35 +01:00
|
|
|
println_Msg(FS(FSTRING_EMPTY));
|
2019-09-05 00:48:39 +02:00
|
|
|
display_Update();
|
|
|
|
|
|
|
|
if ((mapper == 16) || (mapper == 159))
|
2022-10-23 14:26:40 +02:00
|
|
|
printCRC(fileName, NULL, 0);
|
2019-09-05 00:48:39 +02:00
|
|
|
else
|
2022-10-23 14:26:40 +02:00
|
|
|
printCRC(fileName, NULL, 0);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
set_address(0);
|
|
|
|
PHI2_HI;
|
|
|
|
ROMSEL_HI;
|
|
|
|
LED_BLUE_OFF;
|
|
|
|
LED_GREEN_OFF;
|
|
|
|
}
|
|
|
|
|
2024-05-03 23:42:06 +02:00
|
|
|
void writeBankPRG(const size_t from, const size_t to, const size_t base) {
|
|
|
|
for (size_t address = from; address < to; address += 512) {
|
|
|
|
myFile.read(sdBuffer, 512);
|
|
|
|
for (size_t x = 0; x < 512; x++) {
|
|
|
|
write_prg_byte(base + address + x, sdBuffer[x]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void writeBankWRAM(const size_t from, const size_t to, const size_t base) {
|
|
|
|
for (size_t address = from; address < to; address += 512) {
|
|
|
|
myFile.read(sdBuffer, 512);
|
|
|
|
for (size_t x = 0; x < 512; x++) {
|
|
|
|
write_wram_byte(base + address + x, sdBuffer[x]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-25 11:53:45 +01:00
|
|
|
void writeRAM() {
|
2019-09-05 00:48:39 +02:00
|
|
|
display_Clear();
|
|
|
|
|
|
|
|
if (ramsize == 0) {
|
2022-10-30 03:21:01 +01:00
|
|
|
print_Error(F("RAM SIZE 0K"));
|
2022-10-13 09:49:03 +02:00
|
|
|
} else {
|
2019-09-05 00:48:39 +02:00
|
|
|
fileBrowser(F("Select RAM File"));
|
|
|
|
word base = 0x6000;
|
|
|
|
|
|
|
|
sd.chdir();
|
|
|
|
sprintf(filePath, "%s/%s", filePath, fileName);
|
|
|
|
|
2019-09-05 22:18:18 +02:00
|
|
|
display_Clear();
|
2019-09-05 00:48:39 +02:00
|
|
|
println_Msg(F("Writing File: "));
|
|
|
|
println_Msg(filePath);
|
|
|
|
println_Msg(fileName);
|
|
|
|
display_Update();
|
|
|
|
|
|
|
|
//open file on sd card
|
2022-07-07 00:15:13 +02:00
|
|
|
if (myFile.open(filePath, O_READ)) {
|
2019-09-05 00:48:39 +02:00
|
|
|
switch (mapper) {
|
2024-05-03 23:42:06 +02:00
|
|
|
case 0: // 2K/4K
|
|
|
|
writeBankPRG(0x0, (0x800 * ramsize), base); // 2K/4K
|
|
|
|
break; // SWITCH MUST BE IN OFF POSITION
|
2019-11-25 11:53:45 +01:00
|
|
|
|
2019-09-05 00:48:39 +02:00
|
|
|
case 1:
|
|
|
|
case 155:
|
2023-06-27 09:43:40 +02:00
|
|
|
banks = int_pow(2, ramsize) / 2; // banks = 1,2,4
|
|
|
|
for (size_t i = 0; i < banks; i++) { // 8K Banks ($6000-$7FFF)
|
|
|
|
write_prg_byte(0x8000, 0x80); // Clear Register
|
|
|
|
write_mmc1_byte(0x8000, 1 << 3); // PRG ROM MODE 32K
|
|
|
|
write_mmc1_byte(0xE000, 0); // PRG RAM ENABLED
|
|
|
|
if (banks == 4) // 32K
|
2019-09-05 00:48:39 +02:00
|
|
|
write_mmc1_byte(0xA000, i << 2);
|
|
|
|
else
|
|
|
|
write_mmc1_byte(0xA000, i << 3);
|
2024-05-03 23:42:06 +02:00
|
|
|
writeBankPRG(0x0, 0x2000, base); // 8K
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2024-05-03 23:42:06 +02:00
|
|
|
case 4: // 1K/8K (MMC6/MMC3)
|
|
|
|
if (mmc6) { // MMC6 1K
|
|
|
|
write_prg_byte(0x8000, 0x20); // PRG RAM ENABLE
|
|
|
|
write_prg_byte(0xA001, 0x30); // PRG RAM PROTECT - Enable reading/writing to RAM at $7000-$71FF
|
|
|
|
writeBankWRAM(0x1000, 0x1200, base); // 512B
|
|
|
|
|
|
|
|
write_prg_byte(0x8000, 0x20); // PRG RAM ENABLE
|
|
|
|
write_prg_byte(0xA001, 0xC0); // PRG RAM PROTECT - Enable reading/writing to RAM at $7200-$73FF
|
|
|
|
writeBankWRAM(0x1200, 0x1400, base); // 512B
|
|
|
|
|
|
|
|
write_prg_byte(0x8000, 0x6); // PRG RAM DISABLE
|
|
|
|
} else { // MMC3 8K
|
|
|
|
write_prg_byte(0xA001, 0x80); // PRG RAM CHIP ENABLE - Chip Enable, Allow Writes
|
|
|
|
writeBankPRG(0x0, 0x2000, base); // 8K
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0xA001, 0xC0); // PRG RAM CHIP ENABLE - Chip Enable, Write Protect
|
2019-11-25 11:53:45 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-06-27 09:43:40 +02:00
|
|
|
case 5: // 8K/16K/32K
|
|
|
|
write_prg_byte(0x5100, 3); // 8K PRG Banks
|
|
|
|
banks = int_pow(2, ramsize) / 2; // banks = 1,2,4
|
|
|
|
if (banks == 2) { // 16K - Split SRAM Chips 8K/8K [ETROM = 16K (ONLY 1ST 8K BATTERY BACKED)]
|
|
|
|
for (size_t i = 0; i < (banks / 2); i++) { // Chip 1
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x5113, i);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t address = 0; address < 0x2000; address += 512) { // 8K
|
2019-09-05 00:48:39 +02:00
|
|
|
writeMMC5RAM(base, address);
|
|
|
|
}
|
|
|
|
}
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t j = 4; j < (banks / 2) + 4; j++) { // Chip 2
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x5113, j);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t address = 0; address < 0x2000; address += 512) { // 8K
|
2019-09-05 00:48:39 +02:00
|
|
|
writeMMC5RAM(base, address);
|
|
|
|
}
|
|
|
|
}
|
2023-06-27 09:43:40 +02:00
|
|
|
} else { // 8K/32K Single SRAM Chip [EKROM = 8K BATTERY BACKED, EWROM = 32K BATTERY BACKED]
|
|
|
|
for (size_t i = 0; i < banks; i++) { // banks = 1 or 4
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x5113, i);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t address = 0; address < 0x2000; address += 512) { // 8K
|
2019-09-05 00:48:39 +02:00
|
|
|
writeMMC5RAM(base, address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 16: // 256-byte EEPROM 24C02
|
|
|
|
case 159: // 128-byte EEPROM 24C01 [Little Endian]
|
2019-09-05 00:48:39 +02:00
|
|
|
if (mapper == 159)
|
|
|
|
eepsize = 128;
|
|
|
|
else
|
|
|
|
eepsize = 256;
|
2022-07-07 00:15:13 +02:00
|
|
|
myFile.read(sdBuffer, eepsize);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t address = 0; address < eepsize; address++) {
|
2019-09-05 00:48:39 +02:00
|
|
|
EepromWRITE(address);
|
|
|
|
if ((address % 128) == 0)
|
|
|
|
display_Clear();
|
|
|
|
print_Msg(F("."));
|
|
|
|
display_Update();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-11-25 11:53:45 +01:00
|
|
|
case 19:
|
2022-10-13 09:49:03 +02:00
|
|
|
if (ramsize == 2) { // PRG RAM 128B
|
2022-07-07 00:15:13 +02:00
|
|
|
myFile.read(sdBuffer, 128);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t x = 0; x < 128; x++) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_ram_byte(0xF800, x); // PRG RAM ENABLE
|
|
|
|
write_prg_byte(0x4800, sdBuffer[x]); // DATA PORT
|
2019-11-25 11:53:45 +01:00
|
|
|
}
|
2023-06-27 09:43:40 +02:00
|
|
|
} else { // SRAM 8K
|
|
|
|
for (size_t i = 0; i < 64; i++) { // Init Register
|
|
|
|
write_ram_byte(0xF800, 0x40); // PRG RAM WRITE ENABLE
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2024-05-03 23:42:06 +02:00
|
|
|
write_ram_byte(0xF800, 0x40); // PRG RAM WRITE ENABLE
|
|
|
|
writeBankPRG(0x0, 0x2000, base); // 8K
|
2022-10-13 09:49:03 +02:00
|
|
|
write_ram_byte(0xF800, 0x0F); // PRG RAM WRITE PROTECT
|
2019-11-25 11:53:45 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 80: // 1K
|
|
|
|
write_prg_byte(0x7EF8, 0xA3); // PRG RAM ENABLE 0
|
|
|
|
write_prg_byte(0x7EF9, 0xA3); // PRG RAM ENABLE 1
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t address = 0x1F00; address < 0x2000; address += 512) { // PRG RAM 1K ($7F00-$7FFF)
|
2022-07-07 00:15:13 +02:00
|
|
|
myFile.read(sdBuffer, 128);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t x = 0; x < 128; x++) {
|
2019-11-25 11:53:45 +01:00
|
|
|
write_prg_byte(base + address + x, sdBuffer[x]);
|
|
|
|
}
|
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x7EF8, 0xFF); // PRG RAM DISABLE 0
|
|
|
|
write_prg_byte(0x7EF9, 0xFF); // PRG RAM DISABLE 1
|
2019-11-25 11:53:45 +01:00
|
|
|
break;
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
case 82: // 5K
|
|
|
|
write_prg_byte(0x7EF7, 0xCA); // PRG RAM ENABLE 0 ($6000-$67FF)
|
|
|
|
write_prg_byte(0x7EF8, 0x69); // PRG RAM ENABLE 1 ($6800-$6FFF)
|
|
|
|
write_prg_byte(0x7EF9, 0x84); // PRG RAM ENABLE 2 ($7000-$73FF)
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t address = 0x0; address < 0x1400; address += 1024) { // PRG RAM 5K ($6000-$73FF)
|
2022-07-07 00:15:13 +02:00
|
|
|
myFile.read(sdBuffer, 512);
|
2019-11-25 11:53:45 +01:00
|
|
|
firstbyte = sdBuffer[0];
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t x = 0; x < 512; x++)
|
2019-11-25 11:53:45 +01:00
|
|
|
write_prg_byte(base + address + x, sdBuffer[x]);
|
2022-07-07 00:15:13 +02:00
|
|
|
myFile.read(sdBuffer, 512);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t x = 0; x < 512; x++)
|
2019-11-25 11:53:45 +01:00
|
|
|
write_prg_byte(base + address + x + 512, sdBuffer[x]);
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(base + address, firstbyte); // REWRITE 1ST BYTE
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x7EF7, 0xFF); // PRG RAM DISABLE 0 ($6000-$67FF)
|
|
|
|
write_prg_byte(0x7EF8, 0xFF); // PRG RAM DISABLE 1 ($6800-$6FFF)
|
|
|
|
write_prg_byte(0x7EF9, 0xFF); // PRG RAM DISABLE 2 ($7000-$73FF)
|
2019-11-25 11:53:45 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-10-13 09:49:03 +02:00
|
|
|
if (mapper == 118) // 8K
|
|
|
|
write_prg_byte(0xA001, 0x80); // PRG RAM CHIP ENABLE - Chip Enable, Allow Writes
|
|
|
|
else if ((mapper == 21) || (mapper == 25)) // 8K
|
2019-09-05 00:48:39 +02:00
|
|
|
write_prg_byte(0x8000, 0);
|
2022-10-13 09:49:03 +02:00
|
|
|
else if (mapper == 26) // 8K
|
|
|
|
write_prg_byte(0xB003, 0x80); // PRG RAM ENABLE
|
2019-09-05 00:48:39 +02:00
|
|
|
// else if (mapper == 68) // 8K
|
|
|
|
// write_reg_byte(0xF000, 0x10); // PRG RAM ENABLE [WRITE RAM SAFE]
|
2022-10-13 09:49:03 +02:00
|
|
|
else if (mapper == 69) { // 8K
|
|
|
|
write_prg_byte(0x8000, 8); // Command Register - PRG Bank 0
|
|
|
|
write_prg_byte(0xA000, 0xC0); // Parameter Register - PRG RAM Enabled, PRG RAM, Bank 0 to $6000-$7FFF
|
|
|
|
} else if (mapper == 85) // 8K
|
|
|
|
write_ram_byte(0xE000, 0x80); // PRG RAM ENABLE
|
|
|
|
else if (mapper == 153) // 8K
|
|
|
|
write_prg_byte(0x800D, 0x20); // PRG RAM Chip Enable
|
2024-05-03 23:42:06 +02:00
|
|
|
writeBankPRG(0x0, 0x2000, base);
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
if (mapper == 118) // 8K
|
|
|
|
write_prg_byte(0xA001, 0xC0); // PRG RAM CHIP ENABLE - Chip Enable, Write Protect
|
|
|
|
else if (mapper == 26) // 8K
|
|
|
|
write_prg_byte(0xB003, 0); // PRG RAM DISABLE
|
2019-09-05 00:48:39 +02:00
|
|
|
// else if (mapper == 68) // 8K
|
|
|
|
// write_reg_byte(0xF000, 0x00); // PRG RAM DISABLE [WRITE RAM SAFE]
|
2022-10-13 09:49:03 +02:00
|
|
|
else if (mapper == 69) { // 8K
|
|
|
|
write_prg_byte(0x8000, 8); // Command Register - PRG Bank 0
|
|
|
|
write_prg_byte(0xA000, 0); // Parameter Register - PRG RAM Disabled, PRG ROM, Bank 0 to $6000-$7FFF
|
|
|
|
} else if (mapper == 85) // 8K
|
|
|
|
write_reg_byte(0xE000, 0); // PRG RAM DISABLE [WRITE RAM SAFE]
|
2019-09-05 00:48:39 +02:00
|
|
|
break;
|
|
|
|
}
|
2022-07-07 00:15:13 +02:00
|
|
|
myFile.close();
|
2019-09-05 00:48:39 +02:00
|
|
|
LED_GREEN_ON;
|
|
|
|
|
2024-03-02 17:26:35 +01:00
|
|
|
println_Msg(FS(FSTRING_EMPTY));
|
2019-09-05 00:48:39 +02:00
|
|
|
println_Msg(F("RAM FILE WRITTEN!"));
|
|
|
|
display_Update();
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
} else {
|
2022-10-30 03:21:01 +01:00
|
|
|
print_FatalError(sd_error_STR);
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LED_RED_OFF;
|
|
|
|
LED_GREEN_OFF;
|
2022-10-13 09:49:03 +02:00
|
|
|
sd.chdir(); // root
|
|
|
|
filePath[0] = '\0'; // Reset filePath
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2019-11-25 11:53:45 +01:00
|
|
|
|
2019-09-05 00:48:39 +02:00
|
|
|
/******************************************
|
|
|
|
Eeprom Functions
|
|
|
|
*****************************************/
|
|
|
|
// EEPROM MAPPING
|
|
|
|
// 00-01 FOLDER #
|
|
|
|
// 02-05 SNES/GB READER SETTINGS
|
|
|
|
// 06 LED - ON/OFF [SNES/GB]
|
|
|
|
// 07 MAPPER
|
|
|
|
// 08 PRG SIZE
|
|
|
|
// 09 CHR SIZE
|
|
|
|
// 10 RAM SIZE
|
|
|
|
|
|
|
|
void resetEEPROM() {
|
2022-10-13 09:49:03 +02:00
|
|
|
EEPROM_writeAnything(0, 0); // FOLDER #
|
|
|
|
EEPROM_writeAnything(2, 0); // CARTMODE
|
|
|
|
EEPROM_writeAnything(3, 0); // RETRY
|
|
|
|
EEPROM_writeAnything(4, 0); // STATUS
|
|
|
|
EEPROM_writeAnything(5, 0); // UNKNOWNCRC
|
|
|
|
EEPROM_writeAnything(6, 1); // LED (RESET TO ON)
|
|
|
|
EEPROM_writeAnything(7, 0); // MAPPER
|
|
|
|
EEPROM_writeAnything(8, 0); // PRG SIZE
|
|
|
|
EEPROM_writeAnything(9, 0); // CHR SIZE
|
|
|
|
EEPROM_writeAnything(10, 0); // RAM SIZE
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EepromStart_NES() {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x800D, 0x00); // sda low, scl low
|
|
|
|
write_prg_byte(0x800D, 0x60); // sda, scl high
|
|
|
|
write_prg_byte(0x800D, 0x20); // sda low, scl high
|
|
|
|
write_prg_byte(0x800D, 0x00); // START
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EepromStop_NES() {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x800D, 0x00); // sda, scl low
|
|
|
|
write_prg_byte(0x800D, 0x20); // sda low, scl high
|
|
|
|
write_prg_byte(0x800D, 0x60); // sda, scl high
|
|
|
|
write_prg_byte(0x800D, 0x40); // sda high, scl low
|
|
|
|
write_prg_byte(0x800D, 0x00); // STOP
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EepromSet0_NES() {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x800D, 0x00); // sda low, scl low
|
|
|
|
write_prg_byte(0x800D, 0x20); // sda low, scl high // 0
|
|
|
|
write_prg_byte(0x800D, 0x00); // sda low, scl low
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EepromSet1_NES() {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x800D, 0x40); // sda high, scl low
|
|
|
|
write_prg_byte(0x800D, 0x60); // sda high, scl high // 1
|
|
|
|
write_prg_byte(0x800D, 0x40); // sda high, scl low
|
|
|
|
write_prg_byte(0x800D, 0x00); // sda low, scl low
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
void EepromStatus_NES() { // ACK
|
|
|
|
write_prg_byte(0x800D, 0x40); // sda high, scl low
|
|
|
|
write_prg_byte(0x800D, 0x60); // sda high, scl high
|
|
|
|
write_prg_byte(0x800D, 0xE0); // sda high, scl high, read high
|
2023-06-27 09:43:40 +02:00
|
|
|
uint8_t eepStatus = 1;
|
2019-09-05 00:48:39 +02:00
|
|
|
do {
|
|
|
|
eepStatus = (read_prg_byte(0x6000) & 0x10) >> 4;
|
|
|
|
delayMicroseconds(4);
|
2022-10-13 09:49:03 +02:00
|
|
|
} while (eepStatus == 1);
|
|
|
|
write_prg_byte(0x800D, 0x40); // sda high, scl low
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EepromReadData_NES() {
|
|
|
|
// read serial data into buffer
|
2023-06-27 09:43:40 +02:00
|
|
|
for (uint8_t i = 0; i < 8; i++) {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x800D, 0x60); // sda high, scl high, read low
|
|
|
|
write_prg_byte(0x800D, 0xE0); // sda high, scl high, read high
|
|
|
|
eepbit[i] = (read_prg_byte(0x6000) & 0x10) >> 4; // Read 0x6000 with Mask 0x10 (bit 4)
|
|
|
|
write_prg_byte(0x800D, 0x40); // sda high, scl low
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
void EepromDevice_NES() { // 24C02 ONLY
|
2019-09-05 00:48:39 +02:00
|
|
|
EepromSet1_NES();
|
|
|
|
EepromSet0_NES();
|
|
|
|
EepromSet1_NES();
|
|
|
|
EepromSet0_NES();
|
2022-10-13 09:49:03 +02:00
|
|
|
EepromSet0_NES(); // A2
|
|
|
|
EepromSet0_NES(); // A1
|
|
|
|
EepromSet0_NES(); // A0
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EepromReadMode_NES() {
|
2022-10-13 09:49:03 +02:00
|
|
|
EepromSet1_NES(); // READ
|
|
|
|
EepromStatus_NES(); // ACK
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
void EepromWriteMode_NES() {
|
2022-10-13 09:49:03 +02:00
|
|
|
EepromSet0_NES(); // WRITE
|
|
|
|
EepromStatus_NES(); // ACK
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EepromFinish_NES() {
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x800D, 0x00); // sda low, scl low
|
|
|
|
write_prg_byte(0x800D, 0x40); // sda high, scl low
|
|
|
|
write_prg_byte(0x800D, 0x60); // sda high, scl high
|
|
|
|
write_prg_byte(0x800D, 0x40); // sda high, scl low
|
|
|
|
write_prg_byte(0x800D, 0x00); // sda low, scl low
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
2023-06-27 09:43:40 +02:00
|
|
|
void EepromSetAddress01(uint8_t address) { // 24C01 [Little Endian]
|
|
|
|
for (uint8_t i = 0; i < 7; i++) {
|
2022-10-13 09:49:03 +02:00
|
|
|
if (address & 0x1) // Bit is HIGH
|
2019-09-05 00:48:39 +02:00
|
|
|
EepromSet1_NES();
|
2022-10-13 09:49:03 +02:00
|
|
|
else // Bit is LOW
|
2019-09-05 00:48:39 +02:00
|
|
|
EepromSet0_NES();
|
2022-10-13 09:49:03 +02:00
|
|
|
address >>= 1; // rotate to the next bit
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-27 09:43:40 +02:00
|
|
|
void EepromSetAddress02(uint8_t address) { // 24C02
|
|
|
|
for (uint8_t i = 0; i < 8; i++) {
|
2022-10-13 09:49:03 +02:00
|
|
|
if ((address >> 7) & 0x1) // Bit is HIGH
|
2019-09-05 00:48:39 +02:00
|
|
|
EepromSet1_NES();
|
2022-10-13 09:49:03 +02:00
|
|
|
else // Bit is LOW
|
2019-09-05 00:48:39 +02:00
|
|
|
EepromSet0_NES();
|
2022-10-13 09:49:03 +02:00
|
|
|
address <<= 1; // rotate to the next bit
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
EepromStatus_NES(); // ACK
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
void EepromWriteData01() { // 24C01 [Little Endian]
|
2023-06-27 09:43:40 +02:00
|
|
|
for (uint8_t i = 0; i < 8; i++) {
|
2022-10-13 09:49:03 +02:00
|
|
|
if (eeptemp & 0x1) // Bit is HIGH
|
2019-09-05 00:48:39 +02:00
|
|
|
EepromSet1_NES();
|
2022-10-13 09:49:03 +02:00
|
|
|
else // Bit is LOW
|
2019-09-05 00:48:39 +02:00
|
|
|
EepromSet0_NES();
|
2022-10-13 09:49:03 +02:00
|
|
|
eeptemp >>= 1; // rotate to the next bit
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
EepromStatus_NES(); // ACK
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
2022-10-13 09:49:03 +02:00
|
|
|
void EepromWriteData02() { // 24C02
|
2023-06-27 09:43:40 +02:00
|
|
|
for (uint8_t i = 0; i < 8; i++) {
|
2022-10-13 09:49:03 +02:00
|
|
|
if ((eeptemp >> 7) & 0x1) // Bit is HIGH
|
2019-09-05 00:48:39 +02:00
|
|
|
EepromSet1_NES();
|
2022-10-13 09:49:03 +02:00
|
|
|
else // Bit is LOW
|
2019-09-05 00:48:39 +02:00
|
|
|
EepromSet0_NES();
|
2022-10-13 09:49:03 +02:00
|
|
|
eeptemp <<= 1; // rotate to the next bit
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
EepromStatus_NES(); // ACK
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
2023-06-27 09:43:40 +02:00
|
|
|
void EepromREAD(uint8_t address) {
|
2022-10-13 09:49:03 +02:00
|
|
|
EepromStart_NES(); // START
|
|
|
|
if (mapper == 159) { // 24C01
|
|
|
|
EepromSetAddress01(address); // 24C01 [Little Endian]
|
2019-09-05 00:48:39 +02:00
|
|
|
EepromReadMode_NES();
|
|
|
|
EepromReadData_NES();
|
|
|
|
EepromFinish_NES();
|
2022-10-13 09:49:03 +02:00
|
|
|
EepromStop_NES(); // STOP
|
2019-09-05 00:48:39 +02:00
|
|
|
// OR 8 bits into byte
|
|
|
|
eeptemp = eepbit[7] << 7 | eepbit[6] << 6 | eepbit[5] << 5 | eepbit[4] << 4 | eepbit[3] << 3 | eepbit[2] << 2 | eepbit[1] << 1 | eepbit[0];
|
2022-10-13 09:49:03 +02:00
|
|
|
} else { // 24C02
|
|
|
|
EepromDevice_NES(); // DEVICE [1010] + ADDR [A2-A0]
|
2019-09-05 00:48:39 +02:00
|
|
|
EepromWriteMode_NES();
|
|
|
|
EepromSetAddress02(address);
|
2022-10-13 09:49:03 +02:00
|
|
|
EepromStart_NES(); // START
|
|
|
|
EepromDevice_NES(); // DEVICE [1010] + ADDR [A2-A0]
|
2019-09-05 00:48:39 +02:00
|
|
|
EepromReadMode_NES();
|
|
|
|
EepromReadData_NES();
|
|
|
|
EepromFinish_NES();
|
2022-10-13 09:49:03 +02:00
|
|
|
EepromStop_NES(); // STOP
|
2019-09-05 00:48:39 +02:00
|
|
|
// OR 8 bits into byte
|
|
|
|
eeptemp = eepbit[0] << 7 | eepbit[1] << 6 | eepbit[2] << 5 | eepbit[3] << 4 | eepbit[4] << 3 | eepbit[5] << 2 | eepbit[6] << 1 | eepbit[7];
|
|
|
|
}
|
|
|
|
sdBuffer[address] = eeptemp;
|
|
|
|
}
|
|
|
|
|
2023-06-27 09:43:40 +02:00
|
|
|
void EepromWRITE(uint8_t address) {
|
2019-09-05 00:48:39 +02:00
|
|
|
eeptemp = sdBuffer[address];
|
2022-10-13 09:49:03 +02:00
|
|
|
EepromStart_NES(); // START
|
|
|
|
if (mapper == 159) { // 24C01
|
|
|
|
EepromSetAddress01(address); // 24C01 [Little Endian]
|
2019-09-05 00:48:39 +02:00
|
|
|
EepromWriteMode_NES();
|
2022-10-13 09:49:03 +02:00
|
|
|
EepromWriteData01(); // 24C01 [Little Endian]
|
|
|
|
} else { // 24C02
|
|
|
|
EepromDevice_NES(); // DEVICE [1010] + ADDR [A2-A0]
|
2019-09-05 00:48:39 +02:00
|
|
|
EepromWriteMode_NES();
|
|
|
|
EepromSetAddress02(address);
|
|
|
|
EepromWriteData02();
|
|
|
|
}
|
2022-10-13 09:49:03 +02:00
|
|
|
EepromStop_NES(); // STOP
|
2019-09-05 00:48:39 +02:00
|
|
|
}
|
2019-09-01 14:36:53 +02:00
|
|
|
|
2019-11-25 11:53:45 +01:00
|
|
|
/******************************************
|
|
|
|
NESmaker Flash Cart [SST 39SF40]
|
|
|
|
*****************************************/
|
2022-10-13 09:49:03 +02:00
|
|
|
void NESmaker_ResetFlash() { // Reset Flash
|
2019-11-25 11:53:45 +01:00
|
|
|
write_prg_byte(0xC000, 0x01);
|
|
|
|
write_prg_byte(0x9555, 0xAA);
|
|
|
|
write_prg_byte(0xC000, 0x00);
|
|
|
|
write_prg_byte(0xAAAA, 0x55);
|
|
|
|
write_prg_byte(0xC000, 0x01);
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x9555, 0xFF); // Reset
|
2019-11-25 11:53:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// SST 39SF040 Software ID
|
2022-10-13 09:49:03 +02:00
|
|
|
void NESmaker_ID() { // Read Flash ID
|
2019-11-25 11:53:45 +01:00
|
|
|
NESmaker_ResetFlash();
|
|
|
|
write_prg_byte(0xC000, 0x01);
|
|
|
|
write_prg_byte(0x9555, 0xAA);
|
|
|
|
write_prg_byte(0xC000, 0x00);
|
|
|
|
write_prg_byte(0xAAAA, 0x55);
|
|
|
|
write_prg_byte(0xC000, 0x01);
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x9555, 0x90); // Software ID Entry
|
2022-10-22 02:47:50 +02:00
|
|
|
flashid = read_prg_byte(0x8000) << 8;
|
|
|
|
flashid |= read_prg_byte(0x8001);
|
|
|
|
sprintf(flashid_str, "%04X", flashid);
|
2022-07-23 11:04:17 +02:00
|
|
|
write_prg_byte(0xC000, 0x01);
|
|
|
|
write_prg_byte(0x9555, 0xAA);
|
|
|
|
write_prg_byte(0xC000, 0x00);
|
|
|
|
write_prg_byte(0xAAAA, 0x55);
|
|
|
|
write_prg_byte(0xC000, 0x01);
|
2022-10-28 15:02:51 +02:00
|
|
|
write_prg_byte(0x9555, 0xF0); // Software ID Exit
|
|
|
|
if (flashid == 0xBFB7) // SST 39SF040
|
2019-11-25 11:53:45 +01:00
|
|
|
flashfound = 1;
|
|
|
|
}
|
|
|
|
|
2023-06-27 09:43:40 +02:00
|
|
|
void NESmaker_SectorErase(uint8_t bank, word address) {
|
2019-11-25 11:53:45 +01:00
|
|
|
write_prg_byte(0xC000, 0x01);
|
|
|
|
write_prg_byte(0x9555, 0xAA);
|
|
|
|
write_prg_byte(0xC000, 0x00);
|
|
|
|
write_prg_byte(0xAAAA, 0x55);
|
|
|
|
write_prg_byte(0xC000, 0x01);
|
|
|
|
write_prg_byte(0x9555, 0x80);
|
|
|
|
write_prg_byte(0xC000, 0x01);
|
|
|
|
write_prg_byte(0x9555, 0xAA);
|
|
|
|
write_prg_byte(0xC000, 0x00);
|
|
|
|
write_prg_byte(0xAAAA, 0x55);
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0xC000, bank); // $00-$1F
|
|
|
|
write_prg_byte(address, 0x30); // Sector Erase ($8000/$9000/$A000/$B000)
|
2019-11-25 11:53:45 +01:00
|
|
|
}
|
|
|
|
|
2023-06-27 09:43:40 +02:00
|
|
|
void NESmaker_ByteProgram(uint8_t bank, word address, uint8_t data) {
|
2019-11-25 11:53:45 +01:00
|
|
|
write_prg_byte(0xC000, 0x01);
|
|
|
|
write_prg_byte(0x9555, 0xAA);
|
|
|
|
write_prg_byte(0xC000, 0x00);
|
|
|
|
write_prg_byte(0xAAAA, 0x55);
|
|
|
|
write_prg_byte(0xC000, 0x01);
|
|
|
|
write_prg_byte(0x9555, 0xA0);
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0xC000, bank); // $00-$1F
|
|
|
|
write_prg_byte(address, data); // $8000-$BFFF
|
2019-11-25 11:53:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// SST 39SF040 Chip Erase [NOT IMPLEMENTED]
|
2022-10-13 09:49:03 +02:00
|
|
|
void NESmaker_ChipErase() { // Typical 70ms
|
2019-11-25 11:53:45 +01:00
|
|
|
write_prg_byte(0xC000, 0x01);
|
|
|
|
write_prg_byte(0x9555, 0xAA);
|
|
|
|
write_prg_byte(0xC000, 0x00);
|
|
|
|
write_prg_byte(0xAAAA, 0x55);
|
|
|
|
write_prg_byte(0xC000, 0x01);
|
|
|
|
write_prg_byte(0x9555, 0x80);
|
|
|
|
write_prg_byte(0xC000, 0x01);
|
|
|
|
write_prg_byte(0x9555, 0xAA);
|
|
|
|
write_prg_byte(0xC000, 0x00);
|
|
|
|
write_prg_byte(0xAAAA, 0x55);
|
|
|
|
write_prg_byte(0xC000, 0x01);
|
2022-10-13 09:49:03 +02:00
|
|
|
write_prg_byte(0x9555, 0x10); // Chip Erase
|
2019-11-25 11:53:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void writeFLASH() {
|
|
|
|
display_Clear();
|
|
|
|
if (!flashfound) {
|
|
|
|
LED_RED_ON;
|
|
|
|
println_Msg(F("FLASH NOT DETECTED"));
|
|
|
|
display_Update();
|
2022-10-13 09:49:03 +02:00
|
|
|
} else {
|
2019-11-25 11:53:45 +01:00
|
|
|
print_Msg(F("Flash ID: "));
|
2022-10-22 02:47:50 +02:00
|
|
|
println_Msg(flashid_str);
|
2024-03-02 17:26:35 +01:00
|
|
|
println_Msg(FS(FSTRING_EMPTY));
|
2019-11-25 11:53:45 +01:00
|
|
|
println_Msg(F("NESmaker Flash Found"));
|
2024-03-02 17:26:35 +01:00
|
|
|
println_Msg(FS(FSTRING_EMPTY));
|
2019-11-25 11:53:45 +01:00
|
|
|
display_Update();
|
|
|
|
delay(100);
|
|
|
|
|
|
|
|
fileBrowser(F("Select FLASH File"));
|
|
|
|
word base = 0x8000;
|
|
|
|
|
|
|
|
sd.chdir();
|
|
|
|
sprintf(filePath, "%s/%s", filePath, fileName);
|
|
|
|
|
|
|
|
LED_RED_ON;
|
|
|
|
display_Clear();
|
|
|
|
println_Msg(F("Writing File: "));
|
|
|
|
println_Msg(filePath);
|
|
|
|
println_Msg(fileName);
|
|
|
|
display_Update();
|
|
|
|
|
|
|
|
//open file on sd card
|
2022-07-07 00:15:13 +02:00
|
|
|
if (myFile.open(filePath, O_READ)) {
|
2022-10-13 09:49:03 +02:00
|
|
|
banks = int_pow(2, prgsize); // 256K/512K
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t i = 0; i < banks; i++) { // 16K Banks
|
|
|
|
for (size_t sector = 0; sector < 0x4000; sector += 0x1000) { // 4K Sectors ($8000/$9000/$A000/$B000)
|
2019-11-25 11:53:45 +01:00
|
|
|
// Sector Erase
|
|
|
|
NESmaker_SectorErase(i, base + sector);
|
2022-10-13 09:49:03 +02:00
|
|
|
delay(18); // Typical 18ms
|
2023-06-27 09:43:40 +02:00
|
|
|
for (uint8_t j = 0; j < 2; j++) { // Confirm erase twice
|
2019-11-25 11:53:45 +01:00
|
|
|
do {
|
|
|
|
bytecheck = read_prg_byte(base + sector);
|
|
|
|
delay(18);
|
2022-10-13 09:49:03 +02:00
|
|
|
} while (bytecheck != 0xFF);
|
2019-11-25 11:53:45 +01:00
|
|
|
}
|
|
|
|
// Program Byte
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t addr = 0x0; addr < 0x1000; addr += 512) {
|
2022-07-07 00:15:13 +02:00
|
|
|
myFile.read(sdBuffer, 512);
|
2023-06-27 09:43:40 +02:00
|
|
|
for (size_t x = 0; x < 512; x++) {
|
2019-11-25 11:53:45 +01:00
|
|
|
word location = base + sector + addr + x;
|
2022-10-22 10:25:37 +02:00
|
|
|
NESmaker_ByteProgram(i, location, sdBuffer[x]);
|
2022-10-13 09:49:03 +02:00
|
|
|
delayMicroseconds(14); // Typical 14us
|
2023-06-27 09:43:40 +02:00
|
|
|
for (uint8_t k = 0; k < 2; k++) { // Confirm write twice
|
2019-11-25 11:53:45 +01:00
|
|
|
do {
|
2022-10-22 10:25:37 +02:00
|
|
|
bytecheck = read_prg_byte(location);
|
2019-11-25 11:53:45 +01:00
|
|
|
delayMicroseconds(14);
|
2022-10-13 09:49:03 +02:00
|
|
|
} while (bytecheck != sdBuffer[x]);
|
2019-11-25 11:53:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-17 21:31:18 +01:00
|
|
|
|
2024-03-02 17:26:35 +01:00
|
|
|
#if (defined(ENABLE_LCD) || defined(ENABLE_OLED))
|
2021-11-17 21:31:18 +01:00
|
|
|
display.print(F("*"));
|
|
|
|
display.updateDisplay();
|
2019-11-25 11:53:45 +01:00
|
|
|
#else
|
|
|
|
Serial.print(F("*"));
|
|
|
|
if ((i != 0) && ((i + 1) % 16 == 0))
|
2024-03-02 17:30:44 +01:00
|
|
|
Serial.println(FS(FSTRING_EMPTY));
|
2019-11-25 11:53:45 +01:00
|
|
|
#endif
|
|
|
|
}
|
2022-07-07 00:15:13 +02:00
|
|
|
myFile.close();
|
2019-11-25 11:53:45 +01:00
|
|
|
LED_GREEN_ON;
|
|
|
|
|
2024-03-02 17:26:35 +01:00
|
|
|
println_Msg(FS(FSTRING_EMPTY));
|
2019-11-25 11:53:45 +01:00
|
|
|
println_Msg(F("FLASH FILE WRITTEN!"));
|
|
|
|
display_Update();
|
2022-10-13 09:49:03 +02:00
|
|
|
} else {
|
2019-11-25 11:53:45 +01:00
|
|
|
LED_RED_ON;
|
|
|
|
println_Msg(F("SD ERROR"));
|
|
|
|
display_Update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
display_Clear();
|
|
|
|
LED_RED_OFF;
|
|
|
|
LED_GREEN_OFF;
|
2022-10-13 09:49:03 +02:00
|
|
|
sd.chdir(); // root
|
|
|
|
filePath[0] = '\0'; // Reset filePath
|
2019-11-25 11:53:45 +01:00
|
|
|
}
|
2022-10-22 10:25:37 +02:00
|
|
|
|
|
|
|
// avoid warnings
|
|
|
|
#undef MODE_READ
|
|
|
|
#undef MODE_WRITE
|
|
|
|
|
2020-07-04 17:07:14 +02:00
|
|
|
#endif
|
2019-09-01 14:36:53 +02:00
|
|
|
//******************************************
|
|
|
|
// End of File
|
2023-02-06 21:28:51 +01:00
|
|
|
//******************************************
|