Skip to content

Commit b5722cc

Browse files
Version 10.5 - see readme.md for details
1 parent ead75a7 commit b5722cc

File tree

15 files changed

+363
-433
lines changed

15 files changed

+363
-433
lines changed

ColecoDS.nds

512 Bytes
Binary file not shown.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ include $(DEVKITARM)/ds_rules
1515

1616
export TARGET := ColecoDS
1717
export TOPDIR := $(CURDIR)
18-
export VERSION := 10.4b
18+
export VERSION := 10.5
1919

2020
ICON := -b $(CURDIR)/logo.bmp "ColecoDS $(VERSION);wavemotion-dave;https://github.com/wavemotion-dave/ColecoDS"
2121

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,13 @@ And then move the soundbank.h file to the arm9/sources directory
409409

410410
Versions :
411411
-----------------------
412+
V10.5: 14-Mar-2025 by wavemotion-dave
413+
* Update to the Z80 core to improve emulation accuracy. This emulator now passes the ZEXALL test suite.
414+
* Added proper M1 wait states for the Colecovision, ADAM and MSX emulation for improved CPU handling.
415+
* A few optimized Z80 lookup-tables brings in some additional speed for both the DSi and DS-Lite/Phat.
416+
* Improved file loading so that it's more robust - ensuring a higher level of consistency in loading large files into memory.
417+
* Other minor cleanups as time permitted.
418+
412419
V10.4: 10-Mar-2025 by wavemotion-dave
413420
* DSi now supports cart ROMs up to 4MB (4096K). Only a few MSX tech demos / games get anywhere near this.
414421
* New super-simplified Colecovision CPU driver that is used for most of the well-behaved Colecovision games to render them full speed on the older DS-Lite/Phat.

arm9/gfx_data/pdev_bg0.png

261 Bytes
Loading

arm9/source/Adam.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -835,13 +835,8 @@ void adam_drive_update(u8 drive, u8 device, int cmd)
835835
// Read a .dsk or .ddp file from the SD card and place into memory
836836
void adam_drive_insert(u8 drive, char *filename)
837837
{
838-
FILE *fp = fopen(filename, "rb");
839-
if (fp)
840-
{
841-
AdamDrive[drive].image = ROM_Memory + ((drive*320)*1024);
842-
AdamDrive[drive].imageSize = fread(AdamDrive[drive].image, 1, AdamDrive[drive].imageSizeMax, fp);
843-
fclose(fp);
844-
}
838+
AdamDrive[drive].image = ROM_Memory + ((drive*320)*1024);
839+
AdamDrive[drive].imageSize = ReadFileCarefully(filename, AdamDrive[drive].image, AdamDrive[drive].imageSizeMax, 0);
845840
}
846841

847842
// Set the disk image for this drive bay back to NULL

arm9/source/CRC32.c

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,33 +76,78 @@ u32 crcBasedOnFilename(const char *filename)
7676
return ~crc;
7777
}
7878

79+
// -----------------------------------------------------------------------------------------------------------------
80+
// For disk and data pack games which may write back data, we don't want to base the CRC on the actual contents of
81+
// the media... so instead we'll just hash the filename as a CRC which is good enough to identify it in the future.
82+
// -----------------------------------------------------------------------------------------------------------------
83+
u32 getCRC32(u8 *buf, u32 size)
84+
{
85+
u32 crc = 0xFFFFFFFF;
86+
87+
for (int i=0; i < size; i++)
88+
{
89+
crc = (crc >> 8) ^ crc32_table[(crc & 0xFF) ^ (u8)buf[i]];
90+
}
91+
92+
return ~crc;
93+
}
94+
95+
7996
// ------------------------------------------------------------------------------------
8097
// Read the file in and compute CRC... it's a bit slow but good enough and accurate!
98+
// When this routine finishes, the file will be read into ROM_Memory[]
8199
// ------------------------------------------------------------------------------------
82-
u8 file_crc_buffer[2048];
100+
extern u32 MAX_CART_SIZE;
101+
extern u8 *ROM_Memory;
102+
83103
ITCM_CODE u32 getFileCrc(const char* filename)
84104
{
85105
extern u32 file_size;
86-
u32 crc = 0xFFFFFFFF;
87-
int bytesRead;
106+
u32 crc1 = 0;
107+
u32 crc2 = 1;
108+
int bytesRead1 = 0;
109+
int bytesRead2 = 1;
88110

89-
FILE* file = fopen(filename, "rb");
90-
file_size=0;
91-
while ((bytesRead = fread(file_crc_buffer, 1, sizeof(file_crc_buffer), file)) > 0)
111+
// --------------------------------------------------------------------------------------------
112+
// I've seen some rare issues with reading files from the SD card on a DSi so we're doing
113+
// this slow and careful - we will read twice and ensure that we get the same CRC both
114+
// times in order for us to declare that this is a valid read. When we're done, the game
115+
// ROM will be placed in the ROM_Memory[] and will be ready for use by the rest of the system.
116+
// --------------------------------------------------------------------------------------------
117+
do
92118
{
93-
file_size += bytesRead;
94-
for (int i=0; i < bytesRead; i++)
119+
// Read #1
120+
file_size = 0;
121+
crc1 = 0xFFFFFFFF;
122+
FILE* file = fopen(filename, "rb");
123+
while ((bytesRead1 = fread(ROM_Memory, 1, (MAX_CART_SIZE * 1024), file)) > 0)
95124
{
96-
crc = (crc >> 8) ^ crc32_table[(crc & 0xFF) ^ (u8)file_crc_buffer[i]];
125+
file_size += bytesRead1;
126+
for (int i=0; i < bytesRead1; i++)
127+
{
128+
crc1 = (crc1 >> 8) ^ crc32_table[(crc1 & 0xFF) ^ (u8)ROM_Memory[i]];
129+
}
97130
}
98-
}
99-
fclose(file);
131+
fclose(file);
132+
133+
// Read #2
134+
crc2 = 0xFFFFFFFF;
135+
FILE* file2 = fopen(filename, "rb");
136+
while ((bytesRead2 = fread(ROM_Memory, 1, (MAX_CART_SIZE * 1024), file2)) > 0)
137+
{
138+
for (int i=0; i < bytesRead2; i++)
139+
{
140+
crc2 = (crc2 >> 8) ^ crc32_table[(crc2 & 0xFF) ^ (u8)ROM_Memory[i]];
141+
}
142+
}
143+
fclose(file2);
144+
} while (crc1 != crc2);
100145

101146
// After we compute the size above... we check if this is a .dsk file and return CRC by name
102147
if (isDiskOrDataPack(filename))
103148
{
104149
return crcBasedOnFilename(filename);
105150
}
106151

107-
return ~crc;
152+
return ~crc1;
108153
}

arm9/source/CRC32.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <nds.h>
1616

1717
u32 getFileCrc(const char* filename);
18+
u32 getCRC32(u8 *buf, u32 size);
1819

1920
#endif
2021

0 commit comments

Comments
 (0)