diff --git a/.DS_Store b/.DS_Store
index 30bbf75..046bc22 100644
Binary files a/.DS_Store and b/.DS_Store differ
diff --git a/plasm2.xcodeproj/project.xcworkspace/xcuserdata/noahwooten.xcuserdatad/UserInterfaceState.xcuserstate b/plasm2.xcodeproj/project.xcworkspace/xcuserdata/noahwooten.xcuserdatad/UserInterfaceState.xcuserstate
index 7f0f09f..43ce7f9 100644
Binary files a/plasm2.xcodeproj/project.xcworkspace/xcuserdata/noahwooten.xcuserdatad/UserInterfaceState.xcuserstate and b/plasm2.xcodeproj/project.xcworkspace/xcuserdata/noahwooten.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/plasm2.xcodeproj/xcuserdata/noahwooten.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/plasm2.xcodeproj/xcuserdata/noahwooten.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
new file mode 100644
index 0000000..880da93
--- /dev/null
+++ b/plasm2.xcodeproj/xcuserdata/noahwooten.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
@@ -0,0 +1,6 @@
+
+
+
diff --git a/plasm2_asm/cg/cg_compile.c b/plasm2_asm/cg/basetypes.h cg link main.c plasm2_asm.vcxproj plasm2_asm.vcxproj.filters plasm2_asm.vcxproj.user psin2 vf.c
similarity index 100%
rename from plasm2_asm/cg/cg_compile.c
rename to plasm2_asm/cg/basetypes.h cg link main.c plasm2_asm.vcxproj plasm2_asm.vcxproj.filters plasm2_asm.vcxproj.user psin2 vf.c
diff --git a/plasm2_emu/cpu/cpu.h b/plasm2_emu/cpu/cpu.h
index a42af10..818bb8d 100644
--- a/plasm2_emu/cpu/cpu.h
+++ b/plasm2_emu/cpu/cpu.h
@@ -1,6 +1,7 @@
#pragma once
#include "../basetypes.h"
#include
+
/*
cpu.h
plasm2
@@ -148,7 +149,7 @@ extern void(*Instructions[256])(void);
#define REGCOUNT_SPEC 16
#define REGCOUNT_TOTAL REGCOUNT_GPRS + REGCOUNT_SPEC
-struct {
+typedef struct _PLASM2_CTX {
union {
union {
u64 rs_64[REGCOUNT_TOTAL];
@@ -203,7 +204,8 @@ struct {
}pti;
};
};
-}i[1];
+}PLASM2_CTX, *PPLASM2_CTX;
+extern PPLASM2_CTX i;
void cpui_csm_set(u64 Handler);
void cpui_csm_msg(byte Code, u64 AddtData);
diff --git a/plasm2_emu/cpu/cpu_inst.c b/plasm2_emu/cpu/cpu_inst.c
index f6c4b47..91c7953 100644
--- a/plasm2_emu/cpu/cpu_inst.c
+++ b/plasm2_emu/cpu/cpu_inst.c
@@ -34,7 +34,7 @@ void cpui_inst_cll(u64 Address) {
SecurityPacket.Flags = (u32)i->flags;
SecurityPacket.SecurityLevel = i->security_s.SecurityLevel;
mmu_push(SecurityPacket.Raw);
- i->flags_s.SF = 1;
+ i->flags_s.SF = 1;
i->ip = Address;
i->flags_s.CF = 1;
return;
@@ -71,7 +71,6 @@ void cpui_inst_int(byte Interrupt) {
u64* InterruptTable = (u64*)((byte*)cpuctx->PhysicalMemory + i->pti.it); // PM usage good (reason: pti.it is a secure register)
u64 VirtualAddress = InterruptTable[Interrupt];
byte SecurityLevel = (byte)((VirtualAddress & 0xFF00000000000000LLU) >> 56LLU);
- byte BackupLevel = i->security_s.SecurityLevel;
i->security_s.SecurityLevel = SecurityLevel;
u64 PhysicalAddress = mmu_translate(VirtualAddress & 0x00FFFFFFFFFFFFFF, REASON_EXEC | REASON_READ, SIZE_WATCHDOG);
if (!PhysicalAddress) {
@@ -96,4 +95,4 @@ void cpui_inst_int(byte Interrupt) {
i->flags_s.SF = 1;
i->ip = PhysicalAddress;
return;
-}
\ No newline at end of file
+}
diff --git a/plasm2_emu/cpu/mmu/mmu_io.c b/plasm2_emu/cpu/mmu/mmu_io.c
index 0fa9d3b..e5419a0 100644
--- a/plasm2_emu/cpu/mmu/mmu_io.c
+++ b/plasm2_emu/cpu/mmu/mmu_io.c
@@ -51,10 +51,10 @@ void mmu_put1(u64 Address, byte Value) {
}
void mmu_put4(u64 Address, u32 Value) {
- u32* PhysicalBytes = (byte*)((byte*)cpuctx->PhysicalMemory + Address); // PM usage good (reason: comes from trust)
+ u32* PhysicalBytes = (u32*)((byte*)cpuctx->PhysicalMemory + Address); // PM usage good (reason: comes from trust)
if (Address > PHYS_MEMSZ)
i->flags_s.XF = 1;
else
PhysicalBytes[0] = Value;
return;
-}
\ No newline at end of file
+}
diff --git a/plasm2_emu/devices/fdisk/fdisk_init.c b/plasm2_emu/devices/fdisk/fdisk_init.c
index 19dc67f..230601e 100644
--- a/plasm2_emu/devices/fdisk/fdisk_init.c
+++ b/plasm2_emu/devices/fdisk/fdisk_init.c
@@ -1,5 +1,5 @@
#include "fdisk.h"
-#include "../cpu/cpu.h"
+#include "../../cpu/cpu.h"
#include
#include
/*
@@ -105,4 +105,4 @@ void fdisk_clock(void) {
}
// write cache
-}
\ No newline at end of file
+}
diff --git a/plasm2_emu/devices/fdisk/fdisk_native.c b/plasm2_emu/devices/fdisk/fdisk_native.c
index caeb6d9..ba89da9 100644
--- a/plasm2_emu/devices/fdisk/fdisk_native.c
+++ b/plasm2_emu/devices/fdisk/fdisk_native.c
@@ -177,7 +177,7 @@ void fdiski_drivegetvendorsz(int DriveId, u64 Pointer) {
return;
u64 RPointer = mmu_translate(Pointer, REASON_WRTE, 16);
- char* TPointer = ((byte*)cpuctx->PhysicalMemory + RPointer);
+ byte* TPointer = ((byte*)cpuctx->PhysicalMemory + RPointer);
memcpy(TPointer, fdiskctx->Drives[DriveId].DeviceVendor, 16);
return;
@@ -283,4 +283,4 @@ void fdiski_drivewritestack(int DriveId, u64 Data) {
fdiskctx->Drives[DriveId].CurrentFilePointer = CFPBackup;
return;
-}
\ No newline at end of file
+}
diff --git a/plasm2_emu/devices/sdbg/sdbg_init.c b/plasm2_emu/devices/sdbg/sdbg_init.c
index 375fed8..1c9a7b8 100644
--- a/plasm2_emu/devices/sdbg/sdbg_init.c
+++ b/plasm2_emu/devices/sdbg/sdbg_init.c
@@ -1,6 +1,6 @@
#include "sdbg.h"
-#include "../emu.h"
-#include "../cpu/cpu.h"
+#include "../../emu.h"
+#include "../../cpu/cpu.h"
#include
#include
/*
@@ -61,4 +61,4 @@ void sdbg_collect(void) {
devicesctx->DeviceCount++;
return;
-}
\ No newline at end of file
+}
diff --git a/plasm2_emu/devices/sdbg/sdbg_natives.c b/plasm2_emu/devices/sdbg/sdbg_natives.c
index 1024b26..496bc58 100644
--- a/plasm2_emu/devices/sdbg/sdbg_natives.c
+++ b/plasm2_emu/devices/sdbg/sdbg_natives.c
@@ -1,6 +1,6 @@
#include "sdbg.h"
-#include "../cpu/cpu.h"
-#include "../cpu/mmu/mmu.h"
+#include "../../cpu/cpu.h"
+#include "../../cpu/mmu/mmu.h"
#include
/*
sdbg_natives.c
@@ -30,4 +30,4 @@ void sdbg_setsendloc(u64 Location) {
void sdbg_setsendsz(u64 Size) {
sdbgctx->VirtualSize = Size;
return;
-}
\ No newline at end of file
+}
diff --git a/plasm2_emu/devices/video/video_init.c b/plasm2_emu/devices/video/video_init.c
index e763db3..9b54b90 100644
--- a/plasm2_emu/devices/video/video_init.c
+++ b/plasm2_emu/devices/video/video_init.c
@@ -18,7 +18,6 @@ byte PauseDrawing;
videoctx_t* videoctx;
SDL_Thread* LoopThread;
-
#pragma warning(disable: 6011 6387)
void videoii_loop(void);
@@ -67,4 +66,4 @@ void videoii_loop(void) {
SDL_RenderPresent(Renderer);
SDL_Delay(16);
}
-}
\ No newline at end of file
+}
diff --git a/plasm2_emu/main.c b/plasm2_emu/main.c
index 4d1dd5f..0d2e5af 100644
--- a/plasm2_emu/main.c
+++ b/plasm2_emu/main.c
@@ -11,7 +11,6 @@
#include "psin2/psin2.h"
#include "decoder/decoder.h"
#include "tools/tools.h"
-
#pragma warning(disable: 6308 6387 26451 28182)
/*
@@ -19,7 +18,7 @@ main.c
plasm2
plasm2_emu
(c) Noah Wooten 2023, All Rights Reserved
-*/
+*/
/*
Starting physical memory map:
@@ -34,8 +33,11 @@ Starting physical memory map:
0x25F0: End of stack
*/
+int __t_argc;
+char** __t_argv;
+PPLASM2_CTX i;
+
int main(int argc, char** argv) {
- //fgetc(stdin);
FILE* a = freopen("rstd", "w", stdout);
emu_init();
@@ -44,7 +46,7 @@ int main(int argc, char** argv) {
char** FixedDisks = NULL;
int FixedDiskCount = 0;
- for (int i = 0; i < argc; i++) {
+ for (int i = 1; i < argc; i++) {
if (strstr(argv[i], "-d") || strstr(argv[i], "--debug")) {
emuctx->DebuggerEnabled = 1;
}
@@ -60,7 +62,7 @@ int main(int argc, char** argv) {
printf("Misc Switches: (General Function Only)\n\n");
printf("%s -d | --debug : Enables disassembler / debugger mode.\n", argv[0]);
printf("%s -h | --help : Shows this screen.\n", argv[0]);
-
+
printf("\nBy default, PLASM2Emu accepts a properly formed 'bios.bin'.\n");
return 0;
}
@@ -75,15 +77,18 @@ int main(int argc, char** argv) {
FixedDiskCount++;
}
if (strstr(argv[i], "-t") || strstr(argv[i], "--tools")) {
+ __t_argc = argc;
+ __t_argv = argv;
tools_main();
return 0;
}
}
- cpu_init();
-
+ i = malloc(sizeof(PLASM2_CTX));
memset(i, 0, sizeof(*i));
+ cpu_init();
+
i->pti.dvptr = 0x0000;
i->ip = 0x03A0;
i->pti.slb = 0x24F0;
@@ -158,11 +163,12 @@ int main(int argc, char** argv) {
printf("CPU Halted.\n");
printf("Total Clocks: %llu\n", ClockCnt);
- time_t Diff = (Startdown - Startup) + 1;
- printf("Total Time: %llum %llus\n", Diff / 60, Diff % 60);
+ time_t Diff = (Startdown - Startup) + 1;
+ printf("Total Time: %ldm %lds\n", Diff / 60, Diff % 60);
printf("Clocks Per Sec: %llu\n", (ClockCnt) / (Diff));
fclose(a);
-
+ free(i);
+
return 0;
-}
\ No newline at end of file
+}
diff --git a/plasm2_emu/psin2/psin2_data.c b/plasm2_emu/psin2/psin2_data.c
index 5052268..dfce0ee 100644
--- a/plasm2_emu/psin2/psin2_data.c
+++ b/plasm2_emu/psin2/psin2_data.c
@@ -1,4 +1,3 @@
-#pragma once
#include "psin2.h"
/*
psin2_data.c
@@ -96,4 +95,4 @@ void psin2_load(void) {
psin2_parse("__SIT = 0x96, // SIT 96 (R:04,08 IHNDLR) 16 : Set Interrupt Table");
return;
-}
\ No newline at end of file
+}
diff --git a/plasm2_emu/psin2/psin2_parse.c b/plasm2_emu/psin2/psin2_parse.c
index 4e34dab..a5754c5 100644
--- a/plasm2_emu/psin2/psin2_parse.c
+++ b/plasm2_emu/psin2/psin2_parse.c
@@ -1,4 +1,3 @@
-#pragma once
#include
#include
#include
@@ -146,4 +145,4 @@ int psin2_parse(const char* InstructionData) {
int psin2_getcnt(void) {
return psin2ctx->InstructionCount;
-}
\ No newline at end of file
+}
diff --git a/plasm2_emu/tools/tools_bootldr.c b/plasm2_emu/tools/tools_bootldr.c
index 248c775..78a72e6 100644
--- a/plasm2_emu/tools/tools_bootldr.c
+++ b/plasm2_emu/tools/tools_bootldr.c
@@ -34,6 +34,9 @@ typedef struct _bootimg {
#define BOOTLDRFLAG_SAVE 0x01
#define BOOTLDRFLAG_LOAD 0x02
+extern int __t_argc;
+extern char** __t_argv;
+
void toolsi_bootloader(void) {
char* Strbuf = malloc(240);
@@ -161,4 +164,4 @@ void toolsi_bootloader(void) {
printf("Success!\n");
return;
-}
\ No newline at end of file
+}
diff --git a/plasm2_emu/tools/tools_fontgen.c b/plasm2_emu/tools/tools_fontgen.c
index e44c509..c6a6d37 100644
--- a/plasm2_emu/tools/tools_fontgen.c
+++ b/plasm2_emu/tools/tools_fontgen.c
@@ -10,9 +10,6 @@ plasm2_emu
(c) Noah Wooten 2023, All Rights Reserved
*/
-SDL_Window* Window;
-SDL_Renderer* Renderer;
-
#pragma warning(disable: 6011)
#define SINGLE_GET(Single, Bit) (Single & (1LLU << Bit)) >> Bit
@@ -79,8 +76,8 @@ void toolsi_fontgen(void) {
return;
}
- SDL_Window* Window = SDL_CreateWindow("PLASM2 Font Generator", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 257, 640, 0);
- SDL_Renderer* Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_ACCELERATED);
+ SDL_Window* FontWindow = SDL_CreateWindow("PLASM2 Font Generator", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 257, 640, 0);
+ SDL_Renderer* FontRenderer = SDL_CreateRenderer(FontWindow, -1, SDL_RENDERER_ACCELERATED);
char Quit = 0;
while (!Quit) {
@@ -111,19 +108,19 @@ void toolsi_fontgen(void) {
if (Quit)
break;
- SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 255);
- SDL_RenderClear(Renderer);
+ SDL_SetRenderDrawColor(FontRenderer, 0, 0, 0, 255);
+ SDL_RenderClear(FontRenderer);
- SDL_SetRenderDrawColor(Renderer, 200, 200, 200, 255);
+ SDL_SetRenderDrawColor(FontRenderer, 200, 200, 200, 255);
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 16; y++) {
SDL_Rect Rectangle = { (x * 32) + 1, (y * 32) + 1, 31, 31 };
if (Bitmap[CurrentChar][(y * 8) + x]) {
- SDL_SetRenderDrawColor(Renderer, 220, 220, 220, 255);
- SDL_RenderFillRect(Renderer, &Rectangle);
- SDL_SetRenderDrawColor(Renderer, 200, 200, 200, 255);
+ SDL_SetRenderDrawColor(FontRenderer, 220, 220, 220, 255);
+ SDL_RenderFillRect(FontRenderer, &Rectangle);
+ SDL_SetRenderDrawColor(FontRenderer, 200, 200, 200, 255);
}
- SDL_RenderDrawRect(Renderer, &Rectangle);
+ SDL_RenderDrawRect(FontRenderer, &Rectangle);
if (InRange(MousePos[0], Rectangle.x, Rectangle.x + Rectangle.w)) {
if (InRange(MousePos[1], Rectangle.y, Rectangle.y + Rectangle.h)) {
if (IsMouseDown[0])
@@ -136,8 +133,8 @@ void toolsi_fontgen(void) {
}
for (int b = 0; b < 2; b++) {
SDL_Rect Rectangle = { 1 + (1 * b) + (127 * b), 523, 128, 127 };
- SDL_SetRenderDrawColor(Renderer, 200, 200, 200, 255);
- SDL_RenderDrawRect(Renderer, &Rectangle);
+ SDL_SetRenderDrawColor(FontRenderer, 200, 200, 200, 255);
+ SDL_RenderDrawRect(FontRenderer, &Rectangle);
if (InRange(MousePos[0], Rectangle.x, Rectangle.x + Rectangle.w)) {
if (InRange(MousePos[1], Rectangle.y, Rectangle.y + Rectangle.h) && IsMouseDown[0]) {
@@ -151,11 +148,11 @@ void toolsi_fontgen(void) {
}
if (b) {
- SDL_RenderDrawLine(Renderer, Rectangle.x + 20, Rectangle.y + 20, Rectangle.x + 107, Rectangle.y + 64);
- SDL_RenderDrawLine(Renderer, Rectangle.x + 107, Rectangle.y + 64, Rectangle.x + 20, Rectangle.y + 97);
+ SDL_RenderDrawLine(FontRenderer, Rectangle.x + 20, Rectangle.y + 20, Rectangle.x + 107, Rectangle.y + 64);
+ SDL_RenderDrawLine(FontRenderer, Rectangle.x + 107, Rectangle.y + 64, Rectangle.x + 20, Rectangle.y + 97);
} else {
- SDL_RenderDrawLine(Renderer, Rectangle.x + 20, Rectangle.y + 64, Rectangle.x + 107, Rectangle.y + 97);
- SDL_RenderDrawLine(Renderer, Rectangle.x + 20, Rectangle.y + 64, Rectangle.x + 107, Rectangle.y + 20);
+ SDL_RenderDrawLine(FontRenderer, Rectangle.x + 20, Rectangle.y + 64, Rectangle.x + 107, Rectangle.y + 97);
+ SDL_RenderDrawLine(FontRenderer, Rectangle.x + 20, Rectangle.y + 64, Rectangle.x + 107, Rectangle.y + 20);
}
}
@@ -178,7 +175,7 @@ void toolsi_fontgen(void) {
}
}
- SDL_RenderPresent(Renderer);
+ SDL_RenderPresent(FontRenderer);
SDL_Delay(10);
}
@@ -193,4 +190,4 @@ void toolsi_fontgen(void) {
}
return;
-}
\ No newline at end of file
+}
diff --git a/plasm2_emu/tools/tools_hddgen.c b/plasm2_emu/tools/tools_hddgen.c
index d0c6d90..f12d6ec 100644
--- a/plasm2_emu/tools/tools_hddgen.c
+++ b/plasm2_emu/tools/tools_hddgen.c
@@ -120,7 +120,7 @@ void toolsi_hddgen(void) {
memset(FdHdr, 0, sizeof(fdiskhdr_t));
FdHdr->Magic = FDISKHDR_MAGIC;
- srand((u32)time(NULL));
+ srand(time(NULL) & 0xFFFFFFFF);
FdHdr->DeviceSerial = rand();
FdHdr->DeviceVendorId = 0x4273;
strcpy(FdHdr->DeviceVendor, "PLASM2 HDDGnr8r");
@@ -139,4 +139,4 @@ void toolsi_hddgen(void) {
printf(" Successfully wrote HDD file.\n");
return;
-}
\ No newline at end of file
+}