Learn Multi platform 8086 Assembly Programming... For World Domination!

Suck Shoot!

In this series we'll write a little shooter... Suck Shoot!

Lesson SuckShoot1 - Suck Shoot on the 8086
SuckShoot is a simple little shooter game, designed as a test for a minimal 8 bit game... it was written first on the 6809 systems, but has now been ported to the 8086

Dos_SuckShoot.asm


You can play Suck Shoot!
Suck Shoot is a 'miniature' version of my larger "Suck Hunt' game...

Gameplay is simple, you have to shoot bats flying towards the screen... the more you shoot, the faster they get!

SuckShoot uses the BCD, Range Checking and Random number code covered in the Multiplatform series

Suck Shoot for DOS requires VGA!

The game COULD be ported to EGA, but the author is a lazy git!... feel free to insult him on youtube and tell him to "do better!"


The SuckShoot code on MSDOS

SuckShoot on MsDOS uses 7 sprites, One crosshair, and 3 sizes of bat with 2 frames each.

We switch between the sprite sizes depending on the bat position.
Each sprite has a pointer to the bitmap, and a width and height in pixels.

Despite their appearance, The sprites are all 16 color (They were converted from 4 color systems)
We show the Title screen, It has a title, highscore, and animated bat.
We update the bat animation until fire is pressed.

We need quite a long pause on a fast system like the 8086!


Sprite code

When showing the enemy sprite to the screen, we need to calculate the 'offset' within the SpriteInfo table of the sprite we want to show,

To do this we need to calculate the frame, and one of the 3 sizes based on the enemy scale.
We now need to take our sprite position, and size from the sprite lookup and convert it.

First we alter the 'draw position' so the X,Y pos of the sprite is the 'Center' of the drawn sprite (This is for the range checking to work correctly)

As we're using a 1 byte X,Y pos, these are 'Logical units'... where 1 logical unit is 2 pixels, so the center of our 320 x 200 screen is 80,100


Then we multiply up so we have a VRAM position.

As the screen is 320 pixels wide, and in VGA mode, each pixel is one pixel, the formula is VRAM= Xpos+Ypos*320.
We XOR the sprite to the screen.

As it's an XOR sprite, we can remove it by drawing to the same position a second time.

Game Loop

When the game starts, we first need to set up all the gameplay variables to their default state.
At the start of the main loop, we first update the FX counter, and stop any sound if it's time

We read in from the joystick and cursor keys (The two are ANDed together so both work!)

We process each possible direction - this is based on the simple series example.

We check each direction button, and the X,Y range to ensure the cursor doesn't go offscreen
We draw the new sprite positions

Next there's a delay, then we remove the sprites again!... it's time to recalculate!
If the player pressed fire, we test the cursor position, and see if it's in range of the enemy.

If it is, we make a sound, speed up the enemy, and reset the enemy to a new random position.

We also give the player some points.

If they missed, they get nothing... absolutely nothing!
Next we update the bat...

We speed up the bat gradually, and check to see if the bat is now at 'maximum size'

If the bat is in the foreground, the player was bitten, so we take a life away, and end the game if the player has no more lives.


We jump back up to the start of the main game loop.

GameOver

The game over sequence checks if the highscore lower than the current score.

If the player has a highscore, we transfer the current score to the highscore width a pair of MOVSW commands (4 bytes total).
We show a congratulations message, and wait until fire is pressed.

We show a different text message if the player does not have a highscore.

Lesson SuckShoot2 - Suck Shoot on the Wonderswan 1/2 - Sprites!
SuckShoot is a simple little shooter game, designed as a test for a minimal 8 bit game... it was written first on the 6809 systems, but has now been ported to the 8086

WSW_SuckShoot.asm


You can play Suck Shoot!
Suck Shoot is a 'miniature' version of my larger "Suck Hunt' game...

Gameplay is simple, you have to shoot bats flying towards the screen... the more you shoot, the faster they get!

SuckShoot uses the BCD, Range Checking and Random number code covered in the Multiplatform series

Todays gaming presentation works on the Wonderswan or Wonderswan color!

The only differences are the sprite pattern data, and the init routines!


Wonderswan Sprite Data

SuckShoot on 8086 uses 7 sprites, One crosshair, and 3 sizes of bat with 2 frames each.

We switch between the sprite sizes depending on the bat position.
Each sprite has a pointer to the bitmap, and a width and height in pixels.

The WSC sprites are 16 color - they are 4 color on WS classic
Each sprite is represented by a tilemap, which is a grid of the patterns which define that sprite

Preparing the sprites

We need to transfer our pattern data for our sprites... the actual data (and destination) is different depending if we're using the wonderswan or wonderswan color, but the basic procedure is the same for both.


We transfer our pattern data to the correct address (2000h+/4000h+) with an MOVSB command
We need to configure our palettes... on the wonderswan color palette 8-15 can be used.

On the wonderswan classic only palettes 12-15 have color 0 as transparent.

We therefore use color palette 15 - as it will work for both!
We need to turn on sprites, and define the RAM address for our sprite data, we use address 0E00h

Sprite code

When showing the enemy sprite to the screen, we need to calculate the 'offset' within the SpriteInfo table of the sprite we want to show,

