Only the top portion of the screen become black when any key is pressed

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

Only the top portion of the screen become black when any key is pressed

Md. Al-Imran Abir
I have run the code as described in the book. However, when I press a key only a portion (approx 1/15) of the screen blackens. I tried to figure it out but failed. Here is the pseudo-code:


  scradr = SCREEN
  row = 256
  col = 32

INFINITE_LOOP:
  i = 0
  k = KBD
  if k == 0 goto NOT_PRESSED

  PRESSED:
    if i >= row goto INFINITE_LOOP
    j = 0
    PRESSED_INNER_LOOP:
      if j >= col goto BREAK_INNER_LOOP
      RAM[scradr+i+j] = -1
      j = j + 1
      goto PRESSED_INNER_LOOP

    BREAK_INNER_LOOP:
      i = i + 1
      goto PRESSED

  NOT_PRESSED:
    if i >= row goto INFINITE_LOOP
    j = 0
    NOT_PRESSED_INNER_LOOP:
      if j >= col goto BREAK_INNER_LOOP_2
      RAM[scradr+i+j] = 0
      j = j + 1
      goto NOT_PRESSED_INNER_LOOP

    BREAK_INNER_LOOP_2:
      i = i + 1
      goto NOT_PRESSED

Can someone please say how can this be solved?
Reply | Threaded
Open this post in threaded view
|

Re: Only the top portion of the screen become black when any key is pressed

Md. Al-Imran Abir
I have been able to solve it so no need to bother. There was a logical error in the pseudo-code.
Reply | Threaded
Open this post in threaded view
|

Re: Only the top portion of the screen become black when any key is pressed

WBahn
Administrator
Glad you found it.

Was the error neglecting to multiply the row index by the number of words in a row?

Reply | Threaded
Open this post in threaded view
|

Re: Only the top portion of the screen become black when any key is pressed

WBahn
Administrator
Look at the difference between your code segments for pressed and unpressed. What do they differ by? What would it take to combine them into a single code segment? There are a couple of ways to do it.
Reply | Threaded
Open this post in threaded view
|

Re: Only the top portion of the screen become black when any key is pressed

Md. Al-Imran Abir
In reply to this post by WBahn
Yes, you have got it right.
Reply | Threaded
Open this post in threaded view
|

Re: Only the top portion of the screen become black when any key is pressed

Md. Al-Imran Abir
In reply to this post by WBahn
I think a more efficient pseudo-code maybe like this

scradr = SCREEN
row = 256
col = 32

INFINITE_LOOP:

i = 0
k = KBD

for(i = 0; i < row*col; i++)
     if k == 0
         RAM[scradr+i] = 0
     else
         RAM[scradr+i] = 1
end of for

goto INFINITE_LOOP