-*- Text -*-
   This is the file .../info/BIOS.nfo, which contains info
about the services provided by the BIOS. It is intended for use by the
MOOSE developpers not to look into books each time they need this information.
It does not try to incorporate all the info about the BIOS, only that needed
by MOOSE.

    Info taken from:
- The PC system programming BIBLE (Third Edition) by Michael Tischer, 1993
- Advanced MS-DOS (for version 3.2) by Ray Duncan, 1986
- Turbo C's online help by Borland.

File: BIOS.nfo		Node: Top	Up:(MOOSE.nfo)

   This file describes the functions provided by the BIOS, the standard PC
compatible ROM based software. It is far from complete, as I fill it only
when I need some information.

* Menu:

About the BIOS:
* Intro::			What is the BIOS ?
* Int 05h::		n	Print Screen !
* Int 10h::		u	Video services.
* Int 11h::		n	Read Configuration.
* Int 12h::			Get memory size.
* Int 13h::		u	Disk I/O services.
* Int 14h::		n	Serial line services.
* Int 15h::		n	Extended BIOS services (and old Tape services).
* Int 16h::		n	Keyboard services.
* Int 17h::		n	Parallel line services.
* Int 18h::		n	Go into ROM BASIC ! (no return)
* Int 19h::		n	Reboot computer !
* Int 1Ah::		n	Timing functions.

Appendice:
* Boot sequence::	n	What the BIOS does when it boots.
* BIOS Internals::	n	A description of BIOS functions.

Notes:
u means uncompletely documented here.
n means not documented here (yet).

* Ray Duncan says that registers not part of the result are NOT modified.
* Michael Tischer says only BX,CX,DX,BP,SP,CS,DS are saved and restored by
 the BIOS functions, unless stated otherwise. Other registers may have been
 spoilt (notably SI and DI in real mode) or not (the behaviour with respect
 to 32-bit extended registers is not specified), unless stated otherwise.

Node: Int 10h, Up: Top

   Int 10h is the hook for Video services.

* Int 10h Error Codes::		The meaning of error codes returned by Int 10h
* Int 10h Function 00h::	Set Video Mode
* Int 10h Function 01h::	Set Cursor Appearance
* Int 10h Function 02h::	Set Cursor Position
* Int 10h Function 03h::	Get Cursor Position
* Int 10h Function 04h::	Get Optical Pen position
* Int 10h Function 05h::	Select current screen page
* Int 10h Function 06h::	Scroll text screen upward
* Int 10h Function 07h::	Scroll text screen downward
* Int 10h Function 08h::	Read character and attribute
* Int 10h Function 09h::	Write character and attribute
* Int 10h Function 0Ah::	Write character only
* Int 10h Function 0Bh::	Select background colors or set palette
* Int 10h Function 0Ch::	Put Pixel in graphic mode
* Int 10h Function 0Dh::	Get Pixel in graphic mode
* Int 10h Function 0Eh::	Output a character to console
* Int 10h Function 0Fh::	Read Video Mode
* Int 10h Function 10h::	Control EGA palette registers
* Int 10h Function 13h::	Output a string to console
 more on EGA/VGA BIOSes.

Node: Int 10h Function 00h, Up: Int 10h

   Set video mode and clear screen.

* AH=0
* AL=mode

	Mode	T/G	Resolution	Colors	Card
	00h	T	40x25		2	CGA
	01h	T	40x25		16	CGA
	02h	T	80x25		2	CGA
	03h	T	80x25		16	CGA
	04h	G	320x200		4	CGA
	05h	G	320x200		4	CGA (grey levels)
	06h	G	620x200		2	CGA (grey levels)
	07h		Internal mode		MDA
	08h	G	160x200		16	PC Junior
	09h	G	320x200		16	PC Junior
	0Ah	G	640x200		4	PC Junior
	0Dh	G	320x200		16	EGA
	0Eh	G	640x200		16	EGA
	0Fh	G	640x350		2	EGA
	10h	G	640x350		16	EGA
	11h	G	640x480		2	MCGA
	12h	G	640x480		16	VGA
	12h	G	640x480		256	8514
	13h	G	320x200		256	MCGA

* for the palette in mode 4,5,6, see function 11

