@@ -202,24 +202,35 @@ int sendNES(fs::path p)
202
202
ifstream f (p, ios::binary);
203
203
if (!f.is_open ()) { printf (" File open fail\n " ); return 1 ; }
204
204
205
+ // Reset NES machine
205
206
{ char v = 1 ; writePacket (uart, 0x35 , &v, 1 ); }
206
207
{ char v = 0 ; writePacket (uart, 0x35 , &v, 1 ); }
207
208
208
209
size_t total_read = 0xffffff ; // max size 16MB
209
210
size_t pos = 0 ;
210
211
212
+ bool first = true ;
211
213
while (pos < total_read) {
212
214
streamsize want_read = (total_read - pos) > sizeof (sendbuf) ? sizeof (sendbuf) : (total_read - pos);
213
215
f.read (sendbuf, want_read);
214
216
streamsize n = f.gcount ();
215
217
// printf("want_read=%d, actual_read=%d\n", (int)want_read, (int)n);
216
218
if (n > 0 ) {
219
+ if (first && n > 16 && strncmp (&sendbuf[7 ], " DiskDude!" , 9 ) == 0 ) {
220
+ // "DiskDude!" work-around. See https://www.nesdev.org/wiki/INES
221
+ // Older versions of the iNES emulator ignored bytes 7-15 and writes "DiskDude!" there,
222
+ // corrupting byte 7 and results in 64 being added to the mapper number.
223
+ printf (" Old rom file detected with 'DiskDude!' string. Applying fix on-the-fly.\n " );
224
+ sendbuf[7 ] = 0 ; // simply setting byte 7 to 0 should fix it
225
+ }
226
+
217
227
// printf("Write packet\n");
218
228
writePacket (uart, 0x37 , sendbuf, n);
219
229
}
220
230
if (f.eof ())
221
231
break ;
222
232
pos += n;
233
+ first = false ;
223
234
}
224
235
f.close ();
225
236
0 commit comments