Core/burn/drv/sega/sys16_fd1094.cpp
/* this function checks the cache to see if the current state is cached,
   if it is then it copies the cached data to the user region where code is
   executed from, if its not cached then it gets decrypted to the current
   cache position using the functions in fd1094.c */
this function checks the cache to see if the current state is cached,
if it is then it copies the cached data to the user region where code is
executed from, if its not cached then it gets decrypted to the current
cache position using the functions in fd1094.c
this function checks the cache to see if the current state is cached if it is then it copies the cached data to the user region where code is executed from if its not cached then it gets decrypted to the current cache position using the functions in fd1094 . c
static void fd1094_setstate_and_decrypt(INT32 state)
{
	INT32 i;
	UINT32 addr;
	switch (state & 0x300) {
		case 0x000:
		case FD1094_STATE_RESET:
			fd1094_selected_state = state & 0xff;
		break;
	}
	fd1094_state = state;
	m68k_set_reg(M68K_REG_PREF_ADDR, 0x1000);
	state = fd1094_set_state(fd1094_key,state);
	for (i=0;i<S16_NUMCACHE;i++)
	{
		if (fd1094_cached_states[i] == state)
		{
			fd1094_userregion=fd1094_cacheregion[i];
			INT32 nActiveCPU = SekGetActive();
			if (nActiveCPU == -1) {
				SekOpen(nFD1094CPU);
				SekMapMemory((UINT8*)fd1094_userregion, 0x000000, 0x0fffff, SM_FETCH);
				if (System18Banking) SekMapMemory((UINT8*)fd1094_userregion + 0x200000, 0x200000, 0x27ffff, SM_FETCH);
				SekClose();
			} else {
				if (nActiveCPU == nFD1094CPU) {
					SekMapMemory((UINT8*)fd1094_userregion, 0x000000, 0x0fffff, SM_FETCH);
					if (System18Banking) SekMapMemory((UINT8*)fd1094_userregion + 0x200000, 0x200000, 0x27ffff, SM_FETCH);
				} else {
					SekClose();
					SekOpen(nFD1094CPU);
					SekMapMemory((UINT8*)fd1094_userregion, 0x000000, 0x0fffff, SM_FETCH);
					if (System18Banking) SekMapMemory((UINT8*)fd1094_userregion + 0x200000, 0x200000, 0x27ffff, SM_FETCH);
					SekClose();
					SekOpen(nActiveCPU);
				}
			}
			return;
		}
	}
	fd1094_cached_states[fd1094_current_cacheposition]=state;
	for (addr=0;addr<fd1094_cpuregionsize/2;addr++)
	{
		UINT16 dat;
		dat = fd1094_decode(addr,fd1094_cpuregion[addr],fd1094_key,0);
		fd1094_cacheregion[fd1094_current_cacheposition][addr]=dat;
	}
	fd1094_userregion=fd1094_cacheregion[fd1094_current_cacheposition];
	INT32 nActiveCPU = SekGetActive();
	if (nActiveCPU == -1) {
		SekOpen(nFD1094CPU);
		SekMapMemory((UINT8*)fd1094_userregion, 0x000000, 0x0fffff, SM_FETCH);
		if (System18Banking) SekMapMemory((UINT8*)fd1094_userregion + 0x200000, 0x200000, 0x27ffff, SM_FETCH);
		SekClose();
	} else {
		if (nActiveCPU == nFD1094CPU) {
			SekMapMemory((UINT8*)fd1094_userregion, 0x000000, 0x0fffff, SM_FETCH);
			if (System18Banking) SekMapMemory((UINT8*)fd1094_userregion + 0x200000, 0x200000, 0x27ffff, SM_FETCH);
		} else {
			SekClose();
			SekOpen(nFD1094CPU);
			SekMapMemory((UINT8*)fd1094_userregion, 0x000000, 0x0fffff, SM_FETCH);
			if (System18Banking) SekMapMemory((UINT8*)fd1094_userregion + 0x200000, 0x200000, 0x27ffff, SM_FETCH);
			SekClose();
			SekOpen(nActiveCPU);
		}
	}
	fd1094_current_cacheposition++;
	if (fd1094_current_cacheposition>=S16_NUMCACHE)
	{
#if 1 && defined FBA_DEBUG
		bprintf(PRINT_NORMAL, _T("out of cache, performance may suffer, increase S16_NUMCACHE!\n"));
#endif
		fd1094_current_cacheposition=0;
	}
}
static void fd1094_setstate_and_decrypt ( INT32 state ) { INT32 i ; UINT32 addr ; switch ( state & 0x300 ) { case 0x000 : case FD1094_STATE_RESET : fd1094_selected_state = state & 0xff ; break ; } fd1094_state = state ; m68k_set_reg ( M68K_REG_PREF_ADDR , 0x1000 ) ; state = fd1094_set_state ( fd1094_key , state ) ; for ( i = 0 ; i < S16_NUMCACHE ; i ++ ) { if ( fd1094_cached_states [ i ] == state ) { fd1094_userregion = fd1094_cacheregion [ i ] ; INT32 nActiveCPU = SekGetActive ( ) ; if ( nActiveCPU == -1 ) { SekOpen ( nFD1094CPU ) ; SekMapMemory ( ( UINT8 * ) fd1094_userregion , 0x000000 , 0x0fffff , SM_FETCH ) ; if ( System18Banking ) SekMapMemory ( ( UINT8 * ) fd1094_userregion + 0x200000 , 0x200000 , 0x27ffff , SM_FETCH ) ; SekClose ( ) ; } else { if ( nActiveCPU == nFD1094CPU ) { SekMapMemory ( ( UINT8 * ) fd1094_userregion , 0x000000 , 0x0fffff , SM_FETCH ) ; if ( System18Banking ) SekMapMemory ( ( UINT8 * ) fd1094_userregion + 0x200000 , 0x200000 , 0x27ffff , SM_FETCH ) ; } else { SekClose ( ) ; SekOpen ( nFD1094CPU ) ; SekMapMemory ( ( UINT8 * ) fd1094_userregion , 0x000000 , 0x0fffff , SM_FETCH ) ; if ( System18Banking ) SekMapMemory ( ( UINT8 * ) fd1094_userregion + 0x200000 , 0x200000 , 0x27ffff , SM_FETCH ) ; SekClose ( ) ; SekOpen ( nActiveCPU ) ; } } return ; } } fd1094_cached_states [ fd1094_current_cacheposition ] = state ; for ( addr = 0 ; addr < fd1094_cpuregionsize / 2 ; addr ++ ) { UINT16 dat ; dat = fd1094_decode ( addr , fd1094_cpuregion [ addr ] , fd1094_key , 0 ) ; fd1094_cacheregion [ fd1094_current_cacheposition ] [ addr ] = dat ; } fd1094_userregion = fd1094_cacheregion [ fd1094_current_cacheposition ] ; INT32 nActiveCPU = SekGetActive ( ) ; if ( nActiveCPU == -1 ) { SekOpen ( nFD1094CPU ) ; SekMapMemory ( ( UINT8 * ) fd1094_userregion , 0x000000 , 0x0fffff , SM_FETCH ) ; if ( System18Banking ) SekMapMemory ( ( UINT8 * ) fd1094_userregion + 0x200000 , 0x200000 , 0x27ffff , SM_FETCH ) ; SekClose ( ) ; } else { if ( nActiveCPU == nFD1094CPU ) { SekMapMemory ( ( UINT8 * ) fd1094_userregion , 0x000000 , 0x0fffff , SM_FETCH ) ; if ( System18Banking ) SekMapMemory ( ( UINT8 * ) fd1094_userregion + 0x200000 , 0x200000 , 0x27ffff , SM_FETCH ) ; } else { SekClose ( ) ; SekOpen ( nFD1094CPU ) ; SekMapMemory ( ( UINT8 * ) fd1094_userregion , 0x000000 , 0x0fffff , SM_FETCH ) ; if ( System18Banking ) SekMapMemory ( ( UINT8 * ) fd1094_userregion + 0x200000 , 0x200000 , 0x27ffff , SM_FETCH ) ; SekClose ( ) ; SekOpen ( nActiveCPU ) ; } } fd1094_current_cacheposition ++ ; if ( fd1094_current_cacheposition >= S16_NUMCACHE ) { #if 1 && defined FBA_DEBUG bprintf ( PRINT_NORMAL , _T ( " \n " ) ) ; #endif fd1094_current_cacheposition = 0 ; } }
this function checks the cache to see if the current state is cached,
if it is then it copies the cached data to the user region where code is
executed from, if its not cached then it gets decrypted to the current
cache position using the functions in fd1094.c
this function checks the cache to see if the current state is cached if it is then it copies the cached data to the user region where code is executed from if its not cached then it gets decrypted to the current cache position using the functions in fd1094 . c
// force a flush of the prefetch cache /* set the FD1094 state ready to decrypt.. */ /* first check the cache, if its cached we don't need to decrypt it, just copy */ /* copy cached state */ /* mark it as cached (because it will be once we decrypt it) */ /* copy newly decrypted data to user region */