spacer

GID j - Mission Accomplished

Having only had a few hours Sunday night to work on the last part of the code I wasn't expecting to actually reach my goal of a pixel on the screen. In the end though, I managed to get a square block drawn in the center of the screen synced well enough to show flicker free on both my TV and Digital TV card in the PC.

The actual TV picture is a nice vibrant yellow, the screen capture doesn't do it justice looking a little washed out. Oh, that reminds me, the colour burst wasn't that hard afterall, just a case of making sure the colour is set in the upper 4 bits and the luma in the lower 4 :)

big pixel

Adding in the VSync and overscan code wasn't that difficult, the hard part was counting all the clock cycles to make sure they met the timing requirements. In fact the most trouble was with the comparison loop where I check whether the scanline is within the block and needs to be drawn in colour. This results in 3 possible code paths all of which had to have exactly the same number of cycles before reaching the final DEALY(174-3) instruction. A little fudging goes a long way though :)

The theme for this GID was "Extreme Forces" well the forces exerted on my TV by all the badly formed signals I sent throughout Saturday were pretty extreme, does that count?

For those that care the source code is rar'd up and available for download. Although it works fine on my TV that doesn't mean the code is correct so I'd love to hear back from any of the more experienced XGS users if you can see any obvious flaws. The final code weighed in at roughly 374 bytes (don't quote me on that ;) ) After looking at a few other peoples delay macros I can see a saving of several bytes there alone, so I'm sure this code can be optimised significantly, maybe another day :)

Check out the rest of this entry if you want to see the final code

Be aware the tab settings are a little messed up

