Example #1
0
static void saturn_instruction(saturn_state *cpustate)
{
	int reg, adr;

	switch(READ_OP(cpustate)) {
	case 0:
		switch(READ_OP(cpustate)) {
		case 0: saturn_return_xm_set(cpustate);break;
		case 1: saturn_return(cpustate, 1);break;
		case 2: saturn_return_carry_set(cpustate);break;
		case 3: saturn_return_carry_clear(cpustate);break;
		case 4: saturn_sethex(cpustate);break;
		case 5: saturn_setdec(cpustate);break;
		case 6: saturn_push_c(cpustate);break;
		case 7: saturn_pop_c(cpustate);break;
		case 8: saturn_clear_st(cpustate);break;
		case 9: saturn_st_to_c(cpustate);break;
		case 0xa: saturn_c_to_st(cpustate);break;
		case 0xb: saturn_exchange_c_st(cpustate);break;
		case 0xc: saturn_inc_p(cpustate);break;
		case 0xd: saturn_dec_p(cpustate);break;
		case 0xe: saturn_instruction_0e(cpustate);break;
		case 0xf: saturn_return_interrupt(cpustate);break;
		}
		break;
	case 1:
		saturn_instruction_1(cpustate);
		break;
	case 2:
		saturn_load_p(cpustate);
		break;
	case 3:
		saturn_load_reg(cpustate, C);
		break; // lc
	case 4:
		adr=READ_OP_DIS8(cpustate);
		if (adr==0) {
			saturn_return(cpustate, cpustate->carry);
		}
		else {
			saturn_jump(cpustate, (cpustate->pc+adr-2)&0xfffff, cpustate->carry);
		}
		break;
	case 5:
		adr=READ_OP_DIS8(cpustate);
		if (adr==0) {
			saturn_return(cpustate, !cpustate->carry);
		}
		else {
			saturn_jump(cpustate, (cpustate->pc+adr-2)&0xfffff,!cpustate->carry);
		}
		break;
	case 6:
		adr=READ_OP_DIS12(cpustate);
		saturn_jump(cpustate, (cpustate->pc+adr-3)&0xfffff,1); break;
	case 7:
		adr=READ_OP_DIS12(cpustate);
		saturn_call(cpustate, (adr+cpustate->pc)&0xfffff); break;
	case 8:
		saturn_instruction_8(cpustate);
		break;
	case 9:
		saturn_instruction_9(cpustate);
		break;
	case 0xa:
		saturn_instruction_a(cpustate);
		break;
	case 0xb:
		saturn_instruction_b(cpustate);
		break;
	case 0xc:
		switch (reg=READ_OP(cpustate)) {
		case 0: case 1: case 2: case 3:
		case 8: case 9: case 0xa: case 0xb:
			saturn_add(cpustate, add_left[reg], BEGIN_A, COUNT_A, add_right[reg]);
			break;
		case 4: case 5: case 6: case 7:
			saturn_add(cpustate, A+(reg&3), BEGIN_A, COUNT_A, A+(reg&3));
			break;
		case 0xc: case 0xd: case 0xe: case 0xf:
			saturn_decrement(cpustate, A+(reg&3), BEGIN_A, COUNT_A);
			break;
		}
		break;
	case 0xd:
		switch(reg=READ_OP(cpustate)) {
		case 0: case 1: case 2: case 3:
			saturn_clear(cpustate, A+reg, BEGIN_A, COUNT_A);
			break; // a=0 a
		case 4: case 5: case 6: case 7:
		case 8: case 9: case 0xa: case 0xb:
			saturn_copy(cpustate, reg_right[reg&7], BEGIN_A, COUNT_A, reg_left[reg&7]);
			break; // a=b a
		case 0xc: case 0xd: case 0xe: case 0xf:
			saturn_exchange(cpustate, reg_left[reg&3], BEGIN_A, COUNT_A, reg_right[reg&3]);
			break; // abex a
		}
		break;
	case 0xe:
		switch(reg=READ_OP(cpustate)) {
		case 0: case 1: case 2: case 3:
		case 8: case 9: case 0xa: case 0xb:
			saturn_sub(cpustate, sub_left[reg], BEGIN_A, COUNT_A, sub_right[reg]);
			break;
		case 4: case 5: case 6: case 7:
			saturn_increment(cpustate, A+(reg&3), BEGIN_A, COUNT_A);
			break; // a=a+1 a
		case 0xc: case 0xd: case 0xe: case 0xf:
			saturn_sub2(cpustate, sub_left[reg], BEGIN_A, COUNT_A, sub_right[reg]);
			break;
		}
		break;
	case 0xf:
		switch(reg=READ_OP(cpustate)) {
		case 0: case 1: case 2: case 3:
			saturn_shift_nibble_left(cpustate, A+reg,BEGIN_A, COUNT_A);
			break; // asl a
		case 4: case 5: case 6: case 7:
			saturn_shift_nibble_right(cpustate, A+(reg&3),BEGIN_A, COUNT_A);
			break; // asr a
		case 8: case 9: case 0xa: case 0xb:
			saturn_negate(cpustate, A+(reg&3),BEGIN_A, COUNT_A);
			break; // A=-A a
		case 0xc: case 0xd: case 0xe: case 0xf:
			saturn_invert(cpustate, A+(reg&3),BEGIN_A, COUNT_A);
			break; // A=-A-1 a
		}
		break;
	}
}
Example #2
0
static void saturn_instruction(void)
{
	int reg, adr;

	switch(READ_OP()) {
	case 0:
		switch(READ_OP()) {
		case 0: saturn_return_xm_set();break;
		case 1: saturn_return(1);break;
		case 2: saturn_return_carry_set();break;
		case 3: saturn_return_carry_clear();break;
		case 4: saturn_sethex();break;
		case 5: saturn_setdec();break;
		case 6: saturn_push_c();break;
		case 7: saturn_pop_c();break;
		case 8: saturn_clear_st();break;
		case 9: saturn_st_to_c();break;
		case 0xa: saturn_c_to_st();break;
		case 0xb: saturn_exchange_c_st();break;
		case 0xc:
			saturn_inc_p();
			break;
		case 0xd:
			saturn_dec_p();
			break;
		case 0xf: saturn_return_interrupt();break;
		case 0xe:
			saturn_instruction_0e();
			break;
		}
		break;
	case 1:
		saturn_instruction_1();
		break;
	case 2:
		saturn_load_p();
		break;
	case 3: saturn_load_reg(C);break; /* lc */
	case 4: 
		adr=READ_OP_DIS8();
		if (adr==0) {
			saturn_return(saturn.carry);
		} else {
			saturn_jump((saturn.pc+adr-2)&0xfffff, saturn.carry);
		}
		break;
	case 5: 
		adr=READ_OP_DIS8();
		if (adr==0) {
			saturn_return(!saturn.carry);
		} else {
			saturn_jump((saturn.pc+adr-2)&0xfffff,!saturn.carry);
		}
		break;
	case 6: 
		adr=READ_OP_DIS12();
		saturn_jump((saturn.pc+adr-3)&0xfffff,1); break;
	case 7: 
		adr=READ_OP_DIS12();
		saturn_call((adr+saturn.pc)&0xfffff); break;
	case 8:
		saturn_instruction_8();
		break;
	case 9:
		saturn_instruction_9();
		break;
	case 0xa:
		saturn_instruction_a();
		break;
	case 0xb:
		saturn_instruction_b();
		break;
	case 0xc:
		switch (reg=READ_OP()) {
		case 0: case 1: case 2: case 3:
		case 8: case 9: case 0xa: case 0xb:
			saturn_add(add_left[reg], BEGIN_A, COUNT_A, add_right[reg]);
			break;
		case 4: case 5: case 6: case 7:
			saturn_shift_left(A+(reg&3), BEGIN_A, COUNT_A);
			break;
		case 0xc: case 0xd: case 0xe: case 0xf:
			saturn_decrement(A+(reg&3), BEGIN_A, COUNT_A);
			break;
		}
		break;
	case 0xd:
		switch(reg=READ_OP()) {
		case 0: case 1: case 2: case 3:
			saturn_clear(A+reg, BEGIN_A, COUNT_A);
			break; /* a=0 a */
		case 4: case 5: case 6: case 7:
		case 8: case 9: case 0xa: case 0xb:
			saturn_copy(reg_right[reg&7], BEGIN_A, COUNT_A, reg_left[reg&7]); /*correct */
			break; /* a=b a */
		case 0xc: case 0xd: case 0xe: case 0xf:
			saturn_exchange(reg_left[reg&3], BEGIN_A, COUNT_A, reg_right[reg&3]);
			break; /* abex a */
		}
		break;
	case 0xe:
		switch(reg=READ_OP()) {
		case 0: case 1: case 2: case 3:
		case 8: case 9: case 0xa: case 0xb:
			saturn_sub(sub_left[reg], BEGIN_A, COUNT_A, S64_READ_A(sub_right[reg]));
			break;
		case 4: case 5: case 6: case 7:
			saturn_increment(A+(reg&3), BEGIN_A, COUNT_A); 
			break; /* a=a+1 a */
		case 0xc: case 0xd: case 0xe: case 0xf:
			saturn_sub2(sub_left[reg], BEGIN_A, COUNT_A, S64_READ_A(sub_right[reg]));
			break;
		}
		break;
	case 0xf:
		switch(reg=READ_OP()) {
		case 0: case 1: case 2: case 3:
			saturn_shift_nibble_left(A+reg,BEGIN_A, COUNT_A); 
			break; /* asl a */
		case 4: case 5: case 6: case 7:
			saturn_shift_nibble_right(A+(reg&3),BEGIN_A, COUNT_A); 
			break; /* asr a */
		case 8: case 9: case 0xa: case 0xb:
			saturn_invert(A+(reg&3),BEGIN_A, COUNT_A); 
			break; /* A=-A a */
		case 0xc: case 0xd: case 0xe: case 0xf:
			saturn_negate(A+(reg&3),BEGIN_A, COUNT_A); 
			break; /* A=-A-1 a */
		}
		break;
	}
}
Example #3
0
static void saturn_instruction_b(saturn_state *cpustate)
{
	int adr, reg;

	switch(adr=READ_OP(cpustate)) {
	case 0:
		switch(reg=READ_OP(cpustate)) {
		case 0: case 1: case 2: case 3:
		case 8: case 9: case 0xa: case 0xb:
			saturn_sub(cpustate, sub_left[reg], cpustate->p, 1, sub_right[reg]);
			break;
		case 4: case 5: case 6: case 7:
			saturn_increment(cpustate, A+(reg&3), cpustate->p, 1); break; // a=a+1 p
		case 0xc: case 0xd: case 0xe: case 0xf:
			saturn_sub2(cpustate, sub_left[reg], cpustate->p, 1, sub_right[reg]);
			break;
		}
		break;
	case 1:
		switch(reg=READ_OP(cpustate)) {
		case 0: case 1: case 2: case 3:
		case 8: case 9: case 0xa: case 0xb:
			saturn_sub(cpustate, sub_left[reg], 0, cpustate->p+1, sub_right[reg]);
			break;
		case 4: case 5: case 6: case 7:
			saturn_increment(cpustate, A+(reg&3), 0, cpustate->p+1); break; // a=a+1 wp
		case 0xc: case 0xd: case 0xe: case 0xf:
			saturn_sub2(cpustate, sub_left[reg], 0, cpustate->p+1, sub_right[reg]);
			break;
		}
		break;
	case 2: case 3: case 4: case 5: case 6: case 7:
		switch(reg=READ_OP(cpustate)) {
		case 0: case 1: case 2: case 3:
		case 8: case 9: case 0xa: case 0xb:
			saturn_sub(cpustate, sub_left[reg], adr_a_begin[adr], adr_a_count[adr], sub_right[reg]);
			break;
		case 4: case 5: case 6: case 7:
			saturn_increment(cpustate, A+(reg&3), adr_a_begin[adr], adr_a_count[adr]);
			break; // a=a+1 xs
		case 0xc: case 0xd: case 0xe: case 0xf:
			saturn_sub2(cpustate, sub_left[reg], adr_a_begin[adr], adr_a_count[adr],
						sub_right[reg]);
			break;
		}
		break;
	case 8:
		switch(reg=READ_OP(cpustate)) {
		case 0: case 1: case 2: case 3:
			saturn_shift_nibble_left(cpustate, A+reg, cpustate->p, 1); break; // asl p
		case 4: case 5: case 6: case 7:
			saturn_shift_nibble_right(cpustate, A+(reg&3), cpustate->p, 1); break; // asr p
		case 8: case 9: case 0xa: case 0xb:
			saturn_negate(cpustate, A+(reg&3), cpustate->p, 1); break; // A=-A p
		case 0xc: case 0xd: case 0xe: case 0xf:
			saturn_invert(cpustate, A+(reg&3), cpustate->p, 1); break; // A=-A-1 p
		}
		break;
	case 9:
		switch(reg=READ_OP(cpustate)) {
		case 0: case 1: case 2: case 3:
			saturn_shift_nibble_left(cpustate, A+reg,0,cpustate->p+1); break; // asl wp
		case 4: case 5: case 6: case 7:
			saturn_shift_nibble_right(cpustate, A+(reg&3),0,cpustate->p+1); break; // asr wp
		case 8: case 9: case 0xa: case 0xb:
			saturn_negate(cpustate, A+(reg&3),0,cpustate->p+1); break; // A=-A wp
		case 0xc: case 0xd: case 0xe: case 0xf:
			saturn_invert(cpustate, A+(reg&3),0,cpustate->p+1); break; // A=-A-1 wp
		}
		break;
	case 0xa: case 0xb: case 0xc: case 0xd: case 0xe: case 0xf:
		switch(reg=READ_OP(cpustate)) {
		case 0: case 1: case 2: case 3:
			saturn_shift_nibble_left(cpustate, A+reg,adr_b_begin[adr], adr_b_count[adr]);
			break;
		case 4: case 5: case 6: case 7:
			saturn_shift_nibble_right(cpustate, A+(reg&3), adr_b_begin[adr], adr_b_count[adr]);
			break;
		case 8: case 9: case 0xa: case 0xb:
			saturn_negate(cpustate, A+(reg&3), adr_b_begin[adr], adr_b_count[adr]);
			break;
		case 0xc: case 0xd: case 0xe: case 0xf:
			saturn_invert(cpustate, A+(reg&3), adr_b_begin[adr], adr_b_count[adr]);
			break;
		}
		break;
	}
}
Example #4
0
static void saturn_instruction_b(void)
{
	int adr, reg;

	switch(adr=READ_OP()) {
	case 0:
		switch(reg=READ_OP()) {
		case 0: case 1: case 2: case 3:
		case 8: case 9: case 0xa: case 0xb:
			saturn_sub(sub_left[reg], saturn.p, 1, S64_READ_P(sub_right[reg]));
			break;
		case 4: case 5: case 6: case 7:
			saturn_increment(A+(reg&3), saturn.p, 1); break; /* a=a+1 p */
		case 0xc: case 0xd: case 0xe: case 0xf:
			saturn_sub2(sub_left[reg], saturn.p, 1, S64_READ_P(sub_right[reg]));
			break;
		}
		break;
	case 1:
		switch(reg=READ_OP()) {
		case 0: case 1: case 2: case 3:
		case 8: case 9: case 0xa: case 0xb:
			saturn_sub(sub_left[reg], 1, saturn.p+1, sub_right[reg]);
			break;
		case 4: case 5: case 6: case 7:
			saturn_increment(A+(reg&3), 1, saturn.p+1); break; /* a=a+1 wp */
		case 0xc: case 0xd: case 0xe: case 0xf:
			saturn_sub2(sub_left[reg], 1, saturn.p+1, sub_right[reg]);
			break;
		}
		break;
	case 2: case 3: case 4: case 5: case 6: case 7:
		switch(reg=READ_OP()) {
		case 0: case 1: case 2: case 3:
		case 8: case 9: case 0xa: case 0xb:
			saturn_sub(sub_left[reg], adr_a_begin[adr], adr_a_count[adr], 
					   sub_right[reg]);
			break;
		case 4: case 5: case 6: case 7:
			saturn_increment(A+(reg&3), adr_a_begin[adr], adr_a_count[adr]); 
			break; /* a=a+1 xs */
		case 0xc: case 0xd: case 0xe: case 0xf:
			saturn_sub2(sub_left[reg], adr_a_begin[adr], adr_a_count[adr], 
						sub_right[reg]);
			break;
		}
		break;
	case 8:
		switch(reg=READ_OP()) {
		case 0: case 1: case 2: case 3:
			saturn_shift_nibble_left(A+reg, saturn.p, 1); break; /* asl p */
		case 4: case 5: case 6: case 7:
			saturn_shift_nibble_right(A+(reg&3), saturn.p, 1); break; /* asr p */
		case 8: case 9: case 0xa: case 0xb:
			saturn_invert(A+(reg&3), saturn.p, 1); break; /* A=-A p */
		case 0xc: case 0xd: case 0xe: case 0xf:
			saturn_negate(A+(reg&3), saturn.p, 1); break; /* A=-A-1 p */
		}
		break;
	case 9:
		switch(reg=READ_OP()) {
		case 0: case 1: case 2: case 3:
			saturn_shift_nibble_left(A+reg,0,saturn.p+1); break; /* asl wp */
		case 4: case 5: case 6: case 7:
			saturn_shift_nibble_right(A+(reg&3),0,saturn.p+1); break; /* asr wp */
		case 8: case 9: case 0xa: case 0xb:
			saturn_invert(A+(reg&3),0,saturn.p+1); break; /* A=-A wp */
		case 0xc: case 0xd: case 0xe: case 0xf:
			saturn_negate(A+(reg&3),0,saturn.p+1); break; /* A=-A-1 wp */
		}
		break;
	case 0xa: case 0xb: case 0xc: case 0xd: case 0xe: case 0xf:
		switch(reg=READ_OP()) {
		case 0: case 1: case 2: case 3:
			saturn_shift_nibble_left(A+reg,adr_b_begin[adr], adr_b_count[adr]); 
			break;
		case 4: case 5: case 6: case 7:
			saturn_shift_nibble_right(A+(reg&3), adr_b_begin[adr], adr_b_count[adr]); 
			break;
		case 8: case 9: case 0xa: case 0xb:
			saturn_invert(A+(reg&3), adr_b_begin[adr], adr_b_count[adr]); 
			break;
		case 0xc: case 0xd: case 0xe: case 0xf:
			saturn_negate(A+(reg&3), adr_b_begin[adr], adr_b_count[adr]); 
			break;
		}
		break;
	}
}