Advertisement
Guest User

PONG.ASM V3.06

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