
;
; Atari XE Space Harrier Conversion Project (c) 1987-2011 Chris Hutt
;

;
; To Do List
;

;
; Current Bugs
;

; No known serious

;
; Notes and Changes
;

; 03/07/11	Stage number option now set depending on highest stage reached in current game
;
;		Put in 2 cycle delay on DLIs to fix timing on machines with CPU upgrade
;
;		Comma uses ANTIC mode 3 descender on splash screen now
;
;		Uriah dragon pattern changed so man jump off can be seen better
;
;		Changed colours on Stage 6 to be more purple than pink
;
;		Tweaked lives position over to the right one character
;
;		Used man characters for number of lives option to balance display
;
; 02/07/11	dlist4 and dlist5 wrong lengths - didn't add up to 192 scan-lines
;
;		dlist5 changed so more text could be fitted onto the splash screen
;
;		Removed having credits as just an Easter egg. Now display all the time.
;
; 26/06/11	High Scores can now be erased by holding down Select during power-on
;
; 25/06/11	Added option to make game harder by disabling lock-on at suggestion of Sal
;		Easy - lock-on enabled, one continue
;		Normal - lock-on enabled, no continues 
;		Hard - lock-on disabled, no continues
;
;		Made options cursor flash on non-exit items
;
;		Moved IRQ timing down another VCOUNT as seemed to get NMI clash sometimes
;
; 19/06/11	Scenery was too easy to hit on bonus stages. Changed to spread out scenery
;		more (scenery_spread), and reduced collision size of Uriah segments.
;
;		Changed init_stage and init_boss so Stage 18 boss song starts straight away
;
; 16/06/11	Volume on all RMT songs reduced from $0A to $08 to give more prominence
;		to sample playback.
;
;		Removed sound compression from "Welcome" sample - wasn't that great
;
; 13/06/11	Reduced volume of sound effects a little
;
; 12/06/11	Made sample playback code use two channels to be heard above dual POKEY
;		Made main tune music a bit quieter as still too loud when dual POKEY
;		Applied sound compression to "Welcome" sample as still too quiet to be
;		heard when dual POKEY. Sample playback still quiet with dual POKEY after
;		all these changes. Really not sure whether too much more to be done.
;		Main tune track $48 and $49 volumes hadn't been adjusted correctly.
;		Moved drum intro to channel one so can be heard when man dies.
;
; 09/06/11	Fixes to the high score loading and display
;
; 08/06/11	More testing required, but loading of high scores at start up coded now.
;
; 07/06/11	Code to write high scores to cart finally working in emulator. Loading of
;		scores at start up still to be done.
;
; 05/06/11	Default high scores put in last week and tests of data layout for score save
;
; 22/05/11	Put back code in Bonus stage for all of Uriah to kill scenery objects - makes
;		the stage more playable. Just the head colliding as per the arcade version
;		didn't work as well, as not enough collisions were possible. Also extened
;		Bonus stage 12 as much as possible to allow for more collisions and score.
;
; 17/05/11	Stage 17 running out of sprites change was not reducing pat_kill when alien
;		could not be started leading to pattern handlers not being freed up.
;
; 15/05/11	Stage 15, 8th pattern - blue robots pattern 56 was incorrectly set as mirrored
;
;		Stage 15 triads didn't stay open long enough to be able to shoot them in one go
;
;		Stage 17 put in missing pattern of ships after flying heads. Only shows up when
;		heads are hit because the arcade version seems to run out of sprites!
;		My version ran out of sprites by hanging, to indicate a problem. Changed this
;		to mimic the arcade version by just exiting if it fails to initialize an alien.
;
; 11/05/11	Made blue sky colour on stage 16 lighter at Nick's suggestion as objects get
;		hidden by it otherwise.
;
;		collide_objects was adding 4 to divisor instead of 5 for position conversion
;
;		Removed unneeded ldy sine_index in move_scenery. Changed limit check in scenery
;
; 08/05/11	Finally found bug causing incorrect pat_qty decrement. set_linked_anim was only
;		checking whether pattern handler of alien matched rather than also checking if
;		it was still alive. Already dead aliens were caused to become active as the
;		object animation was done and their object properties got set again.
;
; 07/05/11	Sanity check in kill_alien for pat_qty as there is a bug which allows it to be
;		zero when it should never be that. Pattern handlers are lost on linked patterns
;		without the sanity check. Cause remains unknown. The only symptom of this is an
;		inability to finish the game as there is a cumulative effect of pattern handlers
;		not being released, and only by the end of the game are there not enough for the
;		more complex patterns. The bug does not occur if the game is started right at
;		the linked patterns in question, only if it is played through from pattern 4 in
;		stage 3 or earlier.
;
; 05/05/11	Expire lockon object when timer counted down, not when off target. Search for
;		another target when lockon found for object that already has a bullet allocated.
;		Increased lockon time to about 1 second.
;
;		Made colours on stage 3 dimmer at suggestion of Nick
;
;		Adjusted width of taller scenery objects to be narrower - only the average width
;
;		Scenery started too soon on bonus stage 5, arriving before on Uriah properly
;
; 04/05/11	Lockon code was not checking whether other bullets were already locked on
;
;		1st and 2nd patterns on stage 2 didn't start far enough apart in time
;
; 02/05/11	Preliminary lockon and move code for bullets, plus sound effect.
;		Having fairly large, fixed dx and dy movements doesn't really look right. Needs
;		to be more similar to missile aiming; choosing fastest route based on a maximum
;		speed and x,y and z adjustments.
;
; 01/05/11	Changed draw_sprites to leave sprite_count available for new lockon_bullet code
;		Rewrite of move_bullets to work with the lockon
;
; 29/04/11	Changed dragon hit count from 6 to 5 on stage 18 as had been forgotten
;
; 24/04/11	Finished work on stage 9 colour changes
;
; 22/04/11	Finished work on stage 4 colour changes
;
;		Re-jigged colours and positions on stage 6 some more
;
; 20/04/11	Put in colour changes for hexagons on stage 4. Doesn't look too bad
;
;		Darkened under/overlay background for stage 6 and darkened sky slightly.
;		Also changed sky DLI positions.
;
; 18/04/11	Changed stage 4 and 9 so hexagons don't appear at same time as ships
;
; 17/04/11	Brightened up colours and under/overlay backgrounds so sprites show up better
;		on Stage 6
;
;		Changed collision width of pylons to be the average width rather than wider 
;
; 16/04/11	Changed dragon hit count required from 6 to 5
;
;		Put back delay at stage start for pattern and scenery handlers to allow man
;		time to move out of the way of scenery as he can't move during sample playback
;		Adjusted Stage 14 grid colour change timing in accordance with.
;
;		Highscore text luminance changed to always be black. Best change to it so far.
;		This also removes a bug where initial colour luminance wasn't adjusted for.
;
;		Changed purple tall plant colour to red so it can be seen better in stage 3
;
; 13/04/11	Highscore display text luminance change with exclusive or not as good as
;		initial impressions suggested. Put in a simple check for same brighness with
;		reduced luminance applied on match. Also initial luminance was not being set
;
;		Fixed init_kill to set final screen position correctly in line with man run
;		position adjustment changes
;
; 10/04/11	Applied adjustments to man run position to mitigate impression that closest
;		objects can be avoided due to 3D position of man at front of screen. Messed
;		with tilt_lo initial value to make nearest line of grid not go below screen
;
; 07/04/11	Speed of robot missiles on stage 4 way too fast. Corrected in stage file
;
; 03/04/11	Changed all stage colours so there is compatibility between PAL and NTSC -
;		mainly a task of avoiding certain colours such as 3 and 7
;
;		Made highscore display text show up better by using an exclusive or on its
;		highest luminace bit. Seems quite effective. Need something similar in game
;
;		Added extra frame to man die sequence. One of the falling down frames used
;		to make it seem like he's getting up again. Made standing up frame display
;		a bit longer before going into get_ready routine as otherwise, it is only
;		displayed for 1 frame before going into highscore routine at game over -
;		which looks really bad.
;
; 30/03/11	Changed highscore routine to repond instantly to joystick by using more
;		sophisticated autorepeat on left/right movement.
;
;		Attempt to fix score not being always visible in highscore entry (mainly
;		noticable on stage 14).
;
;		Fix grid animation colours on stage 14 which were allowed to go too dark
;
; 29/03/11	enter_initials incorrectly puts in a space if button is pushed on entry to
;		the highscore routine. Put in check for this unassigned state.
;
; 28/03/11	Fixed so frame rate is saved and restored from variable for man die, rather
;		than restored from stage_speed.
;
; 27/03/11	Now man die changes frame rate for consistent speed on faster stages 
;
; 26/03/11	Changed option menu select code to only change on joystick state change, so
;		only moves one selection per joystick push.
;
; 25/03/11	Changed option menu button response to use VBI button_pressed and no delay
;
; 24/03/11	Completed entry of all Stage names. Fixed data overrun in bank 123
;
; 23/03/11	Fixed continue countdown timer which was not displaying correct characters
;		since change to show stage names during stage intermission. Stage name
;		change meant having to store character set more efficiently because of too
;		many characters required otherwise.
;
; 21/03/11	Fixed bug on highscore screen where "PUSH FIRE" text not totally hidden for
;		highscore entry when last grid DLI is right on the text line. Not enough
;		time to turn it invisible. Changed highscore to erase "PUSH FIRE" text and
;		write it back afterwards during highscore entry.
;
; 20/03/11	Changed max_lives override in insert_credit and fixed missing end statement
;
;		Removed unneeded dli_count variable in highscore routine
;
;		Finished stage intermission stage name display
;
; 03/03/11	init_stage changed to increase start stage choices when uriah bonus stages
;
; 02/03/11	start_game code changed to use stage number from option selected.
;		init_stage changed to add a continue when reached uriah bonus stage.
;
; 27/02/11	More work of option selection code. Exit option flashes text on selection
;		Attract mode timer gets reset if option selection states change - will only
;		run attact if options left alone.
;
; 26/02/11	Resumed work on option selection code
;
; 22/02/11	Changed hiscore code so separate clear of "PUSH FIRE" text is not required.
;		Character control changed to invisible after the line of of inverse text.
;		Removed redundant write_info and clear_info routines and removed the info
;		messages data. Renamed flash_info and hide_info to flash_text and hide_text.
;
; 19/02/11	Reduced code size of fill_sample_buffer as banks 126 and 127 are getting full
;		Also moved copy_title_dlis to main_bank. NB if need more RAM, then other
;		routines could be copied to the main_bank where there is still room for more.
;
; 18/02/11	Made coldstart and warmstart detect code more robust and simple. Moved it from
;		highscore routines into init routines since it is needed for things other than
;		highscores now. Simplified highscore setup and load routines.
;
;		Fixed bug with top score which was not getting restored after a warm reset
;
; 15/02/11	Re-implemented split bullet routine and fixed bug by reorganizing move_objects
;		code and one of the return addresses of title_objects.
;
; 12/02/11	Removed 29/01/11 changes to split bullet routine due to bug with bullets not
;		moving when dying unless during a boss.
;
; 09/02/11	Work begun on option selection code for title screen
;
; 08/02/11	Corrected stage 9 patterns so not just a copy of stage 4 patterns.
;		Changed to use grey hexagons rather than blue for both these stages.
;
;		Timing of title screen made longer still for highscore music to finish
;
; 06/02/11	Changed timing of title screen and highscore screen to be longer
;
;		Revised music for highscore entry (instrument sustain on melody)
;
;		Colour animation for stage 18 grid
;
; 04/02/11	Moved init_highscores after the score line copy in the initialize. Code for
;		clearing the score line in init_highscores could then be removed.
;
;		Stage increment and insert credits moved to run when line not being displayed
;
;		Line templates reorganized to use overlapping blank space better in data127
;
; 03/02/11	Changed character set order to align with normal ASCII (with an offset). Only
;		for ease of text entry, actually takes up slightly more space because of
;		wasted characters. Some extra characters defined for credits section which
;		will be displayed on the splash screen.
;
;		Changed highscore routine setup of character selection line. Now full stop
;		and backspace are no longer at the end of the character set they need to be
;		specifically checked for in the generation of the selection line.
;
;		Credits made to show on splash screen only after a high score achieved
;
; 30/01/11	Changed init_pattern to only skip missile speedup reset when Wiwi Jumbo boss
;		and not others. Otherwise missile speed wasn't reset for attract after game
;		over.
;
;		After end of game, remaining lives were not removed from display
;
; 29/01/11	Split bullets routine into two so that end game bullets are not left frozen
;		on screen due to setting of uriah state for end game. Now have move_bullets
;		and init_bullet routines.
;
; 22/01/11	Problem with songs using all channels not playing all channels fixed by
;		stopping sound effect code always stuffing RMT variables even when no sound
;		effects active.
;
; 19/01/11	Changed patch_rmt to use all 4 or 8 channels rather than just 3 or 6, as the
;		high score and end game songs need to use those channels (no sound effects)
;
; 17/01/11	Removed need to copy RMT routines separately. Now included in 2nd copy.
;
; 16/01/11	Corrections to copy routine and address/size setups for it
;
; 15/01/11	Rearranged memory layout to make more room for still too big RMT player
;		Changed copy routine to be smaller (but more complex setup)
;
; 13/01/11	Rearranged memory layout to make room for extra feature enabled RMT player
;
; 11/01/11	Changed state variables to include the word state rather than the word status
;
;		Changed do_man_anim to be able to show frame based on x position when man is
;		in air as per normal in-game routine. This required for end of game.
;
; 09/01/11	Chopped samples a little and added volume fade to end of them instead to stop
;		popping that can be heard in Altirra emulator (fade data is in file fade.bin)
;
; 08/01/11	Stopped sample playback "popping" noise at start by writing gradually ascending
;		volume values from 0 to 8 (sample volume mid-point) into sample buffer before
;		playing actual sample data. This also has the benefit of avoiding an initial
;		call to fill_sample_buffer as it could be done programatically very cheaply.
;		Was also able to tidy up the code some more after the changes in init_sample.
;
; 02/01/11	In sequence_pattern_events the wait was not checking if first alien active
;
;		Previous sum_object was not getting reset for sum patterns without objects
;
; 01/01/11	Allowed init_song to be skipped in init_stage with a song of zero (stage 18)
;
; 22/12/10	Reduce volume level of robot/Wiwi Jumbo missile sound effect
;		Don't display bonus round x50000 score if no objects hit
;
; 21/12/10	Waiting a second for game continue countdown was too annoying. Instead have
;		just made sure that button press is cleared before showing the timer.
;
;		Changed init_linked_kill to stop game command instead of moving on sequencer
;		Made sequencer wait command wait for missiles to finish as well as explosions
;
; 15/12/10	Wait a second during game continue countdown to allow timer to show on screen.
;		Disregard button during this time in case user hasn't realised.
;
; 14/12/10	Put code into init_linked_kill to move on pattern sequencer when Wiwi Jumbo
;		is killed.
;
; 12/12/10	Made man x movement faster when PAL. Now moves at 2 1/2 pixels per VBI instead
;		of 2.
;
;		Renamed init2 to init_cont. Rather than have init2 in memory created a routine
;		to run code from within a bank.
;
; 20/11/10	Wiwi Jumbo changes needed more action/animation frames than 4. Init_pattern was
;		changed to alter the bit usage of the stage overlay data and allow up to 8.
;		Renamed pat_kill_frames to pat_frame_actions as not all actions are to kill now.
;
; 19/11/10	Changed to add extra_properties to queue_missile for easy setting of "virtual"
;		missiles that Wiwi Jumbo fires, which can't be shot and don't kill you.
;
;		Changed collide_objects to display Wiwi Jumbo thrown objects explosions higher
;
; 15/11/10	Changed to initialize Wiwi Jumbo scenery manually so can leave one handler doing
;		brick rocks that don't get thrown.
;
; 14/11/10	Aliens were making initializing noises during boss status since change to timing
;		changes on 27/10/10. Could not simply put back delay though due to the Wiwi
;		requirement for thrown objects. Moved the game command to happen as soon after
;		sequencer as possible.
;
; 06/11/10	Continuing Wiwi Jumbo object throwing. Put in missing check for whether thrown
;		scenery was already dead and exploding. Was causing pattern handlers to not be
;		freed for other use.
;
;		Added checks to collide_objects to allow for collision with missile objects to
;		not corrupt alien and scenery only variables.
;
;		Fixed init_missile speed initialize for Wiwi Jumbo thrown objects and height
;		adjust for non-centred objects.
;
; 03/11/10	Fixed problem when head is used as scenery there should be no sound effect.
;		Negative used to denote effect should be used by scenery handler. When positive
;		it is only for pattern (or Wiwi Jumbo missile).
;
;		Added code for alien to fire self when Wiwi Jumbo missile. Changed order of
;		missile types so Wiwi Jumbo missile is now type zero.
;
; 01/11/10	Changed init_pattern to return status when no available handlers, rather than
;		indicating error by freezing game. Needed as Wiwi Jumbo can try to use more
;		handlers than available to throw scenery.
;
; 29/10/10	Removed unecessary initializing of pat_spacing in init_pattern when multi-hit
;		Moved zeroing of offsets to pattern position into init_pattern rather than stage
;
; 27/10/10	Changed timing of initialize of pattern decoder and alien to occur on same frame
;		rather than next frame (pat_timer and pat_start_timer initialized to 1 not 2).
;		This to allow passing of position data to Wiwi Jumbo thrown scenery objects.
;
;		Changed init_alien to add offsets to the initial pattern positions which will be
;		the position data of Wiwi Jumbo thrown scenery objects. The pattern positions
;		themselves are in ROM and so can't be modified.
;
; 24/10/10	Fixed bugs in set_linked_anim:
;		Was only doing one frame of dying animation. Was not using sprite object 
;		Was not updating size_slot so object size was also not updated
;
;		Fixed bug in collide_objects where bullet would not get bounced on the frame
;		change or die of multi-hit object.
;
; 07/10/10	Added extra grey hexagon for Uriah stage 12 and stage 17
;
; 02/10/10	Added game command do_init_song for Stanray - do_init_boss no good as sound
;		effects are not muted with Stanray.
;
; 28/09/10	Swapped around robot4a and robot4b so pat56 could be done as mirror rather than
;		having seperate special pattern (formerly pat56m). Changed all stage data.
;
; 19/09/10	Added insert coin music to title screen. Changed init_stage and splash so only
;		plays the song one time.
;
; 16/09/10	Made title screen wait minimum 10 seconds always
;
; 13/09/10	Changed title screen anims to use full value of timer instead of only +ve value
;		to deal with title screen running long enough for high score music. This saves
;		a few bytes of data specifying extra repeats of the same frame.
;		Made title screen wait for volume of track to be zero before using the main
;		attract timer at all. This allows it to run long enough for music to finish.
;
; 12/09/10	Started changes to allow high score music to continue to play when goes back
;		to title screen. Problem with title screen running long enough for music to
;		complete still being worked on.
;
; 11/09/10	Fixed button state problem. Just holding down button at switch on or during
;		attract mode would skip the title screen. last_button was not being initialized
;		to the TRIG0 value so forcing a complete release/press or press/release cycle.
;		Added this code to init_stage which is called for title screen as well.
;
;		Allowed button press to skip the splash screen
;
;		Added info message to continue game countdown timer in check_end_game
;
;		Tidied up enabling and disabling of missiles for masking side of screen. Using
;		GRAFM with 0 to hide them on the splash screen and then setting it to 255 to
;		put them back. PRIOR could not be used to set them as under the graphics when
;		they are defined as being the same colour as PF3.
;
; 09/09/10	Added info message to high score screen display screen. Made flashing a more
;		consistent speed when switching screens by changing initial attract timer value.
;
; 08/09/10	Simplification to info message display since there's only 1 message now. Put
;		in hide_info routine to be used rather than clearing it every time. Attract
;		mode now displays the info message.
;
; 07/09/10	Fix to stop_sound. Was not clearing direct writes to RMT track used for effects
;
;		Pressing fire now exits attract mode and goes back to title screen. Fixes to
;		title screen and init_stage to clean up better due to exit at any time, instead
;		of just at game over. EG man status needed setting to dead and joystick off.
;
;		init_sample now writes to IRQEN twice to ensure IRQ disabled first
;
; 06/09/10	Centred text on splash screen by using Horizontal scroll where needed
;
; 05/09/10	Edge case fix for IRQ disable. It is possible for an interrupt to occur just
;		after write to disable IRQEN. SEI used to ensure it doesn't (ref. Avery Lee)
;
;		Completed attract mode apart from button watch code to exit attract
;
; 04/09/10	Splash screen almost completed. Text could be centred better though.
;
;		Work begun on attract mode. Changes to init_game, init_stage, insert_credit
;		and titlescreen.
;
; 29/08/10	Work begun on splash screen
;
; 16/08/10	Tweaked timing of man fall and pause to look better at different frame rates
;
;		Moved return_sample_status routine into seperate file
;
; 14/08/10	Man commands still crashing on high frame rates - changed commands to try fix
;
; 09/08/10	An IRQ occasionally happened in the fill buffer routine between the read buffer
;		pointer load and the stopping of the interrupt, causing the read buffer pointer
;		to move on to a non-zero value, messing up the checks for end of sample in the
;		man commands. Could have set the interrupt disable flag before the read of the
;		pointer, but was more efficient to re-read the pointer and write zero into the
;		buffer if at the end of the sample.
;
; 08/08/10	Fix man trip animation when not exactly on ground. Changed man commands to deal
;		with different frame rates more robustly.
;
; 25/07/10	Continue game countdown needed to wait until sample playing complete or IRQ was
;		hitting VBI when it was running.
;
; 24/07/10	Important IRQ fix. Stack manipulation code causing crashes (in PAL) as had
;		been setting the interrupt flag (sei) when initializing the sample playback.
;		This is because VBI checks for interrupt flag to determine an interrupted IRQ.
;		Also the end check now in fill_sample_buffer was not changing the sample_size
;		to negative as soon as was possible on completion of sample playback.
;
; 23/07/10	It would seem ATasm cannot assemble the zero page located code correctly for
;		the sample playback. Had to pre-assemble the code for it to put the restore
;		for accumulator in the right place.
;
;		Manipulated stack in VBI so if IRQ was interrupted then it is allowed to finish
;		and the deferred VBI is then also done afterwards. Testing with 64KHz clock
;		sample playback which ensures VBI does interrupt the IRQ.
;
; 19/07/10	Redid "Welcome" and "GetReady" as they were a little too quiet after automatic
;		gain adjustment by SoX. Allowing the samples to clip slightly didn't affect the
;		already poor quality of the samples.
;
; 17/07/10	Adjusted pattern 32a so doesn't fail debug left clip (only just failed)
;
; 15/07/10	"Welcome" and "GetReady" samples redone as too much had been chopped off the
;		end of the word "zone" for it to be heard.
;
; 13/07/10	Barbarian (stage 14 boss) crashing due to incorrect data size for main theme
;		causing frame 6 to not quite fit in a bank.
;
;		Trip animation ran over into die commands if frame rate too fast. EG PAL stage 1
;		This was because the sample playback has to be longer than the animation
;		sequence. Increased the length of the animation sequence and also managed to
;		shorten the "Ouch" sample by 256 bytes without adversely affecting the sound.
;		Also chopped "Argh" and "GetReady" samples by 256 bytes for same reason.
;
; 12/07/10	Made init2 code for copying sample playback IRQ to zero page smaller
;
;		Fixed stage 5 speed. Had to reduce to 15 fps otherwise Uriah finishes too early
;
;		Missile speed on stage 13 was way too slow due to incorrect data
;
;		Fixed hexagon top/bottom properties since changes for scenery sine
;
;		Found and fixed some frame mapping errors on "purple" oranges
;
; 11/07/10	Optimization of sample playback IRQ. Code moved into zero page. Made room by
;		moving some zero page variables into $0-$7 region and some rarely used ones out
;		of zero page altogether. Saves another 2 cycles.
;
; 10/07/10	Optimization of sample playback IRQ. There was no need to store the sample value
;		for playback the next time the IRQ is called. Just write straight away. Saves 6
;		cycles. Also removed the end of sample check code in the IRQ. Saves 2 cycles.
;		VBI fill_sample_buffer now keeps filling the buffer with zeros until the read
;		pointer gets to those zeros at which point the IRQ is ended.
;
;		Removed 2 cycle delay in writing colour registers in DLI for processor upgrade
;		compatibility. Different code should be used if CPU upgrade present. Think about
;
; 07/07/10	Pat21 change to not clip offscreen left
;
; 06/07/10	tilt_objects changed to allow movement of certain bosses during man dying as per
;		original arcade.
;
;		Swapped some Valda music channels so sounds better when man dies
;
; 05/07/10	Debug clipping check left was 2 bytes off
;
; 28/06/10	Fixed debug clipping check since change to allow drawing from left or right edge
;
; 24/06/10	Change to draw_sprites code to allow drawing to start from left or right edge now.
;		Sprite first and last non-mask data can sometimes be optimised slightly better
;		from the right edge. Screen start no longer needed +1 adjustment (see framework)
;
;		Optimise to draw_sprites. Saving y position in temporary variable could be avoided
;		by using self modifying code for the object draw code bank switch by freeing the
;		x register. No benefit to using the self modifying code normally over the register
;		switch bank code as it's 3 cycles slower.
;
; 01/06/10	Small optimize on move_man again. If left/right checks are swapped around then a
;		"sec" can be avoided in the player position code, except in one edge case.
;
; 31/05/10	Continued optimize of move_man. Made lookup tables for joystick vectors and also
;		for determining which man frames to based on x position rather than calculating.
;
;		Fixed bug where inverse video still on when pause info displayed. Was not being
;		reset after high score display screen.
;
; 29/05/10	Optimized move_man clear player decision code a little
;
;		Changed green colour in sky so man yellow doesn't get hidden so badly by it
;
; 23/05/10	Looking at dropping rocks on Stage 15, only just realised they are done in the
;		same way as the orange loopers. The starting position in the sine wave gets reset
;		for each new bunch of loopers or rocks though, so there is a consistent drop
;		effect rather than a totally random position as was being done by my code.
;		Scenery routine amended to just nudge the index for each following scenery object
;		rather than random start position. sequence_scenery_events changed to reset the
;		index. Rather than using a "sine bit" on the scenery object's properties, now a
;		stage overlay variable, scenery_sine, is sufficient to determine (along with 
;		high_bit), when the sine wave movement should be used.
;
; 20/05/10	Changed trip_bit to be bit 3 rather than bit 2 to stop conflict with fireball bit
;		which necessitated an extra object just to have head as scenery and an alien. Now
;		only 1 object is needed. Removed extra head object from tables.
;
; 16/05/10	Unrolled some more of the sort routine
;
; 15/05/10	Added info message for when paused. Flashes message while paused.
;
;		Removed unnecessary instrument sounds in sound effects left over from before RMT 
;
; 13/05/10	Added pause when any console key is pressed. Fire resumes.
;
; 07/05/10	Converted RMT 1.28 player XASM code to ATasm. It is to all intents and purposes
;		identical to 1.27. However the song size optimizations are better - Redid RMT song
;		exports. Slowed down high score music at end of song as per original.
;
; 04/05/10	Moved fire_limit out of stage overlay. It is only different on Stage 1. Put code
;		into init_stage to set it instead.
;
; 03/05/10	Tweaked 17 FPS wait timer so Stage 11 doesn't run out of pattern handlers. This
;		has only happened since the removal of wait_adjust code a few days back, which
;		was otherwise unneeded.
;
;		Removed missile_speed from stage overlay, made it fixed for all stages. Still
;		have minimum path length to fine control speed in the overlay.
;
;		New ATasm version 1.07 highlighted logical compare problems in rmtplayr conversion
;		from XASM. rmt_feat comparisons were checking just the label as true/false.
;
;		Flashing hexagon game_command code simplified
;
; 02/05/10	Added extra 2 cycle delay in DLIs for better compatibility with CPU upgrades
;
;		Tweaked 25 FPS wait timer so hexagons tie in better with colour changes
;
; 01/05/10	Added totally independant missile speed for missile types in stage overlay
;
;		Removed random slow missile for bosses. The dragons shouldn't do it, nor Wi Wi
;
;		Changed check for missiles and aliens onscreen when flashing hexagons game
;		command is used. They could still be displaying from the previous frame although
;		their properties at the current time would indicate they were dead. Created
;		variable offscreen_status which is updated in the aliens and missiles routines.
;
;		Changed the flashing hexagons to not flash every game frame, but every VBI. This
;		makes the flashing speed and colour consistent when the man is dying or the
;		continue game timer is on screen.
;
; 25/04/10	Game command do_set_stage_speed created to slow down stage 14 to reasonable speed
;		for boss. set_frame_rate subroutine created so code can be shared with init_stage
;
;		Fix to init_linked_kill so dead aliens are not included in the timed kill
;
; 10/04/10	flash_scenery pattern command changes
;
; 05/04/10	The simple detection method for an extra POKEY on old build instructions didn't
;		actually work on real hardware, or some emulators for that matter. Simply checking
;		that the extra POTs are zero is not enough. Thanks to Rybags for some ideas on how
;		to reliably detect an extra POKEY. Some had to be rejected purely because of
;		emulation problems. Code now checks if POTs count down or not in repeated POKEY
;		address space. If they don't then there is an extra POKEY. This works in the major
;		emulators. Code only run once when game starts rather than in init_stage now
;
; 21/03/10	check_man_collision could initialize man die or trip multiple times per frame
;		due to not exiting collision check after a hit.
;
; 20/03/10	Increased size of scenery events allowed from 30 to 34
;
; 12/03/10	Created demo for Atari Party 2010. Random stage on starting and no continues
;
; 07/03/10	Changed do_scenery_flash to check for active missiles and aliens and revert to
;		default colour rather than flashing if they are active
;
;		Changed scenery sequencers so that their objects are interleaved. This is to
;		allow the sequencers to have the same probability of getting objects assigned
;
; 28/02/10	Running at highest frame rate with little on the screen caused the game to crash
;		on do_man_continue because it does not wait long enough for sample to have finished
;		playing and re-enable man and vbi critical status. On a similar note, the high
;		score screen crashed because do_man_pause was also not waiting long enough at the
;		end of the game with similar high frame rates.
;
; 21/02/10	Past week or so has been a wild goose chase after stage 14's fast hexagons didn't
;		work very well. Was missing whole sets of up or down hexagons that are only on
;		screen a short time. Thought it was down to the simplicity of the scenery handler,
;		so had even written a much more flexible one. Went back to the old way of doing it
;		though when I realised that scenery event 2 stream has higher priority over scenery
;		event stream 1. Also there was a bug in scenery that prematurely stopped scenery
;		selection about half of the time. Things looking better after these fixes.
;	
;		Changed the random x position generation of scenery to be a bit neater and more
;		efficient, not that it mattered that much. scenery_spread variable added to scenery
;		overlay to specify the x range of scenery - whether wide for normal stages or
;		narrow for the bonus stages. Also cut down on the size of the scenery event streams
;		in the stage overlay. They only need about 30 events, not the 40 assigned.
;
;		Removed code that added extra control on the probability of scenery being generated
;		- just left simple one scenery object per every other z position (on average) code.
;
; 03/02/10	Game command to flash hexagon colour on stage 14 created. Not same as other flash
;		colour command as puts colour back to original colour when none on the screen.
;
; 31/01/10	Moved background bank from 122 to 124 to make room for stage data
;
; 02/01/10	Changed pattern handler to allow zero spacing on spread pattern. This gives best
;		results for spread planes on stage 13
;
; 01/01/10	Changed highscore screen text to be bright white. Previous dynamic adjustments still
;		producing unreadable text with some stage backgrounds.
;
;		Upped number of DLIs on stage 8 and 13 - the large cylinders at the top of the sky
;		didn't look good otherwise. Should be OK now cycles clawed back from the PM graphics
;
; 29/12/09	Bonus stage collision rewritten to only allow collision with Uriah head as per the
;		arcade game,rather than checking Uriah segments as well. Some code in collide_uriah
;		was optimised. Because of z freeze not restoring z vectors and timers, Uriah
;		segments lag behind in z position more than they should: adjusted pattern to go into
;		screen a bit further at the end of pattern so segments get to their smallest frame
;		before disappearing.
;
; 28/12/09	Bonus stage text overlay "X 50000 POINT" created. draw_counters name changed to
;		draw_overlays and code inserted there to do the draw of the text. Cleaned up an
;		unneeded write to temp2 variable in the draw counter code.
;
;		Scenery setup made slightly more likely by changing code in scenery routine
;
; 23/12/09	Made scenery less likely to be set up. Now only 1 in 4 chance of set up. Code not as
;		neat as the 1 in 2 chance though.
;
; 20/12/09	PM corruption could happen very occasionally during man dying due to timing of player
;		draw and DMA on/off DLIs. Beam position is now checked to be out of range of the man
;		before any player drawing takes place. Any tearing issues will also be fixed by this.
;
; 19/12/09	After high score entry if there were any continues remaining game restarted without
;		going back to titlescreen, since last changes to highscore and init_game. highscore
;		routine was checking for start console key and trigger being pressed, but not for
;		button being released from previous time. changed to use the button_pressed status
;		which does this in the VBI. Also changed the button press and acknowledge code to
;		not use inc and dec anymore, in case maybe something like an autofire trigger allows
;		them to get out of sync, as acknowledge could take 4 VBIs or more.
;
;		Game continue did not reset vbi_count after countdown timer causing it to wrap by
;		staying on the same frame for longer than during gameplay. This caused an excessive
;		delay before displaying the next frame after deciding to continue.
;
;		Removed some leftover code in do_man_draw
;
; 18/12/09	On game continue man didn't pause with left/right only control for a while. Added
;		extra man command step called do_man_continue to allow this to work like the normal
;		continue when lives are still left.
;
; 15/12/09	pm_dma_on and off code didn't need carry cleared on add, and their values were able
;		to be tweaked to give another 4 scanlines without pm dma on.
;
; 14/12/09	move_man changed to calculate background x_scroll rather than lookup to save having
;		an extra bank switch just for the lookup. Could have moved it into RAM as it's only
;		a couple of bytes, but penalty for calculating is only 2 cycles.
;
;		man frame numbers for facing left/right swapped for ease of mapping from x position
;
; 13/12/09	init_game wasn't been run after highscore at end of game, causing lock up bug when
;		trying to start game again. start_game was skipping essential code. Changed highscore
;		to go to init_game instead, and made init_game check for button press to know to
;		skip titlescreen or not and then run start_game.
;
;		Players for man drawn by using compiled sprite method now. Changes to move_man,
;		do_man_draw and data associated with do_man_draw
;
; 09/12/09	Set NMI vector in init_stage just in case it has not been restored by the last DLI
;		Also set in highscore routine now. Init routine changed to set NMIs to RTI only.
;		Hoping this will fix bug where high score was just starting to be displayed and
;		then locked up immediately - looked like VBI was not running as it should be. The
;		changes to the NMI system the past couple of weeks could possibly have left the
;		NMI pointing to a DLI rather than the NMI detect routine.
;
; 06/12/09	pm_dma_on and pm_dma_off setting added to check_end_game. changed uriah pattern
;		commands to use the shadown registers for turning players and player DMA off and
;		on. Removed setting of player on from title screen code as DLI now does it all.
;		Code for setting player DMA on and off now be complete (excepting any bugs).
;
; 05/12/09	pm_dma_on and pm_dma_off setting added to man death and init_stage man positioning
;
; 04/12/09	New NMI system's DLIs more or less finished. All that should be left now is the
;		setting pm_dma_on and pm_dma_off at the correct places for man death, uriah and
;		game continue counter.
;
; 29/11/09	Put back first moveable DLI write into main code. The next DLI can be found out
;		without too much difficulty.
;
; 22/11/09	In order to do the player DMA switching on/off am rewritting NMI system. Now the
;		first moveable DLI is positioned by the top DLI as per all the other DLIs. It is
;		slightly less efficient than the old way, but the position of the next DLI needs
;		to be known in order to switch on DMA at the right time.
;
;		Sped up the NMI determination by judiciously checking on interrupt type only
;		when needed, and using self modifying jumps.
;
;		DLI routines have spread out past their one page limit by jumps out of their page
;
; 14/11/09	Testing switching on player DMA just before required in DLIs
;
; 08/11/09	Optimized sum_pattern a bit and added variable sum_object to save having to
;		search through all objects to find the sum pattern's object when ending pattern
;		This required change to init_alien to set up the variable.
;
; 07/11/09	Bug in sum_pattern was stopping stage 8 ending. If a sum pattern had its own
;		object that was a multi-hit object, it wasn't zeroing pat_kill properly (which
;		is what indicates pattern handler is finished). Also there was an incorrect
;		assumption that the object should be killed automatically, as other sum patterns
;		with objects are all indestructible on their own. Put in a check to not kill it
;		if it is a destructible object.
;
; 05/11/09	Stage 2 boss incorrectly triggered debug check on pattern validity. Sum pattern
;		is exception to quantity of aliens other than one with zero spacing. This is
;		only because zero is an illegal quantity due to a quirk in the code.
;
; 25/10/09	Changes to pattern 39,40,41 to make them take longer
;
; 11/10/09	Pattern decoder changed to remove immediate looping feature and vector combine
;		function - was over complicated. Now just using extended range bytes when needed
;		for y position and frame change
;
; 07/10/09	Fixed missing x register initialize for do_man_continue in check_end_game
;
; 05/10/09	Changed init_sample wait to miss NMI to use fewer bytes
;
; 27/09/09	Removed scenery size changes. Old width weighting better represents man being
;		hit by scenery or not. Also removed man size check changes too. Made the spacing
;		of scenery in a row smaller again. Man cannot squeeze through now though.
;
;		Fixed regression in unpack_rle where 16-bit lo byte of 0 does 256 too many bytes
;
;		Changed spacing of scenery in a row and man width
;		Made scenery sizes be more weighted to average width than maximum width to help
;		with the man being able to squeeze through the scenery in a row
;
;		Fixed timing problems in robot patterns 40 and 41 - were catching up pattern 39
;
; 26/09/09	Changed scenery objects in a row to always exclude one object rather than applying
;		just a random chance that the objects will be missing. This is turned off with
;		scenery_row in stage overlay, causing all 4 objects to appear in a row. scenery and
;		sequence_scenery_events routines changed.
;
; 19/09/09	New "easy hit" height sizes created for bullets
;
; 13/09/09	Changed option on cart banks 0-126 to diagnostic cart with init pointing to code
;		in RAM to switch to bank 127 and do a cold start. This traps Reset without the
;		memory being cleared of the init code in RAM.
;
; 04/09/09	Increased max_objects from 80 to 96. Had to move some variables around to fit
;
;		Fixed stage intermission screen bug not showing gap for stages greater than 9
;
; 23/08/09	Bug in decode_pattern not restoring pattern handler to x when immediate looping
;
;		Remove end of June's changes to divide as is messes up 3d aliens y position
;
; 22/08/09	Bug in ATasm reusing .Y as a variable in move_man corrupted assembly when data for
;		man was moved slightly. Strange bug, but using another variable fixed problem.
;
;		Added game command to set or flash colour register. Re-initialize colours added to
;		init_stage.
;
; 19/08/09	Change colour registers around in VBI so that red is not the same colour register
;		as the score and lives text. This to allow colour flashing on stage 9 boss robot
;		and top grid stage colour changes on hexagons. All sprites will need converting
;		again and modification to colour mapping in the tools needs to be made.
;
; 15/08/09	Pattern decoder given ability to combine segments into one vector buffer entry.
;		This allows for greater range of y vector and frame changes. Loop also allows
;		for this now so segments can be repeatedly added a certain amount of times.
;		This loop functionality is intended for frame changes which can only go back or
;		forward one frame at a time normally. Will refer to it as "immediate" looping.
;
; 13/08/09	Increased address offset range from 4K to 8K for pattern sequencer. Changes
;		to init_pattern and stage data stream.
;
; 08/08/09	Reworked check of valid scores as blank scores were allowed through sometimes
;
; 01/08/09	Fixed option key check - boot disk was not enabled in cart option byte. Tested
;		on real hardware and working OK.
;
;		Fixed check of valid saved scores to load from upper memory rather than junk
;		Also fixed problem with 10's digit zero missing from generated high scores
;
; 31/07/09	All screen transitions now switch the screen on and off only when VBLANK is
;		in progress. Tested on real hardware and working OK.
;
; 27/07/09	Put in option key check on init to allow AtariMax cart to be re-flashed and
;		set cart option for disk boot.
;
;		Removed incorrect stop_sound calls in init_kill_man and init_trip_man
;		
;		Changed stop_sound to use built-in RMT command rmt_silence
;
;		Changed wait_vblank to wait for same VCOUNT value as when VBI is in progress
;
;		Began serious attempt to make screen transitions totally clean. All screens
;		must be enabled and disabled only during VBLANK. Started on init_stage code
;
; 26/07/09	Tried to stop screen roll on return to title screen by changing init_stage
;		Transition from highscore to game start/titlescreen still is glitchy though.
;
;		Changed sample playback routine to use self modifying code to speed it up at
;		suggestion of Avery Lee. He also suggested a move to zero page to gain a few
;		more cycles.
;
;		Also put delay in init_sample STIMER write due to interrupt hitting VBI in
;		Altirra emulator. Could happen sometimes on real Atari as well. Thanks again
;		to Avery Lee for the explanation.
;
; 14/07/09	Created load_highscores and save_highscores to transfer highscores to high RAM
;		so protected from cold start, as warm start unviable.
;
;		Made attract sequence call init_game rather than init when starting over
;
;		Removed trap_reset code now it has had to be embedded in every bank
;
; 12/07/09	Too many problems to get reset to do a warmstart. Memory 200-3FF would need a
;		scattering of OS variables left untouched in order for it to work properly.
;		I need the memory area for other things, so will have to suffer a coldstart
;		every time instead. Will have to put the score in high memory to save it from
;		getting overwritten.
;
; 11/07/09	NB Reset fixes only work with Atari800WinPlus. On real hardware and other
;		emulators, pressing the reset key locks the system. This seems to be because
;		a warm start isn't happening, and the trap_reset routine in RAM is being wiped.
;
;		NB Volume problems with Bonus music channel 3 (09/07/04) are also due to
;		emulation problems in RMT and Atari800WinPlus rather than anything else. Put
;		back original version of Bonus stage music.
;
; 07/07/09	Reset behaviour regression after changes to cart type. All banks except 127 now
;		set up interrupts again, and just run init_game. Changed init_game to make sure
;		man status set to dead.
;
;		init_game changed to properly initialize grid tilt values in case of reset
;
; 06/07/09	init_game jsr to insert_credit - no return was in insert_credit
;
; 05/07/09	Bug in highscore screen when adapting colour to background - wasn't masking off
;		bit 0 and some stage colour data has bit 0 set for some reason.
;
;		Make AtariMax cart do normal OS initialize rather than as a diagnostic cart.
;		This is to allow option key to work to allow re-flash of cart.
;		Moved routines around between banks 127 and 126 so that high score routines will
;		run in bank 126 rather than 127. This should stop score being cleared on reset.
;
;		Added code to init_missile to make bosses throw in slow missile every 1 in 8 
;
; 04/07/09	Added debug test for failed clipping off left. Alien patterns are not clipped at
;		all, and if designed badly they can allow sprite into variables stored in far
;		right of screen memory. Robot pattern 49 had to be fixed.
;
;		Bonus stage music channel 3 too quiet when single Pokey. Changed volume levels
;
; 03/07/09	Made maximum z_clip objects as large as possible in sort_table - 12. 
;
;		Put titlescreen back to 1 pixel off screen bottom. Amended debug_clip to deal
;		with that when running titlescreen (aka stage 0). Moved setting of start from
;		stage into exit from titlescreen rather than entry into it so stage 0 can be
;		tested for.
;
; 02/07/09	Put in much better debugging for failed clipping off bottom and right to find
;		infrequent crash bug. Bullets were getting crazy high values of z position,
;		causing incorrect frame bank lookup for sprite object address. This turned out
;		to be an incorrect assumption in the initialize of bullets that the man status
;		value in accumulator would be 0, when in fact it will very occasionally be 64.
;
; 28/06/09	Changed divisor for all x pos divisions. Adding 4 to it, rather than 5. This
;		looks better because the object sizes are not strictly accurate, as they are taken
;		from the very front of the screen rather than the z=1.25 line.
;
;		Fixed bug with the init_rmt clearing Pokey registers when sample playing, causing
;		sample playing to crash. This could happen if you die just before boss music is
;		initialized.
;
;		Oranges sometimes went off bottom of screeen,just. Amended data in sine table
;
; 27/06/09	Code from this date corrupt in unknown way. Hangs during Title screen transition.
;		No code deliberately changed, but restoring older code made it work again.
;
; 13/05/09	Man foot not being cleared when going up after sample play bug fixed. Had been
;		introduced by recent changes to do_man_anim. do_man_anim must not fall through
;		to do_draw_man after VBI man routines enabled again.
;
; 13/04/09	Address of backgrounds now includes bank number as they don't fit in one bank
;
; 20/03/09	Added game continue limit check. Changed do_man_flash to not play "get ready"
;		sample after all continues used up.
;
; 17/03/09	Fixed glitch on PM graphics when clearing continue timer. Write a blank char
;		instead of clearing whole PM memory.
;
; 15/03/09	Fixed bug with vbi_count and game continue while waiting for continue timer -
;		vbi_count wraps back to a high positive number causing a delay in resuming the
;		game after pressing button.
;
;		Fixed bug where do_man_anim man run frame animation doesn't get updated before
;		handover to full control.
;
;		Remove unnecessary check for man_lives in do_man_getready and unneeded variable
;		man_run_frame and code in do_man_anim - frame_count is already available.
;
;		Fixed bug in continue countdown where button press check only done every second
;
; 14/03/09	Man should stand before game over continue countdown. Changed do_man_flash to
;		go to do_man_draw before exiting when no lives left.
;
;		Removed clear of button pressed in joystick off section of move_man so that the
;		button can be checked when waiting for continue game. code put into bullets to
;		ignore button when joystick off. do_man_flash and init_stage changed to reset
;		button pressed just before resuming action.
;
;		Fixed do_man_getready so man run frame animation doesn't get stuck on handover
;		back to full control - frame_count reset removed.
;
;		end_game development so button is checked and do_man_continue is performed to
;		make game continue. insert_credit created as a subroutine as needed here as well
;		as in init_game
;
; 08/03/09	Continue counter now appears in middle of screen and different colour than man
;
; 07/03/09	First draft of end game continue counter implemented
;
; 28/02/09	Finished the basic stage intermission screen. Just shows the word "STAGE" and
;		the stage number.
;
; 23/02/09	TriangleA frame error fixed. Corruption of data in spreadsheet
;
; 15/02/09	Experimental code to display next stage presentation screen while calculating
;		background for next stage, rather than just a blank screen.
;
; 13/02/09	Countdown timer code for removing leading zero changed to be smaller. Code only
;		works when timer is two digits or less though. Would have preferred to have made
;		a general routine to deal with any number of digits, although this is not needed.
;
; 12/02/09	Countdown timer code created for Initial Entry Screen and cleanup code for when
;		end character or backspace character are selected when the timer has expired.
;
; 08/02/09	Adjusted speed of White Summer song and moved track 8 to unused track 7 so plays
;		with the modified RMT player.
;
; 07/02/09	Moved initialize of high scores into cold start only, so it is reset protected.
;		NB More work needs doing to what is done on warm start - does more than needed.
;
;		Highscore selection line generated in code rather than copied from ROM as it
;		takes less memory.
;
;		Added White Summer song to High Score Entry. Song needs speed adjusting though
;		as it is quite a bit too slow.
;
; 06/02/09	Regression fix. DLI glitch on bottom of title screen logo where changes priority
;
; 03/02/09	Made cart a diagnostic cart for better control over initialization. Reason it
;		wasn't working before was down to PORTB and PBCTL settings which are needed for
;		PORTB to work correctly (needs setting for output or input etc.)
;
; 31/01/09	Nearly finished writing high_score routine. All features are present now. Just
;		needs tidying up and music adding. insert_high_score had to be changed slightly.
;
; 25/01/09	Slight rewrite of insert_high score to be easier to detect high score. Addition
;		of score_entry_status flag.
;
; 24/01/09	Created display kernel for high score screen to display grid and sky colours
;
; 19/01/09	Changed copy_title_dlis so doesn't have to be continously called on title screen
;		Optimized size of top grid stage DLI routine somewhat
;		Removed extra VBI routine made for high score screen. Using normal VBI and a flag
;
; 17/01/09	High score display created. insert_score finished. Score entry still to do
;
; 11/01/09	Moved make_background code into cart space only to free up some RAM
;
; 04/01/09	Added robot gun sparkle to title screen using PM graphics. Just the logo itself
;		left to animate correctly now.
;
; 03/01/09	Created DLI for title screen to switch player priorities. Had to make space in
;		the page used for DLI's by making 1st DLI on normal stages slightly less efficient
;		Reduced memory usage of init_stage in initialising DLI's required for stage types
;
; 02/01/09	Title screen created using in-game graphics engine and sprites
;		Simple animation engine created for man waving and mammoth's eye moving. 
;
; 19/12/08	Missile_speedup wasn't being reset to missile_speed required in stage overlay
;
; 12/12/08	Changed scenery spread to be less on Uriah stages to give chance of higher score
;
; 11/12/08	Quite a few patterns are repeats but just with more firing. Decided rather than
;		create separate patterns for them, added a missile firing time limit that is
;		governed by the stage overlay. The patterns have the extra firing in them, but
;		it will only be used if the stage fire_limit allows it. The limit is just a
;		countdown until each pattern can fire again. Code is a bit ugly though.
;
; 08/12/08	sort_index data was in screen clip area. Had to be moved, Found out that Stage 1
;		dragon going off left of screen had been crashing game since 01/11/08. Was not
;		crashing before then purely down to it not corrupting critical data by luck.
;		Then the move of variables around the clip space in November caused it to crash.
;
;		Commented out frame wrap code in aliens. Not needed anymore.
;
; 07/12/08	Missile vector position were being overwritten by screen memory since upping the
;		number of missile allowed. Moved them around the unused screen space away from
;		the clip area again.
;
;		Missiles were overriding higher priority sounds queued on the same frame. Put in
;		check to stop that happening.
;
; 06/12/08	Changed man y position top limit to 2 less as robots are now smaller and can be
;		avoided now. That was the only reason the limit was changed in the first place.
;
; 04/12/08	Doing title screen. Had to make all robot graphics smaller, they were incorrectly
;		sized compared to the other graphics.
;
; 30/11/08	Changed move_man so man is only drawn when frame changes or vertical movement has
;		to be made. man_frame variable made for holding current frame and comparison.
;
; 28/11/08	Stage 11 will need 8 simultaneous patterns. Moved things around a bit to make
;		more room for it. Tidied generation of vector buffer limit data.
;
; 27/11/08	Added an extra 2 vector buffers so can be up to 7 simultaneous patterns now.
;		This is needed to do robot "acrobats" totally correctly. Each robot will have
;		to have a separate pattern to stand on the previous one's shoulders.
;
; 19/11/08	Disable interrupts while setting up IRQ's for sample playback
;
; 16/11/08	Made scenery explosions drop slower than aliens and put in special checks for
;		boss segments to drop slowly too.
;
; 06/11/08	Sometimes sounds still not right due to AUDCTL needing to be set in RMT during
;		the sample playback, which was being suppressed until sample finished.
;		Have now added back the setting of AUDCTL in RMT during sample playback and have
;		created s_audctl which gets or'd with RMT v_audctl in the rmtplayr. Sample player
;		alone sets s_audctl giving full control of AUDCTL to RMT and the sample player.
;
; 03/11/08	init_sample wasn't including RMT AUDCTL settings leading to some of the more
;		complex sounds in Wi-Wi Jumbo being wrong during sample playing.
;
; 02/11/08	New music for Wi-Wi Jumbo (and some other end stage bosses) uses extra features of
;		RMT. Had to move rmt_player down a page again to make room.
;
; 01/11/08	Well guess what, there is not enough right clip area with the vector buffers' new
;		size. The right clip needs to be at least 12 bytes rather than 8 bytes assumed on
;		the previous comment. Moved vector buffers out from screen ram areas, into other
;		free ram. moved rmt_player down a page to make room.
;
; 13/10/08	Upped vector buffer sizes to 10. There is enough right clip area for this, despite
;		previous comments to the contrary. Needs size 10 for Stage 6 "balls" boss.
;
; 12/10/08	Added cutoff for when to apply x_scroll to scenery. Should look more like original?
;		Also allows for lesser x movement, so man won't be able to hide on the edges of
;		the screen to avoid scenery so much. NB Doesn't look much more like the original.
;
; 11/10/08	In init_stage rewrote size required table to check for all objects with the same
;		size rather than just checking if the next object along has the same size.
;
; 10/09/08	Increased number of sprites for bullets to 8 and missiles to 12
;
;		Added default missile speed to stage overlay file. Changed init_pattern
;
;		Added scenery row mask to stage overlay file to change probability of there being
;		a gap in a scenery row. This is to allow a solid row of objects with no gaps, as
;		well as the more usual rows with one or two of the objects in the row missing.
;
; 06/09/08	Rather than being absorbed, objects that require multi-hit should bounce the
;		bullets that don't kill them yet. Changed collide_objects to do this.
;
; 24/08/08	Rewrote draw_sprites to check y clip earlier and to not do x register restore
;
; 16/03/08	sine_table wasn't right after yesterday's changes. Extra entry was required to make
;		it right, apart from fixing the other data. This makes it have 17 entries, and even
;		though it's not that important, changed the random entry into the table in scenery
;		routine to allow for this.
;
;		Adjusted height sizes of bullets to make ships and gremlins at back easier to hit
;
; 15/03/08	Just spent several days trying to find the crash bug. It turned out to be an
;		incorrect frame lookup for one of the small bullet frames that only get used during
;		bullets bouncing back. It was trying to draw a large bullet at the bottom of the
;		screen with a small bullets centring data which went past screen memory.
;
;		Searching for crash bug found another problem to do with size calculations of
;		alien and scenery objects. The bottom of them was one pixel too low for size
;		calculations and one pixel too many added to give top position, leading to them
;		actually being drawn correctly, but with incorrect size. Swapped around low_bit
;		and top_bit for move_aliens check and changed all move explosion routines as well
;		as move_scenery and tilt_objects routines. Also had to fix divide by 47 table to
;		not round up as per the y_divide routine.
;
;		tilt_objects had missing sec before sine_table subtract. Changed it to add the
;		sine_table rather than subtract, to take advantage of always clear carry. Changed
;		move_scenery in the same way. Had to change sine_table too as it includes an offset
;
;		Since moving man y limit 2 pixels higher, grid at the new top position looked crap,
;		so tweaked the end of the z_scroll_lo table to make it look better.
;
; 14/03/08	Added missing sec in move_scenery before sine_table subtract. Without it this
;		meant the divide by 47 table wasn't being used for scenery y positions and they
;		were being calculated when they should have just been looked up.
;
; 12/03/08	Put in debug to draw_sprites to try and catch crash bug which is still happening
;		despite changes the other day. In fact it is now more frequent if anything. I
;		have no idea what is causing it now. It is not screen interleaved variables being
;		overwritten though.
;
; 08/03/08	Serious rare crash bug fixed. Had not allowed enough right clip space in screen
;		memory before using remaining space for variables, causing corruption to variables.
;		Only 4 bytes had been allowed due to miscalculation. At least 8 are required for
;		larger object clipping. Upped that to 12 where possible and 11 where some problems
;		memory aligning the vector_buffers. Reduced maximum vector buffer size from 9
;		down to 8 to help with this. This buffer size may not be enough on some patterns
;		with many rapid changes or large delays between the aliens in a pattern. It seems
;		enough for all patterns up to and including stage 5 though.
;
;		Allowed man y limit to be 2 pixels higher to be able to clear top of robots, which
;		is essential or game play is too difficult.
;
; 07/03/08	Problem with man frame animation is caused when variable frame rate alternating
;		is being used and the game is running fast enough that it can be ahead of itself
;		on one of the alternating frames and not the other. Removed unnecessary code from
;		sequence_man_events which initialise the man_run_frame variable - it only needs
;		setting at power on.
;
; 06/03/08	Changed scenery and init_stage to make scenery less sparse on Uriah stage so more
;		scenery likely to be hit - x range of -32 to 32 rather than -64 to 64.
;
;		Man run frame animation not smooth in PAL on Uriah stage. Using frame_count for
;		some reason does not give the frame required when sample is not playing. This makes
;		little sense and I cannot find the problem. Created another variable to do the man
;		run frame animation for main loop.
;
; 03/03/08	draw_counters was setting up an un-needed zero page - big counters only 7 high
;
; 02/03/08	Completed draw_counters soft sprite code for Uriah stage counters and pattern
;		command do_total_counters
;
; 01/03/08	No need for separate man command jump variables. Changed to use standard jump.
;		Renamed man_index to man_command, game_status to game_command
;
; 29/02/08	Pattern command setup and call changed to use index. No need for game command init
;
; 26/02/08	Rework started on Uriah stages:
;		No soft sprite for man running anymore
;		No PM overlay for counters
;
; 25/02/08	Changed so explosions don't get moved back to be seen when grid is still
;
; 23/02/08	Made 1/2 second timer a little more accurate so stage timing better
;
; 17/02/08	Precise timing of pattern and scenery start for stage 3 from step through on MAME.
;		Reduce DLI's on colour bars in sky to help tackle slowdown with stereo Pokey.
;
; 16/02/08	Occlude background in top grid stages fixed for screen layout changes
;
; 13/02/08	Off-screen check for missiles was not high enough to work for robot rockets
;
; 10/02/08	Fixed bug in set_first_dli. First entry in dli_buffer was not being checked for
;		being set, causing multiple problems when top grid on.
;
;		Fixed bug in sum_pattern - active_pat_count was being reduced twice when the sum
;		pattern had its own object and ending. Once on detect of no other patterns and
;		once on the kill of its own object, leading to a negative active_pat_count, and
;		the stage not ending. Not sure when this bug introduced as stage 3 dragon had been
;		working before screen layout changes - probably stage 2 boss improvements.
;
; 09/02/08	Fixed bug in set_first_dli where screen1 setting going into screen2 setting.
;		Fixed bug in copy_title_dlis that occurred after above bug fixed.
;
; 05/02/08	Changed move_scenery and tilt_objects sine table to be subtracted, not added.
;		Not fixed since screen layout changes.
;
;		Changed scenery pattern handler start delay from 5 to 2
;
; 19/01/08	Changed sample playing for beginning of stage - Now "you're doing great" is played
;		for all stages except stage 1.
;
;		Re-jigged explosion drop speed and time to live.
;
; 16/01/08	Added init_song into do_init_boss and added Squilla music. Another game argument
;		was created for passing the starting line of the song.
;
; 13/01/08	Put back stop nmi interrupts code in init_game, as man was observed to die once
;		as the game started, possibly due to this.
;
;		Fixed serious problems with IRQ's. VCOUNT sync value for sample start of 127 is
;		too high, and PAL couldn't sync with it sometimes, causing overruns into next frame
;		and other problems. After this had been corrected there was no need to set the
;		interrupt before syncing VCOUNT and clear afterwards. It turns out that the VBI
;		very rarely if ever interrupts the IRQ's as feared in the entry for the 11/01/08,
;		so fill of buffer in main code removed, sample buffer lock variable removed, and
;		using sample_size again to determine to fill buffer or not. Added a few safeguards
;		to make sure sample_size is always zero until sample in progress, and tidied up the
;		init_sample code. NB It is very important the VBI still checks if it has
;		interrupted an IRQ, as although this doesn't seem to happen, if it ever did then
;		the IRQ's that will take place in the deferred VBI will corrupt the registers.
;
; 11/01/08	man_trip command could finish too fast when frame rates set high, running into the
;		do_man_die command, causing all sorts of glitches. Wrote a new command to hold
;		timer until sample end, called do_man_wait.
;		Some man commands were renamed:
;		do_man_wait becomes do_man_pause as it doesn't wait on anything.
;		do_man_run becomes do_man_anim as it is now used for man tripping as well.
;		do_man_trip just becomes do_man_wait as it waits for the sample to end
;
;		If enough VBI's in a row interrupt the sample playing IRQ it was possible for the
;		buffer to empty, causing sample to hang. Calling the fill buffer code from the main
;		code as well as the VBI now. Although the main code can't always fill the buffer on
;		it's own because of the frame rate, it should prevent this very rare issue. Had to
;		create fill_sample_buffer_lock variable to lock the VBI from the fill buffer code
;		when main code is filling the buffer. Using this instead of sample_size now to
;		determine call to fill buffer in VBI or not.
;
; 10/01/08	Changed frame alternating so it works for PAL and NTSC giving available average
;		frame rates of 25,20,17 and 15. The engine struggles at 20, so the 25 is probably
;		superfluous. New game_speed_table created with frame counts required for speeds.
;		man_run_frame renamed to frame_count as it is now used for this as well. Changed
;		frame_count code slightly in VBI to save an extra load when it wraps.
;
; 09/01/08	Implemented PAL frame speed alternating. There are now 4 entries for game_speed
;		which are indexed by the same counter used for the 4 frame man run animation. Of
;		course only 2 are needed, but no point in using another counter. init_stage changed
;		to assume NTSC speed is given in stage_speed to make code easier on the adjustment
;		to PAL frames. Changed values in fps_table to be NTSC rather than PAL, and removed
;		kludge of using fps_table+1. The alternate fps technique looks slightly odd, but
;		PAL and NTSC run almost exactly the same speed and works better than other speedups
;
; 06/01/08	Experiments on adjusting the scenery speed by skipping the z update every x frames
;		look pretty jerky and dire even only skipping occasionally. Will keep 15fps base.
;		Experiments with different man speeds for PAL and NTSC also not successful. Have
;		PAL frames switching between 16.67 and 12.5 every other frame to be closer to the
;		NTSC rate of 15. Just leave the PAL man speed that little bit slower than NTSC.
;
; 05/01/08	Fixed a problem with sound_queue being corrupted rather than cleared in init_sound.	
;		Stereo/mono patching of RMT moved into init_stage out of init_rmt. init_rmt renamed
;		to init_song. Stereo_status flag created to keep sound effects and RMT synchronised
;		to either stereo or mono.
;
; 04/01/08	Moved check for song_status after TV type adjust in VBI - saves a couple of cycles.
;		Stereo support added back now that single channel sound effects seem to work better.
;
; 30/12/07	Tried to make single pokey sound effects use the channel more effectively:
;		Sound effects no longer get paused when a sample is played, but continue silently
;		until the channel is available again.
;		Even though there is only one channel, two sound effects are allowed simultaneously
;		now. As with the sample playback change above, a lower priority sound can continue
;		in the background until the channel is available again.
;		The sound effect priority selection code had to be beefed up in init_sound.
;
; 24/12/07	Begin work on code for more intelligent sound fx playback.
;
; 22/12/07	Tidied up VBI some more. Moved man_flash_timer inside VBI flip screen code - with a
;		small tweak it is faster having it in there.
;
;		Rename flip_count to flip_screen. A hangover from the triple-buffered version.
;		Changed new_screen to use flip_screen for faster check on whether to start erasing.
;		Moved reset to main cart bank on new_screen exit into main loop. Smaller code (and
;		one less branch) in new_screen now, as there are multiple exits in new_screen.
;
; 16/12/07	Removed more code from VBI. Gone back to writing and erasing the first moveable DLI
;		in main code rather than VBI. This saves a few cycles over doing so in the VBI. Added
;		set_first_dli to end of move_dlis.
;
;		DLIST addresses calculated as part of flipping rather than lookup up now. Changes
;		to VBI and new_screen. dlist_index and vbi_count variables no longer needed.
;
;		Removed need to reset colour_buffer_read in every VBI. colour_buffer_read is reset
;		in the last dli (for free) and the new buffer is selected only in VBI on screen flip.
;
;		Made draw_screen_index use actual offset of screen 1 and 2 rather than 0 or 2 index.
;		Renamed it to just draw_screen. No need for draw_screen_a now, just using draw_screen
;		move_dlis buffer selection needed changing.
;
;		Fixed copy_title_dlis although it probably won't be used on the animated title screen.
;
; 12/12/07	Moved DLISTS onto page boundaries to save a few lookups and writes in the VBI.
;
; 09/12/07	Changed RMT code to latest 1.26 version (see rmtplayr.asm)
;		Some minor bug fixes to FEAT_COMMAND5 and FEAT_COMMAND6 assembly.
;		Some extreme conditional assembly will make the routine smaller, but unfortunately
;		I don't think there are any speed benefits for Space Harrier.
;		Raster's new conditional assembly code is very complex, and although the MAC65
;		conversion is logically equivalent and does assemble cleanly now, I should probably
;		check through the generated code very carefully later on.
;
;		Removed PATCHx labels in RMT code, using native labels where possible. Only major
;		changes are in SetPokey now - SetPokey1 and xtrack3 labels are only added labels.
;		Changed RMT SetPokey code to write $d218 AUDCTL2 earlier to do away with PATCH6
;
; 08/12/07	Made fill_sample_buffer do 16 bytes at a time and only check for buffer full at
;		end of each block of 16. NB This caused deferred VBI to take longer sometimes, and
;		if a sample playing IRQ was outstanding the deferred VBI must be skipped. This is
;		because the registers will get corrupted if another IRQ interrupts before the first
;		IRQ has finished, due to not using stack to hold them. Having an outstanding IRQ is
;		fairly rare, and only 1 in 4 deferred VBI's are needed to keep the buffer filled.
;
;		sort_index-1 no longer needed due to check_object_collision changes. changed in it
;
;		moved man bullets to 1 pixel above ground - 1 higher for easier scenery hit
;
; 06/12/07	One sample per byte implemented for speedup of playback routines
;
; 01/12/07	Set boss_status on init_boss and put check in init_alien and init_kill_man
;
; 28/11/07	Added variable for boss status so sound effects can be stopped and Wi-Wi Jumbo done
;
; 27/11/07	Changed check_object_collisions to not check in front of bullet, only at, or behind
;		bullet. z-2 to z range. This is to avoid being able to kill some low aliens when man
;		is running. Code is not so elegant though, as bullets will sometimes have to be
;		checked against other bullets, unlike previously with z-1 to z+1 range (bullets will
;		be spaced at z, z+2, z+4, etc. as they move in 2 z jumps)
;
; 25/11/07	Finishing off changes to object height and width calculations. Changes made to the
;		calculations due to screen layout changes were too inaccurate; using full height
;		of object as data was causing the bottom of an object to be 2 pixels too great when
;		the middle of the object used as y position. Changed data to be height -1 and also
;		put back the needed setting or clearing of the carry. Same changes with width.
;		Reorganised setting of alien position to avoid duplicate code in middle setting and
;		bottom setting - this had been ugly since screen layout changes.
;
;		Kill_alien hadn't been changed for new screen_layout. Changed sc to ac for top
;		positioning of explosion.
;
; 24/11/07	Swapped around low_bit and high_bit of object properties to make code more efficient
;		positioning aliens since screen layout changes. Just means carry takes on the needed
;		value when using height -1 rather than height alone without an extra shift needed.
;		Reshuffled object_score and scenery_y data to reflect change of bit positions.
;
;		Redone y_divide to deal with zero value rather than code outside of the call. This
;		enabled lookup of special case of on ground to include screen offset in the data,
;		gaining a couple of cycles. Special case of zero is slower now though.
;		Change also allowed a small enough loop in tilt_objects to be able to use branch 
;		without needing a jump. Was the change to y_divide worth it just to look neater?
;
; 21/11/07	Moved man bullet down 1 pixel from man to make some patterns harder to hit when
;		man is on ground. Changed patterns for stage 2 gremlins to be higher. Changed
;		do_reset_sum_loop to reset missile speed to slow for first few missiles after a
;		head has been hit - but then to speed up. Redone pattern data for stage 2 boss.
;
; 18/11/07	Trying to make stage 2 boss heads better. Changed sum pattern to check for death
;		of pattern linked to itself so sum can end. Heads are always circling and moving
;		forwards, and the sum pattern holds them back. Then when sum pattern ends they
;		naturally move off the front of the screen. Created pattern command that checks
;		for a hit alien and exits loop to move pattern forwards - do_reset_sum_loop.
;
;		In collide_objects made pattern_temp get set with pattern number for pattern
;		command do_reset_sum_loop to detect hit alien.
;
; 15/11/07	Restored 3d conversion of y for aliens in tilt_objects. Code removed on 13/10/07
;		is necessary for 3d aliens. Code too large for loop but was able to use a temp
;		zero page variable in place of y_pos_2d_aliens to take less space.
;
; 11/11/07	Changed so missile speedup not done by pattern command, but constantly increases
;		and relies on init_pattern to reset to normal. pattern command too inconsistent
;		to do the speedup reliably. replaced yesterday's changes.
;
;		Added pattern command do_reset_sum_loop to check for end of stage 2 boss so that
;		heads will move towards man once hit. resets loop counter to checked value when
;		finds linked pattern head has been killed. Closer to original stage 2 boss now.
;
; 10/11/07	Changed missile speeds to use missile_speedup/4 as speed-up was happening too
;		quickly, and rate boss pattern command called harder to control.
;
; 04/11/07	Redone move_missile as boss missile speed-up could not increase speed enough to
;		ensure man always died eventually. Speed-up is not done by adjusting max_length
;		anymore, just by increasing the number of loops of move_missile that are done.
;		Also had to change init_missile and queue_missile so that the missile is aimed
;		the next frame after it has been displayed initially - to follow the man more
;		accurately.
;
;		Added off screen check for missiles in move_missiles as there are rounding errors
;		in the move routines that can't be fixed easily. Aiming higher than man was not
;		a good solution.
;
;		Moved missile_speed into stage overlay so speeds can change every stage
;		Stage overlay reorganized.
;
; 03/11/07	Extended character set to 64 characters. All alphabet drawn for high score table.
;		Redone top score line with custom characters.
;
; 31/10/07	Man was getting corrupted on dying and tripping in PAL mode. Traced eventually
;		to old sequence_man_events_vbi code left in move_man. Removed old code, but
;		puzzled why problem never showed up in NTSC, or how the old code was triggered.
;
;		Scrolling of background didn't stop during die sometimes in PAL mode.
;		init_kill_man was clearing x_scroll before setting man_status, leaving a small
;		window where the VBI could interrupt and set x_scroll again. Given that the
;		window was only about 30 cycles or so, it was surprising it happened so often
;		in PAL mode. Problem never manifested when in NTSC.
;
; 29/10/07	Fixed variable clash of pix_a and pix_b with dest_b causing background code
;		generation problems unless make_background was ordered very specifically.
;		Reorganised make_background more logically.
;
; 28/10/07	Start background code at $c000, then skip past hardware registers when needed
;
; 27/10/07	Background drawing code working again now
;
; 21/10/07	Decided to leave background drawing code similar to before screen layout change.
;		Doing A & B screens simultaneously makes for smaller code generated. The extra
;		overhead for set up (and clearing afterwards) is not too bad (200 cycles or less)
;
; 20/10/07	Fixed DLI's not cleared after pressing reset. dli_buffer+1 has to be zero rather
;		than dli_buffer as previously before screen layout changes. Clear of dlis on
;		dlists added to init_stage as reset pressed could leave a dli set.
;
; 14/10/07	Relocated variables/tables to unused portions of screen buffers where possible.
;		Removed unused table slot_addr_lo and hi
;		Separation of score_line and lives_line for relocation needed changes in init
;
; 13/10/07	Removed 3d conversion of y in aliens tilt_objects - it shouldn't be necessary
;
; 10/10/07	Fixed move_alien y as middle of object positioning with new screen layout
;
; 09/10/07	Missiles working as before again now
;
; 07/10/07	Changes to missiles to work with new screen layout begun
;
; 29/09/07	Added a frame size 1 for bounce bullets now they bounce back slower. Wasn't
;		needed when bouncing back 2 z positions per frame. Looks better
;
; 27/09/07	Random position of scenery from -63 to 63 was more likely to be 0 than any
;		other position - simplified and fixed code.
;
; 25/09/07	Bounce bullet was more likely to go vertical than in other directions. Changed
;		so equal probabilities for all angles
;
; 24/09/07	Changes to bounce bullets to work with new screen layout.
;		Made bounce bullet slower coming back towards man
;
; 22/09/07	Changes to tilt_objects and move_alien_explosions to work with new screen layout
;
; 20/09/07	Changes to move_alien to work with new screen layout
;
; 16/09/07	Changed init_sound to ensure sample playback is not overridden by effects
;		Changes to move_scenery_explosion for new screen layout
;
; 15/08/07	New 256 byte wide screen layout - changes to scenery move and collision done
;
; 13/05/07	Fixed problem with 2nd Pokey not always being exactly synchronized with the
;		1st Pokey on sound effects. Added an extra reset of registers to zero in the
;		init_sound. Don't see why this was necessary though, as the registers are only
;		ever set together elsewhere.
;
; 07/05/07	Changed sound effects to only use channel 4 and tried adding stereo support
;
; 29/04/07	Fixed set object number for missile type - everything was using object 0
;		Fixed set object numbers in apply_die_frames and kill_alien  
;
; 20/04/07	Add new size lookup code for aliens and missiles as per scenery and bullets
;
; 16/04/07	NTSC music speed adjust code added into VBI. song_speed and song_frame_count
;		variables created. When NTSC skip RMT player code once every 6 VBI's.
;
; 11/04/07	Fixed sprite144 and sprite240 which didn't have clc after the inx and iny high
;		byte additions.
;
;		Split constants out of framework so stage files can be assembled more easily
;
; 06/04/07	Rewrote copy routine so memory can be copied from banks to exact byte rather
;		than to nearest page. Allows better use of memory so copied banks can be exactly
;		next to each other in RAM.
;
;		Added stereo sample playback by writing another IRQ and added detection code to
;		the init_sample routine. Using AUDC4 rather than AUDC3 for sample playback as
;		AUDC4 is totally unused by Sal's music.
;
; 02/04/07	Deferred VBI changed to work in more simple way - check for IRQ, then just clear
;		interrupt and continue if not an IRQ. Otherwise exit to IRQ.
;
;		Fixed variable clash with NTSC stereo playback. VBI now uses stack for registers
;
; 31/03/07	Problem with RMT and NTSC stereo playback was that the VBI is overrunning into
;		the DLI's. I'm using variables to store the registers rather than the stack, and
;		sharing those variables between the VBI and DLI. Fixed other obscure noises that
;		were happening during switch between sample playback and RMT by ensuring AUDC3
;		is switched off fully before and after sample playback.
;
; 30/03/07	Making changes to allow sample playback at same time as music. The playback code
;		has to use 1.79MHz timing and 2 channels or the quality is very bad, so there is
;		some patching of RMT required so that it doesn't affect these registers when the
;		sample playback is happening. Not working correctly at the moment. Stereo mode
;		for NTSC sample playback causing screen glitches to appear that are not present
;		in PAL mode. I think these are when the VBI deferred rmt player is overrunning.
;
; 29/03/07	RMT player working OK, but stopping music for sample playback sounds bad
;
; 28/03/07	RMT player code inserted after testing externally
;
; 18/03/07	Fixed VBI to deal with outstanding IRQ by not doing deferred VBI. Although this
;		is a very rare event, it is critical it is handled right. The sample buffer fill 
;		is required to happen at least every 3 VBI's, but the careful arrangement of the
;		IRQ timing and minimal immediate VBI should mean it is never a problem.
;
;		Changed sample playback routine to use sample of zero to denote end of sample,
;		rather than checking the sample size being reduced by the fill. I don't think it
;		could actually happen, but the last 128 samples could be missed if the read buffer
;		pointer was exactly 128 samples when the last fill had occurred.
;
; 17/03/07	Got sample buffer fill working in the deferred VBI. This deferred VBI can be
;		interrupted, and it seems to be working correctly, except for the rare occasion of
;		the VBI interrupting the IRQ. When this happens it could be catastrophic to the
;		sample playback IRQ depending where in the routine it is interrupted. At the very
;		least, an incorrect sample nibble could be played.
;
; 16/03/07	Experiments with sample buffer being filled in VBI not yet successful. For now
;		will leave the buffer filling in the main loop, and nibble manipulation in the 
;		IRQ. The buffer is too small to do the nibble manipulation in the main loop, 
;		making for a slightly slower IRQ. VBI runs 3 to 4 times faster than the main loop,
;		which makes the buffer plenty big enough if it is filled then. Have optimised the
;		existing routines some more today - it will probably be good enough as it is.
;
; 14/03/07	Remove sample_queue option - no longer needed
;		Initial version of sample buffer code finished
;
; 13/03/07	Remove existing music code and data ready for RMT music player
;
;		Change sample playback code to use a small buffer rather than large cache
;
; 29/01/07	Splitting source code up into modules for ease of porting to Atarimax cart
;		or MegaCart.
;
; 20/01/07	Frame address lookup now handled by having addresses of the same frame size
;		kept in the same bank, indexed by object - init_sprite changed.
;
; 15/01/07	Fixed occasional poor quality sample playback. Code now waits for a particular
;		scan line to synchronize, rather than just the next one. If the scan line was in
;		the middle of a heavy DMA line then a precise start would not be guaranteed,
;		causing the IRQ's to not interleave cleanly with the DLI's.
;
; 08/01/07	Removing work to do with object sizes stored in object bank. Going back to an
;		improvement on the slot idea. (The idea of slots was to reduce the amount of 
;		object data so it can be handled more easily with faster addressing modes). 
;		Same size objects are now assigned the same slot, which allows more than the 23
;		objects with 11 frame sizes in the original slot scheme.
;
; 03/01/07	Code for tilt_objects rewritten to use banked width and height data. needs
;		more work as it requires switching back to "main bank" for fixed data.
;		dislike the idea of having object sizes in their own banks because of all
;		the switching back and forth that is required
;
; 29/12/06	check bullet collisions was not setting bullet limits correctly
;
; 16/12/06	move_scenery wasn't using new width data correctly
;		check_man_collision changed to use x_left and x_right
;
; 10/12/06	Continuing development of object frame data in banks. Height and width data for
;		move_scenery being worked on. Changing move_scenery to not store x_width, but
;		rather x_left and x_right as it calculates them anyway for clipping at this time
;		y_pos_2d_scenery data combined with y_bottom_scenery, as they will always be the
;		same value. Have to switch back to main_bank after every move_scenery object at
;		moment, because using some tables from there. May be worth getting them into RAM 
;
; 09/12/06	Banks being used to store object frame data. Slot number will not be needed once
;		code change completed. Sprite centring code changed now that y register is zero
;		at left edge of sprite, rather than the centre. This change to sprites makes for
;		less page faults than allowing the y register to be a large value. This can save
;		a hundred or so cycles on large objects. Should have realised that a long time
;		ago, but the sprite code generator never allowed for averaged cycles until now.
;		Object number field extended to include all sprite types, not just aliens.
;		Sprite draw code changed to select correct bank to find object's frame address. 
;		Bullet move code changed to set object for sprite draw
;		Scenery initialise code changed to set object for sprite draw
;
; 08/07/06	Draw_background optimise occlude background code
;
; 02/07/06	Start changing code for increasing background height to 26 pixels. This so that
;		objects can have centre up done as part of embedded code, rather than a separate
;		adjustment byte. Affects background as it shares code for setting the zero pages
;		for height, and objects need more zero pages to do embedded code centre up.
;
; 21/05/06	Removed do_grid_up flip count check, not needed since tidy of dli code on 23/4/06
;
;		Creating extra irq for splitting player missiles during Uriah stage.
;		play_sample initialises irq vectors for itself, init_cart only points irq to rti
;
; 10/05/06	Removed unnecessary cpx #0 and branch code remnant in 8-bit decode_rle
;		Start tidy up of code for draw and clear of dlis now it only has to do first
;		moving dli.
;
; 23/04/06	Tidying dli code up. fixed colour for score now put into colour_buffer rather than
;		depending on top_grid status check for first colour in vbi. Now the dlis can be
;		done with a read to colour_buffer+1 instead of just colour_buffer. This is then
;		the same as the code for the top grid dlis, so now code can be merged. 
;		Fixed bug in bit test of top_grid_status in move_dlis. Accumulator didn't have bits
;		0 to 5 set before test. Top grid status changed to always have these bits set and
;		accumulator loaded with top_grid_status before test.
;
; 09/04/06	draw_dlis and dli code improvements. draw_dlis only puts the first dli onto
;		the dlist now. There is enough time, instead of waiting for wsync, to get the
;		dli to remove itself from the dlist and put the next dli on. Saves quite a few
;		cpu cycles, by using otherwise dead time in the middle of a dli.Still need to get
;		it to work with top grid stages, but the concept is sound. Doing things this way
;		will more or less rule out doing colour changes on man too though - there isn't
;		much time left before the dli runs over now - which if it does, defeats the whole
;		object of the exercise of doing things this way.
;
; 23/03/06	Test code for proper Deferred VBI with priority given to IRQ sample playback
;
; 23/02/06	Changed copy routine to copy to page size rather than to individual byte size
;
; 03/01/06	Changed init_sprite to ora z_to_framex4 from clc, adc z_to_framex4
;
;		Sprite zero page setup rearranged so no unnecessary carry check done on first
;		zero page address being prepared
;
; 21/11/05	dragon1b sizes file had missing value for frame 0 height causing crash on stage 1
;		Had been a problem since 8/6/05 but not noticed until yesterday. Caused by size
;		file utility not substituting value from frame 1 when frame 0 missing as intended.
;
; 16/10/05	init_stage changes. no longer want counters initialised at start of uriah stage
;
; 25/09/05	Small change to init_alien - small optimisation in the code setting up the
;		"other object" - after uriah head the other follow objects get changed to segments.
;
; 07/08/05	Moved main data bank from bank 1 to 63 (on megacart). This so bank number of objects
;		can be defined as a label. frames.asm file is where the label is referenced, and
;		it has to be the last thing, or the wrong values go in there. Shifted up all the
;		other banks in accordance with the removal of bank 1. Bank number label should help
;		me make fewer mistakes repacking all the sprite data into the cart banks now that the
;		size of the sprite data is slightly less.
;
; 30/07/05	sprite zero page setup routines now finish by initialising y and a to 0. This is
;		because nearly all embedded sprite data frames required these values initially and
;		rather than having it stored in the data, it takes up that little bit less space
;		knowing they're going to be those values. NB This has required changes to the
;		embedded sprite conversion routine, and all sprite frames will have to be repacked
;		better into the cart banks again.
;
; 23/07/05	Uriah_status checked in move_man to denote no players required. man_timer is updated
;		in main loop code even for vbi routine - timer in vbi is too quick to be of much use
;		Man jump code worked on - Bresenham line draw again used to make sure man ends up
;		in the right place at the right time from any x running position.
;
; 19/07/05	Yesterday's changes can't work. When man is on Uriah, players are no longer required
;		- using vbi_critical_status gives no way of denoting that players aren't to be drawn
;		in vbi and that the vbi isn't critical (ie music is required). Also syncing the man
;		movement for PAL and NTSC to the patterns will be nearly impossible with the same
;		piece of vbi code.
;
; 18/07/05	Have decided that the VBI will be allowed to call the do_man commands as well as the
;		main loop code. This will enable a smooth jump onto Uriah. The vbi_critical_status
;		is used to determine whether the vbi or main loop is to be used - when the time is
;		critical the vbi can't be used for animation anyway. Have had to give the routine
;		its own jump zero pages (man_jump) now that it can be run in vbi.
;
; 17/07/05	Finished rewrite of man status check. We now have die_on, joystick_off and
;		vbi_anim_off as man states. The right combination of checks of those covers all
;		that is needed for the man's dying, tripping and interaction with Uriah while
;		allowing samples to be played (there is also vbi_critical_status added). Previously
;		weren't able to tilt grid while man was running for Uriah. screen_y_pos variable
;		has been created to allow tilting of screen while man is positioned differently -
;		this is essential for Uriah stages. move_man is where most of the changes done.
;
; 16/07/05	Maybe some good things are happening again - Created a decision matrix of all the
;		possible combinations of joystick-man-uriah interactions. It helped deciding what
;		states are useful. Referring to the matrix when coding has revealed some states
;		that are more overarching than I realised, and other states that are not necessary.
;
; 11/07/05	Trying to change do_man commands and man_status to provide the uriah man jump
;		initially has produced a huge turd of code. It is just not working out. Part of
;		the problem is that the music playback is not always wanted to be skipped when
;		there is no sample playback, as per Uriah stage start. Extra man_status bits
;		seem to be required. sample_status cannot be relied upon to determine music usage
;		as frequency switch gets done later when main code realises sample has finished via
;		sample status - vbi will try music playback before frequency switch of audctl
;		on occasion - plus there could still be a queued sample awaiting playback. I've
;		more or less given up - it's an ugly piece of shit, and I have no good solutions
;
; 05/07/05	Had missed unneeded man_status check in move_scenery and move_scenery_explosion
;
; 02/07/05	Carry wasn't been cleared in tilt_objects aliens when the tilt was added back.
;		Was sometimes giving a slight wobble to the aliens on man dying.
;
; 28/06/05	tilt_objects seems to be OK. Removing man_status code check from inside loops
;		of scenery and aliens. Removed man_status check in front of pattern handler.
;		Changed odd placement of bmi on aliens_properties in "aliens" to more normal.
;		moved "and" of ftimer_buffer to the end of queue_missile rather than in aliens
;		on return. This has finally freed up just enough bytes to have a proper loop
;		without a jmp round a branch. Happy. Removed check of man_status before dragon
;		rotate. Removed man_status check in move_alien_explosion. Removed man_status
;		code in move_alien.
;
;		aliens has to call move_alien in a place in the code where a negative z does not
;		get picked up until the next frame. Added a bmi to avoid ugly values getting into
;		the variables in move_alien that could possibly cause harm. Only one alien pattern
;		goes into negative z by design, and that is for the boss heads on stage 2.
;
; 27/06/05	Started implementing tilt_objects routine to be used only when man dies. This
;		will allow the removal of several checks of man status in the scenery, aliens
;		and other loops. This needs testing properly, especially on 3D alien patterns.
;
; 26/06/05	decode_pattern to stop a branch out of range was doing code that 
;		pattern_handler number before end of pattern had been checked for. Changed
;		position in byte of the new "anim_mirror_bit" so it could be shifted into
;		carry rather than testing for it with "and", making for a smaller routine
;
; 25/06/05	Implemented rough code for animation frames - a few branches out of range need
;		attending to properly rather than just sticking in branch and jumps. Animation
;		frame changes are now possible simultaneously with x position changes, rather than
;		choosing which one to do for a pattern segment. 2 bits are used for the animation
;		with the following meanings: previous frame, same frame, next frame and
;		wrap frame to default object frame.
;
; 24/06/05 	Starting reworking of animation frames so they are not done by hindering
;		the use of x positioning while animating. Have removed hit_count property
;		of patterns to make room for an animation mirror property. Hit_count is now
;		specified by bit 7 of stream_spacing - the hit count required and the
;		quantity of animation frames is already kept there.
;
;		frame animation code being changed in "aliens" and "decode_pattern"
;
; 10/06/05	Explosion frame 0s10 had wrong bank number in "frames" causing crash sometimes
;
; 08/06/05	Corrections to full width collision check routines
;
; 07/06/05	Start change to using full width rather than half width for collision checks
;		- routine is a couple of cycles quicker.
;
; 05/06/05	Yesterday's wrong score line colour fix doesn't work because it is quite
;		possible that a screen flip is outstanding when the top grid status is set
;		and before any of the other top grid setup code has been run. Have made
;		the do_grid_down wait for any outstanding screen flips before setting the
;		top grid status to on. It is only because so little is going on when the
;		grid comes down that the game can get ahead of itself like this. I think the
;		top grid code is a bit of an ugly kludge at the moment, and should probably
;		be rewritten properly at some point, although I'm struggling on the best way
;		on how to do so.
;
;		Renamed top_grid_pos to sky_start_pos as it should more accurately be called,
;		especially as the top grid is not switched on most of the time.
;
;		Tidied up draw_dli routines a little after the top grid changes. Also removed
;		unnecessary jsrs to draw_dlist1 and draw_dlist2 from draw_dlis and new_screen 
;		- all they need is a branch.
;
;		Tidied up setting of dlist_index in VBI. Only needs to toggle now with an eor
;		and not cycle through dlists - a hangover from the pre-cart version.
;
;		Added background occlusion by top grid for new background draw method
;
;		Had to up the maximum amount of DLI's allowed to 50. Made it 52 to be safe
;
;		Had to tweak z_scroll values so top grid animation doesn't jitter at back
;
; 04/06/05	Removed background_y variable, it is just an extra offset to the horizon
;		variable. Don't know why the variable was created, as the offset still only
;		needs to be calculated once in the code that uses background_y.
;
;		Stopped using stack for storing register values in interrupts - gain a few
;		cycles by using zero page locations instead.
;
;		Check on top grid status for dealing with first colour put inside screen
;		flip code in VBI. Has to be done or there can be a couple of frames where the
;		score line colour is wrong when the top grid just starts to come down. Also
;		has the added benefit of optimising the code for the writing of the first
;		colour into the background. A new variable called "first_colour" created
;
;		Removed extraneous write to colour buffer at end of floor grid in move_dlis
;
;		Created a different DLI for after the Antic Mode 2 DLI, as more work can be
;		done before the WSYNC command on the Mode D lines, freeing up cycles.
;
;		Changed top grid down and up speed to be twice as fast.
;
; 02/06/05	Changed uriah_stage flag in overlay file to stage_type - now includes whether
;		a top grid stage. Required for denoting different DLI scheme for top grid
;		Added code to init_stage that sets the extra fixed DLI required for top grid
;		stages. Sets different DLI addresses required for top grid there too.
;
;		Added dli_start_pos since the top grid stages require dli position 4 to be
;		written whereas normal ones do not, because of fixed DLI. dli_start_pos has
;		to be 3 on top grid stages, and 4 normally.
;
;		DLIS are now initialised in VBI. Writing to the dli_addr_init can be written
;		anytime safely.
;
;		Rewrote scroll_sky to try prevent crash when top grid down and scrolling up
;		sometimes. Made much simpler, but has to search from beginning of sky_pos
;		to find next displayable sky DLI when top grid is on. Turned out that this
;		was not the cause of the problem. Seems that if the top grid is not started
;		low enough down, then it can somehow be scrolled above the top score. Fixed
;		in move_dlis(top grid) - top grid positions at zero are skipped until the
;		first non zero one is found, rather than assuming the first one is non zero.
;
; 24/05/05	Testing Antic 2 DLI - changes:
;		Antic Mode 2 DLI always turned off on DLIST - DLI on blank above triggers
;		extra unneeded position means having to use colour_buffer+1 in the DLIS now
;		It's only a test, as sample playback terrible when on - but it will be OK
;		if it is only used on top grid stages, as man cannot die when grid is coming
;		down.
;
; 22/05/05	As expected Stage 4 top grid needs rethinking now that the score line is part
;		of the sky. Unfortunately, the idea I was planning doesn't look so good now.
;		Just having the whole score line change colour when the top grid comes down
;		doesn't work at all well - trying to allow for the grid to start at the top
;		of the score causes incorrect colour animation until the grid is far enough
;		down the screen to show all the animation lines. The lines that are still
;		"hidden" in the score line are what causes the problem. Looks like we need
;		to do the DLI changes for real on the Antic mode 2 line, which is going to
;		be messy, since we will be mixing modes, and will have to do lots of WSYNCS
;		in the Antic mode 2 line to get at the places that need the colour change.
;		This is going to need a dynamic DLI routine, so I'm going to experiment on
;		Stage 3 DLIS being able to go off screen first because it'll be easier.
;		NB the sample playing will work properly when tied into this Antic mode 2 DLI
;
; 15/05/05	Finally getting to the end of stage 3. Some changes to the Godarni pattern to
;		make him fire more.
;
;		Moved whole screen down one scan line so sample playing clashes less with DLI
;		WSYNC. Had been incorrect since change from Antic 3 score line back to Antic 2
;
; 10/05/05	Changed init_missile's setting of maximum length (which determines speed)
;		A "slow down" speed is now applied to the vector. rather than a slower
;		default vector being assigned if the vector is "too fast". This should make
;		the aliens very close to front of screen problem below less noticeable.
;
; 09/05/05	Tweaked default fireball speed up a bit as missiles are still a bit too slow
;		when aliens very close to front of screen, making it harder to avoid them
;		than it should really be.
;
; 08/05/05	When fireballs are fired z close to the player and at a tangent, they slow at
;		front because double speed for fireball move routine checks for z=0 and won't
;		move them faster so man collision check can be performed. Changed move_missile
;		to check z properly - only when it is going to go negative should the speed up
;		be ignored so a man collision check can be performed
;
; 07/05/05	Reworked add_score routine and character set organisation. The blank character
;		is now the first one in the set, and the numbers are at the end instead of
;		characters 0-9. This made checking for a high score much quicker and easier,
;		and made the code for removing trailing blanks better, although it loses
;		slightly on speed by having the numbers offset (along with having the blank
;		character as number 16 is was better in some ways)
;
; 02/05/05	Changed pat19 to start at y=86 instead of y=90 - was possible for man to be
;		killed by the ships going off-screen sometimes, when that shouldn't happen
;
; 01/05/05	Turns out reset key hasn't been working properly when cart is switched off to
;		access ram under it. This had been working just fine as it was fully tested
;		around June 2004; in fact I had to go back to June 2004 to prove this, as the
;		bug has been extremely elusive - everything else apart from this behaviour, in
;		this circumstance, works as intended. The routine in init_game that levels the
;		grid to the man's starting position (without it doing it visibly) seems to be
;		the culprit - although I'm still not exactly sure why. Moving it into the
;		init_stage routine before DMA and interrupts are turned on again causes the
;		problematic behaviour to go away.
;
;		Another related problem was that the title page display list was glitching
;		and unwanted background graphics were appearing, again only after pressing the
;		reset key press with the cart off. Adding 2 calls to the new_screen routine
;		in the title screen fixed it, but this just highlighted that the wrong screen
;		was being displayed when it shouldn't have been. So removed DMACTL enabling
;		from init_stage, and moved it to the VBI to ensure that the screen is only
;		turned on when there is something to see, and not messy workings from their
;		use in the background building or any leftover frames.
;
; 26/04/05	init_missile changed - now split out into queue_missile as well. Previously
;		missiles were being set to an aliens last position, and also were being moved
;		without showing their initial position ever, queue_missile now just assigns
;		a missile the alien that wants to fire in its launcher variable. Then later in
;		the move_missile routine, launcher is checked to see if the missile needs
;		initialising and the current position of the alien is used and the usual move
;		is skipped.
;
; 25/04/05	Fixed some stage 3 ship patterns that could kill man when coming on screen that
;		do not kill man on original
;
; 19/04/05	Made score line Antic mode 2 rather than mode 3. Redesigned char set to support
;		This should make top grid implementation look better
;
; 13/04/05	sequence_scenery changed to deal with setup of only 2 mushroom types now, not 3
;
; 03/04/05	Fixed bug in move_scenery. Oranges still keep moving up and down when man dies.
;		They should stop. Bug introduced when sample playback changes allowed main loop
;		to carry on running, whereas before everything stopped.
;
; 21/03/05	Gave up with attempts to use assembler to assign object numbers, have hard coded
;		them in variables.asm file. The ".=" command does not assign the values at an
;		easily determined time. At some points in the assembly the value is in flux. It
;		almost worked, but the value for the "bullet" was assigned incorrectly for an
;		unknown reason - maybe because some code referred to it earlier than the other
;		objects?
;
; 19/03/05	Fixed bug in do_man_run and do_man_flash where x reg was not being restored for
;		do_draw_man. Problem since init_sample was changed to use x reg to pass sample.
;
; 14/03/05	Remove background bank table, move all background data into last bank to keep
;		separate from other objects as it may change
;
; 13/03/05	Fixed a bug where "Get Ready" sample was being played after man died for game
;		over. Suppose this must have crept in when the sample caching was done?
;
; 08/03/05	For consistency, frame addresses stored as lo, hi, bank rather than hi, lo, bank
;
; 06/03/05	Moved samples back into single bank - changed init_sample.
;		Tweaked copy code slightly
;
; 05/03/05	Reworked code in make_background_code to save a few cycles. column_buffer
;		also made to use temporary zero page RAM for more cycle and byte savings
;
;		set_layer_width made into loop - previously unrolled, but not time critical
;
;		moved screen clear routines back into their own banks rather than the split
;		up routines of the 8K XEGS cart banks
;
; 04/03/05	4 colour background layer code finished
;
;		Small non-critical bug in make_background_code overlay generate fixed - "bne"
;		after mask check "beq" was supposed to be "beq" to always branch. Just meant
;		was not skipping a small section of code that wasn't necessary, but caused no
;		harm.
;
;		Removed mask_buffer in make_background_code overlay generate - looks up the
;		masks directly now. Makes code a bit quicker, but a little more messy
;
; 02/03/05	More bank switches required in make_background
;
;		Generate slot_base_lo and hi in RAM rather than have a table in ROM
;
;		Move z_to_frame and frame_map into RAM to avoid bank switch in init_sprite
;
; 01/03/05	Initialise RAM with bank number same as cart banks for tracking when cart
;		switched off (needed by VBI)
;
; 28/02/05	Putting back extra bank switches required for MegaCart into code
;
; 27/02/05	XEGS switchable cart emulation is broken on all Atari800 based emulators. Have
;		reported problem, and Piotr Fusik has put a patch in the code for Atari800 at
;		Sourceforge. There is no guarantee when or if the code will be released, so I'm
;		going to go back to using MegaCart. Oh well, only 2 months of wasted time.
;
; 20/02/05	Fixed stupid 16-bit problem with RLE decode. Was not checking for no low bytes
;		to copy, so when 0 did 256 bytes instead. However, I'd allowed for that in the
;		high bytes to copy, but it was only correct when it did equal zero.
;		Added zero check, and removed adjustment - range now limited to 32K copy.
;
;		XEGS Switchable cartridge emulation seems to be broken. After switching the cart
;		off, it doesn't seem possible to be able to switch it on again
;
; 12/02/05	A hybrid 8-bit/16-bit count RLE decode completed. 2 symbols are used to represent
;		the different count lengths. This is more efficient than the 8-bit version with
;		count extensions
;
; 07/02/05	A small bug in the RLE decode was fixed. Where there were long runs of more than
;		255 bytes, the subsequent count extension bytes were also being checked for an
;		exit value of zero. Only the first count should be checked for zero value, or a
;		count value of 255 would cause an exit (a count of 255 needs to be followed by
;		an extension count of 0 for a count of 255 to be represented)
;
; 04/02/05	Finished writing and testing symbol RLE decode routine
;
; 03/02/05	Best candidate for RLE uses a symbol prefix to represent runs. This symbol is a
;		byte value that is not used in the data (or the least used, where that is not
;		possible). Only runs of 4 or more are encoded. The "packbits" method where a
;		count of runs and also a count of non-runs is used, with one bit determining the
;		run or non-run, comes a close second place with my data.
;
; 25/01/05	Messing around with the format of the RLE. Several different methods to be tried
;		to see which is most efficient. Latest implemented idea is that assigning the
;		maximum counter value possible (255) will automatically make the next byte of
;		data another counter value. Previously, if more than 255 bytes of data, then
;		the data bytes got written again, then another counter value.
;
; 21/01/05	Unpack routine created for RLE (Run Length Encoded) data. Will replace the
;		background blank compression routine. Background layers will be changed to be 4
;		colours each to take less memory. Intend to use the routine for stage data too.
;
; 16/01/05	Samples now copied from banks to a RAM cache before the sample is played. This
;		avoids the IRQ routine having to save and swap banks thousands of times a second.
;		sound_queue variable added to help with joining  the "welcome" and "get ready"
;		samples. Now treated as separate samples to keep the size of the RAM cache to a
;		minimum.
;
;		Made the setup of init_sample tidier. New tables created with address, bank and
;		size of samples so only sample number needs to be passed to init_sample.
;
; 15/01/05	Changed sample player to use page count to determine end of sample, instead of
;		checking the address. sample_end is now sample_size
;
;		do_man_flash code rearranged as timing changed due to copying samples to RAM.
;		other code moved after the sample is initialised or frame glitches occur
;
; 12/01/05	Removed current bank variable. Each bank now has an id byte so the bank number
;		can be determined by a read. Stops having to save the bank number every time the
;		bank is switched. The IRQ code for sample playback is less efficient though, as
;		the bank has to be saved now. The other code is more efficient, but a lot more
;		cycles are expended on the IRQ. Will look at seeing if the samples can be stored
;		in RAM
;
; 11/01/05	Tweaked copy routine slightly to pass copy size with x and y registers
;
; 10/01/05	Had been wasting space in slot_addr, which holds the objects' frame addresses,
;		bank numbers, and centre up data for the stage. A hang over from an earlier build
;		left it using 5 bytes per frame, when only 4 are required. slot_base lo and hi
;		also had to be corrected.
;
; 08/01/05	AtariMax Flashcart problems. The emulator for it doesn't do coldstart/warmstart
;		or Basic correctly, leading me astray looking for problems with trapping the
;		reset button. Decided to Switch to using XEGS Switchable cart type, it's a much
;		nicer format than either MegaCart or the Flashcart. Although I do like the idea
;		of the Flashcart, it just hasn't gained enough support yet. It's a fairly easy
;		switch too, since XEGS also used 8K bank sizes.
;
; 03/01/05	Because of smaller bank sizes, pattern data cannot stay in main data bank. Code
;		decode_pattern and init_alien rewritten to switch to correct bank when needed.
;
;		Renamed frame_locations to frame_addr, slot_addr_lo/hi to slot_base_lo/hi and
;		frame_addr to slot_addr
;
; 28/12/04	Generate x11_table rather than have it in main data bank. Saves a bank switch
;		Drawn object tested for first time in flash cart, and it's working.
;
; 08/12/04	Implementing new bank switch method. init_sprite needs to be rewritten to be as
;		efficient. New switching for Flash cart required use of index register.
;		NB At this save point during the port to flash cart it is too early for anything
;		to be working.
;
; 07/12/04	Start trying to prepare the game to work as an AtariMax Flash Cart. It has 8K banks
;		rather than 16K ones of the MegaCart. First thing cart does when it starts is to
;		copy code to RAM. At moment there is almost 12K of code. Preferable to have it
;		all in one bank like it is now, but will have to be split into a couple of banks.
;		Same goes for "main data" bank that is usually left switched in.
;
;		Bit of reducing unnecessary code. Added init_draw_background call. It reuses the
;		sprite zero page initialisation code rather than having its own.
;
; 03/10/04	move_missile code to implement the "call twice" idea. Only affects fireballs, so
;		speedup_bit created as a property of missiles to define when the call twice is
;		required. Fireballs are normally moved slowly even though the code for them
;		is called twice. This is done by giving them a high value max_length
;
;		Wrong sign of missile x_vector introduced by 8 times missile speed fixed
;
; 28/09/04 	Removed 8 times missile y speed - just not accurate. Better idea than using proper
;		divide could be to call the move_missile routine twice when needed to go faster.
;		Just have to be careful to allow for collisions on the first move that miss on
;		the second (ie off the front of the screen)
;
; 26/09/04	Optimisation of y_divide routine as per x_divide yesterday
;
;		Put in up to 8 times missile y speed. not very accurate. need to redo routine
;		using proper divide so missiles can speed up more, and more gradually.
;
; 25/09/04	Missed some optimising on x_divide routine: sign conversion and checking dividend
;		against divisor when not necessary due to divisor being >4
;
; 21/09/04	Finished putting in constants. Upped maximum amount of alien missiles to 8 as it
;		had been running out of them
;
; 20/09/04	Rewrite code with constants for maximum sprite types and separate positioning for
;		the sprite types (bullets, missiles, aliens and scenery). To allow for changing
;		maximum amount of sprite types more easily.
;
; 19/09/04	Gremlins frame glitch due to wrong bank in frame_locations for frame 2s9
;
;		Moved tilt_lo and hi to $400 area from $2000 area to make room for extra missiles
;		in the $2000 area
;
; 18/09/04	Patterns for stage 2 had to be changed to start one z position nearer than those
;		of the disk version or out of z range, and don't get close enough. Did I really have
;		to do that for stage 1? No, I didn't. There were not enough entries in z_scroll. Now
;		there are 21 values (not including the zero data entry)
;
;		Removed z_scroll and tilt_lo zero data entry - had been doing tilt_hi+1 since start
;		of cart project - now back to tilt_hi
;
; 12/09/04	Why is limit of objects 22 per stage? It should be able to do 23 - just a miscalc
;		on my part? Try changing it to 23. This means the overlay size would have to
;		change, which will mess up the object packing. The sky position always has one
;		less than the amount of colours - so reduce this.
;
; 30/08/04	Unrolled x_divide and y_divide code
;
; 29/08/04	Initial "welcome" sample disabled background scrolling because using the man_hmove
;		status. Had to create another man status called man_xscroll to allow this.
;
;		Reworked do_man_trip so last frame shows for longer. Consolidated code for
;		do_man_trip and do_man_run. Fixed a small glitch caused by do_man_trip drawing man
;		when normal VBI code has taken over. do_man_trip now no longer draws when control
;		handed back over to the VBI routine.
;
; 26/08/04	Allow man to fire after just dying. move fire button code in front of hmove
;		checks in move_man. Also man_status must be initialised to 128 not 255 or the
;		button check in wait_press is interfered with.
;
;		Increased delay before scenery begins at start of stage. May need to change
;		timing slightly to re sync with patterns. Done to allow man time to get out of the way
;		of scenery when "welcome" sample being played.
;
; 23/08/04	do_man_draw changed to use 255 as indicative of using man running animation
;		rather than 0. Due to yesterday's changes 0 is now a valid frame
;
;		Added tilt loop on init_game to move the grid to the right starting place at the
;		start of a game.
;
;		Unrolled man draw code in move_man using nice .rept and macro features of ATasm
;
; 22/08/04	Fixed bug where make_background creates corrupt overlay area. The temporary mask
;		table zero entry was not being generated.
;
;		If man is only just above ground and hits a bush he will now trip
;
;		Change so man_y_pos is top of man rather than bottom. To save page faults when
;		unrolling draw loops
;
; 19/08/04	Fixed bug where if man starting to trip missiles also get stuck on screen as if
;		he were dying. Extra states created for man_status to be checked in the
;		collision routine. On checking the frame's collisions, the first state decided
;		must be stuck to on checking the rest of the collisions.Extra states of man_status
;		mean freeze_status flag is now removed.
;
; 17/08/04	Fixed man tripping bug where tripping can be interrupted by another trip. Put
;		in extra check of freeze_status before collision check
;
; 15/08/04	Added man tripping over bushes feature using new man sequencer including sample
;
;		Added feature to allow left/right move of man during "getready". This involved
;		changing around move_man code and creating another status flag called freeze_status
;		in addition to using man_status on dying and tripping. Now man_status takes on
;		a different meaning. -ve means no movement allowed, zero means all movement, and
;		+ve means just left/right movement
;
;		Added "Welcome" sample and used mew man sequencer to do left/right movement
;		only when this is occurring
;
; 13/08/04	More or less finished new man sequencer for die animation. Changes to other code
;		to be more like the original on dying:
;		- main loop continues to run now, to allow objects to have tilt added
;		- checks on man status stop alien and scenery objects moving (apart from tilt)
;		- grid always drops during man dying - doesn't follow man as usual
;		- missiles keep moving while man dying
;		- if missiles hit man, even when dying, they stay on screen
;		- explosions drop and stay on screen during dying
;		- sample playing runs in IRQ so main loop can continue
;
; 08/08/04	16-bit 1.79Mhz IRQ timer now syncs with scan lines exactly for clearest sound
;
; 01/08/04	Started moving man die animation into main code, now that tests show that using
;		IRQ for sample playback actually works very well - even with DLI's & DMA 
;
; 26/07/04	Set PORTB bits 4 & 5 for exact 130XE compatibility
;
; 14/07/04	Small tweak to 2's complement code in draw_background. Subtract from 0 rather
;		than eor #255 and adding 1.
;
; 26/06/04	Minor change to new_screen. Use y register to hold clear screen value. Clear
;		screen progs in banks changed to use this instead of accumulator, and removed
;		the "lda" in the banks. Saves a couple of bytes. Also the last byte of the
;		stage file was a blank to make it up to 640. This is not necessary for the
;		cart version.
;
; 25/06/04	Changed man red to a shade darker so "press start" attract shows up better
;
; 22/06/04	Bug where man dies and pressing reset afterwards will cause man to die instantly
;		on the start of a new game. Only noticed after the ram layout was changed. 
;		sort_index+1 must be initialised to z_clip as well as sort_index-1 and
;		sort_index, or man collision check will look in wrong area of memory for
;		objects of z=0. The collision check gets called before the sort routine
;		puts in correct values, so this initialise turns out to be very important.
;
;		Duplicate object_to_slot reset code removed from init_cart - done in init_stage
;
; 21/06/04	Must leave first 15 zero pages alone or game will crash if a warmstart is done
;		when cart is off. But if a warmstart is done when the cart is on first, the
;		warmstart with cart off works from then on. Yes, it's very strange to me too.
;
;		Now that warmstart is working all the cart banks except 0 can be set to point
;		to that reset_trap routine. No need to have a stub of code in each bank that
;		has to be run to get back to bank 0's init_cart routine. Only works if the
;		banks are flagged to diag cart though. Should gain 512 bytes extra storage.
;
; 20/06/04	Moving mask table from $200 to temp area as not needed except during stage
;		initialisation. Moved dlist from $300 to leave $300 page free to try and
;		figure out why reset trap will not work. Doing so has enabled the reset trap
;		to work correctly now. Warmstart does not clear memory, and DOS seems
;		not to reinitialise its own $200-$3ff area, so fails and has to reboot.
;
;		Important that GINTLK is set to 0 when cart is switched off or a warmstart
;		is not allowed. The normal method of setting the DOSINI vector to a trap
;		routine, COLDST to 0 and BOOT? to 1 must also be used of course.
;
; 08/06/04	Dlis on title screen often corrupt after pressing reset
;		make_background variable layer_select causes it when set to 1 for some
;		unknown reason - something the OS does at initialisation most likely
;		Leaving the first 14 zero pages alone cures the problem.
;
; 26/05/04	Removed code for checking data size of sprite to determine sprite routine
;		to use (init_sprite). One routine now, and it doesn't need data size to work.
;		This included changes to frame_map table - times 4 required instead of 5
;		Also the init_stage routines for creating frame_addr table for object slots
;		requires 4 bytes per frame instead of 5.
;
; 19/05/04	Removing shifted version of frame 3. now 22 frames per object instead of 23
;		This may give enough room to do all objects in embedded format.
;		Also single pixel shifted versions of non-scenery objects can go.
;
; 17/05/04	Added run code for new multi zero page embedded sprite format now the format
;		is optimised. Since the new format cuts the size of data by a fair amount the
;		original goal of all objects drawn in embedded format can be attempted again.
;
; 07/05/04	Support being added for larger widths of overlays - previously limited to same
;		as underlay
;
; 03/05/04	Shifted version of underlay integrated
;
; 02/05/04	Background overlays and underlays expanded to 25 pixels high
;
; 01/05/04	Overlay and underlay working in conjunction now
;
; 29/04/04	Background overlay (mask) code generation working
;		background_x renamed to underlay_x. overlay_x created
;
; 27/04/04	Background underlay (no masks) code generation is working fine
;
; 19/04/04	Start replacing background routines with generated code version
;
; 02/02/04	Fixed clipping off top of screen. Disk based version had 48 pixel off screen
;		clipping area, but cart version has only 42 pixels. This is because real
;		memory is used to clip and only 2K is available to each screen for this
;		purpose: 2048/48 lines=42 pixels. An adjustment of 32 was made to the x48_table
;		to make the x positions correct when drawing. The clip screen starts 8 pages
;		back from the real screen now, rather than 9 pages. Since 256*9 divides by
;		48 exactly, an adjustment wasn't required before.
;
;		Y position checks all changed. Centre of screen is now 84, not 90
;		3D to 2D conversion changed from 90 to 84 as above
;		Changed offset of explosions ground check table (div47z_2d_table) to 84
;		All 2D pattern data changed
;
;		Put in a proper check and limit on y off screen top for aliens. Now that the
;		y position with the new clip values only goes from 0-127 this was even easier.
;
; 04/01/04	Routines created for making the 2-pixel shifted version of background. Code
;		from cart version mostly unchanged, except for having to shift A and B screen
;		data separately, and changing the height from 8 pixels to 20 pixels
;
; 03/01/04	Discovered fire button wouldn't work on title screen with a PAL computer.
;		Turns out that it shouldn't really work on NTSC either. Problem was to do with
;		man_status. When man_status is active the fire button is checked and de bounced.
;		But the man status would have been active during title screen, on first boot,
;		confusing it's own button routines. The man_status was made to be not active at
;		cart initialise to avoid confusion. Some VBI code had to be changed though. A
;		screen flip wouldn't occur until the man was active due to the sequence_man_die
;		using man_status to decide on skipping a load of code in the VBI. Made it use its
;		own player_index flag instead to determine skipping code. Note that man_status
;		is not initialised in wait_press, but the title_screen, as wait_press has to
;		be called twice at the end of a game. Once, to get back to the title screen,
;		and then again to start another game. This ensures man_status is never active
;		during the title screen.
;
; 01/01/04	Objects drawn one byte too far to the right. Fixed by changing x48_min9_table
;		to a x48_min8_table. Was due to peculiarity of disk version draw that had to
;		be adjusted for, but no longer applicable to the cart draw routines.
;
;		Man collision check changed. There is no need for a separate copy of positions
;		now we don't have a triple buffered screen anymore. Removed check from VBI
;		and put into main code.
;
;		Also taken code out of main loop and kill_man that makes the current screen be
;		redrawn after man dies - this should also no longer be necessary?
;
; 20/12/03	Fixed firing crashes game problem. init_objects was called too early in the
;		init_stage before the slot number of the bullet was available. Fixed y position
;		of bullet now man lower so doesn't go off bottom of screen.
;
;		Missing 22nd entry in x11_table added
;
; 19/12/03	Fixed soft reset (warm boot) problems last week. All banks have initialisation
;		code now to switch to the bank where the init_cart code is and run it. This code
;		is at the end of the bank. Note that the cart never returns from the init address
;		to run the start address, so the space where start address would go can be used.
;
;		Moved frame locations to bank 8 as there will not be enough room for them in
;		the main data bank. Expecting 7-8k to be used.
;
; 09/12/03	Embedded frame data changed so data size field is included. init_frame_addr
;		changed to use the field
;
; 07/12/03	Changed frame address table layout so data size is first field. This so draw
;		can use this instead of z position to determine whether embedded data sprites
;		are being used for a frame. When the size is zero it's an embedded data frame
;
;		Started looking for bug when man dies instantly on game start. Never happened
;		on disk version of game. Don't know how it's happening as all objects are reset
;		at the start of each game, and the collision table itself is reset. Had thought
;		it might be something to do with the game starting too soon due to non de bounced
;		fire button. OK eventually found the bug. The kill man routine wasn't setting
;		the cart bank back to the main data bank when the man had lost all lives.
;
; 06/12/03	De bounce fire button and console start button on title screen and end of game
;
; 03/12/03	Migrated to ATasm 1.05 Beta for ".bank" and ".set 6" support - all extra labels
;		removed which previously were used for referring to routines when in ROM and
;		when copied over to RAM. Multiple references required to assemble banks
;		separately removed too. Very few problems encountered.
;
; 30/11/03	Background draw works fine. Next to implement the shift version of it.
;		Redrawn stage 1 with some clouds in the sky and re coloured.
;
; 27/11/03	Redoing background draw without self modifying code. Increasing height of
;		background to 20 pixels, up from 8 previously. Since clear screen routines now
;		clear the whole screen rather than leave a strip where the background is,
;		make it avoid drawing blanks where possible. A height jump table for each
;		column of the background. Columns with just stuff at the top will have to draw
;		the full height of the background though, unless a more sophisticated routine
;		is created.
;
;		Have had to mess with z_scroll and initial tilt_lo positions to get grid
;		scrolling nicely and the grid moving up and down a pixel every frame (to ensure
;		background placed on back of grid easily)
;
; 09/11/03	Rewrote the simplistic wait for a draw screen code in new_screen. As each screen
;		is actually composed of 2 overlaid screens, it does not have to wait until the
;		previous screen has flipped - it can start drawing to the part of the current
;		screen that is not showing, as long as it is on the frame just before the flip.
;		This was only a problem since moving over from triple buffered screens to
;		double buffered screens for the cart version.
;
;		Draw code for lengths of 2 byte wide and 1 byte wide integrated with draw code
;		for widths - duplicate code removed.
;
;		Fixed bug in man die - stood up again after last life - due to frame data
;		trying to get modified even though it is now in cart ROM. sequence_man_die
;		rewritten to pause then continue on sequence only when more lives left.
;
; 02/11/03	Tweak how the missiles aim at the man. Mustn't go too low as before, but also
;		make them aim lower when man is higher to make them clip less.
;
; 01/11/03	Don't like the wide screen look. Plus the wider objects don't have enough room
;		to clip properly. Putting back the player missiles down the sides...
;
; 29/10/03	Bug in times 22 table generate in init_stage fixed. Bugs like this make it seem
;		like I'm starting from scratch all over again. Also now the screen is wider,
;		all the patterns are going to have to be redone. Darn this cartridge!
;
;		Redoing kill man routines, samples in separate cart bank and playerb area
;		can be in screen clip area to avoid it having to do dynamically allocate ram.
;
; 28/10/03	init_stage objects height and width initialise code rewritten for cart
;
; 26/10/03	Score and status lines colours changed so merge with rest of display. Widened
;		screen to normal width size. Missiles now all freed up. Some graphics to be
;		made slightly larger. Redone grid co-ordinates to allow for extra on bottom.
;		divide by 47 rather than 43 tables created.
;
; 24/10/03	Display List changed to use horizontal scroll. Saves using wide screen mode and
;		having to use all the missiles to mask the sides of the screen. Same amount of
;		data is retrieved as wide screen, but displays as normal size. Thanks to Analmux
;		for reminding me that horizontal scroll does that. COLPF0 and COLPF1 swapped so
;		score line has constant luminance (grey brighter than other colours in palette)
;
; 14/10/03	Some major changes going in. Work commences on using the COLBK colour register 
;		as a playfield colour and using COLPF2 as the background colour. Although all the
;		sprite masking routines have to be changed and the graphics and my graphics tools
;		redone, there should be some benefits to be had:
;
;		a) Removes the problem of hiding the horizontal colour changes that are wider than
;		the screen
;
;		b) Can experiment with making the top and bottom score line and status displays the
;		same colours as the sky and "grid" as they will be using the same register for the
;		background colour now.
;
;		c) If b) above comes off, the size of the screen will appear larger vertically, and
;		some of the side borders can be widened too, and then objects made bigger which
;		will allow for a slightly more convincing 3d effect (less loss of detail on scaling)
;
; 13/10/03	Reason for sound fx problems due to the objects.asm file being before the
;		sounds.asm file in the code. objects.asm references some variables in sounds.asm
;		and ATasm is assigning the variables before they're ready (but no errors on
;		assembly). Must be very careful of this in future...
;
; 12/10/03	Bug in init_game due to move to cart - wasn't clearing pat_kill of all patterns
;		More incorrect references fixed. Data in slot_addr table needed correcting.
;		Work on init_stage loading of frame addresses into slot tables and other slot
;		references. Sound fx of objects incorrect, but music OK (?)
;
; 08/10/03	Purging references to ROM locations in the routines that get copied to RAM - some
;		jumps were using local labels. Few days earlier successful tests with version 2
;		format sprite routine and converter.
;
; 30/09/03	Made some progress with re-write of draw_screen to make it work with new sprite
;		draw routines. Decided layout of the frame table area...need to have the centre
;		up data and the size of sprite data area as well as the cart bank and address
;		within the bank. It was simpler before switching to cartridge...
;
; 27/09/03	Still can't test the full game yet but all the routines are in the cart. Starting
;		work on new draw routine for just medium size objects. Takes up lots of memory
;		but will be a bit quicker than the current draw routine.
;
; 02/08/03	Start changeover of development to cartridge rather than disk. Too many changes to
;		mention here are required, unfortunately it's not straightforward.
;
; 29/07/03	Changed Uriah z freeze to zero z position on all vector buffers relating to Uriah -
;		freezing only last vector buffer did not give enough flexibility in pattern design
;
; 28/07/03	Pattern command to total the uriah counters and add to score at the end of stage
;
;		Put back code to make PAL computers do one less VBI per frame than NTSC. Game is
;		noticeably too slow on Uriah stage especially, when running in PAL otherwise.
;
; 27/07/03	Game command to reset sprite priority for man jump off 
; 
; 26/07/03	Pattern command to centre uriah ready for man to jump off - do_centre_object
;
; 20/07/03	Overlay counter code
;
; 19/07/03	Initialise stage changes to setup players for counter overlay
;
; 11/07/03	Skip rotate check, move missiles and move bullets during uriah stage
;
; 07/07/03	Code for stopping player/missile man draw while uriah stage 
;
; 06/07/03	Finished some code to deal with wraps of vector buffer when using the chase
;		object pattern command. Previously had assumed won't wrap - there's a 1 in 10
;		chance of it just hitting a wrap, depending on the pattern data.
;
; 01/07/03	Redone collision routine with scenery being checked against uriah, rather
;		than the other way around. Each piece of scenery can only be on one z position
;		so it will be easy to skip the collision check with uriah if there is only
;		1 object in that z position. Uriah is more complicated in its use of z position
;
; 28/06/03	Uriah collision routine started again. Had to go back to backup from last week
;		due to corruption somewhere.
;
;		Small optimise to check_object_collisions. Use x reg instead of zp first_object
;
;		Man right limits were one pixel off intended position
;
; 21/06/03	Past couple of days doing pattern commands for beginning of uriah stage -
;		code for man chasing uriah, ready to jump. code to control man prior to this
;		done earlier. Consolidation of best way to arrange these pattern commands
;
; 14/06/03	last_alien and last_handler initialised to 0 in init_stage for easy uriah setup
;
;		As a game command does not run until end of game loop, and pattern command gets
;		configured by a game command, but gets called mid-loop by patterns - check for
;		use of the pattern command before it has been configured. Pattern command could
;		point to any data before it is configured, making corruption highly likely if it
;		is called too early. game_status now checked before pattern command call
;
; 01/06/03	Made event sequencer able to start straight away at stage start, for man
;		initialisation on uriah stage. Stage data changed IAW.
;
; 15/05/03	Missing plp in decode_pattern in the new frame animation was causing crashes
;
; 12/05/03	Change to object frame animation. Needed to be made more flexible so man animation
;		can be done correctly before the jump onto Uriah. Could only move one frame back
;		or forwards (or mirror) before. Now has ability to move back 16 or forward 15
;		frames at expense of x vector not being used at the same time.
;
; 11/05/03	Change to sprite format file. Qty of zeros to write for missing frames changed to
;		qty of missing frames. There are 2 zeros for each missing frame. Reason for this
;		change is that the man graphics before jumping on Uriah is only one frame and there
;		aren't enough bits to represent all the zeros needed. create_object code changed to
;		multiply the figure by 2. All object files changed.
;
;		object_to_slot amount of objects was too low and routines referencing it were using
;		wrong qty of objects causing problems of animating to incorrect objects.
;		constant created to avoid this problem.
;
; 10/05/03	Code to allow loading of raw graphic data in ASH format. To allow more colours
;		than 4 per object. This is necessary for Uriah with the man sitting on him.
;		Changed load_object, create_object, decode_frame. frame_no used to denote this
;		situation in the file. Also had to move read_joystick from $3000 area to make room.
;		Changes ruin some already ugly code. A cart version with none of this loading and
;		memory management code, or any 4 colour limitations would be very nice...
;
; 09/05/03	Code insert for init_alien to change uriah head into uriah segment for all
;		following aliens - using bit 7 of pat_object to denote. This was done because the
;		joystick follow routine required all of Uriah to be in the same pattern to work,
;		and it seemed the easiest way to allow more than one object type per pattern
;
; 08/05/03	Moved check for pattern command after decode of x movement bits so Uriah
;		x movement can be done as a pattern command and override pattern x movement
;
; 06/05/03	Was not removing mirror bit on properties of object in move_objects(aliens).
;		Code change would not fit, but made room by optimising pat_kill reduction.
;
; 30/04/03	Code to flip to mirror version of sprite put into move_objects(aliens). To make
;		room, restoration of accumulator and stripping of fire bit put into init_missile
;
; 24/04/03	Change labels starting with "_" to "@" so code will assemble with Atasm 1.03
;
; 22/04/03	Made missiles fire from centre of aliens, not where their y position happens to be.
;		Was previously firing from y position, be it top, centre or bottom of object.
;
; 16/04/03	Added lookup table for global timer (timer_wait) now fps can change 
;
; 15/04/03	Added entries to x11_table now there can be 22 objects per stage
;
; 14/04/03	Add in code to set speed of each stage from overlay variable stage_speed
;
; 13/04/03	Created background_y variable to save doing horizon-9. "tilt" sets it in the *3 code
;
; 12/04/03	Increased objects allowed to 22 to use up spare bytes in overlay. This required moving
;		some variables in $600 area to make room for other tables which increase in size the
;		more objects there are. Re-did all stage overlays
;
; 06/04/03	Added code to allow DLI on first line of screen since it looks a bit ugly on some
;		stages by not allowing it. The code needs work though as it is still a bit kludgy
;
; 05/04/03	Changed position co-ordinates on sky colour to allow full freedom of positioning
;		DLIS anywhere. Previously position 57 was off limits due to -57 adjustment pre-
;		calculated into co-ordinates; zero is used to denote end of data. Sky_scroll
;		now used instead of horizon to store scroll value (always 57 less than horizon)
;
; 04/04/03	Still doing code for gradual grid colour cycling - changed previous method and
;		changed overlay area layout again
;
; 31/03/03	Work began on code for gradual grid colour cycling in move_dlis
;		
; 29/03/03	Tweaking DLIS again, as I'm ramping up the amount of them for nicer colour shading.
;		Moved 1st DLI to blank line. Now there is time to finish the inc before the 
;		sta WSYNC in the DLI
;
;		An experiment to test how quickly the colour can be changed on acknowledging an NMI
;		shows there is not quite enough time to change the colour before the scan line is
;		visible, even with normal rather than wide screen. Should be feasible with a narrow
;		screen though. Since nearly 100 cycles are "wasted" per DLI this could be well worth
;		looking at for other games. Using NOP's instead of WSYNC doesn't gain much time for
;		an early exit to DLI's either.
;
;		Put clear of game_status into init_game, in case there is an outstanding request
;		after game over, Luckily this actually happened, so highlighting the problem, despite
;		it being incredibly unlikely.
;
; 28/03/03	Use a constant for maximum amount of DLIS to make changing dli buffers easier
;
; 27/03/03	Removed temp_mask_table code - no longer required
;
;		Moved grid colour data after objects_required in overlay so stage 0 takes 1 sector
;
; 26/03/03	Extended overlay area an extra sector, for grid colour animation. Moving around
;		variables to make room. For some reason I hadn't been using page 6. Now used
;		for mask_table to save having to create a duplicate when the OS is in. Moved
;		old position data from $700 area into the $d800 area.
;		Extension of overlay used to increase number of DLI positions and patterns
;		available per stage too, as well as the initial game speed for the stage.
;
;		Renamed sample_done to sample_status
;
; 22/03/03	Top grid down and up changed to use position check to know when to stop
;		rather than a simple counter, which can't work for knowing when up finished
;
; 17/03/03	Top grid up crash due to temp2 in move_dlis not being initialised to zero
;
; 14/03/03	Merged top grid position and colour buffer code over past couple of days.
;		Tested grid up for first time. Surprise - it doesn't work. Crashes part way up
;
; 10/03/03	Fix top grid start so initial position has tilt removed. Was starting too far
;		down screen, or too far off top of screen.
;
;		If the top grid position of the next DLI was actually less than the current DLI 
;		the top grid position was set incorrectly to the next position.
;
; 09/03/03	Pattern commands do_grid_up, do_grid_down, and overlap of top grid and background
;
; 02/03/03	Top grid initial DLI positions set to 2 rather than 1; to avoid glitch on upward
;		tilt on initial downward movement of top grid
;
;		Changes to sky_index usage - all code in move_dlis now to sync with top grid moves
;
; 25/02/03	Moved inc in DLI to after WSYNC since there doesn't seem to be time on NTSC to
;		always do this before the end of line (according to AtariWinPlus 3.1)
;
; 24/02/03	Fixed z off screen (z clipping) problem. Had forgotten that if not bothering
;		to update the z clipped objects sort index in sort table, they would need to
;		be separated in the sort table from ordinary objects somehow else. Portion at front
;		of sort table set aside for the clipped objects, so no need to do the adds to give
;		a final position in table. collision and draw routines changed to take this extra
;		portion into account.
;
;		Attempt to fix active pattern count. There is an intermittent problem where the
;		pat_kill or active_pat_count is not reduced properly, but it is very rare, and the
;		cause is still not certain. Multi-hit objects now have bounce bit set after
;		initialise for kill, to stop countdown of pat_kill again by another bullet hit
;		in the same screen frame, which in theory could mess up the kill.
;
; 20/02/03	pat_kill changes do not work because sum pattern does not have the qty of aliens
;		in it(!). Change init_pattern to set force no object bit when there is a qty of
;		zero in the pat_qty rather than checking for a sum pattern as well - Only time
;		there will be a zero is for a sum pattern.
;
; 19/02/03	Made sum pattern end leave the active pattern count alone if it has an object to
;		kill (which will do that job for it). Also made to strip off the force no object
;		bit from pat_kill, so the pat_kill counts down to zero when the object does get
;		killed. NB Force no object bit is required when the sum pattern has no object of
;		its own to control.
;
; 18/02/03	Hang problem is basically confusion on my part about how I've written the sum
;		pattern handler. Well, it had to be my fault somewhere along the line.
;		The sum pattern waits, ends and reduces its object count. The move_objects also
;		watches and kills the object, and reduces the object count also...so twice killed.
;		This means the pattern qty is not 0, and so the pattern is still active. This
;		hasn't been noticed before because the sum pattern on stage 2 does not have an
;		object of its own
;
; 16/02/03	Typically, the potential problems listed yesterday are not what is causing the
;		game to hang. The off-screen z is a serious problem though. Tested dragon without
;		rotate, without z off screen, without handler and music reset. Went back to older
;		versions of program to no avail. What else is different about this pattern?
;
;		OK, some progress. Without the fireball speedup pattern command the game doesn't
;		hang. Why is this different to the stage 1 dragon though?
;
;		The sum pattern is still running, after the pattern is supposed to be killed.
;		The pattern command is being called after it has been set to an illegal address
;		by the sequencer.
;
; 15/02/03	Past few days spent trying to track down a nasty bug that has somehow escaped
;		notice before. When moving on from stage 3 to stage 4 the game locks soon after
;		the start of stage 4 (but not always the same place). It is something to do with the
;		2 head dragon pattern, as when this is removed, everything works fine.
;
;		NB Sum pattern should not be set up first if there is a delay between it being started
;		and the patterns it sums with. This is because the sum pattern once running, always  
;		checks to see if it is the last pattern running, and if it is, it will kill itself.
;		so the other patterns must already be running or start at the same time, in order
;		for the sum pattern not to kill itself straight away.
;
;		The extra off-screen z positions will corrupt memory up to a page after sort_table
;		as their position in the sort_table is not calculated, but they are written into
;		the sort_table....somewhere.
;
; 14/02/03	init_objects was not resetting scenery object 0.
;
; 12/02/03	Changes to dli off screen checks. Uses sky_index to keep track of on-screen
;		dlis in an incremental way, rather than running through whole list every time
;		Requires initialising in init_stage for the new sky positions on every stage
;
; 09/02/03	Correction to off-screen dli position check in move_dlis, changed to 1 from 2
;
; 29/01/03	Optimise move_dlis. Reduced compares on next grid position. Merged colour and position
;		code in sky routine. No need for buffer write variables. Optimised top_grid_pos check
;		Fixed bug in sky to top grid compare - Not skipping sky when grid dli on same position
;
; 25/01/03	Used equates file to give proper names of hardware registers rather than addresses
;
;		Made write_data save the buffer size so write_buffer didn't have to do some adding
;
;		Began renaming routines so they begin with an action, for standardisation in naming 
;
; 23/01/03	Merged "sky" and "grid" routines with top grid dli code into one routine - move_dlis
;		Title screen given its own routine - title_dlis - was using "sky"
;
; 20/01/03	Finished mirror_sprite, integrated with create_object and file_load
;
; 19/01/03	Previous week has been spent on drawing objects for stage 4
;		Started work on creating program to mirror objects.
;
;		Redone load_object so doesn't need file_same flag (moved load_file)
;		last_properties created instead for checking whether mirror has been done or not
;
;		Frame buffer and Optimise buffers incorrectly in $a200, moved to screen 2a area
;		Left like that they would overwrite code that is going to be there later.
;
; 11/01/03	Sample playback. NTSC has odd number of VCOUNT, so different value every frame
;		Don't think it really matters to sound quality with my routines though.
;
;		Bug in play_sample the initial wait for VCOUNT was not using VCOUNT! Made it wait
;		for a specific scan-line now, rather than add 2 to current line to start
;
;		Made sequencer wait for all explosions to finish as well as active patterns.
;
; 10/01/03	Changed Display Lists. Removed extra blank line in Display List, and change the
;		single mode e line back to mode d line. Put fixed DLI onto mode 2 line at top instead
;		of the mode e single line. The colour change is then in exactly the right place.
;		Put the other fixed DLI at bottom onto the last mode d line, rather than the mode 2
;		line under it. Takes less cycles that way. Able to move restore of y register in DLI
;		before the WSYNC because of this change. Still not time on a mode 2 DLI or a mode e
;		or mode d first line with LMS to move the INC index in the DLI. 
;
; 08/01/03	Changed how game command is setup. Additional fields are taken from the stream to setup
;		the pattern command required and the music required on the game command. This allows
;		fewer game commands to be needed. New table of pattern_command_lo and hi.
;		Only Stage 3 implemented so far. Must still do stage 1 and 2
;
;		Experiment with extra line in Display List to see if affects the sound sample
;		playback. 48 (4 blank lines) was original, 64 (5 blank lines) was tried. 48 seems
;		to be more crackly than 64. NB Crackle is more noticeable in NTSC for some reason.
;
; 05/01/03	Made init_sound run in VBI at screen flip time to sync sound fx with graphics better.
;		Main code routines now set sound_queue variable instead of calling init_sound
;
;		Add init_sound to scenery for objects like loopers and hexagons
;
; 03/01/03	Delay of 2 seconds at beginning of all stages - init_stage sequence and stream timers.
;		fixed control - needed initialising to zero in init_objects
;
; 24/12/02	No action on game_command. 1 second pause is not too bad. Decided to up the
;		resolution of timer to once every 1/2 second so more fine control
;		wait_second changed to wait_timer
;
;		Changed rotate_dragon alien numbers, so dragon heads can start simultaneously
;
; 23/12/02	Problem with when game_command is run. Only runs at end of code loop. But for 2 head
;		dragon to reset the last_handler with game_command it is too late if the setup
;		patterns for the dragon are run immediately. There has to be a 1 second pause. That
;		adds up to quite a delay with all the other pauses getting the 2 head dragon right.
;
; 12/12/02	Added some extra bytes onto back of sort_index to allow some objects to remain hidden
;		at back of playfield.
;		Created sprite_count variable instead of using sort_index+21
;		Stop man bullets reaching into the back of playfield - limited to z=18 now
;
; 10/12/02	Sum pattern was still checking wrong bit to identify the sum object
;		init_alien shifts the whole properties byte left, so sum_bit*2 is correct bit
;
;		Moved rotate_dragon code after all other alien movement code
;
; 08/11/02	Rotate_dragon was trying to set the x position of a head rather than a segment.
;		Sum pattern was checking wrong bit to identify the sum object
;
; 06/11/02	Bug where gremlins initialised to wrong position or ships go missing, occasionally
;		Have been looking for past 2 weeks, but have found no reason yet. Looks like some
;		kind of initialise problem with the aliens. Don't know when bug was introduced.
;		Changes of 6/10/02 where frame animation is done before fire check removed.
;		The fire check must be done first or it is possible the frame change buffer will
;		put incorrect data into an object. This is because fire check detects the end of
;		pattern. This was not the cause of the bug though...GRRRRR!
;
;		*Think* the bug is to do with rotate_dragon, With the call to that routine gone
;		I haven't got it to go wrong yet.
;
; 27/10/02	sum_pat changed to sum_status. rotate_status initialise changed in init_pattern
;		last pattern in a rotate series should turn on the rotate else gets reset
;
; 22/10/02	Change to how patterns are linked. pattern link_bit denotes the pattern links to
;		the previous pattern, rather than the control_bit specifying the start of a link.
;		control_bit removed - renamed to link_bit. control pattern is now called link pattern
;		pattern_bit removed - used for new hit_count_bit instead, which specifies the object
;		in a pattern requires multiple hits to kill and maybe dying animation frames
;
; 20/10/02	Change to pattern stream properties - use stream_object to detect whether a pattern
;		is required or a command. This gets an extra bit back for the properties.
;
; 16/10/02	Changes to only reduce pat_kill as control linked alien is exploded iaw 15/10/02
;
; 15/10/02	There is a problem with the pattern commands, now that the dragon is actually
;		2 patterns using same data. The priority swap command doesn't work! It does swap
;		but the other pattern swaps back again.
;		Fixed apply die animation yesterday - a missing tax.
;		Made code simpler by using different pattern data for the dragon and segments
;		Removed check to stop bounce objects firing, now that different pattern data is used.
;		Change to "aliens" so uses vector=0 rather than pat_kill=0 to determine whether
;		object is to be control killed. This has the benefit of allowing destructible
;		objects to be control killed, there is no need to risk their pat_kill getting
;		reduced to below zero by a normal hit; as pat_kill was being set to zero before
;		they had died to flag a kill. Bonus of being slightly Optimised as well.
;
;		init_missile changed to not lookup missile properties, but to use immediate mode
;
; 13/10/02	First trials of new pattern handler. Changes are not great but there are major
;		problems of course. Main change has been concept of linking to next pattern if
;		the pattern is a control pattern. The control pattern is then responsible to kill
;		and animate the objects of that linked pattern. The kludgy multi_hit_bit was removed
;		and the lead_bit. In their place the animate_bit and rotate_bit have been created.
;		The animate_bit is necessary for the wi-wi jumbo dogs which are not animated, but
;		wi-wi is. pat_lead removed as now each pattern can only have one object type. This
;		gets round problem of having to create several instances of segment as described in
;		23/9/02 bugs. multi-hit is handled by having the hit count and the amount of frames
;		stored in the spacing - since the control pattern is allowed only 1 alien, the
;		spacing was redundant.
;		red_control_aliens changed to apply_die_frames
;		init_kill_control_aliens changed to init_kill_aliens
;		kill_control_aliens changed to kill_alien
;
; 07/10/02	Tiny optimises in bullet_collision and decode_segment - reduced clear carry's
;		Small fix to move_alien Optimise - must keep z pos in y reg.		
;
; 06/10/02	Changes to not allow indestructible bounce objects fire has stopped animated triads
;		from firing. Their frame properties don't get set until after the firing which messes
;		things up. Moved code in "aliens" around to fix
;		Removed 29/9/02 changes. A sum alien can't fire if it works like that
;		Worked on new handler in init_pattern and init_alien. Optimised some variable restores
;		Optimised move_alien slightly. 3d check changed to use ldy control,x
;
; 05/10/02	Put in new handler code to not allow indestructible objects to fire in "init_missile"
;
; 29/09/02	Started change to rationalize pattern handler. If there is a sum pattern object
;		then it gets pointed to vector 0 (no movement). There is no need to check to stop
;		sum pattern object getting moved twice. Changes to init_alien and sum pattern
;		"aliens" changed to not change vector pointer when it is vector 0
;
; 23/09/02	init_alien can't handle different dragon head unless another instance of segment is
;		created as another object. The pat_lead can only point to next object along. EG At
;		moment segment is next along from stage 1 dragon head, not stage 3 dragon.
;
; 11/06/02	Changed init_alien to set any aliens that are not lead or sum ones to not move when
;		the rotate_status is on. Their movement must be determined by the rotate code. They
;		just get pointed to the special vector buffer 0.
;
; 07/06/02	Changed workings of control for scenery objects. control=0 means no object required
;		rather than a -ve number. After experimenting with bit 7, bit 0 will be used to
;		represent 3-in-a-row. Multi-object bit added to scenery control. To allow 3 different
;		objects to be randomly selected in the same scenery event, eg 3 different mushrooms.
;
; 03/06/02	Noticed bullets never bounce downwards on arcade version. Changed iaw.
;
; 01/06/02	Problem where stage 3 test was crashing on end game return to title screen was found
;		to be due to the heads (which share a slot) not being next to each other in the
;		object_to_slot table. Because they were separated in this table the remove_object
;		routine thought they were different objects and removed them twice, corrupting object
;		stack. Very important lesson - shared slot objects must be next to each other.
;
; 31/05/02	Stage 1 object data now all converted to new sprite format. Changed file_same flag
;		to skip file_load and new create_object if the object is the same - it should not
;		be running create_object when they're the same (machine crashes). Made dragon with
;		red colour use same file as green colour one. Palette needed changing to match the
;		frame bits used for the green one. Different bits get chosen on the old red one.
;		Fixed line_lo-1 to be in byte before $2000 as was intended rather than $a000
;
; 28/05/02	All graphic data eventually changed again 5 days ago. Then mammoth coding and
;		debugging sessions on the internal object convert the rest of the time. Today actually
;		has worked with real data. The bush works OK (I think). Now to move the objects over
;		to the new format, one at a time. load_object slot*11 code moved around a bit to
;		avoid a nasty variable conflict. create_object creates data that is exactly the same
;		as the original load file data from a smaller data file (it calculates the shifts)
;
; 20/05/02	Last several days spent trying to do object convert internally. Not going well. Sprite
;		width increase and shifting done, but convert still glitchy. Just found the way of
;		checking whether mask is required can't work due to the stupid way I've packed the
;		4-colour object data - I have bak as 11 (and black as 00), but also uses zero byte
;		to denote blank data - which can't possibly work in sprite format. All graphic data
;		must be changed now to use bak as 00, before I resume convert program
;
; 14/05/02	Work on addition to scenery handler to do y sine wave for oranges. Had to change how
;		low and high bits work on scenery as head uses these bits and is scenery too.
;
;		Put in clear of all GRAFP registers to try prevent PM glitch during stage loading
;
; 12/05/02	Sum pattern was not being reset after game over, causing it to stop itself at the
;		beginning of next stage and messing the active pat count.
;
;		Man flash not being reset at init_stage causing PM glitch if die just before end stage
;
;		Fix sum pattern animate to check for sum pattern
;
; 11/05/02	Stopped decode_segment from reducing active pat count. Done in aliens now to give
;		accurate pat_kill figure to stop pattern ending too soon. Missing sec in bullet_hit
;		could have given wrong pat_kill figure sometimes as well.
;
;		Stop sum pattern from having animate on multi-hit because using lead object -
;		now no sum animate allowed at all
;
;		kill aliens that go -ve z rather than just clip them - for stage 2 boss heads
;
; 09/05/02	When no object in Sum pattern it doesn't work because pat_kill is zero.
;		Set it as non-zero in init_pattern when there is a sum pattern, should be ok?
;
;		Bug in sum pattern setting 2d position messing up firing position because it was
;		not including the y tilt. turned out to be no need for setting 2d position.		
;
;		Remove Optimise from day before on sum pattern - doesn't work due to bit clash
;
; 08/05/02	Remove clear carry at end of y_divide. It has to be cleared on return anyway.
;
;		*Attempt* to fix serious problem with pattern handler. If the decoder finishes
;		before the last object launched then the remaining objects won't get launched.
;		Removed reliance on pat_hi being 0 to detect handler done - use pat_hit instead.
;
;		Slight Optimise of sum pattern check for lead object and for dead object
;
; 05/05/02	Assumed a clear carry incorrectly in move_aliens. bcc changed to jmp
;
;		Crashes on removing shared slot object. Put code in remove_object and init_stage
;		to use slot_no as a check for trying to remove twice. Also was a bug in load_object
;		which was not setting the shared slot correctly causing a crash too.
;
;		Moved man bullet fire position down slightly to be more accurate to arcade not
;		being able to hit low pattern objects from ground
;
; 30/04/02	Top grid overlay code on background draw. much more self-modifying code needed.
;		More routines had to be moved to $8000 to make room.
;
; 28/04/02	Optimised draw_background setup slightly. Unrolled and used registers better.
;		Then redid whole routine with self-modifying code. Slightly slower setup, but
;		got back over 500 cycles in draw. Had to move copy_background from $3000 area
;		to $8000 to make room. Noticed that top grid overlay won't work. Re-think clear.
;
; 22/04/02	Use vbi_count as music beat timer instead
;
; 20/04/02	New division routines - non-restoring divide is quicker. Optimised for signed nos.
;
; 09/04/02	Demo version for testers
;
; 06/04/02	Dragon music would not initialise in game commands. Was found to be bug with game
;		command not resetting game_status to zero, making it continually initialise.
;
;		Intermittent bug when killing dragon - didn't die right. Maybe due to ftimer_buffer
;		zero entry not set to zero. Bug only seen once though. Can't recreate.
;
;		On init_stage player garbage appears when loading sometimes. Set 559 to no players
;
; 01/04/02	Re-arrange disk overlay to include required_song for stage. Take off 1 byte from
;		sky_pos, that couldn't be used anyway. stop_sound created. make sound_hi zero
;		when end of stage so sound fx not resumed after end stage. 
;
; 28/03/02	Temporary pause command put in for screen shots etc. when press option key
;
; 27/03/02	On real atari, setting SKCTL to 0, rather than 3 causes RANDOM to return 255!
;		Causing non-random scenery when samples played. New AtariWinPlus 3 highlighted problem.
;
;		Move man_die player draw continue into play_sample routine for neatness
;
; 26/03/02	Bug fix in music player - next treble pattern must reset bass and mid timers to 1
;		for problem of syncing timers on a pattern channel that has been off.
;
; 23/03/02	Bug fix in music player - next treble pattern must reset bass and mid loop counters.
;
;		Make addr of music pattern=0 mean ignore - to stop problem where otherwise to not
;		use the channel means to keep having to set it to 0 volume in the pattern, which
;		would mess up a sound effect that could be using the channel.
;
;		Make man_die resume sound work. play_sounds now zeros sound_hi when fx done. 
;
; 19/03/02	Bug fix in music player - not stopping sound fx. sound_stop-1,y not sound_stop,y.
;
; 16/03/02	Added extra voice to music player - must be used sparingly, as shared with sound fx.
;		Changed name of background draw labels to not conflict with music note labels.
;
; 15/03/02	Sound glitch on warble - changed wraps of pitch offset to use 12 rather than 13.
;
; 10/03/02	Bug fix in init_sound. VBI play could interrupt setup so sound must not be enabled
;		until all the sound parameters have been configured.
;		Music player proceeds poorly - can't debug, and getting screen glitches coz VBI
;		is overrunning too.
;
;		VBI code rearranged to stop glitches. dlist address not getting set early enough
;		in VBI. Moved move_man, music_patterns, play_sound to end of vbi. The check on
;		man_status now has to be done again at end of VBI - a bit messy.
;
;		Maybe finished music player. loops work. next pattern works. song loop works.
;		Whether any good music can be done with it is another matter though.
;
; 02/03/02	Feeble attempt at music player started.
;		Pattern data moved to after $4000-$7fff code to make room for music code
;		and data which has to run in non-bank ram as it is used in VBI while main code
;		could have it switched. 
;
; 24/02/02	init_pattern changed to not use a handler till pat_kill is zero to stop problem
;		with handler decoder finished, getting reassigned quickly and then all the aliens
;		being killed from 1st pattern assigned. Since handlers are rotated as assigned
;		this is a highly unlikely problem, but it was still just possible.
;		"aliens" changed to reduce pat_kill as aliens finish pattern.
;		reset for pat_kill put in init_game
;
;		Problem with fire straight away on pattern getting wrong y pos. This is to do
;		with init_missile having to be done before move_alien (animation frames are
;		the reason why done first). Accept it as a limitation of the pattern handler.
;		A slight pause segment can be put in start of a pattern to work around.
;		Remove initialisation of 2d position in init_alien as the previous workaround.
;		It doesn't include the grid tilt which is why it gets wrong y pos, and it's not
;		worth putting it in.
;
;		Optimise pat_lead so -ve when not in use rather than 0, and having to add 12.
;
; 23/02/02	Bug in bullet_hit if all aliens in pattern were killed and decoder finished the
;		pattern - bullet_hit would kill pattern again resulting in wrong pattern count.
;		Bullet_hit changed to check if pattern finished already.
;		Reset active_pat_count at init_game rather than setup.
;
; 22/02/02	Reset last_alien in do_init_drag1 for correct priorities.
;		Reset fireball_speed after man_die
;		Remove step_count in "missiles" use z -ve to check for missile stop. This
;		because sometimes not enough steps to get missile all the way to front.
;		Had to add off screen bottom check for fireball missiles.
;		Make fireball speedup a pattern command. Remove from pattern decoder loop back.
;
; 20/02/02	Fix to "missiles" not remembering missile speed due to call to init_sound
;
; 17/02/02	Missing clc in "missiles" causing wrong frame of missile.
;		pat_lead object number s/be number less 12 in "init_missiles"
;
; 16/02/02	Bug with pat_lead. Was getting reset by follow objects in init_alien.
;		Bug in red_pattern_aliens was not using control to detect lead alien.
;		Add sound fx for explosions in kill_control_alien
;
; 10/02/02	Add 3d conversion for death of 2d bounce (indestructible) objects.
;		renamed init_alien_explosion to kill_control_alien.
;		renamed kill_pattern_aliens to init_kill_control_aliens.
;
; 03/02/02	Added pattern command code to run things such as swap priorities.
;		Added priority and fireball reset to init_pattern for stage 18 bosses.
;
; 29/01/02	Added priority_status to sort to allow swap sprite priorities
;
; 27/01/02	Changed man x limits. must be a gap on side of screen, or patterns going
;		off screen look wrong. move score displays inward slightly.
;
; 26/01/02	To allow deduction of (red frame) multi-hit object number init_alien
;		changed to not increase pat_object if there are no follow objects -
;		because wi-wi jumbo must use lead_bit to allow red frame. Dragons are
;		only other multi-hit objects to need animate red frame. bullet_hit now
;		changed iaw above to make all a patterns objects next object number up.
;
; 23/01/02	Used last pattern properties bit for multi_hit - choice of 2 countdown
;		values before multi_hit object dies. Was always same number before
;
;		Pat_multi_hit created for amount of hits left after multi_hit object
;		has changed colour before it dies. Changed init_pattern. More work on
;		bullet_hit is required to change all patterns objects frames to red
;
; 22/01/02	Swapped around bullet_hit code to make more room for pat_kill routine
;		changes soon. Slightly Optimised bullet_hit - no high/low bit mask needed
;
;		Put scenery scoring round right way after 31/12/01 swapping high/low bits. 
;
; 19/01/02	Removed un-needed z_scroll_hi table, always zero.
;		Re coded move_aliens top/bottom/middle into smaller code.
;
; 16/01/02	Add init_sound to init_missile routine.
;
;		Bug in bullet_hit. Can't tell aliens from scenery since 31/12/01 changes.
;		Fixed by checking object number, rather than top+low properties.
;
; 09/01/02	Done bounce bullet except for sound fx. Vector values may need tweaking.
;
; 08/01/02	Start on bounce bullet routine. Amendment to how property set for bullets.
;		Changed nokill_bit to bounce_bit, to clarify meaning for bullets.
;
; 07/01/02	Changed missile y jump to 4 from 8. Gives smoother result, but still quick.
;		Also gives more accurate final position, to avoid off screen bottom errors.
;		Mod on init_missiles to allow different speeds for types of missile.
;
;		Made "triad" pattern smaller managing to use repeat function of handler. 
;
; 05/01/02	Working on triad animation, bug in "aliens" was not setting the properties of
;		the new animated object to the alien - triad as un killable when closed to 
;		vulnerable when open was not working.
;
;		Bug in init_missile. Was using handler+12 when should have used handler.
;		Causing missile not to fire always because getting wrong pat_lead value.
;
; 31/12/01	Put in code for y position as top, middle or bottom of alien. Swapped top_bit
;		and low_bit to make code more efficient - meant had to swap scenery_y data too.
;
; 29/12/01	Putting back up to 20 object types per stage meant moving things around to make
;		room; vector buffers and old positions swapped around, *48 and *11 tables
;		extended. Surprise bug in *48 data on byte 15 - was +14 instead of *14.
;
;		Added routine to init_missile and decode_segment to be able to speed up
;		missiles as player takes longer to kill infinite repeat patterns.
;		Default speed of missiles can now also be set. x & y move up to 8 pix/s now.
;
; 28/12/01	Small Optimise in init_missile. sound player done without extra audctl stuff
;		a couple of days ago. Test sound effects created for ships, bullet and triads.
;
; 24/12/01	Bug - wasn't stopping pattern handlers after game over.
;
; 20/12/01	Past few days spent working on sounds player. Pitch and volume auto add/subtract
;		segments done, but had to add looping pitch offset table to be able to give
;		various vibrato and warble effects.
;
; 11/12/01	Bugs due to sort index-1 byte being wrongly amended somewhere between
;		01/09/01 and 12/11/01. The missiles weren't always firing because of
;		pat_lead being overwritten with wrong values.
;
; 10/12/01	Using top of object as y position for ships looks better than centre or bottom -
;		try it for all alien objects.
;
;		Problem with pattern address offset - 2k won't be enough. 4k would be, I expect.
;		Can we use some of the other bits to encode more offset? No. Too ugly. Expanded
;		the stage overlay to use 6 command bytes instead of 5. Of course this meant
;		recoding the "init_pattern" decoder. Can also have only 47 patterns per stage now
;		without giving the overlay file another 128 bytes.
;
;		Redone top of display list. DLI can't start on 1st line of graphics so a gap of
;		one line with no colour was there. Making the 1st line 1/2 height looks better. 
;
; 08/12/01	At last, missile stuff finished; smoothing of Bresenham line draw, selection of 
;		different kinds of missile by properties of firing object, and lead object firing
;		for following objects.
;
; 04/12/01	Just noticed screen clip stopped working, crashes when off screen. Eventually found
;		to be a mistaken optimizations on "priority". The initial jump address for sprite
;		must be set back to the clip routine address for every sprite. Can't be set once.
;
; 02/12/01	Fix to init_alien to set 2d position as well as position - needed if missile fired
;		right at pattern start
;
; 24/11/01	optimising sort routine, made z pos -ve to mean hide as well as the hide property.
;
; 18/11/01	Removed explosion routine. Incorporated explosions into aliens and scenery for speed
;
;		Start replacing jsr/rts (12 cycles) with jmp/jmp (6 cycles) in code loops
;
; 17/11/01	2d co-ords changes completed. New table for explosion ground check was required.
;		Centre of screen in 2d co-ords is x=128,y=90.
;
; 14/11/01	Remove y mirror command from aliens. it is not used much in real game, and would
;		need an additional y offset to be specified to work like real game. Changes were made
;		to the values of pat_properties and control bits to remove the option.
;
;		Start work on making x get converted to 2d co-ords before draw so that a non-negative
;		more efficient collision check can be done (x co-ords get too big when +/-)
;
; 12/11/01	Fast line draw being investigated for missile firing is holding up development.
;
;		Optimise slot address lookups in frames - have each slot address predefined
;
;		Moved "frames" code into "Priority". no need for frame addr and bank for objects
;
; 02/11/01	Small Optimise in "priority" and removal of extraneous "dey".
;		line up tabbed comments again - messed up after upgrade to winXP which uses notepad.
;
; 28/10/01	Start work on alien firing routine.
;		z_pos_lo size changed from 24 bytes to 18 - not required by bullets. offsets changed
;
; 24/10/01	Small fix to turn off volume only on the sound channel after playing sample.
;		Small change in making scenery more random. Put 1 in 2 chance of no setup
;
; 23/10/01	Change in palette data and all object data, due to new palette sharing method.
;
; 20/10/01	Serious bug on remove object. Locks up often, despite previous testing.
;		Eventually found to be problem in slot_insert. Stack0 object address being updated
;		incorrectly, due to a typo.
;
; 18/10/01	y mirror patterns are going to need a y offset. y=0 is not far from the top of the
;		mountains here, but on real game is much higher in sky. Not fixed yet. Need to think.
;
; 17/10/01	Bug in y position of aliens. Should not make y bottom of object, but the centre.
;		Still looks kind of wrong compared to original - Tilt of zero is when man on ground
;		in original game. This would be perverse the way I've written my code. Try work round.
;
; 16/10/01	Split disk file data off into separate file for stage reference. Ship graphics done
;
; 08/10/01	Changed organisation of disk overlay. Reduced size of stage 0 overlay.
;
; 07/10/01	Setup code for title screen. Added routine to load_background to create a blank
;		background for the title screen
;
; 29/09/01	Bug in pattern decoder fixed where loop counter not reset after first use in pattern.
;
;		Start re-organizing setup code into first time only setup, game initialise code and stage
;		initialise code. General rationalisation of setup code.
;
; 26/09/01	Testing on spread_bit pattern function successful
;
;		Changed .incbin to use relative file names. Found it can do it if no slash is put on the
;		front of the directory. A ".\" is not recognised though. The working directory of the
;		shortcut to atasm is very important - the "atari space harrier" directory is the working 
;		directory and everything is relative to this now.
;
;		Changed the disk data objects such as backgrounds, stage data and objects to have their
;		own directory. They were starting to clutter up the main directory. Also changed them
;		to take advantage of the relative file names with .incbin.
;
; 25/09/01	Master sequencer mostly ready for testing.
;
; 22/09/01	Work started on master sequencer.
;
;		Moved wait_second reliant code (scenery, and now sequencer), into one routine in main
;		loop.
;
; 17/09/01	fixed bug with stripping fire bit in pattern decode.
;
;		Added pat_lead to store object number of the lead object. Changed sum pattern to use
;		the lead object so knows which object to set the timer of, rather than checking the
;		sum bit of all the objects - A bit more elegant maybe. NB Sum pattern must now always
;		use lead_bit if it has an object of its own.
;
; 16/09/01	Merged Notes and Bug fixes (these comments).
;
;		There will be a bug when alien firing is done. The decoder doesn't strip the fire bit
;		from the timer for the pattern (it must leave it for the buffer though).
;
;		Bug in sum pattern where centre alien won't die quick coz its timer not reset. Fixed,
;		but maybe not in a very elegant way. Maybe sum pattern death should go in bullet_hit
;		and try and use the same routine as the control pattern kill?
;
; 12/09/01	Preliminary alien hit and pattern routines still being developed. Testing going better 
;		than might be expected - Most functions seem to be mostly working. Control patterns
;		going quite well. Just problems with the die timing. But, still have sum pattern to test, so
;		there may be a whole bucket load of problems to resolve.
;
; 06/09/01	Optimise completed on tilt. Back to pattern handler now. Look at alien hit stuff
;
; 05/09/01	Completed a working self-modifying clear screen routine, as per earlier notes. I think
;		it can be Optimised slightly though, to take advantage of the constant screen offsets
;		between the a and b screens now. NB, it is part of the "tilt" routine
;
;		Good News. Another 4k memory mislabel has given me back $9000-$9fff. I'm back to the
;		amount of memory I thought I had originally.
;
;		Changing memory map because of this, and to get all a and b screens the same offset
;		from one another, which has resulted in some small code improvements.
;		$2000-$2fff changes from program to screen1b, so it can follow screen1a in $1000-$1fff
;		$2000-$2fff code moves to $3000-3fff which had yet to be filled.
;		$a000-$afff changes from screen1b to program/data
;
; 04/09/01	Back of grid didn't always move up or down a whole pixel every frame. Adjusted the
;		initial value of tilt_lo to be 128, so that tilt by 255/256 gives a movement of 1 in
;		the tilt_hi for the full up/down scroll range. Had to tweak initial z_scoll values
;		in order for the horizon of grid to look right when at lowest range.
;
; 03/09/01	Tilt routine moved from after new_screen, to just before clear_screen. This to enable
;		knowing where background is going to be, to not waste time clearing its screen area
;
;		More elegant way of resuming game after man dies. Just need to re sync the dlist_screen
;		and the draw_screen, to reset any outstanding frames, rather than trying to move back a
;		frame, erasing and redrawing. The old method had problem when frame rate misses caused
;		the displayed screen to be erased and redrawn in plain view, glitching badly. New way
;		fixes that.
;
; 02/09/01	16 frames per second is not realistic. It may hit this with just scenery going, but it
;		will slow when just one or two large frames of aliens or missiles are about.
;		This is a major limitation with having 2 screens for extra colours. Try 12 fps.
;
;		Bug of man dying when bullet over offending object fixed (again). Was due to move of
;		sort table to an area that is normally ROM. sort_table-1 has to be set at 0, and
;		this had been done with .byte. When program loaded, the area is still ROM, so it
;		doesn't get the value. That meant the collision detection for objects with z=0
;		checked the wrong stuff "behind" them. Changed to make initial setup write the value.
;
;		Bug with object flicking into front of screen from nowhere. Happens even when only
;		scenery is running. Must be something to do with scenery then. Maybe x range.
;
;		Bug is actually to do with priority routine changes. object position includes
;		its centre up now, and it can go beyond the hidden left edge of the
;		screen (-95). Before only the centre of the object got dealt with, so the -95 limit
;		would occur less frequently. To get to the centre of screen 96 is added so anything
;		below this really screws up. To fix it, have allowed x to go off screen by 36 pixels
;		(9 bytes). A new table has been created for times 48 minus 9 to get the screen
;		positions quickly. The existing times 48 table reduced in size. Changes to  background.
;
; 01/09/01	Still doing pattern handler. Even infinite repeat Patterns now should kill themselves
;		when their objects are all dead. This code need putting in the object hit routine. It
;		just counts down each object killed until zero left. This allows the sum pattern to be
;		able to check easily if any objects are alive. It just needs to check if any patterns
;		are left. The sum pattern should be allowed an object of it's own, which it's
;		responsible for killing.
;
; 31/08/01	Old position buffer for man collision check had wrong offsets. Caused crashes when
;		more than 4 objects at z=0. Thought it was pattern handler problem initially
;
; 28/08/01	Moved background data to bank 3 to free memory. Done some optimising of priority routine
;
; 27/08/01	Bad news. 4k I thought I had does not exist! There was a typo on the memory position
;		markers for $0700-0fff. It was set to show $0700-1fff. This was the space where I was
;		going to put alien pattern data. Will have to move background data to one of the memory
;		banks. This is 3k.
;
; 25/08/01	Idea for improving clear screen. Already know there's no need to clear space where 
;		background is drawn. But if self modifying code is used, the clear screen can be 
;		smaller as well. Make code able to clear screen_height-background_height, and alter
;		the location in clear_screen either side of where background is. Has to be reset for
;		next clear of that screen
;
; 19/08/01	Change of plan for patterns. Instead of every alien decoding its pattern, have a
;		pattern handler to do that. Saves overhead of decoding. Only need 4 pattern
;		handlers, I reckon. Oh, and a special one for Sum patterns 
;
; 11/08/01	Scrolling background completed a few days ago. Toughest part was to do the 2 pixel
;		shift version of the background for smoother scroll, in a small routine.
;		Started the alien pattern routines. Needs a bit of a rethink from earlier routine.
;		The sequence list for the stage should use more memory as it is overlay ed each stage.
;		Memory can then be freed up in the patterns themselves, which are memory resident.
;
; 06/08/01	Re-draw background after man dies, as per objects. Changed to use stack to save
;		current screen pointers, as the zero page variables were used for background draw
;
; 03/08/01	Background wasn't scrolling soon enough when man moved left/right. Changed screen
;		back to divided evenly into 5 sections per x_scroll and man frame. Was previously
;		in 6 sections with 2 for the middle.
;		Scroll looks right, but man middle frame doesn't seem to be used enough. Needs work.
;
; 29/07/01	The end of game code needs writing to reset the game variables correctly.
;		The setup routine is run at the moment and that doesn't clear the dlist dlis.
;		However it may be quite possible to not have to reinitialised everything.
;
; 28/07/01	first notes apart from the stuff about the size of the objects compared to the
;		original and the memory map.
;		Scoring routines and display mostly finished last week. Work to be done when
;		scoring hits of spinning head objects and dragon segments. They are worth 100,000.
;		When the pattern handler is written, check if object has a control object
;		Current task is the scrolling background.
;
; 28/07/01	Amount of storage for old position check reduced to 12 objects at z=0.
;		Put in constant to easily change and allocate memory space
;
; 27/07/01	Bug in man_die on game end. PMG glitch in dead man sometimes. Due to rest of main
; 		loop being run before game exited - allowing dead man player_b area to be written
;		with screen data and PMG area not to be reset to normal.
;		Solution was to make code exit main loop straight after last man die.
;
; 26/07/01	Bug in man_die. PMG glitch on 1st frame of man death.
;		Initializations of player_index was wrong. Was not set to do a code fetch first.
;		Was 9 which sequencer counts down to 8. Should be 0 which sequencer wraps to 9.
;
; 25/07/01	Started trying to share zero page variables where possible. This may lead to bugs
;		particularly in complex routines and VBI where shares could be used twice. Take care.

