aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Comeaux <jacquesrcomeaux@protonmail.com>2024-07-20 01:08:03 -0500
committerJacques Comeaux <jacquesrcomeaux@protonmail.com>2024-07-20 01:08:03 -0500
commitce3ddfefd39e556f2dc81806fe8560455cf948b4 (patch)
treeb41f29be6f948f0423650b8345ea872bd064e79a
parentc4bd010cf5f55ff7d12e0b9c5cc69e871d590e2c (diff)
Add string functions for stage 3 editor
-rw-r--r--better_assembler/Makefile8
-rw-r--r--better_assembler/data.as74
-rw-r--r--better_assembler/main.as11
-rw-r--r--better_assembler/slowcat.c11
-rw-r--r--better_assembler/string.as48
5 files changed, 152 insertions, 0 deletions
diff --git a/better_assembler/Makefile b/better_assembler/Makefile
new file mode 100644
index 0000000..3f0c463
--- /dev/null
+++ b/better_assembler/Makefile
@@ -0,0 +1,8 @@
+DEVICE = /dev/ttyUSB0
+
+objects = string.as data.as main.as
+
+.PHONY: serial
+serial: $(objects) slowcat
+ cat $(objects) | tr "\n" "\r" | ./slowcat | picocom -b 115200 -q $(DEVICE)
+ @echo
diff --git a/better_assembler/data.as b/better_assembler/data.as
new file mode 100644
index 0000000..008c0d8
--- /dev/null
+++ b/better_assembler/data.as
@@ -0,0 +1,74 @@
+<0300 comma
+Q 0475 03
+Q 0465 15
+Q 0065 01
+Q 0000 12
+<0308 equals
+Q 0505 05
+Q 0405 25
+Q 0515 14
+Q 0050 15
+Q 0000 00
+<0312 lbrace
+Q 0411 14
+Q 0405 22
+Q 0425 03
+Q 0050 15
+Q 0000 00
+<031C rbrace
+Q 0411 22
+Q 0405 22
+Q 0425 03
+Q 0050 15
+Q 0000 00
+<0326 lbracket
+Q 0411 14
+Q 0405 22
+Q 0455 03
+Q 0521 05
+Q 0050 15
+Q 0000 00
+<0332 rbracket
+Q 0411 22
+Q 0405 22
+Q 0455 03
+Q 0521 05
+Q 0050 15
+Q 0000 00
+<033E directive
+Q 0445 04
+Q 0425 22
+Q 0521 03
+Q 0531 11
+Q 0065 05
+Q 0000 12
+<034A register
+Q 0425 22
+Q 0445 07
+Q 0521 23
+Q 0511 05
+Q 0050 15
+Q 0000 00
+<0356 label
+Q 0405 14
+Q 0425 02
+Q 0065 14
+Q 0000 12
+<035E opcode
+Q 0501 17
+Q 0475 03
+Q 0425 04
+Q 0050 15
+Q 0000 00
+<0368 number
+Q 0525 16
+Q 0411 15
+Q 0511 05
+Q 0050 15
+Q 0000 00
+<372 string
+Q 0521 23
+Q 0445 22
+Q 0435 16
+Q 0050 15
+Q 0000 00
diff --git a/better_assembler/main.as b/better_assembler/main.as
new file mode 100644
index 0000000..28b5139
--- /dev/null
+++ b/better_assembler/main.as
@@ -0,0 +1,11 @@
+<0000
+LL R4 3 load string address
+DRF R0 R4
+JIH 0000 print string
+JIL 0174
+DRF R0 R4
+JIH 0000 read string
+JIL 0371
+JA 3770 infinite loop
+Q 0014 00
+Q 0200 00
diff --git a/better_assembler/slowcat.c b/better_assembler/slowcat.c
new file mode 100644
index 0000000..67725d4
--- /dev/null
+++ b/better_assembler/slowcat.c
@@ -0,0 +1,11 @@
+#include <unistd.h>
+#include <stdint.h>
+
+int main() {
+ uint8_t byte;
+ while (read(STDIN_FILENO, &byte, 1)) {
+ write(STDOUT_FILENO, &byte, 1);
+ usleep(10000);
+ }
+ return 0;
+}
diff --git a/better_assembler/string.as b/better_assembler/string.as
new file mode 100644
index 0000000..35f9248
--- /dev/null
+++ b/better_assembler/string.as
@@ -0,0 +1,48 @@
+<0100 putstr
+register zero : string offset
+register one : current character, uart status
+register two : tx fifo full bitmask
+register three : uart zero base
+LL R3 5 load uart zero base
+DI R2 40 tx fifo full bitmask
+LI5 R1 R3 6 get uart status
+BT R1 R2 check if ready to send
+JN 374 loop if not ready
+LBI R1 R0 0 load one char from memory
+BT R1 R1 test byte
+JE 2 done if zero
+SBI R1 R3 0 send one byte
+AAI8 R0 1 increment string pointer
+JA 3766 next char
+JR R14 jump to link register
+Q 0400 00 uart zero base
+Q 0400 03
+<0200 getstr
+register zero : string offset
+register one : current character, uart status
+register two : rx fifo empty bitmask
+register three : uart zero base
+LL R3 12 load uart zero base
+DI R2 60 rx fifo empty or tx fifo full bitmask
+LI5 R1 R3 6 get uart status
+BT R1 R2 check if ready to receive and transmit
+JN 374 loop if not ready
+LBI R1 R3 0 get one char
+SBI R1 R3 0 echo the char
+CI R1 015 compare to carriage return
+JE 2 done if equal
+SBI R1 R0 0 write one char to memory
+AAI8 R0 1 increment string pointer
+JA 3764 next char
+DI R1 000 null byte
+SBI R1 R0 0 store null byte
+DI R2 40 tx fifo full bitmask
+LI5 R1 R3 6 get uart status
+BT R1 R2 check if ready to transmit
+JN 374 loop if not ready
+DI R1 012 newline
+SBI R1 R3 0 send newline
+JR R14 jump to link register
+Q 0000 00 alignment
+Q 0400 00 uart zero base
+Q 0400 03