project 4

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

project 4

sebbi2005
hello everyone. I would be grateful to all if you can tell me what should be modified in project 4, fill.asm file if i want the screen to be blak not pressing any key, but pressing a specific key from keyboard..it doesn t matter which one...
By default, if you press any key, screen become black, but i want to be black only when i press a specific key...

the cod is this>
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/04/Fill.asm

// Runs an infinite loop that listens to the keyboard input.
// When a key is pressed (any key), the program blackens the screen,
// i.e. writes "black" in every pixel;
// the screen should remain fully black as long as the key is pressed.
// When no key is pressed, the program clears the screen, i.e. writes
// "white" in every pixel;
// the screen should remain fully clear as long as no key is pressed.

// Put your code here.

// First, a simpler program the just fills the entire screen
//@counter
//M=-1
//(LOOP)
//@counter
//M=M+1
//D=M
//@SCREEN
//A=A+D
//M=-1
//@8192
//D=D-A
//@LOOP
//D;JNE
//... this fills the screen with black but stops with err msg: Can't continue past last line

(BEGIN)    

@KBD
D=M
@BLACK
D;JNE
@WHITE
D;JEQ

(BLACK)
@counter    
M=-1
(LOOP)
@counter
M=M+1
D=M
@SCREEN
A=A+D
M=-1
@8191
D=D-A
@LOOP
D;JNE      
@BEGIN
0;JMP


(WHITE)
@counterwhite    
M=-1
(LOOPWHITE)
@counterwhite
M=M+1
D=M
@SCREEN
A=A+D
M=0
@8191
D=D-A
@LOOPWHITE
D;JNE      

@BEGIN      
0;JMP




thank you
Reply | Threaded
Open this post in threaded view
|

Re: project 4

WBahn
Administrator
Examine your code and see why it becomes black when any key is pressed. How does the code know that a key is pressed? What would be different about that condition if, say, the 'B' key was pressed as opposed to the 'W' key?
Reply | Threaded
Open this post in threaded view
|

Re: project 4

sebbi2005
this is what i am trying to find....that s why i asked for your help...Thank you, maybe someone will tell me what dhould i do in order to solve the problem
Reply | Threaded
Open this post in threaded view
|

Re: project 4

ivant
This whole course is done in order for people to learn something valuable. If WBahn or somebody else just solves your problem what would you learn? I think very little.

Instead they are trying to guide you in the right direction without directly saying "this is the problem and this is how to fix it". Try to read the questions again and to actually answer them based on what your code does.
Reply | Threaded
Open this post in threaded view
|

Re: project 4

sebbi2005
Whenever a key is pressed on the physical keyboard, its 16-bit ASCII code appears in
RAM[24576]. When no key is pressed, the code 0 appears in this location..but how to tell to the program that down arrow is pressed for example? where shoud i put its code 133 (down arrow code)..?
Reply | Threaded
Open this post in threaded view
|

Re: project 4

WBahn
Administrator
Instead of checking if the value at RAM[24576]  is not zero, just check if it is 133 (or whatever code you are interested in).