Hello its Keith it and welcome to lesson 8 of my multi-platforms at 80 tutorials now this is going to be the final lesson of this series so we’re gonna have a look at the remaining zhe commands we haven’t covered yet these are gonna be fairly rare commands that aren’t particularly useful or you’ll need very rarely if at all.
But I still think it’s worth you knowing about them and we do want to try and cover all of the commands there’s 880.
Offers to us so that you at least know they exist and you can decide whether you want to use them after that we’re going to look at some optimization tricks that you can.
Use to make your code faster when you’re doing book copying or bulk filling of data and.
This is going to include queue include miss using the stack.
Pointer as a read or write pointer rather than usually the temporary data storage so let’s make a start now first we’re going to have a look at some theory it’s all on my website but I’m just going to quickly talk you through it now so let’s have a.
Look now the first thing we’re going to discuss is there are two remaining registers we haven’t covered before and that’s because they’re slightly unusual and aren’t massively useful to us however they’re worth knowing about because there may be times.
They do help you the first of these two is the eye register now this is used specifically by into a mode to which you will never.
Really have a case for using on the Amstrad.
CPC if you look at the Amstrad CPC zoom debugger you’ll see we’re in intimate mode one and in this mode the eye register here does absolutely nothing and that means we can use it as a template or if we want to the problem with it is is that you can.
Only it only has two commands you can only copy a to the eye register or read the register back to a and it’s actually relatively slow it’s faster than a pushpot though so you may want to use it in some cases.
There’s a kind of temporary store now that said on the spectrum we will use them into a mode too and in that mode the over just has a very important purpose we’re going to cover that in a later lesson because it’s relatively advanced it’ll be a spectrum only lesson but for now just bear it in mind that if you’re planning to support the spectrum.
You may not want to use the eye register at all but if you’re not.
Planning on supporting the spectrum you can use the I register for temporary storage if you want now the other.
Edge is the our register here now this is a rather unusual register because it’s actually used by the z80 for refreshing the memory of the computer the computer needs a kind of electrical charge every so often to keep it from losing all its memory and this register is used by the z80 to know when that electrical charge needs to.
Now the the practical sort of result of this if.
I just press down the f7 you’ll see the I’ll register goes up and what it will do is it will get to 128 and then it will go back to zero now you can read and write to it.
However I strongly recommend against writing to it because I’m told that if you misuse this in the wrong way writing to it could.
Cause the memory to be charged more often it should being damaged the memory that said you can read from it without doing any harm at all the thing is because it’s a constant incrementing counter assuming your code is.
Unpredictable it makes a great source for random numbers so you can read from it.
Just very easily let’s just have a.
Very quick look at that so we’ll just create.
Our standard o and 8000 and we’ll do little date a comma R and.
Then why not we’ll just glued a comma a as well and then we’ll do D I will just do a writ here and we’ll put a breakpoint tip and we’ll.
Assemble that so we’ve just run it and you can see that the rid that 5a is currently in the register when it captured to a it was.
5/8 and that 5/8 has also been moved to.
I because of our command loading I with I here so so you can use I it’s a very crude temporary store if you don’t want to use pushpop for some reason and it’s a is kind of like a random number so you can kind of think think of a random and you’ll notice every time we run it I has a different.
Value because as I say because you can’t really predict how what point are gonna be in the program because it changes so fast it does make a good random number but of course it will never get above 128 so.
If you need a number up to 255 you’re going to have to do some kind of tweaking to it or add some other sources of randomness.
In there but as I say it’s a great great way of getting a quick random number from there’s 880 ok so that’s our first subject of the two registers now and another interesting command that’s rather unusual is the.
DAA command now what I haven’t covered in this tutorial now probably.
Cover it later in an advanced tutorial is something called binary coded decimal now binary coded decimal is it conceptually very simple all.
You do is use you in a byte instead of storing 0 to 255 you store 0 to 9 and this makes it very easy to.
Show digits on to the screen.
And you just have to sort of write some mathematics routines to do addition the chibi Alchemist game I wrote uses this the ‘m scores are in binary coded decimal so the 10 digits go is stored in 10 bytes and there’s code to automatically deal with the incrementing and just shift along.
Sure everything’s updated nicely makes it easier to show on screen.
A bit faster now we did a little lesson in the past where we converted a hexadecimal number to ASCII characters and i am i did some fairly simple mathematics on there but there is a sort of common trick you will see where you can use di a as a as a converter for Hector for a single hexadecimal digit so let’s have a look at that now so we need a print charkham and let’s just get that there’s a.
Print route command and so what we need to do here.
Just need to load a with a value and let’s load it with andouille and now if we.
Call on 8,000 take out that break point you’ll see it’s shown any on screen and if we load it with a nine you’ll see it shows a nine on screen so that’s a kind of quicker more simple way than I showed before but it’s a bit less clear now what does this dia command do well it’s very very complex I’m not going to try and explain it because I would be lying if I claimed to understand it what I’d recommend if you.
Want to know more about it is you have a look at the z80 dialog guide like we looked at before there’s a detailed explanation of it here and as you can see it does.
Have some quite complex functionality I’ve never needed it but you know it’s worth knowing there at least for that hexadecimal functionality so there we go now you’ve got some really weird commands here as well like oh L DRD I’ve never used them I have no idea what you would want to use them for so I’d just recommend you ignore them probably now moving on from that the the.
Carry flag is something we did look up and we didn’t really.
Use it in mathematics and the reason for that is I actually never really needed it when I was writing chibi Akuma’s for mathematical purposes now it’s all to.
Numbers of 32 16-bit registers for calculating 32-bit numbers things like an 8 bit numbers 2 8-bit registers.
First calculating 16-bit numbers but that was not something that to be Occam has ever really used because I was always aiming for maximum speed any time you were kind of branching out like that the wasting speed so it was always how can I do this in 8-bit not how can I use 32 bits you know.
It just didn’t come up one thing that is quite interesting to note when you’re working with 16-bit numbers there’s a 16 bit add command but there is not a 16 bit subtract command for the subtract with Kerry.
So what it would do is it would subtract a register plus the carry from the registry or subtracting from so as.
There is not no subtract command without the carry so what.
You may wish to do is you may actually want to clear the carry and then use that subtract with carry command to effect a subtract command so let’s just have a go at that so if we do load and notate I’ll come up and 0 0 and then load de comma and 1 0 Zuzu and SB c HL comedy now that will subtract de from hey Chel but let’s just play with it a little bit there are.
Some commands for manipulating the co flow but there were little lab strange there’s a SCF command which sets the co flag but there is no clear carry flag command CCF means compliment Co flag which means invert it and one thing you could do is you could set the Co flag and then invert.
It which would set it to 0 but that’s.
A little bit wasteful what you actually want to do is use or a which will have no real effect on the accumulator but it will clear the carry flag as a sort of by-product now let’s just prove that.
So what we’re gonna do is we’re gonna use set Co flag and then or a and we’re going to put a breakpoint there so we.
Can see what happens and we’ll assemble this and now we’ll call 8,000 and.
So you can see the cow flag is currently zero here this one over here and then if I press f7 and step in you’ll now see the Chi flag has been set to one so that would cause a problem for our subtraction because it would subtract one too much but then our a applies and you can see that Co flag is now cleared so a subtract command.