Skip to content

Commit

Permalink
Merge pull request #24 from Z80-Retro/dev
Browse files Browse the repository at this point in the history
Refactor BIOS and I/O lib for shared use on both the Retro! and Nouveau
  • Loading branch information
johnwinans authored Jul 14, 2024
2 parents ef7b3f7 + efcbb2e commit d0dcfd1
Show file tree
Hide file tree
Showing 29 changed files with 423 additions and 178 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
*.sym
mkfs
2063-Z80-cpm.zip
Make.local
10 changes: 10 additions & 0 deletions filesystem/Make.default → Make.default
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# DO NOT EDIT THIS FILE
# Override these values if needed by assigning different values in a Make.local file

# A set of default values of things that might be of
# interest to more than one Makefile.

Expand All @@ -8,3 +11,10 @@ SD_DEV=/dev/sda1

# This is used before burning an SD card image to make sure we are on the correct host!
SD_HOSTNAME=raspberrypi

# Be default, build for the Z80-Retro!
ASM_FLAGS=-I../lib -I../libretro

BOOT_MSG=Z80 Retro Board 2063.3

-include $(TOP)/Make.local
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
SUBDIRS=\
boot \
retro \
tests \
hello \
retro \
filesystem

CLEAN_DIRS=$(SUBDIRS:%=clean-%)
Expand Down Expand Up @@ -33,6 +33,8 @@ REL_FILES=\
doc \
hello \
lib \
libretro \
libnouveau \
retro \
tests \
filesystem/Makefile \
Expand Down
4 changes: 2 additions & 2 deletions README-SD.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Do *NOT* expect that you will be able to recover any data after doing this!
On my raspberry PI, with only one SD adapter plugged into a USB port, I use the
following command:

sudo dd if=/dev/zero of=/dev/sda bs=512 count=10
sudo dd if=/dev/zero of=/dev/sda bs=512 count=100 conv=fsync

## Partition your SD card

Expand Down Expand Up @@ -120,7 +120,7 @@ At this point, Liunux should recognize that the drive has one partition on it:

If we write "Hello world!" into partition 1:

echo "Hello world!" | sudo dd of=/dev/sda1 bs=512
echo "Hello world!" | sudo dd of=/dev/sda1 bs=512 conv=fsync

...then we can see it by looking at the raw disk image:

Expand Down
8 changes: 5 additions & 3 deletions boot/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
ASM_FLAGS=-I../lib

TOP=..
include $(TOP)/Make.default


all: firmware.bin
Expand All @@ -7,10 +9,10 @@ clean:
rm -f ldr
rm -f *.lst *.bin *.hex *.sym

DATE := $(shell date --rfc-3339=seconds)
DATE := $(shell date +"%Y-%m-%d %H:%M:%S%z")
GIT_VERSION := $(shell git describe --long --dirty; git show -s --format='%ci')
%.bin: %.asm
cat $< | sed -e "s/@@DATE@@/$(DATE)/g" -e "s/@@GIT_VERSION@@/$(GIT_VERSION)/g" | z80asm - -o $@ --list=$(basename $@).lst --label=$(basename $@).sym $(ASM_FLAGS)
cat $< | sed -e "s/@@DATE@@/$(DATE)/g" -e "s/@@GIT_VERSION@@/$(GIT_VERSION)/g" -e "s/@@BOOT_MSG@@/$(BOOT_MSG)/g" | z80asm - -o $@ --list=$(basename $@).lst --label=$(basename $@).sym $(ASM_FLAGS)


world: clean all
Expand Down
24 changes: 8 additions & 16 deletions boot/firmware.asm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;****************************************************************************
;
; Copyright (C) 2021,2022,2023 John Winans
; Copyright (C) 2021,2022,2023,2024 John Winans
;
; This library is free software; you can redistribute it and/or
; modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -53,7 +53,7 @@ include 'memory.asm'
; NOTE THAT THE SRAM IS NOT READABLE AT THIS POINT
;###################################################

; Select SRAM low bank 14, idle the SD card, and idle printer signals
; Select SRAM low bank, idle the SD card, etc.
ld a,(gpio_out_cache)
out (gpio_out),a

Expand All @@ -73,14 +73,8 @@ include 'memory.asm'

ld sp,.stacktop

; Initialize the CTC so that the SIO will have a baud clock if J11-A is set to the CTC!
;ld c,1 ; 115200 bps
;ld c,6 ; 19200 bps
ld c,12 ; 9600 bps
call init_ctc_1

