Advertisement
Guest User

PONG.ASM V3.07

a guest
Dec 24th, 2012
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 93.74 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 24, 2012 ;
  13. ; Version: V3.07 ;
  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. ; V3.04: Updated version number display to V3.04 ;
  82. ; - Changed the use of Timer0 (8bit) from ;
  83. ; loading zero and waiting for count to ;
  84. ; loading (inverse) count and waiting for ;
  85. ; overflow flag (TMR0IF) in INTCON. ;
  86. ; - Created _Clear_Items and _Draw_Items. ;
  87. ; _Clear_Items clears ball, paddles, scores ;
  88. ; _Draw_Items draws ball, paddles, scores ;
  89. ; - Removed _Update_Scores, since one half ;
  90. ; went into _Clear_Items and the other half ;
  91. ; went into _Draw_Items. There was nothing ;
  92. ; left, except for 60us line generation, ;
  93. ; after that. ;
  94. ; V3.05: Updated verion number display to V3.05 ;
  95. ; - Changed field size from 32x56 to 32x48 ;
  96. ; - Changed VIDEO_BUFFER start from H'2010' to;
  97. ; H'2020' to recover 16 bytes of data memory;
  98. ; that are now available due to small field ;
  99. ; - Added dynamic creation of blank lines ;
  100. ; depending on screen size. This will keep ;
  101. ; the screen centered (vertically) in the ;
  102. ; viewable area of the video frame and keep ;
  103. ; the video frame at 60hz ;
  104. ; - Added court sidelines so that the limits ;
  105. ; of the court can be easily determined no ;
  106. ; matter the size of the field. ;
  107. ; - Added 'SERVICE' markers (arrows next to ;
  108. ; the scores) to easily determine who's turn;
  109. ; it is to serve. Last one scored serves. ;
  110. ; - Reduced size of title screen and changed ;
  111. ; title back to just 'PONG'. Title screen ;
  112. ; was too large and the time to draw (or ;
  113. ; clear) was blowing WAY past the 60us limit;
  114. ; - Changed wall collision detection so that ;
  115. ; Ball_Dir_Y can be something other that 1 ;
  116. ; or -1. This opens the door to implementing;
  117. ; 'english' on the ball ;
  118. ; - Service is now done from the paddle, not ;
  119. ; center court. And the beginning Ball_Y ;
  120. ; position is centered with the paddle ;
  121. ; - Ball angle on service (Ball_Dir_Y at 1 or ;
  122. ; for the left paddle, -1 or -2 for the ;
  123. ; right paddle) depends on paddle position ;
  124. ; - The starting position of the scores has ;
  125. ; been dropped one line to keep the score ;
  126. ; display from bumping against the court ;
  127. ; side line. ;
  128. ; - With a field of 32x48, PONG has been ;
  129. ; testing on a Sony PS1 LCD monitor, a small;
  130. ; PHILIPS LCD TV, and a regular CRT TV which;
  131. ; all work well. However, a 32" Chinese made;
  132. ; LCD TV does not work - maybe because it ;
  133. ; wants 50hz? Any feedback on various TVs ;
  134. ; used with PONG would be appreciated. ;
  135. ; - Added a check to see if the left or right ;
  136. ; button is being held - this keeps from ;
  137. ; holding the button down and continuously ;
  138. ; serving the ball. ;
  139. ; - Even MORE comments added. I sure hope I ;
  140. ; remove all of the old (irrelevent) ones. ;
  141. ; - Back to the large graphics to the title. ;
  142. ; I split it into two 60us lines. Also did ;
  143. ; a lot of tricks to reduce the instruction ;
  144. ; count. _Clear_Screen replaces _Clear_Items;
  145. ; and will clear the screen OR display the ;
  146. ; title at the appropriate time. ;
  147. ; - EVERYTHING uses TIMER0 now, except for ;
  148. ; generating a positive 2us sync pulse. Not ;
  149. ; enough cycles to incorporate the timer. ;
  150. ; - All loose code and commented out lines ;
  151. ; removed. All timings at spec. RELEASE! ;
  152. ; V3.06: Updated verion number display to V3.06 ;
  153. ; - Corrected a few bugs in ball/paddle ;
  154. ; collision detection. ;
  155. ; - Corrected a bug in _Clear_Screen ;
  156. ; - Moved all 30us stuff to a procedure called;
  157. ; _Vertical_Sync. ;
  158. ; - Split the code as evenly as I could ;
  159. ; between the low page and high page of ;
  160. ; program memory. Lots of room for editing ;
  161. ; now without worrying about bumping the ;
  162. ; ceilings. There's around 900 program words;
  163. ; free in each page. ;
  164. ; - I don't think there are any major bugs - ;
  165. ; just enhancements waiting in the wings. ;
  166. ; Time to final release and move on! ;
  167. ; V3.07: Updated verion number display to V3.07 ;
  168. ; - Added a blank line and then two white ;
  169. ; lines just after the copyright lines. Just;
  170. ; because I like it better. ;
  171. ; - Fixed the 'shoot off in a horitontal angle;
  172. ; when hitting the upper sideline wall' bug.;
  173. ; If you saw the V3.06 demo video, it was ;
  174. ; occurring frequently and the OCD in me ;
  175. ; said "You gotta fix that". ;
  176. ; That's it for this version - RELEASE! ;
  177. ;---------------------------------------------------;
  178. ;---------------------------------------------------;
  179.  
  180. ;---------------------------------------------------;
  181. ; Project Defines ;
  182. ;---------------------------------------------------;
  183. #DEFINE _PONG.ASM_ ;
  184. #DEFINE _MAIN_MODULE_ ;
  185. ;---------------------------------------------------;
  186. #DEFINE _DEBUG_ FALSE ;
  187. #DEFINE _USE_THUMBSTICKS_ TRUE ;
  188. ;---------------------------------------------------;
  189.  
  190. ;---------------------------------------------------;
  191. ; Includes ;
  192. ;---------------------------------------------------;
  193. ; This file has some common defines (TRUE, FALSE, ;
  194. ; etc.) used throughout the program. It also has the;
  195. ; CONFIGURATION_BITS settings for the PIC, which are;
  196. ; only processed in the module that has the define ;
  197. ; _MAIN_MODULE_. ;
  198. ;---------------------------------------------------;
  199. #INCLUDE Common.INC ;
  200. ;---------------------------------------------------;
  201.  
  202. ;---------------------------------------------------;
  203. ; Macros ;
  204. ;---------------------------------------------------;
  205. DELAY MACRO DTIME ;
  206. ;-----------------------------------------------;
  207. ; The time munger used EVERYWHERE ;
  208. ;-----------------------------------------------;
  209. MOVLW DTIME ;
  210. MOVWF DTemp ;
  211. DECFSZ DTemp, F ;
  212. GOTO $-1 ;
  213. ;-----------------------------------------------;
  214. ENDM ;
  215. ;
  216. DO_BIT MACRO THISBIT, NOPS ;
  217. ;-----------------------------------------------;
  218. ; Sets the DAC either WHITE or BLACK ;
  219. ; Does a specified delay in NOPs ;
  220. ;-----------------------------------------------;
  221. ; NOTE: This is used in the higher resolution ;
  222. ; COPYRIGHT lines and when generating the ;
  223. ; gameplay data lines. ;
  224. ;-----------------------------------------------;
  225. ; Note that a WHITE bit check is done first and ;
  226. ; then a BLACK bit check. If you reverse the ;
  227. ; order, things look a bit differently on the ;
  228. ; screen. That is because there is a two ;
  229. ; instruction delay between writing the bit in ;
  230. ; one state or in the other state. Reversing the;
  231. ; order (BLACK first, then WHITE) causes black ;
  232. ; 'gaps'. This order is most visually appealing,;
  233. ; at least to me. ;
  234. ;-----------------------------------------------;
  235. BTFSC INDF1, THISBIT ;
  236. BSF PORTA, VIDEO_0_BIT ;
  237. BTFSS INDF1, THISBIT ;
  238. BCF PORTA, VIDEO_0_BIT ;
  239. #IF NOPS > 0 ;
  240. NOP ;
  241. #ENDIF ;
  242. #IF NOPS > 1 ;
  243. NOP ;
  244. #ENDIF ;
  245. #IF NOPS > 2 ;
  246. NOP ;
  247. #ENDIF ;
  248. #IF NOPS > 3 ;
  249. NOP ;
  250. #ENDIF ;
  251. #IF NOPS > 4 ;
  252. NOP ;
  253. #ENDIF ;
  254. #IF NOPS > 5 ;
  255. NOP ;
  256. #ENDIF ;
  257. #IF NOPS > 6 ;
  258. NOP ;
  259. #ENDIF ;
  260. #IF NOPS > 7 ;
  261. NOP ;
  262. #ENDIF ;
  263. #IF NOPS > 8 ;
  264. NOP ;
  265. #ENDIF ;
  266. #IF NOPS > 9 ;
  267. NOP ;
  268. #ENDIF ;
  269. ;-----------------------------------------------;
  270. ENDM ;
  271. ;
  272. SET_DAC2BIT MACRO COLOR ;
  273. ;-----------------------------------------------;
  274. ; Sets the 2bit DAC to the desired color ;
  275. ; Both bits are done at once, or else some weird;
  276. ; transitions on the DAC can be seen. Okay if ;
  277. ; just colors (WHITE, GRAY, BLACK), but if a ;
  278. ; sync pulse shows up out context, it can really;
  279. ; mess up the video timings ;
  280. ;-----------------------------------------------;
  281. MOVFW PORTA ;
  282. ANDLW ~(VIDEO_0 | VIDEO_1) ;
  283. IORLW COLOR ;
  284. MOVWF PORTA ;
  285. ;-----------------------------------------------;
  286. ENDM ;
  287. ;
  288. NEG_SYNC_4US MACRO ;
  289. ;-----------------------------------------------;
  290. ; 4us Negative Sync Generation ;
  291. ;-----------------------------------------------;
  292. ; Not only does this do a 4us negative sync, it ;
  293. ; also handles the sound generation during the ;
  294. ; game. Sounds are produced by toggling GPIO1 ;
  295. ; during HSYNCs - if it is toggled during ALL ;
  296. ; HSYNCs, you get a high freq (around 7800hz). ;
  297. ; If every other HSYNC, the freq is around lower;
  298. ;-----------------------------------------------;
  299. ; Don't touch this unless you really understand ;
  300. ; it. I am trying to keep the number of cycles ;
  301. ; equal even when playing sounds. If this is ;
  302. ; changed, it could cause 'tearing' of the ;
  303. ; video when a sound is playing. ;
  304. ;-----------------------------------------------;
  305. START_LINE COLOR_SYNC, 4, 6 ;
  306. BTFSS System_Status, BUZZ_BIT ;
  307. GOTO $+16 ;
  308. DECFSZ Buzz_Count, F ;
  309. GOTO $+16 ;
  310. MOVFW Buzz_Reload ;
  311. MOVWF Buzz_Count ;
  312. BANKSEL TRISA ;
  313. BCF TRISA, RBUTT_BIT ; Set as OUTPUT
  314. BANKSEL MEMORY ;
  315. MOVLW RBUTT ;
  316. XORWF PORTA, F ;
  317. DECFSZ Buzz_Dur_LO, F ;
  318. GOTO $+16 ;
  319. DECFSZ Buzz_Dur_HI, F ;
  320. GOTO $+16 ;
  321. BCF System_Status, BUZZ_BIT ;
  322. GOTO $+15 ;
  323. NOP ;
  324. NOP ;
  325. NOP ;
  326. NOP ;
  327. NOP ;
  328. NOP ;
  329. NOP ;
  330. NOP ;
  331. NOP ;
  332. NOP ;
  333. NOP ;
  334. NOP ;
  335. NOP ;
  336. NOP ;
  337. WAIT_FOR_LINE_DONE 0 ;
  338. ;-----------------------------------------------;
  339. ENDM ;
  340. ;
  341. START_LINE MACRO COLOR, LENGTH, ADJUST ;
  342. ;-----------------------------------------------;
  343. ; Starts a line of COLOR (usually WHITE, BLACK, ;
  344. ; or SYNC), for a specified length (usually 30 ;
  345. ; or 60) with an adjustment for the length so ;
  346. ; the line timings can be 'fudged' ;
  347. ;-----------------------------------------------;
  348. SET_DAC2BIT COLOR ;
  349. MOVLW ~((LENGTH*4)-ADJUST) ;
  350. MOVWF TMR0 ;
  351. BCF INTCON, TMR0IF ;
  352. ;-----------------------------------------------;
  353. ENDM ;
  354. ;
  355. WAIT_FOR_LINE_DONE MACRO NOPS ;
  356. ;-----------------------------------------------;
  357. ; Wait for this line to complete. NOPs can be ;
  358. ; added by setting NOPS to a number > 0. Only a ;
  359. ; maximum of 5 NOPs can be added. This is for ;
  360. ; 'fudging' the line timings to get them spot-on;
  361. ;-----------------------------------------------;
  362. BTFSS INTCON, TMR0IF ;
  363. GOTO $-1 ;
  364. #IF NOPS > 0 ;
  365. NOP ;
  366. #ENDIF ;
  367. #IF NOPS > 1 ;
  368. NOP ;
  369. #ENDIF ;
  370. #IF NOPS > 2 ;
  371. NOP ;
  372. #ENDIF ;
  373. #IF NOPS > 3 ;
  374. NOP ;
  375. #ENDIF ;
  376. #IF NOPS > 4 ;
  377. NOP ;
  378. #ENDIF ;
  379. ;-----------------------------------------------;
  380. ENDM ;
  381. ;
  382. NEG_SYNC_2US MACRO ;
  383. ;-----------------------------------------------;
  384. ; 2us Negative Sync Generation ;
  385. ;-----------------------------------------------;
  386. ; Used during VSYNC only. ;
  387. ;-----------------------------------------------;
  388. START_LINE COLOR_SYNC, 2, 6 ;
  389. WAIT_FOR_LINE_DONE 1 ;
  390. ;-----------------------------------------------;
  391. ENDM ;
  392. ;
  393. POS_SYNC_2US MACRO ;
  394. ;-----------------------------------------------;
  395. ; 2us Positive Sync Generation ;
  396. ;-----------------------------------------------;
  397. ; Using during VSYNC only. ;
  398. ; There is not enough time to use TIMER0 ;
  399. ;-----------------------------------------------;
  400. SET_DAC2BIT COLOR_BLACK ;
  401. ;-----------------------------------------------;
  402. ; These NOPs set the timing for the 2us pulse ;
  403. ;-----------------------------------------------;
  404. NOP ;
  405. NOP ;
  406. NOP ;
  407. NOP ;
  408. NOP ;
  409. NOP ;
  410. ;-----------------------------------------------;
  411. ENDM ;
  412. ;
  413. PLAY_SOUND MACRO FREQUENCY, DURATION ;
  414. ;-----------------------------------------------;
  415. ; This will play a sound of a specified ;
  416. ; frequency for a specified duration ;
  417. ; The lower the frequency number, the higher ;
  418. ; the frequency. Duration is also a function ;
  419. ; of the frequency number, so if frequency goes ;
  420. ; up, adjust the duration down. ;
  421. ;-----------------------------------------------;
  422. ; Sound is played during 4us HORIZONTAL SYNC ;
  423. ; times of the video signal. There is a short ;
  424. ; period during VERTICAL SYNC where nothing is ;
  425. ; done with sound because there ARE no 4us ;
  426. ; HSYNCs. There are 2us HSYNCs during VSYNC, but;
  427. ; there isn't enough time to process the sound ;
  428. ; code without stretching out the 2us HSYNCs ;
  429. ; beyond 2us, and that will mess up the video ;
  430. ; timings. The total time between the last 4us ;
  431. ; HSYNC before VSYNC and the first 4us HSYNC ;
  432. ; after VSYNC is only ~512us, so it's barely ;
  433. ; noticable. After all, it's only a game... ;
  434. ;-----------------------------------------------;
  435. ; NOTE that a FREQUENCY of 0 is treated as a ;
  436. ; frequency of 256. 0<=Freq<=255. The count is ;
  437. ; decremented BEFORE it is checked to be 0, so ;
  438. ; starting with 0 will dec, see 255, continue ;
  439. ; loop. Just so you are warned. ;
  440. ;-----------------------------------------------;
  441. MOVLW FREQUENCY ;
  442. MOVWF Buzz_Count ;
  443. MOVWF Buzz_Reload ;
  444. MOVLW LOW DURATION ;
  445. MOVWF Buzz_Dur_LO ;
  446. MOVLW HIGH DURATION ;
  447. MOVWF Buzz_Dur_HI ;
  448. BSF System_Status, BUZZ_BIT ;
  449. ;-----------------------------------------------;
  450. ENDM ;
  451. ;---------------------------------------------------;
  452.  
  453. ;---------------------------------------------------;
  454. ; Defines ;
  455. ;---------------------------------------------------;
  456. ; You have to chose between using all buttons, ;
  457. ; or using a thumbstick with a button. I might ;
  458. ; be able to figure out a way to automatically ;
  459. ; determine which is connected, but for now you ;
  460. ; will just have to decide which you want, set ;
  461. ; _USE_THUMBSTICKS_ to either TRUE or FALSE, and;
  462. ; re-compile the project. ;
  463. ;-----------------------------------------------;
  464. #IF _USE_THUMBSTICKS_ ;
  465. #DEFINE RJOY H'01' ; Right THUMBSTICK
  466. #DEFINE RJOY_BIT 0 ; GPIO 0 - PIN 7
  467. #DEFINE RBUTT H'02' ; Right BUTTON
  468. #DEFINE RBUTT_BIT 1 ; GPIO 1 - PIN 6
  469. #DEFINE LJOY H'04' ; Left THUMBSTICK
  470. #DEFINE LJOY_BIT 2 ; GPIO 2 - PIN 5
  471. #DEFINE LBUTT H'08' ; Left BUTTON
  472. #DEFINE LBUTT_BIT 3 ; GPIO 3 - PIN 4
  473. #ELSE ;!_USE_THUMBSTICKS_ ;
  474. #DEFINE RBUTT_1 H'01' ; Right BUTTON 1
  475. #DEFINE RBUTT_1_BIT 0 ; GPIO 0 - PIN 7
  476. #DEFINE RBUTT_2 H'02' ; Right BUTTON 2
  477. #DEFINE RBUTT_2_BIT 1 ; GPIO 1 - PIN 6
  478. #DEFINE LBUTT_2 H'04' ; Left BUTTON 2
  479. #DEFINE LBUTT_2_BIT 2 ; GPIO 2 - PIN 5
  480. #DEFINE LBUTT_1 H'08' ; Left BUTTON 1
  481. #DEFINE LBUTT_1_BIT 3 ; GPIO 3 - PIN 4
  482. #ENDIF ;_USE_THUMBSTICKS_ ;
  483. ;-----------------------------------------------;
  484. ;
  485. ;-----------------------------------------------;
  486. ; 2bit DAC definitions. The 2bit DAC is just a ;
  487. ; pair of resistors on two GPIOs, which feeds ;
  488. ; the VIDEO out. ;
  489. ;-----------------------------------------------;
  490. #DEFINE VIDEO_1 H'10' ; 1K ohm
  491. #DEFINE VIDEO_1_BIT 4 ; GPIO 5 - PIN 2
  492. #DEFINE VIDEO_0 H'20' ; 470 ohm
  493. #DEFINE VIDEO_0_BIT 5 ; GPIO 4 - PIN 3
  494. ;
  495. #DEFINE COLOR_WHITE (VIDEO_0 + VIDEO_1) ;
  496. #DEFINE COLOR_BLACK VIDEO_1 ;
  497. #DEFINE COLOR_GRAY VIDEO_0 ;
  498. #DEFINE COLOR_SYNC 0 ;
  499. ;-----------------------------------------------;
  500. ;
  501. ;-----------------------------------------------;
  502. ; There are 224 lines created during _Data_Lines;
  503. ; However, because of memory limitations, I ;
  504. ; cannot allocate enough memory for the video ;
  505. ; buffer. So - I do have enough memory for 56 ;
  506. ; lines - 1/4 of 224 - so we display each line ;
  507. ; of data 4 times. ;
  508. ;-----------------------------------------------;
  509. #DEFINE MAX_LINES 56 ; DON'T EXCEED 56
  510. ;-----------------------------------------------;
  511. ; Make certain NUM_LINES is an even number so ;
  512. ; all of the math works out properly. Make sure ;
  513. ; NOT to exceed the MAX_LINES value. And don't ;
  514. ; change NUM_LINES for less than 9 - that's the ;
  515. ; paddle height, so that will probably break it.;
  516. ; But then - the paddle height is adjustable ;
  517. ; with just changing a define (below), so - who ;
  518. ; knows! ;
  519. ;-----------------------------------------------;
  520. #DEFINE NUM_LINES 48 ; DON'T EXCEED 48
  521. ;-----------------------------------------------;
  522. ;
  523. ;-----------------------------------------------;
  524. ; This is my method of making the game easier or;
  525. ; harder - either I update and draw the ball ;
  526. ; every frame (fast ball), or every other frame ;
  527. ; (not as fast), or every 3rd frame (normal ;
  528. ; ball) or higher for slower. Set MAX_BALL_WAIT ;
  529. ; to the desired speed (1=fast, 2=not as fast, ;
  530. ; 3=normal, 4=slower, etc.). This is hardcoded ;
  531. ; right now, a change requires a recompile. I ;
  532. ; have plans to allocate another precious byte ;
  533. ; of data memory so that the ball speed can be ;
  534. ; changed by a menu item. ;
  535. ;-----------------------------------------------;
  536. #DEFINE DRAW_BALL_BIT 0 ;
  537. #DEFINE MAX_BALL_WAIT 3 ;
  538. ;
  539. ;-----------------------------------------------;
  540. ; Just a bunch of hardcoded starting points, ;
  541. ; sizes, and bit-munching stuff for the various ;
  542. ; graphics. ;
  543. ;-----------------------------------------------;
  544. ; I use the PIC's LINEAR MEMORY scheme to create;
  545. ; a contiguous video buffer. Grab the MicroChip ;
  546. ; documentation and read up. Then go search on ;
  547. ; the web for some docs that will really explain;
  548. ; it for you. ;
  549. ;-----------------------------------------------;
  550. #DEFINE VIDEO_BUFFER_START H'2030' ;
  551. #DEFINE FIELD_HEIGHT NUM_LINES ;
  552. #DEFINE FIELD_WIDTH 32 ;
  553. #DEFINE LEFT_SCORE_START H'05' ;
  554. #DEFINE RIGHT_SCORE_START H'06' ;
  555. #DEFINE LEFT_PADDLE_START H'00' ;
  556. #DEFINE LEFT_PADDLE_BIT H'40' ;
  557. #DEFINE LEFT_PADDLE_MASK H'BF' ;
  558. #DEFINE RIGHT_PADDLE_START H'03' ;
  559. #DEFINE RIGHT_PADDLE_BIT H'02' ;
  560. #DEFINE RIGHT_PADDLE_MASK H'FD' ;
  561. #DEFINE PADDLE_HEIGHT 9 ;
  562. #DEFINE BALL_HEIGHT 3 ;
  563. #DEFINE SERVICE_1_START H'04' ;
  564. #DEFINE SERVICE_2_START H'07' ;
  565. ;---------------------------------------------------;
  566.  
  567. ;---------------------------------------------------;
  568. ;---------------------------------------------------;
  569. USER_DATA_1 UDATA H'020' ;
  570. ;---------------------------------------------------;
  571. Ball_X res 1 ; 20
  572. Ball_Y res 1 ; 21
  573. Ball_Dir_X res 1 ; 22
  574. Ball_Dir_Y res 1 ; 23
  575. Paddle_1_Y res 1 ; 24
  576. Paddle_2_Y res 1 ; 25
  577. Score_1 res 1 ; 26
  578. Score_2 res 1 ; 27
  579. Ball_Wait res 1 ; 28
  580. ;---------------------------------------------------;
  581. ; Bit definitions for System_Status ;
  582. ;---------------------------------------------------;
  583. #DEFINE BUZZ H'01' ;
  584. #DEFINE BUZZ_BIT 0 ;
  585. #DEFINE P1_SERVICE H'02' ;
  586. #DEFINE P1_SERVICE_BIT 1 ;
  587. #DEFINE P2_SERVICE H'04' ;
  588. #DEFINE P2_SERVICE_BIT 2 ;
  589. #DEFINE P1_PRESSED H'08' ;
  590. #DEFINE P1_PRESSED_BIT 3 ;
  591. #DEFINE P2_PRESSED H'10' ;
  592. #DEFINE P2_PRESSED_BIT 4 ;
  593. ;---------------------------------------------------;
  594. System_Status res 1 ; 29
  595. ;---------------------------------------------------;
  596. ; Consume Left_Overs / Smaller_Screen for your data ;
  597. ; variables as need. LO/SS is just here to pad to ;
  598. ; push Video_Buffer1 to the proper spot. ;
  599. Left_Overs res 6 ; 2A-2F
  600. ;---------------------------------------------------;
  601. ; Only 6 bytes left - 2A-2F ;
  602. ;---------------------------------------------------;
  603. Smaller_Screen res 32 ; 30-4F
  604. ;---------------------------------------------------;
  605. ; I've pushed the VIDEO_BUFFER to H'2020', since the;
  606. ; field has become smaller (32x48 vs 32x56). The ;
  607. ; required size of the VIDEO_BUFFER is also less, so;
  608. ; this will give up 24 more bytes of data memory for;
  609. ; use in game programming. ;
  610. ;---------------------------------------------------;
  611. ; 16 additional bytes left (smaller screen) - 30-3F ;
  612. ;---------------------------------------------------;
  613. ; We don't access the Video_BufferX arrays directly,;
  614. ; we use LINEAR PAGE memory through the FSR register;
  615. ; LINEAR PAGE memory groups the data memory at 0x20,;
  616. ; 0xA0, and Ox120 into a contiguous linear page. ;
  617. ; Note that the shared memory (at the top 16 bytes ;
  618. ; of each page) is NOT included in the LINEAR PAGE ;
  619. ; memory mapping. ;
  620. ;---------------------------------------------------;
  621. ; MEMORY MAP - LINEAR PAGE MEMORY - 240 bytes total ;
  622. ; 0x2000-0x204F - 0x020-0x06F 80 bytes ;
  623. ; 0x2050-0x20BF - 0x0A0-0x0EF 80 bytes ;
  624. ; 0x20A0-0x20EF - 0x120-0x16F 80 bytes ;
  625. ;---------------------------------------------------;
  626. ; Since out max lines (now) is 48, we need 48x8 ;
  627. ; (192) bytes of memory for the screen buffer. This ;
  628. ; leaves us with 48 bytes of data memory for program;
  629. ; variables, plus the 16 in shared memory for 64! ;
  630. ;---------------------------------------------------;
  631. Video_Buffer1 res 32 ; 50-6F
  632. ;---------------------------------------------------;
  633. ;---------------------------------------------------;
  634.  
  635. ;---------------------------------------------------;
  636. ;---------------------------------------------------;
  637. USER_DATA_2 UDATA H'0A0' ;
  638. ;---------------------------------------------------;
  639. Video_Buffer2 res 80 ; A0-EF
  640. ;---------------------------------------------------;
  641. ;---------------------------------------------------;
  642.  
  643. ;---------------------------------------------------;
  644. ;---------------------------------------------------;
  645. USER_DATA_3 UDATA H'120' ;
  646. ;---------------------------------------------------;
  647. Video_Buffer3 res 80 ; 120-6F
  648. ;---------------------------------------------------;
  649. ;---------------------------------------------------;
  650.  
  651. ;---------------------------------------------------;
  652. ;---------------------------------------------------;
  653. USER_DATA_S UDATA_SHR H'070' ;
  654. ;---------------------------------------------------;
  655. Temp1 res 1 ; 70
  656. Temp2 res 1 ; 71
  657. DTemp res 1 ; 72
  658. DL_Count res 1 ; 73
  659. Line_Data res 4 ; 74-77
  660. Byte_Count res 1 ; 78
  661. Line_Count res 1 ; 79
  662. Repeat_Count res 1 ; 7A
  663. Buzz_Count res 1 ; 7B
  664. Buzz_Reload res 1 ; 7C
  665. Buzz_Dur_HI res 1 ; 7D
  666. Buzz_Dur_LO res 1 ; 7E
  667. ;---------------------------------------------------;
  668. ; Only 1 bytes left! - 7F ;
  669. ;---------------------------------------------------;
  670. ;---------------------------------------------------;
  671.  
  672. ;---------------------------------------------------;
  673. ;---------------------------------------------------;
  674. ; Reset Vector Code - Entry point from reset ;
  675. ;---------------------------------------------------;
  676. ;RESET_VECT CODE H'000' ;
  677. ;---------------------------------------------------;
  678. ; Initialize the hardware and memory elements. ;
  679. ; This is a FAR CALL to a proc in the high ;
  680. ; page of Program Memory, so it needs the ;
  681. ; PAGESEL before and after the CALL to properly ;
  682. ; set the upper 2 bits in the program counter. ;
  683. ; I am slowly converting ALL CALLs (and some ;
  684. ; GOTOs) to having PAGESEL before and after, but;
  685. ; the added instruction cycles mess up the video;
  686. ; timings in some spots. To be done slowly and ;
  687. ; surely. ;
  688. ;-----------------------------------------------;
  689. ; PAGESEL _Initialize_System ;
  690. ; CALL _Initialize_System ;
  691. ; PAGESEL $ ;
  692. ;-----------------------------------------------;
  693. ; Fall through to _Next_Frame ;
  694. ;---------------------------------------------------;
  695. ;---------------------------------------------------;
  696.  
  697. ;---------------------------------------------------;
  698. ;---------------------------------------------------;
  699. ; Interrupt Vector Code ;
  700. ; Since we are not using or desire to use interrupts;
  701. ; this is not needed. ;
  702. ;---------------------------------------------------;
  703. ; INT_VECT CODE H'004' ;
  704. ;---------------------------------------------------;
  705. ;---------------------------------------------------;
  706.  
  707. ;---------------------------------------------------;
  708. ;---------------------------------------------------;
  709. ; User Code in the low page of Program Memory ;
  710. ; More user code (USER_CODE_2) can be found in the ;
  711. ; high page of Program Memory, starting at H'800' ;
  712. ;---------------------------------------------------;
  713. USER_CODE_1 CODE H'000' ;
  714. ;---------------------------------------------------;
  715. _Initialize_System: ;
  716. ;---;-----------------------------------------------;
  717. ; Initialize Hardware ;
  718. ;-----------------------------------------------;
  719. BANKSEL OSCCON ;
  720. MOVLW B'11110000' ; 32Mhz
  721. MOVWF OSCCON ;
  722. ;
  723. BANKSEL OSCSTAT ; Wait for
  724. IS1:MOVFW OSCSTAT ; high speed
  725. ANDLW H'79' ; oscillator
  726. XORLW H'59' ; to be
  727. BTFSS STATUS, Z ; stable and
  728. GOTO IS1 ; locked
  729. ;
  730. BANKSEL ANSELA ;
  731. CLRF ANSELA ; ALL I/O as digital
  732. #IF _USE_THUMBSTICKS_ ;
  733. BSF ANSELA, LJOY_BIT ;
  734. BSF ANSELA, RJOY_BIT ;
  735. #ENDIF ;_USE_THUMBSTICKS_ ;
  736. ;
  737. BANKSEL LATA ;
  738. CLRF LATA ;
  739. ;
  740. BANKSEL TRISA ;
  741. CLRF TRISA ;
  742. BCF TRISA, VIDEO_0_BIT ; Set as OUTPUT
  743. BCF TRISA, VIDEO_1_BIT ; Set As OUTPUT
  744. #IF _USE_THUMBSTICKS_ ;
  745. BSF TRISA, LJOY_BIT ; Set as INPUT
  746. BSF TRISA, LBUTT_BIT ; Set as INPUT
  747. BSF TRISA, RJOY_BIT ; Set as INPUT
  748. BCF TRISA, RBUTT_BIT ; Set as OUTPUT (PIEZO)
  749. #ELSE ;!_USE_THUMBSTICKS_ ;
  750. BSF TRISA, LBUTT_1_BIT ; Set as INPUT
  751. BSF TRISA, LBUTT_2_BIT ; Set as INPUT
  752. BSF TRISA, RBUTT_1_BIT ; Set as INPUT
  753. BSF TRISA, RBUTT_2_BIT ; Set as INPUT
  754. #ENDIF ;_USE_THUMBSTICKS_ ;
  755. ;
  756. BANKSEL PORTA ;
  757. CLRF PORTA ;
  758. BCF PORTA, VIDEO_0_BIT ; Set LOW
  759. BCF PORTA, VIDEO_1_BIT ; Set LOW
  760. #IF _USE_THUMBSTICKS_ ;
  761. BSF PORTA, LJOY_BIT ; Set HIGH
  762. BSF PORTA, LBUTT_BIT ; Set HIGH
  763. BSF PORTA, RJOY_BIT ; Set HIGH
  764. BSF PORTA, RBUTT_BIT ; Set HIGH
  765. #ELSE ;!_USE_THUMBSTICKS_ ;
  766. BSF PORTA, LBUTT_1_BIT ; Set HIGH
  767. BSF PORTA, LBUTT_2_BIT ; Set HIGH
  768. BSF PORTA, RBUTT_1_BIT ; Set HIGH
  769. BSF PORTA, RBUTT_2_BIT ; Set HIGH
  770. #ENDIF ;_USE_THUMBSTICKS_ ;
  771. ;
  772. BANKSEL INTCON ;
  773. CLRF INTCON ;
  774. ;
  775. BANKSEL OPTION_REG ;
  776. CLRF OPTION_REG ;
  777. ;
  778. ;-----------------------------------------------;
  779. ; Initialize Timer0 (for counting cycles) ;
  780. ;-----------------------------------------------;
  781. BANKSEL OPTION_REG ;
  782. BCF OPTION_REG, NOT_WPUEN ;
  783. BCF OPTION_REG, TMR0CS ;
  784. BCF OPTION_REG, PSA ; prescaler to timer0
  785. BCF OPTION_REG, PS2 ;
  786. BCF OPTION_REG, PS1 ; 000 - 250ns
  787. BCF OPTION_REG, PS0 ;
  788. BANKSEL TMR0 ;
  789. CLRF TMR0 ;
  790. ;
  791. ;-----------------------------------------------;
  792. ; Initialize Memory ;
  793. ;-----------------------------------------------;
  794. BANKSEL MEMORY ;
  795. CLRF System_Status ;
  796. BSF System_Status, P1_SERVICE_BIT ;
  797. BSF System_Status, P2_SERVICE_BIT ;
  798. MOVLW 0 ;
  799. MOVWF Buzz_Count ;
  800. MOVWF Buzz_Reload ;
  801. MOVLW H'FF' ;
  802. MOVWF Buzz_Dur_LO ;
  803. MOVLW H'FF' ;
  804. MOVWF Buzz_Dur_HI ;
  805. MOVLW MAX_BALL_WAIT ;
  806. MOVWF Ball_Wait ;
  807. MOVLW 0 ;
  808. MOVWF Score_1 ;
  809. MOVLW 0 ;
  810. MOVWF Score_2 ;
  811. MOVLW 20 ;
  812. MOVWF Paddle_1_Y ;
  813. MOVLW 20 ;
  814. MOVWF Paddle_2_Y ;
  815. MOVLW 15 ;
  816. MOVWF Ball_X ;
  817. MOVLW 27 ;
  818. MOVWF Ball_Y ;
  819. MOVLW 0 ;
  820. MOVWF Ball_Dir_X ;
  821. MOVLW 0 ;
  822. MOVWF Ball_Dir_Y ;
  823. ;
  824. ;-----------------------------------------------;
  825. ; Initialize Video Buffer ;
  826. ;-----------------------------------------------;
  827. PAGESEL _Clear_Screen ;
  828. CALL _Clear_Screen ;
  829. PAGESEL $ ;
  830. ;
  831. ;-----------------------------------------------;
  832. ; Initialize Other Subsystems ;
  833. ;-----------------------------------------------;
  834. ;
  835. ; RETURN ;
  836. ;---------------------------------------------------;
  837.  
  838. ;---------------------------------------------------;
  839. _Next_Frame: ;
  840. ;---------------------------------------------------;
  841. ; VERTICAL SYNC PULSE Time ;
  842. ; This consists of 5 blank half lines, ;
  843. ; 4 inverted half lines, and 5 more blank half ;
  844. ; lines. This totals 7 full lines of 64us each. ;
  845. ; --------------------------------------------- ;
  846. ; NOTE: Timing is CRITICAL for a nice, clean ;
  847. ; display. If you notice the top part of the ;
  848. ; display is skewed or "tearing", your timings ;
  849. ; are wrong and need to be adjusted. Make sure ;
  850. ; you haven't inadvertently dropped a half frame;
  851. ;-----------------------------------------------;
  852. ; First, a special blank 30us line. If _DEBUG_ ;
  853. ; is enabled, it will produce a pulse on the ;
  854. ; GPIO2 pin for debugging purposes (checking the;
  855. ; time elapsed for a single video frame). ;
  856. ;-----------------------------------------------;
  857. PAGESEL _Vertical_Sync ;
  858. CALL _Vertical_Sync ;
  859. PAGESEL $ ;
  860. ;-----------------------------------------------;
  861. ; Just a bunch of BLANK LINES, so that the video;
  862. ; data doesn't start in the non-display area. ;
  863. ; Add or remove lines to adjust the vertical ;
  864. ; position of your video. If you add or remove, ;
  865. ; make sure to adjust the number of BLANK LINES ;
  866. ; which follow the data lines, so that the video;
  867. ; stays at 60hz ;
  868. ;-----------------------------------------------;
  869. MOVLW 14 + ((MAX_LINES - NUM_LINES) * 2) ;
  870. MOVWF Line_Count ;
  871. _NF_Next_Blank_60us_Line1: ;
  872. PAGESEL _Blank_60us_Line ;
  873. CALL _Blank_60us_Line ;
  874. PAGESEL $ ;
  875. DECFSZ Line_Count, F ;
  876. GOTO _NF_Next_Blank_60us_Line1 ;
  877. ;-----------------------------------------------;
  878. ;
  879. ;-----------------------------------------------;
  880. ; 2 WHITE lines + 192 DATA lines (assuming ;
  881. ; NUM_LINES = 48) + 2 WHITE lines + 1 BLANK line;
  882. ;-----------------------------------------------;
  883. PAGESEL _Data_Lines ;
  884. CALL _Data_Lines ;
  885. PAGESEL $ ;
  886. ;-----------------------------------------------;
  887. ;
  888. ;-----------------------------------------------;
  889. ; Display copyright and software version number.;
  890. ; 8 60us lines ;
  891. ;-----------------------------------------------;
  892. PAGESEL _Copyright ;
  893. CALL _Copyright ;
  894. PAGESEL $ ;
  895. ;-----------------------------------------------;
  896. ;
  897. ;-----------------------------------------------;
  898. ; Timing Fudge ;
  899. ;-----------------------------------------------;
  900. NOP ;
  901. NOP ;
  902. ;-----------------------------------------------;
  903. ; One BLANK line and two WHITE lines: ;
  904. ;-----------------------------------------------;
  905. PAGESEL _Blank_60us_Line ;
  906. CALL _Blank_60us_Line ;
  907. PAGESEL $ ;
  908. ;-----------------------------------------------;
  909. ; Timing Fudge ;
  910. ;-----------------------------------------------;
  911. NOP ;
  912. NOP ;
  913. NOP ;
  914. ;-----------------------------------------------;
  915. PAGESEL _White_60us_Line ;
  916. CALL _White_60us_Line ;
  917. PAGESEL $ ;
  918. ;-----------------------------------------------;
  919. ; Timing Fudge ;
  920. ;-----------------------------------------------;
  921. NOP ;
  922. NOP ;
  923. ;-----------------------------------------------;
  924. PAGESEL _White_60us_Line ;
  925. CALL _White_60us_Line ;
  926. PAGESEL $ ;
  927. ;-----------------------------------------------;
  928. ;
  929. ;-----------------------------------------------;
  930. ; More Blank Lines: ;
  931. ;-----------------------------------------------;
  932. #IF ((MAX_LINES - NUM_LINES) * 2) > 7 ;
  933. MOVLW ((MAX_LINES - NUM_LINES) * 2) - 7 ;
  934. MOVWF Line_Count ;
  935. _NF_Next_Blank_60us_Line2: ;
  936. PAGESEL _Blank_60us_Line ;
  937. CALL _Blank_60us_Line ;
  938. PAGESEL $ ;
  939. DECFSZ Line_Count, F ;
  940. GOTO _NF_Next_Blank_60us_Line2 ;
  941. #ENDIF ;
  942. ;-----------------------------------------------;
  943.  
  944. ;-----------------------------------------------;
  945. ; Clear the scores, paddles and ball from the ;
  946. ; display - and draw the Title if necessary. ;
  947. ; 2 60us lines ;
  948. ;-----------------------------------------------;
  949. PAGESEL _Clear_Screen ;
  950. CALL _Clear_Screen ; 2 blank 60us lines
  951. PAGESEL $ ; Screen Clear / Title Draw
  952. ;-----------------------------------------------;
  953. ;
  954. ;-----------------------------------------------;
  955. ; All of the game processing is done here, the ;
  956. ; last 4 full 60us blank lines ;
  957. ;-----------------------------------------------;
  958. PAGESEL _Update_Paddles ;
  959. CALL _Update_Paddles ; 1 blank 60us line
  960. PAGESEL $ ; Paddles Computations
  961. PAGESEL _Update_Ball ;
  962. CALL _Update_Ball ; 1 blank 60us line
  963. PAGESEL $ ; Ball Computations
  964. PAGESEL _Draw_Items ;
  965. CALL _Draw_Items ; 2 blank 60us lines
  966. PAGESEL $ ; Scores/Paddles/Ball Display
  967. ;-----------------------------------------------;
  968. ;
  969. ;-----------------------------------------------;
  970. ; So, to summarize (with NUM_LINES = 48): ;
  971. ; - 7 VERTICAL SYNC lines (14 30us lines) ;
  972. ; - 30 BLANK LINES for screen centering ;
  973. ; - 2 WHITE lines for COURT SIDELINE ;
  974. ; - 192 DATA lines for GAME FIELD ;
  975. ; - 2 WHITE lines for COURT SIDELINE ;
  976. ; - 1 BLANK line between SIDELINE & COPYRIGHT ;
  977. ; - 8 DATA lines for COPYRIGHT ;
  978. ; - 12 BLANK lines for screen centering ;
  979. ; - 2 BLANK lines for screen clear / title ;
  980. ; - 4 BLANK lines for game processing ;
  981. ; ;
  982. ; For a total of 260 lines at 64us each, or ;
  983. ; 16.637ms, or approximately 60hz. 16.666ms ;
  984. ; would be _perfect_. ;
  985. ;-----------------------------------------------;
  986. ;
  987. GOTO _Next_Frame ;
  988. ;---------------------------------------------------;
  989.  
  990. ;---------------------------------------------------;
  991. _Vertical_Sync: ;
  992. ;---------------------------------------------------;
  993. ; The _Special_30us_Line will produce a pulse on;
  994. ; GPIO2 if the _DEBUG_ flag is set to TRUE. This;
  995. ; is for checking the timing of the entire video;
  996. ; frame (~60hz, ~16.66ms). ;
  997. ;-----------------------------------------------;
  998. PAGESEL _Special_30us_Line ;
  999. CALL _Special_30us_Line ;
  1000. PAGESEL $ ;
  1001. ;-----------------------------------------------;
  1002. ;
  1003. ;-----------------------------------------------;
  1004. ; 4 blank 30us lines ;
  1005. ;-----------------------------------------------;
  1006. PAGESEL _Blank_30us_Line ;
  1007. CALL _Blank_30us_Line ;
  1008. PAGESEL $ ;
  1009. ;-----------------------------------------------;
  1010. ; Timing Fudge ;
  1011. ;-----------------------------------------------;
  1012. NOP ;
  1013. NOP ;
  1014. NOP ;
  1015. NOP ;
  1016. NOP ;
  1017. ;-----------------------------------------------;
  1018. PAGESEL _Blank_30us_Line ;
  1019. CALL _Blank_30us_Line ;
  1020. PAGESEL $ ;
  1021. ;-----------------------------------------------;
  1022. ; Timing Fudge ;
  1023. ;-----------------------------------------------;
  1024. NOP ;
  1025. NOP ;
  1026. NOP ;
  1027. NOP ;
  1028. NOP ;
  1029. ;-----------------------------------------------;
  1030. PAGESEL _Blank_30us_Line ;
  1031. CALL _Blank_30us_Line ;
  1032. PAGESEL $ ;
  1033. ;-----------------------------------------------;
  1034. ; Timing Fudge ;
  1035. ;-----------------------------------------------;
  1036. NOP ;
  1037. NOP ;
  1038. NOP ;
  1039. NOP ;
  1040. NOP ;
  1041. ;-----------------------------------------------;
  1042. PAGESEL _Blank_30us_Line ;
  1043. CALL _Blank_30us_Line ;
  1044. PAGESEL $ ;
  1045. ;-----------------------------------------------;
  1046. ; Timing Fudge ;
  1047. ;-----------------------------------------------;
  1048. NOP ;
  1049. NOP ;
  1050. NOP ;
  1051. NOP ;
  1052. NOP ;
  1053. ;-----------------------------------------------;
  1054. ;
  1055. ;-----------------------------------------------;
  1056. ; 4 inverted 30us lines ;
  1057. ;-----------------------------------------------;
  1058. PAGESEL _Inverted_30us_Line ;
  1059. CALL _Inverted_30us_Line ;
  1060. PAGESEL $ ;
  1061. PAGESEL _Inverted_30us_Line ;
  1062. CALL _Inverted_30us_Line ;
  1063. PAGESEL $ ;
  1064. PAGESEL _Inverted_30us_Line ;
  1065. CALL _Inverted_30us_Line ;
  1066. PAGESEL $ ;
  1067. PAGESEL _Inverted_30us_Line ;
  1068. CALL _Inverted_30us_Line ;
  1069. PAGESEL $ ;
  1070. ;-----------------------------------------------;
  1071. ;
  1072. ;-----------------------------------------------;
  1073. ; 5 more blank 30us lines ;
  1074. ;-----------------------------------------------;
  1075. PAGESEL _Blank_30us_Line ;
  1076. CALL _Blank_30us_Line ;
  1077. PAGESEL $ ;
  1078. ;-----------------------------------------------;
  1079. ; Timing Fudge ;
  1080. ;-----------------------------------------------;
  1081. NOP ;
  1082. NOP ;
  1083. NOP ;
  1084. NOP ;
  1085. NOP ;
  1086. ;-----------------------------------------------;
  1087. PAGESEL _Blank_30us_Line ;
  1088. CALL _Blank_30us_Line ;
  1089. PAGESEL $ ;
  1090. ;-----------------------------------------------;
  1091. ; Timing Fudge ;
  1092. ;-----------------------------------------------;
  1093. NOP ;
  1094. NOP ;
  1095. NOP ;
  1096. NOP ;
  1097. NOP ;
  1098. ;-----------------------------------------------;
  1099. PAGESEL _Blank_30us_Line ;
  1100. CALL _Blank_30us_Line ;
  1101. PAGESEL $ ;
  1102. ;-----------------------------------------------;
  1103. ; Timing Fudge ;
  1104. ;-----------------------------------------------;
  1105. NOP ;
  1106. NOP ;
  1107. NOP ;
  1108. NOP ;
  1109. NOP ;
  1110. ;-----------------------------------------------;
  1111. PAGESEL _Blank_30us_Line ;
  1112. CALL _Blank_30us_Line ;
  1113. PAGESEL $ ;
  1114. ;-----------------------------------------------;
  1115. ; Timing Fudge ;
  1116. ;-----------------------------------------------;
  1117. NOP ;
  1118. NOP ;
  1119. NOP ;
  1120. NOP ;
  1121. NOP ;
  1122. ;-----------------------------------------------;
  1123. PAGESEL _Blank_30us_Line ;
  1124. CALL _Blank_30us_Line ;
  1125. PAGESEL $ ;
  1126. ;-----------------------------------------------;
  1127. ;
  1128. RETURN ;
  1129. ;---------------------------------------------------;
  1130.  
  1131. ;---------------------------------------------------;
  1132. _Blank_30us_Line: ;
  1133. ;---------------------------------------------------;
  1134. ; Used only during VERTICAL SYNC ;
  1135. ;---------------------------------------------------;
  1136. ;-----------------------------------------------;
  1137. ; 30us Blank Signal Generation ;
  1138. ;-----------------------------------------------;
  1139. NEG_SYNC_2US ;
  1140. START_LINE COLOR_BLACK, 30, 12 ;
  1141. WAIT_FOR_LINE_DONE 1 ;
  1142. ;-----------------------------------------------;
  1143. ;
  1144. RETURN ;
  1145. ;---------------------------------------------------;
  1146.  
  1147. ;---------------------------------------------------;
  1148. _Special_30us_Line: ;
  1149. ;---------------------------------------------------;
  1150. ; Used only during VERTICAL SYNC ;
  1151. ;---------------------------------------------------;
  1152. ;-----------------------------------------------;
  1153. ; 30us Blank Signal Generation (SPECIAL) ;
  1154. ;-----------------------------------------------;
  1155. ; If _DEBUG_ is TRUE, this will generate a ;
  1156. ; pulse on GPIO2 for debug purposes - used to ;
  1157. ; check the timing of a complete video frame. ;
  1158. ;-----------------------------------------------;
  1159. NEG_SYNC_2US ;
  1160. START_LINE COLOR_BLACK, 30, 10 ;
  1161. ;-----------------------------------------------;
  1162. ;
  1163. #IF _DEBUG_ ;
  1164. BANKSEL TRISA ;
  1165. BCF TRISA, 2 ;
  1166. BANKSEL PORTA ;
  1167. BCF PORTA, 2 ;
  1168. NOP ;
  1169. BSF PORTA, 2 ;
  1170. BANKSEL TRISA ;
  1171. BSF TRISA, 2 ;
  1172. BANKSEL MEMORY ;
  1173. #ENDIF ; _DEBUG_ ;
  1174. ;
  1175. ;-----------------------------------------------;
  1176. ; Wait for this line to complete ;
  1177. ;-----------------------------------------------;
  1178. WAIT_FOR_LINE_DONE 3 ;
  1179. ;-----------------------------------------------;
  1180. ;
  1181. RETURN ;
  1182. ;---------------------------------------------------;
  1183.  
  1184. ;---------------------------------------------------;
  1185. _Inverted_30us_Line: ;
  1186. ;---------------------------------------------------;
  1187. ; Used only during VERTICAL SYNC ;
  1188. ;---------------------------------------------------;
  1189. ;-----------------------------------------------;
  1190. ; 30us Inverted Signal Generation ;
  1191. ;-----------------------------------------------;
  1192. START_LINE COLOR_SYNC, 30, 6 ;
  1193. WAIT_FOR_LINE_DONE 0 ;
  1194. ;-----------------------------------------------;
  1195. ; 2s Positive Sync Generation ;
  1196. ;-----------------------------------------------;
  1197. POS_SYNC_2US ;
  1198. ;-----------------------------------------------;
  1199. ;
  1200. RETURN ;
  1201. ;---------------------------------------------------;
  1202.  
  1203. ;---------------------------------------------------;
  1204. _Update_Paddles: ;
  1205. ;---------------------------------------------------;
  1206. ;-----------------------------------------------;
  1207. ; 60us Blank Signal Generation ;
  1208. ;-----------------------------------------------;
  1209. NEG_SYNC_4US ;
  1210. START_LINE COLOR_BLACK, 60, 9 ;
  1211. ;-----------------------------------------------;
  1212. ;
  1213. #IF _USE_THUMBSTICKS_ ;
  1214. _UP1_Update: ;
  1215. ;-----------------------------------------------;
  1216. ; ADC Magic (Channel 0) ;
  1217. ;-----------------------------------------------;
  1218. BANKSEL ADCON1 ;
  1219. MOVLW H'60' ; Left Justified
  1220. MOVWF ADCON1 ; FOSC/64, VREF
  1221. MOVLW B'00001011' ; AN2, ADC GO, ADC On
  1222. MOVWF ADCON0 ;
  1223. BTFSC ADCON0, GO ; Wait for conversion
  1224. GOTO $-1 ;
  1225. MOVFW ADRESH ; Get result
  1226. BANKSEL MEMORY ;
  1227. ;-----------------------------------------------;
  1228. ;
  1229. MOVWF Temp1 ;
  1230. MOVLW H'60' ;
  1231. SUBWF Temp1, W ;
  1232. BTFSS STATUS, C ;
  1233. DECF Paddle_1_Y, F ;
  1234. MOVLW H'9F' ;
  1235. SUBWF Temp1, W ;
  1236. BTFSC STATUS, C ;
  1237. INCF Paddle_1_Y, F ;
  1238. BTFSC Paddle_1_Y, MSB ;
  1239. CLRF Paddle_1_Y ;
  1240. MOVLW NUM_LINES - PADDLE_HEIGHT ;
  1241. SUBWF Paddle_1_Y, W ;
  1242. BTFSS STATUS, C ;
  1243. GOTO _UP1_Update_Done ;
  1244. MOVLW NUM_LINES - PADDLE_HEIGHT ;
  1245. MOVWF Paddle_1_Y ;
  1246. _UP1_Update_Done: ;
  1247. #ELSE ;!_USE_THUMBSTICKS_ ;
  1248. _UP1_Check_Up: ;
  1249. CLRW ;
  1250. XORWF Paddle_1_Y, W ;
  1251. BTFSC STATUS, Z ;
  1252. GOTO _UP1_Check_Down ;
  1253. BTFSS PORTA, LBUTT_1_BIT ;
  1254. DECF Paddle_1_Y, F ;
  1255. _UP1_Check_Down: ;
  1256. MOVLW NUM_LINES - PADDLE_HEIGHT ;
  1257. XORWF Paddle_1_Y, W ;
  1258. BTFSC STATUS, Z ;
  1259. GOTO _UP1_Draw_Paddle ;
  1260. BTFSS PORTA, LBUTT_2_BIT ;
  1261. INCF Paddle_1_Y, F ;
  1262. #ENDIF ;_USE_THUMBSTICKS_ ;
  1263. ;
  1264. #IF _USE_THUMBSTICKS_ ;
  1265. _UP2_Update: ;
  1266. ;-----------------------------------------------;
  1267. ; ADC Magic (Channel 0) ;
  1268. ;-----------------------------------------------;
  1269. BANKSEL ADCON1 ;
  1270. MOVLW H'60' ; Left Justified
  1271. MOVWF ADCON1 ; FOSC/64, VREF
  1272. MOVLW B'00000011' ; AN0, ADC GO, ADC On
  1273. MOVWF ADCON0 ;
  1274. BTFSC ADCON0, GO ; Wait for conversion
  1275. GOTO $-1 ;
  1276. MOVFW ADRESH ; Get result
  1277. BANKSEL MEMORY ;
  1278. ;-----------------------------------------------;
  1279. ;
  1280. MOVWF Temp1 ;
  1281. MOVLW H'60' ;
  1282. SUBWF Temp1, W ;
  1283. BTFSS STATUS, C ;
  1284. DECF Paddle_2_Y, F ;
  1285. MOVLW H'9F' ;
  1286. SUBWF Temp1, W ;
  1287. BTFSC STATUS, C ;
  1288. INCF Paddle_2_Y, F ;
  1289. BTFSC Paddle_2_Y, MSB ;
  1290. CLRF Paddle_2_Y ;
  1291. MOVLW NUM_LINES - PADDLE_HEIGHT ;
  1292. SUBWF Paddle_2_Y, W ;
  1293. BTFSS STATUS, C ;
  1294. GOTO _UP2_Update_Done ;
  1295. MOVLW NUM_LINES - PADDLE_HEIGHT ;
  1296. MOVWF Paddle_2_Y ;
  1297. _UP2_Update_Done: ;
  1298. #ELSE ;!_USE_THUMBSTICKS_ ;
  1299. _UP2_Check_Up: ;
  1300. CLRW ;
  1301. XORWF Paddle_2_Y, W ;
  1302. BTFSC STATUS, Z ;
  1303. GOTO _UP2_Check_Down ;
  1304. BTFSS PORTA, RBUTT_1_BIT ;
  1305. DECF Paddle_2_Y, F ;
  1306. _UP2_Check_Down: ;
  1307. MOVLW NUM_LINES - PADDLE_HEIGHT ;
  1308. XORWF Paddle_2_Y, W ;
  1309. BTFSC STATUS, Z ;
  1310. GOTO _UP2_Draw_Paddle ;
  1311. BTFSS PORTA, RBUTT_2_BIT ;
  1312. INCF Paddle_2_Y, F ;
  1313. #ENDIF ;_USE_THUMBSTICKS_ ;
  1314. ;
  1315. ;-----------------------------------------------;
  1316. ; Wait for this line to complete ;
  1317. ;-----------------------------------------------;
  1318. WAIT_FOR_LINE_DONE 0 ;
  1319. ;-----------------------------------------------;
  1320. ;
  1321. RETURN ;
  1322. ;---------------------------------------------------;
  1323.  
  1324. ;---------------------------------------------------;
  1325. _Update_Ball: ;
  1326. ;---------------------------------------------------;
  1327. ;-----------------------------------------------;
  1328. ; 60us Blank Signal Generation ;
  1329. ;-----------------------------------------------;
  1330. NEG_SYNC_4US ;
  1331. START_LINE COLOR_BLACK, 60, 10 ;
  1332. ;-----------------------------------------------;
  1333. ;
  1334. _UB_Check_Wait: ;
  1335. ;-----------------------------------------------;
  1336. ; This is the delay so the ball isn't so fast ;
  1337. ;-----------------------------------------------;
  1338. DECFSZ Ball_Wait, F ;
  1339. GOTO _UB_Exit ;
  1340. ;
  1341. MOVLW MAX_BALL_WAIT ;
  1342. MOVWF Ball_Wait ;
  1343. ;-----------------------------------------------;
  1344. ;
  1345. ;-----------------------------------------------;
  1346. ; Is the ball moving? (Ball_Dir_X or Ball_Dir_Y ;
  1347. ; not equal to zero?) If so, update the ball ;
  1348. ; position. Otherwise, check for serve. ;
  1349. ;-----------------------------------------------;
  1350. CLRW ;
  1351. XORWF Ball_Dir_X, W ;
  1352. BTFSS STATUS, Z ;
  1353. GOTO _UB_Update_Ball_X ;
  1354. CLRW ;
  1355. XORWF Ball_Dir_Y, W ;
  1356. BTFSS STATUS, Z ;
  1357. GOTO _UB_Update_Ball_X ;
  1358. ;-----------------------------------------------;
  1359. ;
  1360. ;-----------------------------------------------;
  1361. ; Check if left player pushed button to serve ;
  1362. ;-----------------------------------------------;
  1363. _UB_Check_L_Serve: ;
  1364. BTFSS System_Status, P1_SERVICE_BIT ;
  1365. GOTO _UB_Check_R_Serve ;
  1366. BTFSC PORTA, LBUTT_BIT ;
  1367. GOTO _UB_Check_L_Unpressed ;
  1368. BTFSC System_Status, P1_PRESSED_BIT ;
  1369. GOTO _UB_Check_R_Serve ;
  1370. BSF System_Status, P1_PRESSED_BIT ;
  1371. BCF System_Status, P1_SERVICE_BIT ;
  1372. BCF System_Status, P2_SERVICE_BIT ;
  1373. MOVLW 1 ;
  1374. MOVWF Ball_Dir_X ;
  1375. MOVFW Paddle_1_Y ;
  1376. ADDLW PADDLE_HEIGHT / 2 ;
  1377. SUBLW NUM_LINES / 2 ;
  1378. MOVLW -2 ;
  1379. BTFSC STATUS, C ;
  1380. MOVLW 1 ;
  1381. MOVWF Ball_Dir_Y ;
  1382. MOVLW 2 ;
  1383. MOVWF Ball_X ;
  1384. MOVFW Paddle_1_Y ;
  1385. ADDLW PADDLE_HEIGHT / 2 ;
  1386. MOVWF Ball_Y ;
  1387. GOTO _UB_Service ;
  1388. _UB_Check_L_Unpressed: ;
  1389. BCF System_Status, P1_PRESSED_BIT ;
  1390. ;-----------------------------------------------;
  1391. ;
  1392. ;-----------------------------------------------;
  1393. ; Check if right player pushed button to serve ;
  1394. ;-----------------------------------------------;
  1395. _UB_Check_R_Serve: ;
  1396. BTFSS System_Status, P2_SERVICE_BIT ;
  1397. GOTO _UB_Exit ;
  1398. BTFSC System_Status, BUZZ_BIT ;
  1399. GOTO _UB_Exit ;
  1400. BANKSEL TRISA ;
  1401. BSF TRISA, RBUTT_BIT ;
  1402. BANKSEL PORTA ;
  1403. BTFSC PORTA, RBUTT_BIT ;
  1404. GOTO _UB_Check_R_Unpressed ;
  1405. BTFSC System_Status, P2_PRESSED_BIT ;
  1406. GOTO _UB_Exit ;
  1407. BANKSEL TRISA ;
  1408. BCF TRISA, RBUTT_BIT ;
  1409. BANKSEL PORTA ;
  1410. BSF System_Status, P2_PRESSED_BIT ;
  1411. BCF System_Status, P1_SERVICE_BIT ;
  1412. BCF System_Status, P2_SERVICE_BIT ;
  1413. MOVLW -1 ;
  1414. MOVWF Ball_Dir_X ;
  1415. MOVFW Paddle_2_Y ;
  1416. ADDLW PADDLE_HEIGHT / 2 ;
  1417. SUBLW NUM_LINES / 2 ;
  1418. MOVLW -1 ;
  1419. BTFSC STATUS, C ;
  1420. MOVLW 2 ;
  1421. MOVWF Ball_Dir_Y ;
  1422. MOVLW 29 ;
  1423. MOVWF Ball_X ;
  1424. MOVFW Paddle_2_Y ;
  1425. ADDLW PADDLE_HEIGHT / 2 ;
  1426. MOVWF Ball_Y ;
  1427. GOTO _UB_Service ;
  1428. _UB_Check_R_Unpressed: ;
  1429. BCF System_Status, P2_PRESSED_BIT ;
  1430. GOTO _UB_Exit ;
  1431. ;-----------------------------------------------;
  1432. ;
  1433. ;-----------------------------------------------;
  1434. ;-----------------------------------------------;
  1435. _UB_Service: ;
  1436. MOVLW H'11' ;
  1437. XORWF Score_1, W ;
  1438. BTFSC STATUS, Z ;
  1439. GOTO $+5 ;
  1440. MOVLW H'11' ;
  1441. XORWF Score_2, W ;
  1442. BTFSS STATUS, Z ;
  1443. GOTO _UB_Exit ;
  1444. CLRF Score_1 ;
  1445. CLRF Score_2 ;
  1446. GOTO _UB_Exit ;
  1447. ;-----------------------------------------------;
  1448. ;
  1449. ;-----------------------------------------------;
  1450. ;-----------------------------------------------;
  1451. _UB_Update_Ball_X: ;
  1452. MOVFW Ball_Dir_X ; Update Ball X Position
  1453. ADDWF Ball_X, F ;
  1454. ;
  1455. _UB_Update_Ball_X_Min: ;
  1456. MOVLW 0 ;
  1457. XORWF Ball_X, W ;
  1458. BTFSS STATUS, Z ;
  1459. GOTO _UB_Update_Ball_X_Max ;
  1460. MOVLW 1 ;
  1461. MOVWF Ball_Dir_X ;
  1462. ;
  1463. INCF Score_2, F ;
  1464. PLAY_SOUND 20, H'017F' ; Frequency, Duration
  1465. BCF System_Status, P1_SERVICE_BIT ;
  1466. BSF System_Status, P2_SERVICE_BIT ;
  1467. MOVLW 0 ;
  1468. MOVWF Ball_Dir_X ;
  1469. MOVWF Ball_Dir_Y ;
  1470. MOVLW 15 ;
  1471. MOVWF Ball_X ;
  1472. MOVLW 27 ;
  1473. MOVWF Ball_Y ;
  1474. MOVFW Score_2 ;
  1475. ANDLW H'0F' ;
  1476. XORLW H'0A' ;
  1477. BTFSS STATUS, Z ;
  1478. GOTO _UB_BXMin_Exit ;
  1479. MOVFW Score_2 ;
  1480. ANDLW H'F0' ;
  1481. ADDLW H'10' ;
  1482. MOVWF Score_2 ;
  1483. MOVLW H'A0' ;
  1484. XORWF Score_2, W ;
  1485. BTFSC STATUS, Z ;
  1486. CLRF Score_2 ;
  1487. _UB_BXMin_Exit: ;
  1488. MOVLW H'11' ;
  1489. XORWF Score_2, W ;
  1490. BTFSS STATUS, Z ;
  1491. GOTO _UB_Exit ;
  1492. BSF System_Status, P1_SERVICE_BIT ;
  1493. BSF System_Status, P2_SERVICE_BIT ;
  1494. GOTO _UB_Exit ;
  1495. ;
  1496. _UB_Update_Ball_X_Max: ;
  1497. MOVLW 31 ;
  1498. XORWF Ball_X, W ;
  1499. BTFSS STATUS, Z ;
  1500. GOTO _UB_Update_Ball_Y ;
  1501. MOVLW -1 ;
  1502. MOVWF Ball_Dir_X ;
  1503. ;
  1504. INCF Score_1, F ;
  1505. PLAY_SOUND 20, H'017F' ; Frequency, Duration
  1506. BSF System_Status, P1_SERVICE_BIT ;
  1507. BCF System_Status, P2_SERVICE_BIT ;
  1508. MOVLW 0 ;
  1509. MOVWF Ball_Dir_X ;
  1510. MOVWF Ball_Dir_Y ;
  1511. MOVLW 15 ;
  1512. MOVWF Ball_X ;
  1513. MOVLW 27 ;
  1514. MOVWF Ball_Y ;
  1515. MOVFW Score_1 ;
  1516. ANDLW H'0F' ;
  1517. XORLW H'0A' ;
  1518. BTFSS STATUS, Z ;
  1519. GOTO _UB_BXMax_Exit ;
  1520. MOVFW Score_1 ;
  1521. ANDLW H'F0' ;
  1522. ADDLW H'10' ;
  1523. MOVWF Score_1 ;
  1524. MOVLW H'A0' ;
  1525. XORWF Score_1, W ;
  1526. BTFSC STATUS, Z ;
  1527. CLRF Score_1 ;
  1528. _UB_BXMax_Exit: ;
  1529. MOVLW H'11' ;
  1530. XORWF Score_1, W ;
  1531. BTFSS STATUS, Z ;
  1532. GOTO _UB_Exit ;
  1533. BSF System_Status, P1_SERVICE_BIT ;
  1534. BSF System_Status, P2_SERVICE_BIT ;
  1535. GOTO _UB_Exit ;
  1536. ;-----------------------------------------------;
  1537. ;
  1538. ;-----------------------------------------------;
  1539. ; Update Ball_Y position ;
  1540. ;-----------------------------------------------;
  1541. _UB_Update_Ball_Y: ;
  1542. MOVFW Ball_Dir_Y ;
  1543. ADDWF Ball_Y, F ;
  1544. ;-----------------------------------------------;
  1545. ;
  1546. ;-----------------------------------------------;
  1547. ; Check for collision with upper sideline ;
  1548. ;-----------------------------------------------;
  1549. _UB_Update_Ball_Y_Min: ;
  1550. BTFSS Ball_Y, MSB ;
  1551. GOTO _UB_Update_Ball_Y_Max ;
  1552. COMF Ball_Y, F ;
  1553. COMF Ball_Dir_Y, F ;
  1554. INCF Ball_Dir_Y, F ;
  1555. ;-----------------------------------------------;
  1556. ; Play the 'Ball Hit Sideline' sound ;
  1557. ;-----------------------------------------------;
  1558. PLAY_SOUND 13, H'013F' ; Frequency, Duration
  1559. GOTO _UB_Paddle_Detect_Left ;
  1560. ;-----------------------------------------------;
  1561. ;
  1562. ;-----------------------------------------------;
  1563. ; Check for collision with lower sideline ;
  1564. ;-----------------------------------------------;
  1565. _UB_Update_Ball_Y_Max: ;
  1566. MOVLW NUM_LINES - 2 ;
  1567. SUBWF Ball_Y, W ;
  1568. BTFSS STATUS, C ;
  1569. GOTO _UB_Paddle_Detect_Left ;
  1570. MOVLW NUM_LINES - 2 ;
  1571. MOVWF Ball_Y ;
  1572. COMF Ball_Dir_Y, F ;
  1573. INCF Ball_Dir_Y, F ;
  1574. ;-----------------------------------------------;
  1575. ; Play the 'Ball Hit Wall' sound ;
  1576. ;-----------------------------------------------;
  1577. PLAY_SOUND 13, H'013F' ; Frequency, Duration
  1578. ;-----------------------------------------------;
  1579. ;
  1580. ;-----------------------------------------------;
  1581. ; Check for collision with left paddle ;
  1582. ;-----------------------------------------------;
  1583. _UB_Paddle_Detect_Left: ;
  1584. ;-----------------------------------------------;
  1585. ; On the same vertical line as the left paddle? ;
  1586. ;-----------------------------------------------;
  1587. MOVLW 1 ;
  1588. XORWF Ball_X, W ;
  1589. BTFSS STATUS, Z ;
  1590. GOTO _UB_Paddle_Detect_Right ;
  1591. ;
  1592. MOVFW Paddle_1_Y ;
  1593. MOVWF Temp1 ;
  1594. GOTO _UB_PD_Check_Hit ;
  1595. ;
  1596. ;-----------------------------------------------;
  1597. ; Check for collision with right paddle ;
  1598. ;-----------------------------------------------;
  1599. _UB_Paddle_Detect_Right: ;
  1600. ;-----------------------------------------------;
  1601. ; On the same vertical line as the right paddle?;
  1602. ;-----------------------------------------------;
  1603. MOVLW 30 ;
  1604. XORWF Ball_X, W ;
  1605. BTFSS STATUS, Z ;
  1606. GOTO _UB_Exit ;
  1607. MOVFW Paddle_2_Y ;
  1608. MOVWF Temp1 ;
  1609. ;-----------------------------------------------;
  1610. ;
  1611. _UB_PD_Check_Hit: ;
  1612. ;-----------------------------------------------;
  1613. ; Are we on the save horizontal plane as the ;
  1614. ; paddle? ;
  1615. ;-----------------------------------------------;
  1616. MOVFW Ball_Y ;
  1617. ADDLW BALL_HEIGHT ;
  1618. SUBWF Temp1, W ;
  1619. BTFSC STATUS, C ;
  1620. GOTO _UB_Exit ;
  1621. ;
  1622. MOVFW Temp1 ;
  1623. ADDLW PADDLE_HEIGHT - 1 ;
  1624. MOVWF Temp2 ;
  1625. MOVFW Ball_Y ;
  1626. SUBWF Temp2, W ;
  1627. BTFSS STATUS, C ;
  1628. GOTO _UB_Exit ;
  1629. ;
  1630. _UB_PD_Its_A_Hit: ;
  1631. ;-----------------------------------------------;
  1632. ; Reverse the ball 'X' direction ;
  1633. ;-----------------------------------------------;
  1634. COMF Ball_Dir_X, F ;
  1635. INCF Ball_Dir_X, F ;
  1636. ;-----------------------------------------------;
  1637. ; Adjust the ball 'X' position ;
  1638. ;-----------------------------------------------;
  1639. MOVFW Ball_Dir_X ;
  1640. ADDWF Ball_X, F ;
  1641. ;-----------------------------------------------;
  1642. ; Play the 'Ball Hit Paddle' sound ;
  1643. ;-----------------------------------------------;
  1644. PLAY_SOUND 15, H'013F' ; Frequency, Duration
  1645. ;-----------------------------------------------;
  1646. ;
  1647. ;-----------------------------------------------;
  1648. ; Ball update done. Restore RBUTT as an output ;
  1649. ; for sound and wait for 60us to pass. ;
  1650. ;-----------------------------------------------;
  1651. _UB_Exit: ;
  1652. BANKSEL TRISA ;
  1653. BSF TRISA, RBUTT_BIT ;
  1654. BANKSEL PORTA ;
  1655. ;
  1656. ;-----------------------------------------------;
  1657. ; Wait for this line to complete ;
  1658. ;-----------------------------------------------;
  1659. WAIT_FOR_LINE_DONE 2 ;
  1660. ;-----------------------------------------------;
  1661. ;
  1662. RETURN ;
  1663. ;---------------------------------------------------;
  1664.  
  1665. ;---------------------------------------------------;
  1666. _Blank_60us_Line: ;
  1667. ;---------------------------------------------------;
  1668. ;-----------------------------------------------;
  1669. ; 60us Black Signal Generation ;
  1670. ;-----------------------------------------------;
  1671. NEG_SYNC_4US ;
  1672. START_LINE COLOR_BLACK, 60, 10 ;
  1673. WAIT_FOR_LINE_DONE 0 ;
  1674. ;-----------------------------------------------;
  1675. ;
  1676. RETURN ;
  1677. ;---------------------------------------------------;
  1678.  
  1679. ;---------------------------------------------------;
  1680. _Data_Lines: ;
  1681. ;---------------------------------------------------;
  1682. ; Note: This will generate 1 60us blank line, then ;
  1683. ; 224 60us data lines, and finally a 60us blank line;
  1684. ;---------------------------------------------------;
  1685. ; Timing Fudge ;
  1686. ;-----------------------------------------------;
  1687. NOP ;
  1688. ;-----------------------------------------------;
  1689. ;
  1690. ;-----------------------------------------------;
  1691. ; 60us WHITE Signal Generation ;
  1692. ;-----------------------------------------------;
  1693. NEG_SYNC_4US ;
  1694. START_LINE COLOR_WHITE, 60, 6 ;
  1695. WAIT_FOR_LINE_DONE 1 ;
  1696. ;-----------------------------------------------;
  1697. ;
  1698. ;-----------------------------------------------;
  1699. ; 60us WHITE Signal Generation ;
  1700. ;-----------------------------------------------;
  1701. NEG_SYNC_4US ;
  1702. START_LINE COLOR_WHITE, 60, 7 ;
  1703. ;-----------------------------------------------;
  1704. ;
  1705. ;-----------------------------------------------;
  1706. ; Set up of video buffer pointer and line count ;
  1707. ;-----------------------------------------------;
  1708. MOVLW LOW VIDEO_BUFFER_START ;
  1709. MOVWF FSR1L ;
  1710. MOVLW HIGH VIDEO_BUFFER_START ;
  1711. MOVWF FSR1H ;
  1712. ;
  1713. MOVLW NUM_LINES ;
  1714. MOVWF DL_Count ;
  1715. ;-----------------------------------------------;
  1716. ;
  1717. ;-----------------------------------------------;
  1718. ; Wait for this line to complete ;
  1719. ;-----------------------------------------------;
  1720. WAIT_FOR_LINE_DONE 1 ;
  1721. ;-----------------------------------------------;
  1722. ;
  1723. ;-----------------------------------------------;
  1724. ; We repeat each line 4 times, since we don't ;
  1725. ; have a big enough video buffer for 192 lines ;
  1726. ;-----------------------------------------------;
  1727. _DL_Next_Line: ;
  1728. MOVLW 4 ;
  1729. MOVWF Repeat_Count ;
  1730. _DL_Repeat_Line: ;
  1731. ;-----------------------------------------------;
  1732. ; 60us Line Generation ;
  1733. ;-----------------------------------------------;
  1734. NEG_SYNC_4US ;
  1735. START_LINE COLOR_BLACK, 60, 12 ;
  1736. ;-----------------------------------------------;
  1737. ;
  1738. ;-----------------------------------------------;
  1739. ; Front porch - shifts the data to the right ;
  1740. ; and hopefully centers it on the screen ;
  1741. ; --------------------------------------------- ;
  1742. DELAY 14 ;
  1743. ;-----------------------------------------------;
  1744. ;
  1745. MOVLW H'FC' ;
  1746. ANDWF FSR1L, F ;
  1747. MOVLW 4 ;
  1748. MOVWF Byte_Count ;
  1749. _DL_Next_Byte: ;
  1750. ;-----------------------------------------------;
  1751. ; This is where the 32 bits of data are actually;
  1752. ; send out over the video signal ;
  1753. ;-----------------------------------------------;
  1754. DO_BIT 7, 8 ;
  1755. DO_BIT 6, 8 ;
  1756. DO_BIT 5, 8 ;
  1757. DO_BIT 4, 8 ;
  1758. DO_BIT 3, 8 ;
  1759. DO_BIT 2, 8 ;
  1760. DO_BIT 1, 8 ;
  1761. DO_BIT 0, 1 ;
  1762. ;
  1763. ADDFSR FSR1, 1 ;
  1764. ;
  1765. _DL_Center_Line: ;
  1766. MOVLW 3 ;
  1767. XORWF Byte_Count, W ;
  1768. BTFSS STATUS, Z ;
  1769. GOTO _DL_Center_Line_Done ;
  1770. NOP ;
  1771. NOP ;
  1772. NOP ;
  1773. BCF PORTA, VIDEO_0_BIT ;
  1774. NOP ;
  1775. NOP ;
  1776. NOP ;
  1777. NOP ;
  1778. BSF PORTA, VIDEO_0_BIT ;
  1779. NOP ;
  1780. BCF PORTA, VIDEO_0_BIT ;
  1781. _DL_Center_Line_Done: ;
  1782. ;
  1783. DECFSZ Byte_Count, F ;
  1784. GOTO _DL_Next_Byte ;
  1785. DECF FSR1L, F ;
  1786. ;-----------------------------------------------;
  1787. ;
  1788. ;-----------------------------------------------;
  1789. ; Back porch - between this and the front porch,;
  1790. ; this 'frames' the video on your TV (hopefully);
  1791. ; --------------------------------------------- ;
  1792. ; NOTE: this DELAY and NOPs fleshes out the data;
  1793. ; line to 60us ;
  1794. ;-----------------------------------------------;
  1795. SET_DAC2BIT COLOR_BLACK ;
  1796. WAIT_FOR_LINE_DONE 1 ;
  1797. ;-----------------------------------------------;
  1798. ;
  1799. DECFSZ Repeat_Count, F ;
  1800. GOTO $+2 ;
  1801. GOTO _DL_Next_Data ;
  1802. DELAY 1 ;
  1803. NOP ;
  1804. NOP ;
  1805. GOTO _DL_Repeat_Line ;
  1806. ;
  1807. ;-----------------------------------------------;
  1808. ; 224 lines of information to transmit ;
  1809. ; so the screen size is 32x224. But we transmit ;
  1810. ; each line 4 times, so it's actually 32x56 ;
  1811. ;-----------------------------------------------;
  1812. _DL_Next_Data: ;
  1813. ;-----------------------------------------------;
  1814. ; Timing Fudge ;
  1815. ;-----------------------------------------------;
  1816. NOP ;
  1817. ;-----------------------------------------------;
  1818. ADDFSR FSR1, 1 ;
  1819. DECFSZ DL_Count, F ;
  1820. GOTO _DL_Next_Line ;
  1821. ;
  1822. ;-----------------------------------------------;
  1823. ; Timing Fudge ;
  1824. ;-----------------------------------------------;
  1825. NOP ;
  1826. NOP ;
  1827. NOP ;
  1828. ;-----------------------------------------------;
  1829. ;
  1830. ;-----------------------------------------------;
  1831. ; 60us WHITE Signal Generation ;
  1832. ;-----------------------------------------------;
  1833. NEG_SYNC_4US ;
  1834. START_LINE COLOR_WHITE, 60, 6 ;
  1835. WAIT_FOR_LINE_DONE 0 ;
  1836. ;-----------------------------------------------;
  1837. ;
  1838. ;-----------------------------------------------;
  1839. ; 60us WHITE Signal Generation ;
  1840. ;-----------------------------------------------;
  1841. NEG_SYNC_4US ;
  1842. START_LINE COLOR_WHITE, 60, 6 ;
  1843. WAIT_FOR_LINE_DONE 0 ;
  1844. ;-----------------------------------------------;
  1845. ;
  1846. ;-----------------------------------------------;
  1847. ; 60us BLACK Signal Generation ;
  1848. ;-----------------------------------------------;
  1849. NEG_SYNC_4US ;
  1850. START_LINE COLOR_BLACK, 60, 13 ;
  1851. WAIT_FOR_LINE_DONE 1 ;
  1852. ;-----------------------------------------------;
  1853. ;
  1854. RETURN ;
  1855. ;---------------------------------------------------;
  1856.  
  1857. ;---------------------------------------------------;
  1858. USER_CODE_2 CODE H'800' ;
  1859. ;---------------------------------------------------;
  1860. _Copyright: ;
  1861. ;---------------------------------------------------;
  1862. ; Note: This is a 60us line routine. It will ;
  1863. ; generate 8 60us data lines. ;
  1864. ;---------------------------------------------------;
  1865. ;-----------------------------------------------;
  1866. ; Setup ;
  1867. ;-----------------------------------------------;
  1868. MOVLW LOW COPYRIGHT_TABLE ;
  1869. MOVWF FSR1L ;
  1870. MOVLW HIGH COPYRIGHT_TABLE ;
  1871. MOVWF FSR1H ;
  1872. MOVLW 8 ;
  1873. MOVWF Temp1 ;
  1874. ;-----------------------------------------------;
  1875. ;
  1876. ;-----------------------------------------------;
  1877. ; Timing Fudge ;
  1878. ;-----------------------------------------------;
  1879. NOP ;
  1880. NOP ;
  1881. ;-----------------------------------------------;
  1882. ;
  1883. ;-----------------------------------------------;
  1884. ; 8 60us Data Lines Generation ;
  1885. ;-----------------------------------------------;
  1886. _CR_Next_Line: ;
  1887. ;-----------------------------------------------;
  1888. ; 60us Line Generation ;
  1889. ;-----------------------------------------------;
  1890. NEG_SYNC_4US ;
  1891. START_LINE COLOR_BLACK, 60, 12 ;
  1892. ;-----------------------------------------------;
  1893. ;
  1894. ;-----------------------------------------------;
  1895. ; Xus Back Porch (Black Signal) Generation ;
  1896. ;-----------------------------------------------;
  1897. DELAY 16 ;
  1898. NOP ;
  1899. ;-----------------------------------------------;
  1900. ;
  1901. ;-----------------------------------------------;
  1902. ; Data Generation ;
  1903. ;-----------------------------------------------;
  1904. DO_BIT 7, 0 ;
  1905. DO_BIT 6, 0 ;
  1906. DO_BIT 5, 0 ;
  1907. DO_BIT 4, 0 ;
  1908. DO_BIT 3, 0 ;
  1909. DO_BIT 2, 0 ;
  1910. DO_BIT 1, 0 ;
  1911. DO_BIT 0, 0 ;
  1912. ADDFSR FSR1, 1 ;
  1913. DO_BIT 7, 0 ;
  1914. DO_BIT 6, 0 ;
  1915. DO_BIT 5, 0 ;
  1916. DO_BIT 4, 0 ;
  1917. DO_BIT 3, 0 ;
  1918. DO_BIT 2, 0 ;
  1919. DO_BIT 1, 0 ;
  1920. DO_BIT 0, 0 ;
  1921. ADDFSR FSR1, 1 ;
  1922. DO_BIT 7, 0 ;
  1923. DO_BIT 6, 0 ;
  1924. DO_BIT 5, 0 ;
  1925. DO_BIT 4, 0 ;
  1926. DO_BIT 3, 0 ;
  1927. DO_BIT 2, 0 ;
  1928. DO_BIT 1, 0 ;
  1929. DO_BIT 0, 0 ;
  1930. ADDFSR FSR1, 1 ;
  1931. DO_BIT 7, 0 ;
  1932. DO_BIT 6, 0 ;
  1933. DO_BIT 5, 0 ;
  1934. DO_BIT 4, 0 ;
  1935. DO_BIT 3, 0 ;
  1936. DO_BIT 2, 0 ;
  1937. DO_BIT 1, 0 ;
  1938. DO_BIT 0, 0 ;
  1939. ADDFSR FSR1, 1 ;
  1940. DO_BIT 7, 0 ;
  1941. DO_BIT 6, 0 ;
  1942. DO_BIT 5, 0 ;
  1943. DO_BIT 4, 0 ;
  1944. DO_BIT 3, 0 ;
  1945. DO_BIT 2, 0 ;
  1946. DO_BIT 1, 0 ;
  1947. DO_BIT 0, 0 ;
  1948. ADDFSR FSR1, 1 ;
  1949. DO_BIT 7, 0 ;
  1950. DO_BIT 6, 0 ;
  1951. DO_BIT 5, 0 ;
  1952. DO_BIT 4, 0 ;
  1953. DO_BIT 3, 0 ;
  1954. DO_BIT 2, 0 ;
  1955. DO_BIT 1, 0 ;
  1956. DO_BIT 0, 0 ;
  1957. ADDFSR FSR1, 1 ;
  1958. DO_BIT 7, 0 ;
  1959. DO_BIT 6, 0 ;
  1960. DO_BIT 5, 0 ;
  1961. DO_BIT 4, 0 ;
  1962. DO_BIT 3, 0 ;
  1963. DO_BIT 2, 0 ;
  1964. DO_BIT 1, 0 ;
  1965. DO_BIT 0, 0 ;
  1966. ADDFSR FSR1, 1 ;
  1967. DO_BIT 7, 0 ;
  1968. DO_BIT 6, 0 ;
  1969. DO_BIT 5, 0 ;
  1970. DO_BIT 4, 0 ;
  1971. DO_BIT 3, 0 ;
  1972. DO_BIT 2, 0 ;
  1973. DO_BIT 1, 0 ;
  1974. DO_BIT 0, 0 ;
  1975. ADDFSR FSR1, 1 ;
  1976. ;-----------------------------------------------;
  1977. ;
  1978. ;-----------------------------------------------;
  1979. ; Xus Front Porch (Black Signal) Generation ;
  1980. ;-----------------------------------------------;
  1981. SET_DAC2BIT COLOR_BLACK ;
  1982. WAIT_FOR_LINE_DONE 1 ;
  1983. ;-----------------------------------------------;
  1984. ;
  1985. ;-----------------------------------------------;
  1986. ; All of this nonsense is just to get the timing;
  1987. ; right between doing the next copyright line or;
  1988. ; starting the series of blank lines. ;
  1989. ;-----------------------------------------------;
  1990. DECFSZ Temp1, F ;
  1991. GOTO $+4 ;
  1992. ;-----------------------------------------------;
  1993. ; Timing Fudge ;
  1994. ;-----------------------------------------------;
  1995. NOP ;
  1996. NOP ;
  1997. ;-----------------------------------------------;
  1998. RETURN ;
  1999. DELAY 1 ;
  2000. ;-----------------------------------------------;
  2001. ; Timing Fudge ;
  2002. ;-----------------------------------------------;
  2003. NOP ;
  2004. NOP ;
  2005. NOP ;
  2006. ;-----------------------------------------------;
  2007. GOTO _CR_Next_Line ;
  2008. ;---------------------------------------------------;
  2009.  
  2010. ;---------------------------------------------------;
  2011. _White_60us_Line: ;
  2012. ;---------------------------------------------------;
  2013. ; 60us WHITE Signal Generation ;
  2014. ;-----------------------------------------------;
  2015. NEG_SYNC_4US ;
  2016. START_LINE COLOR_WHITE, 60, 10 ;
  2017. WAIT_FOR_LINE_DONE 1 ;
  2018. ;-----------------------------------------------;
  2019. ;
  2020. RETURN ;
  2021. ;---------------------------------------------------;
  2022.  
  2023. ;---------------------------------------------------;
  2024. _Draw_Items: ;
  2025. ;---------------------------------------------------;
  2026. ;-----------------------------------------------;
  2027. ; 60us Black Signal Generation ;
  2028. ;-----------------------------------------------;
  2029. NEG_SYNC_4US ;
  2030. START_LINE COLOR_BLACK, 60, 6 ;
  2031. ;-----------------------------------------------;
  2032. ;
  2033. _DI_Draw_Service_Player_1: ;
  2034. MOVLW LOW VIDEO_BUFFER_START + SERVICE_1_START;
  2035. MOVWF FSR1L ;
  2036. MOVLW HIGH VIDEO_BUFFER_START ;
  2037. MOVWF FSR1H ;
  2038. MOVLW LOW SERVICE_TABLE ;
  2039. MOVWF FSR0L ;
  2040. MOVLW HIGH SERVICE_TABLE ;
  2041. MOVWF FSR0H ;
  2042. MOVLW (SERVICE_TABLE_END - SERVICE_TABLE_START) / 2
  2043. MOVWF Temp1 ;
  2044. _DI_DSP1_Next_Byte: ;
  2045. MOVFW INDF0 ;
  2046. BTFSS System_Status, P1_SERVICE_BIT ;
  2047. CLRW ;
  2048. BTFSC System_Status, P2_SERVICE_BIT ;
  2049. CLRW ;
  2050. MOVWF INDF1 ;
  2051. ADDFSR FSR0, 1 ;
  2052. ADDFSR FSR1, 4 ;
  2053. DECFSZ Temp1, F ;
  2054. GOTO _DI_DSP1_Next_Byte ;
  2055. ;
  2056. _DI_Draw_Service_Player_2: ;
  2057. MOVLW LOW VIDEO_BUFFER_START + SERVICE_2_START;
  2058. MOVWF FSR1L ;
  2059. MOVLW HIGH VIDEO_BUFFER_START ;
  2060. MOVWF FSR1H ;
  2061. MOVLW LOW SERVICE_TABLE ;
  2062. MOVWF FSR0L ;
  2063. MOVLW HIGH SERVICE_TABLE ;
  2064. MOVWF FSR0H ;
  2065. MOVLW (SERVICE_TABLE_END - SERVICE_TABLE_START) / 2
  2066. MOVWF Temp1 ;
  2067. ADDWF FSR0L, F ;
  2068. _DI_DSP2_Next_Byte: ;
  2069. MOVFW INDF0 ;
  2070. BTFSS System_Status, P2_SERVICE_BIT ;
  2071. CLRW ;
  2072. BTFSC System_Status, P1_SERVICE_BIT ;
  2073. CLRW ;
  2074. MOVWF INDF1 ;
  2075. ADDFSR FSR0, 1 ;
  2076. ADDFSR FSR1, 4 ;
  2077. DECFSZ Temp1, F ;
  2078. GOTO _DI_DSP2_Next_Byte ;
  2079. ;
  2080. _DI_Draw_Score1: ;
  2081. _DI_DS1_Draw_Left_Char: ;
  2082. SWAPF Score_1, W ;
  2083. ANDLW H'0F' ;
  2084. MOVWF Temp1 ;
  2085. ;
  2086. MOVLW LOW VIDEO_BUFFER_START + LEFT_SCORE_START;
  2087. MOVWF FSR1L ;
  2088. MOVLW HIGH VIDEO_BUFFER_START ;
  2089. MOVWF FSR1H ;
  2090. ;
  2091. MOVLW HIGH CHARACTER_TABLE ;
  2092. MOVWF FSR0H ;
  2093. MOVLW LOW CHARACTER_TABLE ;
  2094. ADDWF Temp1, W ;
  2095. BTFSC STATUS, C ;
  2096. INCF FSR0H, F ;
  2097. MOVWF FSR0L ;
  2098. ;
  2099. MOVLW 5 ;
  2100. MOVWF Temp1 ;
  2101. _DI_DS1_DLC_Next_Line: ;
  2102. MOVFW INDF0 ;
  2103. MOVWF DTemp ;
  2104. RRF DTemp, W ;
  2105. ANDLW H'70' ;
  2106. MOVWF INDF1 ;
  2107. ADDFSR FSR0, 10 ;
  2108. ADDFSR FSR1, 4 ;
  2109. DECFSZ Temp1, F ;
  2110. GOTO _DI_DS1_DLC_Next_Line ;
  2111. ;
  2112. _DI_DS1_Draw_Right_Char: ;
  2113. MOVFW Score_1 ;
  2114. ANDLW H'0F' ;
  2115. MOVWF Temp1 ;
  2116. ;
  2117. MOVLW LOW VIDEO_BUFFER_START + LEFT_SCORE_START;
  2118. MOVWF FSR1L ;
  2119. MOVLW HIGH VIDEO_BUFFER_START ;
  2120. MOVWF FSR1H ;
  2121. ;
  2122. MOVLW HIGH CHARACTER_TABLE ;
  2123. MOVWF FSR0H ;
  2124. MOVLW LOW CHARACTER_TABLE ;
  2125. ADDWF Temp1, W ;
  2126. BTFSC STATUS, C ;
  2127. INCF FSR0H, F ;
  2128. MOVWF FSR0L ;
  2129. ;
  2130. MOVLW 5 ;
  2131. MOVWF Temp1 ;
  2132. _DI_DS1_DRC_Next_Line: ;
  2133. MOVFW INDF0 ;
  2134. MOVWF DTemp ;
  2135. RRF DTemp, W ;
  2136. ANDLW H'07' ;
  2137. MOVWF DTemp ;
  2138. MOVFW INDF1 ;
  2139. IORWF DTemp, W ;
  2140. MOVWF INDF1 ;
  2141. ADDFSR FSR0, 10 ;
  2142. ADDFSR FSR1, 4 ;
  2143. DECFSZ Temp1, F ;
  2144. GOTO _DI_DS1_DRC_Next_Line ;
  2145. ;
  2146. _DI_Draw_Score2: ;
  2147. _DI_DS2_Draw_Left_Char: ;
  2148. SWAPF Score_2, W ;
  2149. ANDLW H'0F' ;
  2150. MOVWF Temp1 ;
  2151. ;
  2152. MOVLW LOW VIDEO_BUFFER_START + RIGHT_SCORE_START;
  2153. MOVWF FSR1L ;
  2154. MOVLW HIGH VIDEO_BUFFER_START ;
  2155. MOVWF FSR1H ;
  2156. ;
  2157. MOVLW HIGH CHARACTER_TABLE ;
  2158. MOVWF FSR0H ;
  2159. MOVLW LOW CHARACTER_TABLE ;
  2160. ADDWF Temp1, W ;
  2161. BTFSC STATUS, C ;
  2162. INCF FSR0H, F ;
  2163. MOVWF FSR0L ;
  2164. ;
  2165. MOVLW 5 ;
  2166. MOVWF Temp1 ;
  2167. _DI_DS2_DLC_Next_Line: ;
  2168. MOVFW INDF0 ;
  2169. ANDLW H'E0' ;
  2170. MOVWF INDF1 ;
  2171. ADDFSR FSR0, 10 ;
  2172. ADDFSR FSR1, 4 ;
  2173. DECFSZ Temp1, F ;
  2174. GOTO _DI_DS2_DLC_Next_Line ;
  2175. ;
  2176. _DI_DS2_Draw_Right_Char: ;
  2177. MOVFW Score_2 ;
  2178. ANDLW H'0F' ;
  2179. MOVWF Temp1 ;
  2180. ;
  2181. MOVLW LOW VIDEO_BUFFER_START + RIGHT_SCORE_START;
  2182. MOVWF FSR1L ;
  2183. MOVLW HIGH VIDEO_BUFFER_START ;
  2184. MOVWF FSR1H ;
  2185. ;
  2186. MOVLW HIGH CHARACTER_TABLE ;
  2187. MOVWF FSR0H ;
  2188. MOVLW LOW CHARACTER_TABLE ;
  2189. ADDWF Temp1, W ;
  2190. BTFSC STATUS, C ;
  2191. INCF FSR0H, F ;
  2192. MOVWF FSR0L ;
  2193. MOVLW 5 ;
  2194. MOVWF Temp1 ;
  2195. _DI_DS2_DRC_Next_Line: ;
  2196. MOVFW INDF0 ;
  2197. ANDLW H'0E' ;
  2198. MOVWF DTemp ;
  2199. MOVFW INDF1 ;
  2200. IORWF DTemp, W ;
  2201. MOVWF INDF1 ;
  2202. ADDFSR FSR0, 10 ;
  2203. ADDFSR FSR1, 4 ;
  2204. DECFSZ Temp1, F ;
  2205. GOTO _DI_DS2_DRC_Next_Line ;
  2206. ;
  2207. ;-----------------------------------------------;
  2208. ; Wait for this line to complete ;
  2209. ;-----------------------------------------------;
  2210. WAIT_FOR_LINE_DONE 0 ;
  2211. ;-----------------------------------------------;
  2212. ;
  2213. ;-----------------------------------------------;
  2214. ; 60us Black Signal Generation ;
  2215. ;-----------------------------------------------;
  2216. NEG_SYNC_4US ;
  2217. START_LINE COLOR_BLACK, 60, 12 ;
  2218. ;-----------------------------------------------;
  2219. ;
  2220. _DI_Draw_Paddle_1: ;
  2221. MOVFW Paddle_1_Y ;
  2222. ADDWF Paddle_1_Y, W ;
  2223. ADDWF Paddle_1_Y, W ;
  2224. ADDWF Paddle_1_Y, W ;
  2225. ADDLW LOW VIDEO_BUFFER_START + LEFT_PADDLE_START;
  2226. MOVWF FSR1L ;
  2227. MOVLW HIGH VIDEO_BUFFER_START ;
  2228. MOVLW PADDLE_HEIGHT ;
  2229. MOVWF Temp1 ;
  2230. _DI_DP1_Next_Bit: ;
  2231. MOVFW INDF1 ;
  2232. IORLW LEFT_PADDLE_BIT ;
  2233. MOVWF INDF1 ;
  2234. ADDFSR FSR1, 4 ;
  2235. DECFSZ Temp1, F ;
  2236. GOTO _DI_DP1_Next_Bit ;
  2237. ;
  2238. _DI_Draw_Paddle_2: ;
  2239. MOVFW Paddle_2_Y ;
  2240. ADDWF Paddle_2_Y, W ;
  2241. ADDWF Paddle_2_Y, W ;
  2242. ADDWF Paddle_2_Y, W ;
  2243. ADDLW LOW VIDEO_BUFFER_START + RIGHT_PADDLE_START;
  2244. MOVWF FSR1L ;
  2245. MOVLW HIGH VIDEO_BUFFER_START ;
  2246. MOVWF FSR1H ;
  2247. MOVLW PADDLE_HEIGHT ;
  2248. MOVWF Temp1 ;
  2249. _DI_DP2_Next_Bit: ;
  2250. MOVFW INDF1 ;
  2251. IORLW RIGHT_PADDLE_BIT ;
  2252. MOVWF INDF1 ;
  2253. ADDFSR FSR1, 4 ;
  2254. DECFSZ Temp1, F ;
  2255. GOTO _DI_DP2_Next_Bit ;
  2256. ;
  2257. _DI_Draw_Ball: ;
  2258. ;-----------------------------------------------;
  2259. ; Check to see if the ball has any movement. If ;
  2260. ; not, we are either at the end of a game or ;
  2261. ; waiting for service. In that case, don't draw ;
  2262. ; the ball. ;
  2263. ;-----------------------------------------------;
  2264. CLRW ;
  2265. XORWF Ball_Dir_X, W ;
  2266. BTFSS STATUS, Z ;
  2267. GOTO _DI_DB_Draw ;
  2268. CLRW ;
  2269. XORWF Ball_Dir_Y, W ;
  2270. BTFSC STATUS, Z ;
  2271. GOTO _DI_Exit ;
  2272. MOVLW 1 ;
  2273. XORWF Ball_Wait, W ;
  2274. BTFSS STATUS, Z ;
  2275. GOTO _DI_Exit ;
  2276. ;
  2277. _DI_DB_Draw: ;
  2278. ;-----------------------------------------------;
  2279. ; This is where we actually 'draw' the ball. ;
  2280. ;-----------------------------------------------;
  2281. MOVFW Ball_Y ;
  2282. ADDWF Ball_Y, W ;
  2283. ADDWF Ball_Y, W ;
  2284. ADDWF Ball_Y, W ;
  2285. ADDLW LOW VIDEO_BUFFER_START ;
  2286. MOVWF FSR1L ;
  2287. RRF Ball_X, W ;
  2288. MOVWF Temp1 ;
  2289. RRF Temp1, F ;
  2290. RRF Temp1, W ;
  2291. ANDLW H'1F' ;
  2292. ADDWF FSR1L, F ;
  2293. MOVLW HIGH VIDEO_BUFFER_START ;
  2294. MOVWF FSR1H ;
  2295. ;
  2296. MOVFW Ball_X ;
  2297. ANDLW H'07' ;
  2298. MOVWF Temp1 ;
  2299. MOVLW H'80' ;
  2300. MOVWF DTemp ;
  2301. MOVLW 0 ; ;
  2302. XORWF Temp1, W ;
  2303. BTFSC STATUS, Z ;
  2304. GOTO $+5 ;
  2305. DECF Temp1, F ;
  2306. RRF DTemp, F ;
  2307. BCF DTemp, MSB ;
  2308. GOTO $-7 ;
  2309. ;
  2310. MOVLW BALL_HEIGHT ;
  2311. MOVWF Temp1 ;
  2312. MOVFW DTemp ;
  2313. _DI_DB_D_Next_Pixel: ;
  2314. XORWF INDF1, F ;
  2315. ADDFSR FSR1, 4 ;
  2316. DECFSZ Temp1, F ;
  2317. GOTO _DI_DB_D_Next_Pixel ;
  2318. ;
  2319. _DI_Exit: ;
  2320. ;-----------------------------------------------;
  2321. ; Wait for this line to complete ;
  2322. ;-----------------------------------------------;
  2323. WAIT_FOR_LINE_DONE 2 ;
  2324. ;-----------------------------------------------;
  2325. ;
  2326. RETURN ;
  2327. ;---------------------------------------------------;
  2328.  
  2329. ;---------------------------------------------------;
  2330. _Clear_Screen: ;
  2331. ;---------------------------------------------------;
  2332. ; This is a 2 60us BLANK lines routine ;
  2333. ;---------------------------------------------------;
  2334. ; Timing Fudge ;
  2335. ;-----------------------------------------------;
  2336. NOP ;
  2337. ;-----------------------------------------------;
  2338. ;
  2339. ;-----------------------------------------------;
  2340. ; 60us Black Signal Generation ;
  2341. ;-----------------------------------------------;
  2342. NEG_SYNC_4US ;
  2343. START_LINE COLOR_BLACK, 60, 6 ;
  2344. ;-----------------------------------------------;
  2345. ;
  2346. _CS_Top: ;
  2347. ;-----------------------------------------------;
  2348. ; Set up the pointer to the video buffer ;
  2349. ;-----------------------------------------------;
  2350. MOVLW HIGH VIDEO_BUFFER_START ;
  2351. MOVWF FSR1H ;
  2352. MOVLW LOW VIDEO_BUFFER_START ;
  2353. MOVWF FSR1L ;
  2354. ;-----------------------------------------------;
  2355. ;
  2356. ;-----------------------------------------------;
  2357. ; Set up the pointer to the title table ;
  2358. ;-----------------------------------------------;
  2359. MOVLW HIGH TITLE_TABLE ;
  2360. MOVWF FSR0H ;
  2361. MOVLW LOW TITLE_TABLE ;
  2362. MOVWF FSR0L ;
  2363. ;-----------------------------------------------;
  2364. ;
  2365. ;-----------------------------------------------;
  2366. ; Set up the number of bytes to transfer ;
  2367. ;-----------------------------------------------;
  2368. MOVLW ((NUM_LINES * 4) /2) / 8 ;
  2369. MOVWF Temp1 ;
  2370. ;-----------------------------------------------;
  2371. ;
  2372. ;-----------------------------------------------;
  2373. ; Transfer the data from the title table to the ;
  2374. ; video buffer, 8 bytes at a time. Doing it in ;
  2375. ; groups of 8 in a loop, instead of 1 byte at a ;
  2376. ; time in a loop, speeds up the transfer as it ;
  2377. ; cuts out a lot of the instruction cycles for ;
  2378. ; the looping mechanism. ;
  2379. ;-----------------------------------------------;
  2380. _CS_T_Next_8_Bytes: ;
  2381. MOVIW 0[INDF0] ;
  2382. MOVWI 0[INDF1] ;
  2383. MOVIW 1[INDF0] ;
  2384. MOVWI 1[INDF1] ;
  2385. MOVIW 2[INDF0] ;
  2386. MOVWI 2[INDF1] ;
  2387. MOVIW 3[INDF0] ;
  2388. MOVWI 3[INDF1] ;
  2389. MOVIW 4[INDF0] ;
  2390. MOVWI 4[INDF1] ;
  2391. MOVIW 5[INDF0] ;
  2392. MOVWI 5[INDF1] ;
  2393. MOVIW 6[INDF0] ;
  2394. MOVWI 6[INDF1] ;
  2395. MOVIW 7[INDF0] ;
  2396. MOVWI 7[INDF1] ;
  2397. _CS_T_Check_For_Title: ;
  2398. BTFSC System_Status, P1_SERVICE_BIT ; If SERVICE is clear for both
  2399. BTFSS System_Status, P2_SERVICE_BIT ; players, then it's the start
  2400. GOTO $+2 ; of a game. Draw the title.
  2401. ADDFSR FSR0, 8 ;
  2402. ADDFSR FSR1, 8 ;
  2403. DECFSZ Temp1, F ;
  2404. GOTO _CS_T_Next_8_Bytes ;
  2405. ;-----------------------------------------------;
  2406. ;
  2407. ;-----------------------------------------------;
  2408. ; Wait for this line to complete ;
  2409. ;-----------------------------------------------;
  2410. WAIT_FOR_LINE_DONE 0 ;
  2411. ;-----------------------------------------------;
  2412. ;
  2413. ;-----------------------------------------------;
  2414. ; 60us Black Signal Generation ;
  2415. ;-----------------------------------------------;
  2416. NEG_SYNC_4US ;
  2417. START_LINE COLOR_BLACK, 60, 9 ;
  2418. ;-----------------------------------------------;
  2419. ;
  2420. _CS_Bottom: ;
  2421. ;-----------------------------------------------;
  2422. ; Set up the pointer to the video buffer ;
  2423. ;-----------------------------------------------;
  2424. MOVLW HIGH VIDEO_BUFFER_START ;
  2425. MOVWF FSR1H ;
  2426. MOVLW LOW VIDEO_BUFFER_START ;
  2427. ADDLW (NUM_LINES * 4) / 2 ;
  2428. MOVWF FSR1L ;
  2429. BTFSC STATUS, C ;
  2430. INCF FSR1H, F ;
  2431. ;-----------------------------------------------;
  2432. ;
  2433. ;-----------------------------------------------;
  2434. ; Set up the pointer to the title table ;
  2435. ;-----------------------------------------------;
  2436. MOVLW HIGH TITLE_TABLE ;
  2437. MOVWF FSR0H ;
  2438. MOVLW LOW TITLE_TABLE ;
  2439. _CS_B_Check_For_Title1: ;
  2440. BTFSC System_Status, P1_SERVICE_BIT ; If SERVICE is clear for both
  2441. BTFSS System_Status, P2_SERVICE_BIT ; players, then it's the start
  2442. GOTO $+2 ; of a game. Draw the title.
  2443. ADDLW (NUM_LINES * 4) / 2 ;
  2444. MOVWF FSR0L ;
  2445. BTFSC STATUS, C ;
  2446. INCF FSR0H, F ;
  2447. ;-----------------------------------------------;
  2448. ;
  2449. ;-----------------------------------------------;
  2450. ; Set up the number of bytes to transfer ;
  2451. ;-----------------------------------------------;
  2452. MOVLW ((NUM_LINES * 4) /2) / 8 ;
  2453. MOVWF Temp1 ;
  2454. ;-----------------------------------------------;
  2455. ;
  2456. ;-----------------------------------------------;
  2457. ; Transfer the data from the title table to the ;
  2458. ; video buffer, 8 bytes at a time. Doing it in ;
  2459. ; groups of 8 in a loop, instead of 1 byte at a ;
  2460. ; time in a loop, speeds up the transfer as it ;
  2461. ; cuts out a lot of the instruction cycles for ;
  2462. ; the looping mechanism. ;
  2463. ;-----------------------------------------------;
  2464. _CS_B_Next_8_Bytes: ;
  2465. MOVIW 0[INDF0] ;
  2466. MOVWI 0[INDF1] ;
  2467. MOVIW 1[INDF0] ;
  2468. MOVWI 1[INDF1] ;
  2469. MOVIW 2[INDF0] ;
  2470. MOVWI 2[INDF1] ;
  2471. MOVIW 3[INDF0] ;
  2472. MOVWI 3[INDF1] ;
  2473. MOVIW 4[INDF0] ;
  2474. MOVWI 4[INDF1] ;
  2475. MOVIW 5[INDF0] ;
  2476. MOVWI 5[INDF1] ;
  2477. MOVIW 6[INDF0] ;
  2478. MOVWI 6[INDF1] ;
  2479. MOVIW 7[INDF0] ;
  2480. MOVWI 7[INDF1] ;
  2481. _CS_B_Check_For_Title2: ;
  2482. BTFSC System_Status, P1_SERVICE_BIT ; If SERVICE is clear for both
  2483. BTFSS System_Status, P2_SERVICE_BIT ; players, then it's the start
  2484. GOTO $+2 ; of a game. Draw the title.
  2485. ADDFSR FSR0, 8 ;
  2486. ADDFSR FSR1, 8 ;
  2487. DECFSZ Temp1, F ;
  2488. GOTO _CS_B_Next_8_Bytes ;
  2489. ;-----------------------------------------------;
  2490. ;
  2491. ;-----------------------------------------------;
  2492. ; Wait for this line to complete ;
  2493. ;-----------------------------------------------;
  2494. WAIT_FOR_LINE_DONE 0 ;
  2495. ;-----------------------------------------------;
  2496. ;
  2497. RETURN ;
  2498. ;---------------------------------------------------;
  2499.  
  2500. ;---------------------------------------------------;
  2501. ; Numeric Characters (0-9) Scan Line Data ;
  2502. ;---------------------------------------------------;
  2503. CHARACTER_TABLE: ;
  2504. ;---------------------------------------------------;
  2505. ; These are the bitmaps for the score characters;
  2506. ; 0-9, 4x5 pixels ;
  2507. ;-----------------------------------------------;
  2508. DT B'11101110', B'01000100', B'11101110', B'11101110', B'10101010', B'11101110', B'11101110', B'11101110', B'11101110', B'11101110'
  2509. DT B'10101010', B'11001100', B'00100010', B'00100010', B'10101010', B'10001000', B'10001000', B'00100010', B'10101010', B'10101010'
  2510. DT B'10101010', B'01000100', B'11101110', B'11101110', B'11101110', B'11101110', B'11101110', B'00100010', B'11101110', B'11101110'
  2511. DT B'10101010', B'01000100', B'10001000', B'00100010', B'00100010', B'00100010', B'10101010', B'00100010', B'10101010', B'00100010'
  2512. DT B'11101110', B'01000100', B'11101110', B'11101110', B'00100010', B'11101110', B'11101110', B'00100010', B'11101110', B'00100010'
  2513. ;---------------------------------------------------;
  2514.  
  2515. ;---------------------------------------------------;
  2516. SERVICE_TABLE: ;
  2517. ;---------------------------------------------------;
  2518. ; These are the bitmaps for the 'SERVICE' arrow ;
  2519. ; that shows up next to a score. ;
  2520. ;-----------------------------------------------;
  2521. SERVICE_TABLE_START: ;
  2522. DT B'00000100' ;
  2523. DT B'00000010' ;
  2524. DT B'00000001' ;
  2525. DT B'00000010' ;
  2526. DT B'00000100' ;
  2527. DT B'00100000' ;
  2528. DT B'01000000' ;
  2529. DT B'10000000' ;
  2530. DT B'01000000' ;
  2531. DT B'00100000' ;
  2532. SERVICE_TABLE_END: ;
  2533. ;---------------------------------------------------;
  2534.  
  2535. ;---------------------------------------------------;
  2536. ; Title Title Scan Line Data ;
  2537. ;---------------------------------------------------;
  2538. TITLE_TABLE: ;
  2539. ;---------------------------------------------------;
  2540. TITLE_TABLE_START: ;
  2541. ;-----------------------------------------------;
  2542. ; The first 6x4 lines should be 0 so that the ;
  2543. ; title graphic does not merge with the scores, ;
  2544. ; and for the screen to clear the title properly;
  2545. ;-----------------------------------------------;
  2546. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2547. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2548. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2549. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2550. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2551. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2552. ;-----------------------------------------------;
  2553. ; The next 41x4 lines contain the title graphic ;
  2554. ;-----------------------------------------------;
  2555. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2556. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2557. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2558. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2559. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2560. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2561. DT B'00000111', B'10000000', B'01110000', B'00000000'
  2562. DT B'00000111', B'11000000', B'11111000', B'00000000'
  2563. DT B'00000100', B'01000000', B'10001000', B'00000000'
  2564. DT B'00000100', B'01001110', B'10001001', B'11000000'
  2565. DT B'00000111', B'11011111', B'10001011', B'11100000'
  2566. DT B'00000111', B'10010001', B'10001010', B'00100000'
  2567. DT B'00000100', B'00010001', B'10001010', B'00000000'
  2568. DT B'00000100', B'00010001', B'10001010', B'01100000'
  2569. DT B'00000100', B'00010001', B'10001010', B'01100000'
  2570. DT B'00000100', B'00010001', B'10001010', B'00100000'
  2571. DT B'00000000', B'00010001', B'00000010', B'00100000'
  2572. DT B'00000000', B'00011111', B'00000011', B'11100000'
  2573. DT B'00000000', B'00001110', B'00000001', B'11000000'
  2574. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2575. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2576. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2577. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2578. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2579. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2580. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2581. DT B'00001110', B'11101110', B'01110101', B'01110000'
  2582. DT B'00001110', B'11101110', B'01110101', B'01110000'
  2583. DT B'00001000', B'10101010', B'00100101', B'01000000'
  2584. DT B'00001100', B'10101100', B'00100111', B'01100000'
  2585. DT B'00001000', B'10101010', B'00100101', B'01000000'
  2586. DT B'00001000', B'11101010', B'00100101', B'01110000'
  2587. DT B'00001000', B'11101010', B'00100101', B'01110000'
  2588. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2589. DT B'00000101', B'11011101', B'11101010', B'11100000'
  2590. DT B'00000101', B'11011101', B'11101010', B'11100000'
  2591. DT B'00000100', B'01010001', B'10101010', B'10100000'
  2592. DT B'00000101', B'11011001', B'11101110', B'10100000'
  2593. DT B'00000101', B'00010001', B'10100010', B'10100000'
  2594. DT B'00000101', B'11010001', B'11100010', B'11100000'
  2595. DT B'00000101', B'11010001', B'11100010', B'11100000'
  2596. ;-----------------------------------------------;
  2597. ; This last 1x4 line should be 0 so that the ;
  2598. ; title graphic does bump into the sideline ;
  2599. ;-----------------------------------------------;
  2600. DT B'00000000', B'00000000', B'00000000', B'00000000'
  2601. TITLE_TABLE_END: ;
  2602. ;---------------------------------------------------;
  2603.  
  2604. ;---------------------------------------------------;
  2605. ; COPYRIGHT Scan Line Data ;
  2606. ;---------------------------------------------------;
  2607. COPYRIGHT_TABLE: ;
  2608. ;---------------------------------------------------;
  2609. ; this is the bitmap for the COPYRIGHT line ;
  2610. ; 64x8 pixels ;
  2611. ;-----------------------------------------------;
  2612. DT B'00110011', B'10111000', B'10010010', B'00111001', B'00010111', B'00000101', B'01110000', B'10011100'
  2613. DT B'00111011', B'10111001', B'00111001', B'00111011', B'10110111', B'00000101', B'01110001', B'11011100'
  2614. DT B'10101001', B'00010001', B'00101001', B'00001010', B'10010001', B'01010101', B'00010001', B'01000101'
  2615. DT B'10101001', B'00010001', B'00100001', B'00111010', B'10010111', B'01010101', B'00110001', B'01000101'
  2616. DT B'10101001', B'00010001', B'00100001', B'00111010', B'10010111', B'01010101', B'00110001', B'01001001'
  2617. DT B'10101001', B'00010001', B'00101001', B'00100010', B'10010100', B'01010101', B'00010001', B'01010001'
  2618. DT B'00111001', B'00111001', B'00111001', B'00111011', B'10010111', B'00000101', B'01110101', B'11010000'
  2619. DT B'00110001', B'00111000', B'10010010', B'00111001', B'00010111', B'00000010', B'01110100', B'10010000'
  2620. ;---------------------------------------------------;
  2621.  
  2622. ;---------------------------------------------------;
  2623. ;---------------------------------------------------;
  2624. END ;
  2625. ;---------------------------------------------------;
  2626. ;---------------------------------------------------;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement