TIC TAC TOE
THE PROGRAM
 Page 3

Go to:   P1    P2    P4

Here is the program for TIC TAC TOE. Take it slowly and concentrate on one sub-routine at a time.
The layout of the program is as follows:
SetUp - sets up the ports, disables the comparators and clears the files.
Tables - tables of values for the attract mode
Att - Attract Mode. Produces the patterns on the display when the project is first turned on.
Raster -  Puts anything on the 3x3 display - depending on the values you provide in a Table. 3-values are needed to produce a "cell."  In our case, Raster produces a "dot" moving around the display and uses Table 4.

The .asm and .hex files for Tic Tac Toe

                  ;TicTacToe.asm
                  ;Project: TIC TAC TOE
                  ; use internal 4MHz oscillator
LIST P=16F628 ;f=inhx8m
#include "P16F628.inc"
__CONFIG _CP_OFF &_BODEN_OFF &_PWRTE_OFF &_WDT_OFF &_LVP_OFF &_MCLRE_OFF &_INTRC_OSC_NOCLKOUT

SetUp











Table1





























Table2










Table3




















Table4




















































Table5























Att

Att1



Att2















Att3















Att4

















Att5


Att6




Att7






Att8












Att9


Att10




Att11






Att12

























Raster

Rast1

Rast2





































ButtonA


















ButAA

ButA1








ButA3







ButA4
ButA5






ButA6









ButtonB




ButB1







ButB2




ButB3






Del1




Del2




















PWin





PWin1





PWin2





PWin3





PWin4





PWin5





PWin6





PWin7





PWin8



PWin21










CWin

CWin1


CWin2












CWin3





CWin4










CWin5







Stop

Stop1


Stop2


Stop2A










Stop3

Stop4





Stop5







Stop6








Corner



Corner1



















Center













Fork





ForkA



ForkB


















Divide







































Look4

Look4A


Look4B










Look4L
Look4C







Look4G








Look4H







Random

Random1

















Stale





Stale1


















Preload






















Main

MainA



MainB



MainC


Main1


Main2


Main3


Main4


Main5


Main6








Main7


Main8


Main9


Main10


Main11


Main12








Main13


Main14


Main15


Main16


Main17


Main18



















Main19







Main20






Main21



Main22





 
ORG 0
MOVLW 07
MOVWF 1Fh
BSF 03,5
CLRF 06
MOVLW 18h
MOVWF 05
BCF 03,5
CLRF 2F
CLRF 05
CLRF 06
GOTO Att

ADDWF 02,1
RETLW 31h
RETLW 32h
RETLW 33h
RETLW 34h
RETLW 35h
RETLW 36h
RETLW 37h
RETLW 38h
RETLW 39h
RETLW 31h
RETLW 34h
RETLW 37h
RETLW 32h
RETLW 35h
RETLW 38h
RETLW 33h
RETLW 36h
RETLW 39h
RETLW 31h
RETLW 35h
RETLW 39h
RETLW 37h
RETLW 35h
RETLW 33h
RETLW 31h
RETLW 32h
RETLW 33h
RETLW 0FFh

ADDWF 02,1
RETLW 31h
RETLW 31h
RETLW 33h
RETLW 37h
RETLW 39h
RETLW 31h
RETLW 33h
RETLW 37h
RETLW 39h

ADDWF 02,1
RETLW 32h
RETLW 32h
RETLW 34h
RETLW 36h
RETLW 38h
RETLW 32h
RETLW 34h
RETLW 36h
RETLW 38h
RETLW 32h
RETLW 32h
RETLW 34h
RETLW 36h
RETLW 38h
RETLW 32h
RETLW 34h
RETLW 36h
RETLW 38h


