Skip to content

Commit eaec363

Browse files
authored
Introduce cmake (#8)
This commit makes this project platform-independent with `cmake`.
1 parent 7d13c77 commit eaec363

10 files changed

Lines changed: 90 additions & 100 deletions

File tree

.github/workflows/build.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Build x86 emulator
2+
3+
on: [push,pull_request]
4+
5+
jobs:
6+
build1:
7+
name: Build x86 emulator on Linux
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: libsdl-org/setup-sdl@main
12+
id: sdl
13+
with:
14+
install-linux-dependencies: true
15+
version: 2.30.9
16+
- name: Generate build system
17+
run: cmake .
18+
- name: Build
19+
run: cmake --build .

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build/
2+
.DS_Store
3+
.vscode

CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required(VERSION 3.26.0)
2+
3+
find_package(SDL2 CONFIG REQUIRED)
4+
5+
project(X86_EMULATOR)
6+
7+
file(GLOB SOURCES src/*.cpp)
8+
9+
add_executable(x86
10+
${SOURCES}
11+
)
12+
13+
target_link_libraries(x86 ${SDL2_LIBRARIES})
14+
target_include_directories(x86 PUBLIC
15+
${SDL2_INCLUDE_DIRS}
16+
)
17+
target_include_directories(x86 PRIVATE include SDL2)

Makefile

Lines changed: 0 additions & 52 deletions
This file was deleted.

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@
9898

9999
<h2>Build</h2>
100100

101-
```
102-
make
101+
```bash
102+
mkdir build
103+
cmake ..
104+
cmake --build .
103105
```
104106

105107
<h2>Run</h2>

include/Cpu.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ class DescriptorTableRegister;
2424
#define DPL 0x60 // access_rightのDPLの該当部分
2525

2626
namespace CpuHelper {
27-
inline template <typename type>
28-
uint8_t GetDpl(type data) {
27+
template <typename type>
28+
inline uint8_t GetDpl(type data) {
2929
return (data & DPL) >> 5;
3030
}
3131

32-
inline template <typename type>
33-
uint8_t GetRpl(type data) {
32+
template <typename type>
33+
inline uint8_t GetRpl(type data) {
3434
return data & 0x03;
3535
}
3636
} // namespace CpuHelper

include/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
2+
#include <functional>
23
#include <stdarg.h>
34
#include <string.h>
45
#include <unistd.h>

include/detail/Cpu.h

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ type Cpu::Inc(type data) {
9696
return data + 1;
9797
}
9898

99-
inline template <typename type>
100-
void Cpu::UpdateEflagsForInc(type d) {
99+
template <typename type>
100+
inline void Cpu::UpdateEflagsForInc(type d) {
101101
type result = (type)(d + 1);
102102
this->UpdateZF(result);
103103
this->UpdateSF(result);
@@ -112,8 +112,8 @@ type Cpu::Dec(type data) {
112112
return result;
113113
}
114114

115-
inline template <typename type>
116-
void Cpu::UpdateEflagsForDec(type result, type d1, type d2) {
115+
template <typename type>
116+
inline void Cpu::UpdateEflagsForDec(type result, type d1, type d2) {
117117
this->UpdateZF(result);
118118
this->UpdateSF(result);
119119
this->UpdatePF(result);
@@ -134,46 +134,46 @@ void Cpu::UpdateEflagsForDec(type result, type d1, type d2) {
134134
}
135135
}
136136

137-
inline template <typename type>
138-
type Cpu::Adc(type data1, type data2) {
137+
template <typename type>
138+
inline type Cpu::Adc(type data1, type data2) {
139139
type carry = this->IsFlag(CF) ? 1 : 0;
140140
this->UpdateEflagsForAdc(data1, data2, carry);
141141
return data1 + data2 + carry;
142142
}
143143

144-
inline template <typename type>
145-
type Cpu::Xor(type data1, type data2) {
144+
template <typename type>
145+
inline type Cpu::Xor(type data1, type data2) {
146146
type result = data1 ^ data2;
147147
this->UpdateEflagsForAnd(result);
148148
return result;
149149
}
150150

151-
inline template <typename type>
152-
type Cpu::Or(type data1, type data2) {
151+
template <typename type>
152+
inline type Cpu::Or(type data1, type data2) {
153153
this->UpdateEflagsForAnd((type)(data1 | data2));
154154
return data1 | data2;
155155
}
156156

157-
inline template <typename type>
158-
type Cpu::And(type data1, type data2) {
157+
template <typename type>
158+
inline type Cpu::And(type data1, type data2) {
159159
this->UpdateEflagsForAnd((type)(data1 & data2));
160160
return data1 & data2;
161161
}
162162

163-
inline template <typename type>
164-
type Cpu::Add(type data1, type data2) {
163+
template <typename type>
164+
inline type Cpu::Add(type data1, type data2) {
165165
this->UpdateEflagsForAdd(data1, data2);
166166
return data1 + data2;
167167
}
168168

169-
inline template <typename type>
170-
type Cpu::Sub(type data1, type data2) {
169+
template <typename type>
170+
inline type Cpu::Sub(type data1, type data2) {
171171
this->UpdateEflagsForSub(data1, data2);
172172
return data1 - data2;
173173
}
174174

175-
inline template <typename type>
176-
void Cpu::UpdateEflagsForSub(type data1, type data2) {
175+
template <typename type>
176+
inline void Cpu::UpdateEflagsForSub(type data1, type data2) {
177177
this->UpdateZF((type)(data1 - data2));
178178
this->UpdatePF(data1 - data2);
179179
this->UpdateSF((type)(data1 - data2));
@@ -245,8 +245,8 @@ void Cpu::UpdateEflagsForAdc(type d1, type d2, type c) {
245245
}
246246
}
247247

248-
inline template <typename type>
249-
void Cpu::UpdateEflagsForAdd(type d1, type d2) {
248+
template <typename type>
249+
inline void Cpu::UpdateEflagsForAdd(type d1, type d2) {
250250
this->UpdateZF((type)(d1 + d2));
251251
this->UpdateSF((type)(d1 + d2));
252252
this->UpdatePF((type)(d1 + d2));
@@ -561,15 +561,15 @@ void Cpu::Scas(type data) {
561561
}
562562
}
563563

564-
inline template <typename type>
565-
void Cpu::UpdateEflagsForShr(type result) {
564+
template <typename type>
565+
inline void Cpu::UpdateEflagsForShr(type result) {
566566
this->UpdateZF((uint32_t)result);
567567
this->UpdateSF(result);
568568
this->UpdatePF((uint32_t)result);
569569
}
570570

571-
inline template <typename type>
572-
void Cpu::UpdateOF_Add(type result, type d1, type d2) {
571+
template <typename type>
572+
inline void Cpu::UpdateOF_Add(type result, type d1, type d2) {
573573
switch (sizeof(result)) {
574574
case 1:
575575
this->eflags.flgs.OF = ((d1 & SIGN_FLG1) == (d2 & SIGN_FLG1)) &&
@@ -589,8 +589,8 @@ void Cpu::UpdateOF_Add(type result, type d1, type d2) {
589589
}
590590
}
591591

592-
inline template <typename type>
593-
void Cpu::UpdateCfForSub(type data, int group) {
592+
template <typename type>
593+
inline void Cpu::UpdateCfForSub(type data, int group) {
594594
switch (group) {
595595
case 1:
596596
this->eflags.flgs.CF = ((data >> 8) & 1) ? 1 : 0;
@@ -608,8 +608,8 @@ void Cpu::UpdateCfForSub(type data, int group) {
608608
}
609609
}
610610

611-
inline template <typename type>
612-
void Cpu::UpdateSF(type data) {
611+
template <typename type>
612+
inline void Cpu::UpdateSF(type data) {
613613
switch (sizeof(data)) {
614614
case 1:
615615
this->eflags.flgs.SF = ((data & SIGN_FLG1) == SIGN_FLG1) ? 1 : 0;
@@ -627,17 +627,17 @@ void Cpu::UpdateSF(type data) {
627627
}
628628
}
629629

630-
inline template <typename type>
631-
void Cpu::UpdateEflagsForAnd(type data) {
630+
template <typename type>
631+
inline void Cpu::UpdateEflagsForAnd(type data) {
632632
this->ClearFlag(CF);
633633
this->ClearFlag(OF);
634634
this->UpdateSF(data);
635635
this->UpdateZF(data);
636636
this->UpdatePF(data);
637637
}
638638

639-
inline template <typename type>
640-
void Cpu::UpdateEflagsForUnsignedMul(type data) {
639+
template <typename type>
640+
inline void Cpu::UpdateEflagsForUnsignedMul(type data) {
641641
if (data == 0) {
642642
this->ClearFlag(OF);
643643
this->ClearFlag(CF);

include/detail/Fifo.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include "../Fifo.h"
22

3-
inline template <typename type>
4-
bool Fifo<type>::IsEmpty() {
3+
template <typename type>
4+
inline bool Fifo<type>::IsEmpty() {
55
std::lock_guard<std::mutex> lock(this->fifo_mtx);
66
return this->q.empty();
77
}
88

9-
inline template <typename type>
10-
type Fifo<type>::Pop() {
9+
template <typename type>
10+
inline type Fifo<type>::Pop() {
1111
type element;
1212
if (this->IsEmpty()) {
1313
return element;
@@ -18,8 +18,8 @@ type Fifo<type>::Pop() {
1818
return element;
1919
}
2020

21-
inline template <typename type>
22-
void Fifo<type>::Push(const type data) {
21+
template <typename type>
22+
inline void Fifo<type>::Push(const type data) {
2323
std::lock_guard<std::mutex> lock(this->fifo_mtx);
2424
if (this->q.size() == 16) {
2525
return;
@@ -28,8 +28,8 @@ void Fifo<type>::Push(const type data) {
2828
return;
2929
}
3030

31-
inline template <typename type>
32-
type Fifo<type>::Front() { //読み込むだけ
31+
template <typename type>
32+
inline type Fifo<type>::Front() { //読み込むだけ
3333
type element;
3434
if (this->IsEmpty()) {
3535
return element;

include/detail/Memory.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "../Memory.h"
22

3-
inline template <typename type>
4-
void Memory::Write(const uint32_t addr, const type data) {
3+
template <typename type>
4+
inline void Memory::Write(const uint32_t addr, const type data) {
55
if ((mem_size_ - sizeof(data) + 1) <= addr) {
66
return;
77
}

0 commit comments

Comments
 (0)