![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
FlooringOkay, now we have our environment working, let's get something to display on the screen. To start off with, a simple patterned floor will do. We'll use one of the floor tile graphics from the graphics section. Go grab a floor tile graphic set that you like. For the walkthrough, I'll be using the cross flooring set, but you can use whatever you like. Just remember to change the references in your code that will be different to mine if you use another tile set. Now you have the file, make sure it is in your exped working directory. Open up your exped.asm file and go to the following section of the file: loop: ; This is the main game loop, put your code here. jp loop ;*************************************************** ; Main Memory area ; Use this area to store variables etc ;Now, between the jp loop command and the Main Memory area heading, we need to insert the tiles. We don't place the tiles in the Main memory area because they are only designed to be read, not modified. Therefore we place them in the main cartridge ROM. Later on in the project we may move them to a different place in the ROM, but for now, this place is fine. If you downloaded the binary format tiles, place the following lines between the jp loop command and the main memory area heading. ; This is the main game loop, put your code here. jp loop crossfloor: incbin "cross.bin" ;*************************************************** ; Main Memory area ; Use this area to store variables etc ;If you downloaded the asm format tiles, place the following lines between the jp loop command and the main memory area heading. ; This is the main game loop, put your code here. jp loop crossfloor: include "cross.asm" ;*************************************************** ; Main Memory area ; Use this area to store variables etc ;The crossfloor: text before the include command is a label. Labels are used in assembler to determine the starting points of code, data, etc. The incbin command tells the assembler to include a binary file at this point. The include command tells the assembler to include an assembly language file at this point. Although we now have the tiles in the ROM, they aren't going to be used in the background unless we copy them to somewhere useful. We now need to copy this data into the area of the tile data that we are going to use for the floor. Because in expedition we will never use the floor tiles as a sprite moving across the screen, we can place the data in one of the areas we reserved for the exclusive use of the background and window tiles. We'll use the first four tiles in the second tile area of bank one. These tiles are numbered 0 to 3. Update your tile planner sheet and let's get on with making it work. The first thing we need to do is to copy the tile data into the appropriate section of the tile data area in the gameboy. Thankfully we have a code snippet that will do this for us. We need the copytile.asm file from the source section. Download this file and place it in your exped working directory. We will also need bgtiled.asm and colpal.asm so get those at the same time. Now we have the files, we need to include them into the project. Insert the following code into the correct place in exped.asm (I'll stop telling you that the bits in bold are the bits to include and the bits not in bold are the bits you should be finding now). ; This is the main game loop, put your code here. jp loop ; code snippets include "copytile.asm" include "bgtiled.asm" include "colpal.asm" crossfloor: include "cross.asm"Right, we now have all the pre-written routines we need. Insert the following code. ld a,%01000011 ldh [$40],a ld a,0 ; bank 0 ld h,1 ; high tile set ld d,0 ; tile reference 0 ld e,4 ; 4 tiles to copy ld bc,crossfloor ; where the data is call copy_tile_data ; call the routine loop: ; This is the main game loop, put your code here.That piece of code will copy the tile data into the correct place. We now need to set up the background to display the flooring. Strangely enough, this is what tileback.asm was downloaded for. Insert the following code: ld bc,crossfloor call copy_tile_data ld hl,$9800 ; the start of the background data ld a,0 ; bank 0 ld b,0 ; the first tile of the 2x2 tile ld c,0 ; palette 0 call bgtile_double ; call the routine loop: ; This is the main game loop, put your code here.That piece of code has setup our background to be full of our 2x2 floor tile. The routine can be used to fill the background with any 2x2 tile. Now we need to setup the colour palettes so that we can actually see the flooring in glorious colour when we turn the display on. This is what we downloaded colpal.asm for. The palettes on the gameboy colour are not complicated, but they can be a little daunting to start off with. This is why I have provided colpal.asm. What it does is let you pass colour values to the routine and it sorts the palette out for you. It's worthwhile learning how the palettes work, so that you don't need to use this routine in the future. Having said that, it is a convenient routine. Anyway, enough of that, insert the following code: ; This is the main game loop, put your code here. jp loop setup_palettes ld b,0 ; background palette ld c,0 ; palette 0 ld d,0 ; colour 0 ld e,25 ; red value ld h,25 ; green value ld l,15 ; blue value call colour_palette ld b,0 ; background palette ld c,0 ; palette 0 ld d,1 ; colour 1 ld e,5 ; red value ld h,5 ; green value ld l,0 ; blue value call colour_palette ld b,0 ; background palette ld c,0 ; palette 0 ld d,2 ; colour 2 ld e,0 ; red value ld h,0 ; green value ld l,0 ; blue value call colour_palette ld b,0 ; background palette ld c,0 ; palette 0 ld d,3 ; colour 3 ld e,0 ; red value ld h,0 ; green value ld l,0 ; blue value call colour_palette ret ; code snippets include "copytile.asm"As you can see, this routine will set up the four colours of the first background palette. To set the colours up differently, just alter the red, green, and blue values as you like. Each value needs to be in the range of 0-31. Obviously, we need to actually call this routine at the start of our program otherwise nothing will happen, so insert the following code: Start: ; Do some initialisation stuff here, setup data, etc. ld a,0 ldh [$FF],a ldh [$41],a ldh [$42],a ldh [$43],a ld a,%01000011 ldh [$40],a call setup_palettes ld a,0 ld h,1The last thing to do now, is to turn the screen on, so that we can see all our hard work. Insert the following code: ld b,0 ; the first tile of the 2x2 tile ld c,0 ; palette 0 call bgtile_double ; call the routine ld a,%11000011 ldh [$40],a loop: ; This is the main game loop, put your code here.All that this does is to set the seventh bit to a 1 rather than 0 which turns the screen on. Compile and run the code, you should see the following display.
If you get the same as the screenshot then great, make a backup of your exped.asm file and move on to the next section. If not, back track and see what you did wrong. |