summaryrefslogtreecommitdiff
path: root/stn/stn.c
diff options
context:
space:
mode:
Diffstat (limited to 'stn/stn.c')
-rw-r--r--stn/stn.c236
1 files changed, 236 insertions, 0 deletions
diff --git a/stn/stn.c b/stn/stn.c
new file mode 100644
index 0000000..7ad307a
--- /dev/null
+++ b/stn/stn.c
@@ -0,0 +1,236 @@
+#include <zeta.h>
+
+#include <stdint.h>
+
+#define NOP \
+ do { \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ __asm__("nop"); \
+ } while (0)
+
+// extern const uint8_t font[97][8];
+
+static inline void
+stn_display_on(void)
+{
+ stn_1_inst = 0x3F;
+ NOP;
+ stn_2_inst = 0x3F;
+ NOP;
+}
+
+static inline
+void stn_start_line(uint8_t x)
+{
+ stn_1_inst = 0xC0 | (x & 0x3F);
+ NOP;
+ NOP;
+ NOP;
+ stn_2_inst = 0xC0 | (x & 0x3F);
+ NOP;
+ NOP;
+ NOP;
+}
+
+static inline void
+stn_set_row(uint8_t x)
+{
+ stn_1_inst = 0xB8 | x;
+ NOP;
+ NOP;
+ NOP;
+ stn_2_inst = 0xB8 | x;
+ NOP;
+ NOP;
+ NOP;
+}
+
+
+static inline void
+stn_set_column(uint8_t x)
+{
+ if (x & 0xC0)
+ stn_2_inst = 0x40 | (x >> 6);
+ else
+ stn_1_inst = 0x40 | x;
+
+ NOP;
+ NOP;
+ NOP;
+}
+
+static inline void
+stn_set_columns(uint8_t x)
+{
+ stn_1_inst = 0x40 | x;
+ NOP;
+ NOP;
+ NOP;
+ stn_2_inst = 0x40 | x;
+ NOP;
+ NOP;
+ NOP;
+}
+
+void
+stn_clear_screen(void)
+{
+ for (uint8_t i = 0; i < 8; ++i) {
+ // set x address
+ stn_set_row(i);
+
+ // set y address
+ stn_set_columns(0);
+
+ for (uint8_t j = 0; j < 64; ++j) {
+ stn_1_data = 0;
+ NOP;
+ NOP;
+ NOP;
+ stn_2_data = 0;
+ NOP;
+ NOP;
+ NOP;
+ }
+ }
+}
+
+/* void */
+/* stn_print(int x, int y, const char *str) */
+/* { */
+/* stn_set_row(y); */
+/* stn_set_column(x << 3); */
+
+/* while (*str) { */
+/* const uint8_t *p = font[(*str++) - ' ']; */
+
+/* if (x < 8) { */
+/* for (uint8_t i = 0; i < 8; ++i) */
+/* stn_1_data = p[i]; */
+/* } else { */
+/* for (uint8_t i = 0; i < 8; ++i) */
+/* stn_2_data = p[i]; */
+/* } */
+
+/* if (++x & 0xF0) { */
+/* x = 0; */
+/* stn_set_row(++y & 0x07); */
+/* stn_set_columns(0); */
+/* } */
+/* } */
+/* } */
+
+int
+main(void)
+{
+ stn_display_on();
+ stn_start_line(0);
+ stn_clear_screen();
+ // stn_print(1, 1, "Hello World! how are you");
+ stn_set_columns(0);
+
+ while (1) {
+ stn_set_columns(0);
+
+ for (uint8_t i = 0; i < 64; ++i) {
+ stn_1_data = i;
+ NOP;
+ NOP;
+ NOP;
+ }
+
+ volatile uint8_t c;
+ for (uint8_t i = 0; i < 9; ++i) {
+ c = stn_1_data;
+ NOP;
+ NOP;
+ NOP;
+ }
+
+
+ /* for (uint8_t i = 0; i < 64; ++i) { */
+ /* stn_2_data = i; */
+ /* NOP; */
+ /* } */
+
+ stn_1_inst = 0x40 | 0;
+ NOP;
+ NOP;
+ NOP;
+
+ /* // stn_set_columns(0); */
+ for (uint8_t i = 0; i < 64; ++i) {
+ c = stn_1_data;
+ NOP;
+ NOP;
+ NOP;
+ stn_2_data = c;
+ NOP;
+ NOP;
+ NOP;
+ }
+ }
+
+ // return 0;
+}