]> git.sesse.net Git - pistorm/commitdiff
Fix some RTC and CDTV NVRAM stuff
authorbeeanyew <beeanyew@gmail.com>
Sat, 2 Jan 2021 01:50:28 +0000 (02:50 +0100)
committerbeeanyew <beeanyew@gmail.com>
Sat, 2 Jan 2021 01:50:28 +0000 (02:50 +0100)
platforms/amiga/Gayle.c
platforms/amiga/amiga-platform.c
platforms/shared/rtc.c

index a8d4657b0dbb8e5aed02fe73f905853882e558b8..1bbba361bb929f6af15b3290170f067d405f4cde 100644 (file)
@@ -218,10 +218,12 @@ void writeGayleB(unsigned int address, unsigned int value) {
   if ((address & GAYLEMASK) == CLOCKBASE) {
     if ((address & CLOCKMASK) >= 0x8000) {
       if (cdtv_mode) {
+        //printf("[CDTV] BYTE write to SRAM @%.8X (%.8X): %.2X\n", (address & CLOCKMASK) - 0x8000, address, value);
         cdtv_sram[(address & CLOCKMASK) - 0x8000] = value;
       }
       return;
     }
+    //printf("Byte write to RTC.\n");
     put_rtc_byte(address, value, rtc_type);
     return;
   }
@@ -238,13 +240,14 @@ void writeGayle(unsigned int address, unsigned int value) {
   if ((address & GAYLEMASK) == CLOCKBASE) {
     if ((address & CLOCKMASK) >= 0x8000) {
       if (cdtv_mode) {
+        //printf("[CDTV] WORD write to SRAM @%.8X (%.8X): %.4X\n", (address & CLOCKMASK) - 0x8000, address, htobe16(value));
         ((short *) ((size_t)(cdtv_sram + (address & CLOCKMASK) - 0x8000)))[0] = htobe16(value);
       }
       return;
     }
-    printf("Word write to RTC.\n");
-    put_rtc_byte(address, (value & 0xFF), rtc_type);
-    put_rtc_byte(address + 1, (value >> 8), rtc_type);
+    //printf("Word write to RTC.\n");
+    put_rtc_byte(address + 1, (value & 0xFF), rtc_type);
+    put_rtc_byte(address, (value >> 8), rtc_type);
     return;
   }
 
@@ -255,15 +258,16 @@ void writeGayleL(unsigned int address, unsigned int value) {
   if ((address & GAYLEMASK) == CLOCKBASE) {
     if ((address & CLOCKMASK) >= 0x8000) {
       if (cdtv_mode) {
+        //printf("[CDTV] LONGWORD write to SRAM @%.8X (%.8X): %.8X\n", (address & CLOCKMASK) - 0x8000, address, htobe32(value));
         ((int *) (size_t)(cdtv_sram + (address & CLOCKMASK) - 0x8000))[0] = htobe32(value);
       }
       return;
     }
-    printf("Longword write to RTC.\n");
-    put_rtc_byte(address, (value & 0xFF), rtc_type);
-    put_rtc_byte(address + 1, ((value & 0x0000FF00) >> 8), rtc_type);
-    put_rtc_byte(address + 2, ((value & 0x00FF0000) >> 16), rtc_type);
-    put_rtc_byte(address + 3, (value >> 24), rtc_type);
+    //printf("Longword write to RTC.\n");
+    put_rtc_byte(address + 3, (value & 0xFF), rtc_type);
+    put_rtc_byte(address + 2, ((value & 0x0000FF00) >> 8), rtc_type);
+    put_rtc_byte(address + 1, ((value & 0x00FF0000) >> 16), rtc_type);
+    put_rtc_byte(address, (value >> 24), rtc_type);
     return;
   }
 
@@ -305,10 +309,12 @@ uint8_t readGayleB(unsigned int address) {
   if ((address & GAYLEMASK) == CLOCKBASE) {
     if ((address & CLOCKMASK) >= 0x8000) {
       if (cdtv_mode) {
+        //printf("[CDTV] BYTE read from SRAM @%.8X (%.8X): %.2X\n", (address & CLOCKMASK) - 0x8000, address, cdtv_sram[(address & CLOCKMASK) - 0x8000]);
         return cdtv_sram[(address & CLOCKMASK) - 0x8000];
       }
       return 0;
     }
+    //printf("Byte read from RTC.\n");
     return get_rtc_byte(address, rtc_type);
   }
 
@@ -373,11 +379,12 @@ uint16_t readGayle(unsigned int address) {
   if ((address & GAYLEMASK) == CLOCKBASE) {
     if ((address & CLOCKMASK) >= 0x8000) {
       if (cdtv_mode) {
-
+        //printf("[CDTV] WORD read from SRAM @%.8X (%.8X): %.4X\n", (address & CLOCKMASK) - 0x8000, address, be16toh( (( unsigned short *) (size_t)(cdtv_sram + (address & CLOCKMASK) - 0x8000))[0]));
         return be16toh( (( unsigned short *) (size_t)(cdtv_sram + (address & CLOCKMASK) - 0x8000))[0]);
       }
       return 0;
     }
+    //printf("Word read from RTC.\n");
     return ((get_rtc_byte(address, rtc_type) << 8) | (get_rtc_byte(address + 1, rtc_type)));
   }
 
@@ -389,10 +396,12 @@ uint32_t readGayleL(unsigned int address) {
   if ((address & GAYLEMASK) == CLOCKBASE) {
     if ((address & CLOCKMASK) >= 0x8000) {
       if (cdtv_mode) {
-        return be32toh( (( unsigned short *) (size_t)(cdtv_sram + (address & CLOCKMASK) - 0x8000))[0]);
+        //printf("[CDTV] LONGWORD read from SRAM @%.8X (%.8X): %.8X\n", (address & CLOCKMASK) - 0x8000, address, be32toh( (( unsigned short *) (size_t)(cdtv_sram + (address & CLOCKMASK) - 0x8000))[0]));
+        return be32toh( (( unsigned int *) (size_t)(cdtv_sram + (address & CLOCKMASK) - 0x8000))[0]);
       }
       return 0;
     }
+    //printf("Longword read from RTC.\n");
     return ((get_rtc_byte(address, rtc_type) << 24) | (get_rtc_byte(address + 1, rtc_type) << 16) | (get_rtc_byte(address + 2, rtc_type) << 8) | (get_rtc_byte(address + 3, rtc_type)));
   }
 
index 12d80a4d81f5c23b8c62f2a588e96a2e7776fa62..5eac5d7cb3335ab852a0b97cf1d719b35d03319f 100644 (file)
@@ -247,14 +247,19 @@ void setvar_amiga(char *var, char *val) {
             set_hard_drive_image_file_amiga(0, val);
     }
     if (strcmp(var, "cdtv") == 0) {
+        printf("[AMIGA] CDTV mode enabled.\n");
         cdtv_mode = 1;
     }
-    if (strcmp(var, "rtctype") == 0) {
+    if (strcmp(var, "rtc_type") == 0) {
         if (val && strlen(val) != 0) {
             if (strcmp(val, "msm") == 0) {
+                printf("[AMIGA] RTC type set to MSM.\n");
                 rtc_type = RTC_TYPE_MSM;
             }
-            rtc_type = RTC_TYPE_RICOH;
+            else {
+                printf("[AMIGA] RTC type set to Ricoh.\n");
+                rtc_type = RTC_TYPE_RICOH;
+            }
         }
     }
 }
index dd5edad5c4774f73baf6933ec1d4a31b8b717fdc..2e07493bbdf2a35afea06ebb33d40e4d863a081d 100644 (file)
@@ -7,9 +7,14 @@ static unsigned char rtc_mystery_reg[3];
 unsigned char ricoh_memory[0x0F];
 unsigned char ricoh_alarm[0x0F];
 
-void put_rtc_byte(uint32_t address_, uint8_t value, uint8_t rtc_type) {
+void put_rtc_byte(uint32_t address_, uint8_t value_, uint8_t rtc_type) {
   uint32_t address = address_ & 0x3F;
+  uint8_t value = (value_ & 0x0F);
+
   address >>= 2;
+
+  //printf("Wrote byte %.2X.\n", address);
+
   if (rtc_type == RTC_TYPE_MSM) {
     switch(address) {
       case 0x0D:
@@ -75,6 +80,12 @@ void put_rtc_byte(uint32_t address_, uint8_t value, uint8_t rtc_type) {
 
 uint8_t get_rtc_byte(uint32_t address_, uint8_t rtc_type) {
   uint32_t address = address_ & 0x3F;
+
+       if ((address & 3) == 2 || (address & 3) == 0) {
+    //printf("Garbage byte read.\n");
+               return 0;
+       }
+
   address >>= 2;
   time_t t;
   time(&t);
@@ -92,6 +103,8 @@ uint8_t get_rtc_byte(uint32_t address_, uint8_t rtc_type) {
     }
   }
 
+  //printf("Read byte %.2X.\n", address);
+
   switch (address) {
     case 0x00: // Seconds low?
       return rtc_time->tm_sec % 10;