commit c29ed0580ac71d7db1f7e0c39b0817256239b407 Author: Dreaded_X Date: Fri Jan 8 04:13:12 2021 +0100 First commit diff --git a/.build/bios.lst b/.build/bios.lst new file mode 100644 index 0000000..e3d04be --- /dev/null +++ b/.build/bios.lst @@ -0,0 +1,8 @@ + 0000 1 __bios_call:: + 0000 2A 01 00 [16] 2 ld hl, (1) + 0003 85 [ 4] 3 add l + 0004 6F [ 4] 4 ld l, a + 0005 D2r09r00 [10] 5 jp nc, bios_call_cont + 0008 24 [ 4] 6 inc h + 0009 7 bios_call_cont: + 0009 E9 [ 4] 8 jp (hl) diff --git a/.build/bios.rel b/.build/bios.rel new file mode 100644 index 0000000..13c4a9b --- /dev/null +++ b/.build/bios.rel @@ -0,0 +1,13 @@ +XL2 +H 1 areas 2 global symbols +S .__.ABS. Def0000 +A _CODE size A flags 0 addr 0 +S __bios_call Def0000 +T 00 00 +R 00 00 00 00 +T 00 00 2A 01 00 85 6F D2 09 00 24 +R 00 00 00 00 00 08 00 00 +T 09 00 +R 00 00 00 00 +T 09 00 E9 +R 00 00 00 00 diff --git a/.build/bios.sym b/.build/bios.sym new file mode 100644 index 0000000..25996fe --- /dev/null +++ b/.build/bios.sym @@ -0,0 +1,15 @@ + ASxxxx Assembler V02.00 + NoICE + SDCC mods (Zilog Z80 / Hitachi HD64180 / ZX-Next / eZ80), page 1. +Hexadecimal [16-Bits] + +Symbol Table + + .__.$$$.= 2710 L | .__.ABS.= 0000 G | .__.CPU.= 0000 L + .__.H$L.= 0000 L | 0 __bios_c 0000 GR | 0 bios_cal 0009 R + + ASxxxx Assembler V02.00 + NoICE + SDCC mods (Zilog Z80 / Hitachi HD64180 / ZX-Next / eZ80), page 2. +Hexadecimal [16-Bits] + +Area Table + + 0 _CODE size A flags 0 + diff --git a/.build/console.asm b/.build/console.asm new file mode 100644 index 0000000..754936b --- /dev/null +++ b/.build/console.asm @@ -0,0 +1,96 @@ +;-------------------------------------------------------- +; File Created by SDCC : free open source ANSI-C Compiler +; Version 4.0.0 #11528 (Linux) +;-------------------------------------------------------- + .module console + .optsdcc -mz80 + +;-------------------------------------------------------- +; Public variables in this module +;-------------------------------------------------------- + .globl _get_char + .globl _put_char + .globl _put_string +;-------------------------------------------------------- +; special function registers +;-------------------------------------------------------- +;-------------------------------------------------------- +; ram data +;-------------------------------------------------------- + .area _DATA +;-------------------------------------------------------- +; ram data +;-------------------------------------------------------- + .area _INITIALIZED +;-------------------------------------------------------- +; absolute external ram data +;-------------------------------------------------------- + .area _DABS (ABS) +;-------------------------------------------------------- +; global & static initialisations +;-------------------------------------------------------- + .area _HOME + .area _GSINIT + .area _GSFINAL + .area _GSINIT +;-------------------------------------------------------- +; Home +;-------------------------------------------------------- + .area _HOME + .area _HOME +;-------------------------------------------------------- +; code +;-------------------------------------------------------- + .area _CODE +;src/console.c:3: char get_char() __naked { +; --------------------------------- +; Function get_char +; --------------------------------- +_get_char:: +;src/console.c:9: __endasm; + ld a, #6 + call __bios_call + ld l, a + ret +;src/console.c:10: } +;src/console.c:12: void put_char(char c) __naked { +; --------------------------------- +; Function put_char +; --------------------------------- +_put_char:: +;src/console.c:21: __endasm; + ld iy, #2 + add iy, sp + ld c, 0(iy) + ld a, #9 + call __bios_call + ret +;src/console.c:22: } +;src/console.c:24: void put_string(char* s) { +; --------------------------------- +; Function put_string +; --------------------------------- +_put_string:: +;src/console.c:25: while (*s) { + pop de + pop bc + push bc + push de +00101$: + ld a, (bc) + or a, a + ret Z +;src/console.c:26: put_char(*s); + push bc + push af + inc sp + call _put_char + inc sp + pop bc +;src/console.c:27: s++; + inc bc +;src/console.c:29: } + jr 00101$ + .area _CODE + .area _INITIALIZER + .area _CABS (ABS) diff --git a/.build/console.lst b/.build/console.lst new file mode 100644 index 0000000..88e2e38 --- /dev/null +++ b/.build/console.lst @@ -0,0 +1,96 @@ + 1 ;-------------------------------------------------------- + 2 ; File Created by SDCC : free open source ANSI-C Compiler + 3 ; Version 4.0.0 #11528 (Linux) + 4 ;-------------------------------------------------------- + 5 .module console + 6 .optsdcc -mz80 + 7 + 8 ;-------------------------------------------------------- + 9 ; Public variables in this module + 10 ;-------------------------------------------------------- + 11 .globl _get_char + 12 .globl _put_char + 13 .globl _put_string + 14 ;-------------------------------------------------------- + 15 ; special function registers + 16 ;-------------------------------------------------------- + 17 ;-------------------------------------------------------- + 18 ; ram data + 19 ;-------------------------------------------------------- + 20 .area _DATA + 21 ;-------------------------------------------------------- + 22 ; ram data + 23 ;-------------------------------------------------------- + 24 .area _INITIALIZED + 25 ;-------------------------------------------------------- + 26 ; absolute external ram data + 27 ;-------------------------------------------------------- + 28 .area _DABS (ABS) + 29 ;-------------------------------------------------------- + 30 ; global & static initialisations + 31 ;-------------------------------------------------------- + 32 .area _HOME + 33 .area _GSINIT + 34 .area _GSFINAL + 35 .area _GSINIT + 36 ;-------------------------------------------------------- + 37 ; Home + 38 ;-------------------------------------------------------- + 39 .area _HOME + 40 .area _HOME + 41 ;-------------------------------------------------------- + 42 ; code + 43 ;-------------------------------------------------------- + 44 .area _CODE + 45 ;src/console.c:3: char get_char() __naked { + 46 ; --------------------------------- + 47 ; Function get_char + 48 ; --------------------------------- + 0000 49 _get_char:: + 50 ;src/console.c:9: __endasm; + 0000 3E 06 [ 7] 51 ld a, #6 + 0002 CDr00r00 [17] 52 call __bios_call + 0005 6F [ 4] 53 ld l, a + 0006 C9 [10] 54 ret + 55 ;src/console.c:10: } + 56 ;src/console.c:12: void put_char(char c) __naked { + 57 ; --------------------------------- + 58 ; Function put_char + 59 ; --------------------------------- + 0007 60 _put_char:: + 61 ;src/console.c:21: __endasm; + 0007 FD 21 02 00 [14] 62 ld iy, #2 + 000B FD 39 [15] 63 add iy, sp + 000D FD 4E 00 [19] 64 ld c, 0(iy) + 0010 3E 09 [ 7] 65 ld a, #9 + 0012 CDr00r00 [17] 66 call __bios_call + 0015 C9 [10] 67 ret + 68 ;src/console.c:22: } + 69 ;src/console.c:24: void put_string(char* s) { + 70 ; --------------------------------- + 71 ; Function put_string + 72 ; --------------------------------- + 0016 73 _put_string:: + 74 ;src/console.c:25: while (*s) { + 0016 D1 [10] 75 pop de + 0017 C1 [10] 76 pop bc + 0018 C5 [11] 77 push bc + 0019 D5 [11] 78 push de + 001A 79 00101$: + 001A 0A [ 7] 80 ld a, (bc) + 001B B7 [ 4] 81 or a, a + 001C C8 [11] 82 ret Z + 83 ;src/console.c:26: put_char(*s); + 001D C5 [11] 84 push bc + 001E F5 [11] 85 push af + 001F 33 [ 6] 86 inc sp + 0020 CDr07r00 [17] 87 call _put_char + 0023 33 [ 6] 88 inc sp + 0024 C1 [10] 89 pop bc + 90 ;src/console.c:27: s++; + 0025 03 [ 6] 91 inc bc + 92 ;src/console.c:29: } + 0026 18 F2 [12] 93 jr 00101$ + 94 .area _CODE + 95 .area _INITIALIZER + 96 .area _CABS (ABS) diff --git a/.build/console.rel b/.build/console.rel new file mode 100644 index 0000000..481349b --- /dev/null +++ b/.build/console.rel @@ -0,0 +1,36 @@ +XL2 +H 9 areas 5 global symbols +M console +O -mz80 +S .__.ABS. Def0000 +S __bios_call Ref0000 +A _CODE size 28 flags 0 addr 0 +S _get_char Def0000 +S _put_string Def0016 +S _put_char Def0007 +A _DATA size 0 flags 0 addr 0 +A _INITIALIZED size 0 flags 0 addr 0 +A _DABS size 0 flags 8 addr 0 +A _HOME size 0 flags 0 addr 0 +A _GSINIT size 0 flags 0 addr 0 +A _GSFINAL size 0 flags 0 addr 0 +A _INITIALIZER size 0 flags 0 addr 0 +A _CABS size 0 flags 8 addr 0 +T 00 00 +R 00 00 00 00 +T 00 00 3E 06 CD 00 00 6F C9 +R 00 00 00 00 02 05 01 00 +T 07 00 +R 00 00 00 00 +T 07 00 FD 21 02 00 FD 39 FD 4E 00 3E 09 CD 00 00 +R 00 00 00 00 02 0E 01 00 +T 15 00 C9 +R 00 00 00 00 +T 16 00 +R 00 00 00 00 +T 16 00 D1 C1 C5 D5 +R 00 00 00 00 +T 1A 00 +R 00 00 00 00 +T 1A 00 0A B7 C8 C5 F5 33 CD 07 00 33 C1 03 18 F2 +R 00 00 00 00 00 09 00 00 diff --git a/.build/console.sym b/.build/console.sym new file mode 100644 index 0000000..8e3352f --- /dev/null +++ b/.build/console.sym @@ -0,0 +1,30 @@ + ASxxxx Assembler V02.00 + NoICE + SDCC mods (Zilog Z80 / Hitachi HD64180 / ZX-Next / eZ80), page 1. +Hexadecimal [16-Bits] + +Symbol Table + + .__.$$$. = 2710 L + .__.ABS. = 0000 G + .__.CPU. = 0000 L + .__.H$L. = 0000 L + __bios_call **** GX + 0 _get_char 0000 GR + 0 _put_char 0007 GR + 0 _put_string 0016 GR + + + ASxxxx Assembler V02.00 + NoICE + SDCC mods (Zilog Z80 / Hitachi HD64180 / ZX-Next / eZ80), page 2. +Hexadecimal [16-Bits] + +Area Table + + 0 _CODE size 28 flags 0 + 1 _DATA size 0 flags 0 + 2 _INITIALIZED size 0 flags 0 + 3 _DABS size 0 flags 8 + 4 _HOME size 0 flags 0 + 5 _GSINIT size 0 flags 0 + 6 _GSFINAL size 0 flags 0 + 7 _INITIALIZER size 0 flags 0 + 8 _CABS size 0 flags 8 + diff --git a/.build/crt.a b/.build/crt.a new file mode 100644 index 0000000..acaaea0 Binary files /dev/null and b/.build/crt.a differ diff --git a/.build/crt0.lst b/.build/crt0.lst new file mode 100644 index 0000000..d96893e --- /dev/null +++ b/.build/crt0.lst @@ -0,0 +1,52 @@ + 1 ;-------------------------------------------------------------------------- + 2 ; cpm0.s - Generic cpm0.s for a Z80 CP/M-80 v2.2 Application + 3 ; Copyright (C) 2011, Douglas Goodall All Rights Reserved. + 4 ;-------------------------------------------------------------------------- + 5 + 6 .area _CODE + 0000 7 .ds 0x0100 + 0100 8 init: + 9 ;; Define an adequate stack + 0100 31r00r01 [10] 10 ld sp, #stktop + 11 + 12 ;; Initialise global variables + 0103 CDr00r00 [17] 13 call gsinit + 14 + 15 ;; Call the C main routine + 0106 CDr00r00 [17] 16 call _main + 17 + 18 ;; Return back to CP/M + 0109 0E 00 [ 7] 19 ld c, #0 + 010B CD 05 00 [17] 20 call 5 + 21 + 22 ;; Ordering of segments for the linker. + 23 .area _TPA + 24 + 25 .area _HOME + 26 .area _CODE + 27 .area _INITIALIZER + 28 .area _GSINIT + 29 .area _GSFINAL + 30 .area _DATA + 31 .area _INITIALIZED + 32 + 33 .area _STACK + 0000 34 .ds 256 + 0100 35 stktop: + 36 + 37 .area _GSINIT + 0000 38 gsinit:: + 0000 01r00r00 [10] 39 ld bc, #l__INITIALIZER + 0003 78 [ 4] 40 ld a, b + 0004 B1 [ 4] 41 or a, c + 0005 28 08 [12] 42 jr z, gsinit_next + 0007 11r00r00 [10] 43 ld de, #s__INITIALIZED + 000A 21r00r00 [10] 44 ld hl, #s__INITIALIZER + 000D ED B0 [21] 45 ldir + 000F 46 gsinit_next: + 47 .area _GSFINAL + 0000 C9 [10] 48 ret + 49 + 50 ;;;;;;;;;;;;;;;; + 51 ; eof - cpm0.s ; + 52 ;;;;;;;;;;;;;;;; diff --git a/.build/crt0.rel b/.build/crt0.rel new file mode 100644 index 0000000..5fa1805 --- /dev/null +++ b/.build/crt0.rel @@ -0,0 +1,37 @@ +XL2 +H 9 areas 6 global symbols +S _main Ref0000 +S .__.ABS. Def0000 +S s__INITIALIZED Ref0000 +S l__INITIALIZER Ref0000 +S s__INITIALIZER Ref0000 +A _CODE size 10E flags 0 addr 0 +A _TPA size 0 flags 0 addr 0 +A _HOME size 0 flags 0 addr 0 +A _INITIALIZER size 0 flags 0 addr 0 +A _GSINIT size F flags 0 addr 0 +S gsinit Def0000 +A _GSFINAL size 1 flags 0 addr 0 +A _DATA size 0 flags 0 addr 0 +A _INITIALIZED size 0 flags 0 addr 0 +A _STACK size 100 flags 0 addr 0 +T 00 00 +R 00 00 00 00 +T 00 01 +R 00 00 00 00 +T 00 01 31 00 01 CD 00 00 CD 00 00 0E 00 CD 05 00 +R 00 00 00 00 00 03 08 00 00 06 04 00 02 09 00 00 +T 00 00 +R 00 00 08 00 +T 00 01 +R 00 00 08 00 +T 00 00 +R 00 00 04 00 +T 00 00 01 00 00 78 B1 28 08 11 00 00 21 00 00 ED +R 00 00 04 00 02 03 03 00 02 0A 02 00 02 0D 04 00 +T 0E 00 B0 +R 00 00 04 00 +T 0F 00 +R 00 00 04 00 +T 00 00 C9 +R 00 00 05 00 diff --git a/.build/crt0.sym b/.build/crt0.sym new file mode 100644 index 0000000..b118447 --- /dev/null +++ b/.build/crt0.sym @@ -0,0 +1,25 @@ + ASxxxx Assembler V02.00 + NoICE + SDCC mods (Zilog Z80 / Hitachi HD64180 / ZX-Next / eZ80), page 1. +Hexadecimal [16-Bits] + +Symbol Table + + .__.$$$.= 2710 L | .__.ABS.= 0000 G | .__.CPU.= 0000 L + .__.H$L.= 0000 L | _main **** GX | 4 gsinit 0000 GR + 4 gsinit_n 000F R | 0 init 0100 R | l__INITI **** GX + s__INITI **** GX | s__INITI **** GX | 8 stktop 0100 R + + ASxxxx Assembler V02.00 + NoICE + SDCC mods (Zilog Z80 / Hitachi HD64180 / ZX-Next / eZ80), page 2. +Hexadecimal [16-Bits] + +Area Table + + 0 _CODE size 10E flags 0 + 1 _TPA size 0 flags 0 + 2 _HOME size 0 flags 0 + 3 _INITIAL size 0 flags 0 + 4 _GSINIT size F flags 0 + 5 _GSFINAL size 1 flags 0 + 6 _DATA size 0 flags 0 + 7 _INITIAL size 0 flags 0 + 8 _STACK size 100 flags 0 + diff --git a/.build/random.lst b/.build/random.lst new file mode 100644 index 0000000..d890d60 --- /dev/null +++ b/.build/random.lst @@ -0,0 +1,29 @@ + 1 ; Fast RND + 2 ; + 3 ; An 8-bit pseudo-random number generator, + 4 ; using a similar method to the Spectrum ROM, + 5 ; - without the overhead of the Spectrum ROM. + 6 ; + 7 ; R = random number seed + 8 ; an integer in the range [1, 256] + 9 ; + 10 ; R -> (33*R) mod 257 + 11 ; + 12 ; S = R - 1 + 13 ; an 8-bit unsigned integer + 14 + 0000 15 _random:: + 0000 3Ar00r00 [13] 16 ld a, (_seed) + 0003 47 [ 4] 17 ld b, a + 18 + 0004 0F [ 4] 19 rrca ; multiply by 32 + 0005 0F [ 4] 20 rrca + 0006 0F [ 4] 21 rrca + 0007 EE 1F [ 7] 22 xor #0x1f + 23 + 0009 80 [ 4] 24 add a, b + 000A DE FF [ 7] 25 sbc a, #255 ; carry + 26 + 000C 32r00r00 [13] 27 ld (_seed), a + 000F 6F [ 4] 28 ld l, a + 0010 C9 [10] 29 ret diff --git a/.build/random.rel b/.build/random.rel new file mode 100644 index 0000000..93e740e --- /dev/null +++ b/.build/random.rel @@ -0,0 +1,12 @@ +XL2 +H 1 areas 3 global symbols +S _seed Ref0000 +S .__.ABS. Def0000 +A _CODE size 11 flags 0 addr 0 +S _random Def0000 +T 00 00 +R 00 00 00 00 +T 00 00 3A 00 00 47 0F 0F 0F EE 1F 80 DE FF 32 +R 00 00 00 00 02 03 00 00 +T 0D 00 00 00 6F C9 +R 00 00 00 00 02 02 00 00 diff --git a/.build/random.sym b/.build/random.sym new file mode 100644 index 0000000..cdbced3 --- /dev/null +++ b/.build/random.sym @@ -0,0 +1,15 @@ + ASxxxx Assembler V02.00 + NoICE + SDCC mods (Zilog Z80 / Hitachi HD64180 / ZX-Next / eZ80), page 1. +Hexadecimal [16-Bits] + +Symbol Table + + .__.$$$.= 2710 L | .__.ABS.= 0000 G | .__.CPU.= 0000 L + .__.H$L.= 0000 L | 0 _random 0000 GR | _seed **** GX + + ASxxxx Assembler V02.00 + NoICE + SDCC mods (Zilog Z80 / Hitachi HD64180 / ZX-Next / eZ80), page 2. +Hexadecimal [16-Bits] + +Area Table + + 0 _CODE size 11 flags 0 + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2399ec0 --- /dev/null +++ b/Makefile @@ -0,0 +1,42 @@ +AS = sdasz80 +CC = sdcc +AR = sdar + +BUILD = .build + +TARGET = crt +OPT = s + +CFLAGS = -mz80 -D__SDCC__ -Iinclude +ASFLAGS = -plosgff + +SRC = \ +src/crt0.s \ +src/bios.s \ +src/random.s \ +src/console.c \ + +OBJ_1 = $(notdir $(SRC:.c=.rel)) +OBJ_2 = $(notdir $(OBJ_1:.s=.rel)) +OBJ = $(addprefix $(BUILD)/, $(OBJ_2)) +vpath %.c $(sort $(dir $(SRC))) +vpath %.s $(sort $(dir $(SRC))) + +.PHONY: all clean + +all: $(BUILD) $(BUILD)/$(TARGET).a + +$(BUILD)/%.rel: %.c Makefile | $(BUILD) + $(CC) -c $(CFLAGS) $< -o $@ + +$(BUILD)/%.rel: %.s Makefile | $(BUILD) + $(AS) $(ASFLAGS) $@ $< + +$(BUILD)/$(TARGET).a: $(OBJ) + $(AR) rcs $@ $(OBJ) + +$(BUILD): + mkdir $@ + +clean: + rm -fr $(BUILD) diff --git a/README.md b/README.md new file mode 100644 index 0000000..a90037a --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +Based on: +https://github.com/hkzlab/sdcc-cpm-example diff --git a/include/console.h b/include/console.h new file mode 100644 index 0000000..01d792b --- /dev/null +++ b/include/console.h @@ -0,0 +1,7 @@ +#include "types.h" + +void put_char(char c); +char get_char(); + +void put_string(char* s); + diff --git a/include/random.h b/include/random.h new file mode 100644 index 0000000..8406e3d --- /dev/null +++ b/include/random.h @@ -0,0 +1,3 @@ +#include "types.h" + +uint8_t random(); diff --git a/include/types.h b/include/types.h new file mode 100644 index 0000000..42e764e --- /dev/null +++ b/include/types.h @@ -0,0 +1,7 @@ +#pragma once + +typedef signed char int8_t; +typedef short int int16_t; + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; diff --git a/src/bios.s b/src/bios.s new file mode 100644 index 0000000..b5443f3 --- /dev/null +++ b/src/bios.s @@ -0,0 +1,8 @@ +__bios_call:: + ld hl, (1) + add l + ld l, a + jp nc, bios_call_cont + inc h +bios_call_cont: + jp (hl) diff --git a/src/console.c b/src/console.c new file mode 100644 index 0000000..f3ac80e --- /dev/null +++ b/src/console.c @@ -0,0 +1,29 @@ +#include "console.h" + +char get_char() __naked { + __asm + ld a, #6 + call __bios_call + ld l, a + ret + __endasm; +} + +void put_char(char c) __naked { + c; + __asm + ld iy, #2 + add iy, sp + ld c, 0(iy) + ld a, #9 + call __bios_call + ret + __endasm; +} + +void put_string(char* s) { + while (*s) { + put_char(*s); + s++; + } +} diff --git a/src/crt0.s b/src/crt0.s new file mode 100644 index 0000000..de372b6 --- /dev/null +++ b/src/crt0.s @@ -0,0 +1,52 @@ +;-------------------------------------------------------------------------- +; cpm0.s - Generic cpm0.s for a Z80 CP/M-80 v2.2 Application +; Copyright (C) 2011, Douglas Goodall All Rights Reserved. +;-------------------------------------------------------------------------- + + .area _CODE + .ds 0x0100 +init: + ;; Define an adequate stack + ld sp, #stktop + + ;; Initialise global variables + call gsinit + + ;; Call the C main routine + call _main + + ;; Return back to CP/M + ld c, #0 + call 5 + + ;; Ordering of segments for the linker. + .area _TPA + + .area _HOME + .area _CODE + .area _INITIALIZER + .area _GSINIT + .area _GSFINAL + .area _DATA + .area _INITIALIZED + + .area _STACK + .ds 256 +stktop: + + .area _GSINIT +gsinit:: + 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 + +;;;;;;;;;;;;;;;; +; eof - cpm0.s ; +;;;;;;;;;;;;;;;; diff --git a/src/random.s b/src/random.s new file mode 100644 index 0000000..bca0b9f --- /dev/null +++ b/src/random.s @@ -0,0 +1,29 @@ +; Fast RND +; +; An 8-bit pseudo-random number generator, +; using a similar method to the Spectrum ROM, +; - without the overhead of the Spectrum ROM. +; +; R = random number seed +; an integer in the range [1, 256] +; +; R -> (33*R) mod 257 +; +; S = R - 1 +; an 8-bit unsigned integer + +_random:: + ld a, (_seed) + ld b, a + + rrca ; multiply by 32 + rrca + rrca + xor #0x1f + + add a, b + sbc a, #255 ; carry + + ld (_seed), a + ld l, a + ret