;; Emacs Mode Selection Info: -*-mode: ASM; coding: iso-latin-1-dos;-*- * ;; ******************************************************************************************** ;; File Name: DisCont.inc ;; Auther: John L. Weinrich ;; Date: 04/17/03 ;; Useage 4004 TIC-TAC-TOE Game ;; Description: ;; ;; This is an include file that contains the display control routines. ;; ;; ;; See "4004 FPGA Design" and "4004 Software Design " documents for more detail information. ;; ;; Registers used: SCRATCH_0_L, SCRATCH_0_H, SCRATCH_0_P, SRC_P, UTILITY_1_L, UTILITY_1_H, ;; ARRAY_PTR_L, ARRAY_PTR_H, ARRAY_PTR_P, SCRATCH_1_L, SCRATCH_1_H, SCRATCH_1_P, ;; UTILITY_1_L, UTILITY_1_H ;; Memory used: DIS_ONOFF_CONT_L_RAM, DIS_ONOFF_CONT_H_RAM, MISC_RAM_SHADOW ;; Entrance parameters: DisSetLineCol: UTILITY_1_H, UTILITY_1_H ;; Exit parameters: Accumulator, success, failure ;; Labels used: WaitForDisplay, WaitTillBlue, More, InitDisplay, ClearDisplay, OnDisplay, ;; OffDisplay, OnCurDisplay, OffCurDisplay, CurBlinkOnDis, CurBlinkOffDis, HomeDisplay, ;; DisplayModeData, DisplayModeCMND, DisSetLine1, DisSetLine2, DisSetLine3, DisSetLine4, ;; DisSetLineCol, SetCGRAM, SetDDRAM, LoadCGRAM, Continue5, NoRollover5, EndOfCGRAM, ;; CG_RAM_Char1, CG_RAM_Char2, CG_RAM_Char3, CG_RAM_Char4, CG_RAM_Char5, CG_RAM_Char6, ;; CG_RAM_Char7, CG_RAM_Char8 ;; Routines used: Wait ;; ******************************************************************************************** ;; Wait for display ready routine ;; Preset error counter and check for a display that does not respond WaitForDisplay fim SCRATCH_0_P,00H ; Preset error counter WaitTillBlue isz SCRATCH_0_L,More ; Increment lower nibble of and check for rollover isz SCRATCH_0_H,More ; Increment upper nibble and check for rollover bbl REPORT_FAILURE ; Error counter rolled over, return with error ;; Read lower nibble from display More fim SRC_P,DISPLAY_LOW_PORT ; Select display port lower nibble src SRC_P ; Send out display port lower nibble port selection rdr ; Read display port lower nibble ;; Read upper nibble from display fim SRC_P,DISPLAY_HIGH_PORT ; Select display port upper nibble src SRC_P ; Send out display port upper nibble port selection rdr ; Read display port upper nibble ral ; Move busy bit to carry location jcn C,WaitTillBlue ; Test if display is ready. If not loop till ready bbl REPORT_SUCCESS ; Display is ready, return to caller ;; ******************************************************************************************** ;; This is the initialize display subroutine. This routine has two entry points to support ;; initialization and clearing the display. ;; ;; Wait greater than 15 mS for display to stablize InitDisplay jms Wait ; Make sure the display has time to stablize ;; Send first function set command fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address ldm DISPLAY_FCN1_CMND_H ; Get upper nibble data wrr ; Write upper nibble to display port fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address ldm DISPLAY_FCN1_CMND_L ; Get lower nibble data wrr ; Write lower nibble to display port ;; Wait greater than 4.1 mS jms Wait ; Per display manual ;; Send second function set command fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address ldm DISPLAY_FCN1_CMND_H ; Get upper nibble data wrr ; Write upper nibble to display port fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address ldm DISPLAY_FCN1_CMND_L ; Get lower nibble data wrr ; Write lower nibble to display port ;; Wait greater than 100 umS jms Wait ; Per display manual ;; Send third function set command fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address ldm DISPLAY_FCN1_CMND_H ; Get upper nibble data wrr ; Write upper nibble to display port fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address ldm DISPLAY_FCN1_CMND_L ; Get lower nibble data wrr ; Write lower nibble to display port ;; Wait for busy flag to assert jms WaitForDisplay ; ;; Issue a Function Set Command with 2 line display and 5X7 dots fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address ldm DISPLAY_FCN2_CMND_H ; Get upper nibble data wrr ; Write upper nibble to display port fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address ldm DISPLAY_FCN2_CMND_L ; Get lower nibble data wrr ; Write lower nibble to display port ;; Wait for busy flag to assert jms WaitForDisplay ; ;; Issue a display off command fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address ldm DISPLAY_OFF_CMND_H ; Get upper nibble data wrr ; Write upper nibble to display port fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address ldm DISPLAY_OFF_CMND_L ; Get lower nibble data wrr ; Write lower nibble to display port ;; Wait for busy flag to assert jms WaitForDisplay ;; Issue a clear display command ClearDisplay fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address ldm DISPLAY_CLEAR_CMND_H ; Get upper nibble data wrr ; Write upper nibble to display port fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address ldm DISPLAY_CLEAR_CMND_L ; Get lower nibble data wrr ; Write lower nibble to display port ;; Wait for busy flag to assert jms WaitForDisplay ; ;; Issue a entry mode set command with increments DD RAM and no display shift fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address ldm DISPLAY_MODE_CMND_H ; Get upper nibble data wrr ; Write upper nibble to display port fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address ldm DISPLAY_MODE_CMND_L ; Get lower nibble data wrr ; Write lower nibble to display port ;; Wait for busy flag to assert jms WaitForDisplay ; ;; Issue a display on command with display cursor and cursor blink fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address ldm DISPLAY_ON_CMND_H ; Get upper nibble data wrr ; Write upper nibble to display port fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address ldm DISPLAY_ON_CMND_L ; Get lower nibble data wrr ; Write lower nibble to display port ;; Wait for busy flag to assert jms WaitForDisplay ; ;; Return to caller bbl REPORT_SUCCESS ; All done, return ;; ******************************************************************************************** ;; This subroutine turns on the display ;; Wait for busy flag to assert OnDisplay ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,DIS_ONOFF_CONT_H_RAM ; Get Display on/off control state high storage address src SRC_P ; Send out Display on/off control state high storage address rdm ; Get Display on/off control state fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address wrr ; Write upper nibble to display port ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,DIS_ONOFF_CONT_L_RAM ; Get Display on/off control state low storage address src SRC_P ; Send out Display on/off control state low storage address rdm ; Get Display on/off control state ral ; Select display on/off bit ral ; "" stc ; Set display on/off bit to turn diplay on rar ; Deselect display on/off bit rar ; "" wrm ; Save display on/off control state fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address wrr ; Write lower nibble to display port ;; Return to caller bbl REPORT_SUCCESS ; Return to caller ;; ******************************************************************************************** ;; This subroutine turns off the display ;; Wait for busy flag to assert OffDisplay ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,DIS_ONOFF_CONT_H_RAM ; Get Display on/off control state high storage address src SRC_P ; Send out Display on/off control state high storage address rdm ; Get Display on/off control state fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address wrr ; Write upper nibble to display port ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,DIS_ONOFF_CONT_L_RAM ; Get Display on/off control state low storage address src SRC_P ; Send out Display on/off control state low storage address rdm ; Get Display on/off control state ral ; Select display on/off bit ral ; "" clc ; clear display on/off bit to turn diplay off rar ; Deselect display on/off bit rar ; "" wrm ; Save display on/off control state fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address wrr ; Write lower nibble to display port ;; Return to caller bbl REPORT_SUCCESS ; Return to caller ;; ******************************************************************************************** ;; This subroutine turns on the display cursor ;; Wait for busy flag to assert OnCurDisplay ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,DIS_ONOFF_CONT_H_RAM ; Get Display on/off control state high storage address src SRC_P ; Send out Display on/off control state high storage address rdm ; Get Display on/off control state fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address wrr ; Write upper nibble to display port ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,DIS_ONOFF_CONT_L_RAM ; Get Display on/off control state low storage address src SRC_P ; Send out Display on/off control state low storage address rdm ; Get Display on/off control state rar ; Select display cursor control bit rar ; "" stc ; Set display on/off bit to turn diplay on ral ; Deselect display cursor control bit ral ; "" wrm ; Save display on/off control state fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address wrr ; Write lower nibble to display port ;; Return to caller bbl REPORT_SUCCESS ; Return to caller ;; ******************************************************************************************** ;; This subroutine turns off the display cursor ;; Wait for busy flag to assert OffCurDisplay ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,DIS_ONOFF_CONT_H_RAM ; Get Display on/off control state high storage address src SRC_P ; Send out Display on/off control state high storage address rdm ; Get Display on/off control state fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address wrr ; Write upper nibble to display port ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,DIS_ONOFF_CONT_L_RAM ; Get Display on/off control state low storage address src SRC_P ; Send out Display on/off control state low storage address rdm ; Get Display on/off control state rar ; Select display cursor control bit rar ; "" clc ; Clear display on/off bit to turn diplay off ral ; Deselect display cursor control bit ral ; "" wrm ; Save display on/off control state fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address wrr ; Write lower nibble to display port ;; Return to caller bbl REPORT_SUCCESS ; Return to caller ;; ******************************************************************************************** ;; This subroutine enables the display cursor blink ;; Wait for busy flag to assert CurBlinkOnDis ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,DIS_ONOFF_CONT_H_RAM ; Get Display on/off control state high storage address src SRC_P ; Send out Display on/off control state high storage address rdm ; Get Display on/off control state fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address wrr ; Write upper nibble to display port ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,DIS_ONOFF_CONT_L_RAM ; Get Display on/off control state low storage address src SRC_P ; Send out Display on/off control state low storage address rdm ; Get Display on/off control state rar ; "" stc ; Set display cursor blink bit to turn cursor blink on ral ; "" wrm ; Save display on/off control state fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address wrr ; Write lower nibble to display port ;; Return to caller bbl REPORT_SUCCESS ; Return to caller ;; ******************************************************************************************** ;; This subroutine disables the display cursor blink ;; Wait for busy flag to assert CurBlinkOffDis ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,DIS_ONOFF_CONT_H_RAM ; Get Display on/off control state high storage address src SRC_P ; Send out Display on/off control state high storage address rdm ; Get Display on/off control state fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address wrr ; Write upper nibble to display port ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,DIS_ONOFF_CONT_L_RAM ; Get Display on/off control state low storage address src SRC_P ; Send out Display on/off control state low storage address rdm ; Get Display on/off control state rar ; "" clc ; Set display cursor blink bit to turn cursor blink off ral ; "" wrm ; Save display on/off control state fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address wrr ; Write lower nibble to display port ;; Return to caller bbl REPORT_SUCCESS ; Return to caller ;; ******************************************************************************************** ;; This subroutine sets the display cursor to home HomeDisplay fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address ldm DISPLAY_HOME_CMND_H ; Get upper nibble data wrr ; Write upper nibble to display port fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address ldm DISPLAY_HOME_CMND_L ; Get lower nibble data wrr ; Write lower nibble to display port ;; Return to caller bbl REPORT_SUCCESS ; All done, return ;; ******************************************************************************************** ;; This subroutine sets the display mode bit to data in the MISC port and updates the MISC ;; port shadow RAM. ;; DisplayModeData ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,MISC_RAM_SHADOW ; Select MISC port RAM shadow charactor src SRC_P ; Tell RAM of selection rdm ; Get MISC port shadow data from RAM rar ; Select the display mode bit in MISC port stc ; Set display mode bit to data mode ral ; Restore nibble, de-select display mode bit wrm ; Write MISC port shadow back to RAM fim SRC_P,MISC_PORT ; Select MISC port src SRC_P ; Tell MISC port it is selected wrr ; Update the MISC port to shadow setting bbl REPORT_SUCCESS ; All done, return ;; ******************************************************************************************** ;; This subroutine sets the display mode bit to command in the MISC port and updates the MISC ;; port shadow RAM. ;; DisplayModeCMND clb ldm RAM_BANK_0 ; Select RAM bank 0 dcl ; Send out RAM bank selection fim SRC_P,MISC_RAM_SHADOW ; Select MISC port RAM shadow charactor src SRC_P ; Tell RAM of selection rdm ; Get MISC port shadow data from RAM rar ; Select the display mode bit in MISC port clc ; Set display mode bit to command mode ral ; Restore nibble, de-select display mode bit wrm ; Write MISC port shadow back to RAM fim SRC_P,MISC_PORT ; Select MISC port src SRC_P ; Tell MISC port it is selected wrr ; Update the MISC port to shadow setting bbl REPORT_SUCCESS ; All done, return ;; ******************************************************************************************** ;; This sets the display to line number 1 ;; DisSetLine1 jms DisplayModeCMND jms WaitForDisplay fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address ldm DISPLAY_LINE1_CMND_H ; Get upper nibble data wrr ; Write upper nibble to display port fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address ldm DISPLAY_LINE1_CMND_L ; Get lower nibble data wrr ; Write lower nibble to display port ;; Return to caller bbl REPORT_SUCCESS ; All done, return ;; ******************************************************************************************** ;; This sets the display to line number 2 ;; DisSetLine2 jms DisplayModeCMND jms WaitForDisplay fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address ldm DISPLAY_LINE2_CMND_H ; Get upper nibble data wrr ; Write upper nibble to display port fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address ldm DISPLAY_LINE2_CMND_L ; Get lower nibble data wrr ; Write lower nibble to display port ;; Return to caller bbl REPORT_SUCCESS ; All done, return ;; ******************************************************************************************** ;; This sets the display to line number 2 ;; DisSetLine3 jms DisplayModeCMND jms WaitForDisplay fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address ldm DISPLAY_LINE3_CMND_H ; Get upper nibble data wrr ; Write upper nibble to display port fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address ldm DISPLAY_LINE3_CMND_L ; Get lower nibble data wrr ; Write lower nibble to display port ;; Return to caller bbl REPORT_SUCCESS ; All done, return ;; ******************************************************************************************** ;; This sets the display to line number 4 ;; DisSetLine4 jms DisplayModeCMND jms WaitForDisplay fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address ldm DISPLAY_LINE4_CMND_H ; Get upper nibble data wrr ; Write upper nibble to display port fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address ldm DISPLAY_LINE4_CMND_L ; Get lower nibble data wrr ; Write lower nibble to display port ;; Return to caller bbl REPORT_SUCCESS ; All done, return ;; ******************************************************************************************** ;; This sets the display to line/column specified in UTILITY_1_P ;; DisSetLineCol jms DisplayModeCMND jms WaitForDisplay fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address ld UTILITY_1_H ; Get upper nibble data wrr ; Write upper nibble to display port fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address ld UTILITY_1_L ; Get lower nibble data wrr ; Write lower nibble to display port ;; Return to caller bbl REPORT_SUCCESS ; All done, return ;; ******************************************************************************************** ;; This subroutine sets the display to CG RAM mode SetCGRAM fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address ldm DISPLAY_CG_ADDRESS_H ; Get upper nibble data wrr ; Write upper nibble to display port fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address ldm DISPLAY_CG_ADDRESS_L ; Get lower nibble data wrr ; Write lower nibble to display port ;; Return to caller bbl REPORT_SUCCESS ; All done, return ;; ******************************************************************************************** ;; This subroutine sets the display to DD RAM mode SetDDRAM fim SRC_P,DISPLAY_HIGH_PORT ; Get upper nibble display port address src SRC_P ; Send out upper display port address ldm DISPLAY_DD_ADDRESS_H ; Get upper nibble data wrr ; Write upper nibble to display port fim SRC_P,DISPLAY_LOW_PORT ; Get lower nibble display port address src SRC_P ; Send out lower display port address ldm DISPLAY_DD_ADDRESS_L ; Get lower nibble data wrr ; Write lower nibble to display port ;; Return to caller bbl REPORT_SUCCESS ; All done, return ;; ******************************************************************************************** ;; This subroutine loads the CG RAM with the custom charactors LoadCGRAM fim SCRATCH_0_P,088h ; Load upper and lower loop counters fim ARRAY_PTR_P,lo(CG_RAM_Char1) ; Get pointer of first byte of charactor Continue5 fin SCRATCH_1_P ; Get a byte of the string xch SCRATCH_1_H ; Get the upper nibble into accumulator 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 xch SCRATCH_1_L ; Get the lower nibble into accumulator 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 isz ARRAY_PTR_L,NoRollover5 ; Increment string pointer & check for roll over inc ARRAY_PTR_H ; Increment upper nibble NoRollover5 isz SCRATCH_0_L,Continue5 ; Continue to out more bytes to display ldm 08h ; Rollover, reload xch SCRATCH_0_L ; Move to counter isz SCRATCH_0_H,Continue5 ; Continue to out more bytes to display EndOfCGRAM bbl REPORT_SUCCESS ; All done, go back CG_RAM_Char1 data 20h,20h,20h,20h,20h,20h,20h,1Fh ; CG RAM Charactor #1 CG_RAM_Char2 data 04h,04h,04h,04h,04h,04h,04h,1Fh ; CG RAM Charactor #2 CG_RAM_Char3 data 04h,04h,04h,04h,04h,04h,04h,04h ; CG RAM Charactor #3 CG_RAM_Char4 data 0Eh,11h,11h,11h,11h,0Eh,20h,1Fh ; CG RAM Charactor #4 CG_RAM_Char5 data 20h,11h,0Ah,04h,0Ah,11h,20h,20h ; CG RAM Charactor #5 CG_RAM_Char6 data 0Eh,11h,11h,11h,11h,0Eh,20h,20h ; CG RAM Charactor #6 CG_RAM_Char7 data 20h,11h,0Ah,04h,0Ah,11h,20h,1Fh ; CG RAM Charactor #7 CG_RAM_Char8 data 20h,20h,20h,20h,20h,20h,20h,20h ; CG RAM Charactor #8