Advertisement
Guest User

PONG.ASM V4.00

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