mirror of
https://github.com/tuz358/cpu-emulator.git
synced 2025-12-18 13:04:35 +03:00
Add template_eax_imm32(int calc_type) instruction
This commit is contained in:
@@ -46,6 +46,7 @@ public:
|
|||||||
// templates
|
// templates
|
||||||
void template_r32_rm32(int calc_type);
|
void template_r32_rm32(int calc_type);
|
||||||
void calc_r32_rm32(uint32_t *src, uint32_t *dst, int calc_type);
|
void calc_r32_rm32(uint32_t *src, uint32_t *dst, int calc_type);
|
||||||
|
void template_eax_imm32(int calc_type);
|
||||||
|
|
||||||
void add_rm32_r32(); // 0x01
|
void add_rm32_r32(); // 0x01
|
||||||
void add_r32_rm32(); // 0x03
|
void add_r32_rm32(); // 0x03
|
||||||
|
|||||||
133
instructions.cpp
133
instructions.cpp
@@ -177,31 +177,50 @@ void Instructions::template_r32_rm32(int calc_type){
|
|||||||
void Instructions::calc_r32_rm32(uint32_t *src, uint32_t *dst, int calc_type){
|
void Instructions::calc_r32_rm32(uint32_t *src, uint32_t *dst, int calc_type){
|
||||||
switch (calc_type) {
|
switch (calc_type) {
|
||||||
case ADD:
|
case ADD:
|
||||||
*src += *dst;
|
*src += *dst; break;
|
||||||
break;
|
|
||||||
case OR:
|
case OR:
|
||||||
*src |= *dst;
|
*src |= *dst; break;
|
||||||
break;
|
|
||||||
case ADC:
|
case ADC:
|
||||||
*src += *dst + get_flag(CF);
|
*src += *dst + get_flag(CF); break;
|
||||||
break;
|
|
||||||
case SBB:
|
case SBB:
|
||||||
*src -= *dst + get_flag(CF);
|
*src -= *dst + get_flag(CF); break;
|
||||||
break;
|
|
||||||
case AND:
|
case AND:
|
||||||
*src &= *dst;
|
*src &= *dst; break;
|
||||||
break;
|
|
||||||
case SUB:
|
case SUB:
|
||||||
*src -= *dst;
|
*src -= *dst; break;
|
||||||
break;
|
|
||||||
case XOR:
|
case XOR:
|
||||||
*src ^= *dst;
|
*src ^= *dst; break;
|
||||||
break;
|
|
||||||
case CMP:
|
case CMP:
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
break;
|
break;
|
||||||
default:
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Instructions::template_eax_imm32(int calc_type){
|
||||||
|
this->eip++;
|
||||||
|
uint32_t imm32 = memory.read_uint32(this->eip);
|
||||||
|
imm32 = swap_endian32(imm32);
|
||||||
|
|
||||||
|
switch (calc_type) {
|
||||||
|
case ADD:
|
||||||
|
this->registers[0] += imm32; break;
|
||||||
|
case OR:
|
||||||
|
this->registers[0] |= imm32; break;
|
||||||
|
case ADC:
|
||||||
|
this->registers[0] += imm32 + get_flag(CF); break;
|
||||||
|
case SBB:
|
||||||
|
this->registers[0] -= imm32 + get_flag(CF); break;
|
||||||
|
case AND:
|
||||||
|
this->registers[0] &= imm32; break;
|
||||||
|
case SUB:
|
||||||
|
this->registers[0] -= imm32; break;
|
||||||
|
case XOR:
|
||||||
|
this->registers[0] ^= imm32; break;
|
||||||
|
case CMP:
|
||||||
|
// TODO: implement
|
||||||
break;
|
break;
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,16 +274,8 @@ void Instructions::add_rm32_r32(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instructions::add_r32_rm32(){
|
void Instructions::add_r32_rm32(){ this->template_r32_rm32(ADD); }
|
||||||
this->template_r32_rm32(ADD);
|
void Instructions::add_eax_imm32(){ this->template_eax_imm32(ADD); }
|
||||||
}
|
|
||||||
|
|
||||||
void Instructions::add_eax_imm32(){
|
|
||||||
this->eip++;
|
|
||||||
uint32_t imm32 = memory.read_uint32(this->eip);
|
|
||||||
imm32 = swap_endian32(imm32);
|
|
||||||
this->registers[0] += imm32;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Instructions::or_rm32_r32(){
|
void Instructions::or_rm32_r32(){
|
||||||
//printf("or_rm32_r32 called.\n");
|
//printf("or_rm32_r32 called.\n");
|
||||||
@@ -316,16 +327,8 @@ void Instructions::or_rm32_r32(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instructions::or_r32_rm32(){
|
void Instructions::or_r32_rm32(){ this->template_r32_rm32(OR); }
|
||||||
this->template_r32_rm32(OR);
|
void Instructions::or_eax_imm32(){ this->template_eax_imm32(OR); }
|
||||||
}
|
|
||||||
|
|
||||||
void Instructions::or_eax_imm32(){
|
|
||||||
this->eip++;
|
|
||||||
uint32_t imm32 = memory.read_uint32(this->eip);
|
|
||||||
imm32 = swap_endian32(imm32);
|
|
||||||
this->registers[0] |= imm32;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Instructions::adc_rm32_r32(){
|
void Instructions::adc_rm32_r32(){
|
||||||
//printf("adc_rm32_r32 called.\n");
|
//printf("adc_rm32_r32 called.\n");
|
||||||
@@ -377,16 +380,8 @@ void Instructions::adc_rm32_r32(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instructions::adc_r32_rm32(){
|
void Instructions::adc_r32_rm32(){ this->template_r32_rm32(ADC); }
|
||||||
this->template_r32_rm32(ADC);
|
void Instructions::adc_eax_imm32(){ this->template_eax_imm32(ADC); }
|
||||||
}
|
|
||||||
|
|
||||||
void Instructions::adc_eax_imm32(){
|
|
||||||
this->eip++;
|
|
||||||
uint32_t imm32 = memory.read_uint32(this->eip);
|
|
||||||
imm32 = swap_endian32(imm32);
|
|
||||||
this->registers[0] += imm32 + get_flag(CF);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Instructions::sbb_rm32_r32(){
|
void Instructions::sbb_rm32_r32(){
|
||||||
//printf("sbb_rm32_r32 called.\n");
|
//printf("sbb_rm32_r32 called.\n");
|
||||||
@@ -438,16 +433,8 @@ void Instructions::sbb_rm32_r32(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instructions::sbb_r32_rm32(){
|
void Instructions::sbb_r32_rm32(){ this->template_r32_rm32(SBB); }
|
||||||
this->template_r32_rm32(SBB);
|
void Instructions::sbb_eax_imm32(){ this->template_eax_imm32(SBB); }
|
||||||
}
|
|
||||||
|
|
||||||
void Instructions::sbb_eax_imm32(){
|
|
||||||
this->eip++;
|
|
||||||
uint32_t imm32 = memory.read_uint32(this->eip);
|
|
||||||
imm32 = swap_endian32(imm32);
|
|
||||||
this->registers[0] -= imm32 + get_flag(CF);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Instructions::and_rm32_r32(){
|
void Instructions::and_rm32_r32(){
|
||||||
//printf("and_rm32_r32 called.\n");
|
//printf("and_rm32_r32 called.\n");
|
||||||
@@ -499,16 +486,8 @@ void Instructions::and_rm32_r32(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instructions::and_r32_rm32(){
|
void Instructions::and_r32_rm32() { this->template_r32_rm32(AND); }
|
||||||
this->template_r32_rm32(AND);
|
void Instructions::and_eax_imm32(){ this->template_eax_imm32(AND); }
|
||||||
}
|
|
||||||
|
|
||||||
void Instructions::and_eax_imm32(){
|
|
||||||
this->eip++;
|
|
||||||
uint32_t imm32 = memory.read_uint32(this->eip);
|
|
||||||
imm32 = swap_endian32(imm32);
|
|
||||||
this->registers[0] &= imm32;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Instructions::sub_rm32_r32(){
|
void Instructions::sub_rm32_r32(){
|
||||||
//printf("sub_rm32_r32 called.\n");
|
//printf("sub_rm32_r32 called.\n");
|
||||||
@@ -559,16 +538,8 @@ void Instructions::sub_rm32_r32(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instructions::sub_r32_rm32(){
|
void Instructions::sub_r32_rm32() { this->template_r32_rm32(SUB); }
|
||||||
this->template_r32_rm32(SUB);
|
void Instructions::sub_eax_imm32(){ this->template_eax_imm32(SUB); }
|
||||||
}
|
|
||||||
|
|
||||||
void Instructions::sub_eax_imm32(){
|
|
||||||
this->eip++;
|
|
||||||
uint32_t imm32 = memory.read_uint32(this->eip);
|
|
||||||
imm32 = swap_endian32(imm32);
|
|
||||||
this->registers[0] -= imm32;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Instructions::xor_rm32_r32(){
|
void Instructions::xor_rm32_r32(){
|
||||||
//printf("xor_rm32_r32 called.\n");
|
//printf("xor_rm32_r32 called.\n");
|
||||||
@@ -619,16 +590,8 @@ void Instructions::xor_rm32_r32(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instructions::xor_r32_rm32(){
|
void Instructions::xor_r32_rm32() { this->template_r32_rm32(XOR); }
|
||||||
this->template_r32_rm32(XOR);
|
void Instructions::xor_eax_imm32(){ this->template_eax_imm32(XOR); }
|
||||||
}
|
|
||||||
|
|
||||||
void Instructions::xor_eax_imm32(){
|
|
||||||
this->eip++;
|
|
||||||
uint32_t imm32 = memory.read_uint32(this->eip);
|
|
||||||
imm32 = swap_endian32(imm32);
|
|
||||||
this->registers[0] ^= imm32;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Instructions::cmp_rm32_r32(){
|
void Instructions::cmp_rm32_r32(){
|
||||||
//printf("cmp_rm32_r32 called.\n");
|
//printf("cmp_rm32_r32 called.\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user