Code: Select all
ex de, hl
ex de, ix
Code: Select all
ex de, hl
ex de, ix
Nope. EX DE,IX is not a valid Z80 instruction.
Ah yes! Forgot the push/pop trick!Ast A. Moore wrote: ↑Tue May 04, 2021 7:48 pm Or simply:
Code: Select all
push ix ;2 bytes pop hl ;(or any other register) 1 byte
Code: Select all
PUSH IX ; 15/2
POP HL ; 10/1
; 25 Ts, 3 bytes
LD A, IXH ; 8/2
LD H, A ; 4/1
LD A, IXL ; 8/2
LD L, A ; 4/1
; 24 Ts, 6 bytes
True. IX & IY get a lot of stick for being slow, but I very recently converted a chunk of code to use them. It was much quicker to use IX, rather than shunting data structures back & forth to where they needed to be for the original code to access them. Also prone to bugs having 2 copies of a data structure knocking about in different places, very easy to overwrite the wrong value and wonder why it hasn't updated!Turtle_Quality wrote: ↑Tue May 04, 2021 7:24 pm I think all those can be done with IX / IY also, slower but with the displacement byte when it's indirect ; such as OR (IX+d)
Well, it depends. In "Escape from M.O.N.J.A.S." I really needed IM2: I work on a temporary framebuffer, and I have to wait for an interrupt before copying it into the screen buffer. But doing a HALT would mean to waste a lot of CPU power, so what I do is paint in the buffer, when I ended I set a flag to indicate to the interrupt routine that it can dump the temporary framebuffer, and then I start to pre-calculate things for the next frame (like the next position of all the characters, which objects are near the main character, and so on), and when I did everything that I could before having to paint the new frame, THEN I wait for the interrupt to end copying the screen. This allowed me to gain between one and two FPS.Bubu wrote: ↑Tue May 04, 2021 7:29 pm Z80 things that weren't obvious that you wish you'd known earlier:
When I started programming with Z80, I thought that using IM2 would be a symbol of professional developing... but I never found a real use or utility to implement interrupts: it makes code run so slow, avoids to have sounds meanwhile playing... Never understood the reason for using IM2. My Anteater game doesn't use it at all ( well, only for detecting the coin at the beginning )
To sign-extend an 8-bit number in A to a 16-bit number in BC:
Code: Select all
LD H,(HL)
Why? It’s no different than, say, IN A,(*) (where the full port address is formed by the contents of A placed in the top eight bits).Morkin wrote: ↑Wed May 05, 2021 11:30 pm I still can't get my head around:
Just hurts my brain for some reason.Code: Select all
LD H,(HL)
I'm not sure - it feels like you're trying to scoop water out of a bucket, using the same bucket that's holding the water...Ast A. Moore wrote: ↑Thu May 06, 2021 12:07 amWhy? It’s no different than, say, IN A,(*) (where the full port address is formed by the contents of A placed in the top eight bits).Morkin wrote: ↑Wed May 05, 2021 11:30 pm I still can't get my head around:
Just hurts my brain for some reason.Code: Select all
LD H,(HL)
I see what you mean, but in fact the instruction takes several machine cycles to execute, so by the time H is loaded with the value of the address pointed to by HL, the HL has already been used up, as it were. There are two internal registers in the Z80—W and Z—that are used to temporarily hold some values. They are invisible to the programmer, but they’re there.Morkin wrote: ↑Thu May 06, 2021 9:17 amI'm not sure - it feels like you're trying to scoop water out of a bucket, using the same bucket that's holding the water...Ast A. Moore wrote: ↑Thu May 06, 2021 12:07 am Why? It’s no different than, say, IN A,(*) (where the full port address is formed by the contents of A placed in the top eight bits).
Yes, that’s the approach I use in Yankee. Sometimes, though, there’s an issue with rounding, but overall it works great. I use it to calculate the position of almost all the sprites.AndyC wrote: ↑Thu May 06, 2021 8:49 am Not strictly Z80, but it took me a very long time to realise the benefits of fixed point arithmetic in writing a 2D game. I was always thinking in terms of pixels and could never really get the kind of smoothness I wanted.
Having read how Super Mario does it, the answer is obvious. Use 16-bit math but only pay attention to the top 8-bits as an on screen position (effectively the lower 8-bits being the decimal portion). Now you can manage much smoother speeds etc without sacrificing performance.
That's how I'm doing things in my overhead driving engine. The decimal part is only considered for movement, literally everything else uses the integer part only (as if all values had been floor()ed first)AndyC wrote: ↑Thu May 06, 2021 8:49 am fixed point arithmetic in writing a 2D game ... Use 16-bit math but only pay attention to the top 8-bits as an on screen position (effectively the lower 8-bits being the decimal portion). Now you can manage much smoother speeds etc without sacrificing performance.
And so, indeed, does Sonic! By coincidence Jon Burton posted a new Coding Secrets video today which demonstrates the same technique in 68000 assembly (assuming I’ve understood and recognised it correctly!)AndyC wrote: ↑Thu May 06, 2021 8:49 am Having read how Super Mario does it, the answer is obvious. Use 16-bit math but only pay attention to the top 8-bits as an on screen position (effectively the lower 8-bits being the decimal portion). Now you can manage much smoother speeds etc without sacrificing performance.
So far I have used an IM 2 for two reasonsBubu wrote: ↑Tue May 04, 2021 7:29 pm Z80 things that weren't obvious that you wish you'd known earlier:
When I started programming with Z80, I thought that using IM2 would be a symbol of professional developing... but I never found a real use or utility to implement interrupts: it makes code run so slow, avoids to have sounds meanwhile playing... Never understood the reason for using IM2. My Anteater game doesn't use it at all ( well, only for detecting the coin at the beginning )
You may use IM2 just not to use other modes. And actually have an empty interrupt routineNever understood the reason for using IM2