2009-01-08 08:35:44 +01:00
|
|
|
#include "../System.h"
|
|
|
|
#include "GBA.h"
|
2008-09-23 01:00:10 +02:00
|
|
|
#include "Globals.h"
|
2009-01-08 08:35:44 +01:00
|
|
|
#include "../common/Port.h"
|
|
|
|
#include "../Util.h"
|
|
|
|
#include "../NLS.h"
|
2008-09-23 01:00:10 +02:00
|
|
|
#include "vmmem.h"
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
#include <string.h>
|
2016-06-05 00:59:43 +02:00
|
|
|
|
|
|
|
enum RTCSTATE
|
|
|
|
{
|
|
|
|
IDLE = 0,
|
|
|
|
COMMAND,
|
|
|
|
DATA,
|
|
|
|
READDATA
|
|
|
|
};
|
2009-03-04 07:53:25 +01:00
|
|
|
|
|
|
|
u8 systemGetSensorDarkness();
|
|
|
|
int systemGetSensorZ();
|
2008-09-23 01:00:10 +02:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
u8 byte0;
|
|
|
|
u8 byte1;
|
|
|
|
u8 byte2;
|
|
|
|
u8 command;
|
|
|
|
int dataLen;
|
|
|
|
int bits;
|
|
|
|
RTCSTATE state;
|
|
|
|
u8 data[12];
|
|
|
|
// reserved variables for future
|
|
|
|
u8 reserved[12];
|
|
|
|
bool reserved2;
|
|
|
|
u32 reserved3;
|
|
|
|
} RTCCLOCKDATA;
|
|
|
|
|
|
|
|
static RTCCLOCKDATA rtcClockData;
|
|
|
|
static bool rtcEnabled = false;
|
Rumble for all GBC rumble games and Drill Dozer. Rumble should work on Gamecube controller too. The following games have native rumble support: WarioWare Twisted, Drill Dozer, 10 Pin Bowling, 3-D Ultra Pinball Thrillride, Disney's The Little Mermaid II: Pinball Frenzy, Hole in One Golf, Missile Command, NASCAR Challenge, Perfect Dark, Pokémon Pinball, Polaris SnoCross, Ready 2 Rumble Boxing, Star Wars Episode I: Racer, Test Drive Off-Road 3, Tonka Raceway, Top Gear Pocket\Top Gear Rally, Vigilante 8, Zebco Fishing, and maybe some other games.
Also, rumble and wii-control code has been cleaned up a bit.
2009-03-20 21:22:22 +01:00
|
|
|
static bool rtcWarioRumbleEnabled = false;
|
2009-03-04 07:53:25 +01:00
|
|
|
|
2008-09-23 01:00:10 +02:00
|
|
|
void rtcEnable(bool e)
|
|
|
|
{
|
|
|
|
rtcEnabled = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool rtcIsEnabled()
|
|
|
|
{
|
|
|
|
return rtcEnabled;
|
|
|
|
}
|
|
|
|
|
Rumble for all GBC rumble games and Drill Dozer. Rumble should work on Gamecube controller too. The following games have native rumble support: WarioWare Twisted, Drill Dozer, 10 Pin Bowling, 3-D Ultra Pinball Thrillride, Disney's The Little Mermaid II: Pinball Frenzy, Hole in One Golf, Missile Command, NASCAR Challenge, Perfect Dark, Pokémon Pinball, Polaris SnoCross, Ready 2 Rumble Boxing, Star Wars Episode I: Racer, Test Drive Off-Road 3, Tonka Raceway, Top Gear Pocket\Top Gear Rally, Vigilante 8, Zebco Fishing, and maybe some other games.
Also, rumble and wii-control code has been cleaned up a bit.
2009-03-20 21:22:22 +01:00
|
|
|
void rtcEnableWarioRumble(bool e)
|
|
|
|
{
|
|
|
|
if (e) rtcEnable(true);
|
|
|
|
rtcWarioRumbleEnabled = e;
|
|
|
|
}
|
|
|
|
|
2008-09-23 01:00:10 +02:00
|
|
|
u16 rtcRead(u32 address)
|
|
|
|
{
|
|
|
|
if(rtcEnabled) {
|
|
|
|
switch(address){
|
|
|
|
case 0x80000c8:
|
|
|
|
return rtcClockData.byte2;
|
|
|
|
break;
|
|
|
|
case 0x80000c6:
|
|
|
|
return rtcClockData.byte1;
|
|
|
|
break;
|
|
|
|
case 0x80000c4:
|
2009-03-04 07:53:25 +01:00
|
|
|
|
|
|
|
// Boktai Solar Sensor
|
|
|
|
if (rtcClockData.byte1 == 7) {
|
|
|
|
if (rtcClockData.reserved[11] >= systemGetSensorDarkness()) {
|
|
|
|
rtcClockData.reserved[10] = 0;
|
|
|
|
rtcClockData.reserved[11] = 0;
|
|
|
|
return 8;
|
|
|
|
} else return 0;
|
|
|
|
|
|
|
|
// WarioWare Twisted Tilt Sensor
|
|
|
|
} else if (rtcClockData.byte1 == 0x0b) {
|
|
|
|
//sprintf(DebugStr, "Reading Twisted Sensor bit %d", rtcClockData.reserved[11]);
|
|
|
|
u16 v = systemGetSensorZ();
|
|
|
|
return ((v >> rtcClockData.reserved[11]) & 1) << 2;
|
|
|
|
|
|
|
|
// Real Time Clock
|
|
|
|
} else {
|
|
|
|
//sprintf(DebugStr, "Reading RTC %02x, %02x, %02x", rtcClockData.byte0, rtcClockData.byte1, rtcClockData.byte2);
|
|
|
|
return rtcClockData.byte0;
|
|
|
|
}
|
2008-09-23 01:00:10 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-10-11 10:06:36 +02:00
|
|
|
#ifdef USE_VM
|
2008-09-23 01:00:10 +02:00
|
|
|
return VMRead16( address & 0x1FFFFFE );
|
2008-10-11 10:06:36 +02:00
|
|
|
#else
|
|
|
|
return READ16LE((&rom[address & 0x1FFFFFE]));
|
|
|
|
#endif
|
2008-09-23 01:00:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static u8 toBCD(u8 value)
|
|
|
|
{
|
|
|
|
value = value % 100;
|
|
|
|
int l = value % 10;
|
|
|
|
int h = value / 10;
|
|
|
|
return h * 16 + l;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool rtcWrite(u32 address, u16 value)
|
|
|
|
{
|
|
|
|
if(!rtcEnabled)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(address == 0x80000c8) {
|
2009-03-04 07:53:25 +01:00
|
|
|
rtcClockData.byte2 = (u8)value; // bit 0 = enable reading from 0x80000c4 c6 and c8
|
2008-09-23 01:00:10 +02:00
|
|
|
} else if(address == 0x80000c6) {
|
2009-03-04 07:53:25 +01:00
|
|
|
rtcClockData.byte1 = (u8)value; // 0=read/1=write (for each of 4 low bits)
|
Rumble for all GBC rumble games and Drill Dozer. Rumble should work on Gamecube controller too. The following games have native rumble support: WarioWare Twisted, Drill Dozer, 10 Pin Bowling, 3-D Ultra Pinball Thrillride, Disney's The Little Mermaid II: Pinball Frenzy, Hole in One Golf, Missile Command, NASCAR Challenge, Perfect Dark, Pokémon Pinball, Polaris SnoCross, Ready 2 Rumble Boxing, Star Wars Episode I: Racer, Test Drive Off-Road 3, Tonka Raceway, Top Gear Pocket\Top Gear Rally, Vigilante 8, Zebco Fishing, and maybe some other games.
Also, rumble and wii-control code has been cleaned up a bit.
2009-03-20 21:22:22 +01:00
|
|
|
// rumble is off when not writing to that pin
|
|
|
|
if (rtcWarioRumbleEnabled && !(value & 8)) systemCartridgeRumble(false);
|
2009-03-04 07:53:25 +01:00
|
|
|
} else if(address == 0x80000c4) { // 4 bits of I/O Port Data (upper bits not used)
|
|
|
|
|
|
|
|
// WarioWare Twisted rumble
|
Rumble for all GBC rumble games and Drill Dozer. Rumble should work on Gamecube controller too. The following games have native rumble support: WarioWare Twisted, Drill Dozer, 10 Pin Bowling, 3-D Ultra Pinball Thrillride, Disney's The Little Mermaid II: Pinball Frenzy, Hole in One Golf, Missile Command, NASCAR Challenge, Perfect Dark, Pokémon Pinball, Polaris SnoCross, Ready 2 Rumble Boxing, Star Wars Episode I: Racer, Test Drive Off-Road 3, Tonka Raceway, Top Gear Pocket\Top Gear Rally, Vigilante 8, Zebco Fishing, and maybe some other games.
Also, rumble and wii-control code has been cleaned up a bit.
2009-03-20 21:22:22 +01:00
|
|
|
if(rtcWarioRumbleEnabled && (rtcClockData.byte1 & 8)) {
|
|
|
|
systemCartridgeRumble(value & 8);
|
2009-03-04 07:53:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Boktai solar sensor
|
|
|
|
if (rtcClockData.byte1 == 7) {
|
|
|
|
if (value & 2) {
|
|
|
|
// reset counter to 0
|
|
|
|
rtcClockData.reserved[11]=0;
|
|
|
|
rtcClockData.reserved[10]=0;
|
|
|
|
}
|
|
|
|
if ((value & 1) && (!(rtcClockData.reserved[10] & 1))) {
|
|
|
|
// increase counter, ready to do another read
|
|
|
|
if (rtcClockData.reserved[11]<255) rtcClockData.reserved[11]++;
|
|
|
|
}
|
|
|
|
rtcClockData.reserved[10] = value & rtcClockData.byte1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// WarioWare Twisted rotation sensor
|
|
|
|
if (rtcClockData.byte1 == 0xb) {
|
|
|
|
if (value & 2) {
|
|
|
|
// clock goes high in preperation for reading a bit
|
|
|
|
rtcClockData.reserved[11]--;
|
|
|
|
}
|
|
|
|
if (value & 1) {
|
|
|
|
// start ADC conversion
|
|
|
|
rtcClockData.reserved[11] = 15;
|
|
|
|
}
|
|
|
|
|
|
|
|
rtcClockData.byte0 = value & rtcClockData.byte1;
|
|
|
|
|
|
|
|
// Real Time Clock
|
|
|
|
}
|
|
|
|
/**/
|
|
|
|
|
|
|
|
if(rtcClockData.byte2 & 1) { // if reading is enabled
|
|
|
|
if(rtcClockData.state == IDLE && rtcClockData.byte0 == 1 && value == 5) {
|
2008-09-23 01:00:10 +02:00
|
|
|
rtcClockData.state = COMMAND;
|
|
|
|
rtcClockData.bits = 0;
|
|
|
|
rtcClockData.command = 0;
|
|
|
|
} else if(!(rtcClockData.byte0 & 1) && (value & 1)) { // bit transfer
|
|
|
|
rtcClockData.byte0 = (u8)value;
|
|
|
|
switch(rtcClockData.state) {
|
|
|
|
case COMMAND:
|
|
|
|
rtcClockData.command |= ((value & 2) >> 1) << (7-rtcClockData.bits);
|
|
|
|
rtcClockData.bits++;
|
|
|
|
if(rtcClockData.bits == 8) {
|
|
|
|
rtcClockData.bits = 0;
|
|
|
|
switch(rtcClockData.command) {
|
|
|
|
case 0x60:
|
|
|
|
// not sure what this command does but it doesn't take parameters
|
|
|
|
// maybe it is a reset or stop
|
|
|
|
rtcClockData.state = IDLE;
|
|
|
|
rtcClockData.bits = 0;
|
|
|
|
break;
|
|
|
|
case 0x62:
|
|
|
|
// this sets the control state but not sure what those values are
|
|
|
|
rtcClockData.state = READDATA;
|
|
|
|
rtcClockData.dataLen = 1;
|
|
|
|
break;
|
|
|
|
case 0x63:
|
|
|
|
rtcClockData.dataLen = 1;
|
|
|
|
rtcClockData.data[0] = 0x40;
|
|
|
|
rtcClockData.state = DATA;
|
|
|
|
break;
|
|
|
|
case 0x64:
|
|
|
|
break;
|
|
|
|
case 0x65:
|
|
|
|
{
|
|
|
|
struct tm *newtime;
|
|
|
|
time_t long_time;
|
|
|
|
|
|
|
|
time( &long_time ); /* Get time as long integer. */
|
|
|
|
newtime = localtime( &long_time ); /* Convert to local time. */
|
|
|
|
|
|
|
|
rtcClockData.dataLen = 7;
|
|
|
|
rtcClockData.data[0] = toBCD(newtime->tm_year);
|
|
|
|
rtcClockData.data[1] = toBCD(newtime->tm_mon+1);
|
|
|
|
rtcClockData.data[2] = toBCD(newtime->tm_mday);
|
|
|
|
rtcClockData.data[3] = toBCD(newtime->tm_wday);
|
|
|
|
rtcClockData.data[4] = toBCD(newtime->tm_hour);
|
|
|
|
rtcClockData.data[5] = toBCD(newtime->tm_min);
|
|
|
|
rtcClockData.data[6] = toBCD(newtime->tm_sec);
|
|
|
|
rtcClockData.state = DATA;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x67:
|
|
|
|
{
|
|
|
|
struct tm *newtime;
|
|
|
|
time_t long_time;
|
|
|
|
|
|
|
|
time( &long_time ); /* Get time as long integer. */
|
|
|
|
newtime = localtime( &long_time ); /* Convert to local time. */
|
|
|
|
|
|
|
|
rtcClockData.dataLen = 3;
|
|
|
|
rtcClockData.data[0] = toBCD(newtime->tm_hour);
|
|
|
|
rtcClockData.data[1] = toBCD(newtime->tm_min);
|
|
|
|
rtcClockData.data[2] = toBCD(newtime->tm_sec);
|
|
|
|
rtcClockData.state = DATA;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
systemMessage(0, N_("Unknown RTC command %02x"), rtcClockData.command);
|
|
|
|
rtcClockData.state = IDLE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DATA:
|
|
|
|
if(rtcClockData.byte1 & 2) {
|
|
|
|
} else {
|
|
|
|
rtcClockData.byte0 = (rtcClockData.byte0 & ~2) |
|
|
|
|
((rtcClockData.data[rtcClockData.bits >> 3] >>
|
|
|
|
(rtcClockData.bits & 7)) & 1)*2;
|
|
|
|
rtcClockData.bits++;
|
|
|
|
if(rtcClockData.bits == 8*rtcClockData.dataLen) {
|
|
|
|
rtcClockData.bits = 0;
|
|
|
|
rtcClockData.state = IDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case READDATA:
|
|
|
|
if(!(rtcClockData.byte1 & 2)) {
|
|
|
|
} else {
|
|
|
|
rtcClockData.data[rtcClockData.bits >> 3] =
|
|
|
|
(rtcClockData.data[rtcClockData.bits >> 3] >> 1) |
|
|
|
|
((value << 6) & 128);
|
|
|
|
rtcClockData.bits++;
|
|
|
|
if(rtcClockData.bits == 8*rtcClockData.dataLen) {
|
|
|
|
rtcClockData.bits = 0;
|
|
|
|
rtcClockData.state = IDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-03-04 07:53:25 +01:00
|
|
|
default:
|
2008-09-23 01:00:10 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
rtcClockData.byte0 = (u8)value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rtcReset()
|
|
|
|
{
|
|
|
|
memset(&rtcClockData, 0, sizeof(rtcClockData));
|
|
|
|
|
|
|
|
rtcClockData.byte0 = 0;
|
|
|
|
rtcClockData.byte1 = 0;
|
|
|
|
rtcClockData.byte2 = 0;
|
|
|
|
rtcClockData.command = 0;
|
|
|
|
rtcClockData.dataLen = 0;
|
|
|
|
rtcClockData.bits = 0;
|
|
|
|
rtcClockData.state = IDLE;
|
2009-03-04 07:53:25 +01:00
|
|
|
rtcClockData.reserved[11] = 0;
|
2008-09-23 01:00:10 +02:00
|
|
|
}
|
|
|
|
|
2016-06-05 00:59:43 +02:00
|
|
|
#ifdef __LIBRETRO__
|
|
|
|
void rtcSaveGame(u8 *&data)
|
|
|
|
{
|
|
|
|
utilWriteMem(data, &rtcClockData, sizeof(rtcClockData));
|
|
|
|
}
|
|
|
|
|
|
|
|
void rtcReadGame(const u8 *&data)
|
|
|
|
{
|
|
|
|
utilReadMem(&rtcClockData, data, sizeof(rtcClockData));
|
|
|
|
}
|
|
|
|
#else
|
2008-09-23 01:00:10 +02:00
|
|
|
void rtcSaveGame(gzFile gzFile)
|
|
|
|
{
|
|
|
|
utilGzWrite(gzFile, &rtcClockData, sizeof(rtcClockData));
|
|
|
|
}
|
|
|
|
|
|
|
|
void rtcReadGame(gzFile gzFile)
|
|
|
|
{
|
|
|
|
utilGzRead(gzFile, &rtcClockData, sizeof(rtcClockData));
|
|
|
|
}
|
2016-06-05 00:59:43 +02:00
|
|
|
#endif
|