Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .----------------------------------------.
- ( A P P E N D I X D . S C A N L I N E S )
- `----------------------------------------´
- general contents: pastebin.com/hmpJmurr
- o==========o
- | Contents |
- o==========o
- A. Scan lines and pixels
- 1. Scan lines
- 2. Pixels
- B. Raster time
- C. Bad line
- D. Some calculations
- X. References
- <>-<>-<>-<>-<>-<>
- o==========================o
- | A. Scan lines and pixels |
- o==========================o
- 1. Scan lines
- ~~~~~~~~~~~~~
- The C64 appears not to adhere to the PAL or NTSC standard. A PAL C64 draws 284 lines 50 times per second. After drawing those lines the raster beam takes some time to return and initialize. In that amount of time 28 lines could have been drawn. This is called the vertical blanking time (sometimes called "invisible lines"). The same thing goes for the so called horizontal blank (100 pixels).
- The usable area (work area) is 320 pix. by 200 lines. So including the vertical- and horizontal blank the screen is sometimes described as having 504 by 312 pixels.
- <------ 504 pix ------>
- ___________________________ _________
- | |<- 100 ->| ^
- | __________________ | pix | |
- | | <- 320 pix -> ^ | | | |
- | | | | | | |
- | | | | | Hor. |
- | | 200 lines | | | blank |
- | | | | | | 312 lines
- | |_______________V__| | |
- | | |
- |___________________________| | |
- | Vertical blank, 28 lines | |
- |_____________________________________| V
- Figure 1. Simplified C64 PAL screen.
- Sprites can move in the border [7]. According to the Vic Bible [6] a PAL C64 starts counting line numbers from 0 on at the top most line (NTSC: line nr. 0 is somewhere at the bottom). However, it looks like they start numbering the lines at 1 and the pixels on a horizontal line at 0. The VIC Bible [6] states that the first vert. blank line is nr. 300 and the last vert. blank line is nr. 15. Using that info table 1 has been compiled. Notice that Codebase [7] is probably wrong, other than that the upper and lower margins (border + blank) are 50 and 62 lines respectively.
- Table 1. PAL television lines and the C64 according the the
- VIC Bible [6]. Line numbers, line sum, number of lines and
- description.
- ______________________________________________________________
- Line nr. No. of Sum Description
- lines
- ______________________________________________________________
- 1 - 15 15 Upper vert. blank
- 16 - 50 35 + Upper border (light blue)
- = 50 Upper margin
- 51 - 250 200 Workable area (d. blue)
- 251 - 299 49 Lower border
- 300 - 312 13 + Lower vert. blank
- = 62 Lower margin
- 284 = 35 + 200 + 49 =
- Work area and borders
- 28 = 15 + 13 =
- Both vert. blanks
- 312 = 284 + 28 = All lines (incl. blank)
- ______________________________________________________________
- 2. Pixels
- ~~~~~~~~~
- Refer to figure 1. The VIC-II draws 320 pixels in the work area. In the Vic Bible [6] it is stated that the 320 pixels of the workable area are the numbered from 24 to 343 (= 320 px.). If one plots that in a graph (fig. 2) then the numbers don't add up. Maybe they meant 24 pixels after the number 0 (= 25 including 0) and calculated the number 343 from the number 24.
- All sources seem to agree on a total horizontal with of 504 pix (incl. hor. blank). Codebase [7] is probably wrong concerning a left horizontal blank of 2 pixels which it calls "VSync burst" or "HSync burst".
- The only way the author could get most numbers mentioned in the Vic Bible [6] in a figure is as in table 2 and figure 2.
- Table 2. PAL television pixels and the C64. Pixels per line
- and blanking according to the VIC Bible [6].
- _____________________________________________________________
- Pix nr. No. of Sum Description
- pix.
- _____________________________________________________________
- 0 - 75 76 Left hor. blank
- 76 - 123 48 Left border (light blue)
- 124 - 443 320 Workable area (dark blue)
- 444 - 479 36 Right border (light blue)
- 480 - 503 24 Right hor. blank
- 404 = 48 + 320 + 36 =
- Work area and borders
- 100 = 76 + 24 =
- Left & right hor. blanks
- 504 = 76 + 48 + 320 + 36 +24 =
- Total with of a scan line
- ______________________________________________________________
- Notice that there is a very confusing difference between "pixel number 0" on a raster line and "the first x-coordinate". The x-coordinates are used to place sprites etc. The first x-co. does not have to be pixel 0. It looks like it's at the raster IRQ.
- Pixel numbers:
- L. Hor. Bl. L. Border Workable Area R. Border R. Hor. Bl.
- 0 75 76 123 124 443 444 479 480 503
- |__________| |__________| |______________________| |________| |__________|
- | 76 pix | | 48 pix | | 320 pix | | 36 pix | | 24 pix |
- |__________| |__________| |______________________| |________| |__________|
- | | | | | | | | | | |
- 405 480 481 503/0 24 25 344 345 380 381 404
- | | |
- |23 p|25 px|
- X-coordinates: ----^
- Figure 2. A scan line according to the VIC Bible [6]. Pixel numbers start
- at 0 on the left. The "first x-coordinate" starts after x-co. 24. X-co.
- zero is at the raster IRQ. Numbers between < and > denote an interval.
- The whole picture looks like below (fig. 3):
- .<-------------------- 404 pixels ---------------------->.
- _______.________________________________________________________._______
- | . ^ . |
- | . | 15 lines Upper Vertical Blank . |
- | ._______________V________________________________________. |
- | | ^ ^ | |
- | | | | 35 lines Upper Border | |
- | | | _______V________________________________ | |
- | | | |<-------------- 320 pixels ------------>| | |
- | | | | ^ | | |
- | | | | | | | |
- | | | | | | | |
- | | | | | | | |
- | 76 px | 48 px | | | 36 px | 24 px |
- | Left | Left | | Workable | Right | Right |
- | Hor. | Border| | Area | Border| Hor. |
- | Blank | | | | | | Blank |
- | | | | |200 lines | | |
- | | | | | | | |
- | | | | | | | |
- | | | | | | | |
- | | | |__V_____________________________________| | |
- | | | ^ | |
- | | | 284 lines | 49 lines Lower Border | |
- | |__V____________V________________________________________| |
- | ^ |
- | | 13 lines Lower Vertical Blank |
- |_______________________V________________________________________________|
- Figure 3. Complete PAL C64 television screen. It's 504 pixels by 312
- lines. Horizontal blank is 28 lines, vertical blank is 100 pixels.
- o================o
- | B. Raster time |
- o================o
- Raster Time is the duration it takes to draw a raster line on screen. Raster time is measured in CPU cycles, not in seconds. Note that the CPU deals in words of 8 bits per clock cycle. That's why the VIC needs to be 8 times as fast as the CPU (a character is 8 pix. wide).
- Calculation per scan line:
- 504 pixels (or: cycles) for the VIC per sc. line / 8 times as fast as the CPU =
- 63 CPU cycles / scan line
- So in the time it takes the VIC to print a raster line on the TV the CPU has had 63 cycles. Raster time is "63".
- o=============o
- | C. Bad line |
- o=============o
- Usually a line is drawn by the VIC in 63 CPU cycles (= raster time). But that's when the VIC "has it easy" and doesn't print sprites and only has to print pixels. Every now and then the VIC needs to determine which characters to print, that is: RAM must be read. And the VIC needs to determine if a pixel of one of the 8 sprites must be printed. This takes additional cycles.
- The additional cycles are usually needed every 8 lines because characters are 8 lines high. So what the VIC-II actually does to get hold of those required additional cycles is to block, or "stun", the CPU for about 40 cycles (there are 40 chars on a line). The raster line where this stunning of the CPU happens is called a Bad Line [1].
- Note that in addition to stealing cycles on bad lines, the VIC will also steal cycles from the CPU on raster-lines with sprites [3]. Sprites steal 1-2 cycle as VIC runs effectively at 2 MHz when reading sprite data [4].
- The "stolen" cycles are used by the VIC to read memory and sprite data before the line ends so it's in time to draw the next.
- o======================o
- | D. Some calculations |
- o======================o
- 1/50 sec per screen (field) = 20 ms / 312 lines = 64 * 10^-6 s/line = 64 us/line.
- CPU clock, PAL = 985,248 Hz (~ 1 MHz) [2].
- VIC-II clock, PAL = 7.881984 MHz (exactly 8 times as fast as the CPU because the CPU deals in 8 bits/pixels per cycle)
- 1 field: 504 pix * 312 lines = 157,248 "actions for the VIC" per field.
- 50 fields per second = 50 * 157,248 = 7,863,400 Hz.
- So the VIC needs to be minimally 7.86 MHZ, which it is. :-)
- PAL television standard: 576 lines = 2 x 288 lines. One field = 288 lines. Why is the C64 not that?
- PAL TV: 576 visible lines, 625 total lines [8].
- o===============o
- | X. References |
- o===============o
- [1] Dustlayer, Beyond the screen - rasters and cycles:
- https://dustlayer.com/vic-ii/2013/4/25/vic-ii-for-beginners-beyond-the-screen-rasters-cycle
- [2] Codebase64, clock frequency:
- https://codebase64.org/doku.php?id=base:cpu_clocking
- [3] In case someone reading this does not know what badlines are:
- https://stackoverflow.com/questions/24375150/stable-raster-on-c64
- [4] C64 Scene Database foprum topic:
- https://csdb.dk/forums/?roomid=11&topicid=48890&showallposts=1
- [5] Bad lines and flexible line distance (part 5):
- https://nurpax.github.io/posts/2018-06-19-bintris-on-c64-part-5.html
- [6] The VIC Bible:
- "The MOS 6567/6569 video controller (VIC-II) and its application in the Commodore 64" by Christian Bauer (1996).
- http://www.zimmers.net/cbmpics/cbm/c64/vic-ii.txt
- [7] Codebase64, visible area of the screen on the monitor:
- https://codebase64.org/doku.php?id=base:visible_area
- [8] Visible liens and total lines on PAL and NTSC:
- https://www.filmfix.com/dvd_avi_mpg2_transfer_info.asp
Add Comment
Please, Sign In to add comment