Node: Int 10h Function 01h, Up: Int 10h

   Set cursor appearance

   AH contains 01h
   CH contains the cursor starting line (lower value)
   CL contains the cursor ending line (higher value)

* Varies from 0 to number of lines - 1. MDA and EGA have 14 lines/char,
 CGA has 8, VGA has 16.
* Default is (11,12) for MDA, (6,7) for CGA.
* Unauthorized value may make the cursor disappear.

Node: Int 10h Function 02h, Up: Int 10h

   Set cursor position

   AH contains 02h
   BH contains the screen page number
   DH contains the line
   DL contains the column

* Lines and columns begin at zero.
* Each page has its own cursor; you may change the cursor of an inactive page.
* To have the cursor disappear, put it out of the screen (for example, line 25
 in a 25 line mode)

Node: Int 10h Function 0Eh, Up: Int 10h

   Output a character to console.

   AH contains 0Eh
   AL contains ASCII code of character to output.
   BL contains forecolor of character iff in graphics mode.

* Modifies the character at current cursor position.
* Leaves unchanged the character attribute.
* Cursor position is incremented afterwards.
* Control characters like TAB,CR,LF,BELL have special meaning.
* If bit 7 of AL is set, it is removed on the character attributes are
 inverted.
* If the end of the screen is reached, the screen scrolls up.
* SI (and DI ?) are preserved.

Node: Int 10h Function 13h, Up: Int 10h

   Output a string to console.

   AH contains 13h
   AL contains the output mode.
   BL contains the attribute byte iff output modes 0 or 1.
   CX contains the number of characters to output.
   DH contains the screen line
   DL contains the screen column
   BH contains the screen page
   ES:BP points to the buffer containing the characters to output.

Notes:
* Modes 1 and 3 mean that cursor position is finally set just after the last
 character echoed.
* Modes 0 and 1 mean that the buffer contains only characters to send; the
 attribute of the characters is set according to BL.
* Modes 2 and 3 mean that each character is followed by its attribute. CX
 always contains the number of characters (and not the string length).
* Special characters like BELL, CR are interpreted as such.
* If the last character of the screen is reached, the screen will scroll up

Node: Int 12h, Up: Top

   Modifies only AX.
   Returns in AX the size in KB of "conventional" memory (from 0 to 640).

 Notes:
   (see * Int 15h Function 88h:: for getting the size of "extended" memory).

Node: Int 13h, Up: Top

   Int 13h is the hook for Disk I/O services.

