ZX BASIC:Library

From BorielWiki
Jump to: navigation, search

Contents

Library of Routines and Functions

This is a list of additions to the language that have been produced. They extend the functionality of the compiler by effectively adding reserved words to the language. At their heart, they are all SUB or FUNCTION sets.

How to Include a Library Function

You can either copy and paste the SUB or FUNCTION into your code, or, perhaps more easily, save the text as the recommended name (e.g. fSqrt.bas) and use #include "fSqrt.bas" at the start of the program. Note that the file has to be in the same folder or directory as the original in order for the compiler to find it. If the code is included in the ZX Basic standard library, this is mentioned in the decription. It's then possible to add the code simply with a #INCLUDE instruction.

Maths Library

Fast distance calculation - SQR(x^2 + y^2) - using taylor series expansion. Accuracy tends to drop as x and y get large, but is about 5 times faster even than using iSqrt (and about 750 times faster than using the ROM sqr function).
Sin giving you a headache? At the cost of a few bytes, here are faster and less accurate versions for quick and dirty games calculations.
SQR too slow? Here's a faster (and completely accurate - at least as accurate as Sinclair Basic) replacement for the internal SQR function.
fSqrt.bas Still too slow? Don't need quite so accurate an answer? Try Integer Square roots!
A random stream generator. Fast and efficient. ZX Basic does use this generator, but it's locked to float output. Here are some alternative functions using faster integer and fixed output.

Graphics Library

Function to get the attribute address for a given X-Y character co-ordinate.
Sub to clear a subset of the screen - a window defined with a character box.
Function to get the current cursor vertical co-ordinate.
Routine to plot a pixel on screen (without attributes - speed optimized)
High Resolution Print: Subroutine to print characters at any pixel level position on the screen, instead of just character positions. (Rather slow for sprites, but fine if speed isn't needed)
High Resolution Print: Subroutine to print characters at any pixel level position on the screen, instead of just character positions. (20% faster per character, but much larger version using lookup tables)
Function to mirror the bits in a byte - the basis of printing, say a left facing sprite, if all you have are right facing graphics stored.
Function to get the current cursor horizontal co-ordinate.
Set attributes in a rectangle without changing the bitmap.
Subroutines to put graphics data to the screen in a block. Also contains routines for attribute painting as a block. Passable for character based sprites.
Function to get the top screen address for a given X-Y character co-ordinate.
Subroutine to paint a 2X2 character tile to the screen from a given data address, with attributes. Uses PUSH/POP to the screen memory for speed.
Subroutines to scroll the screen by a specified number of pixel rows. (No attribute scroll)
Subroutine to character scroll a window of screen - good for that sidebar of information. Keep status updates scrolling in and sliding up without affecting the game window.
Subroutine to character scroll the attributes of a window of screen - really a handy addendum utility for windowScrollUP.bas

Text Handling Library

Ascii Code of a character in a string. Compatible with FreeBasic
Prints to the screen with Double Size Characters
High Resolution Print: Subroutine to print characters at any pixel level position on the screen, instead of just character positions. (Rather slow for sprites, but fine if speed isn't needed)
Need characters to look more professional? LCD has weighed in with a Proportional Printing routine - and one that lets you set text position with Pixel accuracy!
Need more screen space? You could try the 42 Character Printing routine. Text still lines up in columns, and attributes are allowed (with limitations).
Need even MORE screen space? Here's a 64 characters per line Subroutine. Works in a very similar way to print42, with printat64 and print64 subs.
What, just 64 chars to a line not enough? This is 64X32 Character printing. Will print 64 characters to a line (grid, not proportional), and 32 lines of text to a screen. Upping the standard 768 character screen to 2048 characters of text on one screen at once. Works in a similar way to print42. This version uses screen tables.

Compression / Decompression Library

Routine wrapping the megaLZ decompression algorithm.
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox
Translate
Google AdSense