SampleCodeLibrary

= Sample Code Library =

BASIC Routines
Text Wrapping Routine by Francis G. Loch

An example of how to dynamically wrap text for use in programs such as text adventures.

Limitless commenting in BASIC by Andrew Weston

Using BeebugSoft's Toolkit Plus *CRUNCH command, with !Beebit and !6502em on RISC OS.

Assembler Routines
Bit manipulation by J.G.Harston

Setting Clearing and Copying bits of data.

Crunching Using Pu Crunch by Dave Footitt

Efficient compaction of data using Pu Crunch.

Custom Text Input by Francis G. Loch

Custom routine for obtaining text input.

Day of week by J.G.Harston

Calculate the day of the week from day/month/year input.

Denormalising by J.G.Harston

Denormalising a number (converting from floating point to integer).

Detecting the TUBE by Francis G. Loch

Routine for detecting whether the TUBE is being used.

Fast fixed-point multiplication library by Rich Talbot-Watkins

A collection of routines designed to perform multiplication by fixed-point values between -1.0 and +1.0 on the 6502, typically for applying transformations to a point, e.g. in a 3D game.

Fast multiplication routines by Rich Talbot-Watkins

Various techniques for performing a multiply quickly on the 6502.

Linear time bucket sort by Richard Broadhurst (tricky)

A linear time bucket sort <60 bytes that takes <2k cycles for 32 sprites indexed by character line and <6k cycles for 128 sprites.

Print decimal by J.G.Harston

Printing decimal numbers.

Reading the keyboard by direct hardware access by Rich Talbot-Watkins

How to improve the speed of your games by ditching OSBYTE and reading the keyboard hardware directly.

Square roots by J.G.Harston

Calculating integer square roots.

BIN/HEX to BCD (to Decimal) by Richard Broadhurst (tricky)

Fast conversion of 16 bit numbers to BCD Binary Coded Decimal, that is 42 = &2A or 42 = &42 in BCD

Random number generator (very fast - very basic) by Richard Broadhurst (tricky)

This is about the fastest random number generator you can get although it is really just a sequence of 256 numbers using 14 bytes (code and data)

Graphic Routines
Line by line vertical scrolling on the Beeb by Rich Talbot-Watkins (Updated with commented source code July 2015!)

An introduction to the "vertical rupture" technique, and then an application of its use in a line-by-line vertical scrolling routine.

Calculate 10K screen mode screen address by Steve O'Leary

A Screen address calculator for use in 10 screens (i.e. Mode 4 and 5).

Calculate 20K sceen mode screen address by Steve O'Leary

A Screen address calculator for use in 20K screens (i.e. Mode 0,1 and 2).

Basic Mode 2 Sprite Plotter (no mask) by Steve O'Leary

A basic sprite plotter (in assembly) for use in Mode 2 but easily adapted for other modes. Written in Swift in P65 assembler.

Mode 2 masked sprite Plotter by Steve O'Leary

A Mode 2 masked sprite plotter but easily adapted for other modes. Written in Swift in P65 assembler.

Moving Mode 2 masked sprites by Steve O'Leary

Demo and source for a mode 2 masked sprite plotter showing how to erase/plot and move sprites about. Written in Swift in P65 assembler.

Vertical Scrolling Mode 7 by Richard Broadhurst (tricky)

Demo of how to scroll a mode 7 screen a pixel at a time vertically in BeebAsm.

Vertical Rupture Scrolling Mode 5 by Richard Broadhurst (tricky)

Demo of how to use vertical rupture to scroll a mode 5 screen a pixel at a time vertically in BeebAsm.

Sound Routines
Sample Sound Routine Example by A.N. Fibber

Read Joystick Routines
Read Joystick by P. Jones

Development Support Routines
BASIC tokeniser/detokeniser in C by Thomas Harte

Micro Power Style Loading Screen
Freeware Loading Screen by Paul Davis

A set of tools and a short tutorial describing how to create your own loading screen for our freeware releases.

Full Game Source Code
Jet Set Miner by Sarah Walker

Sparse Invaders by Neil Beresford

Fully commented GPL source code of a simple P65 assembler Space Invaders clone designed for use with the SWIFT IDE as an extensible base for further projects.

HyperViper by Kenton Price