# Confusion About Column Indexing and Bit Selection in Display Unit Graphic (Module 4.5)

4 messages
Open this post in threaded view
|

## Confusion About Column Indexing and Bit Selection in Display Unit Graphic (Module 4.5)

 This post was updated on . I have a little confusion. In the video course (Module 4.5), a graphic of the display unit is shown (at minute 5:15). This map starts counting from column 0 - 511. The calculation "col % 16" is used to determine the bit. If I want to select the first pixel in a row (column 0) and enter a 0 for col in the calculation "col % 16", the result tells me that I should select the 0th bit. There is no bit 0 in a RAM register. But there is a word 0 and a row 0. For example, the first pixel in the top left corner cannot be selected with row 0 and col 0. Instead, row 0 and col 1 must be selected. Example A (row = 0, col = 0) word: 0 x 32 + 0 / 16 = 0 bit: 0 % 16 = 0 Example B (row = 0, col = 1) word: 0 x 32 + 1 / 16 = 0 bit: 1 % 16 = 1 So that the calculation "row x 32 + col / 16" works, there are rows 0 - 255. But the columns in the calculation "row x 32 + col / 16" and "col % 16" are given from 1-512? Is that correct?
Open this post in threaded view
|

## Re: Confusion About Column Indexing and Bit Selection in Display Unit Graphic (Module 4.5)

 I'll try to summarize the logic of the Hack computer screen - Resolution of 512x256 pixels (512 columns in horizontal(x)-direction and 256 rows in   vertical(y) direction) - Each pixel can be either white or black (1 bit "color" depth) - The required video RAM is therefore 512x256x1=131,072 bits=16,384 bytes=8,192 16-bit words   (hereinafter called "word" or "words"). - The address space of the Hack computer is organized in 16-bit words, e.g. each address corresponds to   one word (there are no individual bytes) - The screen memory consists of 8,192 words, starting at base address 16,384 and ending at    address 24,575 (inclusive) - The 16 bits of a word are counted from 0 to 15, therefore bit_0 to bit_15 of a word in the video RAM   represent 16 pixels.   There is no bit 0 in a RAM register.   I'm not sure what you mean by that? Each RAM register on the Hack platform contains 16 bits. - The video RAM is organized in a way that 16 consecutive horizontal pixels are represented by one word - There are 512/16=32 words per row - There are 256 rows - To calculate the address inside the video RAM, you need to    1. consider in which row you are, since every row consists of 32 words: -> row x 32 (usually y*32)    2. consider in which word inside the row you are, since every word contains 16 horizontal pixels:        -> col / 16 (usually x/16)        With x going from 0 to 511 the result is a value from 0 to 31, which tells you in which        of the 32 words per row you are (see above)    3. consider the base address -> +16384 (reserved word in the Assembler: SCREEN)    4. Add all together: address=16384 + (y * 32) + (x/16)                                 // Jack requires the brackets for the right precedence    - To calculate the bit position inside the word, you take the remainder of 16       -> col % 16 (usually x%16)       This will result in a value from 0 to 15, corresponding to bit_0 to bit_15 of the respective word.