Skip to content

Services

Peter Wilson edited this page Apr 24, 2023 · 8 revisions

During boot ZLoader copies itself and ZIOS into the first two SRAM pages (20h and 21h) so applications should avoid using this space.

ZIOS optionally provides a set of core hardware services that can be used by applications. They don't need to! If you're writing a new application then decide early on whether you want to make use of these core services. If you do then:

The top 512 bytes of RAM in the fourth application memory page (mapped into FE00-FFF) is reserved. This memory contains amongst other things interrupt service routines and the vector table for IM2. Ideally applications should not map any other memory page into bank 3. It is possible, but the application must first copy the top 512 bytes across to the replacement page. Generally applications can map any of the lower 3 pages however note:

ZIOS installs a JP FE00 handler at the RST 30h address to make accessing ZIOS services fairly straightforward. You can overwrite this and instead CALL FE00 in your code.

Applications that use hardware via the ZIOS services can save a significant amount of memory - the bulk of the implementation resides in the ZIOS reserved pages. This is particularly true of access to SDCards which can be complicated to re-create (but feel free to hack my code in zlib to create your own).

RST 30h is reserved for accessing the services.. Alternatively, if your application wants to make use of the 30h RST address then you can CALL $FE00.

All of the documentation in this Wiki assumes you're using the RST 30h entry point to ZIOS.

Services are identified by a command code passed in the C register. The authoritative list of services can be found in zios/api.asm and applications should ideally include that file for the most recent service list. Current commands:

ID Description
0 Return to the ZLoader UI
1 Map a memory page into one of the Z80 memory banks
2 Allocate a new 16K memory page to the application
3 Release a previously allocated memory page back to ZIOS
4 Print a character to an output device
5 Wait for a character from the current console device
6 Check for received characters (non-blocking)
10 Map a logical SDCard disk to one of the 16 available logical drives
11 Return the current drive mappings
12 Set disk DMA address (where ZIOS should get or send data for I/O requests)
13 Read a sector (512 bytes) from one of the 16 virtual drives
14 Raw Read from absolute sector address on an SDCard (generally should be avoided)
15 Write a 512 bytes sector to one of the 16 virtual drives
16 Raw Write to absolute sector address on an SDCard (generally should be avoided)
17 Read a 128 byte block of data from one of the SDCard 512 byte sectors. ZIOS takes care of caching and de/blocking.
18 Write a 128 byte block to one of the SDCard 512 byte sectors. ZIOS takes care of caching and de/blocking.
19 Purge any unwritten data to SDCards.
20 Purge any unwritten data to SDCards and then clear all cached data (forcing subsequent reads from the device)
21 Return (and optionally clear) SDCard access stats.
22 Translate a virtual SDCard address to an absolute sector on a specific SDCard.
24 Hardware inventory (SDCard presence, video card, PIO cards etc)
25 Logical device inventory. Provides logical names and device IDs for SDCards, consoles and other devices.

Example: My CPM BIOS makes use of the service API for character I/O and SDCard access.

More detail to follow. In the meantime, more detailed information on the services and the registers used is available in zloader/services.asm

You can write applications that don't use these services in which case when those applications are loaded and run they take on responsibility for managing the hardware.

Service 0

Name Return to ZLoader
Parameters None
Return None

Description: Returns control to the ZLoader command line. Registers are preserved in the process control block so debugging is then possible.

Service 1

Name Map a memory page into a memory bank
Parameters D - Memory page to be mapped into Z80 memory bank
E - Memory bank (0-3) into which to map the page
Return A - the page that was previously mapped into this bank

Description: The page (0-255) referenced in the D register is mapped into the 16K bank (0-3) referenced in the E register. The A register returns the previously mapped page which can subsequently be used to restore a mapping.

Be careful not to change the page mapped into the currently executing bank. Generally don't map pages into bank 3, this is where the interrupt service routines reside and changing the mapping is likely to end badly!

Service 4

Name Write a character to an output device
Parameters E - Character to be written
B - Device ID to receive the character
Return None

Description: Write a character to an output device. Currently there are two target devices:

  • 0 - device 0 is SIO port A - the usual port to which a terminal is connected
  • 1 - device 1 is the VDU/Omega keyboard combination