ADDWF 02,1
RETLW 20h
RETLW 00h
RETLW 00h
RETLW 08h
RETLW 00h
RETLW 00h
RETLW 02h
RETLW 00h
RETLW 00h
RETLW 00h
RETLW 02h
RETLW 00h
RETLW 00h
RETLW 00h
RETLW 02h
RETLW 00h
RETLW 00h
RETLW 08h
RETLW 00h
RETLW 00h
RETLW 20h
RETLW 00h
RETLW 20h
RETLW 00h
RETLW 25h
RETLW 15h
RETLW 15h
RETLW 19h
RETLW 15h
RETLW 15h
RETLW 16h
RETLW 15h
RETLW 15h
RETLW 15h
RETLW 16h
RETLW 15h
RETLW 15h
RETLW 15h
RETLW 16h
RETLW 15h
RETLW 15h
RETLW 19h
RETLW 15h
RETLW 15h
RETLW 25h
RETLW 15h
RETLW 25h
RETLW 15h
RETLW 0FFh
RETLW 0FFh


ADDWF 02,1
RETLW 31h
RETLW 33h
RETLW 37h
RETLW 39h
RETLW 31h
RETLW 33h
RETLW 37h
RETLW 39h
RETLW 31h
RETLW 32h
RETLW 33h
RETLW 34h
RETLW 36h
RETLW 37h
RETLW 38h
RETLW 39h
RETLW 0FFh






MOVLW 10h
MOVWF 22h
MOVLW 15
MOVWF 06
MOVLW 20h
MOVWF 23h
BSF 05,0
CALL Del2
BCF 05,0
BSF 05,2
CALL Del2
BCF 05,2
BSF 05,1
CALL Del2
BCF 05,1
DECFSZ 23h,1
GOTO Att2

MOVLW 0FFh
MOVWF 06
MOVLW 20h
MOVWF 23h
BSF 05,0
CALL Del2
BCF 05,0
BSF 05,2
CALL Del2
BCF 05,2
BSF 05,1
CALL Del2
BCF 05,1
DECFSZ 23h,1
GOTO Att3

MOVLW 2A
MOVWF 06
MOVLW 20h
MOVWF 23h
BSF 05,0
CALL Del2
BCF 05,0
BSF 05,2
CALL Del2
BCF 05,2
BSF 05,1
CALL Del2
BCF 05,1
DECFSZ 23h,1
GOTO Att4
DECFSZ 22h,1
GOTO Att1

MOVLW 04
MOVWF 22h
CLRF 20h
CLRF 21h
INCF 21h,1
MOVLW 08h
MOVWF 27h
MOVLW 04
MOVWF 06
BSF 05,2
MOVF 20h,0
MOVWF 25h
DECFSZ 25h,1
GOTO Att7
MOVLW 08
MOVWF 06
BSF 05,2
MOVF 21h,0
MOVWF 26h
DECFSZ 26h,1
GOTO Att8
DECFSZ 27h
GOTO Att6
BTFSS 05,3
GOTO Preload
BTFSS 05,4
GOTO Preload
DECFSZ 20h,1
GOTO Att5

CLRF 20h
CLRF 21h
INCF 20h,1
MOVLW 08h
MOVWF 27h
MOVLW 04
MOVWF 06
BSF 05,2
MOVF 20h,0
MOVWF 25h
DECFSZ 25h,1
GOTO Att11
MOVLW 08
MOVWF 06
BSF 05,2
MOVF 21h,0
MOVWF 26h
DECFSZ 26h,1
GOTO Att12
DECFSZ 27h
GOTO Att10
BTFSS 05,3
GOTO Preload
BTFSS 05,4
GOTO Preload
DECFSZ 21h,1
GOTO Att9
DECFSZ 22h
GOTO Att5
GOTO Raster













CLRF 22h
CLRF 05
MOVLW 0Ch
MOVWF 26h
MOVF 22h,0
CALL Table4
XORLW 0FFh
BTFSC 03,2
GOTO Raster
MOVF 22h,0
CALL Table4 XORLW
MOVWF 06
BSF 05,0
CALL Del2
BCF 05,0
INCF 22h,1
MOVF 22h,0
CALL Table4
MOVWF 06
BSF 05,2
CALL Del2
BCF 05,2
INCF 22h,1
MOVF 22h,0
CALL Table4
MOVWF 06
BSF 05,1
CALL Del2
BCF 05,1
DECF 22h,1
DECF 22h,1
DECFSZ 26h,1
GOTO Rast2
INCF 22h,1
INCF 22h,1
INCF 22h,1
GOTO Rast1




