ZLib v1.6 by Joe Wingbermuehle 19981208

>Description
This is a library file used by many SOS programs. It contains some of the
most commonly used routines.

>Usage
If you have a program that requires ZLib, simply send ZLIB to your
calculator and the program will work (or your ZLib version will be updated
if you have an older version).
Note: You MUST have SOS to run SOS programs (SOS is the only shell that
supports external libraries at the time this was written). Libraries MUST
be loaded after all programs that use it! Install rewrites libraries
allowing them to be loaded in any order and still work. SO USE INSTALL!!!

>ZLib History:
Version 1.0 <> ?
	-First release, routines 0-D used.
Version 1.1 <> 19980518
	-Bug fixed in routine 7 (delete program and terminate).
Version 1.2 <> 19980522
	-I updated routine 7 to work with SOS v1.2.
Version 1.3 <> 19980602
	-I updated routine 7 to work with *ANY* version of SOS!
	-I made routines 1 & 2 smaller/faster.
	-I removed routines 5, 8, 9, and A (I doubt they are or
	 ever would be used).
	-I added routine F (version)
	-I all things considered, ZLib v1.3 is 27 bytes smaller than v1.2.
Version 1.4 <> 19980609
	Size: 415 bytes
	-I finally discovered/fixed the bug in the getPixel routine.
	-I wrote a new random number generator, this one generates numbers
	 that are much more random in appearance.
	-I optimized a few other routines; shouldn't have too much effect on their
	 operation, this just makes ZLib smaller :)
	-I fixed the high score bug where if you tied the high score, you got the
	 high score.
Version 1.5 <> 19981022
	Size: 300 bytes
	-I optimized the routines. This should have no effect on their function.
	-I removed routines 7 (delete) and B (invert). If you have a program that uses
	 these routines, the program will not crash, but your program will not delete
	 itself or invert the screen.
Version 1.6 <> 19981208
	Size: 308 bytes
	-I fixed the decompress routine.

-----> ZLib Technical Information <-----

>If you would like to have your own library, talk to me. I don't want a
flood of libs! I will be glad to group all similar libs (that would be
most likely used together) in files so that libs don't become a nuisance.
>Each library can contain up to 16 routines. If two versions of a
library exist and one doesn't contain as many routines as the other,
the library will simply return to the program it was called from if
a nonexistant routine is called! Use the version routine if needed!

>This is the first library file created for SOS.
It contains the following procedures:
	-beep (lib0)
	-putSprite (lib1)
	-rand (lib2)
	-getBit (lib3)
	-detect (lib4)
	-unused (lib5)
	-decomp (lib6)
	-unused (lib7-libB)
	-getPixel (libC)
	-hiScore (libD)
	-unused (libE)
	-version (libF)

>Descriptions of the procedures:
* Beep (lib0)
Makes a very short tone through the IO port.
It is meant to make sounds for during game play.
Input:	b=duration
	c=tone (experiment to find the best values)
Output:	sound is produced
	b=0
Registers destroyed: af b e

* Sprite (lib 1)
Displays a 1 to 8 pixel wide, 1 to 64 pixel high sprite (xor).
Input:	b=height of sprite
	l=y coordinate
	a=x coordinate
	ix->sprite
Output:	sprite is printed to the graph buffer
	ix->first byte after the sprite
	b=0
	de=$000B
	hl->next line of the graph buffer
Registers destroyed: af bc de hl ix

* Rand (lib 2)
Generates an 8-bit random number.
Input:	b=upper bound
Output:	a=random number between 0 and b-1.
	b=0
Registers destroyed: af b

* Getbit (lib 3)
Gets the bit for plotting a pixel etc.
Input:	a=coordinate (x if plotting)
	hl=start location
Output:	a=holds bit (e.g. %00001000)
	hl=location to be plotted (hl+a\8)
	b=0
	c=a\8
Registers destroyed: af bc hl
This routine is used to be a fast alternative to getpixel for those times
when you have a y coordinate that never changes. I'm sure you can come up
with some other uses too if you're clever with it.
Example:
	; plot a pixel on line 7 but at a x coordinate (reg a) unknown
	ld	hl,gbuf+(12*7)	; graph buffer is 12 bytes wide so mult 12
	call	vector0		; whatever getbit is assigned
	or	(hl)		; combine byte with bit
	ld	(hl),a		; plot it
	;<----- End of example

* Detect (lib 4)
Detect a program (var type 6) on the symbol table.
Input:	hl=place to begin looking ( (vat) if first time etc)
	ix->String to check for in a program (0 terminated)
Output:	de=place stopped
	hl->program data (after the string)
	z=0 if found, z=1 if not found
	b=0
Registers destroyed: af bc de hl

* Decomp (lib 6)
Decompress data (Joe's compression scheme)
Input:	hl->compressed data
	de->place to load data after decompression
	b=length of compressed data
	c=compression factor {1, 3, or 15 - 1=8x compression etc}
Output:	Data is decompressed and stored at de
	hl->next byte of compressed data.
	de->de+(b*{8,4,2})
	b=0
Registers destroyed: af bc de hl
See one of my programs if you would like to figure out how to
compress your levels.

* Getpix (lib C)
Get byte/bit for a pixel
Input:	e=y coordinate
	a=x coordinate
Output:	a holds bit of pixel
	hl->byte of pixel on the graph buffer
	(notice the output is the same as for getbit)
Registers destroyed: af bc de hl
Example:
	; if I wanted to plot a pixel at (10,15), I would:
	ld	a,10
	ld	e,15
	call	vector0 	; whatever getpix is assigned
	or	(hl)	; combine existing byte with bit data, use xor to change
	ld	(hl),a	; write the new byte
	;<----- End of example

* Hiscr (lib D)
Test/Sets the high score
Input:	de=previous high score
	hl=current score
Output:	hl=high score
	z=1 (a=0) if new high score, z=0 (a=1) if not
Registers destroyed: af de hl

* Version (lib F)
Gets the version of ZLib that is loaded.
Input:	hl=(any value, preferably $0000)
Output:	h=major, l=minor (e.g. version 1.6 would return: h=1, l=6)
Note: Since ZLib v1.3 was the first version to support this routine, I recommend
setting hl to zero on entry so that you can tell in your program for sure what
version of ZLib is loaded. This is a very useful routine, so I would recommend
all libraries have this routine included as lib F (or as the first routine would
be more desirable actually--too late now!).
Registers destroyed: hl

