From 321307520af00f8e2cacdcda3f95244ba010fbdd Mon Sep 17 00:00:00 2001 From: Dean Netherton Date: Sat, 2 Nov 2024 10:41:43 +1100 Subject: [PATCH] apps: line and mbrot apps ported --- .github/workflows/ez80-for-rc.yml | 6 +- .gitignore | 1 + apps/{mbrot => common}/config_request.c | 0 apps/{mbrot => common}/config_request.h | 0 apps/{mbrot => common}/v9958.asm | 79 ++++++++++++++++++------- apps/{mbrot => common}/v9958.c | 17 ++++-- apps/{mbrot => common}/v9958.h | 2 +- apps/ez80/ez80-instr.inc | 12 +++- apps/line/Makefile | 10 ++++ apps/line/build.sh | 53 +++++++++++++++++ apps/line/line.c | 36 +++++++++++ apps/line/random.asm | 11 ++++ apps/mbrot/Makefile | 2 +- apps/mbrot/mbrot.c | 8 +-- 14 files changed, 199 insertions(+), 38 deletions(-) rename apps/{mbrot => common}/config_request.c (100%) rename apps/{mbrot => common}/config_request.h (100%) rename apps/{mbrot => common}/v9958.asm (61%) rename apps/{mbrot => common}/v9958.c (92%) rename apps/{mbrot => common}/v9958.h (97%) create mode 100644 apps/line/Makefile create mode 100755 apps/line/build.sh create mode 100644 apps/line/line.c create mode 100644 apps/line/random.asm diff --git a/.github/workflows/ez80-for-rc.yml b/.github/workflows/ez80-for-rc.yml index a03e88c..c2cee2e 100644 --- a/.github/workflows/ez80-for-rc.yml +++ b/.github/workflows/ez80-for-rc.yml @@ -135,9 +135,9 @@ jobs: - name: install ez80-clang run: | - wget --progress=dot:giga https://github.com/dinoboards/ez80-clang/releases/download/v0.0.5/ez80-clang-0.0.5.tar.gz - tar -xzvf ez80-clang-0.0.5.tar.gz - cd ez80-clang-0.0.5 + wget --progress=dot:giga https://github.com/dinoboards/ez80-clang/releases/download/v0.0.6/ez80-clang-0.0.6.tar.gz + tar -xzvf ez80-clang-0.0.6.tar.gz + cd ez80-clang-0.0.6 sudo ./install.sh - name: build apps diff --git a/.gitignore b/.gitignore index c23c59f..10019af 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ hardware/bin/**/*.doc apps/bin/ releases/ +.vscode diff --git a/apps/mbrot/config_request.c b/apps/common/config_request.c similarity index 100% rename from apps/mbrot/config_request.c rename to apps/common/config_request.c diff --git a/apps/mbrot/config_request.h b/apps/common/config_request.h similarity index 100% rename from apps/mbrot/config_request.h rename to apps/common/config_request.h diff --git a/apps/mbrot/v9958.asm b/apps/common/v9958.asm similarity index 61% rename from apps/mbrot/v9958.asm rename to apps/common/v9958.asm index 1cd27fd..72fc8ea 100644 --- a/apps/mbrot/v9958.asm +++ b/apps/common/v9958.asm @@ -11,23 +11,34 @@ VDP_STAT: equ $FF99 ; VDP status (read only) VDP_PALT: equ $FF9A ; VDP palette latch (write only) VDP_REGS: equ $FF9B ; VDP register access (write only) + +.macro DELAY_1_7US ; approx 1.7 us @25Mhz CPU + PUSH AF + POP AF + PUSH AF + POP AF + NOP + NOP +.endm + .global _outDat ; void outDat(uint8_t b) _outDat: LD IY, 0 ADD IY, SP - LD L, (IY + 3) + LD A, (IY + 3) LD BC, VDP_DATA - OUT (BC), L + OUT (BC), A RET .global _outCmd -; void outCmd(uint8_t b) __z88dk_fastcall +; void outCmd(uint8_t b) _outCmd: LD IY, 0 ADD IY, SP - LD L, (IY + 3) + LD A, (IY + 3) LD BC, VDP_ADDR + OUT (BC), A RET .global _commandDrawLine @@ -37,9 +48,12 @@ _commandDrawLine: LD BC, VDP_ADDR LD A, 2 OUT (BC), A - LD A, 0x80 | 15 + DELAY_1_7US ; DELAY and LD provde the ~2us required delay + LD A, 0x80 | 15 ; measured on CPU running @25Mhz OUT (BC), A + DELAY_1_7US + ; WAIT FOR ANY PREVIOUS COMMAND TO COMPLETE _commandDrawLineReady: IN A, (BC) @@ -48,19 +62,32 @@ _commandDrawLineReady: ; SET INDIRECT REGISTER TO 36 LD A, 36 + DELAY_1_7US OUT (BC), A - LD A, 0x80 | 17 + DELAY_1_7US ; DELAY and LD provde the ~2us required delay + LD A, 0x80 | 17 ; measured on CPU running @25Mhz OUT (BC), A LD HL, __fromX - LD DE, VDP_REGS - LD BC, 11 - OTIRX + LD BC, VDP_REGS + LD A, 11 +.outs: ; loop calibrated to have appro 2us + PUSH AF ; between rights + POP AF + NOP ; spec seems to indicate we should have a period + ; of 8us after the 2nd byte is written + LD E, (HL) ; but we seem to get a way with 2us just fine??? + OUT (BC), E + INC HL + DEC A + JR NZ, .outs LD BC, VDP_ADDR XOR A + DELAY_1_7US OUT (BC), A - LD A, 0x80 | 15 + DELAY_1_7US ; DELAY and LD provde the ~2us required delay + LD A, 0x80 | 15 ; measured on CPU running @25Mhz OUT (BC), A EI @@ -74,17 +101,22 @@ _waitForCommandCompletion: LD A, 2 OUT (BC), A - LD A, 0x80 | 15 + DELAY_1_7US ; DELAY and LD provde the ~2us required delay + LD A, 0x80 | 15 ; measured on CPU running @25Mhz OUT (BC), A + DELAY_1_7US + _waitForCommandCompletionLoop: IN A, (BC) RRCA JR C, _waitForCommandCompletionLoop XOR A + DELAY_1_7US OUT (BC), A - LD A, 0x80 | 15 + DELAY_1_7US ; DELAY and LD provde the ~2us required delay + LD A, 0x80 | 15 ; measured on CPU running @25Mhz OUT (BC), A EI @@ -107,7 +139,7 @@ _outRegIndByte: LD IY, 0 ADD IY, SP LD A, (IY + 3) - LD BC, VDP_ADDR + LD BC, VDP_REGS OUT (BC), A RET @@ -117,11 +149,11 @@ _outRegIndInt: LD IY, 0 ADD IY, SP LD HL, (IY + 3) - LD BC, VDP_ADDR - LD A, L - OUT (BC), A - LD A, H - OUT (BC), A + LD BC, VDP_REGS + OUT (BC), L + DELAY_1_7US ; DELAY and LD provde the ~2us required delay + LD A, 0 ; measured on CPU running @25Mhz + OUT (BC), H RET .global inDat @@ -142,16 +174,20 @@ _readStatus: ; SET READ REGISTER TO 15 OUT (BC), L + DELAY_1_7US LD A, 0x80 | 15 OUT (BC), A LD HL, 0 - IN L, (BC) ; READ STATUS + IN L, (BC) ; READ STATUS + + DELAY_1_7US ; RESTORE READ REGISTER TO DEFAULT OF 0 XOR A OUT (BC), A - LD A, 0x80 | 15 + DELAY_1_7US ; DELAY and LD provde the ~2us required delay + LD A, 0x80 | 15 ; measured on CPU running @25Mhz OUT (BC), A RET @@ -162,12 +198,11 @@ __writeRegister: ADD IY, SP LD HL, (IY + 3) LD BC, VDP_ADDR - OUT (BC), L LD A, 0x80 OR H + DELAY_1_7US OUT (BC), A - RET diff --git a/apps/mbrot/v9958.c b/apps/common/v9958.c similarity index 92% rename from apps/mbrot/v9958.c rename to apps/common/v9958.c index e72d99e..9715b82 100644 --- a/apps/mbrot/v9958.c +++ b/apps/common/v9958.c @@ -2,15 +2,18 @@ #include #include -#define DI __asm__("DI") +#include +#define DI __asm__("DI") #define EI __asm__("EI") void setBaseRegisters(uint8_t *pReg) { DI; - for (uint8_t i = 0; i < REGISTER_COUNT; i++) - writeRegister(i, *pReg++); + for (uint8_t i = 0; i < REGISTER_COUNT; i++) { + writeRegister(i, *pReg); // if we inline the increment, the compiler (with -Oz seems to pre-increment the pointer) + pReg++; + } EI; } @@ -81,13 +84,15 @@ void clearAllMemory(void) { writeRegister(14, 0); outCmd(0); outCmd(0x40); - for (long i = 0; i < 0x10000; i++) - outDat(0x00); - for (long i = 0x10000; i < 0x20000; i++) + for (int i = 0; i < 0x10000; i++) + outDat(0x41); + for (int i = 0x10000; i < 0x20000; i++) outDat(0x00); EI; } +extern void delay(void); + void clearScreenBank0(uint8_t color) { DI; // Clear bitmap data from 0x0000 to 0x3FFF diff --git a/apps/mbrot/v9958.h b/apps/common/v9958.h similarity index 97% rename from apps/mbrot/v9958.h rename to apps/common/v9958.h index 233b4a5..09bed13 100644 --- a/apps/mbrot/v9958.h +++ b/apps/common/v9958.h @@ -28,7 +28,7 @@ extern void outPal(uint8_t b); extern void outRegIndInt(uint16_t b); extern void outRegIndByte(uint8_t b); -#define writeRegister(a, b) _writeRegister(a * 256 + b) +#define writeRegister(a, b) _writeRegister((a)*256 + (b)) #define REGISTER_COUNT 12 diff --git a/apps/ez80/ez80-instr.inc b/apps/ez80/ez80-instr.inc index 49b1120..7bd567c 100644 --- a/apps/ez80/ez80-instr.inc +++ b/apps/ez80/ez80-instr.inc @@ -3,6 +3,10 @@ RST.L $10 .endm +.macro EZ80_DELAY + RST.L $18 +.endm + .macro EZ80_UTIL_GET_BUSTM XOR A LD B, 1 @@ -12,7 +16,13 @@ .macro EZ80_UTIL_GET_CPU_FQ XOR A LD B, 5 - EZ80_FN + EZ80_FN +.endm + +.macro EZ80_UTIL_DEBUG + XOR A + LD B, 7 + EZ80_FN .endm diff --git a/apps/line/Makefile b/apps/line/Makefile new file mode 100644 index 0000000..78efb4f --- /dev/null +++ b/apps/line/Makefile @@ -0,0 +1,10 @@ +SHELL := /bin/sh +.ONESHELL: +MAKEFLAGS += --warn-undefined-variables +MAKEFLAGS += --no-builtin-rules + +all: LINE.COM + +.PHONY: LINE.COM +LINE.COM: + @ez80-cc --optimise speed --output-dir ../bin LINE.COM line.c ../common/config_request.c ../common/v9958.asm ../common/v9958.c random.asm diff --git a/apps/line/build.sh b/apps/line/build.sh new file mode 100755 index 0000000..df1f45e --- /dev/null +++ b/apps/line/build.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +source ~/.ez80-clang + +SCRIPT_DIR=$(dirname "$0") +SCRIPT_DIR=$(cd "${SCRIPT_DIR}/" && pwd)/../../clang-tool-chain/ + +# export EZ80_CLANG_SYSTEM_INCLUDE_PATH=${SCRIPT_DIR}/include +# export EZ80_CLANG_LIB_PATH=${SCRIPT_DIR}/lib/ +# export EZ80_CLANG_LS_PATH=${SCRIPT_DIR}/linker-scripts/ + +# export INCLUDE_PATHS="-isystem ${SCRIPT_DIR}/include -isystem ${SCRIPT_DIR}/working/llvm-project/build/lib/clang/15.0.0/include/" +# PATH="${SCRIPT_DIR}working/llvm-project/build/bin:${SCRIPT_DIR}working/opt/ez80-none-elf/bin/:${PATH}" + +# shopt -s expand_aliases +# alias ez80-clang="clang -nostdinc" +# alias ez80-as="ez80-none-elf-as" +# alias ez80-ld="ez80-none-elf-ld" + + +set -e + +echo "Compiling line.c -> line.s" +ez80-clang ${INCLUDE_PATHS} -nostdinc -ffunction-sections -fdata-sections -Oz -Wall -Wextra -Wunreachable-code -Werror -mllvm -z80-print-zero-offset -S line.c -c -o line.s + +# echo "Compiling line.s -> line.o" +# ez80-as -march=ez80+full -a=./line.lst ./line.s -o ./line.o + +pushd ../common +echo "Compiling config_request.c -> config_request.s" +ez80-clang ${INCLUDE_PATHS} -nostdinc -ffunction-sections -fdata-sections -Oz -Wall -Wextra -Wunreachable-code -Werror -mllvm -z80-print-zero-offset -S config_request.c -c -o config_request.s + +# echo "Compiling config_request.s -> config_request.o" +# ez80-as -march=ez80+full -a=./config_request.lst ./config_request.s -o ./config_request.o + +echo "Compiling v9958.c -> v9958.s" +ez80-clang ${INCLUDE_PATHS} -nostdinc -ffunction-sections -fdata-sections -O3 -Wall -Wextra -Wunreachable-code -Werror -mllvm -z80-print-zero-offset -S v9958.c -c -o v9958.s + +popd + +# echo "Compiling v9958.asm -> v9958.o" +# ez80-as -march=ez80+full -a=./v9958.asm.lst ./v9958.asm -o ./v9958.o + +# echo "Compiling nanoprintf.c -> nanoprintf.s" +# ez80-clang ${INCLUDE_PATHS} -nostdinc -ffunction-sections -fdata-sections -Oz -Wall -Wextra -Wunreachable-code -Werror -mllvm -z80-print-zero-offset -S nanoprintf.c -c -o nanoprintf.s + +# echo "Compiling nanoprintf.s -> nanoprintf.o" +# ez80-as -march=ez80+full -a=./nanoprintf.lst ./nanoprintf.s -o ./nanoprintf.o + + +# echo "Linking libcrt.a main.o -> main.com" +# ez80-ld -T ${EZ80_CLANG_LS_PATH}cpm-64k.ld --relax -O1 --gc-sections --strip-discarded --orphan-handling=error --print-map-discarded -Map=main.map -L${EZ80_CLANG_LIB_PATH} -lcrt ./mbrot.o ./config_request.o v9958.o -lclib -lcrt --oformat binary -o main.com + diff --git a/apps/line/line.c b/apps/line/line.c new file mode 100644 index 0000000..43faa3f --- /dev/null +++ b/apps/line/line.c @@ -0,0 +1,36 @@ +#include "../common/config_request.h" +#include "../common/v9958.h" +#include +#include +#include +// +extern uint8_t get_random_seed(void); + +RGB palette[16] = { + {0, 0, 0}, {1, 0, 0}, {4, 0, 0}, {4, 1, 1}, {15, 0, 0}, {0, 1, 0}, {0, 4, 0}, {1, 4, 1}, + {1, 8, 1}, {0, 0, 1}, {0, 0, 4}, {1, 1, 4}, {1, 1, 8}, {10, 0, 10}, {0, 15, 15}, {15, 15, 15}, +}; + +int main(void) { + const uint8_t mode = getVideoMode(); + const uint8_t lines = getLineCount(); + + srand(get_random_seed()); + setMode6(lines, mode); + setPalette(palette); + clearScreenBank0(4); + // uint8_t c = rand() & 15; + unsigned int i = 0; + + printf("Press any key to abort\r\n"); + + // for (unsigned int i = 0; i < 4000; i++) { + while (true) { + if (cpm_rawio() != 0) + return 0; + drawLine(rand() % 512, i % lines, rand() % 512, i % lines, rand() & 15, CMD_LOGIC_IMP); + i++; + } + + // return 0; +} diff --git a/apps/line/random.asm b/apps/line/random.asm new file mode 100644 index 0000000..12c0af5 --- /dev/null +++ b/apps/line/random.asm @@ -0,0 +1,11 @@ + + .assume adl = 1 + + section .text,"ax",@progbits + + .global _get_random_seed + +_get_random_seed: + LD A, R + LD L, A + RET diff --git a/apps/mbrot/Makefile b/apps/mbrot/Makefile index 28446f1..afd984e 100644 --- a/apps/mbrot/Makefile +++ b/apps/mbrot/Makefile @@ -7,4 +7,4 @@ all: MBROT.COM .PHONY: MBROT.COM MBROT.COM: - @ez80-cc --output-dir ../bin MBROT.COM mbrot.c config_request.c v9958.asm v9958.c + @ez80-cc --optimise speed --output-dir ../bin MBROT.COM mbrot.c ../common/config_request.c ../common/v9958.asm ../common/v9958.c diff --git a/apps/mbrot/mbrot.c b/apps/mbrot/mbrot.c index fe226d1..d5b722d 100644 --- a/apps/mbrot/mbrot.c +++ b/apps/mbrot/mbrot.c @@ -10,8 +10,8 @@ create 24 bit color graphic file , portable pixmap file = PPM see http://en.wikipedia.org/wiki/Portable_pixmap to see the file use external application ( graphic viewer) */ -#include "config_request.h" -#include "v9958.h" +#include "../common/config_request.h" +#include "../common/v9958.h" #include #include #include @@ -42,7 +42,7 @@ float Zx2; float Zy2; /* screen ( integer) coordinate */ -uint16_t iX, iY; +uint24_t iX, iY; uint8_t iteration; int main(void) { @@ -78,7 +78,7 @@ int main(void) { Zy2 = Zy * Zy; }; - if (cpm_rawio() != 0) + if (((iX & 15) == 0) && cpm_rawio() != 0) return 0; pointSet(iX, iY, iteration, CMD_LOGIC_IMP);