Now that you understand procedures, jumps and shifts, you have enough knowledge to start taking on little assignments. I'd like you to take the pegPosition routine one final stage further. There are many reasons for using procedures and a key one is to remove repetitious code. If you look at our "pegObject.asm" module, you'll see that there are several areas where the code is doing the same thing - centring the "left" co-ordinate, placing a control at the top of the screen, for example. I want you to separate out the repeating code, make them procedures and use the
Invoke command to call them. You can stick all these little routines at the bottom of "pegObject.asm". I will give you the solution in the next thrilling episode but, for now, here's a clue as to how many routines we'll need and suggested names for them:
Next steps ...
Once again, that's all for this session. There was a lot to think about here and always remember that I only deal with just enough from these areas to get you learning. There are plenty of reference books and files out there for all the last bit of detail. That's not my purpose. Survival skills - that's what we're learning here. In the next session, I will be taking a long hard look at loops - the syntax, the usage and some examples. We'll be including some of the material we've learned up to this point in the game, so you're in for some interesting stuff.
In this session, we have looked at the sort of flags which exists inside our CPU to indicate changes in certain conditions as a result of actions we have taken. Based upon the status of these flags, we can make decisions using the various Jump commands and we saw how this can be a useful thing in allowing us conditionally to execute parts of our code. In addition, we looked at the Shift operations which allow us to move bits to the left or right inside a register. This has the effect of multiplying or dividing by powers of 2 but we also saw, in the case of the button click handler, that we can use the shift command to move the topmost 16 bits of a big register down into the lower half to allow us to perform comparisons on it. All of this gives us some powerful tools that we will be able to capitalise on in the coming sessions.
See you next time ...