Houston, we have an image!

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
User avatar
RetroTechie
Posts: 379
Joined: Tue Nov 01, 2011 12:16 am
Location: Hengelo, NL
Contact:

Re: Houston, we have an image!

Post by RetroTechie »

May I suggest you use my ZX81 'ULA schematic' as a reference? It does the same thing as a real ZX81 ULA, but its schematic is much easier to read/understand than the ZX80 schematic + Grant's NMI add-on.

Problem is still in the logic I think:
PokeMon wrote:1. There have been horizontal sync disturbing pulses which are created from IC 19.
The problem is, every Low pulse on /IORQ makes a Preset at IC18 which creates a sync pulse two M1 cycles later.
Are you sure about that? /IORQ going low activates IC18's /preset input, which would change that flipflop's state if it was "0" before that (pin 6 in schematic above is inverted output btw). Read: if flipflop was internally "1" (pin 6 output = low), /IORQ going low would do nothing. Also note the possibility of both /preset and /clear inputs active (/clear input tied to outgoing SYNC signal), which -according to the '74 datasheet- would set both Q and /Q outputs high.

The way I see it, SYNC output is only changed by [any IO write] and [any IO read with A0 = 0, as in: keyboard read]. IC18+19 just use /M1 to synchronize those events with Z80 cycle timing. Presumably to make sure that SYNC transitions occur at exact points in time -> regular spaced SYNC pulses so that TV's produce a stable image.

Perhaps confusing is that the ZX80 only has the software-generated sync (which must serve both as hsync and vsync). Whereas in the ZX81, hsyncs are hardware-generated (but for use as NMI, masked by the NMI enable/disable flipflop), and vsyncs are still software generated (but started & stopped on certain IO operations as with the ZX80). Also see ZX80 <-> ZX81 ROM differences.
2. Every (disturbing and regularly) horizontal Sync caused a "+1" for the scanline counter. That was my problem with the crunched lines.
The logic is simple though:

1. A vertical sync should reset the line counter. Whether that is "reset once when vsync goes active" or "keep resetting, and release when vsync goes inactive" makes no difference when there's just one, continuous vertical sync for each TV frame. At the end of vsync, line counter should read 0.
2. A horizontal sync (= next screen line) should increment the line counter +1. After 7, next count is 0 again - and so on. Whether those hsync's are used as Z80 NMI, whether NMI-enable flipflop is switched on or off in the mean time, should have no effect on this: each screen line should advance the counter +1, and counter should never be advanced more than +1 per screen line.

If 1) and 2) both apply, counter output will be what's needed. If not, the logic for clocking/resetting it is wrong.
So the scanline counter is reset after VSYNC pulse, the OUT ($FF),A does not trigger the counter as described above
Correct - The IO write releases VSYNC, and this in turn releases the line counter (still at 0) so that it can count up.
and the two other OUT instructions and the T-state-SYNC line will trigger the counter and set it's value to 3 when the picture display begins. Too bad. :?
Well there's your problem then. If that happens right after VSYNC ends, but before another screen line has passed, the line counter shouldn't be incremented. Not once, twice, and certainly not +3 (see above). :x
Lets look at the BASIC interpreter. This will execute line by line and after each line it checks wether BREAK key pressed or not with IN A,($FE). This will by the way start a "VSYNC pulse" of variable length (depending on the point of time in execution) in the NMI on phase.
Just a keyboard read should not generate a VSYNC pulse.

For reference, see the AND gate left of "start_vsync" in my ZX81 ULA schematic. NMI's should be disabled for a keyboard read to start a VSYNC pulse. That's either during VSYNC or active display period. Oh wait, BASIC interpreter isn't executing there! (so those BASIC interpreter's keyboard reads take place while NMI's are enabled, and thus do nothing to VSYNC) :idea:
Last but not least I have still a problem with a short black line appearing on chars 5 to 10 in the very first line of the screen, which is the T-State SYNC visible on screen.
Effect of RC delay you mentioned earlier? :?
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: Houston, we have an image!

Post by PokeMon »

Well you should carefully look at this picture and how the 3 flipflops 74LS74 and the additional flipflop build with two NAND gates work together.
Take a look and you will understand why I am right with my remarks.
As I am talking about a real ZX80 I can refer only to ZX80 schematics and not to your circuit design.
This may (and possibly will) differ from the ZX80 logic. :shock:

Image
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: Houston, we have an image!

Post by PokeMon »

RetroTechie wrote: Are you sure about that? /IORQ going low activates IC18's /preset input, which would change that flipflop's state if it was "0" before that (pin 6 in schematic above is inverted output btw). Read: if flipflop was internally "1" (pin 6 output = low), /IORQ going low would do nothing. Also note the possibility of both /preset and /clear inputs active (/clear input tied to outgoing SYNC signal), which -according to the '74 datasheet- would set both Q and /Q outputs high.

