;; Emacs Mode Selection Info: -*-mode: ASM; coding: iso-latin-1-dos;-*- * ;; ******************************************************************************************** ;; File Name: Four_6.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_06.equ" ; Get Page #6 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 routine for the 4004 to play a turn ;; ******************************************************************************************** ;;Get skill level and execute the specific routines Get4004PosP6 clb ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,SKILL_STATE_RAM ; Select mode charactor src SRC_P ; Tell RAM of selection clb ; Make sure accumulator is clear ldm SKILL_LEVEL1 ; Get skill level sbm ; Subtract skill level jcn Z,Skill1 ; Test for skill level clb ; Make sure accumulator is clear ldm SKILL_LEVEL2 ; Get skill level sbm ; Subtract skill level jcn Z,Skill2 ; Test for skill level clb ; Make sure accumulator is clear ldm SKILL_LEVEL3 ; Get skill level sbm ; Subtract skill level jcn Z,Skill3 ; Test for skill level clb ; Make sure accumulator is clear ldm SKILL_LEVEL4 ; Get skill level sbm ; Subtract skill level jcn NZ,Skill1 ; Test for skill level ;; Skill level #4: ;; looks for a win position ;; If none, looks for a position to block ;; If none, looks for an opposite corner of opponent ;; If none, looks for an opposite corner of self ;; If none, looks for center ;; else select random position Skill4 fim SRC_P,PLAYER_START_RAM ; Select player start charactor src SRC_P ; Tell RAM of selection clb ; Make sure accumulator is clear ldm PLAYER_1_START ; Get player #1 start charactor sbm ; Subtract Player Start charactor jcn Z,StartPlayer ; Check if player starts jun Start4004 ; 4004 starts Start4004 jms LookForWin ; Look for a win position jcn Z,SetMark ; Was there a position? jms LookForBlock ; Look for a block position jcn Z,SetMark ; Was there a position? jms LookForCenter ; Look for a center position jcn Z,SetMark ; Was there a position? jms LookForCornerO ; Look for a opponent corner position jcn Z,SetMark ; Was there a position? jms LookForCornerS ; Look for a self corner position jcn Z,SetMark ; Was there a position? jms LookForSide ; Look for a side position jcn Z,SetMark ; Was there a position? jms LookForCornerA ; Look for a any corner position jcn Z,SetMark ; Was there a position? jms NewRandNum ; Get random number board position jun SetMark ; Set the mark for a random number selection StartPlayer jms LookForWin ; Look for a win position jcn Z,SetMark ; Was there a position? jms LookForBlock ; Look for a block position jcn Z,SetMark ; Was there a position? jms LookForCornerO ; Look for a opponent corner position jcn Z,SetMark ; Was there a position? jms LookForCornerS ; Look for a self corner position jcn Z,SetMark ; Was there a position? jms LookForCornerA ; Look for a any corner position jcn Z,SetMark ; Was there a position? jms LookForCenter ; Look for a center position jcn Z,SetMark ; Was there a position? jms LookForSide ; Look for a side position jcn Z,SetMark ; Was there a position? jms NewRandNum ; Get random number board position jun SetMark ; Set the mark for a random number selection ;; Skill level #3 looks for a win position ;; If none, looks for a position to block ;; else select random position Skill3 jms LookForWin ; Look for a win position jcn Z,SetMark ; Was there a position? jms LookForBlock ; Look for a block position jcn Z,SetMark ; Was there a position? jms NewRandNum ; Get random number board position jun SetMark ; Set the mark for a random number selection ;; Skill level #2 looks for a win position ;; If none, select random position Skill2 jms LookForWin ; Look for a win position jcn Z,SetMark ; Was there a position? jms NewRandNum ; Get random number board position jun SetMark ; Set the mark for a random number selection ;; Skill level #1 just picks a random available position Skill1 jms NewRandNum ; Get random number board position ;; Now set the X or O in RAM postion SetMark fim SRC_P,PLAYER_MARK_RAM ; Select player mark charactor src SRC_P ; Tell RAM of selection clb ; Make sure it is all clear rdm ; Get player mark charactor from RAM src UTILITY_1_P ; Tell RAM of selection of board number dac ; Decrement accumulator jcn Z,PosX1 ; Now check for X charactor dac ; Decrement accumulatoa again jcn Z,PosO1 ; Now check foa O charactor PosX1 ldm PLAYER_X_CHAR ; Get X charactor wrm ; Write X charactor to RAM game board jun DonePos ; All done PosO1 ldm PLAYER_O_CHAR ; Get O charactor wrm ; Write O charactor to RAM game board DonePos jms Level5 ; Set level to "5" jms Pitch1116HZ ; Set pitch to "happy" jms Beep ; Tell user that key was pressed jun Get4004PosP6Rtn ; Done