BSF 2F,0
BTFSS 2F,3
GOTO ButAA
BCF 2F,3
BCF 05,6
BCF 05,7
MOVLW 05
MOVWF 30h
CLRF 31h
CLRF 32h
CLRF 33h
CLRF 34h
CLRF 35h
CLRF 36h
CLRF 37h
CLRF 38h
CLRF 39h
CLRF 3Ah
RETURN
MOVLW 30h
MOVWF 04
BTFSC 00,3
GOTO ButA3
BTFSS 00,0
GOTO ButA2
BTFSS 00,2
GOTO ButA2
GOTO ButA3
ButA2 INCF 04
GOTO ButA1
MOVLW 3Ah
XORWF 04,0
BTFSS 03,2
GOTO ButA4
CLRF 3Ah
MOVLW 05
MOVWF 30h
RETURN
CLRF 00
INCF 04,1
MOVLW 3A
XORWF 04,0
BTFSS 03,2
GOTO ButA6
MOVLW 30h
MOVWF 04
MOVLW 00
XORWF 00,0
BTFSS 03,2
GOTO ButA5
MOVLW 05
MOVWF 00
RETURN



BSF 2F,1
MOVLW 09
MOVWF 23h
MOVLW 31h
MOVWF 04
MOVLW 05
XORWF 00,0
BTFSC 03,2
GOTO ButB2
MOVLW 08
XORWF 00,0
BTFSS 03,2
GOTO ButB3
MOVLW 01
MOVWF 00
MOVLW 05
MOVWF 30h
GOTO PWin
INCF 04,1
DECFSZ 23h
GOTO ButB1
GOTO PWin



NOP
DECFSZ 20h,1
GOTO Del1
RETURN

NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ 20h,1
GOTO Del2
BTFSS 05,3
GOTO Preload
BTFSS 05,4
GOTO Preload
RETURN






BTFSS 31h,0
GOTO PWin1
BTFSS 32h,0
GOTO PWin1
BTFSC 33h,0
GOTO PWin21
BTFSS 34h,0
GOTO PWin2
BTFSS 35h,0
GOTO PWin2
BTFSC 36h,0
GOTO PWin21
BTFSS 37h,0
GOTO PWin3
BTFSS 38h,0
GOTO PWin3
BTFSC 39h,0
GOTO PWin21
BTFSS 31h,0
GOTO PWin4
BTFSS 34h,0
GOTO PWin4
BTFSC 37h,0
GOTO PWin21
BTFSS 32h,0
GOTO PWin5
BTFSS 35h,0
GOTO PWin5
BTFSC 38h,0
GOTO PWin21
BTFSS 33h,0
GOTO PWin6
BTFSS 36h,0
GOTO PWin6
BTFSC 39h,0
GOTO PWin21
BTFSS 31h,0
GOTO PWin7
BTFSS 35h,0
GOTO PWin7
BTFSC 39h,0
GOTO PWin21
BTFSS 33h,0
GOTO PWin8
BTFSS 35h,0
GOTO PWin8
BTFSC 37h,0
GOTO PWin21
CALL Stale
BTFSS 2F,3
GOTO CWin
RETURN
BSF 05,6
BSF 2F,3
RETURN








MOVLW 0FFh
MOVWF 25h
CLRF 27h
MOVLW 03
MOVWF 26h
INCF 25h,1
MOVF 25h,0
CALL Table1
XORLW 0FFh
BTFSC 03,2
GOTO Stop
MOVF 25h,0
CALL Table1
MOVWF 04
BTFSC 00,0
DECF 27h,1
BTFSC 00,2
INCF 27h,1
DECFSZ 26h,1
GOTO CWin2
MOVLW 02
XORWF 27h,0
BTFSS 03,2
GOTO CWin1
MOVF 25h,0
CALL Table1
MOVWF 04
MOVF 00,1
BTFSS 03,2
GOTO CWin5
MOVLW 04
MOVWF 00
BSF 05,7
BSF 2F,3
RETURN
DECF 25h,1
GOTO CWin4






