;; Emacs Mode Selection Info: -*-mode: ASM; coding: iso-latin-1-dos;-*- * ;; ******************************************************************************************** ;; File Name: Keyboard.inc ;; Auther: John L. Weinrich ;; Date: 01/31/03 ;; Useage 4004 TIC-TAC-TOE Game ;; Description: ;; ;; This file is an include file containing the keyboard routines. ;; ;; See "4004 FPGA Design" and "4004 Software Design " documents for more detail information. ;; ;; Registers used: SRC_P ;; Memory used: SYSTEM_STATE_RAM, KYB_STATE_L_RAM, KYB_STATE_H_RAM ;; Entrance parameters: None. ;; Exit parameters: KYB_STATE_L_RAM, KYB_STATE_H_RAM, Accumulator, success, failure ;; Labels used: GetChar, StoreChar, NoKeyPress, Inactive, Active, InitKYBD ;; Routines used: Level2, Pitch2232HZ, Beep, InitKYBD, GetChar, DisplayModeCMND, ;; DisplayModeData, DoneLEDGreen, DoneLEDOn, DoneLEDOff, WaitForDisplay, ;; OffDisplay, OnDisplay, HomeDisplay ;; ******************************************************************************************** ;; ******************************************************************************************** ;; This is the wait for key press subroutine. Check ready bit in MISC port and TEST flag. ;; GetChar jcn NT,NoKeyPress ; Now test using TEST line, if ready exit ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,SYSTEM_STATE_RAM ; Select system state charactor src SRC_P ; Tell RAM of selection clb ; Make sure accumulator is clear rdm ; Get system state from RAM jcn NZ,StoreChar ; Check if system just woke up jms Level2 ; Set level to "2" jms Pitch2232HZ ; Set pitch to "awake" jms Beep ; Acknowledge a key was pressed jms InitKYBD ; Clear the keyboard jun GetChar ; Loop back for a real charactor ;; Get the upper nibble from keyboard StoreChar ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,KYBD_HIGH_PORT ; Select keyboard upper nibble port src SRC_P ; Send out keyboard upper nibble port selection clb ; Make sure accumulator is clear rdr ; Get the upper nibble fim SRC_P,KYB_STATE_H_RAM ; Select high keyboard state charactor src SRC_P ; Tell RAM of selection wrm ; Save keyboard high state charactor into RAM ;; Get the lower nibble from keyboard ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,KYBD_LOW_PORT ; Select keyboard lower nibble port src SRC_P ; Send out keyboard lower nibble port selection clb ; Make sure accumulator is clear rdr ; Get the lower nibble fim SRC_P,KYB_STATE_L_RAM ; Select low keyboard state charactor src SRC_P ; Tell RAM of selection wrm ; Save keyboard low state charactor into RAM bbl REPORT_SUCCESS ; Exit, return success ;; Check if inactive signal has asserted NoKeyPress fim SRC_P,MISC_PORT ; Select MISC port src SRC_P ; Send out MISC port selection clb ; Make sure accumulator and carry are cleared rdr ; Get MISC port data rar ; Move MISC port inactive to carry bit location jcn NC,Active ;; System inactive, turn display back lighting off Inactive ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,MISC2_RAM_SHADOW ; Select MISC2 port RAM shadow charactor src SRC_P ; Tell RAM of selection rdm ; Get MISC2 port shadow data from RAM rar ; Select the display back light enable bit in MISC2 port clc ; Set display back light enable bit to extingush ral ; Restore nibble, de-select display back light enable bit wrm ; Write MISC2 port shadow back to RAM fim SRC_P,MISC2_PORT ; Select MISC2 port src SRC_P ; Tell MISC2 port it is selected wrr ; Update the MISC2 port to shadow setting jms DoneLEDGreen ; Call routine to select green LED jms DoneLEDOn ; Turn LED on jms DoneLEDOff ; Turn LED off jms DisplayModeCMND ; Set the display to command mode jms WaitForDisplay ; Wait for display to become ready for data or commands jms OffDisplay ; Turn display off jms WaitForDisplay ; Wait for display to become ready for data or commands jms HomeDisplay ; Set display cursor to home jms DisplayModeData ; Set the display to data mode ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,SYSTEM_STATE_RAM ; Select system state charactor src SRC_P ; Tell RAM of selection ldm INACTIVE ; Get INACTIVE system state value wrm ; Save system state to RAM jun GetChar ;; A key press has occured, system active, light display back light Active ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,MISC2_RAM_SHADOW ; Select MISC2 port RAM shadow charactor src SRC_P ; Tell RAM of selection rdm ; Get MISC2 port shadow data from RAM rar ; Select the display back light enable bit in MISC2 port stc ; Set display back light enable bit to illuminate ral ; Restore nibble, de-select display back light enable bit wrm ; Write MISC2 port shadow back to RAM fim SRC_P,MISC2_PORT ; Select MISC2 port src SRC_P ; Tell MISC2 port it is selected wrr ; Update the MISC2 port to shadow setting jms DisplayModeCMND ; Set the display to command mode jms WaitForDisplay ; Wait for display to become ready for data or commands jms OnDisplay ; Turn display on jms DisplayModeData ; Set the display to data mode jms DoneLEDOn ; Turn LED on dcl ; Send out RAM bank selection fim SRC_P,SYSTEM_STATE_RAM ; Select system state charactor src SRC_P ; Tell RAM of selection ldm ACTIVE ; Get INACTIVE system state value wrm ; Save system state to RAM jun GetChar ;; ******************************************************************************************** ;; This subroutine initializes the keyboard ;; ;; Get upper nibble from keyboard InitKYBD fim SRC_P,KYBD_HIGH_PORT ; Select keyboard upper nibble port src SRC_P ; Send out keyboard upper nibble port selection rdr ; Get the upper nibble ;; Get lower nibble from keyboard fim SRC_P,KYBD_LOW_PORT ; Select keyboard lower nibble port src SRC_P ; Send out keyboard lower nibble port selection rdr ; Get lower nibble bbl REPORT_SUCCESS ; All done, return