; Init the SIO to run at 115200 or at the CTC rate depending on J11-A
call sioa_init
call bsp_init ; board-specific init
call con_init

; Display a hello world message.
ld hl,.boot_msg
Expand All @@ -100,7 +94,7 @@ include 'memory.asm'
.boot_msg:
db '\r\n\n'
db '##############################################################################\r\n'
db 'Z80 Retro Board 2063.3\r\n'
db '@@BOOT_MSG@@\r\n'
db ' git: @@GIT_VERSION@@\r\n'
db ' build: @@DATE@@\r\n'
db '\0'
Expand Down Expand Up @@ -446,17 +440,15 @@ endif
include 'sdcard.asm'
include 'spi.asm'
include 'hexdump.asm'
include 'sio.asm'
include 'ctc1.asm'
include 'console.asm'
include 'puts.asm'
include 'bsp.asm'

;##############################################################################
; This is a cache of the last written data to the gpio_out port.
; The initial value here is what is written to the latch during startup.
;##############################################################################
.low_bank: equ 0x0e ; The RAM BANK to use for the bottom 32K
gpio_out_cache: db gpio_out_sd_mosi|gpio_out_sd_ssel|gpio_out_prn_stb|gpio_out_sd_clk|(.low_bank<<4)

gpio_out_cache: db gpio_out_init

;##############################################################################
; This marks the end of the data copied from FLASH into RAM during boot
Expand Down
8 changes: 5 additions & 3 deletions filesystem/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@

all::

# optionally include rules from a local file:
include Make.default
-include Make.local

# Include the detault and any local override rules
# Must set TOP before including Make.default
TOP=..
include $(TOP)/Make.default

.PHONY: all clean world burn blank-all-sd

Expand Down
5 changes: 3 additions & 2 deletions hello/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
ASM_FLAGS=-I../lib

TOP=..
include $(TOP)/Make.default

all: hello.bin

clean:
rm -f ldr
rm -f *.lst *.bin *.hex

DATE := $(shell date --rfc-3339=seconds)
DATE := $(shell date +"%Y-%m-%d %H:%M:%S%z")
GIT_VERSION := $(shell git describe --long --dirty; git show -s --format='%ci')
%.bin: %.asm
cat $< | sed -e "s/@@DATE@@/$(DATE)/g" -e "s/@@GIT_VERSION@@/$(GIT_VERSION)/g" | z80asm - -o $@ --list=$(basename $@).lst $(ASM_FLAGS)
Expand Down
3 changes: 1 addition & 2 deletions hello/hello.asm
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,5 @@ include 'memory.asm'


include 'hexdump.asm'
include 'sio.asm'
include 'ctc1.asm'
include 'console.asm'
include 'puts.asm'
35 changes: 35 additions & 0 deletions libnouveau/bsp.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
;****************************************************************************
;
; Copyright (C) 2024 John Winans
;
; This library is free software; you can redistribute it and/or
; modify it under the terms of the GNU Lesser General Public
; License as published by the Free Software Foundation; either
; version 2.1 of the License, or (at your option) any later version.
;
; This library is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
; Lesser General Public License for more details.
;
; You should have received a copy of the GNU Lesser General Public
; License along with this library; if not, write to the Free Software
; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
; USA
;
; https://github.com/johnwinans/2063-Z80-cpm
;
;****************************************************************************

bsp_init:
ld a,0
;out0 (0x36),a ; RCR = 0 = disable the DRAM refresh controller
db 0xed,0x39,0x36
;out0 (0x32),a ; DCNTL = 0 = zero wait states
db 0xed,0x39,0x32

ld a,0x80
;out0 (0x1f),a ; CCR = 0x80 = run at 1X extal clock speed
db 0xed,0x39,0x1f

ret
117 changes: 117 additions & 0 deletions libnouveau/console.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
;****************************************************************************
;
; Copyright (C) 2024 John Winans
;
; This library is free software; you can redistribute it and/or
; modify it under the terms of the GNU Lesser General Public
; License as published by the Free Software Foundation; either
; version 2.1 of the License, or (at your option) any later version.
;
; This library is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
; Lesser General Public License for more details.
;
; You should have received a copy of the GNU Lesser General Public
; License along with this library; if not, write to the Free Software
; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
; USA
;
; https://github.com/johnwinans/2063-Z80-cpm
;
;****************************************************************************

