LAB - 3 NUMBER GUESSER GAME
LAB 3
I am writing a Lab 3 for my course SPO600. This Lab is about the Math and Strings in 6502 assembly language. This lab was about the graphical output using bitmap screen, text input using keyboard, and text output.
Requirements for this lab was to write a program which should work in 6502 emulator. This program should output on character screen as well as on bitmap screen. User input from keyboard is mandatory for this lab in some form.
For this lab I thought to make a Number Guessing game.
A simple game in which a random number is generated. User will guess the number using hit and trial method. When user will be enter smaller number or larger number than the guess, system will notify the user. By doing this in this game user has to guess the number in shortest number of attempts.
I decided to make this game simple by choosing to guess number between 0-9, only. The user can only input a one digit number. User can use backspace to edit the number entered and user can press enter to confirm the number.
If the number entered by user is smaller, then bitmap screen will display blue color.
If the number entered by user is greater, the bitmap screen will display red color
If the number entered by user is equal, the bitmap screen will display green color.
Here is the code:
; ROM routines
define SCINIT $ff81 ; initialize/clear screen
define CHRIN $ffcf ; input character from keyboard
define CHROUT $ffd2 ; output character to screen
define SCREEN $ffed ; get screen size
define PLOT $fff0 ; get/set cursor coordinates
define NUM $2000 ; to store the number
define INPUT $2001 ; to store the input
LDA #$00
STA INPUT
JSR SCINIT
GET_RANDOM:
LDA $FE
CMP #48
BCC GET_RANDOM
CMP #58
BCS GET_RANDOM
STA NUM
LDY #$00
INSTUCT:
LDA INSTUCT_TEXT, Y
BEQ DONE_INSTRUCT
JSR CHROUT
INY
BNE INSTUCT
DONE_INSTRUCT:
LDY #$00
JSR PROMPT_CHAR
INSTUCT_TEXT:
dcb "I","n","s","t","r","u","c","t","i","o","n","s",$0d
dcb "G","u","e","s","s",32,"t","h","e",32,"n","u","m","b","e","r",
dcb 30,
dcb "b","e","t","w","e","e","n",30,
dcb "0",30,"-",30,"9", $0d
dcb "I","f",30,
dcb "y","o","u","r",30,
dcb "n","u","m","b","e","r",30,
dcb "i","s",30,
dcb "s","m","a","l","l","e","r",30,
dcb "t","h","e","n",30,
dcb "s","c","r","e","e","n",30,
dcb "w","i","l","l",30,
dcb "d","i","s","p","l","a","y",30,
dcb "b","l","u","e",30,
dcb "c","o","l","o","u","r", $0d,
dcb "I","f",30,
dcb "y","o","u","r",30,
dcb "n","u","m","b","e","r",30,
dcb "i","s",30,
dcb "g","r","e","a","t","e","r",30,
dcb "t","h","e","n",30,
dcb "s","c","r","e","e","n",30,
dcb "w","i","l","l",30,
dcb "d","i","s","p","l","a","y",30,
dcb "r","e","d",30,
dcb "c","o","l","o","u","r", $0d,
dcb "I","f",30,
dcb "y","o","u","r",30,
dcb "n","u","m","b","e","r",30,
dcb "i","s",30,
dcb "e","q","u","a","l",30,
dcb "t","h","e","n",30,
dcb "s","c","r","e","e","n",30,
dcb "w","i","l","l",30,
dcb "d","i","s","p","l","a","y",30,
dcb "g","r","e","e","n",30,
dcb "c","o","l","o","u","r", $0d, 00
PROMPT_CHAR:
LDA PROMPT_TEXT, Y
BEQ DONE_PROMPT
JSR CHROUT
INY
BNE PROMPT_CHAR
DONE_PROMPT:
JSR GET_INPUT
PROMPT_TEXT:
dcb "E","n","t","e","r",32,"a",32,"1","-","d"
dcb "i","g","i","t",32,"n","u","m","b","e","r",":",32,$0d
dcb 00
GET_INPUT:
LDA #$A0
JSR CHROUT
LDA #$83
JSR CHROUT
GET_NUM:
JSR CHRIN
CMP #$00
BEQ GET_NUM
CMP #$0D
BNE CHECK_NUM
LDA INPUT
CMP #$00
BNE INPUT_DONE
CHECK_NUM:
CMP #48 ; Compare input with 0
BCC GET_NUM
CMP #58 ; Compare input with 9
BCS GET_NUM
STA INPUT
JSR CHROUT
LDA #$A0
JSR CHROUT
LDA #$83
JSR CHROUT
CHECK_BACKSPACE:
JSR CHRIN
CMP #$00
BEQ CHECK_BACKSPACE
CMP #$0D
BEQ INPUT_DONE
CMP #$08
BEQ BACKSPACE
JMP CHECK_BACKSPACE
BACKSPACE:
LDA #$20
JSR CHROUT
LDA #$83
JSR CHROUT
LDA #$83
JSR CHROUT
LDA #$A0
JSR CHROUT
LDA #$83
JSR CHROUT
JMP GET_INPUT
; COMPARING THE NUMBER
INPUT_DONE:
LDA #$20
JSR CHROUT
LDA #$83
JSR CHROUT
LDA #$0d
JSR CHROUT
LDA INPUT
CMP NUM
BEQ MATCH
CMP NUM
BCC LESS
CMP NUM
BCS MORE
;-- IF NUMBER IS SMALLER
LESS:
LDA #$00
STA $40
LDA #$02
STA $41
LDA #$06
LDY #$00
BLUE_LOOP:
STA ($40),y
INY
BNE BLUE_LOOP
INC $41
LDX $41
CPX #$06
BNE BLUE_LOOP
LDY #$00
JMP PROMPT_CHAR
;--- IF NUMBER IS GREATER
MORE:
LDA #$00
STA $40
LDA #$02
STA $41
LDA #$0a
LDY #$00
RED_LOOP:
STA ($40),y
INY
BNE RED_LOOP
INC $41
LDX $41
CPX #$06
BNE RED_LOOP
LDY #$00
JMP PROMPT_CHAR
; -- IF NUMBER IS EQUAL
MATCH:
LDA #$00
STA $40
LDA #$02
STA $41
LDA #$0d
LDY #$00
GREEN_LOOP:
STA ($40),y
INY
BNE GREEN_LOOP
INC $41
LDX $41
CPX #$06
BNE GREEN_LOOP
BRK
Comments
Post a Comment