⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 srtc.cpp

📁 SFC游戏模拟器 snes9x 1.43 的原代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	       hours = 0;	   }	   if ( time_diff > MINUTETICKS )	   {	       minutes = time_diff / MINUTETICKS;	       time_diff = time_diff - minutes * MINUTETICKS;	   }	   else	   {	       minutes = 0;	   }	   if ( time_diff > 0 )	   {	       seconds = time_diff;	   }	   else	   {	       seconds = 0;	   }	   seconds += (rtc.data[1]*10 + rtc.data[0]);           if ( seconds >= 60 )	   {	       seconds -= 60;	       minutes += 1;	   }	   minutes += (rtc.data[3]*10 + rtc.data[2]);           if ( minutes >= 60 )	   {	       minutes -= 60;	       hours += 1;	   }	   hours += (rtc.data[5]*10 + rtc.data[4]);           if ( hours >= 24 )	   {	       hours -= 24;	       days += 1;	   }	   if ( days > 0 )	   {	       year =  rtc.data[10]*10 + rtc.data[9];	       year += ( 1000 + rtc.data[11] * 100 );	       month = rtc.data[8];	       days += (rtc.data[7]*10 + rtc.data[6]);	       while ( days > (temp_days = S9xSRTCDaysInMmonth( month, year )) )               {		    days -= temp_days;		    month += 1;		    if ( month > 12 )		    {		        year += 1;		        month = 1;		    }	       }               year_tens = year % 100;               year_ones = year_tens % 10;               year_tens /= 10;               year_hundreds = (year - 1000) / 100;	       rtc.data[6] = days % 10;	       rtc.data[7] = days / 10;	       rtc.data[8] = month;	       rtc.data[9] = year_ones;	       rtc.data[10] = year_tens;	       rtc.data[11] = year_hundreds;	       rtc.data[12] = S9xSRTCComputeDayOfWeek ();	   }	   rtc.data[0] = seconds % 10;	   rtc.data[1] = seconds / 10;	   rtc.data[2] = minutes % 10;	   rtc.data[3] = minutes / 10;	   rtc.data[4] = hours % 10;	   rtc.data[5] = hours / 10;	   return;        }    }}/**********************************************************************************************//* S9xSetSRTC()                                                                               *//* This function sends data to the S-RTC used in Dai Kaijyu Monogatari II                     *//**********************************************************************************************/void S9xSetSRTC (uint8 data, uint16 Address){    data &= 0x0F;	// Data is only 4-bits, mask out unused bits.    if( data >= 0xD )    {        // It's an RTC command        switch ( data )        {            case 0xD:                rtc.mode = MODE_READ;                rtc.index = -1;                break;            case 0xE:                rtc.mode = MODE_COMMAND;                break;            default:                // Ignore the write if it's an 0xF ???	        // Probably should switch back to read mode -- but this	        //  sequence never occurs in DKJM2                break;        }        return;    }    if ( rtc.mode == MODE_LOAD_RTC )    {        if ( (rtc.index >= 0) || (rtc.index < MAX_RTC_INDEX) )        {            rtc.data[rtc.index++] = data;            if ( rtc.index == MAX_RTC_INDEX )            {                // We have all the data for the RTC load                rtc.system_timestamp = time (NULL);	// Get local system time                // Get the day of the week                rtc.data[rtc.index++] = S9xSRTCComputeDayOfWeek ();                // Start RTC counting again                rtc.count_enable = TRUE;                rtc.needs_init = FALSE;            }            return;        }        else        {            // Attempting to write too much data            // error(); // ignore??        }    }    else if ( rtc.mode == MODE_COMMAND )    {        switch( data )        {            case COMMAND_CLEAR_RTC:                // Disable RTC counter                rtc.count_enable = FALSE;                ZeroMemory (rtc.data, MAX_RTC_INDEX+1);                rtc.index = -1;                rtc.mode = MODE_COMMAND_DONE;                break;            case COMMAND_LOAD_RTC:                // Disable RTC counter                rtc.count_enable = FALSE;                rtc.index = 0;  // Setup for writing                rtc.mode = MODE_LOAD_RTC;                break;            default:                rtc.mode = MODE_COMMAND_DONE;                // unrecognized command - need to implement.        }        return;    }    else    {        if ( rtc.mode == MODE_READ )        {            // Attempting to write while in read mode. Ignore.        }        if ( rtc.mode == MODE_COMMAND_DONE )        {            // Maybe this isn't an error.  Maybe we should kick off            // a new E command.  But is this valid?        }    }}/**********************************************************************************************//* S9xGetSRTC()                                                                               *//* This function retrieves data from the S-RTC                                                *//**********************************************************************************************/uint8 S9xGetSRTC (uint16 Address){    if ( rtc.mode == MODE_READ )    {        if ( rtc.index < 0 )        {            S9xUpdateSrtcTime ();	// Only update it if the game reads it            rtc.index++;            return ( 0x0f );        // Send start marker.        }        else if (rtc.index > MAX_RTC_INDEX)        {            rtc.index = -1;         // Setup for next set of reads            return ( 0x0f );        // Data done marker.        }        else        {            // Feed out the data            return rtc.data[rtc.index++];        }     }     else     {         return 0x0;     }}void S9xSRTCPreSaveState (){    if (Settings.SRTC)    {	S9xUpdateSrtcTime ();	int s = Memory.SRAMSize ?		(1 << (Memory.SRAMSize + 3)) * 128 : 0;	if (s > 0x20000)	    s = 0x20000;	SRAM [s + 0] = rtc.needs_init;	SRAM [s + 1] = rtc.count_enable;	memmove (&SRAM [s + 2], rtc.data, MAX_RTC_INDEX + 1);	SRAM [s + 3 + MAX_RTC_INDEX] = rtc.index;	SRAM [s + 4 + MAX_RTC_INDEX] = rtc.mode;#ifdef LSB_FIRST	memmove (&SRAM [s + 5 + MAX_RTC_INDEX], &rtc.system_timestamp, 8);#else	SRAM [s + 5  + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >>  0);	SRAM [s + 6  + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >>  8);	SRAM [s + 7  + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 16);	SRAM [s + 8  + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 24);	SRAM [s + 9  + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 32);	SRAM [s + 10 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 40);	SRAM [s + 11 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 48);	SRAM [s + 12 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 56);#endif    }}void S9xSRTCPostLoadState (){    if (Settings.SRTC)    {	int s = Memory.SRAMSize ?		(1 << (Memory.SRAMSize + 3)) * 128 : 0;	if (s > 0x20000)	    s = 0x20000;	rtc.needs_init = SRAM [s + 0];	rtc.count_enable = SRAM [s + 1];	memmove (rtc.data, &SRAM [s + 2], MAX_RTC_INDEX + 1);	rtc.index = SRAM [s + 3 + MAX_RTC_INDEX];	rtc.mode = SRAM [s + 4 + MAX_RTC_INDEX];#ifdef LSB_FIRST	memmove (&rtc.system_timestamp, &SRAM [s + 5 + MAX_RTC_INDEX], 8);#else	rtc.system_timestamp |= (SRAM [s +  5 + MAX_RTC_INDEX] <<  0);	rtc.system_timestamp |= (SRAM [s +  6 + MAX_RTC_INDEX] <<  8);	rtc.system_timestamp |= (SRAM [s +  7 + MAX_RTC_INDEX] << 16);	rtc.system_timestamp |= (SRAM [s +  8 + MAX_RTC_INDEX] << 24);	rtc.system_timestamp |= (SRAM [s +  9 + MAX_RTC_INDEX] << 32);	rtc.system_timestamp |= (SRAM [s + 10 + MAX_RTC_INDEX] << 40);	rtc.system_timestamp |= (SRAM [s + 11 + MAX_RTC_INDEX] << 48);	rtc.system_timestamp |= (SRAM [s + 12 + MAX_RTC_INDEX] << 56);#endif	S9xUpdateSrtcTime ();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -