;; Emacs Mode Selection Info: -*-mode: ASM; coding: iso-latin-1-dos;-*- * ;; ******************************************************************************************** ;; File Name: Four_5.asm ;; Auther: John L. Weinrich ;; Date: 01/31/03 ;; Useage 4004 TIC-TAC-TOE Game ;; Description: ;; ;; This routine is used for the 4004 TIC-TAC-TOE Game. ;; ;; Assumptions: ;; This assembly code and all the included files assume the following: ;; ;; RAM Memory: 2048 X 4 (8 RAM banks, 4 RAMs/bank, 4 registers/RAM, 16 Char/Reg) ;; 256 status characters. ;; 2 I/O Port ;; RAM1: SPEAKER PITCH/write ;; RAM2: SPEAKER LEVEL/write ;; ;; ROM Memory: 4096 X 8 (16 ROMs @ 256 locations ;; 11 I/O Ports (3 - R/W, 4- Read, 4 - Write) ;; ROM0: MISC/read ;; ROM0: MISC/write ;; ROM3: DISPLAY HIGH IN/read ;; ROM3: DISPLAY HIGH OUT/write ;; ROM4: DISPLAY LOW IN/read ;; ROM4: DISPLAY LOW OUT/write ;; ROM5: KEYBOARD HIGH INPUT/read ;; ROM6: KEYBOARD LOW INPUT/read ;; ROM7: MISC2/write ;; ROM8: PAGE/write ;; ROM9: RANDOM NUMBER GENERATOR/read ;; ROM10: FPGA VERSION/read ;; ;; See "4004 FPGA Design" and "4004 Software Design " documents for more detail information. ;; ;; Registers used: ;; Memory used: ;; Entrance parameters: ;; Exit parameters: ;; Labels used: ;; ******************************************************************************************** ;; ******************************************************************************************** ;; Here are the assembler directives ;; What CPU to assemble for and where in memory to start ;; Also there is the all the include files ;; except subroutines. include "four_ALL.equ" ; Get all equates include "bitfuncs.inc" ; Include bit functions so that fin can be ; loaded from a label (upper 4 bits of address ; are loped off) include "four_05.equ" ; Get Page #3 equates cpu 4004 ; Tell assembler that the processor is a 4004 org CODE_LOCATION ; Set code start location in memory ;; ******************************************************************************************** ;; This is the begining of the get mode routine ;; ******************************************************************************************** DisBrdPos fim SRC_P,POS1_RAM ; Select RAM game board position src SRC_P ; Send out selection clb ; Make sure accumulator is clear rdm ; Get position #1 RAM charactor jcn Z,NextPos2 ; No mark, go to next position dac ; Decrement accumulator jcn Z,Pos1X1 ; Now check for X charactor dac ; Decrement accumulatoa again jcn Z,Pos1O1 ; Now check for O charactor jun NextPos2 ; Neither X or O selected, ERROR Pos1X1 jms DisX1 ; Display X in position #1 jun NextPos2 ; Check position #2 Pos1O1 jms DisO1 ; Display X in position #1 NextPos2 fim SRC_P,POS2_RAM ; Select RAM game board position src SRC_P ; Send out selection clb ; Make sure accumulator is clear rdm ; Get position #1 RAM charactor jcn Z,NextPos3 ; No mark, go to next position dac ; Decrement accumulator jcn Z,Pos2X2 ; Now check for X charactor dac ; Decrement accumulatoa again jcn Z,Pos2O2 ; Now check for O charactor jun NextPos3 ; Neither X or O selected, ERROR Pos2X2 jms DisX2 ; Display X in position #2 jun NextPos3 ; Check position #3 Pos2O2 jms DisO2 ; Display O in position #2 NextPos3 fim SRC_P,POS3_RAM ; Select RAM game board position src SRC_P ; Send out selection clb ; Make sure accumulator is clear rdm ; Get position #1 RAM charactor jcn Z,NextPos4 ; No mark, go to next position dac ; Decrement accumulator jcn Z,Pos3X3 ; Now check for X charactor dac ; Decrement accumulatoa again jcn Z,Pos3O3 ; Now check for O charactor jun NextPos4 ; Neither X or O selected, ERROR Pos3X3 jms DisX3 ; Display X in position #3 jun NextPos4 ; Check position #4 Pos3O3 jms DisO3 ; Display O in position #3 NextPos4 fim SRC_P,POS4_RAM ; Select RAM game board position src SRC_P ; Send out selection clb ; Make sure accumulator is clear rdm ; Get position #1 RAM charactor jcn Z,NextPos5 ; No mark, go to next position dac ; Decrement accumulator jcn Z,Pos4X4 ; Now check for X charactor dac ; Decrement accumulatoa again jcn Z,Pos4O4 ; Now check for O charactor jun NextPos5 ; Neither X or O selected, ERROR Pos4X4 jms DisX4 ; Display X in position #4 jun NextPos5 ; Check position #5 Pos4O4 jms DisO4 ; Display O in position #4 NextPos5 fim SRC_P,POS5_RAM ; Select RAM game board position src SRC_P ; Send out selection clb ; Make sure accumulator is clear rdm ; Get position #1 RAM charactor jcn Z,NextPos6 ; No mark, go to next position dac ; Decrement accumulator jcn Z,Pos5X5 ; Now check for X charactor dac ; Decrement accumulatoa again jcn Z,Pos5O5 ; Now check for O charactor jun NextPos6 ; Neither X or O selected, ERROR Pos5X5 jms DisX5 ; Display X in position #5 jun NextPos6 ; Check position #6 Pos5O5 jms DisO5 ; Display O in position #5 NextPos6 fim SRC_P,POS6_RAM ; Select RAM game board position src SRC_P ; Send out selection clb ; Make sure accumulator is clear rdm ; Get position #1 RAM charactor jcn Z,NextPos7 ; No mark, go to next position dac ; Decrement accumulator jcn Z,Pos6X6 ; Now check for X charactor dac ; Decrement accumulatoa again jcn Z,Pos6O6 ; Now check for O charactor jun NextPos7 ; Neither X or O selected, ERROR Pos6X6 jms DisX6 ; Display X in position #6 jun NextPos7 ; Check position #7 Pos6O6 jms DisO6 ; Display O in position #6 NextPos7 fim SRC_P,POS7_RAM ; Select RAM game board position src SRC_P ; Send out selection clb ; Make sure accumulator is clear rdm ; Get position #1 RAM charactor jcn Z,NextPos8 ; No mark, go to next position dac ; Decrement accumulator jcn Z,Pos7X7 ; Now check for X charactor dac ; Decrement accumulatoa again jcn Z,Pos7O7 ; Now check for O charactor jun NextPos8 ; Neither X or O selected, ERROR Pos7X7 jms DisX7 ; Display X in position #7 jun NextPos8 ; Check position #8 Pos7O7 jms DisO7 ; Display O in position #7 NextPos8 fim SRC_P,POS8_RAM ; Select RAM game board position src SRC_P ; Send out selection clb ; Make sure accumulator is clear rdm ; Get position #1 RAM charactor jcn Z,NextPos9 ; No mark, go to next position dac ; Decrement accumulator jcn Z,Pos8X8 ; Now check for X charactor dac ; Decrement accumulatoa again jcn Z,Pos8O8 ; Now check for O charactor jun NextPos9 ; Neither X or O selected, ERROR Pos8X8 jms DisX8 ; Display X in position #8 jun NextPos9 ; Check position #9 Pos8O8 jms DisO8 ; Display O in position #8 NextPos9 fim SRC_P,POS9_RAM ; Select RAM game board position src SRC_P ; Send out selection clb ; Make sure accumulator is clear rdm ; Get position #1 RAM charactor jcn Z,NextPosDone ; No mark, go to next position dac ; Decrement accumulator jcn Z,Pos9X9 ; Now check for X charactor dac ; Decrement accumulatoa again jcn Z,Pos9O9 ; Now check for O charactor jun NextPosDone ; Neither X or O selected, ERROR Pos9X9 jms DisX9 ; Display X in position #9 jun NextPosDone ; Done Pos9O9 jms DisO9 ; Display O in position #9 NextPosDone jun DisBrdPosP4Rtn ; Done