SPECTRUM UTILITY ROUTINES COMPENDIUM

Contents
Any BASIC routines not already included in TAP files can be loaded using the TXT2Emu program which is also included in this archive.

   3DCK.TXT
** Transferring a 3DCK C64 .d64 file to a Spectrum .dsk file
   Arrays.TXT
** Sorting an array
** Rotate a 3x3 array through 90 degrees
** saving time populating large arrays
** Compact a String Array
** What's the deal with hash tables, anyway?
   Bitwise.TXT
** AND,XOR,OR,BIT,RES,SET,CPL,NEG,RLC,RRC,SLA,SRL,RL,RR,SRA for BASIC
** Bit Operations in BASIC: AND,XOR,OR,BIT,RES,SET,CPL
** Simple BIT,RES,SET in BASIC
   Compression.TXT
** Lempel-Ziv compression routine (draft)
** Lempel-Ziv compression routine (final)
** Lempel-Ziv compression concepts
   DB1.TXT
** Kobrahsoft DB1 - getting it to work
   Display.TXT
** Display file addressing; Screen slicing
** Addressing Bottom 4 Lines of Display
   Editing.TXT
** joining & splitting BASIC lines
** editing strings with INPUT LINE
** INKEY$: No Key / Any Key
** INKEY$: use with caution
** Changing the colour of the INPUT line
** INKEY$ timings
** Keyboard scanning routine
   Errors.TXT
** ON ERROR ... REPEAT
** ON ERROR ... GO TO
** ON ERROR ... REPEAT ... all models
   GOSUB+GOTO.TXT
** Locating the GO SUB stack
** Break from GO SUB (assembler version)
** Break from GO SUB (BASIC version)
** Enhanced RETURN (in BASIC)
** Passing Parameters to Subroutines
** CLEAR does not RESTORE the DATA pointer
** PUTRAM - Move RAMTOP without side effects
   HowTo.TXT
** How To Write A Program
** A Miscellany of Dangerous Tips
** UNTIL ... DO and WHILE ... DO loops
** Pathfinding in Networks/Mazes
** Learning Z80 assembler - Useful Links
** Adding Extra Commands to BASIC
** Renumbering routines
** Detecting the ZX Interface 1 ROM Version
** Paging Memory on the 48k Spectrum
** Converting .Z80 to .TAP
** Countdown Timer
** Calculate the BEEP pitch
** Get the starting address of a game
** A painter (enclose & fill) routine
** Check if two rectangles intersect
   Jelly-Vision.TXT
** Jelly-Vision!
   Mcode_Parameters.TXT
** Passing Parameters to Machine Code
** Assembler Listings with OpCodes in a Distinct Column
** Timing Calculator Extension to Z80 OpCodes Spreadsheet
** BASIC Commands Which Can Include A USR Call
** Machine code optimisation
   Numbers.TXT
** Testing Recursive Functions
** Number Base 2 through 10 Conversion (short numbers, max. 8 digits output)
** Base 10 to 2 Conversion (long numbers, max. 9 digits input)
** Number Base 2 through 36 Conversion (long numbers, max. 8 digits input)
** Calculating Percentages
** Updating BASIC variables from assembler
** Unravelling the Spectrum's Floating Point Number Format
** Exponentiation of Negative Numbers
** Using the ROM's FP Calculator's Memory Area
** Calculating an Expression to Give a Target Number
** Z80 Math Routines
** Full 16*16-digit BASIC multiplication
** Print a large binary integer as a decimal
   Plus128.TXT
** Switching 48/128 modes within a BASIC program
** A 128 Routine to Put Tokens in Strings
** What 128 Spectrum Is This?
** How to check the whole memory on a +2 grey
** Problem with PRINT #stream on +128k
** BEEP durations and PLAY equivalents
** Spectrum 128k Programming Tutorials
** Editing Shortcut Keys for the Spectrum 128k
   Plus3.TXT
** +3 CAT to string
** +3 BASIC DOS_Demo
** File comparator
** 128k+3 RAM paging from BASIC
** +3e Streams & Channels
** RAM used by +3DOS
** Running the +3 Self-Test Program without the Magic Word
** +3e Load & Run from Assembler
** Converting commercial disk games to use standard BASIC loaders
   Printing_Graphics.TXT
** Drawing perspective grids in BASIC
** More on Storing Mazes (Genesis of BOB)
** BOB the Screen Builder
** Overlaid Square Grid
** Increasing the number of UDGs
** Extracting Pictures from GAC & PAWS
** Make 8x UDGs from Attribute Blocks
** Drawing UDGs at Different Scales
** Scrolling a map
** scroll one column
** Plot coordinates for Spectrum character set
** graphics extractor
** simple horizontal scroll
** Drawing Ellipses
** Vertical Downward Character WrapScroll
** UDG Collision Detection
** Sprites in +3 BASIC
** GUI in Sinclair BASIC
** 3D Line Drawing
** Large Sprites
** Machine Code Sprites and Graphics for the ZX Spectrum
** Plotting and Rotating Wireframe Graphics
** Revealing a Hidden Picture
** Fractal Graphics
** Plotting in the Lower Screen
** Colour Clash Comments
** Erasing the Screen
** Next Pixel Down
** Mini scroll routine
** Using SCREEN$ from Assembler
** Colour Considerations when Plotting from Assembler
** Plotting an Energy Bar
** Scrolling by 2 pixels
   Printing_Text.TXT
