| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
| 2 |
|
| 3 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| 4 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 5 |
|
| 6 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
| 7 |
<head> |
| 8 |
<link title="Purple" rel="stylesheet" href="manual-purple.css" type="text/css" /> |
| 9 |
<title>V9938 VRAM timings, part II</title> |
| 10 |
</head> |
| 11 |
|
| 12 |
<body> |
| 13 |
|
| 14 |
<h1>V9938 VRAM timings, part II</h1> |
| 15 |
|
| 16 |
Measurements done by: Joost Yervante Damad, Alex Wulms, Wouter Vermaelen<br/> |
| 17 |
Analysis done by: Wouter Vermaelen<br/> |
| 18 |
Text written by: Wouter Vermaelen<br/> |
| 19 |
with help from the rest of the openMSX team. |
| 20 |
|
| 21 |
<h2>Follow-up</h2> |
| 22 |
|
| 23 |
<h5>V9938</h5> |
| 24 |
|
| 25 |
<p>This text is a follow-up on the earlier <a href="vdp-timing.html">V9938 VRAM |
| 26 |
timings</a> document. If you haven't done so already it's probably a very good |
| 27 |
idea to (re-)read that document first, because this text assumes you remember |
| 28 |
all the earlier details ;-)</p> |
| 29 |
|
| 30 |
<p>Early 2013 the openMSX team made some logic-analyzer-measurements of the |
| 31 |
actual communication between a V9938 and the connected VRAM. The goal of those |
| 32 |
measurements was to improve the emulation of the VDP command engine in openMSX. |
| 33 |
That goal was fully achieved: to the best of our knowledge the timing of the |
| 34 |
VDP command engine is now fully accurate: e.g. recent versions of openMSX now |
| 35 |
generate identical pictures as real MSX machines for the LINE-speed test |
| 36 |
picture shown in the <a href="vdp-timing.html#motivation">motivation</a> |
| 37 |
section of the previous document.</p> |
| 38 |
|
| 39 |
<p>A nice side effect of these measurements was that, next to the command |
| 40 |
engine speed, we also obtained information about what happens when the CPU |
| 41 |
(Z80) reads or writes the VRAM too fast, and what exactly is "too fast". This |
| 42 |
behaviour is now also implemented in openMSX, though only (yet) for the V9938 |
| 43 |
bitmap screen modes (the information in this text should allow us to also |
| 44 |
implement the timing for the other screen modes).</p> |
| 45 |
|
| 46 |
<p>Because the focus was the command engine and because a V9938 can only |
| 47 |
execute commands in bitmap screen modes (screen 5-8), our measurements were |
| 48 |
mostly focused on those screen modes. And especially the analysis of the |
| 49 |
results was initially focused on the bitmap screen modes. In this text we will |
| 50 |
now look at the other screen modes, even though there is less measurement data |
| 51 |
available for those modes.</p> |
| 52 |
|
| 53 |
<h5>TMS9918</h5> |
| 54 |
|
| 55 |
<p>The second half of this text looks at the TMS9918 VDP. We only made |
| 56 |
measurements on a V9938 and as we'll see below the results cannot be |
| 57 |
extrapolated to TMS9918. Luckily there are other sources of information |
| 58 |
available that allow to piece together similar (though less detailed) timing |
| 59 |
diagrams for the TMS9918 as for the V9938.</p> |
| 60 |
|
| 61 |
<h5>results</h5> |
| 62 |
<p>Similar like in the previous document, we'll start by presenting all the |
| 63 |
results in one big diagram. I strongly recommend to open this image in an image |
| 64 |
viewer that easily allows to scroll and zoom-in and -out (so maybe not a |
| 65 |
web-browser). It may also be useful to have this image open while reading the |
| 66 |
later sections in this text.</p> |
| 67 |
|
| 68 |
<img src="vdp-timing-v2.png" width="1200"/> |
| 69 |
|
| 70 |
<p>At the top of this diagram the results of the previous article are repeated, |
| 71 |
these are the V9938 bitmap modes. In the middle are the V9938 character- and |
| 72 |
text-modes. And at the bottom you see the TMS9918 results. They're all included |
| 73 |
in one big diagram to allow to more easily compare them.</p> |
| 74 |
|
| 75 |
<p>Horizontally you see the detailed timing of one display line. On V9938 one |
| 76 |
line takes 1368 cycles, on TMS9918 it takes 342 cycles. The line is divided in |
| 77 |
different phases (indicated by the different background colors) corresponding |
| 78 |
to the left- and right-border, display cycle, etc. Notice that the text modes |
| 79 |
have different border widths than the other modes. Also notice that the lengths |
| 80 |
of these periods are not exactly the same between the two VDP types.</p> |
| 81 |
|
| 82 |
<p>Because these horizontal phases don't fully correspond between the two VDP |
| 83 |
types, I had to make a choice in how to align the results of both VDPs. I |
| 84 |
choose to align the display cycle (the period where the actual pixels are |
| 85 |
shown). Though this means that 'cycle 0' is not located in exactly the same |
| 86 |
horizontal position for both VDPs. But this doesn't matter: as explained in the |
| 87 |
previous article, 'cycle 0' is anyway an arbitrary choice. Just keep it in mind |
| 88 |
when comparing the results.</p> |
| 89 |
|
| 90 |
<p>For the V9938 the diagram shows the RAS and CAS0/1 signals, for TMS9918 that |
| 91 |
information is missing. But that's OK: on V9938 there are burst and non-burst |
| 92 |
accesses, there are idle cycles, dummy accesses, etc. So the RAS/CAS signals do |
| 93 |
provide extra information. As we'll see in the 2nd half of this text, on |
| 94 |
TMS9918 the communication with the VRAM is much simpler, so the RAS/CAS signals |
| 95 |
anyway don't contribute as much extra information.</p> |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
<h2>V9938 (MSX2 VDP)</h2> |
| 100 |
|
| 101 |
<h3>Character modes</h3> |
| 102 |
|
| 103 |
<p>In this section we'll look at the 3 character-based display modes: Graphics |
| 104 |
Mode 1, Graphics Mode 2 and Multi-color Mode (aka screen 1, 2 and 3). As we'll |
| 105 |
see, from a VRAM access point of view, these 3 modes are closely related.</p> |
| 106 |
|
| 107 |
<h4>Graphics mode 2 (aka screen 2)</h4> |
| 108 |
|
| 109 |
<h5>refresh</h5> |
| 110 |
<p>The VRAM needs to be regularly refreshed. The V9938 does this by regular |
| 111 |
reads (from all banks of the DRAM chips). Those reads are located at the |
| 112 |
following moments in time (VDP cycle counts within one display line). Remember |
| 113 |
that one display line has 1368 VDP cycles and that cycle 0 is semi-arbitrarily |
| 114 |
chosen within the line (so only relative numbers matter).</p> |
| 115 |
<table> |
| 116 |
<tr><td>284</td><td>412</td><td>540</td><td>668</td> |
| 117 |
<td>796</td><td>924</td><td>1052</td><td>1180</td></tr> |
| 118 |
</table> |
| 119 |
<p>Note that these are the exact same locations as for the bitmap screen |
| 120 |
modes.</p> |
| 121 |
|
| 122 |
<h5>character rendering</h5> |
| 123 |
<p>To be able to render each character we need to:</p> |
| 124 |
<ul> |
| 125 |
<li>Read 1 byte from the name-table → |
| 126 |
Which character should be displayed?</li> |
| 127 |
<li>Read 1 byte from the pattern-table → |
| 128 |
How does (this line of) that character look?</li> |
| 129 |
<li>Read 1 byte from the color-table → |
| 130 |
What are the colors of (this line of) that character?</li> |
| 131 |
</ul> |
| 132 |
<p>There are 32 characters on a line, so these 3 reads also repeat 32 times. |
| 133 |
The name-, pattern- and color-table reads are located at these respective |
| 134 |
moments in time:</p> |
| 135 |
<table> |
| 136 |
<tr><td>214 + 32n + 0</td><td>214 + 32n + 18</td><td>214 + 32n + 24</td><td>with 0 ≤ n < 32</td></tr> |
| 137 |
</table> |
| 138 |
<p>Notice there's some room between the name-table read and the |
| 139 |
pattern-/color-table reads. <i>The address required to read from the latter two |
| 140 |
tables depends on the result obtained from the first read. So possibly there's |
| 141 |
extra room at this location to give the VDP more time to calculate those |
| 142 |
addresses.</i> In fact there fit exactly 2×6 cycles between the name- and |
| 143 |
pattern-table read. This leaves room for 2 other VRAM accesses:</p> |
| 144 |
<ul> |
| 145 |
<li>The first of those is used for refresh (once every 4 characters) or as a |
| 146 |
potential CPU/cmd access slot.</li> |
| 147 |
<li>The second access is used to read 32 sprite y-coordinates. These are |
| 148 |
required to figure out which of the 32 possible sprites are visible on |
| 149 |
the next display line.</li> |
| 150 |
</ul> |
| 151 |
|
| 152 |
|
| 153 |
<h5>sprite rendering</h5> |
| 154 |
<p>Above we saw there are 32 reads to figure out which sprites are visible. In |
| 155 |
this section we'll see what additional VRAM reads are performed to actually |
| 156 |
render the visible sprites.</p> |
| 157 |
|
| 158 |
<p>In sprite mode 1 there are maximally 4 sprites visible on a line. For each |
| 159 |
of those we need to read the sprite attributes (this is the x- and |
| 160 |
y-coordinate, the sprite pattern number and the sprite color). And we also need |
| 161 |
to read 1 or 2 bytes from the sprite-pattern-table (for 8×8 or |
| 162 |
16×16 sprites). Similar to sprite mode 2, the y-coordinate is re-read |
| 163 |
(the sprite-visibility pass already read it). The VDP always reads 2 sprite |
| 164 |
pattern bytes (for 8×8 sprites that 2nd byte is ignored). And even if |
| 165 |
fewer than 4 sprites are actually visible, the VDP always performs VRAM reads |
| 166 |
for all 4 sprites (and ignores the results of the redundant reads).</p> |
| 167 |
<ul> |
| 168 |
<li>The 4 sprite attributes are read (using a burst read) at times: |
| 169 |
<table> |
| 170 |
<tr><td>x+0</td><td>x+4</td><td>x+8</td><td>x+12</td><td>with x = 1242, 1306, 6, 70</td></tr> |
| 171 |
</table> |
| 172 |
</li> |
| 173 |
<li>The 2 sprite pattern bytes are read (also using a burst read) at times: |
| 174 |
<table> |
| 175 |
<tr><td>x+0</td><td>x+4</td><td>with x = 1274, 1342, 38, 102</td></tr> |
| 176 |
</table> |
| 177 |
</li> |
| 178 |
</ul> |
| 179 |
<p>Next there are a bunch of dummy reads:</p> |
| 180 |
<ul> |
| 181 |
<li>The burst that reads the 4 attribute bytes is extended with 2 dummy reads |
| 182 |
(often but not always these seem to read the x,y-coordinates of the 31st |
| 183 |
sprite).</li> |
| 184 |
<li>For every (burst) read from the sprite-pattern-table, 16 cycles later, |
| 185 |
there's a second dummy (burst) read of 2 bytes from the sprite pattern |
| 186 |
table.</li> |
| 187 |
<li>Right after every read from the sprite-pattern-table (4×2 times), |
| 188 |
there's a 1 byte read from closely before the start of the |
| 189 |
sprite-attribute-table (where in sprite mode 2 the sprite-color-table is |
| 190 |
located).</li> |
| 191 |
</ul> |
| 192 |
<p>(As you may have guessed already) all these dummy reads can be explained by |
| 193 |
looking at how the V9938 implements sprite mode 2:</p> |
| 194 |
<ul> |
| 195 |
<li>Per group of 2 sprites (4 groups), sprite mode 2 reads 6 bytes from the |
| 196 |
sprite attribute table (using a single(*) burst read). Sprite mode 1 reads |
| 197 |
4×(4+2) bytes (in a single burst). In both cases that's 24 bytes |
| 198 |
total.</li> |
| 199 |
<li>In total, sprite mode 2 reads 8×2 bytes from the |
| 200 |
sprite-pattern-table. Sprite mode 1 reads (4+4)×2 bytes.</li> |
| 201 |
<li>In total, sprite mode 2 reads 8 bytes from the sprite-color-table. Sprite |
| 202 |
mode 1 does 8 dummy reads.</li> |
| 203 |
</ul> |
| 204 |
<p>(*)<i>Actually, this is not true. But I believe this is how it was |
| 205 |
intended: the 6 bytes are located in the same DRAM bank. In reality the |
| 206 |
V9938 performs 2 burst reads of 3 bytes each. But because there are only |
| 207 |
28 cycles available it has to use a, strictly speaking, invalid DRAM |
| 208 |
timing. See previous article for more details.</i></p> |
| 209 |
|
| 210 |
<p>So the timing of all sprite mode 2 reads is (almost) identical to all the |
| 211 |
sprite mode 1 normal + dummy reads, only slightly shifted in time.</p> |
| 212 |
|
| 213 |
<p><i>I guess all these dummy reads in sprite mode 1 are the result of |
| 214 |
chip-area optimizations done by Yamaha engineers. In the current design the |
| 215 |
same state machine can generate the CAS/RAS signals for both sprite modes. And |
| 216 |
similarly a large part of the address generation logic for sprite mode 1 and 2 |
| 217 |
can be shared.</i> But unfortunately it does mean the VRAM bandwidth used for |
| 218 |
those dummy reads is not available for CPU VRAM access or (on V9958) for |
| 219 |
command execution.</p> |
| 220 |
|
| 221 |
<h5>dummy reads</h5> |
| 222 |
<p>Next to all the dummy reads related to sprite rendering, there are also |
| 223 |
dummy reads at these moments in time:</p> |
| 224 |
<table> |
| 225 |
<tr><td>182</td><td>200</td><td>206</td><td>1218</td></tr> |
| 226 |
</table> |
| 227 |
<p>These are the locations where you would expect respectively reads from the |
| 228 |
name-, pattern-, color-, and sprite-attribute-table if you'd extend a display |
| 229 |
line to 33 instead of 32 characters. This is similar to how in the bitmap |
| 230 |
screen modes there is a dummy preamble for the bitmap data and a dummy |
| 231 |
postamble for the sprite y-coordinate. All 4 dummy reads read address |
| 232 |
0x1ffff.</p> |
| 233 |
|
| 234 |
<h5>CPU/command-engine access slots</h5> |
| 235 |
<p>These are the available CPU/cmd access slots:</p> |
| 236 |
<table> |
| 237 |
<tr><td>32</td><td>96</td><td>166</td><td>174</td><td>188</td> |
| 238 |
<td>220</td><td>252</td><td>316</td><td>348</td><td>380</td></tr> |
| 239 |
<tr><td>444</td><td>476</td><td>508</td><td>572</td><td>604</td> |
| 240 |
<td>636</td><td>700</td><td>732</td><td>764</td><td>828</td></tr> |
| 241 |
<tr><td>860</td><td>892</td><td>956</td><td>988</td><td>1020</td> |
| 242 |
<td>1084</td><td>1116</td><td>1148</td><td>1212</td><td>1268</td></tr> |
| 243 |
<tr><td>1334</td></tr> |
| 244 |
</tr> |
| 245 |
</table> |
| 246 |
<p>This is very similar to the CPU/cmd slots in bitmap mode with sprites |
| 247 |
enabled. In both cases there are 31 available slots and the largest distance |
| 248 |
between (the start of) two slots is 70 VDP cycles. Only some of the slots |
| 249 |
are slightly shifted when comparing both modes.</p> |
| 250 |
|
| 251 |
|
| 252 |
<h4>Graphics mode 1 (aka screen 1)</h4> |
| 253 |
|
| 254 |
<p>From a VRAM access point of view this mode is quasi identical to Graphics |
| 255 |
mode 2. It does exactly the same number of VRAM reads as Graphics mode 2 at |
| 256 |
exactly the same moments in time. Only the addresses in the color-table are a |
| 257 |
bit different. So it does re-read the same color information for all 8 lines |
| 258 |
in a character.</p> |
| 259 |
|
| 260 |
|
| 261 |
<h4>Multi-color mode (aka screen 3)</h4> |
| 262 |
|
| 263 |
<p>Maybe surprisingly, from a VRAM access point of view, also this mode is |
| 264 |
quasi identical to Graphics mode 2. This mode doesn't have a color-table. But |
| 265 |
the V9938 still uses the same VRAM access schema as it uses for Graphics mode |
| 266 |
2. The reads from the color-table are replaced with dummy reads from address |
| 267 |
0x1ffff, but all the rest is identical.</p> |
| 268 |
|
| 269 |
<p>So unfortunately the VRAM bandwidth used to access the color-table does not |
| 270 |
become available for CPU-VRAM access (or the command engine on V9958).</p> |
| 271 |
|
| 272 |
|
| 273 |
<h3>Text modes</h3> |
| 274 |
<p>Now we'll look at the two text modes. We'll again see that, from a VRAM |
| 275 |
access point of view, both modes are very similar.</p> |
| 276 |
|
| 277 |
<h4>Text mode 2 (aka screen 0, width 80)</h4> |
| 278 |
|
| 279 |
<h5>refresh</h5> |
| 280 |
<p>In all V9938 bitmap and character modes the refresh was handled identically. |
| 281 |
For text modes it's different. Now there are only 7 (instead of 8) refresh |
| 282 |
reads per display line and they are clustered together near the start of the |
| 283 |
line, located at these moments in time:</p> |
| 284 |
<table> |
| 285 |
<tr><td>74</td><td>82</td><td>90</td><td>98</td> |
| 286 |
<td>106</td><td>114</td><td>122</td></tr> |
| 287 |
</table> |
| 288 |
<p><i>So apparently 7 refreshes per line are enough to keep the DRAM content |
| 289 |
intact. Too bad the other screen modes use 8. Also using only 7 could have made |
| 290 |
command execution slightly faster.</i></p> |
| 291 |
|
| 292 |
<h5>dummy reads</h5> |
| 293 |
<p>There are 2 dummy reads from address 0x1ffff located at:</p> |
| 294 |
<table> |
| 295 |
<tr><td>230</td><td>238</td></tr> |
| 296 |
<table> |
| 297 |
|
| 298 |
<h5>text rendering</h5> |
| 299 |
<p>The text rendering itself is pretty straight-forward. We need to read 80 |
| 300 |
bytes from the name-table and also 80 bytes from the pattern-table (the |
| 301 |
pattern-addresses depend on the values read from the name-table). For the blink |
| 302 |
color feature we also need 80 bits (10 bytes) from the color-table.</p> |
| 303 |
|
| 304 |
<p>Rendering is performed in 20 groups of 4 characters. Each group starts |
| 305 |
reading 4 bytes from the name-table using a burst read, these reads are |
| 306 |
located at:</p> |
| 307 |
<table> |
| 308 |
<tr><td>g+0</td><td>g+4</td><td>g+8</td><td>g+12</td></tr> |
| 309 |
</table> |
| 310 |
<p>with g one of:</p> |
| 311 |
<table> |
| 312 |
<tr><td>246</td><td>294</td><td>342</td><td>390</td><td>438</td> |
| 313 |
<td>486</td><td>534</td><td>582</td><td>630</td><td>678</td></tr> |
| 314 |
<tr><td>726</td><td>774</td><td>822</td><td>870</td><td>918</td> |
| 315 |
<td>966</td><td>1014</td><td>1062</td><td>1110</td><td>1158</td></tr> |
| 316 |
</table> |
| 317 |
<p>Next we read 1 byte from the color-table (at cycle g+18). This gives 8 bits, |
| 318 |
so we only need to do this for every other group (in the other group this |
| 319 |
access is used as a CPU/cmd access slot). Last we read 4 bytes from the pattern |
| 320 |
table. These must be non-burst reads because potentially bits 15-8 of the |
| 321 |
pattern-address for each character are different. These reads start at:</p> |
| 322 |
<table> |
| 323 |
<tr><td>g+24</td><td>g+30</td><td>g+36</td><td>g+42</td></tr> |
| 324 |
</table> |
| 325 |
<p>Note that combined all reads in 1 group take 48 cycles, and that's also the |
| 326 |
distance between 2 groups (in character mode there where a few spare cycles in |
| 327 |
a group). So it is really required to process the characters in groups of 4, |
| 328 |
otherwise burst reads aren't possible and all the required VRAM accesses don't |
| 329 |
fit in the available cycle budget (1 narrow pixel is 2 VDP cycles, thus 4 |
| 330 |
characters of each 6 pixels take 48 cycles).</p> |
| 331 |
|
| 332 |
|
| 333 |
<h5>CPU/command-engine access slots</h5> |
| 334 |
<p>These are the positions of the available CPU/cmd access slots:</p> |
| 335 |
<table> |
| 336 |
<tr><td>2</td><td>10</td><td>18</td><td>26</td><td>34</td> |
| 337 |
<td>42</td><td>50</td><td>58</td><td>66</td><td>166</td></tr> |
| 338 |
<tr><td>174</td><td>182</td><td>190</td><td>198</td><td>206</td> |
| 339 |
<td>214</td><td>222</td><td>312</td><td>408</td><td>504</td></tr> |
| 340 |
<tr><td>600</td><td>696</td><td>792</td><td>888</td><td>984</td> |
| 341 |
<td>1080</td><td>1176</td><td>1206</td><td>1214</td><td>1222</td></tr> |
| 342 |
<tr><td>1230</td><td>1238</td><td>1246</td><td>1254</td><td>1262</td> |
| 343 |
<td>1270</td><td>1278</td><td>1286</td><td>1294</td><td>1302</td></tr> |
| 344 |
<tr><td>1310</td><td>1318</td><td>1326</td><td>1336</td><td>1346</td> |
| 345 |
<td>1354</td><td>1362</td></tr> |
| 346 |
</table> |
| 347 |
<p>There are 47 access slots, but they are very unevenly distributed. Often the |
| 348 |
distance between two slots is 96 cycles, and one time even 100 VDP cycles! This |
| 349 |
means that, even though there are more slots compared to bitmap/character mode, |
| 350 |
the Z80 must access the VRAM more slowly in this mode! So to be safe there must |
| 351 |
be 20 Z80 cycles between two CPU-VRAM accesses (see previous article for the |
| 352 |
details of this calculation).</p> |
| 353 |
|
| 354 |
|
| 355 |
<h4>Text mode 1 (aka screen 0, width 40)</h4> |
| 356 |
<p>As mentioned before, from a VRAM access point of view, Text mode 1 is |
| 357 |
similar to Text mode 2. Actually from a VRAM access allocation point of view |
| 358 |
it's identical, only the actually VRAM read addresses are different. This may |
| 359 |
seem strange because Text mode 1 logically needs a lot less data than Text mode |
| 360 |
2. This is because over half of the performed reads are dummy reads:</p> |
| 361 |
<ul> |
| 362 |
<li>In Text mode 1 there are still 4 (burst) reads from the name-table, but the |
| 363 |
3rd and 4th are dummy reads. In our (limited) measurements the address for |
| 364 |
read 3 and 4 was the same as for read 2, but with CAS1 active instead of |
| 365 |
CAS0 (but doesn't really matter as the result is ignored).</li> |
| 366 |
<li>There are also 10 dummy reads at the locations that are reserved for reads |
| 367 |
from the color-table. All these read address 0x1ffff.</li> |
| 368 |
<li>And similarly there are 4 reads from the pattern-table, but the 3rd and |
| 369 |
4th read address 0x1ffff.</li> |
| 370 |
</ul> |
| 371 |
|
| 372 |
<h5>CPU/command-engine access slots</h5> |
| 373 |
<p>The available CPU/cmd access slots are identical to those in Text mode 2. |
| 374 |
<i>It's unfortunate there are so many dummy reads in this mode. If this wasn't |
| 375 |
the case, the available VRAM bandwidth for CPU accesses (or commands on V9958) |
| 376 |
could have been a lot higher. Especially because the Z80 already cannot access |
| 377 |
VRAM very fast in this mode. And also because, as we'll see below, on TMS9918 |
| 378 |
there's no such timing constraint for this mode.</i></p> |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
<h3>Stuff not measured</h3> |
| 383 |
|
| 384 |
<p>There are a number of V9938 cases we don't have measurements for. As already |
| 385 |
said in the beginning of this text, the original goal of these measurements was |
| 386 |
to improve the accuracy of the command engine emulation. And we only had a very |
| 387 |
limited amount of time the day we did this experiment. Re-doing the experiment |
| 388 |
is certainly possible and not even that hard. But it takes a lot of time to |
| 389 |
setup, for, as we'll see below, not too much useful extra knowledge. But of |
| 390 |
course I'd be very happy to hear from other people who do want to repeat and/or |
| 391 |
extend our measurements!</p> |
| 392 |
|
| 393 |
<h4>Graphics mode 3 (aka screen 4)</h4> |
| 394 |
<p>This uses very likely the same timing as Graphics mode 2 (aka screen 2), but |
| 395 |
with the address generation logic of sprite mode 1 replaced with the one for |
| 396 |
sprite mode 2. The timing of all VRAM accesses, even the sprite accesses, can |
| 397 |
remain identical. <i>The existence of this screen mode might have been |
| 398 |
(another) reason to design the timing of sprite mode 1 on V9938 in such a |
| 399 |
strange way.</i></p> |
| 400 |
|
| 401 |
<h4>Character modes with sprites disabled</h4> |
| 402 |
<p>In bitmap modes, when sprite rendering is disabled, the VRAM bandwidth that |
| 403 |
was allocated to sprite rendering becomes available for CPU/cmd accesses. Likely |
| 404 |
the same is true for character modes (and text modes never have sprites). |
| 405 |
Unfortunately since we didn't measure this combination we don't know exactly |
| 406 |
where those slots are located. But it should be possible to make a very |
| 407 |
reasonable estimate.</p> |
| 408 |
|
| 409 |
<h4>Text modes with screen disabled (or vertical border)</h4> |
| 410 |
<p>All non-text modes behave identical when screen display is disabled (and the |
| 411 |
behavior during screen disabled is identical to the behavior during vertical |
| 412 |
border lines): the VRAM reads for screen- and sprite-rendering are gone and |
| 413 |
replaced by CPU/cmd access slots, but e.g. the refresh accesses remain. In the |
| 414 |
2 text modes those refresh accesses are located in different positions compared |
| 415 |
to bitmap/character modes. It's not known whether:</p> |
| 416 |
<ul> |
| 417 |
<li>Screen-disabled in text-mode is the same as screen-disabled in the other |
| 418 |
screen modes.</li> |
| 419 |
<li>Or whether it has a dedicated schema with the refresh-reads in the same |
| 420 |
positions as in the text-mode screen-enabled case.</li> |
| 421 |
|
| 422 |
</ul> |
| 423 |
<p>This might make a difference for the exact position of the CPU/cmd access |
| 424 |
slots. But because there are usually plenty of slots available in screen-off |
| 425 |
mode, this likely won't matter (much).</p> |
| 426 |
|
| 427 |
|
| 428 |
<h2>TMS9918 (MSX1 VDP)</h2> |
| 429 |
<p>All our measurements were performed on a V9938 (MSX2 VDP). It's very likely |
| 430 |
we can extrapolate the results to a V9958 (MSX2+ VDP). But for sure we cannot |
| 431 |
use these results to derive anything meaningful for the TMS9918. Fortunately |
| 432 |
there already is some interesting information available in |
| 433 |
<a href="http://spatula-city.org/~im14u2c/vdp-99xx/">these documents</a> from |
| 434 |
Karl Guttag. Especially this |
| 435 |
<a href="http://spatula-city.org/~im14u2c/vdp-99xx/e2/1978_9918_Master_Timing_by_Serigio_Maggi.jpg"> |
| 436 |
timing picture</a> looks promising. Combined with information found in the |
| 437 |
<a href="http://map.grauw.nl/resources/video/texasinstruments_tms9918.pdf"> |
| 438 |
TMS9918 application manual</a> I was able to deduce the stuff below. <i>This |
| 439 |
wasn't easy because that timing picture does contain some (confusing) mistakes, |
| 440 |
although I can easily forgive those mistakes because drawing this stuff by hand |
| 441 |
is very tedious</i> ;-)</p> |
| 442 |
|
| 443 |
|
| 444 |
<h5>general (memory) timings</h5> |
| 445 |
<p>The TMS9918 runs at 5.37MHz (1.5×3.58MHz, 4× slower than the |
| 446 |
V9938). One display line takes 342 cycles (as expected, 4× less than on |
| 447 |
V9938). One memory access takes only 2 cycles or 372ns. So compared to V9938 |
| 448 |
each memory access takes slightly longer (on V9938 one access takes 6 cycles or |
| 449 |
279ns). The TMS9918 never uses burst memory reads.</p> |
| 450 |
|
| 451 |
<h5>Graphics mode 2 (aka screen 2)</h5> |
| 452 |
<p>For the actual arrangement of the accesses I'll refer to the big timing |
| 453 |
diagram (see top of this article). Most things are reasonably straight-forward. |
| 454 |
One notable thing is the arrangement of the 32 sprite y-coordinate reads (for |
| 455 |
the visibility check): the first 8 follow a different pattern than the last 24. |
| 456 |
This is done to not have too long periods without CPU VRAM access slot. Reading |
| 457 |
the other sprite data (during the horizontal border) also shows some |
| 458 |
irregularities. Like on V9938, the y-coordinates of the visible sprites are |
| 459 |
read twice, but apart from these 4 redundant reads, there are no dummy reads or |
| 460 |
idle cycles (unlike V9938). It is not known whether the TMS9918 performs reads |
| 461 |
for sprites that are not actually visible or that those slots are available for |
| 462 |
CPU access (V9938 performs dummy reads).</p> |
| 463 |
|
| 464 |
<p>The TMS9918 application manual mentions in section 2.1.5 "… CPU |
| 465 |
windows occur once every 16 memory cycles …". This confirms the |
| 466 |
above.</p> |
| 467 |
|
| 468 |
|
| 469 |
<h5>Graphics mode 1 (aka screen 1)</h5> |
| 470 |
<p>I couldn't find anything specific about the timing of this mode in the above |
| 471 |
documentation. But because it requires the same number of reads from VRAM as |
| 472 |
Graphics mode 2, it's logical to assume the timing is identical.</p> |
| 473 |
|
| 474 |
<h5>Multi-color mode (aka screen 3)</h5> |
| 475 |
<p>The documentation also doesn't have specific timing information for this |
| 476 |
mode. In this mode the color-table isn't used, so one possibility is that |
| 477 |
accesses to the color-table are replaced by CPU access slots (not the case on |
| 478 |
V9938). This is confirmed by the following quote from the application manual, |
| 479 |
section 2.1.5 "… in the Multicolor mode, CPU windows occur at least once |
| 480 |
out of every four memory cycles …". Though when you look at the |
| 481 |
sprite-accesses in the horizontal border area this quote isn't true: there's |
| 482 |
still one location where there are 15 memory cycles between 2 CPU access slots! |
| 483 |
<i>On the other hand, it would be possible to distribute the sprite and cpu |
| 484 |
accesses more evenly in the horizontal border. So maybe that hand-drawn timing |
| 485 |
picture is wrong? Or maybe it doesn't correspond to the final TMS9918 |
| 486 |
design?</i></p> |
| 487 |
|
| 488 |
<h5>Text mode 1 (aka screen 0, width 40)</h5> |
| 489 |
<p>Again see the big timing diagram. There's nothing really special about this |
| 490 |
mode. The following quote from the application manual confirms this |
| 491 |
arrangement: section 2.1.5 "… In the Text mode the CPU windows occur at |
| 492 |
least once out of every three memory cycles …". Note that reads from the |
| 493 |
name-table are not immediately followed by reads from the pattern-table. |
| 494 |
<i>Possibly because the addresses in the latter table depend on the results |
| 495 |
from the former reads and the VDP needs time to calculate those |
| 496 |
addresses.</i></p> |
| 497 |
|
| 498 |
<h5>display-disabled</h5> |
| 499 |
<p>On TMS9918 there's no register that allows to disable sprite rendering |
| 500 |
(there is on V9938), but it is possible to disable the whole screen rendering. |
| 501 |
The documentation does hint that the screen-disabled behavior is the same as |
| 502 |
the behavior during the vertical border (just as on V9938).</p> |
| 503 |
|
| 504 |
<p>You may have noticed that in the above TMS9918 display-mode sections we |
| 505 |
didn't mention any refresh reads. Also note that the hand-drawn TMS9918 timing |
| 506 |
picture mentions something called 'refresh mode' (but nothing called 'vertical |
| 507 |
border' or 'screen-disabled'). So I believe that on TMS9918 the VRAM is not |
| 508 |
refreshed during each display line, but instead it's refreshed during the |
| 509 |
vertical border.</p> |
| 510 |
|
| 511 |
<p>On V9938 each display line performs 8 refresh reads (only 7 in text mode), |
| 512 |
so it takes 64 lines or about 4ms to refresh 128kB VRAM (and only 2ms if you |
| 513 |
rely on RAS-without-CAS refresh). On TMS9918 each vertical border line performs |
| 514 |
32 refresh reads. So during the whole vertical border the full 16kB VRAM is |
| 515 |
fully refreshed multiple times. Though between two vertical borders there are |
| 516 |
192 display lines or about 12ms. So DRAM chips connected to TMS9918 have to be |
| 517 |
able to retain their content longer without refresh than those connected to |
| 518 |
V9938. The TMS9918 refresh schema does make more efficient use of the available |
| 519 |
VRAM bandwidth (only do refresh when there's plenty of bandwidth available). On |
| 520 |
the other hand the TMS9918 schema would make something like the |
| 521 |
V9938-overscan-trick impossible (overscan = show display lines everywhere, |
| 522 |
'skip' the vertical border).</p> |
| 523 |
|
| 524 |
<h5>MSX1 CPU-VRAM access</h5> |
| 525 |
<p>So what do the above timings mean for a MSX1 Z80 programmer? In various fora |
| 526 |
(MSX or other) you find discussions about how fast it's allowed to access the |
| 527 |
VRAM (read/write data from/to IO port 0x98). The general consensus seems to be |
| 528 |
"at least 29 Z80 cycles between two accesses". For example an OUT(#99),A |
| 529 |
instruction takes 12 cycles (on MSX), so you need 17 extra cycles before the |
| 530 |
next such instruction.</p> |
| 531 |
|
| 532 |
<p>This value of 29 cycles seems to come directly from the TMS9918 application |
| 533 |
manual: it says in the worst case there must be 6µs+2µs=8µs |
| 534 |
between two accesses. Translated to Z80 cycles this gives 28.6 and rounded up |
| 535 |
29 Z80 cycles. Though IMHO this result isn't very satisfactory. That value |
| 536 |
8µs is only given with one significant digit, so it could just as well be |
| 537 |
7.5µs or 8.5µs. Rounded up to the nearest Z80 cycle that's between |
| 538 |
27 and 31 Z80 cycles. Many people use the 29-cycles rule and apparently that |
| 539 |
works fine in practice. But you also see reports that only 28 cycles |
| 540 |
often(?)/always(?) work as well. It would be nice if we could measure the |
| 541 |
exact value.</p> |
| 542 |
|
| 543 |
<p><i>That value 2µs is also mentioned in table 2.2 of the TMS9918 |
| 544 |
application manual. Other values in that table seem to be accurate to |
| 545 |
±0.05µs, so it's possible (even likely?) those 2µs can be |
| 546 |
read as 2.0µs. It must be an integer multiple of VDP clock cycles: 10 |
| 547 |
cycles is 1.86µs, 11 cycles is 2.05µs. If I have to make a guess |
| 548 |
I'd pick the latter (this still results in a total CPU-VRAM access time of 29 |
| 549 |
Z80 cycles). Though in the rest of this text I'm still assuming the larger |
| 550 |
uncertainty interval.</i></p> |
| 551 |
|
| 552 |
<p>Sometimes you find discussions about when it's allowed to go faster than the |
| 553 |
worst case requirement. Here the consensus is that in the vertical border you |
| 554 |
can go as fast as you want (seems to be correct, see below). Sometimes you see |
| 555 |
suggestions that it's also fine to go faster in the horizontal border or when |
| 556 |
sprites aren't used (this seems wrong, or at least only partly correct).</p> |
| 557 |
|
| 558 |
<p>Anyway, in the remainder as this section I'd like to dig a little deeper. |
| 559 |
Now that the exact VRAM access allocation schemas are known we can say a little |
| 560 |
more. But unfortunately some details will remain unclear.</p> |
| 561 |
<ul> |
| 562 |
<li><p>In the worst case (Graphics mode 1 and 2) there are 16 memory cycles |
| 563 |
(32 VDP cycles, 21.3 Z80 cycles) between two CPU slots. The application |
| 564 |
manual also mentions an additional CPU-access waiting time of 2µs. |
| 565 |
Though as explained above that could be anywhere from |
| 566 |
1.5µs to 2.5µs, this is between 8 to 13 VDP cycles or 5 to 9 |
| 567 |
Z80 cycles. <i>(It's not clear where this time is coming from, maybe |
| 568 |
something similar to the V9938 'slot-reservation' delay of 16 cycles).</i> |
| 569 |
Combined this gives between 26.7 and 30.2 Z80 cycles. But unfortunately |
| 570 |
this isn't more accurate than the range we already found above.</p> |
| 571 |
<p>In this <a href="http://www.msx.org/forum/development/msx-development/bitbuster-depack-vram?page=6"> |
| 572 |
post</a> dvik suggests it's OK to use tighter timings when "sprites aren't |
| 573 |
used". This would mean that the memory slots that are otherwise used for |
| 574 |
sprite rendering are given to the CPU. But what does that mean "sprites |
| 575 |
aren't used"? If it means there simply aren't any sprites visible, the |
| 576 |
TMS9918 still has to fetch 32 y-coordinates to figure out there indeed |
| 577 |
aren't any sprites visible (and then it can maybe omit the reads for the |
| 578 |
actual sprite rendering). But this doesn't improve the worst case timing. |
| 579 |
Another possibility is to explicitly disable sprite rendering. TMS9918 has |
| 580 |
no bit in some register to do this. The only possibility I see is to have |
| 581 |
a sprite with y-coordinate = 208. It <b>might</b> indeed be the case that |
| 582 |
the TMS9918 stops fetching sprite y-coordinates in this scenario (the |
| 583 |
V9938 does not), but without further tests I personally wouldn't trust |
| 584 |
this. It would be nice if someone could confirm or reject this |
| 585 |
theory.</p></li> |
| 586 |
<li><p>In the best case (the vertical border), there are only 4 VDP cycles |
| 587 |
between CPU slots. Taking the uncertainty of those '2µs' into |
| 588 |
account, that results in a minimum distance of 8-12 Z80 cycles between two |
| 589 |
VRAM accesses. The fastest Z80 I/O instruction takes 12 cycles (on MSX, |
| 590 |
taking the extra Z80 wait cycle into account). So this confirms that in |
| 591 |
the vertical border you can indeed access VRAM as fast as you want.</p></li> |
| 592 |
<li><p>Text mode has maximum 6 VDP cycles between CPU slots. So rounded that's |
| 593 |
somewhere between 10 and 13 Z80 cycles. So it's <i>likely</i> OK to also |
| 594 |
in text mode access the VRAM as fast as you want, but we can only be |
| 595 |
certain if we know a more accurate value for those '2µs'. It's worth |
| 596 |
repeating that on V9938 you can <b>not</b> access VRAM as fast in this |
| 597 |
mode. Keep that in mind when writing MSX1 software that needs to be upwards |
| 598 |
compatible with MSX2.</p></li> |
| 599 |
<li><p>Multi-color mode is unclear: the application manual says there's a CPU |
| 600 |
slot at least every 4 memory accesses. But as explained above I don't |
| 601 |
believe this (it's true for the display area, but not for the horizontal |
| 602 |
border). If it were true you only need 11-15 Z80 cycles between two |
| 603 |
CPU-VRAM accesses. But if you do take the border into account you get |
| 604 |
26-29 Z80 cycles, thus only slightly better than Graphics mode 2.</p></li> |
| 605 |
</ul> |
| 606 |
|
| 607 |
<hr/> |
| 608 |
<p align="right" style="font-size:smaller;"> |
| 609 |
2014/08/09, Wouter Vermaelen |
| 610 |
</p> |
| 611 |
|
| 612 |
</body> |
| 613 |
</html> |