Ejemplo n.º 1
0
static int m6502_execute(int cycles)
{
	m6502_ICount = cycles;

	change_pc(PCD);

	do
	{
		UINT8 op;
		PPC = PCD;

		CALL_MAME_DEBUG;

#if 1
		/* if an irq is pending, take it now */
		if( m6502.pending_irq )
			m6502_take_irq();

		op = RDOP();
		(*m6502.insn[op])();
#else
		/* thought as irq request while executing sei */
        /* sei sets I flag on the stack*/
		op = RDOP();

		/* if an irq is pending, take it now */
		if( m6502.pending_irq && (op == 0x78) )
			m6502_take_irq();

		(*m6502.insn[op])();
#endif

		/* check if the I flag was just reset (interrupts enabled) */
		if( m6502.after_cli )
		{
			LOG(("M6502#%d after_cli was >0", cpu_getactivecpu()));
			m6502.after_cli = 0;
			if (m6502.irq_state != CLEAR_LINE)
			{
				LOG((": irq line is asserted: set pending IRQ\n"));
				m6502.pending_irq = 1;
			}
			else
			{
				LOG((": irq line is clear\n"));
			}
		}
		else
		if( m6502.pending_irq )
			m6502_take_irq();

	} while (m6502_ICount > 0);

	return cycles - m6502_ICount;
}
Ejemplo n.º 2
0
Archivo: m6502.c Proyecto: bji/libmame
static CPU_EXECUTE( m6502 )
{
	m6502_Regs *cpustate = get_safe_token(device);

	do
	{
		UINT8 op;
		PPC = PCD;

		debugger_instruction_hook(device, PCD);

		/* if an irq is pending, take it now */
		if( cpustate->pending_irq )
			m6502_take_irq(cpustate);

		op = RDOP();
		(*cpustate->insn[op])(cpustate);

		/* check if the I flag was just reset (interrupts enabled) */
		if( cpustate->after_cli )
		{
			LOG(("M6502 '%s' after_cli was >0", cpustate->device->tag()));
			cpustate->after_cli = 0;
			if (cpustate->irq_state != CLEAR_LINE)
			{
				LOG((": irq line is asserted: set pending IRQ\n"));
				cpustate->pending_irq = 1;
			}
			else
			{
				LOG((": irq line is clear\n"));
			}
		}
		else {
			if ( cpustate->pending_irq == 2 ) {
				if ( cpustate->int_occured - cpustate->icount > 1 ) {
					cpustate->pending_irq = 1;
				}
			}
			if( cpustate->pending_irq == 1 )
				m6502_take_irq(cpustate);
			if ( cpustate->pending_irq == 2 ) {
				cpustate->pending_irq = 1;
			}
		}

	} while (cpustate->icount > 0);
}
Ejemplo n.º 3
0
static CPU_EXECUTE( h6280 )
{
	int in;
	h6280_Regs* cpustate = get_safe_token(device);

	if ( cpustate->irq_pending == 2 ) {
		cpustate->irq_pending--;
	}

	/* Execute instructions */
	do
    {
		cpustate->ppc = cpustate->pc;

		debugger_instruction_hook(device, PCW);

		/* Execute 1 instruction */
		in=RDOP();
		PCW++;
		insnh6280[in](cpustate);

		if ( cpustate->irq_pending ) {
			if ( cpustate->irq_pending == 1 ) {
				if ( !(P & _fI) ) {
					cpustate->irq_pending--;
					CHECK_AND_TAKE_IRQ_LINES;
				}
			} else {
				cpustate->irq_pending--;
			}
		}

		/* Check internal timer */
		if(cpustate->timer_status)
		{
			if(cpustate->timer_value<=0)
			{
				if ( ! cpustate->irq_pending )
					cpustate->irq_pending = 1;
				while( cpustate->timer_value <= 0 )
					cpustate->timer_value += cpustate->timer_load;
				set_irq_line(cpustate, 2,ASSERT_LINE);
			}
		}
	} while (cpustate->ICount > 0);
}
Ejemplo n.º 4
0
void Cm6502::run_one_opecode()
{
    // if an irq is pending, take it now
    if(nmi_state) {
        EAD = NMI_VEC;
        CYCLES(2);
        PUSH(PCH);
        PUSH(PCL);
        PUSH(P & ~F_B);
        P |= F_I;	// set I flag
        PCL = RDMEM(EAD);
        PCH = RDMEM(EAD + 1);
        CallSubLevel++;
        nmi_state = false;
        halt=false;
        AddLog(LOG_CONSOLE,"CPU RUNNING\n");
//        qWarning()<<"CPU RUNNING";
        if (fp_log) fprintf(fp_log,"\n INT NMI newpc:%04x\n",PCW);
    }
    else if(pending_irq) {
        if (halt) Reset();
        else update_irq();
    }
    if (halt) {
        CYCLES(50);
        P &= ~F_I;
        return;
    }

    prev_pc = pc.w.l;
    quint8 code = RDOP();
    OP(code);

    // check if the I flag was just reset (interrupts enabled)
    if(after_cli) {
        after_cli = false;
        if(irq_state) {
            if (fp_log) fprintf(fp_log,"\n INT after_cli irq\n");

            pending_irq = true;
        }
    }
    else if(pending_irq) {
        update_irq();
    }
}
Ejemplo n.º 5
0
static int deco16_execute(int cycles)
{
	m6502_ICount = cycles;

	change_pc(PCD);

	do
	{
		UINT8 op;
		PPC = PCD;

		CALL_MAME_DEBUG;

		op = RDOP();
		(*m6502.insn[op])();

		/* if an irq is pending, take it now */
		if( m6502.pending_irq )
			deco16_take_irq();


		/* check if the I flag was just reset (interrupts enabled) */
		if( m6502.after_cli )
		{
			LOG(("M6502#%d after_cli was >0", cpu_getactivecpu()));
			m6502.after_cli = 0;
			if (m6502.irq_state != CLEAR_LINE)
			{
				LOG((": irq line is asserted: set pending IRQ\n"));
				m6502.pending_irq = 1;
			}
			else
			{
				LOG((": irq line is clear\n"));
			}
		}
		else
		if( m6502.pending_irq )
			deco16_take_irq();

	} while (m6502_ICount > 0);

	return cycles - m6502_ICount;
}
Ejemplo n.º 6
0
static CPU_EXECUTE( m4510 )
{
	m4510_Regs *cpustate = get_safe_token(device);

	cpustate->icount = cycles;

	do
	{
		UINT8 op;
		PPC = PCD;

		debugger_instruction_hook(device, PCD);

		/* if an irq is pending, take it now */
		if( cpustate->pending_irq )
			m4510_take_irq(cpustate);

		op = RDOP();
		(*insn4510[op])(cpustate);

		/* check if the I flag was just reset (interrupts enabled) */
		if( cpustate->after_cli )
		{
			LOG(("M4510 '%s' after_cli was >0", cpustate->device->tag));
			cpustate->after_cli = 0;
			if (cpustate->irq_state != CLEAR_LINE)
			{
				LOG((": irq line is asserted: set pending IRQ\n"));
				cpustate->pending_irq = 1;
			}
			else
			{
				LOG((": irq line is clear\n"));
			}
		}
		else
		if( cpustate->pending_irq )
			m4510_take_irq(cpustate);

	} while (cpustate->icount > 0);

	return cycles - cpustate->icount;
}
Ejemplo n.º 7
0
static int h6280_execute(int cycles)
{
	int in,lastcycle,deltacycle;
	h6280_ICount = cycles;

	/* Subtract cycles used for taking an interrupt */
	h6280_ICount -= h6280.extra_cycles;
	h6280.extra_cycles = 0;
	lastcycle = h6280_ICount;

	/* Execute instructions */
	do
    {
		h6280.ppc = h6280.pc;

#ifdef  MAME_DEBUG
	 	{
			if (mame_debug)
			{
				/* Copy the segmentation registers for debugger to use */
				int i;
				for (i=0; i<8; i++)
					H6280_debug_mmr[i]=h6280.mmr[i];

				MAME_Debug();
			}
		}
#endif

		/* Execute 1 instruction */
		in=RDOP();
		PCW++;
		insnh6280[in]();

		/* Check internal timer */
		if(h6280.timer_status)
		{
			deltacycle = lastcycle - h6280_ICount;
			h6280.timer_value -= deltacycle;
			if(h6280.timer_value<=0 && h6280.timer_ack==1)
			{
				h6280.timer_ack=h6280.timer_status=0;
				set_irq_line(2,ASSERT_LINE);
			}
		}
		lastcycle = h6280_ICount;

		/* If PC has not changed we are stuck in a tight loop, may as well finish */
		if( h6280.pc.d == h6280.ppc.d )
		{
			if (h6280_ICount > 0) h6280_ICount=0;
			h6280.extra_cycles = 0;
			return cycles;
		}

	} while (h6280_ICount > 0);

	/* Subtract cycles used for taking an interrupt */
	h6280_ICount -= h6280.extra_cycles;
	h6280.extra_cycles = 0;

	return cycles - h6280_ICount;
}
Ejemplo n.º 8
0
/*****************************************************************************
 *  Disassemble a single command and return the number of bytes it uses.
 *****************************************************************************/
