summaryrefslogtreecommitdiffstats
path: root/sw-old/z80/tests/pio
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-10-30 11:41:24 +0100
committerNao Pross <naopross@thearcway.org>2018-10-30 11:41:24 +0100
commit43be150dc6e84f6f6eeb071cd3cdb7fc21125d60 (patch)
tree541fd3d690c1bdfd7b68d684029a400b80f4aa06 /sw-old/z80/tests/pio
parentAdd datasheets for ATmega328 and 74LS259 (diff)
downloadz80uPC-43be150dc6e84f6f6eeb071cd3cdb7fc21125d60.tar.gz
z80uPC-43be150dc6e84f6f6eeb071cd3cdb7fc21125d60.zip
Move sw to sw-old and hw to hw-altium, add kicad files
Diffstat (limited to 'sw-old/z80/tests/pio')
-rw-r--r--sw-old/z80/tests/pio/crt0.s38
-rw-r--r--sw-old/z80/tests/pio/main.c50
-rw-r--r--sw-old/z80/tests/pio/makefile72
3 files changed, 160 insertions, 0 deletions
diff --git a/sw-old/z80/tests/pio/crt0.s b/sw-old/z80/tests/pio/crt0.s
new file mode 100644
index 0000000..c900065
--- /dev/null
+++ b/sw-old/z80/tests/pio/crt0.s
@@ -0,0 +1,38 @@
+ .module crt0
+ .area _HEADER (ABS)
+
+;; Reset vectors
+ .org 0
+ jp init
+
+ .org 0x38 ; the instruction 0xff (not written) resets to this location
+ jp init
+
+;; main code
+ .org 0x100
+ .globl _main
+
+init:
+ ;; Set stack pointer directly above top of memory.
+ ld sp,#0xffff
+
+ ;; Start of the program
+ call _main
+ jp _exit
+
+_exit:
+ halt
+ ; jp _exit
+
+;; 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
diff --git a/sw-old/z80/tests/pio/main.c b/sw-old/z80/tests/pio/main.c
new file mode 100644
index 0000000..7ac64bc
--- /dev/null
+++ b/sw-old/z80/tests/pio/main.c
@@ -0,0 +1,50 @@
+// #include "pio.h"
+
+#include <stdint.h>
+
+#define PIO_A_DATA 0x10
+#define PIO_B_DATA 0x11
+#define PIO_A_CMD 0x12
+#define PIO_B_CMD 0x13
+
+void main(void)
+{
+ __asm
+ ;; output variable
+ ld h, #0x00
+
+ ;; set bit mode
+ ld c, #PIO_B_CMD
+
+ ld a, #0xCF
+ out (c), a
+
+ ;; set all pins to output
+ ld a, #0x00
+ out (c), a
+
+ ;; disable interrupts
+ ld a, #0x0C
+ out (c), a
+
+ ;; load data addr
+ ld c, #PIO_B_DATA
+loop:
+ out (c), h
+ ld a, h
+
+ cpl
+ ld h, a
+ jr loop
+ __endasm;
+
+ // uint8_t i = 0;
+
+ // pio_set_mode(PIO_A, PIO_MODE_BIT_IO, 0x00);
+ // pio_set_interrupts(PIO_A, PIO_INT_DISABLE);
+
+ // while (1) {
+ // pio_write(PIO_A, i);
+ // i = ~i;
+ // }
+} \ No newline at end of file
diff --git a/sw-old/z80/tests/pio/makefile b/sw-old/z80/tests/pio/makefile
new file mode 100644
index 0000000..1213902
--- /dev/null
+++ b/sw-old/z80/tests/pio/makefile
@@ -0,0 +1,72 @@
+####
+# source code settings
+#
+OSNAME := pio_test
+
+CSOURCES := $(wildcard *.c)
+LIBS := ../../arch/build/arch.a \
+ ../../drivers/build/drivers.a
+
+OBJECTS := $(patsubst %.c,build/%.rel,$(CSOURCES))
+HEXFILE := build/$(OSNAME).hex
+BINARY := build/$(OSNAME).bin
+
+###
+# compiler settings
+#
+CC := sdcc
+
+CFLAGS := -mz80 \
+ --no-std-crt0 build/crt0.rel \
+ --allow-unsafe-read \
+ -I . \
+ -I ../../arch/include \
+ -I ../../drivers/include \
+ -DDEBUG
+
+LDFLAGS := -mz80 \
+ --no-std-crt0 build/crt0.rel \
+ -L ../../drivers/build \
+ -l drivers.a \
+ -pedantic \
+ --code-loc 0x0200
+ # --data-loc 0x2000
+
+.PHONY: flash dirs dis clean
+all: $(BINARY)
+
+flash: $(BINARY)
+ minipro -p M28C64 -w $<
+
+# build binary
+$(BINARY): $(OBJECTS) dirs
+ $(CC) $(LDFLAGS) $(OBJECTS) -o $(HEXFILE)
+ makebin -s 8192 -yo 1 $(HEXFILE) $(BINARY)
+
+$(OBJECTS): build/%.rel : %.c $(CSOURCES) dirs build/crt0.rel $(LIBS)
+ @printf "\n"
+ $(CC) $(CFLAGS) -c $< -o $@
+
+$(LIBS): %.a:
+ @printf "\n"
+ make -C $(shell printf $@ | sed 's:build.*.::')
+
+build/crt0.rel: crt0.s
+ sdasz80 -o $<
+ @mv crt0.rel build/
+
+dirs:
+ mkdir -p build
+
+dis: $(BINARY)
+ dz80 -b -n -t $(BINARY)
+ r2 -a z80 $< \
+ -c 'afn main 0x200; \
+ pd 0x10; \
+ s 0x100; \
+ pd 10; \
+ s 0x200; \
+ pd 0x95' | tee build/dis.txt
+
+clean:
+ - rm -rd build