-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloaders.c
85 lines (75 loc) · 1.8 KB
/
loaders.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <stdio.h>
#include "cpu.h"
#include "instruction.h"
#include "loaders.h"
void mov(cpu_t* cpu)
{
switch(cpu->memory[cpu->ip])
{
case 0xB8:
mov_reg16_imm(&(cpu->ax),cpu->memory[cpu->ip+1]);
break;
case 0xB9:
mov_reg16_imm(&(cpu->cx),cpu->memory[cpu->ip+1]);
break;
case 0xBA:
mov_reg16_imm(&(cpu->dx),cpu->memory[cpu->ip+1]);
break;
case 0xBB:
mov_reg16_imm(&(cpu->bx),cpu->memory[cpu->ip+1]);
break;
case 0xBC:
mov_reg16_imm(&(cpu->sp),cpu->memory[cpu->ip+1]);
break;
case 0xBD:
mov_reg16_imm(&(cpu->bp),cpu->memory[cpu->ip+1]);
break;
case 0xBE:
mov_reg16_imm(&(cpu->si),cpu->memory[cpu->ip+1]);
break;
case 0xBF:
mov_reg16_imm(&(cpu->di),cpu->memory[cpu->ip+1]);
break;
}
// make sure to increment at the end
cpu->ip += instruction_length(cpu->memory[cpu->ip]);
}
void mov_reg16_imm(uint16_t* dest,uint16_t src)
{
// this one is easy because it's a 16 bit immediate value into a 16 bit register
*dest = src;
}
void mov_regLO_imm(uint16_t* dest,uint8_t src)
{
*dest = (*dest & 0xFF00) | src;
}
void mov_regHO_imm(uint16_t* dest,uint8_t src)
{
*dest = (*dest & 0x00FF) | (src << 8);
}
void mov_reg16_reg16(uint16_t* dest,uint16_t src)
{
*dest = src;
}
void mov_regLO_regLO(uint16_t* dest,uint16_t src)
{
*dest = (*dest & 0xFF00) | (src & 0x00FF);
}
void mov_regHO_regHO(uint16_t* dest,uint16_t src)
{
*dest = (*dest & 0x00FF) | (src & 0xFF00);
}
void mov_regLO_regHO(uint16_t* dest,uint16_t src)
{
*dest = (*dest & 0xFF00) | ((src & 0xFF00) >> 8);
}
void mov_reg16_regHO(uint16_t* dest,uint16_t src)
{
// this nukes *dest then sets the HO byte to match src's HO byte
*dest = (*dest & 0x0000) | (src & 0xFF00);
}
void mov_reg16_regLO(uint16_t* dest,uint16_t src)
{
// same as above, only with LO bytes
*dest = (*dest & 0x0000) | (src & 0x00FF);
}