Advertisement
Guest User

PONG.ASM V3.03

a guest
Dec 21st, 2012
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 71.19 KB | None | 0 0
  1. ;---------------------------------------------------;
  2. ;---------------------------------------------------;
  3. ; Name: PONG.ASM ;
  4. ; Use: DTI's version of the PONG game ;
  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 21, 2012 ;
  13. ; Version: V3.03 ;
  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. ; V3.00: Modified characters, character placement, ;
  28. ; and field to look more like the real PONG ;
  29. ; V3.01: Renamed to PIC-PONG ;
  30. ; - Added 64x224 mode for copyright message ;
  31. ; - Added piezo speaker for sounds ;
  32. ; - Added ball 'slow-down' method ;
  33. ; - Added special dot as court divider ;
  34. ; V3.02: Fixed my program memory page issues. ;
  35. ; - Revamped _Draw_Scores. Cleaner, faster. ;
  36. ; - Redid title - "PONG FOR THE 12F1840" ;
  37. ; - Added _DEBUG_ turns on/off GP2 VSYNC Pulse;
  38. ; - Moved some procs to high page: ;
  39. ; - _Draw_Title ;
  40. ; - _Clear_Court ;
  41. ; - _Copyright ;
  42. ; - _Initialize_System ;
  43. ; - More comments ;
  44. ; - Modified comments discussing the number of;
  45. ; lines, what they do, and how long (in ms) ;
  46. ; for a complete video frame. ;
  47. ; 260 lines * 64us each = 16.64ms per frame ;
  48. ; The current timing is ~16.645ms per frame ;
  49. ; - General Cleanup ;
  50. ; - Added the software version number at the ;
  51. ; bottom right of the screen, in the copy- ;
  52. ; right strip. ;
  53. ; V3.03: Updated version number display to V3.03 ;
  54. ; - Adding more comments ;
  55. ; - Changed references to 'Half_Line' and ;
  56. ; 'Full_Line' in some proc titles to ;
  57. ; '30us_Line' and '60us_Line' respectively. ;
  58. ; (_Blank_Half_Line => _Blank_30us_Line) ;
  59. ; - Moved some line generation procs to high ;
  60. ; page, added PAGESELs, adjusted timings. ;
  61. ; - _Blank_60us_Line ;
  62. ; - _Blank_30us_Line ;
  63. ; - _Special_30us_Line ;
  64. ; - _Inverted_30us_Line ;
  65. ; - Everything possible has been moved to the ;
  66. ; high page of memory, with the exceptions: ;
  67. ; - _Update_Paddle_1 ;
  68. ; - _Update_Paddle_2 ;
  69. ; - _Update_Ball ;
  70. ; I am only using 655 words in the low page ;
  71. ; of program memory now (H'000'-H'28E') out ;
  72. ; of 4096 bytes (2048 words). The high page ;
  73. ; is packed - H'800'-H'D92'. I left the ;
  74. ; above procs in the low page as I will be ;
  75. ; making modifications / enhancements to ;
  76. ; these routines in the near future. ;
  77. ; - NOTE: If you see what appears to be stray ;
  78. ; NOPs strewn about in the code - DON'T ;
  79. ; REMOVE THEM. They are there for video ;
  80. ; timings purposes. Remove them and DOOM! ;
  81. ;---------------------------------------------------;
  82. ;---------------------------------------------------;
  83.  
  84. ;---------------------------------------------------;
  85. ; Project Defines ;
  86. ;---------------------------------------------------;
  87. #DEFINE _PONG.ASM_ ;
  88. #DEFINE _MAIN_MODULE_ ;
  89. ;---------------------------------------------------;
  90. #DEFINE _DEBUG_ FALSE ;
  91. #DEFINE _USE_THUMBSTICKS_ TRUE ;
  92. ;---------------------------------------------------;
  93.  
  94. ;---------------------------------------------------;
  95. ; Includes ;
  96. ;---------------------------------------------------;
  97. #INCLUDE Common.INC ;
  98. ;---------------------------------------------------;
  99.  
  100. ;---------------------------------------------------;
  101. ; Macros ;
  102. ;---------------------------------------------------;
  103. DELAY MACRO DTIME ;
  104. ;-----------------------------------------------;
  105. ; The time munger used EVERYWHERE ;
  106. ;-----------------------------------------------;
  107. MOVLW DTIME ;
  108. MOVWF DTemp ;
  109. DECFSZ DTemp, F ;
  110. GOTO $-1 ;
  111. ;-----------------------------------------------;
  112. ENDM ;
  113. ;
  114. DO_BIT MACRO THISBIT, NOPS ;
  115. ;-----------------------------------------------;
  116. ; Sets the DAC either WHITE or BLACK ;
  117. ; Does a specified delay in NOPs ;
  118. ;-----------------------------------------------;
  119. ; Note that a WHITE bit check is done first and ;
  120. ; then a BLACK bit check. If you reverse the ;
  121. ; order, things look a bit differently on the ;
  122. ; screen. That is because there is a two ;
  123. ; instruction delay and reversing the order ;
  124. ; causes black 'gaps'. This order is most ;
  125. ; visually appealing, at least to me. ;
  126. ;-----------------------------------------------;
  127. BTFSC INDF1, THISBIT ;
  128. BSF PORTA, VIDEO_0_BIT ;
  129. BTFSS INDF1, THISBIT ;
  130. BCF PORTA, VIDEO_0_BIT ;
  131. #IF NOPS > 0 ;
  132. NOP ;
  133. #ENDIF ;
  134. #IF NOPS > 1 ;
  135. NOP ;
  136. #ENDIF ;
  137. #IF NOPS > 2 ;
  138. NOP ;
  139. #ENDIF ;
  140. #IF NOPS > 3 ;
  141. NOP ;
  142. #ENDIF ;
  143. #IF NOPS > 4 ;
  144. NOP ;
  145. #ENDIF ;
  146. #IF NOPS > 5 ;
  147. NOP ;
  148. #ENDIF ;
  149. #IF NOPS > 6 ;
  150. NOP ;
  151. #ENDIF ;
  152. #IF NOPS > 7 ;
  153. NOP ;
  154. #ENDIF ;
  155. #IF NOPS > 8 ;
  156. NOP ;
  157. #ENDIF ;
  158. #IF NOPS > 9 ;
  159. NOP ;
  160. #ENDIF ;
  161. ;-----------------------------------------------;
  162. ENDM ;
  163. ;
  164. SET_SIGNAL MACRO COLOR ;
  165. ;-----------------------------------------------;
  166. ; Sets the 2bit DAC to the desired color ;
  167. ; Both bits are done at once, or else some weird;
  168. ; transitions on the DAC can be seen. Okay if ;
  169. ; just colors (WHITE, GRAY, BLACK), but if a ;
  170. ; sync pulse shows up out context, it can really;
  171. ; mess up the video timings ;
  172. ;-----------------------------------------------;
  173. MOVFW PORTA ;
  174. ANDLW ~(VIDEO_0 | VIDEO_1) ;
  175. IORLW COLOR ;
  176. MOVWF PORTA ;
  177. ;-----------------------------------------------;
  178. ENDM ;
  179. ;
  180. NEG_SYNC_4US MACRO ;
  181. ;-----------------------------------------------;
  182. ; 4us Negative Sync Generation ;
  183. ;-----------------------------------------------;
  184. ; Not only does this do a 4us negative sync, it ;
  185. ; also handles the sound generation during the ;
  186. ; game. Sounds are produced by toggling GPIO1 ;
  187. ; during HSYNCs - if it is toggled during ALL ;
  188. ; HSYNCs, you get a high freq (around 7800hz). ;
  189. ; If every other HSYNC, the freq is around lower;
  190. ;-----------------------------------------------;
  191. ; Don't touch this unless you really understand ;
  192. ; it. I am trying to keep the number of cycles ;
  193. ; equal even when playing sounds. If this is ;
  194. ; changed, it could cause 'tearing' of the ;
  195. ; video when a sound is playing. ;
  196. ;-----------------------------------------------;
  197. SET_SIGNAL COLOR_SYNC ;
  198. BTFSS System_Status, BUZZ_BIT ;
  199. GOTO $+16 ;
  200. DECFSZ Buzz_Count, F ;
  201. GOTO $+16 ;
  202. MOVFW Buzz_Reload ;
  203. MOVWF Buzz_Count ;
  204. BANKSEL TRISA ;
  205. BCF TRISA, RBUTT_BIT ; Set as OUTPUT
  206. BANKSEL MEMORY ;
  207. MOVLW RBUTT ;
  208. XORWF PORTA, F ;
  209. DECFSZ Buzz_Dur_LO, F ;
  210. GOTO $+16 ;
  211. DECFSZ Buzz_Dur_HI, F ;
  212. GOTO $+16 ;
  213. BCF System_Status, BUZZ_BIT ;
  214. GOTO $+15 ;
  215. NOP ;
  216. NOP ;
  217. NOP ;
  218. NOP ;
  219. NOP ;
  220. NOP ;
  221. NOP ;
  222. NOP ;
  223. NOP ;
  224. NOP ;
  225. NOP ;
  226. NOP ;
  227. NOP ;
  228. NOP ;
  229. MOVLW 3 ;
  230. MOVWF DTemp ;
  231. DECFSZ DTemp, F ;
  232. GOTO $-1 ;
  233. NOP ;
  234. ;-----------------------------------------------;
  235. ENDM ;
  236. ;
  237. NEG_SYNC_2US MACRO ;
  238. ;-----------------------------------------------;
  239. ; 2us Negative Sync Generation ;
  240. ;-----------------------------------------------;
  241. ; Used during VSYNC only. ;
  242. ;-----------------------------------------------;
  243. SET_SIGNAL COLOR_SYNC ;
  244. MOVLW 3 ;
  245. MOVWF DTemp ;
  246. DECFSZ DTemp, F ;
  247. GOTO $-1 ;
  248. NOP ;
  249. NOP ;
  250. ;-----------------------------------------------;
  251. ENDM ;
  252. ;
  253. POS_SYNC_2US MACRO ;
  254. ;-----------------------------------------------;
  255. ; 2us Positive Sync Generation ;
  256. ;-----------------------------------------------;
  257. ; Using during VSYNC only. ;
  258. ;-----------------------------------------------;
  259. SET_SIGNAL COLOR_BLACK ;
  260. MOVLW 3 ;
  261. MOVWF DTemp ;
  262. DECFSZ DTemp, F ;
  263. GOTO $-1 ;
  264. NOP ;
  265. NOP ;
  266. ;-----------------------------------------------;
  267. ENDM ;
  268. ;
  269. PLAY_SOUND MACRO FREQUENCY, DURATION ;
  270. ;-----------------------------------------------;
  271. ; This will play a sound of a specified ;
  272. ; frequency for a specified duration ;
  273. ; The lower the frequency number, the higher ;
  274. ; the frequency. Duration is also a function ;
  275. ; of the frequency number, so if frequency goes ;
  276. ; up, adjust the duration down. ;
  277. ;-----------------------------------------------;
  278. ; Sound is played during 4us HORIZONTAL SYNC ;
  279. ; times of the video signal. There is a short ;
  280. ; period during VERTICAL SYNC where nothing is ;
  281. ; done with sound because there ARE no 4us ;
  282. ; HSYNCs. There are 2us HSYNCs during VSYNC, but;
  283. ; there isn't enough time to process the sound ;
  284. ; code without stretching out the 2us HSYNCs ;
  285. ; beyond 2us, and that will mess up the video ;
  286. ; timings. The total time between the last 4us ;
  287. ; HSYNC before VSYNC and the first 4us HSYNC ;
  288. ; after VSYNC is only ~512us, so it's barely ;
  289. ; noticable. After all, it's only a game... ;
  290. ;-----------------------------------------------;
  291. ; NOTE that a FREQUENCY of 0 is treated as a ;
  292. ; frequency of 256. 0<=Freq<=255. The count is ;
  293. ; decremented BEFORE it is checked to be 0, so ;
  294. ; starting with 0 will dec, see 255, continue ;
  295. ; loop. Just so you are warned. ;
  296. ;-----------------------------------------------;
  297. MOVLW FREQUENCY ;
  298. MOVWF Buzz_Count ;
  299. MOVWF Buzz_Reload ;
  300. MOVLW LOW DURATION ;
  301. MOVWF Buzz_Dur_LO ;
  302. MOVLW HIGH DURATION ;
  303. MOVWF Buzz_Dur_HI ;
  304. BSF System_Status, BUZZ_BIT ;
  305. ;-----------------------------------------------;
  306. ENDM ;
  307. ;---------------------------------------------------;
  308.  
  309. ;---------------------------------------------------;
  310. ; Defines ;
  311. ;---------------------------------------------------;
  312. ; You have to chose between using all buttons, ;
  313. ; or using a thumbstick with a button. I might ;
  314. ; be able to figure out a way to automatically ;
  315. ; determine which is connected, but for now you ;
  316. ; will just have to decide which you want, set ;
  317. ; _USE_THUMBSTICKS_ to either TRUE or FALSE, and;
  318. ; re-compile the project. ;
  319. ;-----------------------------------------------;
  320. #IF _USE_THUMBSTICKS_ ;
  321. #DEFINE RJOY H'01' ; Right THUMBSTICK
  322. #DEFINE RJOY_BIT 0 ; GPIO 0 - PIN 7
  323. #DEFINE RBUTT H'02' ; Right BUTTON
  324. #DEFINE RBUTT_BIT 1 ; GPIO 1 - PIN 6
  325. #DEFINE LJOY H'04' ; Left THUMBSTICK
  326. #DEFINE LJOY_BIT 2 ; GPIO 2 - PIN 5
  327. #DEFINE LBUTT H'08' ; Left BUTTON
  328. #DEFINE LBUTT_BIT 3 ; GPIO 3 - PIN 4
  329. #ELSE ;!_USE_THUMBSTICKS_ ;
  330. #DEFINE RBUTT_1 H'01' ; Right BUTTON 1
  331. #DEFINE RBUTT_1_BIT 0 ; GPIO 0 - PIN 7
  332. #DEFINE RBUTT_2 H'02' ; Right BUTTON 2
  333. #DEFINE RBUTT_2_BIT 1 ; GPIO 1 - PIN 6
  334. #DEFINE LBUTT_2 H'04' ; Left BUTTON 2
  335. #DEFINE LBUTT_2_BIT 2 ; GPIO 2 - PIN 5
  336. #DEFINE LBUTT_1 H'08' ; Left BUTTON 1
  337. #DEFINE LBUTT_1_BIT 3 ; GPIO 3 - PIN 4
  338. #ENDIF ;_USE_THUMBSTICKS_ ;
  339. ;-----------------------------------------------;
  340. ;
  341. ;-----------------------------------------------;
  342. ; 2bit DAC definitions. The 2bit DAC is just a ;
  343. ; pair of resistors on two GPIOs, which feeds ;
  344. ; the VIDEO out. ;
  345. ;-----------------------------------------------;
  346. #DEFINE VIDEO_1 H'10' ; 1K ohm
  347. #DEFINE VIDEO_1_BIT 4 ; GPIO 5 - PIN 2
  348. #DEFINE VIDEO_0 H'20' ; 470 ohm
  349. #DEFINE VIDEO_0_BIT 5 ; GPIO 4 - PIN 3
  350. ;
  351. #DEFINE COLOR_WHITE (VIDEO_0 + VIDEO_1) ;
  352. #DEFINE COLOR_BLACK VIDEO_1 ;
  353. #DEFINE COLOR_SYNC 0 ;
  354. ;-----------------------------------------------;
  355. ;
  356. ;-----------------------------------------------;
  357. ; There are 224 lines created during _Data_Lines;
  358. ; However, because of memory limitations, I ;
  359. ; cannot allocate enough memory for the video ;
  360. ; buffer. So - I do have enough memory for 56 ;
  361. ; lines - 1/4 of 224 - so we display each line ;
  362. ; of data 4 times. ;
  363. ;-----------------------------------------------;
  364. #DEFINE MAX_LINES 56 ;
  365. ;-----------------------------------------------;
  366. ;
  367. ;-----------------------------------------------;
  368. ; This is my method of making the game easier or;
  369. ; harder - either I update and draw the ball ;
  370. ; every frame (fast ball), or every other frame ;
  371. ; (not as fast), or every 3rd frame (normal ;
  372. ; ball) or higher for slower. Set MAX_BALL_WAIT ;
  373. ; to the desired speed (1=fast, 2=not as fast, ;
  374. ; 3=normal, 4=slower, etc.). This is hardcoded ;
  375. ; right now, a change requires a recompile. I ;
  376. ; have plans to allocate another precious byte ;
  377. ; of data memory so that the ball speed can be ;
  378. ; changed by a menu item. ;
  379. ;-----------------------------------------------;
  380. #DEFINE DRAW_BALL_BIT 0 ;
  381. #DEFINE MAX_BALL_WAIT 3 ;
  382. ;
  383. ;-----------------------------------------------;
  384. ; Just a bunch of hardcoded starting points, ;
  385. ; sizes, and bit-munching stuff for the various ;
  386. ; graphics. ;
  387. ;-----------------------------------------------;
  388. ; I use the PIC's LINEAR MEMORY scheme to create;
  389. ; a contiguous video buffer. Grab the MicroChip ;
  390. ; documentation and read up. Then go search on ;
  391. ; the web for some docs that will really explain;
  392. ; it for you. ;
  393. ;-----------------------------------------------;
  394. #DEFINE VIDEO_BUFFER_START H'2010' ;
  395. #DEFINE LEFT_SCORE_START H'01' ;
  396. #DEFINE RIGHT_SCORE_START H'02' ;
  397. #DEFINE LEFT_PADDLE_START H'00' ;
  398. #DEFINE LEFT_PADDLE_BIT H'40' ;
  399. #DEFINE LEFT_PADDLE_MASK H'BF' ;
  400. #DEFINE RIGHT_PADDLE_START H'03' ;
  401. #DEFINE RIGHT_PADDLE_BIT H'02' ;
  402. #DEFINE RIGHT_PADDLE_MASK H'FD' ;
  403. #DEFINE PADDLE_SIZE 8 ;
  404. ;---------------------------------------------------;
  405.  
  406. ;---------------------------------------------------;
  407. ;---------------------------------------------------;
  408. USER_DATA_1 UDATA H'020' ;
  409. ;---------------------------------------------------;
  410. Ball_X res 1 ; 20
  411. Ball_Y res 1 ; 21
  412. Ball_Dir_X res 1 ; 22
  413. Ball_Dir_Y res 1 ; 23
  414. Paddle_1_Y res 1 ; 24
  415. Paddle_2_Y res 1 ; 25
  416. Score_1 res 1 ; 26
  417. Score_2 res 1 ; 27
  418. Ball_Wait res 1 ; 28
  419. ;---------------------------------------------------;
  420. ; Bit definitions for System_Status ;
  421. ;---------------------------------------------------;
  422. #DEFINE BUZZ H'01' ;
  423. #DEFINE BUZZ_BIT 0 ;
  424. ;---------------------------------------------------;
  425. System_Status res 1 ; 29
  426. ;---------------------------------------------------;
  427. ; Only 6 bytes left - 2A-2F ;
  428. ;---------------------------------------------------;
  429. ;---------------------------------------------------;
  430.  
  431. ;---------------------------------------------------;
  432. ;---------------------------------------------------;
  433. USER_DATA_2 UDATA_SHR H'070' ;
  434. ;---------------------------------------------------;
  435. Temp1 res 1 ; 70
  436. Temp2 res 1 ; 71
  437. DTemp res 1 ; 72
  438. DL_Count res 1 ; 73
  439. Line_Data res 4 ; 74-77
  440. Byte_Count res 1 ; 78
  441. Line_Count res 1 ; 79
  442. Repeat_Count res 1 ; 7A
  443. Buzz_Count res 1 ; 7B
  444. Buzz_Reload res 1 ; 7C
  445. Buzz_Dur_HI res 1 ; 7D
  446. Buzz_Dur_LO res 1 ; 7E
  447. ;---------------------------------------------------;
  448. ; Only 1 bytes left! - 7F ;
  449. ;---------------------------------------------------;
  450. ;---------------------------------------------------;
  451.  
  452. ;---------------------------------------------------;
  453. ; Reset Vector Code - Entry point from reset ;
  454. ;---------------------------------------------------;
  455. RESET_VECT CODE H'000' ;
  456. ;---------------------------------------------------;
  457. ; Initialize the hardware and memory elements. ;
  458. ; This is a FAR CALL to a proc in the high ;
  459. ; page of Program Memory, so it needs the ;
  460. ; PAGESEL before and after the CALL to properly ;
  461. ; set the upper 2 bits in the program counter. ;
  462. ; I am slowly converting ALL CALLs (and some ;
  463. ; GOTOs) to having PAGESEL before and after, but;
  464. ; the added instruction cycles mess up the video;
  465. ; timings in some spots. To be done slowly and ;
  466. ; surely. ;
  467. ;-----------------------------------------------;
  468. PAGESEL _Initialize_System ;
  469. CALL _Initialize_System ;
  470. PAGESEL $ ;
  471. ;-----------------------------------------------;
  472. ; _Next_Frame is in the high page of Program ;
  473. ; Memory. This is the only GOTO that is in the ;
  474. ; code that requires PAGESEL. ;
  475. ;-----------------------------------------------;
  476. PAGESEL _Next_Frame ;
  477. GOTO _Next_Frame ;
  478. ;---------------------------------------------------;
  479.  
  480. ;---------------------------------------------------;
  481. ; Interrupt Vector Code ;
  482. ; Since we are not using or desire to use interrupts;
  483. ; this is not needed. ;
  484. ;---------------------------------------------------;
  485. ; INT_VECT CODE H'004' ;
  486. ;---------------------------------------------------;
  487.  
  488. ;---------------------------------------------------;
  489. ; User Code in the low page of Program Memory ;
  490. ; More user code (USER_CODE_2) can be found in the ;
  491. ; high page of Program Memory, starting at H'800' ;
  492. ;---------------------------------------------------;
  493. USER_CODE_1 CODE ;
  494. ;---------------------------------------------------;
  495. _Update_Paddle_1: ;
  496. ;---------------------------------------------------;
  497. ; Note: This is a 60us line routine. ;
  498. ;---------------------------------------------------;
  499. NOP ;
  500. ;-----------------------------------------------;
  501. ; 4us Negative Sync Generation ;
  502. ;-----------------------------------------------;
  503. NEG_SYNC_4US ;
  504. ;-----------------------------------------------;
  505. ;
  506. ;-----------------------------------------------;
  507. ; 60us Blank Signal Generation ;
  508. ; But with lots of calculations going on ;
  509. ;-----------------------------------------------;
  510. SET_SIGNAL COLOR_BLACK ;
  511. ;
  512. BANKSEL OPTION_REG ;
  513. BCF OPTION_REG, PSA ;
  514. BANKSEL TMR0 ;
  515. CLRF TMR0 ;
  516. ;
  517. _UP1_Clear_Paddle: ;
  518. MOVFW Paddle_1_Y ;
  519. ADDWF Paddle_1_Y, W ;
  520. ADDWF Paddle_1_Y, W ;
  521. ADDWF Paddle_1_Y, W ;
  522. ADDLW LOW VIDEO_BUFFER_START + LEFT_PADDLE_START;
  523. MOVWF FSR1L ;
  524. MOVLW HIGH VIDEO_BUFFER_START ;
  525. MOVWF FSR1H ;
  526. MOVIW 0[INDF1] ;
  527. ANDLW LEFT_PADDLE_MASK ;
  528. MOVWI 0[INDF1] ;
  529. MOVIW 4[INDF1] ;
  530. ANDLW LEFT_PADDLE_MASK ;
  531. MOVWI 4[INDF1] ;
  532. MOVIW 8[INDF1] ;
  533. ANDLW LEFT_PADDLE_MASK ;
  534. MOVWI 8[INDF1] ;
  535. MOVIW 12[INDF1] ;
  536. ANDLW LEFT_PADDLE_MASK ;
  537. MOVWI 12[INDF1] ;
  538. MOVIW 16[INDF1] ;
  539. ANDLW LEFT_PADDLE_MASK ;
  540. MOVWI 16[INDF1] ;
  541. MOVIW 20[INDF1] ;
  542. ANDLW LEFT_PADDLE_MASK ;
  543. MOVWI 20[INDF1] ;
  544. MOVIW 24[INDF1] ;
  545. ANDLW LEFT_PADDLE_MASK ;
  546. MOVWI 24[INDF1] ;
  547. MOVIW 28[INDF1] ;
  548. ANDLW LEFT_PADDLE_MASK ;
  549. MOVWI 28[INDF1] ;
  550. ;
  551. #IF _USE_THUMBSTICKS_ ;
  552. _UP1_Update: ;
  553. ;-----------------------------------------------;
  554. ; ADC Magic (Channel 0) ;
  555. ;-----------------------------------------------;
  556. BANKSEL ADCON1 ;
  557. MOVLW H'60' ; Left Justified
  558. MOVWF ADCON1 ; FOSC/64, VREF
  559. MOVLW B'00001011' ; AN2, ADC GO, ADC On
  560. MOVWF ADCON0 ;
  561. BTFSC ADCON0, GO ; Wait for conversion
  562. GOTO $-1 ;
  563. MOVFW ADRESH ; Get result
  564. BANKSEL MEMORY ;
  565. ;-----------------------------------------------;
  566. ;
  567. MOVWF Temp1 ;
  568. MOVLW H'60' ;
  569. SUBWF Temp1, W ;
  570. BTFSS STATUS, C ;
  571. DECF Paddle_1_Y, F ;
  572. MOVLW H'9F' ;
  573. SUBWF Temp1, W ;
  574. BTFSC STATUS, C ;
  575. INCF Paddle_1_Y, F ;
  576. BTFSC Paddle_1_Y, MSB ;
  577. CLRF Paddle_1_Y ;
  578. MOVLW 48 ;
  579. SUBWF Paddle_1_Y, W ;
  580. BTFSS STATUS, C ;
  581. GOTO _UP1_Update_Done ;
  582. MOVLW 48 ;
  583. MOVWF Paddle_1_Y ;
  584. _UP1_Update_Done: ;
  585. #ELSE ;!_USE_THUMBSTICKS_ ;
  586. _UP1_Check_Up: ;
  587. CLRW ;
  588. XORWF Paddle_1_Y, W ;
  589. BTFSC STATUS, Z ;
  590. GOTO _UP1_Check_Down ;
  591. BTFSS PORTA, LBUTT_1_BIT ;
  592. DECF Paddle_1_Y, F ;
  593. _UP1_Check_Down: ;
  594. MOVLW 48 ;
  595. XORWF Paddle_1_Y, W ;
  596. BTFSC STATUS, Z ;
  597. GOTO _UP1_Draw_Paddle ;
  598. BTFSS PORTA, LBUTT_2_BIT ;
  599. INCF Paddle_1_Y, F ;
  600. #ENDIF ;_USE_THUMBSTICKS_ ;
  601. ;
  602. _UP1_Draw_Paddle: ;
  603. MOVFW Paddle_1_Y ;
  604. ADDWF Paddle_1_Y, W ;
  605. ADDWF Paddle_1_Y, W ;
  606. ADDWF Paddle_1_Y, W ;
  607. ADDLW LOW VIDEO_BUFFER_START + LEFT_PADDLE_START;
  608. MOVWF FSR1L ;
  609. MOVLW HIGH VIDEO_BUFFER_START ;
  610. MOVWF FSR1H ;
  611. MOVIW 0[INDF1] ;
  612. IORLW LEFT_PADDLE_BIT ;
  613. MOVWI 0[INDF1] ;
  614. MOVIW 4[INDF1] ;
  615. IORLW LEFT_PADDLE_BIT ;
  616. MOVWI 4[INDF1] ;
  617. MOVIW 8[INDF1] ;
  618. IORLW LEFT_PADDLE_BIT ;
  619. MOVWI 8[INDF1] ;
  620. MOVIW 12[INDF1] ;
  621. IORLW LEFT_PADDLE_BIT ;
  622. MOVWI 12[INDF1] ;
  623. MOVIW 16[INDF1] ;
  624. IORLW LEFT_PADDLE_BIT ;
  625. MOVWI 16[INDF1] ;
  626. MOVIW 20[INDF1] ;
  627. IORLW LEFT_PADDLE_BIT ;
  628. MOVWI 20[INDF1] ;
  629. MOVIW 24[INDF1] ;
  630. IORLW LEFT_PADDLE_BIT ;
  631. MOVWI 24[INDF1] ;
  632. MOVIW 28[INDF1] ;
  633. IORLW LEFT_PADDLE_BIT ;
  634. MOVWI 28[INDF1] ;
  635. ;
  636. MOVFW TMR0 ;
  637. SUBLW 228 ;
  638. BTFSC STATUS, C ;
  639. GOTO $-3 ;
  640. NOP ;
  641. NOP ;
  642. NOP ;
  643. ;
  644. RETURN ;
  645. ;---------------------------------------------------;
  646.  
  647. ;---------------------------------------------------;
  648. _Update_Paddle_2: ;
  649. ;---------------------------------------------------;
  650. ; Note: This is a 60us line routine. ;
  651. ;---------------------------------------------------;
  652. ;-----------------------------------------------;
  653. ; 4us Negative Sync Generation ;
  654. ;-----------------------------------------------;
  655. NEG_SYNC_4US ;
  656. ;-----------------------------------------------;
  657. ;
  658. ;-----------------------------------------------;
  659. ; 60us Blank Signal Generation ;
  660. ; But with lots of calculations going on ;
  661. ;-----------------------------------------------;
  662. SET_SIGNAL COLOR_BLACK ;
  663. ;
  664. BANKSEL OPTION_REG ;
  665. BCF OPTION_REG, PSA ;
  666. BANKSEL TMR0 ;
  667. CLRF TMR0 ;
  668. ;
  669. _UP2_Clear_Paddle: ;
  670. MOVFW Paddle_2_Y ;
  671. ADDWF Paddle_2_Y, W ;
  672. ADDWF Paddle_2_Y, W ;
  673. ADDWF Paddle_2_Y, W ;
  674. ADDLW LOW VIDEO_BUFFER_START + RIGHT_PADDLE_START;
  675. MOVWF FSR1L ;
  676. MOVLW HIGH VIDEO_BUFFER_START ;
  677. MOVWF FSR1H ;
  678. MOVIW 0[INDF1] ;
  679. ANDLW RIGHT_PADDLE_MASK ;
  680. MOVWI 0[INDF1] ;
  681. MOVIW 4[INDF1] ;
  682. ANDLW RIGHT_PADDLE_MASK ;
  683. MOVWI 4[INDF1] ;
  684. MOVIW 8[INDF1] ;
  685. ANDLW RIGHT_PADDLE_MASK ;
  686. MOVWI 8[INDF1] ;
  687. MOVIW 12[INDF1] ;
  688. ANDLW RIGHT_PADDLE_MASK ;
  689. MOVWI 12[INDF1] ;
  690. MOVIW 16[INDF1] ;
  691. ANDLW RIGHT_PADDLE_MASK ;
  692. MOVWI 16[INDF1] ;
  693. MOVIW 20[INDF1] ;
  694. ANDLW RIGHT_PADDLE_MASK ;
  695. MOVWI 20[INDF1] ;
  696. MOVIW 24[INDF1] ;
  697. ANDLW RIGHT_PADDLE_MASK ;
  698. MOVWI 24[INDF1] ;
  699. MOVIW 28[INDF1] ;
  700. ANDLW RIGHT_PADDLE_MASK ;
  701. MOVWI 28[INDF1] ;
  702. ;
  703. #IF _USE_THUMBSTICKS_ ;
  704. _UP2_Update: ;
  705. ;-----------------------------------------------;
  706. ; ADC Magic (Channel 0) ;
  707. ;-----------------------------------------------;
  708. BANKSEL ADCON1 ;
  709. MOVLW H'60' ; Left Justified
  710. MOVWF ADCON1 ; FOSC/64, VREF
  711. MOVLW B'00000011' ; AN0, ADC GO, ADC On
  712. MOVWF ADCON0 ;
  713. BTFSC ADCON0, GO ; Wait for conversion
  714. GOTO $-1 ;
  715. MOVFW ADRESH ; Get result
  716. BANKSEL MEMORY ;
  717. ;-----------------------------------------------;
  718. ;
  719. MOVWF Temp1 ;
  720. MOVLW H'60' ;
  721. SUBWF Temp1, W ;
  722. BTFSS STATUS, C ;
  723. DECF Paddle_2_Y, F ;
  724. MOVLW H'9F' ;
  725. SUBWF Temp1, W ;
  726. BTFSC STATUS, C ;
  727. INCF Paddle_2_Y, F ;
  728. BTFSC Paddle_2_Y, MSB ;
  729. CLRF Paddle_2_Y ;
  730. MOVLW 48 ;
  731. SUBWF Paddle_2_Y, W ;
  732. BTFSS STATUS, C ;
  733. GOTO _UP2_Update_Done ;
  734. MOVLW 48 ;
  735. MOVWF Paddle_2_Y ;
  736. _UP2_Update_Done: ;
  737. #ELSE ;!_USE_THUMBSTICKS_ ;
  738. _UP2_Check_Up: ;
  739. CLRW ;
  740. XORWF Paddle_2_Y, W ;
  741. BTFSC STATUS, Z ;
  742. GOTO _UP2_Check_Down ;
  743. BTFSS PORTA, RBUTT_1_BIT ;
  744. DECF Paddle_2_Y, F ;
  745. _UP2_Check_Down: ;
  746. MOVLW 40 ;
  747. XORWF Paddle_2_Y, W ;
  748. BTFSC STATUS, Z ;
  749. GOTO _UP2_Draw_Paddle ;
  750. BTFSS PORTA, RBUTT_2_BIT ;
  751. INCF Paddle_2_Y, F ;
  752. #ENDIF ;_USE_THUMBSTICKS_ ;
  753. ;
  754. _UP2_Draw_Paddle: ;
  755. MOVFW Paddle_2_Y ;
  756. ADDWF Paddle_2_Y, W ;
  757. ADDWF Paddle_2_Y, W ;
  758. ADDWF Paddle_2_Y, W ;
  759. ADDLW LOW VIDEO_BUFFER_START + RIGHT_PADDLE_START;
  760. MOVWF FSR1L ;
  761. MOVLW HIGH VIDEO_BUFFER_START ;
  762. MOVWF FSR1H ;
  763. MOVIW 0[INDF1] ;
  764. IORLW RIGHT_PADDLE_BIT ;
  765. MOVWI 0[INDF1] ;
  766. MOVIW 4[INDF1] ;
  767. IORLW RIGHT_PADDLE_BIT ;
  768. MOVWI 4[INDF1] ;
  769. MOVIW 8[INDF1] ;
  770. IORLW RIGHT_PADDLE_BIT ;
  771. MOVWI 8[INDF1] ;
  772. MOVIW 12[INDF1] ;
  773. IORLW RIGHT_PADDLE_BIT ;
  774. MOVWI 12[INDF1] ;
  775. MOVIW 16[INDF1] ;
  776. IORLW RIGHT_PADDLE_BIT ;
  777. MOVWI 16[INDF1] ;
  778. MOVIW 20[INDF1] ;
  779. IORLW RIGHT_PADDLE_BIT ;
  780. MOVWI 20[INDF1] ;
  781. MOVIW 24[INDF1] ;
  782. IORLW RIGHT_PADDLE_BIT ;
  783. MOVWI 24[INDF1] ;
  784. MOVIW 28[INDF1] ;
  785. IORLW RIGHT_PADDLE_BIT ;
  786. MOVWI 28[INDF1] ;
  787. ;
  788. NOP ;
  789. MOVFW TMR0 ;
  790. SUBLW 226 ;
  791. BTFSC STATUS, C ;
  792. GOTO $-3 ;
  793. NOP ;
  794. NOP ;
  795. ;
  796. RETURN ;
  797. ;---------------------------------------------------;
  798.  
  799. ;---------------------------------------------------;
  800. _Update_Ball: ;
  801. ;---------------------------------------------------;
  802. ; Note: This is a 60us line routine. ;
  803. ;---------------------------------------------------;
  804. ;-----------------------------------------------;
  805. ; 4us Negative Sync Generation ;
  806. ;-----------------------------------------------;
  807. NEG_SYNC_4US ;
  808. ;
  809. ;-----------------------------------------------;
  810. ; 60us Blank Signal Generation ;
  811. ; But with lots of calculations going on ;
  812. ;-----------------------------------------------;
  813. SET_SIGNAL COLOR_BLACK ;
  814. ;
  815. BANKSEL OPTION_REG ;
  816. BCF OPTION_REG, PSA ;
  817. BANKSEL TMR0 ;
  818. CLRF TMR0 ;
  819. ;
  820. _UB_Check_Wait: ;
  821. DECFSZ Ball_Wait, F ;
  822. GOTO _UB_Exit ;
  823. ;
  824. MOVLW MAX_BALL_WAIT ;
  825. MOVWF Ball_Wait ;
  826. ;
  827. CLRW ;
  828. XORWF Ball_Dir_X, W ;
  829. BTFSS STATUS, Z ;
  830. GOTO _UB_Clear_Ball ;
  831. CLRW ;
  832. XORWF Ball_Dir_Y, W ;
  833. BTFSS STATUS, Z ;
  834. GOTO _UB_Clear_Ball ;
  835. ;
  836. _UB_Check_L_Serve: ;
  837. BTFSC PORTA, LBUTT_BIT ;
  838. GOTO _UB_Check_R_Serve ;
  839. MOVLW 1 ;
  840. MOVWF Ball_Dir_X ;
  841. MOVLW 1 ;
  842. MOVWF Ball_Dir_Y ;
  843. MOVLW 16 ;
  844. MOVWF Ball_X ;
  845. MOVLW 27 ;
  846. MOVWF Ball_Y ;
  847. GOTO _UB_Service ;
  848. _UB_Check_R_Serve: ;
  849. BTFSC System_Status, BUZZ_BIT ;
  850. GOTO _UB_Exit ;
  851. BANKSEL TRISA ;
  852. BSF TRISA, RBUTT_BIT ;
  853. BANKSEL PORTA ;
  854. BTFSC PORTA, RBUTT_BIT ;
  855. GOTO _UB_Exit ;
  856. BANKSEL TRISA ;
  857. BCF TRISA, RBUTT_BIT ;
  858. BANKSEL PORTA ;
  859. MOVLW -1 ;
  860. MOVWF Ball_Dir_X ;
  861. MOVLW -1 ;
  862. MOVWF Ball_Dir_Y ;
  863. MOVLW 15 ;
  864. MOVWF Ball_X ;
  865. MOVLW 27 ;
  866. MOVWF Ball_Y ;
  867. _UB_Service: ;
  868. PAGESEL _Clear_Court ;
  869. CALL _Clear_Court ;
  870. PAGESEL $ ;
  871. MOVLW H'11' ;
  872. XORWF Score_1, W ;
  873. BTFSC STATUS, Z ;
  874. GOTO $+5 ;
  875. MOVLW H'11' ;
  876. XORWF Score_2, W ;
  877. BTFSS STATUS, Z ;
  878. GOTO _UB_Draw_Ball ;
  879. CLRF Score_1 ;
  880. CLRF Score_2 ;
  881. GOTO _UB_Draw_Ball ;
  882. ;
  883. _UB_Clear_Ball: ;
  884. MOVFW Ball_Y ;
  885. ADDWF Ball_Y, W ;
  886. ADDWF Ball_Y, W ;
  887. ADDWF Ball_Y, W ;
  888. ADDLW LOW VIDEO_BUFFER_START ;
  889. MOVWF FSR1L ;
  890. RRF Ball_X, W ;
  891. MOVWF Temp1 ;
  892. RRF Temp1, F ;
  893. RRF Temp1, W ;
  894. ANDLW H'1F' ;
  895. ADDWF FSR1L, F ;
  896. MOVLW HIGH VIDEO_BUFFER_START ;
  897. MOVWF FSR1H ;
  898. ;
  899. MOVFW Ball_X ;
  900. ANDLW H'07' ;
  901. MOVWF Temp1 ;
  902. MOVLW H'7F' ;
  903. MOVWF DTemp ;
  904. MOVLW 0 ; ;
  905. XORWF Temp1, W ;
  906. BTFSC STATUS, Z ;
  907. GOTO $+5 ;
  908. DECF Temp1, F ;
  909. RRF DTemp, F ;
  910. BSF DTemp, MSB ;
  911. GOTO $-7 ;
  912. ;
  913. MOVFW DTemp ;
  914. ANDWF INDF1, F ;
  915. ;
  916. MOVLW H'04' ;
  917. ADDWF FSR1L, F ;
  918. MOVFW DTemp ;
  919. ANDWF INDF1, F ;
  920. ;
  921. _UB_Update_Ball_X: ;
  922. MOVFW Ball_Dir_X ; Update Ball X Position
  923. ADDWF Ball_X, F ;
  924. ;
  925. _UB_Update_Ball_X_Min: ;
  926. MOVLW 0 ;
  927. XORWF Ball_X, W ;
  928. BTFSS STATUS, Z ;
  929. GOTO _UB_Update_Ball_X_Max ;
  930. MOVLW 1 ;
  931. MOVWF Ball_Dir_X ;
  932. ;
  933. INCF Score_2, F ;
  934. PLAY_SOUND 20, H'017F' ; Frequency, Duration
  935. MOVLW 0 ;
  936. MOVWF Ball_Dir_X ;
  937. MOVWF Ball_Dir_Y ;
  938. MOVLW 15 ;
  939. MOVWF Ball_X ;
  940. MOVLW 27 ;
  941. MOVWF Ball_Y ;
  942. MOVFW Score_2 ;
  943. ANDLW H'0F' ;
  944. XORLW H'0A' ;
  945. BTFSS STATUS, Z ;
  946. GOTO _UB_BXMin_Exit ;
  947. MOVFW Score_2 ;
  948. ANDLW H'F0' ;
  949. ADDLW H'10' ;
  950. MOVWF Score_2 ;
  951. MOVLW H'A0' ;
  952. XORWF Score_2, W ;
  953. BTFSC STATUS, Z ;
  954. CLRF Score_2 ;
  955. _UB_BXMin_Exit: ;
  956. MOVLW H'11' ;
  957. XORWF Score_2, W ;
  958. BTFSS STATUS, Z ;
  959. GOTO _UB_Exit ;
  960. PAGESEL _Clear_Court ;
  961. CALL _Clear_Court ;
  962. PAGESEL _Draw_Title ;
  963. CALL _Draw_Title ;
  964. PAGESEL $ ;
  965. GOTO _UB_Exit ;
  966. ;
  967. _UB_Update_Ball_X_Max: ;
  968. MOVLW 31 ;
  969. XORWF Ball_X, W ;
  970. BTFSS STATUS, Z ;
  971. GOTO _UB_Update_Ball_Y ;
  972. MOVLW -1 ;
  973. MOVWF Ball_Dir_X ;
  974. ;
  975. INCF Score_1, F ;
  976. PLAY_SOUND 20, H'017F' ; Frequency, Duration
  977. MOVLW 0 ;
  978. MOVWF Ball_Dir_X ;
  979. MOVWF Ball_Dir_Y ;
  980. MOVLW 15 ;
  981. MOVWF Ball_X ;
  982. MOVLW 27 ;
  983. MOVWF Ball_Y ;
  984. MOVFW Score_1 ;
  985. ANDLW H'0F' ;
  986. XORLW H'0A' ;
  987. BTFSS STATUS, Z ;
  988. GOTO _UB_BXMax_Exit ;
  989. MOVFW Score_1 ;
  990. ANDLW H'F0' ;
  991. ADDLW H'10' ;
  992. MOVWF Score_1 ;
  993. MOVLW H'A0' ;
  994. XORWF Score_1, W ;
  995. BTFSC STATUS, Z ;
  996. CLRF Score_1 ;
  997. _UB_BXMax_Exit: ;
  998. MOVLW H'11' ;
  999. XORWF Score_1, W ;
  1000. BTFSS STATUS, Z ;
  1001. GOTO _UB_Exit ;
  1002. PAGESEL _Clear_Court ;
  1003. CALL _Clear_Court ;
  1004. PAGESEL _Draw_Title ;
  1005. CALL _Draw_Title ;
  1006. PAGESEL $ ;
  1007. GOTO _UB_Exit ;
  1008. ;
  1009. _UB_Update_Ball_Y: ;
  1010. MOVFW Ball_Dir_Y ; Update Ball Y Position
  1011. ADDWF Ball_Y, F ;
  1012. ;
  1013. _UB_Update_Ball_Y_Min: ;
  1014. MOVLW 0 ;
  1015. XORWF Ball_Y, W ;
  1016. BTFSS STATUS, Z ;
  1017. GOTO _UB_Update_Ball_Y_Max ;
  1018. MOVLW 1 ;
  1019. MOVWF Ball_Dir_Y ;
  1020. PLAY_SOUND 13, H'013F' ; Frequency, Duration
  1021. GOTO _UB_Paddle_Detect ;
  1022. ;
  1023. _UB_Update_Ball_Y_Max: ;
  1024. MOVLW 55 ;
  1025. XORWF Ball_Y, W ;
  1026. BTFSS STATUS, Z ;
  1027. GOTO _UB_Paddle_Detect ;
  1028. MOVLW -1 ;
  1029. MOVWF Ball_Dir_Y ;
  1030. PLAY_SOUND 13, H'013F' ; Frequency, Duration
  1031. ;
  1032. _UB_Paddle_Detect: ;
  1033. _UB_Paddle_Detect_Left: ;
  1034. MOVLW -1 ;
  1035. XORWF Ball_Dir_X, W ;
  1036. BTFSS STATUS, Z ;
  1037. GOTO _UB_Paddle_Detect_Right ;
  1038. ;
  1039. MOVLW 2 ;
  1040. XORWF Ball_X, W ;
  1041. BTFSS STATUS, Z ;
  1042. GOTO _UB_Draw_Ball ;
  1043. ;
  1044. MOVFW Paddle_1_Y ;
  1045. SUBWF Ball_Y, W ;
  1046. BTFSS STATUS, C ;
  1047. GOTO _UB_Draw_Ball ;
  1048. MOVFW Paddle_1_Y ;
  1049. ADDLW 8 ;
  1050. SUBWF Ball_Y, W ;
  1051. BTFSC STATUS, C ;
  1052. GOTO _UB_Draw_Ball ;
  1053. MOVLW 1 ;
  1054. MOVWF Ball_Dir_X ;
  1055. PLAY_SOUND 15, H'013F' ; Frequency, Duration
  1056. GOTO _UB_Draw_Ball ;
  1057. ;
  1058. _UB_Paddle_Detect_Right: ;
  1059. MOVLW 1 ;
  1060. XORWF Ball_Dir_X, W ;
  1061. BTFSS STATUS, Z ;
  1062. GOTO _UB_Draw_Ball ;
  1063. ;
  1064. MOVLW 29 ;
  1065. XORWF Ball_X, W ;
  1066. BTFSS STATUS, Z ;
  1067. GOTO _UB_Draw_Ball ;
  1068. ;
  1069. MOVFW Paddle_2_Y ;
  1070. SUBWF Ball_Y, W ;
  1071. BTFSS STATUS, C ;
  1072. GOTO _UB_Draw_Ball ;
  1073. MOVFW Paddle_2_Y ;
  1074. ADDLW 8 ;
  1075. SUBWF Ball_Y, W ;
  1076. BTFSC STATUS, C ;
  1077. GOTO _UB_Draw_Ball ;
  1078. MOVLW -1 ;
  1079. MOVWF Ball_Dir_X ;
  1080. PLAY_SOUND 15, H'013F' ; Frequency, Duration
  1081. ;
  1082. _UB_Draw_Ball: ;
  1083. MOVFW Ball_Y ;
  1084. ADDWF Ball_Y, W ;
  1085. ADDWF Ball_Y, W ;
  1086. ADDWF Ball_Y, W ;
  1087. ADDLW LOW VIDEO_BUFFER_START ;
  1088. MOVWF FSR1L ;
  1089. RRF Ball_X, W ;
  1090. MOVWF Temp1 ;
  1091. RRF Temp1, F ;
  1092. RRF Temp1, W ;
  1093. ANDLW H'1F' ;
  1094. ADDWF FSR1L, F ;
  1095. MOVLW HIGH VIDEO_BUFFER_START ;
  1096. MOVWF FSR1H ;
  1097. ;
  1098. MOVFW Ball_X ;
  1099. ANDLW H'07' ;
  1100. MOVWF Temp1 ;
  1101. MOVLW H'80' ;
  1102. MOVWF DTemp ;
  1103. MOVLW 0 ; ;
  1104. XORWF Temp1, W ;
  1105. BTFSC STATUS, Z ;
  1106. GOTO $+5 ;
  1107. DECF Temp1, F ;
  1108. RRF DTemp, F ;
  1109. BCF DTemp, MSB ;
  1110. GOTO $-7 ;
  1111. ;
  1112. MOVFW DTemp ;
  1113. IORWF INDF1, F ;
  1114. ;
  1115. MOVLW H'04' ;
  1116. ADDWF FSR1L, F ;
  1117. MOVFW DTemp ;
  1118. IORWF INDF1, F ;
  1119. ;
  1120. _UB_Exit: ;
  1121. BANKSEL TRISA ;
  1122. BSF TRISA, RBUTT_BIT ;
  1123. BANKSEL PORTA ;
  1124. ;
  1125. NOP ;
  1126. MOVFW TMR0 ;
  1127. SUBLW 227 ;
  1128. BTFSC STATUS, C ;
  1129. GOTO $-3 ;
  1130. NOP ;
  1131. ;
  1132. RETURN ;
  1133. ;---------------------------------------------------;
  1134.  
  1135. ;---------------------------------------------------;
  1136. USER_CODE_2 CODE H'800' ;
  1137. ;---------------------------------------------------;
  1138. _Next_Frame: ;
  1139. ;---------------------------------------------------;
  1140. ;-----------------------------------------------;
  1141. ; VERTICAL SYNC PULSE Time ;
  1142. ; This consists of 5 blank half lines, ;
  1143. ; 4 inverted half lines, and 5 more blank half ;
  1144. ; lines. This totals 7 full lines of 64us each. ;
  1145. ; --------------------------------------------- ;
  1146. ; NOTE: Timing is CRITICAL for a nice, clean ;
  1147. ; display. If you notice the top part of the ;
  1148. ; display is skewed or "tearing", your timings ;
  1149. ; are wrong and need to be adjusted. Make sure ;
  1150. ; you haven't inadvertently dropped a half frame;
  1151. ;-----------------------------------------------;
  1152. ; First, a special blank 30us line. If _DEBUG_ ;
  1153. ; is enabled, it will produce a pulse on the ;
  1154. ; GPIO2 pin for debugging purposes (checking the;
  1155. ; time elapsed for a single video frame). ;
  1156. ;-----------------------------------------------;
  1157. PAGESEL _Special_30us_Line ;
  1158. CALL _Special_30us_Line ;
  1159. PAGESEL $ ;
  1160. ;-----------------------------------------------;
  1161. ;
  1162. ;-----------------------------------------------;
  1163. ; 4 blank 30us lines ;
  1164. ;-----------------------------------------------;
  1165. MOVLW 4 ;
  1166. MOVWF Line_Count ;
  1167. _NF_Next_Blank_30us_Line1: ;
  1168. PAGESEL _Blank_30us_Line ;
  1169. CALL _Blank_30us_Line ;
  1170. PAGESEL $ ;
  1171. DECFSZ Line_Count, F ;
  1172. GOTO _NF_Next_Blank_30us_Line1 ;
  1173. ;-----------------------------------------------;
  1174. ;
  1175. ;-----------------------------------------------;
  1176. ; Timing fix for transition from 30us lines to ;
  1177. ; inverted 30us lines. ;
  1178. ;-----------------------------------------------;
  1179. NOP ;
  1180. ;-----------------------------------------------;
  1181. ;
  1182. ;-----------------------------------------------;
  1183. ; 4 inverted 30us lines ;
  1184. ;-----------------------------------------------;
  1185. MOVLW 4 ;
  1186. MOVWF Line_Count ;
  1187. _NF_Next_Inverted_30us_Line: ;
  1188. PAGESEL _Inverted_30us_Line ;
  1189. CALL _Inverted_30us_Line ;
  1190. PAGESEL $ ;
  1191. DECFSZ Line_Count, F ;
  1192. GOTO _NF_Next_Inverted_30us_Line ;
  1193. ;-----------------------------------------------;
  1194. ;
  1195. ;-----------------------------------------------;
  1196. ; 5 blank 30us lines ;
  1197. ;-----------------------------------------------;
  1198. MOVLW 5 ;
  1199. MOVWF Line_Count ;
  1200. _NF_Next_Blank_30us_Line2: ;
  1201. PAGESEL _Blank_30us_Line ;
  1202. CALL _Blank_30us_Line ;
  1203. PAGESEL $ ;
  1204. DECFSZ Line_Count, F ;
  1205. GOTO _NF_Next_Blank_30us_Line2 ;
  1206. ;-----------------------------------------------;
  1207. ;
  1208. ;-----------------------------------------------;
  1209. ; Just a bunch of BLANK LINES, so that the video;
  1210. ; data doesn't start in the non-display area. ;
  1211. ; Add or remove lines to adjust the vertical ;
  1212. ; position of your video. If you add or remove, ;
  1213. ; make sure to adjust the number of BLANK LINES ;
  1214. ; which follow the data lines, so that the video;
  1215. ; stays at 60hz ;
  1216. ;-----------------------------------------------;
  1217. MOVLW 15 ;
  1218. MOVWF Line_Count ;
  1219. _NF_Next_Blank_60us_Line: ;
  1220. PAGESEL _Blank_60us_Line ;
  1221. CALL _Blank_60us_Line ;
  1222. PAGESEL $ ;
  1223. DECFSZ Line_Count, F ;
  1224. GOTO _NF_Next_Blank_60us_Line ;
  1225. ;-----------------------------------------------;
  1226. ;
  1227. ;-----------------------------------------------;
  1228. ; 224 Data lines + 2 Blank Lines (1 before and ;
  1229. ; one after) for timing fixes ;
  1230. ;-----------------------------------------------;
  1231. PAGESEL _Data_Lines ;
  1232. CALL _Data_Lines ;
  1233. PAGESEL $ ;
  1234. ;-----------------------------------------------;
  1235. ;
  1236. ;-----------------------------------------------;
  1237. ; 8 lines for the copyright. So, to summarize: ;
  1238. ; (note - I needed four full 60us frames for ;
  1239. ; the game processing (paddles, ball, scores, ;
  1240. ; etc.), so I moved four blank line there for ;
  1241. ; use for those routines) ;
  1242. ; ;
  1243. ; - 7 VERTICAL SYNC lines ;
  1244. ; - 15 BLANK LINES ;
  1245. ; - 1 BLANK LINE (for timing fixes) ;
  1246. ; - 224 DATA LINES ;
  1247. ; - 1 BLANK LINE (for timing fixes) ;
  1248. ; - 8 LINES FOR COPYRIGHT ;
  1249. ; - 4 BLANK LINES (game processing) ;
  1250. ; ;
  1251. ; For a total of 260 lines at 64us each, or ;
  1252. ; 16.664ms, or approximately 60hz. 16.666ms ;
  1253. ; would be _perfect_. ;
  1254. ;-----------------------------------------------;
  1255. ;
  1256. ;-----------------------------------------------;
  1257. ; Display copyright and software version number ;
  1258. ;-----------------------------------------------;
  1259. PAGESEL _Copyright ;
  1260. CALL _Copyright ; 8 blank FULL line (60us)
  1261. PAGESEL $ ;
  1262. ;-----------------------------------------------;
  1263. ;
  1264. ;-----------------------------------------------;
  1265. ; All of the game processing is done here, the ;
  1266. ; last 4 full 60us blank lines ;
  1267. ;-----------------------------------------------;
  1268. PAGESEL _Update_Ball ;
  1269. CALL _Update_Ball ; 1 blank FULL line (60us)
  1270. PAGESEL $ ; (ball computations)
  1271. PAGESEL _Update_Scores ;
  1272. CALL _Update_Scores ; 1 blank FULL line (60us)
  1273. PAGESEL $ ; (score display)
  1274. PAGESEL _Update_Paddle_1 ;
  1275. CALL _Update_Paddle_1 ; 1 blank FULL line (60us)
  1276. PAGESEL $ ; (paddle 1 computations)
  1277. PAGESEL _Update_Paddle_2 ;
  1278. CALL _Update_Paddle_2 ; 1 blank FULL line (60us)
  1279. PAGESEL $ ; (paddle 2 computations)
  1280. ;-----------------------------------------------;
  1281. ;
  1282. GOTO _Next_Frame ;
  1283. ;---------------------------------------------------;
  1284. ;
  1285. ;---------------------------------------------------;
  1286. _Blank_30us_Line: ;
  1287. ;---------------------------------------------------;
  1288. ; Used only during VERTICAL SYNC ;
  1289. ; NOTE: This is a 30us line routine ;
  1290. ;---------------------------------------------------;
  1291. ;-----------------------------------------------;
  1292. ; 2us Negative Sync Generation ;
  1293. ;-----------------------------------------------;
  1294. NEG_SYNC_2US ;
  1295. ;-----------------------------------------------;
  1296. ;
  1297. ;-----------------------------------------------;
  1298. ; 30us Blank Signal Generation ;
  1299. ;-----------------------------------------------;
  1300. SET_SIGNAL COLOR_BLACK ;
  1301. ;
  1302. BANKSEL OPTION_REG ;
  1303. BCF OPTION_REG, PSA ;
  1304. BANKSEL TMR0 ;
  1305. CLRF TMR0 ;
  1306. ;
  1307. NOP ;
  1308. MOVFW TMR0 ;
  1309. SUBLW 106 ;
  1310. BTFSC STATUS, C ;
  1311. GOTO $-3 ;
  1312. NOP ;
  1313. NOP ;
  1314. NOP ;
  1315. ;-----------------------------------------------;
  1316. ;
  1317. RETURN ;
  1318. ;---------------------------------------------------;
  1319.  
  1320. ;---------------------------------------------------;
  1321. _Special_30us_Line: ;
  1322. ;---------------------------------------------------;
  1323. ; Note: This is a 30us line routine. ;
  1324. ;---------------------------------------------------;
  1325. ;-----------------------------------------------;
  1326. ; 2us Negative Sync Generation ;
  1327. ;-----------------------------------------------;
  1328. NEG_SYNC_2US ;
  1329. ;-----------------------------------------------;
  1330. ;
  1331. ;-----------------------------------------------;
  1332. ; 30us Blank Signal Generation (SPECIAL) ;
  1333. ;-----------------------------------------------;
  1334. ; If _DEBUG_ is TRUE, this will generate a ;
  1335. ; pulse on GPIO2 for debug purposes - used to ;
  1336. ; check the timing of a complete video frame. ;
  1337. ;-----------------------------------------------;
  1338. SET_SIGNAL COLOR_BLACK ;
  1339. ;
  1340. BANKSEL OPTION_REG ;
  1341. BCF OPTION_REG, PSA ;
  1342. BANKSEL TMR0 ;
  1343. CLRF TMR0 ;
  1344. ;
  1345. #IF _DEBUG_ ;
  1346. BANKSEL TRISA ;
  1347. BCF TRISA, 2 ;
  1348. BANKSEL PORTA ;
  1349. BCF PORTA, 2 ;
  1350. NOP ;
  1351. BSF PORTA, 2 ;
  1352. BANKSEL TRISA ;
  1353. BSF TRISA, 2 ;
  1354. BANKSEL MEMORY ;
  1355. #ENDIF ; _DEBUG_ ;
  1356. ;
  1357. NOP ;
  1358. MOVFW TMR0 ;
  1359. SUBLW 106 ;
  1360. BTFSC STATUS, C ;
  1361. GOTO $-3 ;
  1362. ;
  1363. ;-----------------------------------------------;
  1364. ; This is what irks me about using the Timers ;
  1365. ; for timing the video signals. You would think ;
  1366. ; that since the timing comes AFTER the debug ;
  1367. ; code that is there - or not there - the ;
  1368. ; use of the timer should give you a stable ;
  1369. ; timing. But no - each case requires hand ;
  1370. ; tweaks in order to get the timings right. This;
  1371. ; has been driving me a bit crazy for the entire;
  1372. ; project. Thank God for my USBee ZX analyzer. ;
  1373. ;-----------------------------------------------;
  1374. #IF !_DEBUG_ ;
  1375. NOP ;
  1376. NOP ;
  1377. NOP ;
  1378. NOP ;
  1379. #ENDIF ; !_DEBUG_ ;
  1380. ;
  1381. ;-----------------------------------------------;
  1382. ;
  1383. RETURN ;
  1384. ;---------------------------------------------------;
  1385.  
  1386. ;---------------------------------------------------;
  1387. _Inverted_30us_Line: ;
  1388. ;---------------------------------------------------;
  1389. ; Used only during VERTICAL SYNC ;
  1390. ; Note: This is a 30us line routine. ;
  1391. ;---------------------------------------------------;
  1392. ;-----------------------------------------------;
  1393. ; 30us Inverted Signal Generation ;
  1394. ;-----------------------------------------------;
  1395. SET_SIGNAL COLOR_SYNC ;
  1396. DELAY 77 ;
  1397. NOP ;
  1398. NOP ;
  1399. NOP ;
  1400. NOP ;
  1401. ;-----------------------------------------------;
  1402. ;
  1403. ;-----------------------------------------------;
  1404. ; 2s Positive Sync Generation ;
  1405. ;-----------------------------------------------;
  1406. SET_SIGNAL COLOR_BLACK ;
  1407. ; DELAY 1 ;
  1408. NOP ;
  1409. NOP ;
  1410. NOP ;
  1411. ; POS_SYNC_2US ;
  1412. ;-----------------------------------------------;
  1413. ;
  1414. RETURN ;
  1415. ;---------------------------------------------------;
  1416.  
  1417. ;---------------------------------------------------;
  1418. _Blank_60us_Line: ;
  1419. ;---------------------------------------------------;
  1420. ; Note: This is a 60us line routine. ;
  1421. ;---------------------------------------------------;
  1422. ;-----------------------------------------------;
  1423. ; 4us Negative Sync Generation ;
  1424. ;-----------------------------------------------;
  1425. NEG_SYNC_4US ;
  1426. ;-----------------------------------------------;
  1427. ;
  1428. ;-----------------------------------------------;
  1429. ; 60us Black Signal Generation ;
  1430. ;-----------------------------------------------;
  1431. SET_SIGNAL COLOR_BLACK ;
  1432. DELAY 155 ;
  1433. NOP ;
  1434. ;-----------------------------------------------;
  1435. ;
  1436. RETURN ;
  1437. ;---------------------------------------------------;
  1438.  
  1439. ;---------------------------------------------------;
  1440. _Data_Lines: ;
  1441. ;---------------------------------------------------;
  1442. ; Note: This will generate 1 60us blank line, then ;
  1443. ; 224 60us data lines, and finally a 60us blank line;
  1444. ;---------------------------------------------------;
  1445. ;-----------------------------------------------;
  1446. ; 4us Negative Sync Generation ;
  1447. ;-----------------------------------------------;
  1448. NEG_SYNC_4US ;
  1449. ;-----------------------------------------------;
  1450. SET_SIGNAL COLOR_BLACK ;
  1451. ;
  1452. MOVLW MAX_LINES ;
  1453. MOVWF DL_Count ;
  1454. ;
  1455. MOVLW LOW VIDEO_BUFFER_START ;
  1456. MOVWF FSR1L ;
  1457. MOVLW HIGH VIDEO_BUFFER_START ;
  1458. MOVWF FSR1H ;
  1459. ;
  1460. ;-----------------------------------------------;
  1461. ; 60us Black Signal Generation ;
  1462. ;-----------------------------------------------;
  1463. DELAY 155 ;
  1464. NOP ;
  1465. NOP ;
  1466. ;-----------------------------------------------;
  1467. ;
  1468. _DL_Next_Line: ;
  1469. MOVLW 4 ;
  1470. MOVWF Repeat_Count ;
  1471. _DL_Repeat_Line: ;
  1472. ;-----------------------------------------------;
  1473. ; 4us Negative Sync Generation ;
  1474. ;-----------------------------------------------;
  1475. NEG_SYNC_4US ;
  1476. ;-----------------------------------------------;
  1477. ;
  1478. ;-----------------------------------------------;
  1479. ; Front porch - shifts the data to the right ;
  1480. ; and hopefully centers it on the screen ;
  1481. ; --------------------------------------------- ;
  1482. ; NOTE: a DELAY 12 produces a nice 7.5us porch ;
  1483. ;-----------------------------------------------;
  1484. SET_SIGNAL COLOR_BLACK ;
  1485. DELAY 15 ;
  1486. ;-----------------------------------------------;
  1487. ;
  1488. MOVLW H'FC' ;
  1489. ANDWF FSR1L, F ;
  1490. MOVLW 4 ;
  1491. MOVWF Byte_Count ;
  1492. _DL_Next_Byte: ;
  1493. ;-----------------------------------------------;
  1494. ; This is where the 32 bits of data are actually;
  1495. ; send out over the video signal ;
  1496. ;-----------------------------------------------;
  1497. DO_BIT 7, 8 ;
  1498. DO_BIT 6, 8 ;
  1499. DO_BIT 5, 8 ;
  1500. DO_BIT 4, 8 ;
  1501. DO_BIT 3, 8 ;
  1502. DO_BIT 2, 8 ;
  1503. DO_BIT 1, 8 ;
  1504. DO_BIT 0, 1 ;
  1505. ;
  1506. ADDFSR FSR1, 1 ;
  1507. ;
  1508. _DL_Center_Line: ;
  1509. MOVLW 3 ;
  1510. XORWF Byte_Count, W ;
  1511. BTFSS STATUS, Z ;
  1512. GOTO _DL_Center_Line_Done ;
  1513. NOP ;
  1514. NOP ;
  1515. NOP ;
  1516. BCF PORTA, VIDEO_0_BIT ;
  1517. NOP ;
  1518. NOP ;
  1519. NOP ;
  1520. NOP ;
  1521. BSF PORTA, VIDEO_0_BIT ;
  1522. NOP ;
  1523. BCF PORTA, VIDEO_0_BIT ;
  1524. _DL_Center_Line_Done: ;
  1525. ;
  1526. DECFSZ Byte_Count, F ;
  1527. GOTO _DL_Next_Byte ;
  1528. DECF FSR1L, F ;
  1529. ;-----------------------------------------------;
  1530. ;
  1531. ;-----------------------------------------------;
  1532. ; Back porch - between this and the front porch,;
  1533. ; this 'frames' the video on your TV (hopefully);
  1534. ; --------------------------------------------- ;
  1535. ; NOTE: a DELAY 8 (plus a NOP) produces a ;
  1536. ; nice 4.5us back porch, which fleshes out the ;
  1537. ; data line to 60us ;
  1538. ;-----------------------------------------------;
  1539. SET_SIGNAL COLOR_BLACK ;
  1540. DELAY 2 ;
  1541. NOP ;
  1542. NOP ;
  1543. ;-----------------------------------------------;
  1544. ;
  1545. DECFSZ Repeat_Count, F ;
  1546. GOTO $+2 ;
  1547. GOTO _DL_Next_Data ;
  1548. NOP ;
  1549. NOP ;
  1550. NOP ;
  1551. NOP ;
  1552. NOP ;
  1553. NOP ;
  1554. GOTO _DL_Repeat_Line ;
  1555. ;
  1556. ;-----------------------------------------------;
  1557. ; 224 lines of information to transmit ;
  1558. ; so the screen size is 32x224. But we transmit ;
  1559. ; each line 4 times, so it's actually 32x56 ;
  1560. ;-----------------------------------------------;
  1561. _DL_Next_Data: ;
  1562. NOP ;
  1563. ADDFSR FSR1, 1 ;
  1564. DECFSZ DL_Count, F ;
  1565. GOTO _DL_Next_Line ;
  1566. ;
  1567. NOP ;
  1568. NOP ;
  1569. NOP ;
  1570. NOP ;
  1571. ;-----------------------------------------------;
  1572. ; 4us Negative Sync Generation ;
  1573. ;-----------------------------------------------;
  1574. NEG_SYNC_4US ;
  1575. ;-----------------------------------------------;
  1576. ;
  1577. ;-----------------------------------------------;
  1578. ; 60us Black Signal Generation ;
  1579. ;-----------------------------------------------;
  1580. SET_SIGNAL COLOR_BLACK ;
  1581. DELAY 154 ;
  1582. NOP ;
  1583. ;
  1584. ;-----------------------------------------------;
  1585. ;
  1586. RETURN ;
  1587. ;---------------------------------------------------;
  1588.  
  1589. ;---------------------------------------------------;
  1590. _Clear_Court: ;
  1591. ;---------------------------------------------------;
  1592. MOVLW LOW VIDEO_BUFFER_START ;
  1593. MOVWF FSR1L ;
  1594. MOVLW HIGH VIDEO_BUFFER_START ;
  1595. MOVWF FSR1H ;
  1596. MOVLW MAX_LINES * 4 ;
  1597. MOVWF Temp1 ; 224 bytes
  1598. _CC_Next_Byte: ;
  1599. MOVLW H'00' ;
  1600. MOVWF INDF1 ;
  1601. INCF FSR1L, F ;
  1602. DECFSZ Temp1, F ;
  1603. GOTO _CC_Next_Byte ;
  1604. RETURN ;
  1605. ;---------------------------------------------------;
  1606.  
  1607. ;---------------------------------------------------;
  1608. _Update_Scores: ;
  1609. ;---------------------------------------------------;
  1610. ; Note: This is a 60us line routine. ;
  1611. ;---------------------------------------------------;
  1612. ; This will retrieve the character font information ;
  1613. ; from high program memory and display the two ;
  1614. ; scores at the top middle of the screen. It takes ;
  1615. ; around 40.5us to display both scores. ;
  1616. ;---------------------------------------------------;
  1617. ;-----------------------------------------------;
  1618. ; 4us Negative Sync Generation ;
  1619. ;-----------------------------------------------;
  1620. NEG_SYNC_4US ;
  1621. ;-----------------------------------------------;
  1622. ;
  1623. ;-----------------------------------------------;
  1624. ; 60us Blank Signal Generation ;
  1625. ; But with lots of calculations going on ;
  1626. ;-----------------------------------------------;
  1627. SET_SIGNAL COLOR_BLACK ;
  1628. ;
  1629. BANKSEL OPTION_REG ;
  1630. BCF OPTION_REG, PSA ;
  1631. BANKSEL TMR0 ;
  1632. CLRF TMR0 ;
  1633. ;
  1634. _US_Draw_Score1: ;
  1635. _US1_Clear_Score: ;
  1636. MOVLW LOW VIDEO_BUFFER_START + LEFT_SCORE_START;
  1637. MOVWF FSR1L ;
  1638. MOVLW HIGH VIDEO_BUFFER_START ;
  1639. MOVWF FSR1H ;
  1640. ;
  1641. CLRW ;
  1642. MOVWI 0[INDF1] ;
  1643. MOVWI 4[INDF1] ;
  1644. MOVWI 8[INDF1] ;
  1645. MOVWI 12[INDF1] ;
  1646. MOVWI 16[INDF1] ;
  1647. ;
  1648. _US1_Draw_Left_Char: ;
  1649. SWAPF Score_1, W ;
  1650. ANDLW H'0F' ;
  1651. MOVWF Temp1 ;
  1652. ;
  1653. MOVLW LOW VIDEO_BUFFER_START + LEFT_SCORE_START;
  1654. MOVWF FSR1L ;
  1655. MOVLW HIGH VIDEO_BUFFER_START ;
  1656. MOVWF FSR1H ;
  1657. ;
  1658. MOVLW HIGH CHARACTER_TABLE ;
  1659. MOVWF FSR0H ;
  1660. MOVLW LOW CHARACTER_TABLE ;
  1661. ADDWF Temp1, W ;
  1662. BTFSC STATUS, C ;
  1663. INCF FSR0H, F ;
  1664. MOVWF FSR0L ;
  1665. ;
  1666. MOVLW 5 ;
  1667. MOVWF Temp1 ;
  1668. _US1_DLC_Next_Line: ;
  1669. MOVFW INDF0 ;
  1670. MOVWF DTemp ;
  1671. RRF DTemp, W ;
  1672. ANDLW H'70' ;
  1673. MOVWF INDF1 ;
  1674. ADDFSR FSR0, 10 ;
  1675. ADDFSR FSR1, 4 ;
  1676. DECFSZ Temp1, F ;
  1677. GOTO _US1_DLC_Next_Line ;
  1678. ;
  1679. _US1_Draw_Right_Char: ;
  1680. MOVFW Score_1 ;
  1681. ANDLW H'0F' ;
  1682. MOVWF Temp1 ;
  1683. ;
  1684. MOVLW LOW VIDEO_BUFFER_START + LEFT_SCORE_START;
  1685. MOVWF FSR1L ;
  1686. MOVLW HIGH VIDEO_BUFFER_START ;
  1687. MOVWF FSR1H ;
  1688. ;
  1689. MOVLW HIGH CHARACTER_TABLE ;
  1690. MOVWF FSR0H ;
  1691. MOVLW LOW CHARACTER_TABLE ;
  1692. ADDWF Temp1, W ;
  1693. BTFSC STATUS, C ;
  1694. INCF FSR0H, F ;
  1695. MOVWF FSR0L ;
  1696. ;
  1697. MOVLW 5 ;
  1698. MOVWF Temp1 ;
  1699. _US1_DRC_Next_Line ;
  1700. MOVFW INDF0 ;
  1701. MOVWF DTemp ;
  1702. RRF DTemp, W ;
  1703. ANDLW H'07' ;
  1704. MOVWF DTemp ;
  1705. MOVFW INDF1 ;
  1706. IORWF DTemp, W ;
  1707. MOVWF INDF1 ;
  1708. ADDFSR FSR0, 10 ;
  1709. ADDFSR FSR1, 4 ;
  1710. DECFSZ Temp1, F ;
  1711. GOTO _US1_DRC_Next_Line ;
  1712. ;
  1713. _US_Draw_Score2: ;
  1714. _US2_Clear_Score: ;
  1715. MOVLW LOW VIDEO_BUFFER_START + RIGHT_SCORE_START;
  1716. MOVWF FSR1L ;
  1717. MOVLW HIGH VIDEO_BUFFER_START ;
  1718. MOVWF FSR1H ;
  1719. ;
  1720. CLRW ;
  1721. MOVWI 0[INDF1] ;
  1722. MOVWI 4[INDF1] ;
  1723. MOVWI 8[INDF1] ;
  1724. MOVWI 12[INDF1] ;
  1725. MOVWI 16[INDF1] ;
  1726. ;
  1727. _US2_Draw_Left_Char: ;
  1728. SWAPF Score_2, W ;
  1729. ANDLW H'0F' ;
  1730. MOVWF Temp1 ;
  1731. ;
  1732. MOVLW LOW VIDEO_BUFFER_START + RIGHT_SCORE_START;
  1733. MOVWF FSR1L ;
  1734. MOVLW HIGH VIDEO_BUFFER_START ;
  1735. MOVWF FSR1H ;
  1736. ;
  1737. MOVLW HIGH CHARACTER_TABLE ;
  1738. MOVWF FSR0H ;
  1739. MOVLW LOW CHARACTER_TABLE ;
  1740. ADDWF Temp1, W ;
  1741. BTFSC STATUS, C ;
  1742. INCF FSR0H, F ;
  1743. MOVWF FSR0L ;
  1744. ;
  1745. MOVLW 5 ;
  1746. MOVWF Temp1 ;
  1747. _US2_DLC_Next_Line: ;
  1748. MOVFW INDF0 ;
  1749. ANDLW H'E0' ;
  1750. MOVWF INDF1 ;
  1751. ADDFSR FSR0, 10 ;
  1752. ADDFSR FSR1, 4 ;
  1753. DECFSZ Temp1, F ;
  1754. GOTO _US2_DLC_Next_Line ;
  1755. ;
  1756. _US2_Draw_Right_Char: ;
  1757. MOVFW Score_2 ;
  1758. ANDLW H'0F' ;
  1759. MOVWF Temp1 ;
  1760. ;
  1761. MOVLW LOW VIDEO_BUFFER_START + RIGHT_SCORE_START;
  1762. MOVWF FSR1L ;
  1763. MOVLW HIGH VIDEO_BUFFER_START ;
  1764. MOVWF FSR1H ;
  1765. ;
  1766. MOVLW HIGH CHARACTER_TABLE ;
  1767. MOVWF FSR0H ;
  1768. MOVLW LOW CHARACTER_TABLE ;
  1769. ADDWF Temp1, W ;
  1770. BTFSC STATUS, C ;
  1771. INCF FSR0H, F ;
  1772. MOVWF FSR0L ;
  1773. MOVLW 5 ;
  1774. MOVWF Temp1 ;
  1775. _US2_DRC_Next_Line: ;
  1776. MOVFW INDF0 ;
  1777. ANDLW H'0E' ;
  1778. MOVWF DTemp ;
  1779. MOVFW INDF1 ;
  1780. IORWF DTemp, W ;
  1781. MOVWF INDF1 ;
  1782. ADDFSR FSR0, 10 ;
  1783. ADDFSR FSR1, 4 ;
  1784. DECFSZ Temp1, F ;
  1785. GOTO _US2_DRC_Next_Line ;
  1786. ;
  1787. NOP ;
  1788. MOVFW TMR0 ;
  1789. SUBLW 227 ;
  1790. BTFSC STATUS, C ;
  1791. GOTO $-3 ;
  1792. NOP ;
  1793. NOP ;
  1794. NOP ;
  1795. NOP ;
  1796. ;
  1797. RETURN ;
  1798. ;---------------------------------------------------;
  1799.  
  1800. ;---------------------------------------------------;
  1801. _Initialize_System: ;
  1802. ;---;-----------------------------------------------;
  1803. ; Initialize Hardware ;
  1804. ;-----------------------------------------------;
  1805. BANKSEL OSCCON ;
  1806. MOVLW B'11110000' ; 32Mhz
  1807. MOVWF OSCCON ;
  1808. ;
  1809. BANKSEL OSCSTAT ; Wait for
  1810. IS1:MOVFW OSCSTAT ; high speed
  1811. ANDLW H'79' ; oscillator
  1812. XORLW H'59' ; to be
  1813. BTFSS STATUS, Z ; stable and
  1814. GOTO IS1 ; locked
  1815. ;
  1816. BANKSEL ANSELA ;
  1817. CLRF ANSELA ; ALL I/O as digital
  1818. #IF _USE_THUMBSTICKS_ ;
  1819. BSF ANSELA, LJOY_BIT ;
  1820. BSF ANSELA, RJOY_BIT ;
  1821. #ENDIF ;_USE_THUMBSTICKS_ ;
  1822. ;
  1823. BANKSEL LATA ;
  1824. CLRF LATA ;
  1825. ;
  1826. BANKSEL TRISA ;
  1827. CLRF TRISA ;
  1828. BCF TRISA, VIDEO_0_BIT ; Set as OUTPUT
  1829. BCF TRISA, VIDEO_1_BIT ; Set As OUTPUT
  1830. #IF _USE_THUMBSTICKS_ ;
  1831. BSF TRISA, LJOY_BIT ; Set as INPUT
  1832. BSF TRISA, LBUTT_BIT ; Set as INPUT
  1833. BSF TRISA, RJOY_BIT ; Set as INPUT
  1834. BCF TRISA, RBUTT_BIT ; Set as OUTPUT (PIEZO)
  1835. #ELSE ;!_USE_THUMBSTICKS_ ;
  1836. BSF TRISA, LBUTT_1_BIT ; Set as INPUT
  1837. BSF TRISA, LBUTT_2_BIT ; Set as INPUT
  1838. BSF TRISA, RBUTT_1_BIT ; Set as INPUT
  1839. BSF TRISA, RBUTT_2_BIT ; Set as INPUT
  1840. #ENDIF ;_USE_THUMBSTICKS_ ;
  1841. ;
  1842. BANKSEL PORTA ;
  1843. CLRF PORTA ;
  1844. BCF PORTA, VIDEO_0_BIT ; Set LOW
  1845. BCF PORTA, VIDEO_1_BIT ; Set LOW
  1846. #IF _USE_THUMBSTICKS_ ;
  1847. BSF PORTA, LJOY_BIT ; Set HIGH
  1848. BSF PORTA, LBUTT_BIT ; Set HIGH
  1849. BSF PORTA, RJOY_BIT ; Set HIGH
  1850. BSF PORTA, RBUTT_BIT ; Set HIGH
  1851. #ELSE ;!_USE_THUMBSTICKS_ ;
  1852. BSF PORTA, LBUTT_1_BIT ; Set HIGH
  1853. BSF PORTA, LBUTT_2_BIT ; Set HIGH
  1854. BSF PORTA, RBUTT_1_BIT ; Set HIGH
  1855. BSF PORTA, RBUTT_2_BIT ; Set HIGH
  1856. #ENDIF ;_USE_THUMBSTICKS_ ;
  1857. ;
  1858. BANKSEL INTCON ;
  1859. CLRF INTCON ;
  1860. ;
  1861. BANKSEL OPTION_REG ;
  1862. CLRF OPTION_REG ;
  1863. ;
  1864. ;-----------------------------------------------;
  1865. ; Initialize Timer0 (for counting cycles) ;
  1866. ;-----------------------------------------------;
  1867. BANKSEL OPTION_REG ;
  1868. BCF OPTION_REG, NOT_WPUEN ;
  1869. BCF OPTION_REG, TMR0CS ;
  1870. BCF OPTION_REG, PSA ; prescaler to timer0
  1871. BCF OPTION_REG, PS2 ;
  1872. BCF OPTION_REG, PS1 ; 000 - 250ns
  1873. BCF OPTION_REG, PS0 ;
  1874. BANKSEL TMR0 ;
  1875. CLRF TMR0 ;
  1876. ;
  1877. ;-----------------------------------------------;
  1878. ; Initialize Video Buffer ;
  1879. ; Copy image from EEPROM into buffer memory ;
  1880. ;-----------------------------------------------;
  1881. BANKSEL MEMORY ;
  1882. PAGESEL _Clear_Court ;
  1883. CALL _Clear_Court ;
  1884. PAGESEL _Draw_Title ;
  1885. CALL _Draw_Title ;
  1886. PAGESEL $ ;
  1887. ;
  1888. ;-----------------------------------------------;
  1889. ; Initialize Memory ;
  1890. ;-----------------------------------------------;
  1891. BANKSEL MEMORY ;
  1892. CLRF System_Status ;
  1893. MOVLW 0 ;
  1894. MOVWF Buzz_Count ;
  1895. MOVWF Buzz_Reload ;
  1896. MOVLW H'FF' ;
  1897. MOVWF Buzz_Dur_LO ;
  1898. MOVLW H'FF' ;
  1899. MOVWF Buzz_Dur_HI ;
  1900. MOVLW MAX_BALL_WAIT ;
  1901. MOVWF Ball_Wait ;
  1902. MOVLW 0 ;
  1903. MOVWF Score_1 ;
  1904. MOVLW 0 ;
  1905. MOVWF Score_2 ;
  1906. MOVLW 20 ;
  1907. MOVWF Paddle_1_Y ;
  1908. MOVLW 20 ;
  1909. MOVWF Paddle_2_Y ;
  1910. MOVLW 15 ;
  1911. MOVWF Ball_X ;
  1912. MOVLW 27 ;
  1913. MOVWF Ball_Y ;
  1914. MOVLW 0 ;
  1915. MOVWF Ball_Dir_X ;
  1916. MOVLW 0 ;
  1917. MOVWF Ball_Dir_Y ;
  1918. ;
  1919. ;-----------------------------------------------;
  1920. ; Initialize Other Subsystems ;
  1921. ;-----------------------------------------------;
  1922. ;
  1923. RETURN ;
  1924. ;---------------------------------------------------;
  1925.  
  1926. ;---------------------------------------------------;
  1927. ; Numeric Characters (0-9) Scan Line Data ;
  1928. ;---------------------------------------------------;
  1929. CHARACTER_TABLE: ;
  1930. ;---------------------------------------------------;
  1931. DT B'11101110', B'01000100', B'11101110', B'11101110', B'10101010', B'11101110', B'11101110', B'11101110', B'11101110', B'11101110'
  1932. DT B'10101010', B'11001100', B'00100010', B'00100010', B'10101010', B'10001000', B'10001000', B'00100010', B'10101010', B'10101010'
  1933. DT B'10101010', B'01000100', B'11101110', B'11101110', B'11101110', B'11101110', B'11101110', B'00100010', B'11101110', B'11101110'
  1934. DT B'10101010', B'01000100', B'10001000', B'00100010', B'00100010', B'00100010', B'10101010', B'00100010', B'10101010', B'00100010'
  1935. DT B'11101110', B'01000100', B'11101110', B'11101110', B'00100010', B'11101110', B'11101110', B'00100010', B'11101110', B'00100010'
  1936. ;---------------------------------------------------;
  1937.  
  1938. ;---------------------------------------------------;
  1939. _Draw_Title: ;
  1940. ;---------------------------------------------------;
  1941. MOVLW LOW VIDEO_BUFFER_START + (11 * 4) ;
  1942. MOVWF FSR1L ;
  1943. MOVLW HIGH VIDEO_BUFFER_START ;
  1944. MOVWF FSR1H ;
  1945. MOVLW LOW TITLE_TABLE ;
  1946. MOVWF FSR0L ;
  1947. MOVLW HIGH TITLE_TABLE ;
  1948. MOVWF FSR0H ;
  1949. MOVLW TITLE_TABLE_END - TITLE_TABLE_START ;
  1950. MOVWF Temp1 ;
  1951. _DT_Next_Byte: ;
  1952. MOVFW INDF0 ;
  1953. MOVWF INDF1 ;
  1954. ADDFSR FSR1, 1 ;
  1955. ADDFSR FSR0, 1 ;
  1956. DECFSZ Temp1, F ;
  1957. GOTO _DT_Next_Byte ;
  1958. RETURN ;
  1959. ;---------------------------------------------------;
  1960.  
  1961. ;---------------------------------------------------;
  1962. ; Title Title Scan Line Data ;
  1963. ;---------------------------------------------------;
  1964. TITLE_TABLE: ;
  1965. ;---------------------------------------------------;
  1966. TITLE_TABLE_START: ;
  1967. DT B'00000000', B'00000000', B'00000000', B'00000000'
  1968. DT B'00000000', B'01100010', B'01000100', B'00000000'
  1969. DT B'00000000', B'01110111', B'11101110', B'00000000'
  1970. DT B'00000000', B'01010101', B'10101010', B'00000000'
  1971. DT B'00000000', B'01010101', B'10101010', B'00000000'
  1972. DT B'00000000', B'01010101', B'10101010', B'00000000'
  1973. DT B'00000000', B'01010101', B'10101010', B'00000000'
  1974. DT B'00000000', B'01110101', B'10101110', B'00000000'
  1975. DT B'00000000', B'01100101', B'10100110', B'00000000'
  1976. DT B'00000000', B'01000101', B'10100010', B'00000000'
  1977. DT B'00000000', B'01000101', B'10101010', B'00000000'
  1978. DT B'00000000', B'01000111', B'10101110', B'00000000'
  1979. DT B'00000000', B'01000010', B'10100100', B'00000000'
  1980. DT B'00000000', B'00000000', B'00000000', B'00000000'
  1981. DT B'00001110', B'01001100', B'01110101', B'01110000'
  1982. DT B'00001110', B'11101110', B'01110101', B'01110000'
  1983. DT B'00001000', B'10101010', B'00100101', B'01000000'
  1984. DT B'00001000', B'10101010', B'00100101', B'01000000'
  1985. DT B'00001000', B'10101010', B'00100101', B'01000000'
  1986. DT B'00001100', B'10101110', B'00100111', B'01100000'
  1987. DT B'00001100', B'10101100', B'00100111', B'01100000'
  1988. DT B'00001000', B'10101010', B'00100101', B'01000000'
  1989. DT B'00001000', B'10101010', B'00100101', B'01000000'
  1990. DT B'00001000', B'10101010', B'00100101', B'01000000'
  1991. DT B'00001000', B'11101010', B'00100101', B'01110000'
  1992. DT B'00001000', B'01001010', B'00100101', B'01110000'
  1993. DT B'00000000', B'00000000', B'00000000', B'00000000'
  1994. DT B'00000101', B'10011101', B'01001010', B'01000000'
  1995. DT B'00000101', B'11011101', B'11101010', B'11100000'
  1996. DT B'00000100', B'01010001', B'10101010', B'10100000'
  1997. DT B'00000100', B'01010001', B'10101010', B'10100000'
  1998. DT B'00000100', B'11010001', B'11101010', B'10100000'
  1999. DT B'00000101', B'11011001', B'01001110', B'10100000'
  2000. DT B'00000101', B'00011001', B'11101110', B'10100000'
  2001. DT B'00000101', B'00010001', B'10100010', B'10100000'
  2002. DT B'00000101', B'00010001', B'10100010', B'10100000'
  2003. DT B'00000101', B'00010001', B'10100010', B'10100000'
  2004. DT B'00000101', B'11010001', B'11100010', B'11100000'
  2005. DT B'00000101', B'11010001', B'01000010', B'01000000'
  2006. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2007. TITLE_TABLE_END: ;
  2008. ;---------------------------------------------------;
  2009.  
  2010. ;---------------------------------------------------;
  2011. _Copyright: ;
  2012. ;---------------------------------------------------;
  2013. ; Note: This is a 60us line routine. It will ;
  2014. ; generate 8 60us data lines. ;
  2015. ;---------------------------------------------------;
  2016. ;-----------------------------------------------;
  2017. ; Setup ;
  2018. ;-----------------------------------------------;
  2019. MOVLW LOW COPYRIGHT_TABLE ;
  2020. MOVWF FSR1L ;
  2021. MOVLW HIGH COPYRIGHT_TABLE ;
  2022. MOVWF FSR1H ;
  2023. MOVLW 8 ;
  2024. MOVWF Temp1 ;
  2025. ;-----------------------------------------------;
  2026. ;
  2027. ;-----------------------------------------------;
  2028. ; 8 64us Data Line Generation ;
  2029. ;-----------------------------------------------;
  2030. _CR_Next_Line: ;
  2031. NOP ;
  2032. ;-----------------------------------------------;
  2033. ; 4us Negative Sync Generation ;
  2034. ;-----------------------------------------------;
  2035. NEG_SYNC_4US ;
  2036. ;-----------------------------------------------;
  2037. ;
  2038. ;-----------------------------------------------;
  2039. ; Xus Back Porch (Black Signal) Generation ;
  2040. ;-----------------------------------------------;
  2041. SET_SIGNAL COLOR_BLACK ;
  2042. DELAY 4 ;
  2043. NOP ;
  2044. NOP ;
  2045. NOP ;
  2046. ;-----------------------------------------------;
  2047. ;
  2048. ;-----------------------------------------------;
  2049. ; Data Generation ;
  2050. ;-----------------------------------------------;
  2051. DO_BIT 7, 1 ;
  2052. DO_BIT 6, 1 ;
  2053. DO_BIT 5, 1 ;
  2054. DO_BIT 4, 1 ;
  2055. DO_BIT 3, 1 ;
  2056. DO_BIT 2, 1 ;
  2057. DO_BIT 1, 1 ;
  2058. DO_BIT 0, 0 ;
  2059. ADDFSR FSR1, 1 ;
  2060. DO_BIT 7, 1 ;
  2061. DO_BIT 6, 1 ;
  2062. DO_BIT 5, 1 ;
  2063. DO_BIT 4, 1 ;
  2064. DO_BIT 3, 1 ;
  2065. DO_BIT 2, 1 ;
  2066. DO_BIT 1, 1 ;
  2067. DO_BIT 0, 0 ;
  2068. ADDFSR FSR1, 1 ;
  2069. DO_BIT 7, 1 ;
  2070. DO_BIT 6, 1 ;
  2071. DO_BIT 5, 1 ;
  2072. DO_BIT 4, 1 ;
  2073. DO_BIT 3, 1 ;
  2074. DO_BIT 2, 1 ;
  2075. DO_BIT 1, 1 ;
  2076. DO_BIT 0, 0 ;
  2077. ADDFSR FSR1, 1 ;
  2078. DO_BIT 7, 1 ;
  2079. DO_BIT 6, 1 ;
  2080. DO_BIT 5, 1 ;
  2081. DO_BIT 4, 1 ;
  2082. DO_BIT 3, 1 ;
  2083. DO_BIT 2, 1 ;
  2084. DO_BIT 1, 1 ;
  2085. DO_BIT 0, 0 ;
  2086. ADDFSR FSR1, 1 ;
  2087. DO_BIT 7, 1 ;
  2088. DO_BIT 6, 1 ;
  2089. DO_BIT 5, 1 ;
  2090. DO_BIT 4, 1 ;
  2091. DO_BIT 3, 1 ;
  2092. DO_BIT 2, 1 ;
  2093. DO_BIT 1, 1 ;
  2094. DO_BIT 0, 0 ;
  2095. ADDFSR FSR1, 1 ;
  2096. DO_BIT 7, 1 ;
  2097. DO_BIT 6, 1 ;
  2098. DO_BIT 5, 1 ;
  2099. DO_BIT 4, 1 ;
  2100. DO_BIT 3, 1 ;
  2101. DO_BIT 2, 1 ;
  2102. DO_BIT 1, 1 ;
  2103. DO_BIT 0, 0 ;
  2104. ADDFSR FSR1, 1 ;
  2105. DO_BIT 7, 1 ;
  2106. DO_BIT 6, 1 ;
  2107. DO_BIT 5, 1 ;
  2108. DO_BIT 4, 1 ;
  2109. DO_BIT 3, 1 ;
  2110. DO_BIT 2, 1 ;
  2111. DO_BIT 1, 1 ;
  2112. DO_BIT 0, 0 ;
  2113. ADDFSR FSR1, 1 ;
  2114. DO_BIT 7, 1 ;
  2115. DO_BIT 6, 1 ;
  2116. DO_BIT 5, 1 ;
  2117. DO_BIT 4, 1 ;
  2118. DO_BIT 3, 1 ;
  2119. DO_BIT 2, 1 ;
  2120. DO_BIT 1, 1 ;
  2121. DO_BIT 0, 0 ;
  2122. ADDFSR FSR1, 1 ;
  2123. ;-----------------------------------------------;
  2124. ;
  2125. ;-----------------------------------------------;
  2126. ; Xus Front Porch (Black Signal) Generation ;
  2127. ;-----------------------------------------------;
  2128. SET_SIGNAL COLOR_BLACK ;
  2129. ;-----------------------------------------------;
  2130. ;
  2131. DECFSZ Temp1, F ;
  2132. GOTO $+3 ;
  2133. NOP ;
  2134. RETURN ;
  2135. NOP ;
  2136. NOP ;
  2137. GOTO _CR_Next_Line ;
  2138. ;---------------------------------------------------;
  2139.  
  2140. ;---------------------------------------------------;
  2141. ; COPYRIGHT Scan Line Data ;
  2142. ;---------------------------------------------------;
  2143. COPYRIGHT_TABLE: ;
  2144. ;---------------------------------------------------;
  2145. DT B'00000110', B'01110111', B'00010010', B'01001110', B'01000101', B'11000101', B'01110000', B'10011100'
  2146. DT B'00000111', B'01110111', B'00100111', B'00101110', B'11101101', B'11000101', B'01110001', B'11011100'
  2147. DT B'00000101', B'00100010', B'00100101', B'00100010', B'10100100', B'01000101', B'00010001', B'01000100'
  2148. DT B'01010101', B'00100010', B'00100100', B'00101110', B'10100101', B'11010101', B'00110001', B'01001100'
  2149. DT B'01010101', B'00100010', B'00100100', B'00101110', B'10100101', B'11010101', B'00110001', B'01001100'
  2150. DT B'00000101', B'00100010', B'00100101', B'00101000', B'10100101', B'00000101', B'00010001', B'01000100'
  2151. DT B'00000111', B'00100111', B'00100111', B'00101110', B'11100101', B'11000101', B'01110101', B'11011100'
  2152. DT B'00000110', B'00100111', B'00010010', B'01001110', B'01000101', B'11000010', B'01110100', B'10011100'
  2153. ;---------------------------------------------------;
  2154.  
  2155. ;---------------------------------------------------;
  2156. END ;
  2157. ;---------------------------------------------------;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement