diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000..2f3694f
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,19 @@
+name: Build x86 emulator
+
+on: [push,pull_request]
+
+jobs:
+ build1:
+ name: Build x86 emulator on Linux
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - uses: libsdl-org/setup-sdl@main
+ id: sdl
+ with:
+ install-linux-dependencies: true
+ version: 2.30.9
+ - name: Generate build system
+ run: cmake .
+ - name: Build
+ run: cmake --build .
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d92facb
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+build/
+.DS_Store
+.vscode
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..82bbd53
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,17 @@
+cmake_minimum_required(VERSION 3.26.0)
+
+find_package(SDL2 CONFIG REQUIRED)
+
+project(X86_EMULATOR)
+
+file(GLOB SOURCES src/*.cpp)
+
+add_executable(x86
+ ${SOURCES}
+)
+
+target_link_libraries(x86 ${SDL2_LIBRARIES})
+target_include_directories(x86 PUBLIC
+ ${SDL2_INCLUDE_DIRS}
+)
+target_include_directories(x86 PRIVATE include SDL2)
diff --git a/Makefile b/Makefile
deleted file mode 100644
index e6fbf7c..0000000
--- a/Makefile
+++ /dev/null
@@ -1,52 +0,0 @@
-.PHONY:clean build all test format
-
-EMULATOR = x86
-EMULATOR_TEST = x86_test
-
-CC = clang++
-
-#G++_OPTIONS = -std=c++14 -O3 -g -I $(INCLUDE_DIR) -arch arm64
-#G++_OPTIONS_DEBUG = -Wall -std=c++14 -O0 -g -I $(INCLUDE_DIR) -DDEBUG -arch arm64
-#LD_FLGS += -lSDL2 -arch arm64
-
-G++_OPTIONS = -std=c++14 -O3 -I $(INCLUDE_DIR)
-G++_OPTIONS_DEBUG = -Wall -std=c++14 -O0 -g -I $(INCLUDE_DIR) -DDEBUG
-LD_FLGS += -lSDL2
-
-
-SOURCE_DIR = ./src/
-INCLUDE_DIR = ./include/
-DETAIL_INCLUDE_DIR = ./include/detail/
-
-HEADERS = $(wildcard $(INCLUDE_DIR)*.h)
-DETAIL_HEADERS = $(wildcard $(DETAIL_INCLUDE_DIR)*.h)
-
-SOURCES = $(wildcard $(SOURCE_DIR)*.cpp)
-OBJECTS = $(SOURCES:.cpp=.o)
-OBJECTS_DEBUG = $(SOURCES:.cpp=.test.o)
-
-all:$(EMULATOR)
-
-%.o : %.cpp $(HEADERS) $(DETAIL_HEADERS)
- $(CC) $(G++_OPTIONS) -o $@ -c $<
-
-
-$(EMULATOR) : $(OBJECTS)
- $(CC) $(LD_FLGS) -o $(OUTPUTS_DIR)$(EMULATOR) $^
-
-%.test.o : %.cpp $(HEADERS) $(DETAIL_HEADERS)
- $(CC) $(G++_OPTIONS_DEBUG) -o $@ -c $<
-
-x86_test : $(OBJECTS_DEBUG)
- $(CC) $(LD_FLGS) -o $(EMULATOR_TEST) $^
-
-clean :
- rm -f $(OUTPUTS_DIR)$(EMULATOR)
- rm -f $(SOURCE_DIR)*.o
-
-
-#https://stackoverflow.com/questions/28896909/how-to-call-clang-format-over-a-cpp-project-folder
-#以下のコマンドでフォーマットできるらしい。詳細は上のURLを見て。
-format :
- find include/ -iname *.h -o -iname *.cpp | xargs clang-format -i
- find src/ -iname *.h -o -iname *.cpp | xargs clang-format -i
\ No newline at end of file
diff --git a/README.md b/README.md
index a2eb6a8..e854894 100644
--- a/README.md
+++ b/README.md
@@ -98,8 +98,10 @@
Build
-```
-make
+```bash
+mkdir build
+cmake ..
+cmake --build .
```
Run
diff --git a/include/Cpu.h b/include/Cpu.h
index 2d6f556..d5c3417 100644
--- a/include/Cpu.h
+++ b/include/Cpu.h
@@ -24,13 +24,13 @@ class DescriptorTableRegister;
#define DPL 0x60 // access_rightのDPLの該当部分
namespace CpuHelper {
-inline template
-uint8_t GetDpl(type data) {
+template
+inline uint8_t GetDpl(type data) {
return (data & DPL) >> 5;
}
-inline template
-uint8_t GetRpl(type data) {
+template
+inline uint8_t GetRpl(type data) {
return data & 0x03;
}
} // namespace CpuHelper
diff --git a/include/common.h b/include/common.h
index 1dbbdac..d9d8a39 100644
--- a/include/common.h
+++ b/include/common.h
@@ -1,4 +1,5 @@
#pragma once
+#include
#include
#include
#include
diff --git a/include/detail/Cpu.h b/include/detail/Cpu.h
index 0fdf6ed..ed9e02d 100644
--- a/include/detail/Cpu.h
+++ b/include/detail/Cpu.h
@@ -96,8 +96,8 @@ type Cpu::Inc(type data) {
return data + 1;
}
-inline template
-void Cpu::UpdateEflagsForInc(type d) {
+template
+inline void Cpu::UpdateEflagsForInc(type d) {
type result = (type)(d + 1);
this->UpdateZF(result);
this->UpdateSF(result);
@@ -112,8 +112,8 @@ type Cpu::Dec(type data) {
return result;
}
-inline template
-void Cpu::UpdateEflagsForDec(type result, type d1, type d2) {
+template
+inline void Cpu::UpdateEflagsForDec(type result, type d1, type d2) {
this->UpdateZF(result);
this->UpdateSF(result);
this->UpdatePF(result);
@@ -134,46 +134,46 @@ void Cpu::UpdateEflagsForDec(type result, type d1, type d2) {
}
}
-inline template
-type Cpu::Adc(type data1, type data2) {
+template
+inline type Cpu::Adc(type data1, type data2) {
type carry = this->IsFlag(CF) ? 1 : 0;
this->UpdateEflagsForAdc(data1, data2, carry);
return data1 + data2 + carry;
}
-inline template
-type Cpu::Xor(type data1, type data2) {
+template
+inline type Cpu::Xor(type data1, type data2) {
type result = data1 ^ data2;
this->UpdateEflagsForAnd(result);
return result;
}
-inline template
-type Cpu::Or(type data1, type data2) {
+template
+inline type Cpu::Or(type data1, type data2) {
this->UpdateEflagsForAnd((type)(data1 | data2));
return data1 | data2;
}
-inline template
-type Cpu::And(type data1, type data2) {
+template
+inline type Cpu::And(type data1, type data2) {
this->UpdateEflagsForAnd((type)(data1 & data2));
return data1 & data2;
}
-inline template
-type Cpu::Add(type data1, type data2) {
+template
+inline type Cpu::Add(type data1, type data2) {
this->UpdateEflagsForAdd(data1, data2);
return data1 + data2;
}
-inline template
-type Cpu::Sub(type data1, type data2) {
+template
+inline type Cpu::Sub(type data1, type data2) {
this->UpdateEflagsForSub(data1, data2);
return data1 - data2;
}
-inline template
-void Cpu::UpdateEflagsForSub(type data1, type data2) {
+template
+inline void Cpu::UpdateEflagsForSub(type data1, type data2) {
this->UpdateZF((type)(data1 - data2));
this->UpdatePF(data1 - data2);
this->UpdateSF((type)(data1 - data2));
@@ -245,8 +245,8 @@ void Cpu::UpdateEflagsForAdc(type d1, type d2, type c) {
}
}
-inline template
-void Cpu::UpdateEflagsForAdd(type d1, type d2) {
+template
+inline void Cpu::UpdateEflagsForAdd(type d1, type d2) {
this->UpdateZF((type)(d1 + d2));
this->UpdateSF((type)(d1 + d2));
this->UpdatePF((type)(d1 + d2));
@@ -561,15 +561,15 @@ void Cpu::Scas(type data) {
}
}
-inline template
-void Cpu::UpdateEflagsForShr(type result) {
+template
+inline void Cpu::UpdateEflagsForShr(type result) {
this->UpdateZF((uint32_t)result);
this->UpdateSF(result);
this->UpdatePF((uint32_t)result);
}
-inline template
-void Cpu::UpdateOF_Add(type result, type d1, type d2) {
+template
+inline void Cpu::UpdateOF_Add(type result, type d1, type d2) {
switch (sizeof(result)) {
case 1:
this->eflags.flgs.OF = ((d1 & SIGN_FLG1) == (d2 & SIGN_FLG1)) &&
@@ -589,8 +589,8 @@ void Cpu::UpdateOF_Add(type result, type d1, type d2) {
}
}
-inline template
-void Cpu::UpdateCfForSub(type data, int group) {
+template
+inline void Cpu::UpdateCfForSub(type data, int group) {
switch (group) {
case 1:
this->eflags.flgs.CF = ((data >> 8) & 1) ? 1 : 0;
@@ -608,8 +608,8 @@ void Cpu::UpdateCfForSub(type data, int group) {
}
}
-inline template
-void Cpu::UpdateSF(type data) {
+template
+inline void Cpu::UpdateSF(type data) {
switch (sizeof(data)) {
case 1:
this->eflags.flgs.SF = ((data & SIGN_FLG1) == SIGN_FLG1) ? 1 : 0;
@@ -627,8 +627,8 @@ void Cpu::UpdateSF(type data) {
}
}
-inline template
-void Cpu::UpdateEflagsForAnd(type data) {
+template
+inline void Cpu::UpdateEflagsForAnd(type data) {
this->ClearFlag(CF);
this->ClearFlag(OF);
this->UpdateSF(data);
@@ -636,8 +636,8 @@ void Cpu::UpdateEflagsForAnd(type data) {
this->UpdatePF(data);
}
-inline template
-void Cpu::UpdateEflagsForUnsignedMul(type data) {
+template
+inline void Cpu::UpdateEflagsForUnsignedMul(type data) {
if (data == 0) {
this->ClearFlag(OF);
this->ClearFlag(CF);
diff --git a/include/detail/Fifo.h b/include/detail/Fifo.h
index 2444230..14a5993 100644
--- a/include/detail/Fifo.h
+++ b/include/detail/Fifo.h
@@ -1,13 +1,13 @@
#include "../Fifo.h"
-inline template
-bool Fifo::IsEmpty() {
+template
+inline bool Fifo::IsEmpty() {
std::lock_guard lock(this->fifo_mtx);
return this->q.empty();
}
-inline template
-type Fifo::Pop() {
+template
+inline type Fifo::Pop() {
type element;
if (this->IsEmpty()) {
return element;
@@ -18,8 +18,8 @@ type Fifo::Pop() {
return element;
}
-inline template
-void Fifo::Push(const type data) {
+template
+inline void Fifo::Push(const type data) {
std::lock_guard lock(this->fifo_mtx);
if (this->q.size() == 16) {
return;
@@ -28,8 +28,8 @@ void Fifo::Push(const type data) {
return;
}
-inline template
-type Fifo::Front() { //読み込むだけ
+template
+inline type Fifo::Front() { //読み込むだけ
type element;
if (this->IsEmpty()) {
return element;
diff --git a/include/detail/Memory.h b/include/detail/Memory.h
index 7b20098..ab6b3d6 100644
--- a/include/detail/Memory.h
+++ b/include/detail/Memory.h
@@ -1,7 +1,7 @@
#include "../Memory.h"
-inline template
-void Memory::Write(const uint32_t addr, const type data) {
+template
+inline void Memory::Write(const uint32_t addr, const type data) {
if ((mem_size_ - sizeof(data) + 1) <= addr) {
return;
}