Пример #1
0
//---------------------------------------------------------------------------------
void sdmmcValueHandler(u32 value, void* user_data) {
//---------------------------------------------------------------------------------
	int result;
	
	switch(value) {

	case SDMMC_HAVE_SD:
		result = sdmmc_read16(REG_SDSTATUS0);
		fifoSendValue32(FIFO_SDMMC, result);
		break;

	case SDMMC_SD_START:
		if (sdmmc_read16(REG_SDSTATUS0) == 0) {
			result = 1;
		} else {
			sdmmc_controller_init();
			result = sdmmc_sdcard_init();
		}
		fifoSendValue32(FIFO_SDMMC, result);
		break;

	case SDMMC_SD_IS_INSERTED:
		result = sdmmc_cardinserted();
		fifoSendValue32(FIFO_SDMMC, result);
		break;

	case SDMMC_SD_STOP:
		break;

	}
}
Пример #2
0
//---------------------------------------------------------------------------------
void avrDataHandler(int bytes, void *user_data) {
//---------------------------------------------------------------------------------
	AvrFifoMessage msg;
	int value;

	fifoGetDatamsg(FIFO_AVR, bytes, (u8*)&msg);
	
	if(msg.type == PROFILE_MESSAGE) {
    	long int i;
    	
		for(i=0;i < (50000);i++) {
		    swiDelay(10000);
		}
    	
    	fifoSendValue32(FIFO_AVR, (u32)1337 );
	} else if(msg.type == CONFIG_MESSAGE) {
	   	shortwait = WAIT_1MS * msg.SPIConfig.m1;
	   	speed = msg.SPIConfig.m2;
	   	spi_debug = msg.SPIConfig.debug;
	} else if(msg.type == LED_FLASH_MESSAGE) {
	    send_chars(2, FLASH_LED_COMMAND, msg.LEDFlash.count);
	} else if (msg.type == ANALOG_READ_MESSAGE) {
		send_chars(2, ANALOG_READ_COMMAND, msg.AnalogRead.pin);
		swiDelay(10000);
		send_chars(3, NULL_COMMAND, 0, 0);

		fifoSendDatamsg(FIFO_AVR, sizeof(incoming), incoming);
		//value = incoming[1];
		//value |= (incoming[2] << 8);
		/*value = read_increment(1);
		swiDelay(COMMAND_WAIT);
		value |= (read_increment(1) << 8);*/
		
		//fifoSendValue32(FIFO_AVR, (u32)value);
	} else if (msg.type == IO_PORT_GET_MESSAGE) {
		value = ioport_get(msg.IOPortGetSet.address);
		fifoSendValue32(FIFO_AVR, (u32)value);
	} else if (msg.type == IO_PORT_SET_MESSAGE) {
		ioport_set(msg.IOPortGetSet.address, msg.IOPortGetSet.value);
	} else if (msg.type == PWM_MESSAGE) {
		if(msg.PWM.command == PWM_ON) {
			if(msg.PWM.output == PWM5) {
				reg_orequal(TCCR2B, _BV(CS22));
				//TCCR2B |= CS22
			}
		}
	}
}
Пример #3
0
//---------------------------------------------------------------------------------
bool sdio_Startup() {
//---------------------------------------------------------------------------------
	if (!REG_DSIMODE) return false;

	fifoSendValue32(FIFO_SDMMC,SDMMC_HAVE_SD);
	while(!fifoCheckValue32(FIFO_SDMMC));
	int result = fifoGetValue32(FIFO_SDMMC);

	if(result==0) return false;

	fifoSendValue32(FIFO_SDMMC,SDMMC_SD_START);
	while(!fifoCheckValue32(FIFO_SDMMC));
	result = fifoGetValue32(FIFO_SDMMC);
	
	return result == 0;
}
Пример #4
0
void sleepMode(u32 value32, void* userdata)
{iprintf("sleep mode engaged\n");for(;;);
	fifoSendValue32(FIFO_USER_03, 1);
	
	// turn shit off
	u32 powerstate = *(vu32*)0x04000304;
	*(vu32*)0x04000304 = (powerstate & 0x8001);
	
	swiIntrWait(1, IRQ_FIFO_NOT_EMPTY);
	iprintf("done sleeping\n");
	// turn shit back on
	*(vu32*)0x04000304 = powerstate;
	
	fifoSendValue32(FIFO_USER_03, 1);
	while (!fifoCheckValue32(FIFO_USER_03));
}
Пример #5
0
//---------------------------------------------------------------------------------
void sdmmc_sdcard_readsectors(u32 sector_no, u32 numsectors, void *out) {
//---------------------------------------------------------------------------------
	u16 *out16 = (u16*)out;
//	int ret;

	if(numsectors==1) {
		return sdmmc_sdcard_readsector(sector_no, out);
	}

	if(!sdmmc_sdhc)
		sector_no *= 512;

	sdmmc_mask16(0x100, 2, 0);
	sdmmc_write16(0xd8, 0);

	sdmmc_write16(REG_SDSTOP, 0x100);
	sdmmc_write16(REG_SDBLKCOUNT, numsectors);
	sdmmc_mask16(REG_SDCLKCTL, 0, 0x100);
	sdmmc_write16(REG_SDBLKLEN, 0x200);	
	
	set_irqhandler(1, out16, numsectors);

	// CMD18 - read multiple blocks
	sdmmc_send_command(18, sector_no & 0xffff, (sector_no >> 16));
	if(sdmmc_timeout) {
		sdmmc_mask16(REG_SDCLKCTL, 0x100, 0);
		fifoSendValue32(FIFO_SDMMC, 1);
	}
}
Пример #6
0
//---------------------------------------------------------------------------------
void sdmmc_sdcard_writesectors(u32 sector_no, u32 numsectors, void *in) {
//---------------------------------------------------------------------------------
	u16 *in16 = (u16*)in;

	if(numsectors==1) {
		return sdmmc_sdcard_writesector(sector_no, in);
	}

	if(!sdmmc_sdhc)
		sector_no *= 512;

	sdmmc_mask16(0x100, 2, 0);
	sdmmc_write16(0xd8, 0);

	sdmmc_write16(REG_SDSTOP, 0x100);
	sdmmc_write16(REG_SDBLKCOUNT, numsectors);
	sdmmc_mask16(REG_SDCLKCTL, 0, 0x100);
	sdmmc_write16(REG_SDBLKLEN, 0x200);	
	
	set_irqhandler(2, in16, numsectors);

	// CMD25 - write multiple blocks
	sdmmc_send_command(25, sector_no & 0xffff, (sector_no >> 16));
	if(sdmmc_timeout) {
		sdmmc_mask16(REG_SDCLKCTL, 0x100, 0);
		fifoSendValue32(FIFO_SDMMC, 1);
	}
}
Пример #7
0
int twlwifi_init()
{
	int retval = 0;

	SendFIFOString("work. now.");
	//wifisdio_initirq();
	//wifisdio_controller_init();
	SendFIFOString("cmds init.....");
	retval = wifisdio_ath_init();
	SendFIFOString("alive");
	#ifndef NOIPC
	twlwifi_arm9ready = 0;
	#ifdef USELIBNDS
	fifoSetAddressHandler(TWLWIFI_FIFOCHAN, wifisdiohandler, 0);
	#else
	mininds_setfifochanhandler(TWLWIFI_FIFOCHAN, mini_wifisdiohandler);
	#endif

	if(retval)return retval;
	while(!twlwifi_arm9ready)
	{
		#ifdef USELIBNDS
		fifoSendValue32(TWLWIFI_FIFOCHAN,0x594452);
		#else
		mininds_sendfifodata(TWLWIFI_FIFOCHAN,0x594452);//"RDY"
		#endif
		swiWaitForVBlank();
	}

	#endif
	return retval;
}
Пример #8
0
void CGbaLoader::BootGBA(void)
{
  sysSetBusOwners(BUS_OWNER_ARM7,BUS_OWNER_ARM7);
  if(PersonalData->gbaScreen)
    REG_POWERCNT=1;
  else
    REG_POWERCNT=(POWER_SWAP_LCDS|1)&0xffff;
  fifoSendValue32(FIFO_USER_01,MENU_MSG_GBA);
}
Пример #9
0
//---------------------------------------------------------------------------------
bool sdio_IsInserted() {
//---------------------------------------------------------------------------------
	if (!REG_DSIMODE) return false;

	fifoSendValue32(FIFO_SDMMC,SDMMC_SD_IS_INSERTED);
	while(!fifoCheckValue32(FIFO_SDMMC));
	int result = fifoGetValue32(FIFO_SDMMC);
	return result == 1;
}
Пример #10
0
void CommandNotifyStop(void)
{
	/*
    NTXMFifoMessage command;
    command.commandType = NOTIFY_STOP;

    fifoSendDatamsg(FIFO_NTXM, sizeof(command), (u8*)&command);
	*/
	fifoSendValue32(FIFO_NTXM, NOTIFY_STOP << 16);
}
Пример #11
0
void CommandSampleFinish(void)
{
	/*
    NTXMFifoMessage command;
    command.commandType = SAMPLE_FINISH;

    fifoSendDatamsg(FIFO_NTXM, sizeof(command), (u8*)&command);
	*/
	fifoSendValue32(FIFO_NTXM, SAMPLE_FINISH << 16);
}
Пример #12
0
//---------------------------------------------------------------------------------
bool sdio_IsInserted() {
//---------------------------------------------------------------------------------
	fifoSendValue32(FIFO_SDMMC,SDMMC_SD_IS_INSERTED);

	fifoWaitValue32(FIFO_SDMMC);

	int result = fifoGetValue32(FIFO_SDMMC);

	return result == 1;
}
Пример #13
0
void CommandUpdateRow(u16 row)
{
	/*
    NTXMFifoMessage command;
    command.commandType = UPDATE_ROW;

    UpdateRowCommand *c = &command.updateRow;
    c->row = row;

    fifoSendDatamsg(FIFO_NTXM, sizeof(command), (u8*)&command);
	*/
	fifoSendValue32(FIFO_NTXM, (UPDATE_ROW << 16) | row);
}
Пример #14
0
void CommandUpdatePotPos(u16 potpos)
{
	/*
    NTXMFifoMessage command;
    command.commandType = UPDATE_POTPOS;

    UpdatePotPosCommand *c = &command.updatePotPos;
    c->potpos = potpos;

    fifoSendDatamsg(FIFO_NTXM, sizeof(command), (u8*)&command);
	*/
	fifoSendValue32(FIFO_NTXM, (UPDATE_POTPOS << 16) | potpos);
}
Пример #15
0
//---------------------------------------------------------------------------------
// Reset the DS registers to sensible defaults
//---------------------------------------------------------------------------------
void __attribute__((weak)) initSystem(void) {
//---------------------------------------------------------------------------------
	register int i;
	// stop timers and dma
	for (i=0; i<4; i++) 
	{
		DMA_CR(i) = 0;
		DMA_SRC(i) = 0;
		DMA_DEST(i) = 0;
		TIMER_CR(i) = 0;
		TIMER_DATA(i) = 0;
	}


	// clear video display registers
	dmaFillWords(0, (void*)0x04000000, 0x56);
	dmaFillWords(0, (void*)0x04001008, 0x56);

	videoSetModeSub(0);

	vramDefault();

	VRAM_E_CR = 0;
	VRAM_F_CR = 0;
	VRAM_G_CR = 0;
	VRAM_H_CR = 0;
	VRAM_I_CR = 0;

	irqInit();
	fifoInit();

	fifoSetValue32Handler(FIFO_PM, powerValueHandler, 0);
	fifoSetDatamsgHandler(FIFO_SYSTEM, systemMsgHandler, 0);

	if(REG_DSIMODE) {
		fifoSendValue32(FIFO_PM,PM_DSI_HACK);
		__dsimode = true;
	}
	__transferRegion()->buttons = 0xffff;

	punixTime = (time_t*)memUncached((void *)&__transferRegion()->unixTime);

	__syscalls.exit = __libnds_exit;
	extern  char *fake_heap_end;
	__transferRegion()->bootcode = (struct __bootstub *)fake_heap_end;
	irqEnable(IRQ_VBLANK);

}
Пример #16
0
int main(int argc, char* argv[])
{
    REG_POWERCNT = POWER_ALL & ~(POWER_MATRIX | POWER_3D_CORE); // don't need 3D
    consoleDebugInit(DebugDevice_CONSOLE);

    defaultExceptionHandler();

    time(&rawTime);
    lastRawTime = rawTime;
    timerStart(0, ClockDivider_1024, TIMER_FREQ_1024(1), clockUpdater);

    /* Reset the EZ3in1 if present */
    if (!__dsimode) {
        sysSetCartOwner(BUS_OWNER_ARM9);

        GBA_BUS[0x0000] = 0xF0;
        GBA_BUS[0x1000] = 0xF0;
    }

    fifoSetValue32Handler(FIFO_USER_02, fifoValue32Handler, NULL);

    sharedData = (SharedData*)memUncached(malloc(sizeof(SharedData)));
    sharedData->scalingOn = false;
    // It might make more sense to use "fifoSendAddress" here.
    // However there may have been something wrong with it in dsi mode.
    fifoSendValue32(FIFO_USER_03, ((u32)sharedData)&0x00ffffff);

    consoleOn = true;
    initConsole();
    initInput();
    readConfigFile();

    if (argc >= 2) {
        char* filename = argv[1];
        loadProgram(filename);
        initializeGameboyFirstTime();
    }
    else {
        selectRom();
    }
    consoleOn = false;
    updateScreens();

    runEmul();

    return 0;
}
Пример #17
0
void fifo_DataHandler(int bytes, void *user_data) {
//---------------------------------------------------------------------------------
	fifo_msg msg;

	fifoGetDatamsg(FIFO_9to7, bytes, (u8*)&msg);
	switch(msg.type) {
		case kInit:
		{
	//				*(unsigned int *)malloc = compute_jump((unsigned int)malloc, (unsigned int)new_malloc);
	#if 1
			quake_ipc_9to7_buf = msg.buf_9to7;
			quake_ipc_7to9_buf = msg.buf_7to9;
			fifoSendValue32(FIFO_9to7,1);
	#else
			quake_ipc_9to7->message = 0;
				
			while (quake_ipc_9to7->message == 0);
				
			quake_ipc_9to7_buf = (unsigned char *)quake_ipc_9to7->message;
				
			quake_ipc_9to7->message = 0xffffffff;
				
			while (quake_ipc_9to7->message == 0xffffffff);
				
			quake_ipc_7to9_buf = (unsigned char *)quake_ipc_9to7->message;
				
			ARM7_PRINT("done\n");
	//				ARM7_PRINTF("7: 9->7 %08x 7->9 %08x\n", quake_ipc_9to7_buf, quake_ipc_7to9_buf);

			quake_ipc_9to7->message = 0xffffffff;
	#endif
			arm7_initialised = 1;
			break;
				
		}
		default:
			handle_ipc(msg.type);
			break;
	}
}
Пример #18
0
//---------------------------------------------------------------------------------
void sdmmc_sdcard_readsector(u32 sector_no, void *out) {
//---------------------------------------------------------------------------------
	u16 *out16 = (u16*)out;
//	int ret;

	if(!sdmmc_sdhc)
		sector_no *= 512;

	sdmmc_mask16(0x100, 2, 0);
	sdmmc_write16(0xd8, 0);

	sdmmc_mask16(REG_SDCLKCTL, 0, 0x100);
	sdmmc_write16(REG_SDBLKLEN, 0x200);
	
	set_irqhandler(1, out16, 1);

	// CMD17 - read single block
	sdmmc_send_command(17, sector_no & 0xffff, (sector_no >> 16));
	if(sdmmc_timeout) {
		sdmmc_mask16(REG_SDCLKCTL, 0x100, 0);
		fifoSendValue32(FIFO_SDMMC, 1);
	}
}
Пример #19
0
static void RecvCommandStopRecording()
{
    int ret = tob_StopRecording();
    fifoSendValue32(FIFO_NTXM, (u32)ret);
    ntxm_recording = false;
}
Пример #20
0
void soundResume(int soundId){
	fifoSendValue32(FIFO_SOUND, SOUND_RESUME | (soundId << 16));
}
Пример #21
0
void soundKill(int soundId){
	fifoSendValue32(FIFO_SOUND, SOUND_KILL | (soundId << 16));
}
Пример #22
0
//---------------------------------------------------------------------------------
int loadNDS(int socket, u32 remote) {
//---------------------------------------------------------------------------------
	int len;
	
	int i=0;
	ioctl(socket,FIONBIO,&i);

	len = recvall(socket,__NDSHeader,512,0);
	
	if (len != 512) {
		kprintf("Error reading header.\n");
		return 1;
	}

	int arm7dest = __NDSHeader->arm7destination;
	int arm7size = __NDSHeader->arm7binarySize;

	int arm9dest = __NDSHeader->arm9destination;
	int arm9size = __NDSHeader->arm9binarySize;
	
	volatile int response = 0;
	
	if (arm9dest + arm9size > (int)_start) response = 1;
	if (arm7dest >= 0x02000000 && arm7dest < 0x03000000 && arm7dest + arm7size > (int)_start) response = 2;

	send(socket,(int *)&response,sizeof(response),0);
	
	if(response) return 1;

	kprintf("Reading arm7 binary: ");
	if (progressRead(socket,(char *)memUncached((void*)0x02000000),arm7size)) {
		kprintf("\nReceive error.\n");
		return 1;
	}
	
	fifoSendValue32(FIFO_USER_01,1);

	while(!fifoCheckValue32(FIFO_USER_01)) {
		swiIntrWait(1,IRQ_FIFO_NOT_EMPTY);
	}
	fifoGetValue32(FIFO_USER_01);

	kprintf("Reading arm9 binary: ");
	if(progressRead(socket,(char *)arm9dest,arm9size)) {
		kprintf("\nReceive error.\n");
		return 1;
	}

	volatile int cmdlen=0;
	char *cmdline;
	if (arm9size != 0){
		cmdline = (char*)(arm9dest+arm9size);
	} else {
		cmdline = (char*)(arm7dest+arm7size);
	}
	len = recvall(socket,(char*)&cmdlen,4,0);

	if (cmdlen) {
		len = recvall(socket,cmdline,cmdlen,0);

		__system_argv->argvMagic = ARGV_MAGIC;
		__system_argv->commandLine = cmdline;
		__system_argv->length = cmdlen;
		__system_argv->host = remote;
	}

	Wifi_DisableWifi();

	DC_FlushAll();
	REG_IPC_SYNC = 0;

	fifoSendValue32(FIFO_USER_01,2);
	fifoSendValue32(FIFO_USER_01,__NDSHeader->arm9executeAddress);

	irqDisable(IRQ_ALL);
	REG_IME = 0;

	//clear out ARM9 DMA channels
	for (i=0; i<4; i++) {
		DMA_CR(i) = 0;
		DMA_SRC(i) = 0;
		DMA_DEST(i) = 0;
		TIMER_CR(i) = 0;
		TIMER_DATA(i) = 0;
	}

	u16 *mainregs = (u16*)0x04000000;
	u16 *subregs = (u16*)0x04001000;

	for (i=0; i<43; i++) {
		mainregs[i] = 0;
		subregs[i] = 0;
	}

	REG_DISPSTAT = 0;

	dmaFillWords(0, BG_PALETTE, (2*1024));
	VRAM_A_CR = 0x80;
	dmaFillWords(0, VRAM, 128*1024);
	VRAM_A_CR = 0;
	VRAM_B_CR = 0;
// Don't mess with the ARM7's VRAM
//	VRAM_C_CR = 0;
	VRAM_D_CR = 0;
	VRAM_E_CR = 0;
	VRAM_F_CR = 0;
	VRAM_G_CR = 0;
	VRAM_H_CR = 0;
	VRAM_I_CR = 0;
	REG_POWERCNT  = 0x820F;

	//set shared ram to ARM7
	WRAM_CR = 0x03;
	// Return to passme loop
	*((vu32*)0x02FFFE04) = (u32)0xE59FF018;		// ldr pc, 0x02FFFE24
	*((vu32*)0x02FFFE24) = (u32)0x02FFFE04;		// Set ARM9 Loop address

	REG_IPC_SYNC = 0x500;

	arm9Reset();
	while(1);
}
Пример #23
0
int main(void)
{
	int i;
	
	defaultExceptionHandler();
	
	irqEnable(IRQ_VBLANK);
	irqEnable(IRQ_HBLANK);
	
	irqSet(IRQ_VBLANK, vblank_idle);
	
	fifoSetValue32Handler(FIFO_USER_02, arm7print, NULL);
	fifoSetValue32Handler(FIFO_USER_03, sleepMode, NULL);
	
	//vramSetBankA(VRAM_A_LCD);
	videoSetMode(MODE_0_2D);

	// map some VRAM
	// bank C to ARM7, bank H for subscreen graphics
	*(vu8*)0x04000242 = 0x82;
	*(vu8*)0x04000248 = 0x81;
	
	videoSetModeSub(MODE_0_2D);
	consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 2, 0, false, true);
	
	*(vu16*)0x0400100A = 0x0300;
	
	setBackdropColorSub(0x7C00);
	
	// configure BLDCNT so that backdrop becomes black
	*(vu16*)0x04001050 = 0x00E0;
	*(vu8*)0x04001054 = 16;
	
	// enable window 0 and disable color effects inside it
	*(vu16*)0x04001000 |= 0x2000;
	*(vu16*)0x04001048 = 0x001F;
	*(vu16*)0x0400104A = 0x003F;
	
	toggleConsole(false);
	
