Skip to content

Commit e93ef2c

Browse files
committed
Add mkdir Support
Added missing instructions for mkdir.
1 parent 6fa5b12 commit e93ef2c

File tree

6 files changed

+46
-5
lines changed

6 files changed

+46
-5
lines changed

emulator_functions.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,16 @@ void update_eflags_add_8bit(Emulator *emu, uint8_t value1, uint8_t value2, uint1
475475
set_sign_flag(emu, signr);
476476
}
477477

478+
void update_eflags_add_16bit(Emulator *emu, uint8_t value1, uint8_t value2, uint16_t result)
479+
{
480+
int sign1 = value1 >> 15;
481+
int sign2 = value2 >> 15;
482+
int signr = (result >> 15) & 1;
483+
set_carry_flag(emu, result >> 16);
484+
set_overflow_flag(emu, sign1 == sign2 && sign1 != signr);
485+
set_sign_flag(emu, signr);
486+
}
487+
478488
/*
479489
* 1000 (-8) - 0001 (1) = 10111 (-9) -> carry
480490
* 1000 (-8) - 0010 (2) = 10110 (-10) -> carry

emulator_functions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ int32_t is_overflow(Emulator *emu);
9696

9797
void update_eflags_add(Emulator *emu, uint32_t value1, uint32_t value2, uint64_t result);
9898
void update_eflags_add_8bit(Emulator *emu, uint8_t value1, uint8_t value2, uint16_t result);
99+
void update_eflags_add_16bit(Emulator *emu, uint8_t value1, uint8_t value2, uint16_t result);
99100

100101
void update_eflags_sub(Emulator *emu, uint32_t value1, uint32_t value2, uint64_t result);
101102
void update_eflags_sub_8bit(Emulator *emu, uint8_t value1, uint8_t value2, uint16_t result);

instruction_defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void code_d0(Emulator *emu);
177177
void code_d1(Emulator *emu);
178178
void code_d2(Emulator *emu);
179179
void code_d3(Emulator *emu);
180-
void set_al_on_c(Emulator *emu);
180+
void set_al_on_carry(Emulator *emu);
181181

182182
/* 0xE0 */
183183
void loopnz(Emulator *emu);

instructions.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,12 @@ void init_instructions(void)
402402
instructions[0xCD] = int_imm8;
403403
instructions[0xCF] = iret;
404404

405+
instructions[0xD0] = code_d0;
406+
instructions[0xD1] = code_d1;
407+
instructions[0xD2] = code_d2;
408+
instructions[0xD3] = code_d3;
409+
instructions[0xD6] = set_al_on_carry;
410+
405411
instructions[0xE0] = loopnz;
406412
instructions[0xE1] = loopz;
407413
instructions[0xE2] = loop;

instructions_80.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,24 @@ void code_83(Emulator *emu)
559559
}
560560
}
561561

562+
/*
563+
* add rm16 imm8: 3|4 bytes
564+
* Adds imm8 to RM16. Op code 83 and ModR/M op code: 0 execute this.
565+
* 1 byte: shared op (83)
566+
* 1|2 byte: ModR/M
567+
* 1 byte: imm8 to add
568+
*/
569+
static void add_rm16_imm8(Emulator *emu, ModRM *modrm)
570+
{
571+
uint16_t rm16 = get_rm16(emu, modrm);
572+
uint16_t imm8 = (uint16_t)get_sign_code8(emu, 0);
573+
emu->eip += 1;
574+
575+
uint32_t result = (uint32_t)rm16 + (uint32_t)imm8;
576+
set_rm16(emu, modrm, result);
577+
update_eflags_add_16bit(emu, rm16, imm8, result);
578+
}
579+
562580
/*
563581
* cmp rm16 imm8: 3 bytes
564582
* Compares rm16 value and imm8 value by subtracting in order.
@@ -586,9 +604,9 @@ void code_83_rm16(Emulator *emu)
586604

587605
switch (modrm.opcode)
588606
{
589-
// case 0:
590-
// add_rm16_imm8(emu, &modrm);
591-
// break;
607+
case 0:
608+
add_rm16_imm8(emu, &modrm);
609+
break;
592610
// case 1:
593611
// or_rm16_imm8(emu, &modrm);
594612
// break;

instructions_D0.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,12 @@ void code_d3(Emulator *emu)
271271
}
272272
}
273273

274-
void set_al_on_c(Emulator *emu)
274+
/*
275+
* salc
276+
* Sets AL if carry.
277+
* 1 byte: op (D6)
278+
*/
279+
void set_al_on_carry(Emulator *emu)
275280
{
276281
if (is_carry(emu))
277282
{
@@ -281,4 +286,5 @@ void set_al_on_c(Emulator *emu)
281286
{
282287
set_register8(emu, AL, 0x0);
283288
}
289+
emu->eip += 1;
284290
}

0 commit comments

Comments
 (0)