How the spectrum generates the video from ram

edited January 2011 in Hardware
Hi everyon,

I know that most people here allready know this but i think i found out how the spectrum acctually dispalys stuff and why the LD x, (HL) is used to display stuff.

I found this out accidentally while designing my own z80 computer (Which im still doing, its called inferno). So i had this problem where i needed to display stuff onto a TV using a PIC, the z80 sends the data onto IO and the PIC reads this, stores this and displays in the location. But this involved loading register a and b with the X and Y position of the characters and C with the character In ASCII format.

This is too complex, how else can i do this??
I though that i could assign the first K of ram to video memory and the rest to program data, but how can this be done on a single 64K chip because while the z80 is reading from that chip the PIC cant also read the lower addresses at the same time.....But wait!!!

The spectrum has its lower 16K separated from the higher order memory, THATS IT!!!. While the z80 is accessing the higher order ram (> 16K) the ULA (or PIC in my case) reads from the 16K memory and can display things in real time. The only time the display can not be read is when writing to the video memory, beautiful :) So using the instruction LD x, (HL), you look at address HL (which would be pointing to 16K) and you write your data hence writing stuff to display. No need for complex IO operations!!!

So my computer has two 64K chips, the first chip only needs 1K of video memory and the second chip stores the program/data. Thing is the lower chip only needs to be a tiny thing :P

Done, now i can move on to the perminant data storage + paper tape reading.
Post edited by Robin on

Comments

  • edited January 2011
    I'm a n00b when it comes to designing computers, so I'm sorry if this sounds totally stupid, but I wonder.......

    You say that your lower 64K RAM chip uses only 1K for video.
    Is there a fixed setting for screen resolution in your system, or can more of the RAM in this chip be called upon to display images with larger resolution ?
  • edited January 2011
    sorry, its fixed :(

    I need to think about how to change the resolution :P But it is based on a PIC library for generating composite video
  • edited January 2011
    I think the ULA reads the video ram in a real spectrum by stopping the clock signal to the z80. While the z80 is stopped it reads it, when finished it starts the clock signal again. I think it does this for each video line. This is the source of the contention delays when reading or writing to the lower 16k of ram in a real spectrum.

    Basically the ULA is the master of the lower ram and even takes care of keeping it refreshed.

    See Chris Smiths site: www.zxdesign.info.
    He goes into exhaustive detail about this stuff.
  • edited January 2011
    The cpu and ula cannot access the display ram at the same time -- the display has to take precedence because display devices are time sensitive. The ula has to pause the cpu if there is a conflict and this is called contention. By having a physically separate chip for the 16k containing the display, the z80 can happily access the other 32k without any worries of contention. That's why the top 32k of ram is called uncontended -- the z80 will always run at maximum speed there.

    There are a couple other remedies for this. One is to use dual-port RAM. These are ram chips that can accommodate two simultaneous accesses. They cost correspondingly more $. Another is to use ram that is twice as fast and have the ula or display device access the ram half the time and the z80 access it the other half. Another is to create a shadow copy of the display file area in the display device's own ram. Every time the z80 writes to iots display area, the display device makes a copy of that write to its own ram. This way it always has an exact copy from which it can generate the display. You will still have to buffer a write if the disp device needs to read at the same time as a copy is to occur but this can be done simply and without stopping the z80.

    Another thing you may be confused about is it sounds like the pic is implementing a character mapped display in its own ram. You write x,y coords to some registers followed by an ascii code and the pic updates its own internal representation of the display from which it generates a composite picture. The spectrum is not a character-mapped display, it is a bitmapped one which identifies which pixels are individually set and reset.
  • edited January 2011
    Thats right (perfect i think). i dont want a bitmap system JUST yet, character mapped first. This way more ram gets dedicated to program memory and OS. Ideally i want to make a graphics card which gathers data on IO, this means that there is no need to assign the lower chunk of main memory as video ram.

    But that would make displaying characters alot more complicated:
    Write X to IO address 1
    Write Y to IO address 2
    Write ASCII to address 3

    maybe built in functions into rom that you can just call might be easier...
    So instead of the user to write his own function, he can just call the rom and pass some variables.
  • edited January 2011
    wozname wrote: »
    I think the ULA reads the video ram in a real spectrum by stopping the clock signal to the z80. While the z80 is stopped it reads it, when finished it starts the clock signal again. I think it does this for each video line.
    AFAIK the ULA only makes the Z80 wait (indeed by f**king with its clock signal) when there's a conflict; when the Z80 wants to read/write some other area than the lower 16K, there is no conflict and hence no reason for the ULA to 'steal cycles' from the Z80.
    Basically the ULA is the master of the lower ram and even takes care of keeping it refreshed.
    The ULA doesn't need to do anything *special* to maintain DRAM refresh: for DRAMs to maintain their contents, all rows of memory must be accessed with a certain time (usually some milliseconds). Since displaying the screen involves 'walking' all DRAM rows, this already happens & nothing more is needed.

    And indeed Chris Smith's site is a wonderful reference for all things Spectrum ULA. Tip: you might also want to check out Wilf Rigter's "ZX81 video tutorial". It has a lot of details about composite video timing (and generating black & white composite video is easier than color).
  • edited January 2011
    Of course!, just reading the ram would do it. :)
Sign In or Register to comment.