Day 8: 357 days left..
Todays project time was taken up playing with the examples from the z80 subroutine book.
Code: Select all
; So one thing I never really though about before, but you can load a register into itself..
LD A,A ; A = A <- A Nothing except the PC is changed (PC advanced). takes 4 T states.
LD B,B ; B = B <- B Nothing except the PC is changed (PC advanced). takes 4 T states.
LD C,C ; C = C <- C Nothing except the PC is changed (PC advanced). takes 4 T states.
LD D,D ; D = D <- D Nothing except the PC is changed (PC advanced). takes 4 T states.
LD E,E ; E = E <- E Nothing except the PC is changed (PC advanced). takes 4 T states.
LD H,H ; H = H <- H Nothing except the PC is changed (PC advanced). takes 4 T states.
LD L,L ; L = L <- L Nothing except the PC is changed (PC advanced). takes 4 T states.
So it's the equivalent of a NOP. But looking at the opcode, you can do the same thing with register pairs... (But for greater T-state hit). Might be useful for precise timings that are not T4.
Can see why you wouldn't want to use HALT compared to the previous two (because of having to enable interupts).
The second interesting thing that came out of today's reading was concerning pushing single registers. According to Leventhal
Programmers generally prefer to combine byte-length operands or simply waste a byte of the stack rather than attempt to push a single byte..
He then goes on to show a number of ways to negate the lesser byte of the register pair. But I was curious why he says this. There is no explanation why its just stated as a axiom.
After that reviewed the various conditional calls, and returns. I was surprised how flexible these ops are. Would imagine that condition jumps vs condition calls are a matter of personal style preference or is there a reason to select one over the other?
How does this relate to the project - well all these will help the quality of my work. I figure the more techniques a fella has in his tool box the more flexible the approach to a problem can be.
One op code that will come in handy is the BIT instruction. being able to do bit manipulation like this will enable me to set options/states in the program. What page to display on the screen, what is the menu state, move state, stuff like that. I think it might be a little slow but would save on memory.
As an aside, today I discovered the rabbit hole that is contested memory spaces.
Progress wise I want to continue to get better at z80 so the project can be completed in a competent way - rather than just rushing something out or doing a copy pasta job. I want something I can be proud of. Even if it is a crap game
it will be a crap game with style.