The way I see it, SYNC output is only changed by [any IO write] and [any IO read with A0 = 0, as in: keyboard read]. IC18+19 just use /M1 to synchronize those events with Z80 cycle timing. Presumably to make sure that SYNC transitions occur at exact points in time -> regular spaced SYNC pulses so that TV's produce a stable image.
I am 100% sure on it. (Nearly) Every /IORQ going low will produce a HSYNC, not just IN and OUT instructions, the same for the INT ACK cycle where /IORQ goes low together with /M1. What you missinterpret is, that /M1 to the flipflops does a kind of synchronisation. That's not really true, it does in fact but the more reason for triggering both (!) flipflops with /M1 is another. It is, that there is a delay from a preset of IC18 to the HSYNC of two /M1 cycles. As you read the code executed after INT ACK at $0038 there are two instructions DEC and JP which have instruction duration of 4 and 10 cycles.

So the first IC19a takes the preset state of IC18 with the beginning of the DEC instruction takes 4 cycles and the beginning of the JP will take the preset state with the second /M1 pulse to the SYNC output. In fact if you look at the timing diagram for INT ACK it takes 2 cycles more than a normal RST instruction in IM1, which is 13 cycles instead of 11 cycles (normal execution time). But IORQ goes low two clock cycles later than /M1. So you have 13+4-2=15 clock cycles delay to the beginnin of INT ACK which can be determined only when /M1 and /IORQ go low together, so two clock cycles after beginning of this INT ACK cycle. And this is the reason that the preset state of IC 18 is taken after the SECOND (!) instruction after the INT ACK. Take notice that /M1 is inverted and the flipflops 74LS74 are positive edge triggered. This is when /M1 goes down.

IC 18 will hold the preset state as long as the sync output is high, so as long as there is no sync pulse active. This is most of the time except during long VSYNC. If there is no sync pulse present, clear of IC18 is high. As it is "low active" it will accept preset (which produces delayed syncs) every time there is no sync present. So what happens if the sync goes active (low) ? Well nearly the same. Preset of IC 18 is no more active, clear take place but this state will be delayed to the output again two /M1 cycles. This is a JP instruction (10 cycles) and a POP instruction (10 cycles). This gives a 20 cycles long sync pulse for the ZX80 (about 6us). As the TV syncs with the beginning (!) of a sync pulse a litte bit different sync pulse length doesn't matter. This corresponds to Grant Searles measurements and remarks made here:
http://searle.hostei.com/grant/zx80/zx80nmi.html

The main purpose of two (!) flipflops one after each other was to stretch the pulse together with carefully used instructions (with special execution length). Simple synchronisation with /M1 could have been done with one flipflop only.


RetroTechie wrote: 1. A vertical sync should reset the line counter. Whether that is "reset once when vsync goes active" or "keep resetting, and release when vsync goes inactive" makes no difference when there's just one, continuous vertical sync for each TV frame. At the end of vsync, line counter should read 0.
2. A horizontal sync (= next screen line) should increment the line counter +1. After 7, next count is 0 again - and so on. Whether those hsync's are used as Z80 NMI, whether NMI-enable flipflop is switched on or off in the mean time, should have no effect on this: each screen line should advance the counter +1, and counter should never be advanced more than +1 per screen line.

If 1) and 2) both apply, counter output will be what's needed. If not, the logic for clocking/resetting it is wrong.
Well this sounds logic but is not what the hardware in a ZX80 does. Take a look again at the schematic above. Start of VSYNC is done with a IN A,($FE) - so when reading keyboard. This sets the flipflop created with IC 11 (2 NAND gates) and reset the counter. The flipflop remains set until any OUT instruction is done with /IORQ and /WR together. By the way a high at pin 11 IC11 will produce a low at pin 8 IC11 which starts the VSYNC immediately via clear input of the second IC 19. The reason why the end of VSYNC with a OUT ($FF),A will not produce a (disturbing) sync pulse is that a low on sync will clear flipflop IC18 and hold it clear so that the preset pulse with the OUT instruction doesn't count because it's not stable until next /M1 cycle.

