SPR_CALC_POS
------------

 Calculate the address offset of a point in a sprite

In:
 spr_w = Width of sprite in pixels
 spr_g = Sprite end-of-row data gap in bytes
 x,y = Position of point
 spr_c = Sprite colour depth: 0=8bpp, 1=16bpp, 2=24/32bpp (constant)

Out:
 pix = Address offset into sprite of the pixel

Requirements:
 x,y must be within the sprite bounds


SPR_CALC_DRAW
-------------

 Calculate the variables needed to draw a sprite

In:
 x,y = coordinates of where to draw on screen. Measured in pixels.
 spr = sprite data pointer
 spr_w = width of sprite in pixels
 spr_h = height of sprite in pixels
 spr_g = sprite end-of-row data gap in bytes
 spr_c = sprite colour depth: 0=8bpp, 1=16bpp, 2=24/32bpp (constant)
 scr = screen data pointer
 scr_w = width of screen in pixels
 scr_h = height of screen in pixels
 scr_g = screen end-of-row data gap in bytes
 scr_c = screen colour depth: 0=8bbp, 1=16bpp, 2=24/32bpp (constant)
 tmp = temporary register

Out:
 spr,scr updated to point to data start
 spr_w,spr_h updated to contain size of area to draw
 spr_g,scr_g updated
 tmp mangled

Requirements:
 None?


SPR_CALC_DRAW_PRESHIFTED_8BPP
-----------------------------

 Calculate the variables needed to draw an 8bpp preshifted sprite on an 8bpp screen

In:
 x,y = coordinates of where to draw on screen. Measured in pixels.
 spr = sprite data pointer
 spr_w = width of sprite in pixels
 spr_h = height of sprite in pixels
 spr_g = sprite end-of-row data gap in bytes
 scr = screen data pointer
 scr_w = width of screen in pixels
 scr_h = height of screen in pixels
 scr_g = screen end-of-row data gap in bytes
 tmp,tmp2 = temporary registers

Out:
 x,y updated to contain start/end masks: 1=don't draw, 0=draw
 spr,scr updated to point to data start
 spr_w,spr_h updated to contain size of area to draw
 spr_g,scr_g updated
 tmp,tmp2 mangled

Requirements:
 Sprite width, pointer and gap must be word aligned.
 Screen width, pointer and gap must be word aligned.
 Sprite gap must take into account the 4 extra pixels used for the preshifting
 column (i.e. a 16x16 sprite would have spr_w=16, spr_g=4)
 Preshifted sprites occur directly after the first sprite, such that (spr_w+spr_g)*spr_h*N is the index to preshift #N


SPR_DRAW_SIMPLE_8BPP
--------------------

 Draw an 8bpp sprite to an 8bpp screen pixel by pixel

In:
 w,h = Width, height of area to draw in pixels
 spr = Sprite data pointer
 spr_g = Sprite end-of-row data gap in bytes
 scr = Screen data pointer
 scr_g = Screen end-of-row data gap in bytes
 tmp,tmp2 = Temporary vars

Out:
 h, spr, scr, tmp, tmp2 mangled

Requirements:
 At least one pixel can be drawn (i.e. w > 0, h > 0)


SPR_DRAW_SIMPLE_16BPP
---------------------

 Draw a 16bpp sprite to a 16bpp screen pixel by pixel

In:
 w,h = Width, height of area to draw in pixels
 spr = Sprite data pointer
 spr_g = Sprite end-of-row data gap in bytes
 scr = Screen data pointer
 scr_g = Screen end-of-row data gap in bytes
 tmp,tmp2 = Temporary vars

Out:
 h, spr, scr, tmp, tmp2 mangled

Requirements:
 At least one pixel can be drawn (i.e. w > 0, h > 0)


SPR_DRAW_SIMPLE_WORDALIGNED
---------------------------

 Draw a word-aligned sprite to a word-aligned screen, at up to 4 words at once

