29

The Sinclair computers are known for their low cost compared with other computers that were popular in the early 1980s. This is why they had membrane keyboards, or that rubber stuff in the case of the ZX Spectrum, and did not include a CRT as did the Apple II.

As the 6502 was a good deal cheaper than the Z80, and comparably powerful. And though I don't know a great deal about hardware design, it seems that because the 6502 only uses the memory on every other cycle, the development team could have spend less effort contending part of the address space to get the display subsystem to work.

Omar and Lorraine
  • 38,883
  • 14
  • 134
  • 274
  • 1
    You're conflating a number of contributory factors in the Sinclair Research design decision process - the choice of the Z80 for their product line did not have a rationale as simple as cost, though that of course would have been a consideration. – Eight-Bit Guru Nov 20 '16 at 19:51
  • 3
    I always thought the Z80 was substantially more powerful than the 6502. – JDługosz Nov 21 '16 at 05:34
  • 4
    @JDługosz: There are situations where either can run circles around the other; there are even some where the CDP1802 can actually come out looking almost decent (it's awfully slow, but it has sixteen 16-bit registers). The 6502 excels at accessing tables which are 256 bytes or less since its indexed addressing modes include "free" address arithmetic. I've written wave-table synthesis code for the 6502 which takes 46 cycles of every 76-cycle scan line, and uses 20 different pointers for audio in each group of four scan lines (plus more for video). – supercat Nov 21 '16 at 06:45
  • The 6502 was a good deal cheaper than the Z80 when they were introduced, i.e. in '75 and '76 respectively. I'm far from convinced that there was still a significant difference between the cost of the two by the time the ZX80 was released in 1980. I haven't found pricing information for 1980 from anywhere, but I can tell that by 1981, Z80 CPUs were available at retail for $7 each, and Z80A's for $10, while a 6502 was $7.50 (see advert on page 77). – Jules Jul 31 '17 at 21:18
  • If I recall correctly the authors of the chess program Sargon said the 6502 was very well suited for this particular kind of software. – Thorbjørn Ravn Andersen Feb 05 '19 at 00:57
  • @supercat: The 1802 may have 16 registers but they tend to disappear pretty quickly when you take into account the fact one is the PC, one the SP, and others get used for SCRT, the rather strange way of doing arbitrary function calling :-) For example, I think (from memory) the COMX-35 lost R2/3 for the SP/PC, R4/5/6 to SCRT, and R1 to DMA. – paxdiablo Mar 05 '22 at 22:32
  • @paxdiablo: If one is e.g. generating video by using a shift register hooked up to the 1802, and is e.g. using 32K of address space, with the MSB of the address used to indicate whether the shift register should get loaded, it's possible to display ten columns of character-based video by using ten of the registers to hold the contents of the ten columns. The normal RCA "video chip" requires using 256 bytes of RAM if one wants a 64x32 bitmap, but the approach I described would only need one byte of RAM for each character to be displayed. – supercat Mar 05 '22 at 23:44
  • @supercat, so that scheme takes away ten more registers? Surely that would make it on par with a 6502, if you also took away X and Y :-) I should probably have mentioned that you don't have to use SCRT. If your code is simple enough (with r3 being the normal PC, just a few subroutines and one-level-deep calls), you can dedicate a register to each and just use something like sep r8 to call, sep r3 to return. You don't even need a stack in that case. – paxdiablo Mar 06 '22 at 01:26
  • @supercat: Though that does look like a neat hack, on par with the ZX80 video generation, or Woz's RWTS routines. – paxdiablo Mar 06 '22 at 01:27
  • 1
    @paxdiablo: The routine would save the contents of the registers in response to an interrupt that triggers a few scan lines above where video output would start, and would restore them afterwards, so even though the video routine would use almost all of the registers, nothing else in the system would need to care about that. As with video using the normal chip (CDP1861 I think), the display interrupt handler would keep control until the beam passed the bottom of the displayable region, so nothing else in the system would be able to see what it was doing with registers. – supercat Mar 06 '22 at 19:39

2 Answers2

47

