summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt11
-rw-r--r--README.md19
-rw-r--r--bootloader.lumabin13 -> 19 bytes
-rw-r--r--cartridge.lumabin5 -> 5 bytes
-rw-r--r--changelog.md14
-rw-r--r--luma/src/luma.h28
-rw-r--r--luma/src/luma_abrt.c4
-rw-r--r--luma/src/luma_bootlder.c22
-rw-r--r--luma/src/luma_ldBank.c (renamed from luma/src/luma_initMem.c)8
-rw-r--r--luma/src/luma_ldBootlder.c (renamed from luma/src/luma_setPtrVal.c)6
-rw-r--r--luma/src/luma_ldRom.c (renamed from luma/src/luma_loadRom.c)7
-rw-r--r--luma/src/luma_mem.c19
-rw-r--r--luma/src/luma_memDump.c4
-rw-r--r--luma/src/luma_opcd.c82
-rw-r--r--luma/src/luma_proc.c456
-rw-r--r--luma/src/luma_setByte.c26
-rw-r--r--luma/src/luma_setDbl.c25
-rw-r--r--luma/src/main.c26
18 files changed, 623 insertions, 134 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 397adb2..b8c4b21 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -93,14 +93,17 @@ 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_initMem.c"
"luma/src/luma_instrPtr.c"
- "luma/src/luma_loadRom.c"
+ "luma/src/luma_ldBank.c"
+ "luma/src/luma_ldBootlder.c"
+ "luma/src/luma_ldRom.c"
"luma/src/luma_mem.c"
"luma/src/luma_memDump.c"
- "luma/src/luma_opcd.c"
- "luma/src/luma_setPtrVal.c"
+ "luma/src/luma_proc.c"
+ "luma/src/luma_setByte.c"
+ "luma/src/luma_setDbl.c"
"luma/src/main.c"
) \ No newline at end of file
diff --git a/README.md b/README.md
deleted file mode 100644
index 17c170a..0000000
--- a/README.md
+++ /dev/null
@@ -1,19 +0,0 @@
-# luma
-
-[*luma*](https://mandelbrot.dk/luma/luma) is a free and open-source programming language.
-
-## Copyright & License
-
-Copyright 2021 Gabriel Jensen.
-
-All rights reserved.
-
-This program 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.
-
-This program 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 Affero General Public License for more details.
-
-You should have received a copy of the GNU Affero General Public License along with this program.
-
-If not, see <https://www.gnu.org/licenses/>.
diff --git a/bootloader.luma b/bootloader.luma
index 5f60953..ca7508e 100644
--- a/bootloader.luma
+++ b/bootloader.luma
Binary files differ
diff --git a/cartridge.luma b/cartridge.luma
index 6342611..49baf4c 100644
--- a/cartridge.luma
+++ b/cartridge.luma
Binary files differ
diff --git a/changelog.md b/changelog.md
index d0ecd71..779b1b2 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,3 +1,17 @@
+# 21
+
+* Remove old readme.
+* Update memory model.
+* Fix ROM loader loading ROM into wrong address.
+* Update bootloader.
+* Fix bootloader loaded as bank 0 (should be 1).
+* Add new instructions.
+* Implement more instructions.
+* Rename opcode LDB to BNK.
+* Rewrite instruction interpreter.
+* Writes in ROM no longer succeed.
+* Create SIGINT handler.
+
# 20
* Move all UTF-8 related code into a seperate project, *u8c*.
diff --git a/luma/src/luma.h b/luma/src/luma.h
index eb14e45..834d8e0 100644
--- a/luma/src/luma.h
+++ b/luma/src/luma.h
@@ -29,20 +29,34 @@
typedef uint8_t luma_byte;
typedef uint16_t luma_ptr;
+extern char const * luma_bootlder;
extern char const * luma_cart;
extern bool luma_dead;
extern luma_ptr luma_instrPtr;
extern luma_byte luma_mem[0x10000]; /* 65536-bit address space. */
-#define luma_getPtrVal(_addr) ((luma_ptr)(luma_mem[_addr] | ((luma_ptr)(luma_mem[_addr + 0x1]) << 0x8)))
+#define luma_result (luma_mem[0xE800])
+#define luma_param0 (luma_mem[0xE801])
+#define luma_param1 (luma_mem[0xE802])
+#define luma_param2 (luma_mem[0xE803])
+#define luma_param3 (luma_mem[0xE804])
+#define luma_param4 (luma_mem[0xE805])
+#define luma_param5 (luma_mem[0xE806])
+#define luma_param6 (luma_mem[0xE807])
+#define luma_param7 (luma_mem[0xE808])
-_Noreturn void luma_abrt( void);
- void luma_initMem( void);
- void luma_loadRom( char const * file,luma_byte banknum);
- void luma_memDump( char const * file);
- void luma_opcd( void);
- void luma_setPtrVal(luma_ptr addr,luma_ptr val);
+#define luma_getDbl(_addr) ((luma_ptr)(luma_mem[_addr] | ((luma_ptr)(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_memDump( void);
+ void luma_proc( void);
+ void luma_setByte( luma_ptr addr,luma_byte val);
+ void luma_setDbl( luma_ptr addr,luma_ptr val);
#if defined(NDEBUG)
#define luma_log(...)
diff --git a/luma/src/luma_abrt.c b/luma/src/luma_abrt.c
index f38b01d..dca1d4d 100644
--- a/luma/src/luma_abrt.c
+++ b/luma/src/luma_abrt.c
@@ -23,7 +23,7 @@
#include <stdlib.h>
void luma_abrt(void) {
- fprintf(stderr,"Abort called!\n");
- luma_memDump("memdump");
+ fprintf(stderr,"Abort invoked\n");
+ luma_memDump();
exit(EXIT_FAILURE);
}
diff --git a/luma/src/luma_bootlder.c b/luma/src/luma_bootlder.c
new file mode 100644
index 0000000..e749dc6
--- /dev/null
+++ b/luma/src/luma_bootlder.c
@@ -0,0 +1,22 @@
+/*
+ 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"
+
+char const * luma_bootlder = "bootloader.luma";
diff --git a/luma/src/luma_initMem.c b/luma/src/luma_ldBank.c
index fda04a2..c45e876 100644
--- a/luma/src/luma_initMem.c
+++ b/luma/src/luma_ldBank.c
@@ -19,10 +19,8 @@
#include "luma.h"
-#include <stdbool.h>
-#include <stdint.h>
-#include <string.h>
+#include <stdio.h>
-void luma_initMem(void) {
- memset(luma_mem,0x0,0x10000);
+void luma_ldBank(luma_byte const _num) {
+ luma_ldRom(luma_cart,_num,_num == 0x0 ? 0x2000 : 0x0);
}
diff --git a/luma/src/luma_setPtrVal.c b/luma/src/luma_ldBootlder.c
index 9ff09d1..dba2dca 100644
--- a/luma/src/luma_setPtrVal.c
+++ b/luma/src/luma_ldBootlder.c
@@ -19,7 +19,7 @@
#include "luma.h"
-void luma_setPtrVal(luma_ptr const _addr,luma_ptr const _val) {
- luma_mem[_addr] = (luma_byte)(_val >> 0x8);
- luma_mem[_addr + 0x1] = (luma_byte)_val;
+void luma_ldBootlder(void) {
+ luma_log("Loading boot loader \"%s\"\n",luma_bootlder);
+ luma_ldRom(luma_bootlder,0x0,0x0);
}
diff --git a/luma/src/luma_loadRom.c b/luma/src/luma_ldRom.c
index 9425a58..8a93cda 100644
--- a/luma/src/luma_loadRom.c
+++ b/luma/src/luma_ldRom.c
@@ -19,11 +19,14 @@
#include "luma.h"
+#include <inttypes.h>
#include <stdio.h>
-void luma_loadRom(char const * const restrict _file,luma_byte const _banknum) {
+void luma_ldRom(char const * const restrict _file,luma_byte const _num,luma_ptr 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");
- void * const buf = luma_mem + (_banknum == 0x0 ? 0x0 : 0x2000);
+ void * const buf = luma_mem + _addr;
fread(buf,sizeof (luma_byte),0x4000,file);
fclose(file);
}
diff --git a/luma/src/luma_mem.c b/luma/src/luma_mem.c
index 298a9a6..9805df4 100644
--- a/luma/src/luma_mem.c
+++ b/luma/src/luma_mem.c
@@ -20,11 +20,22 @@
#include "luma.h"
/*
- MEMORY MODEL:
- 0000-3FFF : BOOTLOADER OR CARTRIDGE ROM BANK 1+
- 4000-7FFF : CARTRIDGE ROM BANK 0
+ ADDRESS SPACE:
+ 0000-3FFF : BOOTLOADER OR CARTRIDGE ROM BANK 01-FF
+ 4000-7FFF : CARTRIDGE ROM BANK 00
8000-BFFF : VRAM
C000-DFFF : SYSTEM RAM
- C000-C3FF : I/O BUFFER
+ E000-E7FF : CARTRIDGE RAM
+ E800-E800 : RESULT REGISTER
+ E801-E801 : GENERAL REGISTER 0
+ E802-E802 : GENERAL REGISTER 1
+ E803-E803 : GENERAL REGISTER 2
+ E804-E804 : GENERAL REGISTER 3
+ E805-E805 : GENERAL REGISTER 4
+ E806-E806 : GENERAL REGISTER 5
+ E807-E807 : GENERAL REGISTER 6
+ E808-E808 : GENERAL REGISTER 7
+ E909-EFFF : NOTHING
+ F000-FFFF : SOUND BUFFER
*/
luma_byte luma_mem[0x10000];
diff --git a/luma/src/luma_memDump.c b/luma/src/luma_memDump.c
index ed004db..253618a 100644
--- a/luma/src/luma_memDump.c
+++ b/luma/src/luma_memDump.c
@@ -21,9 +21,9 @@
#include <stdio.h>
-void luma_memDump(char const * const restrict _file) {
+void luma_memDump(void) {
fprintf(stderr,"Creating memory dump...");
- FILE * file = fopen(_file,"w");
+ FILE * file = fopen("memdump","w");
if (fwrite(luma_mem,sizeof (luma_byte),0x10000,file) < 0x10000) {
luma_abrt();
}
diff --git a/luma/src/luma_opcd.c b/luma/src/luma_opcd.c
deleted file mode 100644
index e4bd945..0000000
--- a/luma/src/luma_opcd.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- 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 <inttypes.h>
-#include <stdio.h>
-#include <string.h>
-
-/*
- OPCODES:
- 00 : IGN : : IGNORE
- 01 : CPY : ptr ,ptr : COPY
- 02 : SET : ptr ,byte : SET
- 03 : INC : ptr : INCREMENT
- 04 : DEC : ptr : DECREMENT
- 05 : JMP : ptr : JUMP
- 06 : DIE : : DIE
- 07 : LDB : byte : LOAD BANK
-*/
-
-#include <assert.h>
-
-void luma_opcd() {
- luma_byte const _opcd = luma_mem[luma_instrPtr];
- switch (_opcd) {
- default:
- fprintf(stderr,"Unknown opcode %" PRIx16 " at %" PRIx16 "\n",luma_mem[luma_instrPtr],luma_instrPtr);
- luma_abrt();
- case 0x0:
- break;
- case 0x1:
- {
- luma_ptr const dest = luma_getPtrVal(luma_instrPtr + 0x1);
- luma_ptr const src = luma_getPtrVal(luma_instrPtr + 0x3);
- luma_log("Copying byte at %" PRIx16 " to %" PRIx16 "\n",src,dest);
- luma_mem[dest] = luma_mem[src];
- }
- luma_instrPtr += 0x4;
- break;
- case 0x2:
- {
- luma_ptr const dest = luma_getPtrVal(luma_instrPtr + 0x1);
- luma_byte const val = luma_mem[luma_instrPtr + 0x3];
- luma_log("Setting byte at %" PRIx16 " to %" PRIx16 "\n",dest,val);
- luma_mem[dest] = val;
- }
- luma_instrPtr += 0x3;
- break;
- case 0x5:
- luma_instrPtr = luma_getPtrVal(luma_instrPtr + 0x1);
- luma_log("Jumping to %" PRIx16 "\n",luma_instrPtr);
- return;
- case 0x6:
- luma_dead = true;
- break;
- case 0x7:
- {
- luma_byte const banknum = luma_mem[luma_instrPtr + 0x1];
- luma_log("Loading ROM bank %" PRId8 " from \"%s\"\n",banknum,luma_cart);
- luma_loadRom(luma_cart,banknum);
- }
- luma_instrPtr += 0x1;
- }
- luma_instrPtr += 0x1;
-}
diff --git a/luma/src/luma_proc.c b/luma/src/luma_proc.c
new file mode 100644
index 0000000..03465b8
--- /dev/null
+++ b/luma/src/luma_proc.c
@@ -0,0 +1,456 @@
+/*
+ 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 <inttypes.h>
+#include <stdio.h>
+#include <string.h>
+
+/*
+ OPCODES:
+ HEX : NAME : PARAMETERS : FULL NAME
+
+ 00 : IGN : : IGNORE
+ 01 : CPY : ptr ,ptr : COPY
+ 02 : SET : ptr ,byte : SET
+ 03 : INC : ptr : INCREMENT
+ 04 : DEC : ptr : DECREMENT
+ 05 : JMP : ptr : JUMP
+ 06 : DIE : : DIE
+ 07 : BNK : byte : LOAD BANK
+ 08 : TRP : : TRAP
+ 09 : CMP : ptr ,ptr : COMPARE
+ 0A : JEQ : ptr : JUMP IF EQUAL
+ 0B : JLT : ptr : JUMP IF LESS THAN
+ 0C : JGT : ptr : JUMP IF GREATER THAN
+ 0D : JLE : ptr : JUMP IF LESS THAN OR EQUAL
+ 0E : JGE : ptr : JUMP IF GREATER THAN OR EQUAL
+ 0F : ICD : ptr : INCREMENT DOUBLE
+ 10 : DCD : ptr : DECREMENT DOUBLE
+ 11 : CPD : ptr ,ptr : COMPARE DOUBLE
+*/
+
+typedef void (* luma_opcdHandlTer)(void);
+
+static void luma_opcdHandl_ilg(void);
+static void luma_opcdHandl_ign(void);
+static void luma_opcdHandl_cpy(void);
+static void luma_opcdHandl_set(void);
+static void luma_opcdHandl_inc(void);
+static void luma_opcdHandl_dec(void);
+static void luma_opcdHandl_jmp(void);
+static void luma_opcdHandl_die(void);
+static void luma_opcdHandl_bnk(void);
+static void luma_opcdHandl_trp(void);
+static void luma_opcdHandl_cmp(void);
+static void luma_opcdHandl_jeq(void);
+static void luma_opcdHandl_jlt(void);
+static void luma_opcdHandl_jgt(void);
+static void luma_opcdHandl_jle(void);
+static void luma_opcdHandl_jge(void);
+static void luma_opcdHandl_icd(void);
+static void luma_opcdHandl_dcd(void);
+static void luma_opcdHandl_cpd(void);
+
+luma_opcdHandlTer luma_opcdHandls[0x100] = {
+ luma_opcdHandl_ign,
+ luma_opcdHandl_cpy,
+ luma_opcdHandl_set,
+ luma_opcdHandl_inc,
+ luma_opcdHandl_dec,
+ luma_opcdHandl_jmp,
+ luma_opcdHandl_die,
+ luma_opcdHandl_bnk,
+ luma_opcdHandl_trp,
+ luma_opcdHandl_cmp,
+ luma_opcdHandl_jeq,
+ luma_opcdHandl_jlt,
+ luma_opcdHandl_jgt,
+ luma_opcdHandl_jle,
+ luma_opcdHandl_jge,
+ luma_opcdHandl_icd,
+ luma_opcdHandl_dcd,
+ luma_opcdHandl_cpd,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+ luma_opcdHandl_ilg,
+};
+
+void luma_proc() {
+ luma_opcdHandls[luma_mem[luma_instrPtr]]();
+ luma_instrPtr += 0x1;
+}
+
+static void luma_opcdHandl_ilg(void) {
+ 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_setByte(dest,luma_mem[src]);
+ luma_instrPtr += 0x4;
+}
+
+static void luma_opcdHandl_set(void) {
+ luma_ptr 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_setByte(dest,val);
+ luma_instrPtr += 0x3;
+}
+
+static void luma_opcdHandl_inc(void) {
+ luma_ptr 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_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;
+}
+
+static void luma_opcdHandl_die(void) {
+ luma_log("DIE @%" PRIX16 "\n",luma_instrPtr);
+ luma_dead = true;
+}
+
+static void luma_opcdHandl_bnk(void) {
+ luma_byte const banknum = luma_mem[luma_instrPtr + 0x1];
+ luma_ldBank(banknum);
+ luma_instrPtr += 0x1;
+}
+
+static void luma_opcdHandl_trp(void) {
+ luma_log("TRP @%" PRIX16 "\n",luma_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 %" PRIX8 " %" PRIX8 ": ",lval,rval);
+ if (lval < rval) {
+ luma_result = 0x0;
+ }
+ else if (lval > rval) {
+ luma_result = 0x2;
+ }
+ else {
+ luma_result = 0x1;
+ }
+ luma_log("%" PRIX8 "\n",luma_result);
+ luma_instrPtr += 0x4;
+}
+
+static void luma_opcdHandl_jeq(void) {
+
+}
+
+static void luma_opcdHandl_jlt(void) {
+
+}
+
+static void luma_opcdHandl_jgt(void) {
+
+}
+
+static void luma_opcdHandl_jle(void) {
+
+}
+
+static void luma_opcdHandl_jge(void) {
+
+}
+
+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_log("CPD %" PRIX16 " %" PRIX16 ": ",lval,rval);
+ if (lval < rval) {
+ luma_result = 0x0;
+ }
+ else if (lval > rval) {
+ luma_result = 0x2;
+ }
+ else {
+ luma_result = 0x1;
+ }
+ luma_log("%" PRIX8 "\n",luma_result);
+ luma_instrPtr += 0x2;
+}
+
diff --git a/luma/src/luma_setByte.c b/luma/src/luma_setByte.c
new file mode 100644
index 0000000..c4a26c6
--- /dev/null
+++ b/luma/src/luma_setByte.c
@@ -0,0 +1,26 @@
+/*
+ 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"
+
+void luma_setByte(luma_ptr 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;
+ }
+}
diff --git a/luma/src/luma_setDbl.c b/luma/src/luma_setDbl.c
new file mode 100644
index 0000000..2394dec
--- /dev/null
+++ b/luma/src/luma_setDbl.c
@@ -0,0 +1,25 @@
+/*
+ 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"
+
+void luma_setDbl(luma_ptr const _addr,luma_ptr 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 d7313a8..99e6658 100644
--- a/luma/src/main.c
+++ b/luma/src/main.c
@@ -19,17 +19,35 @@
#include "luma.h"
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+
+static volatile sig_atomic_t luma_hasSig;
+
+static void luma_sigHandl(int const _sig) {
+ (void)_sig;
+ if (luma_hasSig) {
+ exit(EXIT_SUCCESS);
+ }
+ luma_hasSig = 0x1;
+}
int main(void) {
printf("luma %i\n",luma_ver);
- luma_initMem();
- luma_loadRom("bootloader.luma",0x0);
+ 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");
while (!luma_dead) {
- luma_opcd();
+ if (luma_hasSig) {
+ luma_dead = true;
+ break;
+ }
+ luma_proc();
}
#if !defined(NDEBUG)
- luma_memDump("memdump");
+ luma_memDump();
#endif
}