summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2017-11-09 13:17:35 +0100
committerNao Pross <naopross@thearcway.org>2017-11-09 13:17:35 +0100
commit3b2f2ea6c6fbfcb23ea9ab324c83d602d45a8820 (patch)
tree2362bfb36432e551f2f0025d4f12554bddc863c9
parentUpdate gitignore and add sdcc manual (diff)
downloadz80uPC-3b2f2ea6c6fbfcb23ea9ab324c83d602d45a8820.tar.gz
z80uPC-3b2f2ea6c6fbfcb23ea9ab324c83d602d45a8820.zip
Update makefile, and bug fix in pio driver and usart
-rw-r--r--sw/z80/arch/include/addresses.h (renamed from sw/z80/arch/addresses.h)0
-rw-r--r--sw/z80/arch/include/sleep.h14
-rw-r--r--sw/z80/arch/makefile27
-rw-r--r--sw/z80/arch/sleep.c16
-rw-r--r--sw/z80/drivers/include/pio.h19
-rw-r--r--sw/z80/drivers/include/usart.h4
-rw-r--r--sw/z80/drivers/makefile8
-rw-r--r--sw/z80/drivers/pio.c11
-rw-r--r--sw/z80/drivers/usart.c2
-rw-r--r--sw/z80/tests/asm/main.s40
-rw-r--r--sw/z80/tests/asm/makefile47
-rw-r--r--sw/z80/tests/pio/crt0.s2
-rw-r--r--sw/z80/tests/pio/dis.txt225
-rw-r--r--sw/z80/tests/pio/main.c5
-rw-r--r--sw/z80/tests/pio/makefile24
-rw-r--r--sw/z80/tests/ram/makefile1
-rw-r--r--sw/z80/tests/usart/crt0.s38
-rw-r--r--sw/z80/tests/usart/main.c11
-rw-r--r--sw/z80/tests/usart/makefile72
19 files changed, 532 insertions, 34 deletions
diff --git a/sw/z80/arch/addresses.h b/sw/z80/arch/include/addresses.h
index 07ab473..07ab473 100644
--- a/sw/z80/arch/addresses.h
+++ b/sw/z80/arch/include/addresses.h
diff --git a/sw/z80/arch/include/sleep.h b/sw/z80/arch/include/sleep.h
new file mode 100644
index 0000000..bd4214b
--- /dev/null
+++ b/sw/z80/arch/include/sleep.h
@@ -0,0 +1,14 @@
+#ifndef __SLEEP_H__
+#define __SLEEP_H__
+
+#ifndef F_CPU
+#error undefined CPU clock speed
+#endif
+
+#define SLEEP_UNIT ((F_CPU/4)/2)
+
+#include <stdint.h>
+
+void usleep(uint16_t microseconds);
+
+#endif // __SLEEP_H__ \ No newline at end of file
diff --git a/sw/z80/arch/makefile b/sw/z80/arch/makefile
new file mode 100644
index 0000000..2763c10
--- /dev/null
+++ b/sw/z80/arch/makefile
@@ -0,0 +1,27 @@
+# Drivers library
+
+LIB := build/arch.a
+SOURCES := $(wildcard *.c)
+OBJECTS := $(patsubst %.c,build/%.rel,$(SOURCES))
+
+F_CPU := 10000
+
+CC := sdcc
+AR := sdar
+CFLAGS := -mz80 \
+ -Iinclude \
+ -DDEBUG \
+ -DF_CPU=$(F_CPU)
+
+.PHONY: dirs clean
+$(LIB): $(OBJECTS)
+ $(AR) rcs $@ $(OBJECTS)
+
+$(OBJECTS): build/%.rel: %.c $(SOURCES) dirs
+ $(CC) $(CFLAGS) -c $< -o $@
+
+dirs:
+ mkdir -p build
+
+clean:
+ - rm -rd build
diff --git a/sw/z80/arch/sleep.c b/sw/z80/arch/sleep.c
new file mode 100644
index 0000000..154e7ec
--- /dev/null
+++ b/sw/z80/arch/sleep.c
@@ -0,0 +1,16 @@
+#include "sleep.h"
+
+void usleep(uint16_t microseconds)
+{
+ __asm
+ pop hl
+loop:
+ ld bc, #SLEEP_UNIT
+unit:
+ nop
+ dec bc
+ jr nz, unit
+ dec hl
+ jr nz,loop
+ __endasm;
+} \ No newline at end of file
diff --git a/sw/z80/drivers/include/pio.h b/sw/z80/drivers/include/pio.h
index a4b6fc2..a1137e4 100644
--- a/sw/z80/drivers/include/pio.h
+++ b/sw/z80/drivers/include/pio.h
@@ -10,23 +10,24 @@
// registers
#define PIO_REG_DATA 0
-#define PIO_REG_CTRL 1
+#define PIO_REG_CTRL 2
// #define PIO_REG_DATA_A (PIO_A + PIO_REG_PORT)
// #define PIO_REG_DATA_B 1 (PIO_B + PIO_REG_PORT)
// #define PIO_REG_CTRL_A 2 (PIO_A + PIO_REG_CTRL)
// #define PIO_REG_CTRL_B 3 (PIO_B + PIO_REG_CTRL)
-#define PIO_MODE_BYTE_IN 0
-#define PIO_MODE_BYTE_OUT 1
-#define PIO_MODE_BYTE_BI 2
-#define PIO_MODE_BIT_IO 3
+#define PIO_MODE_BYTE_OUT 0 // mode 0
+#define PIO_MODE_BYTE_IN 1 // mode 1
+#define PIO_MODE_BYTE_BI 2 // mode 2
+#define PIO_MODE_BIT_IO 3 // mode 3
-#define PIO_INT_ACTIVE_HIGH (1<<5)
-#define PIO_INT_AND_MODE (1<<6)
-#define PIO_INT_ENABLE (1<<7)
+#define PIO_INT_DISABLE 0
+#define PIO_INT_ACTIVE_HIGH 2
+#define PIO_INT_AND_MODE 4
+#define PIO_INT_ENABLE 8
-/* functions used internallyto interface with the device */
+/* functions used internally to interface with the device */
inline void _pio_write(uint8_t reg, uint8_t data);
inline uint8_t _pio_read(uint8_t reg);
diff --git a/sw/z80/drivers/include/usart.h b/sw/z80/drivers/include/usart.h
index bb06aab..fdc01e2 100644
--- a/sw/z80/drivers/include/usart.h
+++ b/sw/z80/drivers/include/usart.h
@@ -48,8 +48,8 @@
#define USART_AUTOFLOW_CTS 2
#define USART_AUTOFLOW_OFF 0
-typedef unsigned int uint;
-typedef uint8_t register_t;
+typedef unsigned int uint;
+typedef volatile uint8_t register_t;
/* stuctures for usart registers */
struct IER
diff --git a/sw/z80/drivers/makefile b/sw/z80/drivers/makefile
index 98f453a..65ded58 100644
--- a/sw/z80/drivers/makefile
+++ b/sw/z80/drivers/makefile
@@ -6,15 +6,17 @@ OBJECTS := $(patsubst %.c,build/%.rel,$(SOURCES))
CC := sdcc
AR := sdar
-CFLAGS := -mz80 -Iinclude -I../arch -DDEBUG
+CFLAGS := -mz80 -Iinclude -I../arch/include -DDEBUG
-.PHONY: dirs clean
+.PHONY: dirs rebuild clean
$(LIB): $(OBJECTS)
- $(AR) rcs $@ $(OBJECTS)
+ $(AR) vrcs $@ $(OBJECTS)
$(OBJECTS): build/%.rel: %.c $(SOURCES) dirs
$(CC) $(CFLAGS) -c $< -o $@
+rebuild: clean $(LIB)
+
dirs:
mkdir -p build
diff --git a/sw/z80/drivers/pio.c b/sw/z80/drivers/pio.c
index 18697d8..272e191 100644
--- a/sw/z80/drivers/pio.c
+++ b/sw/z80/drivers/pio.c
@@ -1,6 +1,7 @@
#include "pio.h"
-#if 0 /* old inline asm implementation */
+#ifdef PIO_ASM_INTERFACE
+/* old inline asm implementation */
inline void _pio_write(uint8_t reg, uint8_t data)
{
__asm
@@ -17,7 +18,6 @@ inline void _pio_write(uint8_t reg, uint8_t data)
__endasm;
}
-// incomplete
inline uint8_t _pio_read(uint8_t reg) __naked
{
__asm
@@ -31,7 +31,8 @@ inline uint8_t _pio_read(uint8_t reg) __naked
ret
__endasm;
}
-#endif
+
+#else
inline void _pio_write(uint8_t reg, uint8_t data)
{
@@ -43,6 +44,8 @@ inline uint8_t _pio_read(uint8_t reg)
return *((uint8_t *) (ADDR_DEV_PIO + reg));
}
+#endif
+
void pio_set_mode(int port, int mode, uint8_t io)
{
// 0x0F is a control sequence to set mode
@@ -58,7 +61,7 @@ void pio_set_mode(int port, int mode, uint8_t io)
void pio_set_interrupts(int port, int control)
{
// 0x07 is a control sequence to set interrupts
- _pio_write((PIO_REG_CTRL + port), (control | 0x07));
+ _pio_write((PIO_REG_CTRL + port), (control<<4 | 0x07));
}
void pio_set_interrupts_mask(int port, int control, uint8_t mask)
diff --git a/sw/z80/drivers/usart.c b/sw/z80/drivers/usart.c
index 9ec6dbd..9a5ee38 100644
--- a/sw/z80/drivers/usart.c
+++ b/sw/z80/drivers/usart.c
@@ -1,6 +1,6 @@
#include "usart.h"
-static struct _usart_device *_usart = (struct _usart_device *) ADDR_DEV_USART;
+static volatile struct _usart_device *_usart = ((struct _usart_device *) ADDR_DEV_USART);
void usart_set_baudrate(uint16_t baudrate)
{
diff --git a/sw/z80/tests/asm/main.s b/sw/z80/tests/asm/main.s
new file mode 100644
index 0000000..8cf4df0
--- /dev/null
+++ b/sw/z80/tests/asm/main.s
@@ -0,0 +1,40 @@
+ .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
+_main:
+ ret
+ .area _INITIALIZER
+ .area _GSINIT
+ .area _GSFINAL
+
+ .area _DATA
+ .area _INITIALIZED
+ .area _BSEG
+ .area _BSS
+ .area _HEAP
diff --git a/sw/z80/tests/asm/makefile b/sw/z80/tests/asm/makefile
new file mode 100644
index 0000000..413b0fe
--- /dev/null
+++ b/sw/z80/tests/asm/makefile
@@ -0,0 +1,47 @@
+####
+# source code settings
+#
+OSNAME := ram_test
+
+CSOURCES := $(wildcard *.s)
+
+OBJECTS := $(patsubst %.s,build/%.rel,$(SOURCES))
+HEXFILE := build/$(OSNAME).hex
+BINARY := build/$(OSNAME).bin
+
+###
+# compiler settings
+#
+ASM := sdasz80
+LD := sdldz80
+
+FLAGS :=
+LDFLAGS :=
+
+.PHONY: flash dirs dis clean
+all: $(BINARY)
+
+flash: $(BINARY)
+ minipro -p M28C64 -w $<
+
+# build binary
+$(BINARY): $(OBJECTS) dirs
+ $(LD) $(LDFLAGS) $(OBJECTS) -o $(HEXFILE)
+ makebin -s 8192 -yo 1 $(HEXFILE) $(BINARY)
+
+$(OBJECTS): build/%.rel : %.s $(SOURCES) dirs
+ @printf "\n"
+ $(ASM) $(FLAGS) $< -o
+
+build/crt0.rel: crt0.s
+ sdasz80 -o $<
+ @mv crt0.rel build/
+
+dirs:
+ mkdir -p build
+
+dis: $(BINARY)
+ r2 -a z80 $< -c 'pd 0x10; s 0x100; pd 10; s 0x200; pd 10'
+
+clean:
+ - rm -rd build
diff --git a/sw/z80/tests/pio/crt0.s b/sw/z80/tests/pio/crt0.s
index eabe06c..c900065 100644
--- a/sw/z80/tests/pio/crt0.s
+++ b/sw/z80/tests/pio/crt0.s
@@ -36,5 +36,3 @@ _exit:
.area _BSEG
.area _BSS
.area _HEAP
-
- .area _CODE \ No newline at end of file
diff --git a/sw/z80/tests/pio/dis.txt b/sw/z80/tests/pio/dis.txt
new file mode 100644
index 0000000..60bef8e
--- /dev/null
+++ b/sw/z80/tests/pio/dis.txt
@@ -0,0 +1,225 @@
+mkdir -p build
+
+sdcc -mz80 --allow-unsafe-read -I . -I ../../arch/include -I ../../drivers/include -DDEBUG -c main.c -o build/main.rel
+sdcc -mz80 --no-std-crt0 build/crt0.rel -L ../../drivers/build -l drivers.a -pedantic build/main.rel -o build/pio_test.hex
+makebin -s 8192 -yo 1 build/pio_test.hex build/pio_test.bin
+#dz80 -b -n build/pio_test.bin
+r2 -a z80 build/pio_test.bin -A \
+-c 'afr main 0x200; \
+ pd 0x10; \
+ s 0x100; \
+ pd 10; \
+ s 0x200; \
+ pd 0xa0' \
+
+/ (fcn) fcn.00000000 13
+| fcn.00000000 ();
+| ; XREFS: DATA 0x00000202 DATA 0x00000204 DATA 0x00000209 DATA 0x0000020c DATA 0x00000216 DATA 0x00000219 DATA 0x00000220 DATA 0x00000221
+| ; XREFS: DATA 0x00000226 DATA 0x00000256
+\ ,=< 0x00000000 c30001 jp loc.00000100
+ | 0x00000003 ff rst 0x38
+ | 0x00000004 ff rst 0x38
+ | 0x00000005 ff rst 0x38
+ | 0x00000006 ff rst 0x38
+ | 0x00000007 ff rst 0x38
+ | 0x00000008 ff rst 0x38
+ | 0x00000009 ff rst 0x38
+ | 0x0000000a ff rst 0x38
+ | 0x0000000b ff rst 0x38
+ | 0x0000000c ff rst 0x38
+ | 0x0000000d ff rst 0x38
+ | 0x0000000e ff rst 0x38
+ | 0x0000000f ff rst 0x38
+ | 0x00000010 ff rst 0x38
+ | 0x00000011 ff rst 0x38
+|- loc.00000100 10
+| loc.00000100 ();
+| ; JMP XREF from 0x00000000 (fcn.00000000)
+| ; JMP XREF from 0x00000106 (loc.00000100)
+| 0x00000100 31ffff ld sp, 0xffff
+| 0x00000103 cd0002 call main
+| ,=< 0x00000106 c30901 jp 0x0109
+| | ; JMP XREF from 0x00000106 (loc.00000100)
+\ `-> 0x00000109 76 halt
+ 0x0000010a ff rst 0x38
+ 0x0000010b ff rst 0x38
+ 0x0000010c ff rst 0x38
+ 0x0000010d ff rst 0x38
+ 0x0000010e ff rst 0x38
+ 0x0000010f ff rst 0x38
+/ (fcn) main 50
+| main ();
+| ; CALL XREF from 0x00000103 (loc.00000100)
+| ; CALL XREF from 0x00000200 (main)
+| 0x00000200 0600 ld b, 0x00
+| 0x00000202 c5 push bc
+| 0x00000203 af xor a
+| 0x00000204 f5 push af
+| 0x00000205 33 inc sp
+| 0x00000206 210300 ld hl, 0x0003
+| 0x00000209 e5 push hl
+| 0x0000020a 2e00 ld l, 0x00
+| 0x0000020c e5 push hl
+| 0x0000020d cd5502 call fcn.00000255
+| 0x00000210 f1 pop af
+| 0x00000211 f1 pop af
+| 0x00000212 33 inc sp
+| 0x00000213 210000 ld hl, 0x0000
+| 0x00000216 e5 push hl
+| 0x00000217 2e00 ld l, 0x00
+| 0x00000219 e5 push hl
+| 0x0000021a cd8e02 call fcn.0000028e
+| 0x0000021d f1 pop af
+| 0x0000021e f1 pop af
+\ 0x0000021f c1 pop bc
+| ; JMP XREF from 0x00000230 (main)
+| .-> 0x00000220 c5 push bc
+| | 0x00000221 c5 push bc
+| | 0x00000222 33 inc sp
+| | 0x00000223 210000 ld hl, 0x0000
+| | 0x00000226 e5 push hl
+| | 0x00000227 cde002 call fcn.000002e0
+| | 0x0000022a f1 pop af
+| | 0x0000022b 33 inc sp
+| | 0x0000022c c1 pop bc
+| | 0x0000022d 78 ld a, b
+| | 0x0000022e 2f cpl
+| | 0x0000022f 47 ld b, a
+| `=< 0x00000230 18ee jr 0xee
+ 0x00000232 210200 ld hl, 0x0002
+ 0x00000235 39 add hl, sp
+ 0x00000236 4e ld c, [hl]
+ 0x00000237 0600 ld b, 0x00
+ 0x00000239 210042 ld hl, 0x4200
+ 0x0000023c 09 add hl, bc
+ 0x0000023d fd210300 ld iy, 0x0003
+ 0x00000241 fd39 add iy, sp
+ 0x00000243 fd7e00 ld a, [iy+0x00]
+ 0x00000246 77 ld [hl], a
+ 0x00000247 c9 ret
+ 0x00000248 210200 ld hl, 0x0002
+ 0x0000024b 39 add hl, sp
+ 0x0000024c 4e ld c, [hl]
+ 0x0000024d 0600 ld b, 0x00
+ 0x0000024f 210042 ld hl, 0x4200
+ 0x00000252 09 add hl, bc
+ 0x00000253 6e ld l, [hl]
+ 0x00000254 c9 ret
+/ (fcn) fcn.00000255 8
+| fcn.00000255 ();
+| ; CALL XREF from 0x0000020d (main)
+| 0x00000255 dde5 push ix
+| 0x00000257 dd210000 ld ix, 0x0000
+\ 0x0000025b dd39 add ix, sp
+ 0x0000025d dd7e06 ld a, [ix+0x06]
+ 0x00000260 0f rrca
+ 0x00000261 0f rrca
+ 0x00000262 e6c0 and 0xc0
+ 0x00000264 f60f or 0x0f
+ 0x00000266 57 ld d, a
+ 0x00000267 dd5e04 ld e, [ix+0x04]
+ 0x0000026a 1c inc e
+ 0x0000026b 1c inc e
+ 0x0000026c 6b ld l, e
+ 0x0000026d 2600 ld h, 0x00
+ 0x0000026f 010042 ld bc, 0x4200
+ 0x00000272 09 add hl, bc
+ 0x00000273 72 ld [hl], d
+ 0x00000274 dd7e06 ld a, [ix+0x06]
+ 0x00000277 d603 sub 0x03
+ ,=< 0x00000279 2010 jr nz, 0x10
+ | 0x0000027b dd7e07 ld a, [ix+0x07]
+ | 0x0000027e b7 or a
+ ,==< 0x0000027f 200a jr nz, 0x0a
+ || 0x00000281 dd4e08 ld c, [ix+0x08]
+ || 0x00000284 1600 ld d, 0x00
+ || 0x00000286 210042 ld hl, 0x4200
+ || 0x00000289 19 add hl, de
+ || 0x0000028a 71 ld [hl], c
+ ``-> 0x0000028b dde1 pop ix
+ 0x0000028d c9 ret
+/ (fcn) fcn.0000028e 29
+| fcn.0000028e ();
+| ; CALL XREF from 0x0000021a (main)
+| 0x0000028e 210400 ld hl, 0x0004
+| 0x00000291 39 add hl, sp
+| 0x00000292 7e ld a, [hl]
+| 0x00000293 07 rlca
+| 0x00000294 07 rlca
+| 0x00000295 07 rlca
+| 0x00000296 07 rlca
+| 0x00000297 e6f0 and 0xf0
+| 0x00000299 f607 or 0x07
+| 0x0000029b 4f ld c, a
+| 0x0000029c 210200 ld hl, 0x0002
+| 0x0000029f 39 add hl, sp
+| 0x000002a0 5e ld e, [hl]
+| 0x000002a1 1c inc e
+| 0x000002a2 1c inc e
+| 0x000002a3 1600 ld d, 0x00
+| 0x000002a5 210042 ld hl, 0x4200
+| 0x000002a8 19 add hl, de
+| 0x000002a9 71 ld [hl], c
+\ 0x000002aa c9 ret
+ 0x000002ab dde5 push ix
+ 0x000002ad dd210000 ld ix, 0x0000
+ 0x000002b1 dd39 add ix, sp
+ 0x000002b3 dd7e06 ld a, [ix+0x06]
+ 0x000002b6 f617 or 0x17
+ 0x000002b8 57 ld d, a
+ 0x000002b9 dd5e04 ld e, [ix+0x04]
+ 0x000002bc 1c inc e
+ 0x000002bd 1c inc e
+ 0x000002be 6b ld l, e
+ 0x000002bf 2600 ld h, 0x00
+ 0x000002c1 010042 ld bc, 0x4200
+ 0x000002c4 09 add hl, bc
+ 0x000002c5 72 ld [hl], d
+ 0x000002c6 dd4e08 ld c, [ix+0x08]
+ 0x000002c9 1600 ld d, 0x00
+ 0x000002cb 210042 ld hl, 0x4200
+ 0x000002ce 19 add hl, de
+ 0x000002cf 71 ld [hl], c
+ 0x000002d0 dde1 pop ix
+ 0x000002d2 c9 ret
+ 0x000002d3 210200 ld hl, 0x0002
+ 0x000002d6 39 add hl, sp
+ 0x000002d7 4e ld c, [hl]
+ 0x000002d8 0600 ld b, 0x00
+ 0x000002da 210042 ld hl, 0x4200
+ 0x000002dd 09 add hl, bc
+ 0x000002de 6e ld l, [hl]
+ 0x000002df c9 ret
+/ (fcn) fcn.000002e0 18
+| fcn.000002e0 ();
+| ; CALL XREF from 0x00000227 (main)
+| 0x000002e0 210400 ld hl, 0x0004
+| 0x000002e3 39 add hl, sp
+| 0x000002e4 4e ld c, [hl]
+| 0x000002e5 210200 ld hl, 0x0002
+| 0x000002e8 39 add hl, sp
+| 0x000002e9 5e ld e, [hl]
+| 0x000002ea 1600 ld d, 0x00
+| 0x000002ec 210042 ld hl, 0x4200
+| 0x000002ef 19 add hl, de
+| 0x000002f0 71 ld [hl], c
+\ 0x000002f1 c9 ret
+ 0x000002f2 ff rst 0x38
+ 0x000002f3 ff rst 0x38
+ 0x000002f4 ff rst 0x38
+ 0x000002f5 ff rst 0x38
+ 0x000002f6 ff rst 0x38
+ 0x000002f7 ff rst 0x38
+ 0x000002f8 ff rst 0x38
+ 0x000002f9 ff rst 0x38
+ 0x000002fa ff rst 0x38
+ 0x000002fb ff rst 0x38
+ 0x000002fc ff rst 0x38
+ 0x000002fd ff rst 0x38
+ 0x000002fe ff rst 0x38
+ 0x000002ff ff rst 0x38
+ 0x00000300 ff rst 0x38
+ 0x00000301 ff rst 0x38
+ 0x00000302 ff rst 0x38
+ -- Change the graph block definition with graph.callblocks, graph.jmpblocks, graph.flagblocks
+ [0x00000200]> [0x00000200]> q [0x00000200]> q [0x00000200]> q
diff --git a/sw/z80/tests/pio/main.c b/sw/z80/tests/pio/main.c
index c1f3741..c873e20 100644
--- a/sw/z80/tests/pio/main.c
+++ b/sw/z80/tests/pio/main.c
@@ -6,12 +6,11 @@ void main(void)
{
uint8_t i = 0;
- pio_set_mode(PIO_A, PIO_MODE_BYTE_OUT, 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;
}
-
- // return;
}
diff --git a/sw/z80/tests/pio/makefile b/sw/z80/tests/pio/makefile
index 5c3716c..f7f97be 100644
--- a/sw/z80/tests/pio/makefile
+++ b/sw/z80/tests/pio/makefile
@@ -4,6 +4,8 @@
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
@@ -15,9 +17,10 @@ BINARY := build/$(OSNAME).bin
CC := sdcc
CFLAGS := -mz80 \
+ --no-std-crt0 build/crt0.rel \
--allow-unsafe-read \
-I . \
- -I ../../arch \
+ -I ../../arch/include \
-I ../../drivers/include \
-DDEBUG
@@ -25,9 +28,8 @@ LDFLAGS := -mz80 \
--no-std-crt0 build/crt0.rel \
-L ../../drivers/build \
-l drivers.a \
- -pedantic
-
- # --code-loc 0x0120 \
+ -pedantic \
+ --code-loc 0x0200
# --data-loc 0x2000
.PHONY: flash dirs dis clean
@@ -41,10 +43,14 @@ $(BINARY): $(OBJECTS) dirs
$(CC) $(LDFLAGS) $(OBJECTS) -o $(HEXFILE)
makebin -s 8192 -yo 1 $(HEXFILE) $(BINARY)
-$(OBJECTS): build/%.rel : %.c $(CSOURCES) dirs build/crt0.rel
+$(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/
@@ -53,14 +59,14 @@ dirs:
mkdir -p build
dis: $(BINARY)
- #dz80 -b -n $<
- r2 -a z80 $< -A \
- -c 'afr main 0x200; \
+ dz80 -b -n -t $(BINARY)
+ r2 -a z80 $< \
+ -c 'afn main 0x200; \
pd 0x10; \
s 0x100; \
pd 10; \
s 0x200; \
- pd 0x40' \
+ pd 0x95'
clean:
- rm -rd build
diff --git a/sw/z80/tests/ram/makefile b/sw/z80/tests/ram/makefile
index 3db0a67..f8eb9fc 100644
--- a/sw/z80/tests/ram/makefile
+++ b/sw/z80/tests/ram/makefile
@@ -48,7 +48,6 @@ dirs:
mkdir -p build
dis: $(BINARY)
- #dz80 -b -n $<
r2 -a z80 $< -c 'pd 0x10; s 0x100; pd 10; s 0x200; pd 10'
clean:
diff --git a/sw/z80/tests/usart/crt0.s b/sw/z80/tests/usart/crt0.s
new file mode 100644
index 0000000..c900065
--- /dev/null
+++ b/sw/z80/tests/usart/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/z80/tests/usart/main.c b/sw/z80/tests/usart/main.c
new file mode 100644
index 0000000..a905df2
--- /dev/null
+++ b/sw/z80/tests/usart/main.c
@@ -0,0 +1,11 @@
+#include "usart.h"
+#include <stdint.h>
+
+void main(void)
+{
+ usart_init(USART_BAUDRATE_1200, USART_PARITY_NONE, USART_STOP_BITS_1);
+
+ while (1) {
+ usart_write("Hello World!\n", 13);
+ }
+}
diff --git a/sw/z80/tests/usart/makefile b/sw/z80/tests/usart/makefile
new file mode 100644
index 0000000..8aaf6b1
--- /dev/null
+++ b/sw/z80/tests/usart/makefile
@@ -0,0 +1,72 @@
+####
+# source code settings
+#
+OSNAME := usart_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'
+
+clean:
+ - rm -rd build