summaryrefslogtreecommitdiff
path: root/template
diff options
context:
space:
mode:
authorThomas Albers <thomas@thomaslabs.org>2023-08-14 10:47:54 +0200
committerThomas Albers <thomas@thomaslabs.org>2023-08-14 10:47:54 +0200
commitad2623d8c4bc51638343ae9a628f8647ff558155 (patch)
treed41e8390824e6fee4c02eb044c7f5acb94b478bf /template
Initial commitHEADmaster
Diffstat (limited to 'template')
-rw-r--r--template/Makefile31
-rw-r--r--template/crt0.asm59
-rw-r--r--template/template.c30
3 files changed, 120 insertions, 0 deletions
diff --git a/template/Makefile b/template/Makefile
new file mode 100644
index 0000000..32ce503
--- /dev/null
+++ b/template/Makefile
@@ -0,0 +1,31 @@
+ASM=crt0.asm
+SRC=bootloader.c
+
+OBJ=$(ASM:%.asm=build/%.rel) $(SRC:%.c=build/%.rel)
+IHX=output/bootloader.ihx
+TARGET=bootloader.hex
+
+CFLAGS=-mz80
+LDFLAGS=-mz80 --no-std-crt0 --code-loc 0x4010 -Wl-b_GSINIT=0x4150
+
+all : $(TARGET)
+
+output/%.rel : %.asm
+ sdasz80 -g -o $@ $<
+
+output/%.rel : %.c
+ sdcc $(CFLAGS) -c -o $@ $<
+
+$(IHX) : $(OBJ)
+ sdcc $(LDFLAGS) -o $@ $(OBJ)
+
+$(TARGET) : $(IHX)
+ hex2bin.py $< $@
+
+.PHONY: upload
+upload:
+ z80up $(TARGET) -p /dev/ttyUSB0
+
+.PHONY : clean
+clean :
+ @rm -rf output/* $(TARGET)
diff --git a/template/crt0.asm b/template/crt0.asm
new file mode 100644
index 0000000..24c475d
--- /dev/null
+++ b/template/crt0.asm
@@ -0,0 +1,59 @@
+ .module crt0
+ .globl _main
+
+ .area _HEADER (ABS)
+ ;; Reset vector
+ .org 0x4000
+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/template/template.c b/template/template.c
new file mode 100644
index 0000000..8237d68
--- /dev/null
+++ b/template/template.c
@@ -0,0 +1,30 @@
+#define CPU_FREQ 1843200
+
+__sfr __at 0x30 sio_a_data;
+__sfr __at 0x31 sio_b_data;
+__sfr __at 0x32 sio_a_ctrl;
+__sfr __at 0x33 sio_b_ctrl;
+
+void putchar(char c)
+{
+ unsigned char ctrl = 0;
+
+ sio_a_data = c;
+
+ while (!(ctrl & 0x04)) {
+ sio_a_ctrl = ctrl;
+ ctrl = sio_a_ctrl;
+ }
+}
+
+void print(const char *str)
+{
+ for (; *str; str++)
+ putchar(*str);
+}
+
+int main()
+{
+ print("Hello World from C");
+ return 0;
+}