Advertisement
Guest User

NTSC_Interface.ASM V1.00

a guest
Dec 30th, 2012
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.29 KB | None | 0 0
  1. ;---------------------------------------------------;
  2. ;---------------------------------------------------;
  3. ; Name: NTSC_Interface.ASM ;
  4. ; Use: DTI's NTSC Video Interface ;
  5. ;---------------------------------------------------;
  6. ; Copyright: (C)2012 DTI ;
  7. ; Dysfunctional Technologies, Inc. ;
  8. ; All Rights Reserved ;
  9. ;---------------------------------------------------;
  10. ; Author: Timothy S. Carlson ;
  11. ; Dysfunctional Technologies, Inc. ;
  12. ; Date: December 30, 2012 ;
  13. ; Version: V1.00 ;
  14. ;---------------------------------------------------;
  15. ;---------------------------------------------------;
  16. ; WEBSITE: www.dysfunctionaltechnologies.com ;
  17. ; EMAIL: tscarlson@gmail.com ;
  18. ; ;
  19. ; You are welcome to use this code as you see fit, ;
  20. ; however - not to be used in for-profit products ;
  21. ; unless we have come to a monetary agreement. ;
  22. ; ;
  23. ; If this code is used, credit given is appreciated ;
  24. ;---------------------------------------------------;
  25. ;---------------------------------------------------;
  26. ; VERSION LOG: ;
  27. ; V1.00: Created ;
  28. ;---------------------------------------------------;
  29. ;---------------------------------------------------;
  30.  
  31. ;---------------------------------------------------;
  32. ; Project Defines ;
  33. ;---------------------------------------------------;
  34. #DEFINE _NTSC_INTERFACE.ASM_ ;
  35. ;---------------------------------------------------;
  36.  
  37. ;---------------------------------------------------;
  38. ; Includes ;
  39. ;---------------------------------------------------;
  40. ; This file has some common defines (TRUE, FALSE, ;
  41. ; etc.) used throughout the program. It also has the;
  42. ; CONFIGURATION_BITS settings for the PIC, which are;
  43. ; only processed in the module that has the define ;
  44. ; _MAIN_MODULE_. ;
  45. ;---------------------------------------------------;
  46. #INCLUDE Common.INC ;
  47. #INCLUDE NTSC_Interface.INC ;
  48. ;---------------------------------------------------;
  49.  
  50. ;---------------------------------------------------;
  51. ; I've pushed the VIDEO_BUFFER to H'2030', since the;
  52. ; field has become smaller (32x48 vs 32x56). The ;
  53. ; required size of the VIDEO_BUFFER is also less, so;
  54. ; this will give up 32 more bytes of data memory for;
  55. ; use in game programming. ;
  56. ;---------------------------------------------------;
  57. ; We don't access the Video_BufferX arrays directly,;
  58. ; we use LINEAR PAGE memory through the FSR register;
  59. ; LINEAR PAGE memory groups the data memory at 0x20,;
  60. ; 0xA0, and Ox120 into a contiguous linear page. ;
  61. ; Note that the shared memory (at the top 16 bytes ;
  62. ; of each page) is NOT included in the LINEAR PAGE ;
  63. ; memory mapping. ;
  64. ;---------------------------------------------------;
  65. ; MEMORY MAP - LINEAR PAGE MEMORY - 240 bytes total ;
  66. ; 0x2000-0x204F - 0x020-0x06F 80 bytes ;
  67. ; 0x2050-0x20BF - 0x0A0-0x0EF 80 bytes ;
  68. ; 0x20A0-0x20EF - 0x120-0x16F 80 bytes ;
  69. ;---------------------------------------------------;
  70. ; Since out max lines (now) is 48, we need 48x8 ;
  71. ; (192) bytes of memory for the screen buffer. This ;
  72. ; leaves us with 48 bytes of data memory for program;
  73. ; variables, plus the 16 in shared memory for 64! ;
  74. ;---------------------------------------------------;
  75. ;NTSC_DATA_1 UDATA H'050' ;
  76. ;---------------------------------------------------;
  77. ;---------------------------------------------------;
  78. ;Video_Buffer1 res 32 ; 50-6F
  79. ;---------------------------------------------------;
  80. ;---------------------------------------------------;
  81. NTSC_DATA_2 UDATA H'0A0' ;
  82. ;---------------------------------------------------;
  83. Video_Buffer2 res 80 ; A0-EF
  84. ;---------------------------------------------------;
  85. ;---------------------------------------------------;
  86. NTSC_DATA_3 UDATA H'120' ;
  87. ;---------------------------------------------------;
  88. Video_Buffer3 res 80 ; 120-6F
  89. ;---------------------------------------------------;
  90. ;---------------------------------------------------;
  91.  
  92. ;---------------------------------------------------;
  93. ;---------------------------------------------------;
  94. NTSC_DATA_S UDATA_SHR H'070' ;
  95. ;---------------------------------------------------;
  96. Video_Status res 1 ; 70
  97. VTemp res 1 ; 71
  98. Line_Count res 1 ; 72
  99. Repeat_Count res 1 ; 73
  100. Vid_Timing res 1 ; 74
  101. VSync_Count res 1 ; 75
  102. #IF (_AUDIO_ENABLED_ == TRUE) ;
  103. Audio_Count res 1 ; 76
  104. Audio_Reload res 1 ; 77
  105. Audio_Dur_HI res 1 ; 78
  106. Audio_Dur_LO res 1 ; 79
  107. #ENDIF ; (_AUDIO_ENABLED_ == TRUE) ;
  108. ;---------------------------------------------------;
  109. ;---------------------------------------------------;
  110.  
  111. ;---------------------------------------------------;
  112. ;---------------------------------------------------;
  113. ; Interrupt Vector Code ;
  114. ;---------------------------------------------------;
  115. INT_VECT CODE H'004' ;
  116. ;---------------------------------------------------;
  117. _IV_Entry: ;
  118. ;-----------------------------------------------;
  119. ; Toggle the BLACK/SYNC bit ;
  120. ;-----------------------------------------------;
  121. MOVLW VIDEO_1 ;
  122. XORWF PORTA, F ;
  123. ;-----------------------------------------------;
  124. ;
  125. ;-----------------------------------------------;
  126. ; Load current timing into TMR0, load next ;
  127. ; timing into current timing. ;
  128. ;-----------------------------------------------;
  129. MOVFW Vid_Timing ;
  130. MOVWF TMR0 ;
  131. ;-----------------------------------------------;
  132. _IV_Exit: ;
  133. BCF INTCON, TMR0IF ;
  134. RETFIE ;
  135. ;---------------------------------------------------;
  136. ;---------------------------------------------------;
  137.  
  138. ;---------------------------------------------------;
  139. ;---------------------------------------------------;
  140. NTSC_CODE CODE ;
  141. ;---------------------------------------------------;
  142.  
  143. ;---------------------------------------------------;
  144. _NTSC_Initialize_Subsystem: ;
  145. ;---;-----------------------------------------------;
  146. ; Initialize Hardware ;
  147. ;-----------------------------------------------;
  148. ; - Oscillator - MUST BE 32MHZ ;
  149. ;-----------------------------------------------;
  150. _NIS_Init_Oscillator: ;
  151. BANKSEL OSCCON ;
  152. MOVLW B'11110000' ; 32Mhz
  153. MOVWF OSCCON ;
  154. ;
  155. BANKSEL OSCSTAT ; Wait for
  156. _NIS_IO_Wait: ;
  157. MOVFW OSCSTAT ; high speed
  158. ANDLW H'79' ; oscillator
  159. XORLW H'59' ; to be
  160. BTFSS STATUS, Z ; stable and
  161. GOTO _NIS_IO_Wait ; locked
  162. ;-----------------------------------------------;
  163. ;
  164. ;-----------------------------------------------;
  165. ; - GPIOs ;
  166. ;-----------------------------------------------;
  167. _NIS_Init_GPIOs: ;
  168. BANKSEL ANSELA ;
  169. BCF ANSELA, VIDEO_0_BIT ;
  170. BCF ANSELA, VIDEO_1_BIT ;
  171. ;
  172. BANKSEL LATA ;
  173. BCF LATA, VIDEO_0_BIT ;
  174. BCF LATA, VIDEO_1_BIT ;
  175. ;
  176. BANKSEL TRISA ;
  177. BCF TRISA, VIDEO_0_BIT ; Set as OUTPUT
  178. BCF TRISA, VIDEO_1_BIT ; Set as OUTPUT
  179. ;
  180. BANKSEL PORTA ;
  181. BCF PORTA, VIDEO_0_BIT ; Set LOW
  182. BCF PORTA, VIDEO_1_BIT ; Set LOW
  183. ;-----------------------------------------------;
  184. ;
  185. ;-----------------------------------------------;
  186. ; - Timer0 ;
  187. ;-----------------------------------------------;
  188. _NIS_Init_Timer0: ;
  189. BANKSEL OPTION_REG ;
  190. BCF OPTION_REG, NOT_WPUEN ;
  191. BCF OPTION_REG, TMR0CS ;
  192. BCF OPTION_REG, PSA ; prescaler to timer0
  193. BCF OPTION_REG, PS2 ;
  194. BCF OPTION_REG, PS1 ; 000 - 250ns
  195. BCF OPTION_REG, PS0 ;
  196. ;
  197. BANKSEL TMR0 ;
  198. MOVLW H'15' ;
  199. MOVWF TMR0 ;
  200. MOVWF Vid_Timing ;
  201. ;
  202. BANKSEL INTCON ;
  203. BCF INTCON, TMR0IF ;
  204. BSF INTCON, TMR0IE ;
  205. BSF INTCON, GIE ;
  206. ;-----------------------------------------------;
  207. ;
  208. ;-----------------------------------------------;
  209. ; - Memory ;
  210. ;-----------------------------------------------;
  211. _NIS_Init_Memory: ;
  212. BANKSEL MEMORY ;
  213. CLRF Video_Status ;
  214. BSF Video_Status, VERTICAL_SYNC_BIT ;
  215. BCF Video_Status, OE_FIELD_BIT ;
  216. #IF (_AUDIO_ENABLED_ == TRUE) ;
  217. BCF Video_Status, AUDIO_ENABLED_BIT ;
  218. MOVLW 0 ;
  219. MOVWF Audio_Count ;
  220. MOVWF Audio_Reload ;
  221. MOVLW H'FF' ;
  222. MOVWF Audio_Dur_LO ;
  223. MOVLW H'FF' ;
  224. MOVWF Audio_Dur_HI ;
  225. #ENDIF ; (_AUDIO_ENABLED_ == TRUE) ;
  226. ;-----------------------------------------------;
  227. ;
  228. ;-----------------------------------------------;
  229. ; - Video Buffer ;
  230. ;-----------------------------------------------;
  231. _NIS_Clear_Video: ;
  232. PAGESEL _NTSC_Clear_Screen ;
  233. CALL _NTSC_Clear_Screen ;
  234. PAGESEL $ ;
  235. ;-----------------------------------------------;
  236. ;
  237. _NIS_Exit: ;
  238. RETURN ;
  239. ;---------------------------------------------------;
  240.  
  241. ;---------------------------------------------------;
  242. _NTSC_Video: ;
  243. ;---------------------------------------------------;
  244. ; VERTICAL SYNC PULSE Time ;
  245. ; This consists of 6 (or 7) blank half lines, 6 ;
  246. ; inverted half lines, and 6 (or 5) more blank ;
  247. ; half lines. This totals 9 64us lines ;
  248. ; --------------------------------------------- ;
  249. ; NOTE: Timing is CRITICAL for a nice, clean ;
  250. ; display. If you notice the top part of the ;
  251. ; display is skewed or "tearing", your timings ;
  252. ; are wrong and need to be adjusted. Make sure ;
  253. ; you haven't inadvertently dropped a half frame;
  254. ;-----------------------------------------------;
  255. _NV_Vertical_Sync: ;
  256. ;-----------------------------------------------;
  257. PAGESEL _NTSC_Vertical_Sync ;
  258. CALL _NTSC_Vertical_Sync ;
  259. PAGESEL $ ;
  260. ;-----------------------------------------------;
  261. ;
  262. ;-----------------------------------------------;
  263. _NV_Non_Display: ;
  264. ;-----------------------------------------------;
  265. ; These are in the NON-DISPLAY area. Lines 10-21;
  266. ;-----------------------------------------------;
  267. PAGESEL _NTSC_Blank_Line_10 ;
  268. CALL _NTSC_Blank_Line_10 ;
  269. PAGESEL _NTSC_Blank_Line_11 ;
  270. CALL _NTSC_Blank_Line_11 ;
  271. PAGESEL _NTSC_Blank_Line_12 ;
  272. CALL _NTSC_Blank_Line_12 ;
  273. PAGESEL _NTSC_Blank_Line_13 ;
  274. CALL _NTSC_Blank_Line_13 ;
  275. PAGESEL _NTSC_Blank_Line_14 ;
  276. CALL _NTSC_Blank_Line_14 ;
  277. PAGESEL _NTSC_Blank_Line_15 ;
  278. CALL _NTSC_Blank_Line_15 ;
  279. PAGESEL _NTSC_Blank_Line_16 ;
  280. CALL _NTSC_Blank_Line_16 ;
  281. PAGESEL _NTSC_Blank_Line_17 ;
  282. CALL _NTSC_Blank_Line_17 ;
  283. PAGESEL _NTSC_Blank_Line_18 ;
  284. CALL _NTSC_Blank_Line_18 ;
  285. PAGESEL _NTSC_Blank_Line_19 ;
  286. CALL _NTSC_Blank_Line_19 ;
  287. PAGESEL _NTSC_Blank_Line_20 ;
  288. CALL _NTSC_Blank_Line_20 ;
  289. PAGESEL _NTSC_Blank_Line_21 ;
  290. CALL _NTSC_Blank_Line_21 ;
  291. ;-----------------------------------------------;
  292. ;
  293. ;-----------------------------------------------;
  294. _NV_Pre_Blanking: ;
  295. ;-----------------------------------------------;
  296. PAGESEL _NTSC_Blank_Line_22 ;
  297. CALL _NTSC_Blank_Line_22 ;
  298. PAGESEL _NTSC_Blank_Line_23 ;
  299. CALL _NTSC_Blank_Line_23 ;
  300. PAGESEL _NTSC_Blank_Line_24 ;
  301. CALL _NTSC_Blank_Line_24 ;
  302. PAGESEL _NTSC_Blank_Line_25 ;
  303. CALL _NTSC_Blank_Line_25 ;
  304. PAGESEL _NTSC_Blank_Line_26 ;
  305. CALL _NTSC_Blank_Line_26 ;
  306. PAGESEL _NTSC_Blank_Line_27 ;
  307. CALL _NTSC_Blank_Line_27 ;
  308. PAGESEL _NTSC_Blank_Line_28 ;
  309. CALL _NTSC_Blank_Line_28 ;
  310. PAGESEL _NTSC_Blank_Line_29 ;
  311. CALL _NTSC_Blank_Line_29 ;
  312. PAGESEL _NTSC_Blank_Line_30 ;
  313. CALL _NTSC_Blank_Line_30 ;
  314. PAGESEL _NTSC_Blank_Line_31 ;
  315. CALL _NTSC_Blank_Line_31 ;
  316. PAGESEL _NTSC_Blank_Line_32 ;
  317. CALL _NTSC_Blank_Line_32 ;
  318. PAGESEL _NTSC_Blank_Line_33 ;
  319. CALL _NTSC_Blank_Line_33 ;
  320. PAGESEL _NTSC_Blank_Line_34 ;
  321. CALL _NTSC_Blank_Line_34 ;
  322. PAGESEL _NTSC_Blank_Line_35 ;
  323. CALL _NTSC_Blank_Line_35 ;
  324. PAGESEL _NTSC_Blank_Line_36 ;
  325. CALL _NTSC_Blank_Line_36 ;
  326. PAGESEL _NTSC_Blank_Line_37 ;
  327. CALL _NTSC_Blank_Line_37 ;
  328. PAGESEL _NTSC_Blank_Line_38 ;
  329. CALL _NTSC_Blank_Line_38 ;
  330. PAGESEL _NTSC_Blank_Line_39 ;
  331. CALL _NTSC_Blank_Line_39 ;
  332. PAGESEL _NTSC_Blank_Line_40 ;
  333. CALL _NTSC_Blank_Line_40 ;
  334. PAGESEL _NTSC_Blank_Line_41 ;
  335. CALL _NTSC_Blank_Line_41 ;
  336. PAGESEL _NTSC_Blank_Line_42 ;
  337. CALL _NTSC_Blank_Line_42 ;
  338. PAGESEL _NTSC_Blank_Line_43 ;
  339. CALL _NTSC_Blank_Line_43 ;
  340. PAGESEL _NTSC_Blank_Line_44 ;
  341. CALL _NTSC_Blank_Line_44 ;
  342. PAGESEL $ ;
  343. ;-----------------------------------------------;
  344. ;
  345. ;-----------------------------------------------;
  346. _NV_Video_Processing: ;
  347. ;-----------------------------------------------;
  348. ; 192 lines, fed by the VIDEO_BUFFER 45-236 ;
  349. ;-----------------------------------------------;
  350. PAGESEL _NTSC_Data_Lines ;
  351. CALL _NTSC_Data_Lines ;
  352. PAGESEL $ ;
  353. ;-----------------------------------------------;
  354. ;
  355. ;-----------------------------------------------;
  356. _NV_Post_Blanking: ;
  357. ;-----------------------------------------------;
  358. PAGESEL _NTSC_Blank_Line_237 ;
  359. CALL _NTSC_Blank_Line_237 ;
  360. PAGESEL _NTSC_Blank_Line_238 ;
  361. CALL _NTSC_Blank_Line_238 ;
  362. PAGESEL _NTSC_Blank_Line_239 ;
  363. CALL _NTSC_Blank_Line_239 ;
  364. PAGESEL _NTSC_Blank_Line_240 ;
  365. CALL _NTSC_Blank_Line_240 ;
  366. PAGESEL _NTSC_Blank_Line_241 ;
  367. CALL _NTSC_Blank_Line_241 ;
  368. PAGESEL _NTSC_Blank_Line_242 ;
  369. CALL _NTSC_Blank_Line_242 ;
  370. PAGESEL _NTSC_Blank_Line_243 ;
  371. CALL _NTSC_Blank_Line_243 ;
  372. PAGESEL _NTSC_Blank_Line_244 ;
  373. CALL _NTSC_Blank_Line_244 ;
  374. PAGESEL _NTSC_Blank_Line_245 ;
  375. CALL _NTSC_Blank_Line_245 ;
  376. PAGESEL _NTSC_Blank_Line_246 ;
  377. CALL _NTSC_Blank_Line_246 ;
  378. PAGESEL _NTSC_Blank_Line_247 ;
  379. CALL _NTSC_Blank_Line_247 ;
  380. PAGESEL _NTSC_Blank_Line_248 ;
  381. CALL _NTSC_Blank_Line_248 ;
  382. PAGESEL _NTSC_Blank_Line_249 ;
  383. CALL _NTSC_Blank_Line_249 ;
  384. PAGESEL _NTSC_Blank_Line_250 ;
  385. CALL _NTSC_Blank_Line_250 ;
  386. PAGESEL _NTSC_Blank_Line_251 ;
  387. CALL _NTSC_Blank_Line_251 ;
  388. PAGESEL _NTSC_Blank_Line_252 ;
  389. CALL _NTSC_Blank_Line_252 ;
  390. PAGESEL _NTSC_Blank_Line_253 ;
  391. CALL _NTSC_Blank_Line_253 ;
  392. PAGESEL _NTSC_Blank_Line_254 ;
  393. CALL _NTSC_Blank_Line_254 ;
  394. PAGESEL _NTSC_Blank_Line_255 ;
  395. CALL _NTSC_Blank_Line_255 ;
  396. PAGESEL _NTSC_Blank_Line_256 ;
  397. CALL _NTSC_Blank_Line_256 ;
  398. PAGESEL _NTSC_Blank_Line_257 ;
  399. CALL _NTSC_Blank_Line_257 ;
  400. PAGESEL _NTSC_Blank_Line_258 ;
  401. CALL _NTSC_Blank_Line_258 ;
  402. PAGESEL _NTSC_Blank_Line_259 ;
  403. CALL _NTSC_Blank_Line_259 ;
  404. PAGESEL _NTSC_Blank_Line_260 ;
  405. CALL _NTSC_Blank_Line_260 ;
  406. PAGESEL _NTSC_Blank_Line_261 ;
  407. CALL _NTSC_Blank_Line_261 ;
  408. PAGESEL _NTSC_Blank_Line_262 ;
  409. CALL _NTSC_Blank_Line_262 ;
  410. PAGESEL $ ;
  411. ;-----------------------------------------------;
  412. ;
  413. GOTO _NTSC_Video ;
  414. ;---------------------------------------------------;
  415.  
  416. ;---------------------------------------------------;
  417. _NTSC_Vertical_Sync: ;
  418. ;---------------------------------------------------;
  419. ;-----------------------------------------------;
  420. ; Set the VERTICAL_SYNC flag, to keep audio from;
  421. ; playing during this time and possibly ;
  422. ; disrupting the video timing ;
  423. ;-----------------------------------------------;
  424. BSF Video_Status, VERTICAL_SYNC_BIT ;
  425. ;-----------------------------------------------;
  426. ; Increment the vertical sync count. This is ;
  427. ; used as a timer by the BANNER routines ;
  428. ;-----------------------------------------------;
  429. INCF VSync_Count, F ;
  430. ;-----------------------------------------------;
  431. ;
  432. ;-----------------------------------------------;
  433. ; Odd or Even field? ;
  434. ;-----------------------------------------------;
  435. BTFSC Video_Status, OE_FIELD_BIT ;
  436. GOTO _NVS_Pre_Equalizing_EVEN ;
  437. ;-----------------------------------------------;
  438. ;
  439. _NVS_Pre_Equalizing_ODD: ;
  440. ;-----------------------------------------------;
  441. ; THESE 6 30us pulse are the beginning of the ;
  442. ; ODD FIELD VERTICAL SYNC. The previous ;
  443. ; 4us_SYNC_60us_LINE was LINE #262 of the EVEN ;
  444. ; FIELD. Together the 1st two 2us_SYNC_30us_LINE;
  445. ; are LINE #1 of the ODD FIELD ;
  446. ;-----------------------------------------------;
  447. PAGESEL _BLACK_2us_SYNC_30us_LINE ;
  448. CALL _BLACK_2us_SYNC_30us_LINE ;
  449. DEBUG_VSYNC_PULSE ;
  450. CALL _BLACK_2us_SYNC_30us_LINE ;
  451. CALL _BLACK_2us_SYNC_30us_LINE ;
  452. CALL _BLACK_2us_SYNC_30us_LINE ;
  453. CALL _BLACK_2us_SYNC_30us_LINE ;
  454. CALL _BLACK_2us_SYNC_30us_LINE ;
  455. PAGESEL $ ;
  456. ;-----------------------------------------------;
  457. GOTO _NVS_Vertical_Syncronism ;
  458. ;-----------------------------------------------;
  459. ;
  460. _NVS_Pre_Equalizing_EVEN: ;
  461. ;-----------------------------------------------;
  462. ; The following two 30US lines are considered to;
  463. ; be one LINE from the previous (ODD) FIELD. ;
  464. ; Together they are LINE #263 of the ODD FIELD ;
  465. ;-----------------------------------------------;
  466. PAGESEL _BLACK_4us_SYNC_30us_LINE ;
  467. CALL _BLACK_4us_SYNC_30us_LINE ;
  468. PAGESEL _BLACK_2us_SYNC_30us_LINE ;
  469. CALL _BLACK_2us_SYNC_30us_LINE ;
  470. PAGESEL $ ;
  471. ;-----------------------------------------------;
  472. ; These 5 30us pulse are the beginning of the ;
  473. ; EVEN FIELD VERTICAL SYNC. Together the 1st two;
  474. ; 2us_SYNC_30us_LINEs are LINE #1 of the EVEN ;
  475. ; FIELD. ;
  476. ;-----------------------------------------------;
  477. PAGESEL _BLACK_2us_SYNC_30us_LINE ;
  478. CALL _BLACK_2us_SYNC_30us_LINE ;
  479. DEBUG_VSYNC_PULSE ;
  480. CALL _BLACK_2us_SYNC_30us_LINE ;
  481. CALL _BLACK_2us_SYNC_30us_LINE ;
  482. CALL _BLACK_2us_SYNC_30us_LINE ;
  483. CALL _BLACK_2us_SYNC_30us_LINE ;
  484. PAGESEL $ ;
  485. ;-----------------------------------------------;
  486. ;
  487. _NVS_Vertical_Syncronism: ;
  488. ;-----------------------------------------------;
  489. ; 5 inverted 30us lines w/ 4us syncs ;
  490. ; Standard for both ODD and EVEN FIELDS ;
  491. ;-----------------------------------------------;
  492. PAGESEL _INVERTED_30us_SYNC_4us_LINE ;
  493. CALL _INVERTED_30us_SYNC_4us_LINE ;
  494. CALL _INVERTED_30us_SYNC_4us_LINE ;
  495. CALL _INVERTED_30us_SYNC_4us_LINE ;
  496. CALL _INVERTED_30us_SYNC_4us_LINE ;
  497. CALL _INVERTED_30us_SYNC_4us_LINE ;
  498. CALL _INVERTED_30us_SYNC_4us_LINE ;
  499. PAGESEL $ ;
  500. ;-----------------------------------------------;
  501. ;
  502. ;-----------------------------------------------;
  503. BTFSC Video_Status, OE_FIELD_BIT ;
  504. GOTO _NVS_Post_Equalizing_EVEN ;
  505. ;-----------------------------------------------;
  506. ;
  507. _NVS_Post_Equalizing_ODD: ;
  508. ;-----------------------------------------------;
  509. PAGESEL _BLACK_2us_SYNC_30us_LINE ;
  510. CALL _BLACK_2us_SYNC_30us_LINE ;
  511. CALL _BLACK_2us_SYNC_30us_LINE ;
  512. CALL _BLACK_2us_SYNC_30us_LINE ;
  513. CALL _BLACK_2us_SYNC_30us_LINE ;
  514. CALL _BLACK_2us_SYNC_30us_LINE ;
  515. CALL _BLACK_2us_SYNC_30us_LINE ;
  516. PAGESEL $ ;
  517. ;-----------------------------------------------;
  518. ; This is the END of the ODD FIELD VERTICAL SYNC;
  519. ; The next 4us_SYNC_60us_LINE is LINE #10 ;
  520. ;-----------------------------------------------;
  521. GOTO _NVS_Exit ;
  522. ;-----------------------------------------------;
  523. ;
  524. _NVS_Post_Equalizing_EVEN: ;
  525. ;-----------------------------------------------;
  526. PAGESEL _BLACK_2us_SYNC_30us_LINE ;
  527. CALL _BLACK_2us_SYNC_30us_LINE ;
  528. CALL _BLACK_2us_SYNC_30us_LINE ;
  529. CALL _BLACK_2us_SYNC_30us_LINE ;
  530. CALL _BLACK_2us_SYNC_30us_LINE ;
  531. CALL _BLACK_2us_SYNC_30us_LINE ;
  532. ;-----------------------------------------------;
  533. ; The following 2us_SYNC_60us_LINE is part of ;
  534. ; VERTICAL SYNC. It is LINE #9 off the EVEN ;
  535. ; FIELD. The next 4us_SYNC_60us_LINE is LINE #10;
  536. ;-----------------------------------------------;
  537. PAGESEL _BLACK_2us_SYNC_60us_LINE ;
  538. CALL _BLACK_2us_SYNC_60us_LINE ;
  539. PAGESEL $ ;
  540. ;-----------------------------------------------;
  541. ;
  542. _NVS_Exit: ;
  543. ;-----------------------------------------------;
  544. ; Toggle the OE_FIELD flag ;
  545. ;-----------------------------------------------;
  546. MOVLW OE_FIELD ;
  547. XORWF Video_Status, F ;
  548. ;-----------------------------------------------;
  549. ;
  550. ;-----------------------------------------------;
  551. ; Clear the VERTICAL_SYNC flag, so that audio ;
  552. ; can continue playing ;
  553. ;-----------------------------------------------;
  554. BCF Video_Status, VERTICAL_SYNC_BIT ;
  555. ;-----------------------------------------------;
  556. ;
  557. RETURN ;
  558. ;---------------------------------------------------;
  559.  
  560. ;---------------------------------------------------;
  561. _NTSC_Data_Lines: ;
  562. ;---------------------------------------------------;
  563. ; Note: This will generate 192 60us data lines with ;
  564. ; data from the VIDEO buffer. Each lines is repeated;
  565. ; 4 times, so the video_buffer is 48x32 bits in size;
  566. ; or 48x4 bytes, or 192 bytes total ;
  567. ;---------------------------------------------------;
  568. ; Set up of video buffer pointer and line count ;
  569. ;-----------------------------------------------;
  570. MOVLW LOW VIDEO_BUFFER_START ;
  571. MOVWF FSR1L ;
  572. MOVLW HIGH VIDEO_BUFFER_START ;
  573. MOVWF FSR1H ;
  574. ;
  575. MOVLW NUM_LINES ;
  576. MOVWF Line_Count ;
  577. ;-----------------------------------------------;
  578. ;
  579. ;-----------------------------------------------;
  580. ; We repeat each line 4 times, since we don't ;
  581. ; have a big enough video buffer for 192 lines ;
  582. ;-----------------------------------------------;
  583. _NDL_Next_Line: ;
  584. MOVLW 4 ;
  585. MOVWF Repeat_Count ;
  586. _NDL_Repeat_Line: ;
  587. MOVLW H'FC' ;
  588. ANDWF FSR1L, F ;
  589. ;-----------------------------------------------;
  590. ;
  591. ;-----------------------------------------------;
  592. ; 60us Line Generation ;
  593. ;-----------------------------------------------;
  594. PAGESEL _BLACK_4us_SYNC_60us_LINE_BPorch ;
  595. CALL _BLACK_4us_SYNC_60us_LINE_BPorch ;
  596. PAGESEL $ ;
  597. VDELAY 6 ;
  598. ;-----------------------------------------------;
  599. ;
  600. ;-----------------------------------------------;
  601. ; This is where the 32 bits of data are actually;
  602. ; send out over the video signal ;
  603. ;-----------------------------------------------;
  604. DO_BIT 7, 6 ;
  605. DO_BIT 6, 6 ;
  606. DO_BIT 5, 6 ;
  607. DO_BIT 4, 6 ;
  608. DO_BIT 3, 6 ;
  609. DO_BIT 2, 6 ;
  610. DO_BIT 1, 6 ;
  611. DO_BIT 0, 5 ;
  612. ;-----------------------------------------------;
  613. DO_BIT 7, 6 ;
  614. DO_BIT 6, 6 ;
  615. DO_BIT 5, 6 ;
  616. DO_BIT 4, 6 ;
  617. DO_BIT 3, 6 ;
  618. DO_BIT 2, 6 ;
  619. DO_BIT 1, 6 ;
  620. DO_BIT 0, 5 ;
  621. ;-----------------------------------------------;
  622. DO_BIT 7, 6 ;
  623. DO_BIT 6, 6 ;
  624. DO_BIT 5, 6 ;
  625. DO_BIT 4, 6 ;
  626. DO_BIT 3, 6 ;
  627. DO_BIT 2, 6 ;
  628. DO_BIT 1, 6 ;
  629. DO_BIT 0, 5 ;
  630. ;-----------------------------------------------;
  631. DO_BIT 7, 6 ;
  632. DO_BIT 6, 6 ;
  633. DO_BIT 5, 6 ;
  634. DO_BIT 4, 6 ;
  635. DO_BIT 3, 6 ;
  636. DO_BIT 2, 6 ;
  637. DO_BIT 1, 6 ;
  638. DO_BIT 0, 5 ;
  639. ;-----------------------------------------------;
  640. ;
  641. ;-----------------------------------------------;
  642. ; Back porch - between this and the front porch,;
  643. ; this 'frames' the video on your TV (hopefully);
  644. ; --------------------------------------------- ;
  645. ; NOTE: this VDELAY and NOPs fleshes out the ;
  646. ; data line to 60us ;
  647. ;-----------------------------------------------;
  648. VDELAY 1 ;
  649. BCF PORTA, VIDEO_0_BIT ;
  650. ;-----------------------------------------------;
  651. ;
  652. ADDFSR FSR1, -4 ;
  653. DECFSZ Repeat_Count, F ;
  654. GOTO _NDL_Repeat_Line ;
  655. ;
  656. ;-----------------------------------------------;
  657. ; 192 lines of information to transmit ;
  658. ; so the screen size is 32x192. But we transmit ;
  659. ; each line 4 times, so it's actually 32x48 ;
  660. ;-----------------------------------------------;
  661. _NDL_Next_Data: ;
  662. ;-----------------------------------------------;
  663. ADDFSR FSR1, 4 ;
  664. DECFSZ Line_Count, F ;
  665. GOTO _NDL_Next_Line ;
  666. ;
  667. RETURN ;
  668. ;---------------------------------------------------;
  669.  
  670. ;---------------------------------------------------;
  671. _BLACK_2us_SYNC_30us_LINE: ;
  672. ;---------------------------------------------------;
  673. START_TIMING SIG_2US, 0 ;
  674. START_TIMING SIG_30US, 1 ;
  675. RETURN ;
  676. ;---------------------------------------------------;
  677.  
  678. ;---------------------------------------------------;
  679. _BLACK_4us_SYNC_30us_LINE: ;
  680. ;---------------------------------------------------;
  681. START_TIMING SIG_4US, 0 ;
  682. START_TIMING SIG_30US, 1 ;
  683. RETURN ;
  684. ;---------------------------------------------------;
  685.  
  686. ;---------------------------------------------------;
  687. _INVERTED_30us_SYNC_4us_LINE: ;
  688. ;---------------------------------------------------;
  689. START_TIMING SIG_30US, 0 ;
  690. START_TIMING SIG_4US, 1 ;
  691. RETURN ;
  692. ;---------------------------------------------------;
  693.  
  694. ;---------------------------------------------------;
  695. _BLACK_2us_SYNC_60us_LINE: ;
  696. ;---------------------------------------------------;
  697. START_TIMING SIG_2US, 0 ;
  698. START_TIMING SIG_60US, 1 ;
  699. RETURN ;
  700. ;---------------------------------------------------;
  701.  
  702. ;---------------------------------------------------;
  703. _BLACK_4us_SYNC_60us_LINE: ;
  704. ;---------------------------------------------------;
  705. START_TIMING SIG_4US, 0 ;
  706. START_TIMING SIG_60US, 1 ;
  707. RETURN ;
  708. ;---------------------------------------------------;
  709.  
  710. ;---------------------------------------------------;
  711. _BLACK_4us_SYNC_60us_LINE_BPorch: ;
  712. ;---------------------------------------------------;
  713. START_TIMING SIG_4US, 0 ;
  714. START_TIMING SIG_60US, 1 ;
  715. ; VDELAY 11 ; 9 ;
  716. VDELAY 5 ;
  717. NOP ;
  718. RETURN ;
  719. ;---------------------------------------------------;
  720.  
  721. ;---------------------------------------------------;
  722. _WHITE_4us_SYNC_60us_LINE: ;
  723. ;---------------------------------------------------;
  724. START_TIMING SIG_4US, 0 ;
  725. START_TIMING SIG_60US, 1 ;
  726. BCF PORTA, VIDEO_0_BIT ;
  727. ; VDELAY 13 ;
  728. VDELAY 7 ;
  729. NOP ;
  730. NOP ;
  731. BSF PORTA, VIDEO_0_BIT ;
  732. VDELAY 129 ;
  733. NOP ;
  734. NOP ;
  735. BCF PORTA, VIDEO_0_BIT ;
  736. RETURN ;
  737. ;---------------------------------------------------;
  738.  
  739. ;---------------------------------------------------;
  740. _NTSC_Clear_Screen: ;
  741. ;---------------------------------------------------;
  742. ;-----------------------------------------------;
  743. ; Set up the pointer to the video buffer ;
  744. ;-----------------------------------------------;
  745. MOVLW HIGH VIDEO_BUFFER_START ;
  746. MOVWF FSR1H ;
  747. MOVLW LOW VIDEO_BUFFER_START ;
  748. MOVWF FSR1L ;
  749. ;-----------------------------------------------;
  750. ;
  751. ;-----------------------------------------------;
  752. ; Set up the number of bytes to transfer ;
  753. ;-----------------------------------------------;
  754. MOVLW (NUM_LINES * 4) - 16 ;
  755. ADDWF FSR1L, F ;
  756. BTFSC STATUS, C ;
  757. INCF FSR1H, F ;
  758. ;-----------------------------------------------;
  759. ;
  760. ;-----------------------------------------------;
  761. ; Clear the data in the video buffer, 16 bytes ;
  762. ; at a time. Doing it in groups of 16 in a loop,;
  763. ; instead of 1 byte at a time in a loop, speeds ;
  764. ; up the transfer as it cuts out a lot of the ;
  765. ; instruction cycles for the looping mechanism. ;
  766. ;-----------------------------------------------;
  767. CLRW ;
  768. _NCS_Next_16_Bytes: ;
  769. MOVWI 0[INDF1] ;
  770. MOVWI 1[INDF1] ;
  771. MOVWI 2[INDF1] ;
  772. MOVWI 3[INDF1] ;
  773. MOVWI 4[INDF1] ;
  774. MOVWI 5[INDF1] ;
  775. MOVWI 6[INDF1] ;
  776. MOVWI 7[INDF1] ;
  777. MOVWI 8[INDF1] ;
  778. MOVWI 9[INDF1] ;
  779. MOVWI 10[INDF1] ;
  780. MOVWI 11[INDF1] ;
  781. MOVWI 12[INDF1] ;
  782. MOVWI 13[INDF1] ;
  783. MOVWI 14[INDF1] ;
  784. MOVWI 15[INDF1] ;
  785. ADDFSR FSR1, -16 ;
  786. MOVLW H'30' ;
  787. XORWF FSR1L, W ;
  788. BTFSS STATUS, Z ;
  789. GOTO _NCS_Next_16_Bytes ;
  790. ;-----------------------------------------------;
  791. ;
  792. RETURN ;
  793. ;---------------------------------------------------;
  794.  
  795. ;---------------------------------------------------;
  796. ;---------------------------------------------------;
  797. END ;
  798. ;---------------------------------------------------;
  799. ;---------------------------------------------------;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement