6502 - Menu Driven Color selector (October Blog)

I recently worked on 6502 assembly program, this program was based on number guessing game. In this program, I learned to take user input, handle strings,  perform mathematical operations. Here is the link to the blog about the program - Number Guesser


After completing the program, I tried to practice writing more 6502 assembly commands. In order to practice more, I thought of making a menu driven color selector program which will display color on bitmap display according to user input. 


First of all, program will handle the user input, I decided to take single digit input from (0-9). User can press enter to select the option, or user can press backspace to reenter the number. Program will display the color menu in the text output screen. When user will enter an option, color on the whole bitmap will change. 


Here is the menu:

Here is the code for the program: 

; 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 		INPUT		$2001 ; to store the input
define 		COLOR		$2000; to store the color code

	LDA #$00
	STA INPUT
	JSR SCINIT

INSTUCT:
	LDA INSTUCT_TEXT, Y
	BEQ DONE_INSTRUCT
	JSR CHROUT
	INY
	BNE INSTUCT

DONE_INSTRUCT:
	LDY #$00
	JSR PROMPT_CHAR

INSTUCT_TEXT:
	dcb  "E","n","t","e","r",30,
	dcb "F","r","o","m",30,
	dcb "t","h","e",30,
	dcb "f","o","l","l","o","w","i","n","g",":",30, $0d
	dcb "0",30,"-",30,"B","l","a","c","k",$0d
	dcb "1",30,"-",30,"W","h","i","t","e", $0d
	dcb "2",30,"-",30,"R","e","d", $0d
	dcb "3",30,"-",30,"C","y","a","n",$0d
	dcb "4",30,"-",30,"P","u","r","p","l","e",$0d
	dcb "5",30,"-",30,"G","r","e","e","n",$0d
	dcb "6",30,"-",30,"B","l","u","e",$0d
	dcb "7",30,"-",30,"Y","e","l","l","o","w",$0d
	dcb "8",30,"-",30,"O","r","a","n","g","e",$0d
	dcb "9",30,"-",30,"B","r","o","w","n",$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 INPUT
	SBC #$30
	
	

	STA COLOR

	LDA #$00	
	STA $40		
	LDA #$02	
	STA $41		
	LDA COLOR	
	LDY #$00	
LOOP:	
	STA ($40),y	
	INY		
	BNE LOOP	
	INC $41		
	LDX $41		
	CPX #$06	
	BNE LOOP
	LDA #$0d
	JSR CHROUT
	LDY $00
	JMP PROMPT_CHAR

Here are some outputs of the program:




Comments

Popular posts from this blog

Review of 2 Open Source Softwares

Final Implementation of SPO600 Project - Stage III

Testing for Stage II for Project