Advertisement
Guest User

PONG.ASM V3.05

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