In:
 w,h = Width, height of area to draw (pixels)
 spr = Sprite data pointer
 spr_g = Sprite end-of-row data gap in bytes
 scr = Screen data pointer
 scr_g = Screen end-of-row data gap in bytes
 tmp,da,db,dc,dd = Temporary registers
 spr_c = Sprite/screen colour depth: 0=8bpp, 1=16bpp, 2=24/32bpp (constant)

Out:
 h, spr, scr, tmp, da, db, dc, dd mangled

Requirements:
 spr, spr_g, scr, scr_g, w must be word-aligned (For w, the lower 2-spr_c bits must be clear)


SPR_DRAW_PRESHIFTED
-------------------

 Draw a pre-shifted word-aligned sprite to a word-aligned screen, at up to 4 words at once

In:
 w,h = Width, height of area to draw (pixels)
 spr = Sprite data pointer
 spr_g = Sprite end-of-row data gap in bytes
 scr = Screen data pointer
 scr_g = Screen end-of-row data gap in bytes
 tmp,da,db,dc,dd = Temporary registers
 spr_c = Sprite/screen colour depth: 0=8bpp, 1=16bpp, 2=24/32bpp (constant)
 lmask, rmask = Left and right word masks: 1=don't draw, 0=draw

Out:
 h, spr, scr, tmp, da, db, dc, dd mangled

Requirements:
 At least one word can be drawn (i.e. w, h > 0)
 spr, spr_g, scr, scr_g, w must be word-aligned (For w, the lower 2-spr_c bits must be clear)
 spr_g should take into account the preshifting word


SPR_DRAW_TRANSFORMED_ROW_8BPP
-----------------------------

 Draw a horizontal line on an 8bpp screen from a transformed 8bpp sprite, wrapping the sprite coordinates if it leaves the sprite

In:
 scr = Screen data pointer
 len = Length of area to draw (pixels)
 spr = Sprite data pointer
 spr_g = Sprite end-of-row data gap in bytes
 width = Width of sprite (pixels)
 height = Height of sprite (pixels)
 x,y = Location to start plotting from sprite (pixels, fixed-point)
 xd,yd = Direction to move x,y in per screen pixel (pixels, fixed-point)
 shift = Fixed point precision: 16 = 16.16, 24 = 8.24, etc.
 tmp,tmp2 = Temporary registers

Out:
 scr, len, x, y, tmp, tmp2 mangled

Requirements:
 At least one pixel can be drawn (len > 0)
 x,y are already within the range 0 <= (x|y) < (width|height)


ROUND
-----

 Return the remainder of val/lim, using a simple loop (i.e. don't make val more than a few times bigger/smaller than lim)

In:
 val = The value to round (fixed-point)
 lim = The upper limit to use
 shift = Fixed point precision (16 = 16.16, 24 = 8.24, etc)

Out:
 val is now >= 0 and < lim

Requirements
 lim must be > 0


SPR_DRAW_BOUNDED_TRANSFORMED_ROW_8BPP
-------------------------------------

 Draw a horizontal line on an 8bpp screen from a transformed 8bpp sprite, stopping drawing if the coordinates leave the sprite

In:
 scr = Screen data pointer
 len = Length of area to draw (pixels)
 spr = Sprite data pointer
 spr_g = Sprite end-of-row data gap in bytes
 width = Width of sprite (pixels)
 height = Height of sprite (pixels)
 x,y = Location to start plotting from sprite (pixels, fixed-point)
 xd,yd = Direction to move x,y in per screen pixel (pixels, fixed-point)
 shift = Fixed point precision: 16 = 16.16, 24 = 8.24, etc.
 tmp,tmp2 = Temporary registers

Out:
 scr, tmp, tmp2 mangled
 len contains the number of pixels left to draw (i.e. >0 if plotting went outside the sprite)
 x, y contains the location of the not-drawn pixel (i.e. just outside the sprite if len > 0)

Requirements:
 At least one pixel can be drawn (len > 0, x,y, within range)
