Ejemplo n.º 1
0
int testPlpImplied() {
	SR = 0x20;
	push8(0xBA);
	ram[0] = 0x28;
	instructions = 1; run();
	if(!(SR&SR_NEG && !(SR&SR_OVER) && SR&SR_DEC && !(SR&SR_INT) && SR&SR_ZERO && !(SR&SR_CARRY))) return -1;
	return 0;
}
Ejemplo n.º 2
0
Archivo: vm.c Proyecto: kisom/kam
/*
 * Step through a single instruction in the program. Returns VM_ERR
 * on an error condition (if it doesn't abort()), VM_STOP if the
 * program is complete, and VM_OK if the program should keep running.
 */
int
vm_step(machine vm, uint8_t *prog, uint16_t prog_len)
{
	uint16_t	val;
	uint8_t		oper;

	if (NULL == vm) {
		fprintf(stderr, "[!] VM not initialised.\n");
		return VM_ERR;
	}

	if (vm->pc == prog_len)
		return VM_STOP;

	oper = prog[vm->pc];
	vm->pc++;
	switch (oper) {
	case INSTR_STOP:
		return VM_STOP;
	case INSTR_ADD:  /* fall through: store the operator in */
	case INSTR_SUB:  /* the op stack                        */
	case INSTR_DIV:
	case INSTR_MUL:
		push8(vm->opers, oper);
		break;
	case INSTR_IMM:
		/* detect wrap around */
		if ((prog_len - vm->pc) >= prog_len) {
			fprintf(stderr, "[!] PC overflow.\n");
			return VM_ERR;
		}
		/* ensure we have enough progspace left */
		if ((prog_len - vm->pc) < 2) {
			fprintf(stderr, "[!] Out of program space.\n");
			fprintf(stderr, "    %d bytes remain.\n", 
			    prog_len - vm->pc);
			return VM_ERR;
		}
		memcpy(&val, prog + vm->pc, sizeof(val));
		push16(vm->vals, val);
		vm->pc += 2; /* 2 bytes == 16 bits */
		break;
	case INSTR_DO:
		return eval(vm);
	default:
		fprintf(stderr, "[!] Unknown operator: %d.\n", oper);
		return VM_ERR;

	}
	return VM_OK;
}
Ejemplo n.º 3
0
Calculator::Calculator(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Calculator)
{
    ui->setupUi(this);

    pastNumber = 0;
    currentNumber = ui->lcd->value();
    state = '\0';
    point = false;
    in = false;
    count = 0;

    connect(ui->button0, SIGNAL(clicked()),
            this, SLOT(push0()));
    connect(ui->button1, SIGNAL(clicked()),
            this, SLOT(push1()));
    connect(ui->button2, SIGNAL(clicked()),
            this, SLOT(push2()));
    connect(ui->button3, SIGNAL(clicked()),
            this, SLOT(push3()));
    connect(ui->button4, SIGNAL(clicked()),
            this, SLOT(push4()));
    connect(ui->button5, SIGNAL(clicked()),
            this, SLOT(push5()));
    connect(ui->button6, SIGNAL(clicked()),
            this, SLOT(push6()));
    connect(ui->button7, SIGNAL(clicked()),
            this, SLOT(push7()));
    connect(ui->button8, SIGNAL(clicked()),
            this, SLOT(push8()));
    connect(ui->button9, SIGNAL(clicked()),
            this, SLOT(push9()));
    connect(ui->buttonDot, SIGNAL(clicked()),
            this, SLOT(pushpoint()));
    connect(ui->buttonCE, SIGNAL(clicked()),
            this, SLOT(ce()));
    connect(ui->buttonC, SIGNAL(clicked()),
            this, SLOT(c()));
    connect(ui->buttonPlus, SIGNAL(clicked()),
            this, SLOT(pushPlus()));
    connect(ui->buttonSub, SIGNAL(clicked()),
            this, SLOT(pushSub()));
    connect(ui->buttonTimes, SIGNAL(clicked()),
            this, SLOT(pushTimes()));
    connect(ui->buttonDiv, SIGNAL(clicked()),
            this, SLOT(pushDiv()));
    connect(ui->buttonEqual, SIGNAL(clicked()),
            this, SLOT(pushEqual()));

    QFont font = ui->button0->font();
    font.setPointSize(40);
    ui->button0->setFont(font);
    ui->button1->setFont(font);
    ui->button2->setFont(font);
    ui->button3->setFont(font);
    ui->button4->setFont(font);
    ui->button5->setFont(font);
    ui->button6->setFont(font);
    ui->button7->setFont(font);
    ui->button8->setFont(font);
    ui->button9->setFont(font);
    ui->buttonC->setFont(font);
    ui->buttonCE->setFont(font);
    ui->buttonEqual->setFont(font);
    ui->buttonDiv->setFont(font);
    ui->buttonTimes->setFont(font);
    ui->buttonPlus->setFont(font);
    ui->buttonSub->setFont(font);
    ui->buttonDot->setFont(font);
}
//===== PUSH n
void sngPUSH8()
{
	_u8 data = FETCH8;
	push8(data);
	cycles = 4;
}