home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 85 / asm / source / usgard / pente10b.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  22.6 KB  |  1,282 lines

  1. ;            ***************************************
  2. ;            ***                                 ***
  3. ;            ***  PPPP               t           ***
  4. ;            ***  P   P              t           ***
  5. ;            ***  P   P  eee  n nn  ttt    eee   ***
  6. ;            ***  PPPP  e   e nn  n  t    e   e  ***
  7. ;            ***  P     eeeee n   n  t    eeeee  ***
  8. ;            ***  P     e     n   n  t  t e      ***
  9. ;            ***  P      eee  n   n   tt   eee   ***
  10. ;            ***                                 ***
  11. ;            ***      v1.0b by Nick Blizard      ***
  12. ;            ***            11/14/97             ***
  13. ;            ***          Usgard v1.1+           ***
  14. ;            ***                                 ***
  15. ;            ***************************************
  16. ;
  17. ;Here is the source to Pente v0.10b, remember to give me credit for anything you use.
  18. ;Any problems contact me at     nblizard@bellsouth.net
  19. ;
  20. ;Goals : AI , Link Play , Clean up Code , Add more comments
  21.  
  22.  
  23. #include "usgard.h"
  24.  
  25.  
  26. CURX1      = TEXT_MEM       ;cursor's x position in pixels  :  1 byte
  27. CURY1      = TEXT_MEM+1     ;cursor's y position in pixels  :  1 byte
  28. PTURN      = TEXT_MEM+2     ;determines which player's turn it is , 0=P1 , 1=P2  :  1 byte
  29. BOARD      = TEXT_MEM2      ;game board  :  160 bytes
  30. CURX2      = TEXT_MEM+3     ;cursor's x position relative to board  :  1 byte
  31. CURY2      = TEXT_MEM+4     ;cursor's y position relative to board  :  1 byte
  32. TEMP1      = TEXT_MEM+5     ;temporary variable #1  :  1 byte
  33. TEMP2      = TEXT_MEM+6     ;    "        "     #2  :  1 byte
  34. TEMP3      = TEXT_MEM+18    ;    "        "     #3  :  1 byte
  35. PTURN2     = TEXT_MEM+7     ;player's turn in game peice fashion(see below)
  36. LPTURN     = TEXT_MEM+8     ;last player's turn in game peice fashion  ,  1=P1  ,  2=P2  :  1 byte
  37. CC         = TEXT_MEM+9     ;round of check capture your on  :  1 byte
  38. QPOS1X     = TEXT_MEM+10    ;position one queud to capture X  : 1 byte
  39. QPOS1Y     = TEXT_MEM+11    ;position one queud to capture Y  :  1 byte
  40. QPOSONE    = TEXT_MEM+12    ;position one queud to capture  :  1 byte
  41. QPOS2X     = TEXT_MEM+13    ;position two queud to capture X  :  1 byte
  42. QPOS2Y     = TEXT_MEM+14    ;position two queud to capture Y  :  1 byte
  43. QPOSTWO    = TEXT_MEM+15    ;position twp queud to capture  :  1 byte
  44. CAPPOS1    = TEXT_MEM+16    ;start position of where captured peices go for player 1  :  1 byte
  45. CAPPOS2    = TEXT_MEM+17    ;  "      "     "    "      "       "    "   "    "    2  :  1 byte
  46.  
  47.  
  48. .org 0
  49. .db "v1.0b  by Nick Blizard",0
  50.  
  51.  
  52. Init:
  53.   call CLEARLCD
  54.   ld a,4
  55.   out (5),a
  56.   ld a,44
  57.   ld (CURX1),a
  58.   ld a,26
  59.   ld (CURY1),a
  60.   ld a,7
  61.   ld (CURX2),a
  62.   ld a,4
  63.   ld (CURY2),a
  64.   ld a,20
  65.   ld (CAPPOS1),a
  66.   ld (CAPPOS2),a
  67.   ld a,r
  68.   and %00000001
  69.   ld (PTURN),a
  70. Start:
  71.   call CLEARLCD
  72.   call &OpeningScreen1
  73.   call CLEARLCD
  74.   call &OpeningScreen2
  75.   call CLEARLCD
  76.   call &ClearBoardMem
  77.   call &DrawBoard
  78. StartLoop1:
  79.   call &Turn
  80.   call &CursorMain
  81.   jp &CheckDuplicate
  82. CDLoop:
  83.   call &GamePeice
  84.   jp &CheckCapture
  85. CCLoop:
  86.   jp &CheckWin
  87. CWRet:
  88.   jp &StartLoop1
  89.  
  90.  
  91. ;*** Subroutine to make board mem all zeros ***
  92. ClearBoardMem:
  93.   ld a,0
  94. CBMLoop1:
  95.   ld hl,BOARD
  96.   ld c,a
  97.   ld b,0
  98.   add hl,bc
  99.   ld b,h
  100.   ld c,l
  101.   push af
  102.   ld a,0
  103.   ld (bc),a
  104.   pop af
  105.   inc a
  106.   ld b,160
  107.   cp b
  108.   ret z
  109.   jp &CBMLoop1
  110.  
  111. ;*** Subroutine to draw the playing board and the other pics on the main screen ***
  112. ;--- draw vertical lines ---
  113. DrawBoard:
  114.   ld d,-4
  115.   ld e,2
  116.   ld h,-4
  117.   ld l,56
  118. BoardLoop1:
  119.   ld a,d
  120.   add a,6
  121.   ld d,a
  122.   ld a,h
  123.   add a,6
  124.   ld h,a
  125. #fncall fline
  126.   ld a,d
  127.   ld b,a
  128.   ld a,92
  129.   cp b
  130.   jp nz,&BoardLoop1
  131. ;--- draw horizontal lines ---
  132.   ld d,2
  133.   ld e,-4
  134.   ld h,92
  135.   ld l,-4
  136. BoardLoop2:
  137.   ld a,e
  138.   add a,6
  139.   ld e,a
  140.   ld a,l
  141.   add a,6
  142.   ld l,a
  143. #fncall fline
  144.   ld a,e
  145.   ld b,a
  146.   ld a,56
  147.   cp b
  148.   jp nz,&BoardLoop2
  149. ;--- draw other lines ---
  150.   ld d,95
  151.   ld e,0
  152.   ld h,95
  153.   ld l,63
  154. #fncall fline
  155.   ld d,96
  156.   ld e,50
  157.   ld h,127
  158.   ld l,50
  159. #fncall fline
  160.   ld d,97
  161.   ld e,1
  162.   ld h,126
  163.   ld l,1
  164. #fncall fline
  165.   ld h,97
  166.   ld l,9
  167. #fncall fline
  168.   ld d,97
  169.   ld e,9
  170.   ld h,126
  171.   ld l,9
  172. #fncall fline
  173.   ld d,126
  174.   ld e,1
  175.   ld h,126
  176.   ld l,9
  177. #fncall fline
  178.   ld d,97
  179.   ld e,18
  180.   ld h,107
  181.   ld l,18
  182. #fncall fline
  183.   ld d,116
  184.   ld e,18
  185.   ld h,126
  186.   ld l,18
  187. #fncall fline
  188. ;--- draw other pics and words ---
  189.   ld hl,&BoardSprite
  190.   ld b,99
  191.   ld c,4
  192. #fncall pspr_nr
  193.   ld hl,&BoardSprite
  194.   ld b,123
  195.   ld c,4
  196. #fncall pspr_nr
  197.   ld a,102
  198.   ld (CURSOR_X),a
  199.   ld a,2                 ;subtract 1 from Y, don't know why
  200.   ld (CURSOR_Y),a
  201.   ld hl,&BoardText1
  202.   call D_ZM_STR
  203.   ld a,99
  204.   ld (CURSOR_X),a
  205.   ld a,11                ;subtract 1 from Y, don't know why
  206.   ld (CURSOR_Y),a
  207.   ld hl,&BoardText2
  208.   call D_ZM_STR
  209.   ld a,118
  210.   ld (CURSOR_X),a
  211.   ld a,11                ;subtract 1 from Y, don't know why
  212.   ld (CURSOR_Y),a
  213.   ld hl,&BoardText3
  214.   call D_ZM_STR
  215.   ret
  216.  
  217.  
  218. ;*** Subroutine to show who goes next ***
  219. Turn:
  220.   ld a,(PTURN)
  221.   ld b,0
  222.   cp b
  223.   jp z,&Turn1
  224. Turn2:
  225.   ld hl,&TurnText1
  226.   ld a,101
  227.   ld (CURSOR_X),a
  228.   ld a,51
  229.   ld (CURSOR_Y),a
  230.   call D_ZM_STR
  231.   ld hl,&TurnText22
  232.   ld a,99
  233.   ld (CURSOR_X),a
  234.   ld a,57
  235.   ld (CURSOR_Y),a
  236.   call D_ZM_STR
  237.   ret
  238. Turn1:
  239.   ld hl,&TurnText1
  240.   ld a,101
  241.   ld (CURSOR_X),a
  242.   ld a,51
  243.   ld (CURSOR_Y),a
  244.   call D_ZM_STR
  245.   ld hl,&TurnText21
  246.   ld a,99
  247.   ld (CURSOR_X),a
  248.   ld a,57
  249.   ld (CURSOR_Y),a
  250.   call D_ZM_STR
  251.   ret
  252.  
  253.  
  254. ;*** Subroutine to use a cursor to place a game peice ***
  255. ;--- place the two cursor sprites ---
  256. CursorMain:
  257. CursorLoop1:
  258.   ld a,(CURX1)
  259.   ld b,a
  260.   ld a,(CURY1)
  261.   ld c,a
  262.   ld hl,&CursorSprite1
  263.   call &PlaceCursor
  264.   ld b,1
  265.   push bc
  266.   jp &CursorDelay
  267. CursorLoop2:
  268.   ld a,(CURX1)
  269.   ld b,a
  270.   ld a,(CURY1)
  271.   ld c,a
  272.   ld hl,&CursorSprite2
  273.   call &PlaceCursor
  274.   ld b,0
  275.   push bc
  276.   jp &CursorDelay
  277. ;--- delay and key check for cursor ---
  278. CursorDelay:
  279.   ld b, 0
  280.   ld c, 0
  281. CursorDelay1:
  282.   call GET_KEY
  283.   cp K_LEFT
  284.   jp z,&CursorLeft
  285.   cp K_RIGHT
  286.   jp z,&CursorRight
  287.   cp K_DOWN
  288.   jp z,&CursorDown
  289.   cp K_UP
  290.   jp z,&CursorUp
  291.   cp K_SECOND
  292.   jp z,&CursorPlacePeice
  293.   cp K_EXIT
  294.   jp z,&ExitProgram
  295.   cp K_F1
  296.   jp z,&TeacherKey
  297.   cp K_MORE
  298.   call z,&Controls
  299.   cp K_CLEAR
  300.   jp z,&Init
  301.   ld a,255
  302.   inc b
  303.   cp b
  304.   jp z,&CursorDelayLoop1
  305.   jp &CursorDelay1
  306. CursorDelayLoop1:
  307.   ld a,35
  308.   inc c
  309.   cp c
  310.   jp z,&CursorDelay2
  311.   ld b,0
  312.   jp &CursorDelay1
  313. CursorDelay2:
  314.   pop bc
  315.   ld a,0
  316.   cp b
  317.   jp z,&CursorLoop1
  318.   jp &CursorLoop2
  319. ;--- move cursor and check if it goes off screen or exists from an existing peice ---
  320. CursorLeft:
  321.   pop bc
  322.   ld a,(CURX1)
  323.   ld b,2
  324.   cp b
  325.   jp z,&CursorEnd
  326.   ld (TEMP1),a
  327.   call &CursorFixBoard
  328.   ld a,(TEMP1)
  329.   sub 6
  330.   ld (CURX1),a
  331.   ld a,(CURX2)
  332.   dec a
  333.   ld (CURX2),a
  334.   jp &CursorEnd
  335. CursorRight:
  336.   pop bc
  337.   ld a,(CURX1)
  338.   ld b,92
  339.   cp b
  340.   jp z,&CursorEnd
  341.   ld (TEMP1),a
  342.   call &CursorFixBoard
  343.   ld a,(TEMP1)
  344.   add a,6
  345.   ld (CURX1),a
  346.   ld a,(CURX2)
  347.   inc a
  348.   ld (CURX2),a
  349.   jp &CursorEnd
  350. CursorUp:
  351.   pop bc
  352.   ld a,(CURY1)
  353.   ld b,2
  354.   cp b
  355.   jp z,&CursorEnd
  356.   ld (TEMP1),a
  357.   call &CursorFixBoard
  358.   ld a,(TEMP1)
  359.   sub 6
  360.   ld (CURY1),a
  361.   ld a,(CURY2)
  362.   dec a
  363.   ld (CURY2),a
  364.   jp &CursorEnd
  365. CursorDown:
  366.   pop bc
  367.   ld a,(CURY1)
  368.   ld b,56
  369.   cp b
  370.   jp z,&CursorEnd
  371.   ld (TEMP1),a
  372.   call &CursorFixBoard
  373.   ld a,(TEMP1)
  374.   add a,6
  375.   ld (CURY1),a
  376.   ld a,(CURY2)
  377.   inc a
  378.   ld (CURY2),a
  379.   jp &CursorEnd
  380. CursorPlacePeice:
  381.   pop bc
  382.   ret
  383. ;--- fix board after cursor move ---
  384. CursorFixBoard:
  385.   ld a,(CURX1)
  386.   ld b,a
  387.   ld a,(CURY1)
  388.   ld c,a
  389.   push bc
  390.   dec b
  391.   dec c
  392.   ld hl,&FixSprite1
  393. #fncall pspr_nr
  394.   ld a,(CURY2)
  395.   ld b,a
  396.   ld c,16
  397.   call &Multiply
  398.   ld a,(CURX2)
  399.   add a,d
  400.   ld c,a
  401.   ld b,0
  402.   ld hl,BOARD
  403.   add hl,bc
  404.   ld b,h
  405.   ld c,l
  406.   ld a,(bc)
  407.   ld b,a
  408.   ld a,1
  409.   cp b
  410.   jp z,&CursorFixPeice1
  411.   ld a,2
  412.   cp b
  413.   jp z,&CursorFixPeice2
  414.   pop bc
  415.   ld a,2
  416.   cp b
  417.   call z,&CursorFixBoard1
  418.   ld a,92
  419.   cp b
  420.   call z,&CursorFixBoard2
  421.   ld a,2
  422.   cp c
  423.   call z,&CursorFixBoard3
  424.   ld a,56
  425.   cp c
  426.   call z,&CursorFixBoard4
  427.   ret
  428. CursorFixBoard1:
  429.   push bc
  430.   dec b
  431.   call &RemovePixel
  432.   pop bc
  433.   ret
  434. CursorFixBoard2:
  435.   push bc
  436.   inc b
  437.   call &RemovePixel
  438.   pop bc
  439.   ret
  440. CursorFixBoard3:
  441.   push bc
  442.   dec c
  443.   call &RemovePixel
  444.   pop bc
  445.   ret
  446. CursorFixBoard4:
  447.   push bc
  448.   inc c
  449.   call &RemovePixel
  450.   pop bc
  451.   ret
  452. CursorFixPeice1:
  453.   pop bc
  454.   ld hl,&GameSprite1
  455.   call &PlacePeice
  456.   ret
  457. CursorFixPeice2:
  458.   pop bc
  459.   ld hl,&GameSprite2
  460.   call &PlacePeice
  461.   ret
  462. CursorEnd:
  463.   jp &CursorMain
  464.  
  465.  
  466. ;*** Subroutine to place the proper game peice and write to the correct mem location ***
  467. GamePeice:
  468.   ld a,(CURX1)
  469.   ld b,a
  470.   ld a,(CURY1)
  471.   ld c,a
  472.   ld a,(PTURN)
  473.   ld d,1
  474.   cp d
  475.   jp z,&GPPlayer2
  476. GPPlayer1:
  477.   ld hl,&GameSprite1
  478.   call &PlacePeice
  479.   call &GPMemLoc
  480.   ld a,1
  481.   ld (bc),a
  482.   ld a,1
  483.   ld (PTURN),a
  484.   ld (LPTURN),a
  485.   ld a,2
  486.   ld (PTURN2),a
  487.   ret
  488. GPPlayer2:
  489.   ld hl,&GameSprite2
  490.   call &PlacePeice
  491.   call &GPMemLoc
  492.   ld a,2
  493.   ld (bc),a
  494.   ld a,0
  495.   ld (PTURN),a
  496.   ld a,2
  497.   ld (LPTURN),a
  498.   ld a,1
  499.   ld (PTURN2),a
  500.   ret
  501. GPMemLoc:
  502.   ld a,(CURY2)
  503.   ld b,a
  504.   ld c,16
  505.   call &Multiply
  506.   ld a,(CURX2)
  507.   add a,d
  508.   ld c,a
  509.   ld b,0
  510.   ld hl,BOARD
  511.   add hl,bc
  512.   ld b,h
  513.   ld c,l
  514.   ret
  515.  
  516.  
  517. ;*** Subroutine to check and see if someone tries to place a peice on an existing peice ***
  518. CheckDuplicate:
  519.   ld a,(CURY2)
  520.   ld b,a
  521.   ld c,16
  522.   call &Multiply
  523.   ld a,(CURX2)
  524.   add a,d
  525.   ld c,a
  526.   ld b,0
  527.   ld hl,BOARD
  528.   add hl,bc
  529.   ld b,h
  530.   ld c,l
  531.   ld a,(bc)
  532.   ld b,0
  533.   cp b
  534.   jp z,&CDLoop
  535.   jp &StartLoop1
  536.  
  537.  
  538. ;*** Subroutine to check if a capture has occured ***
  539. CheckCapture:
  540.   ld a,1
  541.   ld (CC),a
  542. CheckCLoop:
  543.   ld a,(CURX2)
  544.   ld (TEMP1),a
  545.   ld a,(CURY2)
  546.   ld (TEMP2),a
  547.   call &CheckC1
  548.   ld a,(PTURN2)
  549.   cp b
  550.   jp nz,&CheckCNext  
  551.   ld a,(TEMP1)
  552.   ld (QPOS1X),a
  553.   ld a,(TEMP2)
  554.   ld (QPOS1Y),a
  555.   ld a,e
  556.   ld (QPOSONE),a
  557.   call &CheckC1
  558.   ld a,(PTURN2)
  559.   cp b
  560.   jp nz,&CheckCNext
  561.   ld a,(TEMP1)
  562.   ld (QPOS2X),a
  563.   ld a,(TEMP2)
  564.   ld (QPOS2Y),a
  565.   ld a,e
  566.   ld (QPOSTWO),a
  567.   call &CheckC1
  568.   ld a,(LPTURN)
  569.   cp b
  570.   jp nz,&CheckCNext
  571.   call &CapturePeice
  572.   ld a,(CAPPOS1)
  573.   ld b,50
  574.   cp b
  575.   jp z,&PlayerWin
  576.   ld a,(CAPPOS2)
  577.   ld b,50
  578.   cp b
  579.   jp z,&PlayerWin
  580.   jp &CheckCNext
  581. CheckC1:
  582.   ld a,(TEMP1)
  583.   ld b,a
  584.   ld a,(TEMP2)
  585.   ld c,a
  586.   call &CheckC2
  587.   push bc
  588.   ld b,16
  589.   call &Multiply
  590.   pop bc
  591.   ld a,c
  592.   ld (TEMP2),a
  593.   ld a,b
  594.   ld (TEMP1),a
  595.   add a,d
  596.   ld e,a
  597.   ld c,a
  598.   ld b,0
  599.   ld hl,BOARD
  600.   add hl,bc
  601.   ld b,h
  602.   ld c,l
  603.   ld a,(bc)
  604.   ld b,a
  605.   ret
  606. CheckC2:
  607.   ld a,(CC)
  608.   ld d,a
  609.   ld a,1
  610.   cp d
  611.   call z,&CCUL
  612.   ld a,2
  613.   cp d
  614.   call z,&CCU
  615.   ld a,3
  616.   cp d
  617.   call z,&CCUR
  618.   ld a,4
  619.   cp d
  620.   call z,&CCL
  621.   ld a,5
  622.   cp d
  623.   call z,&CCR
  624.   ld a,6
  625.   cp d
  626.   call z,&CCDL
  627.   ld a,7
  628.   cp d
  629.   call z,&CCD
  630.   ld a,8
  631.   cp d
  632.   call z,&CCDR
  633.   ret
  634. CCUL:
  635.   dec b
  636.   dec c
  637.   ret
  638. CCU:
  639.   dec c
  640.   ret
  641. CCUR:
  642.   inc b
  643.   dec c
  644.   ret
  645. CCL:
  646.   dec b
  647.   ret
  648. CCR:
  649.   inc b
  650.   ret
  651. CCDL:
  652.   dec b
  653.   inc c
  654.   ret
  655. CCD:
  656.   inc c
  657.   ret
  658. CCDR:
  659.   inc b
  660.   inc c
  661.   ret
  662. CheckCNext:
  663.   ld a,(CC)
  664.   ld b,a
  665.   ld a,8
  666.   cp b
  667.   jp z,&CCLoop
  668.   inc b
  669.   ld a,b
  670.   ld (CC),a
  671.   jp &CheckCLoop
  672. CapturePeice:
  673.   ld a,(QPOS1X)
  674.   call &CapPecLoop
  675.   ld a,d
  676.   ld (TEMP1),a
  677.   ld a,(QPOS1Y)
  678.   call &CapPecLoop
  679.   ld c,d
  680.   ld a,(TEMP1)
  681.   ld b,a
  682.   ld hl,&FixSprite2
  683. #fncall pspr_nr
  684.   ld a,(QPOSONE)
  685.   call &CapPecLoop2
  686.   ld a,(QPOS2X)
  687.   call &CapPecLoop
  688.   ld a,d
  689.   ld (TEMP1),a
  690.   ld a,(QPOS2Y)
  691.   call &CapPecLoop
  692.   ld c,d
  693.   ld a,(TEMP1)
  694.   ld b,a
  695.   ld hl,&FixSprite2
  696. #fncall pspr_nr
  697.   ld a,(QPOSTWO)
  698.   call &CapPecLoop2
  699.   call &TallyPeice
  700.   ret
  701. CapPecLoop:
  702.   ld b,a
  703.   ld c,6
  704.   call &Multiply
  705.   ret
  706. CapPecLoop2:
  707.   ld c,a
  708.   ld b,0
  709.   ld hl,Board
  710.   add hl,bc
  711.   ld b,h
  712.   ld c,l
  713.   ld a,0
  714.   ld (bc),a
  715.   ret
  716. TallyPeice:
  717.   ld a,(LPTURN)
  718.   ld b,2
  719.   cp b
  720.   jp z,&TPeice2
  721.   ld a,(CAPPOS1)
  722.   ld c,a
  723.   ld b,97
  724.   ld hl,&GameSprite2
  725. #fncall pspr_nr
  726.   ld a,b
  727.   add a,6
  728.   ld b,a
  729.   ld hl,&GameSprite2
  730. #fncall pspr_nr
  731.   ld a,(CAPPOS1)
  732.   add a,6
  733.   ld (CAPPOS1),a
  734.   ret
  735. TPeice2:
  736.   ld a,(CAPPOS2)
  737.   ld c,a
  738.   ld b,116
  739.   ld hl,&GameSprite1
  740. #fncall pspr_nr
  741.   ld a,b
  742.   add a,6
  743.   ld b,a
  744.   ld hl,&GameSprite1
  745. #fncall pspr_nr
  746.   ld a,(CAPPOS2)
  747.   add a,6
  748.   ld (CAPPOS2),a
  749.   ret
  750.  
  751.  
  752. ;*** Subroutine to check if a win has occured ***
  753. CheckWin:
  754.   ld a,1
  755.   ld (CC),a
  756.   ld a,0
  757.   ld (TEMP1),a
  758. CWLoop1:
  759.   ld a,(CURX2)
  760.   ld b,a
  761.   ld a,(CURY2)
  762.   ld c,a
  763. CWLoop5:
  764.   call &CWLoop2
  765.   call &CWLoop3
  766.   cp b
  767.   jp z,&TallyMark
  768.   ld a,(CC)
  769.   inc a
  770.   ld (CC),a
  771.   call &CWLoop4
  772.   ld a,(CC)
  773.   ld b,9
  774.   cp b
  775.   jp z,&CWRet
  776.   jp &CWLoop1
  777. CWLoop2:
  778.   ld a,(CC)
  779.   ld d,1
  780.   cp d
  781.   call z,&CCL
  782.   ld d,2
  783.   cp d
  784.   call z,&CCR
  785.   ld d,3
  786.   cp d
  787.   call z,&CCUL
  788.   ld d,4
  789.   cp d
  790.   call z,&CCDR
  791.   ld d,5
  792.   cp d
  793.   call z,&CCU
  794.   ld d,6
  795.   cp d
  796.   call z,&CCD
  797.   ld d,7
  798.   cp d
  799.   call z,&CCUR
  800.   ld d,8
  801.   cp d
  802.   call z,&CCDL
  803.   ret
  804. CWLoop3:
  805.   ld a,b
  806.   ld (TEMP2),a
  807.   ld a,c
  808.   ld (TEMP3),a
  809.   push bc
  810.   ld b,16
  811.   call &Multiply
  812.   pop bc
  813.   ld a,b
  814.   add a,d
  815.   ld c,a
  816.   ld b,0
  817.   ld hl,Board
  818.   add hl,bc
  819.   ld b,h
  820.   ld c,l
  821.   ld a,(bc)
  822.   ld b,a
  823.   ld a,(LPTURN)
  824.   ret
  825. TallyMark:
  826.   ld a,(TEMP1)
  827.   inc a
  828.   ld (TEMP1),a
  829.   ld b,4
  830.   cp b
  831.   jp z,&PlayerWin
  832.   call &TMLoop
  833.   jp &CWLoop5
  834. CWLoop4:
  835.   ld b,3
  836.   cp b
  837.   call z,&CWL42
  838.   ld b,5
  839.   cp b
  840.   call z,&CWL42
  841.   ld b,7
  842.   cp b
  843.   call z,&CWL42
  844.   ret
  845. CWL42:
  846.   ld a,0
  847.   ld (TEMP1),a
  848.   ret
  849. TMLoop:
  850.   ld a,(TEMP2)
  851.   ld b,a
  852.   ld a,(TEMP3)
  853.   ld c,a
  854.   ret
  855.  
  856.  
  857. ;*** Subroutine to display who wins and wait for keypress ***
  858. PlayerWin:
  859.   ld a,3
  860.   ld (CURSOR_ROW),a
  861.   ld a,3
  862.   ld (CURSOR_COL),a
  863.   set 3,(IY+05)
  864.   ld a,(PTURN2)
  865.   ld b,1
  866.   cp b
  867.   call z,&PlWLoop2
  868.   ld b,2
  869.   cp b
  870.   call z,&PlWLoop1
  871.   call D_ZT_STR
  872.   res 3,(IY+05)
  873.   ld d,18
  874.   ld e,23
  875.   ld h,101
  876.   ld l,23
  877. #fncall fline
  878. PlWLoop3:
  879.   call GET_KEY
  880.   cp K_EXIT
  881.   jp z,&ExitProgram
  882.   cp K_F1
  883.   jp z,&TeacherKey
  884.   cp K_ENTER
  885.   jp z,&Init
  886.   jp &PlWLoop3
  887. PlWLoop2:
  888.   ld hl,&WinText2
  889.   ret
  890. PlWLoop1:
  891.   ld hl,&WinText1
  892.   ret
  893.  
  894.  
  895. ;*** Subroutine to crash back to TI-OS (in case of teacher :) ) ***
  896. TeacherKey:
  897.   ld a,3
  898.   ld (USG_BITS),a
  899.   ld hl,DELC_LEN
  900.   ld (HL),0
  901.   inc hl
  902.   inc hl
  903.   ld (hl),0
  904.   set 0,(iy+3)
  905.   jp OTH_EXIT
  906.  
  907.  
  908. ;*** Subroutine to display the opening screen 1 ***
  909. OpeningScreen1:
  910.   ld hl,&TitlePic
  911.   ld de,VIDEO_MEM
  912.   ld bc,720
  913.   ldir
  914.   ld a,18
  915.   ld (CURSOR_X),a
  916.   ld a,47
  917.   ld (CURSOR_Y),a
  918.   ld hl,&OScreen1Text1
  919.   call D_ZM_STR
  920. OS1Loop1:
  921.   call GET_KEY
  922.   cp K_F1
  923.   jp z,&TeacherKey
  924.   cp 0
  925.   jp z,&OS1Loop1
  926.   ret  
  927.  
  928.  
  929. ;*** Subroutine to display the opening screen 2 ***
  930. OpeningScreen2:
  931.   ld a,18
  932.   ld (CURSOR_X),a
  933.   ld a,11
  934.   ld (CURSOR_Y),a
  935.   ld hl,&OScreen2Text1
  936.   call D_ZM_STR
  937.   jp &OS2Loop2
  938. OS2Loop1:
  939.   call GET_KEY
  940.   cp K_F1
  941.   jp z,&TeacherKey
  942.   cp 0
  943.   jp z,&OS2Loop1
  944.   call &Controls
  945.   ret
  946. OS2Loop2:
  947.   call &OS2Loop3
  948.   call D_ZM_STR
  949.   ld b,39
  950.   cp b
  951.   jp z,&OS2Loop1
  952.   jp &OS2Loop2
  953. OS2Loop3:
  954.   ld a,18
  955.   ld (CURSOR_X),a
  956.   ld a,(CURSOR_Y)
  957.   add a,7
  958.   ld (CURSOR_Y),a
  959.   ret
  960.  
  961.  
  962. ;*** Subroutine to show the controls ***
  963. Controls:
  964.   push af
  965.   push bc
  966.   ld hl,VIDEO_MEM
  967.   ld de,GRAPH_MEM
  968.   ld bc,1024
  969.   ldir
  970.   call CLEARLCD
  971.   ld a,0
  972.   ld (CURSOR_ROW),a
  973.   ld a,4
  974.   ld (CURSOR_COL),a
  975.   ld hl,&ControlsText1
  976.   call D_ZT_STR
  977.   ld a,0
  978.   ld (CURSOR_X),a
  979.   ld a,14
  980.   ld (CURSOR_Y),a
  981.   ld hl,&ControlsText2
  982.   call D_ZM_STR
  983.   jp &ConLoop2
  984. ConLoop1:
  985.   call GET_KEY
  986.   cp K_F1
  987.   jp z,&TeacherKey
  988.   cp 0
  989.   jp z,&ConLoop1
  990.   ld hl,GRAPH_MEM
  991.   ld de,VIDEO_MEM
  992.   ld bc,1024
  993.   ldir
  994.   pop af
  995.   pop bc
  996.   ret
  997. ConLoop2:
  998.   call &ConLoop3
  999.   call D_ZM_STR
  1000.   ld b,49
  1001.   cp b
  1002.   jp z,&ConLoop1
  1003.   jp &ConLoop2
  1004. ConLoop3:
  1005.   ld a,0
  1006.   ld (CURSOR_X),a
  1007.   ld a,(CURSOR_Y)
  1008.   add a,7
  1009.   ld (CURSOR_Y),a
  1010.   ret
  1011.  
  1012.  
  1013. ;*** Subroutine to exit the program ***
  1014. ExitProgram:
  1015.   call OTH_EXIT
  1016.  
  1017.  
  1018. ;*** Subroutine to Multiply B and C and store answer in D   by: Nick Blizard (nblizard@bellsouth.net) ***
  1019. Multiply:
  1020.   ld d,0
  1021.   ld a,b
  1022.   ld e,0
  1023.   cp e
  1024.   ret z
  1025.   ld a,c
  1026.   cp e
  1027.   ret z
  1028.   ld e,1
  1029.   cp e
  1030.   jp z,&Multiply3
  1031.   ld a,b
  1032.   cp e
  1033.   jp z,&Multiply4
  1034.   ld a,b
  1035. Multiply2:
  1036.   add a,b
  1037.   dec c
  1038.   ld d,a
  1039.   ld a,c
  1040.   ld e,1
  1041.   cp e
  1042.   ret z
  1043.   ld a,d
  1044.   jp &Multiply2
  1045. Multiply3:
  1046.   ld a,b
  1047.   ld d,a
  1048.   ret
  1049. Multiply4:
  1050.   ld a,c
  1051.   ld d,a
  1052.   ret
  1053.  
  1054.  
  1055. ;*** Subroutine to place the cursor at B,C ***
  1056. PlaceCursor:
  1057.   dec b
  1058.   dec c
  1059. #fncall pspr_nr
  1060.   ret
  1061.  
  1062.  
  1063. ;*** Subroutine to place a game peice at B,C ***
  1064. PlacePeice:
  1065.   dec b
  1066.   dec b
  1067.   dec c
  1068.   dec c
  1069. #fncall pspr_nr
  1070.   ret
  1071.  
  1072.  
  1073. ;*** Subroutine to put a pixel at (B,C), by: Jimmy Mardell ***
  1074. PutPixel:
  1075.   ld a,63
  1076.   sub c
  1077.   ld c,a
  1078.   ROM_CALL(FIND_PIXEL)
  1079.   ld de,$FC00
  1080.   add hl,de
  1081.   or (hl)
  1082.   ld (hl),a
  1083.   ret
  1084.  
  1085.  
  1086. ;*** Subroutine to remove a pixel at (B,C), by: Jimmy Mardell ***
  1087. RemovePixel:
  1088.   ld a,63
  1089.   sub c
  1090.   ld c,a
  1091.   ROM_CALL(FIND_PIXEL)
  1092.   ld de,$FC00
  1093.   add hl,de
  1094.   cpl
  1095.   and (hl)
  1096.   ld (hl),a
  1097.   ret
  1098.  
  1099.  
  1100. ;*** Title Picture ***
  1101. TitlePic:
  1102.         .db     $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  1103.         .db     $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  1104.         .db     $00,$00,$02,$E0,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  1105.         .db     $00,$00,$05,$F8,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  1106.         .db     $00,$00,$0B,$FE,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  1107.         .db     $00,$00,$17,$FF,$80,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  1108.         .db     $00,$00,$17,$FF,$C0,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  1109.         .db     $00,$00,$0B,$FF,$E0,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  1110.         .db     $00,$00,$05,$EF,$F0,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  1111.         .db     $00,$00,$05,$F7,$F8,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  1112.         .db     $00,$00,$02,$FB,$FC,$00,$00,$00,$00,$00,$02,$80,$00,$00,$00,$00
  1113.         .db     $00,$00,$02,$F8,$FC,$00,$00,$00,$00,$00,$05,$80,$00,$00,$00,$00
  1114.         .db     $00,$00,$05,$FA,$FE,$00,$00,$00,$00,$00,$05,$C0,$00,$00,$00,$00
  1115.         .db     $00,$00,$05,$F9,$7E,$00,$00,$00,$00,$00,$03,$C0,$00,$00,$00,$00
  1116.         .db     $00,$00,$05,$F8,$BF,$00,$00,$00,$00,$00,$0F,$C0,$00,$00,$00,$00
  1117.         .db     $00,$00,$05,$F0,$BF,$00,$00,$00,$00,$00,$7F,$E0,$00,$00,$00,$00
  1118.         .db     $00,$00,$0B,$F0,$BF,$00,$00,$00,$00,$01,$FF,$E0,$00,$00,$00,$00
  1119.         .db     $00,$00,$0B,$F0,$5F,$00,$00,$00,$00,$03,$FF,$E0,$00,$00,$00,$00
  1120.         .db     $00,$00,$0B,$E0,$5F,$05,$E0,$00,$00,$00,$0F,$81,$78,$00,$00,$00
  1121.         .db     $00,$00,$0B,$E0,$5F,$0B,$F0,$00,$00,$00,$2F,$82,$FC,$00,$00,$00
  1122.         .db     $00,$00,$0B,$E0,$5F,$17,$F0,$00,$00,$00,$5F,$85,$FC,$00,$00,$00
  1123.         .db     $00,$00,$0B,$E0,$5F,$2E,$70,$17,$C0,$00,$5F,$0B,$9C,$00,$00,$00
  1124.         .db     $00,$00,$17,$E0,$BE,$2E,$F0,$2F,$C0,$00,$BF,$0B,$BC,$00,$00,$00
  1125.         .db     $00,$00,$17,$C1,$7E,$5F,$E0,$5F,$C0,$00,$BF,$17,$F8,$00,$00,$00
  1126.         .db     $00,$00,$17,$C4,$FC,$5F,$E0,$BF,$C0,$01,$7F,$17,$F8,$00,$00,$00
  1127.         .db     $00,$00,$17,$CB,$F0,$BF,$C1,$7F,$87,$82,$FE,$2F,$F0,$00,$00,$00
  1128.         .db     $00,$00,$17,$C7,$E0,$BF,$82,$FF,$9F,$85,$FE,$2F,$E0,$00,$00,$00
  1129.         .db     $00,$00,$17,$DF,$80,$BF,$05,$FF,$3F,$CB,$FE,$2F,$C0,$00,$00,$00
  1130.         .db     $00,$00,$17,$FC,$01,$7E,$0B,$EF,$7F,$C7,$BE,$5F,$80,$00,$00,$00
  1131.         .db     $00,$00,$2F,$F0,$02,$FE,$27,$DF,$FF,$E7,$3C,$BF,$80,$00,$00,$00
  1132.         .db     $00,$00,$5F,$80,$02,$FF,$1F,$9F,$F7,$FF,$3C,$3F,$C6,$00,$00,$00
  1133.         .db     $00,$00,$07,$80,$00,$1F,$FF,$3F,$EB,$FE,$3D,$E7,$FF,$00,$00,$00
  1134.         .db     $00,$00,$17,$80,$00,$5F,$FC,$3F,$85,$F9,$7F,$E7,$FF,$00,$00,$00
  1135.         .db     $00,$00,$17,$80,$00,$5F,$F0,$BF,$05,$F1,$7F,$C7,$FC,$00,$00,$00
  1136.         .db     $00,$00,$17,$80,$00,$2F,$E1,$7E,$00,$01,$7F,$03,$F8,$00,$00,$00
  1137.         .db     $00,$00,$17,$80,$00,$00,$01,$7C,$00,$01,$7F,$00,$00,$00,$00,$00
  1138.         .db     $00,$00,$17,$C0,$00,$00,$01,$78,$00,$01,$7E,$00,$00,$00,$00,$00
  1139.         .db     $00,$00,$17,$C0,$00,$00,$00,$00,$00,$00,$BC,$00,$00,$00,$00,$00
  1140.         .db     $00,$00,$17,$80,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  1141.         .db     $00,$00,$0B,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  1142.         .db     $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  1143.         .db     $00,$00,$00,$00,$00,$03,$FF,$FF,$FF,$FF,$FE,$00,$00,$00,$00,$00
  1144.         .db     $00,$00,$00,$00,$1F,$FC,$00,$00,$00,$00,$01,$FF,$00,$00,$00,$00
  1145.         .db     $00,$00,$03,$FF,$E0,$00,$00,$00,$00,$00,$00,$00,$FE,$00,$00,$00
  1146.         .db     $00,$03,$FC,$00,$00,$00,$00,$00,$00,$00,$00,$00,$01,$C0,$00,$00
  1147.  
  1148. ;*** Text for the program ***
  1149. ;--- text for the game board ---
  1150. BoardText1:
  1151. .db "PENTE",0
  1152. BoardText2:
  1153. .db "P1",0
  1154. BoardText3:
  1155. .db "P2",0
  1156.  
  1157. ;--- text for the player's turn ---
  1158. TurnText21:
  1159. .db "1",39,"s Turn",0
  1160. TurnText1:
  1161. .db "Player",0
  1162. TurnText22:
  1163. .db "2",39,"s Turn",0
  1164.  
  1165. ;--- text for winning ---
  1166. WinText1:
  1167. .db "Player 1 Wins!",0
  1168. WinText2:
  1169. .db "Player 2 Wins!",0
  1170.  
  1171. ;--- text for opening screen 1 ---
  1172. OScreen1Text1:
  1173. .db "The  Classic  Game  of  Skill",0
  1174.  
  1175. ;--- text for opening screen 2 ---
  1176. OScreen2Text1:
  1177. .db "Pente  v1.0b",0
  1178. .db "Nick  Blizard",0
  1179. .db "NBlizard@Bellsouth.net",0
  1180. .db "B|izzard  Productions  Inc.",0
  1181. .db "(c)  Nov.  14 ,  1997",0
  1182.  
  1183. ;--- text for controls screen ---
  1184. ControlsText1:
  1185. .db "- Controls -",0
  1186. ControlsText2:
  1187. .db " Arrow  Keys  -  "
  1188. .db "Move  Cursor",0
  1189. .db " [2nd]  -  "
  1190. .db "Place  Game  Peice",0
  1191. .db " [Exit]  -  "
  1192. .db "Exit  Game",0
  1193. .db " [F1]  -  "
  1194. .db "Teacher  Key"
  1195. .db " ( no  save )",0
  1196. .db " [More]  -  "
  1197. .db "Show  Controls",0
  1198. .db " [Clear]  -  "
  1199. .db "New  Game",0
  1200.  
  1201.  
  1202. ;*** Sprites for the program ***
  1203. BoardSprite:
  1204. .db 3,3
  1205. .db %11000000
  1206. .db %11000000
  1207. .db %11000000
  1208. .db %00000000
  1209. .db %00000000
  1210. .db %00000000
  1211. .db %00000000
  1212. .db %00000000
  1213.  
  1214. CursorSprite1:
  1215. .db 3,3
  1216. .db %11100000
  1217. .db %11100000
  1218. .db %11100000
  1219. .db %00000000
  1220. .db %00000000
  1221. .db %00000000
  1222. .db %00000000
  1223. .db %00000000
  1224.  
  1225. CursorSprite2:
  1226. .db 3,3
  1227. .db %00000000
  1228. .db %00000000
  1229. .db %00000000
  1230. .db %00000000
  1231. .db %00000000
  1232. .db %00000000
  1233. .db %00000000
  1234. .db %00000000
  1235.  
  1236. FixSprite1:
  1237. .db 3,3
  1238. .db %01000000
  1239. .db %11100000
  1240. .db %01000000
  1241. .db %00000000
  1242. .db %00000000
  1243. .db %00000000
  1244. .db %00000000
  1245. .db %00000000
  1246.  
  1247. FixSprite2:
  1248. .db 5,5
  1249. .db %00100000
  1250. .db %00100000
  1251. .db %11111000
  1252. .db %00100000
  1253. .db %00100000
  1254. .db %00000000
  1255. .db %00000000
  1256. .db %00000000
  1257.  
  1258. GameSprite1:
  1259. .db 5,5
  1260. .db %01110000
  1261. .db %11111000
  1262. .db %11111000
  1263. .db %11111000
  1264. .db %01110000
  1265. .db %00000000
  1266. .db %00000000
  1267. .db %00000000
  1268.  
  1269. GameSprite2:
  1270. .db 5,5
  1271. .db %01110000
  1272. .db %10001000
  1273. .db %10001000
  1274. .db %10001000
  1275. .db %01110000
  1276. .db %00000000
  1277. .db %00000000
  1278. .db %00000000
  1279.  
  1280.  
  1281. .end
  1282.