MOVLW 0FFh
MOVWF 25h
CLRF 27h
MOVLW 04
MOVWF 26h
DECFSZ 26h,1
GOTO Stop2A
GOTO Stop4
INCF 25h,1
MOVF 25h,0
CALL Table1
MOVWF 04
BTFSC 00,7
GOTO Corner
BTFSC 00,2
GOTO Stop3
BTFSC 00,0
INCF 27h,1
GOTO Stop2
BSF 27h,7
GOTO Stop2
BTFSC 27h,7
GOTO Stop1
BTFSS 27h,1
GOTO Stop1
DECF 25h,1
DECF 25h,1
MOVF 25h,0
CALL Table1
MOVWF 04
BTFSC 00,0
GOTO Stop6
MOVLW 04
MOVWF 00
RETURN
INCF 25h,1
GOTO Stop5







MOVLW 09
MOVWF 25h
MOVLW 30h
MOVWF 04
INCF 04,1
MOVLW 00
XORWF 00,0
BTFSS 03,2
GOTO Center
DECFSZ 25h,1
GOTO Corner1
MOVLW 07
ANDWF 28h,1 
INCF 28h,1
MOVF 28h,0
CALL Table2
MOVWF 04
MOVLW 04
MOVWF 00
RETURN




MOVF 35h,1
BTFSS 03,2
GOTO Fork
MOVLW 04
MOVWF 35h
RETURN








BTFSS 35h,2
GOTO Look4
BTFSS 31h,0
GOTO ForkA
BTFSC 39h,0
GOTO ForkB
BTFSS 33h,0
GOTO Divide
BTFSS 37h,0
GOTO Divide
MOVLW 07
ANDWF 28h,1
INCF 28h,1
MOVF 28h,0
CALL Table3
MOVWF 04
MOVF 00,1
BTFSS 03,2
GOTO ForkB
MOVLW 04
MOVWF 00
RETURN







BTFSC 31h,0
GOTO Look4
BTFSC 31h,2
GOTO Look4
BTFSC 32h,0
GOTO Look4
BTFSC 32h,2
GOTO Look4
BTFSC 33h,0
GOTO Look4
BTFSC 33h,2
GOTO Look4
BTFSC 34h,0
GOTO Look4
BTFSC 34h,2
GOTO Look4
BTFSS 35h,2
GOTO Look4
BTFSS 36h,0
GOTO Look4
BTFSC 37h,0
GOTO Look4
BTFSC 37h,2
GOTO Look4
BTFSS 38h,0
GOTO Look4
BTFSC 39h,0
GOTO Look4
BTFSC 39h,2
GOTO Look4
MOVLW 04
MOVWF 39h
RETURN







MOVLW 0FFh
MOVWF 25h
CLRF 27h
MOVLW 03
MOVWF 26h
INCF 25h,1
MOVF 25h,0
CALL Table1
MOVWF 04
BTFSC 00,7
GOTO Random
BTFSC 00,2
GOTO Look4L
BTFSS 00,0
GOTO Look4C
INCF 27h,1
INCF 27h,1
DECFSZ 26h,1
GOTO Look4B
MOVLW 01
XORWF 27h,1
BTFSS 03,2
GOTO Look4A
DECF 25h,1
DECF 25h,1
MOVF 25h,0
CALL Table1
MOVWF 04
MOVF 00,1
BTFSS 03,2
GOTO Look4H
MOVLW 04
MOVWF 00
RETURN
INCF 25h,1
INCF 25h,1
GOTO Look4G





MOVLW 03
ANDWF 28h,1
INCF 28h,1
MOVF 28h,0
CALL Table5
MOVWF 04
BTFSC 00,7
RETURN
MOVF 00,1
BTFSS 03,2
GOTO Random1
MOVLW 04
MOVWF 00
RETURN






BTFSC 05,6
RETURN
MOVLW 09
MOVWF 25h
MOVLW 31h
MOVWF 04
MOVLW 05
XORWF 00,0
BTFSC 03,2
RETURN
BTFSC 00,3
RETURN

