summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt4
-rw-r--r--bootloader.lumabin19 -> 5 bytes
-rw-r--r--cartridge.lumabin5 -> 42 bytes
-rw-r--r--changelog.md9
-rw-r--r--luma/src/luma.h15
-rw-r--r--luma/src/luma_instrPtr.c2
-rw-r--r--luma/src/luma_ldRom.c2
-rw-r--r--luma/src/luma_mem.c4
-rw-r--r--luma/src/luma_proc.c96
-rw-r--r--luma/src/luma_setByte.c8
-rw-r--r--luma/src/luma_setDbl.c2
-rw-r--r--luma/src/main.c8
12 files changed, 113 insertions, 37 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b8c4b21..90dacb1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,7 +7,7 @@ project(
VERSION
24
DESCRIPTION
- "The luma platform."
+ "Reference emulator for the luma platform."
HOMEPAGE_URL
"https://mandelbrot.dk/luma"
LANGUAGES
@@ -15,7 +15,7 @@ project(
)
set(
CMAKE_C_STANDARD
- 99
+ 11
)
# Disable in-souce builds:
diff --git a/bootloader.luma b/bootloader.luma
index ca7508e..c8df2f9 100644
--- a/bootloader.luma
+++ b/bootloader.luma
Binary files differ
diff --git a/cartridge.luma b/cartridge.luma
index 49baf4c..445f59d 100644
--- a/cartridge.luma
+++ b/cartridge.luma
Binary files differ
diff --git a/changelog.md b/changelog.md
index 276ea10..97425d3 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,3 +1,12 @@
+# 23
+
+* Implement more instructions.
+* Update project description.
+* Fix UB in signal handler.
+* Require C11 instead of C99.
+* Add more instructions.
+* Remove sound buffer.
+
# 22
* Fix version number being out of date.
diff --git a/luma/src/luma.h b/luma/src/luma.h
index 5a36a9e..95340fa 100644
--- a/luma/src/luma.h
+++ b/luma/src/luma.h
@@ -24,15 +24,15 @@
#include <stdint.h>
#include <stdio.h>
-#define luma_ver 0x1A
+#define luma_ver 0x1B
typedef uint8_t luma_byte;
-typedef uint16_t luma_ptr;
+typedef uint16_t luma_dbl;
extern char const * luma_bootlder;
extern char const * luma_cart;
extern bool luma_dead;
-extern luma_ptr luma_instrPtr;
+extern luma_dbl luma_instrPtr;
extern luma_byte luma_mem[0x10000]; /* 65536-bit address space. */
@@ -45,18 +45,19 @@ extern luma_byte luma_mem[0x10000]; /* 65536-bit address space. */
#define luma_param5 (luma_mem[0xE806])
#define luma_param6 (luma_mem[0xE807])
#define luma_param7 (luma_mem[0xE808])
+#define luma_rnd (luma_mem[0xE809])
-#define luma_getDbl(_addr) ((luma_ptr)(luma_mem[_addr] | ((luma_ptr)(luma_mem[_addr + 0x1]) << 0x8)))
+#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);
void luma_ldBank( luma_byte num);
void luma_ldBootlder(void);
- void luma_ldRom( char const * file,luma_byte banknum,luma_ptr addr);
+ void luma_ldRom( char const * file,luma_byte banknum,luma_dbl addr);
void luma_memDump( void);
void luma_proc( void);
- void luma_setByte( luma_ptr addr,luma_byte val);
- void luma_setDbl( luma_ptr addr,luma_ptr val);
+ void luma_setByte( luma_dbl addr,luma_byte val);
+ void luma_setDbl( luma_dbl addr,luma_dbl val);
#if defined(NDEBUG)
#define luma_log(...)
diff --git a/luma/src/luma_instrPtr.c b/luma/src/luma_instrPtr.c
index 395aea9..00c8614 100644
--- a/luma/src/luma_instrPtr.c
+++ b/luma/src/luma_instrPtr.c
@@ -19,4 +19,4 @@
#include "luma.h"
-luma_ptr luma_instrPtr = 0x0;
+luma_dbl luma_instrPtr = 0x0;
diff --git a/luma/src/luma_ldRom.c b/luma/src/luma_ldRom.c
index 8a93cda..88c0a13 100644
--- a/luma/src/luma_ldRom.c
+++ b/luma/src/luma_ldRom.c
@@ -22,7 +22,7 @@
#include <inttypes.h>
#include <stdio.h>
-void luma_ldRom(char const * const restrict _file,luma_byte const _num,luma_ptr const _addr) {
+void luma_ldRom(char const * const restrict _file,luma_byte const _num,luma_dbl const _addr) {
(void)_num;
luma_log("Loading bank %" PRIX8 " of ROM file \"%s\" into address space at %" PRIX16 "\n",_num,_file,_addr);
FILE * file = fopen(_file,"r");
diff --git a/luma/src/luma_mem.c b/luma/src/luma_mem.c
index 9805df4..854976d 100644
--- a/luma/src/luma_mem.c
+++ b/luma/src/luma_mem.c
@@ -35,7 +35,7 @@
E806-E806 : GENERAL REGISTER 5
E807-E807 : GENERAL REGISTER 6
E808-E808 : GENERAL REGISTER 7
- E909-EFFF : NOTHING
- F000-FFFF : SOUND BUFFER
+ E809-E809 : RANDOM REGISTER
+ E90A-FFFF : NOTHING
*/
luma_byte luma_mem[0x10000];
diff --git a/luma/src/luma_proc.c b/luma/src/luma_proc.c
index 03465b8..f2b61b0 100644
--- a/luma/src/luma_proc.c
+++ b/luma/src/luma_proc.c
@@ -45,6 +45,16 @@
0F : ICD : ptr : INCREMENT DOUBLE
10 : DCD : ptr : DECREMENT DOUBLE
11 : CPD : ptr ,ptr : COMPARE DOUBLE
+ 12 : ADB : ptr ,ptr : ADD BYTE
+ 13 : ADD : ptr ,ptr : ADD DOUBLE
+ 14 : SUB : ptr ,ptr : SUBTRACT
+ 15 : SBD : ptr ,ptr : SUBTRACT DOUBLE
+ 16 : MUL : ptr ,ptr : MULTIPLY
+ 17 : MLD : ptr ,ptr : MULTIPLY DOUBLE
+ 18 : DIV : ptr ,ptr : DIVIDE
+ 19 : DVD : ptr ,ptr : DIVIDE DOUBLE
+ 1A : OUT : byte,ptr : OUTPUT
+ 1B : INP : byte,ptr : INPUT
*/
typedef void (* luma_opcdHandlTer)(void);
@@ -334,45 +344,45 @@ void luma_proc() {
}
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_instrPtr],luma_instrPtr);
}
static void luma_opcdHandl_ign(void) {}
static void luma_opcdHandl_cpy(void) {
- luma_ptr const dest = luma_getDbl(luma_instrPtr + 0x1);
- luma_ptr const src = luma_getDbl(luma_instrPtr + 0x3);
- luma_log("CPY %" PRIX16 " %" PRIX16 "\n",src,dest);
+ 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_setByte(dest,luma_mem[src]);
luma_instrPtr += 0x4;
}
static void luma_opcdHandl_set(void) {
- luma_ptr const dest = luma_getDbl(luma_instrPtr + 0x1);
+ luma_dbl const dest = luma_getDbl(luma_instrPtr + 0x1);
luma_byte const val = luma_mem[luma_instrPtr + 0x3];
- luma_log("SET %" PRIX16 " %" PRIX8 "\n",dest,val);
+ luma_log("SET @%" PRIX16 " %" PRIX16 " %" PRIX8 "\n",luma_instrPtr,dest,val);
luma_setByte(dest,val);
luma_instrPtr += 0x3;
}
static void luma_opcdHandl_inc(void) {
- luma_ptr const addr = luma_getDbl(luma_instrPtr + 0x1);
+ 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;
}
static void luma_opcdHandl_dec(void) {
- luma_ptr const addr = luma_getDbl(luma_instrPtr + 0x1);
+ 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;
}
static void luma_opcdHandl_jmp(void) {
- luma_ptr const dest = luma_getDbl(luma_instrPtr + 0x1);
- luma_log("JMP %" PRIX16 "\n",dest);
- luma_instrPtr = dest;
+ 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. */
}
static void luma_opcdHandl_die(void) {
@@ -382,6 +392,7 @@ static void luma_opcdHandl_die(void) {
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_ldBank(banknum);
luma_instrPtr += 0x1;
}
@@ -395,7 +406,7 @@ static void luma_opcdHandl_trp(void) {
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 %" PRIX8 " %" PRIX8 ": ",lval,rval);
+ luma_log("CMP @%" PRIX16 " %" PRIX8 " %" PRIX8 ": ",luma_instrPtr,lval,rval);
if (lval < rval) {
luma_result = 0x0;
}
@@ -410,36 +421,79 @@ static void luma_opcdHandl_cmp(void) {
}
static void luma_opcdHandl_jeq(void) {
-
+ luma_log("JEQ @%" PRIX16 ": ",luma_instrPtr);
+ if (luma_result == 0x1) {
+ luma_dbl const dest = luma_getDbl(luma_instrPtr + 0x1);
+ luma_log("%" PRIX16 "\n",dest);
+ luma_instrPtr = dest - 0x1; /* Compensate for the incremention by luma_proc. */
+ }
+ else {
+ luma_log("%" PRIX16 "\n",luma_instrPtr);
+ luma_instrPtr += 0x2;
+ }
}
static void luma_opcdHandl_jlt(void) {
-
+ luma_log("JLT @%" PRIX16 ": ",luma_instrPtr);
+ if (luma_result == 0x0) {
+ luma_dbl const dest = luma_getDbl(luma_instrPtr + 0x1);
+ luma_log("%" PRIX16 "\n",dest);
+ luma_instrPtr = dest - 0x1; /* Compensate for the incremention by luma_proc. */
+ }
+ else {
+ luma_log("%" PRIX16 "\n",luma_instrPtr);
+ luma_instrPtr += 0x2;
+ }
}
static void luma_opcdHandl_jgt(void) {
-
+ luma_log("JGT @%" PRIX16 ": ",luma_instrPtr);
+ if (luma_result == 0x2) {
+ luma_dbl const dest = luma_getDbl(luma_instrPtr + 0x1);
+ luma_log("%" PRIX16 "\n",dest);
+ luma_instrPtr = dest - 0x1; /* Compensate for the incremention by luma_proc. */
+ }
+ else {
+ luma_log("%" PRIX16 "\n",luma_instrPtr);
+ luma_instrPtr += 0x2;
+ }
}
static void luma_opcdHandl_jle(void) {
-
+ luma_log("JLE @%" PRIX16 ": ",luma_instrPtr);
+ if (luma_result == 0x0 || luma_result == 0x1) {
+ luma_dbl const dest = luma_getDbl(luma_instrPtr + 0x1);
+ luma_log("%" PRIX16 "\n",dest);
+ luma_instrPtr = dest - 0x1; /* Compensate for the incremention by luma_proc. */
+ }
+ else {
+ luma_log("%" PRIX16 "\n",luma_instrPtr);
+ luma_instrPtr += 0x2;
+ }
}
static void luma_opcdHandl_jge(void) {
-
+ luma_log("JGE @%" PRIX16 ": ",luma_instrPtr);
+ if (luma_result == 0x2 || luma_result == 0x1) {
+ luma_dbl const dest = luma_getDbl(luma_instrPtr + 0x1);
+ luma_log("%" PRIX16 "\n",dest);
+ luma_instrPtr = dest - 0x1; /* Compensate for the incremention by luma_proc. */
+ }
+ else {
+ luma_log("%" PRIX16 "\n",luma_instrPtr);
+ luma_instrPtr += 0x2;
+ }
}
static void luma_opcdHandl_icd(void) {
-
}
static void luma_opcdHandl_dcd(void) {
-
}
static void luma_opcdHandl_cpd(void) {
- luma_ptr const lval = luma_mem[luma_instrPtr + 0x1];
- luma_ptr const rval = luma_mem[luma_instrPtr + 0x2];
+ 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);
if (lval < rval) {
luma_result = 0x0;
diff --git a/luma/src/luma_setByte.c b/luma/src/luma_setByte.c
index c4a26c6..f0b79d3 100644
--- a/luma/src/luma_setByte.c
+++ b/luma/src/luma_setByte.c
@@ -19,8 +19,14 @@
#include "luma.h"
-void luma_setByte(luma_ptr const _addr,luma_byte const _val) {
+#include <inttypes.h>
+#include <stdio.h>
+
+void luma_setByte(luma_dbl const _addr,luma_byte const _val) {
if ((_addr >= 0x8000 && _addr <= 0xE808) || (_addr >= 0xF000 && _addr <= 0xFFFF)) { /* Address must be inside VRAM, system RAM, cartridge RAM, any of the registers, or the sound buffer before we can write to it. */
luma_mem[_addr] = _val;
}
+ else {
+ fprintf(stderr,"! Attempted to write at read-only address at %" PRIX16 "\n",_addr);
+ }
}
diff --git a/luma/src/luma_setDbl.c b/luma/src/luma_setDbl.c
index 2394dec..5151abd 100644
--- a/luma/src/luma_setDbl.c
+++ b/luma/src/luma_setDbl.c
@@ -19,7 +19,7 @@
#include "luma.h"
-void luma_setDbl(luma_ptr const _addr,luma_ptr const _val) {
+void luma_setDbl(luma_dbl const _addr,luma_dbl const _val) {
luma_setByte(_addr,(luma_byte)(_val >> 0x8));
luma_setByte(_addr,(luma_byte)_val);
}
diff --git a/luma/src/main.c b/luma/src/main.c
index 99e6658..8ff8825 100644
--- a/luma/src/main.c
+++ b/luma/src/main.c
@@ -23,29 +23,35 @@
#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) {
- exit(EXIT_SUCCESS);
+ 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);
memset(luma_mem,0x0,0x10000); /* We initialise all of the memory to zero so the behaviour is not UB. */
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;
}
luma_proc();
+ getrandom(&luma_rnd,sizeof (luma_byte),GRND_RANDOM);
+ nanosleep(&sleeptimespec,NULL);
}
#if !defined(NDEBUG)
luma_memDump();