offs_t h6280_dasm(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram)
{
    UINT32 flags = 0;
    int PC, OP, opc, arg;

    PC = pc;
    OP = RDOP(PC);
    OP = OP << 1;
    PC++;

    opc = op6280[OP];
    arg = op6280[OP+1];

    if (opc == _jsr || opc == _bsr)
        flags = DASMFLAG_STEP_OVER;
    else if (opc == _rts)
        flags = DASMFLAG_STEP_OUT;

    switch(arg)
    {
    case _acc:
        sprintf(buffer,"%-5sa", token[opc]);
        break;
    case _imp:
        sprintf(buffer,"%s", token[opc]);
        break;
    case _rel:
        sprintf(buffer,"%-5s$%04X", token[opc], (PC + 1 + (signed char)RDBYTE(PC)) & 0xffff);
        PC+=1;
        break;
    case _imm:
        sprintf(buffer,"%-5s#$%02X", token[opc], RDBYTE(PC));
        PC+=1;
        break;
    case _zpg:
        sprintf(buffer,"%-5s$%02X", token[opc], RDBYTE(PC));
        PC+=1;
        break;
    case _zpx:
        sprintf(buffer,"%-5s$%02X,x", token[opc], RDBYTE(PC));
        PC+=1;
        break;
    case _zpy:
        sprintf(buffer,"%-5s$%02X,y", token[opc], RDBYTE(PC));
        PC+=1;
        break;
    case _idx:
        sprintf(buffer,"%-5s($%02X,x)", token[opc], RDBYTE(PC));
        PC+=1;
        break;
    case _idy:
        sprintf(buffer,"%-5s($%02X),y", token[opc], RDBYTE(PC));
        PC+=1;
        break;
    case _zpi:
        sprintf(buffer,"%-5s($%02X)", token[opc], RDBYTE(PC));
        PC+=1;
        break;
    case _abs:
        sprintf(buffer,"%-5s$%04X", token[opc], RDWORD(PC));
        PC+=2;
        break;
    case _abx:
        sprintf(buffer,"%-5s$%04X,x", token[opc], RDWORD(PC));
        PC+=2;
        break;
    case _aby:
        sprintf(buffer,"%-5s$%04X,y", token[opc], RDWORD(PC));
        PC+=2;
        break;
    case _ind:
        sprintf(buffer,"%-5s($%04X)", token[opc], RDWORD(PC));
        PC+=2;
        break;
    case _iax:
        sprintf(buffer,"%-5s($%04X),X", token[opc], RDWORD(PC));
        PC+=2;
        break;
    case _blk:
        sprintf(buffer,"%-5s$%04X $%04X $%04X", token[opc], RDWORD(PC), RDWORD(PC+2), RDWORD(PC+4));
        PC+=6;
        break;
    case _zrl:
        sprintf(buffer,"%-5s$%02X $%04X", token[opc], RDBYTE(PC), (PC + 2 + (signed char)RDBYTE(PC+1)) & 0xffff);
        PC+=2;
        break;
    case _imz:
        sprintf(buffer,"%-5s#$%02X $%02X", token[opc], RDBYTE(PC), RDBYTE(PC+1));
        PC+=2;
        break;
    case _izx:
        sprintf(buffer,"%-5s#$%02X $%02X,x", token[opc], RDBYTE(PC), RDBYTE(PC+1));
        PC+=2;
        break;
    case _ima:
        sprintf(buffer,"%-5s#$%02X $%04X", token[opc], RDBYTE(PC), RDWORD(PC+1));
        PC+=3;
        break;
    case _imx:
        sprintf(buffer,"%-5s#$%02X $%04X,x", token[opc], RDBYTE(PC), RDWORD(PC+1));
        PC+=3;
        break;

    default:
        sprintf(buffer,"%-5s$%02X", token[opc], OP >> 1);
    }
    return (PC - pc) | flags | DASMFLAG_SUPPORTED;
}
Ejemplo n.º 9
0
/*****************************************************************************
 *  Disassemble a single command and return the number of bytes it uses.
 *****************************************************************************/
