★ CODING ★ DDI-1 Firmware: The Complete CPC 464 DISC Operating System ROM Specification ★ |
DDI-1 Firmware: Chapter 2 - CP/M 2.2 and the BIOS (1/3) |
Chapter 2 - CP/M 2.2 and the BIOS This chapter describes the CP/M 2.2 implementation on the CPC464, with particular reference on how to use the extensive facilities available in the firmware jumpblock and in the BIOS extended jumpblock. This is not a tutorial, the reader should have some knowledge of CP/M and its structure (see ‘A Guide to CP/M' SOFT 159). 2.1 Structure of CP/M CP/M consists of three software modules: Console Command Processor (CCP), Basic Disc Operating System (BDOS) and the Basic Input Output System (BIOS). (Note the term ‘Basic' in this context has nothing to do with the BASIC language.) The CCP and BDOS are the machine independent parts of CP/M as supplied by Digital Reserach. The BIOS is the machine dependent part which deals with all the low-level device driving, in particular the disc driving. The BIOS resides in the expansion ROM in the DDI-1 interface. The CCP and BDOS reside on the first two tracks of a system format disc and are loaded into RAM by the BIOS when a ‘Warm boot' is performed. The BIOS ROM starts at #C000 and ends at #FFFF, that is it overlays the screen RAM. The ROM also contains AMSDOS and some parts of DR LOGO. The RAM from #AD33 to #BFFF is always reserved. It contains the firmware jumpblock and the firmware and BIOS data areas. The rest of store is for use by CP/M and Resident System extensions (RSXs). In the system as supplied there is no room for any RSXs, however, the utility MOVCPM.COM can be used to create a smaller CP/M system with space for RSXs as required. The BDOS communicates with the BIOS via the BIOS jumpblock. This is positioned immediately after the BDOS. The 16 bytes from #0040 to #004F are reserved for use by DR LOGO, they are not used by the BIOS. 2.2 Store Map This store map has CP/M positioned as high as possible.
The term ‘cold boot' means invoking CP/M for the first time after the machine has been switched on or reset. CP/M is invoked in one of two ways: either automatically when the machine is switched on, or by issuing the |CPM external command. The method used is determined by an option link on the disc interface board. This sets the address of the BIOS ROM to either 0 or 7. If the ROM address is set to 0 then the BIOS cold boot will be invoked automatically when the machine is switched on. If the ROM address is set to 7 then CP/M may be invoked by issuing the external command |CPM. The DDI-1 is supplied with the ROM number set to 7. See chapter 5.1 for details on how to change the ROM number. Once the BIOS cold boot is invoked the firmware is reset by calling MC START PROGRAM, thus any RAM allocated to background ROMs and RSXs will be lost and all ticker chains reset. The BIOS cold boot routine first initializes the BIOS into a ‘minimum' working state, loads a boot program from the single boot-sector on the disc into store, starting at #0100, and enters it. If all the bytes in the boot sector have the same value an error message is displayed. Otherwise it is assumed that the sector contains a valid boot program. The ‘minimum' working state in which the boot program runs is sufficient to run CP/M but does not do any of the following: display a sign-on message, initialize the serial interface, set any keyboard translations. The standard boot program loads the configuration sector from the disc and performs some further initialization. This ‘two stage' initialization is done so that, if required, the boot program could bring up a totally different operating system. See chapter 2.12. Once the BIOS is initialized a warm boot is performed to load the CCP and BDOS. The term ‘warm boot' means reloading CP/M after a transient program has run or after the user has typed Control-C in order to change a disc. A warm boot is invoked immediately after initialization and thereafter by a jump to location zero, or by calling the BDOS System Reset function. The primary function of the warm boot is to load the BDOS and CCP into memory and then to enter the CCP. The memory location used to start the load is calculated from the jump instruction at the start of the CCP. #035C is subtracted from the JMPs destination address giving the origin of the CCP. Since the position of the CCP is recalculated at every warm boot differing sized CP/Ms can be warm booted from each other. If all the bytes in the first sector of the CCP have the same value an error message is displayed. Otherwise it is assumed that the system tracks contain a valid CCP and BDOS. The warm boot routine initializes the jumps at #0000 and #0005 and also copies the BIOS jumpblock into RAM immediately after the BDOS (see chapter 2.2). 2.5 Resident System extensions Resident System extensions (RSXs) allow the user to keep programs, such as special character I/O drivers, permanently in memory. They must be loaded into memory below the BIOS variable area (which starts at location #AD33) but, above the end of the RAM copy of the BIOS's jumpblock. In the CP/M system as supplied there is no space for RSXs. If RSXs are required the user must reduce the size of the TPA by the amount of space required for all RSXs. Note that the M0VCPM. COM transient utility only allows the user to relocate CP/M onto 256 byte (page) boundaries. Let Srsx be the size of RSX required in pages (1 page = 256 bytes) then the RSX area will start at address # AD33 - (256 * Srsx) and end at # AD32. The BIOS does not initialize any background ROMs. AMSDOS must not be initialized under CP/M. Under version 1 of the firmware ROM the following restrictions apply: Any background ROMs required must be explicitly initialized by calling KL INIT BAK. Using KL ROM WALK would cause the disc expansion ROM to be re-initialized which would lock up the system. The memory pool for the ROM's dynamic variables must lie in the RSX area, that is between the end of the BIOS jumpblock and below the BIOS's variables. If the ROM address is set to 0 and BASIC is invoked AMSDOS will not be available. In order to insert an RSX into store it is necessary to move the CP/M system down store. The CP/M utility MOVCPM.COM will create an in-store image of a CP/M system of the required size. The utility SYSGEN.COM is then used to write this image onto disc, see section 4.11. The MOVCPM utility requires the size of CP/M system to be specified. Historically this size meant the total amount of RAM available to the original CP/M system with BIOS size of 1.5K. Nowadays it is merely a magic number to feed MOVCPM with! The MOV CPM utility supplied requires this size to be expressed in pages (1 page = 256 bytes). It is calculated as follows: Let Scpm be the ‘size of CP/M' in pages as required by the MOVCPM utility Then Scpm = 179 - Srsx. The BDOS will start at address Bstart = (Scpm - 20) * 256 The BDOS entry point will be at address Bentry = Bstart + 6 The TPA size = Bentry - #0100 To run MOVCPM type: MOVCPM nnn * where nnn is the size required and must be in the range 64.. 179. The CP/M system supplied has been created from: MOVCPM 179 * CP/M supports four logical character I/O devices called CONSOLE, READER, PUNCH and LIST. These four logical devices are mapped onto different physical devices. At any one time the current mapping of logical to physical devices is defined in a location called the IOBYTE. The STAT transient utility program can be used to change the IOBYTE. CONSOLE may be assigned to:
READER may be assigned to:
PUNCH may be assigned to:
LIST may be assigned to:
The Keyboard input device uses the firmware routine KM WAIT CHAR to read characters from the keyboard. The screen output device uses the firmware routine TXT OUTPUT to display text and process control characters. Refer to the firmware documentation for details of the control characters supported. The end of file input device always returns the end of file character #1A. The null output device discards all characters sent to it. The two special I/O devices are initially setup to drive channels A and B of a Z80 SIO. Each device has four driver routines which are all indirected via the extended jumpblock (see chapter 2.14). The user may patch these jumps in order to use an RSX device driver. In general the user may freely type-ahead on the keyboard, provided the BIOS is not accessing the discs. While accessing the discs interrupts are disabled and characters can be lost. Some characters are treated specially by the BIOS (see also chapter 2.14 on retries). When performing character I/O with the Centronics or serial interface ports the BIOS polls the keyboard for the following control characters (any other characters are lost). CONTROL-C To stop the system from locking-up the user may press Control-C to perform a warm boot under the following conditions:- a) Whilst waiting to output a character to the serial interface. b) Whilst waiting to input a character from the serial interface. c) Whilst waiting to send a character to the Centronics printer port. CONTROL-S To suspend CP/M when sending or receiving characters from the serial interface the user may press Control-S. Once suspended the user must press any key to continue operation of the BIOS. The control-S and the character typed are both lost. CONTROL-Z Whilst waiting to input a character from the serial interface, the user may press Control-Z. This will result in a Control-Z (eof) being passed back to the calling program. When CP/M is invoked, the keyboard input device reads characters from a special buffer called the Initial Command Buffer. The SETUP utility program allows the user to initialize the initial command buffer, specifying a number of commands to be automatically executed when CP/M is cold booted. The BIOS routine CONST does not reflect the status of the initial command buffer. Thus programs which poll for Control-C will not drain the initial command buffer. In particular the BIOS user interaction, chapter 2.8, will not fetch characters from the initial command buffer. All BIOS messages are sent to the screen via TXT OUTPUT. They are not indirected via the IOBYTE. BIOS messages are followed by the question Retry, Ignore or Cancel?. The system then discards any outstanding characters, turns on the cursor and waits for the user to type R, I or C, anything else will cause a bleep. Typing R for retry causes the BIOS to repeat the operation. Typing I for ignore causes the BIOS to continue as if the problem had not occured. Typing C for cancel causes the BIOS to abandon the operation. This will often result in a BDOS error message. After the user has typed R, I or C the cursor is turned off. The AMSTRAD BIOS messages are as follows:-Drive:disc missing Where < n > is the drive identifier, either A or B. This message is produced when the BIOS attempts to access a drive that does not have a disc inserted or a non-existent drive. Failed to Load boot sector This message is produced during a cold boot when the boot sector is not read correctly or if all the bytes in the boot sector have the same value. Failed to Load CP/M This message is produced during a warm boot when a sector of the CCP or BDOS is not read correctly or if all the bytes in the first CCP sector have the same value. Drive < n >: disc is write protected Where < n > is the drive identifier, either A or B. This message is produced when the BIOS attempts to write to a disc that is write-protected. If the user wishes to write on this disc then the user should remove the disc, write enable it, re-insert it into the drive and then type R for retry. Drive < n >: read faiL Where < n > is the drive identifier, either A or B. This message is produced when a hardware error has been reported whilst reading from the disc. It may also be caused by trying to read from a disc with the wrong format, for example: trying to warm boot from a DATA ONLY format disc. Drive < n >: write faiL Where < n > is the drive identifier, either A or B. This message is produced when a hardware error has been reported whilst writing to the disc. In the event of a read or write fail the user is recommended to remove and re-insert the disc then type ‘R'. This may help in case the disc was badly positioned or may shift any fluff or what-not adhering to the head. If this does not clear the problem then the data will have to be recovered in some other way. It is strongly recommended that the user takes regular back-up copies of discs. The BIOS supports three different disc formats: SYSTEM format, DATA ONLY format and IBM format. The BIOS automatically detects the format of a disc. Under CP/M this occurs for drive A at a warm boot and for drive B the first time it is accessed. Under AMSDOS this occurs each time a disc with no open files is accessed. To permit this automatic detection each format has unique sector numbers. 3 inch discs are double sided, but only one side may be accessed at a time depending on which way round the user inserts the disc. There may be different formats on the two sides. Common To All Formats
System Format
The system format is the main format supported, since CP/M can only be loaded (cold and warm boot) from a system format disc. The reserved tracks are used as follows:
Note: ‘VENDOR' format is a special version of system format which does not contain any software on the two reserved tracks. It is intended for use in software distribution. Data Only Format
This format is intended for future enhancement, it is not recommended for use with CP/M since it is not possible to ‘warm boot' from it. However, if only AMSDOS is to be used then there is a little more disc space available. IBM Format
This format is logically the same as the single-sided format used by CP/M on the IBM PC. It is intended for specialist use and is not otherwise recommended as it is not possible to ‘warm boot' from it. In order that non-CP/M systems may be implemented at a later date the BIOS initialization is performed, in part, by a boot program which is read from the disc before attempting to load CP/M. In the non-CP/M case the boot program would not jump to the warm boot routine but go its own way, using the BIOS and firmware routines as desired. The boot sector is sector #41 on track 0. During a cold boot the BIOS is initialized into a minimum state, i.e:
The CP/M jumps at #0000 and #0005 are not initialized. The boot sector is read and loaded into store at #0100; the stack pointer is initialized to # AD33, a value immediately below the BIOS's data area and the boot program is enteredat #0100. The boot program mayuse store from #0100 to #AD32 inclusive. To run CP/M the boot program must, at least, jump to the warm boot entry in the ROM jumpblock. The boot program has the following interface: Entry:
Exit:
The ROM copy of the BIOS jumpblock should not be used at any other time (indeed, only the boot program knows where it is). The Boot program supplied loads the configuration sector from disc. This contains various system parameters which are used to initialize the BIOS. These parameters may be changed by using the utility SETUP.COM (see chapter 4.10). The configuration sector is sector #42 on track 0. Format: byte 0 = #35, byte 1 = #12 Disc signature.
bytes 2..3 Drive motor on delay
bytes 4..5 Drive motor off delay
byte 6 Step rate.
byte 7 IOBYTE.
byte 8 BIOS disc message enable/disable.
byte 9 Saving alternate and IY register enable/disable.
Bytes 10..21 are used to initialize the serial interface, if fitted.
byte 22 Keep command buffer.
bytes 23..99 reserved.
The following fields are all of variable length and live in bytes 100.... Sign-on string.
Printer power-up string.
Keyboard NORMAL translations.
Table format: byte0 number ofentries, 0..255. Entry format: byte 0 key code, Keyboard SHIFT translations. This table redefines the codes produced by keys with SHIFT pressed. Each entry in the table is two bytes long. The first byte is the key code, the second the key number that will produce that code. See Appendix I for the key numbering. Table format: byte0 number ofentries, 0..255. Entry format: byte 0 key code, Keyboard CONTROL translations. This table redefines the codes produced by keys with CONTROL pressed. Each entry in the table is two bytes long. The first byte is the key code, the second the key number that will produce that code. See Appendix I for the key numbering. Table format: byte0 number of entries, 0..255. Entry format: byte 0 key code, Keyboard expansions. This table defines the keyboard expansion strings (see section 3.7). Table format: byte0 number ofentries, 0..255. Entry format: byte 0 expansion token, The remainder of the configuration sector is set to #00. The AMSTRAD BIOS has two jumpblocks: the standard CP/M jumpblock and an extended jumpblock. The extended jumpblock starts at #BE80 and contains jumps for additional facilities such as physical sector reading and writing. When CP/M is warm-booted the standard BIOS jumpblock is copied into RAM immediately after the BDOS. The address of the warm boot entry in the RAM jumpblock is held in the word at #0001. The entry and exit conditions of the standard BIOS jumpblock are a superset of those defined in the CP/M alteration guide as listed below. All routines in the standard BIOS jumpblock optionally preserve the Z80 alternate and IY registers as specified by the SET REG SAVE routine. READ WRITE These two routines return some hardware error status in the accumulator when a read or write has failed. The definitions of the status bits are listed below.
In addition to the above status byte, the HL register pair contains the address of a buffer of all the bytes received during the results phase of the /J.PD765A disc controller, the first byte is a count of the number of bytes that follow. (See manufacturer's documentation.) SELDSK If bit 0 of E = 0, indicating that this is the first time that the disc is being accessed, then the BIOS will attempt to determine the format of the disc by reading an ID header from the current track. If successful then the relevant extended DPB is altered to correspond to the detected format. The extended jumpblock starts at #BE80 and has the following format:
The following 8 routines are the indirection jumps for the special character I/O devices. The BIOS uses these jumps to access the devices. Thus the user may patch these jumps to an RSX driver if required. They all default to the serial interface driver. Device 0 is channel A of the serial interface, device 1 is channel B.
The action performed by each entry in the extended jumpblock is detailed below, along with the entry and exit conditions of each. These routines will, in turn, call firmware routines so they must themselves be treated like firmware routines, see chapter 2.17.
|