Useful
Inventions
Favorite
Quotes
Game
Design
Atari
Memories
Personal
Pages

batari Basic Example Code

For fast copying and pasting.

As an Amazon Associate I earn from qualifying purchases.

This page has most of the batari Basic example program code right in your face instead of hidden in .bas files. Sometimes I need a chunk of code from an example program and it's faster to copy it from this page. I can left click on this paragraph, then use the Tab key to jump down through the sections to browse or use the browser page search to find something specific.

 

 

 

 

Pulsating Color Cycling Example

Pulsating Color Cycling Example on bB page.

 
   ;***************************************************************
   ;
   ;  Pulsating Color Cycling Example
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Player0 color.
   ;
   dim _P0_Luminosity = a.b

   ;```````````````````````````````````````````````````````````````
   ;  Highest brightness.
   ;
   dim _Hue_Brightness_High = c

   ;```````````````````````````````````````````````````````````````
   ;  Lowest brightness.
   ;
   dim _Hue_Brightness_Low = d

   ;```````````````````````````````````````````````````````````````
   ;  Tiny little itty-bitty bit variables.
   ;
   dim _Bit0_Reset_Restrainer = y
   dim _Bit6_Sequence_Switch = y





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Sets score color.
   ;
   scorecolor = $00


   ;***************************************************************
   ;
   ;  Defines the highest brightness.
   ;
   _Hue_Brightness_High = $0C


   ;***************************************************************
   ;
   ;  Defines the lowest brightness.
   ;
   _Hue_Brightness_Low = $04


   ;***************************************************************
   ;
   ;  Sets the luminosity variable.
   ;
   _P0_Luminosity = $02


   ;***************************************************************
   ;
   ;  Sets starting position of player0.
   ;
   player0x = 66 : player0y = 65


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Defines shape of Player0 sprite.
   ;
   player0:
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Color cycling.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Brightness increase section. (When switch bit is off.)
   ;  Skips to brightness decrease section if switch bit is on.
   ;
   if _Bit6_Sequence_Switch{6} then goto __Switch_Bit_On

   ;```````````````````````````````````````````````````````````````
   ;  Increases the player0 luminosity variable.
   ;
   _P0_Luminosity = _P0_Luminosity + 0.22

   ;```````````````````````````````````````````````````````````````
   ;  The switch bit is turned on and the hue is changed for the
   ;  next loop around if luminosity variable reaches highest
   ;  defined brightness.
   ;
   if _P0_Luminosity >= _Hue_Brightness_High then _Bit6_Sequence_Switch{6} = 1 : _Hue_Brightness_High = _Hue_Brightness_High + $10
   
   goto __Skip_Hue_Change

   ;```````````````````````````````````````````````````````````````
   ;  Brightness decrease section. (When switch bit is on.)
   ;
__Switch_Bit_On

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the luminosity variable.
   ;
    _P0_Luminosity = _P0_Luminosity - 0.22

   ;```````````````````````````````````````````````````````````````
   ;  The switch bit is turned off, the hue is changed, and the
   ;  luminosity variable is updated if luminosity variable
   ;  reaches lowest defined brightness.
   ;
   if _P0_Luminosity <= _Hue_Brightness_Low then _Bit6_Sequence_Switch{6} = 0 : _Hue_Brightness_Low = _Hue_Brightness_Low + $10 : _P0_Luminosity = _Hue_Brightness_Low


__Skip_Hue_Change



   ;***************************************************************
   ;
   ;  Player0 luminosity.
   ;
   COLUP0 = _P0_Luminosity



   ;***************************************************************
   ;
   ;  Sets the width of player0.
   ;
   NUSIZ0 = 7



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````

 

 

 

Pulsating Hue Example

Pulsating Hue Example on bB page.

 
   ;***************************************************************
   ;
   ;  Pulsating Hue Example
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Player0 luminosity.
   ;
   dim _P0_Luminosity = a.b

   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _Bit0_Reset_Restrainer = y
   dim _Bit6_Sequence_Switch = y





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Sets score color.
   ;
   scorecolor = $00


   ;***************************************************************
   ;
   ;  Sets the player0 luminosity variable.
   ;
   _P0_Luminosity = $10


   ;***************************************************************
   ;
   ;  Sets starting position of player0.
   ;
   player0x = 77 : player0y = 55


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Defines shape of player0 sprite.
   ;
   player0:
   %11111111
   %01111110
   %00011000
   %00011000
   %00011000
   %00111100
   %00111100
   %00011000
   %00011000
   %00011000
   %00111100
   %01111110
   %11111111
   %11111111
   %11111111
end






   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Pulsating object.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Makes luminosity brighter if bit is off and checks to see if
   ;  it's time to start making the luminosity darker.
   ;
   if !_Bit6_Sequence_Switch{6} then _P0_Luminosity = _P0_Luminosity + 0.30 : if _P0_Luminosity >= $20 then _Bit6_Sequence_Switch{6} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Makes luminosity darker if bit is on and checks to see if
   ;  it's time to start making the luminosity brighter.
   ;
   if _Bit6_Sequence_Switch{6} then _P0_Luminosity = _P0_Luminosity - 0.30 : if _P0_Luminosity <= $12 then _P0_Luminosity = $10 : _Bit6_Sequence_Switch{6} = 0



   ;***************************************************************
   ;
   ;  Player0 color.
   ;
   COLUP0 = _P0_Luminosity



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````

 

 

 

Pulsating Cursor Example

Pulsating Cursor Example on bB page.

 
   ;***************************************************************
   ;
   ;  Pulsating Cursor Example
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Player0 luminosity.
   ;
   dim _Cursor_Luminosity = a.b

   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _Bit0_Reset_Restrainer = y
   dim _Bit6_Cursor_Throb = y





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Sets score color.
   ;
   scorecolor = $00


   ;***************************************************************
   ;
   ;  Sets the player0 luminosity variable.
   ;
   _Cursor_Luminosity = $02


   ;***************************************************************
   ;
   ;  Sets starting position of player0.
   ;
   player0x = 82 : player0y = 57


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Defines shape of player0 sprite.
   ;
   player0:
   %00000000
   %00000000
   %00000000
   %11000000
   %11000000
   %11000000
   %11000000
   %11000000
end






   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Pulsating cursor.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Makes luminosity brighter if bit is off and checks to see if
   ;  it's time to start making the luminosity darker.
   ;
   if !_Bit6_Cursor_Throb{6} then _Cursor_Luminosity = _Cursor_Luminosity + 0.25 : if _Cursor_Luminosity >= $0C then _Cursor_Luminosity = $0B : _Bit6_Cursor_Throb{6} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Makes luminosity darker if bit is on and checks to see if
   ;  it's time to start making the luminosity brighter.
   ;
   if _Bit6_Cursor_Throb{6} then _Cursor_Luminosity = _Cursor_Luminosity - 0.25 : if _Cursor_Luminosity <= $01 then _Cursor_Luminosity = $02 : _Bit6_Cursor_Throb{6} = 0



   ;***************************************************************
   ;
   ;  Player0 color.
   ;
   COLUP0 = _Cursor_Luminosity



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````

 

 

 

Move a Sprite Example

Move a Sprite Example on bB page.

 
   ;***************************************************************
   ;
   ;  Move a Sprite
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Use the joystick to move the sprite.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  All-purpose bits for various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for an 8 x 8 sprite.
   ;  If your sprite is a different size, you`ll need to adjust
   ;  the numbers.
   ;
   const _P_Edge_Top = 9
   const _P_Edge_Bottom = 88
   const _P_Edge_Left = 1
   const _P_Edge_Right = 153



   ;***************************************************************
   ;
   ;  Disables the score. (We don`t need it in this program.)
   ;
   const noscore = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0


   ;***************************************************************
   ;
   ;  Sets starting position of player0.
   ;
   player0x = 77 : player0y = 53


   ;***************************************************************
   ;
   ;  Sets playfield color.
   ;
   COLUPF = $2C


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Defines shape of player0 sprite.
   ;
   player0:
   %00111100
   %01111110
   %11000011
   %10111101
   %11111111
   %11011011
   %01111110
   %00111100
end


   ;***************************************************************
   ;
   ;  Sets up the playfield.
   ;
   playfield:
   ................................
   ................................
   ....XXXXXXXXXX....XXXXXXXXXX....
   ....X......................X....
   ....X......................X....
   ....X......................X....
   ................................
   ................................
   ....XXXX....XXXXXXXX....XXXX....
   ................................
   ................................
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets color of player0 sprite.
   ;
   COLUP0 = $9C



   ;***************************************************************
   ;
   ;  Moves player0 sprite with the joystick while keeping the
   ;  sprite within the playfield area.
   ;
   if joy0up && player0y > _P_Edge_Top then player0y = player0y - 1

   if joy0down && player0y < _P_Edge_Bottom then player0y = player0y + 1

   if joy0left && player0x > _P_Edge_Left then player0x = player0x - 1

   if joy0right && player0x < _P_Edge_Right then player0x = player0x + 1



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart

 

 

 

Jumping Sprite Example

Jumping Sprite Example on bB page.

 
   ;***************************************************************
   ;
   ;  Jumping Sprite Example Program
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;****************************************************************
   ;
   ;  The kernel option below causes the loss of missile1.
   ;
   set kernel_options player1colors



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit7_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Player1 left/right movement.
   ;
   dim _P1_Left_Right = player1x.a

   ;```````````````````````````````````````````````````````````````
   ;  Limits how high player can jump and affects speed slowdown.
   ;
   dim _Jump_Gravity_Counter = b

   ;```````````````````````````````````````````````````````````````
   ;  Fake gravity fall counter.
   ;
   dim _Fall_Gravity_Counter = c

   ;```````````````````````````````````````````````````````````````
   ;  Controls animation speed.
   ;
   dim _Master_Counter = d

   ;```````````````````````````````````````````````````````````````
   ;  Animation counter.
   ;
   dim _Frame_Counter = e

   ;```````````````````````````````````````````````````````````````
   ;  Channel 0 sound variables.
   ;
   dim _Ch0_Sound = f
   dim _Ch0_Duration = g
   dim _Ch0_Counter = h

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  All-purpose bits for various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit2_Fall_in_Progress = y      ; Player is falling if on.
   dim _Bit3_FireB_Restrainer = y      ; Player can't hold down fire button to jump.
   dim _Bit4_Flip_P1 = y               ; Flips player sprite when necessary.
   dim _Bit5_LR_Joy_Movement = y       ; Left or right joystick movement happened.
   dim _Bit6_Duck_in_Progress = y      ; Allows player to slide while duckting.
   dim _Bit7_Reset_Restrainer = y      ; Restrains the reset switch.



   ;***************************************************************
   ;
   ;  Constants for channel 0 sound effects (_Ch0_Sound).
   ;  [The c stands for constant.]
   ;
   const _c_Jump_Sound = 1



   ;****************************************************************
   ;
   ;  NTSC colors.
   ;
   ;  Use these constants so you can quickly and easily swap them
   ;  out for PAL-60 colors. Or use this if you created a PAL-60
   ;  game and want to instantly convert the colors to NTSC (if you
   ;  were already using the PAL-60 constants).
   ;
   const _00 = $00
   const _02 = $02
   const _04 = $04
   const _06 = $06
   const _08 = $08
   const _0A = $0A
   const _0C = $0C
   const _0E = $0E
   const _10 = $10
   const _12 = $12
   const _14 = $14
   const _16 = $16
   const _18 = $18
   const _1A = $1A
   const _1C = $1C
   const _1E = $1E
   const _20 = $20
   const _22 = $22
   const _24 = $24
   const _26 = $26
   const _28 = $28
   const _2A = $2A
   const _2C = $2C
   const _2E = $2E
   const _30 = $30
   const _32 = $32
   const _34 = $34
   const _36 = $36
   const _38 = $38
   const _3A = $3A
   const _3C = $3C
   const _3E = $3E
   const _40 = $40
   const _42 = $42
   const _44 = $44
   const _46 = $46
   const _48 = $48
   const _4A = $4A
   const _4C = $4C
   const _4E = $4E
   const _50 = $50
   const _52 = $52
   const _54 = $54
   const _56 = $56
   const _58 = $58
   const _5A = $5A
   const _5C = $5C
   const _5E = $5E
   const _60 = $60
   const _62 = $62
   const _64 = $64
   const _66 = $66
   const _68 = $68
   const _6A = $6A
   const _6C = $6C
   const _6E = $6E
   const _70 = $70
   const _72 = $72
   const _74 = $74
   const _76 = $76
   const _78 = $78
   const _7A = $7A
   const _7C = $7C
   const _7E = $7E
   const _80 = $80
   const _82 = $82
   const _84 = $84
   const _86 = $86
   const _88 = $88
   const _8A = $8A
   const _8C = $8C
   const _8E = $8E
   const _90 = $90
   const _92 = $92
   const _94 = $94
   const _96 = $96
   const _98 = $98
   const _9A = $9A
   const _9C = $9C
   const _9E = $9E
   const _A0 = $A0
   const _A2 = $A2
   const _A4 = $A4
   const _A6 = $A6
   const _A8 = $A8
   const _AA = $AA
   const _AC = $AC
   const _AE = $AE
   const _B0 = $B0
   const _B2 = $B2
   const _B4 = $B4
   const _B6 = $B6
   const _B8 = $B8
   const _BA = $BA
   const _BC = $BC
   const _BE = $BE
   const _C0 = $C0
   const _C2 = $C2
   const _C4 = $C4
   const _C6 = $C6
   const _C8 = $C8
   const _CA = $CA
   const _CC = $CC
   const _CE = $CE
   const _D0 = $D0
   const _D2 = $D2
   const _D4 = $D4
   const _D6 = $D6
   const _D8 = $D8
   const _DA = $DA
   const _DC = $DC
   const _DE = $DE
   const _E0 = $E0
   const _E2 = $E2
   const _E4 = $E4
   const _E6 = $E6
   const _E8 = $E8
   const _EA = $EA
   const _EC = $EC
   const _EE = $EE
   const _F0 = $F0
   const _F2 = $F2
   const _F4 = $F4
   const _F6 = $F6
   const _F8 = $F8
   const _FA = $FA
   const _FC = $FC
   const _FE = $FE






   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP SETUP
   ;
   ;
__Main_Loop_Setup


   ;***************************************************************
   ;
   ;  Sets position of player1 sprite.
   ;
   player1x = 79 : player1y = 79


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit7_Reset_Restrainer{7} = 1


   ;***************************************************************
   ;
   ;  Sets up the playfield.
   ;
   playfield:
   ................................
   ................................
   ................................
   ................................
   ................................
   ................................
   ................................
   ................................
   ................................
   ................................
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets colors.
   ;
   COLUPF = _C4 : COLUBK = _00



   ;***************************************************************
   ;
   ;  Controls animation speed.
   ;
   _Master_Counter = _Master_Counter + 1

   if _Master_Counter < 4 then goto __Skip_Frame_Counter

   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   if _Frame_Counter = 4 then _Frame_Counter = 0

__Skip_Frame_Counter



   ;***************************************************************
   ;
   ;  Default standing still position for player1 sprite.
   ;
   player1color:
   _26
   _9C
   _9C
   _9C
   _DA
   _DA
   _3C
   _3C
   _3C
   _26
end

   player1:
   %01100110
   %00100100
   %00111100
   %00011000
   %01011010
   %00111100
   %00011000
   %00111100
   %00111100
   %00011000
end



   ;***************************************************************
   ;
   ;  Fire button (jump) section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if fire button is not pressed.
   ;
   if !joy0fire then _Jump_Gravity_Counter = 0 : _Bit3_FireB_Restrainer{3} = 0 : goto __Skip_Jump

   ;```````````````````````````````````````````````````````````````
   ;  Used when player moves left/right while jumping or falling.
   ;
   if !_Bit3_FireB_Restrainer{3} then player1:
   %11000011
   %01100011
   %00111110
   %00011100
   %00111101
   %01011110
   %00011000
   %00111100
   %00111100
   %00011000
end

   ;```````````````````````````````````````````````````````````````
   ;  Arms up sprite used if player isn't moving left or right.
   ;
   if !joy0left && !joy0right && !_Bit3_FireB_Restrainer{3} then  player1:
   %01100110
   %00100100
   %00111100
   %00011000
   %00011000
   %01111110
   %10011001
   %00111100
   %00111100
   %00011000
end

   ;```````````````````````````````````````````````````````````````
   ;  Skips jump if player is falling.
   ;
   if _Bit2_Fall_in_Progress{2} then goto __Skip_Jump

   ;```````````````````````````````````````````````````````````````
   ;  Skips jump if fire button restrainer bit is on and jump and
   ;  fall are not happening. Fixes it so the player can't hold
   ;  down the fire button to jump repeatedly.
   ;
   if _Bit3_FireB_Restrainer{3} && !_Bit2_Fall_in_Progress{2} && !_Jump_Gravity_Counter then goto __Skip_Jump

   ;```````````````````````````````````````````````````````````````
   ;  Starts jumping sound effect if jump is not happening.
   ;
   if !_Jump_Gravity_Counter then _Ch0_Sound = _c_Jump_Sound : _Ch0_Duration = 1 : _Ch0_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Turns on restrainer bit for fire button.
   ;
   _Bit3_FireB_Restrainer{3} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Adds one to the jump counter.
   ;
   _Jump_Gravity_Counter = _Jump_Gravity_Counter + 1 

   ;```````````````````````````````````````````````````````````````
   ;  Resets jump counter if limit is reached and starts a fall.
   ;  The higher the number used here, the higher the jump.
   ;
   if _Jump_Gravity_Counter > 12 then _Jump_Gravity_Counter = 0 : _Bit2_Fall_in_Progress{2} = 1 : goto __Skip_Jump

   ;```````````````````````````````````````````````````````````````
   ;  Jump happens here.  
   ;
   ;  Skips jump if player1 sprite is at top edge of screen.
   ;
   if player1y < 13 then goto __Skip_Jump

   ;```````````````````````````````````````````````````````````````
   ;  Changes speed of jump over time depending on counter number.
   ;  (Slows down the higher it goes.)
   ;
   if _Jump_Gravity_Counter <= 7 then temp6 = 3
   if _Jump_Gravity_Counter > 7 && _Jump_Gravity_Counter <= 10 then temp6 = 2
   if _Jump_Gravity_Counter > 10 then temp6 = 1

   ;```````````````````````````````````````````````````````````````
   ;  Moves player1 sprite up the screen.
   ;
   player1y = player1y - temp6

__Skip_Jump



   ;***************************************************************
   ;
   ;  Fall down section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if player is jumping.
   ;
   if _Jump_Gravity_Counter then goto __Skip_Fall_01

   ;```````````````````````````````````````````````````````````````
   ;  Skips section if player is on the ground.
   ;
   if player1y >= 79 then player1y = 80 : goto __Skip_Fall_01

   ;```````````````````````````````````````````````````````````````
   ;  Used when player moves left/right while jumping or falling.
   ;
   player1:
   %11000011
   %01100011
   %00111110
   %00011100
   %00111101
   %01011110
   %00011000
   %00111100
   %00111100
   %00011000
end

   ;```````````````````````````````````````````````````````````````
   ;  Arms up sprite used if player isn't moving left or right.
   ;
   if !joy0left && !joy0right then player1:
   %01100110
   %00100100
   %00111100
   %00011000
   %00011000
   %01111110
   %10011001
   %00111100
   %00111100
   %00011000
end

   ;```````````````````````````````````````````````````````````````
   ;  Adds one to the gravity counter.
   ;
   _Fall_Gravity_Counter = _Fall_Gravity_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Fake gravity fall (speed keeps increasing during a fall).
   ;
   temp6 = 0
   if _Fall_Gravity_Counter > 8 && _Jump_Gravity_Counter <= 16 then temp6 = 1
   if _Fall_Gravity_Counter > 16 && _Jump_Gravity_Counter <= 24 then temp6 = 2
   if _Fall_Gravity_Counter > 24 && _Jump_Gravity_Counter <= 32 then temp6 = 3
   if _Fall_Gravity_Counter > 32 then temp6 = 4

   ;```````````````````````````````````````````````````````````````
   ;  Moves player1 down the screen.
   ;
   player1y = player1y + temp6

   ;```````````````````````````````````````````````````````````````
   ;  Lets the program know a fall is in progress.
   ;
   _Bit2_Fall_in_Progress{2} = 1

   goto __Skip_Fall_02

__Skip_Fall_01

   ;```````````````````````````````````````````````````````````````
   ;  Not falling. Clears related variables.
   ;
   _Bit2_Fall_in_Progress{2} = 0 : _Fall_Gravity_Counter = 0

__Skip_Fall_02



   ;***************************************************************
   ;
   ;  Clears left/right joystick movement bit.
   ;
   _Bit5_LR_Joy_Movement{5} = 0



   ;***************************************************************
   ;
   ;  Left movement section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick not moved left.
   ;
   if !joy0left then goto __Skip_Joy0Left

   ;```````````````````````````````````````````````````````````````
   ;  Turns on left/right movement bit.
   ;
   _Bit5_LR_Joy_Movement{5} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Moves player1 left if not hitting border.
   ;
   if player1x > 17 then _P1_Left_Right = _P1_Left_Right - 1.38

   ;```````````````````````````````````````````````````````````````
   ;  Makes sure player1 sprite is facing the correct direction.
   ;
   _Bit4_Flip_P1{4} = 0

__Skip_Joy0Left



   ;***************************************************************
   ;
   ;  Right movement section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick not moved left.
   ;
   if !joy0right then goto __Skip_Joy0Right

   ;```````````````````````````````````````````````````````````````
   ;  Turns on left/right movement bit.
   ;
   _Bit5_LR_Joy_Movement{5} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Moves player1 right if not hitting border.
   ;
   if player1x < 137 then _P1_Left_Right = _P1_Left_Right + 1.38

   ;```````````````````````````````````````````````````````````````
   ;  Makes sure player1 sprite is facing the correct direction.
   ;
   _Bit4_Flip_P1{4} = 1

__Skip_Joy0Right



   ;***************************************************************
   ;
   ;  Left/right walking animation section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips animation if joystick not moved left or right.
   ;
   if !_Bit5_LR_Joy_Movement{5} then  goto __Done_Anim_jump

   ;```````````````````````````````````````````````````````````````
   ;  Skips animation if player1 sprite is jumping or falling.
   ;
   if _Jump_Gravity_Counter || _Bit2_Fall_in_Progress{2} then goto __Done_Anim_jump

   ;```````````````````````````````````````````````````````````````
   ;  Skips animation if player1 sprite is hitting left/right edge.
   ;
   if player1x < 18 || player1x > 136 then goto __Done_Anim_jump

   ;```````````````````````````````````````````````````````````````
   ;  Sets player1 color.
   ;
   player1color:
   _26
   _9C
   _9C
   _9C
   _DA
   _DA
   _3C
   _3C
   _3C
   _26
end

   ;```````````````````````````````````````````````````````````````
   ;  Animates player1 sprite.
   ;
   on _Frame_Counter goto __Frame0 __Frame1 __Frame0 __Frame2

__Done_Anim_jump



   ;****************************************************************
   ;
   ;  Flips player1 sprite horizontally when necessary.
   ;
   if _Bit4_Flip_P1{4} then REFP1 = 8



   ;***************************************************************
   ;
   ;  Channel 0 sound effect check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 0 sounds if sounds are off.
   ;
   if !_Ch0_Sound then goto __Skip_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the channel 0 duration counter.
   ;
   _Ch0_Duration = _Ch0_Duration - 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 0 sounds if duration counter is greater
   ;  than zero
   ;
   if _Ch0_Duration then goto __Skip_Ch_0



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 001.
   ;
   ;  Jump sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 001 isn't on.
   ;
   if _Ch0_Sound <> _c_Jump_Sound then goto __Skip_Ch0_Sound_001

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Jump[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Jump[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Jump[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets Duration.
   ;
   _Ch0_Duration = _SD_Jump[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_001



   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Other channel 0 sound effects go here.
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````



   ;***************************************************************
   ;
   ;  Jumps to end of channel 0 area. (This catches any mistakes.)
   ;
   goto __Skip_Ch_0



   ;***************************************************************
   ;
   ;  Clears channel 0.
   ;
__Clear_Ch_0
   
   _Ch0_Sound = 0 : AUDV0 = 0



   ;***************************************************************
   ;
   ;  End of channel 0 area.
   ;
__Skip_Ch_0



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  If the reset switch is not pressed, turns off reset
   ;  restrainer bit and jumps to beginning of main loop.
   ;
   if !switchreset then _Bit7_Reset_Restrainer{7} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  If reset switch hasn't been released after being pressed,
   ;  program jumps to beginning of main loop.
   ;
   if _Bit7_Reset_Restrainer{7} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Reset pressed correctly, so the the program is restarted.
   ;
   goto __Start_Restart




   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  End of main loop.
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````




   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data starts here.
   ;
   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for jump.
   ;
   data _SD_Jump
   1,12,31
   1
   8,12,31
   1
   6,12,31
   1
   8,12,31
   1
   8,12,30
   1
   8,12,29
   1
   8,12,28
   1
   8,12,27
   1
   8,12,26
   1
   8,12,25
   1
   8,12,24
   1
   8,12,23
   1
   8,12,22
   1
   8,12,21
   1
   8,12,20
   1
   8,12,19
   1
   6,12,18
   1
   4,12,17
   1
   2,12,16
   2
   0,0,0
   8
   255
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Animation frames for player1.
   ;
__Frame0
   player1:
   %01100110
   %00100110
   %00111100
   %00011100
   %00111100
   %00011100
   %00011000
   %00111100
   %00111100
   %00011000
end

   goto __Done_Anim_jump


__Frame1
   player1:
   %11000011
   %01100011
   %00111110
   %00011100
   %00111100
   %01011110
   %00011000
   %00111100
   %00111100
   %00011000
end

   goto __Done_Anim_jump


__Frame2
   player1:
   %00111100
   %00011100
   %00011100
   %00011100
   %00011100
   %00011100
   %00011000
   %00111100
   %00111100
   %00011000
end

   goto __Done_Anim_jump

 

 

 

Move a Sprite With Smooth Slide

Move a Sprite With Smooth Slide on bB page.

 
   ;***************************************************************
   ;
   ;  Move a Sprite With Smooth Slide
   ;
   ;  Example program by Lillapojkenpaon and adapted by Duane Alan
   ;  Hahn (Random Terrain) using hints, tips, code snippets, and
   ;  more from AtariAge members such as batari, SeaGtGruff,
   ;  RevEng, Robert M, Nukey Shay, Atarius Maximus, jrok,
   ;  supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Use the joystick to move the sprite. Stop moving the sprite
   ;  to watch it slide.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Player0 fractional values for smoother movement.
   ;
   dim _P0x = player0x.a
   dim _P0y = player0y.b

   ;```````````````````````````````````````````````````````````````
   ;  Speed variables (fractional values for smoother movement).
   ;
   dim _P0xSpeed1 = c.d
   dim _P0xSpeed2 = d
   dim _P0ySpeed1 = e.f
   dim _P0ySpeed2 = f

   ;```````````````````````````````````````````````````````````````
   ;  All-purpose bits for various jobs.
   ;
   dim _Bit0_Reset_Restrainer = g ; Reset switch becomes inactive if it hasn't been released.
   dim _Bit2_SlideU = g           ; Bit is turned on if joystick pushed up.
   dim _Bit3_SlideD = g           ; Bit is turned on if joystick pushed down.
   dim _Bit4_SlideL = g           ; Bit is turned on if joystick pushed left.
   dim _Bit5_SlideR = g           ; Bit is turned on if joystick pushed right.



   ;***************************************************************
   ;
   ;  Acceleration amount. Change this number to change the
   ;  acceleration throughout the code.
   ;
   ;  The def statement is similar to the dim statement, but it
   ;  lets you define an entire string and assign it to a logical
   ;  name. [The d stands for def.]
   ;
   def _d_Acceleration=0.060



   ;***************************************************************
   ;
   ;  Disables the score. (We don't need it in this program.)
   ;
   const noscore = 1



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for an 8 x 8 sprite.
   ;  If your sprite is a different size, you`ll need to adjust
   ;  the numbers. [The c stands for constant.]
   ;
   const _c_Edge_Top = 9
   const _c_Edge_Bottom = 88
   const _c_Edge_Left = 1
   const _c_Edge_Right = 153



   ;***************************************************************
   ;
   ;  Maximum speed. Increase this number to make sprite faster.
   ;  [The c stands for constant.]
   ;
   const _c_Max_Speed = 2






   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0


   ;***************************************************************
   ;
   ;  Sets starting position of player0.
   ;
   player0x = 77 : player0y = 53


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Defines shape of player0 sprite.
   ;
   player0:
   %00111100
   %01111110
   %11000011
   %10111101
   %11111111
   %11011011
   %01111110
   %00111100
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets color of player0 sprite.
   ;
   COLUP0 = $9C



   ;***************************************************************
   ;
   ;  Up movement section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips up section if player0 sprite is sliding down.
   ;
   if _Bit3_SlideD{3} then __Skip_Up_Slide

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to up slide subsection if joystick not pushed up.
   ;
   if !joy0up then __Up_Slide

   ;```````````````````````````````````````````````````````````````
   ;  Increases speed if not at maximum.
   ;
   if _P0ySpeed1 < _c_Max_Speed then _P0ySpeed1 = _P0ySpeed1 + _d_Acceleration

   ;```````````````````````````````````````````````````````````````
   ;  Turns on up slide bit.
   ;  (Remembers direction when joystick is let go.)
   ;
   _Bit2_SlideU{2} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to sprite movement (skips slide).
   ;
   goto __Move_Up

__Up_Slide

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Skips slide if up slide bit is off.
   ;
   if !_Bit2_SlideU{2} then __Skip_Up_Slide

   ;```````````````````````````````````````````````````````````````
   ;  Decreases slide speed.
   ;
   _P0ySpeed1 = _P0ySpeed1 - _d_Acceleration

   ;```````````````````````````````````````````````````````````````
   ;  Turns off up slide bit if both integer and fraction of
   ;  speed is zero.
   ;
   if _P0ySpeed1 = 0 && _P0ySpeed2 = 0 then _Bit2_SlideU{2} = 0

__Move_Up

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 sprite up.
   ;
   _P0y = _P0y - _P0ySpeed1

   ;```````````````````````````````````````````````````````````````
   ;  Keeps player0 sprite from moving beyond edge of screen.
   ;
   if player0y <= _c_Edge_Top then player0y = _c_Edge_Top : _P0ySpeed1 = 0 : _P0ySpeed2 = 0 : _Bit2_SlideU{2} = 0

__Skip_Up_Slide



   ;***************************************************************
   ;
   ;  Down movement section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips down section if player0 sprite is sliding up.
   ;
   if _Bit2_SlideU{2} then __Skip_Down_Slide

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to down slide subsection if joystick not pushed down.
   ; 
   if !joy0down then __Down_Slide

   ;```````````````````````````````````````````````````````````````
   ;  Increases speed if not at maximum.
   ;
   if _P0ySpeed1 < _c_Max_Speed then _P0ySpeed1 = _P0ySpeed1 + _d_Acceleration

   ;```````````````````````````````````````````````````````````````
   ;  Turns on down slide bit.
   ;  (Remembers direction when joystick is let go.)
   ;
   _Bit3_SlideD{3} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to sprite movement (skips slide).
   ;
   goto __Move_Down
   
__Down_Slide

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Skips slide if down slide bit is off.
   ;
   if !_Bit3_SlideD{3} then __Skip_Down_Slide

   ;```````````````````````````````````````````````````````````````
   ;  Decreases slide speed.
   ; 
   _P0ySpeed1 = _P0ySpeed1 - _d_Acceleration

   ;```````````````````````````````````````````````````````````````
   ;  Turns off down slide bit if both integer and fraction of
   ;  speed is zero.
   ;
   if _P0ySpeed1 = 0 && _P0ySpeed2 = 0 then _Bit3_SlideD{3} = 0

__Move_Down

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 sprite down.
   ;
   _P0y = _P0y + _P0ySpeed1

   ;```````````````````````````````````````````````````````````````
   ;  Keeps player0 sprite from moving beyond edge of screen.
   ;
   if player0y >= _c_Edge_Bottom then player0y = _c_Edge_Bottom : _P0ySpeed1 = 0 : _P0ySpeed2 = 0 : _Bit3_SlideD{3} = 0

__Skip_Down_Slide



   ;***************************************************************
   ;
   ;  Left movement section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips left section if player0 sprite is sliding right.
   ;
   if _Bit5_SlideR{5} then __Skip_Left_Slide

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to left slide subsection if joystick not pushed left.
   ;
   if !joy0left then __Left_Slide

   ;```````````````````````````````````````````````````````````````
   ;  Increases speed if not at maximum.
   ;
   if _P0xSpeed1 < _c_Max_Speed then _P0xSpeed1 = _P0xSpeed1 + _d_Acceleration

   ;```````````````````````````````````````````````````````````````
   ;  Turns on left slide bit.
   ;  (Remembers direction when joystick is let go.)
   ;
   _Bit4_SlideL{4} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to sprite movement (skips slide).
   ;
   goto __Move_Left

__Left_Slide

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Skips slide if left slide bit is off.
   ;
   if !_Bit4_SlideL{4} then __Skip_Left_Slide

   ;```````````````````````````````````````````````````````````````
   ;  Decreases slide speed.
   ;
   _P0xSpeed1 = _P0xSpeed1 - _d_Acceleration

   ;```````````````````````````````````````````````````````````````
   ;  Turns off left slide bit if both integer and fraction of
   ;  speed is zero.
   ;
   if _P0xSpeed1 = 0 && _P0xSpeed2 = 0 then _Bit4_SlideL{4} = 0

__Move_Left

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 sprite to the left.
   ;
   _P0x = _P0x - _P0xSpeed1

   ;```````````````````````````````````````````````````````````````
   ;  Keeps player0 sprite from moving beyond edge of screen.
   ;
   if player0x <= _c_Edge_Left || player0x > 200 then player0x = _c_Edge_Left : _P0xSpeed1 = 0 : _P0xSpeed2 = 0 : _Bit4_SlideL{4} = 0

__Skip_Left_Slide



   ;***************************************************************
   ;
   ;  Right movement section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips right section if player0 sprite is sliding left.
   ;
   if _Bit4_SlideL{4} then __Skip_Right_Slide

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to right slide subsection if joystick not pushed right.
   ;
   if !joy0right then __Right_Slide

   ;```````````````````````````````````````````````````````````````
   ;  Increases speed if not at maximum.
   ;
   if _P0xSpeed1 < _c_Max_Speed then _P0xSpeed1 = _P0xSpeed1 + _d_Acceleration

   ;```````````````````````````````````````````````````````````````
   ;  Turns on right slide bit.
   ;  (Remembers direction when joystick is let go.)
   ;
   _Bit5_SlideR{5} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to sprite movement (skips slide).
   ;
   goto __Move_Right

__Right_Slide

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Skips slide if right slide bit is off.
   ;
   if !_Bit5_SlideR{5} then __Skip_Right_Slide

   ;```````````````````````````````````````````````````````````````
   ;  Decreases speed every frame.
   ;
   _P0xSpeed1 = _P0xSpeed1 - _d_Acceleration

   ;```````````````````````````````````````````````````````````````
   ;  Turns off right slide bit if both integer and fraction of
   ;  speed is zero.
   ;
   if _P0xSpeed1 = 0 && _P0xSpeed2 = 0 then _Bit5_SlideR{5} = 0

__Move_Right

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 sprite to the right.
   ;
   _P0x = _P0x + _P0xSpeed1

   ;```````````````````````````````````````````````````````````````
   ;  Keeps player0 sprite from moving beyond edge of screen.
   ;
   if player0x >= _c_Edge_Right then player0x = _c_Edge_Right : _P0xSpeed1 = 0 : _P0xSpeed2 = 0 : _Bit5_SlideR{5} = 0

__Skip_Right_Slide



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart

 

 

 

Smooth Chase With Bresenham-Like Code

Smooth Chase With Bresenham-Like Code on bB page.

 
   ;***************************************************************
   ;
   ;  Smooth Chase With Bresenham-Like Code
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;  Bresenham-like code provided by bogax:
   ;
   ;  http://atariage.com/forums/topic/235814-some-movement-code/
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Use the joystick to move the sprite as another sprite
   ;  chases you. Press the fire button to make the other
   ;  sprite chase you faster.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Removes overhead from data tables, saving space. Doing so
   ;  will limit them to outside of code. That is, you can no
   ;  longer place data tables inline with code, or your program
   ;  may crash! 
   ;
   set optimization noinlinedata



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Bresenham-related variables.
   ;
   dim _error_accumulator = a
   dim _delta_y = b
   dim _delta_x = c
   dim _octant = g
   dim _Chase_Delay = h

   ;```````````````````````````````````````````````````````````````
   ;  Bits that do various jobs.
   ;
   dim _Bit0_Reset_Restrainer = y
   dim _Bit5_EA = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers.
   ;
   dim rand16 = z



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for an 8 x 8 sprite.
   ;  If your sprite is a different size, you`ll need to adjust
   ;  the numbers.
   ;
   const _P_Edge_Top = 9
   const _P_Edge_Bottom = 88
   const _P_Edge_Left = 1
   const _P_Edge_Right = 153



   ;***************************************************************
   ;
   ;  Disables the score. (We don`t need it in this program.)
   ;
   const noscore = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears 25 of the normal 26 variables (fastest way).
   ;  The variable z is used for random numbers in this program
   ;  and clearing it would mess up those random numbers.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0


   ;***************************************************************
   ;
   ;  Sets starting position of player1.
   ;
   player1x = 77 : player1y = 53


   ;***************************************************************
   ;
   ;  Sets random starting position of player0.
   ;
   player0x = (rand/2) + (rand&15) + 5 : player0y = 9


   ;***************************************************************
   ;
   ;  Sets playfield color.
   ;
   COLUPF = $FC


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Defines shape of player1 sprite.
   ;
   player1:
   %00111100
   %01111110
   %11000011
   %10111101
   %11111111
   %11011011
   %01111110
   %00111100
end


   ;***************************************************************
   ;
   ;  Defines shape of player0 sprite.
   ;
   player0:
   %00111100
   %01100110
   %11000011
   %11000011
   %11111111
   %11011011
   %01111110
   %00111100
end


   ;***************************************************************
   ;
   ;  Sets up the chase.
   ;
   goto __Chase_Setup





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Subtracts one from the chase delay counter.
   ;
   _Chase_Delay = _Chase_Delay - 1



   ;***************************************************************
   ;
   ;  Moves player1 sprite with the joystick while keeping the
   ;  sprite within the playfield area.
   ;
   if joy0up && player1y > _P_Edge_Top then player1y = player1y - 1

   if joy0down && player1y < _P_Edge_Bottom then player1y = player1y + 1

   if joy0left && player1x > _P_Edge_Left then player1x = player1x - 1

   if joy0right && player1x < _P_Edge_Right then player1x = player1x + 1



   ;***************************************************************
   ;
   ;  Collision check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if there is no collision.
   ;
   if !collision(player0, player1) then goto __Skip_p0_p1_Collision

   ;```````````````````````````````````````````````````````````````
   ;  Sets random starting position of enemy.
   ;
   player0x = (rand/2) + (rand&15) + 5 : player0y = 9

   ;```````````````````````````````````````````````````````````````
   ;  New location of Enemy influenced by location of player.
   ;
   if player1y <= 48 then player0y = 88

   ;```````````````````````````````````````````````````````````````
   ;  Sets error accumulator bit.
   ;
   _Bit5_EA{5} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to Bresenham-like chase setup.
   ;
   goto __Chase_Setup

__Skip_p0_p1_Collision



   ;***************************************************************
   ;
   ;  Bresenham-like chase (move code).
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Speeds up the chase if fire button pressed.
   ;
   if !joy0fire && !(_Chase_Delay & %00000001) then goto __Skip_Chase2

   ;```````````````````````````````````````````````````````````````
   ;  Code from bogax at AtariAge (needs more comments).
   ;
   temp1 = _error_accumulator

   if _octant{0} then goto __Skip_Chase1
   player0y = player0y + _Data_yinc[_octant]
   _error_accumulator = _error_accumulator - _delta_x
   if temp1 < _error_accumulator then _error_accumulator = _error_accumulator + _delta_y : player0x = player0x + _Data_xinc[_octant]

   goto __Skip_Chase2

__Skip_Chase1

   player0x = player0x + _Data_xinc[_octant]
   _error_accumulator = _error_accumulator - _delta_y
   if temp1 < _error_accumulator then _error_accumulator = _error_accumulator + _delta_x : player0y = player0y + _Data_yinc[_octant] 

__Skip_Chase2



   ;***************************************************************
   ;
   ;  Sets up the Bresenham-like chase.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  If joystick not moved, skip this section.
   ;
   if !joy0up && !joy0down && !joy0left && !joy0right then goto __Skip_Bresenham_Setup

__Chase_Setup

   ;```````````````````````````````````````````````````````````````
   ;  Code from bogax at AtariAge (needs more comments).
   ;
   if player0x < player1x then _octant{2} = 1 : _delta_x = player1x - player0x else _octant{2} = 0 : _delta_x = player0x - player1x
   if player0y < player1y then _octant{1} = 1 : _delta_y = player1y - player0y else _octant{1} = 0 : _delta_y = player0y - player1y

   if _delta_x < $80 then _delta_y = _delta_y * 2 : _delta_x = _delta_x * 2

   if _delta_x > _delta_y then goto __dx_gt
   _octant{0} = 0
   if _error_accumulator > _delta_y then _error_accumulator = _delta_y / 2
   goto __set_ea

__dx_gt
   _octant{0} = 1 
   if _error_accumulator > _delta_x then _error_accumulator = _delta_x / 2

__set_ea

   ;```````````````````````````````````````````````````````````````
   ;  Sets error accumulator (skips if collision hasn't happened).
   ;
   if !_Bit5_EA{5} then goto __Skip_Bresenham_Setup

   _Bit5_EA{5} = 0

   if _octant{0} then _error_accumulator = _delta_x / 2 else _error_accumulator = _delta_y / 2

__Skip_Bresenham_Setup



   ;***************************************************************
   ;
   ;  Sets color of player1 sprite.
   ;
   COLUP1 = $9C



   ;***************************************************************
   ;
   ;  Sets color of player0 sprite.
   ;
   COLUP0 = $46



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;
   ;  Bresenham-like data.
   ;
   data _Data_yinc
   $FF, $FF, $01, $01, $FF, $FF,$01, $01
end

   data _Data_xinc
   $FF, $FF, $FF, $FF, $01, $01, $01, $01
end

 

 

 

player#height Example

player#height Example on bB page.

 
   player0:
   %00000000
   %00111100
   %01111110
   %11000011
   %10111101
   %11111111
   %11011011
   %01111110
   %00111100
end

   COLUBK = 0

   player0x = 77
   player0y = 53

__Main_Loop

   COLUP0 = $9C

   if !joy0up then goto __Skip_Up
   if player0height < 8 then player0height = player0height + 1
__Skip_Up

   if !joy0down then goto __Skip_Down
   if player0height > 0 then player0height = player0height - 1
__Skip_Down

   drawscreen

   goto __Main_Loop

 

 

 

8 Way Animation With SWCHA

8 Way Animation With SWCHA on bB page.

 
   ;***************************************************************
   ;
   ;  8 Way Animation Example Program based on Seaweed Assault
   ;
   ;  By Duane Alan Hahn (Random Terrain) using hints, tips,
   ;  code snippets, and more from AtariAge members such as
   ;  batari, SeaGtGruff, RevEng, Robert M, Atarius Maximus,
   ;  jrok, Nukey Shay, supercat, GroovyBee, and bogax.
   ;
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Player movement.
   ;
   dim _P0_Left_Right = player0x.a

   dim _P0_Up_Down = player0y.b

   ;```````````````````````````````````````````````````````````````
   ;  _Master_Counter can be used for many things, but it is 
   ;  really useful for animating sprite frames when used
   ;  with _Frame_Counter.
   ;
   dim _Master_Counter = c
   dim _Frame_Counter = d

   ;```````````````````````````````````````````````````````````````
   ;  Remembers SWCHA joystick movement.
   ;
   dim _Mem_SWCHA = e

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  All-purpose bits for various jobs.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Reset switch becomes inactive if it hasn't been released.
   ;
   dim _Bit0_Reset_Restrainer = y

   ;```````````````````````````````````````````````````````````````
   ;  Flips player sprite when necessary.
   ;
   dim _Bit3_Flip_P0 = y

   ;```````````````````````````````````````````````````````````````
   ;  Converts 6 digit score to 3 sets of two digits.
   ;
   ;  The 100 thousands and 10 thousands digits are held by _sc1.
   ;  The thousands and hundreds digits are held by _sc2.
   ;  The tens and ones digits are held by _sc3.
   ;
   dim _sc1 = score
   dim _sc2 = score+1
   dim _sc3 = score+2



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield. The _c_ stands for const
   ;  so I'll remember it's a constant and not a normal variable.
   ;
   const _c_Edge_Top = 10
   const _c_Edge_Bottom = 87
   const _c_Edge_Left = 1
   const _c_Edge_Right = 152




   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = $00


   ;***************************************************************
   ;
   ;  Sets player0 position and starting shape.
   ;
   player0x = 77 : player0y = 53

   player0:
   %00011000
   %00011000
   %00011000
   %11111111
   %01111110
   %00111100
   %01100110
   %01011010
end


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets player0 color.
   ;
   COLUP0 = $0A



   ;***************************************************************
   ;
   ;  Main counters.
   ;
   ;  Controls animation speed.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments the master counter.
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips section if master counter is less than 7.
   ;
   if _Master_Counter < 7 then goto __Skip_Frame_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Increments frame counter.
   ;
   _Frame_Counter = _Frame_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Clears master counter.
   ;
   _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Clears frame counter when it's time.
   ;
   if _Frame_Counter = 4 then _Frame_Counter = 0

__Skip_Frame_Counter



   ;***************************************************************
   ;
   ;  Advanced joystick reading.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Reads joystick. See SWCHA on the bB page for more info.
   ;
   _Mem_SWCHA = SWCHA/16

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to ship movement or skips movement.
   ;                       0         1         2         3         4        5      6      7      8        9     10     11      12      13    14     15
   on _Mem_SWCHA goto __Skip_J0 __Skip_J0 __Skip_J0 __Skip_J0 __Skip_J0 __GoDR __GoUR __GoR __Skip_J0 __GoDL __GoUL __GoL __Skip_J0 __GoD __GoU __Skip_J0



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Player Movement Routines
   ;
   ;***************************************************************
   ;***************************************************************
   ;
   ;  Up joystick direction.
   ;
__GoU

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 if not hitting the border. 
   ;
   if _P0_Up_Down > _c_Edge_Top then _P0_Up_Down = _P0_Up_Down - 1.42

   ;```````````````````````````````````````````````````````````````
   ;  Sprite is not reflected. 
   ;
   _Bit3_Flip_P0{3} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the next animation frame.
   ;
   on _Frame_Counter goto __P0_U_00 __P0_U_01 __P0_U_02 __P0_U_03



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Down joystick direction.
   ;
__GoD

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 if not hitting the border. 
   ;
   if _P0_Up_Down < _c_Edge_Bottom then _P0_Up_Down = _P0_Up_Down + 1.42

   ;```````````````````````````````````````````````````````````````
   ;  Sprite is not reflected. 
   ;
   _Bit3_Flip_P0{3} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the next animation frame.
   ;
   on _Frame_Counter goto __P0_D_00 __P0_D_01 __P0_D_02 __P0_D_03



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Joystick direction: Left.
   ;
__GoL

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 if not hitting the border. 
   ;
   if _P0_Left_Right > _c_Edge_Left then _P0_Left_Right = _P0_Left_Right - 1.42

   ;```````````````````````````````````````````````````````````````
   ;  Sprite is not reflected. 
   ;
   _Bit3_Flip_P0{3} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the next animation frame.
   ;
   on _Frame_Counter goto __P0_L_00 __P0_L_01 __P0_L_02 __P0_L_03

   
   
   ;***************************************************************
   ;***************************************************************
   ;
   ;  Joystick direction: Right.
   ;
__GoR

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 if not hitting the border. 
   ;
   if _P0_Left_Right < _c_Edge_Right then _P0_Left_Right = _P0_Left_Right + 1.42

   ;```````````````````````````````````````````````````````````````
   ;  Sprite is reflected. 
   ;
   _Bit3_Flip_P0{3} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the next animation frame (shared with __GoL).
   ;
   on _Frame_Counter goto __P0_L_00 __P0_L_01 __P0_L_02 __P0_L_03



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Up-Left joystick direction.
   ;
__GoUL

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 if not hitting the border. 
   ;
   if _P0_Up_Down > _c_Edge_Top then _P0_Up_Down = _P0_Up_Down - 1.42
   if _P0_Left_Right > _c_Edge_Left then _P0_Left_Right = _P0_Left_Right - 1.42

   ;```````````````````````````````````````````````````````````````
   ;  Sprite is not reflected. 
   ;
   _Bit3_Flip_P0{3} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the next animation frame.
   ;
   on _Frame_Counter goto __P0_UL_00 __P0_UL_01 __P0_UL_02 __P0_UL_03



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Up-Right joystick direction.
   ;
__GoUR

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 if not hitting the border. 
   ;
   if _P0_Up_Down > _c_Edge_Top then _P0_Up_Down = _P0_Up_Down - 1.42

   if _P0_Left_Right < _c_Edge_Right then _P0_Left_Right = _P0_Left_Right + 1.42

   ;```````````````````````````````````````````````````````````````
   ;  Sprite is reflected. 
   ;
   _Bit3_Flip_P0{3} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the next animation frame (shared with __GoUL).
   ;
   on _Frame_Counter goto __P0_UL_00 __P0_UL_01 __P0_UL_02 __P0_UL_03



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Down-Left joystick direction.
   ;
__GoDL

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 if not hitting the border. 
   ;
   if _P0_Up_Down < _c_Edge_Bottom then _P0_Up_Down = _P0_Up_Down + 1.42
   if _P0_Left_Right > _c_Edge_Left then _P0_Left_Right = _P0_Left_Right - 1.42

   ;```````````````````````````````````````````````````````````````
   ;  Sprite is not reflected. 
   ;
   _Bit3_Flip_P0{3} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the next animation frame.
   ;
   on _Frame_Counter goto __P0_DL_00 __P0_DL_01 __P0_DL_02 __P0_DL_03



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Joystick direction: Down-Right.
   ;
__GoDR

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 if not hitting the border. 
   ;
   if _P0_Up_Down < _c_Edge_Bottom then _P0_Up_Down = _P0_Up_Down + 1.42
   if _P0_Left_Right < _c_Edge_Right then _P0_Left_Right = _P0_Left_Right + 1.42

   ;```````````````````````````````````````````````````````````````
   ;  Sprite is reflected. 
   ;
   _Bit3_Flip_P0{3} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the next animation frame (shared with __GoDL).
   ;
   on _Frame_Counter goto __P0_DL_00 __P0_DL_01 __P0_DL_02 __P0_DL_03


__Skip_J0



   ;***************************************************************
   ;
   ;  Flips player sprite if necessary.
   ;
   if _Bit3_Flip_P0{3} then REFP0 = 8



   ;***************************************************************
   ;
   ;  Sets color of the score.
   ;
   scorecolor = $9C



   ;***************************************************************
   ;
   ;  Puts temp4 in the three score digits on the left side.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Replace "_Mem_SWCHA" with whatever you need to check.
   ;
   temp4 = _Mem_SWCHA

   _sc1 = 0 : _sc2 = _sc2 & 15
   if temp4 >= 100 then _sc1 = _sc1 + 16 : temp4 = temp4 - 100
   if temp4 >= 100 then _sc1 = _sc1 + 16 : temp4 = temp4 - 100
   if temp4 >= 50 then _sc1 = _sc1 + 5 : temp4 = temp4 - 50
   if temp4 >= 30 then _sc1 = _sc1 + 3 : temp4 = temp4 - 30
   if temp4 >= 20 then _sc1 = _sc1 + 2 : temp4 = temp4 - 20
   if temp4 >= 10 then _sc1 = _sc1 + 1 : temp4 = temp4 - 10
   _sc2 = (temp4 * 4 * 4) | _sc2



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Animation frames for player0 sprite.
   ;
__P0_U_00
   player0:
   %01011010
   %01100110
   %00111100
   %01111110
   %11111111
   %00011000
   %00011000
   %00011000
end
   goto __Skip_J0


__P0_U_01
   player0:
   %01100110
   %01000010
   %10111101
   %01111110
   %11111111
   %00011000
   %00011000
   %00011000
end
   goto __Skip_J0


__P0_U_02
   player0:
   %01000010
   %11000011
   %10111101
   %01111110
   %11111111
   %00011000
   %00011000
   %00011000
end
   goto __Skip_J0


__P0_U_03
   player0:
   %11100111
   %11000011
   %10111101
   %01111110
   %11111111
   %00011000
   %00011000
   %00011000
end
   goto __Skip_J0


__P0_D_00
   player0:
   %00011000
   %00011000
   %00011000
   %11111111
   %01111110
   %00111100
   %01100110
   %01011010
end
   goto __Skip_J0


__P0_D_01
   player0:
   %00011000
   %00011000
   %00011000
   %11111111
   %01111110
   %10111101
   %01000010
   %01100110
end
   goto __Skip_J0


__P0_D_02
   player0:
   %00011000
   %00011000
   %00011000
   %11111111
   %01111110
   %10111101
   %11000011
   %01000010
end
   goto __Skip_J0


__P0_D_03
   player0:
   %00011000
   %00011000
   %00011000
   %11111111
   %01111110
   %10111101
   %11000011
   %11100111
end
   goto __Skip_J0


__P0_L_00
   player0:
   %00010000
   %00011011
   %00011110
   %11111101
   %11111101
   %00011110
   %00011011
   %00010000
end
   goto __Skip_J0


__P0_L_01
   player0:
   %00010100
   %00011011
   %00011101
   %11111100
   %11111100
   %00011101
   %00011011
   %00010100
end
   goto __Skip_J0


__P0_L_02
   player0:
   %00010110
   %00011011
   %00011100
   %11111100
   %11111100
   %00011100
   %00011011
   %00010110
end
   goto __Skip_J0


__P0_L_03
   player0:
   %00010111
   %00011011
   %00011101
   %11111100
   %11111100
   %00011101
   %00011011
   %00010111
end
   goto __Skip_J0


__P0_UL_00
   player0:
   %00001000
   %10010010
   %11111000
   %01111101
   %00111110
   %01111100
   %11101100
   %11000110
end
   goto __Skip_J0


__P0_UL_01
   player0:
   %00001100
   %11010000
   %11111001
   %01111101
   %00111110
   %01111110
   %11101100
   %11000110
end
   goto __Skip_J0


__P0_UL_02
   player0:
   %00101000
   %11010000
   %11111000
   %01111101
   %00111110
   %01111111
   %11101100
   %11000110
end
   goto __Skip_J0


__P0_UL_03
   player0:
   %00111100
   %11110000
   %11111001
   %01111101
   %00111111
   %01111111
   %11101100
   %11000110
end
   goto __Skip_J0


__P0_DL_00
   player0:
   %11000110
   %11101100
   %01111100
   %00111110
   %01111101
   %11111000
   %10010010
   %00001000
end
   goto __Skip_J0


__P0_DL_01
   player0:
   %11000110
   %11101100
   %01111110
   %00111110
   %01111101
   %11111001
   %11010000
   %00001100
end
   goto __Skip_J0


__P0_DL_02
   player0:
   %11000110
   %11101100
   %01111111
   %00111110
   %01111101
   %11111000
   %11010000
   %00101000
end
   goto __Skip_J0


__P0_DL_03
   player0:
   %11000110
   %11101100
   %01111111
   %00111111
   %01111101
   %11111001
   %11110000
   %00111100
end
   goto __Skip_J0

 

 

 

Sprite with Missile Example

Sprite with Missile Example on bB page.

 
   ;***************************************************************
   ;
   ;  Sprite with Missile
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Use the joystick to move the sprite. Press the fire button
   ;  to shoot the missile.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Player0/missile0 direction bits.
   ;
   dim _BitOp_P0_M0_Dir = g
   dim _Bit0_P0_Dir_Up = g
   dim _Bit1_P0_Dir_Down = g
   dim _Bit2_P0_Dir_Left = g
   dim _Bit3_P0_Dir_Right = g
   dim _Bit4_M0_Dir_Up = g
   dim _Bit5_M0_Dir_Down = g
   dim _Bit6_M0_Dir_Left = g
   dim _Bit7_M0_Dir_Right = g

   ;```````````````````````````````````````````````````````````````
   ;  Bits that do various jobs.
   ;
   dim _Bit0_Reset_Restrainer = y
   dim _Bit7_M0_Moving = y



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for an 8 x 8 sprite.
   ;  If your sprite is a different size, you`ll need to adjust
   ;  the numbers.
   ;
   const _P_Edge_Top = 9
   const _P_Edge_Bottom = 88
   const _P_Edge_Left = 1
   const _P_Edge_Right = 153



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for the missile.
   ;  If the missile is a different size, you'll need to adjust
   ;  the numbers.
   ;
   const _M_Edge_Top = 2
   const _M_Edge_Bottom = 88
   const _M_Edge_Left = 2
   const _M_Edge_Right = 159



   ;***************************************************************
   ;
   ;  Disables the score. (We don't need it in this program.)
   ;
   const noscore = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0


   ;***************************************************************
   ;
   ;  Sets starting position of player0.
   ;
   player0x = 77 : player0y = 53


   ;***************************************************************
   ;
   ;  Makes sure missile0 is off the screen.
   ;
   missile0x = 200 : missile0y = 200


   ;***************************************************************
   ;
   ;  Defines missile0 size.
   ;
   NUSIZ0 = $10 : missile0height = 1


   ;***************************************************************
   ;
   ;  Sets playfield color.
   ;
   COLUPF = $2C


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Sets beginning direction that missile0 will shoot if the
   ;  player doesn't move.
   ;
   _Bit3_P0_Dir_Right{3} = 1


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Defines shape of Player0 sprite.
   ;
   player0:
   %00111100
   %01111110
   %11000011
   %10111101
   %11111111
   %11011011
   %01111110
   %00111100
end


   ;***************************************************************
   ;
   ;  Sets up the playfield.
   ;
   playfield:
   ................................
   ................................
   ....XXXXXXXXXX....XXXXXXXXXX....
   ....X......................X....
   ....X......................X....
   ....X......................X....
   ................................
   ................................
   ....XXXX....XXXXXXXX....XXXX....
   ................................
   ................................
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets color of player0 sprite and missile.
   ;
   COLUP0 = $9C



   ;***************************************************************
   ;
   ;  Joystick movement precheck.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if joystick hasn't been moved.
   ;
   if !joy0up && !joy0down && !joy0left && !joy0right then goto __Skip_Joystick_Precheck

   ;```````````````````````````````````````````````````````````````
   ;  Clears player0 direction bits since joystick has been moved.
   ;
   _BitOp_P0_M0_Dir = _BitOp_P0_M0_Dir & %11110000

__Skip_Joystick_Precheck



   ;***************************************************************
   ;
   ;  Joy0 up check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved up.
   ;
   if !joy0up then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the up direction bit.
   ;
   _Bit0_P0_Dir_Up{0} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0y <= _P_Edge_Top then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 up.
   ;
   player0y = player0y - 1

__Skip_Joy0_Up



   ;***************************************************************
   ;
   ;  Joy0 down check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved down.
   ;
   if !joy0down then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the down direction bit.
   ;
   _Bit1_P0_Dir_Down{1} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0y >= _P_Edge_Bottom then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 down.
   ;
   player0y = player0y + 1

__Skip_Joy0_Down



   ;***************************************************************
   ;
   ;  Joy0 left check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved to the left.
   ;
   if !joy0left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the left direction bit.
   ;
   _Bit2_P0_Dir_Left{2} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0x <= _P_Edge_Left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 to the left.
   ;
   player0x = player0x - 1

__Skip_Joy0_Left



   ;***************************************************************
   ;
   ;  Joy0 right check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved to the right.
   ;
   if !joy0right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the right direction bit.
   ;
   _Bit3_P0_Dir_Right{3} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0x >= _P_Edge_Right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 to the right.
   ;
   player0x = player0x + 1

__Skip_Joy0_Right



   ;***************************************************************
   ;
   ;  Fire button check.
   ;  
   ;  Turns on missile1 movement if fire button is pressed and
   ;  missile1 is not moving.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the fire button is not pressed.
   ;
   if !joy0fire then goto __Skip_Fire

   ;```````````````````````````````````````````````````````````````
   ;  If missile0 is moving, skip this subsection.
   ;
   if _Bit7_M0_Moving{7} then goto __Skip_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Turns on missile0 movement.
   ;
   _Bit7_M0_Moving{7} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Takes a 'snapshot' of player0 direction so missile0 will
   ;  stay on track until it hits something.
   ;
   _Bit4_M0_Dir_Up{4} = _Bit0_P0_Dir_Up{0}
   _Bit5_M0_Dir_Down{5} = _Bit1_P0_Dir_Down{1}
   _Bit6_M0_Dir_Left{6} = _Bit2_P0_Dir_Left{2}
   _Bit7_M0_Dir_Right{7} = _Bit3_P0_Dir_Right{3}

   ;```````````````````````````````````````````````````````````````
   ;  Sets up starting position of missile0.
   ;
   if _Bit4_M0_Dir_Up{4} then missile0x = player0x + 4 : missile0y = player0y - 5
   if _Bit5_M0_Dir_Down{5} then missile0x = player0x + 4 : missile0y = player0y - 1
   if _Bit6_M0_Dir_Left{6} then missile0x = player0x + 2 : missile0y = player0y - 3
   if _Bit7_M0_Dir_Right{7} then missile0x = player0x + 6 : missile0y = player0y - 3

__Skip_Fire



   ;***************************************************************
   ;
   ;  Missile0 movement check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if missile0 isn't moving.
   ;
   if !_Bit7_M0_Moving{7} then goto __Skip_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Moves missile0 in the appropriate direction.
   ;
   if _Bit4_M0_Dir_Up{4} then missile0y = missile0y - 2
   if _Bit5_M0_Dir_Down{5} then missile0y = missile0y + 2
   if _Bit6_M0_Dir_Left{6} then missile0x = missile0x - 2
   if _Bit7_M0_Dir_Right{7} then missile0x = missile0x + 2

   ;```````````````````````````````````````````````````````````````
   ;  Clears missile0 if it hits the edge of the screen.
   ;
   if missile0y < _M_Edge_Top then goto __Delete_Missile
   if missile0y > _M_Edge_Bottom then goto __Delete_Missile
   if missile0x < _M_Edge_Left then goto __Delete_Missile
   if missile0x > _M_Edge_Right then goto __Delete_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Skips rest of section if no collision.
   ;
   if !collision(playfield,missile0) then goto __Skip_Missile

__Delete_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Clears missile0 moving bit and moves missile0 off the screen.
   ;
   _Bit7_M0_Moving{7} = 0 : missile0x = 200 : missile0y = 200

__Skip_Missile



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart

 

 

 

Shoot pfpixel Example

Shoot pfpixel Example on bB page.

 
   ;***************************************************************
   ;
   ;  Shoot pfpixel
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;***************************************************************
   ;
   ;  Instructions:
   ;  
   ;  Shoot the pfpixels using the fire button.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;****************************************************************
   ;
   ;  Kernel options for this program.
   ;
   set kernel_options pfcolors pfheights



   ;****************************************************************
   ;
   ;  Some multiplication operations require you to include
   ;  a module.
   ;
   include div_mul.asm



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  8.8 fixed point movement for player0 sprite.
   ;
   dim _P0_x = player0x.a

   ;```````````````````````````````````````````````````````````````
   ;  Counts the number of blocks destroyed.
   ;
   dim _Block_Count = b

   ;```````````````````````````````````````````````````````````````
   ;  Converted ball coordinates for playfield.
   ;
   dim _pf_x = c
   dim _pf_y = d

   ;```````````````````````````````````````````````````````````````
   ;  All-purpose bits for various jobs.
   ;
   dim _BitOp_All_Purpose_01 = e

   ;```````````````````````````````````````````````````````````````
   ;  Fixes it so holding it down will not make it keep resetting.
   ;
   dim _Bit0_Reset_Restrainer = e

   ;```````````````````````````````````````````````````````````````
   ;  One fire button press at a time.
   ;
   dim _Bit1_FireB_Restrainer = e

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers.
   ;
   dim rand16 = z



   ;****************************************************************
   ;
   ;  Sets playfield heights.
   ;
   pfheights:
   8
   3
   3
   3
   3
   3
   3
   3
   3
   3
   53
end



   ;***************************************************************
   ;
   ;  Sets playfield colors.
   ;
   pfcolors:
   $00
   $44
   $46
   $48
   $1A
   $1C
   $1E
   $C6
   $C8
   $CA
   $00
end






   ;***************************************************************
   ;***************************************************************
   ;
   ;  Program Start/Restart
   ;
   ;
__Start_Restart



   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.

   ;
   AUDV0 = 0 : AUDV1 = 0



   ;***************************************************************
   ;
   ;  Clears 25 of the normal 26 variables (fastest way).
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0



   ;***************************************************************
   ;
   ;  Draws the blocks.
   ;
   playfield:
   ................................
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   ................................
end



   ;***************************************************************
   ;
   ;  Creates shape of player0 sprite.
   ;
   player0:
   %1111111
   %1111111
   %0111110
   %0011100
end



   ;***************************************************************
   ;
   ;  Starting position of player0 sprite.
   ;
   player0x = 75 : player0y = 83



   ;***************************************************************
   ;
   ;  Makes sure missile0 is off the screen.
   ;
   missile0y = 222



   ;***************************************************************
   ;
   ;  Defines missile0 height.
   ;
   missile0height = 5



   ;***************************************************************
   ;
   ;  Sets repetition restrainer for the reset switch.
   ;  (Holding it down won't make it keep resetting.)
   ;
   _Bit0_Reset_Restrainer{0} = 1



   ;***************************************************************
   ;
   ;  Sets repetition restrainer for the fire button.
   ;
   _Bit1_FireB_Restrainer{1} = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Main Loop
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Player sprite section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Moves sprite if joystick is pressed left or right.
   ;
   if joy0left then _P0_x = _P0_x - 1.500
   if joy0right then _P0_x = _P0_x + 1.500

   ;```````````````````````````````````````````````````````````````
   ;  Limits player sprite movement.
   ;
   if _P0_x < 14 then _P0_x = 14
   if _P0_x > 139 then _P0_x = 139



   ;***************************************************************
   ;
   ;  Missile0 check and fire button check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps to fire button check if missile0 is off the screen.
   ;
   if missile0y > 220 then goto __FireB_Check

   ;```````````````````````````````````````````````````````````````
   ;  Moves missile0 and skips fire button check.
   ;
   missile0y = missile0y - 2 : goto __Skip_FireB

__FireB_Check

   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and skips this section if fire
   ;  button is not pressed.
   ;
   if !joy0fire then _Bit1_FireB_Restrainer{1} = 0 : goto __Skip_FireB

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if fire button hasn't been released since
   ;  program started.
   ;
   if _Bit1_FireB_Restrainer{1} then goto __Skip_FireB

   ;```````````````````````````````````````````````````````````````
   ;  Starts the firing of missile0.
   ;
   missile0y = player0y - 2 : missile0x = player0x + 4

__Skip_FireB



   ;***************************************************************
   ;
   ;  Missile0/playfield collision check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if there is no collision.
   ;
   if !collision(playfield,missile0) then goto __Skip_miss0_to_pf_Coll

   ;```````````````````````````````````````````````````````````````
   ;  Missile0 y coordinate conversion.
   ;
   temp5 = missile0height + 3 : _pf_y = (missile0y-temp5)/3

   ;```````````````````````````````````````````````````````````````
   ;  Missile0 x coordinate conversion.
   ;
   _pf_x = (missile0x-17)/4

   ;```````````````````````````````````````````````````````````````
   ;  If a block is there, skip this subsection.
   ;
   if !pfread(_pf_x,_pf_y) then goto __Skip_miss0_to_pf_Coll

   ;```````````````````````````````````````````````````````````````
   ;  Deletes pfpixel.
   ;
   pfpixel _pf_x _pf_y off

   ;```````````````````````````````````````````````````````````````
   ;  Moves missile0 off the screen.
   ;
   missile0y = 222 

   ;```````````````````````````````````````````````````````````````
   ;  Remembers how many blocks have been hit.
   ;
   _Block_Count = _Block_Count + 1

   ;```````````````````````````````````````````````````````````````
   ;  Deletes pfpixel to the left or right based on whether the 
   ;  currently deleted pfpixel was odd or even.
   ;
   if _pf_x{0} then temp4 = _pf_x - 1 : pfpixel temp4 _pf_y off : goto __Skip_miss0_to_pf_Coll

   temp4 = _pf_x + 1 : pfpixel temp4 _pf_y off  : temp4 = _pf_x

__Skip_miss0_to_pf_Coll



   ;***************************************************************
   ;
   ;  Sets color of player0 sprite.
   ;
   COLUP0 = $0C



   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0



   ;***************************************************************
   ;
   ;  Sets up size of missile0.
   ;
   NUSIZ0 = $10



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  If all blocks destroyed, get new blocks.
   ;
   if _Block_Count > 143 then goto __New_Blocks

__Return_from_Blocks



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart 






   ;***************************************************************
   ;***************************************************************
   ;
   ;  New blocks.
   ;
   ;
__New_Blocks

   ;```````````````````````````````````````````````````````````````
   ;  Clears the block count variable.
   ;
   _Block_Count = 0

   ;```````````````````````````````````````````````````````````````
   ;  Moves missile0 off the screen.
   ;
   missile0y = 222

   ;```````````````````````````````````````````````````````````````
   ;  Draws the blocks.
   ;
   playfield:
   ................................
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   ................................
end

   goto __Return_from_Blocks

 

 

 

Sprite With Missile and pfpixel Destruction

Sprite With Missile and pfpixel Destruction on bB page.

 
   ;***************************************************************
   ;
   ;  Sprite With Missile and pfpixel Destruction
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Use the joystick to move the sprite. Press the fire button
   ;  to shoot the missile.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Player0/missile0 direction bits.
   ;
   dim _BitOp_P0_M0_Dir = g
   dim _Bit0_P0_Dir_Up = g
   dim _Bit1_P0_Dir_Down = g
   dim _Bit2_P0_Dir_Left = g
   dim _Bit3_P0_Dir_Right = g
   dim _Bit4_M0_Dir_Up = g
   dim _Bit5_M0_Dir_Down = g
   dim _Bit6_M0_Dir_Left = g
   dim _Bit7_M0_Dir_Right = g

   ;```````````````````````````````````````````````````````````````
   ;  Bits that do various jobs.
   ;
   dim _Bit0_Reset_Restrainer = y
   dim _Bit7_M0_Moving = y



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for an 8 x 8 sprite.
   ;  If your sprite is a different size, you`ll need to adjust
   ;  the numbers.
   ;
   const _P_Edge_Top = 9
   const _P_Edge_Bottom = 88
   const _P_Edge_Left = 1
   const _P_Edge_Right = 152



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for the missile.
   ;  If the missile is a different size, you'll need to adjust
   ;  the numbers.
   ;
   const _M_Edge_Top = 2
   const _M_Edge_Bottom = 88
   const _M_Edge_Left = 2
   const _M_Edge_Right = 159



   ;***************************************************************
   ;
   ;  Disables the score. (We don't need it in this program.)
   ;
   const noscore = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0


   ;***************************************************************
   ;
   ;  Sets starting position of player0.
   ;
   player0x = 77 : player0y = 53


   ;***************************************************************
   ;
   ;  Makes sure missile0 is off the screen.
   ;
   missile0x = 200 : missile0y = 200


   ;***************************************************************
   ;
   ;  Defines missile0 size.
   ;
   NUSIZ0 = $10 : missile0height = 1


   ;***************************************************************
   ;
   ;  Sets playfield color.
   ;
   COLUPF = $2C


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Sets beginning direction that missile0 will shoot if the
   ;  player doesn't move.
   ;
   _Bit3_P0_Dir_Right{3} = 1


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Defines shape of Player0 sprite.
   ;
   player0:
   %00111100
   %01111110
   %11000011
   %10111101
   %11111111
   %11011011
   %01111110
   %00111100
end


   ;***************************************************************
   ;
   ;  Sets up the playfield.
   ;
   playfield:
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   X..............................X
   X...XXXXXXXXXX....XXXXXXXXXX...X
   X...X......................X...X
   X...X......................X...X
   X...X......................X...X
   X..............................X
   X..............................X
   X...XXXX....XXXXXXXX....XXXX...X
   X..............................X
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets color of player0 sprite and missile.
   ;
   COLUP0 = $9C



   ;***************************************************************
   ;
   ;  Joystick movement precheck.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if joystick hasn't been moved.
   ;
   if !joy0up && !joy0down && !joy0left && !joy0right then goto __Skip_Joystick_Precheck

   ;```````````````````````````````````````````````````````````````
   ;  Clears player0 direction bits since joystick has been moved.
   ;
   _BitOp_P0_M0_Dir = _BitOp_P0_M0_Dir & %11110000

__Skip_Joystick_Precheck



   ;***************************************************************
   ;
   ;  Joy0 up check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved up.
   ;
   if !joy0up then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the up direction bit.
   ;
   _Bit0_P0_Dir_Up{0} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0y <= _P_Edge_Top then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 up.
   ;
   player0y = player0y - 1

__Skip_Joy0_Up



   ;***************************************************************
   ;
   ;  Joy0 down check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved down.
   ;
   if !joy0down then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the down direction bit.
   ;
   _Bit1_P0_Dir_Down{1} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0y >= _P_Edge_Bottom then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 down.
   ;
   player0y = player0y + 1

__Skip_Joy0_Down



   ;***************************************************************
   ;
   ;  Joy0 left check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved to the left.
   ;
   if !joy0left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the left direction bit.
   ;
   _Bit2_P0_Dir_Left{2} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0x <= _P_Edge_Left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 to the left.
   ;
   player0x = player0x - 1

__Skip_Joy0_Left



   ;***************************************************************
   ;
   ;  Joy0 right check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved to the right.
   ;
   if !joy0right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the right direction bit.
   ;
   _Bit3_P0_Dir_Right{3} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0x >= _P_Edge_Right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 to the right.
   ;
   player0x = player0x + 1

__Skip_Joy0_Right



   ;***************************************************************
   ;
   ;  Fire button check.
   ;  
   ;  Turns on missile1 movement if fire button is pressed and
   ;  missile1 is not moving.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the fire button is not pressed.
   ;
   if !joy0fire then goto __Skip_Fire

   ;```````````````````````````````````````````````````````````````
   ;  If missile0 is moving, skip this subsection.
   ;
   if _Bit7_M0_Moving{7} then goto __Skip_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Turns on missile0 movement.
   ;
   _Bit7_M0_Moving{7} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Takes a 'snapshot' of player0 direction so missile0 will
   ;  stay on track until it hits something.
   ;
   _Bit4_M0_Dir_Up{4} = _Bit0_P0_Dir_Up{0}
   _Bit5_M0_Dir_Down{5} = _Bit1_P0_Dir_Down{1}
   _Bit6_M0_Dir_Left{6} = _Bit2_P0_Dir_Left{2}
   _Bit7_M0_Dir_Right{7} = _Bit3_P0_Dir_Right{3}

   ;```````````````````````````````````````````````````````````````
   ;  Sets up starting position of missile0.
   ;
   if _Bit4_M0_Dir_Up{4} then missile0x = player0x + 4 : missile0y = player0y - 5
   if _Bit5_M0_Dir_Down{5} then missile0x = player0x + 4 : missile0y = player0y - 1
   if _Bit6_M0_Dir_Left{6} then missile0x = player0x + 2 : missile0y = player0y - 3
   if _Bit7_M0_Dir_Right{7} then missile0x = player0x + 6 : missile0y = player0y - 3

__Skip_Fire



   ;***************************************************************
   ;
   ;  Missile0 movement check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if missile0 isn't moving.
   ;
   if !_Bit7_M0_Moving{7} then goto __Skip_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Moves missile0 in the appropriate direction and gets
   ;  coordinates for pfpixel check.
   ;
   if _Bit4_M0_Dir_Up{4} then missile0y = missile0y - 2 : temp5 = (missile0x-18)/4 : temp6 = (missile0y-1)/8
   if _Bit5_M0_Dir_Down{5} then missile0y = missile0y + 2 : temp5 = (missile0x-18)/4 : temp6 = (missile0y)/8
   if _Bit6_M0_Dir_Left{6} then missile0x = missile0x - 2 : temp5 = (missile0x-18)/4 : temp6 = (missile0y-1)/8
   if _Bit7_M0_Dir_Right{7} then missile0x = missile0x + 2 : temp5 = (missile0x-18)/4 : temp6 = (missile0y-1)/8

   ;```````````````````````````````````````````````````````````````
   ;  Clears missile0 if it hits the edge of the screen.
   ;
   if missile0y < _M_Edge_Top then goto __Delete_Missile
   if missile0y > _M_Edge_Bottom then goto __Delete_Missile
   if missile0x < _M_Edge_Left then goto __Delete_Missile
   if missile0x > _M_Edge_Right then goto __Delete_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Skips rest of section if no pfpixel shot.
   ;
   if !pfread(temp5,temp6) then goto __Skip_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Deletes pfpixel.
   ;
   pfpixel temp5 temp6 off

__Delete_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Clears missile0 moving bit and moves missile0 off the screen.
   ;
   _Bit7_M0_Moving{7} = 0 : missile0x = 200 : missile0y = 200

__Skip_Missile



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart

 

 

 

Sprite with Ball Example

Sprite with Ball Example on bB page.

 
   ;***************************************************************
   ;
   ;  Sprite With Ball
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Use the joystick to move the sprite. Watch ball bounce.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Bits that do various jobs.
   ;
   dim _Bit0_Reset_Restrainer = y
   dim _Bit5_B_Direction_X = y
   dim _Bit6_B_Direction_Y = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers.
   ;
   dim rand16 = z



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for an 8 x 8 sprite.
   ;  If your sprite is a different size, you`ll need to adjust
   ;  the numbers.
   ;
   const _P_Edge_Top = 9
   const _P_Edge_Bottom = 88
   const _P_Edge_Left = 1
   const _P_Edge_Right = 153



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for the ball. If the
   ;  ball is a different size, you'll need to adjust the numbers.
   ;
   const _B_Edge_Top = 3
   const _B_Edge_Bottom = 88
   const _B_Edge_Left = 2
   const _B_Edge_Right = 159



   ;***************************************************************
   ;
   ;  Disables the score. (We don't need it in this program.)
   ;
   const noscore = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears 25 of the normal 26 variables (fastest way).
   ;  The variable z is used for random numbers in this program
   ;  and clearing it would mess up those random numbers.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0


   ;***************************************************************
   ;
   ;  Sets starting position of player0.
   ;
   player0x = 77 : player0y = 53



   ;***************************************************************
   ;
   ;  Sets random starting position of ball.
   ;
   ballx = (rand/2) + (rand&15) + (rand/32) + 5 : bally = 9


   ;***************************************************************
   ;
   ;  Defines ball size.
   ;
   CTRLPF = $11 : ballheight = 2


   ;***************************************************************
   ;
   ;  Ballx starting direction is random. It will either go left
   ;  or right.
   ;
   temp5 = (rand & %00100000)

   _Bit5_B_Direction_X = _Bit5_B_Direction_X ^ temp5


   ;***************************************************************
   ;
   ;  Bally starting direction is down.
   ;
   _Bit6_B_Direction_Y{6} = 1


   ;***************************************************************
   ;
   ;  Sets playfield color.
   ;
   COLUPF = $2C


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Defines shape of player0 sprite.
   ;
   player0:
   %00111100
   %01111110
   %11000011
   %10111101
   %11111111
   %11011011
   %01111110
   %00111100
end


   ;***************************************************************
   ;
   ;  Sets up the playfield.
   ;
   playfield:
   ................................
   ................................
   ....XXXXXXXXXX....XXXXXXXXXX....
   ....X......................X....
   ....X......................X....
   ....X......................X....
   ................................
   ................................
   ....XXXX....XXXXXXXX....XXXX....
   ................................
   ................................
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets color of player0 sprite.
   ;
   COLUP0 = $9C



   ;***************************************************************
   ;
   ;  Moves player0 sprite with the joystick while keeping the
   ;  sprite within the playfield area.
   ;
   if joy0up && player0y > _P_Edge_Top then player0y = player0y - 1

   if joy0down && player0y < _P_Edge_Bottom then player0y = player0y + 1

   if joy0left && player0x > _P_Edge_Left then player0x = player0x - 1

   if joy0right && player0x < _P_Edge_Right then player0x = player0x + 1



   ;***************************************************************
   ;
   ;  Bounces the ball if it hits the edge of the screen.
   ;
   if ballx < _B_Edge_Left || ballx > _B_Edge_Right then _Bit5_B_Direction_X = _Bit5_B_Direction_X ^ %00100000

   if bally < _B_Edge_Top || bally > _B_Edge_Bottom then _Bit6_B_Direction_Y = _Bit6_B_Direction_Y ^ %01000000



   ;***************************************************************
   ;
   ;  Moves the ball.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Moves ball right if direction isn't left.
   ;
   temp5 = 255 : if _Bit5_B_Direction_X{5} then temp5 = 1

   ballx = ballx + temp5

   ;```````````````````````````````````````````````````````````````
   ;  Moves ball down if direction isn't up.
   ;
   temp5 = 255 : if _Bit6_B_Direction_Y{6} then temp5 = 1

   bally = bally + temp5



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart

 

 

 

Sprite With Collision Prevention

Sprite With Collision Prevention on bB page.

 
   ;***************************************************************
   ;
   ;  Sprite With Collision Prevention
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Use the joystick to move the sprite. Press the reset switch
   ;  to reset the program and toggle between two screens. Notice
   ;  how the sprite smoothly glides along the walls when the
   ;  sprite is moved diagonally. It doesn't stick or bounce.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Bits that do various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y
   dim _Bit4_Toggle_Screen = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers.
   ;
   dim rand16 = z



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for an 8 x 8 sprite.
   ;  If your sprite is a different size, you`ll need to adjust
   ;  the numbers.
   ;
   const _P_Edge_Top = 9
   const _P_Edge_Bottom = 88
   const _P_Edge_Left = 1
   const _P_Edge_Right = 153



   ;***************************************************************
   ;
   ;  Disables the score. (We don't need it in this program.)
   ;
   const noscore = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears 24 of the normal 26 variables (fastest way).
   ;  The variable y holds a bit that should not be cleared. The
   ;  variable z is used for random numbers in this program and
   ;  clearing it would mess up those random numbers.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0


   ;***************************************************************
   ;
   ;  Clears 7 of the 8 bits. The 4th bit toggles the playfield
   ;  when the reset switch is pressed in this example, so we
   ;  have to leave it alone.
   ;
   _BitOp_01 = _BitOp_01 & %00010000


   ;***************************************************************
   ;
   ;  Sets starting position of player0.
   ;
   player0x = 77 : player0y = 48


   ;***************************************************************
   ;
   ;  Sets playfield color.
   ;
   COLUPF = $2C


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Defines shape of Player0 sprite.
   ;
   player0:
   %00111100
   %01111110
   %11000011
   %10111101
   %11111111
   %11011011
   %01111110
   %00111100
end


   ;***************************************************************
   ;
   ;  Toggles the playfield.
   ;
   _Bit4_Toggle_Screen = _Bit4_Toggle_Screen ^ %00010000

   if _Bit4_Toggle_Screen{4} then goto __Skip_Playfield_01

   playfield:
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   X..............XX..............X
   X..XXX..XXXXX..XX..XXXXX..XXX..X
   X..............................X
   X..XXX..XXXXXXX..XXXXXXX..XXX..X
   X....X....................X....X
   XXX..X..X..XXXXXXXXXX..X..X..XXX
   X.......X......XX......X.......X
   X..XXXXXXXXXX..XX..XXXXXXXXXX..X
   X..............................X
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end

   goto __Skip_Playfield_02


__Skip_Playfield_01  


   playfield:
   ................................
   ................................
   ....XXXXXXXXXX....XXXXXXXXXX....
   ....X......................X....
   ....X......................X....
   ....X......................X....
   ................................
   ................................
   ....XXXX....XXX..XXX....XXXX....
   ................................
   ................................
end

__Skip_Playfield_02





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets color of player0 sprite.
   ;
   COLUP0 = $9C



   ;***************************************************************
   ;
   ;  Joy0 up check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved up.
   ;
   if !joy0up then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0y <= _P_Edge_Top then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player0x-10)/4

   temp6 = (player0y-9)/8

   if temp5 < 34 then if pfread(temp5,temp6) then goto __Skip_Joy0_Up

   temp4 = (player0x-17)/4

   if temp4 < 34 then if pfread(temp4,temp6) then goto __Skip_Joy0_Up

   temp3 = temp5 - 1

   if temp3 < 34 then if pfread(temp3,temp6) then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 up.
   ;
   player0y = player0y - 1

__Skip_Joy0_Up



   ;***************************************************************
   ;
   ;  Joy0 down check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved down.
   ;
   if !joy0down then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0y >= _P_Edge_Bottom then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player0x-10)/4

   temp6 = (player0y)/8

   if temp5 < 34 then if pfread(temp5,temp6) then goto __Skip_Joy0_Down

   temp4 = (player0x-17)/4

   if temp4 < 34 then if pfread(temp4,temp6) then goto __Skip_Joy0_Down

   temp3 = temp5 - 1

   if temp3 < 34 then if pfread(temp3,temp6) then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 down.
   ;
   player0y = player0y + 1

__Skip_Joy0_Down



   ;***************************************************************
   ;
   ;  Joy0 left check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved to the left.
   ;
   if !joy0left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0x <= _P_Edge_Left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player0y-1)/8

   temp6 = (player0x-18)/4

   if temp6 < 34 then if pfread(temp6,temp5) then goto __Skip_Joy0_Left

   temp3 = (player0y-8)/8

   if temp6 < 34 then if pfread(temp6,temp3) then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 left.
   ;
   player0x = player0x - 1

__Skip_Joy0_Left



   ;***************************************************************
   ;
   ;  Joy0 right check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved to the right.
   ;
   if !joy0right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0x >= _P_Edge_Right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player0y-1)/8

   temp6 = (player0x-9)/4

   if temp6 < 34 then if pfread(temp6,temp5) then goto __Skip_Joy0_Right

   temp3 = (player0y-8)/8

   if temp6 < 34 then if pfread(temp6,temp3) then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 right.
   ;
   player0x = player0x + 1

__Skip_Joy0_Right



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart

 

 

 

Sprite With Collision Prevention and pfrowheight=7

Sprite With Collision Prevention and pfrowheight=7 on bB page.

 
   ;***************************************************************
   ;
   ;  Sprite With Collision Prevention and pfrowheight=7
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Use the joystick to move the sprite. Press the reset switch
   ;  to reset the program and toggle between two screens. Notice
   ;  how the sprite smoothly glides along the walls when the
   ;  sprite is moved diagonally. It doesn't stick or bounce.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;***************************************************************
   ;
   ;  Division and multiplication module.
   ;
   include div_mul.asm



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Bits that do various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y
   dim _Bit4_Toggle_Screen = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers.
   ;
   dim rand16 = z



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for an 8 x 8 sprite.
   ;  If your sprite is a different size, you`ll need to adjust
   ;  the numbers.
   ;
   const _P_Edge_Top = 12
   const _P_Edge_Bottom = 77
   const _P_Edge_Left = 1
   const _P_Edge_Right = 152



   ;***************************************************************
   ;
   ;  Disables the score. (We don't need it in this program.)
   ;
   const noscore = 1



   ;***************************************************************
   ;
   ;  Makes playfield pixels that aren't as tall.
   ;
   const pfrowheight=7





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears 24 of the normal 26 variables (fastest way).
   ;  The variable y holds a bit that should not be cleared. The
   ;  variable z is used for random numbers in this program and
   ;  clearing it would mess up those random numbers.
   ;
   asm
   LDA #0
   STA a
   STA b
   STA c
   STA d
   STA e
   STA f
   STA g
   STA h
   STA i
   STA j
   STA k
   STA l
   STA m
   STA n
   STA o
   STA p
   STA q
   STA r
   STA s
   STA t
   STA u
   STA v
   STA w
   STA x
end


   ;***************************************************************
   ;
   ;  Clears 7 of the 8 bits. The 4th bit toggles the playfield
   ;  when the reset switch is pressed in this example, so we
   ;  have to leave it alone.
   ;
   _BitOp_01 = _BitOp_01 & %00010000


   ;***************************************************************
   ;
   ;  Sets starting position of player0.
   ;
   player0x = 77 : player0y = 48


   ;***************************************************************
   ;
   ;  Sets playfield color.
   ;
   COLUPF = $2C


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Defines shape of Player0 sprite.
   ;
   player0:
   %11111111
   %11111111
   %11111111
   %11000011
   %10111101
   %11111111
   %11011011
   %11111111
   %11111111
   %11111111
   %11111111
end


   ;***************************************************************
   ;
   ;  Toggles the playfield.
   ;
   _Bit4_Toggle_Screen = _Bit4_Toggle_Screen ^ %00010000

   if _Bit4_Toggle_Screen{4} then goto __Skip_Playfield_01

   playfield:
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   X..............................X
   X..............................X
   X..XXX..XXXXXXX..XXXXXXX..XXX..X
   X..............................X
   X..............................X
   X..............................X
   X..XXX..XXXXXXX..XXXXXXX..XXX..X
   X..............................X
   X..............................X
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end

   goto __Skip_Playfield_02


__Skip_Playfield_01  


   playfield:
   ................................
   ................................
   ....XXXXXXXXXX....XXXXXXXXXX....
   ....X......................X....
   ....X......................X....
   ....X......................X....
   ................................
   ................................
   ....XXXX....XXX..XXX....XXXX....
   ................................
   ................................
end

__Skip_Playfield_02





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets color of player0 sprite.
   ;
   COLUP0 = $9C



   ;***************************************************************
   ;
   ;  Joy0 up check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved up.
   ;
   if !joy0up then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0y <= _P_Edge_Top then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player0x-10)/4

   temp6 = (player0y-12)/7

   if temp5 < 34 then if pfread(temp5,temp6) then goto __Skip_Joy0_Up

   temp4 = (player0x-17)/4

   if temp4 < 34 then if pfread(temp4,temp6) then goto __Skip_Joy0_Up

   temp3 = temp5 - 1

   if temp3 < 34 then if pfread(temp3,temp6) then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 up.
   ;
   player0y = player0y - 1

__Skip_Joy0_Up



   ;***************************************************************
   ;
   ;  Joy0 down check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved down.
   ;
   if !joy0down then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0y >= _P_Edge_Bottom then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player0x-10)/4

   temp6 = (player0y)/7

   if temp5 < 34 then if pfread(temp5,temp6) then goto __Skip_Joy0_Down

   temp4 = (player0x-17)/4

   if temp4 < 34 then if pfread(temp4,temp6) then goto __Skip_Joy0_Down

   temp3 = temp5 - 1

   if temp3 < 34 then if pfread(temp3,temp6) then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 down.
   ;
   player0y = player0y + 1

__Skip_Joy0_Down



   ;***************************************************************
   ;
   ;  Joy0 left check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved to the left.
   ;
   if !joy0left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0x <= _P_Edge_Left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player0y-1)/7

   temp6 = (player0x-18)/4

   if temp6 < 34 then if pfread(temp6,temp5) then goto __Skip_Joy0_Left

   temp3 = (player0y-8)/7

   if temp6 < 34 then if pfread(temp6,temp3) then goto __Skip_Joy0_Left

   temp3 = (player0y-11)/7

   if temp6 < 34 then if pfread(temp6,temp3) then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 left.
   ;
   player0x = player0x - 1

__Skip_Joy0_Left



   ;***************************************************************
   ;
   ;  Joy0 right check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved to the right.
   ;
   if !joy0right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0x >= _P_Edge_Right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player0y-1)/7

   temp6 = (player0x-9)/4

   if temp6 < 34 then if pfread(temp6,temp5) then goto __Skip_Joy0_Right

   temp3 = (player0y-8)/7

   if temp6 < 34 then if pfread(temp6,temp3) then goto __Skip_Joy0_Right

   temp3 = (player0y-11)/7

   if temp6 < 34 then if pfread(temp6,temp3) then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 right.
   ;
   player0x = player0x + 1

__Skip_Joy0_Right



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart

 

 

 

Sprite, Ball, and Missile With Collision Prevention

Sprite, Ball, and Missile With Collision Prevention on bB page.

 
   ;***************************************************************
   ;
   ;  Sprite, Ball, and Missile With Collision Prevention
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Use the joystick to move the sprite. Press the fire button
   ;  to shoot the missile. Watch the ball bounce. Press the reset
   ;  switch to reset the program and toggle between two screens.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Player0/missile0 direction bits.
   ;
   dim _BitOp_P0_M0_Dir = g
   dim _Bit0_P0_Dir_Up = g
   dim _Bit1_P0_Dir_Down = g
   dim _Bit2_P0_Dir_Left = g
   dim _Bit3_P0_Dir_Right = g
   dim _Bit4_M0_Dir_Up = g
   dim _Bit5_M0_Dir_Down = g
   dim _Bit6_M0_Dir_Left = g
   dim _Bit7_M0_Dir_Right = g

   ;```````````````````````````````````````````````````````````````
   ;  Ball direction bits.
   ;
   dim _BitOp_Ball_Dir = h
   dim _Bit0_Ball_Dir_Up = h
   dim _Bit1_Ball_Dir_Down = h
   dim _Bit2_Ball_Dir_Left = h
   dim _Bit3_Ball_Dir_Right = h
   dim _Bit4_Ball_Hit_UD = h

   ;```````````````````````````````````````````````````````````````
   ;  Allows speed and angle adjustments to the ball.
   ;
   dim _B_Y = bally.i
   dim _B_X = ballx.j

   ;```````````````````````````````````````````````````````````````
   ;  Bits that do various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y
   dim _Bit4_Toggle_Screen = y
   dim _Bit7_M0_Moving = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers.
   ;
   dim rand16 = z



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for an 8 x 8 sprite.
   ;  If your sprite is a different size, you`ll need to adjust
   ;  the numbers.
   ;
   const _P_Edge_Top = 9
   const _P_Edge_Bottom = 88
   const _P_Edge_Left = 1
   const _P_Edge_Right = 153



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for the ball. If the
   ;  ball is a different size, you'll need to adjust the numbers.
   ;
   const _B_Edge_Top = 2
   const _B_Edge_Bottom = 88
   const _B_Edge_Left = 2
   const _B_Edge_Right = 160



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for the missile.
   ;  If the missile is a different size, you'll need to adjust
   ;  the numbers.
   ;
   const _M_Edge_Top = 2
   const _M_Edge_Bottom = 88
   const _M_Edge_Left = 2
   const _M_Edge_Right = 159



   ;***************************************************************
   ;
   ;  Disables the score. (We don't need it in this program.)
   ;
   const noscore = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears 24 of the normal 26 variables (fastest way).
   ;  The variable y holds a bit that should not be cleared. The
   ;  variable z is used for random numbers in this program and
   ;  clearing it would mess up those random numbers.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0


   ;***************************************************************
   ;
   ;  Clears 7 of the 8 all-purpose bits. The 4th bit toggles the
   ;  playfield when the reset switch is pressed in this example,
   ;  so we have to leave it alone.
   ;
   _BitOp_01 = _BitOp_01 & %00010000


   ;***************************************************************
   ;
   ;  Sets starting position of player0.
   ;
   player0x = 77 : player0y = 53


   ;***************************************************************
   ;
   ;  Makes sure missile0 is off the screen.
   ;
   missile0x = 200 : missile0y = 200


   ;***************************************************************
   ;
   ;  Defines missile0 size.
   ;
   NUSIZ0 = $10 : missile0height = 1


   ;***************************************************************
   ;
   ;  Sets playfield color.
   ;
   COLUPF = $2C


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Makes the ball 2 pixels wide and 2 pixels high.
   ;
   CTRLPF = $11 : ballheight = 2


   ;***************************************************************
   ;
   ;  Sets random starting position of ball.
   ;
   ballx = (rand/2) + (rand&15) + (rand/32) + 5 : bally = 9


   ;***************************************************************
   ;
   ;  Ballx starting direction is random. It will either go left
   ;  or right.
   ;
   _Bit2_Ball_Dir_Left{2} = 1 : _Bit3_Ball_Dir_Right{3} = 0

   temp5 = rand : if temp5 < 128 then _Bit2_Ball_Dir_Left{2} = 0 : _Bit3_Ball_Dir_Right{3} = 1


   ;***************************************************************
   ;
   ;  Bally starting direction is down.
   ;
   _Bit1_Ball_Dir_Down{1} = 1


   ;***************************************************************
   ;
   ;  Sets beginning direction that missile0 will shoot if the
   ;  player doesn't move.
   ;
   _Bit3_P0_Dir_Right{3} = 1


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Defines shape of player0 sprite.
   ;
   player0:
   %00111100
   %01111110
   %11000011
   %10111101
   %11111111
   %11011011
   %01111110
   %00111100
end


   ;***************************************************************
   ;
   ;  Toggles the playfield.
   ;
   _Bit4_Toggle_Screen = _Bit4_Toggle_Screen ^ %00010000

   if _Bit4_Toggle_Screen{4} then goto __Skip_Playfield_01

   playfield:
   ................................
   ................................
   ....XXXXXXXXXX....XXXXXXXXXX....
   ....X......................X....
   ....X......................X....
   ....X......................X....
   ................................
   ................................
   ....XXXX....XXX..XXX....XXXX....
   ................................
   ................................
end

   goto __Skip_Playfield_02


__Skip_Playfield_01


 playfield:
 ................................
 ................................
 ....XXXXXX...X....X...XX...X....
 .............X....X........X....
 .............X....X........X....
 ....XX....XXXX....XXXX.....X....
 ................................
 ................................
 ....XX...XX..XXXXXX..XX...XX....
 ................................
 ................................
end


__Skip_Playfield_02





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets color of player0 sprite.
   ;
   COLUP0 = $9C



   ;***************************************************************
   ;
   ;  Joystick movement precheck.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if joystick hasn't been moved.
   ;
   if !joy0up && !joy0down && !joy0left && !joy0right then goto __Skip_Joystick_Precheck

   ;```````````````````````````````````````````````````````````````
   ;  Clears player0 direction bits since joystick has been moved.
   ;
   _BitOp_P0_M0_Dir = _BitOp_P0_M0_Dir & %11110000

__Skip_Joystick_Precheck



   ;***************************************************************
   ;
   ;  Joy0 up check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved up.
   ;
   if !joy0up then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the up direction bit.
   ;
   _Bit0_P0_Dir_Up{0} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0y <= _P_Edge_Top then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player0x-10)/4

   temp6 = (player0y-9)/8

   if temp5 < 34 then if pfread(temp5,temp6) then goto __Skip_Joy0_Up

   temp4 = (player0x-17)/4

   if temp4 < 34 then if pfread(temp4,temp6) then goto __Skip_Joy0_Up

   temp3 = temp5 - 1

   if temp3 < 34 then if pfread(temp3,temp6) then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 up.
   ;
   player0y = player0y - 1

__Skip_Joy0_Up



   ;***************************************************************
   ;
   ;  Joy0 down check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved down.
   ;
   if !joy0down then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the down direction bit.
   ;
   _Bit1_P0_Dir_Down{1} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0y >= _P_Edge_Bottom then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player0x-10)/4

   temp6 = (player0y)/8

   if temp5 < 34 then if pfread(temp5,temp6) then goto __Skip_Joy0_Down

   temp4 = (player0x-17)/4

   if temp4 < 34 then if pfread(temp4,temp6) then goto __Skip_Joy0_Down

   temp3 = temp5 - 1

   if temp3 < 34 then if pfread(temp3,temp6) then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 down.
   ;
   player0y = player0y + 1

__Skip_Joy0_Down



   ;***************************************************************
   ;
   ;  Joy0 left check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved to the left.
   ;
   if !joy0left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the left direction bit.
   ;
   _Bit2_P0_Dir_Left{2} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0x <= _P_Edge_Left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player0y-1)/8

   temp6 = (player0x-18)/4

   if temp6 < 34 then if pfread(temp6,temp5) then goto __Skip_Joy0_Left

   temp3 = (player0y-8)/8

   if temp6 < 34 then if pfread(temp6,temp3) then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 left.
   ;
   player0x = player0x - 1

__Skip_Joy0_Left



   ;***************************************************************
   ;
   ;  Joy0 right check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved to the right.
   ;
   if !joy0right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the right direction bit.
   ;
   _Bit3_P0_Dir_Right{3} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0x >= _P_Edge_Right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player0y-1)/8

   temp6 = (player0x-9)/4

   if temp6 < 34 then if pfread(temp6,temp5) then goto __Skip_Joy0_Right

   temp3 = (player0y-8)/8

   if temp6 < 34 then if pfread(temp6,temp3) then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 right.
   ;
   player0x = player0x + 1

__Skip_Joy0_Right



   ;***************************************************************
   ;
   ;  Clears ball hits.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears the up/down ball/playfield hit bit.
   ;
   _Bit4_Ball_Hit_UD{4} = 0



   ;***************************************************************
   ;
   ;  Ball up check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if ball isn't moving up.
   ;
   if !_Bit0_Ball_Dir_Up{0} then goto __Skip_Ball_Up

   ;```````````````````````````````````````````````````````````````
   ;  Changes direction if hitting the edge.
   ;
   if bally <= _B_Edge_Top then goto __Reverse_Ball_Up

   ;```````````````````````````````````````````````````````````````
   ;  Changes direction if a playfield pixel is in the way.
   ;
   temp5 = (ballx-18)/4

   temp6 = (bally-2)/8

   if temp5 < 34 then if pfread(temp5,temp6) then _Bit4_Ball_Hit_UD{4} = 1 : goto __Reverse_Ball_Up

   ;```````````````````````````````````````````````````````````````
   ;  Moves ball up and skips the rest of this section.
   ;
   _B_Y = _B_Y - 1.00 : goto __Skip_Ball_Up

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Reverses direction.
   ;
__Reverse_Ball_Up

   ;```````````````````````````````````````````````````````````````
   ;  Mixes things up a bit to keep the ball from getting caught
   ;  in a pattern.
   ;
   _B_Y = _B_Y + 0.130

   temp5 = rand : if temp5 < 128 then _B_Y = _B_Y + 0.130

   ;```````````````````````````````````````````````````````````````
   ;  Reverses the direction bits.
   ;
   _Bit0_Ball_Dir_Up{0} = 0 : _Bit1_Ball_Dir_Down{1} = 1

__Skip_Ball_Up



   ;***************************************************************
   ;
   ;  Ball down check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if ball isn't moving down.
   ;
   if !_Bit1_Ball_Dir_Down{1} then goto __Skip_Ball_Down

   ;```````````````````````````````````````````````````````````````
   ;  Changes direction if hitting the edge.
   ;
   if bally >= _B_Edge_Bottom then goto __Reverse_Ball_Down

   ;```````````````````````````````````````````````````````````````
   ;  Changes direction if a playfield pixel is in the way.
   ;
   temp5 = (ballx-18)/4

   temp6 = (bally+1)/8

   if temp5 < 34 then if pfread(temp5,temp6) then _Bit4_Ball_Hit_UD{4} = 1 : goto __Reverse_Ball_Down

   ;```````````````````````````````````````````````````````````````
   ;  Moves ball down and skips the rest of this section.
   ;
   _B_Y = _B_Y + 1.00 : goto __Skip_Ball_Down

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Reverses direction.
   ;
__Reverse_Ball_Down

   ;```````````````````````````````````````````````````````````````
   ;  Mixes things up a bit to keep the ball from getting caught
   ;  in a pattern.
   ;
   _B_Y = _B_Y - 0.261

   temp5 = rand : if temp5 < 128 then _B_Y = _B_Y - 0.261

   ;```````````````````````````````````````````````````````````````
   ;  Reverses the direction bits.
   ;
   _Bit0_Ball_Dir_Up{0} = 1 : _Bit1_Ball_Dir_Down{1} = 0

__Skip_Ball_Down



   ;***************************************************************
   ;
   ;  Ball left check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if ball isn't moving left.
   ;
   if !_Bit2_Ball_Dir_Left{2} then goto __Skip_Ball_Left

   ;```````````````````````````````````````````````````````````````
   ;  Changes direction if hitting the edge.
   ;
   if ballx <= _B_Edge_Left then goto __Reverse_Ball_Left

   ;```````````````````````````````````````````````````````````````
   ;  Changes direction if a playfield pixel is in the way.
   ;
   temp5 = (bally)/8

   temp6 = (ballx-19)/4

   if temp6 < 34 then if pfread(temp6,temp5) then goto __Reverse_Ball_Left

   ;```````````````````````````````````````````````````````````````
   ;  Moves ball left and skips the rest of this section.
   ;
   _B_X = _B_X - 1.00 : goto __Skip_Ball_Left

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Reverses direction.
   ;
__Reverse_Ball_Left

   ;```````````````````````````````````````````````````````````````
   ;  Reverses up/down bits if there was an up or down hit.
   ;
   if _Bit4_Ball_Hit_UD{4} then _Bit0_Ball_Dir_Up{0} = !_Bit0_Ball_Dir_Up{0} : _Bit1_Ball_Dir_Down{1} = !_Bit1_Ball_Dir_Down{1}

   ;```````````````````````````````````````````````````````````````
   ;  Mixes things up a bit to keep the ball from getting caught
   ;  in a pattern.
   ;
   _B_X = _B_X + 0.388

   temp5 = rand : if temp5 < 128 then _B_X = _B_X + 0.388

   ;```````````````````````````````````````````````````````````````
   ;  Reverses the direction bits.
   ;
   _Bit2_Ball_Dir_Left{2} = 0 : _Bit3_Ball_Dir_Right{3} = 1

__Skip_Ball_Left



   ;***************************************************************
   ;
   ;  Ball right check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if ball isn't moving right.
   ;
   if !_Bit3_Ball_Dir_Right{3} then goto __Skip_Ball_Right

   ;```````````````````````````````````````````````````````````````
   ;  Changes direction if hitting the edge.
   ;
   if ballx >= _B_Edge_Right then goto __Reverse_Ball_Right

   ;```````````````````````````````````````````````````````````````
   ;  Changes direction if a playfield pixel is in the way.
   ;
   temp5 = (bally)/8

   temp6 = (ballx-16)/4

   if temp6 < 34 then if pfread(temp6,temp5) then goto __Reverse_Ball_Right

   ;```````````````````````````````````````````````````````````````
   ;  Moves ball right and skips the rest of this section.
   ;
   _B_X = _B_X + 1.00 : goto __Skip_Ball_Right

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Reverses direction.
   ;
__Reverse_Ball_Right

   ;```````````````````````````````````````````````````````````````
   ;  Reverses up/down bits if there was an up or down hit.
   ;
   if _Bit4_Ball_Hit_UD{4} then _Bit0_Ball_Dir_Up{0} = !_Bit0_Ball_Dir_Up{0} : _Bit1_Ball_Dir_Down{1} = !_Bit1_Ball_Dir_Down{1}

   ;```````````````````````````````````````````````````````````````
   ;  Mixes things up a bit to keep the ball from getting caught
   ;  in a pattern.
   ;
   _B_X = _B_X - 0.513

   temp5 = rand : if temp5 < 128 then _B_X = _B_X - 0.513

   ;```````````````````````````````````````````````````````````````
   ;  Reverses the direction bits.
   ;
   _Bit2_Ball_Dir_Left{2} = 1 : _Bit3_Ball_Dir_Right{3} = 0

__Skip_Ball_Right



   ;***************************************************************
   ;
   ;  Fire button check.
   ;  
   ;  If fire button is pressed appropriately and missile0
   ;  is not moving, turns on missile0 movement.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the fire button is not pressed.
   ;
   if !joy0fire then goto __Skip_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if missile0 is moving.
   ;
   if _Bit7_M0_Moving{7} then goto __Skip_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Turns on missile0 movement.
   ;
   _Bit7_M0_Moving{7} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Takes a 'snapshot' of player0 direction so missile0 will
   ;  stay on track until it hits something.
   ;
   _Bit4_M0_Dir_Up{4} = _Bit0_P0_Dir_Up{0}
   _Bit5_M0_Dir_Down{5} = _Bit1_P0_Dir_Down{1}
   _Bit6_M0_Dir_Left{6} = _Bit2_P0_Dir_Left{2}
   _Bit7_M0_Dir_Right{7} = _Bit3_P0_Dir_Right{3}

   ;```````````````````````````````````````````````````````````````
   ;  Sets up starting position of missile0.
   ;
   if _Bit4_M0_Dir_Up{4} then missile0x = player0x + 4 : missile0y = player0y - 5
   if _Bit5_M0_Dir_Down{5} then missile0x = player0x + 4 : missile0y = player0y - 1
   if _Bit6_M0_Dir_Left{6} then missile0x = player0x + 2 : missile0y = player0y - 3
   if _Bit7_M0_Dir_Right{7} then missile0x = player0x + 6 : missile0y = player0y - 3

__Skip_Fire



   ;***************************************************************
   ;
   ;  Missile0 movement check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if missile0 isn't moving.
   ;
   if !_Bit7_M0_Moving{7} then goto __Skip_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Moves missile0 in the appropriate direction.
   ;
   if _Bit4_M0_Dir_Up{4} then missile0y = missile0y - 2
   if _Bit5_M0_Dir_Down{5} then missile0y = missile0y + 2
   if _Bit6_M0_Dir_Left{6} then missile0x = missile0x - 2
   if _Bit7_M0_Dir_Right{7} then missile0x = missile0x + 2

   ;```````````````````````````````````````````````````````````````
   ;  Clears missile0 if it hits the edge of the screen.
   ;
   if missile0y < _M_Edge_Top then goto __Skip_to_Clear_Missile
   if missile0y > _M_Edge_Bottom then goto __Skip_to_Clear_Missile
   if missile0x < _M_Edge_Left then goto __Skip_to_Clear_Missile
   if missile0x > _M_Edge_Right then goto __Skip_to_Clear_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Skips rest of section if no collision.
   ;
   if !collision(playfield,missile0) then goto __Skip_Missile

__Skip_to_Clear_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Clears missile0 moving bit and moves missile0 off the screen.
   ;
   _Bit7_M0_Moving{7} = 0 : missile0x = 200 : missile0y = 200

__Skip_Missile



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart

 

 

 

8.8 Fixed Point Sprite Movement

8.8 Fixed Point Sprite Movement on bB page.

 
   ;***************************************************************
   ;
   ;  Sprite Using 8.8 Fixed Point Movement
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Use the joystick to move the sprite. Press the fire button 
   ;  while moving the joystick to go faster. Notice how the
   ;  sprite smoothly glides along the walls when the sprite 
   ;  is moved diagonally. It doesn't stick or bounce.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Player0 fixed point variables for more flexibility in
   ;  gameplay mechanics.
   ;
   dim _P0_L_R = player0x.a
   dim _P0_U_D = player0y.b

   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers.
   ;
   dim rand16 = z



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for an 8 x 8 sprite.
   ;  If your sprite is a different size, you`ll need to adjust
   ;  the numbers.
   ;
   const _P_Edge_Top = 9
   const _P_Edge_Bottom = 88
   const _P_Edge_Left = 1
   const _P_Edge_Right = 153



   ;***************************************************************
   ;
   ;  Disables the score. (We don`t need it in this program.)
   ;
   const noscore = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears 25 of the normal 26 variables.
   ;  The variable z is used for random numbers in this program
   ;  and clearing it would mess up those random numbers.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0


   ;***************************************************************
   ;
   ;  Starting position of Player0.
   ;
   player0x = 77 : player0y = 53


   ;***************************************************************
   ;
   ;  Sets playfield color.
   ;
   COLUPF = $FC


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Defines shape of player0 sprite.
   ;
   player0:
   %00111100
   %01111110
   %11000011
   %10111101
   %11111111
   %11011011
   %01111110
   %00111100
end


   ;***************************************************************
   ;
   ;  Sets up the playfield.
   ;
   playfield:
   ................................
   ................................
   ....XXXXXXXXXX....XXXXXXXXXX....
   ....X......................X....
   ....X......................X....
   ....X......................X....
   ................................
   ................................
   ....XXXX....XXX..XXX....XXXX....
   ................................
   ................................
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets color of player0 sprite.
   ;
   COLUP0 = $9C



   ;***************************************************************
   ;
   ;  Joy0 up check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved up.
   ;
   if !joy0up then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if _P0_U_D <= _P_Edge_Top then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (_P0_L_R-10)/4

   temp6 = (_P0_U_D-9)/8

   if temp5 < 32 then if pfread(temp5,temp6) then goto __Skip_Joy0_Up

   temp4 = (_P0_L_R-17)/4

   if temp4 < 32 then if pfread(temp4,temp6) then goto __Skip_Joy0_Up

   temp3 = temp5 - 1

   if temp3 < 32 then if pfread(temp3,temp6) then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 up.
   ;
   _P0_U_D = _P0_U_D - 1.00

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if _P0_U_D <= _P_Edge_Top then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Speeds up if fire button is pressed.
   ;
   if !joy0fire then goto __Skip_Joy0_Up

   temp6 = (_P0_U_D-9)/8

   if temp5 < 32 then if pfread(temp5,temp6) then goto __Skip_Joy0_Up

   if temp4 < 32 then if pfread(temp4,temp6) then goto __Skip_Joy0_Up

   if temp3 < 32 then if pfread(temp3,temp6) then goto __Skip_Joy0_Up 

   _P0_U_D = _P0_U_D - 0.52

__Skip_Joy0_Up



   ;***************************************************************
   ;
   ;  Joy0 down check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved down.
   ;
   if !joy0down then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if _P0_U_D >= _P_Edge_Bottom then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (_P0_L_R-10)/4

   temp6 = (_P0_U_D)/8

   if temp5 < 32 then if pfread(temp5,temp6) then goto __Skip_Joy0_Down

   temp4 = (_P0_L_R-17)/4

   if temp4 < 32 then if pfread(temp4,temp6) then goto __Skip_Joy0_Down

   temp3 = temp5 - 1

   if temp3 < 32 then if pfread(temp3,temp6) then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 down.
   ;
   _P0_U_D = _P0_U_D + 1.00

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if _P0_U_D >= _P_Edge_Bottom then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Speeds up if fire button is pressed.
   ;
   if !joy0fire then goto __Skip_Joy0_Down

   temp6 = (_P0_U_D)/8

   if temp5 < 32 then if pfread(temp5,temp6) then goto __Skip_Joy0_Down

   if temp4 < 32 then if pfread(temp4,temp6) then goto __Skip_Joy0_Down

   if temp3 < 32 then if pfread(temp3,temp6) then goto __Skip_Joy0_Down

   _P0_U_D = _P0_U_D + 0.52

__Skip_Joy0_Down



   ;***************************************************************
   ;
   ;  Joy0 left check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved to the left.
   ;
   if !joy0left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if _P0_L_R <= _P_Edge_Left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (_P0_U_D-1)/8

   temp6 = (_P0_L_R-18)/4

   if temp6 < 32 then if pfread(temp6,temp5) then goto __Skip_Joy0_Left

   temp3 = (_P0_U_D-8)/8

   if temp6 < 32 then if pfread(temp6,temp3) then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 left.
   ;
   _P0_L_R = _P0_L_R - 1.00

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if _P0_L_R <= _P_Edge_Left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Speeds up if fire button is pressed.
   ;
   if !joy0fire then goto __Skip_Joy0_Left

   temp6 = (_P0_L_R-18)/4

   if temp6 < 32 then if pfread(temp6,temp5) then goto __Skip_Joy0_Left

   if temp6 < 32 then if pfread(temp6,temp3) then goto __Skip_Joy0_Left

   _P0_L_R = _P0_L_R - 0.52

__Skip_Joy0_Left



   ;***************************************************************
   ;
   ;  Joy0 right check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved to the right.
   ;
   if !joy0right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if _P0_L_R >= _P_Edge_Right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (_P0_U_D-1)/8

   temp6 = (_P0_L_R-9)/4

   if temp6 < 32 then if pfread(temp6,temp5) then goto __Skip_Joy0_Right

   temp3 = (_P0_U_D-8)/8

   if temp6 < 32 then if pfread(temp6,temp3) then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 right.
   ;
   _P0_L_R = _P0_L_R + 1.00

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if _P0_L_R >= _P_Edge_Right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Speeds up if fire button is pressed.
   ;
   if !joy0fire then goto __Skip_Joy0_Right

   temp6 = (_P0_L_R-9)/4

   if temp6 < 32 then if pfread(temp6,temp5) then goto __Skip_Joy0_Right

   if temp6 < 32 then if pfread(temp6,temp3) then goto __Skip_Joy0_Right

   _P0_L_R = _P0_L_R + 0.52

__Skip_Joy0_Right



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart

 

 

 

Bankswitching Example

Bankswitching Example on bB page.

 
   ;****************************************************************
   ;
   ;  Title Screen and Game Over With Bankswitching
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;  High score code provided by supercat and polished up
   ;  by Nukey Shay.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  About this program:
   ;  
   ;  Besides being a working example of bankswitching, this
   ;  example program shows different parts of a game. There
   ;  is a fake title screen, a fake game, and a game over
   ;  screen with an initial 2 second freeze. The game over screen
   ;  also flips between the current score and the high score
   ;  every 2 seconds.
   ;
   ;  The fake title screen is displayed for 10 seconds, then it
   ;  switches to auto-play. The current score and high score are
   ;  also displayed during auto-play (just like on the game over
   ;  screen). This attract mode sequence repeats until you press
   ;  the reset switch or the fire button on the left joystick.
   ;
   ;  After you start the fake game, move the sprite with the left
   ;  joystick and press the fire button to shoot missiles. Add to
   ;  the score by shooting the walls with the missiles or by
   ;  shooting the enemy sprite.
   ;
   ;  To pause the fake game on an Atari 2600, flip the COLOR/BW
   ;  switch. To pause on an Atari 7800, press the pause button.
   ;  You can also pause the fake game by pressing the fire button
   ;  on the right controller. To resume play, press and release
   ;  the fire button on the left controller.
   ;
   ;  End the fake game by touching the enemy sprite.
   ;
   ;  Pressing the reset switch during the fake game will take you
   ;  back to the fake title screen. Pressing the reset switch or
   ;  the fire button while on the game over screen will restart
   ;  the fake game and skip the fake title screen. If you do
   ;  nothing for 20 seconds while on the game over screen, you'll
   ;  go back to the fake title screen.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Multicolored playfield and no blank lines.
   ;  Cost: loss of missile0.
   ;
   set kernel_options pfcolors no_blank_lines



   ;***************************************************************
   ;
   ;  This program has 8 banks (32k/4k = 8 banks).
   ;
   set romsize 32k



   ;***************************************************************
   ;
   ;  Random numbers can slow down bankswitched games.
   ;  This will speed things up.
   ;
   set optimization inlinerand



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that

   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  _Master_Counter can be used for many things, but it is 
   ;  really useful for animating sprite frames when used
   ;  with _Frame_Counter.
   ;
   dim _Master_Counter = e
   dim _Frame_Counter = f

   ;```````````````````````````````````````````````````````````````
   ;  Player0/missile1 direction bits.
   ;
   dim _BitOp_P0_M1_Dir = g
   dim _Bit0_P0_Dir_Up = g
   dim _Bit1_P0_Dir_Down = g
   dim _Bit2_P0_Dir_Left = g
   dim _Bit3_P0_Dir_Right = g
   dim _Bit4_M1_Dir_Up = g
   dim _Bit5_M1_Dir_Down = g
   dim _Bit6_M1_Dir_Left = g
   dim _Bit7_M1_Dir_Right = g

   ;```````````````````````````````````````````````````````````````
   ;  Auto-play sprite direction.
   ;  0 = up, 1 = up/right, 2 = right, 3 = down/right, 4 = down,
   ;  5 = down/left, 6 = left, 7 = up/left.
   ;
   dim _T5_AP_Dir = temp5

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the opposite direction the sprite moved during
   ;  auto-play. Keeps the sprite from bouncing back and forth
   ;  between the same two directions like a ping-pong ball.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _AP_Mem_Dir = h

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used in the pause loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _Pause_Counter_Tmp = h

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the last position of the sprite during auto-play.
   ;  A new direction is chosen if the sprite stops moving.
   ;  These variables can be reused if you're sure it won't
   ;  interfere with auto-play.
   ;
   dim _AP_Mem_P0x = i
   dim _AP_Mem_P0y = j

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used for auto-play in the main loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _AP_2_Sec_Score_Flip = k

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used in the pause loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _Pause_Mem_Color_Tmp = k

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used for auto-play in the main loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _AP_Dir_Counter = l

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used in the pause loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _Pause_Color_Tmp = l

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _BitOp_02 = r

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the position of the BW switch.
   ;
   dim _Bit0_BW_Mem = r

   ;```````````````````````````````````````````````````````````````
   ;  Checks to see if the BW switch has moved.
   ;
   dim _Bit1_BW_Check = r

   ;```````````````````````````````````````````````````````````````
   ;  Lets pause section know if the B color scheme should be used.
   ;
   dim _Bit2_Pause_Clr_Scheme = r

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  These can be used for other things using different aliases,
   ;  but for the game over loop and auto-play in the main loop,
   ;  they are used to temporarily remember the score for the 2
   ;  second score/high score flip.
   ;
   dim _Score1_Mem = s
   dim _Score2_Mem = t
   dim _Score3_Mem = u

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the high score until the game is turned off.
   ;
   dim _High_Score1 = v
   dim _High_Score2 = w
   dim _High_Score3 = x

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y
   dim _Bit1_FireB_Restrainer = y
   dim _Bit2_Game_Control = y
   dim _Bit3_Auto_Play = y
   dim _Bit6_Swap_Scores = y
   dim _Bit7_M1_Moving = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers. 
   ;
   dim rand16 = z

   ;```````````````````````````````````````````````````````````````
   ;  Converts 6 digit score to 3 sets of two digits.
   ;
   ;  The 100 thousands and 10 thousands digits are held by _sc1.
   ;  The thousands and hundreds digits are held by _sc2.
   ;  The tens and ones digits are held by _sc3.
   ;
   dim _sc1 = score
   dim _sc2 = score+1
   dim _sc3 = score+2



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for an 8 x 8 sprite.
   ;  If your sprite is a different size, you'll need to adjust
   ;  the numbers.
   ;
   const _P_Edge_Top = 9
   const _P_Edge_Bottom = 88
   const _P_Edge_Left = 1
   const _P_Edge_Right = 152



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for the missile.
   ;  If the missile is a different size, you'll need to adjust
   ;  the numbers.
   ;
   const _M_Edge_Top = 2
   const _M_Edge_Bottom = 88
   const _M_Edge_Left = 2
   const _M_Edge_Right = 159





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears 21 of the normal 26 variables (fastest way).
   ;  Do not clear v, w, x, y, or z in this program. The variables
   ;  v through x remember the high score. The variable y holds a
   ;  bit that should not be cleared. The variable z is used for
   ;  random numbers in this program and clearing it would mess
   ;  up those random numbers.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0


   ;***************************************************************
   ;
   ;  Clears 7 of the 8 bits.
   ;
   ;  Bit 2 is not cleared because _Bit2_Game_Control{2} is used
   ;  to control how the program is reset.
   ;
   _BitOp_01 = _BitOp_01 & %00000100


   ;***************************************************************
   ;
   ;  Makes sure sprites and missile are off the screen.
   ;
   player0y = 200 : player1y = 200 : missile1y = 200


   ;***************************************************************
   ;
   ;  Skips title screen if game has been played and player
   ;  presses fire button or reset switch at the end of the game.
   ;
   ;  0 = Go to title screen.
   ;  1 = Skip title screen and play game.
   ;
   if _Bit2_Game_Control{2} then goto __Main_Loop_Setup bank2





   ;***************************************************************
   ;***************************************************************
   ;
   ;   TITLE SCREEN SETUP
   ;
   ;
__Title_Screen_Setup


   ;***************************************************************
   ;
   ;  Sets score color for title screen.
   ;
   scorecolor = 0


   ;***************************************************************
   ;
   ;  Sets title screen background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after entering a different segment
   ;  of the program. It also does double duty by restraining the
   ;  fire button in the title screen loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets up title screen playfield.
   ;
   playfield:
   .XXXXXX.XXXXXX.XXXXXXXXXX.XXXXX.
   .XX.....XX..XX.XX..XX..XX.XX....
   .XX.XXX.XXXXXX.XX..XX..XX.XXXX..
   .XX..XX.XX..XX.XX..XX..XX.XX....
   .XXXXXX.XX..XX.XX..XX..XX.XXXXX.
   ................................
   ..XXXXXX.XX.XXXXXX.XX....XXXXX..
   ....XX...XX...XX...XX....XX.....
   ....XX...XX...XX...XX....XXXX...
   ....XX...XX...XX...XX....XX.....
   ....XX...XX...XX...XXXXX.XXXXX..
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  TITLE SCREEN LOOP
   ;
   ;
__Title_Screen_Loop



   ;***************************************************************
   ;
   ;  Sets title screen playfield pixel colors.
   ;
   pfcolors:
   $6E
   $6E
   $6C
   $6A
   $68
   $66
   $6E
   $6E
   $6C
   $6A
   $68
   $66
end



   ;***************************************************************
   ;
   ;  Auto-play check.
   ;
   ;  Switches to auto-play after 10 seconds if player doesn't
   ;  start the game.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increment _Master_Counter.
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if counter is less than one second.
   ;
   if _Master_Counter < 60 then goto __TS_AP_Skip

   ;```````````````````````````````````````````````````````````````
   ;  Increments _Frame_Counter and clears _Master_Counter.
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check.
   ;
   ;  Turns on auto-play and jumps to main loop setup if 10 
   ;  seconds have gone by.
   ;
   if _Frame_Counter > 9 then _Bit3_Auto_Play{3} = 1 : goto __Main_Loop_Setup bank2

__TS_AP_Skip



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset/fire button check and end of title screen loop.
   ;  
   ;  Starts the game if the reset switch or the fire button
   ;  is pressed appropriately.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and jumps to beginning of title 
   ;  screen loop if fire button or reset switch is not pressed.
   ;
   if !switchreset && !joy0fire then _Bit0_Reset_Restrainer{0} = 0 : goto __Title_Screen_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of title screen loop if reset or fire 
   ;  hasn't been released since starting title screen loop.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Title_Screen_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Sets control bit so program will jump to main loop setup.
   ;
   _Bit2_Game_Control{2} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Restarts game and program jumps to main loop setup.
   ;
   goto __Start_Restart





   bank 2





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP SETUP
   ;
   ;
__Main_Loop_Setup


   ;***************************************************************
   ;
   ;  In the main loop, _Bit2_Game_Control{2} controls when the
   ;  game ends.
   ;
   ;  0 = Game not over.
   ;  1 = Game over.
   ;
   _Bit2_Game_Control{2} = 0



   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed in the title
   ;  screen section or the game over section. If the reset
   ;  switch isn't being held down, this bit will be cleared
   ;  in the main loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Restrains the fire button for the main loop.
   ;
   ;  This bit fixes it so the fire button becomes inactive if it
   ;  hasn't been released after being pressed in the title
   ;  screen section or the game over section. If the fire
   ;  button isn't being held down, this bit will be cleared
   ;  in the main loop.
   ;
   _Bit1_FireB_Restrainer{1} = 1


   ;***************************************************************
   ;
   ;  Starting position of player0.
   ;
   player0x = 77 : player0y = 53


   ;***************************************************************
   ;
   ;  Sets score color.
   ;
   scorecolor = $1C


   ;***************************************************************
   ;
   ;  Defines missile1 height.
   ;
   missile1height = 1


   ;***************************************************************
   ;
   ;  Sets beginning direction that missile1 will shoot if the
   ;  player doesn't move.
   ;
   _Bit3_P0_Dir_Right{3} = 1


   ;***************************************************************
   ;
   ;  Defines shape of player0 sprite.
   ;
   player0:
   %00111100
   %01111110
   %11000011
   %10111101
   %11111111
   %11011011
   %01111110
   %00111100
end


   ;***************************************************************
   ;
   ;  Defines shape of player1 sprite.
   ;
   player1:
   %00111100
   %01111110
   %11000011
   %11111111
   %11111111
   %11011011
   %01111110
   %00111100
end


   ;***************************************************************
   ;
   ;  Sets starting position of enemy.
   ;
   player1y = (rand&63) + 15 : temp5 = rand

   if temp5 > 128 then player1x = (rand&7) + 5 : goto __Skip_Enemy_Setup

   player1x = (rand&7) + 140

__Skip_Enemy_Setup


   ;***************************************************************
   ;
   ;  Sets up the main loop playfield.
   ;
   playfield:
   ................................
   ................................
   ....XXXXXXXXXX....XXXXXXXXXX....
   ....X......................X....
   ....X......................X....
   ....X......................X....
   ................................
   ................................
   ....XXXX....XXX..XXX....XXXX....
   ................................
   ................................
end


   ;***************************************************************
   ;
   ;  Remembers position of COLOR/BW switch.
   ;
   _Bit0_BW_Mem{0} = 0 : if switchbw then _Bit0_BW_Mem{0} = 1


   ;***************************************************************
   ;
   ;  Auto-play score swap setup.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears score and skips section if auto-play is off.
   ;
   if !_Bit3_Auto_Play{3} then score = 0 : goto __AP_Skip_AP_Setup

   ;```````````````````````````````````````````````````````````````
   ;  Sets up the score swap and clears the swap bit.
   ;
   _Score1_Mem = _sc1 : _Score2_Mem = _sc2 : _Score3_Mem = _sc3

   _Bit6_Swap_Scores{6} = 0

__AP_Skip_AP_Setup





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE GAME GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0



   ;***************************************************************
   ;
   ;  Sets playfield pixel colors.
   ;
   pfcolors:
   $2C
   $2C
   $2C
   $2C
   $2A
   $28
   $26
   $2C
   $2C
   $2C
   $2C
end



   ;***************************************************************
   ;
   ;  Sets sprite colors.
   ;
   COLUP0 = $9C : COLUP1 = $44



   ;***************************************************************
   ;
   ;  Sets missile1 width.
   ;
   NUSIZ1 = $10



   ;***************************************************************
   ;
   ;  Joystick movement precheck.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if auto-play is on.
   ;
   if _Bit3_Auto_Play{3} then goto __Skip_Joystick_Precheck

   ;```````````````````````````````````````````````````````````````
   ;  Skips section if joystick hasn't been moved.
   ;
   if !joy0up && !joy0down && !joy0left && !joy0right then goto __Skip_Joystick_Precheck

   ;```````````````````````````````````````````````````````````````
   ;  Clears player0 direction bits since joystick has been moved.
   ;
   _BitOp_P0_M1_Dir = _BitOp_P0_M1_Dir & %11110000

__Skip_Joystick_Precheck




   ;***************************************************************
   ;
   ;  Auto-play direction change for player0 sprite.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if auto-play is off.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_New_Dir

   ;```````````````````````````````````````````````````````````````
   ;  Adds to the auto-play direction change counter.
   ;
   _AP_Dir_Counter = _AP_Dir_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Forces a direction change when the counter gets too high or
   ;  when it's set high on purpose because the sprite was inactive.
   ;
   if _AP_Dir_Counter > 254 then goto __Get_New_AP_Direction

   ;```````````````````````````````````````````````````````````````
   ;  Grabs a random number (0 to 63) and adds 50. Change 50 to a
   ;  larger number if you want the sprite to move longer before
   ;  changing directions. Don't use a number larger than 190.
   ;
   temp6 = (rand&63) + 50

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the counter isn't high enough.
   ;
   if _AP_Dir_Counter < temp6 then goto __AP_Skip_New_Dir

   ;```````````````````````````````````````````````````````````````
   ;  Grabs a random number (0 to 255).
   ;
   temp5 = rand

   ;```````````````````````````````````````````````````````````````
   ;  There is a 90% chance that this section will be skipped.
   ;
   if temp5 < 230 then goto __AP_Skip_New_Dir

__Get_New_AP_Direction

   ;```````````````````````````````````````````````````````````````
   ;  Grabs a new sprite direction from a random number (0 to 7).
   ;
   ;     0
   ;   7   1
   ;  6     2
   ;   5   3
   ;     4
   ;
   ;  0 = up, 1 = up/right, 2 = right, 3 = down/right, 4 = down,
   ;  5 = down/left, 6 = left, 7 = up/left.
   ;
   _T5_AP_Dir = (rand&7)

   ;```````````````````````````````````````````````````````````````
   ;  Compares the new sprite direction with the opposite direction
   ;  and selects a new direction if there is a match. This keeps
   ;  the sprite from bouncing back and forth between the same two
   ;  directions.
   ;
   if _T5_AP_Dir = _AP_Mem_Dir then _T5_AP_Dir = _T5_AP_Dir + (rand&1) + (rand&3) + 2 : if _T5_AP_Dir > 7 then _T5_AP_Dir = _T5_AP_Dir - 8

   ;```````````````````````````````````````````````````````````````
   ;  Sprite goes up/right or up/left if it is near bottom.
   ;
   if player0y > 85 then _T5_AP_Dir = 1 : temp6 = rand : if temp6 > 128 then _T5_AP_Dir = 7

   ;```````````````````````````````````````````````````````````````
   ;  Sprite goes down/right or down/left if it is near top.
   ;
   if player0y < 12 then _T5_AP_Dir = 3 : temp6 = rand : if temp6 > 128 then _T5_AP_Dir = 5

   ;```````````````````````````````````````````````````````````````
   ;  Sprite goes up/left or down/left if it's near right side.
   ;
   if player0x > 148 then _T5_AP_Dir = 7 : temp6 = rand : if temp6 > 128 then _T5_AP_Dir = 5

   ;```````````````````````````````````````````````````````````````
   ;  Sprite goes up/right or down/right if it's near left side.
   ;
   if player0x < 4 then _T5_AP_Dir = 1 : temp6 = rand : if temp6 > 128 then _T5_AP_Dir = 3

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the opposite direction the sprite is moving. Keeps
   ;  the sprite from bouncing back and forth between the same two
   ;  directions.
   ;
   _AP_Mem_Dir = _T5_AP_Dir + 4 : if _AP_Mem_Dir > 7 then _AP_Mem_Dir = _AP_Mem_Dir - 8

   ;```````````````````````````````````````````````````````````````
   ;  Clears counter and sprite direction bits.
   ;
   _AP_Dir_Counter = 0 : _BitOp_P0_M1_Dir = _BitOp_P0_M1_Dir & %11110000

   ;```````````````````````````````````````````````````````````````
   ;  Converts sprite direction to bits to make things easier.
   ;
   if _T5_AP_Dir = 0 then _Bit0_P0_Dir_Up{0} = 1
   if _T5_AP_Dir = 1 then _Bit0_P0_Dir_Up{0} = 1 : _Bit3_P0_Dir_Right{3} = 1
   if _T5_AP_Dir = 2 then _Bit3_P0_Dir_Right{3} = 1
   if _T5_AP_Dir = 3 then _Bit1_P0_Dir_Down{1} = 1 : _Bit3_P0_Dir_Right{3} = 1
   if _T5_AP_Dir = 4 then _Bit1_P0_Dir_Down{1} = 1
   if _T5_AP_Dir = 5 then _Bit1_P0_Dir_Down{1} = 1 : _Bit2_P0_Dir_Left{2} = 1
   if _T5_AP_Dir = 6 then _Bit2_P0_Dir_Left{2} = 1
   if _T5_AP_Dir = 7 then _Bit0_P0_Dir_Up{0} = 1 : _Bit2_P0_Dir_Left{2} = 1

__AP_Skip_New_Dir




   ;***************************************************************
   ;
   ;  Joy0 up check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps ahead if auto-play is on and the up bit is on.
   ;
   if _Bit3_Auto_Play{3} && _Bit0_P0_Dir_Up{0} then goto __AP_Move_Up

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved up.
   ;
   if !joy0up then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the up direction bit.
   ;
   _Bit0_P0_Dir_Up{0} = 1

__AP_Move_Up

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0y <= _P_Edge_Top then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player0x-10)/4

   temp4 = (player0x-17)/4

   temp3 = temp5 - 1

   temp6 = (player0y-9)/8

   if temp5 < 34 then if pfread(temp5,temp6) then goto __Skip_Joy0_Up

   if temp4 < 34 then if pfread(temp4,temp6) then goto __Skip_Joy0_Up

   if temp3 < 34 then if pfread(temp3,temp6) then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 up.
   ;
   player0y = player0y - 1

__Skip_Joy0_Up



   ;***************************************************************
   ;
   ;  Joy0 down check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps ahead if auto-play is on and the down bit is on.
   ;
   if _Bit3_Auto_Play{3} && _Bit1_P0_Dir_Down{1} then goto __AP_Move_Down

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved down.
   ;
   if !joy0down then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the down direction bit.
   ;
   _Bit1_P0_Dir_Down{1} = 1

__AP_Move_Down

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0y >= _P_Edge_Bottom then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player0x-10)/4

   temp4 = (player0x-17)/4

   temp3 = temp5 - 1

   temp6 = (player0y+1)/8

   if temp5 < 34 then if pfread(temp5,temp6) then goto __Skip_Joy0_Down

   if temp4 < 34 then if pfread(temp4,temp6) then goto __Skip_Joy0_Down

   if temp3 < 34 then if pfread(temp3,temp6) then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 down.
   ;
   player0y = player0y + 1

__Skip_Joy0_Down



   ;***************************************************************
   ;
   ;  Joy0 left check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps ahead if auto-play is on and the left bit is on.
   ;
   if _Bit3_Auto_Play{3} && _Bit2_P0_Dir_Left{2} then goto __AP_Move_Left

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved to the left.
   ;
   if !joy0left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the left direction bit.
   ;
   _Bit2_P0_Dir_Left{2} = 1

__AP_Move_Left

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0x <= _P_Edge_Left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player0y)/8

   temp3 = (player0y-8)/8

   temp6 = (player0x-18)/4

   if temp6 < 34 then if pfread(temp6,temp5) then goto __Skip_Joy0_Left

   if temp6 < 34 then if pfread(temp6,temp3) then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 left.
   ;
   player0x = player0x - 1

__Skip_Joy0_Left



   ;***************************************************************
   ;
   ;  Joy0 right check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps ahead if auto-play is on and the right bit is on.
   ;
   if _Bit3_Auto_Play{3} && _Bit3_P0_Dir_Right{3} then goto __AP_Move_Right

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved to the right.
   ;
   if !joy0right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the right direction bit.
   ;
   _Bit3_P0_Dir_Right{3} = 1

__AP_Move_Right

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0x >= _P_Edge_Right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player0y)/8

   temp3 = (player0y-8)/8

   temp6 = (player0x-9)/4

   if temp6 < 34 then if pfread(temp6,temp5) then goto __Skip_Joy0_Right

   if temp6 < 34 then if pfread(temp6,temp3) then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 right.
   ;
   player0x = player0x + 1

__Skip_Joy0_Right



   ;***************************************************************
   ;
   ;  Auto-play inactivity check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if auto-play is off.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Inactivity

   ;```````````````````````````````````````````````````````````````
   ;  Sprite gets a new direction if it is sitting still.
   ;
   if _AP_Mem_P0x = player0x && _AP_Mem_P0y = player0y then _AP_Dir_Counter = 254

   ;```````````````````````````````````````````````````````````````
   ;  Remembers sprite position during auto-play.
   ;
   _AP_Mem_P0x = player0x : _AP_Mem_P0y = player0y

__AP_Inactivity



   ;***************************************************************
   ;
   ;  Fire button check.
   ;  
   ;  Turns on missile1 movement if fire button is pressed and
   ;  missile1 is not moving.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if auto-play is off.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Fire_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Determines if sprite should fire during auto-play.
   ;  There is a 90% chance that the missile will not fire.
   ;
   temp5 = rand : if temp5 < 230 then goto __Skip_Fire

   goto __AP_Fire

__AP_Skip_Fire_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and skips this section if fire
   ;  button is not pressed.
   ;
   if !joy0fire then _Bit1_FireB_Restrainer{1} = 0 : goto __Skip_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if fire button hasn't been released since
   ;  the title screen.
   ;
   if _Bit1_FireB_Restrainer{1} then goto __Skip_Fire

__AP_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if missile1 is moving.
   ;
   if _Bit7_M1_Moving{7} then goto __Skip_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Turns on missile1 movement.
   ;
   _Bit7_M1_Moving{7} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Takes a 'snapshot' of player0 direction so missile1 will
   ;  stay on track until it hits something.
   ;
   _Bit4_M1_Dir_Up{4} = _Bit0_P0_Dir_Up{0}
   _Bit5_M1_Dir_Down{5} = _Bit1_P0_Dir_Down{1}
   _Bit6_M1_Dir_Left{6} = _Bit2_P0_Dir_Left{2}
   _Bit7_M1_Dir_Right{7} = _Bit3_P0_Dir_Right{3}

   ;```````````````````````````````````````````````````````````````
   ;  Sets up starting position of missile1.
   ;
   if _Bit4_M1_Dir_Up{4} then missile1x = player0x + 4 : missile1y = player0y - 5
   if _Bit5_M1_Dir_Down{5} then missile1x = player0x + 4 : missile1y = player0y - 1
   if _Bit6_M1_Dir_Left{6} then missile1x = player0x + 2 : missile1y = player0y - 3
   if _Bit7_M1_Dir_Right{7} then missile1x = player0x + 6 : missile1y = player0y - 3

__Skip_Fire



   ;***************************************************************
   ;
   ;  Missile1 movement check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if missile1 isn't moving.
   ;
   if !_Bit7_M1_Moving{7} then goto __Skip_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Moves missile1 in the appropriate direction.
   ;
   if _Bit4_M1_Dir_Up{4} then missile1y = missile1y - 2
   if _Bit5_M1_Dir_Down{5} then missile1y = missile1y + 2
   if _Bit6_M1_Dir_Left{6} then missile1x = missile1x - 2
   if _Bit7_M1_Dir_Right{7} then missile1x = missile1x + 2

   ;```````````````````````````````````````````````````````````````
   ;  Clears missile1 if it hits the edge of the screen.
   ;
   if missile1y < _M_Edge_Top then goto __Delete_Missile
   if missile1y > _M_Edge_Bottom then goto __Delete_Missile
   if missile1x < _M_Edge_Left then goto __Delete_Missile
   if missile1x > _M_Edge_Right then goto __Delete_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Skips rest of section if no collision.
   ;
   if !collision(playfield,missile1) then goto __Skip_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Skips points if auto-play is on.
   ;
   if _Bit3_Auto_Play{3} then goto __Delete_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Adds a point to the score.
   ;
   score = score + 1

__Delete_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Clears Missile1_Moving bit and moves missile1 off screen.
   ;
   _Bit7_M1_Moving{7} = 0 : missile1x = 200 : missile1y = 200

__Skip_Missile



   ;***************************************************************
   ;
   ;  Ends the fake game if player0 touches player1.
   ;
   if collision(player0,player1) then _Bit2_Game_Control{2} = 1



   ;***************************************************************
   ;
   ;  Enemy/missile collision check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if there is no collision.
   ;
   if !collision(player1,missile1) then goto __Skip_Shot_Enemy

   ;```````````````````````````````````````````````````````````````
   ;  Clears missile1 bit and moves missile1 off the screen.
   ;
   _Bit7_M1_Moving{7} = 0 : missile1x = 200 : missile1y = 200

   ;```````````````````````````````````````````````````````````````
   ;  Skips points if auto-play is on.
   ;
   if _Bit3_Auto_Play{3} then goto __AP_Skip_Enemy_Points

   ;```````````````````````````````````````````````````````````````
   ;  Adds 20 points to the score.
   ;
   score = score + 20

__AP_Skip_Enemy_Points

   ;```````````````````````````````````````````````````````````````
   ;  Places enemy in new location based on location of player.
   ;
   player1y = (rand&63) + 15

   if player0x >= 77 then player1x = (rand&7) + 5 : goto __Skip_Shot_Enemy

   player1x = (rand&7) + 140

__Skip_Shot_Enemy



   ;***************************************************************
   ;
   ;  Auto-play score flipper.
   ;
   ;  Flips between high score and current score.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if auto-play bit is not on.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Flip

   ;```````````````````````````````````````````````````````````````
   ;  Increments the auto play 2-second counter.
   ;
   _AP_2_Sec_Score_Flip = _AP_2_Sec_Score_Flip + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if auto play 2-second counter is less
   ;  than 2 seconds (120 = 2 seconds).
   ;
   if _AP_2_Sec_Score_Flip < 120 then goto __AP_Skip_Flip

   ;```````````````````````````````````````````````````````````````
   ;  Clears the 2-second counter and flips the score swapping bit.
   ;
   _AP_2_Sec_Score_Flip = 0 : _Bit6_Swap_Scores{6} = !_Bit6_Swap_Scores{6}

   ;```````````````````````````````````````````````````````````````
   ;  Skips high score swap if swap bit is off.
   ;
   if !_Bit6_Swap_Scores{6} then goto __AP_Skip_HiScore_Swap

   ;```````````````````````````````````````````````````````````````
   ;  Displays high score (blue) and skips rest of section.
   ;
   scorecolor = $AE

   _sc1 = _High_Score1 : _sc2 = _High_Score2 : _sc3 = _High_Score3

   goto __AP_Skip_Flip

__AP_Skip_HiScore_Swap

   ;```````````````````````````````````````````````````````````````
   ;  Displays current score (yellow).
   ;
   scorecolor = $1C

   _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem

__AP_Skip_Flip



   ;***************************************************************
   ;
   ;  Pause check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if auto-play is on.
   ;
   if _Bit3_Auto_Play{3} then goto __AP_Skip_Pause

   ;```````````````````````````````````````````````````````````````
   ;  Checks current position of COLOR/BW switch.
   ;
   _Bit1_BW_Check{1} = 0

   if switchbw then _Bit1_BW_Check{1} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Compares bits to see if COLOR/BW switch has moved.
   ;  The game is paused if the switch has moved.
   ;
   if _Bit0_BW_Mem{0} then if !_Bit1_BW_Check{1} then goto __Pause_Setup bank3

   if !_Bit0_BW_Mem{0} then if _Bit1_BW_Check{1} then goto __Pause_Setup bank3

   ;```````````````````````````````````````````````````````````````
   ;  Pauses game if fire button of second joystick is pressed.
   ;
   if joy1fire && !_Bit1_FireB_Restrainer{1} then goto __Pause_Setup bank3

__AP_Skip_Pause



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Game Over Check
   ;
   ;  _Bit2_Game_Control{2} controls when the game ends.
   ;
   ;  0 = Game not over.
   ;  1 = Game over.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if game control bit is off.
   ;
   if !_Bit2_Game_Control{2} then goto __Skip_Check_G_Over

   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check. Puts score back to current score and jumps
   ;  back to the title screen if auto-play bit is on.
   ;
   if _Bit3_Auto_Play{3} then _Bit2_Game_Control{2} = 0 : _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem : goto __Start_Restart bank1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to game over set up.
   ;
   goto __Game_Over_Setup bank3

__Skip_Check_G_Over



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Reset

   ;```````````````````````````````````````````````````````````````
   ;  Starts game during auto-play if reset switch or fire button
   ;  is pressed. Also clears auto-play bit and sets game control
   ;  bit so game will start instead of going to title screen.
   ;
   if switchreset || joy0fire then _Bit3_Auto_Play{3} = 0 : _Bit2_Game_Control{2} = 1 : goto __Start_Restart bank1

__AP_Skip_Reset

   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Clears the game over bit so the title screen will appear.
   ;
   _Bit2_Game_Control{2} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the game over setup section and checks for a high
   ;  score, then jumps to the title screen.
   ;
   goto __Game_Over_Setup bank3





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   bank 3





   ;***************************************************************
   ;***************************************************************
   ;
   ;  GAME OVER SETUP
   ;
   ;
__Game_Over_Setup


   ;***************************************************************
   ;
   ;  High score check.
   ;
   ;  Checks for a new high score.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Checks first byte.
   ;
   if _sc1 > _High_Score1 then goto __New_High_Score
   if _sc1 < _High_Score1 then goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  First byte equal. Checks second byte.
   ;
   if _sc2 > _High_Score2 then goto __New_High_Score
   if _sc2 < _High_Score2 then goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  Second byte equal. Checks third byte.
   ;
   if _sc3 > _High_Score3 then goto __New_High_Score
   if _sc3 < _High_Score3 then goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  All bytes equal. Skips high score.
   ;
   goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  All bytes not equal. New high score!
   ;
__New_High_Score

   _High_Score1 = _sc1 : _High_Score2 = _sc2 : _High_Score3 = _sc3

__Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the game if the reset switch was pressed. Continues
   ;  in the game over setup section if the game ended naturally.
   ;
   if !_Bit2_Game_Control{2} then goto __Start_Restart bank1


   ;***************************************************************
   ;
   ;  Saves the latest score for the high score flip.
   ;
   _Score1_Mem = _sc1 : _Score2_Mem = _sc2 : _Score3_Mem = _sc3


   ;***************************************************************
   ;
   ;  Clears the counters.
   ;
   _Master_Counter = 0 : _Frame_Counter = 0


   ;***************************************************************
   ;
   ;  Makes sure sprites and missile are off the screen.
   ;
   player0y = 200 : player1y = 200 : missile1y = 200


   ;***************************************************************
   ;
   ;  Restrains reset switch and fire button for game over loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after entering a different segment
   ;  of the program. It also does double duty by restraining the
   ;  fire button in the game over loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets up game over playfield.
   ;
   playfield:
   .XXXXXX.XXXXXX.XXXXXXXXXX.XXXXX.
   .XX.....XX..XX.XX..XX..XX.XX....
   .XX.XXX.XXXXXX.XX..XX..XX.XXXX..
   .XX..XX.XX..XX.XX..XX..XX.XX....
   .XXXXXX.XX..XX.XX..XX..XX.XXXXX.
   ................................
   ...XXXXXX.XX..XX.XXXXX.XXXXXX...
   ...XX..XX.XX..XX.XX....XX..XX...
   ...XX..XX.XX..XX.XXXX..XXXXX....
   ...XX..XX.XX..XX.XX....XX..XX...
   ...XXXXXX...XX...XXXXX.XX..XX...
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  GAME OVER LOOP
   ;
   ;
__Game_Over_Loop



   ;***************************************************************
   ;
   ;  20 second counter.
   ;
   ;  This includes a 2 second countdown timer. Any Atari 2600
   ;  game should disable the fire button for 2 seconds when
   ;  the game is over to keep the player from restarting by
   ;  mistake. It is part of the usual standards and procedures.
   ;
   ;  This section also flips between the current score and the
   ;  high score every 2 seconds. It jumps to the title screen
   ;  after 20 seconds if the player does nothing.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments master counter every frame (60 frames = 1 second).
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if master counter is less than 2 seconds.
   ;  The master counter resets every 2 seconds (60 + 60 = 120).
   ;
   if _Master_Counter < 120 then goto __Skip_20_Second_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Increments frame counter and clears master counter.
   ;  (One increment = 2 seconds.)
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Restores the current score, resets the game, and goes to the
   ;  title screen if 20 seconds have gone by.
   ;
   ;  0 = Go to title screen.
   ;  1 = Skip title screen and play game.
   ;
   if _Frame_Counter > 9 then _Bit2_Game_Control{2} = 0 : _sc1=_Score1_Mem : _sc2=_Score2_Mem : _sc3=_Score3_Mem: goto __Start_Restart bank1

   ;```````````````````````````````````````````````````````````````
   ;  Flips the score swapping bit.
   ;
   _Bit6_Swap_Scores{6} = !_Bit6_Swap_Scores{6}

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to current score if swap bit is off.
   ;
   if !_Bit6_Swap_Scores{6} then goto __GO_Current_Score

   ;```````````````````````````````````````````````````````````````
   ;  Displays high score (blue) and skips rest of section.
   ;
   scorecolor = $AE

   _sc1 = _High_Score1 : _sc2 = _High_Score2 : _sc3 = _High_Score3

   goto __Skip_20_Second_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Displays current score (yellow).
   ;
__GO_Current_Score

   scorecolor = $1C

   _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem

__Skip_20_Second_Counter



   ;***************************************************************
   ;
   ;  Playfield and background colors.
   ;
   ;  Changes colors after 2 seconds. This is only done to let
   ;  you, the programmer, know when 2 seconds have gone by. The
   ;  color change doesn't need to happen in a real game.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if first 2 seconds are over.
   ;
   if _Frame_Counter then goto __Skip_First_Colors

   ;```````````````````````````````````````````````````````````````
   ;  Sets background color for first 2 seconds.
   ;
   COLUBK = $44

   ;```````````````````````````````````````````````````````````````
   ;  Sets playfield color for first 2 seconds.
   ;
   pfcolors:
   $2E
   $2E
   $2C
   $2A
   $28
   $26
   $2E
   $2E
   $2C
   $2A
   $28
   $26
end

   goto __Skip_Second_Colors

__Skip_First_Colors

   ;```````````````````````````````````````````````````````````````
   ;  Sets background color after first 2 seconds.
   ;
   COLUBK = $D2

   ;```````````````````````````````````````````````````````````````
   ;  Sets playfield color after first 2 seconds.
   ;
   pfcolors:
   $DE
   $DE
   $DC
   $DA
   $D8
   $D6
   $DE
   $DE
   $DC
   $DA
   $D8
   $D6
end

__Skip_Second_Colors



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset/fire button check and end of game over loop.
   ;  
   ;  Restarts the program if the reset switch or the fire
   ;  button is pressed appropriately.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the game over loop if the initial
   ;  2 second freeze is not over.
   ;
   if _Frame_Counter = 0 then goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and jumps to beginning of game
   ;  over loop if fire button or reset switch is not pressed.
   ;
   if !switchreset && !joy0fire then _Bit0_Reset_Restrainer{0} = 0 : goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the game over loop if fire button
   ;  hasn't been released since leaving the main loop.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  The program is restarted.
   ;
   goto __Start_Restart bank1





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF GAME OVER LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PAUSE SETUP
   ;
__Pause_Setup


   ;***************************************************************
   ;
   ;  Mutes the sound.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Restrains the fire button for the pause loop.
   ;
   _Bit1_FireB_Restrainer{1} = 1


   ;***************************************************************
   ;
   ;  Clears the pause counter.
   ;
   _Pause_Counter_Tmp = 0


   ;***************************************************************
   ;
   ;  Selects a random color scheme.
   ;
   _Pause_Color_Tmp = (rand&7)

   _Pause_Mem_Color_Tmp = _Pause_Color_Tmp





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PAUSE LOOP
   ;
__Pause_Game



   ;***************************************************************
   ;
   ;  Sets missile1 width.
   ;
   NUSIZ1 = $10



   ;***************************************************************
   ;
   ;  Changes color scheme every 4 seconds.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increases the pause counter.
   ;
   _Pause_Counter_Tmp = _Pause_Counter_Tmp + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if counter isn't high enough.
   ;
   if _Pause_Counter_Tmp < 240 then goto __Skip_Pause_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Resets the pause counter.
   ;
   _Pause_Counter_Tmp = 0

   ;```````````````````````````````````````````````````````````````
   ;  Gets a random number from 0 to 7.
   ;
   _Pause_Color_Tmp = (rand&7)

   ;```````````````````````````````````````````````````````````````
   ;  Compares the new color scheme with the previous color scheme
   ;  and selects a new color scheme if they are the same.
   ;
   if _Pause_Color_Tmp = _Pause_Mem_Color_Tmp then _Pause_Color_Tmp = _Pause_Color_Tmp + (rand&3) + 1 : if _Pause_Color_Tmp > 7 then _Pause_Color_Tmp = _Pause_Color_Tmp - 8

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the new color scheme.
   ;
   _Pause_Mem_Color_Tmp = _Pause_Color_Tmp

   ;```````````````````````````````````````````````````````````````
   ;  Decides if the B color scheme should be used.
   ;
   _Bit2_Pause_Clr_Scheme{2} = 0

    temp5 = rand : if temp5 < 128 then _Bit2_Pause_Clr_Scheme{2} = 1

__Skip_Pause_Counter



   ;***************************************************************
   ;
   ;  Jumps to the latest color scheme.
   ;
   on _Pause_Color_Tmp goto __Ps0 __Ps1 __Ps2 __Ps3 __Ps4 __Ps5 __Ps6 __Ps7

__Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Unpause check and end of pause loop.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the pause loop if the fire button
   ;  isn't pressed. Also clears the restrainer bit.
   ;
   if !joy0fire then _Bit1_FireB_Restrainer{1} = 0 : goto __Pause_Game

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the pause loop if the fire button
   ;  hasn't been released since starting the pause loop.
   ;
   if _Bit1_FireB_Restrainer{1} then goto __Pause_Game

   ;```````````````````````````````````````````````````````````````
   ;  Remembers position of COLOR/BW switch.
   ;
   _Bit0_BW_Mem{0} = 0 : if switchbw then _Bit0_BW_Mem{0} = 1





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF PAUSE LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;  RESTORES GAME FROM PAUSE
   ;
   ;  Puts everything back the way it was.
   ;
__Restore_Game_from_Pause


   ;***************************************************************
   ;
   ;  Restrains the fire button for the main loop.
   ;
   _Bit1_FireB_Restrainer{1} = 1


   ;***************************************************************
   ;
   ;  Restores score color.
   ;
   scorecolor = $1C


   goto __Main_Loop bank2





   ;***************************************************************
   ;
   ;  Sets pause colors to gray.
   ;
__Ps0

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps0B

   pfcolors:
   $0C
   $0C
   $0C
   $0C
   $0C
   $0C
   $0C
   $0C
   $0C
   $0C
   $0C
   $0C
end

   COLUP0 = $0C : COLUP1 = $0C

   COLUBK = $0A

   scorecolor = $0C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to gray.
   ;
__Ps0B

   pfcolors:
   $0A
   $0A
   $0A
   $0A
   $0A
   $0A
   $0A
   $0A
   $0A
   $0A
   $0A
   $0A
end

   COLUP0 = $0A : COLUP1 = $0A

   COLUBK = $0C

   scorecolor = $0A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to reddish-orange.
   ;
__Ps1

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps1B

   pfcolors:
   $3C
   $3C
   $3C
   $3C
   $3C
   $3C
   $3C
   $3C
   $3C
   $3C
   $3C
   $3C
end

   COLUP0 = $3C : COLUP1 = $3C

   COLUBK = $3A

   scorecolor = $3C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to reddish-orange.
   ;
__Ps1B

   pfcolors:
   $3A
   $3A
   $3A
   $3A
   $3A
   $3A
   $3A
   $3A
   $3A
   $3A
   $3A
   $3A
end

   COLUP0 = $3A : COLUP1 = $3A

   COLUBK = $3C

   scorecolor = $3A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to purple.
   ;
__Ps2

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps2B

   pfcolors:
   $6C
   $6C
   $6C
   $6C
   $6C
   $6C
   $6C
   $6C
   $6C
   $6C
   $6C
   $6C
end

   COLUP0 = $6C : COLUP1 = $6C

   COLUBK = $6A

   scorecolor = $6C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to purple.
   ;
__Ps2B

   pfcolors:
   $6A
   $6A
   $6A
   $6A
   $6A
   $6A
   $6A
   $6A
   $6A
   $6A
   $6A
   $6A
end

   COLUP0 = $6A : COLUP1 = $6A

   COLUBK = $6C

   scorecolor = $6A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to blue.
   ;
__Ps3

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps3B

   pfcolors:
   $9C
   $9C
   $9C
   $9C
   $9C
   $9C
   $9C
   $9C
   $9C
   $9C
   $9C
   $9C
end

   COLUP0 = $9C : COLUP1 = $9C

   COLUBK = $9A

   scorecolor = $9C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to blue.
   ;
__Ps3B

   pfcolors:
   $9A
   $9A
   $9A
   $9A
   $9A
   $9A
   $9A
   $9A
   $9A
   $9A
   $9A
   $9A
end

   COLUP0 = $9A : COLUP1 = $9A

   COLUBK = $9C

   scorecolor = $9A


   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to green.
   ;
__Ps4

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps4B

   pfcolors:
   $CC
   $CC
   $CC
   $CC
   $CC
   $CC
   $CC
   $CC
   $CC
   $CC
   $CC
   $CC
end

   COLUP0 = $CC : COLUP1 = $CC

   COLUBK = $CA

   scorecolor = $CC

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to green.
   ;
__Ps4B

   pfcolors:
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
end

   COLUP0 = $CA : COLUP1 = $CA

   COLUBK = $CC

   scorecolor = $CA

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to yellowish.
   ;
__Ps5

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps5B

   pfcolors:
   $FC
   $FC
   $FC
   $FC
   $FC
   $FC
   $FC
   $FC
   $FC
   $FC
   $FC
   $FC
end

   COLUP0 = $FC : COLUP1 = $FC

   COLUBK = $FA

   scorecolor = $FC

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to yellowish.
   ;
__Ps5B

   pfcolors:
   $FA
   $FA
   $FA
   $FA
   $FA
   $FA
   $FA
   $FA
   $FA
   $FA
   $FA
   $FA
end

   COLUP0 = $FA : COLUP1 = $FA

   COLUBK = $FC

   scorecolor = $FA

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to darkish-blue.
   ;
__Ps6

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps6B

   pfcolors:
   $8C
   $8C
   $8C
   $8C
   $8C
   $8C
   $8C
   $8C
   $8C
   $8C
   $8C
   $8C
end

   COLUP0 = $8C : COLUP1 = $8C

   COLUBK = $8A

   scorecolor = $8C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to darkish-blue.
   ;
__Ps6B

   pfcolors:
   $8A
   $8A
   $8A
   $8A
   $8A
   $8A
   $8A
   $8A
   $8A
   $8A
   $8A
   $8A
end

   COLUP0 = $8A : COLUP1 = $8A

   COLUBK = $8C

   scorecolor = $8A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to orange-brown.
   ;
__Ps7

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps7B

   pfcolors:
   $2C
   $2C
   $2C
   $2C
   $2C
   $2C
   $2C
   $2C
   $2C
   $2C
   $2C
   $2C
end

   COLUP0 = $2C : COLUP1 = $2C

   COLUBK = $2A

   scorecolor = $2C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to orange-brown.
   ;
__Ps7B

   pfcolors:
   $2A
   $2A
   $2A
   $2A
   $2A
   $2A
   $2A
   $2A
   $2A
   $2A
   $2A
   $2A
end

   COLUP0 = $2A : COLUP1 = $2A

   COLUBK = $2C

   scorecolor = $2A

   goto __Got_Pause_Colors



   bank 4



   bank 5



   bank 6



   bank 7



   bank 8



   ;***************************************************************
   ;
   ;  Sprite graphics will be placed in the last bank no matter
   ;  where you define them. If you have a lot of graphics, you
   ;  may not have much room here for code. Visual batari Basic
   ;  shows the ROM space you have left under the Messages tab
   ;  whenever you compile a game, so you'll always know the
   ;  remaining ROM space in each bank.
   ;
   ;***************************************************************

 

 

 

8 x 8 World (64 Rooms)

8 x 8 World (64 Rooms) on bB page.

 
   ;***************************************************************
   ;
   ;  8 x 8 World (64 Rooms)
   ;
   ;  Example program by Karl G and adapted by Duane Alan Hahn
   ;  (Random Terrain) using hints, tips, code snippets, and
   ;  more from AtariAge members such as batari, SeaGtGruff,
   ;  RevEng, Robert M, Nukey Shay, Atarius Maximus, jrok,
   ;  supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  About:
   ;  
   ;  This example program uses rand and unrand to generate an
   ;  8 x 8 world of 64 rooms without having to use variables
   ;  to track what type of screen is in what position.
   ;
   ;  Select a seed number using the score by moving the joystick
   ;  up, down, left or right. Leaving the score set to zero will
   ;  cause the program to select a random seed number. The screen
   ;  types will be consistent every time when using the same
   ;  seed number. Press the reset switch to restart the program
   ;  whenever you wish to select another seed number.
   ;
   ;  This 8 x 8 world version tracks whether each screen has been
   ;  visited. An eye icon shows at the bottom of the screen if
   ;  the current screen has been previously visited (using the
   ;  6lives minikernel to display the icon). This uses up 8
   ;  variables, so you may not want to use it in an actual game.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;****************************************************************
   ;
   ;  The kernel option below causes the loss of missile1.
   ; 
   set kernel_options player1colors



   ;***************************************************************
   ;
   ;  This program has 4 banks (16k/4k = 4 banks).
   ;
   set romsize 16k



   ;***************************************************************
   ;
   ;  Random numbers can slow down bankswitched games.
   ;  This will speed things up.
   ;
   set optimization inlinerand



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Which room player is in.
   ;
   dim _XRoom = a
   dim _YRoom = b

   ;```````````````````````````````````````````````````````````````
   ;  Which scene should be used.
   ;
   dim _CurrentScene = c

   ;```````````````````````````````````````````````````````````````
   ;  Title screen slowdown variable.
   ;
   dim _TS_Slowdown = c

   ;```````````````````````````````````````````````````````````````
   ;  The 8 variables below remember any rooms that were visited.
   ;
   dim _VisitedRooms = d
   dim _Row1Visited = e
   dim _Row2Visited = f
   dim _Row3Visited = g
   dim _Row4Visited = h
   dim _Row5Visited = i
   dim _Row6Visited = j
   dim _Row7Visited = k

   ;```````````````````````````````````````````````````````````````
   ;  Temp variable.
   ;
   dim _Temp = l

   ;```````````````````````````````````````````````````````````````
   ;  _Master_Counter can be used for many things, but it is 
   ;  really useful for animating sprite frames when used
   ;  with _Frame_Counter.
   ;
   dim _Master_Counter = m
   dim _Frame_Counter = n

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  All-purpose bits for various jobs.
   ;
   dim _BitOp_01 = o
   dim _Bit0_Reset_Restrainer = o     ; Restrains the reset switch.
   dim _Bit1_Next_Room_Up = o         ; Time for new room.
   dim _Bit2_Next_Room_Down = o       ; Time for new room.
   dim _Bit3_Next_Room_Left = o       ; Time for new room.
   dim _Bit4_Next_Room_Right = o      ; Time for new room.
   dim _Bit5_UD_Joy_Movement = o      ; Up/down joystick movement happened.
   dim _Bit6_LR_Joy_Movement = o      ; Left/Right joystick movement happened.
   dim _Bit7_Over_Under = o           ; Overland or Underland.


   ;```````````````````````````````````````````````````````````````
   ;  Player1 left/right movement.
   ;
   dim _P1_Left_Right = player1x.p

   ;```````````````````````````````````````````````````````````````
   ;  Player1 up/down movement.
   ;
   dim _P1_Up_Down = player1y.q

   ;```````````````````````````````````````````````````````````````
   ;  Special rand used for the rooms.
   ;
   dim _RoomRand = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers.
   ;
   dim rand16 = z

   ;```````````````````````````````````````````````````````````````
   ;  Splits up the score into 3 parts.
   ;
   dim _sc1 = score
   dim _sc2 = score+1
   dim _sc3 = score+2



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for the sprite size used
   ;  in this program. If your sprite is a different size, you'll
   ;  need to adjust the numbers. [The c stands for constant.]
   ;
   const _c_Edge_Top = 10
   const _c_Edge_Bottom = 88
   const _c_Edge_Left = 2
   const _c_Edge_Right = 153



   ;***************************************************************
   ;
   ;  World limit constants. Change these based on world size.
   ;  The default here is 8 x 8 (64 rooms).
   ;  [The c stands for constant.]
   ;
   const _c_World_Limit_Top = 0
   const _c_World_Limit_Bottom = 7
   const _c_World_Limit_Left = 0
   const _c_World_Limit_Right = 7



   ;****************************************************************
   ;
   ;  NTSC colors.
   ;
   ;  Use these constants so you can quickly and easily swap them
   ;  out for PAL-60 colors. Or use this if you created a PAL-60
   ;  game and want to instantly convert the colors to NTSC (if you
   ;  were already using the PAL-60 constants).
   ;
   const _00 = $00
   const _02 = $02
   const _04 = $04
   const _06 = $06
   const _08 = $08
   const _0A = $0A
   const _0C = $0C
   const _0E = $0E
   const _10 = $10
   const _12 = $12
   const _14 = $14
   const _16 = $16
   const _18 = $18
   const _1A = $1A
   const _1C = $1C
   const _1E = $1E
   const _20 = $20
   const _22 = $22
   const _24 = $24
   const _26 = $26
   const _28 = $28
   const _2A = $2A
   const _2C = $2C
   const _2E = $2E
   const _30 = $30
   const _32 = $32
   const _34 = $34
   const _36 = $36
   const _38 = $38
   const _3A = $3A
   const _3C = $3C
   const _3E = $3E
   const _40 = $40
   const _42 = $42
   const _44 = $44
   const _46 = $46
   const _48 = $48
   const _4A = $4A
   const _4C = $4C
   const _4E = $4E
   const _50 = $50
   const _52 = $52
   const _54 = $54
   const _56 = $56
   const _58 = $58
   const _5A = $5A
   const _5C = $5C
   const _5E = $5E
   const _60 = $60
   const _62 = $62
   const _64 = $64
   const _66 = $66
   const _68 = $68
   const _6A = $6A
   const _6C = $6C
   const _6E = $6E
   const _70 = $70
   const _72 = $72
   const _74 = $74
   const _76 = $76
   const _78 = $78
   const _7A = $7A
   const _7C = $7C
   const _7E = $7E
   const _80 = $80
   const _82 = $82
   const _84 = $84
   const _86 = $86
   const _88 = $88
   const _8A = $8A
   const _8C = $8C
   const _8E = $8E
   const _90 = $90
   const _92 = $92
   const _94 = $94
   const _96 = $96
   const _98 = $98
   const _9A = $9A
   const _9C = $9C
   const _9E = $9E
   const _A0 = $A0
   const _A2 = $A2
   const _A4 = $A4
   const _A6 = $A6
   const _A8 = $A8
   const _AA = $AA
   const _AC = $AC
   const _AE = $AE
   const _B0 = $B0
   const _B2 = $B2
   const _B4 = $B4
   const _B6 = $B6
   const _B8 = $B8
   const _BA = $BA
   const _BC = $BC
   const _BE = $BE
   const _C0 = $C0
   const _C2 = $C2
   const _C4 = $C4
   const _C6 = $C6
   const _C8 = $C8
   const _CA = $CA
   const _CC = $CC
   const _CE = $CE
   const _D0 = $D0
   const _D2 = $D2
   const _D4 = $D4
   const _D6 = $D6
   const _D8 = $D8
   const _DA = $DA
   const _DC = $DC
   const _DE = $DE
   const _E0 = $E0
   const _E2 = $E2
   const _E4 = $E4
   const _E6 = $E6
   const _E8 = $E8
   const _EA = $EA
   const _EC = $EC
   const _EE = $EE
   const _F0 = $F0
   const _F2 = $F2
   const _F4 = $F4
   const _F6 = $F6
   const _F8 = $F8
   const _FA = $FA
   const _FC = $FC
   const _FE = $FE





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Makes sure sprites are off screen.
   ;
   player1y = 150 : player0y = 150


   ;***************************************************************
   ;
   ;  Sets color and shape of life counter.
   ;
   lifecolor = _8A : lives = 0

   lives:
   %00000000
   %00011000
   %00100100
   %01011010
   %10011001
   %01011010
   %00100100
   %00011000
end


   ;***************************************************************
   ;
   ;  Clears most normal variables.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0





   ;***************************************************************
   ;***************************************************************
   ;
   ;   TITLE SCREEN SETUP
   ;
   ;
__Title_Screen_Setup


   ;***************************************************************
   ;
   ;  Sets score color for title screen.
   ;
   scorecolor = _1C


   ;***************************************************************
   ;
   ;  Sets score and tracker variable.
   ;
   score = 0 : _RoomRand = 0


   ;***************************************************************
   ;
   ;  Sets title screen background color.
   ;
   COLUBK = _00


   ;***************************************************************
   ;
   ;  Sets title screen playfield pixel colors.
   ;
   COLUPF = _08


   ;***************************************************************
   ;
   ;  Restrains the reset switch.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after entering a different segment
   ;  of the program. It also does double duty by restraining the
   ;  fire button in the title screen loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets up title screen playfield.
   ;
   playfield:
   .XXXXX.XXXX.XX...XXXX.XXXX.XXXX.
   .XX....XX...XX...XX...XX....XX..
   .XXXXX.XXXX.XX...XXXX.XX....XX..
   ....XX.XX...XX...XX...XX....XX..
   .XXXXX.XXXX.XXXX.XXXX.XXXX..XX..
   ................................
   XXXXX.XXXX.XXXX.XXXXX....XX.XX..
   XX....XX...XX...XX..XX..XXXXXXX.
   XXXXX.XXXX.XXXX.XX..XX...XX.XX..
   ...XX.XX...XX...XX..XX..XXXXXXX.
   XXXXX.XXXX.XXXX.XXXXX....XX.XX..
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  TITLE SCREEN LOOP
   ;
   ;
__Title_Screen_Loop



   ;***************************************************************
   ;
   ;  Controls seed number selection speed.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments the master counter.
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips section if master counter is less than _TS_Slowdown.
   ;
   if _Master_Counter < _TS_Slowdown then goto __Skip_TS_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Number seed selection for rooms using joystick.
   ;
   if joy0right && _RoomRand < 255 then score = score + 1 : _RoomRand = _RoomRand + 1 : _TS_Slowdown = 11
   if joy0left && _RoomRand > 0 then score = score - 1 : _RoomRand = _RoomRand - 1 : _TS_Slowdown = 11
   if joy0up && _RoomRand < 255 then score = score + 1 : _RoomRand = _RoomRand + 1 : _TS_Slowdown = 2
   if joy0down && _RoomRand > 0 then score = score - 1 : _RoomRand = _RoomRand - 1 : _TS_Slowdown = 2

   ;```````````````````````````````````````````````````````````````
   ;  Clears master counter.
   ;
   _Master_Counter = 0

__Skip_TS_Counter



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset/fire button check and end of title screen loop.
   ;  
   ;  Starts the game if the reset switch or the fire button
   ;  is pressed appropriately.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and jumps to beginning of title 
   ;  screen loop if fire button or reset switch is not pressed.
   ;
   if !switchreset && !joy0fire then _Bit0_Reset_Restrainer{0} = 0 : goto __Title_Screen_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of title screen loop if reset or fire 
   ;  hasn't been released since starting title screen loop.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Title_Screen_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Continues to main loop setup if fire button or reset pressed.
   ;
   goto __Main_Loop_Setup





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP SETUP
   ;
   ;
__Main_Loop_Setup


   ;***************************************************************
   ;
   ;  Sets starting position of player's sprite.
   ;
   player1x = 17 : player1y = 15


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Selects a random world if _RoomRand is zero.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips if _RoomRand is greater than 0.
   ;
   if _RoomRand then goto __Skip_Rand_World

   ;```````````````````````````````````````````````````````````````
   ;  Makes _RoomRand a random number.
   ;
   _RoomRand = rand : if !_RoomRand then _RoomRand = 1

   ;```````````````````````````````````````````````````````````````
   ;  Puts the world number in the score.
   ;
   temp4 = _RoomRand

   _sc2 = _sc2 & 240 : _sc3 = 0
   if temp4 >= 100 then _sc2 = _sc2 + 1 : temp4 = temp4 - 100
   if temp4 >= 100 then _sc2 = _sc2 + 1 : temp4 = temp4 - 100
   if temp4 >= 50 then _sc3 = _sc3 + 80 : temp4 = temp4 - 50
   if temp4 >= 30 then _sc3 = _sc3 + 48 : temp4 = temp4 - 30
   if temp4 >= 20 then _sc3 = _sc3 + 32 : temp4 = temp4 - 20
   if temp4 >= 10 then _sc3 = _sc3 + 16 : temp4 = temp4 - 10
   _sc3 = _sc3 | temp4

__Skip_Rand_World


   ;***************************************************************
   ;
   ;  Jumps to get special starting random number for rooms.
   ;
   goto __Special_Rand bank2





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Main counters.
   ;
   ;  Controls animation speed.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments the master counter.
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips section if master counter is less than 5.
   ;
   if _Master_Counter < 5 then goto __Skip_Frame_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Increments frame counter.
   ;
   _Frame_Counter = _Frame_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Clears master counter.
   ;
   _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Clears frame counter when it's time.
   ;
   if _Frame_Counter = 4 then _Frame_Counter = 0

__Skip_Frame_Counter



   ;***************************************************************
   ;
   ;  Clears joystick movement bits and next room bits.
   ;
   _Bit5_UD_Joy_Movement{5} = 0 : _Bit6_LR_Joy_Movement{6} = 0 : _Bit1_Next_Room_Up{1} = 0 : _Bit2_Next_Room_Down{2} = 0 : _Bit3_Next_Room_Left{3} = 0 : _Bit4_Next_Room_Right{4} = 0



   ;***************************************************************
   ;
   ;  Default standing still position for player1 sprite.
   ;
   player1color:
   _26
   _9C
   _9C
   _9C
   _DA
   _DA
   _3C
   _3C
   _3C
   _26
end

   player1:
   %01100110
   %00100100
   %00111100
   %00011000
   %01011010
   %00111100
   %00011000
   %00111100
   %00111100
   %00011000
end



   ;***************************************************************
   ;
   ;  Up movement section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Up: Skips this section if joystick not moved up.
   ;
   if !joy0up then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Up: Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player1x-11)/4

   temp6 = (player1y-11)/8

   if temp5 < 32 then if pfread(temp5,temp6) then goto __Skip_Joy0_Up

   temp4 = (player1x-16)/4

   if temp4 < 32 then if pfread(temp4,temp6) then goto __Skip_Joy0_Up

   temp3 = temp5 - 1

   if temp3 < 32 then if pfread(temp3,temp6) then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Up: Turns on up/down movement bit.
   ;
   _Bit5_UD_Joy_Movement{5} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Up: Moves player1 up.
   ;
   _P1_Up_Down = _P1_Up_Down - 1.18

   ;```````````````````````````````````````````````````````````````
   ;  Up: Sprite color for up movement.
   ;
   player1color:
   _26
   _9C
   _9C
   _9C
   _DA
   _DA
   _3C
   _26
   _26
   _26
end

   ;```````````````````````````````````````````````````````````````
   ;  Up: Skips if player hasn't gone past top edge.
   ;
   if player1y >= _c_Edge_Top then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Up: Keeps player within the world.
   ;
   if _YRoom = _c_World_Limit_Top then player1y = _c_Edge_Top : goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Up: Moves player to bottom of screen for the next room.
   ;
   player1y = _c_Edge_Bottom

   ;```````````````````````````````````````````````````````````````
   ;  Up: Moves player to next room above.
   ;
   _YRoom = _YRoom - 1

   _Bit1_Next_Room_Up{1} = 1

__Skip_Joy0_Up



   ;***************************************************************
   ;
   ;  Down movement section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Down: Skips this section if joystick not moved up.
   ;
   if !joy0down then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Down: Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player1x-11)/4

   temp6 = (player1y+1)/8

   if temp5 < 32 then if pfread(temp5,temp6) then goto __Skip_Joy0_Down

   temp4 = (player1x-16)/4

   if temp4 < 32 then if pfread(temp4,temp6) then goto __Skip_Joy0_Down

   temp3 = temp5 - 1

   if temp3 < 32 then if pfread(temp3,temp6) then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Down: Turns on up/down movement bit.
   ;
   _Bit5_UD_Joy_Movement{5} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Down: Moves player1 down.
   ;
   _P1_Up_Down = _P1_Up_Down + 1.18

   ;```````````````````````````````````````````````````````````````
   ;  Down: Skips if player hasn't gone past bottom edge.
   ;
   if player1y <= _c_Edge_Bottom then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Down: Keeps player within the world.
   ;
   if _YRoom = _c_World_Limit_Bottom then player1y = _c_Edge_Bottom : goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Down: Moves player to top of screen for the next room.
   ;
   player1y = _c_Edge_Top

   ;```````````````````````````````````````````````````````````````
   ;  Down: Moves player to next room below.
   ;
   _YRoom = _YRoom + 1

   _Bit2_Next_Room_Down{2} = 1

__Skip_Joy0_Down



   ;***************************************************************
   ;
   ;  Left movement section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Left: Skips this section if joystick not moved left.
   ;
   if !joy0left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Left: Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player1y-1)/8

   temp6 = (player1x-18)/4

   if temp6 < 32 then if pfread(temp6,temp5) then goto __Skip_Joy0_Left

   temp3 = (player1y-9)/8

   if temp6 < 32 then if pfread(temp6,temp3) then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Left: Turns on left/right movement bit.
   ;
   _Bit6_LR_Joy_Movement{6} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Left: Moves player1 left.
   ;
   _P1_Left_Right = _P1_Left_Right - 1.48

   ;```````````````````````````````````````````````````````````````
   ;  Left: Makes sure player1 sprite is facing the correct direction.
   ;
   REFP1 = 0

   ;```````````````````````````````````````````````````````````````
   ;  Left: Skips if player hasn't gone past left edge.
   ;
   if player1x >= _c_Edge_Left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Left: Keeps player within the world.
   ;
   if _XRoom = _c_World_Limit_Left then player1x = _c_Edge_Left : goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Left: Skips if player already moved up to next room.
   ;
   if _Bit1_Next_Room_Up{1} then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Left: Moves player to right edge of screen for the next room.
   ;
   player1x = _c_Edge_Right

   ;```````````````````````````````````````````````````````````````
   ;  Left: Moves player to next room on the left.
   ;
   _XRoom = _XRoom - 1

   _Bit3_Next_Room_Left{3} = 1

__Skip_Joy0_Left



   ;***************************************************************
   ;
   ;  Right movement section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Right: Skips this section if joystick not moved right.
   ;
   if !joy0right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Right: Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player1y-1)/8

   temp6 = (player1x-9)/4

   if temp6 < 32 then if pfread(temp6,temp5) then goto __Skip_Joy0_Right

   temp3 = (player1y-9)/8

   if temp6 < 32 then if pfread(temp6,temp3) then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Right: Turns on right movement bit.
   ;
   _Bit6_LR_Joy_Movement{6} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Right: Moves player1 right.
   ;
   _P1_Left_Right = _P1_Left_Right + 1.48

   ;```````````````````````````````````````````````````````````````
   ;  Right: Makes sure player1 sprite is facing the correct direction.
   ;
   REFP1 = 8

   ;```````````````````````````````````````````````````````````````
   ;  Right: Skips if player hasn't gone past left edge.
   ;
   if player1x <= _c_Edge_Right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Right: Keeps player within the world.
   ;
   if _XRoom = _c_World_Limit_Right then player1x = _c_Edge_Right : goto __Skip_Joy0_Right
   
   ;```````````````````````````````````````````````````````````````
   ;  Right: Skips if player already moved down to next room.
   ;
   if _Bit2_Next_Room_Down{2} then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Right: Moves player to left edge of screen for the next room.
   ;
   player1x = _c_Edge_Left

   ;```````````````````````````````````````````````````````````````
   ;  Right: Moves player to next room on the right.
   ;
   _XRoom = _XRoom + 1

   _Bit4_Next_Room_Right{4} = 1

__Skip_Joy0_Right



   ;***************************************************************
   ;
   ;  Up/down walking animation section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips animation if joystick not moved up or down.
   ;
   if !_Bit5_UD_Joy_Movement{5} then goto __Done_UD_Anim

   ;```````````````````````````````````````````````````````````````
   ;  Animates player1 sprite for up/down movement.
   ;
   on _Frame_Counter goto __FrameD0 __FrameD1 __FrameD2 __FrameD3

__Done_UD_Anim



   ;***************************************************************
   ;
   ;  Left/right walking animation section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips animation if joystick not moved left or right.
   ;
   if !_Bit6_LR_Joy_Movement{6} then goto __Done_LR_Anim

   ;```````````````````````````````````````````````````````````````
   ;  Sets player1 left/right color.
   ;
   player1color:
   _26
   _9C
   _9C
   _9C
   _DA
   _DA
   _3C
   _3C
   _3C
   _26
end

   ;```````````````````````````````````````````````````````````````
   ;  Animates player1 sprite for left/right movement.
   ;
   on _Frame_Counter goto __FrameLR0 __FrameLR1 __FrameLR2 __FrameLR3

__Done_LR_Anim



   ;```````````````````````````````````````````````````````````````
   ;
   ;  MORE CODE CAN GO HERE.
   ;
   ;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''



   ;***************************************************************
   ;
   ;  Continues program in Bank 2.
   ;
   goto __Continue_in_Bank_2 bank2





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Left/right animation frames for player1.
   ;
__FrameLR0
   player1:
   %01100110
   %01100110
   %00111100
   %00001100
   %00111100
   %00011100
   %00011000
   %00111100
   %00111100
   %00011000
end

   goto __Done_LR_Anim


__FrameLR1
   player1:
   %11000011
   %01100011
   %00111110
   %00011100
   %00111100
   %01011110
   %00011000
   %00111100
   %00111100
   %00011000
end

   goto __Done_LR_Anim


__FrameLR2
   player1:
   %00110110
   %00110110
   %00011100
   %00001100
   %00111100
   %00011100
   %00011000
   %00111100
   %00111100
   %00011000
end

   goto __Done_LR_Anim


__FrameLR3
   player1:
   %00111100
   %00011100
   %00011100
   %00000100
   %00011100
   %00011100
   %00011000
   %00111100
   %00111100
   %00011000
end

   goto __Done_LR_Anim



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Up/down animation frames for player1.
   ;
__FrameD0
   player1:
   %01100110
   %00100100
   %00011100
   %00011000
   %01111010
   %00111100
   %00011000
   %00111100
   %00111100
   %00011000
end

   goto __Done_UD_Anim
__FrameD1
   player1:
   %01100000
   %00100110
   %00111100
   %00011000
   %00111110
   %00111110
   %00011000
   %00111100
   %00111100
   %00011000
end

   goto __Done_UD_Anim


__FrameD2
   player1:
   %01100110
   %00100100
   %00111000
   %00011000
   %01011110
   %00111100
   %00011000
   %00111100
   %00111100
   %00011000
end

   goto __Done_UD_Anim


__FrameD3
   player1:
   %00000110
   %01100100
   %00111100
   %00011000
   %01111100
   %01111100
   %00011000
   %00111100
   %00111100
   %00011000
end

   goto __Done_UD_Anim





   bank 2





__Continue_in_Bank_2



   ;```````````````````````````````````````````````````````````````
   ;
   ;  MORE CODE CAN GO HERE.
   ;
   ;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''



   ;***************************************************************
   ;
   ;  Displays next room when it's time.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if next room bits are off.
   ;
   if !_Bit1_Next_Room_Up{1} && !_Bit2_Next_Room_Down{2} && !_Bit3_Next_Room_Left{3} && !_Bit4_Next_Room_Right{4} then goto __Done_Next_Room

   ;```````````````````````````````````````````````````````````````
   ;  Skips bBRand section if player didn't move right or down.
   ;
   if !_Bit4_Next_Room_Right{4} && !_Bit2_Next_Room_Down{2} then goto __Skip_bBRand

__Special_Rand

   _Temp = 0

   ;```````````````````````````````````````````````````````````````
   ;  Special Rand for rooms.
   ;
__bBRand
   asm
   lda _RoomRand
   lsr
   bcc __bB_Rand_no_eor
   eor #$B4
__bB_Rand_no_eor
   sta _RoomRand
end

   ;```````````````````````````````````````````````````````````````
   ;  Loops if player moves down to next room.
   ;
   if _Bit2_Next_Room_Down{2} then _Temp = _Temp + 1 : if _Temp <= _c_World_Limit_Right then goto __bBRand

   ;```````````````````````````````````````````````````````````````
   ;  Sets current scene variable.
   ;
   _CurrentScene = _RoomRand

__Skip_bBRand

   ;```````````````````````````````````````````````````````````````
   ;  Skips UnRand section if player didn't move up or left.
   ;
   if !_Bit1_Next_Room_Up{1} && !_Bit3_Next_Room_Left{3} then goto __Skip_UnRand

   _Temp = 0

   ;```````````````````````````````````````````````````````````````
   ;  Special UnRand for rooms.
   ;
__UnRand
   asm
   LDA _RoomRand
   ASL
   BCC __UnRand_no_eor
   EOR #$69
__UnRand_no_eor:
   STA _RoomRand
   STA _CurrentScene
end

   ;```````````````````````````````````````````````````````````````
   ;  Loops if player moves up to next room.
   ;
   if _Bit1_Next_Room_Up{1} then _Temp = _Temp + 1 : if _Temp <= _c_World_Limit_Right then goto __UnRand

__Skip_UnRand

   ;```````````````````````````````````````````````````````````````
   ;  Limits the current scene.
   ;
   _CurrentScene = (_CurrentScene&31)

   ;```````````````````````````````````````````````````````````````
   ;  Checks visited room.
   ;
   _Temp = _VisitedRooms[_YRoom]
   temp5 = _Data_Number_to_Bit[_XRoom]
   _Temp = (_Temp&temp5)

   ;```````````````````````````````````````````````````````````````
   ;  Displays or removes lives icon.
   ;
   if _Temp && lives < 32 then lives = lives + 32
   if !_Temp && lives >= 32 then lives = lives - 32

   ;```````````````````````````````````````````````````````````````
   ;  Sets visited room.
   ;
   _Temp = _VisitedRooms[_YRoom]
   temp5 = _Data_Number_to_Bit[_XRoom]
   _VisitedRooms[_YRoom] = (_Temp|temp5)

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the where current scene is drawn.
   ;
   goto __Set_Current_Scene

__Done_Next_Room



   ;```````````````````````````````````````````````````````````````
   ;
   ;  MORE CODE CAN GO HERE.
   ;
   ;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Continues program in Bank 3.
   ;
   goto __Continue_in_Bank_3 bank3





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sets the colors and playfield design of the current room.
   ;
__Set_Current_Scene
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Sets the playfield background and foreground color.
   ;
   COLUBK = _Data_Background_Color[_CurrentScene]
   COLUPF = _Data_Foreground_Color[_CurrentScene]

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the current scene to be displayed.
   ;
   on _CurrentScene goto __s0 __s1 __s2 __s3 __s4 __s5 __s6 __s7 __s8 __s9 __sA __sB __sC __sD __sE __sF __sG __sH __sI __sJ __sK __sL __sM __sN __sO __sP __sQ __sR __sS __sT __sU __sV


__s0
   playfield:
   ................................
   ................................
   ..............X.................
   .............XXX.......X........
   ............XXXXX.....XXX.......
   ......X..............XXXXX......
   .....XXX............XXXXXXX.....
   ....XXXXX..........XXXXXXXXX....
   ...XXXXXXX......................
   ................................
   ................................
end

   goto __Done_Next_Room

   
__s1
   playfield:
   ................................
   ................................
   ....XXXX...XXXXXXXXXX...XXXX....
   ................................
   ................................
   ....XXXXXXXXXXXXXXXXXXXXXXXX....
   ................................
   ................................
   ....XXXX...XXXXXXXXXX...XXXX....
   ................................
   ................................
end

   goto __Done_Next_Room

   
__s2
   playfield:
   ................................
   ................................
   .......XXX............XXX.......
   ......XXXXX..........XXXXX......
   .......XXX............XXX.......
   ................................
   ..............XXXX..............
   .............XXXXXX.............
   ..............XXXX..............
   ................................
   ................................
end

   goto __Done_Next_Room


__s3
   playfield:
   ................................
   ................................
   ....XXXXX...XXXXXXX...XXXXXX....
   ....XXXXX...XXXXXXX...XXXXXX....
   ................................
   ................................
   ................................
   ....XXXXX...XXXXXXX...XXXXXX....
   ....XXXXX...XXXXXXX...XXXXXX....
   ................................
   ................................
end

   goto __Done_Next_Room


__s4
   playfield:
   ................................
   ................................
   ...............X................
   ..............XXX...............
   .............XXXXX..............
   ...........XXXXXXXXX............
   .........XXXXXXXXXXXXX..........
   .......XXXXXXXXXXXXXXXXX........
   .....XXXXXXXXXXXXXXXXXXXXX......
   ................................
   ................................
end

   goto __Done_Next_Room


__s5
   playfield:
   ................................
   ................................
   ....X.....X.....................
   ...XXX...XXX.........X..........
   ....X.....X.........XXX.........
   .....................X..........
   ...............X..........X.....
   ..............XXX........XXX....
   ...............X..........X.....
   ................................
   ................................
end

   goto __Done_Next_Room


__s6
   playfield:
   ................................
   ................................
   ............XX....XX............
   ............XX....XX............
   ....XXXXXX............XXXXXX....
   ....XXXXXX............XXXXXX....
   ....XXXXXX............XXXXXX....
   ............XX....XX............
   ............XX....XX............
   ................................
   ................................
end

   goto __Done_Next_Room


__s7
   playfield:
   ................................
   ................................
   ................XXXXXXXX........
   ..........XXXXXXXXXXXXXXX.......
   .........XXXXXXXXXXXXXX.........
   ........XXXXXXXXXXXXXXX.........
   ........XXXXXXXXXXXXXXXXXX......
   .........XXXXXXXXXXXXXXXXX......
   ............XXXXX..XXXXXX.......
   ................................
   ................................
end

   goto __Done_Next_Room


__s8
   playfield:
   ................................
   ................................
   ........XXXXXXXXX........X......
   ......XXXXXXXXXXXX......XXX.....
   .....XXXXXXXXXXXXX.....XXXXX....
   .....XXXXXXXXXXXX.....XXXXXXX...
   ......XX..XXXXXXX........X......
   ......XX..XXXXXX.........X......
   ................................
   ................................
   ................................
end

   goto __Done_Next_Room


__s9
   playfield:
   ................................
   ................................
   ................................
   .....XXX........................
   ....XXXXX...........XXX.........
   ....XXXXX..........XXXXX........
   .....XXX...........XXXXX........
   ....................XXX.........
   ................................
   ................................
   ................................
end

   goto __Done_Next_Room


__sA
   playfield:
   ................................
   ................................
   ....XXXXXX..XXXXXXXX..XXXXXX....
   ....XX....................XX....
   ....XX....................XX....
   ................................
   ................................
   ....XX....................XX....
   ....XXXXXX..XXXXXXXX..XXXXXX....
   ................................
   ................................
end
   goto __Done_Next_Room


__sB
   playfield:
   ................................
   ................................
   .......XXXX.....................
   .....XXXXXXXX...................
   ...XXXXXXXXXXXX.................
   .....XXXXXXXX...................
   .......XXXX............XXX......
   ......................XXXXX.....
   .......................XXX......
   ................................
   ................................
end

   goto __Done_Next_Room


__sC
   playfield:
   ................................
   ................................
   ......XXX...XXXXXXXX...XXX......
   ....XXXXXX....XXXX....XXXXXX....
   ...XXXXXXX....XXXX....XXXXXXX...
   ...XXXXXX.....XXXX.....XXXXXX...
   ....XXXX......XXXX......XXXX....
   ....XXX.....XXXXXXXX.....XXX....
   ....XXXX...XXXXXXXXXX...XXXX....
   ................................
   ................................
end

   goto __Done_Next_Room


__sD
   playfield:
   ................................
   ................................
   ..........XXXXXXXXXXXX..........
   ........XXXXXXXXXXXXXXXX........
   ........XXXXXXXXXXXXXXXX........
   ........XXXXXXXXXXXXXXXX........
   ........XXXXXXXXXXXXXXXX........
   ........XXXXXXXXXX..XXXX........
   ..........XXXXXXXX..XXX.........
   ................................
   ................................
end

   goto __Done_Next_Room


__sE
   playfield:
   ................................
   ................................
   ....XXXXXXXXXX....XXXXXXXXXX....
   ....XX....................XX....
   ....XX....................XX....
   ....XX....................XX....
   ............XXX..XXX............
   ............XXX..XXX............
   ....XXXXXX..XXX..XXX..XXXXXX....
   ................................
   ................................
end

   goto __Done_Next_Room


__sF
   playfield:
   ................................
   ................................
   ..........XXXXXXX...............
   .........XXXXXXXXXX.............
   .......XXXXXXXXXXXXXX...........
   ......XXXXXXXXXXXXXXX...........
   .......XXXXXXXXXXXXX............
   ..........XXXXXXX...............
   ................................
   ................................
   ................................
end

   goto __Done_Next_Room


__sG
   playfield:
   ................................
   ................................
   ....XXXX................XXXX....
   ....XXXX................XXXX....
   ....XXXX................XXXX....
   ....XXXXXXXXX......XXXXXXXXX....
   ................................
   ................................
   ....XXXXXXXXX......XXXXXXXXX....
   ................................
   ................................
end

   goto __Done_Next_Room


__sH
   playfield:
   ................................
   ................................
   ...XXXXXXX......................
   ....XXXXX..........XXXXXXXXX....
   .....XXX............XXXXXXX.....
   ......X..............XXXXX......
   ............XXXXX.....XXX.......
   .............XXX.......X........
   ..............X.................
   ................................
   ................................
end

   goto __Done_Next_Room


__sI
   playfield:
   ................................
   ................................
   ....XXXXX..XX..XX..XX..XXXXX....
   ....XXXXX..XX..XX..XX..XXXXX....
   ....XXXXX..XX..XX..XX..XXXXX....
   ....XXXXX..XX..XX..XX..XXXXX....
   ...........XX..XX..XX...........
   ...........XX..XX..XX...........
   ....XXXXXXXXX..XX..XXXXXXXXX....
   ................................
   ................................
end

   goto __Done_Next_Room


__sJ
   playfield:
   ................................
   ................................
   ...................XX...........
   ..................XXXX..........
   .................XXXXXX.........
   ......XX.........XX..XX.........
   .....XXXX.......................
   ....XXXXXX......................
   ....XX..XX......................
   ................................
   ................................
end

   goto __Done_Next_Room


__sK
   playfield:
   ................................
   ................................
   ..............XXX...............
   .............XXXXX..............
   ..............XXX...............
   ................................
   .......XXX...........XXX........
   ......XXXXX.........XXXXX.......
   .......XXX...........XXX........
   ................................
   ................................
end

   goto __Done_Next_Room


__sL
   playfield:
   ................................
   ................................
   .....XX..XXXXXXXXXXXXXXXXXX.....
   .....XX..XX.....................
   .....XX..XX.....................
   .....XX..XX...XXXXXXXXXXXXX.....
   .....XX..XX...XX.........XX.....
   .....XX..XX...XX.........XX.....
   .....XX..XX...XX..XXXXX..XX.....
   ................................
   ................................
end

   goto __Done_Next_Room


__sM
   playfield:
   ................................
   ................................
   .......XXXXXXXXXX...............
   .....XXXXXXXXXXXXX..............
   .....XXXXXXXXXXXXX..............
   .....XXXXXXXXXXXXX..............
   .....XXX..XXXXXXXX.......XXX....
   ......XX..XXXXXXX........XXX....
   ................................
   ................................
   ................................
end


   goto __Done_Next_Room


__sN
   playfield:
   ................................
   ................................
   ......X.........XXXXXXX.........
   .....XXX......XXXXXXXXXXX.......
   ....XXXXX.....XXXXXXXXXXXX......
   ...XXXXXXX....XXXXXXXXXXXX......
   ......X.......XXX..XXXXXXX......
   ......X........XX..XXXXXX.......
   ................................
   ................................
   ................................
end

   goto __Done_Next_Room


__sO
   playfield:
   ................................
   ................................
   ..................XXXXX.........
   ..................XXXXXXX.......
   ...................XXXXX........
   ................................
   .........XXXXX..................
   .......XXXXXXX..................
   ........XXXXX...................
   ................................
   ................................
end

   goto __Done_Next_Room


__sP
   playfield:
   ................................
   ................................
   .....XXXXXXXXXXXXXXXXXXXXXX.....
   .....XXX................XXX.....
   .....XXX................XXX.....
   .....XXX..XXXXXXXXXXXX..XXX.....
   .....XXX..XXXXXXXXXXXX..XXX.....
   .....XXX..XXXXXXXXXXXX..XXX.....
   ................................
   ................................
   ................................
end

   goto __Done_Next_Room


__sQ
   playfield:
   ................................
   ................................
   .........XXX........XXX.........
   .......XXXXXXX....XXXXXXX.......
   ................................
   ................................
   ................................
   .......XXXXXXX....XXXXXXX.......
   .........XXX........XXX.........
   ................................
   ................................
end

   goto __Done_Next_Room


__sR
   playfield:
   ................................
   ................................
   .....XXXXXXXXXX..XXXX..XXXX.....
   .....XXXXXXXXXX..XXXX..XXXX.....
   .................XXXX..XXXX.....
   .................XXXX..XXXX.....
   .....XXXXXXXXXX..XXXX..XXXX.....
   .....XXXXXXXXXX..XXXX..XXXX.....
   ................................
   ................................
   ................................
end

   goto __Done_Next_Room


__sS
   playfield:
   ................................
   ................................
   ............XXX..XXX............
   ..........XXXXX..XXXXX..........
   ................................
   ................................
   ................................
   ..........XXXXX..XXXXX..........
   ............XXX..XXX............
   ................................
   ................................
end

   goto __Done_Next_Room


__sT
   playfield:
   ................................
   ................................
   .....XXX..XXXX....XXXX..XXX.....
   .....XXX..XXXXXXXXXXXX..XXX.....
   ................................
   ................................
   .....XXX..XXXXXXXXXXXX..XXX.....
   .....XXX..XXXX....XXXX..XXX.....
   .....XXX..XXXX....XXXX..XXX.....
   ................................
   ................................
end

   goto __Done_Next_Room


__sU
   playfield:
   ................................
   ................................
   ............XXX..XXX............
   ..........XXXXX..XXXXX..........
   .........XXXXXX..XXXXXX.........
   ........XXXXXXX..XXXXXXX........
   .........XXXXXX..XXXXXX.........
   ..........XXXXX..XXXXX..........
   ............XXX..XXX............
   ................................
   ................................
end

   goto __Done_Next_Room


__sV
   playfield:
   ................................
   ................................
   .....XXXXXXXXX....XXXXXXXXX.....
   .....XXXXXXXXX....XXXXXXXXX.....
   .....XXXX..............XXXX.....
   ................................
   ...........XXX....XXX...........
   ...........XXX....XXX...........
   .....XXXXXXXXX....XXXXXXXXX.....
   ................................
   ................................
end

   goto __Done_Next_Room





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Playfield background color data.
   ;
   data _Data_Background_Color
   _20
   _30
   _50
   _B0
   _C0
   _D0
   _E0
   _F0

   _80
   _62
   _C2
   _60
   _40
   _D2
   _30
   _D0

   _62
   _62
   _90
   _90
   _D0
   _D0
   _40
   _40

   _C2
   _C0
   _20
   _22
   _22
   _D2
   _C2
   _22
end



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Playfield foreground color data.
   ;
   data _Data_Foreground_Color
   _BC
   _3C
   _BC
   _CC
   _2C
   _0C
   _BC
   _AC

   _9C
   _6C
   _CC
   _3C
   _CC
   _9C
   _CC
   _2C

   _5C
   _9C
   _BC
   _5C
   _2C
   _4C
   _0C
   _3C

   _0C
   _AC
   _CC
   _4C
   _3C
   _EC
   _4C
   _2E
end



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Data for converting a room number into a bit (visited rooms).
   ;
   data _Data_Number_to_Bit
   %00000001
   %00000010
   %00000100
   %00001000
   %00010000
   %00100000
   %01000000
   %10000000
end





   bank 3





__Continue_in_Bank_3



   ;```````````````````````````````````````````````````````````````
   ;
   ;  MORE CODE CAN GO HERE.
   ;
   ;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop bank1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop bank1

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart bank1





   bank 4





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Life counter minikernel.
   ;
   inline 6lives.asm

 

 

 

16 x 16 World

16 x 16 World on bB page.

 
   ;***************************************************************
   ;
   ;  16 x 16 World With Extra Underground World
   ;  (256 Rooms + 256 Rooms = 512 Rooms)
   ;
   ;  Example program by Karl G and adapted by Duane Alan Hahn
   ;  (Random Terrain) using hints, tips, code snippets, and
   ;  more from AtariAge members such as batari, SeaGtGruff,
   ;  RevEng, Robert M, Nukey Shay, Atarius Maximus, jrok,
   ;  supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  About:
   ;  
   ;  This example program uses rand and unrand to generate a
   ;  16 x 16 world of 256 rooms without having to use variables
   ;  to track what type of screen is in what position.
   ;
   ;  Select a seed number using the score by moving the joystick
   ;  up, down, left or right. Leaving the score set to zero will
   ;  cause the program to select a random seed number. The screen
   ;  types will be consistent every time when using the same
   ;  seed number. Press the reset switch to restart the program
   ;  whenever you wish to select another seed number.
   ;
   ;  There are stairs in the world that lead to a lower level.
   ;  That lower level has a different layout than the upper
   ;  level, but its screen types will also be consistent every
   ;  time when using the same seed number. (There are stairs that
   ;  lead back to the upper level.)
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;****************************************************************
   ;
   ;  The kernel option below causes the loss of missile1.
   ; 
   set kernel_options player1colors



   ;***************************************************************
   ;
   ;  This program has 4 banks (16k/4k = 4 banks).
   ;
   set romsize 16k



   ;***************************************************************
   ;
   ;  Random numbers can slow down bankswitched games.
   ;  This will speed things up.
   ;
   set optimization inlinerand



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Which room player is in.
   ;
   dim _XRoom = a
   dim _YRoom = b

   ;```````````````````````````````````````````````````````````````
   ;  Which scene should be used.
   ;
   dim _CurrentScene = c

   ;```````````````````````````````````````````````````````````````
   ;  Title screen slowdown variable.
   ;
   dim _TS_Slowdown = c

   ;```````````````````````````````````````````````````````````````
   ;  Temp variable.
   ;
   dim _Temp = d

   ;```````````````````````````````````````````````````````````````
   ;  _Master_Counter can be used for many things, but it is 
   ;  really useful for animating sprite frames when used
   ;  with _Frame_Counter.
   ;
   dim _Master_Counter = e
   dim _Frame_Counter = f

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  All-purpose bits for various jobs.
   ;
   dim _BitOp_01 = g
   dim _Bit0_Reset_Restrainer = g     ; Restrains the reset switch.
   dim _Bit1_Next_Room_Up = g         ; Time for new room.
   dim _Bit2_Next_Room_Down = g       ; Time for new room.
   dim _Bit3_Next_Room_Left = g       ; Time for new room.
   dim _Bit4_Next_Room_Right = g      ; Time for new room.
   dim _Bit5_UD_Joy_Movement = g      ; Up/down joystick movement happened.
   dim _Bit6_LR_Joy_Movement = g      ; Left/Right joystick movement happened.
   dim _Bit7_Over_Under = g           ; Overland or Underland.

   ;```````````````````````````````````````````````````````````````
   ;  Player1 left/right movement.
   ;
   dim _P1_Left_Right = player1x.h

   ;```````````````````````````````````````````````````````````````
   ;  Player1 up/down movement.
   ;
   dim _P1_Up_Down = player1y.i

   ;```````````````````````````````````````````````````````````````
   ;  Special rand used for the rooms.
   ;
   dim _RoomRand = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers.
   ;
   dim rand16 = z

   ;```````````````````````````````````````````````````````````````
   ;  Splits up the score into 3 parts.
   ;
   dim _sc1 = score
   dim _sc2 = score+1
   dim _sc3 = score+2



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for the sprite size used
   ;  in this program. If your sprite is a different size, you'll
   ;  need to adjust the numbers. [The c stands for constant.]
   ;
   const _c_Edge_Top = 10
   const _c_Edge_Bottom = 88
   const _c_Edge_Left = 2
   const _c_Edge_Right = 153



   ;***************************************************************
   ;
   ;  World limit constants. Change these based on world size.
   ;  The default here is 16 x 16 (256 rooms).
   ;  [The c stands for constant.]
   ;
   const _c_World_Limit_Top = 0
   const _c_World_Limit_Bottom = 15
   const _c_World_Limit_Left = 0
   const _c_World_Limit_Right = 15



   ;****************************************************************
   ;
   ;  NTSC colors.
   ;
   ;  Use these constants so you can quickly and easily swap them
   ;  out for PAL-60 colors. Or use this if you created a PAL-60
   ;  game and want to instantly convert the colors to NTSC (if you
   ;  were already using the PAL-60 constants).
   ;
   const _00 = $00
   const _02 = $02
   const _04 = $04
   const _06 = $06
   const _08 = $08
   const _0A = $0A
   const _0C = $0C
   const _0E = $0E
   const _10 = $10
   const _12 = $12
   const _14 = $14
   const _16 = $16
   const _18 = $18
   const _1A = $1A
   const _1C = $1C
   const _1E = $1E
   const _20 = $20
   const _22 = $22
   const _24 = $24
   const _26 = $26
   const _28 = $28
   const _2A = $2A
   const _2C = $2C
   const _2E = $2E
   const _30 = $30
   const _32 = $32
   const _34 = $34
   const _36 = $36
   const _38 = $38
   const _3A = $3A
   const _3C = $3C
   const _3E = $3E
   const _40 = $40
   const _42 = $42
   const _44 = $44
   const _46 = $46
   const _48 = $48
   const _4A = $4A
   const _4C = $4C
   const _4E = $4E
   const _50 = $50
   const _52 = $52
   const _54 = $54
   const _56 = $56
   const _58 = $58
   const _5A = $5A
   const _5C = $5C
   const _5E = $5E
   const _60 = $60
   const _62 = $62
   const _64 = $64
   const _66 = $66
   const _68 = $68
   const _6A = $6A
   const _6C = $6C
   const _6E = $6E
   const _70 = $70
   const _72 = $72
   const _74 = $74
   const _76 = $76
   const _78 = $78
   const _7A = $7A
   const _7C = $7C
   const _7E = $7E
   const _80 = $80
   const _82 = $82
   const _84 = $84
   const _86 = $86
   const _88 = $88
   const _8A = $8A
   const _8C = $8C
   const _8E = $8E
   const _90 = $90
   const _92 = $92
   const _94 = $94
   const _96 = $96
   const _98 = $98
   const _9A = $9A
   const _9C = $9C
   const _9E = $9E
   const _A0 = $A0
   const _A2 = $A2
   const _A4 = $A4
   const _A6 = $A6
   const _A8 = $A8
   const _AA = $AA
   const _AC = $AC
   const _AE = $AE
   const _B0 = $B0
   const _B2 = $B2
   const _B4 = $B4
   const _B6 = $B6
   const _B8 = $B8
   const _BA = $BA
   const _BC = $BC
   const _BE = $BE
   const _C0 = $C0
   const _C2 = $C2
   const _C4 = $C4
   const _C6 = $C6
   const _C8 = $C8
   const _CA = $CA
   const _CC = $CC
   const _CE = $CE
   const _D0 = $D0
   const _D2 = $D2
   const _D4 = $D4
   const _D6 = $D6
   const _D8 = $D8
   const _DA = $DA
   const _DC = $DC
   const _DE = $DE
   const _E0 = $E0
   const _E2 = $E2
   const _E4 = $E4
   const _E6 = $E6
   const _E8 = $E8
   const _EA = $EA
   const _EC = $EC
   const _EE = $EE
   const _F0 = $F0
   const _F2 = $F2
   const _F4 = $F4
   const _F6 = $F6
   const _F8 = $F8
   const _FA = $FA
   const _FC = $FC
   const _FE = $FE




   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Makes sure sprites are off screen.
   ;
   player1y = 150 : player0y = 150


   ;***************************************************************
   ;
   ;  Clears most normal variables.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0





   ;***************************************************************
   ;***************************************************************
   ;
   ;   TITLE SCREEN SETUP
   ;
   ;
__Title_Screen_Setup


   ;***************************************************************
   ;
   ;  Sets score color for title screen.
   ;
   scorecolor = _1C


   ;***************************************************************
   ;
   ;  Sets score and tracker variable.
   ;
   score = 0 : _RoomRand = 0


   ;***************************************************************
   ;
   ;  Sets title screen background color.
   ;
   COLUBK = _00


   ;***************************************************************
   ;
   ;  Sets title screen playfield pixel colors.
   ;
   COLUPF = _08


   ;***************************************************************
   ;
   ;  Restrains the reset switch.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after entering a different segment
   ;  of the program. It also does double duty by restraining the
   ;  fire button in the title screen loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets up title screen playfield.
   ;
   playfield:
   .XXXXX.XXXX.XX...XXXX.XXXX.XXXX.
   .XX....XX...XX...XX...XX....XX..
   .XXXXX.XXXX.XX...XXXX.XX....XX..
   ....XX.XX...XX...XX...XX....XX..
   .XXXXX.XXXX.XXXX.XXXX.XXXX..XX..
   ................................
   XXXXX.XXXX.XXXX.XXXXX....XX.XX..
   XX....XX...XX...XX..XX..XXXXXXX.
   XXXXX.XXXX.XXXX.XX..XX...XX.XX..
   ...XX.XX...XX...XX..XX..XXXXXXX.
   XXXXX.XXXX.XXXX.XXXXX....XX.XX..
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  TITLE SCREEN LOOP
   ;
   ;
__Title_Screen_Loop



   ;***************************************************************
   ;
   ;  Controls seed number selection speed.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments the master counter.
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips section if master counter is less than _TS_Slowdown.
   ;
   if _Master_Counter < _TS_Slowdown then goto __Skip_TS_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Number seed selection for rooms using joystick.
   ;
   if joy0right && _RoomRand < 255 then score = score + 1 : _RoomRand = _RoomRand + 1 : _TS_Slowdown = 11
   if joy0left && _RoomRand > 0 then score = score - 1 : _RoomRand = _RoomRand - 1 : _TS_Slowdown = 11
   if joy0up && _RoomRand < 255 then score = score + 1 : _RoomRand = _RoomRand + 1 : _TS_Slowdown = 2
   if joy0down && _RoomRand > 0 then score = score - 1 : _RoomRand = _RoomRand - 1 : _TS_Slowdown = 2

   ;```````````````````````````````````````````````````````````````
   ;  Clears master counter.
   ;
   _Master_Counter = 0

__Skip_TS_Counter



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset/fire button check and end of title screen loop.
   ;  
   ;  Starts the game if the reset switch or the fire button
   ;  is pressed appropriately.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and jumps to beginning of title 
   ;  screen loop if fire button or reset switch is not pressed.
   ;
   if !switchreset && !joy0fire then _Bit0_Reset_Restrainer{0} = 0 : goto __Title_Screen_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of title screen loop if reset or fire 
   ;  hasn't been released since starting title screen loop.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Title_Screen_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Continues to main loop setup if fire button or reset pressed.
   ;
   goto __Main_Loop_Setup





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP SETUP
   ;
   ;
__Main_Loop_Setup


   ;***************************************************************
   ;
   ;  Sets starting position of player's sprite.
   ;
   player1x = 17 : player1y = 15


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Selects a random world if _RoomRand is zero.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips if _RoomRand is greater than 0.
   ;
   if _RoomRand then goto __Skip_Rand_World

   ;```````````````````````````````````````````````````````````````
   ;  Makes _RoomRand a random number.
   ;
   _RoomRand = rand : if !_RoomRand then _RoomRand = 1

   ;```````````````````````````````````````````````````````````````
   ;  Puts the world number in the score.
   ;
   temp4 = _RoomRand

   _sc2 = _sc2 & 240 : _sc3 = 0
   if temp4 >= 100 then _sc2 = _sc2 + 1 : temp4 = temp4 - 100
   if temp4 >= 100 then _sc2 = _sc2 + 1 : temp4 = temp4 - 100
   if temp4 >= 50 then _sc3 = _sc3 + 80 : temp4 = temp4 - 50
   if temp4 >= 30 then _sc3 = _sc3 + 48 : temp4 = temp4 - 30
   if temp4 >= 20 then _sc3 = _sc3 + 32 : temp4 = temp4 - 20
   if temp4 >= 10 then _sc3 = _sc3 + 16 : temp4 = temp4 - 10
   _sc3 = _sc3 | temp4

__Skip_Rand_World


   ;***************************************************************
   ;
   ;  Jumps to get special starting random number for rooms.
   ;
   goto __Special_Rand bank2





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets color of stairs.
   ;
   COLUP0 = _1A



   ;***************************************************************
   ;
   ;  Main counters.
   ;
   ;  Controls animation speed.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments the master counter.
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips section if master counter is less than 5.
   ;
   if _Master_Counter < 5 then goto __Skip_Frame_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Increments frame counter.
   ;
   _Frame_Counter = _Frame_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Clears master counter.
   ;
   _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Clears frame counter when it's time.
   ;
   if _Frame_Counter = 4 then _Frame_Counter = 0

__Skip_Frame_Counter



   ;***************************************************************
   ;
   ;  Clears joystick movement bits and next room bits.
   ;
   _Bit5_UD_Joy_Movement{5} = 0 : _Bit6_LR_Joy_Movement{6} = 0 : _Bit1_Next_Room_Up{1} = 0 : _Bit2_Next_Room_Down{2} = 0 : _Bit3_Next_Room_Left{3} = 0 : _Bit4_Next_Room_Right{4} = 0



   ;***************************************************************
   ;
   ;  Default standing still position for player1 sprite.
   ;
   player1color:
   _26
   _9C
   _9C
   _9C
   _DA
   _DA
   _3C
   _3C
   _3C
   _26
end

   player1:
   %01100110
   %00100100
   %00111100
   %00011000
   %01011010
   %00111100
   %00011000
   %00111100
   %00111100
   %00011000
end



   ;***************************************************************
   ;
   ;  Up movement section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Up: Skips this section if joystick not moved up.
   ;
   if !joy0up then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Up: Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player1x-11)/4

   temp6 = (player1y-11)/8

   if temp5 < 32 then if pfread(temp5,temp6) then goto __Skip_Joy0_Up

   temp4 = (player1x-16)/4

   if temp4 < 32 then if pfread(temp4,temp6) then goto __Skip_Joy0_Up

   temp3 = temp5 - 1

   if temp3 < 32 then if pfread(temp3,temp6) then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Up: Turns on up/down movement bit.
   ;
   _Bit5_UD_Joy_Movement{5} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Up: Moves player1 up.
   ;
   _P1_Up_Down = _P1_Up_Down - 1.18

   ;```````````````````````````````````````````````````````````````
   ;  Up: Sprite color for up movement.
   ;
   player1color:
   _26
   _9C
   _9C
   _9C
   _DA
   _DA
   _3C
   _26
   _26
   _26
end

   ;```````````````````````````````````````````````````````````````
   ;  Up: Skips if player hasn't gone past top edge.
   ;
   if player1y >= _c_Edge_Top then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Up: Keeps player within the world.
   ;
   if _YRoom = _c_World_Limit_Top then player1y = _c_Edge_Top : goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Up: Moves player to bottom of screen for the next room.
   ;
   player1y = _c_Edge_Bottom

   ;```````````````````````````````````````````````````````````````
   ;  Up: Moves player to next room above.
   ;
   _YRoom = _YRoom - 1

   _Bit1_Next_Room_Up{1} = 1

__Skip_Joy0_Up



   ;***************************************************************
   ;
   ;  Down movement section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Down: Skips this section if joystick not moved up.
   ;
   if !joy0down then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Down: Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player1x-11)/4

   temp6 = (player1y+1)/8

   if temp5 < 32 then if pfread(temp5,temp6) then goto __Skip_Joy0_Down

   temp4 = (player1x-16)/4

   if temp4 < 32 then if pfread(temp4,temp6) then goto __Skip_Joy0_Down

   temp3 = temp5 - 1

   if temp3 < 32 then if pfread(temp3,temp6) then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Down: Turns on up/down movement bit.
   ;
   _Bit5_UD_Joy_Movement{5} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Down: Moves player1 down.
   ;
   _P1_Up_Down = _P1_Up_Down + 1.18

   ;```````````````````````````````````````````````````````````````
   ;  Down: Skips if player hasn't gone past bottom edge.
   ;
   if player1y <= _c_Edge_Bottom then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Down: Keeps player within the world.
   ;
   if _YRoom = _c_World_Limit_Bottom then player1y = _c_Edge_Bottom : goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Down: Moves player to top of screen for the next room.
   ;
   player1y = _c_Edge_Top

   ;```````````````````````````````````````````````````````````````
   ;  Down: Moves player to next room below.
   ;
   _YRoom = _YRoom + 1

   _Bit2_Next_Room_Down{2} = 1

__Skip_Joy0_Down



   ;***************************************************************
   ;
   ;  Left movement section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Left: Skips this section if joystick not moved left.
   ;
   if !joy0left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Left: Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player1y-1)/8

   temp6 = (player1x-18)/4

   if temp6 < 32 then if pfread(temp6,temp5) then goto __Skip_Joy0_Left

   temp3 = (player1y-9)/8

   if temp6 < 32 then if pfread(temp6,temp3) then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Left: Turns on left/right movement bit.
   ;
   _Bit6_LR_Joy_Movement{6} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Left: Moves player1 left.
   ;
   _P1_Left_Right = _P1_Left_Right - 1.48

   ;```````````````````````````````````````````````````````````````
   ;  Left: Makes sure player1 sprite is facing the correct direction.
   ;
   REFP1 = 0

   ;```````````````````````````````````````````````````````````````
   ;  Left: Skips if player hasn't gone past left edge.
   ;
   if player1x >= _c_Edge_Left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Left: Keeps player within the world.
   ;
   if _XRoom = _c_World_Limit_Left then player1x = _c_Edge_Left : goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Left: Skips if player already moved up to next room.
   ;
   if _Bit1_Next_Room_Up{1} then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Left: Moves player to right edge of screen for the next room.
   ;
   player1x = _c_Edge_Right

   ;```````````````````````````````````````````````````````````````
   ;  Left: Moves player to next room on the left.
   ;
   _XRoom = _XRoom - 1

   _Bit3_Next_Room_Left{3} = 1

__Skip_Joy0_Left



   ;***************************************************************
   ;
   ;  Right movement section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Right: Skips this section if joystick not moved right.
   ;
   if !joy0right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Right: Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player1y-1)/8

   temp6 = (player1x-9)/4

   if temp6 < 32 then if pfread(temp6,temp5) then goto __Skip_Joy0_Right

   temp3 = (player1y-9)/8

   if temp6 < 32 then if pfread(temp6,temp3) then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Right: Turns on right movement bit.
   ;
   _Bit6_LR_Joy_Movement{6} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Right: Moves player1 right.
   ;
   _P1_Left_Right = _P1_Left_Right + 1.48

   ;```````````````````````````````````````````````````````````````
   ;  Right: Makes sure player1 sprite is facing the correct direction.
   ;
   REFP1 = 8

   ;```````````````````````````````````````````````````````````````
   ;  Right: Skips if player hasn't gone past left edge.
   ;
   if player1x <= _c_Edge_Right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Right: Keeps player within the world.
   ;
   if _XRoom = _c_World_Limit_Right then player1x = _c_Edge_Right : goto __Skip_Joy0_Right
   
   ;```````````````````````````````````````````````````````````````
   ;  Right: Skips if player already moved down to next room.
   ;
   if _Bit2_Next_Room_Down{2} then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Right: Moves player to left edge of screen for the next room.
   ;
   player1x = _c_Edge_Left

   ;```````````````````````````````````````````````````````````````
   ;  Right: Moves player to next room on the right.
   ;
   _XRoom = _XRoom + 1

   _Bit4_Next_Room_Right{4} = 1

__Skip_Joy0_Right



   ;***************************************************************
   ;
   ;  Up/down walking animation section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips animation if joystick not moved up or down.
   ;
   if !_Bit5_UD_Joy_Movement{5} then goto __Done_UD_Anim

   ;```````````````````````````````````````````````````````````````
   ;  Animates player1 sprite for up/down movement.
   ;
   on _Frame_Counter goto __FrameD0 __FrameD1 __FrameD2 __FrameD3

__Done_UD_Anim



   ;***************************************************************
   ;
   ;  Left/right walking animation section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips animation if joystick not moved left or right.
   ;
   if !_Bit6_LR_Joy_Movement{6} then goto __Done_LR_Anim

   ;```````````````````````````````````````````````````````````````
   ;  Sets player1 left/right color.
   ;
   player1color:
   _26
   _9C
   _9C
   _9C
   _DA
   _DA
   _3C
   _3C
   _3C
   _26
end

   ;```````````````````````````````````````````````````````````````
   ;  Animates player1 sprite for left/right movement.
   ;
   on _Frame_Counter goto __FrameLR0 __FrameLR1 __FrameLR2 __FrameLR3

__Done_LR_Anim



   ;```````````````````````````````````````````````````````````````
   ;
   ;  MORE CODE CAN GO HERE.
   ;
   ;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''



   ;***************************************************************
   ;
   ;  Continues program in Bank 2.
   ;
   goto __Continue_in_Bank_2 bank2





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Left/right animation frames for player1.
   ;
__FrameLR0
   player1:
   %01100110

   %01100110
   %00111100
   %00001100
   %00111100
   %00011100
   %00011000
   %00111100
   %00111100
   %00011000
end

   goto __Done_LR_Anim


__FrameLR1
   player1:
   %11000011
   %01100011
   %00111110
   %00011100
   %00111100
   %01011110
   %00011000
   %00111100
   %00111100
   %00011000
end

   goto __Done_LR_Anim


__FrameLR2
   player1:
   %00110110
   %00110110
   %00011100
   %00001100
   %00111100
   %00011100
   %00011000
   %00111100
   %00111100
   %00011000
end

   goto __Done_LR_Anim


__FrameLR3
   player1:
   %00111100
   %00011100
   %00011100
   %00000100
   %00011100
   %00011100
   %00011000
   %00111100
   %00111100
   %00011000
end

   goto __Done_LR_Anim



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Up/down animation frames for player1.
   ;
__FrameD0
   player1:
   %01100110
   %00100100
   %00011100
   %00011000
   %01111010
   %00111100
   %00011000
   %00111100
   %00111100
   %00011000
end

   goto __Done_UD_Anim
__FrameD1
   player1:
   %01100000
   %00100110
   %00111100
   %00011000
   %00111110
   %00111110
   %00011000
   %00111100
   %00111100
   %00011000
end

   goto __Done_UD_Anim


__FrameD2
   player1:
   %01100110
   %00100100
   %00111000
   %00011000
   %01011110
   %00111100
   %00011000
   %00111100
   %00111100
   %00011000
end

   goto __Done_UD_Anim


__FrameD3
   player1:
   %00000110
   %01100100
   %00111100
   %00011000
   %01111100
   %01111100
   %00011000
   %00111100
   %00111100
   %00011000
end

   goto __Done_UD_Anim





   bank 2





__Continue_in_Bank_2



   ;```````````````````````````````````````````````````````````````
   ;
   ;  MORE CODE CAN GO HERE.
   ;
   ;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''



   ;***************************************************************
   ;
   ;  Player/stairs collision check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if no collision.
   ;
   if !collision(player0,player1) then goto __Skip_Stairs_Collision

   ;```````````````````````````````````````````````````````````````
   ;  Moves stairs off screen.
   ;
   player0y = 150

   ;```````````````````````````````````````````````````````````````
   ;  Flips overworld/underworld bit.
   ;
   _Bit7_Over_Under{7} = !_Bit7_Over_Under{7}

   ;```````````````````````````````````````````````````````````````
   ;  Moves player to correct position.
   ;
   player1y = _c_Edge_Bottom

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to underworld or overworld.
   ;
   goto __Skip_UnRand

__Skip_Stairs_Collision



   ;***************************************************************
   ;
   ;  Displays next room when it's time.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if next room bits are off.
   ;
   if !_Bit1_Next_Room_Up{1} && !_Bit2_Next_Room_Down{2} && !_Bit3_Next_Room_Left{3} && !_Bit4_Next_Room_Right{4} then goto __Done_Next_Room

   ;```````````````````````````````````````````````````````````````
   ;  Skips bBRand section if player didn't move right or down.
   ;
   if !_Bit4_Next_Room_Right{4} && !_Bit2_Next_Room_Down{2} then goto __Skip_bBRand

__Special_Rand

   _Temp = 0

   ;```````````````````````````````````````````````````````````````
   ;  Special Rand for rooms.
   ;
__bBRand
   asm
   lda _RoomRand
   lsr
   bcc __bB_Rand_no_eor
   eor #$B4
__bB_Rand_no_eor
   sta _RoomRand
end

   ;```````````````````````````````````````````````````````````````
   ;  Skips drawscreen most of the time.
   ;
   if _Temp <> 7 then goto __Skip_bBRand_Drawscreen

   ;```````````````````````````````````````````````````````````````
   ;  Draws screen half way through.
   ;
   drawscreen

__Skip_bBRand_Drawscreen

   ;```````````````````````````````````````````````````````````````
   ;  Loops if player moves down to next room.
   ;
   if _Bit2_Next_Room_Down{2} then _Temp = _Temp + 1 : if _Temp <= _c_World_Limit_Right then goto __bBRand

   ;```````````````````````````````````````````````````````````````
   ;  Sets current scene variable.
   ;
   _CurrentScene = _RoomRand

__Skip_bBRand

   ;```````````````````````````````````````````````````````````````
   ;  Skips UnRand section if player didn't move up or left.
   ;
   if !_Bit1_Next_Room_Up{1} && !_Bit3_Next_Room_Left{3} then goto __Skip_UnRand

   _Temp = 0

   ;```````````````````````````````````````````````````````````````
   ;  Special UnRand for rooms.
   ;
__UnRand
   asm
   LDA _RoomRand
   ASL
   BCC __UnRand_no_eor
   EOR #$69
__UnRand_no_eor:
   STA _RoomRand
   STA _CurrentScene
end

   ;```````````````````````````````````````````````````````````````
   ;  Skips drawscreen most of the time.
   ;
   if _Temp <> 7 then goto __Skip_UnRand_Drawscreen

   ;```````````````````````````````````````````````````````````````
   ;  Draws screen half way through.
   ;
   drawscreen

__Skip_UnRand_Drawscreen

   ;```````````````````````````````````````````````````````````````
   ;  Loops if player moves up to next room.
   ;
   if _Bit1_Next_Room_Up{1} then _Temp = _Temp + 1 : if _Temp <= _c_World_Limit_Right then goto __UnRand

__Skip_UnRand

   ;```````````````````````````````````````````````````````````````
   ;  Makes sure stairs are gone.
   ;
   player0y = 150

   ;```````````````````````````````````````````````````````````````
   ;  Sets current scene variable.
   ;
   _CurrentScene = _RoomRand

   ;```````````````````````````````````````````````````````````````
   ;  Limits current scene and jumps to where current overworld
   ;  or underworld scene is drawn.
   ;  (Off is overworld. On is underworld.)
   ;
   if !_Bit7_Over_Under{7} then _CurrentScene = (_CurrentScene&31) : goto __Set_Overworld_Scene
   if _Bit7_Over_Under{7} then _CurrentScene = (_CurrentScene/8) : goto __Set_Underworld_Scene bank3

__Done_Next_Room



   ;```````````````````````````````````````````````````````````````
   ;
   ;  MORE CODE CAN GO HERE.
   ;
   ;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Continues program in Bank 3.
   ;
   goto __Continue_in_Bank_3 bank3





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sets Overworld colors & playfield design for current room.
   ;
__Set_Overworld_Scene
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Defines stair image.
   ;
   player0:
   %11111111
   %11111111
   %11111111
   %00000000
   %01111110
   %01111110
   %00000000
   %00111100
end

   ;```````````````````````````````````````````````````````````````
   ;  Sets the playfield background and foreground color.
   ;
   COLUBK = _Data_Over_Background_Color[_CurrentScene]
   COLUPF = _Data_Over_Foreground_Color[_CurrentScene]

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the current scene to be displayed.
   ;
   on _CurrentScene goto __s0 __s1 __s2 __s3 __s4 __s5 __s6 __s7 __s8 __s9 __sA __sB __sC __sD __sE __sF __sG __sH __sI __sJ __sK __sL __sM __sN __sO __sP __sQ __sR __sS __sT __sU __sV


__s0
   playfield:
   ................................
   ................................
   ..............X.................
   .............XXX.......X........
   ............XXXXX.....XXX.......
   ......X..............XXXXX......
   .....XXX............XXXXXXX.....
   ....XXXXX..........XXXXXXXXX....
   ...XXXXXXX......................
   ................................
   ................................
end

   goto __Done_Next_Room

   
__s1
   playfield:
   ................................
   ................................
   ....XXXX...XXXXXXXXXX...XXXX....
   ................................
   ................................
   ....XXXXXXXXXXXXXXXXXXXXXXXX....
   ................................
   ................................
   ....XXXX...XXXXXXXXXX...XXXX....
   ................................
   ................................
end

   goto __Done_Next_Room

   
__s2
   playfield:
   ................................
   ................................
   .......XXX............XXX.......
   ......XXXXX..........XXXXX......
   .......XXX............XXX.......
   ................................
   ..............XXXX..............
   .............XXXXXX.............
   ..............XXXX..............
   ................................
   ................................
end

   goto __Done_Next_Room


__s3
   playfield:
   ................................
   ................................
   ....XXXXX...XXXXXXX...XXXXXX....
   ....XXXXX...XXXXXXX...XXXXXX....
   ................................
   ................................
   ................................
   ....XXXXX...XXXXXXX...XXXXXX....
   ....XXXXX...XXXXXXX...XXXXXX....
   ................................
   ................................
end

   goto __Done_Next_Room


__s4
   playfield:
   ................................
   ................................
   ...............X................
   ..............XXX...............
   .............XXXXX..............
   ...........XXXXXXXXX............
   .........XXXXXXXXXXXXX..........
   .......XXXXXXXXXXXXXXXXX........
   .....XXXXXXXXXXXXXXXXXXXXX......
   ................................
   ................................
end

   goto __Done_Next_Room


__s5
   playfield:
   ................................
   ................................
   ....X.....X.....................
   ...XXX...XXX.........X..........
   ....X.....X.........XXX.........
   .....................X..........
   ...............X..........X.....
   ..............XXX........XXX....
   ...............X..........X.....
   ................................
   ................................
end

   goto __Done_Next_Room


__s6
   playfield:
   ................................
   ................................
   ............XX....XX............
   ............XX....XX............
   ....XXXXXX............XXXXXX....
   ....XXXXXX............XXXXXX....
   ....XXXXXX............XXXXXX....
   ............XX....XX............
   ............XX....XX............
   ................................
   ................................
end

   goto __Done_Next_Room


__s7
   playfield:
   ................................
   ................................
   ................XXXXXXXX........
   ..........XXXXXXXXXXXXXXX.......
   .........XXXXXXXXXXXXXX.........
   ........XXXXXXXXXXXXXXX.........
   ........XXXXXXXXXXXXXXXXXX......
   .........XXXXXXXXXXXXXXXXX......
   ............XXXXX..XXXXXX.......
   ................................
   ................................
end

   goto __Done_Next_Room


__s8

   player0x = 49 : player0y = 56

   playfield:
   ................................
   ................................
   ........XXXXXXXXX........X......
   ......XXXXXXXXXXXX......XXX.....
   .....XXXXXXXXXXXXX.....XXXXX....
   .....XXXXXXXXXXXX.....XXXXXXX...
   ......XX..XXXXXXX........X......
   ......XX..XXXXXX.........X......
   ................................
   ................................
   ................................
end

   goto __Done_Next_Room


__s9
   playfield:
   ................................
   ................................
   ................................
   .....XXX........................
   ....XXXXX...........XXX.........
   ....XXXXX..........XXXXX........
   .....XXX...........XXXXX........
   ....................XXX.........
   ................................
   ................................
   ................................
end

   goto __Done_Next_Room


__sA
   playfield:
   ................................
   ................................
   ....XXXXXX..XXXXXXXX..XXXXXX....
   ....XX....................XX....
   ....XX....................XX....
   ................................
   ................................
   ....XX....................XX....
   ....XXXXXX..XXXXXXXX..XXXXXX....
   ................................
   ................................
end
   goto __Done_Next_Room


__sB
   playfield:
   ................................
   ................................
   .......XXXX.....................
   .....XXXXXXXX...................
   ...XXXXXXXXXXXX.................
   .....XXXXXXXX...................
   .......XXXX............XXX......
   ......................XXXXX.....
   .......................XXX......
   ................................
   ................................
end

   goto __Done_Next_Room


__sC
   playfield:
   ................................
   ................................
   ......XXX...XXXXXXXX...XXX......
   ....XXXXXX....XXXX....XXXXXX....
   ...XXXXXXX....XXXX....XXXXXXX...
   ...XXXXXX.....XXXX.....XXXXXX...
   ....XXXX......XXXX......XXXX....
   ....XXX.....XXXXXXXX.....XXX....
   ....XXXX...XXXXXXXXXX...XXXX....
   ................................
   ................................
end

   goto __Done_Next_Room


__sD

   player0x = 89 : player0y = 64

   playfield:
   ................................
   ................................
   ..........XXXXXXXXXXXX..........
   ........XXXXXXXXXXXXXXXX........
   ........XXXXXXXXXXXXXXXX........
   ........XXXXXXXXXXXXXXXX........
   ........XXXXXXXXXXXXXXXX........
   ........XXXXXXXXXX..XXXX........
   ..........XXXXXXXX..XXX.........
   ................................
   ................................
end

   goto __Done_Next_Room


__sE
   playfield:
   ................................
   ................................
   ....XXXXXXXXXX....XXXXXXXXXX....
   ....XX....................XX....
   ....XX....................XX....
   ....XX....................XX....
   ............XXX..XXX............
   ............XXX..XXX............
   ....XXXXXX..XXX..XXX..XXXXXX....
   ................................
   ................................
end

   goto __Done_Next_Room


__sF
   playfield:
   ................................
   ................................
   ..........XXXXXXX...............
   .........XXXXXXXXXX.............
   .......XXXXXXXXXXXXXX...........
   ......XXXXXXXXXXXXXXX...........
   .......XXXXXXXXXXXXX............
   ..........XXXXXXX...............
   ................................
   ................................
   ................................
end

   goto __Done_Next_Room


__sG
   playfield:
   ................................
   ................................
   ....XXXX................XXXX....
   ....XXXX................XXXX....
   ....XXXX................XXXX....
   ....XXXXXXXXX......XXXXXXXXX....
   ................................
   ................................
   ....XXXXXXXXX......XXXXXXXXX....
   ................................
   ................................
end

   goto __Done_Next_Room


__sH
   playfield:
   ................................
   ................................
   ...XXXXXXX......................
   ....XXXXX..........XXXXXXXXX....
   .....XXX............XXXXXXX.....
   ......X..............XXXXX......
   ............XXXXX.....XXX.......
   .............XXX.......X........
   ..............X.................
   ................................
   ................................
end

   goto __Done_Next_Room


__sI
   playfield:
   ................................
   ................................
   ....XXXXX..XX..XX..XX..XXXXX....
   ....XXXXX..XX..XX..XX..XXXXX....
   ....XXXXX..XX..XX..XX..XXXXX....
   ....XXXXX..XX..XX..XX..XXXXX....
   ...........XX..XX..XX...........
   ...........XX..XX..XX...........
   ....XXXXXXXXX..XX..XXXXXXXXX....
   ................................
   ................................
end

   goto __Done_Next_Room


__sJ
   playfield:
   ................................
   ................................
   ...................XX...........
   ..................XXXX..........
   .................XXXXXX.........
   ......XX.........XX..XX.........
   .....XXXX.......................
   ....XXXXXX......................
   ....XX..XX......................
   ................................
   ................................
end

   goto __Done_Next_Room


__sK
   playfield:
   ................................
   ................................
   ..............XXX...............
   .............XXXXX..............
   ..............XXX...............
   ................................
   .......XXX...........XXX........
   ......XXXXX.........XXXXX.......
   .......XXX...........XXX........
   ................................
   ................................
end

   goto __Done_Next_Room


__sL
   playfield:
   ................................
   ................................
   .....XX..XXXXXXXXXXXXXXXXXX.....
   .....XX..XX.....................
   .....XX..XX.....................
   .....XX..XX...XXXXXXXXXXXXX.....
   .....XX..XX...XX.........XX.....
   .....XX..XX...XX.........XX.....
   .....XX..XX...XX..XXXXX..XX.....
   ................................
   ................................
end

   goto __Done_Next_Room


__sM

   player0x = 49 : player0y = 56

   playfield:
   ................................
   ................................
   .......XXXXXXXXXX...............
   .....XXXXXXXXXXXXX..............
   .....XXXXXXXXXXXXX..............
   .....XXXXXXXXXXXXX..............
   .....XXX..XXXXXXXX.......XXX....
   ......XX..XXXXXXX........XXX....
   ................................
   ................................
   ................................
end


   goto __Done_Next_Room


__sN

   player0x = 85 : player0y = 56

   playfield:
   ................................
   ................................
   ......X.........XXXXXXX.........
   .....XXX......XXXXXXXXXXX.......
   ....XXXXX.....XXXXXXXXXXXX......
   ...XXXXXXX....XXXXXXXXXXXX......
   ......X.......XXX..XXXXXXX......
   ......X........XX..XXXXXX.......
   ................................
   ................................
   ................................
end

   goto __Done_Next_Room


__sO
   playfield:
   ................................
   ................................
   ..................XXXXX.........
   ..................XXXXXXX.......
   ...................XXXXX........
   ................................
   .........XXXXX..................
   .......XXXXXXX..................
   ........XXXXX...................
   ................................
   ................................
end

   goto __Done_Next_Room


__sP
   playfield:
   ................................
   ................................
   .....XXXXXXXXXXXXXXXXXXXXXX.....
   .....XXX................XXX.....
   .....XXX................XXX.....
   .....XXX..XXXXXXXXXXXX..XXX.....
   .....XXX..XXXXXXXXXXXX..XXX.....
   .....XXX..XXXXXXXXXXXX..XXX.....
   ................................
   ................................
   ................................
end

   goto __Done_Next_Room


__sQ
   playfield:
   ................................
   ................................
   .........XXX........XXX.........
   .......XXXXXXX....XXXXXXX.......
   ................................
   ................................
   ................................
   .......XXXXXXX....XXXXXXX.......
   .........XXX........XXX.........
   ................................
   ................................
end

   goto __Done_Next_Room


__sR
   playfield:
   ................................
   ................................
   .....XXXXXXXXXX..XXXX..XXXX.....
   .....XXXXXXXXXX..XXXX..XXXX.....
   .................XXXX..XXXX.....
   .................XXXX..XXXX.....
   .....XXXXXXXXXX..XXXX..XXXX.....
   .....XXXXXXXXXX..XXXX..XXXX.....
   ................................
   ................................
   ................................
end

   goto __Done_Next_Room


__sS
   playfield:
   ................................
   ................................
   ............XXX..XXX............
   ..........XXXXX..XXXXX..........
   ................................
   ................................
   ................................
   ..........XXXXX..XXXXX..........
   ............XXX..XXX............
   ................................
   ................................
end

   goto __Done_Next_Room


__sT
   playfield:
   ................................
   ................................
   .....XXX..XXXX....XXXX..XXX.....
   .....XXX..XXXXXXXXXXXX..XXX.....
   ................................
   ................................
   .....XXX..XXXXXXXXXXXX..XXX.....
   .....XXX..XXXX....XXXX..XXX.....
   .....XXX..XXXX....XXXX..XXX.....
   ................................
   ................................
end

   goto __Done_Next_Room


__sU
   playfield:
   ................................
   ................................
   ............XXX..XXX............
   ..........XXXXX..XXXXX..........
   .........XXXXXX..XXXXXX.........
   ........XXXXXXX..XXXXXXX........
   .........XXXXXX..XXXXXX.........
   ..........XXXXX..XXXXX..........
   ............XXX..XXX............
   ................................
   ................................
end

   goto __Done_Next_Room


__sV
   playfield:
   ................................
   ................................
   .....XXXXXXXXX....XXXXXXXXX.....
   .....XXXXXXXXX....XXXXXXXXX.....
   .....XXXX..............XXXX.....
   ................................
   ...........XXX....XXX...........
   ...........XXX....XXX...........
   .....XXXXXXXXX....XXXXXXXXX.....
   ................................
   ................................
end

   goto __Done_Next_Room





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Playfield background color data.
   ;
   data _Data_Over_Background_Color
   _20
   _30
   _50
   _B0
   _C0
   _D0
   _E0
   _F0

   _80
   _62
   _C2
   _60
   _40
   _D2
   _30
   _D0

   _62
   _62
   _90
   _90
   _D0
   _D0
   _40
   _40

   _C2
   _C0
   _20
   _22
   _22
   _D2
   _C2
   _22
end



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Playfield foreground color data.
   ;
   data _Data_Over_Foreground_Color
   _BC
   _3C
   _BC
   _CC
   _2C
   _0C
   _BC
   _AC

   _9C
   _6C
   _CC
   _3C
   _CC
   _9C
   _CC
   _2C

   _5C
   _9C
   _BC
   _5C
   _2C
   _4C
   _0C
   _3C

   _0C
   _AC
   _CC
   _4C
   _3C
   _EC
   _4C
   _2E
end





   bank 3





__Continue_in_Bank_3



   ;```````````````````````````````````````````````````````````````
   ;
   ;  MORE CODE CAN GO HERE.
   ;
   ;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop bank1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop bank1

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart bank1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sets Underworld colors & playfield design for current room.
   ;
__Set_Underworld_Scene
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Defines stair image.
   ;
   player0:
   %00111100
   %00000000
   %01111110
   %01111110
   %00000000
   %11111111
   %11111111
   %11111111
end

   ;```````````````````````````````````````````````````````````````
   ;  Sets the playfield background and foreground color.
   ;
   COLUBK = _Data_Under_Background_Color[_CurrentScene]
   COLUPF = _Data_Under_Foreground_Color[_CurrentScene]

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the current scene to be displayed.
   ;
   on _CurrentScene goto __u0 __u1 __u2 __u3 __u4 __u5 __u6 __u7 __u8 __u9 __uA __uB __uC __uD __uE __uF __uG __uH __uI __uJ __uK __uL __uM __uN __uO __uP __uQ __uR __uS __uT __uU __uV


__u0
   playfield:
   ................................
   ................................
   ....................XXX.........
   ...................XXXXXX.......
   .......XX.........XXXXXXXX......
   ......XXXX........XXXXXXXXX.....
   .....XXXXXX........XXXXXXX......
   .....XXXXXXX........XXXX........
   ......XXXXX.....................
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__u1
   playfield:
   ................................
   ................................
   ....XXXX...XXXX...XXX...XXXX....
   ..............X...X.............
   ..............X...X.............
   ....XXXXXXXXXXX...XXXXXXXXXX....
   ................................
   ................................
   ....XXXXXXXXXXXXXXXXXXXXXXXX....
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__u2
   playfield:
   ................................
   ................................
   ................................
   ......XXXXX.........XXXXX.......
   ................................
   ................................
   ................................
   .............XXXXX..............
   ................................
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__u3
   playfield:
   ................................
   ................................
   ....XXXXX..XXXXXXXXX..XXXXXX....
   ....XXXXX..XXXXXXXXX..XXXXXX....
   ...........XX.....XX............
   ...........XX.....XX............
   ...........XX.....XX............
   ....XXXXX..XXXXXXXXX..XXXXXX....
   ....XXXXX..XXXXXXXXX..XXXXXX....
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__u4
   playfield:
   ................................
   ................................
   ................................
   .....XXXXXXXXXX..XXXXXXXXXX.....
   ...........XXXX..XXXX...........
   ...........XXXX..XXXX...........
   .........XXXXXX..XXXXXX.........
   .......XXXXXXXX..XXXXXXXX.......
   .....XXXXXXXXXX..XXXXXXXXXX.....
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__u5
   playfield:
   ................................
   ................................
   ....XXXXXXXXXXXXX..XX...........
   ...............XX..XX...........
   ...............XX..XXXXXXXXX....
   ....XXXXXXXXX..XX.........XX....
   ...............XX.........XX....
   ...............XX.........XX....
   ....XXXXXXXXXXXXX..XXXXXXXXX....
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__u6
   playfield:
   ................................
   ................................
   ........XX..XXX..XXX..XX........
   ........XX..XXX..XXX..XX........
   ....XXXXXX..XXX..XXX..XXXXXX....
   ....XXXXXX..XXX..XXX..XXXXXX....
   ....XXXXXX..XXX..XXX..XXXXXX....
   ........XX..XXX..XXX..XX........
   ........XX..XXX..XXX..XX........
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__u7
   playfield:
   ................................
   ................................
   .....XXXXXXXXX..XXXX............
   ......XXXXXXXX..XXXX............
   .......XXXXXXX..XXXX..X.........
   ........XXXXXX..XXXX..XX........
   .........XXXXX..XXXX..XXX.......
   ..........XXXX..XXXX..XXXX......
   ...........XXX..XXXX..XXXXX.....
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__u8

   player0x = 49 : player0y = 56

   playfield:
   ................................
   ................................
   .....XXXXXXXXXXXXXXXXXXXXX......
   .....XXXXXXXXXXXXXXXXXXXXX......
   .....XXXXXXXXXXXXXXXXXXXXX......
   .....XXXXXXXXXXXXXXXXXXXXX......
   .....XXX..XXXXXXXXXXXXXXXX......
   .....XXX..XXXXXXXXXXXXXXXX......
   ................................
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__u9
   playfield:
   ................................
   ................................
   .....XXX...............XXX......
   ....XXXXX.............XXXXX.....
   ....XXXXX.............XXXXX.....
   .....XXX.......XXX.....XXX......
   ..............XXXXX.............
   ..............XXXXX.............
   ...............XXX..............
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uA
   playfield:
   ................................
   ................................
   ....XXXXXX..XXX..XXX..XXXXXX....
   ....XXXXXX..XXX..XXX..XXXXXX....
   ....XXXXXX..XXX..XXX..XXXXXX....
   ............XXX..XXX............
   ............XXX..XXX............
   ....XXXXXX..XXX..XXX..XXXXXX....
   ....XXXXXX..XXX..XXX..XXXXXX....
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uB
   playfield:
   ................................
   ................................
   ....XXXXXXXXXXXXX..XXXXXXXX.....
   ....XXXXXXXXXXXXX..XXXXXXXX.....
   ...............XX..XX...........
   ...............XX..XX...........
   ...............XX..XX...........
   ....XXXXXXXXXXXXX..XXXXXXXX.....
   ....XXXXXXXXXXXXX..XXXXXXXX.....
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uC
   playfield:
   ................................
   ................................
   ....XXXXXX..XXXXXXXX..XXXXXX....
   .........X............X.........
   .........X............X.........
   ....XXXXXXXXXXXXXXXXXXXXXXXX....
   ....X.......X......X.......X....
   ....X.......X......X.......X....
   ....XXXXXX..XXXXXXXX..XXXXXX....
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uD

   player0x = 89 : player0y = 64

   playfield:
   ................................
   ................................
   ...............XXXXXX...........
   .............XXXXXXXXXX.........
   ............XXXXXXXXXXXX........
   ...........XXXXXXXXXXXXX........
   ..........XXXXXXXXXXXXXX........
   ..........XXXXXXXX..XXXX........
   ..........XXXXXXXX..XXX.........
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uE
   playfield:
   ................................
   ................................
   ....X..X..XXXXXXXXXXXX..X..X....
   ....X..X................X..X....
   ....X..X................X..X....
   ....X..X..XXXXXXXXXXXX..X..X....
   ................................
   ................................
   ....XXXXXXXXXXX..XXXXXXXXXXX....
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uF
   playfield:
   ................................
   ................................
   ......XXXXXXXXXXXXXX............
   ......XXXXX.....................
   ......XXXXX.....................
   ......XXXXX..XXXXXXX............
   ......XXXXX..XXXXXXX............
   ......XXXXX..XXXXXXX............
   ................................
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uG
   playfield:
   ................................
   ................................
   ....XXXXXXXXXXXXXXXX..XX..XX....
   ....XX................XX..XX....
   ....XX................XX..XX....
   ....XX..XXXXXXXXXXXXXXXX..XX....
   ....XX....................XX....
   ....XX....................XX....
   ....XXXXXXXXXXXXXXXXXXXXXXXX....
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uH
   playfield:
   ................................
   ................................
   ...XXXXXX..XXXXX................
   ...XXXXXX.........XXXXXXXXX.....
   ...XXXXXX.........XXXXXXXXX.....
   ...XXXXXX..XXXXX..XXXXXXXXX.....
   ...........XXXXX..XXXXXXXXX.....
   ...........XXXXX..XXXXXXXXX.....
   ...........XXXXX................
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uI
   playfield:
   ................................
   ................................
   ....X..XX..XXXXXXXXXX..XX..X....
   ....X..XX..XX......XX..XX..X....
   ....X..XX..XX......XX..XX..X....
   ....X..XX..XX..XX..XX..XX..X....
   ....X......XX..XX..XX......X....
   ....X......XX..XX..XX......X....
   ....XXXXXXXXX..XX..XXXXXXXXX....
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uJ
   playfield:
   ................................
   ................................
   .......XXX......................
   .......XXX......................
   .......XXX...........XXX........
   ....XXXXXXXXX........XXX........
   ....XXXXXXXXX........XXX........
   ..................XXXXXXXXX.....
   ..................XXXXXXXXX.....
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uK
   playfield:
   ................................
   ................................
   ......XXXXXXXXX..XXXXXXXXX......
   ............XXX..XXX............
   ............XXX..XXX............
   ......XXXX..XXX..XXX..XXXX......
   ......XXXX..XXX..XXX..XXXX......
   ......XXXX..XXX..XXX..XXXX......
   ......XXXX..XXX..XXX..XXXX......
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uL
   playfield:
   ................................
   ................................
   ................................
   .....XXXXXXXXXXXXXXXXXX..XX.....
   .....XX..................XX.....
   .....XX..................XX.....
   .....XX..............XX..XX.....
   .....XX..............XX..XX.....
   .....XX..XXXXXXXXXXXXXX..XX.....
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uM

   player0x = 49 : player0y = 56

   playfield:
   ................................
   ................................
   .......XXXXXXXXX................
   .....XXXXXXXXXXXXX..............
   .....XXXXXXXXXXXXX..............
   .....XXXXXXXXXXXXX......XXX.....
   .....XXX..XXXXXXX......XXXXX....
   ......XX..XXXXXX.......XXXXX....
   ................................
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uN

   player0x = 85 : player0y = 56

   playfield:
   ................................
   ................................
   .................XXXXXX.........
   ...............XXXXXXXXXX.......
   ..............XXXXXXXXXXXX......
   .....XX.......XXXXXXXXXXXX......
   ....XXXX......XXX..XXXXXXX......
   .....XX........XX..XXXXXX.......
   ................................
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uO
   playfield:
   ................................
   ................................
   .....................XXXXX......
   ....................XXXXXXX.....
   .......XXXXX.......XXXXXXXX.....
   ......XXXXXXX......XXXXXXX......
   ......XXXXXXXX......XXXXX.......
   .......XXXXXXX..................
   ........XXXXX...................
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uP
   playfield:
   ................................
   ................................
   .....XXX..XXXXXXXXXXXX..XXX.....
   .....XXX..XXXXXXXXXXXX..XXX.....
   .....XXX..XXXXXXXXXXXX..XXX.....
   .....XXX................XXX.....
   .....XXX................XXX.....
   .....XXXXXXXXXXXXXXXXXXXXXX.....
   ................................
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uQ
   playfield:
   ................................
   ................................
   .........XXX........XXX.........
   .......XXXXXXX....XXXXXXX.......
   .......XX...XX....XX...XX.......
   .......XX...XX....XX...XX.......
   .......XX...XX....XX...XX.......
   .......XXXXXXX....XXXXXXX.......
   .........XXX........XXX.........
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uR
   playfield:
   ................................
   ................................
   .....XXXX..XXXX..XXXXXXXXXX.....
   .....XXXX..XXXX..XXXXXXXXXX.....
   .......XX..XX...................
   .......XX..XX...................
   .....XXXX..XXXX..XXXXXXXXXX.....
   .....XXXX..XXXX..XXXXXXXXXX.....
   ................................
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uS
   playfield:
   ................................
   ................................
   .....XXXXXXXXXX..XXXXXXXXXX.....
   .....XXXXXXXXXX..XXXXXXXXXX.....
   ............XXX..XXX............
   ............XXX..XXX............
   .....XXXXXXXXXX..XXXXXXXXXX.....
   ...........XXXX..XXXX...........
   ............XXX..XXX............
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uT
   playfield:
   ................................
   ................................
   .....XXX..XXXXX..XXXXX..XXX.....
   .....XXX..XXXXX..XXXXX..XXX.....
   ..........X...X..X...X..........
   ..........X...X..X...X..........
   .....XXX..XXXXX..XXXXX..XXX.....
   .....XXX..XXXXX..XXXXX..XXX.....
   .....XXX..XXXXX..XXXXX..XXX.....
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uU
   playfield:
   ................................
   ................................
   ........XXX..XX..XX..XXX........
   ......XXXXX..XX..XX..XXXXX......
   .....XXXXXX..XX..XX..XXXXXX.....
   ....XXXXXXX..XX..XX..XXXXXXX....
   .....XXXXXX..XX..XX..XXXXXX.....
   ......XXXXX..XX..XX..XXXXX......
   ........XXX..XX..XX..XXX........
   ................................
   ................................
end

   goto __Done_Next_Room bank2


__uV
   playfield:
   ................................
   ................................
   .....XXXXXXXXXX..XXXXXXXXXX.....
   .....XX.......X..X.......XX.....
   .....XX.......X..X.......XX.....
   ..............X..X..............
   ..............X..X..............
   .....XX.......X..X.......XX.....
   .....XXXXXXXXXX..XXXXXXXXXX.....
   ................................
   ................................
end

   goto __Done_Next_Room bank2





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Playfield background color data.
   ;
   data _Data_Under_Background_Color
   _00
   _00
   _02
   _02
   _00
   _00
   _02
   _02

   _00
   _00
   _02
   _02
   _00
   _00
   _02
   _02

   _00
   _00
   _02
   _02
   _00
   _00
   _02
   _02

   _00
   _00
   _02
   _02
   _00
   _00
   _02
   _02
end



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Playfield foreground color data.
   ;
   data _Data_Under_Foreground_Color
   _B6
   _36
   _E6
   _06
   _16
   _B6
   _C6
   _96

   _96
   _66
   _C6
   _36
   _06
   _96
   _C6
   _26

   _16
   _96
   _B6
   _C6
   _26
   _46
   _66
   _36

   _06
   _16
   _96
   _46
   _36
   _E6
   _46
   _26
end




   bank 4

 

 

 

Tinkernut World Deluxe

Tinkernut World Deluxe on bB page.

 
   ;****************************************************************
   ;
   ;  Tinkernut World Deluxe With Lives Bar
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) made by
   ;  adapting the original Tinkernut World from www.tinkernut.com
   ;  and using hints, tips, code snippets, and more from AtariAge
   ;  members such as batari, SeaGtGruff, RevEng, Robert M, Nukey
   ;  Shay, Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;  High score code provided by supercat and polished up by
   ;  Nukey Shay.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Shoot the squirrel before he eats you.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  _Master_Counter can be used for many things, but it is 
   ;  really useful for animating sprite frames when used
   ;  with _Frame_Counter.
   ;
   dim _Master_Counter = a
   dim _Frame_Counter = b

   ;```````````````````````````````````````````````````````````````
   ;  Sound variables.
   ;
   dim _Ch0_Sound = c
   dim _Ch0_Counter = d
   dim _C0 = e
   dim _V0 = f
   dim _F0 = g

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used in the pause loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _Pause_Counter_Tmp = h

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used for auto-play in the main loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _AP_2_Sec_Score_Flip = i

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used in the pause loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _Pause_Mem_Color_Tmp = i

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used for auto-play in the main loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _AP_Dir_Counter = j

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used in the pause loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _Pause_Color_Tmp = j

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _BitOp_02 = r

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the position of the BW switch.
   ;
   dim _Bit0_BW_Mem = r

   ;```````````````````````````````````````````````````````````````
   ;  Checks to see if the BW switch has moved.
   ;
   dim _Bit1_BW_Check = r

   ;```````````````````````````````````````````````````````````````
   ;  Lets pause section know if the B color scheme should be used.
   ;
   dim _Bit2_Pause_Clr_Scheme = r

   ;```````````````````````````````````````````````````````````````
   ;  Auto-play direction bit for player0 sprite.
   ;
   dim _Bit3_AP_P0_Dir = r

   ;```````````````````````````````````````````````````````````````
   ;  Converts 6 digit score to 3 sets of two digits.
   ;
   ;  The 100 thousands and 10 thousands digits are held by _sc1.
   ;  The thousands and hundreds digits are held by _sc2.
   ;  The tens and ones digits are held by _sc3.
   ;
   dim _sc1 = score
   dim _sc2 = score+1
   dim _sc3 = score+2

   ;```````````````````````````````````````````````````````````````
   ;  These can be used for other things using different aliases,
   ;  but for the game over loop and auto-play in the main loop,
   ;  they are used to temporarily remember the score for the 2
   ;  second score/high score flip.
   ;
   dim _Score1_Mem = s
   dim _Score2_Mem = t
   dim _Score3_Mem = u

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the high score until the game is turned off.
   ;
   dim _High_Score1 = v
   dim _High_Score2 = w
   dim _High_Score3 = x

   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y
   dim _Bit1_FireB_Restrainer = y
   dim _Bit2_Game_Control = y
   dim _Bit3_Auto_Play = y
   dim _Bit6_Swap_Scores = y
   dim _Bit7_Last_Life = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers. 
   ;
   dim rand16 = z



   ;***************************************************************
   ;
   ;  Turns on pfscore bars.
   ;
   const pfscore = 1



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for an 8 x 8 sprite.
   ;  If your sprite is a different size, you'll need to adjust
   ;  the numbers.
   ;
   const _P_Edge_Top = 10
   const _P_Edge_Bottom = 83
   const _P_Edge_Left = 1
   const _P_Edge_Right = 153





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears 21 of the normal 26 variables (fastest way).
   ;  Do not clear v, w, x, y, or z in this program. The variables
   ;  v through x remember the high score. The variable y holds a
   ;  bit that should not be cleared. The variable z is used for
   ;  random numbers in this program and clearing it would mess
   ;  up those random numbers.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0


   ;***************************************************************
   ;
   ;  Clears 7 of the 8 bits.
   ;
   ;  Bit 2 is not cleared because _Bit2_Game_Control{2} is used
   ;  to control how the program is reset.
   ;
   _BitOp_01 = _BitOp_01 & %00000100


   ;***************************************************************
   ;
   ;  Makes sure sprites and missile are off the screen.
   ;
   player0y = 200 : player1y = 200 : missile0y = 200


   ;***************************************************************
   ;
   ;  Skips title screen if game has been played and player
   ;  presses fire button or reset switch at the end of the game.
   ;
   ;  0 = Go to title screen.
   ;  1 = Skip title screen and play game.
   ;
   if _Bit2_Game_Control{2} then goto __Main_Loop_Setup





   ;***************************************************************
   ;***************************************************************
   ;
   ;   TITLE SCREEN SETUP
   ;
   ;
__Setup_Title_Screen


   ;***************************************************************
   ;
   ;  Clears lives and sets score color.
   ;
   pfscore1 = 0 : scorecolor = $20


   ;***************************************************************
   ;
   ;  Sets title screen background color.
   ;
   COLUBK = $20


   ;***************************************************************
   ;
   ;  Restrains the reset switch.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after entering a different segment
   ;  of the program. It also does double duty by restraining the
   ;  fire button in the title screen loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets up title screen playfield.
   ;
   playfield:
   XXX.X..X.X.X.XX.XX..X..X.X.X.XXX
   .X..X..X.X.X.X..X.X.X..X.X.X..X.
   .X..XX.X.XX..XX.XX..XX.X.X.X..X.
   .X..X.XX.X.X.X..X.X.X.XX.X.X..X.
   .X..X..X.X.X.XX.X.X.X..X.XXX..X.
   ................................
   ....X...X.XXXX.XXX..X...XXX.....
   ....X...X.X..X.X..X.X...X..X....
   ....X...X.X..X.XX...X...X..X....
   ....X.X.X.X..X.X.X..X...X..X....
   ....XX.XX.XXXX.X..X.XXX.XXX.....
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  TITLE SCREEN LOOP
   ;
   ;
__Title_Screen_Loop



   ;***************************************************************
   ;
   ;  Sets title screen playfield pixel color.
   ;
   COLUPF = $D8



   ;***************************************************************
   ;
   ;  Auto-play check.
   ;
   ;  Switches to auto-play after 10 seconds if player doesn't
   ;  start the game.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increment _Master_Counter.
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if counter is less than one second.
   ;
   if _Master_Counter < 60 then goto __TS_AP_Skip

   ;```````````````````````````````````````````````````````````````
   ;  Increments _Frame_Counter and clears _Master_Counter.
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check.
   ;
   ;  Turns on auto-play and jumps to main loop setup if 10 
   ;  seconds have gone by.
   ;
   if _Frame_Counter > 9 then _Bit3_Auto_Play{3} = 1 : goto __Main_Loop_Setup

__TS_AP_Skip



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset/fire button check and end of title screen loop.
   ;  
   ;  Starts the game if the reset switch or the fire button
   ;  is pressed appropriately.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and jumps to beginning of title 
   ;  screen loop if fire button or reset switch is not pressed.
   ;
   if !switchreset && !joy0fire then _Bit0_Reset_Restrainer{0} = 0 : goto __Title_Screen_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of title screen loop if reset or fire 
   ;  hasn't been released since starting title screen loop.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Title_Screen_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Sets control bit so program will jump to main loop setup.
   ;
   _Bit2_Game_Control{2} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Restarts game and program jumps to main loop setup.
   ;
   goto __Start_Restart





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP SETUP
   ;
   ;
__Main_Loop_Setup


   ;***************************************************************
   ;
   ;  In the main loop, _Bit2_Game_Control{2} controls when the
   ;  game ends.
   ;
   ;  0 = Game not over.
   ;  1 = Game over.
   ;
   _Bit2_Game_Control{2} = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed in the title
   ;  screen section or the game over section. If the reset
   ;  switch isn't being held down, this bit will be cleared
   ;  in the main loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Restrains the fire button for the main loop.
   ;
   ;  This bit fixes it so the fire button becomes inactive if it
   ;  hasn't been released after being pressed in the title
   ;  screen section or the game over section. If the fire
   ;  button isn't being held down, this bit will be cleared
   ;  in the main loop.
   ;
   _Bit1_FireB_Restrainer{1} = 1


   ;***************************************************************
   ;
   ;  Starting position of player0 (acorn).
   ;
   player0x = 74 : player0y = 78


   ;***************************************************************
   ;
   ;  Starting position of player1 (squirrel).
   ;
   player1x = (rand/2) + (rand&15) : player1y = 0 


   ;***************************************************************
   ;
   ;  Defines missile0 height and location.
   ;
   missile0height = 4 : missile0y = 250


   ;***************************************************************
   ;
   ;  Sets score color.
   ;
   scorecolor = $1C


   ;***************************************************************
   ;
   ;  Sets number of lives and sets color.
   ;
   pfscore1 = %01010101 : pfscorecolor = $D2


   ;***************************************************************
   ;
   ;  Defines shape of player0 sprite.
   ;
   player0:
   %00011000
   %00111100
   %00111100
   %01111110
   %01111110
   %11111111
   %01111110
   %00011000
end


   ;***************************************************************
   ;
   ;  Sets up the main loop playfield.
   ;
   playfield:
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   ...............................
   ...............................
   ...............................
   ...............................
   ...............................
   ...............................
   ...............................
   ...............................
   ...............................
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end


   ;***************************************************************
   ;
   ;  Remembers position of COLOR/BW switch.
   ;
   _Bit0_BW_Mem{0} = 0 : if switchbw then _Bit0_BW_Mem{0} = 1


   ;***************************************************************
   ;
   ;  Auto-play score swap setup.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears score and skips section if auto-play is off.
   ;
   if !_Bit3_Auto_Play{3} then score = 0 : goto __AP_Skip_AP_Setup

   ;```````````````````````````````````````````````````````````````
   ;  Clears variables.
   ;
   _Master_Counter = 0 : _Frame_Counter = 0 

   ;```````````````````````````````````````````````````````````````
   ;  Sets up the score swap and clears the swap bit.
   ;
   _Score1_Mem = _sc1 : _Score2_Mem = _sc2 : _Score3_Mem = _sc3

   _Bit6_Swap_Scores{6} = 0

__AP_Skip_AP_Setup





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE GAME GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = $D6



   ;***************************************************************
   ;
   ;  Sets playfield pixel color.
   ;
   COLUPF = 0



   ;***************************************************************
   ;
   ;  Sets sprite colors.
   ;
   COLUP0 = $22 : COLUP1 = $20



   ;***************************************************************
   ;
   ;  Makes missile0 a little wider.
   ;
   NUSIZ0 = $10



   ;***************************************************************
   ;
   ;  Makes squirrel wider.
   ;
   NUSIZ1 = $05



   ;***************************************************************
   ;
   ;  Animation counters.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments _Master_Counter.
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if _Master_Counter is less than 7.
   ;
   if _Master_Counter < 7 then goto __Skip_Counters

   ;```````````````````````````````````````````````````````````````
   ;  Increments _Frame_Counter and clears _Master_Counter.
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Clears _Frame_Counter if it is greater than 3.
   ;
   if _Frame_Counter > 3 then _Frame_Counter = 0

__Skip_Counters



   ;***************************************************************
   ;
   ;  Squirrel animation (4 frames, 0 through 3).
   ;
   on _Frame_Counter goto __Sq00 __Sq01 __Sq02 __Sq03

__Squirrel_Frame_Done



   ;***************************************************************
   ;
   ;  Missile0 check and fire button check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps to fire button check if missile0 is off the screen.
   ;
   if missile0y > 240 then goto __FireB_Check

   ;```````````````````````````````````````````````````````````````
   ;  Moves missile0 and skips fire button check.
   ;
   missile0y = missile0y - 2 : goto __Skip_FireB

__FireB_Check

   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if auto-play is off.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Fire_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Determines if sprite should fire during auto-play.
   ;  There is a 90% chance that the missile will not fire.
   ;
   temp5 = rand : if temp5 < 230 then goto __Skip_FireB

   goto __AP_Fire

__AP_Skip_Fire_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and skips this section if fire
   ;  button is not pressed.
   ;
   if !joy0fire then _Bit1_FireB_Restrainer{1} = 0 : goto __Skip_FireB

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if fire button hasn't been released since
   ;  the title screen.
   ;
   if _Bit1_FireB_Restrainer{1} then goto __Skip_FireB

__AP_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Starts the firing of missile0.
   ;
   missile0y = player0y - 2 : missile0x = player0x + 4

__Skip_FireB



   ;***************************************************************
   ;
   ;  Auto-play direction change for player0 sprite.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if auto-play is off.

   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_New_Dir

   ;```````````````````````````````````````````````````````````````
   ;  Adds to the auto-play direction change counter.
   ;
   _AP_Dir_Counter = _AP_Dir_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Grabs a random number (0 to 63) and adds 50. Change 50 to a
   ;  larger number if you want the sprite to move longer before
   ;  changing directions. Don't use a number larger than 190.
   ;
   temp6 = (rand&63) + 50

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the counter isn't high enough.
   ;
   if _AP_Dir_Counter < temp6 then goto __AP_Move_Acorn

   ;```````````````````````````````````````````````````````````````
   ;  Grabs a random number (0 to 255).
   ;
   temp5 = rand

   ;```````````````````````````````````````````````````````````````
   ;  There is a 90% chance that this section will be skipped.
   ;
   if temp5 < 230 then goto __AP_Move_Acorn

   ;```````````````````````````````````````````````````````````````
   ;  Changes player0 direction.
   ;
   _Bit3_AP_P0_Dir{3} = !_Bit3_AP_P0_Dir{3}

   ;```````````````````````````````````````````````````````````````
   ;  Clears counter.
   ;
   _AP_Dir_Counter = 0

__AP_Move_Acorn

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 sprite.
   ;
   if !_Bit3_AP_P0_Dir{3} then if player0x > _P_Edge_Left then player0x = player0x - 1
   if _Bit3_AP_P0_Dir{3} then if player0x < _P_Edge_Right then player0x = player0x + 1

   goto __Skip_Joy_Movement

__AP_Skip_New_Dir



   ;***************************************************************
   ;
   ;  Joystick movement check. This section is skipped if
   ;  auto-play is on.
   ;
   if joy0up then if player0y > _P_Edge_Top then player0y = player0y - 1
   if joy0down then if player0y < _P_Edge_Bottom then player0y = player0y + 1
   if joy0left then if player0x > _P_Edge_Left then player0x = player0x - 1
   if joy0right then if player0x < _P_Edge_Right then player0x = player0x + 1

__Skip_Joy_Movement



   ;***************************************************************
   ;
   ;  Squirrel chases the player.
   ;
   if player1y < player0y then player1y = player1y + 1
   if player1y > player0y then player1y = player1y - 1
   temp5 = player1x + 8 : if temp5 < player0x then if player1x < 144 then player1x = player1x + 1
   temp5 = player1x + 8 : if temp5 > player0x then if player1x > 0 then player1x = player1x - 1



   ;***************************************************************
   ;
   ;  Squirrel/missile0 collision check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if there is no collision.
   ;
   if !collision(missile0,player1) then goto __Skip_Squirrel_Kill

   ;```````````````````````````````````````````````````````````````
   ;  Temporarily remembers squirrel's y position.
   ;
   temp6 = player1y

   ;```````````````````````````````````````````````````````````````
   ;  Moves squirrel to new location and removes missile.
   ;
   player1x = (rand/2) + (rand&15) : player1y = 0 : missile0y = 250

   ;```````````````````````````````````````````````````````````````
   ;  Skips sound and points if auto-play is on.
   ;
   if _Bit3_Auto_Play{3} then goto __Skip_Squirrel_Kill

   ;```````````````````````````````````````````````````````````````
   ;  Adds 1 to the score.
   ;
   score = score + 1

   ;```````````````````````````````````````````````````````````````
   ;  Sound effect 1 setup.
   ;
   if _Ch0_Sound then goto __Skip_Squirrel_Kill

   _Ch0_Sound = 1 : _Ch0_Counter = 10

   _C0 = 4 : _V0 = 12 : _F0 = 14

   ;```````````````````````````````````````````````````````````````
   ;  Makes a different sound when closer to player.
   ;
   temp5 = 255 : if player0y > temp6 then temp5 = player0y - temp6

   if temp5 < 30 then _C0 = 12

__Skip_Squirrel_Kill



   ;***************************************************************
   ;
   ;  Squirrel/acorn collision check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if there is no collision.
   ;
   if !collision(player0,player1) then goto __Skip_Acorn_Eaten

   ;```````````````````````````````````````````````````````````````
   ;  Activates last life bit if pfscore1 bar is empty. Also ends
   ;  auto-play if it's on.
   ;
   if !pfscore1 then _Bit7_Last_Life{7} = 1 : if _Bit3_Auto_Play{3} then _Bit2_Game_Control{2} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Deletes a life.
   ;
   if pfscore1 then pfscore1 = pfscore1/4

   ;```````````````````````````````````````````````````````````````
   ;  Moves squirrel to new location and removes missile.
   ;
   player1x = (rand/2) + (rand&15) : player1y = 0 : missile0y = 250

   ;```````````````````````````````````````````````````````````````
   ;  Skips sound effect and score if auto-play is on.
   ;
   if _Bit3_Auto_Play{3} then goto __Skip_Acorn_Eaten

   ;```````````````````````````````````````````````````````````````
   ;  Subtracts 1 from the score.
   ;
   if _sc3 > 0 then score = score - 1

   ;```````````````````````````````````````````````````````````````
   ;  Sound effect 2 setup.
   ;
   if _Ch0_Sound then goto __Skip_Acorn_Eaten

   _Ch0_Sound = 2 : _Ch0_Counter = 10

   _C0 = 7 : _V0 = 12 : _F0 = 12

__Skip_Acorn_Eaten



   ;***************************************************************
   ;
   ;  Point sound.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the sound isn't on.
   ;
   if _Ch0_Sound <> 1 then goto __Skip_Sound1

   ;```````````````````````````````````````````````````````````````
   ;  Flips the frequency between 11 and 14.
   ;
   _F0 = _F0 ^ 5

   ;```````````````````````````````````````````````````````````````
   ;  Sets the tone, volume and frequency.
   ;
   AUDC0 = _C0 : AUDV0 = _V0 : AUDF0 = _F0

   ;```````````````````````````````````````````````````````````````
   ;  Decreases volume by 1 and makes sure it doesn't go below 2.
   ;
   _V0 = _V0 - 1 : if _V0 < 2 then _V0 = 2

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the sound counter.
   ;
   _Ch0_Counter = _Ch0_Counter - 1

   ;```````````````````````````````````````````````````````````````
   ;  Clears _Ch0_Sound and mutes channel if sound counter is zero.
   ;
   if !_Ch0_Counter then _Ch0_Sound = 0 : AUDV0 = 0

__Skip_Sound1



   ;***************************************************************
   ;
   ;  Squirrel eats acorn sound.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the sound isn't on.
   ;
   if _Ch0_Sound <> 2 then goto __Skip_Sound2

   ;```````````````````````````````````````````````````````````````
   ;  Sets the tone, volume and frequency.
   ;
   AUDC0 = _C0 : AUDV0 = _V0 : AUDF0 = _F0

   ;```````````````````````````````````````````````````````````````
   ;  Decreases volume by 1 and makes sure it doesn't go below 2.
   ;
   _V0 = _V0 - 1 : if _V0 < 2 then _V0 = 2

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the sound counter.
   ;
   _Ch0_Counter = _Ch0_Counter - 1

   ;```````````````````````````````````````````````````````````````
   ;  Clears _Ch0_Sound and mutes channel if sound counter is zero.
   ;  Also tells game to end if last life is lost.
   ;
   if !_Ch0_Counter then _Ch0_Sound = 0 : AUDV0 = 0 : if _Bit7_Last_Life{7} then _Bit2_Game_Control{2} = 1

__Skip_Sound2



   ;***************************************************************
   ;
   ;  Auto-play score flipper.
   ;
   ;  Flips between high score and current score.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if auto-play bit is not on.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Flip

   ;```````````````````````````````````````````````````````````````
   ;  Increments the auto play 2-second counter.
   ;
   _AP_2_Sec_Score_Flip = _AP_2_Sec_Score_Flip + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if auto play 2-second counter is less
   ;  than 2 seconds (120 = 2 seconds).
   ;
   if _AP_2_Sec_Score_Flip < 120 then goto __AP_Skip_Flip

   ;```````````````````````````````````````````````````````````````
   ;  Clears the 2-second counter and flips the score swapping bit.
   ;
   _AP_2_Sec_Score_Flip = 0 : _Bit6_Swap_Scores{6} = !_Bit6_Swap_Scores{6}

   ;```````````````````````````````````````````````````````````````
   ;  Skips high score swap if swap bit is off.
   ;
   if !_Bit6_Swap_Scores{6} then goto __AP_Skip_HiScore_Swap

   ;```````````````````````````````````````````````````````````````
   ;  Displays high score (blue) and skips rest of section.
   ;
   scorecolor = $AE

   _sc1 = _High_Score1 : _sc2 = _High_Score2 : _sc3 = _High_Score3

   goto __AP_Skip_Flip

__AP_Skip_HiScore_Swap

   ;```````````````````````````````````````````````````````````````
   ;  Displays current score (yellow).
   ;
   scorecolor = $1C

   _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem

__AP_Skip_Flip



   ;***************************************************************
   ;
   ;  Pause check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if auto-play is on.
   ;
   if _Bit3_Auto_Play{3} then goto __AP_Skip_Pause

   ;```````````````````````````````````````````````````````````````
   ;  Checks current position of COLOR/BW switch.
   ;
   _Bit1_BW_Check{1} = 0

   if switchbw then _Bit1_BW_Check{1} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Compares bits to see if COLOR/BW switch has moved.
   ;  The game is paused if the switch has moved.
   ;
   if _Bit0_BW_Mem{0} then if !_Bit1_BW_Check{1} then goto __Pause_Setup

   if !_Bit0_BW_Mem{0} then if _Bit1_BW_Check{1} then goto __Pause_Setup

   ;```````````````````````````````````````````````````````````````
   ;  Pauses game if fire button of second joystick is pressed.
   ;
   if joy1fire && !_Bit1_FireB_Restrainer{1} then goto __Pause_Setup

__AP_Skip_Pause



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Game Over Check
   ;
   ;  _Bit2_Game_Control{2} controls when the game ends.
   ;
   ;  0 = Game not over.
   ;  1 = Game over.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if game control bit is off.
   ;
   if !_Bit2_Game_Control{2} then goto __Skip_Check_G_Over

   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check. Puts score back to current score and jumps
   ;  back to the title screen if auto-play bit is on.
   ;
   if _Bit3_Auto_Play{3} then _Bit2_Game_Control{2} = 0 : _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem : goto __Start_Restart

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to game over set up.
   ;
   goto __Game_Over_Setup

__Skip_Check_G_Over



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Reset

   ;```````````````````````````````````````````````````````````````
   ;  Starts game during auto-play if reset switch or fire button
   ;  is pressed. Also clears auto-play bit and sets game control
   ;  bit so game will start instead of going to title screen.
   ;
   if switchreset || joy0fire then _Bit3_Auto_Play{3} = 0 : _Bit2_Game_Control{2} = 1 : goto __Start_Restart

__AP_Skip_Reset

   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Clears the game over bit so the title screen will appear.
   ;
   _Bit2_Game_Control{2} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the game over setup section and checks for a high
   ;  score, then jumps to the title screen.
   ;
   goto __Game_Over_Setup




   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;
   ;  Squirrel animation frames.
   ;
__Sq00
   player1:
   %00001010
   %00001110
   %00110011
   %01110100
end

   goto __Squirrel_Frame_Done


__Sq01
   player1:
   %00001001
   %00001110
   %00110011
   %01110100
end

   goto __Squirrel_Frame_Done


__Sq02
   player1:
   %00010001
   %00001110
   %00110011
   %01110100
end

   goto __Squirrel_Frame_Done


__Sq03
   player1:
   %00010010
   %00001110
   %00110011
   %01110100
end

   goto __Squirrel_Frame_Done





   ;***************************************************************
   ;***************************************************************
   ;
   ;  GAME OVER SETUP
   ;
   ;
__Game_Over_Setup


   ;***************************************************************
   ;
   ;  High score check.
   ;
   ;  Checks for a new high score.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Checks first byte.
   ;
   if _sc1 > _High_Score1 then goto __New_High_Score
   if _sc1 < _High_Score1 then goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  First byte equal. Checks second byte.
   ;
   if _sc2 > _High_Score2 then goto __New_High_Score
   if _sc2 < _High_Score2 then goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  Second byte equal. Checks third byte.
   ;
   if _sc3 > _High_Score3 then goto __New_High_Score
   if _sc3 < _High_Score3 then goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  All bytes equal. Skips high score.
   ;
   goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  All bytes not equal. New high score!
   ;
__New_High_Score

   _High_Score1 = _sc1 : _High_Score2 = _sc2 : _High_Score3 = _sc3

__Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the game if the reset switch was pressed. Continues
   ;  in the game over setup section if the game ended naturally.
   ;
   if !_Bit2_Game_Control{2} then goto __Start_Restart


   ;***************************************************************
   ;
   ;  Saves the latest score for the high score flip.
   ;
   _Score1_Mem = _sc1 : _Score2_Mem = _sc2 : _Score3_Mem = _sc3


   ;***************************************************************
   ;
   ;  Clears the counters.
   ;
   _Master_Counter = 0 : _Frame_Counter = 0


   ;***************************************************************
   ;
   ;  Makes sure sprites and missile are off the screen.
   ;
   player0y = 200 : player1y = 200 : missile0y = 200


   ;***************************************************************
   ;
   ;  Restrains reset switch and fire button for game over loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after entering a different segment
   ;  of the program. It also does double duty by restraining the
   ;  fire button in the game over loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets up game over playfield.
   ;
   playfield:
   .XXXXXX.XXXXXX.XXXXXXXXXX.XXXXX.
   .XX.....XX..XX.XX..XX..XX.XX....
   .XX.XXX.XXXXXX.XX..XX..XX.XXXX..
   .XX..XX.XX..XX.XX..XX..XX.XX....
   .XXXXXX.XX..XX.XX..XX..XX.XXXXX.
   ................................
   ...XXXXXX.XX..XX.XXXXX.XXXXXX...
   ...XX..XX.XX..XX.XX....XX..XX...
   ...XX..XX.XX..XX.XXXX..XXXXX....
   ...XX..XX.XX..XX.XX....XX..XX...
   ...XXXXXX...XX...XXXXX.XX..XX...
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  GAME OVER LOOP
   ;
   ;
__Game_Over_Loop



   ;***************************************************************
   ;
   ;  20 second counter.
   ;
   ;  This includes a 2 second countdown timer. Any Atari 2600
   ;  game should disable the fire button for 2 seconds when
   ;  the game is over to keep the player from restarting by
   ;  mistake. It is part of the usual standards and procedures.
   ;
   ;  This section also flips between the current score and the
   ;  high score every 2 seconds. It jumps to the title screen
   ;  after 20 seconds if the player does nothing.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments master counter every frame (60 frames = 1 second).
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if master counter is less than 2 seconds.
   ;  The master counter resets every 2 seconds (60 + 60 = 120).
   ;
   if _Master_Counter < 120 then goto __Skip_20_Second_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Increments frame counter and clears master counter.
   ;  (One increment = 2 seconds.)
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Restores the current score, resets the game, and goes to the
   ;  title screen if 20 seconds have gone by.
   ;
   ;  0 = Go to title screen.
   ;  1 = Skip title screen and play game.
   ;
   if _Frame_Counter > 9 then _Bit2_Game_Control{2} = 0 : _sc1=_Score1_Mem : _sc2=_Score2_Mem : _sc3=_Score3_Mem: goto __Start_Restart

   ;```````````````````````````````````````````````````````````````
   ;  Flips the score swapping bit.
   ;
   _Bit6_Swap_Scores{6} = !_Bit6_Swap_Scores{6}

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to current score if swap bit is off.
   ;
   if !_Bit6_Swap_Scores{6} then goto __GO_Current_Score

   ;```````````````````````````````````````````````````````````````
   ;  Displays high score (blue) and skips rest of section.
   ;
   scorecolor = $AE

   _sc1 = _High_Score1 : _sc2 = _High_Score2 : _sc3 = _High_Score3

   goto __Skip_20_Second_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Displays current score (yellow).
   ;
__GO_Current_Score

   scorecolor = $1C

   _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem

__Skip_20_Second_Counter



   ;***************************************************************
   ;
   ;  Sets background color and playfield color.
   ;
   COLUBK = $44 : COLUPF = $2C

   ;```````````````````````````````````````````````````````````````
   ;  Changes colors after 2 seconds. This is only done to let
   ;  you, the programmer, know when 2 seconds have gone by. The
   ;  color change doesn't need to happen in a real game.
   ;
   if _Frame_Counter > 0 then COLUBK = $D2 : COLUPF = $DA



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset/fire button check and end of GAME OVER loop.
   ;  
   ;  Restarts the program if the reset switch or the fire
   ;  button is pressed appropriately.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the game over loop if the initial
   ;  2 second freeze is not over.
   ;
   if _Frame_Counter = 0 then goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and jumps to beginning of game
   ;  over loop if fire button or reset switch is not pressed.
   ;
   if !switchreset && !joy0fire then _Bit0_Reset_Restrainer{0} = 0 : goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the game over loop if fire button
   ;  hasn't been released since leaving the main loop.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  The program is restarted.
   ;
   goto __Start_Restart





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF GAME OVER LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PAUSE SETUP
   ;
__Pause_Setup


   ;***************************************************************
   ;
   ;  Mutes the sound.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Restrains the fire button for the pause loop.
   ;
   _Bit1_FireB_Restrainer{1} = 1


   ;***************************************************************
   ;
   ;  Clears the pause counter.
   ;
   _Pause_Counter_Tmp = 0


   ;***************************************************************
   ;
   ;  Selects a random color scheme.
   ;
   _Pause_Color_Tmp = (rand&7)

   _Pause_Mem_Color_Tmp = _Pause_Color_Tmp





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PAUSE LOOP
   ;
__Pause_Game



   ;***************************************************************
   ;
   ;  Makes missile0 a little wider.
   ;
   NUSIZ0 = $10



   ;***************************************************************
   ;
   ;  Makes squirrel wider.
   ;
   NUSIZ1 = $05



   ;***************************************************************
   ;
   ;  Changes color scheme every 4 seconds.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increases the pause counter.
   ;
   _Pause_Counter_Tmp = _Pause_Counter_Tmp + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if counter isn't high enough.
   ;
   if _Pause_Counter_Tmp < 240 then goto __Skip_Pause_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Resets the pause counter.
   ;
   _Pause_Counter_Tmp = 0

   ;```````````````````````````````````````````````````````````````
   ;  Gets a random number from 0 to 7.
   ;
   _Pause_Color_Tmp = (rand&7)

   ;```````````````````````````````````````````````````````````````
   ;  Compares the new color scheme with the previous color scheme
   ;  and selects a new color scheme if they are the same.
   ;
   if _Pause_Color_Tmp = _Pause_Mem_Color_Tmp then _Pause_Color_Tmp = _Pause_Color_Tmp + (rand&3) + 1 : if _Pause_Color_Tmp > 7 then _Pause_Color_Tmp = _Pause_Color_Tmp - 8

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the new color scheme.
   ;
   _Pause_Mem_Color_Tmp = _Pause_Color_Tmp

   ;```````````````````````````````````````````````````````````````
   ;  Decides if the B color scheme should be used.
   ;
   _Bit2_Pause_Clr_Scheme{2} = 0

    temp5 = rand : if temp5 < 128 then _Bit2_Pause_Clr_Scheme{2} = 1

__Skip_Pause_Counter



   ;***************************************************************
   ;
   ;  Jumps to the latest color scheme.
   ;
   on _Pause_Color_Tmp goto __Ps0 __Ps1 __Ps2 __Ps3 __Ps4 __Ps5 __Ps6 __Ps7

__Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Unpause check and end of pause loop.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the pause loop if the fire button
   ;  isn't pressed. Also clears the restrainer bit.
   ;
   if !joy0fire then _Bit1_FireB_Restrainer{1} = 0 : goto __Pause_Game

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the pause loop if the fire button
   ;  hasn't been released since starting the pause loop.
   ;
   if _Bit1_FireB_Restrainer{1} then goto __Pause_Game

   ;```````````````````````````````````````````````````````````````
   ;  Remembers position of COLOR/BW switch.
   ;
   _Bit0_BW_Mem{0} = 0 : if switchbw then _Bit0_BW_Mem{0} = 1





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF PAUSE LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;  RESTORES GAME FROM PAUSE
   ;
   ;  Puts everything back the way it was.
   ;
__Restore_Game_from_Pause


   ;***************************************************************
   ;
   ;  Restrains the fire button for the main loop.
   ;
   _Bit1_FireB_Restrainer{1} = 1


   ;***************************************************************
   ;
   ;  Restores score color and more.
   ;
   scorecolor = $1C : pfscorecolor = $D2


   goto __Main_Loop





   ;***************************************************************
   ;
   ;  Sets pause colors to gray.
   ;
__Ps0

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps0B

   COLUPF = $0C : COLUP0 = $0C : COLUP1 = $0C : pfscorecolor = $0C : scorecolor = $0C

   COLUBK = $0A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to gray.
   ;
__Ps0B

   COLUPF = $0A : COLUP0 = $0A : COLUP1 = $0A : pfscorecolor = $0A : scorecolor = $0A

   COLUBK = $0C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to reddish-orange.
   ;
__Ps1

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps1B

   COLUPF = $3C : COLUP0 = $3C : COLUP1 = $3C : pfscorecolor = $3C : scorecolor = $3C

   COLUBK = $3A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to reddish-orange.
   ;
__Ps1B

   COLUPF = $3A : COLUP0 = $3A : COLUP1 = $3A : pfscorecolor = $3A : scorecolor = $3A

   COLUBK = $3C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to purple.
   ;
__Ps2

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps2B

   COLUPF = $6C : COLUP0 = $6C : COLUP1 = $6C : pfscorecolor = $6C : scorecolor = $6C

   COLUBK = $6A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to purple.
   ;
__Ps2B

   COLUPF = $6A : COLUP0 = $6A : COLUP1 = $6A : pfscorecolor = $6A : scorecolor = $6A



   COLUBK = $6C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to blue.
   ;
__Ps3

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps3B

   COLUPF = $9C : COLUP0 = $9C : COLUP1 = $9C : pfscorecolor = $9C : scorecolor = $9C

   COLUBK = $9A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to blue.
   ;
__Ps3B

   COLUPF = $9A : COLUP0 = $9A : COLUP1 = $9A : pfscorecolor = $9A : scorecolor = $9A

   COLUBK = $9C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to green.
   ;
__Ps4

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps4B

   COLUPF = $CC : COLUP0 = $CC : COLUP1 = $CC : pfscorecolor = $CC : scorecolor = $CC

   COLUBK = $CA

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to green.
   ;
__Ps4B

   COLUPF = $CA : COLUP0 = $CA : COLUP1 = $CA : pfscorecolor = $CA : scorecolor = $CA

   COLUBK = $CC

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to yellowish.
   ;
__Ps5

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps5B

   COLUPF = $FC : COLUP0 = $FC : COLUP1 = $FC : pfscorecolor = $FC : scorecolor = $FC

   COLUBK = $FA

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to yellowish.
   ;
__Ps5B

   COLUPF = $FA : COLUP0 = $FA : COLUP1 = $FA : pfscorecolor = $FA: scorecolor = $FA

   COLUBK = $FC

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to darkish-blue.
   ;
__Ps6

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps6B

   COLUPF = $8C : COLUP0 = $8C : COLUP1 = $8C : pfscorecolor = $8C : scorecolor = $8C

   COLUBK = $8A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to darkish-blue.
   ;
__Ps6B

   COLUPF = $8A : COLUP0 = $8A : COLUP1 = $8A : pfscorecolor = $8A : scorecolor = $8A

   COLUBK = $8C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to orange-brown.
   ;
__Ps7

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps7B

   COLUPF = $2C : COLUP0 = $2C : COLUP1 = $2C : pfscorecolor = $2C : scorecolor = $2C

   COLUBK = $2A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to orange-brown.
   ;
__Ps7B

   COLUPF = $2A : COLUP0 = $2A : COLUP1 = $2A : pfscorecolor = $2A : scorecolor = $2A

   COLUBK = $2C

   goto __Got_Pause_Colors
 
   ;****************************************************************
   ;
   ;  Tinkernut World Deluxe With Health Bar
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) made by
   ;  adapting the original Tinkernut World from www.tinkernut.com
   ;  and using hints, tips, code snippets, and more from AtariAge
   ;  members such as batari, SeaGtGruff, RevEng, Robert M, Nukey
   ;  Shay, Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;  High score code provided by supercat and polished up by
   ;  Nukey Shay.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Shoot the squirrel before he eats you.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  _Master_Counter can be used for many things, but it is 
   ;  really useful for animating sprite frames when used
   ;  with _Frame_Counter.
   ;
   dim _Master_Counter = a
   dim _Frame_Counter = b

   ;```````````````````````````````````````````````````````````````
   ;  Sound variables.
   ;
   dim _Ch0_Sound = c
   dim _Ch0_Counter = d
   dim _C0 = e
   dim _V0 = f
   dim _F0 = g

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used in the pause loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _Pause_Counter_Tmp = h

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used for auto-play in the main loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _AP_2_Sec_Score_Flip = i

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used in the pause loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _Pause_Mem_Color_Tmp = i

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used for auto-play in the main loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _AP_Dir_Counter = j

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used in the pause loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _Pause_Color_Tmp = j

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _BitOp_02 = r

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the position of the BW switch.
   ;
   dim _Bit0_BW_Mem = r

   ;```````````````````````````````````````````````````````````````
   ;  Checks to see if the BW switch has moved.
   ;
   dim _Bit1_BW_Check = r

   ;```````````````````````````````````````````````````````````````
   ;  Lets pause section know if the B color scheme should be used.
   ;
   dim _Bit2_Pause_Clr_Scheme = r

   ;```````````````````````````````````````````````````````````````
   ;  Auto-play direction bit for player0 sprite.
   ;
   dim _Bit3_AP_P0_Dir = r

   ;```````````````````````````````````````````````````````````````
   ;  Converts 6 digit score to 3 sets of two digits.
   ;
   ;  The 100 thousands and 10 thousands digits are held by _sc1.
   ;  The thousands and hundreds digits are held by _sc2.
   ;  The tens and ones digits are held by _sc3.
   ;
   dim _sc1 = score
   dim _sc2 = score+1
   dim _sc3 = score+2

   ;```````````````````````````````````````````````````````````````
   ;  These can be used for other things using different aliases,
   ;  but for the game over loop and auto-play in the main loop,
   ;  they are used to temporarily remember the score for the 2
   ;  second score/high score flip.
   ;
   dim _Score1_Mem = s
   dim _Score2_Mem = t
   dim _Score3_Mem = u

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the high score until the game is turned off.
   ;
   dim _High_Score1 = v
   dim _High_Score2 = w
   dim _High_Score3 = x

   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y
   dim _Bit1_FireB_Restrainer = y
   dim _Bit2_Game_Control = y
   dim _Bit3_Auto_Play = y
   dim _Bit6_Swap_Scores = y
   dim _Bit7_Last_Life = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers. 
   ;
   dim rand16 = z



   ;***************************************************************
   ;
   ;  Turns on pfscore bars.
   ;
   const pfscore = 1



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for an 8 x 8 sprite.
   ;  If your sprite is a different size, you'll need to adjust
   ;  the numbers.
   ;
   const _P_Edge_Top = 10
   const _P_Edge_Bottom = 83
   const _P_Edge_Left = 1
   const _P_Edge_Right = 153





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears 21 of the normal 26 variables (fastest way).
   ;  Do not clear v, w, x, y, or z in this program. The variables
   ;  v through x remember the high score. The variable y holds a
   ;  bit that should not be cleared. The variable z is used for
   ;  random numbers in this program and clearing it would mess
   ;  up those random numbers.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0


   ;***************************************************************
   ;
   ;  Clears 7 of the 8 bits.
   ;
   ;  Bit 2 is not cleared because _Bit2_Game_Control{2} is used
   ;  to control how the program is reset.
   ;
   _BitOp_01 = _BitOp_01 & %00000100


   ;***************************************************************
   ;
   ;  Makes sure sprites and missile are off the screen.
   ;
   player0y = 200 : player1y = 200 : missile0y = 200


   ;***************************************************************
   ;
   ;  Skips title screen if game has been played and player
   ;  presses fire button or reset switch at the end of the game.
   ;
   ;  0 = Go to title screen.
   ;  1 = Skip title screen and play game.
   ;
   if _Bit2_Game_Control{2} then goto __Main_Loop_Setup





   ;***************************************************************
   ;***************************************************************
   ;
   ;   TITLE SCREEN SETUP
   ;
   ;
__Setup_Title_Screen


   ;***************************************************************
   ;
   ;  Clears health bar and sets score color.
   ;
   pfscore1 = 0 : scorecolor = $20


   ;***************************************************************
   ;
   ;  Sets title screen background color.
   ;
   COLUBK = $20


   ;***************************************************************
   ;
   ;  Restrains the reset switch.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after entering a different segment
   ;  of the program. It also does double duty by restraining the
   ;  fire button in the title screen loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets up title screen playfield.
   ;
   playfield:
   XXX.X..X.X.X.XX.XX..X..X.X.X.XXX
   .X..X..X.X.X.X..X.X.X..X.X.X..X.
   .X..XX.X.XX..XX.XX..XX.X.X.X..X.
   .X..X.XX.X.X.X..X.X.X.XX.X.X..X.
   .X..X..X.X.X.XX.X.X.X..X.XXX..X.
   ................................
   ....X...X.XXXX.XXX..X...XXX.....
   ....X...X.X..X.X..X.X...X..X....
   ....X...X.X..X.XX...X...X..X....
   ....X.X.X.X..X.X.X..X...X..X....
   ....XX.XX.XXXX.X..X.XXX.XXX.....
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  TITLE SCREEN LOOP
   ;
   ;
__Title_Screen_Loop



   ;***************************************************************
   ;
   ;  Sets title screen playfield pixel color.
   ;
   COLUPF = $D8



   ;***************************************************************
   ;
   ;  Auto-play check.
   ;
   ;  Switches to auto-play after 10 seconds if player doesn't
   ;  start the game.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increment _Master_Counter.
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if counter is less than one second.
   ;
   if _Master_Counter < 60 then goto __TS_AP_Skip

   ;```````````````````````````````````````````````````````````````
   ;  Increments _Frame_Counter and clears _Master_Counter.
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check.
   ;
   ;  Turns on auto-play and jumps to main loop setup if 10 
   ;  seconds have gone by.
   ;
   if _Frame_Counter > 9 then _Bit3_Auto_Play{3} = 1 : goto __Main_Loop_Setup

__TS_AP_Skip



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset/fire button check and end of title screen loop.
   ;  
   ;  Starts the game if the reset switch or the fire button
   ;  is pressed appropriately.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and jumps to beginning of title 
   ;  screen loop if fire button or reset switch is not pressed.
   ;
   if !switchreset && !joy0fire then _Bit0_Reset_Restrainer{0} = 0 : goto __Title_Screen_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of title screen loop if reset or fire 
   ;  hasn't been released since starting title screen loop.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Title_Screen_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Sets control bit so program will jump to main loop setup.
   ;
   _Bit2_Game_Control{2} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Restarts game and program jumps to main loop setup.
   ;
   goto __Start_Restart





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP SETUP
   ;
   ;
__Main_Loop_Setup


   ;***************************************************************
   ;
   ;  In the main loop, _Bit2_Game_Control{2} controls when the
   ;  game ends.
   ;
   ;  0 = Game not over.
   ;  1 = Game over.
   ;
   _Bit2_Game_Control{2} = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed in the title
   ;  screen section or the game over section. If the reset
   ;  switch isn't being held down, this bit will be cleared
   ;  in the main loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Restrains the fire button for the main loop.
   ;
   ;  This bit fixes it so the fire button becomes inactive if it
   ;  hasn't been released after being pressed in the title
   ;  screen section or the game over section. If the fire
   ;  button isn't being held down, this bit will be cleared
   ;  in the main loop.
   ;
   _Bit1_FireB_Restrainer{1} = 1


   ;***************************************************************
   ;
   ;  Starting position of player0 (acorn).
   ;
   player0x = 74 : player0y = 78


   ;***************************************************************
   ;
   ;  Starting position of player1 (squirrel).
   ;
   player1x = (rand/2) + (rand&15) : player1y = 0 


   ;***************************************************************
   ;
   ;  Defines missile0 height and location.
   ;
   missile0height = 4 : missile0y = 250


   ;***************************************************************
   ;
   ;  Sets score color.
   ;
   scorecolor = $1C


   ;***************************************************************
   ;
   ;  Sets health bar and sets color.
   ;
   pfscore1 = %11111111 : pfscorecolor = $D2


   ;***************************************************************
   ;
   ;  Defines shape of player0 sprite.
   ;
   player0:
   %00011000
   %00111100
   %00111100
   %01111110
   %01111110
   %11111111
   %01111110
   %00011000
end


   ;***************************************************************
   ;
   ;  Sets up the main loop playfield.
   ;
   playfield:
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   ...............................
   ...............................
   ...............................
   ...............................
   ...............................
   ...............................
   ...............................
   ...............................
   ...............................
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end


   ;***************************************************************
   ;
   ;  Remembers position of COLOR/BW switch.
   ;
   _Bit0_BW_Mem{0} = 0 : if switchbw then _Bit0_BW_Mem{0} = 1


   ;***************************************************************
   ;
   ;  Auto-play score swap setup.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears score and skips section if auto-play is off.
   ;
   if !_Bit3_Auto_Play{3} then score = 0 : goto __AP_Skip_AP_Setup

   ;```````````````````````````````````````````````````````````````
   ;  Clears variables.
   ;
   _Master_Counter = 0 : _Frame_Counter = 0 

   ;```````````````````````````````````````````````````````````````
   ;  Sets up the score swap and clears the swap bit.
   ;
   _Score1_Mem = _sc1 : _Score2_Mem = _sc2 : _Score3_Mem = _sc3

   _Bit6_Swap_Scores{6} = 0

__AP_Skip_AP_Setup





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE GAME GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = $D6



   ;***************************************************************
   ;
   ;  Sets playfield pixel color.
   ;
   COLUPF = 0



   ;***************************************************************
   ;
   ;  Sets sprite colors.
   ;
   COLUP0 = $22 : COLUP1 = $20



   ;***************************************************************
   ;
   ;  Makes missile0 a little wider.
   ;
   NUSIZ0 = $10



   ;***************************************************************
   ;
   ;  Makes squirrel wider.
   ;
   NUSIZ1 = $05



   ;***************************************************************
   ;
   ;  Animation counters.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments _Master_Counter.
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if _Master_Counter is less than 7.
   ;
   if _Master_Counter < 7 then goto __Skip_Counters

   ;```````````````````````````````````````````````````````````````
   ;  Increments _Frame_Counter and clears _Master_Counter.
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Clears _Frame_Counter if it is greater than 3.
   ;
   if _Frame_Counter > 3 then _Frame_Counter = 0

__Skip_Counters



   ;***************************************************************
   ;
   ;  Squirrel animation (4 frames, 0 through 3).
   ;
   on _Frame_Counter goto __Sq00 __Sq01 __Sq02 __Sq03

__Squirrel_Frame_Done



   ;***************************************************************
   ;
   ;  Missile0 check and fire button check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps to fire button check if missile0 is off the screen.
   ;
   if missile0y > 240 then goto __FireB_Check

   ;```````````````````````````````````````````````````````````````
   ;  Moves missile0 and skips fire button check.
   ;
   missile0y = missile0y - 2 : goto __Skip_FireB

__FireB_Check

   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if auto-play is off.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Fire_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Determines if sprite should fire during auto-play.
   ;  There is a 90% chance that the missile will not fire.
   ;
   temp5 = rand : if temp5 < 230 then goto __Skip_FireB

   goto __AP_Fire

__AP_Skip_Fire_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and skips this section if fire
   ;  button is not pressed.
   ;
   if !joy0fire then _Bit1_FireB_Restrainer{1} = 0 : goto __Skip_FireB

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if fire button hasn't been released since
   ;  the title screen.
   ;
   if _Bit1_FireB_Restrainer{1} then goto __Skip_FireB

__AP_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Starts the firing of missile0.
   ;
   missile0y = player0y - 2 : missile0x = player0x + 4

__Skip_FireB



   ;***************************************************************
   ;
   ;  Auto-play direction change for player0 sprite.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if auto-play is off.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_New_Dir

   ;```````````````````````````````````````````````````````````````
   ;  Adds to the auto-play direction change counter.
   ;
   _AP_Dir_Counter = _AP_Dir_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Grabs a random number (0 to 63) and adds 50. Change 50 to a
   ;  larger number if you want the sprite to move longer before
   ;  changing directions. Don't use a number larger than 190.
   ;
   temp6 = (rand&63) + 50

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the counter isn't high enough.
   ;
   if _AP_Dir_Counter < temp6 then goto __AP_Move_Acorn

   ;```````````````````````````````````````````````````````````````
   ;  Grabs a random number (0 to 255).
   ;
   temp5 = rand

   ;```````````````````````````````````````````````````````````````
   ;  There is a 90% chance that this section will be skipped.
   ;
   if temp5 < 230 then goto __AP_Move_Acorn

   ;```````````````````````````````````````````````````````````````
   ;  Changes player0 direction.
   ;
   _Bit3_AP_P0_Dir{3} = !_Bit3_AP_P0_Dir{3}

   ;```````````````````````````````````````````````````````````````
   ;  Clears counter.
   ;
   _AP_Dir_Counter = 0

__AP_Move_Acorn

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 sprite.
   ;
   if !_Bit3_AP_P0_Dir{3} then if player0x > _P_Edge_Left then player0x = player0x - 1
   if _Bit3_AP_P0_Dir{3} then if player0x < _P_Edge_Right then player0x = player0x + 1

   goto __Skip_Joy_Movement

__AP_Skip_New_Dir



   ;***************************************************************
   ;
   ;  Joystick movement check. This section is skipped if
   ;  auto-play is on.
   ;
   if joy0up then if player0y > _P_Edge_Top then player0y = player0y - 1
   if joy0down then if player0y < _P_Edge_Bottom then player0y = player0y + 1
   if joy0left then if player0x > _P_Edge_Left then player0x = player0x - 1
   if joy0right then if player0x < _P_Edge_Right then player0x = player0x + 1

__Skip_Joy_Movement



   ;***************************************************************
   ;
   ;  Squirrel chases the player.
   ;
   if player1y < player0y then player1y = player1y + 1
   if player1y > player0y then player1y = player1y - 1
   temp5 = player1x + 8 : if temp5 < player0x then if player1x < 144 then player1x = player1x + 1
   temp5 = player1x + 8 : if temp5 > player0x then if player1x > 0 then player1x = player1x - 1



   ;***************************************************************
   ;
   ;  Squirrel/missile0 collision check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if there is no collision.
   ;
   if !collision(missile0,player1) then goto __Skip_Squirrel_Kill

   ;```````````````````````````````````````````````````````````````
   ;  Temporarily remembers squirrel's y position.
   ;
   temp6 = player1y

   ;```````````````````````````````````````````````````````````````
   ;  Moves squirrel to new location and removes missile.
   ;
   player1x = (rand/2) + (rand&15) : player1y = 0 : missile0y = 250

   ;```````````````````````````````````````````````````````````````
   ;  Skips sound and points if auto-play is on.
   ;
   if _Bit3_Auto_Play{3} then goto __Skip_Squirrel_Kill

   ;```````````````````````````````````````````````````````````````
   ;  Adds 1 to the score.
   ;
   score = score + 1

   ;```````````````````````````````````````````````````````````````
   ;  Sound effect 1 setup.
   ;
   if _Ch0_Sound then goto __Skip_Squirrel_Kill

   _Ch0_Sound = 1 : _Ch0_Counter = 10

   _C0 = 4 : _V0 = 12 : _F0 = 14

   ;```````````````````````````````````````````````````````````````
   ;  Makes a different sound when closer to player.
   ;
   temp5 = 255 : if player0y > temp6 then temp5 = player0y - temp6

   if temp5 < 30 then _C0 = 12

__Skip_Squirrel_Kill



   ;***************************************************************
   ;
   ;  Squirrel/acorn collision check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if there is no collision.
   ;
   if !collision(player0,player1) then goto __Skip_Acorn_Eaten

   ;```````````````````````````````````````````````````````````````
   ;  Activates last life bit if pfscore1 bar is empty. Also ends
   ;  auto-play if it's on.
   ;
   if !pfscore1 then _Bit7_Last_Life{7} = 1 : if _Bit3_Auto_Play{3} then _Bit2_Game_Control{2} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Deletes a life.
   ;
   if pfscore1 then pfscore1 = pfscore1/4

   ;```````````````````````````````````````````````````````````````
   ;  Moves squirrel to new location and removes missile.
   ;
   player1x = (rand/2) + (rand&15) : player1y = 0 : missile0y = 250

   ;```````````````````````````````````````````````````````````````
   ;  Skips sound effect and score if auto-play is on.
   ;
   if _Bit3_Auto_Play{3} then goto __Skip_Acorn_Eaten

   ;```````````````````````````````````````````````````````````````
   ;  Subtracts 1 from the score.
   ;
   if _sc3 > 0 then score = score - 1

   ;```````````````````````````````````````````````````````````````
   ;  Sound effect 2 setup.
   ;
   if _Ch0_Sound then goto __Skip_Acorn_Eaten

   _Ch0_Sound = 2 : _Ch0_Counter = 10

   _C0 = 7 : _V0 = 12 : _F0 = 12

__Skip_Acorn_Eaten



   ;***************************************************************
   ;
   ;  Point sound.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the sound isn't on.
   ;
   if _Ch0_Sound <> 1 then goto __Skip_Sound1

   ;```````````````````````````````````````````````````````````````
   ;  Flips the frequency between 11 and 14.
   ;
   _F0 = _F0 ^ 5

   ;```````````````````````````````````````````````````````````````
   ;  Sets the tone, volume and frequency.
   ;
   AUDC0 = _C0 : AUDV0 = _V0 : AUDF0 = _F0

   ;```````````````````````````````````````````````````````````````
   ;  Decreases volume by 1 and makes sure it doesn't go below 2.
   ;
   _V0 = _V0 - 1 : if _V0 < 2 then _V0 = 2

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the sound counter.
   ;
   _Ch0_Counter = _Ch0_Counter - 1

   ;```````````````````````````````````````````````````````````````
   ;  Clears _Ch0_Sound and mutes channel if sound counter is zero.
   ;
   if !_Ch0_Counter then _Ch0_Sound = 0 : AUDV0 = 0

__Skip_Sound1



   ;***************************************************************
   ;
   ;  Squirrel eats acorn sound.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the sound isn't on.
   ;
   if _Ch0_Sound <> 2 then goto __Skip_Sound2

   ;```````````````````````````````````````````````````````````````
   ;  Sets the tone, volume and frequency.
   ;
   AUDC0 = _C0 : AUDV0 = _V0 : AUDF0 = _F0

   ;```````````````````````````````````````````````````````````````
   ;  Decreases volume by 1 and makes sure it doesn't go below 2.
   ;
   _V0 = _V0 - 1 : if _V0 < 2 then _V0 = 2

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the sound counter.
   ;
   _Ch0_Counter = _Ch0_Counter - 1

   ;```````````````````````````````````````````````````````````````
   ;  Clears _Ch0_Sound and mutes channel if sound counter is zero.
   ;  Also tells game to end if last life is lost.
   ;
   if !_Ch0_Counter then _Ch0_Sound = 0 : AUDV0 = 0 : if _Bit7_Last_Life{7} then _Bit2_Game_Control{2} = 1

__Skip_Sound2



   ;***************************************************************
   ;
   ;  Auto-play score flipper.
   ;
   ;  Flips between high score and current score.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if auto-play bit is not on.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Flip

   ;```````````````````````````````````````````````````````````````
   ;  Increments the auto play 2-second counter.
   ;
   _AP_2_Sec_Score_Flip = _AP_2_Sec_Score_Flip + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if auto play 2-second counter is less
   ;  than 2 seconds (120 = 2 seconds).
   ;
   if _AP_2_Sec_Score_Flip < 120 then goto __AP_Skip_Flip

   ;```````````````````````````````````````````````````````````````
   ;  Clears the 2-second counter and flips the score swapping bit.
   ;
   _AP_2_Sec_Score_Flip = 0 : _Bit6_Swap_Scores{6} = !_Bit6_Swap_Scores{6}

   ;```````````````````````````````````````````````````````````````
   ;  Skips high score swap if swap bit is off.
   ;
   if !_Bit6_Swap_Scores{6} then goto __AP_Skip_HiScore_Swap

   ;```````````````````````````````````````````````````````````````
   ;  Displays high score (blue) and skips rest of section.
   ;
   scorecolor = $AE

   _sc1 = _High_Score1 : _sc2 = _High_Score2 : _sc3 = _High_Score3

   goto __AP_Skip_Flip

__AP_Skip_HiScore_Swap

   ;```````````````````````````````````````````````````````````````
   ;  Displays current score (yellow).
   ;
   scorecolor = $1C

   _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem

__AP_Skip_Flip



   ;***************************************************************
   ;
   ;  Pause check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if auto-play is on.
   ;
   if _Bit3_Auto_Play{3} then goto __AP_Skip_Pause

   ;```````````````````````````````````````````````````````````````
   ;  Checks current position of COLOR/BW switch.
   ;
   _Bit1_BW_Check{1} = 0

   if switchbw then _Bit1_BW_Check{1} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Compares bits to see if COLOR/BW switch has moved.
   ;  The game is paused if the switch has moved.
   ;
   if _Bit0_BW_Mem{0} then if !_Bit1_BW_Check{1} then goto __Pause_Setup

   if !_Bit0_BW_Mem{0} then if _Bit1_BW_Check{1} then goto __Pause_Setup

   ;```````````````````````````````````````````````````````````````
   ;  Pauses game if fire button of second joystick is pressed.
   ;
   if joy1fire && !_Bit1_FireB_Restrainer{1} then goto __Pause_Setup

__AP_Skip_Pause



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Game Over Check
   ;
   ;  _Bit2_Game_Control{2} controls when the game ends.
   ;
   ;  0 = Game not over.
   ;  1 = Game over.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if game control bit is off.
   ;
   if !_Bit2_Game_Control{2} then goto __Skip_Check_G_Over

   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check. Puts score back to current score and jumps
   ;  back to the title screen if auto-play bit is on.
   ;
   if _Bit3_Auto_Play{3} then _Bit2_Game_Control{2} = 0 : _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem : goto __Start_Restart

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to game over set up.
   ;
   goto __Game_Over_Setup

__Skip_Check_G_Over



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Reset

   ;```````````````````````````````````````````````````````````````
   ;  Starts game during auto-play if reset switch or fire button
   ;  is pressed. Also clears auto-play bit and sets game control
   ;  bit so game will start instead of going to title screen.
   ;
   if switchreset || joy0fire then _Bit3_Auto_Play{3} = 0 : _Bit2_Game_Control{2} = 1 : goto __Start_Restart

__AP_Skip_Reset

   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Clears the game over bit so the title screen will appear.
   ;
   _Bit2_Game_Control{2} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the game over setup section and checks for a high
   ;  score, then jumps to the title screen.
   ;
   goto __Game_Over_Setup




   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;
   ;  Squirrel animation frames.
   ;
__Sq00
   player1:
   %00001010
   %00001110
   %00110011
   %01110100
end

   goto __Squirrel_Frame_Done


__Sq01
   player1:
   %00001001
   %00001110
   %00110011
   %01110100
end

   goto __Squirrel_Frame_Done


__Sq02
   player1:
   %00010001
   %00001110
   %00110011
   %01110100
end

   goto __Squirrel_Frame_Done


__Sq03
   player1:
   %00010010
   %00001110
   %00110011
   %01110100
end

   goto __Squirrel_Frame_Done





   ;***************************************************************
   ;***************************************************************
   ;
   ;  GAME OVER SETUP
   ;
   ;
__Game_Over_Setup


   ;***************************************************************
   ;
   ;  High score check.
   ;
   ;  Checks for a new high score.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Checks first byte.
   ;
   if _sc1 > _High_Score1 then goto __New_High_Score
   if _sc1 < _High_Score1 then goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  First byte equal. Checks second byte.
   ;
   if _sc2 > _High_Score2 then goto __New_High_Score
   if _sc2 < _High_Score2 then goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  Second byte equal. Checks third byte.
   ;
   if _sc3 > _High_Score3 then goto __New_High_Score
   if _sc3 < _High_Score3 then goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  All bytes equal. Skips high score.
   ;
   goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  All bytes not equal. New high score!
   ;
__New_High_Score

   _High_Score1 = _sc1 : _High_Score2 = _sc2 : _High_Score3 = _sc3

__Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the game if the reset switch was pressed. Continues
   ;  in the game over setup section if the game ended naturally.
   ;
   if !_Bit2_Game_Control{2} then goto __Start_Restart


   ;***************************************************************
   ;
   ;  Saves the latest score for the high score flip.
   ;
   _Score1_Mem = _sc1 : _Score2_Mem = _sc2 : _Score3_Mem = _sc3


   ;***************************************************************
   ;
   ;  Clears the counters.
   ;
   _Master_Counter = 0 : _Frame_Counter = 0


   ;***************************************************************
   ;
   ;  Makes sure sprites and missile are off the screen.
   ;
   player0y = 200 : player1y = 200 : missile0y = 200


   ;***************************************************************
   ;
   ;  Restrains reset switch and fire button for game over loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after entering a different segment
   ;  of the program. It also does double duty by restraining the
   ;  fire button in the game over loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets up game over playfield.
   ;
   playfield:
   .XXXXXX.XXXXXX.XXXXXXXXXX.XXXXX.
   .XX.....XX..XX.XX..XX..XX.XX....
   .XX.XXX.XXXXXX.XX..XX..XX.XXXX..
   .XX..XX.XX..XX.XX..XX..XX.XX....
   .XXXXXX.XX..XX.XX..XX..XX.XXXXX.
   ................................
   ...XXXXXX.XX..XX.XXXXX.XXXXXX...
   ...XX..XX.XX..XX.XX....XX..XX...
   ...XX..XX.XX..XX.XXXX..XXXXX....
   ...XX..XX.XX..XX.XX....XX..XX...
   ...XXXXXX...XX...XXXXX.XX..XX...
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  GAME OVER LOOP
   ;
   ;
__Game_Over_Loop



   ;***************************************************************
   ;
   ;  20 second counter.
   ;
   ;  This includes a 2 second countdown timer. Any Atari 2600
   ;  game should disable the fire button for 2 seconds when
   ;  the game is over to keep the player from restarting by
   ;  mistake. It is part of the usual standards and procedures.
   ;
   ;  This section also flips between the current score and the
   ;  high score every 2 seconds. It jumps to the title screen
   ;  after 20 seconds if the player does nothing.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments master counter every frame (60 frames = 1 second).
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if master counter is less than 2 seconds.
   ;  The master counter resets every 2 seconds (60 + 60 = 120).
   ;
   if _Master_Counter < 120 then goto __Skip_20_Second_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Increments frame counter and clears master counter.
   ;  (One increment = 2 seconds.)
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Restores the current score, resets the game, and goes to the
   ;  title screen if 20 seconds have gone by.
   ;
   ;  0 = Go to title screen.
   ;  1 = Skip title screen and play game.
   ;
   if _Frame_Counter > 9 then _Bit2_Game_Control{2} = 0 : _sc1=_Score1_Mem : _sc2=_Score2_Mem : _sc3=_Score3_Mem: goto __Start_Restart

   ;```````````````````````````````````````````````````````````````
   ;  Flips the score swapping bit.
   ;
   _Bit6_Swap_Scores{6} = !_Bit6_Swap_Scores{6}

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to current score if swap bit is off.
   ;
   if !_Bit6_Swap_Scores{6} then goto __GO_Current_Score

   ;```````````````````````````````````````````````````````````````
   ;  Displays high score (blue) and skips rest of section.
   ;
   scorecolor = $AE

   _sc1 = _High_Score1 : _sc2 = _High_Score2 : _sc3 = _High_Score3

   goto __Skip_20_Second_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Displays current score (yellow).
   ;
__GO_Current_Score

   scorecolor = $1C

   _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem

__Skip_20_Second_Counter



   ;***************************************************************
   ;
   ;  Sets background color and playfield color.
   ;
   COLUBK = $44 : COLUPF = $2C

   ;```````````````````````````````````````````````````````````````
   ;  Changes colors after 2 seconds. This is only done to let
   ;  you, the programmer, know when 2 seconds have gone by. The
   ;  color change doesn't need to happen in a real game.
   ;
   if _Frame_Counter > 0 then COLUBK = $D2 : COLUPF = $DA



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset/fire button check and end of GAME OVER loop.
   ;  
   ;  Restarts the program if the reset switch or the fire
   ;  button is pressed appropriately.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the game over loop if the initial
   ;  2 second freeze is not over.
   ;
   if _Frame_Counter = 0 then goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and jumps to beginning of game
   ;  over loop if fire button or reset switch is not pressed.
   ;
   if !switchreset && !joy0fire then _Bit0_Reset_Restrainer{0} = 0 : goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the game over loop if fire button
   ;  hasn't been released since leaving the main loop.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  The program is restarted.
   ;
   goto __Start_Restart





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF GAME OVER LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PAUSE SETUP
   ;
__Pause_Setup


   ;***************************************************************
   ;
   ;  Mutes the sound.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Restrains the fire button for the pause loop.
   ;
   _Bit1_FireB_Restrainer{1} = 1


   ;***************************************************************
   ;
   ;  Clears the pause counter.
   ;
   _Pause_Counter_Tmp = 0


   ;***************************************************************
   ;
   ;  Selects a random color scheme.
   ;
   _Pause_Color_Tmp = (rand&7)

   _Pause_Mem_Color_Tmp = _Pause_Color_Tmp





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PAUSE LOOP
   ;
__Pause_Game



   ;***************************************************************
   ;
   ;  Makes missile0 a little wider.
   ;
   NUSIZ0 = $10



   ;***************************************************************
   ;
   ;  Makes squirrel wider.
   ;
   NUSIZ1 = $05



   ;***************************************************************
   ;
   ;  Changes color scheme every 4 seconds.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increases the pause counter.
   ;
   _Pause_Counter_Tmp = _Pause_Counter_Tmp + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if counter isn't high enough.
   ;
   if _Pause_Counter_Tmp < 240 then goto __Skip_Pause_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Resets the pause counter.
   ;
   _Pause_Counter_Tmp = 0

   ;```````````````````````````````````````````````````````````````
   ;  Gets a random number from 0 to 7.
   ;
   _Pause_Color_Tmp = (rand&7)

   ;```````````````````````````````````````````````````````````````
   ;  Compares the new color scheme with the previous color scheme
   ;  and selects a new color scheme if they are the same.
   ;
   if _Pause_Color_Tmp = _Pause_Mem_Color_Tmp then _Pause_Color_Tmp = _Pause_Color_Tmp + (rand&3) + 1 : if _Pause_Color_Tmp > 7 then _Pause_Color_Tmp = _Pause_Color_Tmp - 8

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the new color scheme.
   ;
   _Pause_Mem_Color_Tmp = _Pause_Color_Tmp

   ;```````````````````````````````````````````````````````````````
   ;  Decides if the B color scheme should be used.
   ;
   _Bit2_Pause_Clr_Scheme{2} = 0

    temp5 = rand : if temp5 < 128 then _Bit2_Pause_Clr_Scheme{2} = 1

__Skip_Pause_Counter



   ;***************************************************************
   ;
   ;  Jumps to the latest color scheme.
   ;
   on _Pause_Color_Tmp goto __Ps0 __Ps1 __Ps2 __Ps3 __Ps4 __Ps5 __Ps6 __Ps7

__Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Unpause check and end of pause loop.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the pause loop if the fire button
   ;  isn't pressed. Also clears the restrainer bit.
   ;
   if !joy0fire then _Bit1_FireB_Restrainer{1} = 0 : goto __Pause_Game

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the pause loop if the fire button
   ;  hasn't been released since starting the pause loop.
   ;
   if _Bit1_FireB_Restrainer{1} then goto __Pause_Game

   ;```````````````````````````````````````````````````````````````
   ;  Remembers position of COLOR/BW switch.
   ;
   _Bit0_BW_Mem{0} = 0 : if switchbw then _Bit0_BW_Mem{0} = 1





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF PAUSE LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;  RESTORES GAME FROM PAUSE
   ;
   ;  Puts everything back the way it was.
   ;
__Restore_Game_from_Pause


   ;***************************************************************
   ;
   ;  Restrains the fire button for the main loop.
   ;
   _Bit1_FireB_Restrainer{1} = 1


   ;***************************************************************
   ;
   ;  Restores score color and more.
   ;
   scorecolor = $1C : pfscorecolor = $D2


   goto __Main_Loop





   ;***************************************************************
   ;
   ;  Sets pause colors to gray.
   ;
__Ps0

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps0B

   COLUPF = $0C : COLUP0 = $0C : COLUP1 = $0C : pfscorecolor = $0C : scorecolor = $0C

   COLUBK = $0A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to gray.
   ;
__Ps0B

   COLUPF = $0A : COLUP0 = $0A : COLUP1 = $0A : pfscorecolor = $0A : scorecolor = $0A

   COLUBK = $0C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to reddish-orange.
   ;
__Ps1

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps1B

   COLUPF = $3C : COLUP0 = $3C : COLUP1 = $3C : pfscorecolor = $3C : scorecolor = $3C

   COLUBK = $3A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to reddish-orange.
   ;
__Ps1B

   COLUPF = $3A : COLUP0 = $3A : COLUP1 = $3A : pfscorecolor = $3A : scorecolor = $3A

   COLUBK = $3C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to purple.
   ;
__Ps2

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps2B

   COLUPF = $6C : COLUP0 = $6C : COLUP1 = $6C : pfscorecolor = $6C : scorecolor = $6C

   COLUBK = $6A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to purple.
   ;
__Ps2B

   COLUPF = $6A : COLUP0 = $6A : COLUP1 = $6A : pfscorecolor = $6A : scorecolor = $6A



   COLUBK = $6C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to blue.
   ;
__Ps3

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps3B

   COLUPF = $9C : COLUP0 = $9C : COLUP1 = $9C : pfscorecolor = $9C : scorecolor = $9C

   COLUBK = $9A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to blue.
   ;
__Ps3B

   COLUPF = $9A : COLUP0 = $9A : COLUP1 = $9A : pfscorecolor = $9A : scorecolor = $9A

   COLUBK = $9C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to green.
   ;
__Ps4

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps4B

   COLUPF = $CC : COLUP0 = $CC : COLUP1 = $CC : pfscorecolor = $CC : scorecolor = $CC

   COLUBK = $CA

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to green.
   ;
__Ps4B

   COLUPF = $CA : COLUP0 = $CA : COLUP1 = $CA : pfscorecolor = $CA : scorecolor = $CA

   COLUBK = $CC

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to yellowish.
   ;
__Ps5

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps5B

   COLUPF = $FC : COLUP0 = $FC : COLUP1 = $FC : pfscorecolor = $FC : scorecolor = $FC

   COLUBK = $FA

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to yellowish.
   ;
__Ps5B

   COLUPF = $FA : COLUP0 = $FA : COLUP1 = $FA : pfscorecolor = $FA: scorecolor = $FA

   COLUBK = $FC

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to darkish-blue.
   ;
__Ps6

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps6B

   COLUPF = $8C : COLUP0 = $8C : COLUP1 = $8C : pfscorecolor = $8C : scorecolor = $8C

   COLUBK = $8A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to darkish-blue.
   ;
__Ps6B

   COLUPF = $8A : COLUP0 = $8A : COLUP1 = $8A : pfscorecolor = $8A : scorecolor = $8A

   COLUBK = $8C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to orange-brown.
   ;
__Ps7

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps7B

   COLUPF = $2C : COLUP0 = $2C : COLUP1 = $2C : pfscorecolor = $2C : scorecolor = $2C

   COLUBK = $2A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to orange-brown.
   ;
__Ps7B

   COLUPF = $2A : COLUP0 = $2A : COLUP1 = $2A : pfscorecolor = $2A : scorecolor = $2A

   COLUBK = $2C

   goto __Got_Pause_Colors
 
   ;****************************************************************
   ;
   ;  Tinkernut World Deluxe With Sound Data and Health Bar
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) made by
   ;  adapting the original Tinkernut World from www.tinkernut.com
   ;  and using hints, tips, code snippets, and more from AtariAge
   ;  members such as batari, SeaGtGruff, RevEng, Robert M, Nukey
   ;  Shay, Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;  High score code provided by supercat and polished up by
   ;  Nukey Shay.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Shoot the squirrel before he eats you.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  _Master_Counter can be used for many things, but it is 
   ;  really useful for animating sprite frames when used
   ;  with _Frame_Counter.
   ;
   dim _Master_Counter = a
   dim _Frame_Counter = b

   ;```````````````````````````````````````````````````````````````
   ;  Sound channel 0 variables.
   ;
   dim _Ch0_Sound = c
   dim _Ch0_Duration = d
   dim _Ch0_Counter = e

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used in the pause loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _Pause_Counter_Tmp = h

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used for auto-play in the main loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _AP_2_Sec_Score_Flip = i

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used in the pause loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _Pause_Mem_Color_Tmp = i

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used for auto-play in the main loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _AP_Dir_Counter = j

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used in the pause loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _Pause_Color_Tmp = j

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _BitOp_02 = r

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the position of the BW switch.
   ;
   dim _Bit0_BW_Mem = r

   ;```````````````````````````````````````````````````````````````
   ;  Checks to see if the BW switch has moved.
   ;
   dim _Bit1_BW_Check = r

   ;```````````````````````````````````````````````````````````````
   ;  Lets pause section know if the B color scheme should be used.
   ;
   dim _Bit2_Pause_Clr_Scheme = r

   ;```````````````````````````````````````````````````````````````
   ;  Auto-play direction bit for player0 sprite.
   ;
   dim _Bit3_AP_P0_Dir = r

   ;```````````````````````````````````````````````````````````````
   ;  Converts 6 digit score to 3 sets of two digits.
   ;
   ;  The 100 thousands and 10 thousands digits are held by _sc1.
   ;  The thousands and hundreds digits are held by _sc2.
   ;  The tens and ones digits are held by _sc3.
   ;
   dim _sc1 = score
   dim _sc2 = score+1
   dim _sc3 = score+2

   ;```````````````````````````````````````````````````````````````
   ;  These can be used for other things using different aliases,
   ;  but for the game over loop and auto-play in the main loop,
   ;  they are used to temporarily remember the score for the 2
   ;  second score/high score flip.
   ;
   dim _Score1_Mem = s
   dim _Score2_Mem = t
   dim _Score3_Mem = u

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the high score until the game is turned off.
   ;
   dim _High_Score1 = v
   dim _High_Score2 = w
   dim _High_Score3 = x

   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y
   dim _Bit1_FireB_Restrainer = y
   dim _Bit2_Game_Control = y
   dim _Bit3_Auto_Play = y
   dim _Bit6_Swap_Scores = y
   dim _Bit7_Last_Life = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers. 
   ;
   dim rand16 = z



   ;***************************************************************
   ;
   ;  Turns on pfscore bars.
   ;
   const pfscore = 1



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for an 8 x 8 sprite.
   ;  If your sprite is a different size, you'll need to adjust
   ;  the numbers.
   ;
   const _P_Edge_Top = 10
   const _P_Edge_Bottom = 83
   const _P_Edge_Left = 1
   const _P_Edge_Right = 153





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears 21 of the normal 26 variables (fastest way).
   ;  Do not clear v, w, x, y, or z in this program. The variables
   ;  v through x remember the high score. The variable y holds a
   ;  bit that should not be cleared. The variable z is used for
   ;  random numbers in this program and clearing it would mess
   ;  up those random numbers.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0


   ;***************************************************************
   ;
   ;  Clears 7 of the 8 bits.
   ;
   ;  Bit 2 is not cleared because _Bit2_Game_Control{2} is used
   ;  to control how the program is reset.
   ;
   _BitOp_01 = _BitOp_01 & %00000100


   ;***************************************************************
   ;
   ;  Makes sure sprites and missile are off the screen.
   ;
   player0y = 200 : player1y = 200 : missile0y = 200


   ;***************************************************************
   ;
   ;  Skips title screen if game has been played and player
   ;  presses fire button or reset switch at the end of the game.
   ;
   ;  0 = Go to title screen.
   ;  1 = Skip title screen and play game.
   ;
   if _Bit2_Game_Control{2} then goto __Main_Loop_Setup





   ;***************************************************************
   ;***************************************************************
   ;
   ;   TITLE SCREEN SETUP
   ;
   ;
__Setup_Title_Screen


   ;***************************************************************
   ;
   ;  Clears health bar and sets score color.
   ;
   pfscore1 = 0 : scorecolor = $20


   ;***************************************************************
   ;
   ;  Sets title screen background color.
   ;
   COLUBK = $20


   ;***************************************************************
   ;
   ;  Restrains the reset switch.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after entering a different segment
   ;  of the program. It also does double duty by restraining the
   ;  fire button in the title screen loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets up title screen playfield.
   ;
   playfield:
   XXX.X..X.X.X.XX.XX..X..X.X.X.XXX
   .X..X..X.X.X.X..X.X.X..X.X.X..X.
   .X..XX.X.XX..XX.XX..XX.X.X.X..X.
   .X..X.XX.X.X.X..X.X.X.XX.X.X..X.
   .X..X..X.X.X.XX.X.X.X..X.XXX..X.
   ................................
   ....X...X.XXXX.XXX..X...XXX.....
   ....X...X.X..X.X..X.X...X..X....
   ....X...X.X..X.XX...X...X..X....
   ....X.X.X.X..X.X.X..X...X..X....
   ....XX.XX.XXXX.X..X.XXX.XXX.....
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  TITLE SCREEN LOOP
   ;
   ;
__Title_Screen_Loop



   ;***************************************************************
   ;
   ;  Sets title screen playfield pixel color.
   ;
   COLUPF = $D8



   ;***************************************************************
   ;
   ;  Auto-play check.
   ;
   ;  Switches to auto-play after 10 seconds if player doesn't
   ;  start the game.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increment _Master_Counter.
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if counter is less than one second.
   ;
   if _Master_Counter < 60 then goto __TS_AP_Skip

   ;```````````````````````````````````````````````````````````````
   ;  Increments _Frame_Counter and clears _Master_Counter.
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check.
   ;
   ;  Turns on auto-play and jumps to main loop setup if 10 
   ;  seconds have gone by.
   ;
   if _Frame_Counter > 9 then _Bit3_Auto_Play{3} = 1 : goto __Main_Loop_Setup

__TS_AP_Skip



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset/fire button check and end of title screen loop.
   ;  
   ;  Starts the game if the reset switch or the fire button
   ;  is pressed appropriately.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and jumps to beginning of title 
   ;  screen loop if fire button or reset switch is not pressed.
   ;
   if !switchreset && !joy0fire then _Bit0_Reset_Restrainer{0} = 0 : goto __Title_Screen_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of title screen loop if reset or fire 
   ;  hasn't been released since starting title screen loop.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Title_Screen_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Sets control bit so program will jump to main loop setup.
   ;
   _Bit2_Game_Control{2} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Restarts game and program jumps to main loop setup.
   ;
   goto __Start_Restart





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP SETUP
   ;
   ;
__Main_Loop_Setup


   ;***************************************************************
   ;
   ;  In the main loop, _Bit2_Game_Control{2} controls when the
   ;  game ends.
   ;
   ;  0 = Game not over.
   ;  1 = Game over.
   ;
   _Bit2_Game_Control{2} = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed in the title
   ;  screen section or the game over section. If the reset
   ;  switch isn't being held down, this bit will be cleared
   ;  in the main loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Restrains the fire button for the main loop.
   ;
   ;  This bit fixes it so the fire button becomes inactive if it
   ;  hasn't been released after being pressed in the title
   ;  screen section or the game over section. If the fire
   ;  button isn't being held down, this bit will be cleared
   ;  in the main loop.
   ;
   _Bit1_FireB_Restrainer{1} = 1


   ;***************************************************************
   ;
   ;  Starting position of player0 (acorn).
   ;
   player0x = 74 : player0y = 78


   ;***************************************************************
   ;
   ;  Starting position of player1 (squirrel).
   ;
   player1x = (rand/2) + (rand&15) : player1y = 0 


   ;***************************************************************
   ;
   ;  Defines missile0 height and location.
   ;
   missile0height = 4 : missile0y = 250


   ;***************************************************************
   ;
   ;  Sets score color.
   ;
   scorecolor = $1C


   ;***************************************************************
   ;
   ;  Sets health bar and sets color.
   ;
   pfscore1 = %11111111 : pfscorecolor = $D2


   ;***************************************************************
   ;
   ;  Defines shape of player0 sprite.
   ;
   player0:
   %00011000
   %00111100
   %00111100
   %01111110
   %01111110
   %11111111
   %01111110
   %00011000
end


   ;***************************************************************
   ;
   ;  Sets up the main loop playfield.
   ;
   playfield:
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   ...............................
   ...............................
   ...............................
   ...............................
   ...............................
   ...............................
   ...............................
   ...............................
   ...............................
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end


   ;***************************************************************
   ;
   ;  Remembers position of COLOR/BW switch.
   ;
   _Bit0_BW_Mem{0} = 0 : if switchbw then _Bit0_BW_Mem{0} = 1


   ;***************************************************************
   ;
   ;  Auto-play score swap setup.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears score and skips section if auto-play is off.
   ;
   if !_Bit3_Auto_Play{3} then score = 0 : goto __AP_Skip_AP_Setup

   ;```````````````````````````````````````````````````````````````
   ;  Clears variables.
   ;
   _Master_Counter = 0 : _Frame_Counter = 0 

   ;```````````````````````````````````````````````````````````````
   ;  Sets up the score swap and clears the swap bit.
   ;
   _Score1_Mem = _sc1 : _Score2_Mem = _sc2 : _Score3_Mem = _sc3

   _Bit6_Swap_Scores{6} = 0

__AP_Skip_AP_Setup





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE GAME GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = $D6



   ;***************************************************************
   ;
   ;  Sets playfield pixel color.
   ;
   COLUPF = 0



   ;***************************************************************
   ;
   ;  Sets sprite colors.
   ;
   COLUP0 = $22 : COLUP1 = $20



   ;***************************************************************
   ;
   ;  Makes missile0 a little wider.
   ;
   NUSIZ0 = $10



   ;***************************************************************
   ;
   ;  Makes squirrel wider.
   ;
   NUSIZ1 = $05



   ;***************************************************************
   ;
   ;  Animation counters.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments _Master_Counter.
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if _Master_Counter is less than 7.
   ;
   if _Master_Counter < 7 then goto __Skip_Counters

   ;```````````````````````````````````````````````````````````````
   ;  Increments _Frame_Counter and clears _Master_Counter.
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Clears _Frame_Counter if it is greater than 3.
   ;
   if _Frame_Counter > 3 then _Frame_Counter = 0

__Skip_Counters



   ;***************************************************************
   ;
   ;  Squirrel animation (4 frames, 0 through 3).
   ;
   on _Frame_Counter goto __Sq00 __Sq01 __Sq02 __Sq03

__Squirrel_Frame_Done



   ;***************************************************************
   ;
   ;  Missile0 check and fire button check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps to fire button check if missile0 is off the screen.
   ;
   if missile0y > 240 then goto __FireB_Check

   ;```````````````````````````````````````````````````````````````
   ;  Moves missile0 and skips fire button check.
   ;
   missile0y = missile0y - 2 : goto __Skip_FireB

__FireB_Check

   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if auto-play is off.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Fire_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Determines if sprite should fire during auto-play.
   ;  There is a 90% chance that the missile will not fire.
   ;
   temp5 = rand : if temp5 < 230 then goto __Skip_FireB

   goto __AP_Fire

__AP_Skip_Fire_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and skips this section if fire
   ;  button is not pressed.
   ;
   if !joy0fire then _Bit1_FireB_Restrainer{1} = 0 : goto __Skip_FireB

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if fire button hasn't been released since
   ;  the title screen.
   ;
   if _Bit1_FireB_Restrainer{1} then goto __Skip_FireB

__AP_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Starts the firing of missile0.
   ;
   missile0y = player0y - 2 : missile0x = player0x + 4

   ;```````````````````````````````````````````````````````````````
   ;  Skips sound effect if auto-play is on.
   ;
   if _Bit3_Auto_Play{3} then goto __Skip_FireB

   ;```````````````````````````````````````````````````````````````
   ;  Sound effect 001 setup.
   ;
   if _Ch0_Sound then goto __Skip_FireB

   _Ch0_Sound = 1 : _Ch0_Duration = 1 : _Ch0_Counter = 0

__Skip_FireB



   ;***************************************************************
   ;
   ;  Auto-play direction change for player0 sprite.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if auto-play is off.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_New_Dir

   ;```````````````````````````````````````````````````````````````
   ;  Adds to the auto-play direction change counter.
   ;
   _AP_Dir_Counter = _AP_Dir_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Grabs a random number (0 to 63) and adds 50. Change 50 to a
   ;  larger number if you want the sprite to move longer before
   ;  changing directions. Don't use a number larger than 190.
   ;
   temp6 = (rand&63) + 50

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the counter isn't high enough.
   ;
   if _AP_Dir_Counter < temp6 then goto __AP_Move_Acorn

   ;```````````````````````````````````````````````````````````````
   ;  Grabs a random number (0 to 255).
   ;
   temp5 = rand

   ;```````````````````````````````````````````````````````````````
   ;  There is a 90% chance that this section will be skipped.
   ;
   if temp5 < 230 then goto __AP_Move_Acorn

   ;```````````````````````````````````````````````````````````````
   ;  Changes player0 direction.
   ;
   _Bit3_AP_P0_Dir{3} = !_Bit3_AP_P0_Dir{3}

   ;```````````````````````````````````````````````````````````````
   ;  Clears counter.
   ;
   _AP_Dir_Counter = 0

__AP_Move_Acorn

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 sprite.
   ;
   if !_Bit3_AP_P0_Dir{3} then if player0x > _P_Edge_Left then player0x = player0x - 1
   if _Bit3_AP_P0_Dir{3} then if player0x < _P_Edge_Right then player0x = player0x + 1

   goto __Skip_Joy_Movement

__AP_Skip_New_Dir



   ;***************************************************************
   ;
   ;  Joystick movement check. This section is skipped if
   ;  auto-play is on.
   ;
   if joy0up then if player0y > _P_Edge_Top then player0y = player0y - 1
   if joy0down then if player0y < _P_Edge_Bottom then player0y = player0y + 1
   if joy0left then if player0x > _P_Edge_Left then player0x = player0x - 1
   if joy0right then if player0x < _P_Edge_Right then player0x = player0x + 1

__Skip_Joy_Movement



   ;***************************************************************
   ;
   ;  Squirrel chases the player.
   ;
   if player1y < player0y then player1y = player1y + 1
   if player1y > player0y then player1y = player1y - 1
   temp5 = player1x + 8 : if temp5 < player0x then if player1x < 144 then player1x = player1x + 1
   temp5 = player1x + 8 : if temp5 > player0x then if player1x > 0 then player1x = player1x - 1



   ;***************************************************************
   ;
   ;  Squirrel/missile0 collision check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if there is no collision.
   ;
   if !collision(missile0,player1) then goto __Skip_Squirrel_Kill

   ;```````````````````````````````````````````````````````````````
   ;  Temporarily remembers squirrel's y position.
   ;
   temp6 = player1y

   ;```````````````````````````````````````````````````````````````
   ;  Moves squirrel to new location and removes missile.
   ;
   player1x = (rand/2) + (rand&15) : player1y = 0 : missile0y = 250

   ;```````````````````````````````````````````````````````````````
   ;  Skips sound and points if auto-play is on.
   ;
   if _Bit3_Auto_Play{3} then goto __Skip_Squirrel_Kill

   ;```````````````````````````````````````````````````````````````
   ;  Adds 1 to the score.
   ;
   score = score + 1

   ;```````````````````````````````````````````````````````````````
   ;  Sound effect 002 setup.
   ;
   if _Ch0_Sound then goto __Skip_Squirrel_Kill

   _Ch0_Sound = 2 : _Ch0_Duration = 1 : _Ch0_Counter = 0

__Skip_Squirrel_Kill



   ;***************************************************************
   ;
   ;  Squirrel/acorn collision check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if there is no collision.
   ;
   if !collision(player0,player1) then goto __Skip_Acorn_Eaten

   ;```````````````````````````````````````````````````````````````
   ;  Activates last life bit if pfscore1 bar is empty. Also ends
   ;  auto-play if it's on.
   ;
   if !pfscore1 then _Bit7_Last_Life{7} = 1 : if _Bit3_Auto_Play{3} then _Bit2_Game_Control{2} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Deletes a life.
   ;
   if pfscore1 then pfscore1 = pfscore1/4

   ;```````````````````````````````````````````````````````````````
   ;  Moves squirrel to new location and removes missile.
   ;
   player1x = (rand/2) + (rand&15) : player1y = 0 : missile0y = 250

   ;```````````````````````````````````````````````````````````````
   ;  Skips sound effect and score if auto-play is on.
   ;
   if _Bit3_Auto_Play{3} then goto __Skip_Acorn_Eaten

   ;```````````````````````````````````````````````````````````````
   ;  Subtracts 1 from the score.
   ;
   if _sc3 > 0 then score = score - 1

   ;```````````````````````````````````````````````````````````````
   ;  Sound effect 003 setup.
   ;
   if _Ch0_Sound then goto __Skip_Acorn_Eaten

   _Ch0_Sound = 3 : _Ch0_Duration=1 : _Ch0_Counter=0

__Skip_Acorn_Eaten



   ;***************************************************************
   ;
   ;  Channel 0 sound effect check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 0 sounds if sounds are off.
   ;
   if !_Ch0_Sound then goto __Skip_Channel_0

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the channel 0 duration counter.
   ;
   _Ch0_Duration = _Ch0_Duration - 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 0 sounds if duration counter is greater
   ;  than zero.
   ;
   if _Ch0_Duration then goto __Skip_Channel_0



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 001.
   ;
   ;  Fire button sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 001 isn't on.
   ;
   if _Ch0_Sound <> 1 then goto __Skip_Chan0_Sound_001

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _Data_Fire_B_Sound[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Channel_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   temp5 = _Data_Fire_B_Sound[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _Data_Fire_B_Sound[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets Duration.
   ;
   _Ch0_Duration = _Data_Fire_B_Sound[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Channel_0

__Skip_Chan0_Sound_001



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 002.
   ;
   ;  Squirrel killed sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 002 isn't on.
   ;
   if _Ch0_Sound <> 2 then goto __Skip_Chan0_Sound_002

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _Data_Enemy_Destroyed[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Channel_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   temp5 = _Data_Enemy_Destroyed[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _Data_Enemy_Destroyed[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets duration.
   ;
   _Ch0_Duration = _Data_Enemy_Destroyed[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Channel_0

__Skip_Chan0_Sound_002



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 003.
   ;
   ;  Player damaged sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 003 isn't on.
   ;
   if _Ch0_Sound <> 3 then goto __Skip_Chan0_Sound_003

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _Data_Player_Damaged[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Tells game to end if last life is lost and sound is done.
   ;
   if temp4 = 255 then if _Bit7_Last_Life{7} then _Bit2_Game_Control{2} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Channel_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   temp5 = _Data_Player_Damaged[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _Data_Player_Damaged[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets duration.
   ;
   _Ch0_Duration = _Data_Player_Damaged[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Channel_0

__Skip_Chan0_Sound_003



   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Other channel 0 sound effects go here.
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````



   ;***************************************************************
   ;
   ;  Jumps to end of channel 0 area. (This catches any mistakes.)
   ;
   goto __Skip_Channel_0



   ;***************************************************************
   ;
   ;  Clears channel 0.
   ;
__Clear_Channel_0

   ;```````````````````````````````````````````````````````````````
   ;  Turns off channel 0 sound variable and mutes channel.
   ;
   _Ch0_Sound = 0 : AUDV0 = 0



   ;***************************************************************
   ;
   ;  End of channel 0 area.
   ;
__Skip_Channel_0



   ;***************************************************************
   ;
   ;  Auto-play score flipper.
   ;
   ;  Flips between high score and current score.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if auto-play bit is not on.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Flip

   ;```````````````````````````````````````````````````````````````
   ;  Increments the auto play 2-second counter.
   ;
   _AP_2_Sec_Score_Flip = _AP_2_Sec_Score_Flip + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if auto play 2-second counter is less
   ;  than 2 seconds (120 = 2 seconds).
   ;
   if _AP_2_Sec_Score_Flip < 120 then goto __AP_Skip_Flip

   ;```````````````````````````````````````````````````````````````
   ;  Clears the 2-second counter and flips the score swapping bit.
   ;
   _AP_2_Sec_Score_Flip = 0 : _Bit6_Swap_Scores{6} = !_Bit6_Swap_Scores{6}

   ;```````````````````````````````````````````````````````````````
   ;  Skips high score swap if swap bit is off.
   ;
   if !_Bit6_Swap_Scores{6} then goto __AP_Skip_HiScore_Swap

   ;```````````````````````````````````````````````````````````````
   ;  Displays high score (blue) and skips rest of section.
   ;
   scorecolor = $AE

   _sc1 = _High_Score1 : _sc2 = _High_Score2 : _sc3 = _High_Score3

   goto __AP_Skip_Flip

__AP_Skip_HiScore_Swap

   ;```````````````````````````````````````````````````````````````
   ;  Displays current score (yellow).
   ;
   scorecolor = $1C

   _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem

__AP_Skip_Flip



   ;***************************************************************
   ;
   ;  Pause check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if auto-play is on.
   ;
   if _Bit3_Auto_Play{3} then goto __AP_Skip_Pause

   ;```````````````````````````````````````````````````````````````
   ;  Checks current position of COLOR/BW switch.
   ;
   _Bit1_BW_Check{1} = 0

   if switchbw then _Bit1_BW_Check{1} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Compares bits to see if COLOR/BW switch has moved.
   ;  The game is paused if the switch has moved.
   ;
   if _Bit0_BW_Mem{0} then if !_Bit1_BW_Check{1} then goto __Pause_Setup

   if !_Bit0_BW_Mem{0} then if _Bit1_BW_Check{1} then goto __Pause_Setup

   ;```````````````````````````````````````````````````````````````
   ;  Pauses game if fire button of second joystick is pressed.
   ;
   if joy1fire && !_Bit1_FireB_Restrainer{1} then goto __Pause_Setup

__AP_Skip_Pause



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Game Over Check
   ;
   ;  _Bit2_Game_Control{2} controls when the game ends.
   ;
   ;  0 = Game not over.
   ;  1 = Game over.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if game control bit is off.
   ;
   if !_Bit2_Game_Control{2} then goto __Skip_Check_G_Over

   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check. Puts score back to current score and jumps
   ;  back to the title screen if auto-play bit is on.
   ;
   if _Bit3_Auto_Play{3} then _Bit2_Game_Control{2} = 0 : _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem : goto __Start_Restart

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to game over set up.
   ;
   goto __Game_Over_Setup

__Skip_Check_G_Over



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Reset

   ;```````````````````````````````````````````````````````````````
   ;  Starts game during auto-play if reset switch or fire button
   ;  is pressed. Also clears auto-play bit and sets game control
   ;  bit so game will start instead of going to title screen.
   ;
   if switchreset || joy0fire then _Bit3_Auto_Play{3} = 0 : _Bit2_Game_Control{2} = 1 : goto __Start_Restart

__AP_Skip_Reset

   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Clears the game over bit so the title screen will appear.
   ;
   _Bit2_Game_Control{2} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the game over setup section and checks for a high
   ;  score, then jumps to the title screen.
   ;
   goto __Game_Over_Setup




   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;
   ;  Squirrel animation frames.
   ;
__Sq00
   player1:
   %00001010
   %00001110
   %00110011
   %01110100
end

   goto __Squirrel_Frame_Done


__Sq01
   player1:
   %00001001
   %00001110
   %00110011
   %01110100
end

   goto __Squirrel_Frame_Done


__Sq02
   player1:
   %00010001
   %00001110
   %00110011
   %01110100
end

   goto __Squirrel_Frame_Done


__Sq03
   player1:
   %00010010
   %00001110
   %00110011
   %01110100
end

   goto __Squirrel_Frame_Done





   ;***************************************************************
   ;***************************************************************
   ;
   ;  GAME OVER SETUP
   ;
   ;
__Game_Over_Setup


   ;***************************************************************
   ;
   ;  High score check.
   ;
   ;  Checks for a new high score.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Checks first byte.
   ;
   if _sc1 > _High_Score1 then goto __New_High_Score
   if _sc1 < _High_Score1 then goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  First byte equal. Checks second byte.
   ;
   if _sc2 > _High_Score2 then goto __New_High_Score
   if _sc2 < _High_Score2 then goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  Second byte equal. Checks third byte.
   ;
   if _sc3 > _High_Score3 then goto __New_High_Score
   if _sc3 < _High_Score3 then goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  All bytes equal. Skips high score.
   ;
   goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  All bytes not equal. New high score!
   ;
__New_High_Score

   _High_Score1 = _sc1 : _High_Score2 = _sc2 : _High_Score3 = _sc3

__Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the game if the reset switch was pressed. Continues
   ;  in the game over setup section if the game ended naturally.
   ;
   if !_Bit2_Game_Control{2} then goto __Start_Restart


   ;***************************************************************
   ;
   ;  Saves the latest score for the high score flip.
   ;
   _Score1_Mem = _sc1 : _Score2_Mem = _sc2 : _Score3_Mem = _sc3


   ;***************************************************************
   ;
   ;  Clears the counters.
   ;
   _Master_Counter = 0 : _Frame_Counter = 0


   ;***************************************************************
   ;
   ;  Makes sure sprites and missile are off the screen.
   ;
   player0y = 200 : player1y = 200 : missile0y = 200


   ;***************************************************************
   ;
   ;  Restrains reset switch and fire button for game over loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after entering a different segment
   ;  of the program. It also does double duty by restraining the
   ;  fire button in the game over loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets up game over playfield.
   ;
   playfield:
   .XXXXXX.XXXXXX.XXXXXXXXXX.XXXXX.
   .XX.....XX..XX.XX..XX..XX.XX....
   .XX.XXX.XXXXXX.XX..XX..XX.XXXX..
   .XX..XX.XX..XX.XX..XX..XX.XX....
   .XXXXXX.XX..XX.XX..XX..XX.XXXXX.
   ................................
   ...XXXXXX.XX..XX.XXXXX.XXXXXX...
   ...XX..XX.XX..XX.XX....XX..XX...
   ...XX..XX.XX..XX.XXXX..XXXXX....
   ...XX..XX.XX..XX.XX....XX..XX...
   ...XXXXXX...XX...XXXXX.XX..XX...
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  GAME OVER LOOP
   ;
   ;
__Game_Over_Loop



   ;***************************************************************
   ;
   ;  20 second counter.
   ;
   ;  This includes a 2 second countdown timer. Any Atari 2600
   ;  game should disable the fire button for 2 seconds when
   ;  the game is over to keep the player from restarting by
   ;  mistake. It is part of the usual standards and procedures.
   ;
   ;  This section also flips between the current score and the
   ;  high score every 2 seconds. It jumps to the title screen
   ;  after 20 seconds if the player does nothing.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments master counter every frame (60 frames = 1 second).
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if master counter is less than 2 seconds.
   ;  The master counter resets every 2 seconds (60 + 60 = 120).
   ;
   if _Master_Counter < 120 then goto __Skip_20_Second_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Increments frame counter and clears master counter.
   ;  (One increment = 2 seconds.)
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Restores the current score, resets the game, and goes to the
   ;  title screen if 20 seconds have gone by.
   ;
   ;  0 = Go to title screen.
   ;  1 = Skip title screen and play game.
   ;
   if _Frame_Counter > 9 then _Bit2_Game_Control{2} = 0 : _sc1=_Score1_Mem : _sc2=_Score2_Mem : _sc3=_Score3_Mem: goto __Start_Restart

   ;```````````````````````````````````````````````````````````````
   ;  Flips the score swapping bit.
   ;
   _Bit6_Swap_Scores{6} = !_Bit6_Swap_Scores{6}

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to current score if swap bit is off.
   ;
   if !_Bit6_Swap_Scores{6} then goto __GO_Current_Score

   ;```````````````````````````````````````````````````````````````
   ;  Displays high score (blue) and skips rest of section.
   ;
   scorecolor = $AE

   _sc1 = _High_Score1 : _sc2 = _High_Score2 : _sc3 = _High_Score3

   goto __Skip_20_Second_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Displays current score (yellow).
   ;
__GO_Current_Score

   scorecolor = $1C

   _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem

__Skip_20_Second_Counter



   ;***************************************************************
   ;
   ;  Sets background color and playfield color.
   ;
   COLUBK = $44 : COLUPF = $2C

   ;```````````````````````````````````````````````````````````````
   ;  Changes colors after 2 seconds. This is only done to let
   ;  you, the programmer, know when 2 seconds have gone by. The
   ;  color change doesn't need to happen in a real game.
   ;
   if _Frame_Counter > 0 then COLUBK = $D2 : COLUPF = $DA



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset/fire button check and end of GAME OVER loop.
   ;  
   ;  Restarts the program if the reset switch or the fire
   ;  button is pressed appropriately.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the game over loop if the initial
   ;  2 second freeze is not over.
   ;
   if _Frame_Counter = 0 then goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and jumps to beginning of game
   ;  over loop if fire button or reset switch is not pressed.
   ;
   if !switchreset && !joy0fire then _Bit0_Reset_Restrainer{0} = 0 : goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the game over loop if fire button
   ;  hasn't been released since leaving the main loop.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  The program is restarted.
   ;
   goto __Start_Restart





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF GAME OVER LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PAUSE SETUP
   ;
__Pause_Setup


   ;***************************************************************
   ;
   ;  Mutes the sound.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Restrains the fire button for the pause loop.
   ;
   _Bit1_FireB_Restrainer{1} = 1


   ;***************************************************************
   ;
   ;  Clears the pause counter.
   ;
   _Pause_Counter_Tmp = 0


   ;***************************************************************
   ;
   ;  Selects a random color scheme.
   ;
   _Pause_Color_Tmp = (rand&7)

   _Pause_Mem_Color_Tmp = _Pause_Color_Tmp





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PAUSE LOOP
   ;
__Pause_Game



   ;***************************************************************
   ;
   ;  Makes missile0 a little wider.
   ;
   NUSIZ0 = $10



   ;***************************************************************
   ;
   ;  Makes squirrel wider.
   ;
   NUSIZ1 = $05



   ;***************************************************************
   ;
   ;  Changes color scheme every 4 seconds.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increases the pause counter.
   ;
   _Pause_Counter_Tmp = _Pause_Counter_Tmp + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if counter isn't high enough.
   ;
   if _Pause_Counter_Tmp < 240 then goto __Skip_Pause_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Resets the pause counter.
   ;
   _Pause_Counter_Tmp = 0

   ;```````````````````````````````````````````````````````````````
   ;  Gets a random number from 0 to 7.
   ;
   _Pause_Color_Tmp = (rand&7)

   ;```````````````````````````````````````````````````````````````
   ;  Compares the new color scheme with the previous color scheme
   ;  and selects a new color scheme if they are the same.
   ;
   if _Pause_Color_Tmp = _Pause_Mem_Color_Tmp then _Pause_Color_Tmp = _Pause_Color_Tmp + (rand&3) + 1 : if _Pause_Color_Tmp > 7 then _Pause_Color_Tmp = _Pause_Color_Tmp - 8

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the new color scheme.
   ;
   _Pause_Mem_Color_Tmp = _Pause_Color_Tmp

   ;```````````````````````````````````````````````````````````````
   ;  Decides if the B color scheme should be used.
   ;
   _Bit2_Pause_Clr_Scheme{2} = 0

   temp5 = rand : if temp5 < 128 then _Bit2_Pause_Clr_Scheme{2} = 1

__Skip_Pause_Counter



   ;***************************************************************
   ;
   ;  Jumps to the latest color scheme.
   ;
   on _Pause_Color_Tmp goto __Ps0 __Ps1 __Ps2 __Ps3 __Ps4 __Ps5 __Ps6 __Ps7

__Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Unpause check and end of pause loop.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the pause loop if the fire button
   ;  isn't pressed. Also clears the restrainer bit.
   ;
   if !joy0fire then _Bit1_FireB_Restrainer{1} = 0 : goto __Pause_Game

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the pause loop if the fire button
   ;  hasn't been released since starting the pause loop.
   ;
   if _Bit1_FireB_Restrainer{1} then goto __Pause_Game

   ;```````````````````````````````````````````````````````````````
   ;  Remembers position of COLOR/BW switch.
   ;
   _Bit0_BW_Mem{0} = 0 : if switchbw then _Bit0_BW_Mem{0} = 1





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF PAUSE LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;  RESTORES GAME FROM PAUSE
   ;
   ;  Puts everything back the way it was.
   ;
__Restore_Game_from_Pause


   ;***************************************************************
   ;
   ;  Restrains the fire button for the main loop.
   ;
   _Bit1_FireB_Restrainer{1} = 1


   ;***************************************************************
   ;
   ;  Restores score color and more.
   ;
   scorecolor = $1C : pfscorecolor = $D2


   goto __Main_Loop





   ;***************************************************************
   ;
   ;  Sets pause colors to gray.
   ;
__Ps0

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps0B

   COLUPF = $0C : COLUP0 = $0C : COLUP1 = $0C : pfscorecolor = $0C : scorecolor = $0C

   COLUBK = $0A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to gray.
   ;
__Ps0B

   COLUPF = $0A : COLUP0 = $0A : COLUP1 = $0A : pfscorecolor = $0A : scorecolor = $0A

   COLUBK = $0C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to reddish-orange.
   ;
__Ps1

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps1B

   COLUPF = $3C : COLUP0 = $3C : COLUP1 = $3C : pfscorecolor = $3C : scorecolor = $3C

   COLUBK = $3A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to reddish-orange.
   ;
__Ps1B

   COLUPF = $3A : COLUP0 = $3A : COLUP1 = $3A : pfscorecolor = $3A : scorecolor = $3A

   COLUBK = $3C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to purple.
   ;
__Ps2

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps2B

   COLUPF = $6C : COLUP0 = $6C : COLUP1 = $6C : pfscorecolor = $6C : scorecolor = $6C

   COLUBK = $6A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to purple.
   ;
__Ps2B

   COLUPF = $6A : COLUP0 = $6A : COLUP1 = $6A : pfscorecolor = $6A : scorecolor = $6A



   COLUBK = $6C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to blue.
   ;
__Ps3

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps3B

   COLUPF = $9C : COLUP0 = $9C : COLUP1 = $9C : pfscorecolor = $9C : scorecolor = $9C

   COLUBK = $9A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to blue.
   ;
__Ps3B

   COLUPF = $9A : COLUP0 = $9A : COLUP1 = $9A : pfscorecolor = $9A : scorecolor = $9A

   COLUBK = $9C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to green.
   ;
__Ps4

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps4B

   COLUPF = $CC : COLUP0 = $CC : COLUP1 = $CC : pfscorecolor = $CC : scorecolor = $CC

   COLUBK = $CA

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to green.
   ;
__Ps4B

   COLUPF = $CA : COLUP0 = $CA : COLUP1 = $CA : pfscorecolor = $CA : scorecolor = $CA

   COLUBK = $CC

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to yellowish.
   ;
__Ps5

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps5B

   COLUPF = $FC : COLUP0 = $FC : COLUP1 = $FC : pfscorecolor = $FC : scorecolor = $FC

   COLUBK = $FA

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to yellowish.
   ;
__Ps5B

   COLUPF = $FA : COLUP0 = $FA : COLUP1 = $FA : pfscorecolor = $FA: scorecolor = $FA

   COLUBK = $FC

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to darkish-blue.
   ;
__Ps6

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps6B

   COLUPF = $8C : COLUP0 = $8C : COLUP1 = $8C : pfscorecolor = $8C : scorecolor = $8C

   COLUBK = $8A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to darkish-blue.
   ;
__Ps6B

   COLUPF = $8A : COLUP0 = $8A : COLUP1 = $8A : pfscorecolor = $8A : scorecolor = $8A

   COLUBK = $8C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to orange-brown.
   ;
__Ps7

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps7B

   COLUPF = $2C : COLUP0 = $2C : COLUP1 = $2C : pfscorecolor = $2C : scorecolor = $2C

   COLUBK = $2A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to orange-brown.
   ;
__Ps7B

   COLUPF = $2A : COLUP0 = $2A : COLUP1 = $2A : pfscorecolor = $2A : scorecolor = $2A

   COLUBK = $2C

   goto __Got_Pause_Colors





   ;***************************************************************
   ;***************************************************************
   ;
   ;
   ;  Sound effect data starts here.
   ;
   ;
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Fire button sound effect.
   ;
   data _Data_Fire_B_Sound
   8,8,2
   1
   8,8,8
   1
   8,8,12
   1
   8,8,19
   1
   8,8,23
   1
   2,8,27
   4
   255
end



   ;***************************************************************
   ;
   ;  Enemy Destroyed sound effect.
   ;
   data _Data_Enemy_Destroyed
   10,8,15
   1
   8,15,15
   1
   8,4,17
   1
   6,7,16
   1
   4,8,19
   1
   2,7,10
   1
   6,4,18
   1
   6,8,5
   1
   10,7,10
   1
   10,4,19
   1
   10,8,29
   1
   2,4,21
   1
   2,15,18
   8
   255
end



   ;***************************************************************
   ;
   ;  Player Damaged sound effect.
   ;
   data _Data_Player_Damaged
   12,8,3
   1
   8,6,3
   1
   6,8,6
   1
   8,8,9
   1
   10,8,12
   1
   8,8,15
   1
   6,8,17
   1
   4,8,19
   1
   8,8,21
   1
   10,8,23
   1
   12,8,25
   1
   10,8,27
   1
   8,8,27
   1
   6,8,29
   1
   4,6,29
   1
   2,8,31
   8
   255
end
 
   ;****************************************************************
   ;
   ;  Tinkernut World Deluxe With Double Animation
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) made by
   ;  adapting the original Tinkernut World from www.tinkernut.com
   ;  and using hints, tips, code snippets, and more from AtariAge
   ;  members such as batari, SeaGtGruff, RevEng, Robert M, Nukey
   ;  Shay, Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;  High score code provided by supercat and polished up by
   ;  Nukey Shay.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Shoot the squirrel before he eats you.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  _Master_Counter can be used for many things, but it is 
   ;  really useful for animating sprite frames when used
   ;  with _Frame_Counter.
   ;
   dim _Master_Counter = a
   dim _Frame_Counter = b

   ;```````````````````````````````````````````````````````````````
   ;  Sound variables.
   ;
   dim _Ch0_Sound = c
   dim _Ch0_Counter = d
   dim _C0 = e
   dim _V0 = f
   dim _F0 = g

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used in the pause loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _Pause_Counter_Tmp = h

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used for auto-play in the main loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _AP_2_Sec_Score_Flip = i

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used in the pause loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _Pause_Mem_Color_Tmp = i

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used for auto-play in the main loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _AP_Dir_Counter = j

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used in the pause loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play or the pause feature.
   ;
   dim _Pause_Color_Tmp = j

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _BitOp_02 = r

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the position of the BW switch.
   ;
   dim _Bit0_BW_Mem = r

   ;```````````````````````````````````````````````````````````````
   ;  Checks to see if the BW switch has moved.
   ;
   dim _Bit1_BW_Check = r

   ;```````````````````````````````````````````````````````````````
   ;  Lets pause section know if the B color scheme should be used.
   ;
   dim _Bit2_Pause_Clr_Scheme = r

   ;```````````````````````````````````````````````````````````````
   ;  Auto-play direction bit for player0 sprite.
   ;
   dim _Bit3_AP_P0_Dir = r

   ;```````````````````````````````````````````````````````````````
   ;  Converts 6 digit score to 3 sets of two digits.
   ;
   ;  The 100 thousands and 10 thousands digits are held by _sc1.
   ;  The thousands and hundreds digits are held by _sc2.
   ;  The tens and ones digits are held by _sc3.
   ;
   dim _sc1 = score
   dim _sc2 = score+1
   dim _sc3 = score+2

   ;```````````````````````````````````````````````````````````````
   ;  These can be used for other things using different aliases,
   ;  but for the game over loop and auto-play in the main loop,
   ;  they are used to temporarily remember the score for the 2
   ;  second score/high score flip.
   ;
   dim _Score1_Mem = s
   dim _Score2_Mem = t
   dim _Score3_Mem = u

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the high score until the game is turned off.
   ;
   dim _High_Score1 = v
   dim _High_Score2 = w
   dim _High_Score3 = x

   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y
   dim _Bit1_FireB_Restrainer = y
   dim _Bit2_Game_Control = y
   dim _Bit3_Auto_Play = y
   dim _Bit6_Swap_Scores = y
   dim _Bit7_Last_Life = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers. 
   ;
   dim rand16 = z



   ;***************************************************************
   ;
   ;  Turns on pfscore bars.
   ;
   const pfscore = 1



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for an 8 x 8 sprite.
   ;  If your sprite is a different size, you'll need to adjust
   ;  the numbers.
   ;
   const _P_Edge_Top = 10
   const _P_Edge_Bottom = 83
   const _P_Edge_Left = 1
   const _P_Edge_Right = 153





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears 21 of the normal 26 variables (fastest way).
   ;  Do not clear v, w, x, y, or z in this program. The variables
   ;  v through x remember the high score. The variable y holds a
   ;  bit that should not be cleared. The variable z is used for
   ;  random numbers in this program and clearing it would mess
   ;  up those random numbers.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0


   ;***************************************************************
   ;
   ;  Clears 7 of the 8 bits.
   ;
   ;  Bit 2 is not cleared because _Bit2_Game_Control{2} is used
   ;  to control how the program is reset.
   ;
   _BitOp_01 = _BitOp_01 & %00000100


   ;***************************************************************
   ;
   ;  Makes sure sprites and missile are off the screen.
   ;
   player0y = 200 : player1y = 200 : missile0y = 200


   ;***************************************************************
   ;
   ;  Skips title screen if game has been played and player
   ;  presses fire button or reset switch at the end of the game.
   ;
   ;  0 = Go to title screen.
   ;  1 = Skip title screen and play game.
   ;
   if _Bit2_Game_Control{2} then goto __Main_Loop_Setup





   ;***************************************************************
   ;***************************************************************
   ;
   ;   TITLE SCREEN SETUP
   ;
   ;
__Setup_Title_Screen


   ;***************************************************************
   ;
   ;  Clears lives and sets score color.
   ;
   pfscore1 = 0 : scorecolor = $20


   ;***************************************************************
   ;
   ;  Sets title screen background color.
   ;
   COLUBK = $20


   ;***************************************************************
   ;
   ;  Restrains the reset switch.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after entering a different segment
   ;  of the program. It also does double duty by restraining the
   ;  fire button in the title screen loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets up title screen playfield.
   ;
   playfield:
   XXX.X..X.X.X.XX.XX..X..X.X.X.XXX
   .X..X..X.X.X.X..X.X.X..X.X.X..X.
   .X..XX.X.XX..XX.XX..XX.X.X.X..X.
   .X..X.XX.X.X.X..X.X.X.XX.X.X..X.
   .X..X..X.X.X.XX.X.X.X..X.XXX..X.
   ................................
   ....X...X.XXXX.XXX..X...XXX.....
   ....X...X.X..X.X..X.X...X..X....
   ....X...X.X..X.XX...X...X..X....
   ....X.X.X.X..X.X.X..X...X..X....
   ....XX.XX.XXXX.X..X.XXX.XXX.....
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  TITLE SCREEN LOOP
   ;
   ;
__Title_Screen_Loop



   ;***************************************************************
   ;
   ;  Sets title screen playfield pixel color.
   ;
   COLUPF = $D8



   ;***************************************************************
   ;
   ;  Auto-play check.
   ;
   ;  Switches to auto-play after 10 seconds if player doesn't
   ;  start the game.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increment _Master_Counter.
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if counter is less than one second.
   ;
   if _Master_Counter < 60 then goto __TS_AP_Skip

   ;```````````````````````````````````````````````````````````````
   ;  Increments _Frame_Counter and clears _Master_Counter.
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check.
   ;
   ;  Turns on auto-play and jumps to main loop setup if 10 
   ;  seconds have gone by.
   ;
   if _Frame_Counter > 9 then _Bit3_Auto_Play{3} = 1 : goto __Main_Loop_Setup

__TS_AP_Skip



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset/fire button check and end of title screen loop.
   ;  
   ;  Starts the game if the reset switch or the fire button
   ;  is pressed appropriately.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and jumps to beginning of title 
   ;  screen loop if fire button or reset switch is not pressed.
   ;
   if !switchreset && !joy0fire then _Bit0_Reset_Restrainer{0} = 0 : goto __Title_Screen_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of title screen loop if reset or fire 
   ;  hasn't been released since starting title screen loop.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Title_Screen_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Sets control bit so program will jump to main loop setup.
   ;
   _Bit2_Game_Control{2} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Restarts game and program jumps to main loop setup.
   ;
   goto __Start_Restart





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP SETUP
   ;
   ;
__Main_Loop_Setup


   ;***************************************************************
   ;
   ;  In the main loop, _Bit2_Game_Control{2} controls when the
   ;  game ends.
   ;
   ;  0 = Game not over.
   ;  1 = Game over.
   ;
   _Bit2_Game_Control{2} = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed in the title
   ;  screen section or the game over section. If the reset
   ;  switch isn't being held down, this bit will be cleared
   ;  in the main loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Restrains the fire button for the main loop.
   ;
   ;  This bit fixes it so the fire button becomes inactive if it
   ;  hasn't been released after being pressed in the title
   ;  screen section or the game over section. If the fire
   ;  button isn't being held down, this bit will be cleared
   ;  in the main loop.
   ;
   _Bit1_FireB_Restrainer{1} = 1


   ;***************************************************************
   ;
   ;  Starting position of player0 (acorn).
   ;
   player0x = 74 : player0y = 78


   ;***************************************************************
   ;
   ;  Starting position of player1 (squirrel).
   ;
   player1x = (rand/2) + (rand&15) : player1y = 0 


   ;***************************************************************
   ;
   ;  Defines missile0 height and location.
   ;
   missile0height = 4 : missile0y = 250


   ;***************************************************************
   ;
   ;  Sets score color.
   ;
   scorecolor = $1C


   ;***************************************************************
   ;
   ;  Sets number of lives and sets color.
   ;
   pfscore1 = %01010101 : pfscorecolor = $D2


   ;***************************************************************
   ;
   ;  Sets up the main loop playfield.
   ;
   playfield:
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   ...............................
   ...............................
   ...............................
   ...............................
   ...............................
   ...............................
   ...............................
   ...............................
   ...............................
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end


   ;***************************************************************
   ;
   ;  Remembers position of COLOR/BW switch.
   ;
   _Bit0_BW_Mem{0} = 0 : if switchbw then _Bit0_BW_Mem{0} = 1


   ;***************************************************************
   ;
   ;  Auto-play score swap setup.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears score and skips section if auto-play is off.
   ;
   if !_Bit3_Auto_Play{3} then score = 0 : goto __AP_Skip_AP_Setup

   ;```````````````````````````````````````````````````````````````
   ;  Clears variables.
   ;
   _Master_Counter = 0 : _Frame_Counter = 0 

   ;```````````````````````````````````````````````````````````````
   ;  Sets up the score swap and clears the swap bit.
   ;
   _Score1_Mem = _sc1 : _Score2_Mem = _sc2 : _Score3_Mem = _sc3

   _Bit6_Swap_Scores{6} = 0

__AP_Skip_AP_Setup





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE GAME GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = $D6



   ;***************************************************************
   ;
   ;  Sets playfield pixel color.
   ;
   COLUPF = 0



   ;***************************************************************
   ;
   ;  Sets sprite colors.
   ;
   COLUP0 = $22 : COLUP1 = $20



   ;***************************************************************
   ;
   ;  Makes missile0 a little wider.
   ;
   NUSIZ0 = $10



   ;***************************************************************
   ;
   ;  Makes squirrel wider.
   ;
   NUSIZ1 = $05



   ;***************************************************************
   ;
   ;  Animation counters.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments _Master_Counter.
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if _Master_Counter is less than 7.
   ;
   if _Master_Counter < 7 then goto __Skip_Counters

   ;```````````````````````````````````````````````````````````````
   ;  Increments _Frame_Counter and clears _Master_Counter.
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Clears _Frame_Counter if it is greater than 3.
   ;
   if _Frame_Counter > 3 then _Frame_Counter = 0

__Skip_Counters



   ;***************************************************************
   ;
   ;  Squirrel animation (4 frames, 0 through 3).
   ;
   on _Frame_Counter goto __Sq00 __Sq01 __Sq02 __Sq03

__Squirrel_Frame_Done



   ;***************************************************************
   ;
   ;  Acorn animation (4 frames, 0 through 3).
   ;
   on _Frame_Counter goto __Ac00 __Ac01 __Ac02 __Ac03

__Acorn_Frame_Done



   ;***************************************************************
   ;
   ;  Missile0 check and fire button check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps to fire button check if missile0 is off the screen.
   ;
   if missile0y > 240 then goto __FireB_Check

   ;```````````````````````````````````````````````````````````````
   ;  Moves missile0 and skips fire button check.
   ;
   missile0y = missile0y - 2 : goto __Skip_FireB

__FireB_Check

   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if auto-play is off.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Fire_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Determines if sprite should fire during auto-play.
   ;  There is a 90% chance that the missile will not fire.
   ;
   temp5 = rand : if temp5 < 230 then goto __Skip_FireB

   goto __AP_Fire

__AP_Skip_Fire_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and skips this section if fire
   ;  button is not pressed.
   ;
   if !joy0fire then _Bit1_FireB_Restrainer{1} = 0 : goto __Skip_FireB

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if fire button hasn't been released since
   ;  the title screen.
   ;
   if _Bit1_FireB_Restrainer{1} then goto __Skip_FireB

__AP_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Starts the firing of missile0.
   ;
   missile0y = player0y - 2 : missile0x = player0x + 4

__Skip_FireB



   ;***************************************************************
   ;
   ;  Auto-play direction change for player0 sprite.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if auto-play is off.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_New_Dir

   ;```````````````````````````````````````````````````````````````
   ;  Adds to the auto-play direction change counter.
   ;
   _AP_Dir_Counter = _AP_Dir_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Grabs a random number (0 to 63) and adds 50. Change 50 to a
   ;  larger number if you want the sprite to move longer before
   ;  changing directions. Don't use a number larger than 190.
   ;
   temp6 = (rand&63) + 50

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the counter isn't high enough.
   ;
   if _AP_Dir_Counter < temp6 then goto __AP_Move_Acorn

   ;```````````````````````````````````````````````````````````````
   ;  Grabs a random number (0 to 255).
   ;
   temp5 = rand

   ;```````````````````````````````````````````````````````````````
   ;  There is a 90% chance that this section will be skipped.
   ;
   if temp5 < 230 then goto __AP_Move_Acorn

   ;```````````````````````````````````````````````````````````````
   ;  Changes player0 direction.
   ;
   _Bit3_AP_P0_Dir{3} = !_Bit3_AP_P0_Dir{3}

   ;```````````````````````````````````````````````````````````````
   ;  Clears counter.
   ;
   _AP_Dir_Counter = 0

__AP_Move_Acorn

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 sprite.
   ;
   if !_Bit3_AP_P0_Dir{3} then if player0x > _P_Edge_Left then player0x = player0x - 1
   if _Bit3_AP_P0_Dir{3} then if player0x < _P_Edge_Right then player0x = player0x + 1

   goto __Skip_Joy_Movement

__AP_Skip_New_Dir



   ;***************************************************************
   ;
   ;  Joystick movement check. This section is skipped if
   ;  auto-play is on.
   ;
   if joy0up then if player0y > _P_Edge_Top then player0y = player0y - 1
   if joy0down then if player0y < _P_Edge_Bottom then player0y = player0y + 1
   if joy0left then if player0x > _P_Edge_Left then player0x = player0x - 1
   if joy0right then if player0x < _P_Edge_Right then player0x = player0x + 1

__Skip_Joy_Movement



   ;***************************************************************
   ;
   ;  Squirrel chases the player.
   ;
   if player1y < player0y then player1y = player1y + 1
   if player1y > player0y then player1y = player1y - 1
   temp5 = player1x + 8 : if temp5 < player0x then if player1x < 144 then player1x = player1x + 1
   temp5 = player1x + 8 : if temp5 > player0x then if player1x > 0 then player1x = player1x - 1



   ;***************************************************************
   ;
   ;  Squirrel/missile0 collision check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if there is no collision.
   ;
   if !collision(missile0,player1) then goto __Skip_Squirrel_Kill

   ;```````````````````````````````````````````````````````````````
   ;  Temporarily remembers squirrel's y position.
   ;
   temp6 = player1y

   ;```````````````````````````````````````````````````````````````
   ;  Moves squirrel to new location and removes missile.
   ;
   player1x = (rand/2) + (rand&15) : player1y = 0 : missile0y = 250

   ;```````````````````````````````````````````````````````````````
   ;  Skips sound and points if auto-play is on.
   ;
   if _Bit3_Auto_Play{3} then goto __Skip_Squirrel_Kill

   ;```````````````````````````````````````````````````````````````
   ;  Adds 1 to the score.
   ;
   score = score + 1

   ;```````````````````````````````````````````````````````````````
   ;  Sound effect 1 setup.
   ;
   if _Ch0_Sound then goto __Skip_Squirrel_Kill

   _Ch0_Sound = 1 : _Ch0_Counter = 10

   _C0 = 4 : _V0 = 12 : _F0 = 14

   ;```````````````````````````````````````````````````````````````
   ;  Makes a different sound when closer to player.
   ;
   temp5 = 255 : if player0y > temp6 then temp5 = player0y - temp6

   if temp5 < 30 then _C0 = 12

__Skip_Squirrel_Kill



   ;***************************************************************
   ;
   ;  Squirrel/acorn collision check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if there is no collision.
   ;
   if !collision(player0,player1) then goto __Skip_Acorn_Eaten

   ;```````````````````````````````````````````````````````````````
   ;  Activates last life bit if pfscore1 bar is empty. Also ends
   ;  auto-play if it's on.
   ;
   if !pfscore1 then _Bit7_Last_Life{7} = 1 : if _Bit3_Auto_Play{3} then _Bit2_Game_Control{2} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Deletes a life.
   ;
   if pfscore1 then pfscore1 = pfscore1/4

   ;```````````````````````````````````````````````````````````````
   ;  Moves squirrel to new location and removes missile.
   ;
   player1x = (rand/2) + (rand&15) : player1y = 0 : missile0y = 250

   ;```````````````````````````````````````````````````````````````
   ;  Skips sound effect and score if auto-play is on.
   ;
   if _Bit3_Auto_Play{3} then goto __Skip_Acorn_Eaten

   ;```````````````````````````````````````````````````````````````
   ;  Subtracts 1 from the score.
   ;
   if _sc3 > 0 then score = score - 1

   ;```````````````````````````````````````````````````````````````
   ;  Sound effect 2 setup.
   ;
   if _Ch0_Sound then goto __Skip_Acorn_Eaten

   _Ch0_Sound = 2 : _Ch0_Counter = 10

   _C0 = 7 : _V0 = 12 : _F0 = 12

__Skip_Acorn_Eaten



   ;***************************************************************
   ;
   ;  Point sound.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the sound isn't on.
   ;
   if _Ch0_Sound <> 1 then goto __Skip_Sound1

   ;```````````````````````````````````````````````````````````````
   ;  Flips the frequency between 11 and 14.
   ;
   _F0 = _F0 ^ 5

   ;```````````````````````````````````````````````````````````````
   ;  Sets the tone, volume and frequency.
   ;
   AUDC0 = _C0 : AUDV0 = _V0 : AUDF0 = _F0

   ;```````````````````````````````````````````````````````````````
   ;  Decreases volume by 1 and makes sure it doesn't go below 2.
   ;
   _V0 = _V0 - 1 : if _V0 < 2 then _V0 = 2

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the sound counter.
   ;
   _Ch0_Counter = _Ch0_Counter - 1

   ;```````````````````````````````````````````````````````````````
   ;  Clears _Ch0_Sound and mutes channel if sound counter is zero.
   ;
   if !_Ch0_Counter then _Ch0_Sound = 0 : AUDV0 = 0

__Skip_Sound1



   ;***************************************************************
   ;
   ;  Squirrel eats acorn sound.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the sound isn't on.
   ;
   if _Ch0_Sound <> 2 then goto __Skip_Sound2

   ;```````````````````````````````````````````````````````````````
   ;  Sets the tone, volume and frequency.
   ;
   AUDC0 = _C0 : AUDV0 = _V0 : AUDF0 = _F0

   ;```````````````````````````````````````````````````````````````
   ;  Decreases volume by 1 and makes sure it doesn't go below 2.
   ;
   _V0 = _V0 - 1 : if _V0 < 2 then _V0 = 2

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the sound counter.
   ;
   _Ch0_Counter = _Ch0_Counter - 1

   ;```````````````````````````````````````````````````````````````
   ;  Clears _Ch0_Sound and mutes channel if sound counter is zero.
   ;  Also tells game to end if last life is lost.
   ;
   if !_Ch0_Counter then _Ch0_Sound = 0 : AUDV0 = 0 : if _Bit7_Last_Life{7} then _Bit2_Game_Control{2} = 1

__Skip_Sound2



   ;***************************************************************
   ;
   ;  Auto-play score flipper.
   ;
   ;  Flips between high score and current score.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if auto-play bit is not on.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Flip

   ;```````````````````````````````````````````````````````````````
   ;  Increments the auto play 2-second counter.
   ;
   _AP_2_Sec_Score_Flip = _AP_2_Sec_Score_Flip + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if auto play 2-second counter is less
   ;  than 2 seconds (120 = 2 seconds).
   ;
   if _AP_2_Sec_Score_Flip < 120 then goto __AP_Skip_Flip

   ;```````````````````````````````````````````````````````````````
   ;  Clears the 2-second counter and flips the score swapping bit.
   ;
   _AP_2_Sec_Score_Flip = 0 : _Bit6_Swap_Scores{6} = !_Bit6_Swap_Scores{6}

   ;```````````````````````````````````````````````````````````````
   ;  Skips high score swap if swap bit is off.
   ;
   if !_Bit6_Swap_Scores{6} then goto __AP_Skip_HiScore_Swap

   ;```````````````````````````````````````````````````````````````
   ;  Displays high score (blue) and skips rest of section.
   ;
   scorecolor = $AE

   _sc1 = _High_Score1 : _sc2 = _High_Score2 : _sc3 = _High_Score3

   goto __AP_Skip_Flip

__AP_Skip_HiScore_Swap

   ;```````````````````````````````````````````````````````````````
   ;  Displays current score (yellow).
   ;
   scorecolor = $1C

   _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem

__AP_Skip_Flip



   ;***************************************************************
   ;
   ;  Pause check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if auto-play is on.
   ;
   if _Bit3_Auto_Play{3} then goto __AP_Skip_Pause

   ;```````````````````````````````````````````````````````````````
   ;  Checks current position of COLOR/BW switch.
   ;
   _Bit1_BW_Check{1} = 0

   if switchbw then _Bit1_BW_Check{1} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Compares bits to see if COLOR/BW switch has moved.
   ;  The game is paused if the switch has moved.
   ;
   if _Bit0_BW_Mem{0} then if !_Bit1_BW_Check{1} then goto __Pause_Setup

   if !_Bit0_BW_Mem{0} then if _Bit1_BW_Check{1} then goto __Pause_Setup

   ;```````````````````````````````````````````````````````````````
   ;  Pauses game if fire button of second joystick is pressed.
   ;
   if joy1fire && !_Bit1_FireB_Restrainer{1} then goto __Pause_Setup

__AP_Skip_Pause



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Game Over Check
   ;
   ;  _Bit2_Game_Control{2} controls when the game ends.
   ;
   ;  0 = Game not over.
   ;  1 = Game over.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if game control bit is off.
   ;
   if !_Bit2_Game_Control{2} then goto __Skip_Check_G_Over

   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check. Puts score back to current score and jumps
   ;  back to the title screen if auto-play bit is on.
   ;
   if _Bit3_Auto_Play{3} then _Bit2_Game_Control{2} = 0 : _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem : goto __Start_Restart

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to game over set up.
   ;
   goto __Game_Over_Setup

__Skip_Check_G_Over



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Reset

   ;```````````````````````````````````````````````````````````````
   ;  Starts game during auto-play if reset switch or fire button
   ;  is pressed. Also clears auto-play bit and sets game control
   ;  bit so game will start instead of going to title screen.
   ;
   if switchreset || joy0fire then _Bit3_Auto_Play{3} = 0 : _Bit2_Game_Control{2} = 1 : goto __Start_Restart

__AP_Skip_Reset

   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Clears the game over bit so the title screen will appear.
   ;
   _Bit2_Game_Control{2} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the game over setup section and checks for a high
   ;  score, then jumps to the title screen.
   ;
   goto __Game_Over_Setup




   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;
   ;  Acorn animation frames.
   ;
__Ac00
   player0:
   %00011000
   %00111000
   %00111100
   %01111110
   %01111110
   %11111111
   %01111110
   %00011000
end

   goto __Acorn_Frame_Done


__Ac01
   player0:
   %00011000
   %00110100
   %00111100
   %01111110
   %01111110
   %11111111
   %01111110
   %00011000
end

   goto __Acorn_Frame_Done


__Ac02
   player0:
   %00011000
   %00101100
   %00111100
   %01111110
   %01111110
   %11111111
   %01111110
   %00011000
end

   goto __Acorn_Frame_Done


__Ac03
   player0:
   %00011000
   %00011100
   %00111100
   %01111110
   %01111110
   %11111111
   %01111110
   %00011000
end

   goto __Acorn_Frame_Done





   ;***************************************************************
   ;
   ;  Squirrel animation frames.
   ;
__Sq00
   player1:
   %00001010
   %00001110
   %00110011
   %01110100
end

   goto __Squirrel_Frame_Done


__Sq01
   player1:
   %00001001
   %00001110
   %00110011
   %01110100
end

   goto __Squirrel_Frame_Done


__Sq02
   player1:
   %00010001
   %00001110
   %00110011
   %01110100
end

   goto __Squirrel_Frame_Done


__Sq03
   player1:
   %00010010
   %00001110
   %00110011
   %01110100
end

   goto __Squirrel_Frame_Done





   ;***************************************************************
   ;***************************************************************
   ;
   ;  GAME OVER SETUP
   ;
   ;
__Game_Over_Setup


   ;***************************************************************
   ;
   ;  High score check.
   ;
   ;  Checks for a new high score.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Checks first byte.
   ;
   if _sc1 > _High_Score1 then goto __New_High_Score
   if _sc1 < _High_Score1 then goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  First byte equal. Checks second byte.
   ;
   if _sc2 > _High_Score2 then goto __New_High_Score
   if _sc2 < _High_Score2 then goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  Second byte equal. Checks third byte.
   ;
   if _sc3 > _High_Score3 then goto __New_High_Score
   if _sc3 < _High_Score3 then goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  All bytes equal. Skips high score.
   ;
   goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  All bytes not equal. New high score!
   ;
__New_High_Score

   _High_Score1 = _sc1 : _High_Score2 = _sc2 : _High_Score3 = _sc3

__Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the game if the reset switch was pressed. Continues
   ;  in the game over setup section if the game ended naturally.
   ;
   if !_Bit2_Game_Control{2} then goto __Start_Restart


   ;***************************************************************
   ;
   ;  Saves the latest score for the high score flip.
   ;
   _Score1_Mem = _sc1 : _Score2_Mem = _sc2 : _Score3_Mem = _sc3


   ;***************************************************************
   ;
   ;  Clears the counters.
   ;
   _Master_Counter = 0 : _Frame_Counter = 0


   ;***************************************************************
   ;
   ;  Makes sure sprites and missile are off the screen.
   ;
   player0y = 200 : player1y = 200 : missile0y = 200


   ;***************************************************************
   ;
   ;  Restrains reset switch and fire button for game over loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after entering a different segment
   ;  of the program. It also does double duty by restraining the
   ;  fire button in the game over loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets up game over playfield.
   ;
   playfield:
   .XXXXXX.XXXXXX.XXXXXXXXXX.XXXXX.
   .XX.....XX..XX.XX..XX..XX.XX....
   .XX.XXX.XXXXXX.XX..XX..XX.XXXX..
   .XX..XX.XX..XX.XX..XX..XX.XX....
   .XXXXXX.XX..XX.XX..XX..XX.XXXXX.
   ................................
   ...XXXXXX.XX..XX.XXXXX.XXXXXX...
   ...XX..XX.XX..XX.XX....XX..XX...
   ...XX..XX.XX..XX.XXXX..XXXXX....
   ...XX..XX.XX..XX.XX....XX..XX...
   ...XXXXXX...XX...XXXXX.XX..XX...
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  GAME OVER LOOP
   ;
   ;
__Game_Over_Loop



   ;***************************************************************
   ;
   ;  20 second counter.
   ;
   ;  This includes a 2 second countdown timer. Any Atari 2600
   ;  game should disable the fire button for 2 seconds when
   ;  the game is over to keep the player from restarting by
   ;  mistake. It is part of the usual standards and procedures.
   ;
   ;  This section also flips between the current score and the
   ;  high score every 2 seconds. It jumps to the title screen
   ;  after 20 seconds if the player does nothing.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments master counter every frame (60 frames = 1 second).
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if master counter is less than 2 seconds.
   ;  The master counter resets every 2 seconds (60 + 60 = 120).
   ;
   if _Master_Counter < 120 then goto __Skip_20_Second_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Increments frame counter and clears master counter.
   ;  (One increment = 2 seconds.)
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Restores the current score, resets the game, and goes to the
   ;  title screen if 20 seconds have gone by.
   ;
   ;  0 = Go to title screen.
   ;  1 = Skip title screen and play game.
   ;
   if _Frame_Counter > 9 then _Bit2_Game_Control{2} = 0 : _sc1=_Score1_Mem : _sc2=_Score2_Mem : _sc3=_Score3_Mem: goto __Start_Restart

   ;```````````````````````````````````````````````````````````````
   ;  Flips the score swapping bit.
   ;
   _Bit6_Swap_Scores{6} = !_Bit6_Swap_Scores{6}

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to current score if swap bit is off.
   ;
   if !_Bit6_Swap_Scores{6} then goto __GO_Current_Score

   ;```````````````````````````````````````````````````````````````
   ;  Displays high score (blue) and skips rest of section.
   ;
   scorecolor = $AE

   _sc1 = _High_Score1 : _sc2 = _High_Score2 : _sc3 = _High_Score3

   goto __Skip_20_Second_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Displays current score (yellow).
   ;
__GO_Current_Score

   scorecolor = $1C

   _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem

__Skip_20_Second_Counter



   ;***************************************************************
   ;
   ;  Sets background color and playfield color.
   ;
   COLUBK = $44 : COLUPF = $2C

   ;```````````````````````````````````````````````````````````````
   ;  Changes colors after 2 seconds. This is only done to let
   ;  you, the programmer, know when 2 seconds have gone by. The
   ;  color change doesn't need to happen in a real game.
   ;
   if _Frame_Counter > 0 then COLUBK = $D2 : COLUPF = $DA



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset/fire button check and end of GAME OVER loop.
   ;  
   ;  Restarts the program if the reset switch or the fire
   ;  button is pressed appropriately.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the game over loop if the initial
   ;  2 second freeze is not over.
   ;
   if _Frame_Counter = 0 then goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and jumps to beginning of game
   ;  over loop if fire button or reset switch is not pressed.
   ;
   if !switchreset && !joy0fire then _Bit0_Reset_Restrainer{0} = 0 : goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the game over loop if fire button
   ;  hasn't been released since leaving the main loop.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  The program is restarted.
   ;
   goto __Start_Restart





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF GAME OVER LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PAUSE SETUP
   ;
__Pause_Setup


   ;***************************************************************
   ;
   ;  Mutes the sound.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Restrains the fire button for the pause loop.
   ;
   _Bit1_FireB_Restrainer{1} = 1


   ;***************************************************************
   ;
   ;  Clears the pause counter.
   ;
   _Pause_Counter_Tmp = 0


   ;***************************************************************
   ;
   ;  Selects a random color scheme.
   ;
   _Pause_Color_Tmp = (rand&7)

   _Pause_Mem_Color_Tmp = _Pause_Color_Tmp





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PAUSE LOOP
   ;
__Pause_Game



   ;***************************************************************
   ;
   ;  Makes missile0 a little wider.
   ;
   NUSIZ0 = $10



   ;***************************************************************
   ;
   ;  Makes squirrel wider.

   ;
   NUSIZ1 = $05



   ;***************************************************************
   ;
   ;  Changes color scheme every 4 seconds.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increases the pause counter.
   ;
   _Pause_Counter_Tmp = _Pause_Counter_Tmp + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if counter isn't high enough.
   ;
   if _Pause_Counter_Tmp < 240 then goto __Skip_Pause_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Resets the pause counter.
   ;
   _Pause_Counter_Tmp = 0

   ;```````````````````````````````````````````````````````````````
   ;  Gets a random number from 0 to 7.
   ;
   _Pause_Color_Tmp = (rand&7)

   ;```````````````````````````````````````````````````````````````
   ;  Compares the new color scheme with the previous color scheme
   ;  and selects a new color scheme if they are the same.
   ;
   if _Pause_Color_Tmp = _Pause_Mem_Color_Tmp then _Pause_Color_Tmp = _Pause_Color_Tmp + (rand&3) + 1 : if _Pause_Color_Tmp > 7 then _Pause_Color_Tmp = _Pause_Color_Tmp - 8

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the new color scheme.
   ;
   _Pause_Mem_Color_Tmp = _Pause_Color_Tmp

   ;```````````````````````````````````````````````````````````````
   ;  Decides if the B color scheme should be used.
   ;
   _Bit2_Pause_Clr_Scheme{2} = 0

    temp5 = rand : if temp5 < 128 then _Bit2_Pause_Clr_Scheme{2} = 1

__Skip_Pause_Counter



   ;***************************************************************
   ;
   ;  Jumps to the latest color scheme.
   ;
   on _Pause_Color_Tmp goto __Ps0 __Ps1 __Ps2 __Ps3 __Ps4 __Ps5 __Ps6 __Ps7

__Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Unpause check and end of pause loop.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the pause loop if the fire button
   ;  isn't pressed. Also clears the restrainer bit.
   ;
   if !joy0fire then _Bit1_FireB_Restrainer{1} = 0 : goto __Pause_Game

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the pause loop if the fire button
   ;  hasn't been released since starting the pause loop.
   ;
   if _Bit1_FireB_Restrainer{1} then goto __Pause_Game

   ;```````````````````````````````````````````````````````````````
   ;  Remembers position of COLOR/BW switch.
   ;
   _Bit0_BW_Mem{0} = 0 : if switchbw then _Bit0_BW_Mem{0} = 1





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF PAUSE LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;  RESTORES GAME FROM PAUSE
   ;
   ;  Puts everything back the way it was.
   ;
__Restore_Game_from_Pause


   ;***************************************************************
   ;
   ;  Restrains the fire button for the main loop.
   ;
   _Bit1_FireB_Restrainer{1} = 1


   ;***************************************************************
   ;
   ;  Restores score color and more.
   ;
   scorecolor = $1C : pfscorecolor = $D2


   goto __Main_Loop





   ;***************************************************************
   ;
   ;  Sets pause colors to gray.
   ;
__Ps0

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps0B

   COLUPF = $0C : COLUP0 = $0C : COLUP1 = $0C : pfscorecolor = $0C : scorecolor = $0C

   COLUBK = $0A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to gray.
   ;
__Ps0B

   COLUPF = $0A : COLUP0 = $0A : COLUP1 = $0A : pfscorecolor = $0A : scorecolor = $0A

   COLUBK = $0C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to reddish-orange.
   ;
__Ps1

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps1B

   COLUPF = $3C : COLUP0 = $3C : COLUP1 = $3C : pfscorecolor = $3C : scorecolor = $3C

   COLUBK = $3A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to reddish-orange.
   ;
__Ps1B

   COLUPF = $3A : COLUP0 = $3A : COLUP1 = $3A : pfscorecolor = $3A : scorecolor = $3A

   COLUBK = $3C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to purple.
   ;
__Ps2

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps2B

   COLUPF = $6C : COLUP0 = $6C : COLUP1 = $6C : pfscorecolor = $6C : scorecolor = $6C

   COLUBK = $6A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to purple.
   ;
__Ps2B

   COLUPF = $6A : COLUP0 = $6A : COLUP1 = $6A : pfscorecolor = $6A : scorecolor = $6A



   COLUBK = $6C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to blue.
   ;
__Ps3

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps3B

   COLUPF = $9C : COLUP0 = $9C : COLUP1 = $9C : pfscorecolor = $9C : scorecolor = $9C

   COLUBK = $9A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to blue.
   ;
__Ps3B

   COLUPF = $9A : COLUP0 = $9A : COLUP1 = $9A : pfscorecolor = $9A : scorecolor = $9A

   COLUBK = $9C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to green.
   ;
__Ps4

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps4B

   COLUPF = $CC : COLUP0 = $CC : COLUP1 = $CC : pfscorecolor = $CC : scorecolor = $CC

   COLUBK = $CA

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to green.
   ;
__Ps4B

   COLUPF = $CA : COLUP0 = $CA : COLUP1 = $CA : pfscorecolor = $CA : scorecolor = $CA

   COLUBK = $CC

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to yellowish.
   ;
__Ps5

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps5B

   COLUPF = $FC : COLUP0 = $FC : COLUP1 = $FC : pfscorecolor = $FC : scorecolor = $FC

   COLUBK = $FA

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to yellowish.
   ;
__Ps5B

   COLUPF = $FA : COLUP0 = $FA : COLUP1 = $FA : pfscorecolor = $FA: scorecolor = $FA

   COLUBK = $FC

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to darkish-blue.
   ;
__Ps6

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps6B

   COLUPF = $8C : COLUP0 = $8C : COLUP1 = $8C : pfscorecolor = $8C : scorecolor = $8C

   COLUBK = $8A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to darkish-blue.
   ;
__Ps6B

   COLUPF = $8A : COLUP0 = $8A : COLUP1 = $8A : pfscorecolor = $8A : scorecolor = $8A

   COLUBK = $8C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to orange-brown.
   ;
__Ps7

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps7B

   COLUPF = $2C : COLUP0 = $2C : COLUP1 = $2C : pfscorecolor = $2C : scorecolor = $2C

   COLUBK = $2A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to orange-brown.
   ;
__Ps7B

   COLUPF = $2A : COLUP0 = $2A : COLUP1 = $2A : pfscorecolor = $2A : scorecolor = $2A

   COLUBK = $2C

   goto __Got_Pause_Colors

 

 

 

8.8 Speed Change

8.8 Speed Change on bB page.

 
   ;***************************************************************
   ;
   ;  8.8 Speed Change
   ;
   ;  By Duane Alan Hahn (Random Terrain) using hints, tips,
   ;  code snippets, and more from AtariAge members such as
   ;  batari, SeaGtGruff, RevEng, Robert M, Atarius Maximus,
   ;  jrok, Nukey Shay, supercat, and GroovyBee.
   ;
   ;  Special data provided by bogax.
   ;
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Switches between objects.
   ;
   dim _Current_Object = a

   ;```````````````````````````````````````````````````````````````
   ;  Object jiggle counter.
   ;
   dim _Jiggle_Counter = b

   ;```````````````````````````````````````````````````````````````
   ;  Remembers position of jiggled object.
   ;
   dim _Memx = c
   dim _Memy = d

   ;```````````````````````````````````````````````````````````````
   ;  Player0 left/right movement.
   ;
   dim _P0_LR = player0x.e

   ;```````````````````````````````````````````````````````````````
   ;  Player1 left/right movement.
   ;
   dim _P1_LR = player1x.f

   ;```````````````````````````````````````````````````````````````
   ;  Ball left/right movement.
   ;
   dim _B_LR = ballx.g

   ;```````````````````````````````````````````````````````````````
   ;  Player0 left/right movement.
   ;
   dim _P0_Speed = h.i

   ;```````````````````````````````````````````````````````````````
   ;  Player0 left number.
   ;
   dim _P0_Left_Number = h

   ;```````````````````````````````````````````````````````````````
   ;  Player0 right number.
   ;
   dim _P0_Right_Number = i

   ;```````````````````````````````````````````````````````````````
   ;  Player1 left/right movement.
   ;
   dim _P1_Speed = j.k

   ;```````````````````````````````````````````````````````````````
   ;  Player1 left number.
   ;
   dim _P1_Left_Number = j

   ;```````````````````````````````````````````````````````````````
   ;  Player1 right number.
   ;
   dim _P1_Right_Number = k

   ;```````````````````````````````````````````````````````````````
   ;  Ball left/right movement.
   ;
   dim _B_Speed = l.m

   ;```````````````````````````````````````````````````````````````
   ;  Ball left number.
   ;
   dim _B_Left_Number = l

   ;```````````````````````````````````````````````````````````````
   ;  Ball right number.
   ;
   dim _B_Right_Number = m

   ;```````````````````````````````````````````````````````````````
   ;  Score speed counter.
   ;
   dim _Score_Counter = n

   ;```````````````````````````````````````````````````````````````
   ;  Score slowdown variable.
   ;
   dim _Score_Slowdown = o

   ;```````````````````````````````````````````````````````````````
   ;  Tracks the score.
   ;
   dim _Score_Right_Number = p

   ;```````````````````````````````````````````````````````````````
   ;  Remembers object speed.
   ;
   dim _P0Left_Mem = q
   dim _P0Right_Mem = r

   dim _P1Left_Mem = s
   dim _P1Right_Mem = t

   dim _BLeft_Mem = u
   dim _BRight_Mem = v

   ;```````````````````````````````````````````````````````````````
   ;  Used to figure out the left number.
   ;
   dim _Left_Number = w

   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y
   dim _Bit1_P0_Direction = y
   dim _Bit2_P1_Direction = y
   dim _Bit5_Ball_Direction = y
   dim _Bit6_Joy0_Restrainer = y
   dim _Bit7_Activate_Jiggle = y

   ;```````````````````````````````````````````````````````````````
   ;  Converts 6 digit score to 3 sets of two digits.
   ;
   ;  The 100 thousands and 10 thousands digits are held by _sc1.
   ;  The thousands and hundreds digits are held by _sc2.
   ;  The tens and ones digits are held by _sc3.
   ;
   dim _sc1 = score
   dim _sc2 = score+1
   dim _sc3 = score+2



   ;***************************************************************
   ;
   ;  Constants for the 6 objects.
   ;  [The c stands for constant.]
   ;
   const _c_Player0 = 0
   const _c_Ball = 1
   const _c_Player1 = 2



   ;***************************************************************
   ;
   ;  Default object colors.
   ;  [The c stands for constant.]
   ;
   const _c_PlayerMissile0_Color = $9C
   const _c_Ball_Color = $FC
   const _c_PlayerMissile1_Color = $CA




   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0


   ;***************************************************************
   ;
   ;  Sets starting position of player0.
   ;
   player0x = 79 : player0y = 64


   ;***************************************************************
   ;
   ;  Sets starting position of ball.
   ;
   ballx = 83 : bally = player0y - 16


   ;***************************************************************
   ;
   ;  Sets starting position of player0.
   ;
   player1x = 79 : player1y = bally - 8


   ;***************************************************************
   ;
   ;  Sets ball properties.
   ;
   CTRLPF = $01 : ballheight = 0


   ;***************************************************************
   ;
   ;  Sets the speed of the ball and player0 and player1.
   ;
   _P0_Speed = 0.72 : _B_Speed = 1.00 : _P1_Speed = 1.50


   ;***************************************************************
   ;
   ;  Sets number left of period. (Must match above.)
   ;
   _P0_Left_Number = 0 : _B_Left_Number = 1 : _P1_Left_Number = 1

   
   ;***************************************************************
   ;
   ;  Sets right score number tracker. Must be same as _P0_Speed.
   ;
    _Score_Right_Number = 72


   ;***************************************************************
   ;
   ;  Sets starting speed memory for objects.
   ;
   _P0Left_Mem = $00 : _P0Right_Mem = $72
   _BLeft_Mem = $10 : _BRight_Mem = $00
   _P1Left_Mem = $10 : _P1Right_Mem = $50


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Defines shape of player0 sprite.
   ;
   player0:
   %00111100
   %01111110
   %11000011
   %10111101
   %11111111
   %11011011
   %01111110
   %00111100
end


   ;***************************************************************
   ;
   ;  Defines shape of player1 sprite.
   ;
   player1:
   %00111100
   %01111110
   %11000011
   %10111101
   %11111111
   %11011011
   %01111110
   %00111100
end


   goto __Score_Color_Start




   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Fire button section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off joystick restrainer bit and skips this section if
   ;  fire button is not pressed.
   ;
   if !joy0fire then _Bit6_Joy0_Restrainer{6} = 0 : goto __Skip_Fire_Button

   ;```````````````````````````````````````````````````````````````
   ;  Clears the joystick restrainer bit if joystick is not moved.
   ;
   if !joy0up && !joy0down then _Bit6_Joy0_Restrainer{6} = 0 : goto __Skip_Fire_Button

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick already moved.
   ;
   if _Bit6_Joy0_Restrainer{6} then goto __Skip_Score_Change

   ;```````````````````````````````````````````````````````````````
   ;  Switches object if joystick is moved up or down.
   ;
   if joy0up then _Bit6_Joy0_Restrainer{6} = 1 : _Bit7_Activate_Jiggle{7} = 1 : _Jiggle_Counter = 0 : _Current_Object = _Current_Object + 1 : if _Current_Object > 2 then _Current_Object = 0

   if joy0down then _Bit6_Joy0_Restrainer{6} = 1 : _Bit7_Activate_Jiggle{7} = 1 : _Jiggle_Counter = 0 : _Current_Object = _Current_Object - 1 : if _Current_Object > 200 then _Current_Object = 2

__Score_Color_Start

   ;```````````````````````````````````````````````````````````````
   ;  Changes score color and speed info in score.
   ;
   if _Current_Object = _c_Player0 then scorecolor = _c_PlayerMissile0_Color : _sc2  = _P0Left_Mem : _sc2 = _sc2  & %11110000 : _sc2 = _sc2 | $0A : _sc3 = _P0Right_Mem : _Left_Number = _P0_Left_Number 
   if _Current_Object = _c_Ball then scorecolor = _c_Ball_Color : _sc2  = _BLeft_Mem : _sc2 = _sc2  & %11110000 : _sc2 = _sc2 | $0A : _sc3 = _BRight_Mem : _Left_Number = _B_Left_Number 
   if _Current_Object = _c_Player1 then scorecolor = _c_PlayerMissile1_Color : _sc2  = _P1Left_Mem : _sc2 = _sc2  & %11110000 : _sc2 = _sc2 | $0A : _sc3 = _P1Right_Mem : _Left_Number = _P1_Left_Number 

   ;```````````````````````````````````````````````````````````````
   ;  Turns on joystick restrainer bit.
   ;
   _Bit6_Joy0_Restrainer{6} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips score change (skips the whole next section).
   ;
   goto __Skip_Score_Change

__Skip_Fire_Button



   ;***************************************************************
   ;
   ;  Score change section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments _Score_Counter.
   ;
   _Score_Counter = _Score_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips section if _Score_Counter is less than _Score_Slowdown.
   ;
   if _Score_Counter < _Score_Slowdown then goto __Skip_Score_Change

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Left check.
   ;
   if !joy0left then goto __Skip_Score_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Subtracts from the tracker counter and sets selection speed.
   ;
   _Score_Right_Number = _Score_Right_Number - 1 : _Score_Slowdown = 10

   ;```````````````````````````````````````````````````````````````
   ;  Skips if tracker hasn't gone below zero.
   ;
   if _Score_Right_Number < 200 then goto __Skip_Left_Decrement 

   ;```````````````````````````````````````````````````````````````
   ;  Skips if left number is zero.
   ;
   if !_Left_Number then _Score_Right_Number = 0 : goto __Skip_Score_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Tracker went below zero, so tracker and score changed to 99.
   ;
   _Score_Right_Number = 99 : _sc3 = $99

   ;```````````````````````````````````````````````````````````````
   ;  Subtracts thousands digit if it's not zero.
   ;
   if _Left_Number then _Left_Number = _Left_Number - 1 : _sc2 = _sc2 - $10 : _sc2 = _sc2  & %11110000 : _sc2 = _sc2 | $0A 

   goto __Skip_Score_Joy0_Left

__Skip_Left_Decrement

   ;```````````````````````````````````````````````````````````````
   ;  Subtracts from score only if it's above zero.
   ;
   dec _sc3 = _sc3 - $01

__Skip_Score_Joy0_Left

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Right check.
   ;
   if !joy0right then goto __Skip_Score_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Adds to the tracker counter and sets selection speed.
   ;
   _Score_Right_Number = _Score_Right_Number + 1 : _Score_Slowdown = 10

   ;```````````````````````````````````````````````````````````````
   ;  Resets tracker and score if it's time to increment thousands digit.
   ;
   if _Score_Right_Number < 100 then goto __Skip_Right_Increment

   if _Left_Number > 8 then _Score_Right_Number = 99 : _sc3 = $99 : goto __Skip_Score_Joy0_Right

   _Score_Right_Number = 0 : _sc3 = $00 : _Left_Number = _Left_Number + 1 : _sc2 = _sc2 + $10 : _sc2 = _sc2  & %11110000 : _sc2 = _sc2 | $0A : goto __Skip_Score_Joy0_Right

__Skip_Right_Increment

   ;```````````````````````````````````````````````````````````````
   ;  Adds to score only if range is between 0 and 99.
   ;
   dec _sc3 = _sc3 + $01

__Skip_Score_Joy0_Right

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Up check.
   ;
   if !joy0up then goto __Skip_Score_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Adds to the tracker counter and sets selection speed.
   ;
   _Score_Right_Number = _Score_Right_Number + 1 : _Score_Slowdown = 1

   ;```````````````````````````````````````````````````````````````
   ;  Resets tracker and score if it's time to increment thousands digit.
   ;
   if _Score_Right_Number < 100 then goto __Skip_Up_Increment

   if _Left_Number > 8 then _Score_Right_Number = 99 : _sc3 = $99 : goto __Skip_Score_Joy0_Up

   _Score_Right_Number = 0 : _sc3 = $00 : _Left_Number = _Left_Number + 1 : _sc2 = _sc2 + $10 : _sc2 = _sc2  & %11110000 : _sc2 = _sc2 | $0A : goto __Skip_Score_Joy0_Up

__Skip_Up_Increment

   ;```````````````````````````````````````````````````````````````
   ;  Adds to score only if range is between 0 and 99.
   ;
   dec _sc3 = _sc3 + $01

__Skip_Score_Joy0_Up

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Down check.
   ;
  if !joy0down then goto __Skip_Score_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Subtracts from the tracker counter and sets selection speed.
   ;
   _Score_Right_Number = _Score_Right_Number - 1 : _Score_Slowdown = 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips if tracker hasn't gone below zero.
   ;
   if _Score_Right_Number < 200 then goto __Skip_Down_Decrement 

   ;```````````````````````````````````````````````````````````````
   ;  Skips if left number is zero.
   ;
   if !_Left_Number then _Score_Right_Number = 0 : goto __Skip_Score_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Tracker went below zero, so tracker and score changed to 99.
   ;
   _Score_Right_Number = 99 : _sc3 = $99

   ;```````````````````````````````````````````````````````````````
   ;  Grabs the thousands digit and subtracts if it's not zero.
   ;
   if _Left_Number then _Left_Number = _Left_Number - 1 : _sc2 = _sc2 - $10 : _sc2 = _sc2  & %11110000 : _sc2 = _sc2 | $0A

   goto __Skip_Score_Joy0_Down

__Skip_Down_Decrement

   ;```````````````````````````````````````````````````````````````
   ;  Subtracts from score only if it's above zero.
   ;
   dec _sc3 = _sc3 - $01

__Skip_Score_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Sets the current object speed.
   ;
   temp5 = _sc3 & $0F
   temp6 = _sc3 / 16

   if _Current_Object = _c_Player0 then _P0Left_Mem = _sc2  & %11110000 : _P0Right_Mem = _sc3 : _P0_Left_Number = _Left_Number : _P0_Right_Number = _DATA_Lo_Table[temp5] + _DATA_Hi_Table[temp6]

   if _Current_Object = _c_Ball then _BLeft_Mem = _sc2  & %11110000 : _BRight_Mem = _sc3 : _B_Left_Number = _Left_Number : _B_Right_Number = _DATA_Lo_Table[temp5] + _DATA_Hi_Table[temp6]

   if _Current_Object = _c_Player1 then _P1Left_Mem = _sc2  & %11110000 : _P1Right_Mem = _sc3 : _P1_Left_Number = _Left_Number : _P1_Right_Number = _DATA_Lo_Table[temp5] + _DATA_Hi_Table[temp6]

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Clears score counter.
   ;
   _Score_Counter = 0

__Skip_Score_Change



   ;***************************************************************
   ;
   ;  Object jiggle check.
   ;
   ;  Activates object jiggle if new object has been selected.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if object has not been changed.
   ;
   if !_Bit7_Activate_Jiggle{7} then goto __Skip_Object_Jiggle

   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if object is jiggling.
   ;
   if _Jiggle_Counter >= 1 then goto __Skip_Memory

   if _Current_Object = _c_Player0 then _Memx = player0x : _Memy = player0y

   if _Current_Object = _c_Ball then _Memx = ballx : _Memy = bally

   if _Current_Object = _c_Player1 then _Memx = player1x : _Memy = player1y

__Skip_Memory

   ;```````````````````````````````````````````````````````````````
   ;  Adds one to the object jiggle counter.
   ;
   _Jiggle_Counter = _Jiggle_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Applies jiggle to the currently selected object.
   ;
   if _Current_Object = _c_Player0 then temp5 = 255 + (rand&3) : player0x = player0x + temp5: temp5 = 255 + (rand&3) : player0y = player0y + temp5

   if _Current_Object = _c_Ball then temp5 = 255 + (rand&3) : ballx = ballx + temp5: temp5 = 255 + (rand&3) : bally = bally + temp5

   if _Current_Object = _c_Player1 then temp5 = 255 + (rand&3) : player1x = player1x + temp5: temp5 = 255 + (rand&3) : player1y = player1y + temp5

   ;```````````````````````````````````````````````````````````````
   ;  Stops jiggling and restores position of the selected object
   ;  if counter limit has been reached.
   ;
   if _Jiggle_Counter <= 4 then goto __Skip_Object_Jiggle

   _Bit7_Activate_Jiggle{7} = 0 : _Jiggle_Counter = 0

   if _Current_Object = _c_Player0 then player0x = _Memx : player0y = _Memy

   if _Current_Object = _c_Ball then ballx = _Memx : bally = _Memy

   if _Current_Object = _c_Player1 then player1x = _Memx : player1y = _Memy

__Skip_Object_Jiggle



   ;***************************************************************
   ;
   ;  Sets color of player0 sprite and missile0.
   ;
   COLUP0 = _c_PlayerMissile0_Color 



   ;***************************************************************
   ;
   ;  Sets color of player1 sprite and missile1.
   ;
   COLUP1 = _c_PlayerMissile1_Color 



   ;***************************************************************
   ;
   ;  Sets playfield and ball color.
   ;
   COLUPF = _c_Ball_Color



   ;***************************************************************
   ;
   ;  Moves player0 horizontally from edge to edge.
   ;
   if !_Bit1_P0_Direction{1} then _P0_LR = _P0_LR - _P0_Speed : temp6 = 2 + _P0_Left_Number : if player0x < temp6 then _Bit1_P0_Direction{1} = 1

   if _Bit1_P0_Direction{1} then _P0_LR = _P0_LR + _P0_Speed : temp6 = 152 - _P0_Left_Number : if player0x > temp6 then _Bit1_P0_Direction{1} = 0



   ;***************************************************************
   ;
   ;  Moves the ball horizontally from edge to edge.
   ;
   if !_Bit5_Ball_Direction{5} then _B_LR = _B_LR - _B_Speed : temp6 = 3 + _B_Left_Number : if ballx < temp6 then _Bit5_Ball_Direction{5} = 1

   if _Bit5_Ball_Direction{5} then _B_LR = _B_LR + _B_Speed : temp6 = 160 - _B_Left_Number : if ballx > temp6 then _Bit5_Ball_Direction{5} = 0



   ;***************************************************************
   ;
   ;  Moves player1 horizontally from edge to edge.
   ;
   if !_Bit2_P1_Direction{2} then _P1_LR = _P1_LR - _P1_Speed : temp6 = 2 + _P1_Left_Number : if player1x < temp6 then _Bit2_P1_Direction{2} = 1

   if _Bit2_P1_Direction{2} then _P1_LR = _P1_LR + _P1_Speed : temp6 = 152 - _P1_Left_Number : if player1x > temp6 then _Bit2_P1_Direction{2} = 0



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;
   ;  BCD conversion data by bogax.
   ;
    data _DATA_Lo_Table
    0,   5,   3,   8,  10,  13,  15,  18,  20,  23
end

    data _DATA_Hi_Table
    0,  26,  51,  77, 102, 128, 154, 179, 205, 230
end

 

 

 

32 x 23 Maze With Animated Sprite and Roaming Sprite Using 8.8 Fixed Point Movement

32 x 23 Maze With Animated Sprite and Roaming Sprite Using 8.8 Fixed Point Movement on bB page.

 
   ;****************************************************************
   ;
   ;  Maze With Animated Sprite and Roaming Sprite (32 x 24)
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Use the joystick to move the sprite.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;****************************************************************
   ;
   ;  Kernel options for this program eliminate the blank lines.
   ;
   set kernel_options no_blank_lines



   ;****************************************************************
   ;
   ;  This program has 4 banks (16k/4k = 4 banks).
   ;
   set romsize 16kSC



   ;****************************************************************
   ;
   ;  Random numbers can slow down bankswitched games.
   ;  This will speed things up.
   ;
   set optimization inlinerand



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Player0 fixed point variables for more flexibility in
   ;  gameplay mechanics.
   ;
   dim _P0_L_R = player0x.a
   dim _P0_U_D = player0y.b

   ;```````````````````````````````````````````````````````````````
   ;  Player1 fixed point variables for more flexibility in
   ;  gameplay mechanics.
   ;
   dim _P1_L_R = player1x.c
   dim _P1_U_D = player1y.d

   ;```````````````````````````````````````````````````````````````
   ;  Makes the enemy change directions properly and not bounce
   ;  back.
   ;
   dim _Enemy_Counter = e

   ;```````````````````````````````````````````````````````````````
   ;  How often enemy looks for opening.
   ;
   dim _Enemy_Rand_Look = f

   ;```````````````````````````````````````````````````````````````
   ; All-purpose, reusable variable.
   ;
   dim _MyTemp01 = k

   ;```````````````````````````````````````````````````````````````
   ; Animation counters.
   ;
   dim _Master_Counter = m
   dim _Frame_Counter = n

   ;```````````````````````````````````````````````````````````````
   ;  Player0/player1 direction bits.
   ;
   dim _BitOp_P0_P1_Dir = u
   dim _Bit0_P0_Dir_Up = u
   dim _Bit1_P0_Dir_Down = u
   dim _Bit2_P0_Dir_Left = u
   dim _Bit3_P0_Dir_Right = u
   dim _Bit4_P1_Dir_Up = u
   dim _Bit5_P1_Dir_Down = u
   dim _Bit6_P1_Dir_Left = u
   dim _Bit7_P1_Dir_Right = u

   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y
   dim _Bit3_vblank = y
   dim _Bit5_Direction_Changed = y
   dim _Bit6_Flip_P0 = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers.
   ;
   dim rand16 = z



   ;****************************************************************
   ;
   ;  Defines number of playfield rows.
   ;
   const pfres=23





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears 25 of the normal 26 variables (fastest way).
   ;  The variable z is used for random numbers in this program
   ;  and clearing it would mess up those random numbers.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0


   ;***************************************************************
   ;
   ;  Sets starting position of player0.
   ;
   player0x = 77 : player0y = 47


   ;***************************************************************
   ;
   ;  Sets starting position of enemy sprite.
   ;
   player1x = 77 : player1y = 83


   ;***************************************************************
   ;
   ;  Sets playfield color.
   ;
   COLUPF = $96


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Sets beginning direction for player0.
   ;
   _Bit2_P0_Dir_Left{2} = 1


   ;***************************************************************
   ;
   ;  Sets beginning direction for the enemy sprite.
   ;
   _Bit7_P1_Dir_Right{7} = 1


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Determines how often the enemy looks for alternate routes.
   ;  The smaller the number, the less often it will happen.
   ;
   _Enemy_Rand_Look = 50


   ;***************************************************************
   ;
   ;  Sets up the playfield.
   ;
   playfield:
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   X..............XX..............X
   X..............XX..............X
   X..XXX..XXXXX..XX..XXXXX..XXX..X
   X..............................X
   X..............................X
   X..XXX..X..XXXXXXXXXX..X..XXX..X
   X.......X......XX......X.......X
   X.......X......XX......X.......X
   XXXXXX..XXXXX..XX..XXXXX..XXXXXX
   X..............................X
   X..............................X
   X..XXX..XXXXXXX..XXXXXXX..XXX..X
   X....X....................X....X
   X....X....................X....X
   XXX..X..X..XXXXXXXXXX..X..X..XXX
   X.......X......XX......X.......X
   X.......X......XX......X.......X
   X..XXXXXXXXXX..XX..XXXXXXXXXX..X
   X..............................X
   X..............................X
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end


   ;****************************************************************
   ;
   ;  Displays the screen prematurely so we won't go over 262.
   ;
   drawscreen


   goto __Main_Loop bank2





   bank 2





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;****************************************************************
   ;
   ;  Sets color of sprites and score.
   ;
   COLUP0 = $1E : COLUP1 = $AE : scorecolor = $0A



   ;***************************************************************
   ;
   ;  Controls animation speed.
   ;
   _Master_Counter = _Master_Counter + 1

   if _Master_Counter < 4 then goto __Skip_Frame_Counter

   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   if _Frame_Counter = 4 then _Frame_Counter = 0

__Skip_Frame_Counter



   ;***************************************************************
   ;
   ;  Turns on vblank section.
   ;
   _Bit3_vblank{3} = 1



   ;****************************************************************
   ;
   ;  Flips player sprite when necessary.
   ;
   if _Bit6_Flip_P0{6} then REFP0 = 8



   ;****************************************************************
   ;
   ;  Starts counting if enemy direction has changed.
   ;  This keeps the enemy from changing directions right away
   ;  so he won't bounce back and reverse direction.
   ;
   if _Bit5_Direction_Changed{5} then _Enemy_Counter = _Enemy_Counter + 1



   ;****************************************************************
   ;
   ;  Enemy up check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if enemy up direction bit isn't on.
   ;
   if !_Bit4_P1_Dir_Up{4} then goto __Skip_P1_Up

   ;```````````````````````````````````````````````````````````````
   ;  Enemy up: Converts enemy sprite coordinates and checks to see
   ;  if any playfield pixels are in the way.
   ;
   temp3 = (player1x-17)/4

   temp6 = (player1y/4)-2

   if pfread(temp3,temp6) then goto __Enemy_Cant_Move_Up

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then goto __Enemy_Cant_Move_Up

   goto __Skip_to_P1_Move_Up

__Enemy_Cant_Move_Up

   ;```````````````````````````````````````````````````````````````
   ;  Enemy up: PF pixel in the way. Clears the up bit, gets a new 
   ;  direction and jumps to the beginning of enemy movement.
   ;
   _Bit4_P1_Dir_Up{4} = 0

   gosub __Check_P1_LR

   goto __Clear_Direction

__Skip_to_P1_Move_Up

   ;```````````````````````````````````````````````````````````````
   ;  Enemy up: Moves up only if sprite is lined up with playfield.
   ;
   temp5 = (temp3*4)+17

   if temp5 <> player1x then goto __Skip_P1_Up

   _P1_U_D = _P1_U_D - 0.52

   ;```````````````````````````````````````````````````````````````
   ;  Enemy up: Randomly checks to see if a new direction can be
   ;  taken if the direction hasn't changed lately.
   ;
   ;  Remember that the value of _Enemy_Rand_Look can be increased to make
   ;  it more likely that a new direction will be looked for.
   ;
   if _Bit5_Direction_Changed{5} then goto __Skip_Enemy_Look_Up

   temp5 = rand

   temp6 = (((player1y-7)/4)*4)+7

   if temp5 < _Enemy_Rand_Look then if temp6 = player1y then gosub __Check_P1_LR : if _Bit5_Direction_Changed{5} then _Bit4_P1_Dir_Up{4} = 0 : goto __Clear_Direction

   _Bit5_Direction_Changed{5} = 0

__Skip_Enemy_Look_Up

   ;```````````````````````````````````````````````````````````````
   ;  Enemy up: Turns on the up direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %00001111

   _Bit4_P1_Dir_Up{4} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Enemy up: Enemy sprite up frame.
   ;
   player1:
   %10101010
   %11111110
   %11111110
   %11111110
   %11010110
   %11010110
   %01111100
end

__Skip_P1_Up



   ;****************************************************************
   ;
   ;  Enemy down check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if enemy down direction bit isn't on.
   ;
   if !_Bit5_P1_Dir_Down{5} then goto __Skip_P1_Down

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Down: Converts enemy sprite coordinates and checks to
   ;  see if any playfield pixels are in the way.
   ;
   temp3 = (player1x-17)/4

   temp6 = ((player1y-3)/4) + 1

   if pfread(temp3,temp6) then goto __Enemy_Cant_Move_Down

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then goto __Enemy_Cant_Move_Down

   goto __Skip_to_P1_Move_Down

__Enemy_Cant_Move_Down

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Down: PF pixel in the way. Clears the down bit, gets a 
   ;  new direction and jumps to the beginning of enemy movement.
   ;
   _Bit5_P1_Dir_Down{5} = 0

   gosub __Check_P1_LR

   goto __Clear_Direction

__Skip_to_P1_Move_Down

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Down: Moves down only if sprite is lined up with PF.
   ;
   temp5 = (temp3*4)+17

   if temp5 <> player1x then goto __Skip_P1_Down

   _P1_U_D = _P1_U_D + 0.52

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Down: Randomly checks to see if a new direction can be 
   ;  taken if the direction hasn't changed lately.
   ;
   ;  Remember that the value of _Enemy_Rand_Look can be increased to make
   ;  it more likely that a new direction will be looked for.
   ;
   if _Bit5_Direction_Changed{5} then goto __Skip_Enemy_Look_Down

   temp5 = rand

   temp6 = (((player1y-7)/4)*4)+7

   if temp5 < _Enemy_Rand_Look then if temp6 = player1y then gosub __Check_P1_LR : if _Bit5_Direction_Changed{5} then _Bit5_P1_Dir_Down{5} = 0 : goto __Clear_Direction

   _Bit5_Direction_Changed{5} = 0

__Skip_Enemy_Look_Down

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Down: Turns on the down direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %00001111

   _Bit5_P1_Dir_Down{5} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Down: Enemy sprite down frame.
   ;
   player1:
   %10101010
   %11111110
   %11010110
   %11010110
   %11111110
   %11111110
   %01111100
end

__Skip_P1_Down



   ;****************************************************************
   ;
   ;  Enemy left check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if enemy left direction bit isn't on.
   ;
   if !_Bit6_P1_Dir_Left{6} then goto __Skip_P1_Left

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Left: Converts enemy sprite coordinates and checks to
   ;  see if any playfield pixels are in the way.
   ;
   temp5 = ((player1x-14)/4) - 1

   temp6 = (player1y-7)/4

   if pfread(temp5,temp6) then goto __Enemy_Cant_Move_Left

   temp3 = temp6 + 1

   if pfread(temp5,temp3) then goto __Enemy_Cant_Move_Left

   goto __Skip_to_P1_Move_Left

__Enemy_Cant_Move_Left

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Left: PF pixel in the way. Clears the left bit, gets a 
   ;  new direction and jumps to the beginning of enemy movement.
   ;
   _Bit6_P1_Dir_Left{6} = 0

   gosub __Check_P1_UD

   goto __Clear_Direction

__Skip_to_P1_Move_Left

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Left: Moves left only if sprite is lined up with PF.
   ;
   temp5 = (temp6*4)+7

   if temp5 <> player1y then goto __Skip_P1_Left

   _P1_L_R = _P1_L_R - 0.52

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Left: Randomly checks to see if a new direction can be
   ;  taken if the direction hasn't changed lately.
   ;
   ;  Remember that the value of _Enemy_Rand_Look can be increased to make
   ;  it more likely that a new direction will be looked for.
   ;
   if _Bit5_Direction_Changed{5} then goto __Skip_Enemy_Look_Left

   temp5 = rand

   if temp5 < _Enemy_Rand_Look then temp5 = (((player1x-17)/4)*4)+17 : if temp5 = player1x then gosub __Check_P1_UD : if _Bit5_Direction_Changed{5} then _Bit6_P1_Dir_Left{6} = 0 : goto __Clear_Direction

   _Bit5_Direction_Changed{5} = 0

__Skip_Enemy_Look_Left

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Left: Turns on the left direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %00001111

   _Bit6_P1_Dir_Left{6} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Left: Enemy sprite left frame.
   ;
   player1:
   %10101010
   %11111110
   %11111110
   %10101110
   %10101110
   %11111110
   %01111100
end

__Skip_P1_Left



   ;****************************************************************
   ;
   ;  Enemy right check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if enemy right direction bit isn't on.
   ;
   if !_Bit7_P1_Dir_Right{7} then goto __Skip_P1_Right

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Right: Converts enemy sprite coordinates and checks to
   ;  see if any playfield pixels are in the way.
   ;
   temp5 = ((player1x-13)/4)+1

   temp6 = ((player1y-7)/4)

   if pfread(temp5,temp6) then goto __Enemy_Cant_Move_Right

   temp3 = (temp6)+1

   if pfread(temp5,temp3) then goto __Enemy_Cant_Move_Right

   goto __Skip_to_P1_Move_Right

__Enemy_Cant_Move_Right

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Right: PF pixel in the way. Clears the right bit, gets
   ;  a new direction and jumps to the beginning of enemy movement.
   ;
   _Bit7_P1_Dir_Right{7} = 0

   gosub __Check_P1_UD

   goto __Clear_Direction

__Skip_to_P1_Move_Right

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Right: Moves right only if sprite is lined up with PF.
   ;
   temp5 = (temp6*4)+7

   if temp5 <> player1y then goto __Skip_P1_Right

   _P1_L_R = _P1_L_R + 0.52

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Right: Randomly checks to see if a new direction can
   ;  be taken if the direction hasn't changed lately.
   ;
   ;  Remember that the value of _Enemy_Rand_Look can be increased to make
   ;  it more likely that a new direction will be looked for.
   ;
   if _Bit5_Direction_Changed{5} then goto __Skip_Enemy_Look_Right

   temp5 = rand

   if temp5 < _Enemy_Rand_Look then temp5 = (((player1x-17)/4)*4)+17 : if temp5 = player1x then gosub __Check_P1_UD : if _Bit5_Direction_Changed{5} then _Bit7_P1_Dir_Right{7} = 0 : goto __Clear_Direction

   _Bit5_Direction_Changed{5} = 0

__Skip_Enemy_Look_Right

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Right: Turns on the right direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %00001111

   _Bit7_P1_Dir_Right{7} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Right: Enemy sprite right frame.
   ;
   player1:
   %10101010
   %11111110
   %11111110
   %11101010
   %11101010
   %11111110
   %01111100
end

__Skip_P1_Right



   ;***************************************************************
   ;
   ;  Enemy counter check.
   ;
__Clear_Direction

   ;```````````````````````````````````````````````````````````````
   ;  Clears enemy direction flag and enemy counter if enemy
   ;  counter is greater than 2.
   ;
   if _Enemy_Counter = 3 then _Bit5_Direction_Changed{5} = 0 : _Enemy_Counter = 0



   ;****************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart bank1





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;****************************************************************
   ;
   ;  Checks left and right for an opening.
   ;
__Check_P1_LR

   ;```````````````````````````````````````````````````````````````
   ;  Clears direction changed bit and chooses which direction to
   ;  start looking.
   ;
   _Bit5_Direction_Changed{5} = 0

   ;```````````````````````````````````````````````````````````````
   ;  15 percent chance that player location will be ignored.
   ;
   temp5 = rand : if temp5 < 38 then goto __Skip_LR_Check

   ;```````````````````````````````````````````````````````````````
   ;  Player location not ignored. Skips first left check if player
   ;  is to the right of the enemy.
   ;
   if player0x > player1x then goto __Skip_LR_Check

   ;```````````````````````````````````````````````````````````````
   ;  Looks to the left.
   ;
   temp5 = ((player1x-17)/4) - 1

   temp6 = (player1y-7)/4

   if pfread(temp5,temp6) then goto __Skip_LR_Check

   temp3 = temp6 + 1

   if pfread(temp5,temp3) then goto __Skip_LR_Check

   _Bit6_P1_Dir_Left{6} = 1 : _Bit5_Direction_Changed{5} = 1 : return thisbank

__Skip_LR_Check

   ;```````````````````````````````````````````````````````````````
   ;  Looks to the right.
   ;
   temp5 = ((player1x-13)/4)+1

   temp6 = ((player1y-7)/4)

   if pfread(temp5,temp6) then goto __Skip_R_Check

   temp3 = (temp6)+1

   if pfread(temp5,temp3) then goto __Skip_R_Check

   _Bit7_P1_Dir_Right{7} = 1 : _Bit5_Direction_Changed{5} = 1 : return thisbank

__Skip_R_Check

   ;```````````````````````````````````````````````````````````````
   ;  Looks to the left.
   ;
   temp5 = ((player1x-17)/4) - 1

   temp6 = (player1y-7)/4

   if pfread(temp5,temp6) then return thisbank

   temp3 = temp6 + 1

   if pfread(temp5,temp3) then return thisbank

   _Bit6_P1_Dir_Left{6} = 1 : _Bit5_Direction_Changed{5} = 1 : return thisbank



   ;****************************************************************
   ;
   ;  Looks up and down for an opening.
   ;
__Check_P1_UD

   ;```````````````````````````````````````````````````````````````
   ;  Clears direction changed bit and chooses which direction to
   ;  start looking.
   ;
   _Bit5_Direction_Changed{5} = 0

   ;```````````````````````````````````````````````````````````````
   ;  15 percent chance that player location will be ignored.
   ;
   temp5 = rand : if temp5 < 38 then goto __Skip_UD_Check

   ;```````````````````````````````````````````````````````````````
   ;  Player location not ignored. Skips first up check if player
   ;  is lower than enemy.
   ;
   if player0y > player1y then goto __Skip_UD_Check

   ;```````````````````````````````````````````````````````````````
   ;  Looks up.
   ;
   temp3 = (player1x-17)/4

   temp6 = (player1y/4)-2

   if pfread(temp3,temp6) then goto __Skip_UD_Check

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then goto __Skip_UD_Check

   _Bit4_P1_Dir_Up{4} = 1 : _Bit5_Direction_Changed{5}=1 : return thisbank

__Skip_UD_Check

   ;```````````````````````````````````````````````````````````````
   ;  Looks down.
   ;
   temp3 = (player1x-17)/4

   temp6 = (player1y/4) + 1

   if pfread(temp3,temp6) then goto __Skip_U_Check

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then goto __Skip_U_Check

   _Bit5_P1_Dir_Down{5} = 1 : _Bit5_Direction_Changed{5} = 1 : return thisbank

__Skip_U_Check

   ;```````````````````````````````````````````````````````````````
   ;  Looks up.
   ;
   temp3 = (player1x-17)/4

   temp6 = (player1y/4)-2

   if pfread(temp3,temp6) then return thisbank

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then return thisbank

   _Bit4_P1_Dir_Up{4} = 1 : _Bit5_Direction_Changed{5} = 1 : return thisbank



   bank 3



   bank 4



   ;****************************************************************
   ;
   ;  I'm using vblank to avoid having a scanline count over 262.
   ;
   vblank

   if !_Bit3_vblank{3} then goto __Done_Player_Section


   ;****************************************************************
   ;
   ;  Up Joy0 check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the up bit is off or the joystick
   ;  isn't moved up.
   ;
   if _Bit0_P0_Dir_Up{0} then goto __Test_P0_Up

   if joy0up then goto __Test_P0_Up

   goto __Skip_Joy0_Up

__Test_P0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Up P0: Converts P0 sprite coordinates and checks to see if
   ;  any playfield pixels are in the way.
   ;
   temp3 = (player0x-17)/4

   temp6 = (player0y/4)-2

   if pfread(temp3,temp6) then goto __Cant_Move_Up

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then goto __Cant_Move_Up

   goto __P0_Move_Up

__Cant_Move_Up

   ;```````````````````````````````````````````````````````````````
   ;  Up P0: Playfield pixel is in the way.
   ;  Shows up frame only if up bit is on. Clears the up bit and
   ;  skips this section.
   ;
   if _Bit0_P0_Dir_Up{0} then gosub __Frame_U_01

   _Bit0_P0_Dir_Up{0} = 0

   goto __Skip_Joy0_Up

__P0_Move_Up

   ;```````````````````````````````````````````````````````````````
   ;  Up P0: Moves player0 up only if sprite is lined up with playfield.
   ;
   temp5 = (temp3*4)+17

   if temp5 <> player0x then goto __Skip_Joy0_Up

   _P0_U_D = _P0_U_D - 0.85

   ;```````````````````````````````````````````````````````````````
   ;  Up P0: Sprite animation.
   ;
   on _Frame_Counter gosub __Frame_U_00 __Frame_U_01 __Frame_U_02 __Frame_U_01

   ;```````````````````````````````````````````````````````````````
   ;  Up P0: Clears bits and turns on the up direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %11110000

   _Bit0_P0_Dir_Up{0} = 1

__Skip_Joy0_Up



   ;****************************************************************
   ;
   ;  Down Joy0 check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the down bit is off or the joystick
   ;  isn't moved down.
   ;
   if _Bit1_P0_Dir_Down{1} then goto __Test_P0_Down

   if joy0down then goto __Test_P0_Down

   goto __Skip_Joy0_Down

__Test_P0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Down P0: Converts P0 sprite coordinates and checks to see if
   ;  any playfield pixels are in the way.
   ;
   temp3 = (player0x-17)/4

   temp6 = ((player0y-3)/4) + 1

   if pfread(temp3,temp6) then goto __Cant_Move_Down

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then goto __Cant_Move_Down

   goto __P0_Move_Down

__Cant_Move_Down

   ;```````````````````````````````````````````````````````````````
   ;  Down P0: Playfield pixel is in the way.
   ;  Shows down frame only if down bit is on. Clears the down bit
   ;  and skips this section.
   ;
   if _Bit1_P0_Dir_Down{1} then gosub __Frame_D_01

   _Bit1_P0_Dir_Down{1} = 0

   goto __Skip_Joy0_Down

__P0_Move_Down

   ;```````````````````````````````````````````````````````````````
   ;  Down P0: Moves down only if sprite is lined up with PF.
   ;
   temp5 = (temp3*4) + 17

   if temp5 <> player0x then goto __Skip_Joy0_Down

   _P0_U_D = _P0_U_D + 0.85

   ;```````````````````````````````````````````````````````````````
   ;  Down P0: Sprite animation.
   ;
   on _Frame_Counter gosub __Frame_D_00 __Frame_D_01 __Frame_D_02 __Frame_D_01

   ;```````````````````````````````````````````````````````````````
   ;  Clears bits and turns on the down direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %11110000

   _Bit1_P0_Dir_Down{1} = 1

__Skip_Joy0_Down



   ;****************************************************************
   ;
   ;  Left Joy0 check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the left bit is off or the joystick
   ;  isn't moved left.
   ;
   if _Bit2_P0_Dir_Left{2} then goto __Test_P0_Left

   if joy0left then goto __Test_P0_Left

   goto __Skip_Joy0_Left

__Test_P0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Left P0: Converts P0 sprite coordinates and checks to see if
   ;  any playfield pixels are in the way.
   ;
   temp5 = ((player0x-14)/4)-1

   temp6 = (player0y-7)/4

   if pfread(temp5,temp6) then goto __Cant_Move_Left

   temp3 = temp6 + 1

   if pfread(temp5,temp3) then goto __Cant_Move_Left

   goto __P0_Move_Left

__Cant_Move_Left

   ;```````````````````````````````````````````````````````````````
   ;  Left P0: Playfield pixel is in the way.
   ;  Shows left frame only if left bit is on. Clears the left bit
   ;  and skips this section.
   ;
   if _Bit2_P0_Dir_Left{2} then gosub __Frame_LR_01

   _Bit2_P0_Dir_Left{2} = 0

   goto __Skip_Joy0_Left

__P0_Move_Left

   ;```````````````````````````````````````````````````````````````
   ;  Left P0: Moves left only if sprite is lined up with PF.
   ;
   temp5 = (temp6*4)+7

   if temp5 <> player0y then goto __Skip_Joy0_Left

   _P0_L_R = _P0_L_R - 0.85

   ;```````````````````````````````````````````````````````````````
   ;  Left P0: Sprite animation.
   ;
   on _Frame_Counter gosub __Frame_LR_00 __Frame_LR_01 __Frame_LR_02 __Frame_LR_01

   ;```````````````````````````````````````````````````````````````
   ;  Left P0: Makes sure sprite is facing the correct direction.
   ;
   _Bit6_Flip_P0{6} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Left P0: Clears bits and turns on the left direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %11110000

   _Bit2_P0_Dir_Left{2} = 1

__Skip_Joy0_Left



   ;****************************************************************
   ;
   ;  Right Joy0 check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the right bit is off or the joystick
   ;  isn't moved right.
   ;
   if _Bit3_P0_Dir_Right{3} then goto __Test_P0_Right

   if joy0right then goto __Test_P0_Right

   goto __Skip_Joy0_Right

__Test_P0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Right P0: Converts P0 sprite coordinates and checks to see if
   ;  any playfield pixels are in the way.
   ;
   temp5 = ((player0x-13)/4)+1

   temp6 = ((player0y-7)/4)

   if pfread(temp5,temp6) then goto __Cant_Move_Right

   temp3 = (temp6)+1

   if pfread(temp5,temp3) then goto __Cant_Move_Right

   goto __P0_Move_Right

__Cant_Move_Right

   ;```````````````````````````````````````````````````````````````
   ;  Right P0: Playfield pixel is in the way.
   ;  Shows right frame only if right bit is on. Clears the right
   ;  bit and skips this section.
   ;
   if _Bit3_P0_Dir_Right{3} then gosub __Frame_LR_01

   _Bit3_P0_Dir_Right{3} = 0

   goto __Skip_Joy0_Right

__P0_Move_Right

   ;```````````````````````````````````````````````````````````````
   ;  Right P0: Moves right only if sprite is lined up with PF.
   ;
   temp5 = (temp6*4)+7

   if temp5 <> player0y then goto __Skip_Joy0_Right

   _P0_L_R = _P0_L_R + 0.85

   ;```````````````````````````````````````````````````````````````
   ;  Right P0: Sprite animation.
   ;
   on _Frame_Counter gosub __Frame_LR_00 __Frame_LR_01 __Frame_LR_02 __Frame_LR_01

   ;```````````````````````````````````````````````````````````````
   ;  Right P0: Makes sure sprite is facing the correct direction.
   ;
   _Bit6_Flip_P0{6} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Right P0: Clears bits and turns on the right direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %11110000

   _Bit3_P0_Dir_Right{3} = 1

__Skip_Joy0_Right

__Done_Player_Section

   _Bit3_vblank{3} = 0

   return



   ;****************************************************************
   ;
   ;  Left/right animation frames for player.
   ;
__Frame_LR_00
   player0:
   %01111100
   %11111110
   %11111110
   %11110000
   %11111110
   %11111110
   %01111100
end

   return thisbank


__Frame_LR_01
   player0:
   %01111100
   %11111110
   %11111000
   %11100000
   %11111000
   %11111110
   %01111100
end

   return thisbank


__Frame_LR_02
   player0:
   %01111100
   %11111000
   %11110000
   %11100000
   %11110000
   %11111000
   %01111100
end

   return thisbank


   ;****************************************************************
   ;
   ;  Up animation frames for player.
   ;
__Frame_U_00
   player0:
   %01111100
   %11111110
   %11111110
   %11111110
   %11101110
   %11101110
   %01101100
end

   return thisbank


__Frame_U_01
   player0:
   %01111100
   %11111110
   %11111110
   %11101110
   %11101110
   %11000110
   %01000100
end

   return thisbank


__Frame_U_02
   player0:
   %01111100
   %11111110
   %11111110
   %11101110
   %11000110
   %10000010
   %00000000
end

   return thisbank


   ;****************************************************************
   ;
   ;  Down animation frames for player.
   ;
__Frame_D_00
   player0:
   %01101100
   %11101110
   %11101110
   %11111110
   %11111110
   %11111110
   %01111100
end

   return thisbank


__Frame_D_01
   player0:
   %01000100
   %11000110
   %11101110
   %11101110
   %11111110
   %11111110
   %01111100
end

   return thisbank


__Frame_D_02
   player0:
   %00000000
   %10000010
   %11000110
   %11101110
   %11111110
   %11111110
   %01111100
end

   return thisbank

 

 

 

32 x 12 Maze With Animated Sprite and Roaming Sprite Using 8.8 Fixed Point Movement

32 x 12 Maze With Animated Sprite and Roaming Sprite Using 8.8 Fixed Point Movement on bB page.

 
   ;***************************************************************
   ;
   ;  Maze With Animated Sprite and Roaming Sprite (32 x 12)
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Use the joystick to move the sprite.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Kernel options for this program eliminate the blank lines.
   ;
   set kernel_options no_blank_lines



   ;***************************************************************
   ;
   ;  This program has 4 banks (16k/4k = 4 banks).
   ;
   set romsize 16k



   ;***************************************************************
   ;
   ;  Random numbers can slow down bankswitched games.
   ;  This will speed things up.
   ;
   set optimization inlinerand



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Player0 fixed point variables for more flexibility in
   ;  gameplay mechanics.
   ;
   dim _P0_L_R = player0x.a
   dim _P0_U_D = player0y.b

   ;```````````````````````````````````````````````````````````````
   ;  Player1 fixed point variables for more flexibility in
   ;  gameplay mechanics.
   ;
   dim _P1_L_R = player1x.c
   dim _P1_U_D = player1y.d

   ;```````````````````````````````````````````````````````````````
   ;  Makes the enemy change directions properly and not bounce
   ;  back.
   ;
   dim _Enemy_Counter = e

   ;```````````````````````````````````````````````````````````````
   ;  How often enemy looks for opening.
   ;
   dim _Enemy_Rand_Look = f

   ;```````````````````````````````````````````````````````````````
   ; All-purpose, reusable variable.
   ;
   dim _MyTemp01 = k

   ;```````````````````````````````````````````````````````````````
   ; Animation counters.
   ;
   dim _Master_Counter = m
   dim _Frame_Counter = n

   ;```````````````````````````````````````````````````````````````
   ;  Player0/player1 direction bits.
   ;
   dim _BitOp_P0_P1_Dir = u
   dim _Bit0_P0_Dir_Up = u
   dim _Bit1_P0_Dir_Down = u
   dim _Bit2_P0_Dir_Left = u
   dim _Bit3_P0_Dir_Right = u
   dim _Bit4_P1_Dir_Up = u
   dim _Bit5_P1_Dir_Down = u
   dim _Bit6_P1_Dir_Left = u
   dim _Bit7_P1_Dir_Right = u

   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y
   dim _Bit5_Direction_Changed = y
   dim _Bit6_Flip_P0 = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers.
   ;
   dim rand16 = z





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears 25 of the normal 26 variables (fastest way).
   ;  The variable z is used for random numbers in this program
   ;  and clearing it would mess up those random numbers.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0


   ;***************************************************************
   ;
   ;  Sets starting position of player0.
   ;
   player0x = 77 : player0y = 47


   ;***************************************************************
   ;
   ;  Sets starting position of enemy sprite.
   ;
   player1x = 77 : player1y = 79


   ;***************************************************************
   ;
   ;  Sets playfield color.
   ;
   COLUPF = $96


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Sets beginning direction for Player0.
   ;
   _Bit2_P0_Dir_Left{2} = 1


   ;***************************************************************
   ;
   ;  Sets beginning direction for the enemy sprite.
   ;
   _Bit7_P1_Dir_Right{7} = 1


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Determines how often the enemy looks for alternate routes.
   ;  The smaller the number, the less often it will happen.
   ;
   _Enemy_Rand_Look = 50


   ;***************************************************************
   ;
   ;  Sets up the playfield.
   ;
   playfield:
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   X..............XX..............X
   X..XXX..XXXXX..XX..XXXXX..XXX..X
   X..............................X
   X..XXX..XXXXXXX..XXXXXXX..XXX..X
   X....X....................X....X
   XXX..X..X..XXXXXXXXXX..X..X..XXX
   X.......X......XX......X.......X
   X..XXXXXXXXXX..XX..XXXXXXXXXX..X
   X..............................X
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end


   ;****************************************************************
   ;
   ;  Displays the screen prematurely so we won't go over 262.
   ;
   drawscreen


   goto __Main_Loop bank2





   bank 2





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets color of sprites and score.
   ;
   COLUP0 = $1E : COLUP1 = $AE : scorecolor = $0A



   ;***************************************************************
   ;
   ;  Controls animation speed.
   ;
   _Master_Counter = _Master_Counter + 1

   if _Master_Counter < 4 then goto __Skip_Frame_Counter

   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   if _Frame_Counter = 4 then _Frame_Counter = 0

__Skip_Frame_Counter



   ;***************************************************************
   ;
   ;  Up Joy0 check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the up bit is off or the joystick
   ;  isn't moved up.
   ;
   if _Bit0_P0_Dir_Up{0} then goto __Test_P0_Up

   if joy0up then goto __Test_P0_Up

   goto __Skip_Joy0_Up

__Test_P0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Up P0: Converts player0 sprite coordinates and checks to see
   ;  if any playfield pixels are in the way.
   ;
   temp3 = (player0x-17)/4

   temp6 = (player0y/8)-1

   if pfread(temp3,temp6) then goto __Cant_Move_Up

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then goto __Cant_Move_Up

   goto __P0_Move_Up

__Cant_Move_Up

   ;```````````````````````````````````````````````````````````````
   ;  Up P0: Playfield pixel is in the way.
   ;  Shows up frame only if up bit is on. Clears the up bit and
   ;  skips this section.
   ;
   if _Bit0_P0_Dir_Up{0} then gosub __Frame_U_01

   _Bit0_P0_Dir_Up{0} = 0

   goto __Skip_Joy0_Up

__P0_Move_Up

   ;```````````````````````````````````````````````````````````````
   ;  Up P0: Moves P0 up only if sprite is lined up with playfield.
   ;
   temp5 = (temp3*4)+17

   if temp5 <> player0x then goto __Skip_Joy0_Up

   _P0_U_D = _P0_U_D - 0.85

   ;```````````````````````````````````````````````````````````````
   ;  Up P0: Sprite animation.
   ;
   on _Frame_Counter gosub __Frame_U_00 __Frame_U_01 __Frame_U_02 __Frame_U_01

   ;```````````````````````````````````````````````````````````````
   ;  Up P0: Clears bits and turns on the up direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %11110000

   _Bit0_P0_Dir_Up{0} = 1

__Skip_Joy0_Up



   ;***************************************************************
   ;
   ;  Down Joy0 check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the down bit is off or the joystick
   ;  isn't moved down.
   ;
   if _Bit1_P0_Dir_Down{1} then goto __Test_P0_Down

   if joy0down then goto __Test_P0_Down

   goto __Skip_Joy0_Down

__Test_P0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Down P0: Converts player0 sprite coordinates and checks to
   ;  see if any playfield pixels are in the way.
   ;
   temp3 = (player0x-17)/4

   temp6 = ((player0y-7)/8) + 1

   if pfread(temp3,temp6) then goto __Cant_Move_Down

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then goto __Cant_Move_Down

   goto __P0_Move_Down

__Cant_Move_Down

   ;```````````````````````````````````````````````````````````````
   ;  Down P0: Playfield pixel is in the way.
   ;  Shows down frame only if down bit is on. Clears the down bit
   ;  and skips this section.
   ;
   if _Bit1_P0_Dir_Down{1} then gosub __Frame_D_01

   _Bit1_P0_Dir_Down{1} = 0

   goto __Skip_Joy0_Down

__P0_Move_Down

   ;```````````````````````````````````````````````````````````````
   ;  Down P0: Moves P0 down only if sprite is lined up with PF.
   ;
   temp5 = (temp3*4) + 17

   if temp5 <> player0x then goto __Skip_Joy0_Down

   _P0_U_D = _P0_U_D + 0.85

   ;```````````````````````````````````````````````````````````````
   ;  Down P0: Sprite animation.
   ;
   on _Frame_Counter gosub __Frame_D_00 __Frame_D_01 __Frame_D_02 __Frame_D_01

   ;```````````````````````````````````````````````````````````````
   ;  Down P0: Clears bits and turns on the down direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %11110000

   _Bit1_P0_Dir_Down{1} = 1

__Skip_Joy0_Down



   ;***************************************************************
   ;
   ;  Left Joy0 check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the left bit is off or the joystick
   ;  isn't moved left.
   ;
   if _Bit2_P0_Dir_Left{2} then goto __Test_P0_Left

   if joy0left then goto __Test_P0_Left

   goto __Skip_Joy0_Left

__Test_P0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Left P0: Converts player0 sprite coordinates and checks to
   ;  see if any playfield pixels are in the way.
   ;
   temp5 = ((player0x-14)/4)-1

   temp6 = (player0y-7)/8

   if pfread(temp5,temp6) then goto __Cant_Move_Left

   goto __P0_Move_Left

__Cant_Move_Left

   ;```````````````````````````````````````````````````````````````
   ;  Left P0: Playfield pixel is in the way.
   ;  Shows left frame only if left bit is on. Clears the left bit
   ;  and skips this section.
   ;
   if _Bit2_P0_Dir_Left{2} then gosub __Frame_LR_01

   _Bit2_P0_Dir_Left{2} = 0

   goto __Skip_Joy0_Left

__P0_Move_Left

   ;```````````````````````````````````````````````````````````````
   ;  Left P0: Moves P0 left only if sprite is lined up with PF.
   ;
   temp5 = (temp6*8)+7

   if temp5 <> player0y then goto __Skip_Joy0_Left

   _P0_L_R = _P0_L_R - 0.85

   ;```````````````````````````````````````````````````````````````
   ;  Left P0: Sprite animation.
   ;
   on _Frame_Counter gosub __Frame_LR_00 __Frame_LR_01 __Frame_LR_02 __Frame_LR_01

   ;```````````````````````````````````````````````````````````````
   ;  Left P0: Makes sure sprite is facing the correct direction.
   ;
   _Bit6_Flip_P0{6} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Left P0: Clears bits and turns on the left direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %11110000

   _Bit2_P0_Dir_Left{2} = 1

__Skip_Joy0_Left



   ;***************************************************************
   ;
   ;  Right Joy0 check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the right bit is off or the joystick
   ;  isn't moved right.
   ;
   if _Bit3_P0_Dir_Right{3} then goto __Test_P0_Right

   if joy0right then goto __Test_P0_Right

   goto __Skip_Joy0_Right

__Test_P0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Right P0: Converts player0 sprite coordinates and checks to
   ;  see if any playfield pixels are in the way.
   ;
   temp5 = ((player0x-13)/4)+1

   temp6 = ((player0y-7)/8)

   if pfread(temp5,temp6) then goto __Cant_Move_Right

   goto __P0_Move_Right

__Cant_Move_Right

   ;```````````````````````````````````````````````````````````````
   ;  Right P0: Playfield pixel is in the way.
   ;  Shows right frame only if right bit is on. Clears the right
   ;  bit and skips this section.
   ;
   if _Bit3_P0_Dir_Right{3} then gosub __Frame_LR_01

   _Bit3_P0_Dir_Right{3} = 0

   goto __Skip_Joy0_Right

__P0_Move_Right

   ;```````````````````````````````````````````````````````````````
   ;  Right P0: Moves P0 right only if sprite is lined up with PF.
   ;
   temp5 = (temp6*8)+7

   if temp5 <> player0y then goto __Skip_Joy0_Right

   _P0_L_R = _P0_L_R + 0.85

   ;```````````````````````````````````````````````````````````````
   ;  Right P0: Sprite animation.
   ;
   on _Frame_Counter gosub __Frame_LR_00 __Frame_LR_01 __Frame_LR_02 __Frame_LR_01

   ;```````````````````````````````````````````````````````````````
   ;  Right P0: Makes sure sprite is facing the correct direction.
   ;
   _Bit6_Flip_P0{6} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Right P0: Clears bits and turns on the right direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %11110000

   _Bit3_P0_Dir_Right{3} = 1

__Skip_Joy0_Right



   ;****************************************************************
   ;
   ;  Flips player sprite when necessary.
   ;
   if _Bit6_Flip_P0{6} then REFP0 = 8



   ;***************************************************************
   ;
   ;  Starts counting if enemy direction has changed.
   ;  This keeps the enemy from changing directions right away
   ;  so he won't bounce back and reverse direction.
   ;
   ;***************************************************************
   ;
   if _Bit5_Direction_Changed{5} then _Enemy_Counter = _Enemy_Counter + 1



   ;***************************************************************
   ;
   ;  Enemy up check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if enemy up direction bit isn't on.
   ;
   if !_Bit4_P1_Dir_Up{4} then goto __Skip_P1_Up

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Up: Converts enemy sprite coordinates and checks to
   ;  see if any playfield pixels are in the way.
   ;
   temp3 = (player1x-17)/4

   temp6 = (player1y/8)-1

   if pfread(temp3,temp6) then goto __Enemy_Cant_Move_Up

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then goto __Enemy_Cant_Move_Up

   goto __Skip_to_P1_Move_Up

__Enemy_Cant_Move_Up

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Up: Playfield pixel in the way. Clears the up bit, gets 
   ;  a new direction and jumps to the beginning of enemy movement.
   ;
   _Bit4_P1_Dir_Up{4} = 0

   gosub __Check_P1_LR

   goto __Clear_Direction

__Skip_to_P1_Move_Up

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Up: Moves enemy up only if sprite is lined up with PF.
   ;
   temp5 = (temp3*4)+17

   if temp5 <> player1x then goto __Skip_P1_Up

   _P1_U_D = _P1_U_D - 0.52

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Up: Randomly checks to see if a new direction can be
   ;  taken if the direction hasn't changed lately.
   ;
   ;  Remember that the value of _Enemy_Rand_Look can be increased to make
   ;  it more likely that a new direction will be looked for.
   ;
   if _Bit5_Direction_Changed{5} then goto __Skip_Enemy_Look_Up

   temp5 = rand

   temp6 = (((player1y-7)/8)*8)+7

   if temp5 < _Enemy_Rand_Look then if temp6 = player1y then gosub __Check_P1_LR : if _Bit5_Direction_Changed{5} then _Bit4_P1_Dir_Up{4} = 0 : goto __Clear_Direction

   _Bit5_Direction_Changed{5} = 0

__Skip_Enemy_Look_Up

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Up: Turns on the up direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %00001111

   _Bit4_P1_Dir_Up{4} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Up: Enemy sprite up frame.
   ;
   player1:
   %10101010
   %11111110
   %11111110
   %11111110
   %11010110
   %11010110
   %01111100
end

__Skip_P1_Up



   ;***************************************************************
   ;
   ;  Enemy down check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if enemy down direction bit isn't on.
   ;
   if !_Bit5_P1_Dir_Down{5} then goto __Skip_P1_Down

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Down: Converts enemy sprite coordinates and checks to
   ;  see if any playfield pixels are in the way.
   ;
   temp3 = (player1x-17)/4

   temp6 = ((player1y-7)/8) + 1

   if pfread(temp3,temp6) then goto __Enemy_Cant_Move_Down

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then goto __Enemy_Cant_Move_Down

   goto __Skip_to_P1_Move_Down

__Enemy_Cant_Move_Down

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Down: PF pixel in the way. Clears the down bit, gets a
   ;  new direction and jumps to the beginning of enemy movement.
   ;
   _Bit5_P1_Dir_Down{5} = 0

   gosub __Check_P1_LR

   goto __Clear_Direction

__Skip_to_P1_Move_Down

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Down: Moves down only if sprite is lined up with PF.
   ;
   temp5 = (temp3*4)+17

   if temp5 <> player1x then goto __Skip_P1_Down

   _P1_U_D = _P1_U_D + 0.52

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Down: Randomly checks to see if a new direction can be
   ;  taken if the direction hasn't changed lately.
   ;
   ;  Remember that the value of _Enemy_Rand_Look can be increased to make
   ;  it more likely that a new direction will be looked for.
   ;
   if _Bit5_Direction_Changed{5} then goto __Skip_Enemy_Look_Down

   temp5 = rand

   temp6 = (((player1y-7)/8)*8)+7

   if temp5 < _Enemy_Rand_Look then if temp6 = player1y then gosub __Check_P1_LR : if _Bit5_Direction_Changed{5} then _Bit5_P1_Dir_Down{5} = 0 : goto __Clear_Direction

   _Bit5_Direction_Changed{5} = 0

__Skip_Enemy_Look_Down

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Down: Turns on the down direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %00001111

   _Bit5_P1_Dir_Down{5} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Down: Enemy sprite down frame.
   ;
   player1:
   %10101010
   %11111110
   %11010110
   %11010110
   %11111110
   %11111110
   %01111100
end

__Skip_P1_Down



   ;***************************************************************
   ;
   ;  Enemy left check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if enemy left direction bit isn't on.
   ;
   if !_Bit6_P1_Dir_Left{6} then goto __Skip_P1_Left

   ;```````````````````````````````````````````````````````````````
   ;  Converts enemy sprite coordinates and checks to see if
   ;  any playfield pixels are in the way.
   ;
   temp5 = ((player1x-14)/4) - 1

   temp6 = (player1y-7)/8

   if pfread(temp5,temp6) then goto __Enemy_Cant_Move_Left

   goto __Skip_to_P1_Move_Left

__Enemy_Cant_Move_Left

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Left: PF pixel in the way. Clears the left bit, gets a
   ;  new direction and jumps to the beginning of enemy movement.
   ;
   _Bit6_P1_Dir_Left{6} = 0

   gosub __Check_P1_UD

   goto __Clear_Direction

__Skip_to_P1_Move_Left

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Left: Moves left only if sprite is lined up with PF.
   ;
   temp5 = (temp6*8)+7

   if temp5 <> player1y then goto __Skip_P1_Left

   _P1_L_R = _P1_L_R - 0.52

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Left: Randomly checks to see if a new direction can be
   ;  taken if the direction hasn't changed lately.
   ;
   ;  Remember that the value of _Enemy_Rand_Look can be increased to make
   ;  it more likely that a new direction will be looked for.
   ;
   if _Bit5_Direction_Changed{5} then goto __Skip_Enemy_Look_Left

   temp5 = rand

   if temp5 < _Enemy_Rand_Look then temp5 = (((player1x-17)/4)*4)+17 : if temp5 = player1x then gosub __Check_P1_UD : if _Bit5_Direction_Changed{5} then _Bit6_P1_Dir_Left{6} = 0 : goto __Clear_Direction

   _Bit5_Direction_Changed{5} = 0

__Skip_Enemy_Look_Left

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Left: Turns on the left direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %00001111

   _Bit6_P1_Dir_Left{6} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Left: Enemy sprite left frame.
   ;
   player1:
   %10101010
   %11111110
   %11111110
   %10101110
   %10101110
   %11111110
   %01111100
end

__Skip_P1_Left



   ;***************************************************************
   ;
   ;  Enemy right check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if enemy right direction bit isn't on.
   ;
   if !_Bit7_P1_Dir_Right{7} then goto __Skip_P1_Right

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Right: Converts enemy sprite coordinates and checks to
   ;  see if any playfield pixels are in the way.
   ;
   temp5 = ((player1x-13)/4)+1

   temp6 = ((player1y-7)/8)

   if pfread(temp5,temp6) then goto __Enemy_Cant_Move_Right

   goto __Skip_to_P1_Move_Right

__Enemy_Cant_Move_Right

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Right: PF pixel in the way. Clears the right bit, gets
   ;  a new direction and jumps to the beginning of enemy movement.
   ;
   _Bit7_P1_Dir_Right{7} = 0

   gosub __Check_P1_UD

   goto __Clear_Direction

__Skip_to_P1_Move_Right

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Right: Move right only if sprite is lined up with PF.
   ;
   temp5 = (temp6*8)+7

   if temp5 <> player1y then goto __Skip_P1_Right

   _P1_L_R = _P1_L_R + 0.52

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Right: Randomly checks to see if a new direction can be
   ;  taken if the direction hasn't changed lately.
   ;
   ;  Remember that the value of _Enemy_Rand_Look can be increased to make
   ;  it more likely that a new direction will be looked for.
   ;
   if _Bit5_Direction_Changed{5} then goto __Skip_Enemy_Look_Right

   temp5 = rand

   if temp5 < _Enemy_Rand_Look then temp5 = (((player1x-17)/4)*4)+17 : if temp5 = player1x then gosub __Check_P1_UD : if _Bit5_Direction_Changed{5} then _Bit7_P1_Dir_Right{7} = 0 : goto __Clear_Direction

   _Bit5_Direction_Changed{5} = 0

__Skip_Enemy_Look_Right

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Right: Turns on the right direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %00001111

   _Bit7_P1_Dir_Right{7} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Right: Enemy sprite right frame.
   ;
   player1:
   %10101010
   %11111110
   %11111110
   %11101010
   %11101010
   %11111110
   %01111100
end

__Skip_P1_Right



   ;***************************************************************
   ;
   ;  Enemy counter check.
   ;
__Clear_Direction

   ;```````````````````````````````````````````````````````````````
   ;  Clears enemy direction flag and enemy counter if enemy
   ;  counter is greater than 2.
   ;
   if _Enemy_Counter > 2 then _Bit5_Direction_Changed{5} = 0 : _Enemy_Counter = 0



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart bank1





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;
   ;  Checks left and right for an opening.
   ;
__Check_P1_LR

   ;```````````````````````````````````````````````````````````````
   ;  Clears direction changed bit and chooses which direction to
   ;  start looking.
   ;
   _Bit5_Direction_Changed{5} = 0

   ;```````````````````````````````````````````````````````````````
   ;  15 percent chance that player location will be ignored.
   ;
   temp5 = rand : if temp5 < 38 then goto __Skip_LR_Check

   ;```````````````````````````````````````````````````````````````
   ;  Player location not ignored. Skips first left check if player
   ;  is to the right of the enemy.
   ;
   if player0x > player1x then goto __Skip_LR_Check

   ;```````````````````````````````````````````````````````````````
   ;  Looks to the left.
   ;
   temp5 = ((player1x-17)/4) - 1

   temp6 = (player1y-7)/8

   if pfread(temp5,temp6) then goto __Skip_LR_Check

   _Bit6_P1_Dir_Left{6} = 1 : _Bit5_Direction_Changed{5} = 1 : return thisbank

__Skip_LR_Check

   ;```````````````````````````````````````````````````````````````
   ;  Looks to the right.
   ;
   temp5 = ((player1x-13)/4)+1

   temp6 = (player1y-7)/8

   if pfread(temp5,temp6) then goto __Skip_R_Check

   _Bit7_P1_Dir_Right{7} = 1 : _Bit5_Direction_Changed{5} = 1 : return thisbank

__Skip_R_Check

   ;```````````````````````````````````````````````````````````````
   ;  Look to the left.
   ;
   temp5 = ((player1x-17)/4) - 1

   temp6 = (player1y-7)/8

   if pfread(temp5,temp6) then return thisbank

   _Bit6_P1_Dir_Left{6} = 1 : _Bit5_Direction_Changed{5} = 1 : return thisbank




   ;***************************************************************
   ;
   ;  Looks up and down for an opening.
   ;
__Check_P1_UD

   ;```````````````````````````````````````````````````````````````
   ;  Clears direction changed bit and chooses which direction to
   ;  start looking.
   ;
   _Bit5_Direction_Changed{5} = 0

   ;```````````````````````````````````````````````````````````````
   ;  15 percent chance that player location will be ignored.
   ;
   temp5 = rand : if temp5 < 38 then goto __Skip_UD_Check

   ;```````````````````````````````````````````````````````````````
   ;  Player location not ignored. Skips first up check if player
   ;  is lower than enemy.
   ;
   if player0y > player1y then goto __Skip_UD_Check

   ;```````````````````````````````````````````````````````````````
   ;  Looks up.
   ;
   temp3 = (player1x-17)/4

   temp6 = (player1y/8)-1

   if pfread(temp3,temp6) then goto __Skip_UD_Check

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then goto __Skip_UD_Check

   _Bit4_P1_Dir_Up{4} = 1 : _Bit5_Direction_Changed{5} = 1 : return thisbank

__Skip_UD_Check

   ;```````````````````````````````````````````````````````````````
   ;  Looks down.
   ;
   temp3 = (player1x-17)/4

   temp5 = temp3 + 1

   temp6 = ((player1y-7)/8) + 1

   if pfread(temp3,temp6) then goto __Skip_U_Check

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then goto __Skip_U_Check

   _Bit5_P1_Dir_Down{5} = 1 : _Bit5_Direction_Changed{5} = 1 : return thisbank

__Skip_U_Check

   ;```````````````````````````````````````````````````````````````
   ;  Lookd up.
   ;
   temp3 = (player1x-17)/4

   temp6 = (player1y/8)-1

   if pfread(temp3,temp6) then return thisbank

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then return thisbank

   _Bit4_P1_Dir_Up{4} = 1 : _Bit5_Direction_Changed{5} = 1 : return thisbank




   ;***************************************************************
   ;
   ;  Left/right animation frames for player.
   ;
   ;```````````````````````````````````````````````````````````````
__Frame_LR_00
   player0:
   %01111100
   %11111110
   %11111110
   %11110000
   %11111110
   %11111110
   %01111100
end

   return thisbank


__Frame_LR_01
   player0:
   %01111100
   %11111110
   %11111000
   %11100000
   %11111000
   %11111110
   %01111100
end

   return thisbank


__Frame_LR_02
   player0:
   %01111100
   %11111000
   %11110000
   %11100000
   %11110000
   %11111000
   %01111100
end

   return thisbank



   ;****************************************************************
   ;
   ;  Up animation frames for player.
   ;
__Frame_U_00
   player0:
   %01111100
   %11111110
   %11111110
   %11111110
   %11101110
   %11101110
   %01101100
end

   return thisbank


__Frame_U_01
   player0:
   %01111100
   %11111110
   %11111110
   %11101110
   %11101110
   %11000110
   %01000100
end

   return thisbank


__Frame_U_02
   player0:
   %01111100
   %11111110
   %11111110
   %11101110
   %11000110
   %10000010
   %00000000
end

   return thisbank



   ;****************************************************************
   ;
   ;  Down animation frames for player.
   ;
__Frame_D_00
   player0:
   %01101100
   %11101110
   %11101110
   %11111110
   %11111110
   %11111110
   %01111100
end

   return thisbank


__Frame_D_01
   player0:
   %01000100
   %11000110
   %11101110
   %11101110
   %11111110
   %11111110
   %01111100
end

   return thisbank


__Frame_D_02
   player0:
   %00000000
   %10000010
   %11000110
   %11101110
   %11111110
   %11111110
   %01111100
end

   return thisbank




   bank 3




   bank 4

 

 

 

Sprite/Playfield Priority Example

Sprite/Playfield Priority Example on bB page.

 
   ;***************************************************************
   ;
   ;  Sprite/Playfield Priority
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Use the joystick to move the sprite. Press the fire button 
   ;  to flip the priority so the sprite will either be in front
   ;  of or behind the playfield.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y
   dim _Bit1_FireB_Restrainer = y
   dim _Bit7_Flip_CTRLPF = y



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for an 8 x 8 sprite.
   ;  If your sprite is a different size, you`ll need to adjust
   ;  the numbers.
   ;
   const _P_Edge_Top = 9
   const _P_Edge_Bottom = 88
   const _P_Edge_Left = 1
   const _P_Edge_Right = 153



   ;***************************************************************
   ;
   ;  Disables the score. (We don't need it in this program.)
   ;
   const noscore = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables (fastest way).
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0


   ;***************************************************************
   ;
   ;  Sets starting position of player0.
   ;
   player0x = 77 : player0y = 53


   ;***************************************************************
   ;
   ;  Sets playfield color.
   ;
   COLUPF = $FC


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Makes sure sprite is in front of the playfield.
   ;
   CTRLPF = 1


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Restrains the fire button for the main loop.
   ;
   ;  This bit fixes it so the fire button becomes inactive if it
   ;  hasn't been released after being pressed once. If the fire
   ;  button isn't being held down, this bit will be cleared
   ;  in the main loop.
   ;
   _Bit1_FireB_Restrainer{1} = 1


   ;***************************************************************
   ;
   ;  Defines shape of player0 sprite.
   ;
   player0:
   %00111100
   %01111110
   %11000011
   %10111101
   %11111111
   %11011011
   %01111110
   %00111100
end


   ;***************************************************************
   ;
   ;  Sets up the playfield.
   ;
   playfield:
   ................................
   ................................
   ....XXXXXXXXXX....XXXXXXXXXX....
   ....X......................X....
   ....X......................X....
   ....X......................X....
   ................................
   ................................
   ....XXXX....XXXXXXXX....XXXX....
   ................................
   ................................
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets color of player0 sprite.
   ;
   COLUP0 = $9C



   ;***************************************************************
   ;
   ;  Moves player0 sprite with the joystick while keeping the
   ;  sprite within the playfield area.
   ;
   if joy0up && player0y > _P_Edge_Top then player0y = player0y - 1

   if joy0down && player0y < _P_Edge_Bottom then player0y = player0y + 1

   if joy0left && player0x > _P_Edge_Left then player0x = player0x - 1

   if joy0right && player0x < _P_Edge_Right then player0x = player0x + 1



   ;***************************************************************
   ;
   ;  Fire button check.
   ;
   ;  Moves sprite in front of or behind playfield when the fire
   ;  button is pressed. The fire button is also restrained, so
   ;  holding it down won't make it keep firing.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skip this section if fire button not pressed.
   ;
   if !joy0fire then _Bit1_FireB_Restrainer{1} = 0 : goto __Skip_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Skip this section if fire button hasn't been released.
   ;
   if _Bit1_FireB_Restrainer{1} then goto __Skip_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Turns on fire button restrainer.
   ;
   _Bit1_FireB_Restrainer{1} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Flips sprite/playfield priority bit.
   ;
   _Bit7_Flip_CTRLPF{7} = !_Bit7_Flip_CTRLPF{7}

   ;```````````````````````````````````````````````````````````````
   ;  Assigns either 4+1 or 0+1 to CTRLPF, depending on the value
   ;  in _Bit7_Flip_CTRLPF{7}. Do not change the 2 in "temp5{2}".
   ;  It will only work correctly if bit 2 is used.
   ;
   temp5 = 1 : temp5{2} = _Bit7_Flip_CTRLPF{7} : CTRLPF = temp5

__Skip_Fire



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart

 

 

 

pfscore Lives and Health Example

pfscore Lives and Health Example on bB page.

 
   ;***************************************************************
   ;
   ;  pfscore Lives and Health Toy
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;  Special thanks to Nukey Shay for the increment code.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  When the program starts, there will be two icons that stand
   ;  for Lives and Health. Move the joystick left to choose the
   ;  type of bar you want on the left and move the joystick right
   ;  to choose the type of bar on the right. When you are done,
   ;  press the fire button.
   ;
   ;  You will now see your choices near the bottom of the screen.
   ;  
   ;  Left Bar: Move the joystick right/left to decrease/increase.
   ;  
   ;  Right Bar: Move the joystick down/up to decrease/increase.
   ;
   ;  Hit the reset switch if you want to restart the program.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;  
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  This joystick restrainer slows down joystick input so things
   ;  will not move at the speed of light. When the joystick is
   ;  moved, _Joy0_Restrainer_Counter gets a value of 15 and until
   ;  it counts down to zero, the program will ignore joystick
   ;  movement.
   ;
   dim _Joy0_Restrainer_Counter = m

   ;```````````````````````````````````````````````````````````````
   ;  Left selection bit:
   ;      0 = Lives
   ;      1 = Health
   ;
   dim _Bit0_Left_Selection = p

   ;```````````````````````````````````````````````````````````````
   ;  Right selection bit:
   ;      0 = Lives
   ;      1 = Health
   ;
   dim _Bit1_Right_Selection = p

   ;```````````````````````````````````````````````````````````````
   ;  Splits up the score into 3 parts.
   ;
   dim _sc1 = score
   dim _sc2 = score+1
   dim _sc3 = score+2



   ;***************************************************************
   ;
   ;  Enables pfscore bars.
   ;
   const pfscore = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart



   ;***************************************************************
   ;
   ;  Sets the default look of the sprites.
   ;
   player0:
   %10101010
end

   player1:
   %11111111
end


   ;***************************************************************
   ;
   ;  Sets up pfscore bar selection bits.
   ;
   _Bit0_Left_Selection{0} = 0 :  _Bit1_Right_Selection{1}= 1


   ;***************************************************************
   ;
   ;  Sets up pfscore bars.
   ;
   pfscore1 = %10101010 : pfscore2 = %11111111


   ;***************************************************************
   ;
   ;  Sets color for pfscore bars.
   ;
   pfscorecolor = 0


   ;***************************************************************
   ;
   ;  Sets joystick restrainer counter.
   ;
   _Joy0_Restrainer_Counter = 15


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Sets starting position of player0.
   ;
   player0x = 70 : player0y = 50


   ;***************************************************************
   ;
   ;  Sets starting position of player1.
   ;
   player1x = 86 : player1y = 50





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Select Lives or Health Bars
   ;
   ;
__Choose_Lives_Health



   ;***************************************************************
   ;
   ;  Sets the score color and color of the sprites.
   ;
   scorecolor = 0 : COLUP0 = $CB : COLUP1 = $CB



   ;***************************************************************
   ;
   ;  Skips joystick input if _Joy0_Restrainer_Counter is not zero.
   ;
   if _Joy0_Restrainer_Counter <> 0 then goto __R_Done



   ;***************************************************************
   ;
   ;  Left choice.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick not moved left.
   ;
   if !joy0left then goto __L_Done

   _Joy0_Restrainer_Counter = 15 : if !_Bit0_Left_Selection{0} then goto __Skip_L

   ;```````````````````````````````````````````````````````````````
   ;  pfscore1 will be a lives bar.
   ;
   _Bit0_Left_Selection{0} = 0 : pfscore1 = %10101010

   player0:
   %10101010
end

   goto __L_Done

__Skip_L

   ;```````````````````````````````````````````````````````````````
   ;  pfscore1 will be a health bar.
   ;
   _Bit0_Left_Selection{0} = 1 : pfscore1 = %11111111

   player0:
   %11111111
end

__L_Done



   ;***************************************************************
   ;
   ;  Right choice.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick not moved right.
   ;
   if !joy0right then goto __R_Done

   _Joy0_Restrainer_Counter = 15 : if !_Bit1_Right_Selection{1} then goto __Skip_R

   ;```````````````````````````````````````````````````````````````
   ;  pfscore2 will be a lives bar.
   ;
   _Bit1_Right_Selection{1} = 0 : pfscore2 = %10101010

   player1:
   %10101010
end

   goto __R_Done

__Skip_R

   ;```````````````````````````````````````````````````````````````
   ;  pfscore2 will be a health bar.
   ;
   _Bit1_Right_Selection{1} = 1 : pfscore2 = %11111111

   player1:
   %11111111
end

__R_Done



   ;***************************************************************
   ;
   ;  Decreases joystick restrainer counter. When counter reaches
   ;  zero, joystick movement is allowed again.
   ;
   if _Joy0_Restrainer_Counter then _Joy0_Restrainer_Counter = _Joy0_Restrainer_Counter - 1



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Fire button check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Loops back if fire button not pressed.
   ;
   if !joy0fire then goto __Choose_Lives_Health

   ;```````````````````````````````````````````````````````````````
   ;  Sets up variables and any colors for main loop.
   ;
   _Joy0_Restrainer_Counter = 15 : pfscorecolor = $CB

   goto __Main_Loop





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets colors for score and sprites.
   ;
   scorecolor = 28 : COLUP0 = $CB : COLUP1 = $CB



   ;***************************************************************
   ;
   ;  Skips joystick input if joystick restrainer is not zero.
   ;
   if _Joy0_Restrainer_Counter <> 0 then goto __Skip_All_Joystick_Input



   ;***************************************************************
   ;
   ;  Increases the bar on the left (pfscore1).
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick not moved left.
   ;
   if !joy0left then goto __Joy0Left_Check_Done

   ;```````````````````````````````````````````````````````````````
   ;  Sets joystick restrainer counter.
   ;
   _Joy0_Restrainer_Counter = 15

   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if selection bit is set to health bar.
   ;
   if _Bit0_Left_Selection{0} then goto __Increase_Left_Health_Bar

   ;```````````````````````````````````````````````````````````````
   ;  Increases lives bar on the left.
   ;
   ;  Full lives bar looks like this: 10101010
   ;
   ;  How to increase lives bar on left side of screen:
   ;
   ;  Multiply pfscore1 by 4, then use OR 2.
   ;
   pfscore1 = pfscore1*4|2

   goto __Joy0Left_Check_Done

__Increase_Left_Health_Bar

   ;```````````````````````````````````````````````````````````````
   ;  Increases health bar on the left.
   ;
   ;  Full health bar looks like this: 11111111
   ;
   ;  How to increase health bar on left side of screen:
   ;
   ;  Multiply pfscore1 by 2 then use OR 1.
   ;
   pfscore1 = pfscore1*2|1

__Joy0Left_Check_Done



   ;***************************************************************
   ;
   ;  Decreases the bar on the left (pfscore1).
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick not moved right.
   ;
   if !joy0right then goto __Joy0Right_Check_Done

   ;```````````````````````````````````````````````````````````````
   ;  Sets joystick restrainer counter.
   ;
   _Joy0_Restrainer_Counter = 15

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if selection bit is set to health bar, skip ahead.
   ;
   if _Bit0_Left_Selection{0} then goto __Decrease_Left_Health_Bar

   ;```````````````````````````````````````````````````````````````
   ;  Decreases lives bar on the left.
   ;
   ;  Full lives bar looks like this: 10101010
   ;
   ;  How to decrease lives bar on left side of screen:
   ;
   ;  Divide pfscore1 by 4.
   ;
   pfscore1 = pfscore1/4

   goto __Joy0Right_Check_Done

__Decrease_Left_Health_Bar

   ;```````````````````````````````````````````````````````````````
   ;  Decreases lives bar on the left.
   ;
   ;  Full health bar looks like this: 11111111
   ;
   ;  How to decrease health bar on left side of screen:
   ;
   ;  Divide pfscore1 by 2.
   ;
   pfscore1 = pfscore1/2

__Joy0Right_Check_Done



   ;***************************************************************
   ;
   ;  Increases the bar on the right (pfscore2).
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick not moved up.
   ;
   if !joy0up then goto __Joy0Up_Check_Done

   ;```````````````````````````````````````````````````````````````
   ;  Sets joystick restrainer counter.
   ;
   _Joy0_Restrainer_Counter = 15

   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if selection bit is set to health bar.
   ;
   if _Bit1_Right_Selection{1} then goto __Increase_Right_Health_Bar

   ;```````````````````````````````````````````````````````````````
   ;  Increases lives bar on the right.
   ;
   ;  Full lives bar looks like this: 10101010
   ;
   ;  How to increase lives bar on right side of screen:
   ;
   ;  Multiply pfscore2 by 4, then use OR 2.
   ;
   pfscore2 = pfscore2*4|2

   goto __Joy0Up_Check_Done

__Increase_Right_Health_Bar

   ;```````````````````````````````````````````````````````````````
   ;  Increases health bar on the right.
   ;
   ;  Full health bar looks like this: 11111111
   ;
   ;  How to increase health bar on right side of screen:
   ;
   ;  Multiply pfscore2 by 2 then use OR 1.
   ;
   pfscore2 = pfscore2*2|1

__Joy0Up_Check_Done



   ;***************************************************************
   ;
   ;  Decreases the bar on the right (pfscore2).
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick not moved down.
   ;
   if !joy0down then goto __Skip_All_Joystick_Input

   ;```````````````````````````````````````````````````````````````
   ;  Sets joystick restrainer counter.
   ;
   _Joy0_Restrainer_Counter = 15

   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if selection bit is set to health bar.
   ;
   if _Bit1_Right_Selection{1} then goto __Decrease_Right_Health_Bar

   ;```````````````````````````````````````````````````````````````
   ;  Decreases lives bar on the right.
   ;
   ;  Full lives bar looks like this: 10101010
   ;
   ;  How to decrease lives bar on right side of screen:
   ;
   ;  Divide pfscore2 by 4.
   ;
   pfscore2 = pfscore2/4

   goto __Skip_All_Joystick_Input

__Decrease_Right_Health_Bar

   ;```````````````````````````````````````````````````````````````
   ;  Decreases health bar on the right.
   ;
   ;  Full health bar looks like this: 11111111
   ;
   ;  How to decrease health bar on right side of screen:
   ;
   ;  Divide pfscore2 by 2.
   ;
   pfscore2 = pfscore2/2

__Skip_All_Joystick_Input



   ;***************************************************************
   ;
   ;  Decreases joystick restrainer counter. When counter reaches
   ;  zero, joystick movement is allowed again.
   ;
   if _Joy0_Restrainer_Counter then _Joy0_Restrainer_Counter = _Joy0_Restrainer_Counter - 1



   ;***************************************************************
   ;
   ;  Puts temp4 in the three score digits on the left side.
   ;
   temp4 = pfscore1

   _sc1 = 0 : _sc2 = _sc2 & 15
   if temp4 >= 100 then _sc1 = _sc1 + 16 : temp4 = temp4 - 100
   if temp4 >= 100 then _sc1 = _sc1 + 16 : temp4 = temp4 - 100
   if temp4 >= 50 then _sc1 = _sc1 + 5 : temp4 = temp4 - 50
   if temp4 >= 30 then _sc1 = _sc1 + 3 : temp4 = temp4 - 30
   if temp4 >= 20 then _sc1 = _sc1 + 2 : temp4 = temp4 - 20
   if temp4 >= 10 then _sc1 = _sc1 + 1 : temp4 = temp4 - 10
   _sc2 = (temp4 * 4 * 4) | _sc2



   ;***************************************************************
   ;
   ;  Puts temp4 in the three score digits on the right side.
   ;
   temp4 = pfscore2

   _sc2 = _sc2 & 240 : _sc3 = 0
   if temp4 >= 100 then _sc2 = _sc2 + 1 : temp4 = temp4 - 100
   if temp4 >= 100 then _sc2 = _sc2 + 1 : temp4 = temp4 - 100
   if temp4 >= 50 then _sc3 = _sc3 + 80 : temp4 = temp4 - 50
   if temp4 >= 30 then _sc3 = _sc3 + 48 : temp4 = temp4 - 30
   if temp4 >= 20 then _sc3 = _sc3 + 32 : temp4 = temp4 - 20
   if temp4 >= 10 then _sc3 = _sc3 + 16 : temp4 = temp4 - 10
   _sc3 = _sc3 | temp4



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if reset switch not pressed.
   ;
   if !switchreset then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart

 

 

 

8-Way Scrolling

8-Way Scrolling on bB page.

 
   ;***************************************************************
   ;
   ;  pfscroll Example
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Tiny little itty-bitty bit variables.
   ;
   dim _Bit0_Reset_Restrainer = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers. 
   ;
   dim rand16 = z





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Resets the playfield after scrolling.
   ;
   playfieldpos = 8


   ;***************************************************************
   ;
   ;  Clears 25 of the normal 26 variables (fastest way).
   ;  The variable z is used for random numbers in this program
   ;  and clearing it would mess up those random numbers.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0


   ;***************************************************************
   ;
   ;  Sets background color, score color, and playfield color.
   ;
   COLUBK = $C4 : scorecolor = $C4 : COLUPF = $CE


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets up the playfield.
   ;
   playfield:
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   X..............................X
   X...XXXXXXXXXX....XXXXXXXXXX...X
   X...X......................X...X
   X...X......................X...X
   X...X......................X...X
   X..............................X
   X..............................X
   X...XXXX....XXXXXXXX....XXXX...X
   X..............................X
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   ................................
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Scrolls screen using joystick.
   ;
   if joy0up then pfscroll up
   if joy0down then pfscroll down
   if joy0left then pfscroll left
   if joy0right then pfscroll right



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````

 

 

 

Paddle Example

Paddle Example on bB page.

 
   ;***************************************************************
   ;
   ;  Read Paddle
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Bounce the ball back up with the paddle.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;****************************************************************
   ;
   ;  Kernel options for this program eliminate the blank lines
   ;  and allow the paddles to be read.
   ;
   set kernel_options no_blank_lines readpaddle



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Paddle direction.
   ;
   dim _Paddle_Direction = c

   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y
   dim _Bit5_B_Direction_X = y
   dim _Bit6_B_Direction_Y = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers. 
   ;
   dim rand16 = z



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for the ball. If the
   ;  ball is a different size, you'll need to adjust the numbers.
   ;
   const _B_Edge_Top = 3
   const _B_Edge_Bottom = 88
   const _B_Edge_Left = 3
   const _B_Edge_Right = 159





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears 25 of the normal 26 variables (fastest way).
   ;  The variable z is used for random numbers in this program
   ;  and clearing it would mess up those random numbers.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0


   ;***************************************************************
   ;
   ;  Sets positions of player0 and ball.
   ;
   player0y = 85 : bally = 200


   ;***************************************************************
   ;
   ;  Sets background color and foreground color.
   ;
   COLUBK = $00 : COLUPF = $2C


   ;***************************************************************
   ;
   ;  Makes the ball 2 pixels wide and 2 pixels high.
   ;
   CTRLPF = $11 : ballheight = 2


   ;***************************************************************
   ;
   ;  Sets random starting position of ball.
   ;
   ballx = (rand/2) + (rand&15) + (rand/32) + 5 : bally = 6


   ;***************************************************************
   ;
   ;  Ballx starting direction is random. It will either go left
   ;  or right.
   ;
   temp5 = (rand & %00100000)

   _Bit5_B_Direction_X = _Bit5_B_Direction_X ^ temp5


   ;***************************************************************
   ;
   ;  Bally starting direction is down.
   ;
   _Bit6_B_Direction_Y{6} = 1


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Creates shape of paddle.
   ;
   player0:
   %1111111
   %1111111
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE GAME GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets up color and size of player0 (double size).
   ;
   COLUP0 = $9C : NUSIZ0 = $05



   ;***************************************************************
   ;
   ;  Bounces the ball if it hits the edge of the screen.
   ;
   if ballx < _B_Edge_Left || ballx > _B_Edge_Right then _Bit5_B_Direction_X = _Bit5_B_Direction_X ^ %00100000

   if bally < _B_Edge_Top then _Bit6_B_Direction_Y = _Bit6_B_Direction_Y ^ %01000000



   ;***************************************************************
   ;
   ;  Moves the ball.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Moves ball right if direction isn't left.
   ;
   temp5 = 255 : if _Bit5_B_Direction_X{5} then temp5 = 1

   ballx = ballx + temp5

   ;```````````````````````````````````````````````````````````````
   ;  Moves ball down if direction isn't up.
   ;
   temp5 = 255 : if _Bit6_B_Direction_Y{6} then temp5 = 1

   bally = bally + temp5



   ;***************************************************************
   ;
   ;  Lost ball check. Resets ball if it hits the bottom.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if ball isn't at bottom of screen.
   ;
   if bally < 100 then goto __Skip_Ball_Reset

   ;```````````````````````````````````````````````````````````````
   ;  Chooses a new random location at the top of the screen.
   ;
   ballx = (rand/2) + (rand&15) + (rand/32) + 5 : bally = 6

   ;```````````````````````````````````````````````````````````````
   ;  Selects a random x direction.
   ;
   temp5 = (rand & %00100000)

   _Bit5_B_Direction_X = _Bit5_B_Direction_X ^ temp5

   ;```````````````````````````````````````````````````````````````
   ;  Bally starting direction is down.
   ;
   _Bit6_B_Direction_Y{6} = 1

__Skip_Ball_Reset



   ;***************************************************************
   ;
   ;  Paddle 0 will be read.
   ;
   currentpaddle = 0



   ;***************************************************************
   ;
   ;  Draws the screen and reads the paddle.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Gets old position of player0x.
   ;
   _Paddle_Direction = player0x



   ;***************************************************************
   ;
   ;  Converts value of paddle to useable coordinate.
   ;
   player0x = (paddle * 2) + 1

   ;```````````````````````````````````````````````````````````````
   ;  Limits player movement.
   ;
   if player0x > 141 then player0x = 141



   ;***************************************************************
   ;
   ;  Paddle collision. Influences direction of ball with paddle.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if there is no collision.
   ;
   if !collision(player0,ball) then goto __Skip_Paddle_Influence

   ;```````````````````````````````````````````````````````````````
   ;  Ball will move up now.
   ;
   _Bit6_B_Direction_Y{6} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if player hasn't moved.
   ;
   if _Paddle_Direction = player0x then goto __Skip_Paddle_Influence

   ;```````````````````````````````````````````````````````````````
   ;  Sets ball direction to the left.
   ;
   _Bit5_B_Direction_X{5} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Sets ball direction to the right if paddle has moved right.
   ;
   if player0x > _Paddle_Direction then _Bit5_B_Direction_X{5} = 1

__Skip_Paddle_Influence



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart

 

 

 

Paddle Example With Playfield Collision

Paddle Example With Playfield Collision on bB page.

 
   ;***************************************************************
   ;
   ;  Read Paddle With Playfield Collision
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Bounce the ball back up with the paddle.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;****************************************************************
   ;
   ;  Kernel options for this program eliminate the blank lines
   ;  and allow the paddles to be read.
   ;
   set kernel_options no_blank_lines readpaddle



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Paddle direction.
   ;
   dim _Paddle_Direction = g

   ;```````````````````````````````````````````````````````````````
   ;  Ball direction bits.
   ;
   dim _BitOp_Ball_Dir = h
   dim _Bit0_Ball_Dir_Up = h
   dim _Bit1_Ball_Dir_Down = h
   dim _Bit2_Ball_Dir_Left = h
   dim _Bit3_Ball_Dir_Right = h
   dim _Bit4_Ball_Hit_UD = h

   ;```````````````````````````````````````````````````````````````
   ;  Allows speed and angle adjustments to the ball.
   ;
   dim _B_Y = bally.i
   dim _B_X = ballx.j

   ;```````````````````````````````````````````````````````````````
   ;  All-purpose bits for various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers. 
   ;
   dim rand16 = z



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for the ball. If the
   ;  ball is a different size, you'll need to adjust the numbers.
   ;
   const _B_Edge_Top = 3
   const _B_Edge_Bottom = 88
   const _B_Edge_Left = 2
   const _B_Edge_Right = 159





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears 25 of the normal 26 variables (fastest way).
   ;  The variable z is used for random numbers in this program
   ;  and clearing it would mess up those random numbers.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0

   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0


   ;***************************************************************
   ;
   ;  Sets positions of player0 and ball.
   ;
   player0y = 85 : bally = 200


   ;***************************************************************
   ;
   ;  Sets background color and foreground color.
   ;
   COLUBK = $00 : COLUPF = $2C


   ;***************************************************************
   ;
   ;  Makes the ball 2 pixels wide and 2 pixels high.
   ;
   CTRLPF = $11 : ballheight = 2


   ;***************************************************************
   ;
   ;  Sets random starting position of ball.
   ;
   ballx = (rand/2) + (rand&15) + (rand/32) + 5 : bally = 6


   ;***************************************************************
   ;
   ;  Ballx starting direction is random. It will either go left
   ;  or right.
   ;
   _Bit2_Ball_Dir_Left{2} = 1 : _Bit3_Ball_Dir_Right{3} = 0

   temp5 = rand : if temp5 < 128 then _Bit2_Ball_Dir_Left{2} = 0 : _Bit3_Ball_Dir_Right{3} = 1


   ;***************************************************************
   ;
   ;  Bally starting direction is down.
   ;
   _Bit1_Ball_Dir_Down{1} = 1


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Creates shape of paddle.
   ;
   player0:
   %1111111
   %1111111
end


   ;***************************************************************
   ;
   ;  Sets up the playfield.
   ;
   playfield:
   ................................
   ................................
   ....XXX....XXX....XXX....XXX....
   ................................
   ................................
   ..X..........................X..
   ..X..........................X..
   ................................
   ................................
   ................................
   ................................
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE GAME GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets up color and size of player0 (double size).
   ;
   COLUP0 = $9C : NUSIZ0 = $05



   ;***************************************************************
   ;
   ;  Lost ball check. Resets ball if it hits the bottom.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if ball isn't at bottom of screen.
   ;
   if bally < 90 then goto __Skip_Ball_Reset

   ;```````````````````````````````````````````````````````````````
   ;  Chooses a new random location at the top of the screen.
   ;
   ballx = (rand/2) + (rand&15) + (rand/32) + 5 : bally = 6

   ;```````````````````````````````````````````````````````````````
   ;  Selects a random x direction.
   ;
   _Bit2_Ball_Dir_Left{2} = 1 : _Bit3_Ball_Dir_Right{3} = 0

   temp5 = rand : if temp5 < 128 then _Bit2_Ball_Dir_Left{2} = 0 : _Bit3_Ball_Dir_Right{3} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Bally starting direction is down.
   ;
   _Bit1_Ball_Dir_Down{1} = 1

__Skip_Ball_Reset



   ;***************************************************************
   ;
   ;  Clears ball hits.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears the up/down ball/playfield hit bit.
   ;
   _Bit4_Ball_Hit_UD{4} = 0



   ;***************************************************************
   ;
   ;  Ball up check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if ball isn't moving up.
   ;
   if !_Bit0_Ball_Dir_Up{0} then goto __Skip_Ball_Up

   ;```````````````````````````````````````````````````````````````
   ;  Changes direction if hitting the edge.
   ;
   if bally <= _B_Edge_Top then goto __Reverse_Ball_Up

   ;```````````````````````````````````````````````````````````````
   ;  Changes direction if a playfield pixel is in the way.
   ;
   temp5 = (ballx-18)/4

   temp6 = (bally-2)/8

   if temp5 < 34 then if pfread(temp5,temp6) then _Bit4_Ball_Hit_UD{4} = 1 : goto __Reverse_Ball_Up

   ;```````````````````````````````````````````````````````````````
   ;  Moves ball up and skips the rest of this section.
   ;
   _B_Y = _B_Y - 1.00 : goto __Skip_Ball_Up

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Reverses direction.
   ;
__Reverse_Ball_Up

   ;```````````````````````````````````````````````````````````````
   ;  Mixes things up a bit to keep the ball from getting caught
   ;  in a pattern.
   ;
   _B_Y = _B_Y + 0.130

   temp5 = rand : if temp5 < 128 then _B_Y = _B_Y + 0.130

   ;```````````````````````````````````````````````````````````````
   ;  Reverses the direction bits.
   ;
   _Bit0_Ball_Dir_Up{0} = 0 : _Bit1_Ball_Dir_Down{1} = 1

__Skip_Ball_Up



   ;***************************************************************
   ;
   ;  Ball down check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if ball isn't moving down.
   ;
   if !_Bit1_Ball_Dir_Down{1} then goto __Skip_Ball_Down

   ;```````````````````````````````````````````````````````````````
   ;  Changes direction if a playfield pixel is in the way.
   ;
   temp5 = (ballx-18)/4

   temp6 = (bally+1)/8

   if temp5 < 34 then if pfread(temp5,temp6) then _Bit4_Ball_Hit_UD{4} = 1 : goto __Reverse_Ball_Down

   ;```````````````````````````````````````````````````````````````
   ;  Moves ball down and skips the rest of this section.
   ;
   _B_Y = _B_Y + 1.00 : goto __Skip_Ball_Down

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Reverses direction.
   ;
__Reverse_Ball_Down

   ;```````````````````````````````````````````````````````````````
   ;  Mixes things up a bit to keep the ball from getting caught
   ;  in a pattern.
   ;
   _B_Y = _B_Y - 0.261

   temp5 = rand : if temp5 < 128 then _B_Y = _B_Y - 0.261

   ;```````````````````````````````````````````````````````````````
   ;  Reverses the direction bits.
   ;
   _Bit0_Ball_Dir_Up{0} = 1 : _Bit1_Ball_Dir_Down{1} = 0

__Skip_Ball_Down



   ;***************************************************************
   ;
   ;  Ball left check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if ball isn't moving left.
   ;
   if !_Bit2_Ball_Dir_Left{2} then goto __Skip_Ball_Left

   ;```````````````````````````````````````````````````````````````
   ;  Changes direction if hitting the edge.
   ;
   if ballx <= _B_Edge_Left then goto __Reverse_Ball_Left

   ;```````````````````````````````````````````````````````````````
   ;  Changes direction if a playfield pixel is in the way.
   ;
   temp5 = (bally)/8

   temp6 = (ballx-19)/4

   if temp6 < 34 then if pfread(temp6,temp5) then goto __Reverse_Ball_Left

   ;```````````````````````````````````````````````````````````````
   ;  Moves ball left and skips the rest of this section.
   ;
   _B_X = _B_X - 1.00 : goto __Skip_Ball_Left

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Reverses direction.
   ;
__Reverse_Ball_Left

   ;```````````````````````````````````````````````````````````````
   ;  Reverses up/down bits if there was an up or down hit.
   ;
   if _Bit4_Ball_Hit_UD{4} then _Bit0_Ball_Dir_Up{0} = !_Bit0_Ball_Dir_Up{0} : _Bit1_Ball_Dir_Down{1} = !_Bit1_Ball_Dir_Down{1}

   ;```````````````````````````````````````````````````````````````
   ;  Mixes things up a bit to keep the ball from getting caught
   ;  in a pattern.
   ;
   _B_X = _B_X + 0.388

   temp5 = rand : if temp5 < 128 then _B_X = _B_X + 0.388

   ;```````````````````````````````````````````````````````````````
   ;  Reverses the direction bits.
   ;
   _Bit2_Ball_Dir_Left{2} = 0 : _Bit3_Ball_Dir_Right{3} = 1

__Skip_Ball_Left



   ;***************************************************************
   ;
   ;  Ball right check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if ball isn't moving right.
   ;
   if !_Bit3_Ball_Dir_Right{3} then goto __Skip_Ball_Right

   ;```````````````````````````````````````````````````````````````
   ;  Changes direction if hitting the edge.
   ;
   if ballx >= _B_Edge_Right then goto __Reverse_Ball_Right

   ;```````````````````````````````````````````````````````````````
   ;  Changes direction if a playfield pixel is in the way.
   ;
   temp5 = (bally)/8

   temp6 = (ballx-16)/4

   if temp6 < 34 then if pfread(temp6,temp5) then goto __Reverse_Ball_Right

   ;```````````````````````````````````````````````````````````````
   ;  Moves ball right and skips the rest of this section.
   ;
   _B_X = _B_X + 1.00 : goto __Skip_Ball_Right

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Reverses direction.
   ;
__Reverse_Ball_Right

   ;```````````````````````````````````````````````````````````````
   ;  Reverses up/down bits if there was an up or down hit.
   ;
   if _Bit4_Ball_Hit_UD{4} then _Bit0_Ball_Dir_Up{0} = !_Bit0_Ball_Dir_Up{0} : _Bit1_Ball_Dir_Down{1} = !_Bit1_Ball_Dir_Down{1}

   ;```````````````````````````````````````````````````````````````
   ;  Mixes things up a bit to keep the ball from getting caught
   ;  in a pattern.
   ;
   _B_X = _B_X - 0.513

   temp5 = rand : if temp5 < 128 then _B_X = _B_X - 0.513

   ;```````````````````````````````````````````````````````````````
   ;  Reverses the direction bits.
   ;
   _Bit2_Ball_Dir_Left{2} = 1 : _Bit3_Ball_Dir_Right{3} = 0

__Skip_Ball_Right



   ;***************************************************************
   ;
   ;  Paddle 0 will be read.
   ;
   currentpaddle = 0



   ;***************************************************************
   ;
   ;  Draws the screen and reads the paddle.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Gets old position of player0x.
   ;
   _Paddle_Direction = player0x



   ;***************************************************************
   ;
   ;  Converts value of paddle to useable coordinate.
   ;
   player0x = (paddle * 2) + 1

   ;```````````````````````````````````````````````````````````````
   ;  Limits player movement.
   ;
   if player0x > 141 then player0x = 141



   ;***************************************************************
   ;
   ;  Paddle collision. Influences direction of ball with paddle.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if there is no collision.
   ;
   if !collision(player0,ball) then goto __Skip_Paddle_Influence

   ;```````````````````````````````````````````````````````````````
   ;  Ball will move up now.
   ;
   _Bit1_Ball_Dir_Down{1} = 0 : _Bit0_Ball_Dir_Up{0} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips rest of section if player hasn't moved.
   ;
   if _Paddle_Direction = player0x then goto __Skip_Paddle_Influence

   ;```````````````````````````````````````````````````````````````
   ;  Sets ball direction to the left.
   ;
   _Bit2_Ball_Dir_Left{2} = 1 : _Bit3_Ball_Dir_Right{3} = 0 

   ;```````````````````````````````````````````````````````````````
   ;  Sets ball direction to the right if paddle has moved right.
   ;
   if player0x > _Paddle_Direction then _Bit2_Ball_Dir_Left{2} = 0 : _Bit3_Ball_Dir_Right{3} = 1

__Skip_Paddle_Influence



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart

 

 

 

Plain Sound Without Data

Plain Sound Without Data on bB page.

 
   dim _Ch0_Sound = c
   dim _Ch0_Duration = d
   dim _C0 = e
   dim _V0 = f
   dim _F0 = g





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Fire button check.
   ;
   ;  Turns on channel 0 sound effect 1 if fire button is pressed.
   ;
   if joy0fire then if !_Ch0_Sound then _Ch0_Sound = 1 : _Ch0_Duration = 15



   ;***************************************************************
   ;
   ;  Channel 0 sound effect check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 0 sounds if sounds are off.
   ;
   if !_Ch0_Sound then goto __Skip_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the channel 0 duration counter.
   ;
   _Ch0_Duration = _Ch0_Duration - 1

   ;```````````````````````````````````````````````````````````````
   ;  Turns off sound if channel 0 duration counter is zero.
   ;
   if !_Ch0_Duration then goto __Clear_Ch_0



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 001.
   ;
   ;  A simple/plain/lazy sound.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 001 isn't on.
   ;
   if _Ch0_Sound <> 1 then goto __Skip_Ch0_Sound_001

   ;```````````````````````````````````````````````````````````````
   ;  Sets the tone, volume and frequency.
   ;
   AUDC0 = 4 : AUDV0 = 8 : AUDF0 = 19

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_001



   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Other channel 0 sound effects go here.
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````



   ;***************************************************************
   ;
   ;  Jumps to end of channel 0 area. (Catches any mistakes.)
   ;
   goto __Skip_Ch_0



   ;***************************************************************
   ;
   ;  Clears channel 0.
   ;
__Clear_Ch_0
   
   _Ch0_Sound = 0 : AUDV0 = 0



   ;***************************************************************
   ;
   ;  End of channel 0 area.
   ;
__Skip_Ch_0



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   goto __Main_Loop

 

 

 

Multiple Sounds Without Data

Multiple Sounds Without Data on bB page.

 
   ;***************************************************************
   ;
   ;  Sound Example Without Data
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Move the joystick in 4 directions and press the fire button
   ;  to hear sounds.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Channel 0 sound variables.
   ;
   dim _Ch0_Sound = c
   dim _Ch0_Duration = d
   dim _C0 = e
   dim _V0 = f
   dim _F0 = g



   ;***************************************************************
   ;
   ;  Disables the score.
   ;
   const noscore = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Joystick check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips joystick section if a channel 0 sound effect is on.
   ;
   if _Ch0_Sound then goto __Skip_Joy0

   ;```````````````````````````````````````````````````````````````
   ;  Fire button check.
   ;  Turns on channel 0 sound effect 1 if fire button is pressed.
   ;
   if joy0fire then _Ch0_Sound = 1 : _Ch0_Duration = 15 :  COLUBK = $4A : goto __Skip_Joy0

   ;```````````````````````````````````````````````````````````````
   ;  Up check.
   ;  Turns on channel 0 sound effect 2 if joystick is moved up.
   ;
   if joy0up then _Ch0_Sound = 2 : _Ch0_Duration = 30 : _V0 = 12 : COLUBK = $9E : goto __Skip_Joy0

   ;```````````````````````````````````````````````````````````````
   ;  Down check.
   ;  Turns on channel 0 sound effect 3 if joystick is moved down.
   ;
   if joy0down then _Ch0_Sound = 3 : _Ch0_Duration = 32 : _F0 = 31 : COLUBK = $DE : goto __Skip_Joy0

   ;```````````````````````````````````````````````````````````````
   ;  Left check.
   ;  Turns on channel 0 sound effect 4 if joystick is moved left.
   ;
   if joy0left then _Ch0_Sound = 4 : _Ch0_Duration = 32 : _V0 = 12 : _F0 = 31 : COLUBK = $6E : goto __Skip_Joy0

   ;```````````````````````````````````````````````````````````````
   ;  Right check.
   ;  Turns on channel 0 sound effect 5 if joystick is moved right.
   ;
   if joy0right then _Ch0_Sound = 5 : _Ch0_Duration = 32 : _C0 = 4 : _V0 = 12 : _F0 = 31 : COLUBK = $1E

__Skip_Joy0



   ;***************************************************************
   ;
   ;  Channel 0 sound effect check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 0 sounds if sounds are off.
   ;
   if !_Ch0_Sound then goto __Skip_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the channel 0 duration counter.
   ;
   _Ch0_Duration = _Ch0_Duration - 1

   ;```````````````````````````````````````````````````````````````
   ;  Turns off sound if channel 0 duration counter is zero.
   ;
   if !_Ch0_Duration then goto __Clear_Ch_0

   

   ;***************************************************************
   ;
   ;  Channel 0 sound effect 001.
   ;
   ;  A simple/plain/lazy sound.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 001 isn't on.
   ;
   if _Ch0_Sound <> 1 then goto __Skip_Ch0_Sound_001

   ;```````````````````````````````````````````````````````````````
   ;  Sets the tone, volume and frequency.
   ;
   AUDC0 = 4 : AUDV0 = 8 : AUDF0 = 19

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_001



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 002.
   ;
   ;  A slightly less lazy sound since the volume changes.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 002 isn't on.
   ;
   if _Ch0_Sound <> 2 then goto __Skip_Ch0_Sound_002

   ;```````````````````````````````````````````````````````````````
   ;  Sets the tone, volume and frequency.
   ;
   AUDC0 = 4 : AUDV0 = _V0 : AUDF0 = 19

   ;```````````````````````````````````````````````````````````````
   ;  Only looks at the even/odd bit.
   ;
   temp5 = _Ch0_Duration & %00000001

   ;```````````````````````````````````````````````````````````````
   ;  Decreases volume only when _Ch0_Duration is an odd number.
   ;
   if temp5 && _V0 then _V0 = _V0 - 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_002



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 003.
   ;
   ;  Only the frequency changes.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 003 isn't on.
   ;
   if _Ch0_Sound <> 3 then goto __Skip_Ch0_Sound_003

   ;```````````````````````````````````````````````````````````````
   ;  Sets the tone, volume and frequency.
   ;
   AUDC0 = 4 : AUDV0 = 8 : AUDF0 = _F0

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the frequency variable.
   ;
   _F0 = _F0 - 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_003



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 004.
   ;
   ;  The volume and the frequency changes.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 004 isn't on.
   ;
   if _Ch0_Sound <> 4 then goto __Skip_Ch0_Sound_004

   ;```````````````````````````````````````````````````````````````
   ;  Sets the tone, volume and frequency.
   ;
   AUDC0 = 4 : AUDV0 = _V0 : AUDF0 = _F0

   ;```````````````````````````````````````````````````````````````
   ;  Only looks at the even/odd bit.
   ;
   temp5 = _Ch0_Duration & %00000001

   ;```````````````````````````````````````````````````````````````
   ;  Decreases volume only when _Ch0_Duration is an odd number.
   ;
   if temp5 && _V0 then _V0 = _V0 - 1

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the frequency variable.
   ;
   if _F0 then _F0 = _F0 - 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_004



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 005.
   ;
   ;  The tone, volume, and frequency changes.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 005 isn't on.
   ;
   if _Ch0_Sound <> 5 then goto __Skip_Ch0_Sound_005

   ;```````````````````````````````````````````````````````````````
   ;  Sets the tone, volume and frequency.
   ;
   AUDC0 = _C0 : AUDV0 = _V0 : AUDF0 = _F0

   ;```````````````````````````````````````````````````````````````
   ;  Flips the tone between 4 and 12.
   ;
   _C0 = _C0 ^ 8

   ;```````````````````````````````````````````````````````````````
   ;  Only looks at the even/odd bit.
   ;
   temp5 = _Ch0_Duration & %00000001

   ;```````````````````````````````````````````````````````````````
   ;  Decreases volume only when _Ch0_Duration is an odd number.
   ;
   if temp5 && _V0 then _V0 = _V0 - 1

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the frequency variable.
   ;
   if _F0 then _F0 = _F0 - 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_005



   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Other channel 0 sound effects go here.
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````



   ;***************************************************************
   ;
   ;  Jumps to end of channel 0 area. (This catches any mistakes.)
   ;
   goto __Skip_Ch_0



   ;***************************************************************
   ;
   ;  Clears channel 0.
   ;
__Clear_Ch_0

   _Ch0_Sound = 0 : AUDV0 = 0



   ;***************************************************************
   ;
   ;  End of channel 0 area.
   ;
__Skip_Ch_0



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   goto __Main_Loop

 

 

 

Sound Example Using Data

Sound Example Using Data on bB page.

 
   ;***************************************************************
   ;
   ;  Sound Example Using Data
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Move the joystick in 4 directions and press the fire button
   ;  to hear sounds.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Channel 0 sound variables.
   ;
   dim _Ch0_Sound = q
   dim _Ch0_Duration = r
   dim _Ch0_Counter = s

   ;```````````````````````````````````````````````````````````````
   ;  Channel 1 sound variables.
   ;
   dim _Ch1_Sound = t
   dim _Ch1_Duration = u
   dim _Ch1_Counter = v

   ;```````````````````````````````````````````````````````````````
   ;  Keeps the reset switch from repeating when pressed.
   ;
   dim _Bit0_Reset_Restrainer = y



   ;***************************************************************
   ;
   ;  Disables the score.
   ;
   const noscore = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables (fastest way).
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Joystick check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips joystick section if a channel 0 sound effect is on.
   ;
   if _Ch0_Sound then goto __Skip_Joy0

   ;```````````````````````````````````````````````````````````````
   ;  Up check.
   ;  Turns on channel 0 sound effect 1 if joystick is moved up.
   ;
   if joy0up then _Ch0_Sound = 1 : _Ch0_Duration = 1 : _Ch0_Counter = 0 : COLUBK = $9E : goto __Skip_Joy0

   ;```````````````````````````````````````````````````````````````
   ;  Down check.
   ;  Turns on channel 0 sound effect 2 if joystick is moved down.
   ;
   if joy0down then _Ch0_Sound = 2 : _Ch0_Duration = 1 : _Ch0_Counter = 0 : COLUBK = $DE : goto __Skip_Joy0

   ;```````````````````````````````````````````````````````````````
   ;  Left check.
   ;  Turns on channel 0 sound effect 3 if joystick is moved left.
   ;
   if joy0left then _Ch0_Sound = 3 : _Ch0_Duration = 1 : _Ch0_Counter = 0 : COLUBK = $6E : goto __Skip_Joy0

   ;```````````````````````````````````````````````````````````````
   ;  Right check.
   ;  Turns on channel 0 sound effect 4 if joystick is moved right.
   ;
   if joy0right then _Ch0_Sound = 4 : _Ch0_Duration = 1 : _Ch0_Counter = 0 : COLUBK = $1E

__Skip_Joy0



   ;***************************************************************
   ;
   ;  Fire button check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips fire button section if a channel 1 sound effect is on.
   ;
   if _Ch1_Sound then goto __Skip_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Fire button check.
   ;  Turns on channel 1 sound effect 1 if fire button is pressed.
   ;
   if joy0fire then _Ch1_Sound = 1 : _Ch1_Duration = 1 : _Ch1_Counter = 0 : COLUBK = $4A

__Skip_Fire



   ;***************************************************************
   ;
   ;  Channel 0 sound effect check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 0 sounds if sounds are off.
   ;
   if !_Ch0_Sound then goto __Skip_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the channel 0 duration counter.
   ;
   _Ch0_Duration = _Ch0_Duration - 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 0 sounds if duration counter is greater
   ;  than zero
   ;
   if _Ch0_Duration then goto __Skip_Ch_0



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 001.
   ;
   ;  Up sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 001 isn't on.
   ;
   if _Ch0_Sound <> 1 then goto __Skip_Ch0_Sound_001

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Up[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Up[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Up[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets Duration.
   ;
   _Ch0_Duration = _SD_Up[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_001



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 002.
   ;
   ;  Down sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 002 isn't on.
   ;
   if _Ch0_Sound <> 2 then goto __Skip_Ch0_Sound_002

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Down[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Down[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Down[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets duration.
   ;
   _Ch0_Duration = _SD_Down[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_002



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 003.
   ;
   ;  Left sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 003 isn't on.
   ;
   if _Ch0_Sound <> 3 then goto __Skip_Ch0_Sound_003

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Left[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Left[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Left[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets duration.
   ;
   _Ch0_Duration = _SD_Left[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_003



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 004.
   ;
   ;  Right sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 004 isn't on.
   ;
   if _Ch0_Sound <> 4 then goto __Skip_Ch0_Sound_004

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Right[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Right[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Right[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets duration.
   ;
   _Ch0_Duration = _SD_Right[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_004



   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Other channel 0 sound effects go here.
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````



   ;***************************************************************
   ;
   ;  Jumps to end of channel 0 area. (This catches any mistakes.)
   ;
   goto __Skip_Ch_0



   ;***************************************************************
   ;
   ;  Clears channel 0.
   ;
__Clear_Ch_0
   
   _Ch0_Sound = 0 : AUDV0 = 0



   ;***************************************************************
   ;
   ;  End of channel 0 area.
   ;
__Skip_Ch_0



   ;***************************************************************
   ;
   ;  Channel 1 sound effect check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 1 sounds if sounds are off.
   ;
   if !_Ch1_Sound then goto __Skip_Ch_1

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the channel 1 duration counter.
   ;
   _Ch1_Duration = _Ch1_Duration - 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 1 sounds if duration counter is greater
   ;  than zero.
   ;
   if _Ch1_Duration then goto __Skip_Ch_1



   ;***************************************************************
   ;
   ;  Channel 1 sound effect 001.
   ;
   ;  Fire button sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 001 isn't on.
   ;
   if _Ch1_Sound <> 1 then goto __Skip_Chan1_Sound_001

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 1 data.
   ;
   temp4 = _SD_FireB[_Ch1_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_1

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 1 data.
   ;
   _Ch1_Counter = _Ch1_Counter + 1
   temp5 = _SD_FireB[_Ch1_Counter] : _Ch1_Counter = _Ch1_Counter + 1
   temp6 = _SD_FireB[_Ch1_Counter] : _Ch1_Counter = _Ch1_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 1.
   ;
   AUDV1 = temp4
   AUDC1 = temp5
   AUDF1 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets duration.
   ;
   _Ch1_Duration = _SD_FireB[_Ch1_Counter] : _Ch1_Counter = _Ch1_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 1 area.
   ;
   goto __Skip_Ch_1

__Skip_Chan1_Sound_001



   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Other channel 1 sound effects go here.
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````



   ;***************************************************************
   ;
   ;  Jumps to end of channel 1 area. (This catches any mistakes.)
   ;
   goto __Skip_Ch_1



   ;***************************************************************
   ;
   ;  Clears channel 1.
   ;
__Clear_Ch_1
   
   _Ch1_Sound = 0 : AUDV1 = 0



   ;***************************************************************
   ;
   ;  End of channel 1 area.
   ;
__Skip_Ch_1



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````




   
   ;***************************************************************
   ;***************************************************************
   ;
   ;
   ;  Sound effect data starts here.
   ;
   ;
   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for up sound effect.
   ;
   data _SD_Up
   9,12,23
   1
   8,12,23
   2
   6,12,23
   2
   5,12,23
   2
   4,12,23
   1
   2,12,23
   8

   9,12,20
   1
   8,12,20
   2
   6,12,20
   2
   5,12,20
   2
   4,12,20
   2
   2,12,20
   8

   9,12,17
   1
   8,12,17
   1
   6,12,17
   6
   5,12,17
   6
   4,12,17
   1
   2,12,17
   8

   9,12,20
   1
   8,12,20
   1
   6,12,20
   1
   5,12,20
   1
   4,12,20
   1
   2,12,20
   8

   9,12,23
   1
   8,12,23
   1
   6,12,23
   1
   5,12,23
   1
   4,12,23
   1
   2,12,23
   8

   9,12,20
   1
   8,12,20
   1
   6,12,20
   1
   5,12,20
   1
   4,12,20
   1
   2,12,20
   8

   9,12,26
   1
   8,12,26
   1
   6,12,26
   1
   5,12,26
   1
   4,12,26
   1
   2,12,26
   8
   255
end



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for down sound effect.
   ;
   data _SD_Down
   8,4,25
   1
   8,4,24
   1
   8,4,27
   1
   8,4,23
   1
   8,4,26
   1
   8,4,28
   1
   8,4,25
   1
   8,4,23
   1
   8,4,28
   1
   8,4,24
   1
   8,4,28
   1
   8,4,25
   1
   8,4,26
   1
   8,4,25
   1
   8,4,23
   1
   8,4,27
   1
   8,4,24
   1
   8,4,26
   1
   8,4,28
   1
   8,4,27
   1
   8,4,25
   1
   255
end



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for left sound effect.
   ;
   data _SD_Left
   5,8,2
   1
   4,8,2
   1
   3,8,2
   1
   2,8,2
   1
   1,8,2
   1
   0,8,2
   1

   5,8,2
   1
   4,8,2
   1
   3,8,2
   1
   2,8,2
   1
   1,8,2
   1
   0,8,2
   18


   5,8,2
   1
   4,8,2
   1
   3,8,2
   1
   2,8,2
   1
   1,8,2
   1
   0,8,2
   1

   5,8,2
   1
   4,8,2
   1
   3,8,2
   1
   2,8,2
   1
   1,8,2
   1
   0,8,2
   18


   5,8,2
   1
   4,8,2
   1
   3,8,2
   1
   2,8,2
   1
   1,8,2
   1
   0,8,2
   2

   5,8,2
   1
   4,8,2
   1
   3,8,2
   1
   2,8,2
   1
   1,8,2
   1
   0,8,2
   2

   5,8,2
   1
   4,8,2
   1
   3,8,2
   1
   2,8,2
   1
   1,8,2
   1
   0,8,2
   2

   5,8,2
   1
   4,8,2
   1
   3,8,2
   1
   2,8,2
   1
   1,8,2
   1
   0,8,2
   18

   255
end



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for right sound effect.
   ;
   data _SD_Right
   15,8,2
   1
   8,8,2
   1
   4,8,2
   1
   0,8,2
   4

   15,8,2
   1
   8,8,2
   1
   4,8,2
   1
   0,8,2
   4

   15,8,2
   1
   8,8,2
   1
   4,8,2
   1
   0,8,2
   11

   15,8,2
   1
   8,8,2
   1
   4,8,2
   1
   0,8,2
   4
   0,0,0
   8
   255
end



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for fire button sound effect.
   ;
   data _SD_FireB
   2,12,17
   1
   4,12,17
   1
   8,12,17
   7
   4,12,17
   1
   2,12,17
   8


   2,12,26
   1
   4,12,26
   1
   8,12,26
   12
   4,12,26
   1
   2,12,26
   8

   2,12,17
   1
   4,12,17
   1
   8,12,17
   7
   4,12,17
   1
   2,12,17
   8

   2,12,29
   1
   4,12,29
   1
   8,12,29
   12
   4,12,29
   1
   2,12,29
   8


   2,12,29
   1
   4,12,29
   1
   8,12,29
   3
   4,12,29
   1
   2,12,29
   8


   2,12,23
   1
   4,12,23
   1
   8,12,23
   3
   4,12,23
   1
   2,12,23
   8

   2,12,26
   1
   4,12,26
   1
   8,12,26
   3
   4,12,26
   1
   2,12,26
   8


   2,12,19
   1
   4,12,19
   1
   8,12,19
   12
   4,12,19
   1
   2,12,19
   8

   2,12,17
   1
   4,12,17
   1
   8,12,17
   7
   4,12,17
   1
   2,12,17
   8

   2,12,26
   1
   4,12,26
   1
   8,12,26
   12
   4,12,26
   1
   2,12,26
   8

   2,12,19
   1
   4,12,19
   1
   8,12,19
   7
   4,12,19
   1
   2,12,19
   8

   2,12,29
   1
   4,12,29
   1
   8,12,29
   12
   4,12,29
   1
   2,12,29
   8
   255
end

 

 

 

Sound Example Using Data and Bankswitching

Sound Example Using Data and Bankswitching on bB page.

 
   ;***************************************************************
   ;
   ;  Sound Example Using Data and Bankswitching
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Move the joystick in 4 directions and press the fire button
   ;  to hear sounds.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;***************************************************************
   ;
   ;  This example has 4 banks (16k/4k = 4 banks).
   ;
   set romsize 16k



   ;***************************************************************
   ;
   ;  Random numbers can slow down bank-switched games. This will
   ;  speed things up.
   ;
   set optimization inlinerand



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Channel 0 sound variables.
   ;
   dim _Ch0_Sound = q
   dim _Ch0_Duration = r
   dim _Ch0_Counter = s

   ;```````````````````````````````````````````````````````````````
   ;  Channel 1 sound variables.
   ;
   dim _Ch1_Sound = t
   dim _Ch1_Duration = u
   dim _Ch1_Counter = v

   ;```````````````````````````````````````````````````````````````
   ;  Keeps the reset switch from repeating when pressed.
   ;
   dim _Bit0_Reset_Restrainer = y



   ;***************************************************************
   ;
   ;  Disables the score.
   ;
   const noscore = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables (fastest way).
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1



   goto __Main_Loop bank2





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   bank 2
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Joystick check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips joystick section if a channel 0 sound effect is on.
   ;
   if _Ch0_Sound then goto __Skip_Joy0

   ;```````````````````````````````````````````````````````````````
   ;  Up check.
   ;  Turns on channel 0 sound effect 1 if joystick is moved up.
   ;
   if joy0up then _Ch0_Sound = 1 : _Ch0_Duration = 1 : _Ch0_Counter = 0 : COLUBK = $9E : goto __Skip_Joy0

   ;```````````````````````````````````````````````````````````````
   ;  Down check.
   ;  Turns on channel 0 sound effect 2 if joystick is moved down.
   ;
   if joy0down then _Ch0_Sound = 2 : _Ch0_Duration = 1 : _Ch0_Counter = 0 : COLUBK = $DE : goto __Skip_Joy0

   ;```````````````````````````````````````````````````````````````
   ;  Left check.
   ;  Turns on channel 0 sound effect 3 if joystick is moved left.
   ;
   if joy0left then _Ch0_Sound = 3 : _Ch0_Duration = 1 : _Ch0_Counter = 0 : COLUBK = $6E : goto __Skip_Joy0

   ;```````````````````````````````````````````````````````````````
   ;  Right check.
   ;  Turns on channel 0 sound effect 4 if joystick is moved right.
   ;
   if joy0right then _Ch0_Sound = 4 : _Ch0_Duration = 1 : _Ch0_Counter = 0 : COLUBK = $1E

__Skip_Joy0



   ;***************************************************************
   ;
   ;  Fire button check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips fire button section if a channel 1 sound effect is on.
   ;
   if _Ch1_Sound then goto __Skip_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Fire button check.
   ;  Turns on channel 1 sound effect 1 if fire button is pressed.
   ;
   if joy0fire then _Ch1_Sound = 1 : _Ch1_Duration = 1 : _Ch1_Counter = 0 : COLUBK = $4A

__Skip_Fire



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Goes to bank 3 to see if any sounds should be playing.  
   ;
   goto __Check_Sound bank3



   ;***************************************************************
   ;
   ;  Returns from bank 3.  
   ;
__Done_Check_Sound



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart bank1





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   bank 3
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Area of the program that checks if sounds should be playing.
   ;
__Check_Sound



   ;***************************************************************
   ;
   ;  Channel 0 sound effect check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 0 sounds if sounds are off.
   ;
   if !_Ch0_Sound then goto __Skip_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the channel 0 duration counter.
   ;
   _Ch0_Duration = _Ch0_Duration - 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 0 sounds if duration counter is greater
   ;  than zero
   ;
   if _Ch0_Duration then goto __Skip_Ch_0



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 001.
   ;
   ;  Up sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 001 isn't on.
   ;
   if _Ch0_Sound <> 1 then goto __Skip_Ch0_Sound_001

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Up[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Up[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Up[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets Duration.
   ;
   _Ch0_Duration = _SD_Up[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_001



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 002.
   ;
   ;  Down sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 002 isn't on.
   ;
   if _Ch0_Sound <> 2 then goto __Skip_Ch0_Sound_002

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Down[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Down[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Down[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets duration.
   ;
   _Ch0_Duration = _SD_Down[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_002



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 003.
   ;
   ;  Left sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 003 isn't on.
   ;
   if _Ch0_Sound <> 3 then goto __Skip_Ch0_Sound_003

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Left[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Left[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Left[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets duration.
   ;
   _Ch0_Duration = _SD_Left[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_003



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 004.
   ;
   ;  Right sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 004 isn't on.
   ;
   if _Ch0_Sound <> 4 then goto __Skip_Ch0_Sound_004

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Right[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Right[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Right[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets duration.
   ;
   _Ch0_Duration = _SD_Right[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_004



   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Other channel 0 sound effects go here.
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````



   ;***************************************************************
   ;
   ;  Jumps to end of channel 0 area. (This catches any mistakes.)
   ;
   goto __Skip_Ch_0



   ;***************************************************************
   ;
   ;  Clears channel 0.
   ;
__Clear_Ch_0
   
   _Ch0_Sound = 0 : AUDV0 = 0



   ;***************************************************************
   ;
   ;  End of channel 0 area.
   ;
__Skip_Ch_0



   ;***************************************************************
   ;
   ;  Channel 1 sound effect check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 1 sounds if sounds are off.
   ;
   if !_Ch1_Sound then goto __Skip_Ch_1

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the channel 1 duration counter.
   ;
   _Ch1_Duration = _Ch1_Duration - 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 1 sounds if duration counter is greater
   ;  than zero.
   ;
   if _Ch1_Duration then goto __Skip_Ch_1



   ;***************************************************************
   ;
   ;  Channel 1 sound effect 001.
   ;
   ;  Fire button sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 001 isn't on.
   ;
   if _Ch1_Sound <> 1 then goto __Skip_Chan1_Sound_001

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 1 data.
   ;
   temp4 = _SD_FireB[_Ch1_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_1

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 1 data.
   ;
   _Ch1_Counter = _Ch1_Counter + 1
   temp5 = _SD_FireB[_Ch1_Counter] : _Ch1_Counter = _Ch1_Counter + 1
   temp6 = _SD_FireB[_Ch1_Counter] : _Ch1_Counter = _Ch1_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 1.
   ;
   AUDV1 = temp4
   AUDC1 = temp5
   AUDF1 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets duration.
   ;
   _Ch1_Duration = _SD_FireB[_Ch1_Counter] : _Ch1_Counter = _Ch1_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 1 area.
   ;
   goto __Skip_Ch_1

__Skip_Chan1_Sound_001



   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Other channel 1 sound effects go here.
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````



   ;***************************************************************
   ;
   ;  Jumps to end of channel 1 area. (This catches any mistakes.)
   ;
   goto __Skip_Ch_1



   ;***************************************************************
   ;
   ;  Clears channel 1.
   ;
__Clear_Ch_1
   
   _Ch1_Sound = 0 : AUDV1 = 0



   ;***************************************************************
   ;
   ;  End of channel 1 area.
   ;
__Skip_Ch_1



   ;***************************************************************
   ;
   ;  Returns to bank 2.
   ;
   goto __Done_Check_Sound bank2





   ;***************************************************************
   ;***************************************************************
   ;
   ;
   ;  Sound effect data starts here.
   ;
   ;
   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for up sound effect.
   ;
   data _SD_Up
   9,12,23
   1
   8,12,23
   2
   6,12,23
   2
   5,12,23
   2
   4,12,23
   1
   2,12,23
   8

   9,12,20
   1
   8,12,20
   2
   6,12,20
   2
   5,12,20
   2
   4,12,20
   2
   2,12,20
   8

   9,12,17
   1
   8,12,17
   1
   6,12,17
   6
   5,12,17
   6
   4,12,17
   1
   2,12,17
   8

   9,12,20
   1
   8,12,20
   1
   6,12,20
   1
   5,12,20
   1
   4,12,20
   1
   2,12,20
   8

   9,12,23
   1
   8,12,23
   1
   6,12,23
   1
   5,12,23
   1
   4,12,23
   1
   2,12,23
   8

   9,12,20
   1
   8,12,20
   1
   6,12,20
   1
   5,12,20
   1
   4,12,20
   1
   2,12,20
   8

   9,12,26
   1
   8,12,26
   1
   6,12,26
   1
   5,12,26
   1
   4,12,26
   1
   2,12,26
   8
   255
end



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for down sound effect.
   ;
   data _SD_Down
   8,4,25
   1
   8,4,24
   1
   8,4,27
   1
   8,4,23
   1
   8,4,26
   1
   8,4,28
   1
   8,4,25
   1
   8,4,23
   1
   8,4,28
   1
   8,4,24
   1
   8,4,28
   1
   8,4,25
   1
   8,4,26
   1
   8,4,25
   1
   8,4,23
   1
   8,4,27
   1
   8,4,24
   1
   8,4,26
   1
   8,4,28
   1
   8,4,27
   1
   8,4,25
   1
   255
end



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for left sound effect.
   ;
   data _SD_Left
   5,8,2
   1
   4,8,2
   1
   3,8,2
   1
   2,8,2
   1
   1,8,2
   1
   0,8,2
   1

   5,8,2
   1
   4,8,2
   1
   3,8,2
   1
   2,8,2
   1
   1,8,2
   1
   0,8,2
   18


   5,8,2
   1
   4,8,2
   1
   3,8,2
   1
   2,8,2
   1
   1,8,2
   1
   0,8,2
   1

   5,8,2
   1
   4,8,2
   1
   3,8,2
   1
   2,8,2
   1
   1,8,2
   1
   0,8,2
   18


   5,8,2
   1
   4,8,2
   1
   3,8,2
   1
   2,8,2
   1
   1,8,2
   1
   0,8,2
   2

   5,8,2
   1
   4,8,2
   1
   3,8,2
   1
   2,8,2
   1
   1,8,2
   1
   0,8,2
   2

   5,8,2
   1
   4,8,2
   1
   3,8,2
   1
   2,8,2
   1
   1,8,2
   1
   0,8,2
   2

   5,8,2
   1
   4,8,2
   1
   3,8,2
   1
   2,8,2
   1
   1,8,2
   1
   0,8,2
   18

   255
end



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for right sound effect.
   ;
   data _SD_Right
   15,8,2
   1
   8,8,2
   1
   4,8,2
   1
   0,8,2
   4

   15,8,2
   1
   8,8,2
   1
   4,8,2
   1
   0,8,2
   4

   15,8,2
   1
   8,8,2
   1
   4,8,2
   1
   0,8,2
   11

   15,8,2
   1
   8,8,2
   1
   4,8,2
   1
   0,8,2
   4
   0,0,0
   8
   255
end



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for fire button sound effect.
   ;
   data _SD_FireB
   2,12,17
   1
   4,12,17
   1
   8,12,17
   7
   4,12,17
   1
   2,12,17
   8


   2,12,26
   1
   4,12,26
   1
   8,12,26
   12
   4,12,26
   1
   2,12,26
   8

   2,12,17
   1
   4,12,17
   1
   8,12,17
   7
   4,12,17
   1
   2,12,17
   8

   2,12,29
   1
   4,12,29
   1
   8,12,29
   12
   4,12,29
   1
   2,12,29
   8


   2,12,29
   1
   4,12,29
   1
   8,12,29
   3
   4,12,29
   1
   2,12,29
   8


   2,12,23
   1
   4,12,23
   1
   8,12,23
   3
   4,12,23
   1
   2,12,23
   8

   2,12,26
   1
   4,12,26
   1
   8,12,26
   3
   4,12,26
   1
   2,12,26
   8


   2,12,19
   1
   4,12,19
   1
   8,12,19
   12
   4,12,19
   1
   2,12,19
   8

   2,12,17
   1
   4,12,17
   1
   8,12,17
   7
   4,12,17
   1
   2,12,17
   8

   2,12,26
   1
   4,12,26
   1
   8,12,26
   12
   4,12,26
   1
   2,12,26
   8

   2,12,19
   1
   4,12,19
   1
   8,12,19
   7
   4,12,19
   1
   2,12,19
   8

   2,12,29
   1
   4,12,29
   1
   8,12,29
   12
   4,12,29
   1
   2,12,29
   8
   255
end





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   bank 4
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````

 

 

 

Sound Example Using Data (One Sound Only)

Sound Example Using Data (One Sound Only) on bB page.

 
   ;***************************************************************
   ;
   ;  Sound Example Using Data (One Sound)
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Press the fire button to hear a sound.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Channel 0 sound variables.
   ;
   dim _Ch0_Sound = q
   dim _Ch0_Duration = r
   dim _Ch0_Counter = s

   ;```````````````````````````````````````````````````````````````
   ;  Keeps the reset switch from repeating when pressed.
   ;
   dim _Bit0_Reset_Restrainer = y



   ;***************************************************************
   ;
   ;  Disables the score.
   ;
   const noscore = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables (fastest way).
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop


   ;***************************************************************
   ;
   ;  Fire button check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if a channel 0 sound effect is on.
   ;
   if _Ch0_Sound then goto __Skip_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Turns on channel 0 sound effect 1 if fire button is pressed.
   ;
   if joy0fire then _Ch0_Sound = 1 : _Ch0_Duration = 1 : _Ch0_Counter = 0

__Skip_Fire



   ;***************************************************************
   ;
   ;  Channel 0 sound effect check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 0 sounds if sounds are off.
   ;
   if !_Ch0_Sound then goto __Skip_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Decreases channel 0 duration counter.
   ;
   _Ch0_Duration = _Ch0_Duration - 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 0 sounds if duration counter is greater
   ;  than zero.
   ;
   if _Ch0_Duration then goto __Skip_Ch_0



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 001.
   ;
   ;  Fire button.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 001 isn't on.
   ;
   if _Ch0_Sound <> 1 then goto __Skip_Ch0_Sound_001

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_FireB[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_FireB[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_FireB[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets duration.
   ;
   _Ch0_Duration = _SD_FireB[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_001



   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Other channel 0 sound effects go here.
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````



   ;***************************************************************
   ;
   ;  Jumps to end of channel 0 area. (This catches any mistakes.)
   ;
   goto __Skip_Ch_0



   ;***************************************************************
   ;
   ;  Clears channel 0.
   ;
__Clear_Ch_0
   
   _Ch0_Sound = 0 : AUDV0 = 0



   ;***************************************************************
   ;
   ;  End of channel 0 area.
   ;
__Skip_Ch_0



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;
   ;  Sound effect data starts here.
   ;
   ;
   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for fire button sound effect.
   ;
   data _SD_FireB
   15,8,2
   1
   8,8,2
   1
   4,8,2
   1
   0,8,2
   4

   15,8,2
   1
   8,8,2
   1
   4,8,2
   1
   0,8,2
   4

   15,8,2
   1
   8,8,2
   1
   4,8,2
   1
   0,8,2
   11

   15,8,2
   1
   8,8,2
   1
   4,8,2
   1
   0,8,2
   4
   0,0,0
   8
   255
end

 

 

 

Sound Example With Background “Music”

Sound Example With Background “Music” on bB page.

 
   ;***************************************************************
   ;
   ;  Sound Example With Background "Music"
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Use the joystick to move the sprite. Press the fire button
   ;  to shoot the missile. There is a sound effect on channel 0
   ;  for shooting a missile, hitting a wall with a missile,
   ;  hitting the enemy with a missile, and when the player and
   ;  enemy touch. Channel 1 is used for the background "music."
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  This program has 2 banks (8k/4k = 2 banks).
   ;
   set romsize 8k



   ;***************************************************************
   ;
   ;  Random numbers can slow down bankswitched games. This will
   ;  speed things up.
   ;
   set optimization inlinerand



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Player0/missile0 direction bits.
   ;
   dim _BitOp_P0_M0_Dir = g
   dim _Bit0_P0_Dir_Up = g
   dim _Bit1_P0_Dir_Down = g
   dim _Bit2_P0_Dir_Left = g
   dim _Bit3_P0_Dir_Right = g
   dim _Bit4_Missile0_Dir_Up = g
   dim _Bit5_Missile0_Dir_Down = g
   dim _Bit6_Missile0_Dir_Left = g
   dim _Bit7_Missile0_Dir_Right = g

   ;```````````````````````````````````````````````````````````````
   ;  Enemy direction bits.
   ;
   dim _BitOp_P1_Dir = h
   dim _Bit0_P1_Dir_Up = h
   dim _Bit1_P1_Dir_Down = h
   dim _Bit2_P1_Dir_Left = h
   dim _Bit3_P1_Dir_Right = h

   ;```````````````````````````````````````````````````````````````
   ;  Helps the program know when it's time for the enemy to
   ;  change direction.
   ;
   dim _Enemy_Counter = i

   ;```````````````````````````````````````````````````````````````
   ;  Enemy direction.
   ;  0 = up, 1 = up/right, 2 = right, 3 = down/right, 4 = down,
   ;  5 = down/left, 6 = left, 7 = up/left.
   ;
   dim _Enemy_Dir = j

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the opposite direction the enemy moved. Keeps the
   ;  enemy sprite from bouncing back and forth between the same
   ;  two directions like a ping-pong ball.
   ;
   dim _Mem_E_Dir = k

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the last position of the enemy. A new direction is
   ;  chosen if the enemy stops moving.
   ;
   dim _Mem_P1x = l
   dim _Mem_P1y = m

   ;```````````````````````````````````````````````````````````````
   ;  Channel 0 sound variables.
   ;
   dim _Ch0_Sound = q
   dim _Ch0_Duration = r
   dim _Ch0_Counter = s

   ;```````````````````````````````````````````````````````````````
   ;  Channel 1 sound variables.
   ;
   dim _Ch1_Duration = t
  
   ;```````````````````````````````````````````````````````````````
   ;  u and v used for channel 1 sdata.
   ;
   ;```````````````````````````````````````````````````````````````

   ;```````````````````````````````````````````````````````````````
   ;  Bits that do various jobs.
   ;
   dim _Bit0_Reset_Restrainer = y
   dim _Bit7_Missile0_Moving = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers.
   ;
   dim rand16 = z



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for an 8 x 8 sprite.
   ;  If your sprite is a different size, you'll need to adjust
   ;  the numbers.
   ;
   const _c_Edge_Left = 1
   const _c_Edge_Right = 152
   const _c_Edge_Top = 9
   const _c_Edge_Bottom = 88



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for the missile.
   ;  If the missile is a different size, you'll need to adjust
   ;  the numbers.
   ;
   const _c_Missile_Edge_Top = 2
   const _c_Missile_Edge_Bottom = 88
   const _c_Missile_Edge_Left = 2
   const _c_Missile_Edge_Right = 159



   ;***************************************************************
   ;
   ;  Disables the score. (We don't need it in this program.)
   ;
   const noscore = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables except for z (used for rand).
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0


   ;***************************************************************
   ;
   ;  Sets starting position of player1 enemy.
   ;
   player1x = 140 : player1y = 78


   ;***************************************************************
   ;
   ;  Sets starting position of player0.
   ;
   player0x = 77 : player0y = 53


   ;***************************************************************
   ;
   ;  Makes sure missile0 is off the screen.
   ;
   missile0x = 200 : missile0y = 200


   ;***************************************************************
   ;
   ;  Defines missile0 height.
   ;
   missile0height = 1


   ;***************************************************************
   ;
   ;  Sets playfield color.
   ;
   COLUPF = $FC


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Sets beginning direction that missile0 will shoot if the
   ;  player doesn't move.
   ;
   _Bit3_P0_Dir_Right{3} = 1


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Defines shape of player0 sprite.
   ;
   player0:
   %00111100
   %01111110
   %11000011
   %10111101
   %11111111
   %11011011
   %01111110
   %00111100
end


   ;***************************************************************
   ;
   ;  Defines shape of player1 sprite.
   ;
   player1:
   %00111100
   %01111110
   %11000011
   %11111111
   %11111111
   %11011011
   %01111110
   %00111100
end


   ;***************************************************************
   ;
   ;  Sets up the playfield.
   ;
   playfield:
   ................................
   ................................
   ....XXXXXXXXXX....XXXXXXXXXX....
   ....X......................X....
   ....X......................X....
   ....X......................X....
   ................................
   ................................
   ....XXXX....XXX..XXX....XXXX....
   ................................
   ................................
end


   ;***************************************************************
   ;
   ;  Starts the background "music."
   ;
   goto __BG_Music_Setup_01 bank2





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets color of player0 sprite and missile.
   ;
   COLUP0 = $9C



   ;***************************************************************
   ;
   ;  Sets color of player1 sprite.
   ;
   COLUP1 = $44



   ;***************************************************************
   ;
   ;  Defines missile0 width.
   ;
   NUSIZ0 = $10



   ;***************************************************************
   ;
   ;  Joystick movement precheck.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if joystick hasn't been moved.
   ;
   if !joy0up && !joy0down && !joy0left && !joy0right then goto __Skip_Joystick_Precheck

   ;```````````````````````````````````````````````````````````````
   ;  Clears player0 direction bits since joystick has been moved.
   ;
   _BitOp_P0_M0_Dir = _BitOp_P0_M0_Dir & %11110000

__Skip_Joystick_Precheck



   ;***************************************************************
   ;
   ;  Joy0 up check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved up.
   ;
   if !joy0up then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the up direction bit.
   ;
   _Bit0_P0_Dir_Up{0} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0y <= _c_Edge_Top then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Skips pfread if player0 is outside of PF pixel area.
   ;
   if player0x < 17 || player0x > 137 then goto __Move_P0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 up if a pfpixel is not in the way.
   ;
   temp5 = (player0x-10)/4

   temp4 = (player0x-17)/4

   temp3 = temp5 - 1

   temp6 = (player0y-9)/8

   if !pfread(temp5,temp6) then if !pfread(temp4,temp6) then if !pfread(temp3,temp6) then goto __Move_P0_Up

   goto __Skip_Joy0_Up

__Move_P0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 up.
   ;
   player0y = player0y - 1

__Skip_Joy0_Up



   ;***************************************************************
   ;
   ;  Joy0 down check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved down.
   ;
   if !joy0down then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the down direction bit.
   ;
   _Bit1_P0_Dir_Down{1} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0y >= _c_Edge_Bottom then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Skips pfread if player0 is outside of PF pixel area.
   ;
   if player0x < 17 || player0x > 137 then goto __Move_P0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 down if a pfpixel is not in the way.
   ;
   temp5 = (player0x-10)/4

   temp4 = (player0x-17)/4

   temp3 = temp5 - 1

   temp6 = (player0y)/8

   if !pfread(temp5,temp6) then if !pfread(temp4,temp6) then if !pfread(temp3,temp6) then goto __Move_P0_Down

   goto __Skip_Joy0_Down

__Move_P0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 down.
   ;
   player0y = player0y + 1

__Skip_Joy0_Down



   ;***************************************************************
   ;
   ;  Joy0 left check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved to the left.
   ;
   if !joy0left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the left direction bit.
   ;
   _Bit2_P0_Dir_Left{2} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0x <= _c_Edge_Left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Skips pfread if player0 is outside of PF pixel area.
   ;
   if player0x < 17 || player0x > 137 then goto __Move_P0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 left if a pfpixel is not in the way.
   ;
   temp5 = (player0y-1)/8

   temp3 = (player0y-8)/8

   temp6 = (player0x-18)/4

   if !pfread(temp6,temp5) then if !pfread(temp6,temp3) then goto __Move_P0_Left

   goto __Skip_Joy0_Left

__Move_P0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 left.
   ;
   player0x = player0x - 1

__Skip_Joy0_Left



   ;***************************************************************
   ;
   ;  Joy0 right check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved to the right.
   ;
   if !joy0right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the right direction bit.
   ;
   _Bit3_P0_Dir_Right{3} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0x >= _c_Edge_Right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Skips pfread if player0 is outside of PF pixel area.
   ;
   if player0x < 17 || player0x > 137 then goto __Move_P0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 right if a pfpixel is not in the way.
   ;
   temp5 = (player0y-1)/8

   temp3 = (player0y-8)/8

   temp6 = (player0x-9)/4

   if !pfread(temp6,temp5) then if !pfread(temp6,temp3) then goto __Move_P0_Right

   goto __Skip_Joy0_Right

__Move_P0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 right.
   ;
   player0x = player0x + 1

__Skip_Joy0_Right




   ;***************************************************************
   ;
   ;  Fire button check.
   ;  
   ;  If fire button is pressed appropriately and missile1
   ;  is not moving, turns on missile1 movement.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the fire button is not pressed.
   ;
   if !joy0fire then goto __Skip_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if missile0 is moving.

   ;
   if _Bit7_Missile0_Moving{7} then goto __Skip_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Turns on missile0 movement.
   ;
   _Bit7_Missile0_Moving{7} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Takes a 'snapshot' of player0 direction so missile0 will
   ;  stay on track until it hits something.
   ;
   _Bit4_Missile0_Dir_Up{4} = _Bit0_P0_Dir_Up{0}
   _Bit5_Missile0_Dir_Down{5} = _Bit1_P0_Dir_Down{1}
   _Bit6_Missile0_Dir_Left{6} = _Bit2_P0_Dir_Left{2}
   _Bit7_Missile0_Dir_Right{7} = _Bit3_P0_Dir_Right{3}

   ;```````````````````````````````````````````````````````````````
   ;  Sets up starting position of missile0.
   ;
   if _Bit4_Missile0_Dir_Up{4} then missile0x = player0x + 4 : missile0y = player0y - 5
   if _Bit5_Missile0_Dir_Down{5} then missile0x = player0x + 4 : missile0y = player0y - 1
   if _Bit6_Missile0_Dir_Left{6} then missile0x = player0x + 2 : missile0y = player0y - 3
   if _Bit7_Missile0_Dir_Right{7} then missile0x = player0x + 6 : missile0y = player0y - 3

   ;```````````````````````````````````````````````````````````````
   ;  Turns on sound effect.
   ;
   if _Ch0_Sound <> 3 then _Ch0_Sound = 2 : _Ch0_Duration = 1 : _Ch0_Counter = 0

__Skip_Fire



   ;***************************************************************
   ;
   ;  Missile0 movement check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if missile0 isn't moving.
   ;
   if !_Bit7_Missile0_Moving{7} then goto __Skip_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Moves missile0 in the appropriate direction.
   ;
   if _Bit4_Missile0_Dir_Up{4} then missile0y = missile0y - 2
   if _Bit5_Missile0_Dir_Down{5} then missile0y = missile0y + 2
   if _Bit6_Missile0_Dir_Left{6} then missile0x = missile0x - 2
   if _Bit7_Missile0_Dir_Right{7} then missile0x = missile0x + 2

   ;```````````````````````````````````````````````````````````````
   ;  Clears missile0 if it hits the edge of the screen.
   ;
   if missile0y < _c_Missile_Edge_Top then goto __Delete_Missile
   if missile0y > _c_Missile_Edge_Bottom then goto __Delete_Missile
   if missile0x < _c_Missile_Edge_Left then goto __Delete_Missile
   if missile0x > _c_Missile_Edge_Right then goto __Delete_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Skips rest of section if no collision.
   ;
   if !collision(playfield,missile0) then goto __Skip_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Turns on sound effect.
   ;
   if _Ch0_Sound <> 3 then _Ch0_Sound = 1 : _Ch0_Duration = 1 : _Ch0_Counter = 0

__Delete_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Clears missile0 bit and moves missile0 off the screen.
   ;
   _Bit7_Missile0_Moving{7} = 0 : missile0x = 200 : missile0y = 200
   
__Skip_Missile



   ;***************************************************************
   ;
   ;  Enemy/missile collision check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if there is no collision.
   ;
   if !collision(player1,missile0) then goto __Skip_Shot_Enemy

   ;```````````````````````````````````````````````````````````````
   ;  Turns on sound effect.
   ;
   _Ch0_Sound = 3 : _Ch0_Duration = 1 : _Ch0_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Clears missile0 bit and moves missile0 off the screen.
   ;
   _Bit7_Missile0_Moving{7} = 0 : missile0x = 200 : missile0y = 200

   ;```````````````````````````````````````````````````````````````
   ;  Places enemy in new location based on location of player.
   ;
   if player0y >= 52 then player1y = (rand&7) + 10 : goto __Skip_Y_Placement

   player1y = (rand&7) + 78

__Skip_Y_Placement

   if player0x >= 77 then player1x = (rand&7) + 5 : goto __Skip_Shot_Enemy


   player1x = (rand&7) + 140

__Skip_Shot_Enemy



   ;***************************************************************
   ;
   ;  Enemy/player collision check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if there is no collision.
   ;
   if !collision(player1,player0) then goto __Skip_P0_Touched_Enemy

   ;```````````````````````````````````````````````````````````````
   ;  Turns on sound effect.
   ;
   if _Ch0_Sound <> 4 then _Ch0_Sound = 4 : _Ch0_Duration = 1 : _Ch0_Counter = 0

__Skip_P0_Touched_Enemy



   ;***************************************************************
   ;
   ;  Enemy direction change.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Adds to the enemy counter.
   ;
   _Enemy_Counter = _Enemy_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Forces a direction change when the counter gets too high or
   ;  when it's set high on purpose because the enemy was inactive.
   ;
   if _Enemy_Counter > 254 then goto __Get_New_E_Direction

   ;```````````````````````````````````````````````````````````````
   ;  Grabs a random number (0 to 63) and adds 50. Change 50 to a
   ;  larger number if you want the enemy to move longer before
   ;  changing directions. Don't use a number larger than 190.
   ;
   temp6 = (rand&63) + 50

   ;```````````````````````````````````````````````````````````````
   ;  Skips section if the counter isn't high enough.
   ;
   if _Enemy_Counter < temp6 then goto __Skip_New_E_Dir

   ;```````````````````````````````````````````````````````````````
   ;  Grabs a random number (0 to 255).
   ;
   temp5 = rand

   ;```````````````````````````````````````````````````````````````
   ;  There is a 90% chance that this section will be skipped.
   ;
   if temp5 < 230 then goto __Skip_New_E_Dir

__Get_New_E_Direction

   ;```````````````````````````````````````````````````````````````
   ;  Grabs a new enemy direction from a random number (0 to 7).
   ;
   _Enemy_Dir = (rand&7)

   ;```````````````````````````````````````````````````````````````
   ;  Compares the new enemy direction with the opposite direction
   ;  and selects a new direction if there is a match. This keeps
   ;  the enemy from bouncing back and forth between the same two
   ;  directions.
   ;
   if _Enemy_Dir = _Mem_E_Dir then _Enemy_Dir = _Enemy_Dir + (rand&1) + (rand&1) + 3 : if _Enemy_Dir > 7 then _Enemy_Dir = _Enemy_Dir - 8

   ;```````````````````````````````````````````````````````````````
   ;  Enemy goes up/right or up/left if it is near bottom.
   ;
   if player1y > 85 then _Enemy_Dir = 1 : temp6 = rand : if temp6 > 128 then _Enemy_Dir = 7

   ;```````````````````````````````````````````````````````````````
   ;  Enemy goes down/right or down/left if it is near top.
   ;
   if player1y < 12 then _Enemy_Dir = 3 : temp6 = rand : if temp6 > 128 then _Enemy_Dir = 5

   ;```````````````````````````````````````````````````````````````
   ;  Enemy goes up/left or down/left if it's near right side.
   ;
   if player1x > 148 then _Enemy_Dir = 7 : temp6 = rand : if temp6 > 128 then _Enemy_Dir = 5

   ;```````````````````````````````````````````````````````````````
   ;  Enemy goes up/right or down/right if it's near left side.
   ;
   if player1x < 4 then _Enemy_Dir = 1 : temp6 = rand : if temp6 > 128 then _Enemy_Dir = 3

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the opposite direction the enemy is moving. Keeps
   ;  the enemy from bouncing back and forth between the same two
   ;  directions.
   ;
   _Mem_E_Dir = _Enemy_Dir + 4 : if _Mem_E_Dir > 7 then _Mem_E_Dir = _Mem_E_Dir - 8

   ;```````````````````````````````````````````````````````````````
   ;  Clears counter and enemy direction bits.
   ;
   _Enemy_Counter = 0 : _BitOp_P1_Dir = _BitOp_P1_Dir & %11110000

   ;```````````````````````````````````````````````````````````````
   ;  Converts enemy direction to bits to make things easier.
   ;
   if _Enemy_Dir = 0 then _Bit0_P1_Dir_Up{0} = 1
   if _Enemy_Dir = 1 then _Bit0_P1_Dir_Up{0} = 1 : _Bit3_P1_Dir_Right{3} = 1
   if _Enemy_Dir = 2 then _Bit3_P1_Dir_Right{3} = 1
   if _Enemy_Dir = 3 then _Bit1_P1_Dir_Down{1} = 1 : _Bit3_P1_Dir_Right{3} = 1
   if _Enemy_Dir = 4 then _Bit1_P1_Dir_Down{1} = 1
   if _Enemy_Dir = 5 then _Bit1_P1_Dir_Down{1} = 1 : _Bit2_P1_Dir_Left{2} = 1
   if _Enemy_Dir = 6 then _Bit2_P1_Dir_Left{2} = 1
   if _Enemy_Dir = 7 then _Bit0_P1_Dir_Up{0} = 1 : _Bit2_P1_Dir_Left{2} = 1

__Skip_New_E_Dir



   ;***************************************************************
   ;
   ;  Enemy up check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if enemy isn't moving up.
   ;
   if !_Bit0_P1_Dir_Up{0} then goto __Skip_Enemy_Up

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player1y <= _c_Edge_Top then goto __Skip_Enemy_Up

   ;```````````````````````````````````````````````````````````````
   ;  Skips pfread if player1 is outside of PF pixel area.
   ;
   if player1x < 17 || player1x > 137 then goto __Enemy_Move_Up

   ;```````````````````````````````````````````````````````````````
   ;  Checks for any playfield pixels that might be in the way.
   ;
   temp5 = (player1x-10)/4

   temp4 = (player1x-17)/4

   temp3 = temp5 - 1

   temp6 = (player1y-9)/8

   if !pfread(temp5,temp6) then if !pfread(temp4,temp6) then if !pfread(temp3,temp6) then goto __Enemy_Move_Up

   goto __Skip_Enemy_Up

__Enemy_Move_Up

   ;```````````````````````````````````````````````````````````````
   ;  Moves enemy up.
   ;
   player1y = player1y - 1

__Skip_Enemy_Up



   ;***************************************************************
   ;
   ;  Enemy down check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if enemy isn't moving down.
   ;
   if !_Bit1_P1_Dir_Down{1} then goto __Skip_Enemy_Down

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player1y >= _c_Edge_Bottom then goto __Skip_Enemy_Down

   ;```````````````````````````````````````````````````````````````
   ;  Skips pfread if player1 is outside of PF pixel area.
   ;
   if player1x < 17 || player1x > 137 then goto __Enemy_Move_Down

   ;```````````````````````````````````````````````````````````````
   ;  Checks for any playfield pixels that might be in the way.
   ;
   temp5 = (player1x-10)/4

   temp4 = (player1x-17)/4

   temp3 = temp5 - 1

   temp6 = (player1y)/8

   if !pfread(temp5,temp6) then if !pfread(temp4,temp6) then if !pfread(temp3,temp6) then goto __Enemy_Move_Down

   goto __Skip_Enemy_Down

__Enemy_Move_Down

   ;```````````````````````````````````````````````````````````````
   ;  Moves enemy down.
   ;
   player1y = player1y + 1

__Skip_Enemy_Down



   ;***************************************************************
   ;
   ;  Enemy left check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if enemy isn't moving left.
   ;
   if !_Bit2_P1_Dir_Left{2} then goto __Skip_Enemy_Left

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player1x <= _c_Edge_Left then goto __Skip_Enemy_Left

   ;```````````````````````````````````````````````````````````````
   ;  Skips pfread if player1 is outside of PF pixel area.
   ;
   if player1x < 17 || player1x > 137 then goto __Enemy_Move_Left

   ;```````````````````````````````````````````````````````````````
   ;  Checks for any playfield pixels that might be in the way.
   ;
   temp5 = (player1y-1)/8

   temp3 = (player1y-8)/8

   temp6 = (player1x-18)/4

   if !pfread(temp6,temp5) then if !pfread(temp6,temp3) then goto __Enemy_Move_Left

   goto __Skip_Enemy_Left

__Enemy_Move_Left

   ;```````````````````````````````````````````````````````````````
   ;  Moves enemy left.
   ;
   player1x = player1x - 1

__Skip_Enemy_Left



   ;***************************************************************
   ;
   ;  Enemy right check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if enemy isn't moving right.
   ;
   if !_Bit3_P1_Dir_Right{3} then goto __Skip_Enemy_Right

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player1x >= _c_Edge_Right then goto __Skip_Enemy_Right

   ;```````````````````````````````````````````````````````````````
   ;  Skips pfread if player1 is outside of PF pixel area.
   ;
   if player1x < 17 || player1x > 137 then goto __Enemy_Move_Right

   ;```````````````````````````````````````````````````````````````
   ;  Checks for any playfield pixels that might be in the way.
   ;
   temp5 = (player1y-1)/8

   temp3 = (player1y-8)/8

   temp6 = (player1x-9)/4

   if !pfread(temp6,temp5) then if !pfread(temp6,temp3) then goto __Enemy_Move_Right

   goto __Skip_Enemy_Right

__Enemy_Move_Right

   ;```````````````````````````````````````````````````````````````
   ;  Moves enemy right.
   ;
   player1x = player1x + 1

__Skip_Enemy_Right



   ;***************************************************************
   ;
   ;  Enemy inactivity check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Enemy gets a new direction if it is sitting still.
   ;
   if _Mem_P1x = player1x && _Mem_P1y = player1y then _Enemy_Counter = 254

   ;```````````````````````````````````````````````````````````````
   ;  Remembers enemy position.
   ;
   _Mem_P1x = player1x : _Mem_P1y = player1y



   ;***************************************************************
   ;
   ;  Code continues in next bank.
   ;
   goto __Code_Section_2 bank2




   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  End of first section of main loop.
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   bank 2
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Second section of main loop.
   ;
__Code_Section_2



   ;***************************************************************
   ;
   ;  Channel 0 sound effect check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 0 sounds if sounds are off.
   ;
   if !_Ch0_Sound then goto __Skip_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the channel 0 duration counter.
   ;
   _Ch0_Duration = _Ch0_Duration - 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 0 sounds if duration counter is greater
   ;  than zero
   ;
   if _Ch0_Duration then goto __Skip_Ch_0



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 001.
   ;
   ;  Up sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 001 isn't on.
   ;
   if _Ch0_Sound <> 1 then goto __Skip_Ch0_Sound_001

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Shot_Wall[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Shot_Wall[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Shot_Wall[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets Duration.
   ;
   _Ch0_Duration = _SD_Shot_Wall[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_001



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 002.
   ;
   ;  Shoot missile sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 002 isn't on.
   ;
   if _Ch0_Sound <> 2 then goto __Skip_Ch0_Sound_002

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Shoot_Miss[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Shoot_Miss[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Shoot_Miss[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets Duration.
   ;
   _Ch0_Duration = _SD_Shoot_Miss[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_002



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 003.
   ;
   ;  Shoot enemy.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 003 isn't on.
   ;
   if _Ch0_Sound <> 3 then goto __Skip_Ch0_Sound_003

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Shoot_Enemy[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Shoot_Enemy[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Shoot_Enemy[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets Duration.
   ;
   _Ch0_Duration = _SD_Shoot_Enemy[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_003



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 004.
   ;
   ;  Touch enemy.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 004 isn't on.
   ;
   if _Ch0_Sound <> 4 then goto __Skip_Ch0_Sound_004

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Touch_Enemy[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Touch_Enemy[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Touch_Enemy[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets Duration.
   ;
   _Ch0_Duration = _SD_Touch_Enemy[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_004



   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Other channel 0 sound effects go here.
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````



   ;***************************************************************
   ;
   ;  Jumps to end of channel 0 area. (This catches any mistakes.)
   ;
   goto __Skip_Ch_0



   ;***************************************************************
   ;
   ;  Clears channel 0.
   ;
__Clear_Ch_0
   
   _Ch0_Sound = 0 : AUDV0 = 0



   ;***************************************************************
   ;
   ;  End of channel 0 area.
   ;
__Skip_Ch_0



   ;***************************************************************
   ;
   ;  Channel 1 background music check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips music if left difficulty switch is set to A.
   ;
   if !switchleftb then AUDV1 = 0 : goto __Skip_Ch_1

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the channel 1 duration counter.
   ;
   _Ch1_Duration = _Ch1_Duration - 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips channel 1 if duration counter is greater than zero.
   ;
   if _Ch1_Duration then goto __Skip_Ch_1



   ;***************************************************************
   ;
   ;  Channel 1 background music.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 1 data.
   ;
   temp4 = sread(_SD_Music01)

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __BG_Music_Setup_01

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 1 data.
   ;
   temp5 = sread(_SD_Music01)
   temp6 = sread(_SD_Music01)

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 1.
   ;
   AUDV1 = temp4
   AUDC1 = temp5
   AUDF1 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets duration.
   ;
   _Ch1_Duration = sread(_SD_Music01)



   ;***************************************************************
   ;
   ;  End of channel 1 area.
   ;
__Skip_Ch_1



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  If the reset switch is not pressed, turn off reset
   ;  restrainer bit and jump to beginning of main loop.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop bank1

   ;```````````````````````````````````````````````````````````````
   ;  If the reset switch hasn't been released after being
   ;  pressed, jump to beginning of main loop.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop bank1

   ;```````````````````````````````````````````````````````````````
   ;  Reset pressed appropriately. Restart the program.
   ;
   goto __Start_Restart bank1





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  End of second section of main loop.
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for shot hitting wall.
   ;
   data _SD_Shot_Wall
   8,8,0
   1
   8,8,1
   1
   8,14,1
   1
   8,8,0
   1
   8,8,2
   1
   8,14,2
   1
   8,8,1
   1
   7,8,3
   1
   6,8,2
   1
   5,8,4
   1
   4,8,3
   1
   3,8,5
   1
   2,14,4
   4
   255
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for shooting missile.
   ;
   data _SD_Shoot_Miss
   8,15,0
   1
   12,15,1
   1
   8,7,20
   1
   10,15,3
   1
   8,7,22
   1
   10,15,5
   1
   8,15,6
   1
   10,7,24
   1
   8,15,8
   1
   9,7,27
   1
   8,15,10
   1
   7,14,11
   1
   6,15,12
   1
   5,6,13
   1
   4,15,14
   1
   3,6,27
   1
   2,6,30
   8
   255
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for shooting enemy.
   ;
   data _SD_Shoot_Enemy
   12,4,23
   4
   10,4,29
   4
   8,4,23
   4
   6,4,29
   4
   4,4,23
   4
   3,4,29
   4
   2,4,23
   1
   1,4,29
   1
   255
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for touching enemy.
   ;
   data _SD_Touch_Enemy
   2,7,11
   2
   10,7,12
   2
   8,7,13
   2
   8,7,14
   2
   8,7,21
   8
   4,7,22
   2
   2,7,23
   1
   255
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Channel 1 background music sound data.
   ;
__BG_Music_Setup_01

   sdata _SD_Music01 = u
   4,8,2
   1
   8,12,31
   8
   2,8,2
   1
   2,12,31
   8

   4,8,2
   1
   8,12,26
   11

   8,12,23
   8

   4,8,2
   1
   8,12,23
   8
   2,8,2
   1
   2,12,23
   8

   4,8,2
   1
   8,12,23
   8
   2,8,2
   1
   2,12,23
   8

   4,8,2
   1
   8,12,20
   8
   2,8,2
   1
   2,12,20
   8

   4,8,2
   1
   8,12,26
   8
   2,8,2
   1
   2,12,26
   8

   4,8,2
   1
   8,12,31
   8
   2,8,2
   1
   2,12,31
   8

   4,8,2
   1
   8,12,26
   8
   2,8,2
   1
   3,12,26
   8

   4,8,2
   1
   2,12,26
   8
   2,8,2
   1
   1,12,26
   8

   4,8,2
   1
   0,0,0
   8
   2,8,2
   1
   0,0,0
   8

   4,8,2
   1
   0,0,0
   8
   2,8,2
   1
   0,0,0
   8

   4,8,2
   1
   8,12,23
   8
   2,8,2
   1
   2,12,23
   8

   4,8,2
   1
   8,12,29
   8
   2,8,2
   1
   2,12,29
   8

   4,8,2
   1
   8,12,24
   8
   2,8,2
   1
   2,12,24
   8

   4,8,2
   1
   8,12,31
   8
   2,8,2
   1
   3,12,31
   8

   4,8,2
   1
   2,12,31
   8
   2,8,2
   1
   1,12,31
   8

   4,8,2
   1
   8,12,15
   8
   2,8,2
   1
   2,12,15
   8

   4,8,2
   1
   8,12,17
   8
   2,8,2
   1
   2,12,17
   8

   4,8,2
   1
   8,12,19
   8
   2,8,2
   1
   2,12,19
   8

   4,8,2
   1
   8,12,20
   8
   2,8,2
   1
   2,12,20
   8

   4,8,2
   1
   8,12,20
   8
   2,8,2
   1
   2,12,20
   8

   4,8,2
   1
   8,12,17
   8
   2,8,2
   1
   2,12,17
   8

   4,8,2
   1
   8,12,15
   8
   2,8,2
   1
   3,12,15
   8
   
   4,8,2
   1
   2,12,15
   8
   2,8,2
   1
   1,12,15
   8


   4,8,2
   1
   8,12,31
   8
   2,8,2
   1
   2,12,31
   8

   4,8,2
   1
   8,12,15
   8
   2,8,2
   1
   2,12,15
   8

   4,8,2
   1
   8,12,29
   8
   2,8,2
   1
   2,12,29
   8

   4,8,2
   1
   8,12,17
   8
   2,8,2
   1
   2,12,17
   8

   4,8,2
   1
   8,12,31
   8
   2,8,2
   1
   2,12,31
   8

   4,8,2
   1
   8,12,15
   8
   2,8,2
   1
   2,12,15
   8

   4,8,2
   1
   8,12,29
   8
   2,8,2
   1
   2,12,29
   8

   4,8,2
   1
   8,12,17
   8
   2,8,2
   1
   2,12,17
   8


   4,8,2
   1
   8,12,31
   8
   2,8,2
   1
   2,12,31
   8

   4,8,2
   1
   8,12,15
   8
   2,8,2
   1
   2,12,15
   8

   4,8,2
   1
   8,12,29
   8
   2,8,2
   1
   2,12,29
   8

   4,8,2
   1
   8,12,17
   8
   2,8,2
   1
   2,12,17
   8



   4,8,2
   1
   8,12,15
   8
   2,8,2
   1
   2,12,15
   8

   4,8,2
   1
   8,12,20
   8
   2,8,2
   1
   3,12,20
   8


   4,8,2
   1
   2,12,20
   8
   2,8,2
   1
   2,12,20
   8

   4,8,2
   1
   8,12,15
   8
   2,8,2
   1
   2,12,15
   8

   4,8,2
   1
   8,12,17
   8
   2,8,2
   1
   3,12,17
   8

   4,8,2
   1
   2,12,17
   8
   2,8,2
   1
   1,12,17
   8

   4,8,2
   1
   8,12,14
   8
   2,8,2
   1
   3,12,14
   8

   4,8,2
   1
   2,12,14
   8
   2,8,2
   1
   1,12,14
   8

   4,8,2
   1
   0,0,0
   8
   2,8,2
   1
   0,0,0
   8

   4,8,2
   1
   0,0,0
   8
   2,8,2
   1
   0,0,0
   8

   4,8,2
   1
   0,0,0
   8
   2,8,2
   1
   0,0,0
   8

   4,8,2
   1
   0,0,0
   8
   2,8,2
   1
   0,0,0
   8
   255
end

   _Ch1_Duration = 1

   goto __Skip_Ch_1

 

 

 

Sound Example With BGM and Animation

Sound Example With BGM and Animation on bB page.

 
   ;***************************************************************
   ;
   ;  Sound Example With Background "Music" and Animation.
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Use the joystick to move the sprite. Press the fire button
   ;  to shoot the missile. There is a sound effect on channel 0
   ;  for shooting a missile, hitting a wall with a missile,
   ;  hitting the enemy with a missile, and when the player and
   ;  enemy touch. Channel 1 is used for the background "music."
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  This program has 2 banks (8k/4k = 2 banks).
   ;
   set romsize 8k



   ;***************************************************************
   ;
   ;  Random numbers can slow down bankswitched games. This will
   ;  speed things up.
   ;
   set optimization inlinerand



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Player movement.
   ;
   dim _P0_Left_Right = player0x.a

   dim _P0_Up_Down = player0y.b

   ;```````````````````````````````````````````````````````````````
   ;  _Master_Counter can be used for many things, but it is 
   ;  really useful for animating sprite frames when used
   ;  with _Frame_Counter.
   ;
   dim _Master_Counter = c
   dim _Frame_Counter = d

   ;```````````````````````````````````````````````````````````````
   ;  Flips player sprite when necessary.
   ;
   dim _Bit3_Flip_P0 = e

   ;```````````````````````````````````````````````````````````````
   ;  Player0/missile0 direction bits.
   ;
   dim _BitOp_P0_M0_Dir = g
   dim _Bit0_P0_Dir_Up = g
   dim _Bit1_P0_Dir_Down = g
   dim _Bit2_P0_Dir_Left = g
   dim _Bit3_P0_Dir_Right = g
   dim _Bit4_Missile0_Dir_Up = g
   dim _Bit5_Missile0_Dir_Down = g
   dim _Bit6_Missile0_Dir_Left = g
   dim _Bit7_Missile0_Dir_Right = g

   ;```````````````````````````````````````````````````````````````
   ;  Enemy direction bits.
   ;
   dim _BitOp_P1_Dir = h
   dim _Bit0_P1_Dir_Up = h
   dim _Bit1_P1_Dir_Down = h
   dim _Bit2_P1_Dir_Left = h
   dim _Bit3_P1_Dir_Right = h

   ;```````````````````````````````````````````````````````````````
   ;  Helps the program know when it's time for the enemy to
   ;  change direction.
   ;
   dim _Enemy_Counter = i

   ;```````````````````````````````````````````````````````````````
   ;  Enemy direction.
   ;  0 = up, 1 = up/right, 2 = right, 3 = down/right, 4 = down,
   ;  5 = down/left, 6 = left, 7 = up/left.
   ;
   dim _Enemy_Dir = j

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the opposite direction the enemy moved. Keeps the
   ;  enemy sprite from bouncing back and forth between the same
   ;  two directions like a ping-pong ball.
   ;
   dim _Mem_E_Dir = k

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the last position of the enemy. A new direction is
   ;  chosen if the enemy stops moving.
   ;
   dim _Mem_P1x = l
   dim _Mem_P1y = m

   ;```````````````````````````````````````````````````````````````
   ;  Channel 0 sound variables.
   ;
   dim _Ch0_Sound = q
   dim _Ch0_Duration = r
   dim _Ch0_Counter = s

   ;```````````````````````````````````````````````````````````````
   ;  Channel 1 sound variables.
   ;
   dim _Ch1_Duration = t
  
   ;```````````````````````````````````````````````````````````````
   ;  u and v used for channel 1 sdata.
   ;
   ;```````````````````````````````````````````````````````````````

   ;```````````````````````````````````````````````````````````````
   ;  Bits that do various jobs.
   ;
   dim _Bit0_Reset_Restrainer = y
   dim _Bit7_Missile0_Moving = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers.
   ;
   dim rand16 = z




   ;***************************************************************
   ;
   ;  Defines the edges of the playfield. The _c_ stands for const
   ;  so I'll remember it's a constant and not a normal variable.
   ;
   const _c_Edge_Top = 9
   const _c_Edge_Bottom = 87
   const _c_Edge_Left = 1
   const _c_Edge_Right = 152




   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for the missile.
   ;  If the missile is a different size, you'll need to adjust
   ;  the numbers.
   ;
   const _c_Missile_Edge_Top = 2
   const _c_Missile_Edge_Bottom = 88
   const _c_Missile_Edge_Left = 2
   const _c_Missile_Edge_Right = 159




   ;***************************************************************
   ;
   ;  Disables the score. (We don't need it in this program.)
   ;
   const noscore = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables except for z (used for rand).
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0


   ;***************************************************************
   ;
   ;  Sets starting position of player1 enemy.
   ;
   player1x = 140 : player1y = 78


   ;***************************************************************
   ;
   ;  Sets player0 position and starting shape.
   ;
   player0x = 75 : player0y = 55

   player0:
   %00011000
   %00011000
   %00011000
   %11111111
   %01111110
   %00111100
   %01100110
   %01011010
end


   ;***************************************************************
   ;
   ;  Makes sure missile0 is off the screen.
   ;
   missile0x = 200 : missile0y = 200


   ;***************************************************************
   ;
   ;  Defines missile0 height.
   ;
   missile0height = 1


   ;***************************************************************
   ;
   ;  Sets playfield color.
   ;
   COLUPF = $FC


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Sets beginning direction that missile0 will shoot if the
   ;  player doesn't move.
   ;
   _Bit1_P0_Dir_Down{1} = 1 : _Bit5_Missile0_Dir_Down{5} = 1


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Defines shape of player1 sprite.
   ;
   player1:
   %00111100
   %01111110
   %11000011
   %11111111
   %11111111
   %11011011
   %01111110
   %00111100
end


   ;***************************************************************
   ;
   ;  Sets up the playfield.
   ;
   playfield:
   ................................
   ................................
   ....XXXXXXXXXX....XXXXXXXXXX....
   ....X......................X....
   ....X......................X....
   ....X......................X....
   ................................
   ................................
   ....XXXX....XXX..XXX....XXXX....
   ................................
   ................................
end


   ;***************************************************************
   ;
   ;  Starts the background "music."
   ;
   goto __BG_Music_Setup_01 bank2





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets color of player0 sprite and missile.
   ;
   COLUP0 = $9C



   ;***************************************************************
   ;
   ;  Sets color of player1 sprite.
   ;
   COLUP1 = $44



   ;***************************************************************
   ;
   ;  Defines missile0 width.
   ;
   NUSIZ0 = $10



   ;***************************************************************
   ;
   ;  Main counters.
   ;
   ;  Controls animation speed.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments the master counter.
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips section if master counter is less than 7.
   ;
   if _Master_Counter < 7 then goto __Skip_Frame_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Increments frame counter.
   ;
   _Frame_Counter = _Frame_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Clears master counter.
   ;
   _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Clears frame counter when it's time.
   ;
   if _Frame_Counter = 4 then _Frame_Counter = 0

__Skip_Frame_Counter



   ;***************************************************************
   ;
   ;  Joystick movement precheck.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if joystick hasn't been moved.
   ;
   if !joy0up && !joy0down && !joy0left && !joy0right then goto __Skip_Joystick_Precheck

   ;```````````````````````````````````````````````````````````````
   ;  Clears player0 direction bits since joystick has been moved.
   ;
   _BitOp_P0_M0_Dir = _BitOp_P0_M0_Dir & %11110000

__Skip_Joystick_Precheck



   ;***************************************************************
   ;
   ;  Joy0 up check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved up.
   ;
   if !joy0up then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the up direction bit.
   ;
   _Bit0_P0_Dir_Up{0} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Sprite is not reflected. 
   ;
   _Bit3_Flip_P0{3} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if _P0_Up_Down <= _c_Edge_Top then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Skips pfread if player0 is outside of PF pixel area.
   ;
   if player0x < 17 || player0x > 137 then goto __Move_P0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 up if a pfpixel is not in the way.
   ;
   temp5 = (player0x-10)/4

   temp4 = (player0x-17)/4

   temp3 = temp5 - 1

   temp6 = (player0y-9)/8

   if !pfread(temp5,temp6) then if !pfread(temp4,temp6) then if !pfread(temp3,temp6) then goto __Move_P0_Up

   goto __Skip_Joy0_Up

__Move_P0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 up.
   ;
   _P0_Up_Down = _P0_Up_Down - 1.42

__Skip_Joy0_Up



   ;***************************************************************
   ;
   ;  Joy0 down check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved down.
   ;
   if !joy0down then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the down direction bit.
   ;
   _Bit1_P0_Dir_Down{1} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Sprite is not reflected. 
   ;
   _Bit3_Flip_P0{3} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if _P0_Up_Down >= _c_Edge_Bottom then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Skips pfread if player0 is outside of PF pixel area.
   ;
   if player0x < 17 || player0x > 137 then goto __Move_P0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 down if a pfpixel is not in the way.
   ;
   temp5 = (player0x-10)/4

   temp4 = (player0x-17)/4

   temp3 = temp5 - 1

   temp6 = (player0y)/8

   if !pfread(temp5,temp6) then if !pfread(temp4,temp6) then if !pfread(temp3,temp6) then goto __Move_P0_Down

   goto __Skip_Joy0_Down

__Move_P0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 down.
   ;
   _P0_Up_Down = _P0_Up_Down + 1.42

__Skip_Joy0_Down



   ;***************************************************************
   ;
   ;  Joy0 left check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved to the left.
   ;
   if !joy0left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the left direction bit.
   ;
   _Bit2_P0_Dir_Left{2} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Sprite is not reflected. 
   ;
   _Bit3_Flip_P0{3} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if _P0_Left_Right <= _c_Edge_Left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Skips pfread if player0 is outside of PF pixel area.
   ;
   if player0x < 17 || player0x > 137 then goto __Move_P0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 left if a pfpixel is not in the way.
   ;
   temp5 = (player0y-1)/8

   temp3 = (player0y-8)/8

   temp6 = (player0x-19)/4

   if !pfread(temp6,temp5) then if !pfread(temp6,temp3) then goto __Move_P0_Left

   goto __Skip_Joy0_Left

__Move_P0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 left.

   ;
   _P0_Left_Right = _P0_Left_Right - 1.42

__Skip_Joy0_Left



   ;***************************************************************
   ;
   ;  Joy0 right check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved to the right.
   ;
   if !joy0right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the right direction bit.
   ;
   _Bit3_P0_Dir_Right{3} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Sprite is reflected.
   ;
   _Bit3_Flip_P0{3} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if _P0_Left_Right >= _c_Edge_Right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Skips pfread if player0 is outside of PF pixel area.
   ;
   if player0x < 17 || player0x > 137 then goto __Move_P0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 right if a pfpixel is not in the way.
   ;
   temp5 = (player0y-1)/8

   temp3 = (player0y-8)/8

   temp6 = (player0x-9)/4

   if !pfread(temp6,temp5) then if !pfread(temp6,temp3) then goto __Move_P0_Right

   goto __Skip_Joy0_Right

__Move_P0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 right.
   ;
   _P0_Left_Right = _P0_Left_Right + 1.42

__Skip_Joy0_Right



   ;***************************************************************
   ;
   ;  Animation: jumps to the next animation frame.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Get rid of the REM below if you don't want constant animation.
   ;
   rem if !joy0up && !joy0down && !joy0left && !joy0right then goto __Done_Anim

   ;```````````````````````````````````````````````````````````````
   ;  Up related checks.
   ;
   if !_Bit0_P0_Dir_Up{0} then goto __Skip_Up_Anim

   if _Bit2_P0_Dir_Left{2} || _Bit3_P0_Dir_Right{3} then on _Frame_Counter goto __P0_UL_00 __P0_UL_01 __P0_UL_02 __P0_UL_03

   on _Frame_Counter goto __P0_U_00 __P0_U_01 __P0_U_02 __P0_U_03

__Skip_Up_Anim

   ;```````````````````````````````````````````````````````````````
   ;  Down related checks.
   ;
   if !_Bit1_P0_Dir_Down{1} then goto __Skip_Down_Anim

   if _Bit2_P0_Dir_Left{2} || _Bit3_P0_Dir_Right{3} then on _Frame_Counter goto __P0_DL_00 __P0_DL_01 __P0_DL_02 __P0_DL_03

   on _Frame_Counter goto __P0_D_00 __P0_D_01 __P0_D_02 __P0_D_03

__Skip_Down_Anim

   ;```````````````````````````````````````````````````````````````
   ;  Left check.
   ;
   if _Bit2_P0_Dir_Left{2} then on _Frame_Counter goto __P0_L_00 __P0_L_01 __P0_L_02 __P0_L_03

   ;```````````````````````````````````````````````````````````````
   ;  Right check.
   ;
   if _Bit3_P0_Dir_Right{3} then on _Frame_Counter goto __P0_L_00 __P0_L_01 __P0_L_02 __P0_L_03


__Done_Anim



   ;***************************************************************
   ;
   ;  Flips player sprite if necessary.
   ;
   if _Bit3_Flip_P0{3} then REFP0 = 8



   ;***************************************************************
   ;
   ;  Fire button check.
   ;  
   ;  If fire button is pressed appropriately and missile1
   ;  is not moving, turns on missile1 movement.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the fire button is not pressed.
   ;
   if !joy0fire then goto __Skip_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if missile0 is moving.
   ;
   if _Bit7_Missile0_Moving{7} then goto __Skip_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Turns on missile0 movement.
   ;
   _Bit7_Missile0_Moving{7} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Takes a 'snapshot' of player0 direction so missile0 will
   ;  stay on track until it hits something.
   ;
   _Bit4_Missile0_Dir_Up{4} = _Bit0_P0_Dir_Up{0}
   _Bit5_Missile0_Dir_Down{5} = _Bit1_P0_Dir_Down{1}
   _Bit6_Missile0_Dir_Left{6} = _Bit2_P0_Dir_Left{2}
   _Bit7_Missile0_Dir_Right{7} = _Bit3_P0_Dir_Right{3}

   ;```````````````````````````````````````````````````````````````
   ;  Sets up starting position of missile0.
   ;
   if _Bit4_Missile0_Dir_Up{4} then missile0x = player0x + 4 : missile0y = player0y - 5
   if _Bit5_Missile0_Dir_Down{5} then missile0x = player0x + 4 : missile0y = player0y - 1
   if _Bit6_Missile0_Dir_Left{6} then missile0x = player0x + 2 : missile0y = player0y - 3
   if _Bit7_Missile0_Dir_Right{7} then missile0x = player0x + 6 : missile0y = player0y - 3

   ;```````````````````````````````````````````````````````````````
   ;  Turns on sound effect.
   ;
   if _Ch0_Sound <> 3 then _Ch0_Sound = 2 : _Ch0_Duration = 1 : _Ch0_Counter = 0

__Skip_Fire



   ;***************************************************************
   ;
   ;  Missile0 movement check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if missile0 isn't moving.
   ;
   if !_Bit7_Missile0_Moving{7} then goto __Skip_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Moves missile0 in the appropriate direction.
   ;
   if _Bit4_Missile0_Dir_Up{4} then missile0y = missile0y - 2
   if _Bit5_Missile0_Dir_Down{5} then missile0y = missile0y + 2
   if _Bit6_Missile0_Dir_Left{6} then missile0x = missile0x - 2
   if _Bit7_Missile0_Dir_Right{7} then missile0x = missile0x + 2

   ;```````````````````````````````````````````````````````````````
   ;  Clears missile0 if it hits the edge of the screen.
   ;
   if missile0y < _c_Missile_Edge_Top then goto __Delete_Missile
   if missile0y > _c_Missile_Edge_Bottom then goto __Delete_Missile
   if missile0x < _c_Missile_Edge_Left then goto __Delete_Missile
   if missile0x > _c_Missile_Edge_Right then goto __Delete_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Skips rest of section if no collision.
   ;
   if !collision(playfield,missile0) then goto __Skip_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Turns on sound effect.
   ;
   if _Ch0_Sound <> 3 then _Ch0_Sound = 1 : _Ch0_Duration = 1 : _Ch0_Counter = 0

__Delete_Missile

   ;```````````````````````````````````````````````````````````````
   ;  Clears missile0 bit and moves missile0 off the screen.
   ;
   _Bit7_Missile0_Moving{7} = 0 : missile0x = 200 : missile0y = 200
   
__Skip_Missile



   ;***************************************************************
   ;
   ;  Enemy/missile collision check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if there is no collision.
   ;
   if !collision(player1,missile0) then goto __Skip_Shot_Enemy

   ;```````````````````````````````````````````````````````````````
   ;  Turns on sound effect.
   ;
   _Ch0_Sound = 3 : _Ch0_Duration = 1 : _Ch0_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Clears missile0 bit and moves missile0 off the screen.
   ;
   _Bit7_Missile0_Moving{7} = 0 : missile0x = 200 : missile0y = 200

   ;```````````````````````````````````````````````````````````````
   ;  Places enemy in new location based on location of player.
   ;
   if player0y >= 52 then player1y = (rand&7) + 10 : goto __Skip_Y_Placement

   player1y = (rand&7) + 78

__Skip_Y_Placement

   if player0x >= 77 then player1x = (rand&7) + 5 : goto __Skip_Shot_Enemy

   player1x = (rand&7) + 140

__Skip_Shot_Enemy



   ;***************************************************************
   ;
   ;  Enemy/player collision check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if there is no collision.

   ;
   if !collision(player1,player0) then goto __Skip_P0_Touched_Enemy

   ;```````````````````````````````````````````````````````````````
   ;  Turns on sound effect.
   ;
   if _Ch0_Sound <> 4 then _Ch0_Sound = 4 : _Ch0_Duration = 1 : _Ch0_Counter = 0

__Skip_P0_Touched_Enemy



   ;***************************************************************
   ;
   ;  Enemy direction change.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Adds to the enemy counter.
   ;
   _Enemy_Counter = _Enemy_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Forces a direction change when the counter gets too high or
   ;  when it's set high on purpose because the enemy was inactive.
   ;
   if _Enemy_Counter > 254 then goto __Get_New_E_Direction

   ;```````````````````````````````````````````````````````````````
   ;  Grabs a random number (0 to 63) and adds 50. Change 50 to a
   ;  larger number if you want the enemy to move longer before
   ;  changing directions. Don't use a number larger than 190.
   ;
   temp6 = (rand&63) + 50

   ;```````````````````````````````````````````````````````````````
   ;  Skips section if the counter isn't high enough.
   ;
   if _Enemy_Counter < temp6 then goto __Skip_New_E_Dir

   ;```````````````````````````````````````````````````````````````
   ;  Grabs a random number (0 to 255).
   ;
   temp5 = rand

   ;```````````````````````````````````````````````````````````````
   ;  There is a 90% chance that this section will be skipped.
   ;
   if temp5 < 230 then goto __Skip_New_E_Dir

__Get_New_E_Direction

   ;```````````````````````````````````````````````````````````````
   ;  Grabs a new enemy direction from a random number (0 to 7).
   ;
   _Enemy_Dir = (rand&7)

   ;```````````````````````````````````````````````````````````````
   ;  Compares the new enemy direction with the opposite direction
   ;  and selects a new direction if there is a match. This keeps
   ;  the enemy from bouncing back and forth between the same two
   ;  directions.
   ;
   if _Enemy_Dir = _Mem_E_Dir then _Enemy_Dir = _Enemy_Dir + (rand&1) + (rand&1) + 3 : if _Enemy_Dir > 7 then _Enemy_Dir = _Enemy_Dir - 8

   ;```````````````````````````````````````````````````````````````
   ;  Enemy goes up/right or up/left if it is near bottom.
   ;
   if player1y > 85 then _Enemy_Dir = 1 : temp6 = rand : if temp6 > 128 then _Enemy_Dir = 7

   ;```````````````````````````````````````````````````````````````
   ;  Enemy goes down/right or down/left if it is near top.
   ;
   if player1y < 12 then _Enemy_Dir = 3 : temp6 = rand : if temp6 > 128 then _Enemy_Dir = 5

   ;```````````````````````````````````````````````````````````````
   ;  Enemy goes up/left or down/left if it's near right side.
   ;
   if player1x > 148 then _Enemy_Dir = 7 : temp6 = rand : if temp6 > 128 then _Enemy_Dir = 5

   ;```````````````````````````````````````````````````````````````
   ;  Enemy goes up/right or down/right if it's near left side.
   ;
   if player1x < 4 then _Enemy_Dir = 1 : temp6 = rand : if temp6 > 128 then _Enemy_Dir = 3

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the opposite direction the enemy is moving. Keeps
   ;  the enemy from bouncing back and forth between the same two
   ;  directions.
   ;
   _Mem_E_Dir = _Enemy_Dir + 4 : if _Mem_E_Dir > 7 then _Mem_E_Dir = _Mem_E_Dir - 8

   ;```````````````````````````````````````````````````````````````
   ;  Clears counter and enemy direction bits.
   ;
   _Enemy_Counter = 0 : _BitOp_P1_Dir = _BitOp_P1_Dir & %11110000

   ;```````````````````````````````````````````````````````````````
   ;  Converts enemy direction to bits to make things easier.
   ;
   if _Enemy_Dir = 0 then _Bit0_P1_Dir_Up{0} = 1
   if _Enemy_Dir = 1 then _Bit0_P1_Dir_Up{0} = 1 : _Bit3_P1_Dir_Right{3} = 1
   if _Enemy_Dir = 2 then _Bit3_P1_Dir_Right{3} = 1

   if _Enemy_Dir = 3 then _Bit1_P1_Dir_Down{1} = 1 : _Bit3_P1_Dir_Right{3} = 1
   if _Enemy_Dir = 4 then _Bit1_P1_Dir_Down{1} = 1
   if _Enemy_Dir = 5 then _Bit1_P1_Dir_Down{1} = 1 : _Bit2_P1_Dir_Left{2} = 1
   if _Enemy_Dir = 6 then _Bit2_P1_Dir_Left{2} = 1
   if _Enemy_Dir = 7 then _Bit0_P1_Dir_Up{0} = 1 : _Bit2_P1_Dir_Left{2} = 1

__Skip_New_E_Dir



   ;***************************************************************
   ;
   ;  Enemy up check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if enemy isn't moving up.
   ;
   if !_Bit0_P1_Dir_Up{0} then goto __Skip_Enemy_Up

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player1y <= _c_Edge_Top then goto __Skip_Enemy_Up

   ;```````````````````````````````````````````````````````````````
   ;  Skips pfread if player1 is outside of PF pixel area.
   ;
   if player1x < 17 || player1x > 137 then goto __Enemy_Move_Up

   ;```````````````````````````````````````````````````````````````
   ;  Checks for any playfield pixels that might be in the way.
   ;
   temp5 = (player1x-10)/4

   temp4 = (player1x-17)/4

   temp3 = temp5 - 1

   temp6 = (player1y-9)/8

   if !pfread(temp5,temp6) then if !pfread(temp4,temp6) then if !pfread(temp3,temp6) then goto __Enemy_Move_Up

   goto __Skip_Enemy_Up

__Enemy_Move_Up

   ;```````````````````````````````````````````````````````````````
   ;  Moves enemy up.
   ;
   player1y = player1y - 1

__Skip_Enemy_Up



   ;***************************************************************
   ;
   ;  Enemy down check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if enemy isn't moving down.
   ;
   if !_Bit1_P1_Dir_Down{1} then goto __Skip_Enemy_Down

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player1y >= _c_Edge_Bottom then goto __Skip_Enemy_Down

   ;```````````````````````````````````````````````````````````````
   ;  Skips pfread if player1 is outside of PF pixel area.
   ;
   if player1x < 17 || player1x > 137 then goto __Enemy_Move_Down

   ;```````````````````````````````````````````````````````````````
   ;  Checks for any playfield pixels that might be in the way.
   ;
   temp5 = (player1x-10)/4

   temp4 = (player1x-17)/4

   temp3 = temp5 - 1

   temp6 = (player1y)/8

   if !pfread(temp5,temp6) then if !pfread(temp4,temp6) then if !pfread(temp3,temp6) then goto __Enemy_Move_Down

   goto __Skip_Enemy_Down

__Enemy_Move_Down

   ;```````````````````````````````````````````````````````````````
   ;  Moves enemy down.
   ;
   player1y = player1y + 1

__Skip_Enemy_Down



   ;***************************************************************
   ;
   ;  Enemy left check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if enemy isn't moving left.
   ;
   if !_Bit2_P1_Dir_Left{2} then goto __Skip_Enemy_Left

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player1x <= _c_Edge_Left then goto __Skip_Enemy_Left

   ;```````````````````````````````````````````````````````````````
   ;  Skips pfread if player1 is outside of PF pixel area.
   ;
   if player1x < 17 || player1x > 137 then goto __Enemy_Move_Left

   ;```````````````````````````````````````````````````````````````
   ;  Checks for any playfield pixels that might be in the way.
   ;
   temp5 = (player1y-1)/8

   temp3 = (player1y-8)/8

   temp6 = (player1x-18)/4

   if !pfread(temp6,temp5) then if !pfread(temp6,temp3) then goto __Enemy_Move_Left

   goto __Skip_Enemy_Left

__Enemy_Move_Left

   ;```````````````````````````````````````````````````````````````
   ;  Moves enemy left.
   ;
   player1x = player1x - 1

__Skip_Enemy_Left



   ;***************************************************************
   ;
   ;  Enemy right check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if enemy isn't moving right.
   ;
   if !_Bit3_P1_Dir_Right{3} then goto __Skip_Enemy_Right

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player1x >= _c_Edge_Right then goto __Skip_Enemy_Right

   ;```````````````````````````````````````````````````````````````
   ;  Skips pfread if player1 is outside of PF pixel area.
   ;
   if player1x < 17 || player1x > 137 then goto __Enemy_Move_Right

   ;```````````````````````````````````````````````````````````````
   ;  Checks for any playfield pixels that might be in the way.
   ;
   temp5 = (player1y-1)/8

   temp3 = (player1y-8)/8

   temp6 = (player1x-9)/4

   if !pfread(temp6,temp5) then if !pfread(temp6,temp3) then goto __Enemy_Move_Right

   goto __Skip_Enemy_Right

__Enemy_Move_Right

   ;```````````````````````````````````````````````````````````````
   ;  Moves enemy right.
   ;
   player1x = player1x + 1

__Skip_Enemy_Right



   ;***************************************************************
   ;
   ;  Enemy inactivity check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Enemy gets a new direction if it is sitting still.
   ;
   if _Mem_P1x = player1x && _Mem_P1y = player1y then _Enemy_Counter = 254

   ;```````````````````````````````````````````````````````````````
   ;  Remembers enemy position.
   ;
   _Mem_P1x = player1x : _Mem_P1y = player1y



   ;***************************************************************
   ;
   ;  Code continues in next bank.
   ;
   goto __Code_Section_2 bank2





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  End of first section of main loop.
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````




   ;***************************************************************
   ;***************************************************************
   ;
   ;  Animation frames for player0 sprite.
   ;
__P0_U_00
   player0:
   %01011010
   %01100110
   %00111100
   %01111110
   %11111111
   %00011000
   %00011000
   %00011000
end
   goto __Done_Anim


__P0_U_01
   player0:
   %01100110
   %01000010
   %10111101
   %01111110
   %11111111
   %00011000
   %00011000
   %00011000
end
   goto __Done_Anim


__P0_U_02
   player0:
   %01000010
   %11000011
   %10111101
   %01111110
   %11111111
   %00011000
   %00011000
   %00011000
end
   goto __Done_Anim


__P0_U_03
   player0:
   %11100111
   %11000011
   %10111101
   %01111110
   %11111111
   %00011000
   %00011000
   %00011000
end
   goto __Done_Anim


__P0_D_00
   player0:
   %00011000
   %00011000
   %00011000
   %11111111
   %01111110
   %00111100
   %01100110
   %01011010
end
   goto __Done_Anim


__P0_D_01
   player0:
   %00011000
   %00011000
   %00011000
   %11111111
   %01111110
   %10111101
   %01000010
   %01100110
end
   goto __Done_Anim


__P0_D_02
   player0:
   %00011000
   %00011000
   %00011000
   %11111111
   %01111110
   %10111101
   %11000011
   %01000010
end
   goto __Done_Anim


__P0_D_03
   player0:
   %00011000
   %00011000
   %00011000
   %11111111
   %01111110
   %10111101
   %11000011
   %11100111
end
   goto __Done_Anim


__P0_L_00
   player0:
   %00010000
   %00011011
   %00011110
   %11111101
   %11111101
   %00011110
   %00011011
   %00010000
end
   goto __Done_Anim


__P0_L_01
   player0:
   %00010100
   %00011011
   %00011101
   %11111100
   %11111100
   %00011101
   %00011011
   %00010100
end
   goto __Done_Anim


__P0_L_02
   player0:
   %00010110
   %00011011
   %00011100
   %11111100
   %11111100
   %00011100
   %00011011
   %00010110
end
   goto __Done_Anim


__P0_L_03
   player0:
   %00010111
   %00011011
   %00011101
   %11111100
   %11111100
   %00011101
   %00011011
   %00010111
end
   goto __Done_Anim


__P0_UL_00
   player0:
   %00001000
   %10010010
   %11111000
   %01111101
   %00111110
   %01111100
   %11101100
   %11000110
end
   goto __Done_Anim


__P0_UL_01
   player0:
   %00001100
   %11010000
   %11111001
   %01111101
   %00111110
   %01111110
   %11101100
   %11000110
end
   goto __Done_Anim


__P0_UL_02
   player0:
   %00101000
   %11010000
   %11111000
   %01111101
   %00111110
   %01111111
   %11101100
   %11000110
end
   goto __Done_Anim


__P0_UL_03
   player0:
   %00111100
   %11110000
   %11111001
   %01111101
   %00111111
   %01111111
   %11101100
   %11000110
end
   goto __Done_Anim


__P0_DL_00
   player0:
   %11000110
   %11101100
   %01111100
   %00111110
   %01111101
   %11111000
   %10010010
   %00001000
end
   goto __Done_Anim


__P0_DL_01
   player0:
   %11000110
   %11101100
   %01111110
   %00111110
   %01111101
   %11111001
   %11010000
   %00001100
end
   goto __Done_Anim


__P0_DL_02
   player0:
   %11000110
   %11101100
   %01111111
   %00111110
   %01111101
   %11111000
   %11010000
   %00101000
end
   goto __Done_Anim


__P0_DL_03
   player0:
   %11000110
   %11101100
   %01111111
   %00111111
   %01111101
   %11111001
   %11110000
   %00111100
end
   goto __Done_Anim





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   bank 2
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Second section of main loop.
   ;
__Code_Section_2



   ;***************************************************************
   ;
   ;  Channel 0 sound effect check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 0 sounds if sounds are off.
   ;
   if !_Ch0_Sound then goto __Skip_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the channel 0 duration counter.
   ;
   _Ch0_Duration = _Ch0_Duration - 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 0 sounds if duration counter is greater
   ;  than zero
   ;
   if _Ch0_Duration then goto __Skip_Ch_0



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 001.
   ;
   ;  Up sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 001 isn't on.
   ;
   if _Ch0_Sound <> 1 then goto __Skip_Ch0_Sound_001

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Shot_Wall[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Shot_Wall[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Shot_Wall[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets Duration.
   ;
   _Ch0_Duration = _SD_Shot_Wall[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_001



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 002.
   ;
   ;  Shoot missile sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 002 isn't on.
   ;
   if _Ch0_Sound <> 2 then goto __Skip_Ch0_Sound_002

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Shoot_Miss[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Shoot_Miss[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Shoot_Miss[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets Duration.
   ;
   _Ch0_Duration = _SD_Shoot_Miss[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_002



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 003.
   ;
   ;  Shoot enemy.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 003 isn't on.
   ;
   if _Ch0_Sound <> 3 then goto __Skip_Ch0_Sound_003

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Shoot_Enemy[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Shoot_Enemy[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Shoot_Enemy[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets Duration.
   ;
   _Ch0_Duration = _SD_Shoot_Enemy[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_003



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 004.
   ;
   ;  Touch enemy.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 004 isn't on.
   ;
   if _Ch0_Sound <> 4 then goto __Skip_Ch0_Sound_004

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Touch_Enemy[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Touch_Enemy[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Touch_Enemy[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets Duration.
   ;
   _Ch0_Duration = _SD_Touch_Enemy[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_004



   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Other channel 0 sound effects go here.
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````



   ;***************************************************************
   ;
   ;  Jumps to end of channel 0 area. (This catches any mistakes.)
   ;
   goto __Skip_Ch_0



   ;***************************************************************
   ;
   ;  Clears channel 0.
   ;
__Clear_Ch_0
   
   _Ch0_Sound = 0 : AUDV0 = 0



   ;***************************************************************
   ;
   ;  End of channel 0 area.
   ;
__Skip_Ch_0



   ;***************************************************************
   ;
   ;  Channel 1 background music check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips music if left difficulty switch is set to A.
   ;
   if !switchleftb then AUDV1 = 0 : goto __Skip_Ch_1

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the channel 1 duration counter.
   ;
   _Ch1_Duration = _Ch1_Duration - 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips channel 1 if duration counter is greater than zero.
   ;
   if _Ch1_Duration then goto __Skip_Ch_1



   ;***************************************************************
   ;
   ;  Channel 1 background music.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 1 data.
   ;
   temp4 = sread(_SD_Music01)

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __BG_Music_Setup_01

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 1 data.
   ;
   temp5 = sread(_SD_Music01)
   temp6 = sread(_SD_Music01)

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 1.
   ;
   AUDV1 = temp4
   AUDC1 = temp5
   AUDF1 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets duration.
   ;
   _Ch1_Duration = sread(_SD_Music01)



   ;***************************************************************
   ;
   ;  End of channel 1 area.
   ;
__Skip_Ch_1



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  If the reset switch is not pressed, turn off reset
   ;  restrainer bit and jump to beginning of main loop.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop bank1

   ;```````````````````````````````````````````````````````````````
   ;  If the reset switch hasn't been released after being
   ;  pressed, jump to beginning of main loop.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop bank1

   ;```````````````````````````````````````````````````````````````
   ;  Reset pressed appropriately. Restart the program.
   ;
   goto __Start_Restart bank1





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  End of second section of main loop.
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for shot hitting wall.
   ;
   data _SD_Shot_Wall
   8,8,0
   1
   8,8,1
   1
   8,14,1
   1
   8,8,0
   1
   8,8,2
   1
   8,14,2
   1
   8,8,1
   1
   7,8,3
   1
   6,8,2
   1
   5,8,4
   1
   4,8,3
   1
   3,8,5
   1
   2,14,4
   4
   255
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for shooting missile.
   ;
   data _SD_Shoot_Miss
   8,15,0
   1
   12,15,1
   1
   8,7,20
   1
   10,15,3
   1
   8,7,22
   1
   10,15,5
   1
   8,15,6
   1
   10,7,24
   1
   8,15,8
   1
   9,7,27
   1
   8,15,10
   1
   7,14,11
   1
   6,15,12
   1
   5,6,13
   1
   4,15,14
   1
   3,6,27
   1
   2,6,30
   8
   255
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for shooting enemy.
   ;
   data _SD_Shoot_Enemy
   12,4,23
   4
   10,4,29
   4
   8,4,23
   4
   6,4,29
   4
   4,4,23
   4
   3,4,29
   4
   2,4,23
   1
   1,4,29
   1
   255
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for touching enemy.
   ;
   data _SD_Touch_Enemy
   2,7,11
   2
   10,7,12
   2
   8,7,13
   2
   8,7,14
   2
   8,7,21
   8
   4,7,22
   2
   2,7,23
   1
   255
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Channel 1 background music sound data.
   ;
__BG_Music_Setup_01

   sdata _SD_Music01 = u
   4,8,2
   1
   8,12,31
   8
   2,8,2
   1
   2,12,31
   8

   4,8,2
   1
   8,12,26
   11

   8,12,23
   8

   4,8,2
   1
   8,12,23
   8
   2,8,2
   1
   2,12,23
   8

   4,8,2
   1
   8,12,23
   8
   2,8,2
   1
   2,12,23
   8

   4,8,2
   1
   8,12,20
   8
   2,8,2
   1
   2,12,20
   8

   4,8,2
   1
   8,12,26
   8
   2,8,2
   1
   2,12,26
   8

   4,8,2
   1
   8,12,31
   8
   2,8,2
   1
   2,12,31
   8

   4,8,2
   1
   8,12,26
   8
   2,8,2
   1
   3,12,26
   8

   4,8,2
   1
   2,12,26
   8
   2,8,2
   1
   1,12,26
   8

   4,8,2
   1
   0,0,0
   8
   2,8,2
   1
   0,0,0
   8

   4,8,2
   1
   0,0,0
   8
   2,8,2
   1
   0,0,0
   8

   4,8,2
   1
   8,12,23
   8
   2,8,2
   1
   2,12,23
   8

   4,8,2
   1
   8,12,29
   8
   2,8,2
   1
   2,12,29
   8

   4,8,2
   1
   8,12,24
   8
   2,8,2
   1
   2,12,24
   8

   4,8,2
   1
   8,12,31
   8
   2,8,2
   1
   3,12,31
   8

   4,8,2
   1
   2,12,31
   8
   2,8,2
   1
   1,12,31
   8

   4,8,2
   1
   8,12,15
   8
   2,8,2
   1
   2,12,15
   8

   4,8,2
   1
   8,12,17
   8
   2,8,2
   1
   2,12,17
   8

   4,8,2
   1
   8,12,19
   8
   2,8,2
   1
   2,12,19
   8

   4,8,2
   1
   8,12,20
   8
   2,8,2
   1
   2,12,20
   8

   4,8,2
   1
   8,12,20
   8
   2,8,2
   1
   2,12,20
   8

   4,8,2
   1
   8,12,17
   8
   2,8,2
   1
   2,12,17
   8

   4,8,2
   1
   8,12,15
   8
   2,8,2
   1
   3,12,15
   8
   
   4,8,2
   1
   2,12,15
   8
   2,8,2
   1
   1,12,15
   8


   4,8,2
   1
   8,12,31
   8
   2,8,2
   1
   2,12,31
   8

   4,8,2
   1
   8,12,15
   8
   2,8,2
   1
   2,12,15
   8

   4,8,2
   1
   8,12,29
   8
   2,8,2
   1
   2,12,29
   8

   4,8,2
   1
   8,12,17
   8
   2,8,2
   1
   2,12,17
   8

   4,8,2
   1
   8,12,31
   8
   2,8,2
   1
   2,12,31
   8

   4,8,2
   1
   8,12,15
   8
   2,8,2
   1
   2,12,15
   8

   4,8,2
   1
   8,12,29
   8
   2,8,2
   1
   2,12,29
   8

   4,8,2
   1
   8,12,17
   8
   2,8,2
   1
   2,12,17
   8


   4,8,2
   1
   8,12,31
   8
   2,8,2
   1
   2,12,31
   8

   4,8,2
   1
   8,12,15
   8
   2,8,2
   1
   2,12,15
   8

   4,8,2
   1
   8,12,29
   8
   2,8,2
   1
   2,12,29
   8

   4,8,2
   1
   8,12,17
   8
   2,8,2
   1
   2,12,17
   8



   4,8,2
   1
   8,12,15
   8
   2,8,2
   1
   2,12,15
   8

   4,8,2
   1
   8,12,20
   8
   2,8,2
   1
   3,12,20
   8


   4,8,2
   1
   2,12,20
   8
   2,8,2
   1
   2,12,20
   8

   4,8,2
   1
   8,12,15
   8
   2,8,2
   1
   2,12,15
   8

   4,8,2
   1
   8,12,17
   8
   2,8,2
   1
   3,12,17
   8

   4,8,2
   1
   2,12,17
   8
   2,8,2
   1
   1,12,17
   8

   4,8,2
   1
   8,12,14
   8
   2,8,2
   1
   3,12,14
   8

   4,8,2
   1
   2,12,14
   8
   2,8,2
   1
   1,12,14
   8

   4,8,2
   1
   0,0,0
   8
   2,8,2
   1
   0,0,0
   8

   4,8,2
   1
   0,0,0
   8
   2,8,2
   1
   0,0,0
   8

   4,8,2
   1
   0,0,0
   8
   2,8,2
   1
   0,0,0
   8

   4,8,2
   1
   0,0,0
   8
   2,8,2
   1
   0,0,0
   8
   255
end

   _Ch1_Duration = 1

   goto __Skip_Ch_1

 

 

 

How to Check Score Digits

How to Check Score Digits on bB page.

 
   ;***************************************************************
   ;  Converts 6 digit score to 3 sets of two digits.
   ;  _sc1 holds the 100 thousands and 10 thousands
   ;  digits of the score. _sc2 holds the thousands and
   ;  hundreds digits of the score. _sc3 holds the tens
   ;  and ones digits of the score.
   ;
   dim _sc1 = score
   dim _sc2 = score+1
   dim _sc3 = score+2


   ;***************************************************************
   ;  How to check the digits:
   ;
   ;  100 thousands digit .. _sc1 & $F0 (X0 00 00)
   ;  10 thousands digit ... _sc1 & $0F (0X 00 00)
   ;
   ;  Thousands digit ...... _sc2 & $F0 (00 X0 00)
   ;  Hundreds digit ....... _sc2 & $0F (00 0X 00)
   ;
   ;  Tens digit ........... _sc3 & $F0 (00 00 X0)
   ;  Ones digit ........... _sc3 & $0F (00 00 0X)


   scorecolor = $FA


__Main_Loop


   ;***************************************************************
   ;
   ;  Fire button check.
   ;
   ;
   if !joy0fire then goto __Skip_FireB

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the thousands digit.
   ;
   temp5 = _sc2 & $F0

   ;```````````````````````````````````````````````````````````````
   ;  Add points to score.
   ;
   score = score + 10

   ;```````````````````````````````````````````````````````````````
   ;  Grabs the thousands digit.
   ;
   temp6 = _sc2 & $F0

   ;```````````````````````````````````````````````````````````````
   ;  Skips this part if thousands digit has NOT changed.
   ;  
   if temp5 = temp6 then goto __Skip_FireB

   COLUBK = $B4 : c = 45

__Skip_FireB


   if c then c = c - 1 : if !c then COLUBK = 0


   drawscreen


   goto __Main_Loop

 

 

 

Saving a High Score

Saving a High Score on bB page.

 
   ;***************************************************************
   ;
   ;  Save High Score
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;  High score code provided by supercat and polished up
   ;  by Nukey Shay.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Move the joystick to increase the score. Press the fire
   ;  button to end the fake game and the score will flip
   ;  between the current score and the high score every 2
   ;  seconds on the game over screen. Press the fire button or
   ;  reset switch to go back to the fake game.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  _Master_Counter can be used for many things, but it is 
   ;  really useful for animating sprite frames when used
   ;  with _Frame_Counter.
   ;
   dim _Master_Counter = a
   dim _Frame_Counter = b

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used for auto-play in the main loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play.
   ;
   dim _AP_2_Sec_Score_Flip = k

   ;```````````````````````````````````````````````````````````````
   ;  These can be used for other things using different aliases,
   ;  but for the game over loop and auto-play in the main loop,
   ;  they are used to temporarily remember the score for the 2
   ;  second score/high score flip.
   ;
   dim _Score1_Mem = s
   dim _Score2_Mem = t
   dim _Score3_Mem = u

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the high score until the game is turned off.
   ;
   dim _High_Score1 = v
   dim _High_Score2 = w
   dim _High_Score3 = x

   ;```````````````````````````````````````````````````````````````
   ;  All-purpose bits for various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y
   dim _Bit1_FireB_Restrainer = y
   dim _Bit2_Game_Control = y
   dim _Bit3_Auto_Play = y
   dim _Bit6_Swap_Scores = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers. 
   ;
   dim rand16 = z

   ;```````````````````````````````````````````````````````````````
   ;  Converts 6 digit score to 3 sets of two digits.
   ;
   ;  The 100 thousands and 10 thousands digits are held by _sc1.
   ;  The thousands and hundreds digits are held by _sc2.
   ;  The tens and ones digits are held by _sc3.
   ;
   dim _sc1 = score
   dim _sc2 = score+1
   dim _sc3 = score+2





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears 21 of the normal 26 variables (fastest way using asm).
   ;  Do not clear v, w, x, y, or z in this program. The variables
   ;  v through x remember the high score. The variable y holds a
   ;  bit that should not be cleared. The variable z is used for
   ;  random numbers in this program and clearing it would mess
   ;  up those random numbers.
   ;
   asm
   LDA #0
   STA a
   STA b
   STA c
   STA d
   STA e
   STA f
   STA g
   STA h
   STA i
   STA j
   STA k
   STA l
   STA m
   STA n
   STA o
   STA p
   STA q
   STA r
   STA s
   STA t
   STA u
end


   ;***************************************************************
   ;
   ;  Clears 7 of the 8 bits.
   ;
   ;  Bit 2 is not cleared because _Bit2_Game_Control{2} is used
   ;  to control how the program is reset.
   ;
   _BitOp_01 = _BitOp_01 & %00000100


   ;***************************************************************
   ;
   ;  Game control bit tells program where to go.
   ;
   ;  0 = Go to title screen.
   ;  1 = Skip title screen and play game.
   ;
   if _Bit2_Game_Control{2} then goto __Main_Loop_Setup 





   ;***************************************************************
   ;***************************************************************
   ;
   ;   TITLE SCREEN SETUP
   ;
   ;
__Setup_Title_Screen


   ;***************************************************************
   ;
   ;  Sets score color for title screen.
   ;
   scorecolor = 0


   ;***************************************************************
   ;
   ;  Sets title screen background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after entering a different segment
   ;  of the program. It also does double duty by restraining the
   ;  fire button in the title screen loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets up title screen playfield.
   ;
   playfield:
   .XXXXXX.XXXXXX.XXXXXXXXXX.XXXXX.
   .XX.....XX..XX.XX..XX..XX.XX....
   .XX.XXX.XXXXXX.XX..XX..XX.XXXX..
   .XX..XX.XX..XX.XX..XX..XX.XX....
   .XXXXXX.XX..XX.XX..XX..XX.XXXXX.
   ................................
   ..XXXXXX.XX.XXXXXX.XX....XXXXX..
   ....XX...XX...XX...XX....XX.....
   ....XX...XX...XX...XX....XXXX...
   ....XX...XX...XX...XX....XX.....
   ....XX...XX...XX...XXXXX.XXXXX..
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  TITLE SCREEN LOOP
   ;
   ;
__Title_Screen_Loop



   ;***************************************************************
   ;
   ;  Sets title screen playfield pixel color.
   ;
   COLUPF = $2C



   ;***************************************************************
   ;
   ;  Auto-play check.
   ;
   ;  Switches to auto-play after 10 seconds if player doesn't
   ;  start the game.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increment _Master_Counter.
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if counter is less than one second.
   ;
   if _Master_Counter < 60 then goto __TS_AP_Skip

   ;```````````````````````````````````````````````````````````````
   ;  Increments _Frame_Counter and clears _Master_Counter.
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check.
   ;
   ;  Turns on auto-play and jumps to main loop setup if 10 
   ;  seconds have gone by.
   ;
   if _Frame_Counter > 9 then _Bit3_Auto_Play{3} = 1 : goto __Main_Loop_Setup

__TS_AP_Skip



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset/fire button check and end of title screen loop.
   ;  
   ;  Starts the game if the reset switch or the fire button
   ;  is pressed appropriately.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and jumps to beginning of title 
   ;  screen loop if fire button or reset switch is not pressed.
   ;
   if !switchreset && !joy0fire then _Bit0_Reset_Restrainer{0} = 0 : goto __Title_Screen_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of title screen loop if reset or fire 
   ;  hasn't been released since starting title screen loop.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Title_Screen_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Sets control bit so program will jump to main loop setup.
   ;
   _Bit2_Game_Control{2} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Restarts game and program jumps to main loop setup.
   ;
   goto __Start_Restart





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP SETUP
   ;
   ;
__Main_Loop_Setup


   ;***************************************************************
   ;
   ;  In the main loop, _Bit2_Game_Control{2} controls when the
   ;  game ends.
   ;
   ;  0 = Game not over.
   ;  1 = Game over.
   ;
   _Bit2_Game_Control{2} = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed in the title
   ;  screen section or the game over section. If the reset
   ;  switch isn't being held down, this bit will be cleared
   ;  in the main loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Restrains the fire button for the main loop.
   ;
   ;  This bit fixes it so the fire button becomes inactive if it
   ;  hasn't been released after being pressed in the title
   ;  screen section or the game over section. If the fire
   ;  button isn't being held down, this bit will be cleared
   ;  in the main loop.
   ;
   _Bit1_FireB_Restrainer{1} = 1


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = $80


   ;***************************************************************
   ;
   ;  Sets score color.
   ;
   scorecolor = $AE


   ;***************************************************************
   ;
   ;  Sets up the main loop playfield.
   ;
   playfield:
   ................................
   ................................
   ................................
   .XXXXXX.XXXXXX.XXXXXXXXXX.XXXXX.
   .XX.....XX..XX.XX..XX..XX.XX....
   .XX.XXX.XXXXXX.XX..XX..XX.XXXX..
   .XX..XX.XX..XX.XX..XX..XX.XX....
   .XXXXXX.XX..XX.XX..XX..XX.XXXXX.
   ................................
   ................................
   ................................
end


   ;***************************************************************
   ;
   ;  Auto-play score swap setup.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears score and skips section if auto-play is off.
   ;
   if !_Bit3_Auto_Play{3} then score = 0 : goto __AP_Skip_AP_Setup

   ;```````````````````````````````````````````````````````````````
   ;  Clears variables.
   ;
   _Master_Counter = 0 : _Frame_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Sets up the score swap, clears the swap bit, sets background
   ;  color, and draws auto-play screen.
   ;
   _Score1_Mem = _sc1 : _Score2_Mem = _sc2 : _Score3_Mem = _sc3

   _Bit6_Swap_Scores{6} = 0 : COLUBK = $30

   playfield:
   ..XXXXXX.XX..XX.XXXXXX.XXXXXX...
   ..XX..XX.XX..XX...XX...XX..XX...
   ..XXXXXX.XX..XX...XX...XX..XX...
   ..XX..XX.XX..XX...XX...XX..XX...
   ..XX..XX.XXXXXX...XX...XXXXXX...
   ................................
   ..XXXXXX.XX.....XXXXXX.XX..XX...
   ..XX..XX.XX.....XX..XX.XX..XX...
   ..XXXXXX.XX.....XXXXXX.XXXXXX...
   ..XX.....XX.....XX..XX...XX.....
   ..XX.....XXXXXX.XX..XX...XX.....
end

__AP_Skip_AP_Setup





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE GAME GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets playfield pixel color.
   ;
   COLUPF = $9A



   ;***************************************************************
   ;
   ;  Auto-play playfield pixel color.
   ;
   if _Bit3_Auto_Play{3} then COLUPF = $3A



   ;***************************************************************
   ;
   ;  Slows down the joystick and adds 10 to the score if the
   ;  joystick is moved.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments the counter.
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if auto-play is off.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Skips section if master counter is less than 2 seconds.
   ;  The master counter resets every 2 seconds (60 + 60 = 120).
   ;
   if _Master_Counter < 120 then goto __Skip_Joystick_Check

   ;```````````````````````````````````````````````````````````````
   ;  Increments frame counter and clears master counter.
   ;  (One increment = 2 seconds.)
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Ends auto-play if 10 seconds have gone by.
   ;
   if _Frame_Counter > 4 then _Bit2_Game_Control{2} = 1

   goto __Skip_Joystick_Check

__AP_Skip_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Skip this section if the counter is less than 8.
   ;
   if _Master_Counter < 8 then goto __Skip_Joystick_Check

   ;```````````````````````````````````````````````````````````````
   ;  Clears the counter.
   ;
   _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Adds 10 points to the score if joystick is moved.
   ;
   if !joy0up && !joy0down && !joy0left && !joy0right then goto __Skip_Joystick_Check

   score = score + 10

__Skip_Joystick_Check



   ;***************************************************************
   ;
   ;  Fire button section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and skips this section if the fire
   ;  button is not pressed.
   ;
   if !joy0fire then _Bit1_FireB_Restrainer{1} = 0 : goto __Done_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the fire button hasn't been released
   ;  since starting.
   ;
   if _Bit1_FireB_Restrainer{1} then goto __Done_Fire

   ;```````````````````````````````````````````````````````````````
   ;  For this example, the fire button ends the program.
   ;
   _Bit2_Game_Control{2} = 1

__Done_Fire



   ;***************************************************************
   ;
   ;  Auto-play score flipper.
   ;
   ;  Flips between high score and current score.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if auto-play bit is not on.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Flip

   ;```````````````````````````````````````````````````````````````
   ;  Increments the auto play 2-second counter.
   ;
   _AP_2_Sec_Score_Flip = _AP_2_Sec_Score_Flip + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if auto play 2-second counter is less
   ;  than 2 seconds (120 = 2 seconds).
   ;
   if _AP_2_Sec_Score_Flip < 120 then goto __AP_Skip_Flip

   ;```````````````````````````````````````````````````````````````
   ;  Clears the 2-second counter and flips the score swapping bit.
   ;
   _AP_2_Sec_Score_Flip = 0 : _Bit6_Swap_Scores{6} = !_Bit6_Swap_Scores{6}

   ;```````````````````````````````````````````````````````````````
   ;  Skips high score swap if swap bit is off.
   ;
   if !_Bit6_Swap_Scores{6} then goto __AP_Skip_HiScore_Swap

   ;```````````````````````````````````````````````````````````````
   ;  Displays high score (yellow) and skips rest of section.
   ;
   scorecolor = $1C

   _sc1 = _High_Score1 : _sc2 = _High_Score2 : _sc3 = _High_Score3

   goto __AP_Skip_Flip

__AP_Skip_HiScore_Swap

   ;```````````````````````````````````````````````````````````````
   ;  Displays current score (blue).
   ;
   scorecolor = $AE

   _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem

__AP_Skip_Flip



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Game Over Check
   ;
   ;  _Bit2_Game_Control{2} controls when the game ends.
   ;
   ;  0 = Game not over.
   ;  1 = Game over.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if game control bit is off.
   ;
   if !_Bit2_Game_Control{2} then goto __Skip_Check_G_Over

   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check. Puts score back to current score and jumps
   ;  back to the title screen if auto-play bit is on.
   ;
   if _Bit3_Auto_Play{3} then _Bit2_Game_Control{2} = 0 : _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem : goto __Start_Restart

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to game over set up.
   ;
   goto __Game_Over_Setup

__Skip_Check_G_Over



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Reset

   ;```````````````````````````````````````````````````````````````
   ;  Starts game during auto-play if reset switch or fire button
   ;  is pressed. Also clears auto-play bit and sets game control
   ;  bit so game will start instead of going to title screen.
   ;
   if switchreset || joy0fire then _Bit3_Auto_Play{3} = 0 : _Bit2_Game_Control{2} = 1 : goto __Start_Restart

__AP_Skip_Reset

   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Clears the game over bit so the title screen will appear.
   ;
   _Bit2_Game_Control{2} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the game over setup section and checks for a high
   ;  score, then jumps to the title screen.
   ;
   goto __Game_Over_Setup




   ;***************************************************************
   ;***************************************************************
   ;
   ;  GAME OVER SETUP
   ;
   ;
__Game_Over_Setup


   ;***************************************************************
   ;
   ;  High score check.
   ;
   ;  Checks for a new high score.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Checks first byte.
   ;
   if _sc1 > _High_Score1 then goto __New_High_Score
   if _sc1 < _High_Score1 then goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  First byte equal. Checks second byte.
   ;
   if _sc2 > _High_Score2 then goto __New_High_Score
   if _sc2 < _High_Score2 then goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  Second byte equal. Checks third byte.
   ;
   if _sc3 > _High_Score3 then goto __New_High_Score
   if _sc3 < _High_Score3 then goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  All bytes equal. Skips high score.
   ;
   goto __Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  All bytes not equal. New high score!
   ;
__New_High_Score

   _High_Score1 = _sc1 : _High_Score2 = _sc2 : _High_Score3 = _sc3

__Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the game if the reset switch was pressed. Continues
   ;  in the game over setup section if the game ended naturally.
   ;
   if !_Bit2_Game_Control{2} then goto __Start_Restart


   ;***************************************************************
   ;
   ;  Saves the latest score for the high score flip.
   ;
   _Score1_Mem = _sc1 : _Score2_Mem = _sc2 : _Score3_Mem = _sc3

   ;***************************************************************
   ;
   ;  Clears the counters.
   ;
   _Master_Counter = 0 : _Frame_Counter = 0


   ;***************************************************************
   ;
   ;  Restrains reset switch and fire button for GAME OVER loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after entering a different segment
   ;  of the program. It does double duty by restraining the
   ;  fire button too in the GAME OVER loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1 


   ;***************************************************************
   ;
   ;  Sets up GAME OVER playfield.
   ;
   playfield:
   .XXXXXX.XXXXXX.XXXXXXXXXX.XXXXX.
   .XX.....XX..XX.XX..XX..XX.XX....
   .XX.XXX.XXXXXX.XX..XX..XX.XXXX..
   .XX..XX.XX..XX.XX..XX..XX.XX....
   .XXXXXX.XX..XX.XX..XX..XX.XXXXX.
   ................................
   ...XXXXXX.XX..XX.XXXXX.XXXXXX...
   ...XX..XX.XX..XX.XX....XX..XX...
   ...XX..XX.XX..XX.XXXX..XXXXX....
   ...XX..XX.XX..XX.XX....XX..XX...
   ...XXXXXX...XX...XXXXX.XX..XX...
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  GAME OVER LOOP
   ;
   ; 
__Game_Over_Loop



   ;***************************************************************
   ;
   ;  20 second counter.
   ;
   ;  This includes a 2 second countdown timer. Any Atari 2600
   ;  game should disable the fire button for 2 seconds when
   ;  the game is over to keep the player from restarting by
   ;  mistake. It is part of the usual standards and procedures.
   ;
   ;  This section also flips between the current score and the
   ;  high score every 2 seconds. It jumps to the title screen
   ;  after 20 seconds if the player does nothing.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments master counter every frame (60 frames = 1 second).
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if master counter is less than 2 seconds.
   ;  The master counter resets every 2 seconds (60 + 60 = 120).
   ;
   if _Master_Counter < 120 then goto __Skip_20_Second_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Increments frame counter and clears master counter.
   ;  (One increment = 2 seconds.)
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Restores the current score, resets the game, and goes to the
   ;  title screen if 20 seconds have gone by.
   ;
   ;  0 = Go to title screen.
   ;  1 = Skip title screen and play game.
   ;
   if _Frame_Counter > 9 then _Bit2_Game_Control{2} = 0 : _sc1=_Score1_Mem : _sc2=_Score2_Mem : _sc3=_Score3_Mem: goto __Start_Restart

   ;```````````````````````````````````````````````````````````````
   ;  Flips the score swapping bit.
   ;
   _Bit6_Swap_Scores{6} = !_Bit6_Swap_Scores{6}

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to current score if swap bit is off.
   ;
   if !_Bit6_Swap_Scores{6} then goto __GO_Current_Score

   ;```````````````````````````````````````````````````````````````
   ;  Displays high score (yellow) and skips rest of section.
   ;
   scorecolor = $1C

   _sc1 = _High_Score1 : _sc2 = _High_Score2 : _sc3 = _High_Score3

   goto __Skip_20_Second_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Displays current score (blue).
   ;
__GO_Current_Score

   scorecolor = $AE

   _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem

__Skip_20_Second_Counter



   ;***************************************************************
   ;
   ;  Sets background color and playfield color.
   ;
   COLUBK = $44 : COLUPF = $2C

   ;```````````````````````````````````````````````````````````````
   ;  Changes colors after 2 seconds. This is only done to let
   ;  you, the programmer, know when 2 seconds have gone by. The
   ;  color change doesn't need to happen in a real game.
   ;
   if _Frame_Counter > 0 then COLUBK = $D2 : COLUPF = $DA



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset/fire button check and end of game over loop.
   ;  
   ;  Restarts the program if the reset switch or the fire
   ;  button is pressed appropriately.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the game over loop if the initial
   ;  2 second freeze is not over.
   ;
   if _Frame_Counter = 0 then goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and jumps to beginning of game
   ;  over loop if fire button or reset switch is not pressed.
   ;
   if !switchreset && !joy0fire then _Bit0_Reset_Restrainer{0} = 0 : goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the game over loop if fire button
   ;  hasn't been released since leaving the main loop.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  The program is restarted.
   ;
   goto __Start_Restart

 

 

 

Saving a High Score (asm)

Saving a High Score (asm) on bB page.

 
   ;***************************************************************
   ;
   ;  Save High Score
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;  High score code provided by supercat and polished up
   ;  by Nukey Shay.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Move the joystick to increase the score. Press the fire
   ;  button to end the fake game and the score will flip
   ;  between the current score and the high score every 2
   ;  seconds on the game over screen. Press the fire button or
   ;  reset switch to go back to the fake game.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  _Master_Counter can be used for many things, but it is 
   ;  really useful for animating sprite frames when used
   ;  with _Frame_Counter.
   ;
   dim _Master_Counter = a
   dim _Frame_Counter = b

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used for auto-play in the main loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with auto-play.
   ;
   dim _AP_2_Sec_Score_Flip = k

   ;```````````````````````````````````````````````````````````````
   ;  These can be used for other things using different aliases,
   ;  but for the game over loop and auto-play in the main loop,
   ;  they are used to temporarily remember the score for the 2
   ;  second score/high score flip.
   ;
   dim _Score1_Mem = s
   dim _Score2_Mem = t
   dim _Score3_Mem = u

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the high score until the game is turned off.
   ;
   dim _High_Score1 = v
   dim _High_Score2 = w
   dim _High_Score3 = x

   ;```````````````````````````````````````````````````````````````
   ;  All-purpose bits for various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y
   dim _Bit1_FireB_Restrainer = y
   dim _Bit2_Game_Control = y
   dim _Bit3_Auto_Play = y
   dim _Bit6_Swap_Scores = y

   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers. 
   ;
   dim rand16 = z

   ;```````````````````````````````````````````````````````````````
   ;  Converts 6 digit score to 3 sets of two digits.
   ;
   ;  The 100 thousands and 10 thousands digits are held by _sc1.
   ;  The thousands and hundreds digits are held by _sc2.
   ;  The tens and ones digits are held by _sc3.
   ;
   dim _sc1 = score
   dim _sc2 = score+1
   dim _sc3 = score+2





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears 21 of the normal 26 variables (fastest way using asm).
   ;  Do not clear v, w, x, y, or z in this program. The variables
   ;  v through x remember the high score. The variable y holds a
   ;  bit that should not be cleared. The variable z is used for
   ;  random numbers in this program and clearing it would mess
   ;  up those random numbers.
   ;
   asm
   LDA #0
   STA a
   STA b
   STA c
   STA d
   STA e
   STA f
   STA g
   STA h
   STA i
   STA j
   STA k
   STA l
   STA m
   STA n
   STA o
   STA p
   STA q
   STA r
   STA s
   STA t
   STA u
end


   ;***************************************************************
   ;
   ;  Clears 7 of the 8 bits.
   ;
   ;  Bit 2 is not cleared because _Bit2_Game_Control{2} is used
   ;  to control how the program is reset.
   ;
   _BitOp_01 = _BitOp_01 & %00000100


   ;***************************************************************
   ;
   ;  Game control bit tells program where to go.
   ;
   ;  0 = Go to title screen.
   ;  1 = Skip title screen and play game.
   ;
   if _Bit2_Game_Control{2} then goto __Main_Loop_Setup 





   ;***************************************************************
   ;***************************************************************
   ;
   ;   TITLE SCREEN SETUP
   ;
   ;
__Setup_Title_Screen


   ;***************************************************************
   ;
   ;  Sets score color for title screen.
   ;
   scorecolor = 0


   ;***************************************************************
   ;
   ;  Sets title screen background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after entering a different segment
   ;  of the program. It also does double duty by restraining the
   ;  fire button in the title screen loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets up title screen playfield.
   ;
   playfield:
   .XXXXXX.XXXXXX.XXXXXXXXXX.XXXXX.
   .XX.....XX..XX.XX..XX..XX.XX....
   .XX.XXX.XXXXXX.XX..XX..XX.XXXX..
   .XX..XX.XX..XX.XX..XX..XX.XX....
   .XXXXXX.XX..XX.XX..XX..XX.XXXXX.
   ................................
   ..XXXXXX.XX.XXXXXX.XX....XXXXX..
   ....XX...XX...XX...XX....XX.....
   ....XX...XX...XX...XX....XXXX...
   ....XX...XX...XX...XX....XX.....
   ....XX...XX...XX...XXXXX.XXXXX..
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  TITLE SCREEN LOOP
   ;
   ;
__Title_Screen_Loop



   ;***************************************************************
   ;
   ;  Sets title screen playfield pixel color.
   ;
   COLUPF = $2C



   ;***************************************************************
   ;
   ;  Auto-play check.
   ;
   ;  Switches to auto-play after 10 seconds if player doesn't
   ;  start the game.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increment _Master_Counter.
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if counter is less than one second.
   ;
   if _Master_Counter < 60 then goto __TS_AP_Skip

   ;```````````````````````````````````````````````````````````````
   ;  Increments _Frame_Counter and clears _Master_Counter.
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check.
   ;
   ;  Turns on auto-play and jumps to main loop setup if 10 
   ;  seconds have gone by.
   ;
   if _Frame_Counter > 9 then _Bit3_Auto_Play{3} = 1 : goto __Main_Loop_Setup

__TS_AP_Skip



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset/fire button check and end of title screen loop.
   ;  
   ;  Starts the game if the reset switch or the fire button
   ;  is pressed appropriately.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and jumps to beginning of title 
   ;  screen loop if fire button or reset switch is not pressed.
   ;
   if !switchreset && !joy0fire then _Bit0_Reset_Restrainer{0} = 0 : goto __Title_Screen_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of title screen loop if reset or fire 
   ;  hasn't been released since starting title screen loop.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Title_Screen_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Sets control bit so program will jump to main loop setup.
   ;
   _Bit2_Game_Control{2} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Restarts game and program jumps to main loop setup.
   ;
   goto __Start_Restart





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP SETUP
   ;
   ;
__Main_Loop_Setup


   ;***************************************************************
   ;
   ;  In the main loop, _Bit2_Game_Control{2} controls when the
   ;  game ends.
   ;
   ;  0 = Game not over.
   ;  1 = Game over.
   ;
   _Bit2_Game_Control{2} = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed in the title
   ;  screen section or the game over section. If the reset
   ;  switch isn't being held down, this bit will be cleared
   ;  in the main loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Restrains the fire button for the main loop.
   ;
   ;  This bit fixes it so the fire button becomes inactive if it
   ;  hasn't been released after being pressed in the title
   ;  screen section or the game over section. If the fire
   ;  button isn't being held down, this bit will be cleared
   ;  in the main loop.
   ;
   _Bit1_FireB_Restrainer{1} = 1


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = $80


   ;***************************************************************
   ;
   ;  Sets score color.
   ;
   scorecolor = $AE


   ;***************************************************************
   ;
   ;  Sets up the main loop playfield.
   ;
   playfield:
   ................................
   ................................
   ................................
   .XXXXXX.XXXXXX.XXXXXXXXXX.XXXXX.
   .XX.....XX..XX.XX..XX..XX.XX....
   .XX.XXX.XXXXXX.XX..XX..XX.XXXX..
   .XX..XX.XX..XX.XX..XX..XX.XX....
   .XXXXXX.XX..XX.XX..XX..XX.XXXXX.
   ................................
   ................................
   ................................
end


   ;***************************************************************
   ;
   ;  Auto-play score swap setup.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears score and skips section if auto-play is off.
   ;
   if !_Bit3_Auto_Play{3} then score = 0 : goto __AP_Skip_AP_Setup

   ;```````````````````````````````````````````````````````````````
   ;  Clears variables.
   ;
   _Master_Counter = 0 : _Frame_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Sets up the score swap, clears the swap bit, sets background
   ;  color, and draws auto-play screen.
   ;
   _Score1_Mem = _sc1 : _Score2_Mem = _sc2 : _Score3_Mem = _sc3

   _Bit6_Swap_Scores{6} = 0 : COLUBK = $30

   playfield:
   ..XXXXXX.XX..XX.XXXXXX.XXXXXX...
   ..XX..XX.XX..XX...XX...XX..XX...
   ..XXXXXX.XX..XX...XX...XX..XX...
   ..XX..XX.XX..XX...XX...XX..XX...
   ..XX..XX.XXXXXX...XX...XXXXXX...
   ................................
   ..XXXXXX.XX.....XXXXXX.XX..XX...
   ..XX..XX.XX.....XX..XX.XX..XX...
   ..XXXXXX.XX.....XXXXXX.XXXXXX...
   ..XX.....XX.....XX..XX...XX.....
   ..XX.....XXXXXX.XX..XX...XX.....
end

__AP_Skip_AP_Setup





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE GAME GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets playfield pixel color.
   ;
   COLUPF = $9A



   ;***************************************************************
   ;
   ;  Auto-play playfield pixel color.
   ;
   if _Bit3_Auto_Play{3} then COLUPF = $3A



   ;***************************************************************
   ;
   ;  Slows down the joystick and adds 10 to the score if the
   ;  joystick is moved.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments the counter.
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if auto-play is off.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Skips section if master counter is less than 2 seconds.
   ;  The master counter resets every 2 seconds (60 + 60 = 120).
   ;
   if _Master_Counter < 120 then goto __Skip_Joystick_Check

   ;```````````````````````````````````````````````````````````````
   ;  Increments frame counter and clears master counter.
   ;  (One increment = 2 seconds.)
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Ends auto-play if 10 seconds have gone by.
   ;
   if _Frame_Counter > 4 then _Bit2_Game_Control{2} = 1

   goto __Skip_Joystick_Check

__AP_Skip_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Skip this section if the counter is less than 8.
   ;
   if _Master_Counter < 8 then goto __Skip_Joystick_Check

   ;```````````````````````````````````````````````````````````````
   ;  Clears the counter.
   ;
   _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Adds 10 points to the score if joystick is moved.
   ;
   if !joy0up && !joy0down && !joy0left && !joy0right then goto __Skip_Joystick_Check

   score = score + 10

__Skip_Joystick_Check



   ;***************************************************************
   ;
   ;  Fire button section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and skips this section if the fire
   ;  button is not pressed.
   ;
   if !joy0fire then _Bit1_FireB_Restrainer{1} = 0 : goto __Done_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the fire button hasn't been released
   ;  since starting.
   ;
   if _Bit1_FireB_Restrainer{1} then goto __Done_Fire

   ;```````````````````````````````````````````````````````````````
   ;  For this example, the fire button ends the program.
   ;
   _Bit2_Game_Control{2} = 1

__Done_Fire



   ;***************************************************************
   ;
   ;  Auto-play score flipper.
   ;
   ;  Flips between high score and current score.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if auto-play bit is not on.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Flip

   ;```````````````````````````````````````````````````````````````
   ;  Increments the auto play 2-second counter.
   ;
   _AP_2_Sec_Score_Flip = _AP_2_Sec_Score_Flip + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if auto play 2-second counter is less
   ;  than 2 seconds (120 = 2 seconds).
   ;
   if _AP_2_Sec_Score_Flip < 120 then goto __AP_Skip_Flip

   ;```````````````````````````````````````````````````````````````
   ;  Clears the 2-second counter and flips the score swapping bit.
   ;
   _AP_2_Sec_Score_Flip = 0 : _Bit6_Swap_Scores{6} = !_Bit6_Swap_Scores{6}

   ;```````````````````````````````````````````````````````````````
   ;  Skips high score swap if swap bit is off.
   ;
   if !_Bit6_Swap_Scores{6} then goto __AP_Skip_HiScore_Swap

   ;```````````````````````````````````````````````````````````````
   ;  Displays high score (yellow) and skips rest of section.
   ;
   scorecolor = $1C

   _sc1 = _High_Score1 : _sc2 = _High_Score2 : _sc3 = _High_Score3

   goto __AP_Skip_Flip

__AP_Skip_HiScore_Swap

   ;```````````````````````````````````````````````````````````````
   ;  Displays current score (blue).
   ;
   scorecolor = $AE

   _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem

__AP_Skip_Flip



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Game Over Check
   ;
   ;  _Bit2_Game_Control{2} controls when the game ends.
   ;
   ;  0 = Game not over.
   ;  1 = Game over.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if game control bit is off.
   ;
   if !_Bit2_Game_Control{2} then goto __Skip_Check_G_Over

   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check. Puts score back to current score and jumps
   ;  back to the title screen if auto-play bit is on.
   ;
   if _Bit3_Auto_Play{3} then _Bit2_Game_Control{2} = 0 : _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem : goto __Start_Restart

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to game over set up.
   ;
   goto __Game_Over_Setup

__Skip_Check_G_Over



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Auto-play check.
   ;
   if !_Bit3_Auto_Play{3} then goto __AP_Skip_Reset

   ;```````````````````````````````````````````````````````````````
   ;  Starts game during auto-play if reset switch or fire button
   ;  is pressed. Also clears auto-play bit and sets game control
   ;  bit so game will start instead of going to title screen.
   ;
   if switchreset || joy0fire then _Bit3_Auto_Play{3} = 0 : _Bit2_Game_Control{2} = 1 : goto __Start_Restart

__AP_Skip_Reset

   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Clears the game over bit so the title screen will appear.
   ;
   _Bit2_Game_Control{2} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the game over setup section and checks for a high
   ;  score, then jumps to the title screen.
   ;
   goto __Game_Over_Setup




   ;***************************************************************
   ;***************************************************************
   ;
   ;  GAME OVER SETUP
   ;
   ;
__Game_Over_Setup


   ;***************************************************************
   ;
   ;  High score check using asm.
   ;
   ;  The original supercat code was adapted by Karl G with input
   ;  from bogax.
   ;
   asm
   sed                    ; Set the Decimal Mode Flag
   lda _High_Score3       ; Load the Accumulator
   cmp _sc3               ; Compare Memory and the Accumulator
   lda _High_Score2       ; Load the Accumulator
   sbc _sc2               ; Subtract With Carry
   lda _High_Score1       ; Load the Accumulator
   sbc _sc1               ; Subtract With Carry
   cld                    ; Clear the Decimal Flag
   bcs .__Skip_High_Score ; Branch if Carry Set
                          ; (goto label if carry is set)
end

   ;```````````````````````````````````````````````````````````````
   ;  New high score!
   ;
   _High_Score1 = _sc1 : _High_Score2 = _sc2 : _High_Score3 = _sc3

__Skip_High_Score

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the game if the reset switch was pressed. Continues
   ;  in the game over setup section if the game ended naturally.
   ;
   if !_Bit2_Game_Control{2} then goto __Start_Restart


   ;***************************************************************
   ;
   ;  Saves the latest score for the high score flip.
   ;
   _Score1_Mem = _sc1 : _Score2_Mem = _sc2 : _Score3_Mem = _sc3


   ;***************************************************************
   ;
   ;  Clears the counters.
   ;
   _Master_Counter = 0 : _Frame_Counter = 0


   ;***************************************************************
   ;
   ;  Restrains reset switch and fire button for GAME OVER loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after entering a different segment
   ;  of the program. It does double duty by restraining the
   ;  fire button too in the GAME OVER loop.
   ;
   _Bit0_Reset_Restrainer{0} = 1 


   ;***************************************************************
   ;
   ;  Sets up GAME OVER playfield.
   ;
   playfield:
   .XXXXXX.XXXXXX.XXXXXXXXXX.XXXXX.
   .XX.....XX..XX.XX..XX..XX.XX....
   .XX.XXX.XXXXXX.XX..XX..XX.XXXX..
   .XX..XX.XX..XX.XX..XX..XX.XX....
   .XXXXXX.XX..XX.XX..XX..XX.XXXXX.
   ................................
   ...XXXXXX.XX..XX.XXXXX.XXXXXX...
   ...XX..XX.XX..XX.XX....XX..XX...
   ...XX..XX.XX..XX.XXXX..XXXXX....
   ...XX..XX.XX..XX.XX....XX..XX...
   ...XXXXXX...XX...XXXXX.XX..XX...
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  GAME OVER LOOP
   ;
   ; 
__Game_Over_Loop



   ;***************************************************************
   ;
   ;  20 second counter.
   ;
   ;  This includes a 2 second countdown timer. Any Atari 2600
   ;  game should disable the fire button for 2 seconds when
   ;  the game is over to keep the player from restarting by
   ;  mistake. It is part of the usual standards and procedures.
   ;
   ;  This section also flips between the current score and the
   ;  high score every 2 seconds. It jumps to the title screen
   ;  after 20 seconds if the player does nothing.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments master counter every frame (60 frames = 1 second).
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if master counter is less than 2 seconds.
   ;  The master counter resets every 2 seconds (60 + 60 = 120).
   ;
   if _Master_Counter < 120 then goto __Skip_20_Second_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Increments frame counter and clears master counter.
   ;  (One increment = 2 seconds.)
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Restores the current score, resets the game, and goes to the
   ;  title screen if 20 seconds have gone by.
   ;
   ;  0 = Go to title screen.
   ;  1 = Skip title screen and play game.
   ;
   if _Frame_Counter > 9 then _Bit2_Game_Control{2} = 0 : _sc1=_Score1_Mem : _sc2=_Score2_Mem : _sc3=_Score3_Mem: goto __Start_Restart

   ;```````````````````````````````````````````````````````````````
   ;  Flips the score swapping bit.
   ;
   _Bit6_Swap_Scores{6} = !_Bit6_Swap_Scores{6}

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to current score if swap bit is off.
   ;
   if !_Bit6_Swap_Scores{6} then goto __GO_Current_Score

   ;```````````````````````````````````````````````````````````````
   ;  Displays high score (yellow) and skips rest of section.
   ;
   scorecolor = $1C

   _sc1 = _High_Score1 : _sc2 = _High_Score2 : _sc3 = _High_Score3

   goto __Skip_20_Second_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Displays current score (blue).
   ;
__GO_Current_Score

   scorecolor = $AE

   _sc1 = _Score1_Mem : _sc2 = _Score2_Mem : _sc3 = _Score3_Mem

__Skip_20_Second_Counter



   ;***************************************************************
   ;
   ;  Sets background color and playfield color.
   ;
   COLUBK = $44 : COLUPF = $2C

   ;```````````````````````````````````````````````````````````````
   ;  Changes colors after 2 seconds. This is only done to let
   ;  you, the programmer, know when 2 seconds have gone by. The
   ;  color change doesn't need to happen in a real game.
   ;
   if _Frame_Counter > 0 then COLUBK = $D2 : COLUPF = $DA



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset/fire button check and end of game over loop.
   ;  
   ;  Restarts the program if the reset switch or the fire
   ;  button is pressed appropriately.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the game over loop if the initial
   ;  2 second freeze is not over.
   ;
   if _Frame_Counter = 0 then goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Clears the restrainer bit and jumps to beginning of game
   ;  over loop if fire button or reset switch is not pressed.
   ;
   if !switchreset && !joy0fire then _Bit0_Reset_Restrainer{0} = 0 : goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the game over loop if fire button
   ;  hasn't been released since leaving the main loop.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Game_Over_Loop

   ;```````````````````````````````````````````````````````````````
   ;  The program is restarted.
   ;
   goto __Start_Restart

 

 

 

Repetition Restrainer for the Fire Button

Repetition Restrainer for the Fire Button on bB page.

 
   ;***************************************************************
   ;
   ;  Repetition Restrainer for the Fire Button
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;
   ;  This example program disables rapid-fire using a bit instead
   ;  of wasting a variable. Press the fire button to shoot the
   ;  missile. The fire button must be released and pressed to
   ;  shoot the missile again. This is used for games where you do
   ;  not want rapid-fire. A slightly edited version of this can
   ;  be used to keep a button press in a title screen section
   ;  or a game over section from contaminating another part of
   ;  your game. For example, you don't want a title screen
   ;  button press to count as a button press in the actual game.
   ;  A similar thing can be done for the reset switch.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  All-purpose bits for various jobs.
   ;
   dim _Bit0_Reset_Restrainer = y
   dim _Bit1_FireB_Restrainer = y
   dim _Bit2_Missile0_Moving = y





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables (fastest way).
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets up missile0 position and height.
   ;
   missile0x = 85
   missile0y = 85
   missile0height = 4





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets score color and missile0 color.
   ;
   scorecolor = $1A : COLUP0 = $0C



   ;***************************************************************
   ;
   ;  Fire button check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off restrainer bit and skips this section if button is
   ;  not pressed.
   ;
   if !joy0fire then _Bit1_FireB_Restrainer{1} = 0 : goto __Skip_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if button hasn't been released after
   ;  being pressed.
   ;
   if _Bit1_FireB_Restrainer{1} then goto __Skip_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Turns on restrainer bit for fire button and turns on
   ;  missile movement bit.
   ;
   _Bit1_FireB_Restrainer{1} = 1 : _Bit2_Missile0_Moving{2} = 1

__Skip_Fire



   ;***************************************************************
   ;
   ;  Missile0 movement check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if missile is not moving.
   ;
   if !_Bit2_Missile0_Moving{2} then goto __Skip_Missile0_Movement

   ;```````````````````````````````````````````````````````````````
   ;  Moves missile up the screen by 2 pixels.
   ;
   missile0y = missile0y - 2

   ;```````````````````````````````````````````````````````````````
   ;  Resets missile position and clears missile movement bit if
   ;  the missile moves off the screen.
   ;
   if missile0y > 250 then _Bit2_Missile0_Moving{2} = 0 : missile0y = 85

__Skip_Missile0_Movement



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart

 

 

 

Variable-Speed Rapid-fire

Variable-Speed Rapid-fire on bB page.

 
   ;***************************************************************
   ;
   ;  Variable-Speed Rapid-fire
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;
   ;  This example program uses variable-speed rapid-fire. Press
   ;  the fire button to shoot the missile. If the fire button is
   ;  not released, the missile will repeat at a certain speed.
   ;  Change the _c_FBSpeed constant from 20 to a larger number to
   ;  slow it down.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Fire button repeat speed counter.
   ;
   dim _Fire0_Repeat_Speed = e

   ;```````````````````````````````````````````````````````````````
   ;  All-purpose bits for various jobs.
   ;
   dim _Bit0_Reset_Restrainer = y
   dim _Bit2_Missile0_Moving = y



   ;***************************************************************
   ;
   ;  Constant for the speed you want to use.
   ;  [The c stands for constant.]
   ;
   const _c_FBSpeed = 20





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables (fastest way).
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets up missile0 position and height.
   ;
   missile0x = 85
   missile0y = 85
   missile0height = 4





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets score color and missile0 color.
   ;
   scorecolor = $1A : COLUP0 = $0C



   ;***************************************************************
   ;
   ;  Fire button section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Decrements repeat speed counter if it is greater than zero.
   ;
   if _Fire0_Repeat_Speed then _Fire0_Repeat_Speed = _Fire0_Repeat_Speed - 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if button is not pressed.
   ;
   if !joy0fire then goto __Skip_Joy0_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if counter is greater than zero.
   ;
   if _Fire0_Repeat_Speed then goto __Skip_Joy0_Fire

   ;```````````````````````````````````````````````````````````````
   ;  Resets counter since it is zero.
   ;
   _Fire0_Repeat_Speed = _c_FBSpeed

   ;```````````````````````````````````````````````````````````````
   ;  Turns on missile movement bit.
   ;
   _Bit2_Missile0_Moving{2} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Resets position of missile.
   ;
   missile0y = 85 ; Delete this line if you don't want it to reset.

__Skip_Joy0_Fire



   ;***************************************************************
   ;
   ;  Missile0 movement check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if missile is not moving.
   ;
   if !_Bit2_Missile0_Moving{2} then goto __Skip_Missile0_Movement

   ;```````````````````````````````````````````````````````````````
   ;  Moves missile up the screen by 2 pixels.
   ;
   missile0y = missile0y - 2

   ;```````````````````````````````````````````````````````````````
   ;  Resets missile position and clears missile movement bit if
   ;  the missile moves off the screen.
   ;
   if missile0y > 250 then _Bit2_Missile0_Moving{2} = 0 : missile0y = 85

__Skip_Missile0_Movement



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart

 

 

 

Double Click

Double Click on bB page.

 
   ;***************************************************************
   ;
   ;  Double Click
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Double click the fire button on the left joystick to change
   ;  the background color.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Color change variable.
   ;
   dim _Color_Change = q

   ;```````````````````````````````````````````````````````````````
   ;  Timer for double click.
   ;
   dim _Timer = r

   ;```````````````````````````````````````````````````````````````
   ;  All-purpose bits for various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y
   dim _Bit1_1st_Click = y
   dim _Bit2_2nd_Click = y
   dim _Bit3_Finish_Double_Click = y



   ;***************************************************************
   ;
   ;  Disables the score. (We don't need it in this program.)
   ;
   const noscore = 1



   ;***************************************************************
   ;
   ;  Double click speed (how much time you have between clicks).
   ;  [The c stands for constant.]
   ;
   const _c_Double_Click_Speed = 15





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets starting color.
   ;
   _Color_Change = $0C


   ;***************************************************************
   ;
   ;  Turns off double click timer (200 = off).
   ;
   _Timer = 200





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = _Color_Change



   ;***************************************************************
   ;
   ;  Timer section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if timer is off (200 = off).
   ;
   if _Timer = 200 then goto __Skip_Timer

   ;```````````````````````````````````````````````````````````````
   ;  Increases the timer.
   ;
   _Timer = _Timer + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips rest of section if timer is not at the limit.
   ;
   if _Timer < _c_Double_Click_Speed then goto __Skip_Timer

   ;```````````````````````````````````````````````````````````````
   ;  Time ran out! Turns off timer and clears double click bits.
   ;
   _Timer = 200

   _Bit1_1st_Click{1} = 0 : _Bit2_2nd_Click{2} = 0 : _Bit3_Finish_Double_Click{3} = 0

__Skip_Timer



   ;***************************************************************
   ;
   ;  Double click section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Fire button ON subsection.
   ;
   ;  Skips subsection if fire button is off or finish bit is on.
   ;
   if !joy0fire || _Bit3_Finish_Double_Click{3} then goto __Skip_DC_Fire_01

   ;```````````````````````````````````````````````````````````````
   ;  First click check (fire button ON).
   ;
   ;  If 2nd click bit is OFF and 1st click bit is OFF, turns on
   ;  the 1st click bit and restarts the timer.
   ;
   if !_Bit2_2nd_Click{2} && !_Bit1_1st_Click{1} then _Bit1_1st_Click{1} = 1 : _Timer = 0

   ;```````````````````````````````````````````````````````````````
   ;  Second click check (fire button ON).
   ;
   ;  If the 2nd click bit is ON, clears the 2nd click bit, turns
   ;  on the finish bit and restarts the timer.
   ;
   if _Bit2_2nd_Click{2} then _Bit2_2nd_Click{2} = 0 : _Bit3_Finish_Double_Click{3} = 1 : _Timer = 0

__Skip_DC_Fire_01

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Fire button OFF subsection.
   ;
   ;  Skips subsection if fire button is on.
   ;
   if joy0fire then goto __Skip_DC_Fire_02

   ;```````````````````````````````````````````````````````````````
   ;  First click done check (fire button OFF).
   ;
   ;  If 1st click bit is ON, clears the 1st click bit, turns on
   ;  the 2nd click bit, and restarts the timer.
   ;
   if _Bit1_1st_Click{1} then _Bit1_1st_Click{1} = 0 : _Bit2_2nd_Click{2} = 1 : _Timer = 0

   ;```````````````````````````````````````````````````````````````
   ;  Double click finish check (fire button OFF).
   ; 
   ;  If finish bit is OFF, skips finish of double click.
   ;
   if !_Bit3_Finish_Double_Click{3} then goto __Skip_DC_Fire_02

   ;```````````````````````````````````````````````````````````````
   ;  Finish bit is on, so the it's the end of the double click.
   ;
   ;  Turns off the double click bits and turns off the timer.
   ;
   _Bit3_Finish_Double_Click{3} = 0 : _Bit1_1st_Click{1} = 0 : _Bit2_2nd_Click{2} = 0 : _Timer = 200

   ;```````````````````````````````````````````````````````````````
   ;  Changes background color. (Replace this color change with
   ;  whatever you need done with a double click.)
   ;
   _Color_Change = _Color_Change + $10

__Skip_DC_Fire_02



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  If the reset switch is not pressed, turns off reset
   ;  restrainer bit and jumps to beginning of main loop.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  If reset switch hasn't been released after being pressed,
   ;  program jumps to beginning of main loop.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Reset pressed correctly, so the the program is restarted.
   ;
   goto __Start_Restart

 

 

 

Reset Switch Restrainer

Reset Switch Restrainer on bB page.

 
   ;***************************************************************
   ;
   ;  Reset Switch Restrainer
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  About this program:
   ;  
   ;  Press the reset switch to change the background color.
   ;  Notice how you have to let go of the reset switch and press
   ;  it again before the color will change. A bit is used to
   ;  restrain the reset switch (keeps it from repeating).
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Current background color.
   ;
   dim _Background_Color = a

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Bits that do various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers.
   ;
   dim rand16 = z



   ;***************************************************************
   ;
   ;  Disables the score. (We don't need it in this program.)
   ;
   const noscore = 1



   ;***************************************************************
   ;
   ;  Sets the background color variable.
   ;
   _Background_Color = $FA





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears most of the normal 26 variables (fastest way). The
   ;  variable z is used for random numbers in this program and
   ;  clearing it would mess up those random numbers. The
   ;  variable a is not cleared since it is used for changing
   ;  colors using the reset switch.
   ;
   b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   _Background_Color = _Background_Color + 16

   COLUBK = _Background_Color


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart

 

 

 

Select Switch Example

Select Switch Example on bB page.

 
   ;***************************************************************
   ;
   ;  Select Switch Example
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;
   ;  There is a multicolored sprite on the screen. Pressing the
   ;  select switch changes the sprite colors. If you repeatedly
   ;  press and let go of the select switch, you can change the
   ;  colors as fast as you want. If you hold down the select
   ;  switch, there is a half second delay. That's based on
   ;  Atari's Game Standards and Procedures.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;***************************************************************
   ;
   ;  Provides one multicolored sprite.
   ;
   set kernel_options player1colors



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Select switch variables.
   ;
   dim _Select_Color = w
   dim _Select_Counter = x

   ;```````````````````````````````````````````````````````````````
   ;  This bit restrains the reset switch.
   ;
   dim _Bit0_Reset_Restrainer = y





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears the normal 26 variables (fastest way).
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets starting position of player1.
   ;
   player1x = 77 : player1y = 53


   ;***************************************************************
   ;
   ;  Defines shape of player1 sprite.
   ;
   player1:
   %00111100
   %01111110
   %11000011
   %10111101
   %11111111
   %11011011
   %01111110
   %00111100
end


   ;***************************************************************
   ;
   ;  Sets color of player1 sprite.
   ;
   player1color:
   $94
   $96
   $98
   $9A
   $9C
   $9A
   $98
   $96
end





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Select switch check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Sets select counter to maximum and skips this section if
   ;  the select switch is not pressed.
   ;
   if !switchselect then _Select_Counter = 30 : goto __Done_Select

   ;```````````````````````````````````````````````````````````````
   ;  Adds one to the select counter.
   ;
   _Select_Counter = _Select_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if select counter value is less than 30.
   ;
   if _Select_Counter < 30 then goto __Done_Select

   ;```````````````````````````````````````````````````````````````
   ;  Clears the select counter, but holding down the reset switch
   ;  and the select switch rapidly changes the selection. The
   ;  closer the number is to 30, the faster the change happens.
   ;
   _Select_Counter = 0 : if switchreset then _Select_Counter = 20

   ;```````````````````````````````````````````````````````````````
   ;  Adds one to the select color variable.
   ;
   _Select_Color = _Select_Color + 1 : if _Select_Color > 5 then _Select_Color = 0

   ;```````````````````````````````````````````````````````````````
   ;  Changes color of sprite.
   ;
   on _Select_Color goto __P1_00 __P1_01 __P1_02 __P1_03 __P1_04 __P1_05 

__Done_Select



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the select switch is pressed.
   ;
   if switchselect then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Select switch colors.
   ;
__P1_00
   player1color:
   $94
   $96
   $98
   $9A
   $9C
   $9A
   $98
   $96
end
   goto __Done_Select


__P1_01
   player1color:
   $44
   $46
   $48
   $4A
   $4C
   $4A
   $48
   $46
end
   goto __Done_Select


__P1_02
   player1color:
   $C4
   $C6
   $C8
   $CA
   $CC
   $CA
   $C8
   $C6
end
   goto __Done_Select


__P1_03
   player1color:
   $14
   $16
   $18
   $1A
   $1C
   $1A
   $18
   $16
end
   goto __Done_Select


__P1_04
   player1color:
   $64
   $66
   $68
   $6A
   $6C
   $6A
   $68
   $66
end
   goto __Done_Select


__P1_05
   player1color:
   $04
   $06
   $08
   $0A
   $0C
   $0A
   $08
   $06
end
   goto __Done_Select

 

 

 

Pause Example

Pause Example on bB page.

 
   ;****************************************************************
   ;
   ;  Pause Example
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  About this program:
   ;  
   ;  Use the joystick to move the sprite. Notice how the sprite
   ;  smoothly glides along the walls when the the sprite is moved
   ;  diagonally. It doesn't stick or bounce.
   ;
   ;  To pause on an Atari 2600, flip the COLOR/BW switch. To
   ;  pause on an Atari 7800, press the pause button. You can also
   ;  pause by pressing the fire button on the right controller.
   ;  To unpause, press and release the fire button on the left
   ;  controller.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;***************************************************************
   ;
   ;  Multicolored playfield and no blank lines.
   ;  Cost: loss of missile0.
   ;
   set kernel_options pfcolors no_blank_lines



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used in the pause loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with the pause feature.
   ;
   dim _Pause_Counter_Tmp = o

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used in the pause loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with the pause feature.
   ;
   dim _Pause_Mem_Color_Tmp = p

   ;```````````````````````````````````````````````````````````````
   ;  Temporary variable used in the pause loop.
   ;  This variable can be reused if you're sure it won't
   ;  interfere with the pause feature.
   ;
   dim _Pause_Color_Tmp = q

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _BitOp_02 = r

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the position of the BW switch.
   ;
   dim _Bit0_BW_Mem = r

   ;```````````````````````````````````````````````````````````````
   ;  Checks to see if the BW switch has moved.
   ;
   dim _Bit1_BW_Check = r

   ;```````````````````````````````````````````````````````````````
   ;  Lets pause section know if the B color scheme should be used.
   ;
   dim _Bit2_Pause_Clr_Scheme = r

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _BitOp_01 = y

   ;```````````````````````````````````````````````````````````````
   ;  Keeps the reset switch from repeating when pressed.
   ;
   dim _Bit0_Reset_Restrainer = y

   ;```````````````````````````````````````````````````````````````
   ;  Restrains the fire button.
   ;
   dim _Bit1_FireB_Restrainer = y

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Makes better random numbers. 
   ;
   dim rand16 = z



   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for an 8 x 8 sprite.
   ;  If your sprite is a different size, you'll need to adjust
   ;  the numbers.
   ;
   const _P_Edge_Top = 9
   const _P_Edge_Bottom = 88
   const _P_Edge_Left = 1
   const _P_Edge_Right = 152





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears 25 of the normal 26 variables (fastest way). The
   ;  variable z is used for random numbers in this program and
   ;  clearing it would mess up those random numbers.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP SETUP
   ;
   ;
__Main_Loop_Setup


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Starting position of player0.
   ;
   player0x = 77 : player0y = 53


   ;***************************************************************
   ;
   ;  Sets score color.
   ;
   scorecolor = $1C


   ;***************************************************************
   ;
   ;  Defines missile1 height.
   ;
   missile1height = 1


   ;***************************************************************
   ;
   ;  Defines shape of player0 sprite.
   ;
   player0:
   %00111100
   %01111110
   %11000011
   %10111101
   %11111111
   %11011011
   %01111110
   %00111100
end



   ;***************************************************************
   ;
   ;  Sets up the main loop playfield.
   ;
   playfield:
   ................................
   ................................
   ....XXXXXXXXXX....XXXXXXXXXX....
   ....X......................X....
   ....X......................X....
   ....X......................X....
   ................................
   ................................
   ....XXXX....XXX..XXX....XXXX....
   ................................
   ................................
end


   ;***************************************************************
   ;
   ;  Remembers position of COLOR/BW switch.
   ;
   _Bit0_BW_Mem{0} = 0 : if switchbw then _Bit0_BW_Mem{0} = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE GAME GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   COLUBK = 0



   ;***************************************************************
   ;
   ;  Sets playfield pixel colors.
   ;
   pfcolors:
   $2C
   $2C
   $2C
   $2C
   $2A
   $28
   $26
   $2C
   $2C
   $2C
   $2C
end



   ;***************************************************************
   ;
   ;  Sets sprite color.
   ;
   COLUP0 = $9C



   ;***************************************************************
   ;
   ;  Sets missile1 width.
   ;
   NUSIZ1 = $10



   ;***************************************************************
   ;
   ;  Joy0 up check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved up.
   ;
   if !joy0up then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0y <= _P_Edge_Top then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player0x-10)/4

   temp4 = (player0x-17)/4

   temp3 = temp5 - 1

   temp6 = (player0y-9)/8

   if temp5 < 34 then if pfread(temp5,temp6) then goto __Skip_Joy0_Up

   if temp4 < 34 then if pfread(temp4,temp6) then goto __Skip_Joy0_Up

   if temp3 < 34 then if pfread(temp3,temp6) then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 up.
   ;
   player0y = player0y - 1

__Skip_Joy0_Up



   ;***************************************************************
   ;
   ;  Joy0 down check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved down.
   ;
   if !joy0down then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0y >= _P_Edge_Bottom then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player0x-10)/4

   temp4 = (player0x-17)/4

   temp3 = temp5 - 1

   temp6 = (player0y+1)/8

   if temp5 < 34 then if pfread(temp5,temp6) then goto __Skip_Joy0_Down

   if temp4 < 34 then if pfread(temp4,temp6) then goto __Skip_Joy0_Down

   if temp3 < 34 then if pfread(temp3,temp6) then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 down.
   ;
   player0y = player0y + 1

__Skip_Joy0_Down



   ;***************************************************************
   ;
   ;  Joy0 left check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved to the left.
   ;
   if !joy0left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0x <= _P_Edge_Left then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player0y)/8

   temp3 = (player0y-8)/8

   temp6 = (player0x-18)/4

   if temp6 < 34 then if pfread(temp6,temp5) then goto __Skip_Joy0_Left

   if temp6 < 34 then if pfread(temp6,temp3) then goto __Skip_Joy0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 left.
   ;
   player0x = player0x - 1

__Skip_Joy0_Left



   ;***************************************************************
   ;
   ;  Joy0 right check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick isn't moved to the right.
   ;
   if !joy0right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if hitting the edge.
   ;
   if player0x >= _P_Edge_Right then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Stops movement if a playfield pixel is in the way.
   ;
   temp5 = (player0y)/8

   temp3 = (player0y-8)/8

   temp6 = (player0x-9)/4

   if temp6 < 34 then if pfread(temp6,temp5) then goto __Skip_Joy0_Right

   if temp6 < 34 then if pfread(temp6,temp3) then goto __Skip_Joy0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Moves player0 right.
   ;
   player0x = player0x + 1

__Skip_Joy0_Right



   ;***************************************************************
   ;
   ;  Pause check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Checks current position of COLOR/BW switch.
   ;
   _Bit1_BW_Check{1} = 0

   if switchbw then _Bit1_BW_Check{1} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Compares bits to see if COLOR/BW switch has moved.
   ;  The game is paused if the switch has moved.
   ;
   if _Bit0_BW_Mem{0} then if !_Bit1_BW_Check{1} then goto __Pause_Setup

   if !_Bit0_BW_Mem{0} then if _Bit1_BW_Check{1} then goto __Pause_Setup

   ;```````````````````````````````````````````````````````````````
   ;  Pauses game if fire button of second joystick is pressed.
   ;
   if joy1fire then goto __Pause_Setup

__AP_Skip_Pause



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart




   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PAUSE SETUP
   ;
__Pause_Setup


   ;***************************************************************
   ;
   ;  Mutes the sound.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Restrains the fire button for the pause loop.
   ;
   _Bit1_FireB_Restrainer{1} = 1


   ;***************************************************************
   ;
   ;  Clears the pause counter.
   ;
   _Pause_Counter_Tmp = 0


   ;***************************************************************
   ;
   ;  Selects a random color scheme.
   ;
   _Pause_Color_Tmp = (rand&7)

   _Pause_Mem_Color_Tmp = _Pause_Color_Tmp





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PAUSE LOOP
   ;
__Pause_Game



   ;***************************************************************
   ;
   ;  Sets missile1 width.
   ;
   NUSIZ1 = $10



   ;***************************************************************
   ;
   ;  Changes color scheme every 4 seconds.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increases the pause counter.
   ;
   _Pause_Counter_Tmp = _Pause_Counter_Tmp + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if counter isn't high enough.
   ;
   if _Pause_Counter_Tmp < 240 then goto __Skip_Pause_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Resets the pause counter.
   ;
   _Pause_Counter_Tmp = 0

   ;```````````````````````````````````````````````````````````````
   ;  Gets a random number from 0 to 7.
   ;
   _Pause_Color_Tmp = (rand&7)

   ;```````````````````````````````````````````````````````````````
   ;  Compares the new color scheme with the previous color scheme
   ;  and selects a new color scheme if they are the same.
   ;
   if _Pause_Color_Tmp = _Pause_Mem_Color_Tmp then _Pause_Color_Tmp = _Pause_Color_Tmp + (rand&3) + 1 : if _Pause_Color_Tmp > 7 then _Pause_Color_Tmp = _Pause_Color_Tmp - 8

   ;```````````````````````````````````````````````````````````````
   ;  Remembers the new color scheme.
   ;
   _Pause_Mem_Color_Tmp = _Pause_Color_Tmp

   ;```````````````````````````````````````````````````````````````
   ;  Decides if the B color scheme should be used.
   ;
   _Bit2_Pause_Clr_Scheme{2} = 0

    temp5 = rand : if temp5 < 128 then _Bit2_Pause_Clr_Scheme{2} = 1

__Skip_Pause_Counter



   ;***************************************************************
   ;
   ;  Jumps to the latest color scheme.
   ;
   on _Pause_Color_Tmp goto __Ps0 __Ps1 __Ps2 __Ps3 __Ps4 __Ps5 __Ps6 __Ps7

__Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Unpause check and end of pause loop.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the pause loop if the fire button
   ;  isn't pressed. Also clears the restrainer bit.
   ;
   if !joy0fire then _Bit1_FireB_Restrainer{1} = 0 : goto __Pause_Game

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of the pause loop if the fire button
   ;  hasn't been released since starting the pause loop.
   ;
   if _Bit1_FireB_Restrainer{1} then goto __Pause_Game

   ;```````````````````````````````````````````````````````````````
   ;  Remembers position of COLOR/BW switch.
   ;
   _Bit0_BW_Mem{0} = 0 : if switchbw then _Bit0_BW_Mem{0} = 1





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF PAUSE LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;  RESTORES GAME FROM PAUSE
   ;
   ;  Puts everything back the way it was.
   ;
__Restore_Game_from_Pause


   ;***************************************************************
   ;
   ;  Restrains the fire button for the main loop.
   ;
   _Bit1_FireB_Restrainer{1} = 1


   ;***************************************************************
   ;
   ;  Restores score color.
   ;
   scorecolor = $1C


   goto __Main_Loop





   ;***************************************************************
   ;
   ;  Sets pause colors to gray.
   ;
__Ps0

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps0B

   pfcolors:
   $0C
   $0C
   $0C
   $0C
   $0C
   $0C
   $0C
   $0C
   $0C
   $0C
   $0C
   $0C
end

   COLUP0 = $0C

   COLUBK = $0A

   scorecolor = $0C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to gray.
   ;
__Ps0B

   pfcolors:
   $0A
   $0A
   $0A
   $0A
   $0A
   $0A
   $0A
   $0A
   $0A
   $0A
   $0A
   $0A
end

   COLUP0 = $0A

   COLUBK = $0C

   scorecolor = $0A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to reddish-orange.
   ;
__Ps1

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps1B

   pfcolors:
   $3C
   $3C
   $3C
   $3C
   $3C
   $3C
   $3C
   $3C
   $3C
   $3C
   $3C
   $3C
end

   COLUP0 = $3C

   COLUBK = $3A

   scorecolor = $3C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to reddish-orange.
   ;
__Ps1B

   pfcolors:
   $3A
   $3A
   $3A
   $3A
   $3A
   $3A
   $3A
   $3A
   $3A
   $3A
   $3A
   $3A
end

   COLUP0 = $3A

   COLUBK = $3C

   scorecolor = $3A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to purple.
   ;
__Ps2

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps2B

   pfcolors:
   $6C
   $6C
   $6C
   $6C
   $6C
   $6C
   $6C
   $6C
   $6C
   $6C
   $6C
   $6C
end

   COLUP0 = $6C

   COLUBK = $6A

   scorecolor = $6C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to purple.
   ;
__Ps2B

   pfcolors:
   $6A
   $6A
   $6A
   $6A
   $6A
   $6A
   $6A
   $6A
   $6A
   $6A
   $6A
   $6A
end

   COLUP0 = $6A

   COLUBK = $6C

   scorecolor = $6A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to blue.
   ;
__Ps3

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps3B

   pfcolors:
   $9C
   $9C
   $9C
   $9C
   $9C
   $9C
   $9C
   $9C
   $9C
   $9C
   $9C
   $9C
end

   COLUP0 = $9C

   COLUBK = $9A

   scorecolor = $9C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to blue.
   ;
__Ps3B

   pfcolors:
   $9A
   $9A
   $9A
   $9A
   $9A
   $9A
   $9A
   $9A
   $9A
   $9A
   $9A
   $9A
end

   COLUP0 = $9A

   COLUBK = $9C

   scorecolor = $9A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to green.
   ;
__Ps4

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps4B

   pfcolors:
   $CC
   $CC
   $CC
   $CC
   $CC
   $CC
   $CC
   $CC
   $CC
   $CC
   $CC
   $CC
end

   COLUP0 = $CC

   COLUBK = $CA

   scorecolor = $CC

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to green.
   ;
__Ps4B

   pfcolors:
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
end

   COLUP0 = $CA

   COLUBK = $CC

   scorecolor = $CA

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to yellowish.
   ;
__Ps5

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps5B

   pfcolors:
   $FC
   $FC
   $FC
   $FC
   $FC
   $FC
   $FC
   $FC
   $FC
   $FC
   $FC
   $FC
end

   COLUP0 = $FC

   COLUBK = $FA

   scorecolor = $FC

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to yellowish.
   ;
__Ps5B

   pfcolors:
   $FA
   $FA
   $FA
   $FA
   $FA
   $FA
   $FA
   $FA
   $FA
   $FA
   $FA
   $FA
end

   COLUP0 = $FA

   COLUBK = $FC

   scorecolor = $FA

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to darkish-blue.
   ;
__Ps6

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps6B

   pfcolors:
   $8C
   $8C
   $8C
   $8C
   $8C
   $8C
   $8C
   $8C
   $8C
   $8C
   $8C
   $8C
end

   COLUP0 = $8C

   COLUBK = $8A

   scorecolor = $8C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to darkish-blue.
   ;
__Ps6B

   pfcolors:
   $8A
   $8A
   $8A
   $8A
   $8A
   $8A
   $8A
   $8A
   $8A
   $8A
   $8A
   $8A
end

   COLUP0 = $8A

   COLUBK = $8C

   scorecolor = $8A

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to orange-brown.
   ;
__Ps7

   if _Bit2_Pause_Clr_Scheme{2} then goto __Ps7B

   pfcolors:
   $2C
   $2C
   $2C
   $2C
   $2C
   $2C
   $2C
   $2C
   $2C
   $2C
   $2C
   $2C
end

   COLUP0 = $2C

   COLUBK = $2A

   scorecolor = $2C

   goto __Got_Pause_Colors



   ;***************************************************************
   ;
   ;  Sets pause colors to orange-brown.
   ;
__Ps7B

   pfcolors:
   $2A
   $2A
   $2A
   $2A
   $2A
   $2A
   $2A
   $2A
   $2A
   $2A
   $2A
   $2A
end

   COLUP0 = $2A

   COLUBK = $2C

   scorecolor = $2A

   goto __Got_Pause_Colors

 

 

 

Shooting NUSIZ Copies (DPC+)

Shooting NUSIZ Copies (DPC+) on bB page.

 
   ;***************************************************************
   ;
   ;  Shooting NUSIZ copies (DPC+)
   ;
   ;  Example program by iesposta. Code and graphics adapted by
   ;  Duane Alan Hahn (Random Terrain) using hints, tips, code
   ;  snippets, and more from AtariAge members such as batari,
   ;  SeaGtGruff, RevEng, Robert M, Nukey Shay, Atarius Maximus,
   ;  jrok, supercat, GroovyBee, and bogax.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;****************************************************************
   ;
   ;  This program uses the DPC+ kernel.
   ;
   set kernel DPC+



   ;****************************************************************
   ;
   ;  Removes overhead from data tables, saving space. Doing so
   ;  will limit them to outside of code. That is, you can no
   ;  longer place data tables inline with code, or your program
   ;  may crash!
   ;
   set optimization noinlinedata



   ;****************************************************************
   ;
   ;  Will place calls to the random number generator inline with
   ;  your code. This is particularly useful for bankswitched games,
   ;  where a call to the random number generator would normally
   ;  have to switch banks, so this will speed up your code with a
   ;  minimal increase in code size.
   ;
   set optimization inlinerand



   ;****************************************************************
   ;
   ;  Standard used in North America and most of South America.
   ;
   set tv ntsc

   
   
   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  The following 7 must be sequential for _VSPointer to work.
   ;
   dim _EnemyP2 = a
   dim _EnemyP3 = b
   dim _EnemyP4 = c
   dim _EnemyP5 = d
   dim _EnemyP6 = e
   dim _EnemyP7 = f
   dim _EnemyP8 = g

   ;```````````````````````````````````````````````````````````````
   ;  Virtual sprite pointer.
   ;
   dim _VSPointer = h

   ;```````````````````````````````````````````````````````````````
   ;  _Master_Counter can be used for many things, but it is 
   ;  really useful for animating sprite frames when used
   ;  with _Frame_Counter.
   ;
   dim _Master_Counter = i
   dim _Frame_Counter = j

   ;```````````````````````````````````````````````````````````````
   ;  Enemy data counters.
   ;
   dim _Enemy_D_Counter_y = k
   dim _Enemy_D_Counter_x = l

   ;```````````````````````````````````````````````````````````````
   ;  Destroyed enemy counter.
   ;
   dim _Dead_Enemy_Counter = m

   ;```````````````````````````````````````````````````````````````
   ;  Channel 0 sound variables.
   ;
   dim _Ch0_Sound = n
   dim _Ch0_Duration = o
   dim _Ch0_Counter = p

   ;```````````````````````````````````````````````````````````````
   ;  Channel 1 sound variables. Only used for background "music,"
   ;  so we can save a variable here by leaving out _Ch1_Sound.
   ;
   dim _Ch1_Duration = q
   dim _Ch1_Counter = r

   ;```````````````````````````````````````````````````````````````
   ;  In charge of how hard the game is. Controls the enemy
   ;  movement data that is used and how often shots are dropped.
   ;
   dim _Wave = s

   ;```````````````````````````````````````````````````````````````
   ;  Keeps track of player damage.
   ;
   dim _Damage_Counter = t

   ;```````````````````````````````````````````````````````````````
   ;  Fixes it so the player can't restart after death until 2
   ;  seconds has gone by.
   ;
   dim _Game_Over_Counter = u

   ;```````````````````````````````````````````````````````````````
   ;  All-purpose variable for temporary jobs.
   ;
   dim _MyTemp01 = v

   ;```````````````````````````````````````````````````````````````
   ;  All-purpose bits for various jobs.
   ;
   dim _BitOp_All_Purpose_01 = y
   dim _Bit0_Reset_Restrainer = y
   dim _Bit1_FireB_Restrainer = y
   dim _Bit2_Game_Over = y
   dim _Bit3_Swap_Scores = y
   dim _Bit7_Last_Life = y

   ;```````````````````````````````````````````````````````````````
   ;  All-purpose bits for various jobs.
   ;
   dim _BitOp_All_Purpose_02 = z
   dim _Bit0_Enemy_Bottom = z



   ;****************************************************************
   ;
   ;  Built-in custom score font.
   ;
   const font = retroputer



   ;****************************************************************
   ;
   ;  Height of the enemy sprites minus one. Or just ignore row 0 in
   ;  the sprite editor and the last row number is the one you use.
   ;
   const _c_SpriteHeight = 7



   ;***************************************************************
   ;
   ;  Constants for channel 0 sound effects (_Ch0_Sound).
   ;  [The c stands for constant.]
   ;
   const _c_Enemy_Boom = 1
   const _c_Player_Missile = 2
   const _c_Player_Hurt = 3
   const _c_Player_Destroyed = 4



   ;****************************************************************
   ;
   ;  Jumps to bank 6 to set up the program.
   ;
   goto __Start_Restart bank6



   ;****************************************************************
   ;
   ;  Score background color.
   ;
   asm
minikernel
   ldx #$94
   stx COLUBK
   rts
end



   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   bank 2
   temp1 = temp1
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````



__Bank_2



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Main Loop
   ;
__Main_Loop


   
   ;***************************************************************
   ;
   ;  Animation counters.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Increments _Master_Counter.
   ;
   _Master_Counter = _Master_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this subsection if _Master_Counter is less than 8.
   ;
   if _Master_Counter < 8 then __Skip_Counters

   ;```````````````````````````````````````````````````````````````
   ;  Increments _Frame_Counter and clears _Master_Counter.
   ;
   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Clears _Frame_Counter if it is greater than 5.
   ;
   if _Frame_Counter > 5 then _Frame_Counter = 0

__Skip_Counters

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to enemy animation frames and player0 color cycling.
   ;
   on _Frame_Counter goto __1A_Enemy __1B_Enemy __1C_Enemy __1D_Enemy __1E_Enemy __1F_Enemy

__End_Enemy_Animation



   ;***************************************************************
   ;
   ;  Enemy movement.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Gets a number between 0 and 15 from _Master_Counter.
   ;
   temp6 = _Master_Counter & $0F

   ;```````````````````````````````````````````````````````````````
   ;  Increments enemy x and y data counters if the number is 0.
   ;
   if !temp6 then _Enemy_D_Counter_y = _Enemy_D_Counter_y + 1 : _Enemy_D_Counter_x = _Enemy_D_Counter_x + 1

   ;```````````````````````````````````````````````````````````````
   ;  Gets enemy Y movement data.
   ;
   temp6 = _D_EnemyY[_Enemy_D_Counter_y]

   ;```````````````````````````````````````````````````````````````
   ;  Starts the Y data over if the number $80 is read.
   ;
   if temp6 = $80 then _Enemy_D_Counter_y = 11 : temp6 = 0

   ;```````````````````````````````````````````````````````````````
   ;  Gets enemy X movement data.
   ;
   if _Wave = 10 then temp5 = _D_EnemyX_W1[_Enemy_D_Counter_x]
   if _Wave = 13 then temp5 = _D_EnemyX_W2[_Enemy_D_Counter_x]
   if _Wave = 16 then temp5 = _D_EnemyX_W3[_Enemy_D_Counter_x]
   if _Wave = 19 then temp5 = _D_EnemyX_W4[_Enemy_D_Counter_x]
   if _Wave = 22 then temp5 = _D_EnemyX_W5[_Enemy_D_Counter_x]
   if _Wave = 25 then temp5 = _D_EnemyX_W6[_Enemy_D_Counter_x]
   if _Wave = 28 || _Wave = 31 then temp5 = _D_EnemyX_W7[_Enemy_D_Counter_x]

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the 11th position of the X data if the number $80
   ;  is read.
   ;
   if temp5 = $80 then _Enemy_D_Counter_x = 0 : temp5 = 255

__Skip_Read

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Moves any enemy sprite rows that haven't been destroyed.
   ;
   for _MyTemp01 = 6 to 0 step -1

   ;```````````````````````````````````````````````````````````````
   ;  Skips all movement if row of enemies has been destroyed.
   ;
   if !_EnemyP2[_MyTemp01] then goto __Skip_Move

   ;```````````````````````````````````````````````````````````````
   ;  Gets the next Y position.
   ;
   temp3 = player2y[_MyTemp01]+temp6

   ;```````````````````````````````````````````````````````````````
   ;  Limits how low the first enemy row can go. The bit keeps any
   ;  rows above from moving down too.
   ;
   if temp3 > 140 && temp3 < 180 then _Bit0_Enemy_Bottom{0} = 1

   ;```````````````````````````````````````````````````````````````
   ;  If the bottom row hit the limit, all rows that are left move
   ;  up and the Y data is ignored.
   ;
   if _Bit0_Enemy_Bottom{0} then temp3 = temp3 - 1

   ;```````````````````````````````````````````````````````````````
   ;  Moves the row up or down or neither.
   ;
   player2y[_MyTemp01] = temp3

__Skip_Move_Y

   ;```````````````````````````````````````````````````````````````
   ;  Moves the row left or right or neither.
   ;
   player2x[_MyTemp01] = player2x[_MyTemp01]+temp5

__Skip_Move

   next

   ;```````````````````````````````````````````````````````````````
   ;  Clears the bottom limit bit.
   ;
   _Bit0_Enemy_Bottom{0} = 0



   ;***************************************************************
   ;
   ;  Missile0 check and fire button check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Jumps to fire button check if missile0 is off the screen.
   ;
   if missile0y > 240 && missile0y < 250 then goto __FireB_Check

   ;```````````````````````````````````````````````````````````````
   ;  Moves missile0 and skips fire button check.
   ;
   missile0y = missile0y - 5 : goto __Skip_FireB

__FireB_Check

   ;```````````````````````````````````````````````````````````````
   ;  Skips subsection if game is over.
   ;
   if _Bit2_Game_Over{2} then goto __Skip_FireB

   ;```````````````````````````````````````````````````````````````
   ;  Checks fire button since missile0 is off the screen.
   ;  Skips this subsection if fire button is not pressed.
   ;
   if !joy0fire then _Bit1_FireB_Restrainer{1} = 0 : goto __Skip_FireB

   ;```````````````````````````````````````````````````````````````
   ;  Skips this subsection if fire button hasn't been released
   ;  since beginning of game.
   ;
   if _Bit1_FireB_Restrainer{1} then goto __Skip_FireB

   ;```````````````````````````````````````````````````````````````
   ;  Starts the firing of missile0.
   ;
   missile0y = player0y - 4 : missile0x = player0x + 5

   ;```````````````````````````````````````````````````````````````
   ;  Won't let the missile shooting sound happen if an enemy boom
   ;  explosion sound is happening (unless enough of the boom
   ;  sound has played).
   ;
   if _Ch0_Sound = _c_Enemy_Boom && _Ch0_Counter < 20 then goto __Skip_FireB

   ;```````````````````````````````````````````````````````````````
   ;  Starts the missile shooting sound effect.
   ;
   _Ch0_Sound = _c_Player_Missile : _Ch0_Duration = 1 : _Ch0_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Randomly selects from 2 other missile shooting sound
   ;  effects. Keeps it from getting monotonous.
   ;
   temp5 = rand : if temp5 > 128 then _Ch0_Counter = 57
   temp5 = rand : if temp5 > 128 then _Ch0_Counter = 114

__Skip_FireB



   ;***************************************************************
   ;
   ;  Joystick movement (left/right).
   ;
   if joy0right && player0x < 136 then player0x = player0x + 1
   if joy0left && player0x > 15 then player0x = player0x - 1



   ;***************************************************************
   ;
   ;  Firing enemies. (S7 = which of the 7 sprites is Shooting)
   ;
   ;  An enemy ship randomly fires a playfield pixel.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Gets a randomish number between 0 and 7. This subsection is
   ;  skipped if the number is 7.
   ;
   temp6 = (rand&7) : if temp6 = 7 then goto __Skip_Enemy_Firing

   ;```````````````````````````````````````````````````````````````
   ;  There is a small chance that an enemy will fire based on
   ;  the wave. The higher the wave, the more the enemies will
   ;  shoot.
   ;
   temp5 = rand : if temp5 > _Wave then goto __Skip_Enemy_Firing

   ;```````````````````````````````````````````````````````````````
   ;  Converts sprite x and y postions to playfield coordinates.
   ;
   temp4 = (player2x[temp6]-12)/4 : temp5 = player2y[temp6]+3 

   ;```````````````````````````````````````````````````````````````
   ;  Skips to the odd subsection if the random enemy is odd. The
   ;  odd numbered enemies can have 3 copies.
   ;
   if temp6{0} then goto __Odd_Enemy_Shooting

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Even jump subsection for rows that have 2 enemy sprites.
   ;
   temp1 = _EnemyP2[temp6]

   on temp1 goto __Skip_Enemy_Firing __S73C00 __S7_2_Medium_Copies

   goto __Skip_Enemy_Firing

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Odd jump subsection for rows that have 3 enemy sprites.
   ;
__Odd_Enemy_Shooting

   temp2 = _EnemyP2[temp6]

   on temp2 goto __Skip_Enemy_Firing __S73C00 __S73C00 __S7_2_Medium_Copies __S73C00 __S7_2_Wide_Copies __S7_2_Medium_Copies __S7_3_Copies

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to 1 of 3 medium copies based on location of player.
   ;
__S7_3_Copies

   ;```````````````````````````````````````````````````````````````
   ;  Shoots from the enemy ship in the middle if the player is in
   ;  the middle 3rd of the screen.
   ;
   temp3 = 1

   ;```````````````````````````````````````````````````````````````
   ;  Shoots from the enemy ship on the left if the player is on
   ;  the left 3rd of the screen.
   ;
   if player0x < 40 then temp3 = 0

   ;```````````````````````````````````````````````````````````````
   ;  Shoots from the enemy ship on the right if the player is on
   ;  the right 3rd of the screen.
   ;
   if player0x > 96 then temp3 = 2

   ;```````````````````````````````````````````````````````````````
   ;  This does the actual jumping.
   ;
   on temp3 goto __S73C00 __S73C01 __S73C02

__S73C00

   pfpixel temp4 temp5 on : goto __Skip_Enemy_Firing

__S73C01

   temp3 = temp4+8 : pfpixel temp3 temp5 on : goto __Skip_Enemy_Firing

__S73C02

   temp3 = temp4+16 : pfpixel temp3 temp5 on : goto __Skip_Enemy_Firing

   ;```````````````````````````````````````````````````````````````
   ;  Randomly jumps to 1 of 2 wide copies.
   ;
__S7_2_Wide_Copies

   temp3 = (rand&1)

   on temp3 goto __S73C00 __S73C02

   ;```````````````````````````````````````````````````````````````
   ;  Randomly jumps to 1 of 2 medium copies.
   ;
__S7_2_Medium_Copies

   temp3 = (rand&1)

   on temp3 goto __S73C00 __S73C01

__Skip_Enemy_Firing



   ;***************************************************************
   ;
   ;  Scrolls the playfield pixels down the screen.
   ;
   pfscroll 255



   ;***************************************************************
   ;
   ;  Doubles width of player's health indicator.
   ;
   rem _NUSIZ1 = $05



   ;***************************************************************
   ;
   ;  176 rows that are 1 scanline high except the top and bottom
   ;  rows (which seem to be 2 scanlines high). All of the colors
   ;  seem to be 2 scanlines high.
   ;
   DF6FRACINC = 0 : DF4FRACINC = 0
   DF0FRACINC = 255 : DF1FRACINC = 255 : DF2FRACINC = 255 : DF3FRACINC = 255



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Player collision check.
   ;   
   ;```````````````````````````````````````````````````````````````
   ;  Checks for player0/playfield collision.
   ;
   if !collision(player0,playfield) then goto __Skip_Player_Collision

   ;```````````````````````````````````````````````````````````````
   ;  Skips subsection if game is over.
   ;
   if _Bit2_Game_Over{2} then goto __Skip_Player_Collision

   ;```````````````````````````````````````````````````````````````
   ;  Starts the player hurt sound effect.
   ;
   _Ch0_Sound = _c_Player_Hurt : _Ch0_Duration = 1 : _Ch0_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  This controls the damage the player receives.
   ;
   if _Damage_Counter > 1 then _Damage_Counter = _Damage_Counter - 2

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to the damage images and colors.
   ;
   if _Damage_Counter = 223 then goto __Player_Damage01
   if _Damage_Counter = 193 then goto __Player_Damage02
   if _Damage_Counter = 163 then goto __Player_Damage03
   if _Damage_Counter = 131 then goto __Player_Damage04
   if _Damage_Counter = 101 then goto __Player_Damage05
   if _Damage_Counter = 69 then goto __Player_Damage06
   if _Damage_Counter = 37 then goto __Player_Damage07
   if _Damage_Counter = 7 then goto __Player_Damage08

   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if the player's ship isn't destroyed.
   ;
   if _Damage_Counter <> 1 then goto __Skip_Player_Collision

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the game over bit, fire button restrainer bit, and
   ;  the sound effect. Also gets rid of the health indicator.
   ;
   _Bit2_Game_Over{2} = 1 : _Bit1_FireB_Restrainer{1} = 1  : _Ch0_Duration = 1
   _Damage_Counter = 0 : _Ch0_Counter = 0
   _Ch0_Sound = _c_Player_Destroyed : player1y = 241

__Skip_Player_Collision



   ;***************************************************************
   ;
   ;  Game over.
   ;   
   ;```````````````````````````````````````````````````````````````
   ;  Skips this subsection if the game isn't over.
   ;
   if !_Bit2_Game_Over{2} then goto __Skip_Game_over

   ;```````````````````````````````````````````````````````````````
   ;  Erases the player's ship.
   ;
   if player0height > 0 then player0height = player0height - 1

   ;```````````````````````````````````````````````````````````````
   ;  Increments the game over counter.
   ;
   _Game_Over_Counter = _Game_Over_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this subsection if 2 seconds haven't gone by.
   ;
   if _Game_Over_Counter < 120 then goto __Skip_Game_over

   ;```````````````````````````````````````````````````````````````
   ;  Keeps the game over counter from rolling over.
   ;
   _Game_Over_Counter = 130

   ;```````````````````````````````````````````````````````````````
   ;  Skips this subsection if fire button is not pressed.
   ;
   if !joy0fire then _Bit1_FireB_Restrainer{1} = 0 : goto __Skip_Game_over

   ;```````````````````````````````````````````````````````````````
   ;  Skips this subsection if fire button hasn't been released
   ;  since the game ended.
   ;
   if _Bit1_FireB_Restrainer{1} then goto __Skip_Game_over

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the game.
   ;
   goto __Start_Restart bank6

__Skip_Game_over



   ;***************************************************************
   ;
   ;  Missile0 collision check. (W7 = Which of the 7 sprites)
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this subsection if there is no collision between
   ;  missile0 and an enemy sprite.
   ;
   if !collision(missile0,player1) then goto __Skip_Missile0_Collision

   ;```````````````````````````````````````````````````````````````
   ;  Checks for missile0 collision with other 7 sprites.
   ;  7 is used for the y check because these sprites are 8
   ;  pixels high (8 - 1 = 7). For example, if your sprite is
   ;  40 pixels tall, use 39 instead of 10. This finds the row that
   ;  was hit.
   ;
   if (missile0y + missile0height) >= player2y && missile0y <= (player2y + _c_SpriteHeight) then _VSPointer = 0 : goto __Which_1_of_2_Copies
   if (missile0y + missile0height) >= player3y && missile0y <= (player3y + _c_SpriteHeight) then _VSPointer = 1 : goto __Which_1_of_3_Copies
   if (missile0y + missile0height) >= player4y && missile0y <= (player4y + _c_SpriteHeight) then _VSPointer = 2 : goto __Which_1_of_2_Copies
   if (missile0y + missile0height) >= player5y && missile0y <= (player5y + _c_SpriteHeight) then _VSPointer = 3 : goto __Which_1_of_3_Copies
   if (missile0y + missile0height) >= player6y && missile0y <= (player6y + _c_SpriteHeight) then _VSPointer = 4 : goto __Which_1_of_2_Copies
   if (missile0y + missile0height) >= player7y && missile0y <= (player7y + _c_SpriteHeight) then _VSPointer = 5 : goto __Which_1_of_3_Copies
   if (missile0y + missile0height) >= player8y && missile0y <= (player8y + _c_SpriteHeight) then _VSPointer = 6 : goto __Which_1_of_2_Copies

   goto __Skip_Missile0_Collision

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Jump subsection for rows that have 2 enemy sprites.
   ;
__Which_1_of_2_Copies

   temp1 = _EnemyP2[_VSPointer]

   on temp1 goto __Reset_Missile0 __W7_1_Copy __W7_2_Medium_Copies 

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Jump subsection for rows that have 3 enemy sprites.
   ;
__Which_1_of_3_Copies

   temp2 = _EnemyP2[_VSPointer]

   on temp2 goto __Skip_Missile0_Collision __W7_1_Copy __W7_1_Copy __W7_2_Medium_Copies __W7_1_Copy __W7_2_Wide_Copies __W7_2_Medium_Copies __W7_3_Copies

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Collision with 1 of 3 medium copies.
   ;
__W7_3_Copies

   ;```````````````````````````````````````````````````````````````
   ;  If sprite on the left was hit, switches to 2 medium copies
   ;  and moves copies to the right side.
   ;
   if missile0x <= player2x[_VSPointer]+9 then NUSIZ2[_VSPointer] = $02 : player2x[_VSPointer] = player2x[_VSPointer]+32 : _EnemyP2[_VSPointer] = 3 : goto __Reset_Missile0

   ;```````````````````````````````````````````````````````````````
   ;  If sprite in the middle was hit, switches to 2 wide copies.
   ;
   if missile0x >= player2x[_VSPointer]+33 && missile0x <= player2x[_VSPointer]+41 then NUSIZ2[_VSPointer] = $04 : _EnemyP2[_VSPointer] = 5 : goto __Reset_Missile0

   ;```````````````````````````````````````````````````````````````
   ;  If sprite on the right was hit, switches to 2 medium copies
   ;  and moves copies to the left side.
   ;
   if missile0x >= player2x[_VSPointer]+65 && missile0x <= player2x[_VSPointer]+73 then NUSIZ2[_VSPointer] = $02 : _EnemyP2[_VSPointer] = 3 : goto __Reset_Missile0

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Collision with 1 copy.
   ;
__W7_1_Copy

   ;```````````````````````````````````````````````````````````````
   ;  Last copy on current row is removed and missile0 is reset.
   ;
   if missile0x <= player2x[_VSPointer]+9 then player2y[_VSPointer] = 200 : _EnemyP2[_VSPointer] = 0 : goto __Reset_Missile0

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Collision with 1 of 2 wide copies.
   ;
__W7_2_Wide_Copies

   ;```````````````````````````````````````````````````````````````
   ;  If sprite on the left was hit, switches to 1 copy and moves
   ;  it to the right side.
   ;
   if missile0x <= player2x[_VSPointer]+9 then player2x[_VSPointer] = player2x[_VSPointer]+64 : goto __W7_1_Copy_Remaining

   ;```````````````````````````````````````````````````````````````
   ;  If sprite on the right was hit, switches to 1 copy and moves
   ;  it to the left side.
   ;
   if missile0x >= player2x[_VSPointer]+65 && missile0x <= player2x[_VSPointer]+73 then goto __W7_1_Copy_Remaining

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Collision with 1 of 2 medium copies.
   ;
__W7_2_Medium_Copies

   ;```````````````````````````````````````````````````````````````
   ;  If sprite to the left was hit, switches to 1 copy and moves
   ;  it to the right.
   ;
   if missile0x <= player2x[_VSPointer]+9 then player2x[_VSPointer] = player2x[_VSPointer]+32 : goto __W7_1_Copy_Remaining

   ;```````````````````````````````````````````````````````````````
   ;  If sprite to the right was hit, switches to 1 copy and moves
   ;  it to the left.
   ;
   if missile0x >= player2x[_VSPointer]+33 && missile0x <= player2x[_VSPointer]+41 then goto __W7_1_Copy_Remaining

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Only 1 copy of enemy sprite remaining on current row.
   ;
__W7_1_Copy_Remaining

   NUSIZ2[_VSPointer] = $00 : _EnemyP2[_VSPointer] = 1 : goto __Reset_Missile0

   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;  Missile0 reset after enemy death.
   ;
__Reset_Missile0

   ;```````````````````````````````````````````````````````````````
   ;  Removes missile0 from the screen.
   ;
   missile0y = 241

   ;```````````````````````````````````````````````````````````````
   ;  Clears the fire button restrainer bit so the player can fire. 
   ;
   _Bit1_FireB_Restrainer{1} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Adds to the score based on the wave number.
   ;
   if _Wave = 10 then score = score + 10
   if _Wave = 13 then score = score + 20
   if _Wave = 16 then score = score + 30
   if _Wave = 19 then score = score + 40
   if _Wave = 22 then score = score + 50
   if _Wave = 25 then score = score + 60
   if _Wave = 28 then score = score + 70
   if _Wave = 31 then score = score + 100

   ;```````````````````````````````````````````````````````````````
   ;  Adds to the dead enemy counter.
   ;
   _Dead_Enemy_Counter = _Dead_Enemy_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips sound if game is over.
   ;
   if _Bit2_Game_Over{2} then goto __Skip_Missile0_Collision

   ;```````````````````````````````````````````````````````````````
   ;  Starts the enemy death boom sound effect.
   ;
   _Ch0_Sound = _c_Enemy_Boom : _Ch0_Duration = 1 : _Ch0_Counter = 0

__Skip_Missile0_Collision



   ;****************************************************************
   ;
   ;  Starts a new wave if last enemy has been destroyed.
   ;
   if _Dead_Enemy_Counter > 16 then if _Ch0_Sound <> _c_Enemy_Boom then goto __Enemy_Reset bank6



   ;****************************************************************
   ;
   ;  Erases a line so the enemy shots won't keep coming back on.
   ;
   pfhline 0 173 31 off



   ;***************************************************************
   ;
   ;  Code continues in next bank.
   ;
   goto __Code_Section_2 bank3



   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  End of first section of main loop.
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````




   ;***************************************************************
   ;***************************************************************
   ;
   ;  Enemy animation data.
   ;
__1A_Enemy
   player2-8:
   %00011000
   %00111100
   %00111100
   %00111110
   %00111110
   %10110111
   %11111111
   %11001101
end

   player0color:
   $1A
   $98
   $96
   $9A
   $96
   $94
   $94
   $18
   $98
   $9A
   $98
   $96
   $98
   $96
   $94
   $96
   $94
end


   goto __End_Enemy_Animation
   
__1B_Enemy
   player2-8:
   %00001000
   %00111100
   %00111100
   %01011110
   %01011110
   %11011011
   %11111111
   %10100111
end

   player0color:
   $1A
   $98
   $96
   $9A
   $96
   $94
   $94
   $18
   $16
   $9A
   $98
   $96
   $98
   $96
   $94
   $96
   $94
end

   goto __End_Enemy_Animation

__1C_Enemy
   player2-8:
   %00010000
   %00111100
   %00111100
   %01101110
   %01101110
   %11101101
   %11111111
   %10010011
end

   player0color:
   $1A
   $98
   $96
   $9A
   $96
   $94
   $94
   $18
   $98
   $9A
   $16
   $96
   $98
   $96
   $94
   $96
   $94
end
   goto __End_Enemy_Animation


__1D_Enemy
   player2-8:
   %00011000
   %00111100
   %00111100
   %01110110
   %01110110
   %10110111
   %11111111
   %11001001
end

   player0color:
   $1A
   $98
   $96
   $9A
   $96
   $94
   $94
   $18
   $98
   $9A
   $98
   $96
   $16
   $96
   $94
   $96
   $94
end

   goto __End_Enemy_Animation

__1E_Enemy
   player2-8:
   %00011000
   %00111100
   %00111100
   %01111010
   %01111010
   %11011011
   %11111111
   %10100101
end

   player0color:
   $1A
   $98
   $96
   $9A
   $96
   $94
   $94
   $18
   $98
   $9A
   $98
   $96
   $98
   $96
   $14
   $96
   $94
end

   goto __End_Enemy_Animation

__1F_Enemy
   player2-8:
   %00011000
   %00111100
   %00111100
   %01111100
   %01111100
   %11101101
   %11111111
   %10010011
end

   player0color:
   $1A
   $98
   $96
   $9A
   $96
   $94
   $94
   $18
   $98
   $9A
   $98
   $96
   $98
   $96
   $94
   $96
   $14
end

   goto __End_Enemy_Animation



   ;***************************************************************
   ;
   ;  Sets the shape of the player's ship with 1 damage and sets
   ;  shape and color of health indicator.
   ;
__Player_Damage01

   player0:
   %00001000
   %00011000
   %00010100
   %00101000
   %00111110
   %00101010
   %00001000
   %01001001
   %01001001
   %01011101
   %01010101
   %01010101
   %01101011
   %01011101
   %01001001
   %01010101
   %01010101
end

   player1:
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
end

   player1color:
   $C8
   $C8
   $C8
   $C8
   $C8
   $C8
   $C8
   $C8
   $C8
   $C8
   $C8
   $C8
   $C8
   $C8
   $C8
   $C8
end

   player1y = 160


   goto __Skip_Player_Collision


   ;***************************************************************
   ;
   ;  Sets the shape of the player's ship with 2 damage and sets
   ;  shape and color of health indicator.
   ;
__Player_Damage02

   player0:
   %00001000
   %00001000
   %00010100
   %00101000
   %00011110
   %00101010
   %00001000
   %01001001
   %01001001
   %01011101
   %01010101
   %01010101
   %01101011
   %01011101
   %01001001
   %01010101
   %01010101
end

   player1:
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
end

   player1color:
   $C6
   $C6
   $C6
   $C6
   $C6
   $C6
   $C6
   $C6
   $C6
   $C6
   $C6
   $C6
   $C6
   $C6
end

   player1y = 162


   goto __Skip_Player_Collision


   ;***************************************************************
   ;
   ;  Sets the shape of the player's ship with 3 damage and sets
   ;  shape and color of health indicator.
   ;
__Player_Damage03

   player0:
   %00001000
   %00001000
   %00010100
   %00001000
   %00011100
   %00101110
   %00001000
   %01001001
   %01001001
   %01011101
   %01010101
   %01010101
   %01101011
   %01011101
   %01001001
   %01010101
   %01010101
end

   player1:
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
end

   player1color:
   $1C
   $1C
   $1C
   $1C
   $1C
   $1C
   $1C
   $1C
   $1C
   $1C
   $1C
   $1C
end

   player1y = 164

   goto __Skip_Player_Collision


   ;***************************************************************
   ;
   ;  Sets the shape of the player's ship with 4 damage and sets
   ;  shape and color of health indicator.
   ;
__Player_Damage04

   player0:
   %00001000
   %00001000
   %00010100
   %00001000
   %00011100
   %00101110
   %00001000
   %01001000
   %01001001
   %01011001
   %01010101
   %01010101
   %01101011
   %01011101
   %01001001
   %01010101
   %01010101
end

   player1:
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
end

   player1color:
   $1A
   $1A
   $1A
   $1A
   $1A
   $1A
   $1A
   $1A
   $1A
   $1A
end

   player1y = 166

   goto __Skip_Player_Collision


   ;***************************************************************
   ;
   ;  Sets the shape of the player's ship with 5 damage and sets
   ;  shape and color of health indicator.
   ;
__Player_Damage05

   player0:
   %00001000
   %00001000
   %00010100
   %00001000
   %00011100
   %00101110
   %00001000
   %00001000
   %01001001
   %01011001

   %01000101
   %01010101
   %01101011
   %01011101
   %01001001
   %01010101
   %01010101
end

   player1:
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
end

   player1color:
   $18
   $18
   $18
   $18
   $18
   $18
   $18
   $18
end

   player1y = 168

   goto __Skip_Player_Collision


   ;***************************************************************
   ;
   ;  Sets the shape of the player's ship with 6 damage and sets
   ;  shape and color of health indicator.
   ;
__Player_Damage06

   player0:
   %00001000
   %00001000
   %00000100
   %00001000
   %00011100
   %00011110
   %00001000
   %00001000
   %01001001
   %01011001
   %01000101
   %01010101
   %00101011
   %01011101
   %01001001
   %01010101
   %01010101
end

   player1:
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
end

   player1color:
   $48
   $48
   $48
   $48
   $48
   $48
end

   player1y = 170

   goto __Skip_Player_Collision


   ;***************************************************************
   ;
   ;  Sets the shape of the player's ship with 7 damage and sets
   ;  shape and color of health indicator.
   ;
__Player_Damage07

   player0:
   %00001000
   %00001000
   %00000100
   %00001000
   %00011100
   %00001100
   %00001100
   %00001000
   %01001001
   %00011000
   %01000101
   %01010101
   %00101011
   %01011101
   %01001000
   %01010101
   %01010101
end

   player1:
   %00001111
   %00001111
   %00001111
   %00001111
end

   player1color:
   $46
   $46
   $46
   $46
end

   player1y = 172

   goto __Skip_Player_Collision


   ;***************************************************************
   ;
   ;  Sets the shape of the player's ship with 8 damage and sets
   ;  shape and color of health indicator.
   ;
__Player_Damage08

   player0:
   %00001000
   %00001000
   %00000100
   %00001000
   %00011000
   %00001100
   %00001100
   %00001000
   %01001001
   %00011000
   %01000101
   %01010101
   %00101011
   %01011101
   %01001000
   %00000101
   %01000101
end

   player1:
   %00001111
   %00001111
end

   player1color:
   $44
   $44
end

   player1y = 174

   goto __Skip_Player_Collision



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Data for enemy x movement (wave 1).
   ;
   ;  $FE = -2, $FF = -1, $00 = sit still, $01 = 1, $02 = 2
   ;
   data _D_EnemyX_W1
   $FF,$FE,$FF,$FF,$00,$00,$01,$00,$00,$01,$00,$00,$00,$00
   $01,$02,$01,$01,$00,$00,$FF,$00,$00,$FF,$00,$00,$00,$00
   $FF,$00,$01,$00,$80
end


   ;***************************************************************
   ;***************************************************************
   ;
   ;  Data for enemy x movement (wave 2).
   ;
   data _D_EnemyX_W2
   $FF,$FE,$FF,$FF,$00,$00,$01,$00,$00,$01,$00,$00,$00
   $01,$02,$01,$01,$00,$00,$FF,$00,$00,$FF,$00,$00,$00
   $FF,$00,$01,$00,$80
end


   ;***************************************************************
   ;***************************************************************
   ;
   ;  Data for enemy x movement (wave 3).
   ;
   data _D_EnemyX_W3
   $FF,$FE,$FE,$00,$01,$00,$01,$00,$00
   $01,$02,$02,$00,$FF,$00,$FF,$00,$00
   $FF,$00,$01,$00,$80
end


   ;***************************************************************
   ;***************************************************************
   ;
   ;  Data for enemy x movement (wave 4).
   ;
   data _D_EnemyX_W4
   $FF,$FE,$FE,$00,$02,$00,$00,$00
   $01,$02,$02,$00,$FE,$00,$00,$00
   $FF,$00,$01,$00,$80
end


   ;***************************************************************
   ;***************************************************************
   ;
   ;  Data for enemy x movement (wave 5).
   ;
   data _D_EnemyX_W5
   $FF,$FE,$FE,$00,$02,$00,$00
   $01,$02,$02,$00,$FE,$00,$00
   $FF,$00,$01,$00,$80
end


   ;***************************************************************
   ;***************************************************************
   ;
   ;  Data for enemy x movement (wave 6).
   ;
   data _D_EnemyX_W6
   $FF,$FE,$FE,$00,$00,$02,$00
   $01,$02,$02,$00,$00,$FE,$00
   $02,$00,$FE,$00,$80
end


   ;***************************************************************
   ;***************************************************************
   ;
   ;  Data for enemy x movement (wave 7).
   ;
   data _D_EnemyX_W7
   $FF,$FE,$FE,$00,$02
   $01,$02,$02,$00,$FE
   $FE,$00,$00,$02,$00,$80
end


   ;***************************************************************
   ;***************************************************************
   ;
   ;  Data for y enemy movement. Jumps to the 11th spot after
   ;  the data has been read once.
   ;
   data _D_EnemyY
   $01,$01,$01,$01,$01,$01,$01,$00,$FF,$FE,$FF,$00,$00,$00,$00,$00
   $00,$01,$02,$01,$00,$FF,$FE,$FF,$00,$01,$00,$00,$00,$00,$80
end



   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   bank 3
   temp1 = temp1
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Second section of main loop.
   ;
__Code_Section_2



   ;***************************************************************
   ;
   ;  Channel 0 sound effect check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 0 sounds if sounds are off.
   ;
   if !_Ch0_Sound then goto __Skip_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Decreases the channel 0 duration counter.
   ;
   _Ch0_Duration = _Ch0_Duration - 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 0 sounds if duration counter is greater
   ;  than zero
   ;
   if _Ch0_Duration then goto __Skip_Ch_0



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 001.
   ;
   ;  Enemy explosion sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 001 isn't on.
   ;
   if _Ch0_Sound <> _c_Enemy_Boom then goto __Skip_Ch0_Sound_001

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Enemy_Boom[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Enemy_Boom[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Enemy_Boom[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets Duration.
   ;
   _Ch0_Duration = _SD_Enemy_Boom[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_001



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 002.
   ;
   ;  Player0 missile sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 002 isn't on.
   ;
   if _Ch0_Sound <> _c_Player_Missile then goto __Skip_Ch0_Sound_002

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Player_Missile[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Player_Missile[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Player_Missile[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets duration.
   ;
   _Ch0_Duration = _SD_Player_Missile[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_002



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 003.
   ;
   ;  Player hurt sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 003 isn't on.
   ;
   if _Ch0_Sound <> 3 then goto __Skip_Ch0_Sound_003

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Player_Hurt[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Player_Hurt[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Player_Hurt[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets duration.
   ;
   _Ch0_Duration = _SD_Player_Hurt[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_003



   ;***************************************************************
   ;
   ;  Channel 0 sound effect 004.
   ;
   ;  Player destroyed sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if sound 004 isn't on.
   ;
   if _Ch0_Sound <> 4 then goto __Skip_Ch0_Sound_004

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 0 data.
   ;
   temp4 = _SD_Player_Destroyed[_Ch0_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Clear_Ch_0

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 0 data.
   ;
   _Ch0_Counter = _Ch0_Counter + 1
   temp5 = _SD_Player_Destroyed[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1
   temp6 = _SD_Player_Destroyed[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 0.
   ;
   AUDV0 = temp4
   AUDC0 = temp5
   AUDF0 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets duration.
   ;
   _Ch0_Duration = _SD_Player_Destroyed[_Ch0_Counter] : _Ch0_Counter = _Ch0_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 0 area.
   ;
   goto __Skip_Ch_0

__Skip_Ch0_Sound_004



   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Other channel 0 sound effects go here.
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````



   ;***************************************************************
   ;
   ;  Jumps to end of channel 0 area. (This catches any mistakes.)
   ;
   goto __Skip_Ch_0



   ;***************************************************************
   ;
   ;  Clears channel 0.
   ;
__Clear_Ch_0
   
   _Ch0_Sound = 0 : AUDV0 = 0



   ;***************************************************************
   ;
   ;  End of channel 0 area.
   ;
__Skip_Ch_0



   ;***************************************************************
   ;
   ;  Channel 1 sound effect area.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Decreases the channel 1 duration counter.
   ;
   _Ch1_Duration = _Ch1_Duration - 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips all channel 1 sounds if duration counter is greater
   ;  than zero.
   ;
   if _Ch1_Duration then goto __Skip_Ch_1


   ;***************************************************************
   ;
   ;  Channel 1 sound effect 001.
   ;
   ;  Fire button sound effect.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if left difficulty is switched to A.
   ;
   if !switchleftb then goto __Skip_Chan1_Sound_001

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves first part of channel 1 data.
   ;
   temp4 = _SD_Background[_Ch1_Counter]

   ;```````````````````````````````````````````````````````````````
   ;  Checks for end of data.
   ;
   if temp4 = 255 then goto __Restart_Ch_1

   ;```````````````````````````````````````````````````````````````
   ;  Retrieves more channel 1 data.
   ;
   _Ch1_Counter = _Ch1_Counter + 1
   temp5 = _SD_Background[_Ch1_Counter] : _Ch1_Counter = _Ch1_Counter + 1
   temp6 = _SD_Background[_Ch1_Counter] : _Ch1_Counter = _Ch1_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Plays channel 1.
   ;
   AUDV1 = temp4
   AUDC1 = temp5
   AUDF1 = temp6

   ;```````````````````````````````````````````````````````````````
   ;  Sets duration.
   ;
   _Ch1_Duration = _SD_Background[_Ch1_Counter] : _Ch1_Counter = _Ch1_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Randomly resets the counter so we won't hear the same 3
   ;  notes in a row over and over and over and over.
   ;
   if _Ch1_Counter = 84 then temp5 = rand : if rand > 128 then _Ch1_Counter = 84
   if _Ch1_Counter = 84 then temp5 = rand : if rand > 128 then _Ch1_Counter = 0

   if _Ch1_Counter = 168 then temp5 = rand : if rand > 128 then _Ch1_Counter = 84
   if _Ch1_Counter = 168 then temp5 = rand : if rand > 128 then _Ch1_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to end of channel 1 area.
   ;
   goto __Skip_Ch_1

__Skip_Chan1_Sound_001



   ;***************************************************************
   ;
   ;  Restarts channel 1 background "music."
   ;
__Restart_Ch_1
   
   _Ch1_Duration = 1 : _Ch1_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Randomly changes the counter so we won't hear the same 3
   ;  notes in a row over and over and over and over.
   ;
   temp5 = rand : if rand > 128 then _Ch1_Counter = 84
   temp5 = rand : if rand > 128 then _Ch1_Counter = 168



   ;***************************************************************
   ;
   ;  End of channel 1 area.
   ;
__Skip_Ch_1



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0: goto __Main_Loop bank2

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop bank2

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart bank6




   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  End of main loop.
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````



   ;***************************************************************
   ;***************************************************************
   ;
   ;
   ;  Sound effect data starts here.
   ;
   ;
   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for enemy boom explosion sound effect.
   ;
   data _SD_Enemy_Boom
   10,14,2
   1
   9,8,2
   1
   8,8,31
   1
   12,2,12
   2
   11,2,11
   2
   10,2,10
   2
   9,2,9
   2
   8,2,8
   2
   7,2,7
   2
   6,2,6
   2
   5,2,5
   2
   4,2,4
   2
   3,2,3
   2
   2,2,2
   2
   1,8,31
   8
   255
end



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for shooting sound effect.
   ;
   data _SD_Player_Missile
   7,8,31
   1
   7,8,0
   1
   6,12,5
   1
   5,8,31
   1
   4,12,8
   1
   3,8,31
   1
   2,12,11
   1
   2,8,31
   1
   2,12,14
   1
   2,8,31
   1
   2,12,17
   1
   2,8,31
   1
   2,12,20
   1
   1,8,31
   8
   255
   7,8,31
   1
   7,8,0
   1
   6,12,5
   1
   5,8,31
   1
   4,12,7
   1
   3,8,31
   1
   2,12,9
   1
   2,8,31
   1
   2,12,11
   1
   2,8,31
   1
   2,12,13
   1
   2,8,31
   1
   2,12,15
   1
   1,8,31
   8
   255
   7,8,31
   1
   7,8,0
   1
   6,12,5
   1
   5,8,31
   1
   4,12,9
   1
   3,8,31
   1
   2,12,13
   1
   2,8,31
   1
   2,12,17
   1
   2,8,31
   1
   2,12,21
   1
   2,8,31
   1
   2,12,25
   1
   1,8,31
   8
   255
end



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for player hurt sound effect.
   ;
   data _SD_Player_Hurt
   5,8,11
   1
   4,8,11
   1
   3,8,11
   1
   2,8,11
   1
   3,8,11
   1
   2,8,11
   1
   2,8,11
   8
   1,8,11
   8
   255
end


   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for player destroid sound effect.
   ;
   data _SD_Player_Destroyed
   10,8,31
   2
   12,2,12
   2
   11,2,11
   2
   10,2,10
   2
   10,8,31
   2
   9,2,9
   2
   9,8,31
   2
   8,2,8
   2
   7,2,7
   2
   6,2,6
   2
   5,2,5
   2
   5,8,31
   2
   4,2,4
   2
   3,2,3
   2
   3,8,31
   2
   2,2,2
   2
   1,8,31
   16
   255
end



   ;***************************************************************
   ;***************************************************************
   ;
   ;  Sound data for background "music."
   ;
   data _SD_Background
   2,6,30
   4
   2,6,28
   4
   2,6,30
   4
   2,6,28
   4
   2,6,30
   4
   2,6,28
   4
   2,6,30
   4
   2,6,28
   4
   2,6,30
   4
   2,6,28
   4
   2,6,30
   4
   2,6,28
   4
   2,6,30
   4
   2,6,28
   4
   2,6,30
   4
   2,6,28
   4
   2,6,30
   4
   2,6,28
   4
   2,6,30
   4
   2,6,28
   4
   2,6,30
   4
   2,6,27
   4
   2,6,25
   4
   2,6,27
   4
   2,6,25
   4
   2,6,27
   4
   2,6,25
   4
   2,6,27
   4
   2,6,25
   4
   2,6,27
   4
   2,6,25
   4
   2,6,27
   4
   2,6,25
   4
   2,6,27
   4
   2,6,25
   4
   2,6,27
   4
   2,6,25
   4
   2,6,27
   4
   2,6,25
   4
   2,6,27
   4
   2,6,25
   4
   2,6,27
   4
   2,6,24
   4
   2,6,22
   4
   2,6,24
   4
   2,6,22
   4
   2,6,24
   4
   2,6,22
   4
   2,6,24
   4
   2,6,22
   4
   2,6,24
   4
   2,6,22
   4
   2,6,24
   4
   2,6,22
   4
   2,6,24
   4
   2,6,22
   4
   2,6,24
   4
   2,6,22
   4
   2,6,24
   4
   2,6,22
   4
   2,6,24
   4
   2,6,22
   4
   2,6,24
   4
   255
end



   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   bank 4
   temp1 = temp1
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````



   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   bank 5
   temp1 = temp1
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````



   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   bank 6
   temp1 = temp1
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````



   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  176 rows that are 1 scanline high except the top and bottom
   ;  rows (which seem to be 2 scanlines high). All of the colors
   ;  seem to be 2 scanlines high.
   ;
   DF6FRACINC = 0 : DF4FRACINC = 0
   DF0FRACINC = 255 : DF1FRACINC = 255 : DF2FRACINC = 255 : DF3FRACINC = 255


   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen


   ;***************************************************************
   ;
   ;  Clears the screen.
   ;
   pfclear


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Sets playfield colors.
   ;
   pfcolors:
   $94
end


   ;***************************************************************
   ;
   ;  Sets background colors.
   ;
   bkcolors:
   $00
end


   ;***************************************************************
   ;
   ;  Clears the score.
   ;
   score = 0


   ;***************************************************************
   ;
   ;  Sets score colors.
   ;
   scorecolors:
   $AE
   $AE
   $AC
   $AC
   $AA
   $AA
   $A8
   $A8
end


   ;***************************************************************
   ;
   ;  Sets the color used by enemies.
   ;
   player2-8color:
   $18
   $42
   $44
   $46
   $46
   $44
   $42
   $38
end


   ;***************************************************************
   ;
   ;  Sets the color of the player's ship.
   ;
   player0color:
   $1A
   $98
   $96
   $9A
   $96
   $94
   $94
   $18
   $98
   $9A
   $98
   $96
   $98
   $96
   $94
   $96
   $94
end


   ;***************************************************************
   ;
   ;  Sets the shape of the player's ship.
   ;
   player0:
   %00001000
   %00011100
   %00010100
   %00101010
   %00111110
   %00101010
   %00001000
   %01001001
   %01001001
   %01011101
   %01010101
   %01010101
   %01101011
   %01011101
   %01001001
   %01010101
   %01010101
end


   ;***************************************************************
   ;
   ;  Sets the color of the player's health indicator.
   ;
   player1color:
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
   $CA
end


   ;***************************************************************
   ;
   ;  Sets the shape of the player's health indicator.
   ;
   player1:
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
   %00001111
end


   ;***************************************************************
   ;
   ;  Clears all normal variables and the extra 9 (fastest way).
   ;
   asm
   LDA #0
   STA a
   STA b
   STA c
   STA d
   STA e
   STA f
   STA g
   STA h
   STA i
   STA j
   STA k
   STA l
   STA m
   STA n
   STA o
   STA p
   STA q
   STA r
   STA s
   STA t
   STA u
   STA v
   STA w
   STA x
   STA y
   STA z
   STA var0
   STA var1
   STA var2
   STA var3
   STA var4
   STA var5
   STA var6
   STA var7
   STA var8
end


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once. The fire
   ;  button is also restrained.
   ;
   _Bit0_Reset_Restrainer{0} = 1 : _Bit1_FireB_Restrainer{1} = 1

   
   ;***************************************************************
   ;
   ;  Puts borders on the sides of the playfield.
   ;
   PF0 = %10000000


   ;***************************************************************
   ;
   ;  Sets missile height.
   ;
   missile0height = 5


   ;***************************************************************
   ;
   ;  Sets color of missile.
   ;
   COLUM0 = $CC


   ;***************************************************************
   ;
   ;  Sets the position of the player's ship.
   ;
   player0x = 77 : player0y = 158


   ;***************************************************************
   ;
   ;  Sets the position of the player's health indicator.
   ;
   player1x = 0 : player1y = 158


   ;***************************************************************
   ;
   ;  Sets player damage counter.
   ;
   _Damage_Counter = 255


   ;***************************************************************
   ;
   ;  Starts background "music."
   ;
   _Ch1_Duration = 1 : _Ch1_Counter = 0


   ;***************************************************************
   ;
   ;  Sets wave at 7 so it will start at 10 when 3 is added to it.
   ;
   _Wave = 7


   ;***************************************************************
   ;
   ;  Game jumps here when a new wave starts.
   ;
__Enemy_Reset


   ;***************************************************************
   ;
   ;  Makes sure the missile is off screen.
   ;
   missile0y = 241


   ;***************************************************************
   ;
   ;  Clears certain counters.
   ;
   _Master_Counter = 0 : _Enemy_D_Counter_y = 0 : _Enemy_D_Counter_x = 0 : _Dead_Enemy_Counter = 0


   ;***************************************************************
   ;
   ;  Sets NUSIZ and variables related to the enemy sprites.
   ;
   NUSIZ2 = $02 : NUSIZ4 = $02 : NUSIZ6 = $02 : NUSIZ8 = $02 : _EnemyP8 = 2 : _EnemyP6 = 2 : _EnemyP4 = 2 : _EnemyP2 = 2
   NUSIZ3 = $06 : NUSIZ5 = $06 : NUSIZ7 = $06
   _EnemyP7 = 7 : _EnemyP5 = 7 : _EnemyP3 = 7


   ;***************************************************************
   ;
   ;  Sets positions of enemy sprites.
   ;
   player2y = 201
   player3y = player2y + 14
   player4y = player3y + 14
   player5y = player4y + 14
   player6y = player5y + 14
   player7y = player6y + 14
   player8y = player7y + 14

   player2x = 71 :  player4x = 71 : player6x = 71 :  player8x = 71
   player3x = 55 :  player5x = 55 : player7x = 55


   ;***************************************************************
   ;
   ;  Increases the wave. Makes the "game" harder.
   ;
   if _Wave < 31 then _Wave = _Wave + 3


   goto __Main_Loop bank2

 

 

 

Shared 8.8 Type Movement (DPC+)

Shared 8.8 Type Movement (DPC+) on bB page.

 
   ;***************************************************************
   ;
   ;  Shared 8.8 Type Movement
   ;
   ;  Example program by Lillapojkenpaon and adapted by Duane Alan
   ;  Hahn (Random Terrain) using hints, tips, code snippets, and
   ;  more from AtariAge members such as batari, SeaGtGruff,
   ;  RevEng, Robert M, Nukey Shay, Atarius Maximus, jrok,
   ;  supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Push the joystick left or right to change the speed.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;****************************************************************
   ;
   ;  This program uses the DPC+ kernel.
   ;
   set kernel DPC+



   ;****************************************************************
   ;
   ;  Standard used in North America and most of South America.
   ;
   set tv ntsc



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  a is integer, b is fraction.
   ;
   dim _8_8_Speed = a.b
   dim _Integer = a
   dim _Fraction = b

   ;```````````````````````````````````````````````````````````````
   ;  Counter for the fraction.
   ;
   dim _Fraction_Counter = c

   ;```````````````````````````````````````````````````````````````
   ;  Temporarily remembers the fraction counter value.
   ;
   dim _Frac_Mem = temp5

   ;```````````````````````````````````````````````````````````````
   ;  Temporarily remembers the speed.
   ;
   dim _Speed = temp6

   ;```````````````````````````````````````````````````````````````
   ;  All-purpose bits for various jobs.
   ;
   dim _Bit0_Reset_Restrainer = y ; Reset switch becomes inactive if it hasn't been released.



   goto __Bank_2 bank2



   bank 2
   temp1=temp1



__Bank_2




   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables and the extra 9.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0
   var0 = 0 : var1 = 0 : var2 = 0 : var3 = 0 : var4 = 0
   var5 = 0 : var6 = 0 : var7 = 0 : var8 = 0


   ;***************************************************************
   ;
   ;  Sets colors for player1 through player8.
   ;
   player1-8color:
   $8E
   $8C
   $8A
   $88
   $86
end


   ;***************************************************************
   ;
   ;  Sets same shape for player1 through player8.
   ;
   player1-8:
   %11111111
   %11111111
   %11111111
   %11111111
   %11111111
end


   ;***************************************************************
   ;
   ;  Sets positions for player1 through player4.
   ;
   player1x = 69 : player2x = 69 : player3x = 69 : player4x = 69
   player5x = 69 : player6x = 69 : player7x = 69 : player8x = 69

   player1y = 17 : player2y = player1y + 18 : player3y = player2y + 17
   player4y = player3y + 18 : player5y = player4y + 17 : player6y = player5y + 18
   player7y = player6y + 17 : player8y = player7y + 18


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets startup speed.
   ;
   _8_8_Speed  = 0.85





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Fraction counter section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Remembers fraction counter value.
   ;
   _Frac_Mem = _Fraction_Counter

   ;```````````````````````````````````````````````````````````````
   ;  Increases fraction counter.
   ;
   _Fraction_Counter = _Fraction_Counter + _Fraction

   ;```````````````````````````````````````````````````````````````
   ;  Speed is increased when fraction counter is rolled over.
   ;
   _Speed = _Integer : if _Fraction_Counter < _Frac_Mem then _Speed = _Speed + 1



   ;***************************************************************
   ;
   ;  Moves 8 sprites.
   ;
   player1x = player1x - _Speed
   player2x = player2x + _Speed
   player3x = player3x - _Speed
   player4x = player4x + _Speed
   player5x = player5x - _Speed
   player6x = player6x + _Speed
   player7x = player7x - _Speed
   player8x = player8x + _Speed



   ;***************************************************************
   ;
   ;  Decreases speed if joystick is pushed left.
   ;
   if joy0left then _8_8_Speed = _8_8_Speed - 0.05



   ;***************************************************************
   ;
   ;  Increases speed if joystick is pushed right.
   ;
   if joy0right then _8_8_Speed = _8_8_Speed + 0.05



   ;***************************************************************
   ;
   ;  88 rows that are 2 scanlines high.
   ;
   DF6FRACINC = 0 : DF4FRACINC = 0

   DF0FRACINC = 128 : DF1FRACINC = 128 : DF2FRACINC = 128 : DF3FRACINC = 128



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart





   bank 3
   temp1=temp1





   bank 4
   temp1=temp1





   bank 5
   temp1=temp1





   bank 6
   temp1=temp1

 

 

 

DFxFRACINC Tool (DPC+)

DFxFRACINC Tool (DPC+) on bB page.

 
   ;***************************************************************
   ;
   ;  DFxFRACINC Tool (DPC+)
   ;
   ;  By Duane Alan Hahn (Random Terrain) using hints, tips,
   ;  code snippets, and more from AtariAge members such as
   ;  batari, SeaGtGruff, RevEng, Robert M, Atarius Maximus,
   ;  jrok, Nukey Shay, supercat, and GroovyBee.
   ;
   ;  Score code provided by bogax.
   ;  Score background color asm code provided by RevEng.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions
   ;  
   ;  Press the joystick left or right to select DF6FRACINC,
   ;  DF0FRACINC, DF1FRACINC, DF2FRACINC, DF3FRACINC or
   ;  DF4FRACINC. Press the joystick up or down to increase or
   ;  decrease the selected register. Press the fire button to
   ;  slow things down when you get near a number that you'd like
   ;  to stop on. Hit reset to go back to the default settings.
   ;  Use the select switch to choose a preset selection.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Date created: 2013y_09m_11d_0149t
   ;
   ;  Date Updated: 2025y_01m_19d_2347t
   ;
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;****************************************************************
   ;
   ;  This program uses the DPC+ kernel.
   ;
   set kernel DPC+



   ;****************************************************************
   ;
   ;  Standard used in North America and most of South America.
   ;
   set tv ntsc




   goto __Start_Restart bank2




   ;***************************************************************
   ;
   ;  Sets score background color.
   ;
   asm
minikernel
   ldx #$00
   stx COLUBK
   rts
end





   bank 2
   temp1=temp1





   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Switches between DFxFRACINC registers.
   ;
   dim _Current_Selection = a

   ;```````````````````````````````````````````````````````````````
   ;  DFxFRACINC register values.
   ;
   dim _Frac0 = b
   dim _Frac1 = c
   dim _Frac2 = d
   dim _Frac3 = e
   dim _Frac4 = f
   dim _Frac6 = h

   ;```````````````````````````````````````````````````````````````
   ;  Select switch preset variable.
   ;
   dim _Select_Switch = i

   ;```````````````````````````````````````````````````````````````
   ;  Select switch counter.
   ;
   dim _Select_Counter = j

   ;```````````````````````````````````````````````````````````````
   ;  Fire button counter.
   ;
   dim _FB_Counter = p

   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _Bit0_Reset_Restrainer = t
   dim _Bit1_Joy0_Restrainer = t

   ;```````````````````````````````````````````````````````````````
   ;  Splits up the score into 3 parts.
   ;
   dim _sc1 = score
   dim _sc2 = score+1
   dim _sc3 = score+2



   ;***************************************************************
   ;
   ;  Constants for DFxFRACINC.
   ;  [The c stands for constant.]
   ;
   const _c_Background_Color = 0
   const _c_Column0 = 1
   const _c_Column1 = 2
   const _c_Column2 = 3
   const _c_Column3 = 4
   const _c_Forground_Color = 5



   ;****************************************************************
   ;
   ;  NTSC colors.
   ;
   ;  Use these constants so you can quickly and easily swap them
   ;  out for PAL-60 colors. Or use this if you created a PAL-60
   ;  game and want to instantly convert the colors to NTSC (if you
   ;  were already using the PAL-60 constants).
   ;
   const _00 = $00
   const _02 = $02
   const _04 = $04
   const _06 = $06
   const _08 = $08
   const _0A = $0A
   const _0C = $0C
   const _0E = $0E
   const _10 = $10
   const _12 = $12
   const _14 = $14
   const _16 = $16
   const _18 = $18
   const _1A = $1A
   const _1C = $1C
   const _1E = $1E
   const _20 = $20
   const _22 = $22
   const _24 = $24
   const _26 = $26
   const _28 = $28
   const _2A = $2A
   const _2C = $2C
   const _2E = $2E
   const _30 = $30
   const _32 = $32
   const _34 = $34
   const _36 = $36
   const _38 = $38
   const _3A = $3A
   const _3C = $3C
   const _3E = $3E
   const _40 = $40
   const _42 = $42
   const _44 = $44
   const _46 = $46
   const _48 = $48
   const _4A = $4A
   const _4C = $4C
   const _4E = $4E
   const _50 = $50
   const _52 = $52
   const _54 = $54
   const _56 = $56
   const _58 = $58
   const _5A = $5A
   const _5C = $5C
   const _5E = $5E
   const _60 = $60
   const _62 = $62
   const _64 = $64
   const _66 = $66
   const _68 = $68
   const _6A = $6A
   const _6C = $6C
   const _6E = $6E
   const _70 = $70
   const _72 = $72
   const _74 = $74
   const _76 = $76
   const _78 = $78
   const _7A = $7A
   const _7C = $7C
   const _7E = $7E
   const _80 = $80
   const _82 = $82
   const _84 = $84
   const _86 = $86
   const _88 = $88
   const _8A = $8A
   const _8C = $8C
   const _8E = $8E
   const _90 = $90
   const _92 = $92
   const _94 = $94
   const _96 = $96
   const _98 = $98
   const _9A = $9A
   const _9C = $9C
   const _9E = $9E
   const _A0 = $A0
   const _A2 = $A2
   const _A4 = $A4
   const _A6 = $A6
   const _A8 = $A8
   const _AA = $AA
   const _AC = $AC
   const _AE = $AE
   const _B0 = $B0
   const _B2 = $B2
   const _B4 = $B4
   const _B6 = $B6
   const _B8 = $B8
   const _BA = $BA
   const _BC = $BC
   const _BE = $BE
   const _C0 = $C0
   const _C2 = $C2
   const _C4 = $C4
   const _C6 = $C6
   const _C8 = $C8
   const _CA = $CA
   const _CC = $CC
   const _CE = $CE
   const _D0 = $D0
   const _D2 = $D2
   const _D4 = $D4
   const _D6 = $D6
   const _D8 = $D8
   const _DA = $DA
   const _DC = $DC
   const _DE = $DE
   const _E0 = $E0
   const _E2 = $E2
   const _E4 = $E4
   const _E6 = $E6
   const _E8 = $E8
   const _EA = $EA
   const _EC = $EC
   const _EE = $EE
   const _F0 = $F0
   const _F2 = $F2
   const _F4 = $F4
   const _F6 = $F6
   const _F8 = $F8
   const _FA = $FA
   const _FC = $FC
   const _FE = $FE





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Displays the screen to avoid going over 262.
   ;
   drawscreen


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0


   ;***************************************************************
   ;
   ;  Sets playfield.
   ;
   playfield:
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
   .XXXXXX..XXXXXX..XXXXXX..XXXXXX.
   .X....X..X....X..X....X..X....X.
end


   ;***************************************************************
   ;
   ;  Sets playfield colors.
   ;
   pfcolors:
   _0E
   _0C
   _0A
   _08
   _06
   _1E
   _1C
   _1A
   _18
   _16
   _2E
   _2C
   _2A
   _28
   _26
   _3E
   _3C
   _3A
   _38
   _36
   _4E
   _4C
   _4A
   _48
   _46
   _5E
   _5C
   _5A
   _58
   _56
   _6E
   _6C
   _6A
   _68
   _66
   _7E
   _7C
   _7A
   _78
   _76
   _9E
   _9C
   _9A
   _98
   _96
   _AE
   _AC
   _AA
   _A8
   _A6
   _BE
   _BC
   _BA
   _B8
   _B6
   _CE
   _CC
   _CA
   _C8
   _C6
   _DE
   _DC
   _DA
   _D8
   _D6
   _EE
   _EC
   _EA
   _E8
   _E6
   _3E
   _3C
   _3A
   _38
   _36
   _4E
   _4C
   _4A
   _48
   _46
   _5E
   _5C
   _5A
   _58
   _56
   _6E
   _6C
   _6A
   _68
   _66
end


   ;***************************************************************
   ;
   ;  Sets background colors.
   ;
   bkcolors:
   _80
   _82
   _84
   _86
   _88
   _8A
   _8C
   _8E
   _80
   _82
   _84
   _86
   _88
   _8A
   _8C
   _8E
   _80
   _82
   _84
   _86
   _88
   _8A
   _8C
   _8E
   _80
   _82
   _84
   _86
   _88
   _8A
   _8C
   _8E
   _80
   _82
   _84
   _86
   _88
   _8A
   _8C
   _8E
   _80
   _82
   _84
   _86
   _88
   _8A
   _8C
   _8E
   _80
   _82
   _84
   _86
   _88
   _8A
   _8C
   _8E
   _80
   _82
   _84
   _86
   _88
   _8A
   _8C
   _8E
   _80
   _82
   _84
   _86
   _88
   _8A
   _8C
   _8E
   _80
   _82
   _84
   _86
   _88
   _8A
   _8C
   _8E
   _80
   _82
   _84
   _86
   _88
   _8A
   _8C
   _80
end


   ;***************************************************************
   ;
   ;  Sprite colors.
   ;
   player0color:
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
   _FE
end


   ;***************************************************************
   ;
   ;  Sets color of missiles.
   ;
   COLUM0 = _FE : COLUM1 = _FE


   ;***************************************************************
   ;
   ;  Sets height of missiles.
   ;
   missile0height = 220 : missile1height = 220


   ;***************************************************************
   ;
   ;  Sets repetition restrainer for the reset switch.
   ;  (Holding it down won't make it keep resetting.)
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Sets starting values used by DFxFRACINC registers.
   ;
   _Frac0 = 128 : _Frac1 = 128 : _Frac2 = 128 : _Frac3 = 128
   _Frac4 = 255 : _Frac6 = 255


   ;***************************************************************
   ;
   ;  Sets starting value for select switch.
   ;
   _Select_Switch = 1


   ;***************************************************************
   ;
   ;  Sets default DFxFRACINC register selection.
   ;
   _Current_Selection = _c_Column0


   ;***************************************************************
   ;
   ;  Gets default sprite info, missile info, and score colors.
   ;
   goto __DF0





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Current selection.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Clears joystick restrainer bit and skips this section if 
   ;  joy0 not moved left or right.
   ;
   if !joy0left && !joy0right then _Bit1_Joy0_Restrainer{1} = 0 : goto __Skip_Selection

   ;```````````````````````````````````````````````````````````````
   ;  Skips all movement if joystick already moved.
   ;
   if _Bit1_Joy0_Restrainer{1} then goto __Skip_All

   ;```````````````````````````````````````````````````````````````
   ;  Turns on the joystick repetition restrainer bit.
   ;
   _Bit1_Joy0_Restrainer{1} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Switches selection if joystick is moved left or right.
   ;
   if joy0left then _Current_Selection = _Current_Selection - 1 : if _Current_Selection = 255 then _Current_Selection = _c_Forground_Color

   if joy0right then _Current_Selection = _Current_Selection + 1 : if _Current_Selection > _c_Forground_Color then _Current_Selection = _c_Background_Color

   if _Current_Selection = _c_Background_Color then goto __DF6
   if _Current_Selection = _c_Column0 then goto __DF0
   if _Current_Selection = _c_Column1 then goto __DF1
   if _Current_Selection = _c_Column2 then goto __DF2
   if _Current_Selection = _c_Column3 then goto __DF3
   if _Current_Selection = _c_Forground_Color then goto __DF4

__Skip_Selection



   ;***************************************************************
   ;
   ;  Decreases or increases selected DFxFRACINC register.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if joystick not moved up or down.
   ;
   if !joy0up && !joy0down then goto __Skip_All

   ;```````````````````````````````````````````````````````````````
   ;  Skips slowdown code if fire button not pressed.
   ;
   if !joy0fire then goto __Skip_FB_Check

   ;```````````````````````````````````````````````````````````````
   ;  Slows down size change.
   ;
   if _FB_Counter <= 9 then _FB_Counter = _FB_Counter + 1 : goto __Skip_Size_Increase

__Skip_FB_Check

   ;```````````````````````````````````````````````````````````````
   ;  Resets the slowdown counter.
   ;
   _FB_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if joystick not moved down.
   ;
   if !joy0down then goto __Skip_Size_Decrease

   ;```````````````````````````````````````````````````````````````
   ;  Joystick moved down. Decreases size of appropriate object.
   ;
   if _Current_Selection = _c_Background_Color then _Frac6 = _Frac6 - 1
   if _Current_Selection = _c_Column0 then _Frac0 = _Frac0 - 1
   if _Current_Selection = _c_Column1 then _Frac1 = _Frac1 - 1
   if _Current_Selection = _c_Column2 then _Frac2 = _Frac2 - 1
   if _Current_Selection = _c_Column3 then _Frac3 = _Frac3 - 1
   if _Current_Selection = _c_Forground_Color then _Frac4 = _Frac4 - 1

   goto __Skip_Size_Increase

__Skip_Size_Decrease

   ;```````````````````````````````````````````````````````````````
   ;  Skips ahead if joystick not moved up.
   ;
   if !joy0up then goto __Skip_Size_Increase

   ;```````````````````````````````````````````````````````````````
   ;  Joystick moved up. Increases size of appropriate object.
   ;
   if _Current_Selection = _c_Background_Color then _Frac6 = _Frac6 + 1
   if _Current_Selection = _c_Column0 then _Frac0 = _Frac0 + 1
   if _Current_Selection = _c_Column1 then _Frac1 = _Frac1 + 1
   if _Current_Selection = _c_Column2 then _Frac2 = _Frac2 + 1
   if _Current_Selection = _c_Column3 then _Frac3 = _Frac3 + 1
   if _Current_Selection = _c_Forground_Color then _Frac4 = _Frac4 + 1

__Skip_Size_Increase

__Skip_All



   ;***************************************************************
   ;
   ;  Select switch presets.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Sets select counter to maximum and skips this section if
   ;  the select switch is not pressed.
   ;
   if !switchselect then _Select_Counter = 30 : goto __Done_Select

   ;```````````````````````````````````````````````````````````````
   ;  Adds one to the select counter.
   ;
   _Select_Counter = _Select_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if select counter value is less than 30.
   ;
   if _Select_Counter < 30 then goto __Done_Select

   ;```````````````````````````````````````````````````````````````
   ;  Clears the select counter.
   ;
   _Select_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Increases select switch preset counter.
   ;
   _Select_Switch = _Select_Switch + 1

   ;```````````````````````````````````````````````````````````````
   ;  Limits the select switch preset counter.
   ;
   if _Select_Switch > 5 then _Select_Switch = 0

   ;```````````````````````````````````````````````````````````````
   ;  Gets preset information.
   ;
   on _Select_Switch goto __Preset255 __Preset128 __Preset64 __Preset32 __Preset16 __Preset8

__Done_Select



   ;***************************************************************
   ;
   ;  Puts temp4 in the three score digits on the right side.
   ;
   if _Current_Selection = _c_Background_Color then temp4 = _Frac6
   if _Current_Selection = _c_Column0 then temp4 = _Frac0
   if _Current_Selection = _c_Column1 then temp4 = _Frac1
   if _Current_Selection = _c_Column2 then temp4 = _Frac2
   if _Current_Selection = _c_Column3 then temp4 = _Frac3
   if _Current_Selection = _c_Forground_Color then temp4 = _Frac4

   _sc2 = _sc2 & 240 : _sc3 = 0
   if temp4 >= 100 then _sc2 = _sc2 + 1 : temp4 = temp4 - 100
   if temp4 >= 100 then _sc2 = _sc2 + 1 : temp4 = temp4 - 100
   if temp4 >= 50 then _sc3 = _sc3 + 80 : temp4 = temp4 - 50
   if temp4 >= 30 then _sc3 = _sc3 + 48 : temp4 = temp4 - 30
   if temp4 >= 20 then _sc3 = _sc3 + 32 : temp4 = temp4 - 20
   if temp4 >= 10 then _sc3 = _sc3 + 16 : temp4 = temp4 - 10
   _sc3 = _sc3 | temp4



   ;***************************************************************
   ;
   ;  Sets DFxFRACINC registers.
   ;
   DF6FRACINC = _Frac6 ; Background colors.
   DF4FRACINC = _Frac4 ; Playfield colors.

   DF0FRACINC = _Frac0 ; Column 0.
   DF1FRACINC = _Frac1 ; Column 1.
   DF2FRACINC = _Frac2 ; Column 2.
   DF3FRACINC = _Frac3 ; Column 3.



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;***************************************************************
   ;***************************************************************
   ;
   ;  Selections start here.
   ;
__DF6
   player0:
   %11000000
   %10100000
   %10100000
   %10100000
   %10100000
   %10100000
   %11000000
   %00000000
   %00000000
   %11100000
   %10000000
   %10000000
   %11000000
   %10000000
   %10000000
   %10000000
   %00000000
   %00000000
   %01000000
   %10100000
   %10000000
   %11000000
   %10100000
   %10100000
   %01000000
end

   player0x = 8 : player0y = 3
   missile0x = 2 : missile1x = missile0x + 16

   scorecolors:
   $AE
   $AC
   $AA
   $AA
   $A8
   $A8
   $A6
   $A6
end

   goto __Skip_Selection


   ;***************************************************************
   ;
__DF0
   player0:
   %11000000
   %10100000
   %10100000
   %10100000
   %10100000
   %10100000
   %11000000
   %00000000
   %00000000
   %11100000
   %10000000
   %10000000
   %11000000
   %10000000
   %10000000
   %10000000
   %00000000
   %00000000
   %01000000
   %10100000
   %10100000
   %10100000
   %10100000
   %10100000
   %01000000
end

   player0x = 14 : player0y = 3
   missile0x = 19 : missile1x = missile0x + 27

   scorecolors:
   $4E
   $4C
   $4A
   $4A
   $48
   $48
   $46
   $46
end

   goto __Skip_Selection


   ;***************************************************************
   ;
__DF1
   player0:
   %11000000
   %10100000
   %10100000
   %10100000
   %10100000
   %10100000
   %11000000
   %00000000
   %00000000
   %11100000
   %10000000
   %10000000
   %11000000
   %10000000
   %10000000
   %10000000
   %00000000
   %00000000
   %01000000
   %01000000
   %01000000
   %01000000
   %01000000
   %01000000
   %01000000
end

   player0x = 46 : player0y = 3
   missile0x = 51 : missile1x = missile0x + 27

   scorecolors:
   $CE
   $CC
   $CA
   $CA
   $C8
   $C8
   $C6
   $C6
end

   goto __Skip_Selection


   ;***************************************************************
   ;
__DF2
   player0:
   %11000000
   %10100000
   %10100000
   %10100000
   %10100000
   %10100000
   %11000000
   %00000000
   %00000000
   %11100000
   %10000000
   %10000000
   %11000000
   %10000000
   %10000000
   %10000000
   %00000000
   %00000000
   %01000000
   %10100000
   %00100000
   %01000000
   %10000000
   %10000000
   %11100000
end

   player0x = 78 : player0y = 3
   missile0x = 83 : missile1x = missile0x + 27

   scorecolors:
   $2E
   $2C
   $2A
   $2A
   $28
   $28
   $26
   $26
end

   goto __Skip_Selection


   ;***************************************************************
   ;
__DF3
   player0:
   %11000000
   %10100000
   %10100000
   %10100000
   %10100000
   %10100000
   %11000000
   %00000000
   %00000000
   %11100000
   %10000000
   %10000000
   %11000000
   %10000000
   %10000000
   %10000000
   %00000000
   %00000000
   %01000000
   %10100000
   %00100000
   %01000000
   %00100000
   %10100000
   %01000000
end

   player0x = 110 : player0y = 3
   missile0x = 115 : missile1x = missile0x + 27

   scorecolors:
   $6E
   $6C
   $6A
   $6A
   $68
   $68
   $66
   $66
end

   goto __Skip_Selection


   ;***************************************************************
   ;
__DF4
   player0:
   %11000000
   %10100000
   %10100000
   %10100000
   %10100000
   %10100000
   %11000000
   %00000000
   %00000000
   %11100000
   %10000000
   %10000000
   %11000000
   %10000000
   %10000000
   %10000000
   %00000000
   %00000000
   %10100000
   %10100000
   %10100000
   %11100000
   %00100000
   %00100000
   %00100000
end

   player0x = 149 : player0y = 3
   missile0x = 143 : missile1x = missile0x + 15

   scorecolors:
   $1E
   $1C
   $1A
   $1A
   $18
   $18
   $16
   $16
end

   goto __Skip_Selection




   ;***************************************************************
   ;***************************************************************
   ;
   ;  Presets start here.
   ;
__Preset255

   _Frac0 = 255 : _Frac1 = 255 : _Frac2 = 255 : _Frac3 = 255
   _Frac4 = 255 : _Frac6 = 255

   goto __Done_Select


   ;***************************************************************
   ;
__Preset128

   _Frac0 = 128 : _Frac1 = 128 : _Frac2 = 128 : _Frac3 = 128
   _Frac4 = 255 : _Frac6 = 255

   goto __Done_Select


   ;***************************************************************
   ;
__Preset64

   _Frac0 = 64 : _Frac1 = 64 : _Frac2 = 64 : _Frac3 = 64
   _Frac4 = 128 : _Frac6 = 128

   goto __Done_Select


   ;***************************************************************
   ;
__Preset32

   _Frac0 = 32 : _Frac1 = 32 : _Frac2 = 32 : _Frac3 = 32
   _Frac4 = 64 : _Frac6 = 64

   goto __Done_Select


   ;***************************************************************
   ;
__Preset16

   _Frac0 = 16 : _Frac1 = 16 : _Frac2 = 16 : _Frac3 = 16
   _Frac4 = 32 : _Frac6 = 32

   goto __Done_Select


   ;***************************************************************
   ;
__Preset8

   _Frac0 = 8 : _Frac1 = 8 : _Frac2 = 8 : _Frac3 = 8
   _Frac4 = 16 : _Frac6 = 16

   goto __Done_Select




   bank 3
   temp1=temp1




   bank 4
   temp1=temp1




   bank 5
   temp1=temp1




   bank 6
   temp1=temp1

 

 

 

Playfield Color & Background Color Scrolling With Changeable Score Background Color (DPC+)

Playfield Color & Background Color Scrolling With Changeable Score Background Color (DPC+) on bB page.

 
   ;***************************************************************
   ;
   ;  DPC+ Example Program
   ;
   ;  Playfield/Background Color Scrolling With Score Background
   ;
   ;  By Duane Alan Hahn (Random Terrain) using hints, tips,
   ;  code snippets, and more from AtariAge members such as
   ;  batari, SeaGtGruff, RevEng, Robert M, Atarius Maximus,
   ;  jrok, Nukey Shay, supercat, and GroovyBee.
   ;
   ;  Score background color asm code provided by RevEng.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Press fire button to change score background color. Hold
   ;  to change colors slowly. Quickly press and release
   ;  repeatedly to change colors faster. You can also press the
   ;  fire button while holding the joystick in any direction to
   ;  rapidly change the colors.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************


   ;****************************************************************
   ;
   ;  This program uses the DPC+ kernel.
   ;
   set kernel DPC+



   ;****************************************************************
   ;
   ;  Standard used in North America and most of South America.
   ;
   set tv ntsc



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Slows fire button when held down.
   ;
   dim _Speed_Counter = a

   ;```````````````````````````````````````````````````````````````
   ;  Speed of background scroll.
   ;
   dim _Background_Scroll_Counter = b

   ;```````````````````````````````````````````````````````````````
   ;  Reset switch bit.
   ;
   dim _Bit0_Reset_Restrainer = t

   ;```````````````````````````````````````````````````````````````
   ;  Used by asm code to set score bg color.
   ;
   dim _Score_Background = y




   goto __Start_Restart bank2




   ;***************************************************************
   ;
   ;  Score background color. If you don't want the score 
   ;  background color to change during your game, use a color 
   ;  after ldx instead of a variable. Example: ldx $84
   ;
   asm
minikernel
   ldx _Score_Background
   stx COLUBK
   rts
end





   bank 2
   temp1=temp1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Playfield data.
   ;
   playfield:
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
   XXXXXXXX................XXXXXXXX
end


   ;***************************************************************
   ;
   ;  Playfield colors.
   ;
   pfcolors:
   $0E
   $0C
   $0A
   $08
   $06
   $1E
   $1C
   $1A
   $18
   $16
   $2E
   $2C
   $2A
   $28
   $26
   $3E
   $3C
   $3A
   $38
   $36
   $4E
   $4C
   $4A
   $48
   $46
   $5E
   $5C
   $5A
   $58
   $56
   $6E
   $6C
   $6A
   $68
   $66
   $7E
   $7C
   $7A
   $78
   $76
   $9E
   $9C
   $9A
   $98
   $96
   $AE
   $AC
   $AA
   $A8
   $A6
   $BE
   $BC
   $BA
   $B8
   $B6
   $CE
   $CC
   $CA
   $C8
   $C6
   $DE
   $DC
   $DA
   $D8
   $D6
   $EE
   $EC
   $EA
   $E8
   $E6
   $3E
   $3C
   $3A
   $38
   $36
   $4E
   $4C
   $4A
   $48
   $46
   $5E
   $5C
   $5A
   $58
   $56
   $6E
   $6C
   $6A
   $68
   $66
   $0E
   $0C
   $0A
   $08
   $06
   $1E
   $1C
   $1A
   $18
   $16
   $2E
   $2C
   $2A
   $28
   $26
   $3E
   $3C
   $3A
   $38
   $36
   $4E
   $4C
   $4A
   $48
   $46
   $5E
   $5C
   $5A
   $58
   $56
   $6E
   $6C
   $6A
   $68
   $66
   $7E
   $7C
   $7A
   $78
   $76
   $9E
   $9C
   $9A
   $98
   $96
   $AE
   $AC
   $AA
   $A8
   $A6
   $BE
   $BC
   $BA
   $B8
   $B6
   $CE
   $CC
   $CA
   $C8
   $C6
   $DE
   $DC
   $DA
   $D8
   $D6
   $EE
   $EC
   $EA
   $E8
   $E6
   $3E
   $3C
   $3A
   $38
   $36
   $4E
   $4C
   $4A
   $48
   $46
   $5E
   $5C
   $5A
   $58
   $56
   $6E
   $6C
   $6A
   $68
   $66
   $0E
   $0C
   $0A
   $08
   $06
   $1E
   $1C
   $1A
   $18
   $16
   $2E
   $2C
   $2A
   $28
   $26
   $3E
   $3C
   $3A
   $38
   $36
   $4E
   $4C
   $4A
   $48
   $46
   $5E
   $5C
   $5A
   $58
   $56
   $6E
   $6C
   $6A
   $68
   $66
   $7E
   $7C
   $7A
   $78
   $76
   $9E
   $9C
   $9A
   $98
   $96
   $0E
   $0C
   $0A
   $08
   $06
   $1E
   $1C
   $1A
   $18
   $16
   $2E
   $2C
   $2A
   $28
   $26
   $3E
   $3C
   $3A
   $38
   $36
   $4E
   $4C
   $4A
   $48
   $46
   $5E
   $5C
   $5A
   $58
   $56
end

   ;```````````````````````````````````````````````````````````````
   ;  RevEng trick to get 256 playfield colors. Read more here:
   ;
   ;  http://atariage.com/forums/topic/214909-bb-with-native-64k-cart-support-11dreveng/page-12#entry2910997
   ;
   pfscroll 255 4 4

   pfcolors:
   $54
end


   ;***************************************************************
   ;
   ;  Background color data.
   ;
   bkcolors:
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
   $04
   $02
   $02
   $02
   $02
   $02
   $04
   $04
end

   ;```````````````````````````````````````````````````````````````
   ;  RevEng trick to get 256 background colors.
   ;
   pfscroll 255 6 6

   bkcolors:
   $04
end


   ;***************************************************************
   ;
   ;  Score colors.
   ;
   scorecolors:
   $3E
   $3C
   $3A
   $3A
   $38
   $38
   $36
   $36
end


   ;***************************************************************
   ;
   ;  Clears the variable used with score background color.
   ;
   _Score_Background = 0


   ;***************************************************************
   ;
   ;  Sets the background color scroll speed counter.
   ;
   _Background_Scroll_Counter = 3


   ;***************************************************************
   ;
   ;  Sets repetition restrainer for the reset switch.
   ;  (Holding it down won't make it keep resetting.)
   ;
   _Bit0_Reset_Restrainer{0} = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Fire button section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Sets speed counter to maximum and skips this section if the
   ;  fire button is not pressed.
   ;
   if !joy0fire then _Speed_Counter = 20 : goto __Skip_Joy0

   ;```````````````````````````````````````````````````````````````
   ;  Adds one to the speed counter.
   ;
   _Speed_Counter = _Speed_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if speed counter value is less than 20.
   ;
   if _Speed_Counter < 20 then goto __Skip_Joy0

   ;```````````````````````````````````````````````````````````````
   ;  Clears the speed counter, but holding the joystick in any
   ;  direction while pressing the fire button rapidly changes the
   ;  color. The closer the number is to 20, the faster the change
   ;  happens.
   ;
   _Speed_Counter = 0

   if !joy0up && !joy0down && !joy0left && !joy0right then goto __Skip_Joy0_Fast_Speed

   _Speed_Counter = 13

__Skip_Joy0_Fast_Speed

   ;```````````````````````````````````````````````````````````````
   ;  Changes score background color.
   ;
   _Score_Background = _Score_Background + 2

__Skip_Joy0



   ;***************************************************************
   ;
   ;  Scrolls the foreground color.
   ;
   pfscroll 255 4 4



   ;***************************************************************
   ;
   ;  Scrolls the background color at a slower speed than the
   ;  foreground color.
   ;
   _Background_Scroll_Counter = _Background_Scroll_Counter - 1

   if !_Background_Scroll_Counter then _Background_Scroll_Counter = 3 : pfscroll 255 6 6



   ;***************************************************************
   ;
   ;  Sets DFxFRACINC registers.
   ;
   DF6FRACINC = 255 ; Background colors.
   DF4FRACINC = 255 ; Playfield colors.

   DF0FRACINC = 128 ; Column 0.
   DF1FRACINC = 128 ; Column 1.
   DF2FRACINC = 128 ; Column 2.
   DF3FRACINC = 128 ; Column 3.



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   bank 3
   temp1=temp1




   bank 4
   temp1=temp1




   bank 5
   temp1=temp1




   bank 6
   temp1=temp1

 

 

 

Change Background Row Colors (DPC+)

Change Background Row Colors (DPC+) on bB page.

 
   ;***************************************************************
   ;
   ;  Change Background Color of Any Row (DPC+)
   ;
   ;  Example program by Lillapojkenpaon and adapted by Duane Alan
   ;  Hahn (Random Terrain) using hints, tips, code snippets, and
   ;  more from AtariAge members such as batari, SeaGtGruff,
   ;  RevEng, Robert M, Nukey Shay, Atarius Maximus, jrok,
   ;  supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Push joystick up or down to select any row. Push joystick
   ;  right to change color of the selected row. Push joystick
   ;  left while pushing up or down to paint background with the
   ;  last color that was selected. Push joystick right while
   ;  pushing up or down to paint with multiple colors. Holding
   ;  down the fire button slows down row selection and color
   ;  selection.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;****************************************************************
   ;
   ;  This program uses the DPC+ kernel.
   ;
   set kernel DPC+



   ;****************************************************************
   ;
   ;  Standard used in North America and most of South America.
   ;
   set tv ntsc



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Current row. (a is integer, b is fraction).
   ;
   dim _Row = a.b

   ;```````````````````````````````````````````````````````````````
   ;  Current row integer.
   ;
   dim _Row_Integer = a

   ;```````````````````````````````````````````````````````````````
   ;  Row color of background.
   ;
   dim _bgRow_Color = c.d

   ;```````````````````````````````````````````````````````````````
   ;  Row color integer for background.
   ;
   dim _bgRowColor_Integer = c

   ;```````````````````````````````````````````````````````````````
   ;  All-purpose bits for various jobs.
   ;
   dim _Bit0_Reset_Restrainer = y ; Reset switch becomes inactive if it hasn't been released.

   ;```````````````````````````````````````````````````````````````
   ;  Splits up the score into 3 parts.
   ;
   dim _sc1 = score
   dim _sc2 = score+1
   dim _sc3 = score+2



   ;***************************************************************
   ;
   ;  Background color constants.
   ;  [The c stands for constant.]
   ;
   const _c_BKCOLS_Lo = #<(BKCOLS)
   const _c_BKCOLS_Hi = #(>BKCOLS) & $0F



   goto __Bank_2 bank2



   bank 2
   temp1=temp1



__Bank_2





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables and the extra 9.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0
   var0 = 0 : var1 = 0 : var2 = 0 : var3 = 0 : var4 = 0
   var5 = 0 : var6 = 0 : var7 = 0 : var8 = 0


   ;***************************************************************
   ;
   ;  Score colors.
   ;
   scorecolors:
   $0E
   $0E
   $0C
   $0C
   $0A
   $0A
   $08
   $08
end


   ;***************************************************************
   ;
   ;  Cursor color.
   ;
   player0color:
   $08
   $08
end


   ;***************************************************************
   ;
   ;  Cursor shape.
   ;
   player0:
   %11111111
   %11111111
end


   ;***************************************************************
   ;
   ;  Starting cursor position.
   ;
   player0x = 0 : player0y = 0


   ;***************************************************************
   ;
   ;  Displays the screen to keep from going over 262.
   ;
   drawscreen


   ;***************************************************************
   ;
   ;  Starting row color for loop.
   ;
   _bgRowColor_Integer = 1


   ;***************************************************************
   ;
   ;  Creates colors for bottom half of screen.
   ;
   for _Row_Integer = 88 to 45 step -1

   DF0LOW = _c_BKCOLS_Lo + _Row_Integer
   DF0HI = _c_BKCOLS_Hi
   DF0PUSH = _bgRowColor_Integer

   _bgRowColor_Integer = _bgRowColor_Integer + 2

   next


   ;***************************************************************
   ;
   ;  Displays the screen to keep from going over 262.
   ;
   drawscreen


   ;***************************************************************
   ;
   ;  Creates colors for top half of screen.
   ;
   for _Row_Integer = 44 to 1 step -1

   DF0LOW = _c_BKCOLS_Lo + _Row_Integer
   DF0HI = _c_BKCOLS_Hi
   DF0PUSH = _bgRowColor_Integer

   _bgRowColor_Integer = _bgRowColor_Integer + 2

   next


   ;***************************************************************
   ;
   ;  Displays the screen to keep from going over 262.
   ;
   drawscreen


   ;***************************************************************
   ;
   ;  Starting row and color.
   ;
   _Row = 1.0 : _bgRow_Color = $1E


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  1 pixel wide missile. Double-sized player.
   ;
   NUSIZ0 = $05



   ;***************************************************************
   ;
   ;  Up joystick section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if joystick not pushed up.
   ;
   if !joy0up then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Temporarily remembers the integer and moves up a little.
   ;
   temp5 = _Row_Integer : _Row = _Row - 0.25

   ;```````````````````````````````````````````````````````````````
   ;  Moves faster if fire button not pressed.
   ;
   if !joy0fire then _Row = _Row - 0.75

   ;```````````````````````````````````````````````````````````````
   ;  Moves cursor if integer changed.
   ;
   if _Row_Integer <> temp5 then player0y = player0y - 2

   ;```````````````````````````````````````````````````````````````
   ;  Moves to bottom if cursor moved past top of screen.
   ;
   if _Row_Integer = 0 || _Row_Integer > 200 then _Row = 88.0 : player0y = 174
   
__Skip_Joy0_Up



   ;***************************************************************
   ;
   ;  Down joystick section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if joystick not pushed down.
   ;
   if !joy0down then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Temporarily remembers the integer and moves down a little.
   ;
   temp5 = _Row_Integer : _Row = _Row + 0.25

   ;```````````````````````````````````````````````````````````````
   ;  Moves faster if fire button not pressed.
   ;
   if !joy0fire then _Row = _Row + 0.75

   ;```````````````````````````````````````````````````````````````
   ;  Moves cursor if integer changed.
   ;
   if _Row_Integer <> temp5 then player0y = player0y + 2

   ;```````````````````````````````````````````````````````````````
   ;  Moves to top if cursor moved past bottom of screen.
   ;
   if _Row > 88 then _Row = 1.0 : player0y = 0
   
__Skip_Joy0_Down



   ;***************************************************************
   ;
   ;  Left joystick section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if joystick not pushed left.
   ;
   if !joy0left then goto __Skip_Joy0Left

   ;```````````````````````````````````````````````````````````````
   ;  Color change. This is the important code.
   ;
   DF0LOW = _c_BKCOLS_Lo + _Row_Integer
   DF0HI = _c_BKCOLS_Hi
   DF0PUSH = _bgRowColor_Integer

__Skip_Joy0Left



   ;***************************************************************
   ;
   ;  Right joystick section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if joystick not pushed right.
   ;
   if !joy0right then goto __Skip_Joy0Right

   ;```````````````````````````````````````````````````````````````
   ;  Temporarily remembers the integer and changes color slowly.
   ;
   temp5 = _bgRowColor_Integer : _bgRow_Color = _bgRow_Color + 0.15

   ;```````````````````````````````````````````````````````````````
   ;  Changes color faster if fire button not pressed.
   ;
   if !joy0fire then _bgRow_Color = _bgRow_Color + 0.85

   ;```````````````````````````````````````````````````````````````
   ;  Jumps color by one if integer changed.
   ;
   if _bgRowColor_Integer <> temp5 then _bgRow_Color = _bgRow_Color + 1.0

   ;```````````````````````````````````````````````````````````````
   ;  Color change. This is the important code.
   ;
   DF0LOW = _c_BKCOLS_Lo + _Row_Integer
   DF0HI = _c_BKCOLS_Hi
   DF0PUSH = _bgRowColor_Integer

__Skip_Joy0Right



   ;***************************************************************
   ;
   ;  Puts temp4 in the three score digits on the right side.
   ;
   temp4 = _Row_Integer

   _sc2 = _sc2 & 240 : _sc3 = 0
   if temp4 >= 100 then _sc2 = _sc2 + 1 : temp4 = temp4 - 100
   if temp4 >= 100 then _sc2 = _sc2 + 1 : temp4 = temp4 - 100
   if temp4 >= 50 then _sc3 = _sc3 + 80 : temp4 = temp4 - 50
   if temp4 >= 30 then _sc3 = _sc3 + 48 : temp4 = temp4 - 30
   if temp4 >= 20 then _sc3 = _sc3 + 32 : temp4 = temp4 - 20
   if temp4 >= 10 then _sc3 = _sc3 + 16 : temp4 = temp4 - 10
   _sc3 = _sc3 | temp4



   ;***************************************************************
   ;
   ;  88 rows that are 2 scanlines high.
   ;
   DF6FRACINC = 255 : DF4FRACINC = 255

   DF0FRACINC = 128 : DF1FRACINC = 128 : DF2FRACINC = 128 : DF3FRACINC = 128



   ;***************************************************************
   ;
   ;  Simple fix for the top two lines having the same color.
   ;
   asm
   lda DF6FRACDATA ; bgcolor priming read (first value will be read twice)
   lda DF4FRACDATA ; pfcolor priming read (first value will be read twice)
end



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart





   bank 3
   temp1=temp1





   bank 4
   temp1=temp1





   bank 5
   temp1=temp1





   bank 6
   temp1=temp1

 

 

 

Change Playfield Row Colors (DPC+)

Change Playfield Row Colors (DPC+) on bB page.

 
   ;***************************************************************
   ;
   ;  Change Playfield Color of Any Row (DPC+)
   ;
   ;  Example program by Lillapojkenpaon and adapted by Duane Alan
   ;  Hahn (Random Terrain) using hints, tips, code snippets, and
   ;  more from AtariAge members such as batari, SeaGtGruff,
   ;  RevEng, Robert M, Nukey Shay, Atarius Maximus, jrok,
   ;  supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Push joystick up or down to select any row. Push joystick
   ;  right to change color of the selected row. Push joystick
   ;  left while pushing up or down to paint playfield with the
   ;  last color that was selected. Push joystick right while
   ;  pushing up or down to paint with multiple colors. Holding
   ;  down the fire button slows down row selection and color
   ;  selection.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;****************************************************************
   ;
   ;  This program uses the DPC+ kernel.
   ;
   set kernel DPC+



   ;****************************************************************
   ;
   ;  Standard used in North America and most of South America.
   ;
   set tv ntsc



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Current row. (a is integer, b is fraction).
   ;
   dim _Row = a.b

   ;```````````````````````````````````````````````````````````````
   ;  Current row integer.
   ;
   dim _Row_Integer = a

   ;```````````````````````````````````````````````````````````````
   ;  Row color of playfield.
   ;
   dim _pfRow_Color = e.f

   ;```````````````````````````````````````````````````````````````
   ;  Row color integer for playfield.
   ;
   dim _pfRowColor_Integer = e

   ;```````````````````````````````````````````````````````````````
   ;  All-purpose bits for various jobs.
   ;
   dim _Bit0_Reset_Restrainer = y ; Reset switch becomes inactive if it hasn't been released.

   ;```````````````````````````````````````````````````````````````
   ;  Splits up the score into 3 parts.
   ;
   dim _sc1 = score
   dim _sc2 = score+1
   dim _sc3 = score+2



   ;***************************************************************
   ;
   ;  Playfield color constants.
   ;  [The c stands for constant.]
   ;
   const _c_PFCOLS_Lo = #<(PFCOLS)
   const _c_PFCOLS_Hi = #(>PFCOLS) & $0F



   goto __Bank_2 bank2



   bank 2
   temp1=temp1



__Bank_2





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables and the extra 9.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0
   var0 = 0 : var1 = 0 : var2 = 0 : var3 = 0 : var4 = 0
   var5 = 0 : var6 = 0 : var7 = 0 : var8 = 0


   ;***************************************************************
   ;
   ;  Score colors.
   ;
   scorecolors:
   $0E
   $0E
   $0C
   $0C
   $0A
   $0A
   $08
   $08
end


   ;***************************************************************
   ;
   ;  Cursor color.
   ;
   player0color:
   $08
   $08
end


   ;***************************************************************
   ;
   ;  Cursor shape.
   ;
   player0:
   %11111111
   %11111111
end


   ;***************************************************************
   ;
   ;  Fills the playfield.
   ;
   playfield: 
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ;10
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ;20
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ;30
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ;40
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ;50
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ;60
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ;70
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ;80
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ;88
end


   ;***************************************************************
   ;
   ;  Starting cursor position.
   ;
   player0x = 0 : player0y = 0


   ;***************************************************************
   ;
   ;  Displays the screen to keep from going over 262.
   ;
   drawscreen


   ;***************************************************************
   ;
   ;  Starting row color for loop.
   ;
   _pfRowColor_Integer = 1


   ;***************************************************************
   ;
   ;  Creates colors for bottom half of screen.
   ;
   for _Row_Integer = 88 to 45 step -1

   DF0LOW = _c_PFCOLS_Lo + _Row_Integer
   DF0HI = _c_PFCOLS_Hi
   DF0PUSH = _pfRowColor_Integer

   _pfRowColor_Integer = _pfRowColor_Integer + 2

   next


   ;***************************************************************
   ;
   ;  Displays the screen to keep from going over 262.
   ;
   drawscreen


   ;***************************************************************
   ;
   ;  Creates colors for top half of screen.
   ;
   for _Row_Integer = 44 to 1 step -1

   DF0LOW = _c_PFCOLS_Lo + _Row_Integer
   DF0HI = _c_PFCOLS_Hi
   DF0PUSH = _pfRowColor_Integer

   _pfRowColor_Integer = _pfRowColor_Integer + 2

   next


   ;***************************************************************
   ;
   ;  Displays the screen to keep from going over 262.
   ;
   drawscreen


   ;***************************************************************
   ;
   ;  Starting row and color.
   ;
   _Row = 1.0 : _pfRow_Color = $1E


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  1 pixel wide missile. Double-sized player.
   ;
   NUSIZ0 = $05



   ;***************************************************************
   ;
   ;  Up joystick section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if joystick not pushed up.
   ;
   if !joy0up then goto __Skip_Joy0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Temporarily remembers the integer and moves up a little.
   ;
   temp5 = _Row_Integer : _Row = _Row - 0.25

   ;```````````````````````````````````````````````````````````````
   ;  Moves faster if fire button not pressed.
   ;
   if !joy0fire then _Row = _Row - 0.75

   ;```````````````````````````````````````````````````````````````
   ;  Moves cursor if integer changed.
   ;
   if _Row_Integer <> temp5 then player0y = player0y - 2

   ;```````````````````````````````````````````````````````````````
   ;  Moves to bottom if cursor moved past top of screen.
   ;
   if _Row_Integer = 0 || _Row_Integer > 200 then _Row = 88.0 : player0y = 174
   
__Skip_Joy0_Up



   ;***************************************************************
   ;
   ;  Down joystick section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if joystick not pushed down.
   ;
   if !joy0down then goto __Skip_Joy0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Temporarily remembers the integer and moves down a little.
   ;
   temp5 = _Row_Integer : _Row = _Row + 0.25

   ;```````````````````````````````````````````````````````````````
   ;  Moves faster if fire button not pressed.
   ;
   if !joy0fire then _Row = _Row + 0.75

   ;```````````````````````````````````````````````````````````````
   ;  Moves cursor if integer changed.
   ;
   if _Row_Integer <> temp5 then player0y = player0y + 2

   ;```````````````````````````````````````````````````````````````
   ;  Moves to top if cursor moved past bottom of screen.
   ;
   if _Row > 88 then _Row = 1.0 : player0y = 0
   
__Skip_Joy0_Down



   ;***************************************************************
   ;
   ;  Left joystick section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if joystick not pushed left.
   ;
   if !joy0left then goto __Skip_Joy0Left

   ;```````````````````````````````````````````````````````````````
   ;  Color change. This is the important code.
   ;
   DF0LOW = _c_PFCOLS_Lo + _Row_Integer
   DF0HI = _c_PFCOLS_Hi
   DF0PUSH = _pfRowColor_Integer

__Skip_Joy0Left



   ;***************************************************************
   ;
   ;  Right joystick section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if joystick not pushed right.
   ;
   if !joy0right then goto __Skip_Joy0Right

   ;```````````````````````````````````````````````````````````````
   ;  Temporarily remembers the integer and changes color slowly.
   ;
   temp5 = _pfRowColor_Integer : _pfRow_Color = _pfRow_Color + 0.15

   ;```````````````````````````````````````````````````````````````
   ;  Changes color faster if fire button not pressed.
   ;
   if !joy0fire then _pfRow_Color = _pfRow_Color + 0.85

   ;```````````````````````````````````````````````````````````````
   ;  Jumps color by one if integer changed.
   ;
   if _pfRowColor_Integer <> temp5 then _pfRow_Color = _pfRow_Color + 1.0

   ;```````````````````````````````````````````````````````````````
   ;  Color change. This is the important code.
   ;
   DF0LOW = _c_PFCOLS_Lo + _Row_Integer
   DF0HI = _c_PFCOLS_Hi
   DF0PUSH = _pfRowColor_Integer

__Skip_Joy0Right



   ;***************************************************************
   ;
   ;  Puts temp4 in the three score digits on the right side.
   ;
   temp4 = _Row_Integer

   _sc2 = _sc2 & 240 : _sc3 = 0
   if temp4 >= 100 then _sc2 = _sc2 + 1 : temp4 = temp4 - 100
   if temp4 >= 100 then _sc2 = _sc2 + 1 : temp4 = temp4 - 100
   if temp4 >= 50 then _sc3 = _sc3 + 80 : temp4 = temp4 - 50
   if temp4 >= 30 then _sc3 = _sc3 + 48 : temp4 = temp4 - 30
   if temp4 >= 20 then _sc3 = _sc3 + 32 : temp4 = temp4 - 20
   if temp4 >= 10 then _sc3 = _sc3 + 16 : temp4 = temp4 - 10
   _sc3 = _sc3 | temp4



   ;***************************************************************
   ;
   ;  88 rows that are 2 scanlines high.
   ;
   DF6FRACINC = 255 : DF4FRACINC = 255

   DF0FRACINC = 128 : DF1FRACINC = 128 : DF2FRACINC = 128 : DF3FRACINC = 128



   ;***************************************************************
   ;
   ;  Simple fix for the top two lines having the same color.
   ;
   asm
   lda DF6FRACDATA ; bgcolor priming read (first value will be read twice)
   lda DF4FRACDATA ; pfcolor priming read (first value will be read twice)
end



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart





   bank 3
   temp1=temp1





   bank 4
   temp1=temp1





   bank 5
   temp1=temp1





   bank 6
   temp1=temp1

 

 

 

Change Score Color (DPC+)

Change Score Color (DPC+) on bB page.

 
   ;***************************************************************
   ;
   ;  Change Score Color (DPC+)
   ;
   ;  Example program by Lillapojkenpaon and adapted by Duane Alan
   ;  Hahn (Random Terrain) using hints, tips, code snippets, and
   ;  more from AtariAge members such as batari, SeaGtGruff,
   ;  RevEng, Robert M, Nukey Shay, Atarius Maximus, jrok,
   ;  supercat, GroovyBee, and bogax.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;****************************************************************
   ;
   ;  This program uses the DPC+ kernel.
   ;
   set kernel DPC+



   ;****************************************************************
   ;
   ;  Standard used in North America and most of South America.
   ;
   set tv ntsc



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Slows color change.
   ;
   dim _Speed_Counter = g

   ;```````````````````````````````````````````````````````````````
   ;  Score color.
   ;
   dim _Score_Color = h

   ;```````````````````````````````````````````````````````````````
   ;  All-purpose bits for various jobs.
   ;
   dim _Bit0_Reset_Restrainer = y ; Reset switch becomes inactive if it hasn't been released.




   ;***************************************************************
   ;
   ;  Score color constants.
   ;  [The c stands for constant.]
   ;
   const _c_SCOREDATA_Lo = #<scoredata
   const _c_SCOREDATA_Hi = #((>scoredata) & $0f)



   goto __Bank_2 bank2



   bank 2
   temp1=temp1



__Bank_2





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables and the extra 9.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0
   var0 = 0 : var1 = 0 : var2 = 0 : var3 = 0 : var4 = 0
   var5 = 0 : var6 = 0 : var7 = 0 : var8 = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Score color change section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Adds one to the speed counter.
   ;
   _Speed_Counter = _Speed_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips section if counter isn't at the limit.
   ;
   if _Speed_Counter < 6 then goto __Skip_Color_Change

   ;```````````````````````````````````````````````````````````````
   ;  Clears the speed counter.
   ;
   _Speed_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Adds two to the score color variable.
   ;
   _Score_Color = _Score_Color + 2

   ;```````````````````````````````````````````````````````````````
   ;  Color change important code.
   ;
   DF0LOW = _c_SCOREDATA_Lo
   DF0HI = _c_SCOREDATA_Hi

   ;```````````````````````````````````````````````````````````````
   ;  More color change important code.
   ;
   DF0WRITE = _Score_Color
   DF0WRITE = _Score_Color
   DF0WRITE = _Score_Color - 2
   DF0WRITE = _Score_Color - 2
   DF0WRITE = _Score_Color - 4
   DF0WRITE = _Score_Color - 4
   DF0WRITE = _Score_Color - 6
   DF0WRITE = _Score_Color - 6

__Skip_Color_Change



   ;***************************************************************
   ;
   ;  88 rows that are 2 scanlines high.
   ;
   DF6FRACINC = 255 : DF4FRACINC = 255

   DF0FRACINC = 128 : DF1FRACINC = 128 : DF2FRACINC = 128 : DF3FRACINC = 128



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart





   bank 3
   temp1=temp1





   bank 4
   temp1=temp1





   bank 5
   temp1=temp1





   bank 6
   temp1=temp1

 

 

 

Change Score Background Color (DPC+)

Change Score Background Color (DPC+) on bB page.

 
   ;***************************************************************
   ;
   ;  Change Score Background Color (DPC+)
   ;
   ;  Example program by Lillapojkenpaon and adapted by Duane Alan
   ;  Hahn (Random Terrain) using hints, tips, code snippets, and
   ;  more from AtariAge members such as batari, SeaGtGruff,
   ;  RevEng, Robert M, Nukey Shay, Atarius Maximus, jrok,
   ;  supercat, GroovyBee, and bogax.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Press fire button to change score background color.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;****************************************************************
   ;
   ;  This program uses the DPC+ kernel.
   ;
   set kernel DPC+



   ;****************************************************************
   ;
   ;  Standard used in North America and most of South America.
   ;
   set tv ntsc



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer 
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Slows color change.
   ;
   dim _Speed_Counter = g

   ;```````````````````````````````````````````````````````````````
   ;  Score color.
   ;
   dim _Score_Color = h

   ;```````````````````````````````````````````````````````````````
   ;  All-purpose bits for various jobs.
   ;
   dim _Bit0_Reset_Restrainer = y ; Reset switch becomes inactive if it hasn't been released.



   ;***************************************************************
   ;
   ;  Score Background color constants.
   ;  [The c stands for constant.]
   ;
   const _c_BKCOLS_Lo_Plus_88 = #<(BKCOLS+88)
   const _c_BKCOLS_Hi = #(>BKCOLS) & $0F



   goto __Bank_2 bank2



   bank 2
   temp1=temp1



__Bank_2





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables and the extra 9.
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0
   var0 = 0 : var1 = 0 : var2 = 0 : var3 = 0 : var4 = 0
   var5 = 0 : var6 = 0 : var7 = 0 : var8 = 0


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Starting score background color.
   ;
   _Score_Color = $8E





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Score color change section.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips section if fire button not pressed.
   ;
   if !joy0fire then goto __Skip_Color_Change

   ;```````````````````````````````````````````````````````````````
   ;  Adds one to the speed counter.
   ;
   _Speed_Counter = _Speed_Counter + 1

   ;```````````````````````````````````````````````````````````````
   ;  Skips section if counter isn't at the limit.
   ;
   if _Speed_Counter < 6 then goto __Skip_Color_Change

   ;```````````````````````````````````````````````````````````````
   ;  Clears the speed counter.
   ;
   _Speed_Counter = 0

   ;```````````````````````````````````````````````````````````````
   ;  Adds two to the score color variable.
   ;
   _Score_Color = _Score_Color + 2

__Skip_Color_Change



   ;***************************************************************
   ;
   ;  Color change important code.
   ;
   DF0LOW = _c_BKCOLS_Lo_Plus_88
   DF0HI = _c_BKCOLS_Hi
   DF0PUSH = _Score_Color ; Pushes the color to the 89th row (88 starting from 0).



   ;***************************************************************
   ;
   ;  88 rows that are 2 scanlines high.
   ;
   DF6FRACINC = 255 : DF4FRACINC = 255

   DF0FRACINC = 128 : DF1FRACINC = 128 : DF2FRACINC = 128 : DF3FRACINC = 128



   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart





   bank 3
   temp1=temp1





   bank 4
   temp1=temp1





   bank 5
   temp1=temp1





   bank 6
   temp1=temp1

 

 

 

DPC+ Maze With Animated Sprite and Roaming Sprite Using 8.8 Fixed Point Movement

DPC+ Maze With Animated Sprite and Roaming Sprite Using 8.8 Fixed Point Movement on bB page.

 
   ;****************************************************************
   ;
   ;  Maze With Animated Sprite and Roaming Sprite (DPC+)
   ;
   ;  Example program by Duane Alan Hahn (Random Terrain) using
   ;  hints, tips, code snippets, and more from AtariAge members
   ;  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   ;  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   ;
   ;```````````````````````````````````````````````````````````````
   ;
   ;  Instructions:
   ;  
   ;  Use the joystick to move the sprite.
   ;  
   ;```````````````````````````````````````````````````````````````
   ;
   ;  If this program will not compile for you, get the latest
   ;  version of batari Basic:
   ;  
   ;  http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#gettingstarted
   ;  
   ;***************************************************************



   ;****************************************************************
   ;
   ;  This program uses the DPC+ kernel.
   ;
   set kernel DPC+



   ;****************************************************************
   ;
   ;  Standard used in North America and most of South America.
   ;
   set tv ntsc



   ;****************************************************************
   ;
   ;  Helps player1 sprites register a collision with the playfield.
   ;
   set kernel_options collision(player1,playfield)



   ;****************************************************************
   ;
   ;  Random numbers can slow down bankswitched games. This will
   ;  speed things up.
   ;
   set optimization inlinerand



   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   ;  You can have more than one alias for each variable.
   ;  If you use different aliases for bit operations,
   ;  it's easier to understand and remember what they do.
   ;
   ;  I start variable aliases with one underscore so I won't
   ;  have to worry that I might be using bB keywords by mistake.
   ;  I also start labels with two underscores for the same
   ;  reason. The second underscore also makes labels stand out 
   ;  so I can tell at a glance that they are labels and not
   ;  variables.
   ;
   ;  Use bit operations any time you need a simple off/on
   ;  variable. One variable essentially becomes 8 smaller
   ;  variables when you use bit operations.
   ;
   ;  I start my bit aliases with "_Bit" then follow that
   ;  with the bit number from 0 to 7, then another underscore
   ;  and the name. Example: _Bit0_Reset_Restrainer
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Player0 fixed point variables for more flexibility in
   ;  gameplay mechanics.
   ;
   dim _P0_L_R = player0x.a
   dim _P0_U_D = player0y.b

   ;```````````````````````````````````````````````````````````````
   ;  Player1 fixed point variables for more flexibility in
   ;  gameplay mechanics.
   ;
   dim _P1_L_R = player1x.c
   dim _P1_U_D = player1y.d

   ;```````````````````````````````````````````````````````````````
   ;  Makes the enemy change directions properly and not bounce
   ;  back.
   ;
   dim _Enemy_Counter = k

   ;```````````````````````````````````````````````````````````````
   ;  How often enemy looks for opening.
   ;
   dim _Enemy_Rand_Look = l

   ;```````````````````````````````````````````````````````````````
   ; Animation counters.
   ;
   dim _Master_Counter = m
   dim _Frame_Counter = n

   ;```````````````````````````````````````````````````````````````
   ;  Player0/player1 direction bits.
   ;
   dim _BitOp_P0_P1_Dir = u
   dim _Bit0_P0_Dir_Up = u
   dim _Bit1_P0_Dir_Down = u
   dim _Bit2_P0_Dir_Left = u
   dim _Bit3_P0_Dir_Right = u
   dim _Bit4_P1_Dir_Up = u
   dim _Bit5_P1_Dir_Down = u
   dim _Bit6_P1_Dir_Left = u
   dim _Bit7_P1_Dir_Right = u

   ;```````````````````````````````````````````````````````````````
   ;  Bits for various jobs.
   ;
   dim _BitOp_01 = y
   dim _Bit0_Reset_Restrainer = y
   dim _Bit3_vblank = y
   dim _Bit5_Direction_Changed = y
   dim _Bit6_Flip_P0 = y





   goto __Start_Restart bank2





   bank 2
   temp1=temp1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  PROGRAM START/RESTART
   ;
   ;
__Start_Restart


   ;***************************************************************
   ;
   ;  Mutes volume of both sound channels.
   ;
   AUDV0 = 0 : AUDV1 = 0


   ;***************************************************************
   ;
   ;  Clears all normal variables and the extra 9 (fastest way).
   ;
   a = 0 : b = 0 : c = 0 : d = 0 : e = 0 : f = 0 : g = 0 : h = 0 : i = 0
   j = 0 : k = 0 : l = 0 : m = 0 : n = 0 : o = 0 : p = 0 : q = 0 : r = 0
   s = 0 : t = 0 : u = 0 : v = 0 : w = 0 : x = 0 : y = 0 : z = 0
   var0 = 0 : var1 = 0 : var2 = 0 : var3 = 0 : var4 = 0
   var5 = 0 : var6 = 0 : var7 = 0 : var8 = 0


   ;***************************************************************
   ;
   ;  Sets starting position of player0.
   ;
   player0x = (15*4)+16 : player0y = (10*8)


   ;***************************************************************
   ;
   ;  Sets player0 color.
   ;
   player0color:
   $1E
   $1E
   $1E
   $1E
   $1E
   $1E
   $1E
   $1E
   $1E
   $1E
   $1E
   $1E
   $1E
   $1E
end


   ;***************************************************************
   ;
   ;  Sets starting position of enemy sprite.
   ;
   player1x = (15*4)+16 : player1y = (19*8)


   ;***************************************************************
   ;
   ;  Sets player1 color.
   ;
   player1color:
   $AE
   $AE
   $AE
   $AE
   $AE
   $AE
   $AE
   $AE
   $AE
   $AE
   $AE
   $AE
   $AE
   $AE
end


   ;***************************************************************
   ;
   ;  Sets beginning direction for player0.
   ;
   _Bit2_P0_Dir_Left{2} = 1


   ;***************************************************************
   ;
   ;  Sets beginning direction for the enemy sprite.
   ;
   _Bit7_P1_Dir_Right{7} = 1


   ;***************************************************************
   ;
   ;  Restrains the reset switch for the main loop.
   ;
   ;  This bit fixes it so the reset switch becomes inactive if
   ;  it hasn't been released after being pressed once.
   ;
   _Bit0_Reset_Restrainer{0} = 1


   ;***************************************************************
   ;
   ;  Determines how often the enemy looks for alternate routes.
   ;  The smaller the number, the less often it will happen.
   ;
   _Enemy_Rand_Look = 50


   ;***************************************************************
   ;
   ;  Sets up the playfield.
   ;
   playfield:
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   X..............XX..............X
   X..............XX..............X
   X..XXX..XXXXX..XX..XXXXX..XXX..X
   X..............................X
   X..............................X
   X..XXX..X..XXXXXXXXXX..X..XXX..X
   X.......X......XX......X.......X
   X.......X......XX......X.......X
   XXXXXX..XXXXX..XX..XXXXX..XXXXXX
   X..............................X
   X..............................X
   X..XXX..XXXXXXX..XXXXXXX..XXX..X
   X....X....................X....X
   X....X....................X....X
   XXX..X..X..XXXXXXXXXX..X..X..XXX
   X.......X......XX......X.......X
   X.......X......XX......X.......X
   X..XXXXXXXXXX..XX..XXXXXXXXXX..X
   X..............................X
   X..............................X
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end


   ;***************************************************************
   ;
   ;  Sets playfield color.
   ;
   pfcolors:
   $96
end


   ;***************************************************************
   ;
   ;  Sets background color.
   ;
   bkcolors:
   $00
end


   ;****************************************************************
   ;
   ;  Sets color of the score.
   ;
   scorecolors:
   $0E
   $0C
   $0A
   $0A
   $08
   $08
   $06
   $06
end


   ;****************************************************************
   ;
   ;  Displays the screen prematurely so we won't go over 262.
   ;
   drawscreen



   goto __Main_Loop bank3





   bank 3
   temp1=temp1





   ;***************************************************************
   ;***************************************************************
   ;
   ;  MAIN LOOP (MAKES THE PROGRAM GO)
   ;
   ;
__Main_Loop



   ;***************************************************************
   ;
   ;  Controls animation speed.
   ;
   _Master_Counter = _Master_Counter + 1

   if _Master_Counter < 4 then goto __Skip_Frame_Counter

   _Frame_Counter = _Frame_Counter + 1 : _Master_Counter = 0

   if _Frame_Counter > 3 then _Frame_Counter = 0

__Skip_Frame_Counter



   ;****************************************************************
   ;
   ;  Up Joy0 check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the up bit is off or the joystick
   ;  isn't moved up.
   ;
   if _Bit0_P0_Dir_Up{0} then goto __Test_P0_Up

   if joy0up then goto __Test_P0_Up

   goto __Skip_Joy0_Up

__Test_P0_Up

   ;```````````````````````````````````````````````````````````````
   ;  Up P0: Converts player0 sprite coordinates and checks to
   ;  see if any playfield pixels are in the way.
   ;
   temp3 = (player0x-16)/4

   temp6 = (player0y-3)/8

   if pfread(temp3,temp6) then goto __Cant_Move_Up

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then goto __Cant_Move_Up

   goto __P0_Move_Up

__Cant_Move_Up

   ;```````````````````````````````````````````````````````````````
   ;  Up P0: Playfield pixel is in the way.
   ;  Shows up frame only if up bit is on. Clears the up bit and
   ;  skips this section.
   ;
   if _Bit0_P0_Dir_Up{0} then player0y = (temp6+1)*8 : gosub __Frame_U_01

   _Bit0_P0_Dir_Up{0} = 0

   goto __Skip_Joy0_Up

__P0_Move_Up

   ;```````````````````````````````````````````````````````````````
   ;  Up P0: Moves P0 up only if sprite is lined up with playfield.
   ;
   temp5 = (temp3*4)+16

   if temp5 <> player0x then goto __Skip_Joy0_Up

   player0x = temp5 : _P0_U_D = _P0_U_D - 1.70

   ;```````````````````````````````````````````````````````````````
   ;  Up P0: Sprite animation.
   ;
   on _Frame_Counter gosub __Frame_U_00 __Frame_U_01 __Frame_U_02 __Frame_U_01

   ;```````````````````````````````````````````````````````````````
   ;  Up P0: Clears bits and turns on the up direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %11110000

   _Bit0_P0_Dir_Up{0} = 1

__Skip_Joy0_Up



   ;****************************************************************
   ;
   ;  Down Joy0 check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the down bit is off or the joystick
   ;  isn't moved down.
   ;
   if _Bit1_P0_Dir_Down{1} then goto __Test_P0_Down

   if joy0down then goto __Test_P0_Down

   goto __Skip_Joy0_Down

__Test_P0_Down

   ;```````````````````````````````````````````````````````````````
   ;  Down P0: Converts player0 sprite coordinates and checks to
   ;  see if any playfield pixels are in the way.
   ;
   temp3 = (player0x-16)/4

   temp6 = (player0y/8)+2

   if pfread(temp3,temp6) then goto __Cant_Move_Down

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then goto __Cant_Move_Down

   goto __P0_Move_Down

__Cant_Move_Down

   ;```````````````````````````````````````````````````````````````
   ;  Down P0: Playfield pixel is in the way.
   ;  Shows down frame only if down bit is on. Clears the down bit
   ;  and skips this section.
   ;
   if _Bit1_P0_Dir_Down{1} then player0y = (temp6-2)*8 : gosub __Frame_D_01

   _Bit1_P0_Dir_Down{1} = 0

   goto __Skip_Joy0_Down

__P0_Move_Down

   ;```````````````````````````````````````````````````````````````
   ;  Down P0: Moves P0 down only if sprite is lined up with PF.
   ;
   temp5 = (temp3*4)+16

   if temp5 <> player0x then goto __Skip_Joy0_Down

   player0x = temp5 : _P0_U_D = _P0_U_D + 1.70

   ;```````````````````````````````````````````````````````````````
   ;  Down P0: Sprite animation.
   ;
   on _Frame_Counter gosub __Frame_D_00 __Frame_D_01 __Frame_D_02 __Frame_D_01

   ;```````````````````````````````````````````````````````````````
   ;  Down P0: Clears bits and turns on the down direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %11110000

   _Bit1_P0_Dir_Down{1} = 1

__Skip_Joy0_Down



   ;****************************************************************
   ;
   ;  Left Joy0 check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the left bit is off or the joystick
   ;  isn't moved left.
   ;
   if _Bit2_P0_Dir_Left{2} then goto __Test_P0_Left

   if joy0left then goto __Test_P0_Left

   goto __Skip_Joy0_Left

__Test_P0_Left

   ;```````````````````````````````````````````````````````````````
   ;  Left P0: Converts player0 sprite coordinates and checks to
   ;  see if any playfield pixels are in the way.
   ;
   temp5 = (player0x-17)/4

   temp6 = (player0y)/8

   if pfread(temp5,temp6) then goto __Cant_Move_Left

   temp3 = temp6 + 1

   if pfread(temp5,temp3) then goto __Cant_Move_Left

   goto __P0_Move_Left

__Cant_Move_Left

   ;```````````````````````````````````````````````````````````````
   ;  Left P0: Playfield pixel is in the way.
   ;  Shows left frame only if left bit is on. Clears the left bit
   ;  and skips this section.
   ;
   if _Bit2_P0_Dir_Left{2} then gosub __Frame_LR_01

   _Bit2_P0_Dir_Left{2} = 0

   goto __Skip_Joy0_Left

__P0_Move_Left

   ;```````````````````````````````````````````````````````````````
   ;  Left P0: Moves P0 left only if sprite is lined up with PF.
   ;
   temp5 = (temp6*8) : temp6 = player0y - 1

   if temp5 <> player0y && temp5 <> temp6 then goto __Skip_Joy0_Left

   player0y = temp5 : _P0_L_R = _P0_L_R - 0.85

   ;```````````````````````````````````````````````````````````````
   ;  Left P0: Sprite animation.
   ;
   on _Frame_Counter gosub __Frame_LR_00 __Frame_LR_01 __Frame_LR_02 __Frame_LR_01

   ;```````````````````````````````````````````````````````````````
   ;  Left P0: Makes sure sprite is facing the correct direction.
   ;
   _Bit6_Flip_P0{6} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Left P0: Clears bits and turns on the left direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %11110000

   _Bit2_P0_Dir_Left{2} = 1

__Skip_Joy0_Left



   ;****************************************************************
   ;
   ;  Right Joy0 check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if the right bit is off or the joystick
   ;  isn't moved right.
   ;
   if _Bit3_P0_Dir_Right{3} then goto __Test_P0_Right

   if joy0right then goto __Test_P0_Right

   goto __Skip_Joy0_Right

__Test_P0_Right

   ;```````````````````````````````````````````````````````````````
   ;  Right P0: Converts player0 sprite coordinates and checks to
   ;  see if any playfield pixels are in the way.
   ;
   temp5 = ((player0x-8)/4)

   temp6 = ((player0y)/8)

   if pfread(temp5,temp6) then goto __Cant_Move_Right

   temp3 = (temp6)+1

   if pfread(temp5,temp3) then goto __Cant_Move_Right

   goto __P0_Move_Right

__Cant_Move_Right

   ;```````````````````````````````````````````````````````````````
   ;  Right P0: Playfield pixel is in the way.
   ;  Shows right frame only if right bit is on. Clears the right
   ;  bit and skips this section.
   ;
   if _Bit3_P0_Dir_Right{3} then gosub __Frame_LR_01

   _Bit3_P0_Dir_Right{3} = 0

   goto __Skip_Joy0_Right

__P0_Move_Right

   ;```````````````````````````````````````````````````````````````
   ;  Right P0: Moves P0 right only if sprite is lined up with PF.
   ;
   temp5 = (temp6*8) : temp6 = player0y - 1

   if temp5 <> player0y && temp5 <> temp6 then goto __Skip_Joy0_Right

   player0y = temp5 : _P0_L_R = _P0_L_R + 0.85

   ;```````````````````````````````````````````````````````````````
   ;  Right P0: Sprite animation.
   ;
   on _Frame_Counter gosub __Frame_LR_00 __Frame_LR_01 __Frame_LR_02 __Frame_LR_01

   ;```````````````````````````````````````````````````````````````
   ;  Right P0: Makes sure sprite is facing the correct direction.
   ;
   _Bit6_Flip_P0{6} = 0

   ;```````````````````````````````````````````````````````````````
   ;  Right P0: Clears bits and turns on the right direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %11110000

   _Bit3_P0_Dir_Right{3} = 1

__Skip_Joy0_Right



   ;****************************************************************
   ;
   ;  Flips player sprite when necessary.
   ;
   if _Bit6_Flip_P0{6} then REFP0 = 8



   ;****************************************************************
   ;
   ;  Starts counting if enemy direction has changed.
   ;  This keeps the enemy from changing directions right away
   ;  so he won't bounce back and reverse direction.
   ;
   if _Bit5_Direction_Changed{5} then _Enemy_Counter = _Enemy_Counter + 1



   ;****************************************************************
   ;
   ;  Enemy up check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if enemy up direction bit isn't on.
   ;
   if !_Bit4_P1_Dir_Up{4} then goto __Skip_P1_Up

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Up: Converts enemy sprite coordinates and checks to
   ;  see if any playfield pixels are in the way.
   ;
   temp3 = (player1x-16)/4

   temp6 = (player1y-3)/8

   if pfread(temp3,temp6) then goto __Enemy_Cant_Move_Up

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then goto __Enemy_Cant_Move_Up

   goto __Skip_to_P1_Move_Up

__Enemy_Cant_Move_Up

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Up: Playfield pixel in the way. Clears the up bit, gets
   ;  a new direction and jumps to the beginning of enemy movement.
   ;
   _Bit4_P1_Dir_Up{4} = 0

   gosub __Check_P1_LR

   goto __Clear_Direction

__Skip_to_P1_Move_Up

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Up: Moves enemy up only if sprite is lined up with PF.
   ;
   temp5 = (temp3*4)+16

   if temp5 <> player1x then goto __Skip_P1_Up

   _P1_U_D = _P1_U_D - 1.20

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Up: Randomly checks to see if a new direction can be
   ;  taken if the direction hasn't changed lately.
   ;
   ;  Remember that the value of _Enemy_Rand_Look can be increased to make
   ;  it more likely that a new direction will be looked for.
   ;
   if _Bit5_Direction_Changed{5} then goto __Skip_Enemy_Look_Up

   temp5 = rand

   temp6 = (player1y/8)*8

   if temp5 < _Enemy_Rand_Look then if temp6 = player1y then gosub __Check_P1_LR : if _Bit5_Direction_Changed{5} then _Bit4_P1_Dir_Up{4} = 0 : goto __Clear_Direction

   _Bit5_Direction_Changed{5} = 0

__Skip_Enemy_Look_Up

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Up: Turns on the up direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %00001111

   _Bit4_P1_Dir_Up{4} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Up: Enemy sprite up frame.
   ;
   player1:
   %01111100
   %01111100
   %11010110
   %11010110
   %11010110
   %11010110
   %11111110
   %11111110
   %11111110
   %11111110
   %11111110
   %11111110
   %10101010
   %10101010
end

__Skip_P1_Up



   ;****************************************************************
   ;
   ;  Enemy down check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if enemy down direction bit isn't on.
   ;
   if !_Bit5_P1_Dir_Down{5} then goto __Skip_P1_Down

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Down: Converts enemy sprite coordinates and checks to
   ;  see if any playfield pixels are in the way.
   ;
   temp3 = (player1x-16)/4

   temp6 = ((player1y+8)/8) + 1

   if pfread(temp3,temp6) then goto __Enemy_Cant_Move_Down

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then goto __Enemy_Cant_Move_Down

   goto __Skip_to_P1_Move_Down

__Enemy_Cant_Move_Down

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Down: PF pixel in the way. Clears the down bit, gets a
   ;  new direction and jumps to the beginning of enemy movement.
   ;
   _Bit5_P1_Dir_Down{5} = 0

   gosub __Check_P1_LR

   goto __Clear_Direction

__Skip_to_P1_Move_Down

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Down: Moves down only if sprite is lined up with PF.
   ;
   temp5 = (temp3*4)+16

   if temp5 <> player1x then goto __Skip_P1_Down

   _P1_U_D = _P1_U_D + 1.20

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Down: Randomly checks to see if a new direction can be
   ;  taken if the direction hasn't changed lately.
   ;
   ;  Remember that the value of _Enemy_Rand_Look can be increased to make
   ;  it more likely that a new direction will be looked for.
   ;
   if _Bit5_Direction_Changed{5} then goto __Skip_Enemy_Look_Down

   temp5 = rand

   temp6 = (player1y/8)*8

   if temp5 < _Enemy_Rand_Look then if temp6 = player1y then gosub __Check_P1_LR : if _Bit5_Direction_Changed{5} then _Bit5_P1_Dir_Down{5} = 0 : goto __Clear_Direction

   _Bit5_Direction_Changed{5} = 0

__Skip_Enemy_Look_Down

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Down: Turns on the down direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %00001111

   _Bit5_P1_Dir_Down{5} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Down: Enemy sprite down frame.
   ;
   player1:
   %01111100
   %01111100
   %11111110
   %11111110
   %11111110
   %11111110
   %11010110
   %11010110
   %11010110
   %11010110
   %11111110
   %11111110
   %10101010
   %10101010
end

__Skip_P1_Down



   ;****************************************************************
   ;
   ;  Enemy left check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if enemy left direction bit isn't on.
   ;
   if !_Bit6_P1_Dir_Left{6} then goto __Skip_P1_Left

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Left: Converts enemy sprite coordinates and checks to
   ;  see ifany playfield pixels are in the way.
   ;
   temp5 = ((player1x-17)/4)

   temp6 = player1y/8

   if pfread(temp5,temp6) then goto __Enemy_Cant_Move_Left

   temp3 = temp6 + 1

   if pfread(temp5,temp3) then goto __Enemy_Cant_Move_Left

   goto __Skip_to_P1_Move_Left

__Enemy_Cant_Move_Left

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Left: PF pixel in the way. Clears the left bit, gets a
   ;  new direction and jumps to the beginning of enemy movement.
   ;
   _Bit6_P1_Dir_Left{6} = 0

   gosub __Check_P1_UD

   goto __Clear_Direction

__Skip_to_P1_Move_Left

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Left: Move left only if sprite is lined up with PF.
   ;
   temp5 = temp6*8 : temp6 = player1y - 1 : temp4 = player1y - 2

   if temp5 <> player1y && temp5 <> temp6 && temp5 <> temp4 then goto __Skip_P1_Left

   _P1_L_R = _P1_L_R - 0.60

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Left: Randomly checks to see if a new direction can be
   ;  taken if the direction hasn't changed lately.
   ;
   ;  Remember that the value of _Enemy_Rand_Look can be increased to make
   ;  it more likely that a new direction will be looked for.
   ;
   if _Bit5_Direction_Changed{5} then goto __Skip_Enemy_Look_Left

   temp5 = rand

   if temp5 < _Enemy_Rand_Look then temp5 = (((player1x-16)/4)*4)+16 : if temp5 = player1x then gosub __Check_P1_UD : if _Bit5_Direction_Changed{5} then _Bit6_P1_Dir_Left{6} = 0 : goto __Clear_Direction

   _Bit5_Direction_Changed{5} = 0

__Skip_Enemy_Look_Left

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Left: Turns on the left direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %00001111

   _Bit6_P1_Dir_Left{6} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Left: Enemy sprite left frame.
   ;
   player1:
   %01111100
   %01111100
   %11111110
   %11111110
   %10101110
   %10101110
   %10101110
   %10101110
   %11111110
   %11111110
   %11111110
   %11111110
   %10101010
   %10101010
end


__Skip_P1_Left



   ;****************************************************************
   ;
   ;  Enemy right check.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Skips this section if enemy right direction bit isn't on.
   ;
   if !_Bit7_P1_Dir_Right{7} then goto __Skip_P1_Right

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Right: Converts enemy sprite coordinates and checks to
   ;  see if any playfield pixels are in the way.
   ;
   temp5 = (player1x-8)/4

   temp6 = player1y/8

   if pfread(temp5,temp6) then goto __Enemy_Cant_Move_Right

   temp3 = temp6 + 1

   if pfread(temp5,temp3) then goto __Enemy_Cant_Move_Right

   goto __Skip_to_P1_Move_Right

__Enemy_Cant_Move_Right

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Right: PF pixel in the way. Clears the right bit, gets 
   ;  a new direction and jumps to the beginning of enemy movement.
   ;
   _Bit7_P1_Dir_Right{7} = 0

   gosub __Check_P1_UD

   goto __Clear_Direction

__Skip_to_P1_Move_Right

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Right: Moves right only if sprite is lined up with PF.
   ;
   temp5 = temp6*8 : temp6 = player1y - 1 : temp4 = player1y - 2

   if temp5 <> player1y && temp5 <> temp6 && temp5 <> temp4 then goto __Skip_P1_Right

   _P1_L_R = _P1_L_R + 0.60

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Right: Randomly checks to see if a new direction can be
   ;  taken if the direction hasn't changed lately.
   ;
   ;  Remember that the value of _Enemy_Rand_Look can be increased to make
   ;  it more likely that a new direction will be looked for.
   ;
   if _Bit5_Direction_Changed{5} then goto __Skip_Enemy_Look_Right

   temp5 = rand

   if temp5 < _Enemy_Rand_Look then temp5 = (((player1x-16)/4)*4)+16 : if temp5 = player1x then gosub __Check_P1_UD : if _Bit5_Direction_Changed{5} then _Bit7_P1_Dir_Right{7} = 0 : goto __Clear_Direction

   _Bit5_Direction_Changed{5} = 0

__Skip_Enemy_Look_Right

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Right: Turns on the right direction bit.
   ;
   _BitOp_P0_P1_Dir = _BitOp_P0_P1_Dir & %00001111

   _Bit7_P1_Dir_Right{7} = 1

   ;```````````````````````````````````````````````````````````````
   ;  Enemy Right: Enemy sprite right frame.
   ;
   player1:
   %01111100
   %01111100
   %11111110
   %11111110
   %11101010
   %11101010
   %11101010
   %11101010
   %11111110
   %11111110
   %11111110
   %11111110
   %10101010
   %10101010
end

__Skip_P1_Right



   ;***************************************************************
   ;
   ;  Enemy counter check.
   ;
__Clear_Direction

   ;```````````````````````````````````````````````````````````````
   ;  Clears enemy direction flag and enemy counter if enemy
   ;  counter is greater than 2.
   ;
   if _Enemy_Counter > 2 then _Bit5_Direction_Changed{5} = 0 : _Enemy_Counter = 0



   ;***************************************************************
   ;
   ;  22 rows that are 8 scanlines high.
   ;
   DF6FRACINC = 0 ; Background colors.
   DF4FRACINC = 0 ; Playfield colors.

   DF0FRACINC = 32 ; Column 0.
   DF1FRACINC = 32 ; Column 1.
   DF2FRACINC = 32 ; Column 2.
   DF3FRACINC = 32 ; Column 3.



   ;****************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen



   ;***************************************************************
   ;
   ;  Reset switch check and end of main loop.
   ;
   ;  Any Atari 2600 program should restart when the reset  
   ;  switch is pressed. It is part of the usual standards
   ;  and procedures.
   ;
   ;```````````````````````````````````````````````````````````````
   ;  Turns off reset restrainer bit and jumps to beginning of
   ;  main loop if the reset switch is not pressed.
   ;
   if !switchreset then _Bit0_Reset_Restrainer{0} = 0 : goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Jumps to beginning of main loop if the reset switch hasn't
   ;  been released after being pressed.
   ;
   if _Bit0_Reset_Restrainer{0} then goto __Main_Loop

   ;```````````````````````````````````````````````````````````````
   ;  Restarts the program.
   ;
   goto __Start_Restart bank2





   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````
   ;
   ;  END OF MAIN LOOP
   ;
   ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
   ;```````````````````````````````````````````````````````````````





   ;****************************************************************
   ;
   ;  Checks left and right for an opening.
   ;
__Check_P1_LR

   ;```````````````````````````````````````````````````````````````
   ;  Clears direction changed bit and chooses which direction to
   ;  start looking.
   ;
   _Bit5_Direction_Changed{5} = 0

   ;```````````````````````````````````````````````````````````````
   ;  15 percent chance that player location will be ignored.
   ;
   temp5 = rand : if temp5 < 38 then goto __Skip_LR_Check

   ;```````````````````````````````````````````````````````````````
   ;  Player location not ignored. Skips first left check if player
   ;  is to the right of the enemy.
   ;
   if player0x > player1x then goto __Skip_LR_Check

   ;```````````````````````````````````````````````````````````````
   ;  Looks to the left.
   ;
   temp5 = ((player1x-17)/4)

   temp6 = player1y/8

   if pfread(temp5,temp6) then goto __Skip_LR_Check

   temp3 = temp6 + 1

   if pfread(temp5,temp3) then goto __Skip_LR_Check

   _Bit6_P1_Dir_Left{6} = 1 : _Bit5_Direction_Changed{5} = 1 : return thisbank

__Skip_LR_Check

   ;```````````````````````````````````````````````````````````````
   ;  Looks to the right.
   ;
   temp5 = (player1x-8)/4

   temp6 = player1y/8

   if pfread(temp5,temp6) then goto __Skip_R_Check

   temp3 = temp6 + 1

   if pfread(temp5,temp3) then goto __Skip_R_Check

   _Bit7_P1_Dir_Right{7} = 1 : _Bit5_Direction_Changed{5} = 1 : return thisbank

__Skip_R_Check

   ;```````````````````````````````````````````````````````````````
   ;  Looks to the left.
   ;
   temp5 = ((player1x-17)/4)

   temp6 = player1y/8

   if pfread(temp5,temp6) then return thisbank

   temp3 = temp6 + 1

   if pfread(temp5,temp3) then return thisbank

   _Bit6_P1_Dir_Left{6} = 1 : _Bit5_Direction_Changed{5} = 1 : return thisbank



   ;****************************************************************
   ;
   ;  Looks up and down for an opening.
   ;
__Check_P1_UD

   ;```````````````````````````````````````````````````````````````
   ;  Clears direction changed bit and chooses which direction to
   ;  start looking.
   ;
   _Bit5_Direction_Changed{5} = 0

   ;```````````````````````````````````````````````````````````````
   ;  15 percent chance that player location will be ignored.
   ;
   temp5 = rand : if temp5 < 38 then goto __Skip_UD_Check

   ;```````````````````````````````````````````````````````````````
   ;  Player location not ignored. Skips first up check if player
   ;  is lower than enemy.
   ;
   if player0y > player1y then goto __Skip_UD_Check

   ;```````````````````````````````````````````````````````````````
   ;  Looks up.
   ;
   temp3 = (player1x-16)/4

   temp6 = (player1y-3)/8

   if pfread(temp3,temp6) then goto __Skip_UD_Check

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then goto __Skip_UD_Check

   _Bit4_P1_Dir_Up{4} = 1 : _Bit5_Direction_Changed{5} = 1 : return thisbank

__Skip_UD_Check

   ;```````````````````````````````````````````````````````````````
   ;  Looks down.
   ;
   temp3 = (player1x-16)/4

   temp6 = ((player1y+8)/8) + 1

   if pfread(temp3,temp6) then goto __Skip_U_Check

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then goto __Skip_U_Check

   _Bit5_P1_Dir_Down{5} = 1 : _Bit5_Direction_Changed{5} = 1 : return thisbank

__Skip_U_Check

   ;```````````````````````````````````````````````````````````````
   ;  Looks up.
   ;
   temp3 = (player1x-16)/4

   temp6 = (player1y-3)/8

   if pfread(temp3,temp6) then return thisbank

   temp5 = temp3 + 1

   if pfread(temp5,temp6) then return thisbank

   _Bit4_P1_Dir_Up{4} = 1 : _Bit5_Direction_Changed{5} = 1 : return thisbank





   ;****************************************************************
   ;
   ;  Left/right animation frames for player.
   ;
__Frame_LR_00
   player0:
   %01111100
   %01111100
   %11111110
   %11111110
   %11111110
   %11111110
   %11110000
   %11110000
   %11111110
   %11111110
   %11111110
   %11111110
   %01111100
   %01111100
end

   return thisbank


__Frame_LR_01
   player0:
   %01111100
   %01111100
   %11111110
   %11111110
   %11111000
   %11111000
   %11100000
   %11100000
   %11111000
   %11111000
   %11111110
   %11111110
   %01111100
   %01111100
end

   return thisbank


__Frame_LR_02
   player0:
   %01111100
   %01111100
   %11111000
   %11111000
   %11110000
   %11110000
   %11100000
   %11100000
   %11110000
   %11110000
   %11111000
   %11111000
   %01111100
   %01111100
end

   return thisbank


   ;****************************************************************
   ;
   ;  Up animation frames for player.
   ;
__Frame_U_00
   player0:
   %01101100
   %01101100
   %11101110
   %11101110
   %11101110
   %11101110
   %11111110
   %11111110
   %11111110
   %11111110
   %11111110
   %11111110
   %01111100
   %01111100
end

   return thisbank


__Frame_U_01
   player0:
   %01000100
   %01000100
   %11000110
   %11000110
   %11101110
   %11101110
   %11101110
   %11101110
   %11111110
   %11111110
   %11111110
   %11111110
   %01111100
   %01111100
end

   return thisbank


__Frame_U_02
   player0:
   %00000000
   %00000000
   %10000010
   %10000010
   %11000110
   %11000110
   %11101110
   %11101110
   %11111110
   %11111110
   %11111110
   %11111110
   %01111100
   %01111100
end

   return thisbank



   ;****************************************************************
   ;
   ;  Down animation frames for player.
   ;
__Frame_D_00
   player0:
   %01111100
   %01111100
   %11111110
   %11111110
   %11111110
   %11111110
   %11111110
   %11111110
   %11101110
   %11101110
   %11101110
   %11101110
   %01101100
   %01101100
end

   return thisbank


__Frame_D_01
   player0:
   %01111100
   %01111100
   %11111110
   %11111110
   %11111110
   %11111110
   %11101110
   %11101110
   %11101110
   %11101110
   %11000110
   %11000110
   %01000100
   %01000100
end

   return thisbank


__Frame_D_02
   player0:
   %01111100
   %01111100
   %11111110
   %11111110
   %11111110
   %11111110
   %11101110
   %11101110
   %11000110
   %11000110
   %10000010
   %10000010
   %00000000
   %00000000
end

   return thisbank





   bank 4
   temp1=temp1





   bank 5
   temp1=temp1





   bank 6
   temp1=temp1

Back to Top

 

 

Affirmations

I'm a money magnet. Good things happen to me. I get things done. I'm happy. I'm healthy. I'm smart. I'm creative. I'm a nice person. I'm successful. I'm good with money. I'm honest. I'm trustworthy. I'm responsible. I'm wise. I'm easygoing. I'm clear-minded. I'm sober. I'm calm. I'm thankful. I'm satisfied. I'm forgiving. I'm confident. I'm kind. I'm considerate. I'm likeable. I'm friendly. I'm loving. I'm loveable. I'm joyful. I'm playful. I'm full of energy. I'm fun to be around. I'm a good friend. I'm eternal. I'm powerful. I'm a being of light. I'm a spirit wearing a body.

 

In Case You Didn't Know

 

Trump's Jab = Bad

Did you know that Trump's rushed Operation Warp Speed rona jab has less than one percent overall benefit? Some people call it the depopulation jab and it has many possible horrible side effects (depending on the lot number, concentration, and if it was kept cold). Remember when many Democrats were against Trump's Operation Warp Speed depopulation jab, then they quickly changed their minds when Biden flip-flopped and started pushing it?

 

Some brainwashed rona jab cultists claim that there are no victims of the jab, but person after person will post what the jab did to them, a friend, or a family member on web sites such as Facebook and they'll be lucky if they don't get banned soon after. Posting the truth is “misinformation” don't you know. Awakened sheep might turn into lions, so powerful people will do just about anything to keep the sheep from waking up.

 

Check out these videos:

If You Got the COVID Shot and Aren't Injured, This May Be Why

Thought Experiment: What Happens After the Jab?

The Truth About Polio and Vaccines

What Is Causing the Mysterious Self-Assembling Non-Organic Clots and Sudden Deaths?

Full Video of Tennessee House of Representatives Health Subcommittee Hearing Room 2 (The Doctors Start Talking at 33:28)

 

 

H Word and I Word = Good

Take a look at my page about the famous demonized medicines called The H Word and Beyond. You might also want to look at my page called Zinc and Quercetin. My sister and I have been taking zinc and quercetin since the summer of 2020 in the hopes that they would scare away the flu and other viruses (or at least make them less severe). Here's one more page to check out: My Sister's Experiences With COVID-19.

 

 

B Vitamins = Good

Some people appear to have a mental illness because they have a vitamin B deficiency. For example, the wife of a guy I used to chat with online had severe mood swings which seemed to be caused by food allergies or intolerances. She would became irrational, obnoxious, throw tantrums, and generally act like she had a mental illness. The horrid behavior stopped after she started taking a vitamin B complex. I've been taking Jarrow B-Right (#ad) for many years. It makes me much easier to live with. I wonder how many people with schizophrenia and other mental mental illnesses could be helped by taking a B complex once or twice a day with meals (depending on their weight)?

 

 

Soy = Bad

Unfermented soy is bad!When she stopped eating soy, the mental problems went away.” Fermented soy doesn't bother me, but the various versions of unfermented soy (soy flour, soybean oil, and so on) that are used in all kinds of products these days causes a negative mental health reaction in me that a vitamin B complex can't tame. The sinister encroachment of soy has made the careful reading of ingredients a necessity.

 

I wouldn't be surprised to find out that unfermented soy is the main reason why so many soy-sucking Democrats in the USA seem to be constantly angry and have a tendency to be violent when hearing words or reading signs that they don't agree with. If I unknowingly eat something with unfermented soy in it, I get irritable, angry, and feel like breaking things, so it's not the placebo effect. Scientists in the future will probably find out that unfermented soy can make people angry. We already know that food sensitivities cause mood changes. It took me over a decade to figure out that unfermented soy was affecting my mood. What if millions of people are having a similar reaction to soy and don't even know it? Some people eat it and drink it every day.

 

I started taking AyaLife (99% Pure CBD oil) as needed in April of 2020. So far it's the only thing that helps my mood when I've mistakenly eaten something that contains soy. AyaLife is THC-free (non-psychoactive) and is made in the USA. I also put a couple dropper fulls under my tongue before leaving the house or if I just need to calm down.

 

It's supposedly common knowledge that constantly angry Antifa-types basically live on soy products. What would happen if they stopped eating and drinking soy sludge and also took a B complex every day? Would a significant number of them become less angry? Would AyaLife CBD oil also help?

 

 

Wheat = Bad

If you are overweight, have type II diabetes, or are worried about the condition of your heart, check out the videos by Ken D Berry, William Davis, and Ivor Cummins. It seems that most people should avoid wheat, not just those who have a wheat allergy or celiac disease. Check out these books: Undoctored (#ad), Wheat Belly (#ad), and Eat Rich, Live Long (#ad).

 

 

Negative Ions = Good

Negative ions are good for us. You might want to avoid positive ion generators and ozone generators. A plain old air cleaner is better than nothing, but one that produces negative ions makes the air in a room fresher and easier for me to breathe. It also helps to brighten my mood.

 

 

Litterbugs = Bad

Never litter. Toss it in the trash or take it home. Do not throw it on the ground. Also remember that good people clean up after themselves at home, out in public, at a campsite and so on. Leave it better than you found it.

 

 

Climate Change Cash Grab = Bad

Seems like more people than ever finally care about water, land, and air pollution, but the climate change cash grab scam is designed to put more of your money into the bank accounts of greedy politicians. Those power-hungry schemers try to trick us with bad data and lies about overpopulation while pretending to be caring do-gooders. Trying to eliminate pollution is a good thing, but the carbon footprint of the average law-abiding human right now is actually making the planet greener instead of killing it.

 

Eliminating farms and ranches, eating bugs, getting locked down in 15-minute cities, owning nothing, using digital currency (with expiration dates) that is tied to your social credit score, and paying higher taxes will not make things better and “save the Earth.” All that stuff is part of an agenda that has nothing to do with making the world a better place for the average person. It's all about control, depopulation, and making things better for the ultra-rich. They just want enough peasants left alive to keep things running smoothly.

 

Watch these two videos for more information:

CO2 is Greening The Earth

The Climate Agenda

 

 

How to Wake Up Normies

Charlie Robinson had some good advice about waking up normies (see the link to the video below). He said instead of verbally unloading or being nasty or acting like a bully, ask the person a question. Being nice and asking a question will help the person actually think about the subject.

 

Interesting videos:

Charlie Robinson Talks About the Best Way to Wake Up Normies

Georgia Guidestones Explained

The Men Who Own Everything

Disclaimer

View this page and any external web sites at your own risk. I am not responsible for any possible spiritual, emotional, physical, financial or any other damage to you, your friends, family, ancestors, or descendants in the past, present, or future, living or dead, in this dimension or any other.

 

Use any example programs at your own risk. I am not responsible if they blow up your computer or melt your Atari 2600.

 

Home Inventions Quotations Game Design Atari Memories Personal Pages About Site Map Contact Privacy Policy Tip Jar