To do this we need to calculate the frame, and one of the 3 sizes based on the enemy scale.
We now need to take our sprite position, and size from the sprite lookup and convert it.

First we alter the 'draw position' so the X,Y pos of the sprite is the 'Center' of the drawn sprite (This is for the range checking to work correctly)

As we're using a 1 byte X,Y pos, these are 'Logical units'... where 1 logical unit is 2 pixels, so the center of our 320 x 200 screen is 80,100


Then we multiply up so we have a VRAM position.

As the screen is 320 pixels wide, and in VGA mode, each pixel is one pixel, the formula is VRAM= Xpos+Ypos*320.
When we want to draw a sprite, we need to calculate the location within the SpriteInfo table of the sprite we want to show.

Each sprite has 4 byte entries, so our first operation is to decide the sprite number we want to show (There are 3 sets of 2 frames of animation for the sizes of sprite)

We take this value and multiply it by 4... then add this offset to SpriteInfo
Our sprite settings are held in ram at address 0E00h+... Each sprite uses 4 bytes.

We calculate the next free slot and return the address in DI
We load in the details of the sprite from the table.

We were passed an X and Ypos... we now 'Center' our sprite by subtracting half the width and height.

We convert the pixel width and height in to a number of 8x8 tiles (we divide by 8 / shift right 3 times)

We also load the table pointer into SI
We define each hardware sprite by setting the 4 bytes of the sprite.

our pattern data for our sprites are pattern 128+, so we add &0080h... we use palette 15 (Which offers transparency on wonderswan classic) so we add 0E00h

We repeat for each sprite along the tilemap, adding 8 pixels each time.

We repeat going down the screen.

We then update the sprite count... setting First Sprite to draw with port 05h, and the sprite count with 06h


Lesson SuckShoot3 - Suck Shoot on the Wonderswan 2/2!
Lets take a look at more of the SuckShoot code on the wonderswan!

WSW_SuckShoot.asm

Title Screen

Our title screen shows the 'Suck Shoot' Game name, the highscore, and a bat sprite.

We need to define the position of the bat sprite, so it's central and uses the biggest possible sprite.
We update the bat animation until fire is pressed.

We need to zero the hardware sprite count before using the 'ShowEnemy' routine to show the sprite

We need quite a long pause on a fast system like the 8086!

Game Loop

When the game starts, we first need to set up all the gameplay variables to their default state.

We also need to define the 'BcdScoreAdd' - which is added to the score when we kill a bat, we copy this so it's in the same data segment as the current score.
At the start of the main loop, we first update the FX counter, and stop any sound if it's time

We read in from the joystick and cursor keys (The two are ANDed together so both work!)

We process each possible direction - this is based on the simple series example.

We check each direction button, and the X,Y range to ensure the cursor doesn't go offscreen
We draw the new sprite positions

Next there's a delay, then we remove the sprites again!... it's time to recalculate!
If the player pressed fire, we test the cursor position, and see if it's in range of the enemy.

If it is, we make a sound, speed up the enemy, and reset the enemy to a new random position.

We also give the player some points.

If they missed, they get nothing... absolutely nothing!
Next we update the bat...

We speed up the bat gradually, and check to see if the bat is now at 'maximum size'

If the bat is in the foreground, the player was bitten, so we take a life away, and end the game if the player has no more lives.


We jump back up to the start of the main game loop.

GameOver

The game over sequence checks if the highscore lower than the current score.

If the player has a highscore, we transfer the current score to the highscore width a pair of MOVSW commands (4 bytes total).
We show a congratulations message, and wait until fire is pressed.

We show a different text message if the player does not have a highscore.

Other Routines

We have a 'ClearScreen' routine,

This blanks all the tiles in the tilemap, and sets the sprite count to zero.
On the wonderswan, We need to read in the directions and fire buttons separately.

The direction buttons aren't in the order we want, so we read the directions one by one.

We then process the fire buttons.
We also have a function to wait for fire to be released. we use this between screens, for example when showing game over, to ensure fire isn't still held down.


Lesson SuckShoot4 - Suck Shoot on the 8086 with CGA
I've finally got round to porting SuckShoot to CGA graphics... Lets see what's changed!

DosCGA_SuckShoot.asm


You can play Suck Shoot!
Suck Shoot is a 'miniature' version of my larger "Suck Hunt' game...

Gameplay is simple, you have to shoot bats flying towards the screen... the more you shoot, the faster they get!

SuckShoot uses the BCD, Range Checking and Random number code covered in the Multiplatform series

This version of Suck shoot uses CGA!... This time we'll only look at the new CGA code, so please see the VGA tutorial for the general code.

New Graphics code
At the start of our code we need to set up our screen into CGA mode

We also need to select the color palette.
in our CLS function we use STOSB to clear the screen
We need our bitmap font!

here is a routine to convert a 1bpp font into 2bpp for the screen memory.

It should be remembered that the CGA screen is interlaced in memory, with alternate lines at address segment B800/BA00
We need some new sprites! so we'll have to get scribbling and draw some nice cga graphics!
Our showsprite routine needs to start by calculating the VRAM destination,

Because alternate lines of the screen are interlaced
The drawing routine draws the lines of the sprite, XORing them with the current screen data, alternating between banks every other line.