; Drivers for the Z8S180 ASCI

.CNTLA0: equ 0x00
.CNTLB0: equ 0x02
.RDR0: equ 0x08
.ASEXT0: equ 0x12
.STAT0: equ 0x04
.TDR0: equ 0x06

;##############################################################
; Return NZ if the console UART is ready and Z (with A=0) if not ready.
; Clobbers: AF
;##############################################################
con_tx_ready:
;IN0 A,(.STAT0) ;C4H,read status
db 11101101B,00111000B,.STAT0
AND 2
ret ; a = 0 = not ready

;##############################################################
; Return NZ if the console UART is ready and Z (with A=0) if not ready.
; Clobbers: AF
;##############################################################
con_rx_ready:
; hack to clear any overrun errors (See Errata about ASCI seizures)
;IN0 A,(.CNTLA0) ;C4H,read status
db 11101101B,00111000B,.CNTLA0
and ~0x08
;OUT0 (.CNTLA0),A
db 0xed,0x39,.CNTLA0

;IN0 A,(.STAT0) ;C4H,read status
db 11101101B,00111000B,.STAT0
AND 10000000B
ret ; 0 = not ready


;##############################################################
; stolen from https://groups.google.com/g/retro-comp/c/N574sGiwmaI?pli=1
; mods are my fault :-)
;##############################################################
con_init:
LD A,01100100B ; rcv enable, xmit enable, no parity
;LD A,01100101B ; rcv enable, xmit enable, no parity
;OUT0 (.CNTLA0),A ; set cntla
db 0xed,0x39,.CNTLA0

LD A,00000000B ; div 10, div 16, div 2 18432000/1/1/10/16/1 = 115200
;OUT0 (.CNTLB0),A ; set cntlb
db 0xed,0x39,.CNTLB0

LD A,01100110B ; no cts, no dcd, no break detect
;OUT0 (.ASEXT0),A ; set ASCI0 EXTENSION CONTROL (Z8S180 only)
db 0xed,0x39,.ASEXT0
XOR A
;OUT0 (.STAT0),A ; ASCI Status Reg Ch 0
db 0xed,0x39,.STAT0
ret


;##############################################################
; Wait for the transmitter to become ready and then
; print the character in the C register.
; Clobbers: AF
;##############################################################
con_tx_char:
call con_tx_ready
jr z,con_tx_char
ld a,c

;OUT0 (.TDR0),A ;C6H
db 0xed,0x39,.TDR0

ret

;##############################################################
; Wait for the receiver to become ready and then return the
; character in the A register.
; Clobbers: AF
;
; XXX need to concern ourselves with the Errata note that
; says we need to write zero into CNTLA0, bit 3 (ERF) to
; reset an overflow error flag when set because RX will
; seize.
;
;##############################################################
con_rx_char:
call con_rx_ready
jr z,con_rx_char

;IN0 A,(.RDR0)
db 11101101B,00111000B,.RDR0

ret
42 changes: 42 additions & 0 deletions libnouveau/io.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
;****************************************************************************
;
; Copyright (C) 2024 John Winans
;
; This library is free software; you can redistribute it and/or
; modify it under the terms of the GNU Lesser General Public
; License as published by the Free Software Foundation; either
; version 2.1 of the License, or (at your option) any later version.
;
; This library is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
; Lesser General Public License for more details.
;
; You should have received a copy of the GNU Lesser General Public
; License along with this library; if not, write to the Free Software
; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
; USA
;
; https://github.com/johnwinans/2063-Z80-cpm
;
;****************************************************************************

; Z80 Nouveau

gpio_in: equ 0xf0 ; GP input port
gpio_out: equ 0xf1 ; GP output port
flash_disable: equ 0xfe ; dummy-read from this port to disable the FLASH

; bit-assignments for General Purpose output port
gpio_out_sd_mosi: equ 0x01
gpio_out_sd_clk: equ 0x02
gpio_out_sd_ssel: equ 0x04

; bit-assignments for General Purpose input port
;gpio_in_user1: equ 0x20
gpio_in_sd_det: equ 0x40
gpio_in_sd_miso: equ 0x80

; The initial value to write into the gpio_out latch.
; The value here will idle the SD card interface.
gpio_out_init: equ gpio_out_sd_mosi|gpio_out_sd_clk|gpio_out_sd_ssel
Loading

0 comments on commit d0dcfd1

Please sign in to comment.