** Number Padding Function
** Procrustean Printing
** Printing Text with Condensed Print Controls
** Printing 64 Column Text from BASIC
** A neat little BASIC trick for TALL letters
** Proportional Print Routine
** Printing a Listing
** Printing text at any position/size
   QuickCopy.TXT
** Quick BASIC RAM copy
** Writing Faster BASIC
   RAMdisk.TXT
** RAMdisk functions
   Random.TXT
** Constraining a list of RND numbers
** RND Commands
** Using RND in machine code
** Some alternatives to RND
** Random point screen fill
   Relocating_Mcode.TXT
** relocating machine code
** Getting PC into HL
   ROM.TXT
** Which BASIC commands/functions affect FRAMES?
** System Flag Variables
** The $028e KEY_SCAN routine
** Spectrum 48k ROM routines
   SaveLoad.TXT
** SAVE-ing SCREEN$ & BASIC as one file
** SAVE-ing without waiting for a keypress
** LOAD-ing without displaying the filename
** Saving BASIC Programs in a Stack
** Using the ROM's tape routines from assembler
** Force Auto-RUN after LOAD
** Using MERGE in a BASIC program
** Recovering BASIC from a faulty tape
** Why no 'Avalon' loading screen?
   Space.TXT
** calculating free memory
** How much space does a number take?
** Making Room
** Unused RAM check
** calculating FN memory usage
   Storing_Mcode.TXT
** Storing machine code in a BASIC program
** Inserting binary code into ZX Spin assembler
** Embedding/Concealing static data in BASIC
** Insert a REM of a given length into a BASIC program
   Strings.TXT
** String DEF FNs
** Find-Fill-Copy functions for BASIC
** Bytes to String
** Screen2String
** STR$ bug fix
** SCREEN$ bug fix
   TAP2DSK.TXT
** Converting programs from TAP to DSK
** Converting bootstrap loaders to standard loaders
   TXT2EMU.TXT
** TXT2EMU (load BASIC text into an emulator)
** TXT2EMU truncate REM enhancement
   Validation.TXT
** Input Validation
   Variables.TXT
** Finding a Variable in VARS
** Indirect Variable Assignment
** Undefine function
** Using the DEFADD area for extra variables
** DumpVARS (listing variables during runtime)

** DEF FN Domain
                          length       time (sec)   recursive alternative
  *  1  AND (i8,i8)     A    940   84  1.94                238  837  1.88
  *  2  BIN (a$)        B     29   36  0.000005
  *  3  BIN$ (i8)       B$   405  129  0.84                 66  629  0.32
  *  4  CHAR$ (i16)     C$    58   20  0.02
  *  5  DEC (h4$)       D    240   20  0.04->0.06          108  226  0.58
  *  6  DEG (n)         G     25   14  0.000005
  *  7  DPEEK (a)       P     37   20  0.000005
  *  8  EVEN/ODD (a,b)  E     78   22  0.02
  *  9  FREE ()         F     28,92    0.000005,0.02
  * 10  HEX$ (i16)      H$   401   69  0.44                125  507  0.48
  * 11  ITEM ()         T    124  bug  0.22                154 7195varies
  * 12  LEFT$ (a$,n)    L$    28   12  0.000005
  * 13  LOWER$ (1$)     W$    59 1byte 0.000005            111 any$  0.02
  * 14  MAX (n,o)       M     40   16  0.02
  * 15  MAX$ (a$,b$)    A$    44   24  0.000005
  * 16  MID$ (a$,n,o)   M$    47   10  0.000005
  * 17  MIN (n,o)       Q     40   10  0.02
  * 18  MIN$ (a$,b$)    Q$    44   20  0.000005
  * 19  MOD (n,o)       V     30   16  0.000002
  * 20  NOT/CPL (i8)    N    647   90  1.1                 106  584  1.24
  * 21  NUMBER (2$)     U     48   16  0.000002
  * 22  OR (i8,i8)      O   1110   88  2.66                238  837  1.88
  * 23  RAD (n)         R     25   16  0.000002
  * 24  RNDM (n)        I     28   10  0.02
  * 25  RIGHT$ (a$,n)   R$    43   10  0.000005
  * 26  STRING$ (a$,n)  S$    77  482  0.1
  * 27  TIME ()         Z    130   26  0.12
  * 28  TIME$ (n)       T$   375  113  0.56                175 1036  0.82
  * 29  UPPER$ (1$)     U$    60 1byte 0.000002            111 any$  0.02
  * 30  XOR (i8,i8)     X   1030   82  2.64                238  837  1.88

** END