Skip to content

Commit

Permalink
apps: line and mbrot apps ported
Browse files Browse the repository at this point in the history
  • Loading branch information
dinoboards committed Nov 1, 2024
1 parent 2a21f99 commit 3213075
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 38 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ez80-for-rc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ hardware/bin/**/*.doc

apps/bin/
releases/
.vscode
File renamed without changes.
File renamed without changes.
79 changes: 57 additions & 22 deletions apps/mbrot/v9958.asm → apps/common/v9958.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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


Expand Down
17 changes: 11 additions & 6 deletions apps/mbrot/v9958.c → apps/common/v9958.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
#include <stdbool.h>
#include <stdlib.h>

#define DI __asm__("DI")
#include <stdio.h>

#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;
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/mbrot/v9958.h → apps/common/v9958.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion apps/ez80/ez80-instr.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down
10 changes: 10 additions & 0 deletions apps/line/Makefile
Original file line number Diff line number Diff line change
@@ -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
53 changes: 53 additions & 0 deletions apps/line/build.sh
Original file line number Diff line number Diff line change
@@ -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

36 changes: 36 additions & 0 deletions apps/line/line.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "../common/config_request.h"
#include "../common/v9958.h"
#include <cpm.h>
#include <math.h>
#include <stdio.h>
//
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;
}
11 changes: 11 additions & 0 deletions apps/line/random.asm
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion apps/mbrot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit 3213075

Please sign in to comment.