;; Emacs Mode Selection Info: -*-mode: ASM; coding: iso-latin-1-dos;-*- * ;; ******************************************************************************************** ;; File Name: Random.inc ;; 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: ;; ******************************************************************************************** ;; Get random number NewRandNum ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,RAND_NUM_GEN_PORT ; Select random number port src SRC_P ; Send out port selection clb ; Make sure accumulator is clear rdr ; Get random number fim SRC_P,RNG_RAM ; Select random number RAM storage src SRC_P ; Send out RAM selection wrm ; Write random number to RAM clb ; Make sure accumulator is clear ldm 09h ; Get max numer sbm ; Subtract random number generator jcn NC,NewRandNum ; Random number is not within range ;; Check for position #1 fim SRC_P,RNG_RAM ; Select random number RAM storage src SRC_P ; Send out RAM selection clb ; Make sure accumulator is clear ldm 00h sbm ; Subtract random number to RAM jcn NZ,NotPos1 ; Equal fim UTILITY_1_P,POS1_RAM ; Select RAM game board position jun Pos ; Position found ;; Check for position #2 NotPos1 fim SRC_P,RNG_RAM ; Select random number RAM storage src SRC_P ; Send out RAM selection clb ; Make sure accumulator is clear ldm 01h sbm ; Subtract random number to RAM jcn NZ,NotPos2 ; Equal fim UTILITY_1_P,POS2_RAM ; Select RAM game board position jun Pos ; Position found ;; Check for position #3 NotPos2 fim SRC_P,RNG_RAM ; Select random number RAM storage src SRC_P ; Send out RAM selection clb ; Make sure accumulator is clear ldm 02h sbm ; Subtract random number to RAM jcn NZ,NotPos3 ; Equal fim UTILITY_1_P,POS3_RAM ; Select RAM game board position jun Pos ; Position found ;; Check for position #4 NotPos3 fim SRC_P,RNG_RAM ; Select random number RAM storage src SRC_P ; Send out RAM selection clb ; Make sure accumulator is clear ldm 03h sbm ; Subtract random number to RAM jcn NZ,NotPos4 ; Equal fim UTILITY_1_P,POS4_RAM ; Select RAM game board position jun Pos ; Position found ;; Check for position #5 NotPos4 fim SRC_P,RNG_RAM ; Select random number RAM storage src SRC_P ; Send out RAM selection clb ; Make sure accumulator is clear ldm 04h sbm ; Subtract random number to RAM jcn NZ,NotPos5 ; Equal fim UTILITY_1_P,POS5_RAM ; Select RAM game board position jun Pos ; Position found ;; Check for position #6 NotPos5 fim SRC_P,RNG_RAM ; Select random number RAM storage src SRC_P ; Send out RAM selection clb ; Make sure accumulator is clear ldm 05h sbm ; Subtract random number to RAM jcn NZ,NotPos6 ; Equal fim UTILITY_1_P,POS6_RAM ; Select RAM game board position jun Pos ; Position found ;; Check for position #7 NotPos6 fim SRC_P,RNG_RAM ; Select random number RAM storage src SRC_P ; Send out RAM selection clb ; Make sure accumulator is clear ldm 06h sbm ; Subtract random number to RAM jcn NZ,NotPos7 ; Equal fim UTILITY_1_P,POS7_RAM ; Select RAM game board position jun Pos ; Position found ;; Check for position #8 NotPos7 fim SRC_P,RNG_RAM ; Select random number RAM storage src SRC_P ; Send out RAM selection clb ; Make sure accumulator is clear ldm 07h sbm ; Subtract random number to RAM jcn NZ,NotPos8 ; Equal fim UTILITY_1_P,POS8_RAM ; Select RAM game board position jun Pos ; Position found ;; Check for position #9 NotPos8 fim SRC_P,RNG_RAM ; Select random number RAM storage src SRC_P ; Send out RAM selection clb ; Make sure accumulator is clear ldm 08h sbm ; Subtract random number to RAM jcn NZ,NotPos9 ; Equal fim UTILITY_1_P,POS9_RAM ; Select RAM game board position jun Pos ; Position found NotPos9 jun NewRandNum ; Position not found, try again ;; Check to see if there is a X or O from a previous turn Pos src UTILITY_1_P ; Tell RAM of selection of board number clb rdm ; Get position #1 RAM charactor jcn NZ,NewRandNum ; Previous turn X or O bbl REPORT_SUCCESS ; All done, report success