Wading through documentation is always hard and, to quote the IETF "
we believe in rough consensus and running code", I thought that it would be worthwhile building an example which demonstrates many of the capabilities of the z88dk with respect to the RC2014 community, and platform.
The example is a kind of a C shell (
Yet Another SHell) that can read an underlying FAT32 (or smaller) file system, and allow you to do a number of things to that file system, such as creating directories, copying and deleting files, and modifying file characteristics.
The program is not a finished, polished, product. But rather it is supposed to demonstrate the following things with running code.
- Use of C language with no assembly required, invoking the zsdcc and the rest of the z88dk development kit, to produce finished binaries.
- Use of all of the different subtypes possible for the RC2014 target. Including the ACIA and SIO subtypes for building bare metal ROMs, and the CPM and HBIOS subtypes for use with CP/M and RomWBW.
- Use of serial input and output to capture commands and output results at a high level using standard C library calls.
- Installation and usage of the time and ff (ChaN FAT file system) libraries, together with the appropriate diskio library to interface to the hardware or bios API as relevant.
- An implementation of Stephen Brennan's shell, or at github code in lsh.
To build the example, start off by installing z88dk, using the instructions found
here,
there, and
everywhere.
Then clone or download these
z88dk-libraries. From the base directory, install the libraries relevant to the RC2014, including the HBIOS libraries too.
> z88dk-lib +rc2014 time ff
> z88dk-lib +hbios time ff diskio_hbios
Then download the example program, or any other example. And from the same directory you can choose a command line.
> zcc +rc2014 -subtype=acia -clib=sdcc_iy -SO3 -v -m --list --max-allocs-per-node100000 -llib/rc2014/time -llib/rc2014/ff yash.c -o yash -create-app
> zcc +rc2014 -subtype=sio -clib=sdcc_iy -SO3 -v -m --list --max-allocs-per-node100000 -llib/rc2014/time -llib/rc2014/ff yash.c -o yash -create-app
> zcc +rc2014 -subtype=hbios -clib=sdcc_iy -SO3 -v -m --list --max-allocs-per-node100000 -llib/rc2014/time -llib/rc2014/ff yash.c -o yash -create-app
> zcc +rc2014 -subtype=cpm -clib=sdcc_iy -SO3 -v -m --list --max-allocs-per-node100000 -llib/rc2014/time -llib/rc2014/ff yash.c -o yash -create-app
This is for the RC2014 when it has a 82C55 IDE diskio Interface. The output will be written to the first FAT file system found on the drive.
Most likely to be used with CP/M-IDE firmware, but any CPM that supports the standard 82C55 IDE interface will work.
The drive will be seen as Drive 0:
#include <arch/rc2014.h> /* Declarations of IDE functions */
#include <lib/rc2014/ff.h> /* Declarations of FatFs API */
#include <arch/rc2014/diskio.h> /* Declarations of diskio functions */
The following are ONLY needed for the hbios subtype. To allow buffers to be copied using the hbios api, they have to be located above 0x8000, so this is where the BSS section starts.
A warning is produced should the BSS section need to be moved to prevent clashing with the DATA section (using the #pragma), so watch for warnings to confirm there is no overlap between DATA and BSS sections, and set as needed.
#include <arch/hbios.h> /* Declarations of HBIOS functions */
#pragma output CRT_ORG_BSS = 0x9000 // move bss origin to address 0x9000
It is also possible to link in the hbios diskio layer and use that to interface to any drive (not just an IDE drive).
The command looks quite similar, except for the extra diskio library that takes precedence over the inbuilt IDE diskio functions.
> zcc +rc2014 -subtype=hbios -clib=sdcc_iy -SO3 -v -m --list --max-allocs-per-node100000 -llib/hbios/time -llib/hbios/diskio_hbios -llib/hbios/ff yash.c -o yash -create-app
#include <arch/rc2014.h> /* Declarations of IDE functions */
#include <arch/hbios.h> /* Declarations of HBIOS functions */
#include <lib/hbios/ff.h> /* Declarations of FatFs API */
#include <lib/hbios/diskio_hbios.h> /* Declarations of diskio functions */
#pragma output CRT_ORG_BSS = 0x9000 // move bss origin to address 0x9000
This is for the RC2014 when it has RomWBW firmware and any type of drive. The drive number is the same as the logical drive number reported on boot.
The program is loaded in the monitor, and started by R100.
Note that relative directories are not working currently for hbios (a limitation of the example code that I've not bothered to fix), so just use the full path.
i.e "mkdir 2:/test", "ls 2:/test", and "cp 2:/test.bin 2:/test/test2.bin"
If the example were to be extended, it would be possible to copy from multiple volumes (currently only one volume supported), and to move files between FATFS and CP/M, for example.
But today, the program reports the following options.
>R100
> help
yash v1.0 2020
The following functions are built in:
md - [origin] - memory dump
help - this is it
exit - exit
mount [drive:] - mount a FAT file system
umount [drive:] - unmount a FAT file system
ls [path] - directory listing
rm [file] - delete a file
cp [src][dest] - copy a file
cd [path] - change the current working directory
pwd - show the current working directory
mkdir [path] - create a new directory
chmod [path][attr][mask] - change file or directory attributes
ds [drive:] - disk status
dd [drive][sector] - disk dump, drive in decimal, sector in decimal
clock [timestamp] - set the time (UNIX epoch) 'date +%s'
tz [tz] - set timezone (no daylight saving)
diso - local time ISO format: 2013-03-23 01:03:52
date - local time: Sun Mar 23 01:03:52 2013
>
Hope this sparks interest.
Enjoy
Phillip