But if the SYNC out is high after the VSYNC (and it remains high as the NMIs don't generate sync pulses), every /IORQ low will produce addition syncs AND (!!!) trigger the counter. There are two OUT instructions (NMI on and NMI off) and the T-State sync pulse and together they will count IC21 to 3 after reset during VSYNC. That is fact and true. I spent many hours to investigate and to understand the logic with oscilloscope and brain. So believe me. :mrgreen:

Well the logic is wrong for this scenario but don't forget we are talking here about ZX81 software in ZX80 hardware which has been developped earlier. So they couldn't know that the logic would be wrong with ZX81 software which doesn't exist at the ZX80 development. And take notice, that there is a difference between FAST and SLOW mode. During FAST mode the whole picture is generated by software and perfect. There the NMI lines are executed as (pseudo) video code as well and they will trigger the counter each line. There is no NMI on and no NMI off - so just 55 lines plus 1 T-State sync line = 56. So 7*8=56 and the counter is 0 at start of picture. That is the trick. AND (!!) take notice that the SLOW mode wasn't provided by Sinclair in the ZX80 hardware. So the logic is problematic but Sinclair never decided to provide a SLOW mode for ZX80. This was the idea of Grant Searle. And I think Sinclair know why they never did. ;)


RetroTechie wrote:
and the two other OUT instructions and the T-state-SYNC line will trigger the counter and set it's value to 3 when the picture display begins. Too bad. :?
Well there's your problem then. If that happens right after VSYNC ends, but before another screen line has passed, the line counter shouldn't be incremented. Not once, twice, and certainly not +3 (see above). :x
No, you are wrong as I explained earlier. It is 3 because the NMI do no trigger the counter, it is reset after VSYNC but the two OUT instructions and the T-State sync will trigger it to +3.


RetroTechie wrote:
Lets look at the BASIC interpreter. This will execute line by line and after each line it checks wether BREAK key pressed or not with IN A,($FE). This will by the way start a "VSYNC pulse" of variable length (depending on the point of time in execution) in the NMI on phase.
Just a keyboard read should not generate a VSYNC pulse.
No you are wrong, it does. Any IN A,($FE) with /IORQ low and /RD low and A0 low will set the flipflop with the two NAND gates from IC 11, produce a high (=reset) for the counter, reset the other part of the flipflop (IC 11 pin 8) and produce a low at clear input of second flipflop IC 19. And (more important) it will stay this way as long as there is no OUT instruction (/IORQ low and /WR low). If it will be really a VSYNC depends on the time the flip flop is set. In fact it can be up to 3 ms long in bad case (55*64us when keyboard read in the first margin line). On the scope you can see this on running a (BASIC) program very good and you can see the differing length and start point. It is ended any way with the T-State sync at the same time. Very nervous signal. :mrgreen:

And please refer to this description (there are more on the internet) to port $FE.
http://nocash.emubase.de/zxdocs.htm#zx80zx81ioports
Input from Port FEh (or any other port with A0 zero)
Reading from this port initiates the Vertical Retrace period (and accordingly, Cassette Output becomes Low), and resets the LINECNTR register to zero, LINECNTR remains stopped/zero until user terminates retrace - In the ZX81, all of the above happens only if NMIs are disabled.
Well NMI's can not be disabled in ZX80 hardware. In fact there don't have to be any NMI. :shock:


RetroTechie wrote:
Last but not least I have still a problem with a short black line appearing on chars 5 to 10 in the very first line of the screen, which is the T-State SYNC visible on screen.
Effect of RC delay you mentioned earlier? :?
Yes maybe but I am tired to investigate this in detail as I decided not to realize the NMI generator. ;)
User avatar
Ziggy
Posts: 11
Joined: Sat Jul 20, 2013 12:18 pm
Location: Cork, Ireland

Re: Houston, we have an image!

Post by Ziggy »

All this talk of Vsync/Hsync reminds me of a puzzle I've been thinking about recently.

On the original Sinclair Zx80 schematic the SYNC and /SYNC are the reverse of what is shown of Grant's redrawn schematic.
Pin 5 IC 19 is shown as SYNC or /SYNC and
Pin 6 IC19 is Shown a /SYNC or SYNC
depending on which schematic you examine.

Does this matter ?

Z.
UK101, ZX80 (3) , ZX81(5 ), ZXSpectrum (3 ) , Harlequin 1 :)
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: Houston, we have an image!

Post by PokeMon »

Can you post a resource to the original Sinclair ZX80 schematic ?
There is no convention of naming this signal.
It is low active, so it could be named /SYNC but I think SYNC is more common used as a function of this signal and not polarity.
User avatar
Ziggy
Posts: 11
Joined: Sat Jul 20, 2013 12:18 pm
Location: Cork, Ireland

Re: Houston, we have an image!

Post by Ziggy »

I've just reexamined Grant's schematic on line and it does agree with the original in respect of the SYNC and /SYNC.

I realise now that it was this one, commented by Martin - altered the references.

http://nocash.emubase.de/zx80-sch.gif

Sorry , if I've caused confusion :(

Original sinclair schematic here:

http://www.1000bit.it/SUPPORT/SCHEMA/zx80/zx80_cir.gif

Z.
UK101, ZX80 (3) , ZX81(5 ), ZXSpectrum (3 ) , Harlequin 1 :)
Post Reply