;; Emacs Mode Selection Info: -*-mode: ASM; coding: iso-latin-1-dos;-*- * ;; ******************************************************************************************** ;; File Name: GetPlayers.inc ;; Auther: John L. Weinrich ;; Date: 01/31/03 ;; Useage 4004 TIC-TAC-TOE Game ;; Description: ;; ;; This file is an include file containing misc routines. ;; ;; See "4004 FPGA Design" and "4004 Software Design " documents for more detail information. ;; ;; Registers used: SRC_P, UTILITY_0_P, UTILITY_1_P, UTILITY_3_P, ARRAY_PTR_P ;; Memory used: PLAYER_1_RAM, PLAYER_2_RAM, KYB_STATE_L_RAM, KYB_STATE_H_RAM ;; Entrance parameters: None. ;; Exit parameters: Accumulator, success, failure, DEFAULT_PLAYER ;; Labels used: GetPlayer1, GetPlayer2, GetPlayer, GetPlayerLoop, UpperUEnter, ;; D_Player1, LowerLEnter, RAMPtrRollOver1, NotEnter, Borrow1, NoBorrow1, ;; Borrow2, NoBorrow2, DecDisPtr, SetDisplay, NotBackSpace, NotRollOver2, ;; SetDisplay2, IncCharCntr, DefaultPlayer1, DefaultPlayer2, StorePlayerRAM, ;; LowerEOS3, NotEOS3, NoRollOver3, NoRollOver4, NoRollOver5, EndOfString3, ;; NoRollOver6, D_Player_1, D_Player_2 ;; Routines used: DisplayModeCMND, DisplayModeData, WaitForDisplay, DisSetLineCol, ;; GetChar, Level4, Pitch1116HZ, Beep ;; ******************************************************************************************** ;; ******************************************************************************************** ;; Get player #1 name, put name in RAMRAM, and display on display. If no name is entered ;; ("enter" key without any charactors preceding), then enter a generic name "Player 1" in ;; RAM. Use "<" key as backspace. Limit length to 15 charactors. ;; GetPlayer1 ldm RAM_BANK_0 ; Move RAM bank pointer to ACC dcl ; Select RAM bank ;; Select player #1 RAM space fim UTILITY_0_P,PLAYER_1_RAM ; Get address of player #1 RAM space ;; Select player #1 display location fim UTILITY_1_P,L3C2 ; Get address of player #1 display location jun GetPlayer ;; ******************************************************************************************** ;; Get player #2 name, put name in RAM, and display on display. If no name is entered ;; ("enter" key without ant charactors preceding), then enter a generic name "Player 1" in ;; RAM. Use "<" key as backspace. Limit length to 15 charactors. ;; GetPlayer2 ldm RAM_BANK_0 ; Move RAM bank pointer to ACC dcl ; Select RAM bank ;; Select player #1 RAM space fim UTILITY_0_P,PLAYER_2_RAM ; Get address of player #2 RAM space ;; Select player #1 display location fim UTILITY_1_P,L3C2 ; Get address of player #2 display location jun GetPlayer ;; Set display charactor location GetPlayer jms DisplayModeCMND ; Put display in command mode for commands jms WaitForDisplay ; Make sure display is ready for a command jms DisSetLineCol ; Call the routine to set the display cursor jms DisplayModeData ; Set display to data mode ;; Initialize charactor counter fim UTILITY_3_P,0 ; Init charactor counter to 0 ;; Get charactor GetPlayerLoop jms GetChar ; Get a charactor jms Level4 ; Set level to "5" jms Pitch1116HZ ; Set pitch to "happy" jms Beep ; Tell user that key was pressed ;; Test if charactor is "enter" and charactor counter is zero ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,KYB_STATE_H_RAM ; Select upper keyboard state charactor src SRC_P ; Tell RAM of selection clb ; Make sure accumulator is clear (check ; for upper nibble of "enter" sbm ; Test charactor upper nibble from RAM jcn NZ,NotEnter ; " UpperUEnter ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,KYB_STATE_L_RAM ; Select lower keyboard state charactor src SRC_P ; Tell RAM of selection clb ; Make sure accumulator is clear ldm 0DH ; Get lower nibble of an "enter" sbm ; Test charactor upper nibble from RAM jcn NZ,NotEnter ; " ;; Check if the charactor counter is zero. If it is then enter was pressed ;; without any charactors entered. clb ; Make sure accumulator is clear sub UTILITY_3_L ; Compare jcn NZ,LowerLEnter ; Set default player name ;; Set player name to default D_Player1 clb bbl DEFAULT_PLAYER ; Return with a default player selected ;; Since charactor counter is not zero but "enter" has been pressed, ;; then append a "0" to player1 name string and return to caller LowerLEnter src UTILITY_0_P ; Select upper nibble RAM ldm 0 ; Get a zero to store wrm ; Store zero at end of string isz UTILITY_0_L,RAMPtrRollOver1 ; Increment lower nibble pointer and check for rollover inc UTILITY_0_H ; Rollover, increment upper nibble pointer RAMPtrRollOver1 src UTILITY_0_P ; Send out pointer to select RAM charactor ldm 0 ; Get a zero to store wrm ; Store zero at end of string bbl REPORT_SUCCESS ; All done, return ;; Check for backspace charactor "<". If backspace, decrement pointers ;; if charactor counter is greater than 0. When backspacing, erase ;; backspace charactor NotEnter ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,KYB_STATE_H_RAM ; Select upper keyboard state charactor src SRC_P ; Tell RAM of selection clb ; Make sure accumulator is clear ldm 03H ; Get upper nibble of an "<" sbm ; Test charactor upper nibble from RAM jcn NZ,NotBackSpace ; " ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,KYB_STATE_L_RAM ; Select lower keyboard state charactor src SRC_P ; Tell RAM of selection clb ; Make sure accumulator is clear ldm 0CH ; Get lower nibble of an "<" sbm ; Test charactor upper nibble from RAM jcn NZ,NotBackSpace ; " ;; Backspace charactor has been pressed ;; Check if the charactor counter is zero. If it is then do not backspace clb ; Make sure accumulator is clear sub UTILITY_3_L ; Compare jcn Z,GetPlayerLoop ; Go back and get another charactor ;; Charactor counter not 0, decrement clb ; Make sure accumulator is clear xch UTILITY_3_L ; Get charactor counter dac ; Decrement charactor counter xch UTILITY_3_L ; Put back charactor counter ;; Deccrement RAM pointer xch UTILITY_0_L ; Get RAM pointer lower nibble to decrement dac ; Decrement lower nibble jcn C,NoBorrow1 ; If carry set then there is no borrow xch UTILITY_0_L ; Get RAM pointer lower nibble to decrement xch UTILITY_0_H ; Get RAM pointer upper nibble to decrement dac ; Decrement upper nibble xch UTILITY_0_H ; Put back upper nibble RAM pointer Borrow1 xch UTILITY_0_L ; Put back lower nibble RAM pointer NoBorrow1 dac ; Decrement lower nibble jcn C,NoBorrow2 ; If carry set then there is no borrow xch UTILITY_0_L ; Get RAM pointer lower nibble to decrement xch UTILITY_0_H ; Get RAM pointer upper nibble to decrement dac ; Decrement upper nibble xch UTILITY_0_H ; Put back upper nibble RAM pointer jun Borrow2 NoBorrow2 xch UTILITY_0_L ; Put back lower nibble RAM pointer Borrow2 jun DecDisPtr ; If carry set then there is no borrow ;; Decrement display pointer DecDisPtr clb ; Make sure accumulator is clear xch UTILITY_1_L ; Get display pointer lower nibble to decrement dac ; Decrement lower nibble xch UTILITY_1_L ; Put back lower nibble display pointer jcn C,SetDisplay ; If carry set then there is no borrow clb ; Make sure accumulator is clear xch UTILITY_1_H ; Get display pointer upper nibble to decrement dac ; Decrement upper nibble xch UTILITY_1_H ; Put back upper nibble display pointer ;; Set display charactor location SetDisplay jms DisplayModeCMND ; Put display in command mode for commands jms WaitForDisplay ; Make sure display is ready for a command jms DisSetLineCol ; Call the routine to set the display cursor jms DisplayModeData ; Set display to data mode ;; Write "space" upper nibble to display ldm 02H ; Get "space" upper nibble fim SRC_P,DISPLAY_HIGH_PORT ; Get address to display upper nibble port src SRC_P ; Send out display upper nibble address wrr ; Write the display upper nibble to display ;; Write "space" lower nibble to display ldm 00H ; Get "space" lower nibble fim SRC_P,DISPLAY_LOW_PORT ; Get address to display lower nibble port src SRC_P ; Send out display lower nibble address wrr ; Write the display lower nibble to display ;; Set display charactor location jms DisplayModeCMND ; Put display in command mode for commands jms WaitForDisplay ; Make sure display is ready for a command jms DisSetLineCol ; Call the routine to set the display cursor jms DisplayModeData ; Set display to data mode ;; Finished processing a backspace, go get another charactor jun GetPlayerLoop ; Go back and get another charactor ;; Since the keypress is not "enter" or backspace, save charactor to RAM and write ;; to display if charactor counter is less than 15. ;; Also increment display, RAM, and charactor pointers/counter. ;; Get RAM pointer NotBackSpace clb ; Make sure accumulator is clear ldm 15 ; Get maximum string length sub UTILITY_3_L ; Test for maximum string length jcn Z,GetPlayerLoop ; If maximum, start over, getting another charactor ;; Select & fetch keypress charactor upper nibble fim SRC_P,KYB_STATE_H_RAM ; Select upper keyboard state charactor src SRC_P ; Tell RAM of selection rdm ; Get upper charactor nibble ;; Write keypress upper nibble to RAM src UTILITY_0_P ; Select upper nibble RAM wrm ; Write upper nibble to RAM ;; Increment RAM pointer isz UTILITY_0_L,NotRollOver2 ; Increment lower nibble pointer and check for rollover inc UTILITY_0_H ; Rollover, increment upper nibble pointer NotRollOver2 src UTILITY_0_P ; Send out pointer to select RAM charactor ;; Select & fetch keypress charactor lower nibble fim SRC_P,KYB_STATE_L_RAM ; Select lower keyboard state charactor src SRC_P ; Tell RAM of selection rdm ; Get upper charactor nibble ;; Write keypress lower nibble to RAM src UTILITY_0_P ; Select lower nibble RAM wrm ; Write lower nibble to RAM ;; Increment RAM pointer isz UTILITY_0_L,SetDisplay2 ; Increment lower nibble pointer and check for rollover inc UTILITY_0_H ; Rollover, increment upper nibble pointer ;; Set display charactor location SetDisplay2 jms DisplayModeCMND ; Put display in command mode for commands jms WaitForDisplay ; Make sure display is ready for a command jms DisSetLineCol ; Call the routine to set the display cursor jms DisplayModeData ; Set display to data mode ;; Select & fetch keypress charactor upper nibble fim SRC_P,KYB_STATE_H_RAM ; Select upper keyboard state charactor src SRC_P ; Tell RAM of selection rdm ; Get upper charactor nibble ;; Write keypress upper nibble to display fim SRC_P,DISPLAY_HIGH_PORT ; Get address to display upper nibble port src SRC_P ; Send out display upper nibble address wrr ; Write the display upper nibble to display ;; Select & fetch keypress charactor lower nibble fim SRC_P,KYB_STATE_L_RAM ; Select lower keyboard state charactor src SRC_P ; Tell RAM of selection rdm ; Get upper charactor nibble ;; Write keypress lower nibble to display fim SRC_P,DISPLAY_LOW_PORT ; Get address to display lower nibble port src SRC_P ; Send out display lower nibble address wrr ; Write the display lower nibble to display ;; Increment display pointer isz UTILITY_1_L,IncCharCntr ; Increment lower nibble pointer and check for rollover inc UTILITY_1_H ; Rollover, increment upper nibble pointer ;; Increment charactor counter IncCharCntr inc UTILITY_3_L ; Increment charactor counter ;; Return to start of loop jun GetPlayerLoop ;; ******************************************************************************************** ;; Sets player name to default in RAM ;; org GET_PLAYERS_LOCATION + 0100H DefaultPlayer1 ldm RAM_BANK_0 ; Move RAM bank pointer to ACC dcl ; Select RAM bank ;; Select player #1 RAM space fim UTILITY_0_P,PLAYER_1_RAM ; Get address of player #1 RAM space fim ARRAY_PTR_P,lo(D_Player_1) ; Get pointer to the string to be stored jun StorePlayerRAM DefaultPlayer2 ldm RAM_BANK_0 ; Move RAM bank pointer to ACC dcl ; Select RAM bank ;; Select player #2 RAM space fim UTILITY_0_P,PLAYER_2_RAM ; Get address of player #2 RAM space fim ARRAY_PTR_P,lo(D_Player_2) ; Get pinter to the string to be stored jun StorePlayerRAM ; Now store the player name to RAM Mode2_4004 ldm RAM_BANK_0 ; Move RAM bank pointer to ACC dcl ; Select RAM bank ;; Select player #2 RAM space fim UTILITY_0_P,PLAYER_2_RAM ; Get address of player #2 RAM space fim ARRAY_PTR_P,lo(D_4004_2) ; Get pinter to the string to be stored jun StorePlayerRAM ; Now store the player name to RAM StorePlayerRAM fin SCRATCH_1_P ; Get a byte of the string clb ; Make sure accumulator is clear xch SCRATCH_1_L ; Get the lower nibble into accumulator jcn Z,LowerEOS3 ; Check if lower nibble is zero jun NotEOS3 ; Lower nibble not zero, then display it LowerEOS3 clb xch SCRATCH_1_H ; Lower nibble is zero, now check upper nibble jcn Z,EndOfString3 ; Upper nibble zero, go to return NotEOS3 fin SCRATCH_1_P ; Upper nibble not zero, get byte again xch SCRATCH_1_H ; Get the upper nibble into accumulator ;; Write lower nibble to RAM src UTILITY_0_P ; Select upper nibble RAM wrm ; Write upper nibble to RAM ;; Increment RAM pointer isz UTILITY_0_L,NoRollOver3 ; Increment lower nibble pointer and check for rollover inc UTILITY_0_H ; Rollover, increment upper nibble pointer NoRollOver3 xch SCRATCH_1_L ; Get the lower nibble into accumulator ;; Write upper nibble to RAM src UTILITY_0_P ; Select lower nibble RAM wrm ; Write lower nibble to RAM isz UTILITY_0_L,NoRollOver4 ; Increment lower nibble pointer and check for rollover inc UTILITY_0_H ; Rollover, increment upper nibble pointer NoRollOver4 isz ARRAY_PTR_L,NoRollOver5 ; Increment string pointer & check for roll over inc ARRAY_PTR_H ; String pointer rolled over, increment upper nibble NoRollOver5 jun StorePlayerRAM ; Continue to out more bytes to display EndOfString3 src UTILITY_0_P ; Select lower nibble RAM ldm 000h ; Get upper nibble of string termination charactor wrm ; Write upper nibble to RAM ;; Increment RAM pointer isz UTILITY_0_L,NoRollOver6 ; Increment lower nibble pointer and check for rollover inc UTILITY_0_H ; Rollover, increment upper nibble pointer ;; Write upper nibble to RAM NoRollOver6 src UTILITY_0_P ; Select lower nibble RAM ldm 000h ; Get lower nibble of string termination charactor wrm ; Write lower nibble to RAM bbl REPORT_SUCCESS ; All done, go back D_Player_1 data "PLAYER #1...",000h ; Display Player #1 name, default D_Player_2 data "PLAYER #2...",000h ; Display Player #2 name, default D_4004_2 data "4004",000h ; Display Player #2 name, 4004 default