@@ -99,6 +99,23 @@ static void patchOsRom(uint32_t address, char* patch){
9999 swap16BufferIfLittle (& palmRom [swapBegin ], swapSize );
100100}
101101
102+ /**
103+ * Fills the initial RAM with garbage.
104+ *
105+ * @param ram The RAM to fill.
106+ * @param size The size of RAM.
107+ * @since 2024/06/14
108+ */
109+ void mu_garbage_fill (uint8_t * ram , uint32_t size ) {
110+ uint32_t i ;
111+ uint8_t vis ;
112+
113+ vis = 179 ;
114+ for (i = 0 ; i < size ; i ++ ) {
115+ ram [i ] = vis ;
116+ vis = ((vis << 1 ) | ((vis >> 7 ) & 1 )) ^ 0xFF ;
117+ }
118+ }
102119
103120uint32_t emulatorInit (uint8_t emulatedDevice , uint8_t * palmRomData , uint32_t palmRomSize , uint8_t * palmBootloaderData , uint32_t palmBootloaderSize , bool syncRtc , bool allowInvalidBehavior ){
104121 if (emulatorInitialized )
@@ -173,7 +190,9 @@ uint32_t emulatorInit(uint8_t emulatedDevice, uint8_t* palmRomData, uint32_t pal
173190
174191 //allocate buffers, add 4 to memory regions to prevent SIGSEGV from accessing off the end
175192 palmRom = malloc (M5XX_ROM_SIZE + 4 );
176- palmRam = malloc ((palmEmulatingM500 ? M500_RAM_SIZE : M515_RAM_SIZE ) + 4 );
193+
194+ palmRam = malloc ((emulatorGetRamSize ()) + 4 );
195+
177196 palmFramebuffer = malloc (160 * 220 * sizeof (uint16_t ));
178197 palmAudio = malloc (AUDIO_SAMPLES_PER_FRAME * 2 * sizeof (int16_t ));
179198 palmAudioResampler = blip_new (AUDIO_SAMPLE_RATE );//have 1 second of samples
@@ -191,7 +210,10 @@ uint32_t emulatorInit(uint8_t emulatedDevice, uint8_t* palmRomData, uint32_t pal
191210 if (palmRomSize < M5XX_ROM_SIZE )
192211 memset (palmRom + palmRomSize , 0x00 , M5XX_ROM_SIZE - palmRomSize );
193212 swap16BufferIfLittle (palmRom , M5XX_ROM_SIZE / sizeof (uint16_t ));
194- memset (palmRam , 0x00 , palmEmulatingM500 ? M500_RAM_SIZE : M515_RAM_SIZE );
213+
214+ memset (palmRam , 0x00 , emulatorGetRamSize ());
215+ mu_garbage_fill (palmRam , emulatorGetRamSize ());
216+
195217 dbvzLoadBootloader (palmBootloaderData , palmBootloaderSize );
196218 memcpy (palmFramebuffer + 160 * 160 , silkscreen160x60 , 160 * 60 * sizeof (uint16_t ));
197219 memset (palmAudio , 0x00 , AUDIO_SAMPLES_PER_FRAME * 2 /*channels*/ * sizeof (int16_t ));
@@ -262,7 +284,7 @@ void emulatorHardReset(void){
262284 }
263285 else {
264286#endif
265- memset (palmRam , 0x00 , palmEmulatingM500 ? M500_RAM_SIZE : M515_RAM_SIZE );
287+ memset (palmRam , 0x00 , emulatorGetRamSize () );
266288 emulatorSoftReset ();
267289 sdCardReset ();
268290 dbvzSetRtc (0 , 0 , 0 , 0 );
@@ -330,7 +352,7 @@ uint32_t emulatorGetStateSize(void){
330352 size += sed1376StateSize ();
331353 size += ads7846StateSize ();
332354 size += pdiUsbD12StateSize ();
333- size += palmEmulatingM500 ? M500_RAM_SIZE : M515_RAM_SIZE ;//system RAM buffer
355+ size += emulatorGetRamSize () ;//system RAM buffer
334356#if defined(EMU_SUPPORT_PALM_OS5 )
335357 }
336358#endif
@@ -402,9 +424,9 @@ bool emulatorSaveState(uint8_t* data, uint32_t size){
402424 offset += pdiUsbD12StateSize ();
403425
404426 //memory
405- memcpy (data + offset , palmRam , palmEmulatingM500 ? M500_RAM_SIZE : M515_RAM_SIZE );
406- swap16BufferIfLittle (data + offset , (palmEmulatingM500 ? M500_RAM_SIZE : M515_RAM_SIZE ) / sizeof (uint16_t ));
407- offset += palmEmulatingM500 ? M500_RAM_SIZE : M515_RAM_SIZE ;
427+ memcpy (data + offset , palmRam , emulatorGetRamSize () );
428+ swap16BufferIfLittle (data + offset , (emulatorGetRamSize () ) / sizeof (uint16_t ));
429+ offset += emulatorGetRamSize () ;
408430#if defined(EMU_SUPPORT_PALM_OS5 )
409431 }
410432#endif
@@ -526,9 +548,9 @@ bool emulatorLoadState(uint8_t* data, uint32_t size){
526548 offset += pdiUsbD12StateSize ();
527549
528550 //memory
529- memcpy (palmRam , data + offset , palmEmulatingM500 ? M500_RAM_SIZE : M515_RAM_SIZE );
530- swap16BufferIfLittle (palmRam , (palmEmulatingM500 ? M500_RAM_SIZE : M515_RAM_SIZE ) / sizeof (uint16_t ));
531- offset += palmEmulatingM500 ? M500_RAM_SIZE : M515_RAM_SIZE ;
551+ memcpy (palmRam , data + offset , emulatorGetRamSize () );
552+ swap16BufferIfLittle (palmRam , (emulatorGetRamSize () ) / sizeof (uint16_t ));
553+ offset += emulatorGetRamSize () ;
532554#if defined(EMU_SUPPORT_PALM_OS5 )
533555 }
534556#endif
@@ -608,7 +630,9 @@ uint32_t emulatorGetRamSize(void){
608630 if (palmEmulatingTungstenT3 )
609631 return TUNGSTEN_T3_RAM_SIZE ;
610632#endif
611- return palmEmulatingM500 ? M500_RAM_SIZE : M515_RAM_SIZE ;
633+ if (palmEmulatingM500 )
634+ return M500_RAM_SIZE ;
635+ return M515_RAM_SIZE ;
612636}
613637
614638bool emulatorSaveRam (uint8_t * data , uint32_t size ){
@@ -621,11 +645,11 @@ bool emulatorSaveRam(uint8_t* data, uint32_t size){
621645 }
622646 else {
623647#endif
624- if (size < (palmEmulatingM500 ? M500_RAM_SIZE : M515_RAM_SIZE ))
648+ if (size < (emulatorGetRamSize () ))
625649 return false;
626650
627- memcpy (data , palmRam , palmEmulatingM500 ? M500_RAM_SIZE : M515_RAM_SIZE );
628- swap16BufferIfLittle (data , (palmEmulatingM500 ? M500_RAM_SIZE : M515_RAM_SIZE ) / sizeof (uint16_t ));
651+ memcpy (data , palmRam , emulatorGetRamSize () );
652+ swap16BufferIfLittle (data , (emulatorGetRamSize () ) / sizeof (uint16_t ));
629653#if defined(EMU_SUPPORT_PALM_OS5 )
630654 }
631655#endif
@@ -643,11 +667,11 @@ bool emulatorLoadRam(uint8_t* data, uint32_t size){
643667 }
644668 else {
645669#endif
646- if (size < (palmEmulatingM500 ? M500_RAM_SIZE : M515_RAM_SIZE ))
670+ if (size < (emulatorGetRamSize () ))
647671 return false;
648672
649- memcpy (palmRam , data , palmEmulatingM500 ? M500_RAM_SIZE : M515_RAM_SIZE );
650- swap16BufferIfLittle (palmRam , (palmEmulatingM500 ? M500_RAM_SIZE : M515_RAM_SIZE ) / sizeof (uint16_t ));
673+ memcpy (palmRam , data , emulatorGetRamSize () );
674+ swap16BufferIfLittle (palmRam , (emulatorGetRamSize () ) / sizeof (uint16_t ));
651675#if defined(EMU_SUPPORT_PALM_OS5 )
652676 }
653677#endif
0 commit comments