MOVLW 00
XORWF 00,0
BTFSC 03,2
RETURN
INCF 04,1
DECFSZ 25h,1
GOTO Stale1
BSF 05,6
BSF 05,7
BSF 2F,3
RETURN


MOVLW 05
MOVWF 30h
CLRF 31h
CLRF 32h
CLRF 33h
CLRF 34h
CLRF 35h
CLRF 36h
CLRF 37h
CLRF 38h
CLRF 39h
CLRF 3Ah
BTFSS 05,3
GOTO Preload
BTFSS 05,4
GOTO Preload
GOTO Main






MOVLW 20h
MOVWF 22h
BTFSC 2F,0
GOTO MainB
BTFSS 05,3
CALL ButtonA
BTFSC 2F,1
GOTO MainC
BTFSS 05,4
CALL ButtonB
BTFSS 31h,0
GOTO Main1
BSF 06,5
BTFSS 31h,2
GOTO Main2
BSF 06,4
BTFSS 32h,0
GOTO Main3
BSF 06,3
BTFSS 32h,2
GOTO Main4
BSF 06,2
BTFSS 33h,0
GOTO Main5
BSF 06,1
BTFSS 33h,2
GOTO Main6
BSF 06,0
BSF 05,0
CALL Del1
BCF 05,0
CLRF 06
CALL Del1

BTFSS 34h,0
GOTO Main7
BSF 06,5
BTFSS 34h,2
GOTO Main8
BSF 06,4
BTFSS 35h,0
GOTO Main9
BSF 06,3
BTFSS 35h,2
GOTO Main10
BSF 06,2
BTFSS 36h,0
GOTO Main11
BSF 06,1
BTFSS 36h,2
GOTO Main12
BSF 06,0
BSF 05,2
CALL Del1
BCF 05,2
CLRF 06
CALL Del1

BTFSS 37h,0
GOTO Main13
BSF 06,5
BTFSS 37h,2
GOTO Main14
BSF 06,4
BTFSS 38h,0
GOTO Main15
BSF 06,3
BTFSS 38h,2
GOTO Main16
BSF 06,2
BTFSS 39h,0
GOTO Main17
BSF 06,1
BTFSS 39h,2
GOTO Main18
BSF 06,0
BSF 05,1
CALL Del1
BCF 05,1
CLRF 06
BTFSC 05,3
BCF 2F,0
BTFSC 05,4
BCF 2F,1
DECFSZ 22h,1
GOTO MainA






MOVLW 0A
MOVWF 23h
MOVLW 30h
MOVWF 04
BTFSS 00,0
GOTO Main20
BTFSS 00,2
GOTO Main20
MOVLW 08
MOVWF 00
GOTO Main

INCF 04,1
DECFSZ 23h,1
GOTO Main19


MOVLW 30h
MOVWF 04
BTFSC 00,3
GOTO Main22
INCF 04,1
GOTO Main21
MOVLW 05
MOVWF 00h
INCF 28h
INCF 28h
CALL Stale
GOTO Main

END
;This is the start of memory for the program.
;Disable the comparators
;File 1F is the CMCON file
;Go to Bank 1
;Make all port B output
;Load W with 0001 1000
;Make RA0,1,2,6,7 output and RA3, RA4 input
;Go to Bank 0 - the program memory area.
;Clear the button-press file
;Clear the output lines of PortA
;Blank the output









































































































































;ATTRACT mode comes ON when the project is  
;          switched on.
;Push either button to get to TIC TAC TOE mode.


;File to be decremented


















































;Create 4 cycles of green-to-red-to-green






















;Test for ButtonA

;Test for ButtonB

























;Test for ButtonA

;Test for ButtonB





;Not needed but tells you where micro is going




;Raster is a scanning program for the display
;Raster displays each row in turn and scans down the rows.   It has a display time of 250mS
;Values on the display are taken from Table4 - 3 bytes are needed.


;Raster puts anything you want, on the display

;Jump value for table4

;Number of scans for each increment of the display

;Copy jump value into W

 ;See if end of table reached
;Test zero flag
;Start again
;Copy jump value into W
 ;Call Table4 again as value was lost via

;Move table value to display
 ;Turn on top row