int Dasm6280(char *buffer, int pc)
{
	int PC, OP, opc, arg;

	PC = pc;
	OP = RDOP(PC);
	OP = OP << 1;
	PC++;

	opc = op6280[OP];
    arg = op6280[OP+1];

	switch(arg)
	{
		case _acc:
			sprintf(buffer,"%-5sa", token[opc]);
			break;
		case _imp:
			sprintf(buffer,"%s", token[opc]);
			break;
		case _rel:
			sprintf(buffer,"%-5s$%04X", token[opc], (PC + 1 + (signed char)RDBYTE(PC)) & 0xffff);
			PC+=1;
			break;
		case _imm:
			sprintf(buffer,"%-5s#$%02X", token[opc], RDBYTE(PC));
			PC+=1;
			break;
		case _zpg:
			sprintf(buffer,"%-5s$%02X", token[opc], RDBYTE(PC));
			PC+=1;
			break;
		case _zpx:
			sprintf(buffer,"%-5s$%02X,x", token[opc], RDBYTE(PC));
			PC+=1;
			break;
		case _zpy:
			sprintf(buffer,"%-5s$%02X,y", token[opc], RDBYTE(PC));
			PC+=1;
			break;
		case _idx:
			sprintf(buffer,"%-5s($%02X,x)", token[opc], RDBYTE(PC));
			PC+=1;
			break;
		case _idy:
			sprintf(buffer,"%-5s($%02X),y", token[opc], RDBYTE(PC));
			PC+=1;
			break;
		case _zpi:
			sprintf(buffer,"%-5s($%02X)", token[opc], RDBYTE(PC));
            PC+=1;
            break;
		case _abs:
			sprintf(buffer,"%-5s$%04X", token[opc], RDWORD(PC));
			PC+=2;
			break;
		case _abx:
			sprintf(buffer,"%-5s$%04X,x", token[opc], RDWORD(PC));
			PC+=2;
			break;
		case _aby:
			sprintf(buffer,"%-5s$%04X,y", token[opc], RDWORD(PC));
			PC+=2;
			break;
		case _ind:
			sprintf(buffer,"%-5s($%04X)", token[opc], RDWORD(PC));
			PC+=2;
			break;
		case _iax:
			sprintf(buffer,"%-5s($%04X),X", token[opc], RDWORD(PC));
			PC+=2;
            break;
		case _blk:
			sprintf(buffer,"%-5s$%04X $%04X $%04X", token[opc], RDWORD(PC), RDWORD(PC+2), RDWORD(PC+4));
			PC+=6;
            break;
		case _zrl:
			sprintf(buffer,"%-5s$%02X $%04X", token[opc], RDBYTE(PC), (PC + 2 + (signed char)RDBYTE(PC+1)) & 0xffff);
			PC+=2;
			break;
		case _imz:
			sprintf(buffer,"%-5s#$%02X $%02X", token[opc], RDBYTE(PC), RDBYTE(PC+1));
			PC+=2;
			break;
		case _izx:
			sprintf(buffer,"%-5s#$%02X $%02X,x", token[opc], RDBYTE(PC), RDBYTE(PC+1));
			PC+=2;
			break;
		case _ima:
			sprintf(buffer,"%-5s#$%02X $%04X", token[opc], RDBYTE(PC), RDWORD(PC+1));
			PC+=3;
			break;
		case _imx:
			sprintf(buffer,"%-5s#$%02X $%04X,x", token[opc], RDBYTE(PC), RDWORD(PC+1));
			PC+=3;
			break;

		default:
			sprintf(buffer,"%-5s$%02X", token[opc], OP >> 1);
	}
	return PC - pc;
}