#ifdef NITROFS_ROM
	if (!nitroFSInit())
#else
	if (!fatInitDefault())
#endif
	{
		toggleConsole(true);
		iprintf("FAT init failed\n");
		return -1;
	}
	
	makeROMList();
	
	makeMenu();

	iprintf("lolSnes " VERSION " -- by Mega-Mario\n");
	
	for (;;)
	{
		if (keypress != 0x03FF)
		{
			if (!(keypress & 0x0040)) // up
			{
				menusel--;
				if (menusel < 0) menusel = 0;
				if (menusel < menuscroll) menuscroll = menusel;
				makeMenu();
			}
			else if (!(keypress & 0x0080)) // down
			{
				menusel++;
				if (menusel > nfiles-1) menusel = nfiles-1;
				if (menusel-21 > menuscroll) menuscroll = menusel-21;
				makeMenu();
			}
			else if ((keypress & 0x0003) != 0x0003) // A/B
			{
				strncpy(fullpath, "snes/", 5);
				strncpy(fullpath + 5, &filelist[menusel << 8], 256);
				
				if (!Mem_LoadROM(fullpath))
				{
					iprintf("ROM loading failed\n");
					continue;
				}
				
				*(vu16*)0x04001000 &= 0xDFFF;
				toggleConsole(true);
				iprintf("ROM loaded, running\n");

				CPU_Reset();
				fifoSendValue32(FIFO_USER_01, 1);
				
				swiWaitForVBlank();
				fifoSendValue32(FIFO_USER_01, 2);
				
				irqSet(IRQ_VBLANK, vblank);
				irqSet(IRQ_HBLANK, PPU_HBlank);

				swiWaitForVBlank();
				CPU_Run();
			}
			
			keypress = 0x03FF;
		}
		
		swiWaitForVBlank();
	}

	return 0;
}
Пример #24
0
void soundEnableFunc(int value) {
    soundDisabled = !value;
    sharedData->fifosSent++;
    fifoSendValue32(FIFO_USER_01, GBSND_MUTE_COMMAND<<20);
}
Пример #25
0
void hyperSoundFunc(int value) {
    hyperSound = value;
    sharedData->hyperSound = value;
    sharedData->fifosSent++;
    fifoSendValue32(FIFO_USER_01, GBSND_HYPERSOUND_ENABLE_COMMAND<<20 | hyperSound);
}
Пример #26
0
void enableSleepMode() {
    if (!sharedData->enableSleepMode) {
        sharedData->enableSleepMode = true;
        fifoSendValue32(FIFO_PM, PM_REQ_SLEEP_ENABLE);
    }
}
Пример #27
0
void disableSleepMode() {
    if (sharedData->enableSleepMode) {
        sharedData->enableSleepMode = false;
        fifoSendValue32(FIFO_PM, PM_REQ_SLEEP_DISABLE);
    }
}
Пример #28
0
int main(int _argc, char **_argv) {
    int framecount=0;
    int sramcount=0;

    argc=_argc, argv=_argv;
    defaultExceptionHandler();

    fifoSendValue32(FIFO_USER_06, (u32)ipc_region);

    DS_init(); //DS init.
#ifndef ROM_EMBEDED
    active_interface = fatInitDefault(); //init file operations to your external card.

    initNiFi();
#endif
    EMU_Init(); //emulation init.

    irqSet(IRQ_VBLANK, vblankinterrupt);
    irqEnable(IRQ_HBLANK);
    //fifoSetValue32Handler(FIFO_USER_06, aliveinterrupt, 0);
    //fifoSetValue32Handler(FIFO_USER_05, reg4015interrupt, 0);

    IPC_ALIVE = 0;
    IPC_APUIRQ = 0;
    IPC_REG4015 = 0;

    consoleinit(); //init subscreen to show chars.
    crcinit();	//init the crc table.

    //pre-alocate memory....
    //IPC_FILES = malloc(MAXFILES * 256 + MAXFILES * 4);
    //IPC_ROM = malloc(ROM_MAX_SIZE);

#ifndef ROM_EMBEDED
    if(!bootext()) {
        //chdir("/");
        do_rommenu(); //show a menu selecting rom files.
    }
#else
    do_romebd();
#endif

    //__emuflags |= PALSYNC;

    while(1) { // main loop to do the emulation
        framecount++;
        if(__emuflags & PALTIMING && global_playcount == 0) {
            framecount--;
        }
        if(debuginfo[VBLS]>59) {
            debuginfo[VBLS]-=60;
            debuginfo[1] = debuginfo[0];
            debuginfo[0] = 0;
            debuginfo[FPS]=framecount;
            framecount=0;
        }

        scanKeys();
        IPC_KEYS = keysCurrent();

        //change nsf states
        if(__emuflags & NSFFILE) {
            static int oldkey = 0;
            int keydown = IPC_KEYS & (~oldkey);
            oldkey = IPC_KEYS;

            if(keydown & KEY_LEFT) {
                if(__nsfsongno == 0) {
                    __nsfsongno = nsfheader.TotalSong-1;
                } else {
                    __nsfsongno--;
                }
            }
            if(keydown & KEY_RIGHT) {
                if(++__nsfsongno > nsfheader.TotalSong-1) {
                    __nsfsongno = 0;
                }
            }
            if(keydown & KEY_UP) {
                __nsfplay = 1;
                __nsfinit = 1;
            }
            if(keydown & KEY_DOWN) {
                __nsfplay = 0;
                Sound_reset();
            }
        }

        do_shortcuts();
        if((__emuflags & AUTOSRAM)) {
            if(__emuflags & NEEDSRAM) {
                sramcount = 1;
                __emuflags&=~NEEDSRAM;
            }
            if(sramcount > 0)
                sramcount++;
            if(sramcount > 120) {		//need auto save for sram.
                sramcount = 0;
                save_sram();
            }
        }

        touch_update(); // do menu functions.
        do_menu();	//do control menu.

        do_multi();
        if(nifi_stat == 0 || nifi_stat >= 5)
            play(); //emulate a frame of the NES game.
        else
            swiWaitForVBlank();
    }
}
Пример #29
0
static void twlescrypthandler(void * address, void * userdata)
{
	escryptipc_cmd *cmd = (escryptipc_cmd*)address;
	u32 *args = cmd->args;
	switch(cmd->cmdtype)
	{
		case 0xFF:
			twlescrypt_arm9ready = 1;
			#ifdef USELIBNDS
			fifoSendValue32(TWLESCRYPT_FIFOCHAN,0x594452);
			#endif
		break;

		case CMD_dsi_set_key:
			dsi_set_key((dsictx*)args[0], (u8*)args[1], (u8*)args[2], (u8*)args[3]);
		break;

		case CMD_dsi_add_ctr:
			dsi_add_ctr((dsictx*)args[0], (u8)args[1]);
		break;

		case CMD_dsi_set_ctr:
			dsi_set_ctr((dsictx*)args[0], (u8*)args[1]);
		break;

		case CMD_dsi_init_ctr:
			dsi_init_ctr((dsictx*)args[0], (u8*)args[1], (u8*)args[2], (u8*)args[2], (u8*)args[3]);
		break;

		case CMD_dsi_crypt_ctr_block:
			dsi_crypt_ctr_block((dsictx*)args[0], (u8*)args[1], (u8*)args[2]);
		break;

		case CMD_dsi_init_ccm:
			dsi_init_ccm((dsictx*)args[0], (u8*)args[1], (u8*)args[2], (u8*)args[3], (u32)args[4], (u32)args[5], (u32)args[6], (u8*)args[7]);
		break;

		#ifdef AESENC
		case CMD_dsi_encrypt_ccm_block:
			dsi_encrypt_ccm_block((dsictx*)args[0], (u8*)args[1], (u8*)args[2], (u8*)args[3]);
		break;
		#endif

		case CMD_dsi_decrypt_ccm_block:
			cmd->retval = dsi_decrypt_ccm_block((dsictx*)args[0], (u8*)args[1], (u8*)args[2], (u8*)args[3]);
		break;

		case CMD_dsi_decrypt_ccm:
			cmd->retval = dsi_decrypt_ccm((dsictx*)args[0], (u8*)args[1], (u8*)args[2], (u32)args[3], (u8*)args[4]);
		break;

		#ifdef AESENC
		case CMD_dsi_encrypt_ccm:
			dsi_encrypt_ccm((dsictx*)args[0], (u8*)args[1], (u8*)args[2], (u32)args[3], (u8*)args[4]);
		break;
		#endif

		case CMD_dsi_es_init:
			dsi_es_init((dsi_es_context*)args[0], (u8*)args[1], (u8*)args[2], (u8*)args[3]);
		break;

		case CMD_dsi_es_set_nonce:
			dsi_es_set_nonce((dsi_es_context*)args[0], (u8*)args[1]);
		break;

		case CMD_dsi_es_set_random_nonce:
			dsi_es_set_random_nonce((dsi_es_context*)args[0]);
		break;

		case CMD_dsi_es_decrypt:
			cmd->retval = dsi_es_decrypt((dsi_es_context*)args[0], (u8*)args[1], (u8*)args[2], (u32)args[3]);
		break;

		#ifdef AESENC
		case CMD_dsi_es_encrypt:
			dsi_es_encrypt((dsi_es_context*)args[0], (u8*)args[1], (u8*)args[2], (u32)args[3]);
		break;
		#endif
	}
	
	cmd->busy = 0;
}
Пример #30
0
extern "C" void handle_ipc(u32 type)
{
//	if (arm7_initialised)
//	{
//		keepalive++;
//		if (keepalive > 96)
//		{
//			ARM7_PRINT("keepalive\n");
//			keepalive = 0;
//		}
//	}
	
	
	//if (quake_ipc_9to7->message == 0xffffffff)
	//{
//		ARM7_PRINTF("message type %d\n", quake_ipc_9to7->message_type);
		
		switch (type)
		{
			case kPrintMessage:
			{
				ARM7_PRINTF((char *)quake_ipc_9to7_buf);
				break;
			}
			case kStopAllSounds:
			{
				ARM7_PRINT("ARM7: Stopping sounds...");
				stopAllSounds();
				ARM7_PRINT("...done\n");
				
				break;
			}
			case kPlayMP3:
			{
				ARM7_PRINT("arm7 mp3 start msg\ntrack: ");
				memcpy((void *)track_name, (void *)quake_ipc_9to7_buf, 100);
				ARM7_PRINT((char *)track_name);
				ARM7_PRINT("\n");
				do_mp3 = 1;
				
				break;
			}
			case kStopMP3:
			{
				ARM7_PRINT("arm7 mp3 stop msg\n");
				do_mp3 = 0;
				
//				if (decoder_stopped)
//					send_mp3_stop_message();
				
				break;
			}
			
			//sound subsystem
			case kS_Init:
			{
				S_Init7(((unsigned int *)quake_ipc_9to7_buf)[0], ((unsigned int *)quake_ipc_9to7_buf)[1]);
				break;
			}
			case kS_AmbientOff:
			{
				S_AmbientOff7();
				break;
			}
			case kS_AmbientOn:
			{
				S_AmbientOn7();
				break;
			}
			case kS_Shutdown:
			{
				S_Shutdown7();
				break;
			}
			case kS_TouchSound:
			{
				S_TouchSound7((char *)quake_ipc_9to7_buf);
				break;
			}
			case kS_ClearBuffer:
			{
				S_ClearBuffer7();
				break;
			}
			case kS_StaticSound:
			{
				float *floats = (float *)quake_ipc_9to7_buf;
				S_StaticSound7((void *)*(unsigned int *)quake_ipc_9to7_buf,
					&floats[1],
					floats[4],
					floats[5]);
				break;
			}
			case kS_StartSound:
			{
				float *floats = (float *)quake_ipc_9to7_buf;
				S_StartSound7(((unsigned int *)quake_ipc_9to7_buf)[0], ((unsigned int *)quake_ipc_9to7_buf)[1],
					(void *)((unsigned int *)quake_ipc_9to7_buf)[2],
					&floats[3], //floats[6], floats[7],
					((unsigned int *)quake_ipc_9to7_buf)[8], ((unsigned int *)quake_ipc_9to7_buf)[9]);
				break;
			}
			case kS_StopSound:
			{
				S_StopSound7(((unsigned int *)quake_ipc_9to7_buf)[0], ((unsigned int *)quake_ipc_9to7_buf)[1]);
				break;
			}
			case kS_StopAllSounds:
			{
				S_StopAllSounds7(((unsigned int *)quake_ipc_9to7_buf)[0]);
				break;
			}
			case kS_ClearPrecache:
			{
				S_ClearPrecache7();
				break;
			}
			case kS_BeginPrecaching:
			{
				S_BeginPrecaching7();
				break;
			}
			case kS_EndPrecaching:
			{
				S_EndPrecaching7();
				break;
			}
			case kS_PrecacheSound:
			{
				void *pc = S_PrecacheSound7((char *)quake_ipc_9to7_buf);
				*(unsigned int *)quake_ipc_7to9_buf = (unsigned int)pc;
				break;
			}
			case kS_Update:
			{
//				float *floats = (float *)quake_ipc_9to7_buf;
//				S_Update7(&floats[0], &floats[3], &floats[6], &floats[9]);
				S_UpdateStatics((void *)((unsigned int *)quake_ipc_9to7_buf)[12], ((unsigned int *)quake_ipc_9to7_buf)[13]);
				break;
			}
			case kS_ExtraUpdate:
			{
				S_ExtraUpdate7();
				break;
			}
			case kS_LocalSound:
			{
				S_LocalSound7((char *)quake_ipc_9to7_buf);
				break;
			}
			case kFreeTime:
			case kRunningOut:
			case kGetReady:
			{
				//free_time = quake_ipc_9to7->message_type;
//				ARM7_PRINTF("free time is %d\n", quake_ipc_9to7->message_type);
				break;
			}
			case kStartWifi:
			{
#ifdef WIFI_ON_DEMAND
//				ARM7_PRINT("ARM7 Initialising wifi...\n");
				wifi_go();
//				ARM7_PRINTF("ARM7 ...done\n");
#else
				ARM7_PRINT("Wifi has already been initialised\n");
#endif
				break;
			}
			case kDMATransfer:
			{
				unsigned int source = ((unsigned int *)quake_ipc_9to7_buf)[0];
				unsigned int size = ((unsigned int *)quake_ipc_9to7_buf)[1];
				unsigned int dest = ((unsigned int *)quake_ipc_9to7_buf)[2];
				
				while(DMA_CR(dma_channel & 0x3) & DMA_BUSY);

				DMA_SRC(dma_channel & 0x3) = source;
				DMA_DEST(dma_channel & 0x3) = dest;
				DMA_CR(dma_channel & 0x3) = (DMA_ENABLE | DMA_32_BIT  | DMA_DST_FIX | DMA_START_NOW) | size;
				
				while(DMA_CR(dma_channel & 0x3) & DMA_BUSY);
//				ARM7_PRINT("from ");
//				ARM7_PRINT_NUMBER(source);
//				ARM7_PRINT("to ");
//				ARM7_PRINT_NUMBER(dest);
//				ARM7_PRINT("size ");
//				ARM7_PRINT_NUMBER(size);
				
				dma_channel++;
				break;
			}
			case kPowerOff:
			{
				ARM7_PRINT("ARM7: Powering down...\n");
				SerialWaitBusy();

				REG_SPICNT = SPI_ENABLE | SPI_DEVICE_POWER | SPI_BAUD_1MHz | SPI_CONTINUOUS;
				REG_SPIDATA = 0;

				SerialWaitBusy();

				REG_SPICNT = SPI_ENABLE | SPI_DEVICE_POWER | SPI_BAUD_1MHz;
				REG_SPIDATA = 1 << 6;

				break;
			}
			case kBspRender:
			{
//				ARM7_PRINT("ARM7: BSP Render\n");
				
				setup_bsp_render((void *)((unsigned int *)quake_ipc_9to7_buf)[0],
					(void *)((unsigned int *)quake_ipc_9to7_buf)[1],
					((int *)quake_ipc_9to7_buf)[2],
					((int *)quake_ipc_9to7_buf)[3],
					(unsigned char *)((unsigned int *)quake_ipc_9to7_buf)[4],
					(int **)((unsigned int *)quake_ipc_9to7_buf)[5],
					(int *)((unsigned int *)quake_ipc_9to7_buf)[6],
					(unsigned int *)((unsigned int *)quake_ipc_9to7_buf)[7]);
//				ARM7_PRINT("ARM7: BSP Render done\n");
				break;
			}
			//
			default:
			{
				ARM7_PRINT("some other message, ");
				ARM7_PRINT_NUMBER(type);
				ARM7_PRINT("\n");
				break;
			}
		}
		//quake_ipc_9to7->message = 0;
		fifoSendValue32(FIFO_9to7,0);
	//}

low_mem:

	if (low_memory)
	{
		mark_freeable();
		free_marked();
		
		low_memory = false;
	}
}