******************************************************************************** * oo oo * * \( )/ Bullfrog Demo \( )/ * * ^ ^^ ^ Month 1 ^ ^^ ^ * ******************************************************************************** So you want to be a games programmer. Well then read on, and you should get a few helpful hints. Included on the disk is a simple shell for writing programs in assembler. It sets you up with all you need to swap screens, draw sprites, and so on... With this shell you don't have to wade through loads of reference manuals to find out how to set up screens, or display sprites, its been done for you. Over the course of several months we will be putting together a very simple game, but there are several things you will need:- * Enthusiasm. Yep I know, sounds obvious but you will always be just a standard programmer unless you really want to do it. * It would be nice if you read a 68000 assembler book. * Do you know what binary / hexidecimal are, no then thry and find out, get one of those boring reference manauls out the libarary. Ok, thats the boring introduction done, lets have a look at the disk. If you first assemble Demo.s and then run Demo. All that should happen is that we display a sprite on the screen. To exit from the program press the Q Key. Great. There you go. What? You want more? Then lets try and move the sprite. Have a look in draw.s in the routine _draw_all you will see we have moveq.w #0,d0 moveq.w #0,d1 moveq #0,d2 now if we change these to move.w man_x,d0 move.w man_y,d1 move.w man_frame,d2 Right, now the impatient ones of you will have assembled that. No change, of course not, but if you go into move.s and remove the indicated ;'s our sprite should start to move to the right and return to the start when he reaches the end of the screen. The way these instructions work is as follows. First we increment the value of the man x co-ordinate by 1 every turn. The value is then compared with 304 and if it is greater than this the position is reset to 0 otherwise we jump over the reset command. The value is then stored back into man_x ready for the next draw. You can change the value in the add command to increase the speed of movement. A small challenge for you, see if you can write the code to move the man down the screen. The code will be basically the same as the move x stuff, but remember the screen size is 320 by 200 pixels, and that the label lessthanx has already been used, so use something different. A note on labels, try and keep them meaningful, 6 labels with the name .here is not very helpful. We should have, by now, got the man moving down and across the screen, but thats the problem he is not moving. Lets put a bit of animation into the man. To do this we took the same routine as was used in the movement and changed a few things. Be careful, we only have 4 frames of animation so dont set the compare to high. Compile this and have a look. He is changing frames just a little bit fast, too fast in fact so we need to slow him down. To do this change the line cmp #4,d0 to cmp #4*4,d0 thats not quite all, we need to scale the number back down. To do this after the line move.w man_frame,d2 in draw.s, place the following piece of code:- asr.w #2,d2 Assemble this, and the man should be walking a bit slower. COMMAND OVERVIEW move.w 1,2 The move command is one of the most heavily used commands for simplicity we are using move.w the w means word sized data. It is the equivelent of the basic LET statement. It loads 1 into 2. add.w 1,2 The add command does just that adds the value of 1 to 2. sub.w 1,2 The sub command is similar to the add but does subtracts instead. cmp.w 1,2 The compare command compares the value of 1 with the value of 2. When used in conjunction with a branch you get the equivelent of the basic IF statement Branches The branch checks on the flags set by the compare statement. There are 15 different versions of this command:- bra Branch always. Same as GOTO bcc Branch if carry clear bcs Branch if carry set beq Branch if equal bge Branch if greater than or equal to bhi Branch if higher ble Branch if less than or equal to bls Branch if low or same blt Branch if less than bmi Branch if minus bne Branch if not equal to bpl Branch if plus bvc Branch if overflow clear bvs Branch if overflow set Dont worry if you dont understand what all of these do, we want be using all of them. I hope. Anyway, when the condition is true the branch is taken, if not them we move onto the next instruction. Labels You will notice that some of the labels have a '.' in front of them, these are called local labels. Now that means that you can use words like .finished more than once, though not inside the same routine. Routines are defined by labels which have not got a period '.' in front of them and are finished with an RTS command. jsr Jump to subroutine. This command is basically the same as the GOSUB command. rts This is basically the same as the RETURN command. asr.w 1,2 The asr command means Arithmetic Shift Right and works by moving a binary number to the right the define number of times. eg. on a asr.w #1,10 we get an answer of 5. This is because 10 in binary looks like this:- 1010 = 10 and when we move it to the right by one it becomes:- 0101 = 5