Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

**LOOKING FOR HELP WITH THE SCORE REGISTER AND CONTROL OF THIS MACHINE** Descrip

ID: 3777749 • Letter: #

Question

**LOOKING FOR HELP WITH THE SCORE REGISTER AND CONTROL OF THIS MACHINE**

Description

To start the game, the player presses the reset switch. The score will be set to zero and both the Win and Lose LEDs will be turned off. The player then rolls the die by toggling the Rb switch to the Roll position. The die counter should operate with a clock frequency of 27 MHz or 50 MHz so that the player cannot control the outcome of a roll. After about a second or more, the player toggles the Rb switch back to the Off position to end the roll. The Turn Counter should be incremented to indicate that the player has taken a roll. If the player rolled a six, it is automatically added to his or her score. Otherwise, the player can press the Add button to add the die value to his or her score or the player can press the Pass button to leave the score unchanged. After each roll, the score will be greater than, less than or equal to 15. If the score is equal to 15, the player wins – the Win LED should be turned on and remain on until the system is reset for a new game. If the score is greater than 15, the player loses – the Lose LED should be turned on and remain on until the system is reset. Once the player has won or lost, the player cannot roll the die again until the system is reset. (The Rb switch will not have any effect in these states.) If the score is less than 15, the player will roll again. After each roll, the player presses either the Add button or the Pass button (unless a six is rolled) before the die can be rolled again. Play continues until the player’s score equals or exceeds 15.

Logic Clock 7-segment Turn Counter Enable Clock Displays (27 MHz or 50 MHz) Logic 1-to-6 Die 7-segment Clock Reset switch Counter Roll Rb switch Displays Six Add switch Control Pass switch Adder Lose LED Clock Score Register Load Win LED Display (LEDs) Figure 1. Block diagram of die game

Explanation / Answer

.equ   lcd_horiz_size, 16
.equ   lcd_vert_size, 2
.equ   lcd_bytes_per_line, (128 / lcd_vert_size)

; Misc constants to outline commands offer to the show.
.equ   lcd_clear_cmd, 0x01       ;clears show
.equ   lcd_home_cmd, 0x02       ;put pointer reception position
.equ   lcd_on_cmd, 0x0C       ;turn on show (cursor off)
.equ   lcd_shift_cmd, 0x10
.equ   lcd_config_cmd, 0x38       ;config eight bit, 2 lines, 5x7

; Memory mapped locations to accessing the LCD.
.equ   lcd_command_wr, 0xFE00
.equ   lcd_status_rd, 0xFE01
.equ   lcd_data_wr, 0xFE02
.equ   lcd_data_rd, 0xFE03

; Routines inside PAULMON2 for interacting with the port.
.equ   cout, 0x0030
.equ   cin, 0x0032
.equ   phex, 0x0034
.equ   phex16, 0x0036
.equ   pstr, 0x0038
.equ   newline, 0x0048


; Program header, therefore this program can show up in PAULMON2's menus
.org locat
.db 0xA5,0xE5,0xE0,0xA5 ;signiture bytes
.db 35,255,0,0 ;id (35=prog)
.db 0,0,0,0 ;prompt code vector
.db 0,0,0,0 ;reserved
.db 0,0,0,0 ;reserved
.db 0,0,0,0 ;reserved
.db 0,0,0,0 ;user outlined
.db 255,255,255,255 ;length and substantiation (255=unused)
.db "LCD Test",0 ;max thirty one characters, and the zero
.org locat+64 ;executable code begins here


; Finally, the most program. this easy program prints some
; welcome messages and so enters a loop wherever everything the
; user varieties is displayed on the LCD. A combine of registers track
; the pointer position and also the code repositions the pointer once it
; reaches the proper facet or bottom fringe of the show, so that
; the user's characters can keep displaying somewhere on the LCD.