;
; graphic sizes of objects compared to original:
;

; Original has resolution of 320*224 (over scanned)
; My Atari screen is now 144*94 (144*85 excluding score and status)
; So the aspect ratio is not the same, the Atari screen being more squashed vertically
; I feel the vertical is the one to base the object sizes on - to avoid them having their tops cut
; off if they're too big (this is because the objects can't draw over the score and status lines)
;
; This gives a size ratio of 94/224, or 42% of original size
;
; Exact frame sizes based on starting at z=1:
; 100%, 80%, 67%, 57%, 50%, 44%, 38%, 33%, 27%, 22%, 18%
;
; However frame sizes start at z=1.25 now, and to reduce pop-up the frames at the back need to
; be made smaller. Everything is so blocky I don't think it's going to matter if we fudge the
; sizes something like this instead:
;
; 100%, 80%, 66%, 56%, 50%, 42%, 35%, 26%, 19%, 12%, 7% 

;   1. Moot
;   2. Geeza
;   3. Amar
;   4. Ceiciel
;   5. Bonus
;   6. Olisis
;   7. Lucasia
;   8. Ida
;   9. Revi
;  10. Minia
;  11. Parms
;  12. Bonus
;  13. Drail
;  14. Asute
;  15. Vicel
;  16. Natura
;  17. Nark
;  18. Absymbel