;Show top row
;Turn off top row
;Increment the table pointer
;Copy jump value into W
;Call Table4
;Move table value to display
;Turn on middle row
;Show middle row
;Turn off top row
;Increment the table pointer
;Copy jump value into W
;Call Table4
;Move table value to display
;Turn on bottom row
;Show bottom row
;Turn off bottom row
;Decrement the table pointer











;Set button-press flag
;Is Win-LED/stalemate bit=1?




;Put cursor into "ready" file












;Start of "board"
;Start FSR at file 30h
;Look for "8"
;Found cursor

;Cursor not found


;Found cursor


;Has cursor reached end of "board?"

;Test the zero flag
;not at end of board
;reached end of board

;Return cursor to start

;Clear the cursor


;If cursor has reached end of board,
; return it to file 30h


;Return cursor to start

;Is board location empty?
;Test zero flag
;Not empty
;Empty location
;Show cursor in new location


;ButtonB converts a flashing cursor into a red LED =01

;Set button-press flag

;Decrementing file
;Start of "board"
;FSR starts at file 31h

;Is the file looked at by FSR=5?
;Test zero flag
;Found
;Not found try "08" = flashing cursor
;Is the file looked at by FSR=8?

;Not found
;Cursor found
;Make file = 1 = red

;Put cursor into "hide" file

;Increment the pointer


;ButtonB pushed for computer goes first



;Create delay




;Create delay









;Test for ButtonA

;Test for ButtonB




;Player WINS
;Check all possibilities for PLAYER WIN
;Looking for a HIGH in bit0 = 01 in three files
;This routine is in "Linear Programming Mode"




















































;Player WINS!
;Set the Win-LED/stalemate bit




;Computer WINS
;Check all possibilities for "COMPUTER WINS"
;Looking for a HIGH in bit2 = 04 in 2 files
;This routine is in "Algorithm Mode"

;The value will be incremented to 00!
;Table jump file
;Clear the Computer counter

;Fetch 3 table values in a loop.
;Increment the table-jump file
;Copy jump file into W
;Get first table value
;Look for end-of-table
;Test zero flag
;End of table found - no result obtained
;Copy jump file into W again
;Call table again as previous value was lost via XORLW
;Move table value into FSR
;Look for unwanted player piece
;Dec. computer counter so count cannot be recognised
;Look at bit2 of file 31h (first table value)
;Increment the Computer counter
;Decrement the 3 table-values counter
;Loop for next piece
;See if 2 computer pieces are found


;2 computer pieces not found
;2 Computer pieces found. Put 25h into W
;Locate table value
;Put W into FSR
;Move value in file in and out to see if it is zero
;Test zero flag
;Not zero
;Square is zero. Load computer piece

;Computer WINS!
;Set the Win-LED/stalemate bit




;Look for a "stopper"
;Any row or diagonal containing a "2" must be stopped
; i.e: two files in a row or diag with 01


;The value will be incremented to 00!
;Table jump file
;Clear the "player" counter
;This will be decremented to 3!
;Fetch 3 table-values in a loop.


;3 values have been processed
;Increment the table-jump file
;Copy jump file into W
;Get first table value
;Move table value into FSR
;Look for end-of-table
;End of table found - no result obtained
;Look at bit2 of file 31h for computer piece
;Computer piece found
;Look at bit0 of file 31h (first table value)
;Increment the "player" counter

;Set bit 7 of "player" counter

;Is computer in the row?

;Is counter=2?

;Two player files found! Go back to start of the 3 files.
;Take table-jump value up-table
;Start of the three files. Move Jump value into W
;Look at value of first of three files.
;Put jump value into FSR
;Test for player
;Not empty
;Empty so put 04 into file looked at by FSR


;Increment the pointer




;Random Corner if first move.
;Look to see if all locations are empty.
;Place Computer value in a corner.


;The loop file
;This will be incremented before starting routine
;The pointer file
;Look at first board location
;Put 00 into W
;Is location empty?
;Test the zero flag
;Location is not empty
;File is zero. Decrement the loop file
;Loop again
;Board is empty. Put masking value (7) into W
;AND 07 with random number file. Result in 28h
;File will be 1 to 8
;Put value in file 28 into W
;Fetch random corner from table
;Put random corner into FSR

