Gameboys
So I started trying out to work on a game boy again. This time for sure I will get it done :D.
This project has been on my mind for quite awhile now, but I never get it to render stuff properly. And gave up.
This time it seems like I finally got enough skill and patient to pull it off.
I started with coding the PPU (Picture Processing Unit)
[1, 2, 3] [4, 5, 6] [7, 8, 9] [10, 11, 12] [13, 14, 15] [16, 17, 18]
So i need to figure out how it renders the image right?
It seems like the PPU read ram starting at 0x8000, and it reads 2 bytes every time to create different shade of colors.
I have been spending time writing how it renders, and it don on me that it render tiles. First i was doing 8 cols, then increase the row by 1, but that is not how scan line works.
It should render the whole line and then go to the next row, and not trying to increase any row.
Row means each of the horizontal lines, and col is the vertical lines.
The program should (in my opinion), renders 2 bytes (16 bits) every time the loop in render runs.
It rendered but something is not right, there are more pixel being added at the bottom of the "screen"
My render loop is adding more pixel to the "screen", which is an unintended behaviour. The loop runs from 0x8000 to 0x87FF, so about 2048 addresses. But we are reading at speed of 16 bits here, so the loop will need to skip one.
for (let i = 0x8000; i <= 0x87FF; i += 2) {
// Why +2???
// I want to read 16 bits to render 1 single column of a tile of 8x8
}
That mean we got 2048 / 2 = 1024 iterations.
If we takes that 1024 and divide it by 64, we should get 16 tiles? That didnt sounds right to me.
It said in the doc, i should see 0–127 tiles. Im a bit confused here
My appoach is incorrect, I think I should go for every tile, one by one
for (let i = 0x8000; i <= 0x87FF; i += 128) {
// 128 bytes for a tile of 8x8 pixels (2 bytes per pixel???)
}
Im soooo confused at this point. But I think I am going the correct route. It will require 128 bytes to render 1 tiles (1 col 16 bits 2 bytes), so 1 tile would need 8 rows to make an 8x8 pixels. So I would need 128 bits, which is 16 bytes. It would make sense to have for loop going every 16 bytes
for (let i = 0x8000; i <= 0x87FF; i += 16) {
// 16 bytes for a tile of 8x8 pixels (2 bytes per 8 pixel)
}
This would mean the for loop will go 128 times, which makes sense, rendering 128 tiles for this block of memory!
Still couldnt figure out how to deal with this rendering problem. However I am trying to break the problem down to a smaller scale, and then solve the small scale first
1 | 2 | 3 | 4 | 5 | 6 |
---|---|---|---|---|---|
7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 |
31 | 32 | 33 | 34 | 35 | 36 |
Let say I have 3x3 tile, tileId 0, col 0, row 0 will give me 1. Hmm.