Example #1
0
/* Process 1OP Integer instructions */
bool eval_1OP_Int(struct lilith* vm, struct Instruction* c)
{
	#ifdef DEBUG
	char Name[20] = "ILLEGAL_1OP";
	#endif

	switch(c->raw_XOP)
	{
		case 0x00000: /* READPC */
		{
			#ifdef DEBUG
			strncpy(Name, "READPC", 19);
			#elif TRACE
			record_trace("READPC");
			#endif

			READPC(vm, c);
			break;
		}
		case 0x00001: /* READSCID */
		{
			#ifdef DEBUG
			strncpy(Name, "READSCID", 19);
			#elif TRACE
			record_trace("READSCID");
			#endif

			READSCID(vm, c);
			break;
		}
		case 0x00002: /* FALSE */
		{
			#ifdef DEBUG
			strncpy(Name, "FALSE", 19);
			#elif TRACE
			record_trace("FALSE");
			#endif

			FALSE(vm, c);
			break;
		}
		case 0x00003: /* TRUE */
		{
			#ifdef DEBUG
			strncpy(Name, "TRUE", 19);
			#elif TRACE
			record_trace("TRUE");
			#endif

			TRUE(vm, c);
			break;
		}
		case 0x01000: /* JSR_COROUTINE */
		{
			#ifdef DEBUG
			strncpy(Name, "JSR_COROUTINE", 19);
			#elif TRACE
			record_trace("JSR_COROUTINE");
			#endif

			JSR_COROUTINE(vm, c);
			break;
		}
		case 0x01001: /* RET */
		{
			#ifdef DEBUG
			strncpy(Name, "RET", 19);
			#elif TRACE
			record_trace("RET");
			#endif

			RET(vm, c);
			break;
		}
		case 0x02000: /* PUSHPC */
		{
			#ifdef DEBUG
			strncpy(Name, "PUSHPC", 19);
			#elif TRACE
			record_trace("PUSHPC");
			#endif

			PUSHPC(vm, c);
			break;
		}
		case 0x02001: /* POPPC */
		{
			#ifdef DEBUG
			strncpy(Name, "POPPC", 19);
			#elif TRACE
			record_trace("POPPC");
			#endif

			POPPC(vm, c);
			break;
		}
		default:
		{
			illegal_instruction(vm, c);
			break;
		}
	}
	#ifdef DEBUG
	fprintf(stdout, "# %s reg%u\n", Name, c->reg0);
	#endif
	return false;
}
Example #2
0
int execute(int ncycles)
{

//    FILE *fp;

//    fp = fopen("log.txt","a");

    int Counter = ncycles;
    gbcpu.forcequit=0;

    //emulation loop
    for (;;)
    {
        //variaveis temporarias para operacoes(não existe no processador)
        reg16bit opAux;
        uint16 address;
        uint8 tempbyte;
        int8 signedtempbyte;
        reg32bit opAux32;
        uint32_t temp32;
        uint8 OpCode;
        int usedcycles=0;

#ifdef DEBUG
        printStatusZ80();
        printf("Counter: %u \n",Counter);
        printf("**************************\n");
        printMEMStatus(gbcpu.mem);
        /*misc*/
        printf("lcd cyclecounter: %d\n",gbcpu.lcd->scanlinecyclecounter);
        printf("**************************\n");
#endif
    if(IE & IF){
       gbcpu.halt=0;
       /*interupts*/
       if (IME){

           //v-sync
           if (IE & IF & 0x1){
               IME=0;
               IF&= ~(0x1);
               PUSHPC();
               PC=0x40;

           }else
           //LCD STAT
           if (IE & IF & 0x2){
               IME=0;
               IF&= ~(0x2);
               PUSHPC();
               PC=0x48;

           }else
           //Timer
           if (IE & IF & 0x4){
               IME=0;
               IF&= ~(0x4);
               PUSHPC();
               PC=0x50;

           }else
           //Serial
           if (IE & IF & 0x8){
                IME=0;
                IF&= ~(0x8);
                PUSHPC();
                PC=0x58;

           }else
           //Joypad
           if (IE & IF & 0x10){
                IME=0;
                IF&= ~(0x10);
                PUSHPC();
                PC=0x60;
            }
        }
       }

       if (SET_IME){
        IME=1;
        SET_IME=0;
       }


       if(!gbcpu.halt){

        OpCode = readMem(PC, gbcpu.mem);
        PC++;
        usedcycles += Cycles[OpCode];

#ifdef DEBUG
	printf("opcode:%02x ",OpCode);
	CyclesCount[OpCode]++;
#endif

	switch (OpCode)
    {

        #include "Opcodes.h"

        default:
            printf("error undefined opcode");
            exit(-1);
            break;
        }
    }else
        //halt
        usedcycles=4;

#ifdef DEBUG
        /*printf("Press <ENTER> to Continue\n\n");
        for(;;){
            char c=getchar();
	    if (c == '\n')
		break;
        }*/
#endif

        //update timers,lcd status and cyclecount
        Counter-=usedcycles;
        gbcpu.cyclecounter += usedcycles;

        updatetimers(usedcycles);
        updateLCDStatus(usedcycles);




    if (Counter <= 0)
	{
            return 0;
	}

    if (gbcpu.forcequit == 1)
    {
        return 0;
    }

    }
    return 0;
}