ASM:
  1. ; //////////////////////////////////////////////////////////////////////
  2. ; GID j - Pixel in a day entry
  3. ; Gary Preston 8th April 2006
  4. ; //////////////////////////////////////////////////////////////////////
  5. include "Setup52.inc"
  6. include "macros.inc"
  7.  
  8. ; //////////////////////////////////////////////////////////////////////
  9. ; Consts
  10. ; //////////////////////////////////////////////////////////////////////
  11. ;
  12. BLACK_LEVEL EQU 6
  13. WHITE_LEVEL EQU 15
  14.  
  15.  
  16. ; Colors
  17. VID_SYNC      EQU %11110000             ; No color + 0v
  18. VID_BLACK   EQU (%11110000 + BLACK_LEVEL)     ; 0.25-0.3V
  19. VID_WHITE   EQU (%11110000 + WHITE_LEVEL)      ; 1.0V
  20. TEMP_COLOUR EQU %00011111                                       ; yellow
  21.  
  22. ; Color Burst signal
  23. VID_COLORBURST_OFF EQU (%11110000 + BLACK_LEVEL)
  24. VID_COLORBURST_ON EQU  (%00000000 + BLACK_LEVEL)
  25.  
  26. ; //////////////////////////////////////////////////////////////////////
  27. ; Variables
  28. ; //////////////////////////////////////////////////////////////////////
  29.  
  30. ;----------------------------------------------------------------------
  31. ; $00 - 09 - registers (05-09 = ports RA-RE)
  32. ; 0A - 0F - globals
  33. ; Banks (00-0F, 10-1F, 20-2F ... F0-FF) bank 0 via semi-direct only
  34.  
  35. ;----------------------------------------------------------------------
  36. ; GLOBALS (Not available using semi-direct!)
  37. ORG $0A        ; skip past global registers and banks 1-F
  38. counter DS   1  ; counter required by delay macro
  39.  
  40. ;----------------------------------------------------------------------
  41. ; defines for TV Signal generation using Bank 1
  42. ORG $10
  43. BANK_VIDEO EQU $
  44.  
  45. pixels    DS 1
  46. scanline       DS 1
  47.  
  48. ; //////////////////////////////////////////////////////////////////////
  49. ; Program start
  50. ; //////////////////////////////////////////////////////////////////////
  51. main
  52.     ; Initialise ports for video (RE port tied to video hardware)
  53.     mov RE, #%00000000      ; clear port
  54.     mov !RE, #%00000000    ; set all pins to output
  55.  
  56.     ; --------------------------------------------------------------
  57.     ; Video Kernel (Colour upper nibble, Luma lower nibble)
  58.     ; VID_CSEL3 (b7) - VID_CSEL0 (b4)
  59.     ; VID_ISEL3 (b3) - VID_ISEL0 (b0)
  60.     ; Tied to port RE0-7
  61.     ; PAL 5Mhz
  62.     ;   312 scan lines
  63.     ;   pixel every 181.81ns approx 292 pixels per line (53.1us / 181.81ns)
  64.  
  65.     ; set bank
  66.     _bank   BANK_VIDEO
  67.  
  68. vidloop  
  69.  
  70.     ; we have 312 lines potentially with pal but will use only 192 active
  71.     mov scanline, #206          ; 2
  72. :scanline_loop
  73.     ;--------------------------------------------------------------
  74.     ; Horizontal signal component 274 active lines
  75.     ; blanking voltage 0.3V for 1.5us (front porch)
  76.     mov RE, #VID_BLACK                        ; 2
  77.     DELAY( 120-2 )
  78.  
  79.     ; horizontal sync 0V delay 4.7us
  80.     mov RE, #VID_SYNC                           ; 2
  81.     DELAY( 376-2 )
  82.  
  83.     ; pre burst breezeway 0.6us voltage 0.3V
  84.     mov RE, #VID_BLACK                  ; 2
  85.     DELAY( 48-2 )
  86.  
  87.     ; color burst 9-10cycles 0.3V for 2.5us (skipping data just delay for now)
  88.     mov RE, #VID_COLORBURST_ON            ; 2
  89.     DELAY( 200-2 )                              ; 200-2
  90.    
  91.     ; post burst blanking 0.3V 1.6us
  92.     mov RE, #VID_BLACK                ; 2
  93.     mov pixels, #255                              ; 2   
  94.     DELAY( 128-4 )
  95.  
  96.     ; All the 3 branches following MUST have the same execution time, thus
  97.   ; the extra jumps that don't go anywhere
  98.     ; black for 141 pixels (2037 cycles) and color for 12 (174 cycles)
  99.     mov RE, #VID_BLACK                ; 2
  100.  
  101.     ; color for 12 pixels (174 cycles)   
  102.     cjb scanline, #97, :skipcolor1        ; 4/6
  103.     cja scanline, #109, :skipcolor2   ; 4/6
  104.     DELAY(2037-10)
  105.     mov RE, #TEMP_COLOUR                            ; 2 setup pixel colour 
  106.     jmp :color                        ; 3
  107.  
  108. :skipcolor2
  109.     DELAY(2037-12)
  110.     nop 
  111.     nop
  112.     jmp :color                        ; 3
  113. :skipcolor1
  114.     DELAY(2037-6)
  115.     nop 
  116.     nop
  117.     jmp :color                        ; 3
  118. :color
  119.     DELAY( 174-5 )
  120.  
  121.     ; black for 141 pixels (2037 cycles)                           
  122.     mov RE, #VID_BLACK                              ; 2 setup pixel colour 
  123.     DELAY(2037-6)            ; inc following jump
  124.  
  125.     djnz scanline, :scanline_loop   ; 2/4 (extra 2 from 4 is unaccounted for!)
  126.    
  127.   ; END of Horizontal Component (total scanline = 64us)
  128.   ; we're 2 clock cycles over!
  129.  
  130. ; ---------------------------------------------------------------------------------------------
  131. ; OVERSCAN BOTTOM
  132. ; --------------------------------------------------------------------------------------------- 
  133.     mov scanline, #50   ; 2
  134. :overscan_bottom
  135.     ;--------------------------------------------------------------
  136.     ; Horizontal signal component 274 active lines
  137.     ; blanking voltage 0.3V for 1.5us (front porch)
  138.     mov RE, #VID_BLACK                        ; 2
  139.     DELAY( 120-2 )
  140.  
  141.     ; horizontal sync 0V delay 4.7us
  142.     mov RE, #VID_SYNC                           ; 2
  143.     DELAY( 376-2 )
  144.  
  145.     ; pre burst breezeway 0.6us voltage 0.3V
  146.     mov RE, #VID_BLACK                  ; 2
  147.     DELAY( 48-2 )
  148.  
  149.     ; color burst 9-10cycles 0.3V for 2.5us (skipping data just delay for now)
  150.     mov RE, #VID_COLORBURST_ON            ; 2
  151.     DELAY( 200-2 )                              ; 200-2
  152.    
  153.     ; post burst blanking 0.3V 1.6us
  154.     mov RE, #VID_BLACK                ; 2
  155.     mov pixels, #255                              ; 2   
  156.     DELAY( 128-4 )
  157.  
  158.     ; draw full scanline (53.1us = 4248 cycles)
  159.     mov RE, #VID_BLACK    ; 2
  160.     DELAY( 2124-2 )  ; 4248 is one full scanline, delay function would overflow with that amount
  161.     DELAY( 2124-4 )  ; Really need to build a better delay function that supports longer delays
  162.     djnz scanline, :overscan_bottom ; 2/4
  163.     ; full scanlein = 64us
  164.  
  165. ; ---------------------------------------------------------------------------------------------
  166. ; VSYNC LINES
  167. ; ---------------------------------------------------------------------------------------------
  168.     mov scanline, #5        ; 2
  169. :vsync
  170.     ; 4 sync lines
  171.     mov RE, #VID_SYNC      ; 2
  172.     DELAY( 2560-2 )  ; 4248 is one full scanline, delay function would overflow with that amount
  173.     DELAY( 2560-4 )  ; Really need to build a better delay function that supports longer delays
  174.     djnz scanline, :vsync   ; 2/4
  175.  
  176. ; ---------------------------------------------------------------------------------------------
  177. ; OVERSCAN TOP
  178. ; --------------------------------------------------------------------------------------------- 
  179.     mov scanline, #50   ; 2
  180. :overscan_top
  181.     ;--------------------------------------------------------------
  182.     ; Horizontal signal component 274 active lines
  183.     ; blanking voltage 0.3V for 1.5us (front porch)
  184.     mov RE, #VID_BLACK                        ; 2
  185.     DELAY( 120-2 )
  186.  
  187.     ; horizontal sync 0V delay 4.7us
  188.     mov RE, #VID_SYNC                           ; 2
  189.     DELAY( 376-2 )
  190.  
  191.     ; pre burst breezeway 0.6us voltage 0.3V
  192.     mov RE, #VID_BLACK                  ; 2
  193.     DELAY( 48-2 )
  194.  
  195.     ; color burst 9-10cycles 0.3V for 2.5us (skipping data just delay for now)
  196.     mov RE, #VID_COLORBURST_ON            ; 2
  197.     DELAY( 200-2 )                              ; 200-2
  198.    
  199.     ; post burst blanking 0.3V 1.6us
  200.     mov RE, #VID_BLACK                ; 2
  201.     mov pixels, #255                              ; 2   
  202.     DELAY( 128-4 )
  203.  
  204.     ; draw full scanline (53.1us = 4248 cycles)
  205.     mov RE, #VID_BLACK    ; 2
  206.     DELAY( 2124-2 )  ; 4248 is one full scanline, delay function would overflow with that amount
  207.     DELAY( 2124-4 )  ; Really need to build a better delay function that supports longer delays
  208.     djnz scanline, :overscan_top    ; 2/4
  209.  
  210.     jmp     vidloop     ; 3

Comments are closed.

 
 
 
© 2005-2007 Gary Preston
Figment Games is hosted by DreamHost
Entries (RSS) and Comments (RSS).