TmEE co.(TM) wrote:Some writes such as TLs seem to take longer to process than other stuff, I do full software timing in my old sound driver and I always had to have longer delays on TL writes or the data got mangled and I got wrong output. Same deal with the LR flags register. Others seemed to work faster. It doesn't make too much sense on hardware level though, at least if I designed the thing it wouldn't work like that
The busy flag SHOULD tell you when the chip is ready to grab new data. I would have thought the busy flag is cleared every sample or so. I guess it isn't the case...
Haven't checked yet, but this is how I think it is:
- All $2X registers will update within one internal clock.
- All operator registers update once every 24 internal clocks. But you never know where in the cycle you're going to be, so you have to wait at least 24 clocks in all cases to be sure.
- Some channel registers are like the operator registers and only update once every 24 clocks. Others update every 6 clocks. Hopefully I'll figure this out soon.
The BUSY flag/bit does indeed tell you that the chip is ready--it just waits longer than the maximum necessary, so if you wait for it you're guaranteed to not mess anything up.
Stef wrote:About the BUSY flag itself, well in my case i never measured how much time it stay up but if it counts one sample for each write (even after address register write ?) then that is a pure waste of time :-/
No, it's triggered by data write, you can write addresses all day and the BUSY flag won't be affected. But yes, it waits more than one sample, since one sample is 24 clocks and it waits 32.
One other thing to mention: it's possible they might have changed the BUSY flag in the YM3438 to actually only wait 24 clocks--I took a quick look at the die of that chip, and it's completely different, almost unrecognizable. The YM2612 is not only similar to the YM2203, they actually copied-and-pasted blocks from the YM2203 to the YM2612--in fact the position of some of the control units in the operator unit of the YM2612 matches where they were in the YM2203, even though this positioning doesn't make sense anymore in the YM2612. But anyway, both of these chips are built in NMOS, not CMOS (there's no P-channel FETs, and they vary transistor lengths rather than widths to control current and timing--breaking all the rules I'm learning in VLSI class!), so when the chip was redesigned in CMOS, it had to be completely redone from the ground up, they couldn't keep a single register. If they indeed changed the BUSY flag timing, this might explain how that one track in that one game plays faster on one system than another.
I would say that a good practice to write YM register is to always check BUSY flag to be 0 first.
Then if you need to write severals 2x registers you can write them really quickly with maybe 2 NOP to be safe between each write.
When you write a specific register you write its address then you can immediately write its value, no need to check the BUSY flag between the address and value write... If that work then that is already a good thing to know
I would say this:
- Always give at least 1 YM2612 internal cycle (about 4 Z80 cycles) between any writes to the chip.
- Don't ever check the BUSY flag between writing address and data, it'll never be set anyway (unless it was already set before you wrote the address).
- Don't check the BUSY flag if the last address written was a $2X register.
- For all other writes, do software timing of just over 24 YM2612 internal cycles (about 70 Z80 cycles); this will save you about 25% from waiting for BUSY (about 90 Z80 cycles).
Could someone please check this on hardware? I especially want to see what the minimum timing is for $2X writes and between address and data for all writes.
You said that :
<<You can write to a $2X register while you're waiting for the channel/operator register write to complete.>>
But if you do that, you can change the address register before the write to channel/operator occurred so the value is lost (or happen in the 2X register) ?
I did mean that, but after thinking about it I take it back. The address register and data register for all other chip writes are at the same "level" as the $2X registers. So the access time for any of them is the same, and there ordinarily would be no reason you couldn't put an address and data in the operator/channel address register and data register, and then write to another $2X register immediately afterward. However, unfortunately, the operator/channel address register is enabled by any address which is not $0X. If I was designing it, I would have made it enabled by any address not $0X or $2X (would have taken slightly less logic than they actually have)--but the way it is, if you write another $2X register the operator/channel address register will get overwritten with that value as well. Sorry!
Oh and by the way, internal clock of YM is not Z80 clock but 68000 clock (i just said that in regard of the Z80 cycle informations i gave) =)
Fixed, thanks! Dumb mistake, I've been playing with hardware clock circuits for these chips for the past few days, I know their frequencies.