How to get multiple inputs from the emulator

Description

Currently, I'm creating a project where you would have to guess a letter the from the emulator, and I would need the user to enter a random character and the application will let the user know whether they entered a correct character or not. This is what I learnt about how to get an input from a user

Get an input and print it out

In our emulator, if we click the note button, we can see these definitions, we’ll focus on CHRIN and CHROUT today.

 

; 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

 

CHRIN will get an input, and CHROUT will print out whatever character currently stored in the accumulator

Basic input/output

If so then if we need an input, we just need to enter this, right?

JSR CHRIN

Well, this will not work because the program will not wait for your input and it will keep running. As the result, your program will stop even before you can press any button.

To deal with this, we would need to create a for/while loop that keeps running , we can do that by:

LOOP: 
        JSR CHRIN
        JMP LOOP

This will make sure that the program will keep checking whether we have an input or not and it will not stop. If we want to print out all the character we enter, we just need to add JSR CHROUT

LOOP: 
        JSR CHRIN
        JSR CHROUT
        JMP LOOP

Now if you run the program, you notice that every time you enter a character, it would appear randomly instead of next to each other. This is because if we don’t enter anything, the compiler will fill that with blank space instead. That’s why we have characters all over the place. Here is how you can make sure that you only enter uppercase letters:

LOOP: 
        JSR CHRIN
        CMP #65 
        BCC LOOP
 
        CMP #91 
        BCS LOOP 
 
        JSR CHROUT
        JMP LOOP

What’s I’m doing here is that I’ll make sure the program will not print out anything if my input is not in the range of 65 to 91, which is A-Z in ASCII table.

 

 

 

 

 

 

 


Comments

Popular posts from this blog

Project update 1.2

Lab 2 - Letter guessing game