Sinclair didn't always use the Z80 for its computers. The MK14 computer, sold in kit form (like the ZX80 was), used a National Semiconductor INS8060.

The ZX range of home computers have a video display hardware that is very closely tied to the architecture of the Z80.

On the two first models, ZX80 and ZX81, the video display hardware was kept to a minimum, yet allowing a decent resolution of 256x192 pixels and the ability to move the screen memory back and forward in the memory space, although it was not pixel addressable.

To accomplish this, the Z80 played an important role as RAM address generator for the video hardware (resembling in some way what the Motorola 6845 CRTC chip does for other microcomputers).

When it is time to read a TV scanline from memory, the Z80 is directed to "execute" (i.e. fetch instructions) from the memory address where video data is stored. The Z80 does not actually execute the instruction read. Instead, the video hardware peeks the data bus and retrieves whatever data the memory put there for the Z80. Just after that, and before the second clock cycle of the fetch bus cycle is ended, the data bus is forced to 00000000 so the Z80 ends up reading a NOP instruction, which does nothing and goes for the next instruction at the next address.

This way, the video hardware doesn't have to implement an address counter, logic to access memory and logic to perform bus contention, as it is the Z80 which is actually taking part in the video generation process.

The ZX81 is just a ZX80 with all the video hardware encapsulated in a ULA chip, plus some other features such as the "slow circuit", which was an improvement over the ZX80 video circuit, designed to avoid flickering while the user was inputting data.

The ZX Spectrum only shares some visual resemblance with the ZX81 video output, but it is actually a totally different beast. It could have been designed around a different CPU, but Sinclair had already a BASIC interpreter written for the Z80, and so the Spectrum ROM inherited much code from its ancestors, including some routines that shouldn't be in the Spectrum ROM because they made sense only in a ZX81.

Summarizing: the ZX80 and ZX81 relied on the Z80 way of performing a memory bus cycle to use it as a DMA engine. The Spectrum used a Z80 because it shared a lot of ROM code with previous models.

Chenmunka
  • 8,141
  • 3
  • 39
  • 65
