Hacker's Edge Game Guide: Programming/Hacker's Edge BIOS v1.2

Hacker's Edge BIOS v1.2
Jan. 27, 2019

HE Bios v1.1 - v1.2

The Boot Process

First it disables interupts and set the SP to $ff and clears the SR.
Then it gets the CPU type and the avaiable non ROM memory.
After this it looks for hardware installed on the computer like blockdevices.

Then it looks to all avaiable blockdevices and try to load a master boot record at block zero 
that contains code at start adress $0200. A master boot record has to start with a valid byte <> $00 (BRK).
If one is found it loads it and jumps to them otherwise it trys to load a HeOS, the code here has to start at $0800.
Now the bios is done.
The BIOS do not enable interupts or reset the SP or SR after it is done.
Also it does not initialising any vectors or memory.

Thats all.

Other Informations about the BIOS

The bios saves its data to the ZP address for later use or to 
make a backup copy to other memory adresses.

This ZP adresses are this:
$ff      1 byte : the blockdevice with the MBR on it  
$fb-$fe  4 bytes: the free memory in hex format
$f7-$fa  4 bytes: the extended memory in hex format (not in use yet)
$f6      1 byte : the CPU type
               0: 65xx   (including 6502, 6509, 6510, 7501, 850x and 65DTV02 etc.) 
               1: 65CE02 (or 4510 in the C65 and MEGA65) 
               2: 65C02  (or 65C102 in the LCD) 
               3: 65816  (on SuperCPU and other accelerator cards)
$f2-$f5  4 bytes: the CPU speed in Hz in hex format (not in use yet)
$f0-$f1  2 bytes: a bitset that represents the installed devices
                  if bit is set the device is present else it is not 
             $f0: bit 0: BLKDEV0
                  bit 1: BLKDEV1
                  bit 2: BLKDEV2
                  bit 3: BLKDEV3
                  bit 4: BLKDEV4
                  bit 5: unused
                  bit 6: CFFA1 card
                  bit 7: unused
             $f1: not in use yet

The BIOS uses some other ZP addresses for 
temporary use in the internal routines.
This are the following ones.
The ZP adresses are this.
$02-$09     1 bytes each: this are temproarly variables called VAR0-7 
$0a-$0c     1 bytes each: here the BIOS saves the register temporarly
$10-$17     2 bytes each: used as adresses called ADDR0-3
$1a-$1d     2 bytes each: used as pointers called POINTER0-3
$20-$2d     4 bytes each: 32bit accumulators for calculations called IACC0-3 
$030       10 bytes	: the dezimal representation of an 32bit value called BCDBUF 

The BIOS has also usefull routines you can use.
All this routiness are called by an JSR.

This routines are this:
V1.1    V1.2
$f800   *       	bios_start       usefull for a warmstart it clears nothing but the SP and SR
                         		 also it disables interupts
$f803   *	   	get_cpu_type     gets the CPU type A and $f6 holds result 
$f81f   *	   	get_main_mem     mesures the main memory result is in $fb-$fe
$f857   $f848   	get_block_dev    get the avaiable blockdevices result bits 0-4 in $f0
$f893   $f875   	CFFA1Present     get the pressence of an CFFA1 card result is the bit 6 in $f0
$f8a7   $f889   	Imprint          print a ZSTRING followed immedate by the caller.
                         		 example: JSR $f8a7 ;for v1.1
                                  		  DCS a wonderfull text\0
                         			  WARNING: do not call this absolut indirect if your prozessor can this!
$f8c7   $f8a9   	get_key          get a key, result is in A and $07
$f8e1   $f8b7   	cout             prints an charater stored in A to the terminal
$f8e5   $f8cd   	set_cursor_xy    sets the cursor to position X and Y stored in register X and Y if CARRY is not set
                         		 else it get the values from $08 for x and $09 for y.
$f8f2   $f8e0   	get_cursor_xy    gets the x and y position of the cursor and save it to $08 and $09
$f8fd   $f8eb   	clrscr           clears the screen 
$f90b   $f8f6   	save_regs        saves the A,X,Y register to $0a-$0c
$f912   $f8fd   	load_regs        load the registers A,X,Y with values from $0a-$0c
$f94e   $f933   	print_zstr       prints an ZSTRING, address of the string has stored in $18-$19
$f964   $f949   	print_dez        converts and prints a value store at $20-$23 to a dezimal number is stored at $30-$39
$f97a   $f95f   	print_hex        prints A as 2byte hex number. if CARRY is set it skips the highnibble
$f996   $f97b   	bin2bcd          converts a number stored in $20-$23 result is in $30-$39
$f9a3   $f988   	div10            divides the number sored at $20-$23 by ten the remainder is in A
$f9bb   $f99a   	copy_zp2zp_bw    copys values from ZP address in A to ZP address in X backwards. Lenght is given by Y.
                         		 example: lda #$f0 ;copy 4 bytes from $f0 to $a0
                                  		  ldx #$a0
                                  		  ldy #$04
                                  		  jsr $f9bb ;for v1.1
                         			  NOTE: choose the locations wisely otherwise the copy overwrites
                               			        the values at the source addresses.
* means the same address as v1.1

and here ends the jorney in the BIOS.

Thanks for reading.