Merge branch 'master' of ichibi:/home/git/Repositories/pato-z80-home-computer

This commit is contained in:
Daniele Verducci (ZenPenguin)
2021-01-01 17:51:02 +01:00
24 changed files with 131 additions and 64 deletions

View File

@ -0,0 +1,12 @@
# Pat80 Applications
## Intro
This folder contains some example applications.
The folder `brief` contains little applications that can be entered directly via keyboard in the memory monitor.
The folder `big` contains complete applications to be loaded via sdcard or tape.
## How to write an application
When the Pat80 operating system is built, a `abi-generated.asm` file is built along with the rom binary. This file contains the description of the OS available API.
An application targeting the last version of the OS should include this file, to make the system calls labels available inside the application code.
The application can obtain the operating system ABI version (ABI -> https://en.wikipedia.org/wiki/Application_binary_interface) via the Sys_ABI call (it is a 16 bits integer returned in BC).
The application's first command should be an ABI check: if the OS version is not compatible with the app, the app should exit displaying an error message.

View File

@ -0,0 +1,7 @@
org 0xA000
include '../../os/abi-generated.asm'
STRING: DB "Hello",0
ld bc, STRING
call Sys_Print
jp 0

View File

@ -1,3 +0,0 @@
ld bc, 0xA000
call 0x0010
jp 0

View File

@ -1,9 +0,0 @@
org 0x00A0
test:
nop
nop
nop
nop
nop
jp test

View File

@ -1,16 +0,0 @@
; Prints "Hello world" in terminal
; Usage: assemble this file with z80asm and insert the resulting bytes
; via Memory Monitor from address 0xA000 to test SET and RUN commands.
org 0xA000 ; Set starting position to ram
ld bc, HELLO_WORLD_STR
Term_print:
ld a, (bc) ; bc is the pointer to string's first char
cp 0 ; compare A content with 0 (subtract 0 from value and set zero flag Z if result is 0)
jp z, term_print_end
out (0x00),a ; output char to IO device 0, addr 0
inc bc ; increment bc to move to next char
jp Term_print
term_print_end:
halt
HELLO_WORLD_STR: DB "Hello world!",0

View File

@ -1,5 +0,0 @@
Sys_Beep: equ $0050
Sys_Print: equ $0010
Sys_Printc: equ $0020
Sys_Readc: equ $0030
Sys_Readline: equ $0040

View File

@ -1,2 +1,2 @@
org 0xA000 ; Set starting position to ram
include '../bios/main.asm'
include '../os/main.asm'

View File

@ -1,8 +1,8 @@
bios:
os:
@echo "Building PAT80 rom..."
@z80asm -i main.asm -o rom.bin || (exit 1)
@echo "Generating label lookup table..."
@z80asm -i main.asm -o rom.bin -L 2>&1 | grep "Sys_" > rom.label
@z80asm -i main.asm -o rom.bin -L 2>&1 | grep "Sys_" > abi-generated.asm
@echo "PAT80 Rom size:"
@du -h rom.bin
@echo "Stretching rom to EEPROM size..."

15
assembly/os/README.md Normal file
View File

@ -0,0 +1,15 @@
# Pat80 Operating System and Memory Monitor
## Intro
This folder contains the Pat80 Operating System.
It is a System Monitor that makes available also some system API to access hardware (monitor, sound, keyboard, parallel terminal...).
## Build
### Requirements
z80asm, minipro
### Make
The os can be build issuing command `make`.
Two files will be generated:
- `rom.bin` is the rom file to be flashed on the eeprom
- `abi-generated.asm` is the file to be included in any Pat80 application to access system APIs (see README.md in ../applications/)
The build routine will then try to write the rom to a MiniPRO.

View File

@ -0,0 +1,6 @@
Sys_ABI: equ $0003
Sys_Beep: equ $0013
Sys_Print: equ $0007
Sys_Printc: equ $000a
Sys_Readc: equ $000d
Sys_Readline: equ $0010

View File

@ -23,39 +23,37 @@ jp Sysinit ; Startup vector: DO NOT MOVE! Must be the first instruction
; System calls provide access to low level functions (input from keyboard, output to screen etc).
; The name starts always with Sys_
; Returns ABI version.
; (ABI -> https://en.wikipedia.org/wiki/Application_binary_interface)
; Any Pat80 application should check the ABI version on startup, and refuse to run if not compatible.
; @return bc the ABI version
Sys_ABI:
ld bc, 0
ret
; Prints string
; @param BC Pointer to a null-terminated string first character
org 0x0010
Sys_Print:
call Term_print
ret
jp Term_print
; Writes a single character
; @param A Value of character to print
org 0x0020
Sys_Printc:
call Term_printc
ret
jp Term_printc
; Reads a single character
; @return A The read character
org 0x0030
Sys_Readc:
call Term_readc
ret
jp Term_readc
; Reads a line
; @return BC The pointer to a null-terminated read string
org 0x0040
Sys_Readline:
call Term_readline
ret
jp Term_readline
; Emits system beep
org 0x0050
Sys_Beep:
call Snd_beep
ret
jp Snd_beep

View File

@ -469,22 +469,47 @@ monitor_printAsciiByte:
call Sys_Printc
ret
; Copy data from STDIN to application memory. This is tought to be used with parallel terminal, not keyboard:
; 0s are not ignored and the sequence is complete when no data is available for 8 cpu cycles.
; Copy data from parallel terminal to application memory. This is tought to be used with the ADB function of the Pat80 Python Terminal.
; Uses TERM_DATA_AVAIL_REG to check if a byte is available before reading it.
; The first two received bytes (heading bytes) defines the stream length (MSB first), the rest of the bytes are copied to memory.
; The copy is completed when the number of bytes defined in the heading bytes are received.
; @uses a, b, c, d, h, l
monitor_copyTermToAppMem:
; d contains the current status.
; 2 = waiting for first heading byte
; 1 = waiting for second heading byte
; 0 = heading bytes received, now receiving binary stream
ld d, 2
ld hl, APP_SPACE ; we will write in APP_SPACE
ld b, 255; MON_ADB_TIMEOUT ; the timeout counter (number cycles without available data that represent the end of stream)
monitor_copyTermToAppMem_loop:
dec b ; decrement the timeout counter
ret z ; if counter is 0, timeout reached: return
; check if bytes are available
call Term_availb
cp 0
jp z, monitor_copyTermToAppMem ; no bytes available, next loop
; bytes are available
ld b, 255 ;MON_ADB_TIMEOUT; reset the counter
ld (hl), a ; copy byte to memory
inc hl ; move to next memory position
; check if bytes are available
call Term_availb
cp 0
jp z, monitor_copyTermToAppMem ; no bytes available, next loop
; bytes are available
ld a, d
cp 2 ; check if we are receiving first header byte
jp z, monitor_copyTermToAppMem_loop_rec_head_byte_1
ld a, d
cp 1 ; check if we are receiving second header byte
jp z, monitor_copyTermToAppMem_loop_rec_head_byte_2
; we are receiving binary stream: read byte and save to memory
call Term_readb
ld (hl), a ; copy byte to memory
inc hl ; move to next memory position
jp monitor_copyTermToAppMem_loop ; continue loop
monitor_copyTermToAppMem_loop_rec_head_byte_1:
; we are receiving first header byte: read byte and save to b
call Term_readb
ld b, a
dec d
jp monitor_copyTermToAppMem_loop ; continue loop
monitor_copyTermToAppMem_loop_rec_head_byte_2:
; we are receiving second header byte: read byte and save to c
call Term_readb
ld c, a
dec d
jp monitor_copyTermToAppMem_loop ; continue loop