How to enter an inifinte loop to take keyboard entry

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to enter an inifinte loop to take keyboard entry

kraftwerk1611
Hi all,

My understanding of keybaord part of Project 4 is following. Please correct me if it is wrong.

"The program has to enter an infinite loop that keeps looking for keybaord input. And when user clicks any key it should start executing a code that blackens the whole screen. When user releases the key the code should execute to turn all screen pixels white"

My question is how to enter in such an infinite loop to keep checking keyboard keys press events?

So far I have been ending my programs on inifinite loop of the type
(END)
@END
0;JMP

Should I replace above loop in in Fill.asm file with some other loop? How that loop should be implemented?

Thanks for any reply.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to enter an inifinte loop to take keyboard entry

ybakos
HI Kraftwerk1611,
First, the technique of:

(END)
@END
0; JMP

Is just a conventional Hack way of ending a program such that it never terminates. Rather, the program just loops at the end indefinitely.

But, this doesn't mean that all programs should end this way.

I'll give you a hint. The program should indeed engage in an infinite loop: it should always be painting the screen one color or another.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to enter an inifinte loop to take keyboard entry

cadet1620
Administrator
In reply to this post by kraftwerk1611
kraftwerk1611 wrote
"The program has to enter an infinite loop that keeps looking for keybaord input. And when user clicks any key it should start executing a code that blackens the whole screen. When user releases the key the code should execute to turn all screen pixels white"
Another thing that can help is to write out pseudo code for the program. Start by translating the above description into
while(true) {
    if key_code != 0
        draw black
    else
        draw white
}
--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to enter an inifinte loop to take keyboard entry

kraftwerk1611
Thanks for the replies.

I implemented the keybaord and when I run it manually and with Fill.tst script it seems to be running fine. The screen turns black when a key is pressed and turns white when it is released.

However when i run it test it with Fill_atomatic.tst script it fails. I seems that when key is released by automatic script then the screen is not going white again.

This is not what I see when I run the program manually or with Fill.tst script. When doing manually when I release the key the screen turns white as expected.

Can you give me some hint what could be causing this.

I am pasting Compare.tst and Output file below.

Thanks.



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to enter an inifinte loop to take keyboard entry

cadet1620
Administrator
Due to the scrolling bug in the simulator it is difficult to see the right end of the lines in the compare and output files.

FillAutomatic.cmp:
|RAM[16384]|RAM[17648]|RAM[18349]|RAM[19444]|RAM[20771]|RAM[21031]|RAM[22596]|RAM[23754]|RAM[24575]|
|       0  |       0  |       0  |       0  |       0  |       0  |       0  |       0  |       0  |
|      -1  |      -1  |      -1  |      -1  |      -1  |      -1  |      -1  |      -1  |      -1  |
|       0  |       0  |       0  |       0  |       0  |       0  |       0  |       0  |       0  |

Look at your actual FillAutomatic.out file with a text editor. I suspect that you are not setting RAM[24575] to -1. "Off by 1" errors are a common source of bugs.

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to enter an inifinte loop to take keyboard entry

kraftwerk1611
Thank you Mark. That indeed was the case. The the register RAM[24575] was not being updated.

Loading...