# Screen mapping

8 messages
Open this post in threaded view
|
Report Content as Inappropriate

## Screen mapping

 Dear Forum, I'm moving on to Fill.asm On page 70 of the text, in the Screen paragraph, the fourth sentence reads: "Thus the pixel at row r......". Firstly, I'm not sure of the meaning of c%16 and secondly, should the formula for the word location read RAM[16384+r.32+c.16]? Finally, if you'll excuse, am I correct in my understanding that as long as a key is pressed, each bit of the current word needs to be sequentially set to  1? Cheers John Savage
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Screen mapping

 Administrator savage wrote Dear Forum, I'm moving on to Fill.asm On page 70 of the text, in the Screen paragraph, the fourth sentence reads: "Thus the pixel at row r......". Firstly, I'm not sure of the meaning of c%16 and secondly, should the formula for the word location read RAM[16384+r.32+c.16]? Finally, if you'll excuse, am I correct in my understanding that as long as a key is pressed, each bit of the current word needs to be sequentially set to  1? Cheers John Savage "%" means modular division (remainder), so c%16 is the remainder from c divided by 16. RAM[16384 + r·32 + c/16] is correct.  r times 32 gives the address of the first word in row r; c divided by 16 gives the offset to the word containing the bit in column c. For Fill.asm you do not need to set the pixels one bit at a time; do them a word at a time. --Mark
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Screen mapping

 In reply to this post by savage Hi savage, The point is that the 16-bit word at address 16384 (SCREEN) represents the first 16 pixels in the upper left corner of the screen. So if you wanted just the upper left pixel of SCREEN to be black, then the value at address 16384 would have to be 1000000000000000. "as long as a key is pressed, each bit of the current word needs to be sequentially set to  1? " I think you're on the right track, but just to be clear, as long as a key is pressed, Fill.asm should be setting all words between 16384 and 24575 to 1111111111111111. (And what is that in base 10?)
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Screen mapping

 Hello Mark and Ybakos, Thank you very much for your comments. May I summarize please to see if my thinking is correct? The row number, r, is in the range 0,1,...,255 The column number refers to the pixel element in the row and is in the range 0,1,...,511 If, for example, I wanted to access the 40th pixel in row 1, I'd be looking at the (40mod16) 8th element from the left in word 16384 + 32*1 + ? (should be word 16419) I put the ? in because the formula looks as though it could have a fractional value for the word location. If I ignore the notion of accessing individual pixels, I'll press on using your good advice. Thanks John Savage
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Screen mapping

 Administrator Generally, when working with computers at this low level, division is understood to mean integer division with the fractional part rounded towards zero. The bad news is that Hack does not have any hardware support for division.  If you continue through chapter 12 you will write system software to do division. The good news is that you don't need to do any division for Fill.asm. --Mark
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Screen mapping

 Thanks Mark, It's on with the march then.... John Savage
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Screen mapping

 In reply to this post by cadet1620 And in the formula for the Screen word, the first row is indexed as 0? I noticed I get the address for KBD if I muliply 32 by 256. So really the first row for the formula is r=0 and the last is r=255, and the first column is c=1 and the last column is c=512? It's kind of confusing that the r value should start at 0 but the c at 1.