begin:
   mov   dptr, #mesg_start   ;print a message for the user
   lcall   pstr
   acall   lcd_init
   acall   lcd_clear       ;setup the LCD
   acall   lcd_home
   mov   r4, #0           ;r4/r5 can keep in mind pointer position
   mov   r5, #1
   mov   dptr, #mesg_start_lcd
   acall   lcd_pstr       ;print a message on the LCD prime line
   sjmp   reposition_cursor   ;start the pointer on second line
main_loop:
   lcall   cin           ;get a user keystroke
   cjne   a, #27, main2
   ljmp   0           ;quit if they ironed ESC
main2:   acall   lcd_cout
   inc   r4           ;keep up with pointer position
   cjne   r4, #lcd_horiz_size, main_loop
   mov   r4, #0           ;if right edge, come to left facet
   inc   r5
   cjne   r5, #lcd_vert_size, reposition_cursor
   mov   r5, #0           ;if bottom edge, come to prime line
reposition_cursor:
   mov   a, r4
   mov   r2, a
   mov   a, r5
   mov   r3, a
   acall   lcd_set_xy       ;set the pointer back onto screen
   sjmp   main_loop

mesg_start:
   .db   "Type text to indicate on the display",13,10
   .db   "and press ESC to quit",13,10,0

mesg_start_lcd:
   .db   "Type Something",0


;----------------------------------------------------------------
; General purpose routines for accessing the LCD
;----------------------------------------------------------------

; Print one character in command to the show.

lcd_cout:
   push   dpl
   push   dph
   push   acc
   acall   lcd_busy
   mov   dptr, #lcd_data_wr
   pop   acc
   movx   @dptr, a
   pop   dph
   pop   dpl
   ret


; Print a string @DPTR to the show.

lcd_pstr:
   clr   a
   movc   a, @a+dptr
   inc   dptr
   jz   lcd_pstr_end
   acall   lcd_cout
   sjmp   lcd_pstr
lcd_pstr_end:
   ret


; watch for the show to be prepared for a command or knowledge.

lcd_busy:
   mov   dptr, #lcd_status_rd
lcd_busy_wait:
   movx   a, @dptr
   jb   acc.7, lcd_busy_wait
   ret


; Set the display's pointer position.
; R2 = X position (0 to 15), R3 = Y position (0 to 1)

lcd_set_xy:
   ;check X is inside show size
   mov   a, r2
   add   a, #256 - lcd_horiz_size
   jnc   lcd_set_xok
   mov   r2, #lcd_horiz_size - one
lcd_set_xok:
   ;check Y is inside show size
   mov   a, r3
   add   a, #256 - lcd_vert_size
   jnc   lcd_set_yok
   mov   r3, #lcd_vert_size - one
lcd_set_yok:
   acall   lcd_busy
   ;compute address inside knowledge show ram in LCD controller chip
   mov   a, r3
   mov   b, #lcd_bytes_per_line
   mul   ab
   add   a, r2
   orl   a, #0x80   ;msb set for set Doctor of Divinity RAM address
   mov   dptr, #lcd_command_wr
   movx   @dptr, a
   ret


; Initialize the show to be used.

lcd_init:
   lcall   lcd_busy
   mov   dptr, #lcd_command_wr
   mov   a, #lcd_config_cmd
   movx   @dptr, a
   lcall   lcd_busy
   mov   dptr, #lcd_command_wr
   mov   a, #lcd_on_cmd
   movx   @dptr, a
   lcall   lcd_busy
   mov   dptr, #lcd_command_wr
   mov   a, #lcd_shift_cmd
   movx   @dptr, a
   ret

; Clear the screen.

lcd_clear:
   lcall   lcd_busy
   mov   dptr, #lcd_command_wr
   mov   a, #lcd_clear_cmd
   movx   @dptr, a
   ret

; come the pointer to the house position.

lcd_home:
   lcall   lcd_busy
   mov   dptr, #lcd_command_wr
   mov   a, #lcd_home_cmd
   movx   @dptr, a
   ret