diff options
author | Thomas Albers <thomas@thomaslabs.org> | 2023-08-14 10:47:54 +0200 |
---|---|---|
committer | Thomas Albers <thomas@thomaslabs.org> | 2023-08-14 10:47:54 +0200 |
commit | ad2623d8c4bc51638343ae9a628f8647ff558155 (patch) | |
tree | d41e8390824e6fee4c02eb044c7f5acb94b478bf /stn |
Diffstat (limited to 'stn')
-rw-r--r-- | stn/Makefile | 40 | ||||
-rw-r--r-- | stn/crt0.asm | 66 | ||||
-rw-r--r-- | stn/font.c | 101 | ||||
-rw-r--r-- | stn/stn.c | 236 |
4 files changed, 443 insertions, 0 deletions
diff --git a/stn/Makefile b/stn/Makefile new file mode 100644 index 0000000..861b459 --- /dev/null +++ b/stn/Makefile @@ -0,0 +1,40 @@ +ASM=crt0.asm +SRC=stn.c + +OBJ=$(ASM:%.asm=build/%.rel) $(SRC:%.c=build/%.rel) +IHX=build/stn.ihx +TARGET=stn.hex + +CFLAGS=-mz80 -I../dev/include -I. --Werror +LDFLAGS=-mz80 --no-std-crt0 --code-loc 0x4100 --data-loc 0xC000 -Wl-b_GSINIT=0x4080 + +all : $(TARGET) + +build/%.rel : %.asm + @echo ' (AS)' $< + @sdcpp -P -I. -I../dev/include -DASSEMBLY $< > build/$< + @sdasz80 -g -o $@ build/$< + +build/%.rel : %.c + @echo ' (CC)' $< + @sdcc $(CFLAGS) -c -o $@ $< + +$(IHX) : $(OBJ) + @echo ' (LD)' $(OBJ) + @sdcc $(LDFLAGS) -o $@ $(OBJ) + +$(TARGET) : $(IHX) + @hex2bin.py $< $@ + +.PHONY : upload +upload : + + +.PHONE : flash +flash : + @zup -a 5 -P -b38400 -p /dev/ttyUSB0 "w:0:4000:$(TARGET)" +# zup -a 5 -P -p /dev/ttyUSB0 "w:0:4000:$(TARGET)" + +.PHONY : clean +clean : + @rm -rf build/* $(TARGET) diff --git a/stn/crt0.asm b/stn/crt0.asm new file mode 100644 index 0000000..2fdef59 --- /dev/null +++ b/stn/crt0.asm @@ -0,0 +1,66 @@ +#include <zeta.h> + + .module crt0 + .globl _main + + .area _HEADER (ABS) + ;; Reset vector + .org 0x4000 + ld SP, #0x00 + jp init + ;; ISR table + + ;; Init code +init: + call gsinit + call _main +1$: + halt + jr 1$ + + ;; Ordering of segments for the linker. + .area _HOME + .area _CODE + .area _INITIALIZER + .area _GSINIT + .area _GSFINAL + + .area _DATA + .area _INITIALIZED + .area _BSEG + .area _BSS + .area _HEAP + + .area _CODE + + .area _GSINIT +gsinit: + ;; Default-initialized global variables. + ld bc, #l__DATA + ld a, b + or a, c + jr Z, zeroed_data + ld hl, #s__DATA + ld (hl), #0x00 + dec bc + ld a, b + or a, c + jr Z, zeroed_data + ld e, l + ld d, h + inc de + ldir +zeroed_data: + ;; Explicitly initialized global variables. + ld bc, #l__INITIALIZER + ld a, b + or a, c + jr Z, gsinit_next + ld de, #s__INITIALIZED + ld hl, #s__INITIALIZER + ldir + +gsinit_next: + + .area _GSFINAL + ret diff --git a/stn/font.c b/stn/font.c new file mode 100644 index 0000000..2d5c4cf --- /dev/null +++ b/stn/font.c @@ -0,0 +1,101 @@ +#include <stdint.h> + +const uint8_t font[97][8] = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // ' ' + {0x00, 0x00, 0x00, 0x4F, 0x4F, 0x00, 0x00, 0x00}, // ! + {0x00, 0x07, 0x07, 0x00, 0x00, 0x07, 0x07, 0x00}, // " + {0x14, 0x7F, 0x7F, 0x14, 0x14, 0x7F, 0x7F, 0x14}, // # + {0x00, 0x24, 0x2E, 0x6B, 0x6B, 0x3A, 0x12, 0x00}, // $ + {0x00, 0x63, 0x33, 0x18, 0x0C, 0x66, 0x63, 0x00}, // % + {0x00, 0x32, 0x7F, 0x4D, 0x4D, 0x77, 0x72, 0x50}, // & + {0x00, 0x00, 0x00, 0x04, 0x06, 0x03, 0x01, 0x00}, // ' + {0x00, 0x00, 0x1C, 0x3E, 0x63, 0x41, 0x00, 0x00}, // ( + {0x00, 0x00, 0x41, 0x63, 0x3E, 0x1C, 0x00, 0x00}, // ) + {0x08, 0x2A, 0x3E, 0x1C, 0x1C, 0x3E, 0x2A, 0x08}, // * + {0x00, 0x08, 0x08, 0x3E, 0x3E, 0x08, 0x08, 0x00}, // + + {0x00, 0x00, 0x80, 0xE0, 0x60, 0x00, 0x00, 0x00}, // , + {0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00}, // - + {0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00}, // . + {0x00, 0x40, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x02}, // / + {0x00, 0x3E, 0x7F, 0x49, 0x45, 0x7F, 0x3E, 0x00}, // 0 + {0x00, 0x40, 0x44, 0x7F, 0x7F, 0x40, 0x40, 0x00}, // 1 + {0x00, 0x62, 0x73, 0x51, 0x49, 0x4F, 0x46, 0x00}, // 2 + {0x003, 0x22, 0x63, 0x49, 0x49, 0x7F, 0x36, 0x00}, // + {0x00, 0x18, 0x18, 0x14, 0x16, 0x7F, 0x7F, 0x10}, // 4 + {0x00, 0x27, 0x67, 0x45, 0x45, 0x7D, 0x39, 0x00}, // 5 + {0x00, 0x3E, 0x7F, 0x49, 0x49, 0x7B, 0x32, 0x00}, // 6 + {0x00, 0x03, 0x03, 0x79, 0x7D, 0x07, 0x03, 0x00}, // 7 + {0x00, 0x36, 0x7F, 0x49, 0x49, 0x7F, 0x36, 0x00}, // 8 + {0x00, 0x26, 0x6F, 0x49, 0x49, 0x7F, 0x3E, 0x00}, // 9 + {0x00, 0x00, 0x00, 0x24, 0x24, 0x00, 0x00, 0x00}, // : + {0x00, 0x00, 0x80, 0xE4, 0x64, 0x00, 0x00, 0x00}, // // + {0x00, 0x08, 0x1C, 0x36, 0x63, 0x41, 0x41, 0x00}, // < + {0x00, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00}, // = + {0x00, 0x41, 0x41, 0x63, 0x36, 0x1C, 0x08, 0x00}, // > + {0x00, 0x02, 0x03, 0x51, 0x59, 0x0F, 0x06, 0x00}, // ? + {0x00, 0x3E, 0x7F, 0x41, 0x4D, 0x4F, 0x2E, 0x00}, // @ + {0x00, 0x7C, 0x7E, 0x0B, 0x0B, 0x7E, 0x7C, 0x00}, // A + {0x00, 0x7F, 0x7F, 0x49, 0x49, 0x7F, 0x36, 0x00}, // B + {0x00, 0x3E, 0x7F, 0x41, 0x41, 0x63, 0x22, 0x00}, // C + {0x00, 0x7F, 0x7F, 0x41, 0x63, 0x3E, 0x1C, 0x00}, // D + {0x00, 0x7F, 0x7F, 0x49, 0x49, 0x41, 0x41, 0x00}, // E + {0x00, 0x7F, 0x7F, 0x09, 0x09, 0x01, 0x01, 0x00}, // F + {0x00, 0x3E, 0x7F, 0x41, 0x49, 0x7B, 0x3A, 0x00}, // G + {0x00, 0x7F, 0x7F, 0x08, 0x08, 0x7F, 0x7F, 0x00}, // H + {0x00, 0x00, 0x41, 0x7F, 0x7F, 0x41, 0x00, 0x00}, // I + {0x00, 0x20, 0x60, 0x41, 0x7F, 0x3F, 0x01, 0x00}, // J + {0x00, 0x7F, 0x7F, 0x1C, 0x36, 0x63, 0x41, 0x00}, // K + {0x00, 0x7F, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00}, // L + {0x00, 0x7F, 0x7F, 0x06, 0x0C, 0x06, 0x7F, 0x7F}, // M + {0x00, 0x7F, 0x7F, 0x0E, 0x1C, 0x7F, 0x7F, 0x00}, // N + {0x00, 0x3E, 0x7F, 0x41, 0x41, 0x7F, 0x3E, 0x00}, // O + {0x00, 0x7F, 0x7F, 0x09, 0x09, 0x0F, 0x06, 0x00}, // P + {0x00, 0x1E, 0x3F, 0x21, 0x61, 0x7F, 0x5E, 0x00}, // Q + {0x00, 0x7F, 0x7F, 0x19, 0x39, 0x6F, 0x46, 0x00}, // R + {0x00, 0x26, 0x6F, 0x49, 0x49, 0x7B, 0x32, 0x00}, // S + {0x00, 0x01, 0x01, 0x7F, 0x7F, 0x01, 0x01, 0x00}, // T + {0x00, 0x3F, 0x7F, 0x40, 0x40, 0x7F, 0x3F, 0x00}, // U + {0x00, 0x1F, 0x3F, 0x60, 0x60, 0x3F, 0x1F, 0x00}, // V + {0x00, 0x7F, 0x7F, 0x30, 0x18, 0x30, 0x7F, 0x7F}, // W + {0x00, 0x63, 0x77, 0x1C, 0x1C, 0x77, 0x63, 0x00}, // X + {0x00, 0x07, 0x0F, 0x78, 0x78, 0x0F, 0x07, 0x00}, // Y + {0x00, 0x61, 0x71, 0x59, 0x4D, 0x47, 0x43, 0x00}, // Z + {0x00, 0x00, 0x7F, 0x7F, 0x41, 0x41, 0x00, 0x00}, // [ + {0x00, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01}, /* \ */ + {0x00, 0x00, 0x41, 0x41, 0x7F, 0x7F, 0x00, 0x00}, // ] + {0x00, 0x08, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x08}, // ^ + {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80}, // _ + {0x00, 0x00, 0x00, 0x04, 0x07, 0x03, 0x00, 0x00}, // ` + {0x00, 0x20, 0x74, 0x54, 0x54, 0x7C, 0x78, 0x00}, // a + {0x00, 0x7E, 0x7E, 0x48, 0x48, 0x78, 0x30, 0x00}, // b + {0x00, 0x38, 0x7C, 0x44, 0x44, 0x44, 0x00, 0x00}, // c + {0x00, 0x30, 0x78, 0x48, 0x48, 0x7E, 0x7E, 0x00}, // d + {0x00, 0x38, 0x7C, 0x54, 0x54, 0x5C, 0x18, 0x00}, // e + {0x00, 0x00, 0x08, 0x7C, 0x7E, 0x0A, 0x0A, 0x00}, // f + {0x00, 0x98, 0xBC, 0xA4, 0xA4, 0xFC, 0x7C, 0x00}, // g + {0x00, 0x7E, 0x7E, 0x08, 0x08, 0x78, 0x70, 0x00}, // h + {0x00, 0x00, 0x48, 0x7A, 0x7A, 0x40, 0x00, 0x00}, // i + {0x00, 0x00, 0x80, 0x80, 0x80, 0xFA, 0x7A, 0x00}, // j + {0x00, 0x7E, 0x7E, 0x10, 0x38, 0x68, 0x40, 0x00}, // k + {0x00, 0x00, 0x42, 0x7E, 0x7E, 0x40, 0x00, 0x00}, // l + {0x00, 0x7C, 0x7C, 0x18, 0x38, 0x1C, 0x7C, 0x78}, // m + {0x00, 0x7C, 0x7C, 0x04, 0x04, 0x7C, 0x78, 0x00}, // n + {0x00, 0x38, 0x7C, 0x44, 0x44, 0x7C, 0x38, 0x00}, // o + {0x00, 0xFC, 0xFC, 0x24, 0x24, 0x3C, 0x18, 0x00}, // p + {0x00, 0x18, 0x3C, 0x24, 0x24, 0xFC, 0xFC, 0x00}, // q + {0x00, 0x7C, 0x7C, 0x04, 0x04, 0x0C, 0x08, 0x00}, // r + {0x00, 0x48, 0x5C, 0x54, 0x54, 0x74, 0x24, 0x00}, // s + {0x00, 0x04, 0x04, 0x3E, 0x7E, 0x44, 0x44, 0x00}, // t + {0x00, 0x3C, 0x7C, 0x40, 0x40, 0x7C, 0x7C, 0x00}, // u + {0x00, 0x1C, 0x3C, 0x60, 0x60, 0x3C, 0x1C, 0x00}, // v + {0x00, 0x1C, 0x7C, 0x70, 0x38, 0x70, 0x7C, 0x1C}, // w + {0x00, 0x44, 0x6C, 0x38, 0x38, 0x6C, 0x44, 0x00}, // x + {0x00, 0x9C, 0xBC, 0xA0, 0xE0, 0x7C, 0x3C, 0x00}, // y + {0x00, 0x44, 0x64, 0x74, 0x5C, 0x4C, 0x44, 0x00}, // z + {0x00, 0x00, 0x41, 0x41, 0x77, 0x3E, 0x08, 0x08}, // { + {0x00, 0x00, 0x00, 0x77, 0x77, 0x00, 0x00, 0x00}, // | + {0x00, 0x00, 0x08, 0x08, 0x3E, 0x77, 0x41, 0x41}, // } + {0x00, 0x01, 0x03, 0x02, 0x03, 0x01, 0x03, 0x02}, // ~ + {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // DEL + {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} // CURSOR +}; 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; +} |