* Int 13h Arguments::		How Int 13h functions get their arguments.
* Int 13h Error Codes::		The meaning of error codes returned by Int 13h
* Disk Drive Parameter Table::	BIOS Parameter structure for advanced functions
* Int 13h Function 00h::	Reset disk controller
* Int 13h Function 01h::	Get disk controller status (last error code).
* Int 13h Function 02h::	Read Sectors
* Int 13h Function 03h::	Write Sectors
* Int 13h Function 04h::	Verify Sectors
* Int 13h Function 05h::	Format a Track
* Int 13h Function 06h::	(06h and 07h were used on XT's to low-level)
* Int 13h Function 07h::	(format the computer's HD)
* Int 13h Function 08h::	Get the Disk Format
* Int 13h Function 09h::	Adapt strange disks to BIOS use.
* Int 13h Function 0Ah::	Extended Read Sectors (AT)
* Int 13h Function 0Bh::	Extended Write Sectors (AT)
* Int 13h Function 0Ch::	Move HD heads (AT)
* Int 13h Function 0Dh::	Reset hard disks (same as Function 00h)
* Int 13h Function 0Eh::	Controller Read Test (PS/2)
* Int 13h Function 0Fh::	Controller Write Test (PS/2)
* Int 13h Function 10h::	Is Drive Ready ? (AT)
* Int 13h Function 11h::	Recalibrate HD (AT)
* Int 13h Function 12h::	Controller RAM Test (PS/2)
* Int 13h Function 13h::	Mechanical Drive Test (PS/2)
* Int 13h Function 15h::	Get Disk Drive Type (AT)
* Int 13h Function 16h::	Detect Floppy change (AT)
* Int 13h Function 17h::	Set Floppy Format (AT)
* Int 13h Function 18h::	Set Floppy Format (AT, Replaces function 17h)
* Int 13h Function 19h::	Park HD heads.

By default, ES, SI, DI are preserved by Int 13h

Node: Int 13h Arguments, Up: Int 13h

   How arguments are given to Int 13h. Of course, you need give the argument
only if the function uses it (for example, you don't need specify a sector to
reset the controller).

Contents of the registers:
-------------------------
	AH	contains the function number, as always
	AL	contains the number of sector to R/W if needed
	DL	is the number identifying the disk.
	DH	is the number of the head.
	CL	is the sector number (2).
	CH	is the track/cylinder number (2).
	ES:BX	contains the address of a buffer if required.

On failure, CF is set, and AH contains an error code.
Unless specified, BX, CX, DX, BP, CS, DS, ES, SS are saved, while other
  registers may have been destroyed.

Note that:
 (1) Sectors are numbered from 1 to the number of sectors per track, while
   heads and cylinders are numbered from 0 to the number of heads or cylinders
   (respectively) minus one. On floppies, head 1 is the upper side of the
   floppy (the one with the labels on); but this is of little importance,
   except if you write single sided (presumably 5"1/4) floppies.
 (2) For hard disks, the number of cylinders may exceed 256, so bits 6 and 7
   of CL are used as the high-order part of the cylinder number (now up to
   1023), and not as the number of sectors.
 (3) DL is 0 for floppy A, 1 for floppy B; 2 or 3 for additional floppies on
   a possible second controller. It is similarly 80h to 83h for hard disks.

Node: Int 13h Error Codes, Up: Int 13h

		01h: bad function
		02h: address mark not found
		03h: tried to write on write-protected floppy (FD)
		04h: sector not found
		05h: error resetting controller (HD)
		08h: DMA overflow
		09h: DMA data transfered above segment limit
		0Ah: bad sector
		10h: read error (CRC failed)
		11h: read error (corrected by ECC) (HD)
		20h: disk controller error
		40h: track not found
		80h: Time out error; drive does not respond.
		AAh: Drive not ready (HD)
		CCh: Write Error (HD)

Node: Disk Drive Parameter Table, Up: Int 13h

   A BIOS Parameter structure for disk access.

byte	meaning
00h	Progression speed & Head-Unload-Time (1)
01h	Head-Load-Time (2)
02h	Time before the motor stops after a diskette access
03h	Sector size
04h	sectors per track
05h	GAP3 size while reading/writing
06h	data transfer duration
07h	GAP3 size while formating
08h	ASCII code for formatting
09h	Rest time
0Ah	motor acceleration time

* Byte 00h contains two nybbles
 - bits 4-7 is the progression speed: it measures the maximal time before next
  track is reached. 0Fh is 1ms, 0Eh is 2ms, 0Dh is 3 ms, etc.
 - bits 0-3 is the time the head needs to unload from the disk's surface. It
  is expressed in units of 16 ms. The default is 0Fh (240 ms), which leaves a
  good safety margin, so we can generally reduce it.
* Byte 01h is divided into two zones:
 - bits 1-7 contain the time for the read/write head to position down to the
  diskette surface. It is expressed in units of 2 ms. Generally, will be 1 or
  2.
 - bit 0 is a flag to know if we'll use DMA access. Let it to 0 (no, 'cause
  4.77MHz DMA is so slow :-( ).
* Byte 3 is expressed in 18.2 Hz (55ms) clock ticks. In general, 3 for common
  512 byte sectors
* Byte 4 tells max. number of sectors per track, which depends on the floppy
  format.
* Bytes 5-7 decide the physical size of sectors and gaps between sectors
  [no more info in the BIBLE]
* Byte 8 is the character that'll be written on formatted sectors.
  (default: 0F6h, 246, divide sign in the OEM charset).
* Byte 9 is the time to wait for vibrations due to the intertrack head
  displacement to fade out before the head can access the disk again. Expressed
  in units of 1 ms. Default is 25.
* Byte 10 is the time before the motor reaches its cruise speed for disk
  accesses. the unit is 1/8 s, BIOS default is 1/4, DOS default is 1/2.

Node: Int 13h Function 00h, Up: Int 13h

   Reset the floppy disk controller.
   Reads: AH,DL only.

Notes:
 * DL contains the disk to reset. Actually, the two floppies or two harddisk
  connected to the same controller would be reset.
 * The BIBLE says you need do call this function each time an error was
  returned by an Int 13h function.

Node: Int 13h Function 01h, Up: Int 13h

   Read the disk status.
   Reads: AH,DL only.

Notes:
 * Returns the error status of the disk in CF (1=error), and on error, the code
  in AH, as usual.

Node: Int 13h Function 02h, Up: Int 13h

   Read sectors from disk to memory.

Notes:
 * AL must be such that only sectors on the same track are read if used on a
  Floppy disk.
 * Ray Duncan says that on success AL contains the number of bytes sent (?).
 AL: only same track/head.

Node: Int 13h Function 03h, Up: Int 13h
 
  Write sectors from memory to disk.

Notes: (same as function 02h).
 * AL must be such that only sectors on the same track are read if used on a
  Floppy disk.
 * Ray Duncan says that on success AL contains the number of bytes sent (?).

Node: Int 13h Function 04h, Up: Int 13h
 
  Verify sectors.

Notes: 
* AL must be such that only sectors on the same track are read if used on a
  Floppy disk.
* Floppy: compares buffer to sector.
* HD: only checks CRC.

* Extended read (A):
 HD: same as read, but up to 127 sectors on multiple tracks.
* Extended write (B):
 HD: same as read, but up to 127 sectors on multiple tracks.

Node: Int 15h, Up: Top

   Int 15h is the BIOS hook for functions added to the BIOS, including
functions involving Protected mode. It used to be a hook for a cassette
recorder driver on old IBM PC's, not anymore supported by today's
cassette-less computers' BIOSes.

* Old Tape Functions::			Put it here if you want.
* Int 15h Function 83h::		Set flag after given delay.
* Int 15h Function 84h::		Test joystick buttons/Position.
* Int 15h Function 85h::		Hook for SysReq hot key
* Int 15h Function 86h::		Sleep
* Int 15h Function 87h::		Transfer Memory accross the 1MB barrier
* Int 15h Function 88h::		Get Size of Extended Memory.
* Int 15h Function 89h::		Go to Protected Mode !

Node: Int 15h Function 88h, Up: Int 15h

   Return in AX the size of available memory above 1MB in kilobytes.
   The size below the 1MB barrier is given by Int 12h.

   To get some memory and let the remaining for use by other DOS/BIOS based
programs, use memory in the top of reported memory, then hook this function so
that it answers the amount of memory you leave.

Node: Int 16h, Up: Top

   Int 16h is the BIOS hook for Keyboard I/O services.

* Int 16h Function 00h::		Read a character
* Int 16h Function 01h::		Character present ?
* Int 16h Function 02h::		Test kbd state
* Int 16h Function 03h::		Define repeat rate

Node: Int 16h Function 00h, Up: Int 16h

  Wait for a character and read it.

  AL=0, AH=non zero extended code,
  or AL=ASCII, AH=scn code (see Annexe J, 7.11)
  BX spoiled (?)

Node: Int 16h Function 01h, Up: Int 16h

  Is character present ? If yes, read it.

  ZF=1 if none, ZF=0 and as in fun 0 else if present
  AX,BX spoiled.

Node: Int 16h Function 02h, Up: Int 16h

  Test Keyboard state.

  BX&same saved. AL=state
       bit
	7	Insert
	6	Caps Lock
	5	Num Lock
	4	Scroll Lock
	3	Alt
	2	Ctrl
	1	Left Shift
	0	Right Shift

Node: Int 16h Function 03h, Up: Int 16h

  Define keyboard repeat rate

???
  AX=0305h
  BH= ralentisst avant mise en place.
  BL=Repeat Rate
  BL= 00h:1/4 s 01h:1/2 s 10h:3/4 s 11h:1 s
  same as 02h saved.          ?

	Code	RPS
	1F	2.0
	1E	2.1
	1D	2.3
	1C	2.5
	1B	2.7
	1A	3.0
	19	3.3
	18	3.7
	17	4.0
	16	4.3
	15	4.6
	14	5.0
	13	5.5
	12	6.0
	11	6.7
	10	7.5
	0F	8.0
	0E	8.6
	0D	9.2
	0C	10.0
	0B	10.9
	0A	12.0
	09	13.3
	08	15.0
