getting out of screen bounds

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

getting out of screen bounds

itamar_5250
I try to run my code. when I press for too long(or don't press for too long), i get the message:
"Destination is M but A=24577 is an illegal memory address".
The problem is I think I did handle this situation, so why isn't it working?

Here is my code:

//initiallize variables:
@idx_b // black index
M=0
@idx_w // white index
M=0
//loop condition:
(LOOP)
@KBD
D=M
@WHITE_COLOR
D;JEQ


//fill the screen in black color:
@idx_w
M=0
//check if i got to the end of the screen, if true, then return back to the beginning of the loop:
@idx_b
D=M
@KBD
D=D-A
@LOOP
D;JGE
// if i got here, i can fill the current 16 pixels:
@idx_b
D=M
@SCREEN
A=D+A
M=-1
//index+1 and return back to loop:
@idx_b
M=M+1
@LOOP
0;JMP

(WHITE_COLOR)
//fill the screen in white color:
@idx_b
M=0
//check if i got to the end of the screen, if true, then return back to the beginning of the loop:
@idx_w
D=M
@KBD
D=D-A
@LOOP
D;JGE
// if i got here, i can fill the current 16 pixels:
@idx_w
D=M
@SCREEN
A=D+A
M=0
//index+1 and return back to loop:
@idx_w
M=M+1
@LOOP
0;JMP


// (RESETB)
// @idx_b
// M=0
// @LOOP
// 0;JMP

// (RESETW)
// @idx_w
// M=0
// @LOOP
// 0;JMP
Reply | Threaded
Open this post in threaded view
|

Re: getting out of screen bounds

WBahn
Administrator
Is the value stored in idx_b and idx_w an index relative to the start of the screen memory (i.e., low numbers from 0 to 8191), or are they memory addresses (i.e., high numbers from 16384 to 24575)?

A quick glance at your code leaves me to think they are being used differently at different places, so decide how you want them to be interpreted and then make sure that everywhere they are used is consistent with that interpretation.
Reply | Threaded
Open this post in threaded view
|

Re: getting out of screen bounds

itamar_5250
Thank you! your tip helped me to solve my problem
Reply | Threaded
Open this post in threaded view
|

Re: getting out of screen bounds

WBahn
Administrator
Glad I could help.

It often helps to make a little dictionary of your variables detailing exactly what the values they hold mean. Not only does that help others that are reviewing your code, but it gives you something to refer back to and just writing it our can help cement it in your mind.