mcleod_ideafix
  • 18,784
  • 2
  • 70
  • 102
  • +1. I'd like to add all this isn't possible with the 6502, as it has a one-stage pipeline and automatically reads the next byte from memory during the execution stage of the current command. – Janka Nov 21 '16 at 03:23
  • 1
    @Janka: Jamming a NOP on the 6052 bus would cause it to advance one address every two cycles, but choosing a different opcode would make it advance every cycle. If one has 64 cycles per scan line of which 40 should display something and arranges for the Z flag to be set, one could stuff F0 at even addresses and anything at odd addresses during the displayed part of the frame, and D0+FE during the non-displayed part. If the branch ends up crossing a page boundary, it would run 8 times in the 24 non-display cycles; otherwise it will run 12 times. Either way the timing works out nicely. – supercat Nov 21 '16 at 06:57
  • 2
    I've read that it also takes advantage of the Z80's Row Address Strobe feature to help make refreshing dynamic RAM easier. The ZX80 of course didn't have dynamic RAM, so this allowed this feature to be harnessed for other purposes. In this case, the CPU puts a different address (defined by the IX register combined with the R register) onto the address bus, which a multiplexing circuit combines with the data just read from display RAM to produce the address at which to look up the character in question. This register is also used for determining when the end of the scanline has been reached. – Muzer Nov 21 '16 at 11:28
  • 1
    (The ZX80/ZX81 to save RAM store the display buffer in terms of characters rather than pixels, and don't even store entire lines if the whole line is not being used, thus there needs to be some timing to figure out when the CPU should start reading in the next line. The refresh register provides this). The source of this info: http://searle.hostei.com/grant/zx80/zx80ScopePics.html – Muzer Nov 21 '16 at 11:29
  • @Muzer: Code may use the refresh-count register to trigger an interrupt to exit the loop, but some other approaches could work as well, e.g. output "INC L" instructions until the end-of-line is detected, and then an RST 38h. The RST38 could then do a EX (SP),HL and a RET to transfer control to a routine which waits out a suitable number of characters before hsync. – supercat Nov 21 '16 at 22:15
  • But the CPU gives you a "free" RAM access during instruction decoding. I was under the impression that the whole point of this palaver was to avoid having to have their own DMA hardware that does its own RAM access. – Muzer Nov 22 '16 at 08:57
  • 1
    I believe they also used a Z80 due to it´s low cost by the time the Speccy was released in the market. – Rui F Ribeiro Dec 04 '16 at 21:59
  • The Sinclair QL used a 68008, the MK14 a National CPU, so the Z80 wasn't exactly "Sinclair's CPU of choice". – tofro Feb 08 '17 at 08:16
  • 1
    In ZX Spectrum, the ability of Z80 to refresh dynamic RAM is also used to the full. Z80 provides refresh for the upper 32k of DRAM (absent in 16k version) and for the video DRAM during retrace times (though I might be wrong with video DRAM). – lvd Apr 07 '17 at 09:26
  • @Muzer - it's entirely possible to arrange for the 6502 to have "spare" bus cycles too. If you feed it instructions that take two cycles to execute, then during the first cycle of execution it entirely ignores the memory read. Unlike the Z80 it doesn't have tristate connections to its bus, so you'll need to forcibly disconnect it from the address bus in order to look up your character bitmap in the second cycle, but that's not exactly hard to achieve. – Jules Jul 31 '17 at 20:33
  • The MK14 was made by Chris Curry (Science of Cambridge). Curry was more interested in persueing opportunities in the micro market than Sinclair himself and frustration with Sinclairs lack of support prompted Curry to leave and form Acorn (where they used the 6502). Later when Sinclair realised the potential he tasked Jim Westwood to design the ZX80. – Tim Ring Aug 23 '17 at 10:08
  • @Jules: Alternatively, if one is using fast enough memory, one could have a range of address space that enables RAM for the first half of a cycle and ROM for the second half, and have a shift register grab the data that was fetched from RAM. A ROM routine run at this part of the address space could then generate the screen display with a minimum of circuitry; adding some gates to mask out some of the address bits feeding the ROM could minimize the amount of actual ROM storage this would actually take. – supercat Mar 31 '18 at 23:50
  • 1
    Years back having looked at both 6502 and Z80 assembly I found the latter much easier to learn. I realise this probably has little bearing on the original question but the sole reason for my comment is the slight "learning curve" effect perhaps. Sinclair = easy to learn and use. I'm not suggesting that it would be the same for everyone though. btw the nearest in erm "hardware" design (similar features, well kind of) with a 6502 processor would likely be the Oric Atmos I suspect. – AndyF Jan 08 '20 at 13:21
0

I thought they chose the Z80 as a differentiator from the plethora of systems available at the time and, of course, cost. I'm sure this is mentioned in the TV programme Micromen? (A good watch if you've not seen it).

  • 4
    This doesn't sound convincing as there were several other Z80-based systems around at the time - although somewhat more expensive. It would be great if you could expand on this a bit. – Chenmunka Nov 21 '16 at 16:14
  • They mention in Micro Men that it uses a Z80A, after earlier saying that they'll go with the 6502 because it's the only real choice for their price bracket, but no more than that. – Muzer Nov 21 '16 at 16:25
  • 4
    (Micro Men was a great programme but it's hardly useful for technical details like this) – Muzer Nov 21 '16 at 16:42
  • @Muzer - Actually it is the proto-Acorn team who state that they will use the 6502 (for those reasons), see MIcromen@20:53, not Sinclair. The Sinclair team imply (without saying why) that a Z80 will be used - by the use of the name ZX80 @22:58 and confirmed @24:55 with the ZX80's board inspection by the Acorn team. Although as you say, it is merely a dramatical representation and should be taken with a pinch of salt. – Greenonline Jun 19 '18 at 15:02
  • @Greenonline apologies, yes, I did know that but I phrased it very ambiguously! Here "They" meant the Acorn Team and "it" meant the ZX80 (of which the Acorn team were doing a tear-down in that scene) – Muzer Jun 23 '18 at 02:24