summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore7
-rw-r--r--CMakeLists.txt106
-rw-r--r--Makefile39
-rw-r--r--PKGBUILD19
-rw-r--r--README.html16
-rw-r--r--bootloader.lumabin0 -> 13 bytes
-rw-r--r--cartridge.lumabin0 -> 5 bytes
-rw-r--r--changelog.md9
-rw-r--r--include/luma/arch.h52
-rw-r--r--include/luma/print.h20
-rw-r--r--include/luma/utf8dec.h21
-rw-r--r--include/luma/utf8enc.h21
-rw-r--r--luma/src/luma.h53
-rw-r--r--luma/src/luma_abrt.c29
-rw-r--r--luma/src/luma_cart.c22
-rw-r--r--luma/src/luma_dead.c24
-rw-r--r--luma/src/luma_initMem.c28
-rw-r--r--luma/src/luma_instrPtr.c22
-rw-r--r--luma/src/luma_loadRom.c29
-rw-r--r--luma/src/luma_mem.c30
-rw-r--r--luma/src/luma_memDump.c32
-rw-r--r--luma/src/luma_opcd.c82
-rw-r--r--luma/src/luma_setPtrVal.c25
-rw-r--r--luma/src/main.c35
-rw-r--r--main5
-rw-r--r--src/luma/print.c44
-rw-r--r--src/luma/utf8dec.c105
-rw-r--r--src/luma/utf8enc.c82
-rw-r--r--src/main.c50
29 files changed, 545 insertions, 462 deletions
diff --git a/.gitignore b/.gitignore
index 4a0bf6c..90eaf89 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
-*.o
-/delete_me_pls
-/luma
+/build
+/memdump
+/old
+vgcore.* \ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..397adb2
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,106 @@
+cmake_minimum_required(
+ VERSION
+ 3.22
+)
+project(
+ luma
+ VERSION
+ 24
+ DESCRIPTION
+ "The luma platform."
+ HOMEPAGE_URL
+ "https://mandelbrot.dk/luma"
+ LANGUAGES
+ C
+)
+set(
+ CMAKE_C_STANDARD
+ 99
+)
+
+# Disable in-souce builds:
+if(
+ "${PROJECT_BINARY_DIR}"
+ STREQUAL
+ "${PROJECT_SOURCE_DIR}"
+)
+ message(
+ FATAL_ERROR
+ "Building in the source tree is not allowed."
+ )
+endif()
+
+# Include directories:
+include_directories(
+ "${PROJECT_SOURCE_DIR}/include"
+ "/home/delta/repos/u8c/u8c/include"
+)
+
+# Enable compiler warnings:
+if(
+ MSVC
+)
+ add_compile_options(
+ "/W4"
+ "/WX"
+ )
+else()
+ add_compile_options(
+ "-pedantic-errors"
+ "-Wfatal-errors"
+ "-Wall"
+ "-Wconversion"
+ "-Werror"
+ "-Wextra"
+ "-Wunreachable-code"
+ "-Wunused"
+ )
+ if(
+ "${CMAKE_CXX_COMPILER_ID}"
+ STREQUAL
+ "Clang"
+ )
+ add_compile_options(
+ "-Wnewline-eof"
+ )
+ endif()
+endif()
+
+# Set compiler optimisations level:
+if(
+ CMAKE_BUILD_TYPE
+ MATCHES
+ Release
+)
+ message(
+ STATUS
+ "Setting optimisation level..."
+ )
+ if(
+ MSVC
+ )
+ add_compile_options(
+ "/Os"
+ )
+ else()
+ add_compile_options(
+ "-Os"
+ )
+ endif()
+endif()
+
+# Sources:
+add_executable(
+ luma
+ "luma/src/luma_abrt.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_mem.c"
+ "luma/src/luma_memDump.c"
+ "luma/src/luma_opcd.c"
+ "luma/src/luma_setPtrVal.c"
+ "luma/src/main.c"
+) \ No newline at end of file
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 2385529..0000000
--- a/Makefile
+++ /dev/null
@@ -1,39 +0,0 @@
-CC = clang
-CFLAGS = -std=c17 -Wall -Wextra -Wpedantic -I include -march=native -mtune=native -O3
-ifneq ($(debug),1)
-CFLAGS += -DNDEBUG
-else
-CFLAGS += -g
-endif
-LDFLAGS =
-SRCS = \
- src/luma/print.c \
- src/luma/utf8dec.c \
- src/luma/utf8enc.c \
- src/main.c
-HDRS = \
- include/luma/arch.h \
- include/luma/print.h \
- include/luma/utf8dec.h \
- include/luma/utf8enc.h
-OBJS = $(SRCS:.c=.o)
-BIN = luma
-$(BIN): $(OBJS)
- $(CC) $(LDFLAGS) $^ -o $@
-$(OBJS): $(HDRS)
-.PHONY: run
-run: luma
- ./luma
-.PHONY: clean
-clean:
- rm $(OBJS)
-.PHONY: purge
-purge:
- rm $(BIN) $(OBJS)
-.PHONY: install
-install: $(BIN)
- mkdir --parents $(DESTDIR)/bin
- install --mode=555 $(BIN) $(DESTDIR)/bin
-.PHONY: uninstall
-uninstall:
- rm --force --recursive $(DESTDIR)/bin/$(BIN)
diff --git a/PKGBUILD b/PKGBUILD
deleted file mode 100644
index 110bb30..0000000
--- a/PKGBUILD
+++ /dev/null
@@ -1,19 +0,0 @@
-# Maintainer: Gabriel Jensen
-pkgname=luma
-pkgver=23.0.0
-pkgrel=1
-pkgdesc="luma programming language - runtime environment"
-arch=("any")
-url="https://mandelbrot.dk/luma/luma"
-license=("AGPL3")
-makedepends=("git")
-source=("git+https://mandelbrot.dk/luma/luma.git")
-sha512sums=("SKIP")
-build() {
- cd "$srcdir/$pkgname"
- make -j$(nproc)
-}
-package() {
- cd "$srcdir/$pkgname"
- make DESTDIR="$pkgdir/usr" install
-}
diff --git a/README.html b/README.html
new file mode 100644
index 0000000..d7d25d8
--- /dev/null
+++ b/README.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+ <body>
+ <h1>luma</h1>
+ <p><a href="https://mandelbrot.dk/luma">luma</a> is a free, open-source, and portable emulator for the luma platform.</p>
+ <p>This project serves as the reference implementation for the luma platform.</p>
+ <h2 id="copyright-license">Copyright &amp; License</h2>
+ <p>Copyright 2021, 2022 Gabriel Jensen.</p>
+ <p>All rights reserved.</p>
+ <p>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.</p>
+ <p>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.</p>
+ <p>See the GNU Affero General Public License for more details.</p>
+ <p>You should have received a copy of the GNU Affero General Public License along with this program.</p>
+ <p>If not, see <a href="https://www.gnu.org/licenses">&lthttps://www.gnu.org/licenses&gt</a>.</p>
+ </body>
+</html>
diff --git a/bootloader.luma b/bootloader.luma
new file mode 100644
index 0000000..5f60953
--- /dev/null
+++ b/bootloader.luma
Binary files differ
diff --git a/cartridge.luma b/cartridge.luma
new file mode 100644
index 0000000..6342611
--- /dev/null
+++ b/cartridge.luma
Binary files differ
diff --git a/changelog.md b/changelog.md
index d410dcb..d0ecd71 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,6 +1,13 @@
+# 20
+
+* Move all UTF-8 related code into a seperate project, *u8c*.
+* Rewrite project.
+* Require C99 instead of C17.
+* Reformat the readme into HTML.
+
# 1↋
-* Create *bin* folder in destination directory.
+* Create *bin* folder in destination directory when installing.
# 1↊
diff --git a/include/luma/arch.h b/include/luma/arch.h
deleted file mode 100644
index c4ce2eb..0000000
--- a/include/luma/arch.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- Copyright 2021 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 Affero 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/>.
-*/
-# if !defined(LUMA_HDR_ARCH)
-# define LUMA_HDR_ARCH
-enum luma_arch {
- // Null
- luma_arch_null,
- // Keywords
- luma_arch_lab,
- luma_arch_next,
- // Instructions
- luma_arch_add,
- luma_arch_call,
- luma_arch_cp,
- luma_arch_div,
- luma_arch_ex,
- luma_arch_fac,
- luma_arch_get,
- luma_arch_hello,
- luma_arch_luma,
- luma_arch_mult,
- luma_arch_pow,
- luma_arch_root,
- luma_arch_sub,
- // Numbers
- luma_arch_zero,
- luma_arch_one,
- luma_arch_two,
- luma_arch_three,
- luma_arch_four,
- luma_arch_five,
- luma_arch_six,
- luma_arch_seven,
- luma_arch_eight,
- luma_arch_nine,
- luma_arch_dek,
- luma_arch_el,
-};
-# endif
diff --git a/include/luma/print.h b/include/luma/print.h
deleted file mode 100644
index 8a359fb..0000000
--- a/include/luma/print.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- Copyright 2021 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 Affero 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/>.
-*/
-# if !defined(LUMA_HDR_PRINT)
-# define LUMA_HDR_PRINT
-# include <stdint.h>
-extern void luma_print(uint32_t * str,...);
-# endif
diff --git a/include/luma/utf8dec.h b/include/luma/utf8dec.h
deleted file mode 100644
index c9913b2..0000000
--- a/include/luma/utf8dec.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- Copyright 2021 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 Affero 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/>.
-*/
-# if !defined(LUMA_HDR_UTF8DEC)
-# define LUMA_HDR_UTF8DEC
-# include <stddef.h>
-# include <stdint.h>
-extern int luma_utf8dec(uint8_t * utf,uint32_t * * codeps,size_t * outszptr);
-# endif
diff --git a/include/luma/utf8enc.h b/include/luma/utf8enc.h
deleted file mode 100644
index 4426183..0000000
--- a/include/luma/utf8enc.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- Copyright 2021 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 Affero 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/>.
-*/
-# if !defined(LUMA_HDR_UTF8ENC)
-# define LUMA_HDR_UTF8ENC
-# include <stddef.h>
-# include <stdint.h>
-extern int luma_utf8enc(uint32_t * codeps,uint8_t * * utf,size_t * outszptr);
-# endif
diff --git a/luma/src/luma.h b/luma/src/luma.h
new file mode 100644
index 0000000..eb14e45
--- /dev/null
+++ b/luma/src/luma.h
@@ -0,0 +1,53 @@
+/*
+ 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/>.
+*/
+
+#if !defined(luma_hdr_luma)
+#define luma_hdr_luma
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+
+#define luma_ver 0x18
+
+typedef uint8_t luma_byte;
+typedef uint16_t luma_ptr;
+
+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)))
+
+_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);
+
+#if defined(NDEBUG)
+#define luma_log(...)
+#else
+#define luma_log(...) (fprintf(stderr,__VA_ARGS__))
+#endif
+
+#endif
diff --git a/luma/src/luma_abrt.c b/luma/src/luma_abrt.c
new file mode 100644
index 0000000..f38b01d
--- /dev/null
+++ b/luma/src/luma_abrt.c
@@ -0,0 +1,29 @@
+/*
+ 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 <stdio.h>
+#include <stdlib.h>
+
+void luma_abrt(void) {
+ fprintf(stderr,"Abort called!\n");
+ luma_memDump("memdump");
+ exit(EXIT_FAILURE);
+}
diff --git a/luma/src/luma_cart.c b/luma/src/luma_cart.c
new file mode 100644
index 0000000..c891229
--- /dev/null
+++ b/luma/src/luma_cart.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_cart = "cartridge.luma";
diff --git a/luma/src/luma_dead.c b/luma/src/luma_dead.c
new file mode 100644
index 0000000..4ee1a59
--- /dev/null
+++ b/luma/src/luma_dead.c
@@ -0,0 +1,24 @@
+/*
+ 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 <stdbool.h>
+
+bool luma_dead = false;
diff --git a/luma/src/luma_initMem.c b/luma/src/luma_initMem.c
new file mode 100644
index 0000000..fda04a2
--- /dev/null
+++ b/luma/src/luma_initMem.c
@@ -0,0 +1,28 @@
+/*
+ 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 <stdbool.h>
+#include <stdint.h>
+#include <string.h>
+
+void luma_initMem(void) {
+ memset(luma_mem,0x0,0x10000);
+}
diff --git a/luma/src/luma_instrPtr.c b/luma/src/luma_instrPtr.c
new file mode 100644
index 0000000..395aea9
--- /dev/null
+++ b/luma/src/luma_instrPtr.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"
+
+luma_ptr luma_instrPtr = 0x0;
diff --git a/luma/src/luma_loadRom.c b/luma/src/luma_loadRom.c
new file mode 100644
index 0000000..9425a58
--- /dev/null
+++ b/luma/src/luma_loadRom.c
@@ -0,0 +1,29 @@
+/*
+ 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 <stdio.h>
+
+void luma_loadRom(char const * const restrict _file,luma_byte const _banknum) {
+ FILE * file = fopen(_file,"r");
+ void * const buf = luma_mem + (_banknum == 0x0 ? 0x0 : 0x2000);
+ fread(buf,sizeof (luma_byte),0x4000,file);
+ fclose(file);
+}
diff --git a/luma/src/luma_mem.c b/luma/src/luma_mem.c
new file mode 100644
index 0000000..298a9a6
--- /dev/null
+++ b/luma/src/luma_mem.c
@@ -0,0 +1,30 @@
+/*
+ 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"
+
+/*
+ MEMORY MODEL:
+ 0000-3FFF : BOOTLOADER OR CARTRIDGE ROM BANK 1+
+ 4000-7FFF : CARTRIDGE ROM BANK 0
+ 8000-BFFF : VRAM
+ C000-DFFF : SYSTEM RAM
+ C000-C3FF : I/O BUFFER
+*/
+luma_byte luma_mem[0x10000];
diff --git a/luma/src/luma_memDump.c b/luma/src/luma_memDump.c
new file mode 100644
index 0000000..ed004db
--- /dev/null
+++ b/luma/src/luma_memDump.c
@@ -0,0 +1,32 @@
+/*
+ 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 <stdio.h>
+
+void luma_memDump(char const * const restrict _file) {
+ fprintf(stderr,"Creating memory dump...");
+ FILE * file = fopen(_file,"w");
+ if (fwrite(luma_mem,sizeof (luma_byte),0x10000,file) < 0x10000) {
+ luma_abrt();
+ }
+ fclose(file);
+ fputs(" done\n",stderr);
+}
diff --git a/luma/src/luma_opcd.c b/luma/src/luma_opcd.c
new file mode 100644
index 0000000..e4bd945
--- /dev/null
+++ b/luma/src/luma_opcd.c
@@ -0,0 +1,82 @@
+/*
+ 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_setPtrVal.c b/luma/src/luma_setPtrVal.c
new file mode 100644
index 0000000..9ff09d1
--- /dev/null
+++ b/luma/src/luma_setPtrVal.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_setPtrVal(luma_ptr const _addr,luma_ptr const _val) {
+ luma_mem[_addr] = (luma_byte)(_val >> 0x8);
+ luma_mem[_addr + 0x1] = (luma_byte)_val;
+}
diff --git a/luma/src/main.c b/luma/src/main.c
new file mode 100644
index 0000000..d7313a8
--- /dev/null
+++ b/luma/src/main.c
@@ -0,0 +1,35 @@
+/*
+ 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 <stdio.h>
+#include <stdlib.h>
+
+int main(void) {
+ printf("luma %i\n",luma_ver);
+ luma_initMem();
+ luma_loadRom("bootloader.luma",0x0);
+ while (!luma_dead) {
+ luma_opcd();
+ }
+#if !defined(NDEBUG)
+ luma_memDump("memdump");
+#endif
+}
diff --git a/main b/main
deleted file mode 100644
index 0eaa3ce..0000000
--- a/main
+++ /dev/null
@@ -1,5 +0,0 @@
-luma #0
-fn “main”
- gæt “std:print”
- cɑll “std:print” “Hællo ðære!”
- æx #0
diff --git a/src/luma/print.c b/src/luma/print.c
deleted file mode 100644
index a085e8f..0000000
--- a/src/luma/print.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- Copyright 2021 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 Affero 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/utf8enc.h>
-# include <stdarg.h>
-# include <stdint.h>
-# include <stdio.h>
-# include <stdlib.h>
-void luma_print(uint32_t * msg,...) {
- va_list args;
- va_start(args,msg);
- for(size_t n = (size_t){0x0};;n += (size_t){0x1}) {
- if(msg[n] == (uint32_t){0x0}) {
- fwrite(&(uint8_t){0xA},0x1,0x1,stdout);
- break;
- }
- if(msg[n] == (uint32_t){0xFFFD}) {
- size_t chrsz = (size_t){0x0};
- uint8_t * chr = NULL;
- luma_utf8enc((uint32_t[]){va_arg(args,uint32_t),0x0},&chr,&chrsz);
- fwrite(chr,0x1,chrsz - (size_t){0x1},stdout);
- free((void *)chr);
- continue;
- }
- size_t chrsz = (size_t){0x0};
- uint8_t * chr = NULL;
- luma_utf8enc((uint32_t[]){msg[n],0x0,0x0},&chr,&chrsz);
- fwrite(chr,0x1,chrsz - (size_t){0x1},stdout);
- free((void *)chr);
- }
- va_end(args);
-}
diff --git a/src/luma/utf8dec.c b/src/luma/utf8dec.c
deleted file mode 100644
index e6c302e..0000000
--- a/src/luma/utf8dec.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- Copyright 2021 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 Affero 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/utf8dec.h>
-# include <stdint.h>
-# include <stdio.h>
-# include <stdlib.h>
-int luma_utf8dec(uint8_t * utf,uint32_t * * codeps,size_t * outszptr) {
- size_t sz = (size_t){0x0};
- size_t outsz = (size_t){0x0};
- for(size_t n = (size_t){0x0};;n += (size_t){0x1}) { // First pass: get size of input array and determine size of output array.
- if(utf[n] == (uint8_t){0x0}) { // Null-terminator.
- sz = n;
- break;
- }
- if(utf[n] >= (uint8_t){0xF0}) { // Four byte.
- outsz += (size_t){0x4};
- n += (size_t){0x3};
- continue;
- }
- if(utf[n] >= (uint8_t){0xE0}) { // Three bytes.
- outsz += (size_t){0x3};
- n += (size_t){0x2};
- continue;
- }
- if(utf[n] >= (uint8_t){0xC0}) { // Two bytes.
- outsz += (size_t){0x2};
- n += (size_t){0x1};
- continue;
- }
- if(utf[n] >= (uint8_t){0x80}) { // One byte.
- outsz += (size_t){0x1};
- continue;
- }
- // Out of range.
- return 0x1;
- }
- outsz += (size_t){0x1}; // Reserve space for null-terminator.
- if(outszptr != NULL) {
- *outszptr = outsz;
- }
- *codeps = malloc(outsz);
- (*codeps)[outsz - (size_t){0x1}] = (uint32_t){0x0}; // Create null-terminator on output array.
- for(size_t n = (size_t){0x0}, outn = (size_t){0x0};n < sz;n += (size_t){0x1},outn += (size_t){0x1}) { // Second pass: decode UTF-8.
- uint8_t chr = utf[n];
- if(chr >= (uint8_t){0xF7}) { // Out of range.
- return 0x1;
- }
- if(chr >= (uint8_t){0xF0}) { // Four byte.
- uint32_t codep = (uint32_t){(chr ^ 0xF0) << 0x12};
- n += (size_t){0x1};
- chr = utf[n];
- codep += (uint32_t){(chr ^ 0x80) << 0xC};
- n += (size_t){0x1};
- chr = utf[n];
- codep += (uint32_t){(chr ^ 0x80) << 0x6};
- n += (size_t){0x1};
- chr = utf[n];
- codep += (uint32_t){(chr ^ 0x80)};
- (*codeps)[outn] = codep;
- continue;
- }
- if(chr >= (uint8_t){0xE0}) { // Three bytes.
- uint32_t codep = (uint32_t){(chr ^ 0xE0) << 0xC};
- n += (size_t){0x1};
- chr = utf[n];
- codep += (uint32_t){(chr ^ 0x80) << 0x6};
- n += (size_t){0x1};
- chr = utf[n];
- codep += (uint32_t){(chr ^ 0x80)};
- n += (size_t){0x1};
- (*codeps)[outn] = codep;
- continue;
- }
- if(chr >= (uint8_t){0xC0}) { // Two bytes.
- uint32_t codep = (uint32_t){(chr ^ 0xC0) << 0x6};
- n += (size_t){0x1};
- chr = utf[n];
- codep += (uint32_t){(chr ^ 0x80)};
- n += (size_t){0x1};
- (*codeps)[outn] = codep;
- continue;
- }
- if(chr > (uint8_t){0x7F}) { // One byte.
- uint32_t codep = (uint32_t){chr};
- (*codeps)[outn] = codep;
- continue;
- }
- // Out of range.
- return 0x1;
- }
- return 0x0;
-}
diff --git a/src/luma/utf8enc.c b/src/luma/utf8enc.c
deleted file mode 100644
index 3315026..0000000
--- a/src/luma/utf8enc.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- Copyright 2021 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 Affero 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/utf8enc.h>
-# include <stdint.h>
-# include <stdio.h>
-# include <stdlib.h>
-int luma_utf8enc(uint32_t * codeps,uint8_t * * utf,size_t * outszptr) {
- size_t sz = (size_t){0x0}; // Size of input array (bytes).
- size_t outsz = (size_t){0x0}; // Size of output array /bytes).
- for(size_t n = (size_t){0x0};;n += (size_t){0x1}) { // First pass: get size of input array, and determine size of output array.
- uint32_t codep = codeps[n]; // Current Unicode codepoint.
- if(codep == (uint32_t){0x0}) { // U+0000 is Null.
- sz = n;
- break;
- }
- if(codep >= (uint32_t){0x110000}) { // Codepoint out of range.
- return 0x1;
- }
- if(codep >= (uint32_t){0x10000}) { // 4 bytes.
- outsz += (size_t){0x4};
- continue;
- }
- if(codep >= (uint32_t){0x800}) { // 3 bytes.
- outsz += (size_t){0x3};
- continue;
- }
- if(codep >= (uint32_t){0x80}) { // 2 bytes.
- outsz += (size_t){0x2};
- continue;
- }
- // 1 byte.
- outsz += (size_t){0x1};
- }
- outsz += (size_t){0x1}; // Add space for null-terminator.
- if(outszptr != NULL) {
- *outszptr = outsz;
- }
- *utf = malloc(outsz); // Allocate space for output array.
- (*utf)[outsz - (size_t){0x1}] = (uint8_t){0x0}; // Create null-terminator on output array.
- for(size_t n = (size_t){0x0}, outn = (size_t){0x0};n < sz;n += (size_t){0x1},outn += (size_t){0x1}) { // Second pass: encode each codepoint into UTF-8.
- if(codeps[n] >= 0x10000) { // Four bytes.
- (*utf)[outn] = (uint8_t){0xF0 + (codeps[n] >> 0x12)};
- outn += (size_t){0x1};
- (*utf)[outn] = (uint8_t){0x80 + ((codeps[n] >> 0xC) & 0x3F)};
- outn += (size_t){0x1};
- (*utf)[outn] = (uint8_t){0x80 + ((codeps[n] >> 0x6) & 0x3F)};
- outn += (size_t){0x1};
- (*utf)[outn] = (uint8_t){0x80 + (codeps[n] & 0x3F)};
- continue;
- }
- if(codeps[n] >= 0x800) { // Three bytes.
- (*utf)[outn] = (uint8_t){0xE0 + (codeps[n] >> 0xC)};
- outn += (size_t){0x1};
- (*utf)[outn] = (uint8_t){0x80 + ((codeps[n] >> 0x6) & 0x3F)};
- outn += (size_t){0x1};
- (*utf)[outn] = (uint8_t){0x80 + (codeps[n] & 0x3F)};
- continue;
- }
- if(codeps[n] >= 0x80) { // Two bytes.
- (*utf)[outn] = (uint8_t){0xC0 + (codeps[n] >> 0x6)};
- outn += (size_t){0x1};
- (*utf)[outn] = (uint8_t){0x80 + (codeps[n] & 0x3F)};
- continue;
- }
- // One byte.
- (*utf)[outn] = codeps[n];
- }
- return 0x0;
-}
diff --git a/src/main.c b/src/main.c
deleted file mode 100644
index 969bdcd..0000000
--- a/src/main.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- Copyright 2021 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 Affero 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 <locale.h>
-# include <luma/arch.h>
-# include <luma/print.h>
-# include <luma/utf8dec.h>
-# include <luma/utf8enc.h>
-# include <stdint.h>
-# include <stdio.h>
-# include <stdlib.h>
-int main(void) {
- setlocale(LC_ALL,"en_GB.UTF-8");
- enum luma_arch code[] = {
- luma_arch_lab,
- luma_arch_hello,
- };
- for(size_t i = (size_t){0x0};i < sizeof code / sizeof code[0x0];++i) {
- printf("Got code %d.\n",code[i]);
- }
- {
- uint8_t * msg = NULL;
- luma_utf8enc((uint32_t[]){0x00A2,0x2C,0x939,0x2C,0x10348,0x2C,0x20AC,0x2C,0x218A,0x2C,0x1F44B,0x0},&msg,NULL);
- printf("Array: %s\n",msg);
- free((void *){msg});
- }
- {
- uint32_t * codeps = NULL;
- uint8_t * utf = NULL;
- luma_utf8enc((uint32_t[]){0x1F44B,0x0},&utf,NULL);
- luma_utf8dec(utf,&codeps,NULL);
- free((void *)utf);
- printf("It is %u.\n",codeps[0x0]);
- free((void *)codeps);
- }
- luma_print((uint32_t[]){0x48,0x65,0x6C,0x6C,0x6F,0x20,0xFFFD,0x65,0x72,0x65,0x21,0x0},(uint32_t){0xF0});
- exit(EXIT_SUCCESS);
-}