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

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!

Graphics Library

Function to get the attribute address for a given X-Y character co-ordinate.
Function to get the current cursor vertical co-ordinate.
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 get the current cursor horizontal co-ordinate.
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.
Subroutine 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.

Text Handling Library

Ascii Code of a character in a string. Compatible with FreeBasic
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.
Personal tools
Translate