diff options
-rw-r--r-- | CMakeLists.txt | 25 | ||||
-rw-r--r-- | cartridge.luma | bin | 42 -> 39 bytes | |||
-rw-r--r-- | changelog.md | 14 | ||||
-rw-r--r-- | luma/src/luma.h | 24 | ||||
-rw-r--r-- | luma/src/luma_checkEvts.c (renamed from luma/src/luma_dead.c) | 14 | ||||
-rw-r--r-- | luma/src/luma_dat.c (renamed from luma/src/luma_instrPtr.c) | 2 | ||||
-rw-r--r-- | luma/src/luma_drwVram.c | 40 | ||||
-rw-r--r-- | luma/src/luma_initDat.c (renamed from luma/src/luma_bootlder.c) | 7 | ||||
-rw-r--r-- | luma/src/luma_initWin.c (renamed from luma/src/luma_cart.c) | 9 | ||||
-rw-r--r-- | luma/src/luma_ldBank.c | 2 | ||||
-rw-r--r-- | luma/src/luma_ldBootlder.c | 4 | ||||
-rw-r--r-- | luma/src/luma_proc.c | 173 | ||||
-rw-r--r-- | luma/src/luma_setDbl.c | 2 | ||||
-rw-r--r-- | luma/src/main.c | 33 |
14 files changed, 244 insertions, 105 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 90dacb1..1cf6af2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,10 +30,16 @@ if( ) endif() +# Dependencies: +find_package( + SDL2 + REQUIRED +) + # Include directories: include_directories( "${PROJECT_SOURCE_DIR}/include" - "/home/delta/repos/u8c/u8c/include" + "${SDL2_INCLUDE_DIRS}" ) # Enable compiler warnings: @@ -93,10 +99,11 @@ endif() add_executable( luma "luma/src/luma_abrt.c" - "luma/src/luma_bootlder.c" - "luma/src/luma_cart.c" - "luma/src/luma_dead.c" - "luma/src/luma_instrPtr.c" + "luma/src/luma_checkEvts.c" + "luma/src/luma_dat.c" + "luma/src/luma_drwVram.c" + "luma/src/luma_initDat.c" + "luma/src/luma_initWin.c" "luma/src/luma_ldBank.c" "luma/src/luma_ldBootlder.c" "luma/src/luma_ldRom.c" @@ -106,4 +113,10 @@ add_executable( "luma/src/luma_setByte.c" "luma/src/luma_setDbl.c" "luma/src/main.c" -)
\ No newline at end of file +) + +# Link Libraries: +target_link_libraries( + luma + ${SDL2_LIBRARIES} +) diff --git a/cartridge.luma b/cartridge.luma Binary files differindex 445f59d..35adbc2 100644 --- a/cartridge.luma +++ b/cartridge.luma diff --git a/changelog.md b/changelog.md index 97425d3..b3b1d51 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,17 @@ +# 24 + +* Depend on SDL2. +* Remove include directory path. +* Add new instruction: DRW, CPP, STP. +* Implement more instruction: DRW, CPP, STP. +* Fix logger for CPD. +* Create window for visualising VRAM. +* Remove speed limiter. +* Unify all global variables into a struct. +* Fix luma_setDbl. +* Improve some loggers. +* Create new test program. + # 23 * Implement more instructions. diff --git a/luma/src/luma.h b/luma/src/luma.h index 95340fa..e87e905 100644 --- a/luma/src/luma.h +++ b/luma/src/luma.h @@ -20,19 +20,25 @@ #if !defined(luma_hdr_luma) #define luma_hdr_luma +#include <SDL2/SDL.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> -#define luma_ver 0x1B +#define luma_ver 0x1C typedef uint8_t luma_byte; typedef uint16_t luma_dbl; -extern char const * luma_bootlder; -extern char const * luma_cart; -extern bool luma_dead; -extern luma_dbl luma_instrPtr; +typedef struct { + char const * bootlder; + char const * cart; + bool dead; + luma_dbl instrPtr; + SDL_Surface * srf; + SDL_Window * win; +} luma_dattyp; +extern luma_dattyp luma_dat; extern luma_byte luma_mem[0x10000]; /* 65536-bit address space. */ @@ -50,7 +56,10 @@ extern luma_byte luma_mem[0x10000]; /* 65536-bit address space. */ #define luma_getDbl(_addr) ((luma_dbl)(luma_mem[_addr] | ((luma_dbl)(luma_mem[_addr + 0x1]) << 0x8))) _Noreturn void luma_abrt( void); - void luma_initMem( void); + bool luma_checkEvts( void); + void luma_drwVram( void); + void luma_initDat( void); + bool luma_initWin( void); void luma_ldBank( luma_byte num); void luma_ldBootlder(void); void luma_ldRom( char const * file,luma_byte banknum,luma_dbl addr); @@ -59,7 +68,8 @@ _Noreturn void luma_abrt( void); void luma_setByte( luma_dbl addr,luma_byte val); void luma_setDbl( luma_dbl addr,luma_dbl val); -#if defined(NDEBUG) +#define luma_noLog true +#if defined(NDEBUG) || luma_noLog #define luma_log(...) #else #define luma_log(...) (fprintf(stderr,__VA_ARGS__)) diff --git a/luma/src/luma_dead.c b/luma/src/luma_checkEvts.c index 4ee1a59..c1d3231 100644 --- a/luma/src/luma_dead.c +++ b/luma/src/luma_checkEvts.c @@ -19,6 +19,18 @@ #include "luma.h" +#include <SDL2/SDL.h> #include <stdbool.h> -bool luma_dead = false; +bool luma_checkEvts(void) { + SDL_Event evt; + while (SDL_PollEvent(&evt)) { + switch (evt.type) { + default: + break; + case SDL_QUIT: + return true; + } + } + return false; +} diff --git a/luma/src/luma_instrPtr.c b/luma/src/luma_dat.c index 00c8614..358bd08 100644 --- a/luma/src/luma_instrPtr.c +++ b/luma/src/luma_dat.c @@ -19,4 +19,4 @@ #include "luma.h" -luma_dbl luma_instrPtr = 0x0; +luma_dattyp luma_dat; diff --git a/luma/src/luma_drwVram.c b/luma/src/luma_drwVram.c new file mode 100644 index 0000000..4019ff1 --- /dev/null +++ b/luma/src/luma_drwVram.c @@ -0,0 +1,40 @@ +/* + Copyright 2021, 2022 Gabriel Jensen + + This file is part of luma. + + luma is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + luma is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with luma. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include "luma.h" + +#include <SDL2/SDL.h> + +#include <stdio.h> + +void luma_drwVram(void) { + SDL_Rect rect; + rect.w = 0x4; + rect.h = 0x4; + for (luma_dbl y = 0x0;y < 0x80;y += 0x1) { + rect.y = y * 0x4; + for (luma_dbl x = 0x0;x < 0x80;x += 0x1) { + rect.x = x * 0x4; + luma_byte const memVal = luma_mem[0x8000 + x + y * 0x80]; + Uint32 const col = (Uint32)((memVal << 0x10) + (memVal << 0x8) + memVal); + SDL_FillRect(luma_dat.srf,&rect,col); + } + } + SDL_UpdateWindowSurface(luma_dat.win); +} diff --git a/luma/src/luma_bootlder.c b/luma/src/luma_initDat.c index e749dc6..c5c0b02 100644 --- a/luma/src/luma_bootlder.c +++ b/luma/src/luma_initDat.c @@ -19,4 +19,9 @@ #include "luma.h" -char const * luma_bootlder = "bootloader.luma"; +void luma_initDat(void) { + luma_dat.bootlder = "bootloader.luma"; + luma_dat.cart = "cartridge.luma"; + luma_dat.dead = false; + luma_dat.instrPtr = 0x0; +} diff --git a/luma/src/luma_cart.c b/luma/src/luma_initWin.c index c891229..26e5246 100644 --- a/luma/src/luma_cart.c +++ b/luma/src/luma_initWin.c @@ -19,4 +19,11 @@ #include "luma.h" -char const * luma_cart = "cartridge.luma"; +#include <SDL2/SDL.h> + +bool luma_initWin(void) { + SDL_Init(SDL_INIT_VIDEO); + luma_dat.win = SDL_CreateWindow("luma",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,0x200,0x200,0x0); + luma_dat.srf = SDL_GetWindowSurface(luma_dat.win); + return false; +} diff --git a/luma/src/luma_ldBank.c b/luma/src/luma_ldBank.c index c45e876..f1f2616 100644 --- a/luma/src/luma_ldBank.c +++ b/luma/src/luma_ldBank.c @@ -22,5 +22,5 @@ #include <stdio.h> void luma_ldBank(luma_byte const _num) { - luma_ldRom(luma_cart,_num,_num == 0x0 ? 0x2000 : 0x0); + luma_ldRom(luma_dat.cart,_num,_num == 0x0 ? 0x2000 : 0x0); } diff --git a/luma/src/luma_ldBootlder.c b/luma/src/luma_ldBootlder.c index dba2dca..391ff2d 100644 --- a/luma/src/luma_ldBootlder.c +++ b/luma/src/luma_ldBootlder.c @@ -20,6 +20,6 @@ #include "luma.h" void luma_ldBootlder(void) { - luma_log("Loading boot loader \"%s\"\n",luma_bootlder); - luma_ldRom(luma_bootlder,0x0,0x0); + luma_log("Loading boot loader \"%s\"\n",luma_dat.bootlder); + luma_ldRom(luma_dat.bootlder,0x0,0x0); } diff --git a/luma/src/luma_proc.c b/luma/src/luma_proc.c index f2b61b0..ef42ace 100644 --- a/luma/src/luma_proc.c +++ b/luma/src/luma_proc.c @@ -55,6 +55,9 @@ 19 : DVD : ptr ,ptr : DIVIDE DOUBLE 1A : OUT : byte,ptr : OUTPUT 1B : INP : byte,ptr : INPUT + 1C : DRW : : DRAW + 1D : CPP : ptr ,byte : COPY POINTER + 1E : STP : ptr ,byte : SET POINTER */ typedef void (* luma_opcdHandlTer)(void); @@ -78,6 +81,9 @@ static void luma_opcdHandl_jge(void); static void luma_opcdHandl_icd(void); static void luma_opcdHandl_dcd(void); static void luma_opcdHandl_cpd(void); +static void luma_opcdHandl_drw(void); +static void luma_opcdHandl_cpp(void); +static void luma_opcdHandl_stp(void); luma_opcdHandlTer luma_opcdHandls[0x100] = { luma_opcdHandl_ign, @@ -108,9 +114,9 @@ luma_opcdHandlTer luma_opcdHandls[0x100] = { luma_opcdHandl_ilg, luma_opcdHandl_ilg, luma_opcdHandl_ilg, - luma_opcdHandl_ilg, - luma_opcdHandl_ilg, - luma_opcdHandl_ilg, + luma_opcdHandl_drw, + luma_opcdHandl_cpp, + luma_opcdHandl_stp, luma_opcdHandl_ilg, luma_opcdHandl_ilg, luma_opcdHandl_ilg, @@ -339,74 +345,78 @@ luma_opcdHandlTer luma_opcdHandls[0x100] = { }; void luma_proc() { - luma_opcdHandls[luma_mem[luma_instrPtr]](); - luma_instrPtr += 0x1; + luma_opcdHandls[luma_mem[luma_dat.instrPtr]](); + luma_dat.instrPtr += 0x1; } static void luma_opcdHandl_ilg(void) { - fprintf(stderr,"! ILG-%" PRIX8 " @%" PRIX16 "\n",luma_mem[luma_instrPtr],luma_instrPtr); + fprintf(stderr,"! ILG-%" PRIX8 " @%" PRIX16 "\n",luma_mem[luma_dat.instrPtr],luma_dat.instrPtr); } static void luma_opcdHandl_ign(void) {} static void luma_opcdHandl_cpy(void) { - luma_dbl const dest = luma_getDbl(luma_instrPtr + 0x1); - luma_dbl const src = luma_getDbl(luma_instrPtr + 0x3); - luma_log("CPY @%" PRIX16 " %" PRIX16 " %" PRIX16 "\n",luma_instrPtr,src,dest); + luma_dbl const dest = luma_getDbl(luma_dat.instrPtr + 0x1); + luma_dbl const src = luma_getDbl(luma_dat.instrPtr + 0x3); + luma_log("CPY @%" PRIX16 " %" PRIX16 " %" PRIX16 "\n",luma_dat.instrPtr,src,dest); luma_setByte(dest,luma_mem[src]); - luma_instrPtr += 0x4; + luma_dat.instrPtr += 0x4; } static void luma_opcdHandl_set(void) { - luma_dbl const dest = luma_getDbl(luma_instrPtr + 0x1); - luma_byte const val = luma_mem[luma_instrPtr + 0x3]; - luma_log("SET @%" PRIX16 " %" PRIX16 " %" PRIX8 "\n",luma_instrPtr,dest,val); + luma_dbl const dest = luma_getDbl(luma_dat.instrPtr + 0x1); + luma_byte const val = luma_mem[luma_dat.instrPtr + 0x3]; + luma_log("SET @%" PRIX16 " %" PRIX16 " %" PRIX8 "\n",luma_dat.instrPtr,dest,val); luma_setByte(dest,val); - luma_instrPtr += 0x3; + luma_dat.instrPtr += 0x3; } static void luma_opcdHandl_inc(void) { - luma_dbl const addr = luma_getDbl(luma_instrPtr + 0x1); - luma_log("INC %" PRIX16 "\n",addr); - luma_setByte(addr,luma_mem[addr] + 0x1); - luma_instrPtr += 0x2; + luma_dbl const addr = luma_getDbl(luma_dat.instrPtr + 0x1); + luma_byte const val = luma_mem[addr]; + luma_log("INC %" PRIX16 "=%" PRIX8 "\n",addr,val); + luma_setByte(addr,val + 0x1); + luma_dat.instrPtr += 0x2; } static void luma_opcdHandl_dec(void) { - luma_dbl const addr = luma_getDbl(luma_instrPtr + 0x1); - luma_log("DEC %" PRIX16 "\n",addr); - luma_setByte(addr,luma_mem[addr] - 0x1); - luma_instrPtr += 0x2; + luma_dbl const addr = luma_getDbl(luma_dat.instrPtr + 0x1); + luma_byte const val = luma_mem[addr]; + luma_log("DEC %" PRIX16 "=%" PRIX8 "\n",addr,val); + luma_setByte(addr,val - 0x1); + luma_dat.instrPtr += 0x2; } static void luma_opcdHandl_jmp(void) { - luma_dbl const dest = luma_getDbl(luma_instrPtr + 0x1); - luma_log("JMP @%" PRIX16 " %" PRIX16 "\n",luma_instrPtr,dest); - luma_instrPtr = dest - 0x1; /* Compensate for the incremention by luma_proc. */ + luma_dbl const dest = luma_getDbl(luma_dat.instrPtr + 0x1); + luma_log("JMP @%" PRIX16 " %" PRIX16 "\n",luma_dat.instrPtr,dest); + luma_dat.instrPtr = dest - 0x1; /* Compensate for the incremention by luma_proc. */ } static void luma_opcdHandl_die(void) { - luma_log("DIE @%" PRIX16 "\n",luma_instrPtr); - luma_dead = true; + luma_log("DIE @%" PRIX16 "\n",luma_dat.instrPtr); + luma_dat.dead = true; } static void luma_opcdHandl_bnk(void) { - luma_byte const banknum = luma_mem[luma_instrPtr + 0x1]; - luma_log("BNK @%" PRIX16 " %" PRIX8 "\n",luma_instrPtr,banknum); + luma_byte const banknum = luma_mem[luma_dat.instrPtr + 0x1]; + luma_log("BNK @%" PRIX16 " %" PRIX8 "\n",luma_dat.instrPtr,banknum); luma_ldBank(banknum); - luma_instrPtr += 0x1; + luma_dat.instrPtr += 0x1; } static void luma_opcdHandl_trp(void) { - luma_log("TRP @%" PRIX16 "\n",luma_instrPtr); + luma_log("TRP @%" PRIX16 "\n",luma_dat.instrPtr); luma_memDump(); for (;;) {} } static void luma_opcdHandl_cmp(void) { - luma_byte const lval = luma_mem[luma_getDbl(luma_instrPtr + 0x1)]; - luma_byte const rval = luma_mem[luma_getDbl(luma_instrPtr + 0x3)]; - luma_log("CMP @%" PRIX16 " %" PRIX8 " %" PRIX8 ": ",luma_instrPtr,lval,rval); + luma_dbl const laddr = luma_getDbl(luma_dat.instrPtr + 0x1); + luma_dbl const raddr = luma_getDbl(luma_dat.instrPtr + 0x3); + luma_byte const lval = luma_mem[laddr]; + luma_byte const rval = luma_mem[raddr]; + luma_log("CMP @%" PRIX16 " %" PRIX8 "=%" PRIX8 " %" PRIX8 "=%" PRIX8 ": ",luma_dat.instrPtr,laddr,lval,raddr,rval); if (lval < rval) { luma_result = 0x0; } @@ -417,84 +427,96 @@ static void luma_opcdHandl_cmp(void) { luma_result = 0x1; } luma_log("%" PRIX8 "\n",luma_result); - luma_instrPtr += 0x4; + luma_dat.instrPtr += 0x4; } static void luma_opcdHandl_jeq(void) { - luma_log("JEQ @%" PRIX16 ": ",luma_instrPtr); + luma_log("JEQ @%" PRIX16 ": ",luma_dat.instrPtr); if (luma_result == 0x1) { - luma_dbl const dest = luma_getDbl(luma_instrPtr + 0x1); + luma_dbl const dest = luma_getDbl(luma_dat.instrPtr + 0x1); luma_log("%" PRIX16 "\n",dest); - luma_instrPtr = dest - 0x1; /* Compensate for the incremention by luma_proc. */ + luma_dat.instrPtr = dest - 0x1; } else { - luma_log("%" PRIX16 "\n",luma_instrPtr); - luma_instrPtr += 0x2; + luma_log("%" PRIX16 "\n",luma_dat.instrPtr); + luma_dat.instrPtr += 0x2; } } static void luma_opcdHandl_jlt(void) { - luma_log("JLT @%" PRIX16 ": ",luma_instrPtr); + luma_log("JLT @%" PRIX16 ": ",luma_dat.instrPtr); if (luma_result == 0x0) { - luma_dbl const dest = luma_getDbl(luma_instrPtr + 0x1); + luma_dbl const dest = luma_getDbl(luma_dat.instrPtr + 0x1); luma_log("%" PRIX16 "\n",dest); - luma_instrPtr = dest - 0x1; /* Compensate for the incremention by luma_proc. */ + luma_dat.instrPtr = dest - 0x1; } else { - luma_log("%" PRIX16 "\n",luma_instrPtr); - luma_instrPtr += 0x2; + luma_log("%" PRIX16 "\n",luma_dat.instrPtr); + luma_dat.instrPtr += 0x2; } } static void luma_opcdHandl_jgt(void) { - luma_log("JGT @%" PRIX16 ": ",luma_instrPtr); + luma_log("JGT @%" PRIX16 ": ",luma_dat.instrPtr); if (luma_result == 0x2) { - luma_dbl const dest = luma_getDbl(luma_instrPtr + 0x1); + luma_dbl const dest = luma_getDbl(luma_dat.instrPtr + 0x1); luma_log("%" PRIX16 "\n",dest); - luma_instrPtr = dest - 0x1; /* Compensate for the incremention by luma_proc. */ + luma_dat.instrPtr = dest - 0x1; } else { - luma_log("%" PRIX16 "\n",luma_instrPtr); - luma_instrPtr += 0x2; + luma_log("%" PRIX16 "\n",luma_dat.instrPtr); + luma_dat.instrPtr += 0x2; } } static void luma_opcdHandl_jle(void) { - luma_log("JLE @%" PRIX16 ": ",luma_instrPtr); + luma_log("JLE @%" PRIX16 ": ",luma_dat.instrPtr); if (luma_result == 0x0 || luma_result == 0x1) { - luma_dbl const dest = luma_getDbl(luma_instrPtr + 0x1); + luma_dbl const dest = luma_getDbl(luma_dat.instrPtr + 0x1); luma_log("%" PRIX16 "\n",dest); - luma_instrPtr = dest - 0x1; /* Compensate for the incremention by luma_proc. */ + luma_dat.instrPtr = dest - 0x1; } else { - luma_log("%" PRIX16 "\n",luma_instrPtr); - luma_instrPtr += 0x2; + luma_log("%" PRIX16 "\n",luma_dat.instrPtr); + luma_dat.instrPtr += 0x2; } } static void luma_opcdHandl_jge(void) { - luma_log("JGE @%" PRIX16 ": ",luma_instrPtr); + luma_log("JGE @%" PRIX16 ": ",luma_dat.instrPtr); if (luma_result == 0x2 || luma_result == 0x1) { - luma_dbl const dest = luma_getDbl(luma_instrPtr + 0x1); + luma_dbl const dest = luma_getDbl(luma_dat.instrPtr + 0x1); luma_log("%" PRIX16 "\n",dest); - luma_instrPtr = dest - 0x1; /* Compensate for the incremention by luma_proc. */ + luma_dat.instrPtr = dest - 0x1; } else { - luma_log("%" PRIX16 "\n",luma_instrPtr); - luma_instrPtr += 0x2; + luma_log("%" PRIX16 "\n",luma_dat.instrPtr); + luma_dat.instrPtr += 0x2; } } static void luma_opcdHandl_icd(void) { + luma_dbl const addr = luma_getDbl(luma_dat.instrPtr + 0x1); + luma_dbl const val = luma_getDbl(addr); + luma_log("ICD @%" PRIX16 " %" PRIX16 "=%" PRIX16 "\n",luma_dat.instrPtr,addr,val); + luma_setDbl(addr,val + 0x1); + luma_dat.instrPtr += 0x2; } static void luma_opcdHandl_dcd(void) { + luma_dbl const addr = luma_getDbl(luma_dat.instrPtr + 0x1); + luma_dbl const val = luma_getDbl(addr); + luma_log("DCD @%" PRIX16 " %" PRIX16 "=%" PRIX16 "\n",luma_dat.instrPtr,addr,val); + luma_setDbl(addr,val - 0x1); + luma_dat.instrPtr += 0x2; } static void luma_opcdHandl_cpd(void) { - luma_dbl const lval = luma_mem[luma_instrPtr + 0x1]; - luma_dbl const rval = luma_mem[luma_instrPtr + 0x2]; - luma_log("CPD %" PRIX16 " %" PRIX16 ": ",lval,rval); + luma_dbl const laddr = luma_getDbl(luma_dat.instrPtr + 0x1); + luma_dbl const raddr = luma_getDbl(luma_dat.instrPtr + 0x3); + luma_dbl const lval = luma_getDbl(laddr); + luma_dbl const rval = luma_getDbl(raddr); + luma_log("CPD @%" PRIX16 " %" PRIX16 "=%" PRIX16 " %" PRIX16 "=%" PRIX16 ": ",luma_dat.instrPtr,laddr,lval,raddr,rval); if (lval < rval) { luma_result = 0x0; } @@ -505,6 +527,29 @@ static void luma_opcdHandl_cpd(void) { luma_result = 0x1; } luma_log("%" PRIX8 "\n",luma_result); - luma_instrPtr += 0x2; + luma_dat.instrPtr += 0x4; +} + +static void luma_opcdHandl_drw(void) { + luma_log("DRW @%" PRIX16 "\n",luma_dat.instrPtr); + luma_drwVram(); } +static void luma_opcdHandl_cpp(void) { + luma_dbl const destPtr = luma_getDbl(luma_dat.instrPtr + 0x1); + luma_dbl const dest = luma_getDbl(destPtr); + luma_dbl const src = luma_getDbl(luma_dat.instrPtr + 0x3); + luma_byte const srcVal = luma_mem[src]; + luma_log("CPP @%" PRIX16 " %" PRIX16 "=%" PRIX16 " %" PRIX16 "=%" PRIX8 "\n",luma_dat.instrPtr,destPtr,dest,src,srcVal); + luma_setByte(dest,srcVal); + luma_dat.instrPtr += 0x4; +} + +static void luma_opcdHandl_stp(void) { + luma_dbl const destPtr = luma_getDbl(luma_dat.instrPtr + 0x1); + luma_dbl const dest = luma_getDbl(destPtr); + luma_byte const val = luma_mem[luma_dat.instrPtr + 0x3]; + luma_log("STP @%" PRIX16 " %" PRIX16 "=%" PRIX16 " %" PRIX8 "\n",luma_dat.instrPtr,destPtr,dest,val); + luma_setByte(dest,val); + luma_dat.instrPtr += 0x4; +} diff --git a/luma/src/luma_setDbl.c b/luma/src/luma_setDbl.c index 5151abd..2a67e23 100644 --- a/luma/src/luma_setDbl.c +++ b/luma/src/luma_setDbl.c @@ -20,6 +20,6 @@ #include "luma.h" void luma_setDbl(luma_dbl const _addr,luma_dbl const _val) { - luma_setByte(_addr,(luma_byte)(_val >> 0x8)); luma_setByte(_addr,(luma_byte)_val); + luma_setByte(_addr + 0x1,(luma_byte)(_val >> 0x8)); } diff --git a/luma/src/main.c b/luma/src/main.c index 8ff8825..7427f07 100644 --- a/luma/src/main.c +++ b/luma/src/main.c @@ -19,41 +19,34 @@ #include "luma.h" -#include <signal.h> +#include <SDL2/SDL.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/random.h> -#include <time.h> - -static volatile sig_atomic_t luma_hasSig; - -static void luma_sigHandl(int const _sig) { - (void)_sig; - if (luma_hasSig) { - quick_exit(EXIT_FAILURE); /* We must call quick_exit, as the normal exit causes UB when invoked from a signal handler. */ - } - luma_hasSig = 0x1; -} int main(void) { printf("luma %i\n",luma_ver); printf("Copyright 2021, 2022 Gabriel Jensen\n\n"); - signal(SIGINT,luma_sigHandl); + luma_initDat(); memset(luma_mem,0x0,0x10000); /* We initialise all of the memory to zero so the behaviour is not UB. */ + if (luma_initWin()) { + return EXIT_FAILURE; + } luma_ldBootlder(); luma_log("\nBootstrapping...\n"); - struct timespec const sleeptimespec = {.tv_sec = 0x0,.tv_nsec = 0x7D}; /* We want to run at 8Mhz. 0x7D = 125 = 1000000000/8000000 */ - while (!luma_dead) { - if (luma_hasSig) { - luma_dead = true; - break; + while (!luma_dat.dead) { + if (luma_checkEvts()) { + goto stop; } - luma_proc(); getrandom(&luma_rnd,sizeof (luma_byte),GRND_RANDOM); - nanosleep(&sleeptimespec,NULL); + luma_proc(); } + while (!luma_checkEvts()) {} +stop:; #if !defined(NDEBUG) luma_memDump(); #endif + SDL_DestroyWindow(luma_dat.win); + SDL_Quit(); } |