mirror of
https://github.com/captain-amygdala/pistorm.git
synced 2026-02-02 14:51:03 +00:00
Fix some RTC and CDTV NVRAM stuff
This commit is contained in:
@@ -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)));
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user