home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 89 / asm / source / tictacto.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  28.0 KB  |  1,012 lines

  1.      include "tios.h";includes all libraries that I use
  2.      include "util.h"
  3.      include "linelib.h"
  4.      include "graphlib.h"
  5.  
  6.      xdef _main                  ;program starts at main
  7.      xdef _comment
  8.      xdef _ti89                                         ;defines what calc is used
  9.  
  10. _main:
  11.      jsr util::clr_scr                                   ;lib function which clears the screen
  12.      
  13.      move.w #2,-(a7)                                 ;set to big font
  14.      jsr tios::FontSetSys                           ;calls tios romcall which sets the desired font
  15.  
  16.      add.l #2,a7           ;fixes stack because a word(2 bytes) was pushed...if not fixed then CRASH
  17.      move.w #4,-(a7)                                 ;set to black on white
  18.      pea tic(pc)                                        ;pushes tic string onto the stac
  19.      move.w #0,-(a7)             ;y-coord
  20.      move.w #0,-(a7)        ;x-coord
  21.      jsr tios::DrawStrXY        ;calls ti romcall which displays a string (basically words)
  22.      add.l #10,a7            ;fixes stack 3 words and one longword were pushed=10
  23.  
  24.      move.w #1,-(a7)            ;small font
  25.      jsr tios::FontSetSys
  26.      add.l #2,a7
  27.  
  28.      move.w #4,-(a7)            ;black on white
  29.      pea by(pc)                ;pushes by string on stack...refer to bottom of code
  30.      move.w #12,-(a7)            ;y-coord
  31.      move.w #70,-(a7)            ;x-coord   -----------------see hello wold-----------------
  32.      jsr tios::DrawStrXY                ;calls ti rom call again
  33.      add.l #10,a7                    ;fixes stack again     
  34.  
  35.      move.w #2,-(a7)
  36.      jsr tios::FontSetSys            ;large font
  37.      add.l #2,a7
  38.  
  39.      move.w #4,-(a7)                ;black on white
  40.      pea scr(pc)                    ;pushes effective address of scr to stack
  41.      move.w #22,-(a7)                ;y-coord
  42.      move.w #25,-(a7)                ;x-coord
  43.      jsr tios::DrawStrXY                ;calls rom call again
  44.      add.l #10,a7;fixes stack
  45.      bsr title_screen_grid                ;draws grid seen at title screen
  46.      jsr util::idle_loop    ;calls idle loop which waits for a key press and stores keycode in d0
  47. Begin:            ;game jumps back here after someone wins (new game)
  48.      bsr clear_vars            ;clears all vars that may have been left by last game
  49.      jsr util::clr_scr    ;after key pressed (title screen exited) then clear the screen for the game
  50.      bsr drawgrid                ;calls sub routine which draws the grid using fline
  51. ;----program begins here----
  52.      move #1,tracker            ;x goes first
  53. ;-------------------------POSITION 1-------------------------------
  54. Pos1: ;set box to position 1
  55.      move.w #49,box_x            ; x coordinate is stored in variable box_x for later
  56.      move.w #15,box_y
  57.      move.w #51,xo_xpos            ;set x-coord.if F1 pressed then x or o will be displayed
  58.      move.w #17,xo_ypos            ;set y-coord
  59.      bsr box_sprite_setup            ;goto box_sprite_setup subroutine
  60. test1:   
  61.      jsr util::idle_loop            ;waits for keypress/stores keycode in d0
  62. test_esc1:
  63.      cmp.w #264,d0            ;264=keycode of esc...cmp subtracts 264 from d0
  64.      beq Exit    ;if d0 - 264 =0 then esc was pressed...this says if z flag is set then goto Exit label
  65. test_up:     
  66.      cmp.w #337,d0        ;337 is keycode of up...check page 530 of 89 manual
  67.      bne test_down    ;if up wasn't pressed then check for down...goto down if z flag not set
  68.      bsr box_erase_setup      ;coordinates were set earlier...got box_erase_setup and delete old box
  69.      bra Pos7            ; at subroutine "Pos7" a new box will be displayed
  70. test_down:
  71.      cmp.w #340,d0            ;340=keycode of down
  72.      bne test_right    
  73.      bsr box_erase_setup
  74.      bra Pos4
  75.  test_right:
  76.      cmp.w #344,d0            ;344=keycode of right
  77.      bne test_left
  78.      bsr box_erase_setup
  79.      bra Pos2
  80. test_left:
  81.      cmp.w #338,d0            ;338=keycode of left arrow
  82.      bne test_F1 ;if none of these keys were pressed then test all again *note*idle_loop called again
  83.      bsr box_erase_setup            ; so if left was pressed then goto pos3
  84.      bra Pos3
  85. test_F1:
  86.      cmp.w #268,d0
  87.      bne test1
  88.      move.w tracker,d4
  89.      cmp.w #2,d4                
  90.      beq store_o
  91. store_x:
  92.      cmp.b #10,x1            ;if x1 is already 10 then you can't go here again
  93.      beq test1
  94.      cmp.b #1,o1                ;if o1 is already 1 then you can't go here again
  95.      beq test1
  96.      move.b #10,x1            ;x's = 10 and o's = 1
  97.      bsr setup_xo                ; and later we can check who won
  98.      bra test1
  99. store_o:
  100.      cmp.b #1,o1                ;if o1 is already 1 then you can't go here again
  101.      beq test1
  102.      cmp.b #10,x1            ;if x1 is already 10 then you can't go here again
  103.      beq test1
  104.      move.b #1,o1            ;o's = 1 and x's = 10
  105.      bsr setup_xo
  106.      bra test1
  107. ;-----------------------------------POSITION 2------------------------------------
  108. Pos2:
  109.      move.w #71,box_x            ;set box in position2
  110.      move.w #15,box_y
  111.      move.w #73,xo_xpos            ;set x-coord.if F1 pressed then x or o will be displayed
  112.      move.w #17,xo_ypos            ;set y-coord   
  113.      bsr box_sprite_setup
  114. test2:
  115.      jsr util::idle_loop
  116. test_esc2:
  117.      cmp.w #264,d0
  118.      beq Exit
  119. test_up2:     
  120.      cmp.w #337,d0
  121.      bne test_down2
  122.      bsr box_erase_setup
  123.      bra Pos8
  124. test_down2:
  125.      cmp.w #340,d0
  126.      bne test_right2    
  127.      bsr box_erase_setup
  128.      bra Pos5
  129.  test_right2:
  130.      cmp.w #344,d0
  131.      bne test_left2
  132.      bsr box_erase_setup
  133.      bra Pos3
  134. test_left2:
  135.      cmp.w #338,d0
  136.      bne test_F12
  137.      bsr box_erase_setup
  138.      bra Pos1
  139. test_F12:
  140.      cmp.w #268,d0
  141.      bne test2
  142.      move.w tracker,d4
  143.      cmp.w #2,d4                
  144.      beq store_o2
  145. store_x2:
  146.      cmp.b #10,x2            ;if x2 is already 10 then you can't go here again
  147.      beq test2
  148.      cmp.b #1,o2                ;if o2 is already 1 then you can't go here again
  149.      beq test2
  150.      move.b #10,x2            ;x's = 10 and o's = 1
  151.      bsr setup_xo                ; and later we can check who won
  152.      bra test2
  153. store_o2:
  154.      cmp.b #1,o2                ;if o2 is already 1 then you can't go here again
  155.      beq test2
  156.      cmp.b #10,x2            ;if x2 is already 10 then you can't go here again
  157.      beq test2
  158.      move.b #1,o2            ;o's = 1 and x's = 10
  159.      bsr setup_xo
  160.      bra test2
  161. ;---------------------------------------------POSITION 3-----------------------------------------------
  162. Pos3:
  163.      move.w #93,box_x            ;set box in position1
  164.      move.w #15,box_y
  165.      move.w #95,xo_xpos            ;set x-coord.if F1 pressed then x or o will be displayed
  166.      move.w #17,xo_ypos            ;set y-coord
  167.      bsr box_sprite_setup
  168. test3:
  169.      jsr util::idle_loop
  170. test_esc3:
  171.      cmp.w #264,d0
  172.      beq Exit
  173. test_up3:     
  174.      cmp.w #337,d0
  175.      bne test_down3
  176.      bsr box_erase_setup
  177.      bra Pos9
  178. test_down3:
  179.      cmp.w #340,d0
  180.      bne test_right3    
  181.      bsr box_erase_setup
  182.      bra Pos6
  183.  test_right3:
  184.      cmp.w #344,d0
  185.      bne test_left3
  186.      bsr box_erase_setup
  187.      bra Pos1
  188. test_left3:
  189.      cmp.w #338,d0
  190.      bne test_F13
  191.      bsr box_erase_setup
  192.      bra Pos2
  193. test_F13:
  194.      cmp.w #268,d0
  195.      bne test3
  196.      move.w tracker,d4
  197.      cmp.w #2,d4                
  198.      beq store_o3
  199. store_x3:
  200.      cmp.b #10,x3            ;if x3 is already 10 then you can't go here again
  201.      beq test3
  202.      cmp.b #1,o3                ;if o3 is already 1 then you can't go here again
  203.      beq test3
  204.      move.b #10,x3            ;x's = 10 and o's = 1
  205.      bsr setup_xo                ; and later we can check who won
  206.      bra test3
  207. store_o3:
  208.      cmp.b #1,o3                ;if o3 is already 1 then you can't go here again
  209.      beq test3
  210.      cmp.b #10,x3            ;if x3 is already 10 then you can't go here again
  211.      beq test3
  212.      move.b #1,o3            ;o's = 1 and x's = 10
  213.      bsr setup_xo
  214.      bra test3
  215. ;----------------------------------------------POSITION 4---------------------------------------------------------
  216. Pos4:
  217.      move.w #49,box_x;set box in position1
  218.      move.w #37,box_y
  219.      move.w #51,xo_xpos            ;set x-coord.if F1 pressed then x or o will be displayed
  220.      move.w #39,xo_ypos            ;set y-coord
  221.      bsr box_sprite_setup
  222. test4:
  223.      jsr util::idle_loop
  224. test_esc4:
  225.      cmp.w #264,d0
  226.      beq Exit
  227. test_up4:     
  228.      cmp.w #337,d0
  229.      bne test_down4
  230.      bsr box_erase_setup
  231.      bra Pos1
  232. test_down4:
  233.      cmp.w #340,d0
  234.      bne test_right4 
  235.      bsr box_erase_setup
  236.      bra Pos7
  237.  test_right4:
  238.      cmp.w #344,d0
  239.      bne test_left4
  240.      bsr box_erase_setup
  241.      bra Pos5
  242. test_left4:
  243.      cmp.w #338,d0
  244.      bne test_F14
  245.      bsr box_erase_setup
  246.      bra Pos6
  247. test_F14:
  248.      cmp.w #268,d0
  249.      bne test4
  250.      move.w tracker,d4
  251.      cmp.w #2,d4                
  252.      beq store_o4
  253. store_x4:
  254.      cmp.b #10,x4            ;if x4 is already 10 then you can't go here again
  255.      beq test4
  256.      cmp.b #1,o4                ;if o4 is already 1 then you can't go here again
  257.      beq test4
  258.      move.b #10,x4            ;x's = 10 and o's = 1
  259.      bsr setup_xo                ; and later we can check who won
  260.      bra test4
  261. store_o4:
  262.      cmp.b #1,o4                ;if o4 is already 1 then you can't go here again
  263.      beq test4
  264.      cmp.b #10,x4            ;if x4 is already 10 then you can't go here again
  265.      beq test4
  266.      move.b #1,o4            ;o's = 1 and x's = 10
  267.      bsr setup_xo
  268.      bra test4
  269.  
  270. ;---------------------------------------POSITION 5----------------------------------------
  271. Pos5:
  272.      move.w #71,box_x;set box in position1
  273.      move.w #37,box_y
  274.      move.w #73,xo_xpos            ;set x-coord.if F1 pressed then x or o will be displayed
  275.      move.w #39,xo_ypos            ;set y-coord
  276.      bsr box_sprite_setup
  277. test5:   
  278.      jsr util::idle_loop
  279. test_esc5:
  280.      cmp.w #264,d0
  281.      beq Exit
  282. test_up5:     
  283.      cmp.w #337,d0
  284.      bne test_down5
  285.      bsr box_erase_setup
  286.      bra Pos2
  287. test_down5:
  288.      cmp.w #340,d0
  289.      bne test_right5    
  290.      bsr box_erase_setup
  291.      bra Pos8
  292.  test_right5:
  293.      cmp.w #344,d0
  294.      bne test_left5
  295.      bsr box_erase_setup
  296.      bra Pos6
  297. test_left5:
  298.      cmp.w #338,d0
  299.      bne test_F15
  300.      bsr box_erase_setup
  301.      bra Pos4
  302. test_F15:
  303.      cmp.w #268,d0
  304.      bne test5
  305.      move.w tracker,d4
  306.      cmp.w #2,d4                
  307.      beq store_o5
  308. store_x5:
  309.      cmp.b #10,x5            ;if x5 is already 10 then you can't go here again
  310.      beq test5
  311.      cmp.b #1,o5                ;if o5 is already 1 then you can't go here again
  312.      beq test5
  313.      move.b #10,x5            ;x's = 10 and o's = 1
  314.      bsr setup_xo                ; and later we can check who won
  315.      bra test5
  316. store_o5:
  317.      cmp.b #1,o5                ;if o5 is already 1 then you can't go here again
  318.      beq test5
  319.      cmp.b #10,x5            ;if x5 is already 10 then you can't go here again
  320.      beq test5
  321.      move.b #1,o5            ;o's = 1 and x's = 10
  322.      bsr setup_xo
  323.      bra test5
  324.  
  325. ;----------------------------------------POSITION 6-------------------------------------------
  326. Pos6:
  327.      move.w #93,box_x;set box in position1
  328.      move.w #37,box_y
  329.      move.w #95,xo_xpos            ;set x-coord.if F1 pressed then x or o will be displayed
  330.      move.w #39,xo_ypos            ;set y-coord
  331.      bsr box_sprite_setup
  332. test6:
  333.      jsr util::idle_loop
  334. test_esc6:
  335.      cmp.w #264,d0
  336.      beq Exit
  337. test_up6:     
  338.      cmp.w #337,d0
  339.      bne test_down6
  340.      bsr box_erase_setup
  341.      bra Pos3
  342. test_down6:
  343.      cmp.w #340,d0
  344.      bne test_right6    
  345.      bsr box_erase_setup
  346.      bra Pos9
  347.  test_right6:
  348.      cmp.w #344,d0
  349.      bne test_left6
  350.      bsr box_erase_setup
  351.      bra Pos4
  352. test_left6:
  353.      cmp.w #338,d0
  354.      bne test_F16
  355.      bsr box_erase_setup
  356.      bra Pos5
  357. test_F16:
  358.      cmp.w #268,d0
  359.      bne test6
  360.      move.w tracker,d4
  361.      cmp.w #2,d4                
  362.      beq store_o6
  363. store_x6:
  364.      cmp.b #10,x6            ;if x6 is already 10 then you can't go here again
  365.      beq test6
  366.      cmp.b #1,o6                ;if o6 is already 1 then you can't go here again
  367.      beq test6
  368.      move.b #10,x6            ;x's = 10 and o's = 1
  369.      bsr setup_xo                ; and later we can check who won
  370.      bra test6
  371. store_o6:
  372.      cmp.b #1,o6                ;if o6 is already 1 then you can't go here again
  373.      beq test6
  374.      cmp.b #10,x6            ;if x6 is already 10 then you can't go here again
  375.      beq test6
  376.      move.b #1,o6            ;o's = 1 and x's = 10
  377.      bsr setup_xo
  378.      bra test6
  379.  
  380. ;-------------------------------------POSITION 7---------------------------------------
  381. Pos7:
  382.      move.w #49,box_x;set box in position1
  383.      move.w #59,box_y
  384.      move.w #51,xo_xpos            ;set x-coord.if F1 pressed then x or o will be displayed
  385.      move.w #61,xo_ypos            ;set y-coord
  386.      bsr box_sprite_setup
  387. test7:
  388.      jsr util::idle_loop
  389. test_esc7:
  390.      cmp.w #264,d0
  391.      beq Exit
  392. test_up7:     
  393.      cmp.w #337,d0
  394.      bne test_down7
  395.      bsr box_erase_setup
  396.      bra Pos4
  397. test_down7:
  398.      cmp.w #340,d0
  399.      bne test_right7   
  400.      bsr box_erase_setup
  401.      bra Pos1
  402.  test_right7:
  403.      cmp.w #344,d0
  404.      bne test_left7
  405.      bsr box_erase_setup
  406.      bra Pos8
  407. test_left7:
  408.      cmp.w #338,d0
  409.      bne test_F17
  410.      bsr box_erase_setup
  411.      bra Pos9
  412. test_F17:
  413.      cmp.w #268,d0
  414.      bne test7
  415.      move.w tracker,d4
  416.      cmp.w #2,d4                
  417.      beq store_o7
  418. store_x7:
  419.      cmp.b #10,x7            ;if x7 is already 10 then you can't go here again
  420.      beq test7
  421.      cmp.b #1,o7                ;if o7 is already 1 then you can't go here again
  422.      beq test7
  423.      move.b #10,x7            ;x's = 10 and o's = 1
  424.      bsr setup_xo                ; and later we can check who won
  425.      bra test7
  426. store_o7:
  427.      cmp.b #1,o7                ;if o7 is already 1 then you can't go here again
  428.      beq test7
  429.      cmp.b #10,x7            ;if x7 is already 10 then you can't go here again
  430.      beq test7
  431.      move.b #1,o7            ;o's = 1 and x's = 10
  432.      bsr setup_xo
  433.      bra test7
  434.  
  435. ;---------------------------------------------POSITION 8----------------------------------------------------
  436. Pos8:
  437.      move.w #71,box_x;set box in position1
  438.      move.w #59,box_y
  439.      move.w #73,xo_xpos            ;set x-coord.if F1 pressed then x or o will be displayed
  440.      move.w #61,xo_ypos            ;set y-coord
  441.      bsr box_sprite_setup
  442. test8:
  443.      jsr util::idle_loop
  444. test_esc8:
  445.      cmp.w #264,d0
  446.      beq Exit
  447. test_up8:     
  448.      cmp.w #337,d0
  449.      bne test_down8
  450.      bsr box_erase_setup
  451.      bra Pos5
  452. test_down8:
  453.      cmp.w #340,d0
  454.      bne test_right8    
  455.      bsr box_erase_setup
  456.      bra Pos2
  457.  test_right8:
  458.      cmp.w #344,d0
  459.      bne test_left8
  460.      bsr box_erase_setup
  461.      bra Pos9
  462. test_left8:
  463.      cmp.w #338,d0
  464.      bne test_F18
  465.      bsr box_erase_setup
  466.      bra Pos7
  467. test_F18:
  468.      cmp.w #268,d0
  469.      bne test8
  470.      move.w tracker,d4
  471.      cmp.w #2,d4                
  472.      beq store_o8
  473. store_x8:
  474.      cmp.b #10,x8            ;if x8 is already 10 then you can't go here again
  475.      beq test8
  476.      cmp.b #1,o8                ;if o8 is already 1 then you can't go here again
  477.      beq test8
  478.      move.b #10,x8            ;x's = 10 and o's = 1
  479.      bsr setup_xo                ; and later we can check who won
  480.      bra test8
  481. store_o8:
  482.      cmp.b #1,o8                ;if o8 is already 1 then you can't go here again
  483.      beq test8
  484.      cmp.b #10,x8            ;if x8 is already 10 then you can't go here again
  485.      beq test8
  486.      move.b #1,o8            ;o's = 1 and x's = 10
  487.      bsr setup_xo
  488.      bra test8
  489.  
  490. ;------------------------------------------POSITION 9-------------------------------------------------
  491. Pos9:
  492.      move.w #93,box_x;set box in position1
  493.      move.w #59,box_y
  494.      move.w #95,xo_xpos            ;set x-coord.if F1 pressed then x or o will be displayed
  495.      move.w #61,xo_ypos            ;set y-coord
  496.      bsr box_sprite_setup
  497. test9:
  498.      jsr util::idle_loop
  499. test_esc9:
  500.      cmp.w #264,d0
  501.      beq Exit
  502. test_up9:     
  503.      cmp.w #337,d0
  504.      bne test_down9
  505.      bsr box_erase_setup
  506.      bra Pos6
  507. test_down9:
  508.      cmp.w #340,d0
  509.      bne test_right9    
  510.      bsr box_erase_setup
  511.      bra Pos3
  512.  test_right9:
  513.      cmp.w #344,d0
  514.      bne test_left9
  515.      bsr box_erase_setup
  516.      bra Pos7
  517. test_left9:
  518.      cmp.w #338,d0
  519.      bne test_F19
  520.      bsr box_erase_setup
  521.      bra Pos8
  522. test_F19:
  523.      cmp.w #268,d0
  524.      bne test9
  525.      move.w tracker,d4
  526.      cmp.w #2,d4                
  527.      beq store_o9
  528. store_x9:
  529.      cmp.b #10,x9            ;if x9 is already 10 then you can't go here again
  530.      beq test9
  531.      cmp.b #1,o9                ;if o9 is already 1 then you can't go here again
  532.      beq test9
  533.      move.b #10,x9            ;x's = 10 and o's = 1
  534.      bsr setup_xo                ; and later we can check who won
  535.      bra test9
  536. store_o9:
  537.      cmp.b #1,o9                ;if o9 is already 1 then you can't go here again
  538.      beq test9
  539.      cmp.b #10,x9            ;if x9 is already 10 then you can't go here again
  540.      beq test9
  541.      move.b #1,o9            ;o's = 1 and x's = 10
  542.      bsr setup_xo
  543.      bra test9
  544.  
  545. Exit:
  546.      rts                 ;returns from game to shell/home if esc was pressed
  547.  
  548.  
  549. box_sprite_setup:    
  550.      move.w box_x,d0            ;put x-coord in d0
  551.      move.w box_y,d1            ;put y-coord in d0
  552.      move.l #box_sprite,a0        ;displays box;address of box_sprite
  553.      jsr graphlib::put_sprite        ;calls put_sprite which will create the box 
  554.      rts
  555.  
  556. box_erase_setup:
  557.      move.w box_x,d0  ;put the x-coordinate in do because that is how you use the putsprite routine
  558.      move.w box_y,d1              ;y-coordinate in d1
  559.      move.l #box_sprite_erase,a0      ;erases box;address of box_sprite_erase
  560.      jsr graphlib::put_sprite  ;calls putsprite which will ultimately delete the old box when moved
  561.      rts                      ;returns from subroutine
  562.  
  563. setup_xo:
  564.      move.w xo_xpos,d0
  565.      move.w xo_ypos,d1
  566.      move.w tracker,d3
  567.      cmp.w #2,d3
  568.      beq setup_o                ;if keeptrack = 2 then goto setup_o
  569. setup_x:
  570.      move.l #x_sprite,a0
  571.      jsr graphlib::put_sprite        ;display x in desired location
  572.      move.w #2,tracker        ;next time o will be displayed
  573.      bsr check_win
  574.      rts
  575. setup_o:
  576.      move.l #o_sprite,a0
  577.      jsr graphlib::put_sprite        ;display o in desired location
  578.      move.w #1,tracker        ;next time x will be displayed
  579.      bsr check_win
  580.      rts
  581.      
  582. check_win:
  583. ;---------check if  3 x's in row one----------
  584.      move.b x1,d5
  585.      add.b x2,d5
  586.      add.b x3,d5
  587.      cmp.b #30,d5
  588.      beq xwin
  589. ;--------check if 3 x's in row two-------------
  590.      move.b x4,d5
  591.      add.b x5,d5
  592.      add.b x6,d5
  593.      cmp.b #30,d5
  594.      beq xwin
  595. ;---------check if 3 x's in row three---------
  596.      move.b x7,d5
  597.      add.b x8,d5
  598.      add.b x9,d5
  599.      cmp.b #30,d5
  600.      beq xwin
  601. ;-----------check if 3 x's in column one--------
  602.      move.b x1,d5
  603.      add.b x4,d5
  604.      add.b x7,d5
  605.      cmp.b #30,d5
  606.      beq xwin
  607. ;---------check if 3 x's in column two----------
  608.      move.b x2,d5
  609.      add.b x5,d5
  610.      add.b x8,d5
  611.      cmp.b #30,d5
  612.      beq xwin
  613. ;---------check if 3 x's in column three----------
  614.      move.b x3,d5
  615.      add.b x6,d5
  616.      add.b x9,d5
  617.      cmp.b #30,d5
  618.      beq xwin
  619. ;----------check if 3 x's are diagonal (pos1 through pos9)--------
  620.      move.b x1,d5
  621.      add.b x5,d5
  622.      add.b x9,d5
  623.      cmp.b #30,d5
  624.      beq xwin
  625. ;---------------check if 3 x's are diagonal (pos7 through pos3)----------
  626.      move.b x7,d5
  627.      add.b x5,d5
  628.      add.b x3,d5
  629.      cmp.b #30,d5
  630.      beq xwin
  631. ;---------check if  3 o's in row one----------
  632.      move.b o1,d5
  633.      add.b o2,d5
  634.      add.b o3,d5
  635.      cmp.b #3,d5
  636.      beq owin
  637. ;--------check if 3 o's in row two-------------
  638.      move.b o4,d5
  639.      add.b o5,d5
  640.      add.b o6,d5
  641.      cmp.b #3,d5
  642.      beq owin
  643. ;---------check if 3 o's in row three---------
  644.      move.b o7,d5
  645.      add.b o8,d5
  646.      add.b o9,d5
  647.      cmp.b #3,d5
  648.      beq owin
  649. ;-----------check if 3 o's in column one--------
  650.      move.b o1,d5
  651.      add.b o4,d5
  652.      add.b o7,d5
  653.      cmp.b #3,d5
  654.      beq owin
  655. ;---------check if 3 o's in column two----------
  656.      move.b o2,d5
  657.      add.b o5,d5
  658.      add.b o8,d5
  659.      cmp.b #3,d5
  660.      beq owin
  661. ;---------check if 3 o's in column three----------
  662.      move.b o3,d5
  663.      add.b o6,d5
  664.      add.b o9,d5
  665.      cmp.b #3,d5
  666.      beq owin
  667. ;----------check if 3 o's are diagonal (pos1 through pos9)--------
  668.      move.b o1,d5
  669.      add.b o5,d5
  670.      add.b o9,d5
  671.      cmp.b #3,d5
  672.      beq owin
  673. ;---------------check if 3 o's are diagonal (pos7 through pos3)----------
  674.      move.b o7,d5
  675.      add.b o5,d5
  676.      add.b o3,d5
  677.      cmp.b #3,d5
  678.      beq owin
  679.      add.b #1,tie
  680.      cmp.b #9,tie    ;if noone won goto its_a_tie
  681.      beq its_a_tie
  682.      rts
  683.      
  684. xwin:     
  685.      move.w #4,-(a7)
  686.      pea xwins(pc)
  687.      move.w #42,-(a7)
  688.      move.w #56,-(a7)
  689.      jsr tios::DrawStrXY
  690.      add.l #10,a7
  691.      jsr util::idle_loop
  692.      bra Begin                ;after someone wins start new game
  693.  
  694. owin:     
  695.      move.w #4,-(a7)
  696.      pea owins(pc)
  697.      move.w #42,-(a7)
  698.      move.w #56,-(a7)
  699.      jsr tios::DrawStrXY
  700.      add.l #10,a7
  701.      jsr util::idle_loop
  702.      bra Begin                ;after someone wins start new game
  703.  
  704. its_a_tie:
  705.      move.w #4,-(a7)
  706.      pea itsatie(pc)
  707.      move.w #42,-(a7)
  708.      move.w #40,-(a7)
  709.      jsr tios::DrawStrXY
  710.      add.l #10,a7
  711.      jsr util::idle_loop
  712.      bra Begin                ;after someone wins start new game
  713.  
  714.      
  715.  
  716. clear_vars:
  717.      clr.b x1
  718.      clr.b x2
  719.      clr.b x3
  720.      clr.b x4
  721.      clr.b x5
  722.      clr.b x6
  723.      clr.b x7
  724.      clr.b x8
  725.      clr.b x9
  726.      clr.b o1
  727.      clr.b o2
  728.      clr.b o3
  729.      clr.b o4
  730.      clr.b o5
  731.      clr.b o6
  732.      clr.b o7
  733.      clr.b o8
  734.      clr.b o9
  735.      clr.b tie
  736.      rts
  737.  
  738. drawgrid:      ;the draw grid routine draws 4 lines (the grid) using fline in the line library
  739.      move.l #LCD_MEM,a0        ;line 1
  740.      move.w #47,d0            ;x1
  741.      move.w #57,d1            ;y1
  742.      move.w #113,d2            ;x2
  743.      move.w #57,d3            ;y2
  744.      jsr linelib::fline            ;calls library function
  745.  
  746.      move.l #LCD_MEM,a0;line 2
  747.      move.w #47,d0
  748.      move.w #35,d1
  749.      move.w #113,d2
  750.      move.w #35,d3
  751.      jsr linelib::fline
  752.  
  753.      move.l #LCD_MEM,a0;line 3
  754.      move.w #69,d0
  755.      move.w #79,d1
  756.      move.w #69,d2
  757.      move.w #13,d3
  758.      jsr linelib::fline
  759.  
  760.      move.l #LCD_MEM,a0;line 4
  761.      move.w #91,d0
  762.      move.w #79,d1
  763.      move.w #91,d2
  764.      move.w #13,d3
  765.      jsr linelib::fline
  766.      rts;returns from subroutine
  767.  
  768.  
  769. title_screen_grid:             ;draws the grid you see during the title screen
  770.      move.l #LCD_MEM,a0        ;line 1
  771.      move.w #75,d0            ;x1
  772.      move.w #35,d1            ;y1
  773.      move.w #65,d2            ;x2
  774.      move.w #90,d3            ;y2
  775.      jsr linelib::fline            ;calls library function
  776.  
  777.      move.l #LCD_MEM,a0;line 2
  778.      move.w #95,d0
  779.      move.w #35,d1;down
  780.      move.w #85,d2
  781.      move.w #90,d3
  782.      jsr linelib::fline
  783.  
  784.      move.l #LCD_MEM,a0;line 3
  785.      move.w #45,d0
  786.      move.w #60,d1
  787.      move.w #120,d2
  788.      move.w #45,d3
  789.      jsr linelib::fline
  790.  
  791.      move.l #LCD_MEM,a0;line 4
  792.      move.w #45,d0
  793.      move.w #80,d1
  794.      move.w #120,d2
  795.      move.w #65,d3
  796.      jsr linelib::fline
  797.  
  798.      rts;return
  799.  
  800.  
  801.  
  802. box_sprite:
  803.      dc.w 19;height of box_sprite
  804.      dc.w 3;width
  805.      dc.b %11111111,%11111111,%11100000    ;1
  806.      dc.b %10000000,%00000000,%00100000    ;this is the box that is moved around
  807.      dc.b %10000000,%00000000,%00100000
  808.      dc.b %10000000,%00000000,%00100000
  809.      dc.b %10000000,%00000000,%00100000
  810.      dc.b %10000000,%00000000,%00100000
  811.      dc.b %10000000,%00000000,%00100000
  812.      dc.b %10000000,%00000000,%00100000
  813.      dc.b %10000000,%00000000,%00100000
  814.      dc.b %10000000,%00000000,%00100000    ;10
  815.      dc.b %10000000,%00000000,%00100000
  816.      dc.b %10000000,%00000000,%00100000
  817.      dc.b %10000000,%00000000,%00100000
  818.      dc.b %10000000,%00000000,%00100000
  819.      dc.b %10000000,%00000000,%00100000
  820.      dc.b %10000000,%00000000,%00100000
  821.      dc.b %10000000,%00000000,%00100000
  822.      dc.b %10000000,%00000000,%00100000
  823.      dc.b %11111111,%11111111,%11100000    ;19
  824.  
  825. mask:
  826.      dc.b %00000000,%00000000,%00000000    ;mask of box_sprite
  827.      dc.b %00000000,%00000000,%00000000    ;all 0's lets the box be transparent
  828.      dc.b %00000000,%00000000,%00000000    ;  so the x's and o's will not be erased
  829.      dc.b %00000000,%00000000,%00000000
  830.      dc.b %00000000,%00000000,%00000000
  831.      dc.b %00000000,%00000000,%00000000
  832.      dc.b %00000000,%00000000,%00000000
  833.      dc.b %00000000,%00000000,%00000000
  834.      dc.b %00000000,%00000000,%00000000
  835.      dc.b %00000000,%00000000,%00000000    ;10
  836.      dc.b %00000000,%00000000,%00000000
  837.      dc.b %00000000,%00000000,%00000000
  838.      dc.b %00000000,%00000000,%00000000
  839.      dc.b %00000000,%00000000,%00000000
  840.      dc.b %00000000,%00000000,%00000000
  841.      dc.b %00000000,%00000000,%00000000
  842.      dc.b %00000000,%00000000,%00000000
  843.      dc.b %00000000,%00000000,%00000000
  844.      dc.b %00000000,%00000000,%00000000    ;19
  845.  
  846. box_sprite_erase:
  847.      dc.w 19                        ;height
  848.      dc.w 3                        ;width
  849.      dc.b %00000000,%00000000,%00000000;1
  850.      dc.b %00000000,%00000000,%00000000
  851.      dc.b %00000000,%00000000,%00000000
  852.      dc.b %00000000,%00000000,%00000000        ;all 0's to erase the box
  853.      dc.b %00000000,%00000000,%00000000
  854.      dc.b %00000000,%00000000,%00000000
  855.      dc.b %00000000,%00000000,%00000000
  856.      dc.b %00000000,%00000000,%00000000
  857.      dc.b %00000000,%00000000,%00000000
  858.      dc.b %00000000,%00000000,%00000000        ;10
  859.      dc.b %00000000,%00000000,%00000000
  860.      dc.b %00000000,%00000000,%00000000
  861.      dc.b %00000000,%00000000,%00000000
  862.      dc.b %00000000,%00000000,%00000000
  863.      dc.b %00000000,%00000000,%00000000
  864.      dc.b %00000000,%00000000,%00000000
  865.      dc.b %00000000,%00000000,%00000000
  866.      dc.b %00000000,%00000000,%00000000        ;18
  867.      dc.b %00000000,%00000000,%00000000
  868.  
  869. mask2:
  870.      dc.b %11111111,%11111111,%11100000    ;mask of the box_erase_sprite
  871.      dc.b %10000000,%00000000,%00100000    ;the 1's will delete the black lines of the box
  872.      dc.b %10000000,%00000000,%00100000
  873.      dc.b %10000000,%00000000,%00100000
  874.      dc.b %10000000,%00000000,%00100000
  875.      dc.b %10000000,%00000000,%00100000
  876.      dc.b %10000000,%00000000,%00100000
  877.      dc.b %10000000,%00000000,%00100000
  878.      dc.b %10000000,%00000000,%00100000
  879.      dc.b %10000000,%00000000,%00100000    ;10
  880.      dc.b %10000000,%00000000,%00100000
  881.      dc.b %10000000,%00000000,%00100000
  882.      dc.b %10000000,%00000000,%00100000
  883.      dc.b %10000000,%00000000,%00100000
  884.      dc.b %10000000,%00000000,%00100000
  885.      dc.b %10000000,%00000000,%00100000
  886.      dc.b %10000000,%00000000,%00100000
  887.      dc.b %10000000,%00000000,%00100000
  888.      dc.b %11111111,%11111111,%11100000    ;19
  889.  
  890. x_sprite:
  891.      dc.w 15
  892.      dc.w 2
  893.      dc.b %10000000,%00000010;1
  894.      dc.b %01000000,%00000100
  895.      dc.b %00100000,%00001000
  896.      dc.b %00010000,%00010000
  897.      dc.b %00001000,%00100000
  898.      dc.b %00000100,%01000000
  899.      dc.b %00000010,%10000000
  900.      dc.b %00000001,%00000000
  901.      dc.b %00000010,%10000000
  902.      dc.b %00000100,%01000000;10
  903.      dc.b %00001000,%00100000
  904.      dc.b %00010000,%00010000
  905.      dc.b %00100000,%00001000
  906.      dc.b %01000000,%00000100
  907.      dc.b %10000000,%00000010;15
  908. mask3:
  909.      dc.b 0,0;1
  910.      dc.b 0,0
  911.      dc.b 0,0
  912.      dc.b 0,0
  913.      dc.b 0,0
  914.      dc.b 0,0
  915.      dc.b 0,0
  916.      dc.b 0,0
  917.      dc.b 0,0
  918.      dc.b 0,0;10
  919.      dc.b 0,0
  920.      dc.b 0,0
  921.      dc.b 0,0
  922.      dc.b 0,0
  923.      dc.b 0,0;15
  924.  
  925. o_sprite:
  926.      dc.w 15
  927.      dc.w 2
  928.      dc.b %00000111,%11000000;1
  929.      dc.b %00011000,%00110000
  930.      dc.b %00100000,%00001000
  931.      dc.b %01000000,%00000100
  932.      dc.b %01000000,%00000100
  933.      dc.b %10000000,%00000010
  934.      dc.b %10000000,%00000010
  935.      dc.b %10000000,%00000010
  936.      dc.b %10000000,%00000010
  937.      dc.b %10000000,%00000010;10
  938.      dc.b %01000000,%00000100
  939.      dc.b %01000000,%00000100
  940.      dc.b %00100000,%00001000
  941.      dc.b %00011000,%00110000
  942.      dc.b %00000111,%11000000;15
  943. mask4:
  944.      dc.b 0,0;1
  945.      dc.b 0,0
  946.      dc.b 0,0
  947.      dc.b 0,0
  948.      dc.b 0,0
  949.      dc.b 0,0
  950.      dc.b 0,0
  951.      dc.b 0,0
  952.      dc.b 0,0
  953.      dc.b 0,0;10
  954.      dc.b 0,0
  955.      dc.b 0,0
  956.      dc.b 0,0
  957.      dc.b 0,0
  958.      dc.b 0,0;15
  959.  
  960. ;----------------------------------KEEP TRACK OF POSITIONS BEING USED--------------------------
  961. x1 dc.b 0        ;keep track if x was put in position 1
  962. x2 dc.b 0        ;keep track if x was put in position 2
  963. x3 dc.b 0
  964. x4 dc.b 0
  965. x5 dc.b 0
  966. x6 dc.b 0
  967. x7 dc.b 0
  968. x8 dc.b 0
  969. x9 dc.b 0
  970. o1 dc.b 0        ;keep track if o was put in position 1
  971. o2 dc.b 0        ;keep track if o was put in positon 2
  972. o3 dc.b 0
  973. o4 dc.b 0
  974. o5 dc.b 0
  975. o6 dc.b 0
  976. o7 dc.b 0
  977. o8 dc.b 0
  978. o9 dc.b 0
  979.  
  980. tie dc.b 0        ;if tie=9 nobody wins
  981.  
  982.  
  983.  
  984. ;-----------------------------------------------------COORDINATES---------------------------------------------
  985. xo_xpos dc.w 0                    ;x-coordinate of the x's and o's
  986. xo_ypos dc.w 0                    ;y-coordinate of teh x's and o's
  987.  
  988. box_x dc.w 0                    ;x-coordinate of box displayed
  989. box_y dc.w 0                    ;y-coordinate of box displayed
  990.  
  991. tracker dc.w 0                ;keeps track of who's turn...
  992.  
  993. itsatie:
  994.      dc.b "Nobody Wins",0        ;if noone wins print "nobody wins"
  995. xwins:
  996.      dc.b "X Wins",0
  997. owins:
  998.      dc.b "O Wins",0
  999. tic:    
  1000.      dc.b "T i c  T a c  T o e",0            ;words displayed at title screen
  1001. by:
  1002.      dc.b "By:",0
  1003. scr:
  1004.      dc.b "Steven Reagan",0            ;me the author
  1005. _comment:
  1006.      dc.b "Tic Tac Toe by: S43R80@aol.com",0    ;description of the program
  1007.  
  1008.      end
  1009.  
  1010.  
  1011.  
  1012.