;Put computer piece onto board



;If board is not empty, place computer in center square

;Move 35h in and out of file to see if it is zero
;Test zero flag


;Put computer into center square




;This is a "trick" situation where the player is
; forming a "fork." If two player and one
; computer piece is found, and computer is in
; middle, computer plays a side square

;Is computer in centre square?
;Not computer piece
;Computer in centre. Is player in first square?
;Player not in first square
;Player in first square. Is player in last square?
;Player in last square




;Get a random value. Put masking value (7) into W
;AND 07 with random number file. Result in file
;File will be 1 to 8
;Put value in file 28 into W
;Fetch random side from table
;Put random side into FSR
;Move side value in and out of file to see if it is zero

;Side not empty

;Put computer piece onto board




;Divide is another "trick" situation.
;If computer in centre and player on two adjoining sides
; computer must go between player pieces.

;Test for player in first square

;Test for computer in first square

;Test for player in second square

;Test for computer in second square

;Test for player in third square

;Test for computer in third square

;Test for player in fourth square

;Test for computer in fourth square

;Look for computer in centre square

;Test for player in sixth square

;Test for player in seventh square

;Test for computer in seventh square

;Test for player in eighth square

;Test for player in ninth square

;Look for computer in last location


;Put computer piece into last location



;Look for a row containing just a computer piece (04) ;and add another computer piece. If not, add a random
; computer piece.


;The value will be incremented to 00!
;Table jump file
;Clear the Look counter

;Fetch 3 table values in a loop.
;Increment the table-jump file
;Copy jump file into W
;Get first table value
;Move table value into FSR
;Look for end-of-table
;End of table found - no result obtained
;Look for computer

;Look for player

;Prevent row being accessed
;Increment the Look counter (If=1, Computer only once)
;Decrement the 3 table-values counter




;Computer nil or more than once
;Computer only once. Find start of row

;Move 25h into W

;Move table value into pointer
;Move file in and out to see it is zero
;Test zero flag

;Square is empty
;Put computer piece into empty square


;Place computer piece only in corner!



;Insert a random computer piece
;corners are first selected

;Put masking value (3) into W
;AND 03 with random number file. Result in file
;File will be 1 to 4 on first pass.
;Put value into W
;Fetch random location from table
;Put random location into FSR
;Test for end-of-table

;Move value in and out of file to see if it is zero
;Test the zero-bit
;location not empty

;Put computer piece onto board



;STALEMATE
;Board is checked to see if any square is empty
;If all full, both LEDs are illuminated

;Check Player-WINS! bit


;Decrementing file

;Start of files into FSR



;Square has cursor
;Test for "hidden" cursor


;Test zero flag
;Square is empty
;Square is full. Increment the pointer




;Set the Win-LED/stalemate bit




;Put cursor into "ready" file











;Make sure button "A" is released

;Make sure button "B" is released

;Go to Main


;Player Value = 01 = red
;Computer Value = 04 = green
;Cursor = 05

;Loops of Main for flashing cursor
;File to decrement
;ButtonA pressed first time?

;Test for ButtonA

;ButtonB pressed first time?

;Test for ButtonB







































































;Skip if ButtonA is still pressed
;Clear button-press flag
;Skip if ButtonB is still pressed
;Clear button-press flag



;The following section hides and shows cursor
;If cursor is showing, it hides cursor
;If cursor is hidden, it shows cursor
;Cursor changes from 05 to 08 to 05 etc

;Ten loops of routine
;Loop file
;Start of files for board
;Load start into FSR
;Test bit0 of INDF

;Is bit2 = HIGH?

;File contains cursor. Put 08 into file to "hide"
;08 will be put into a file 30h to 39h
;Cursor has been hidden

;Increment pointer
;Decrement loop file



;Start of files for board
;Load start into FSR
;Look for "8" in a file

;Increment the pointer

;Put 5 in file looked at by FSR

;Increment the RANDOM NUMBER file




;Tells assembler end of program