Sunday, August 17, 2014

HTPTSMS Part 4: A Look Into The Depths [2]

Hope you got a good rest since last time, because we're going to keep it up with the coding.

What's going on, is we're loading hl with $c000, the VDP location for the palette. What we're doing, is we are loading a with hl's lower digits ($00) and throwing them at the VDP, then doing the same with the higher bits ($C0). Note that we had to throw them in reverse order.

This is the same as what we did at some point last time when initializing the VDP. Remember that $be is the port for writing, $bf for setting the address.

What the loop is doing, is it's making a label called -. This is an anonymous label, which we'll cover later on. a is treating hl's value like a point in memory, and getting data from that point. It then feeds the data to the VDP. hl is incremented (hl=hl+1,) bc is decremented (bc=bc-1,) and what happens next is a bit complicated. A takes b's value, and or c basically says, "Check if both a and c are equal to 0". The flag z means true, the flag nz means false. jr nz, - is saying "If not true, go back to -". It's a good way to check if bc is 0.


The reason we're loading hl with $3800|$4000, is because the first two bits of h have to be both 1's. %11000000 = $40, so or'ing them makes the first two bits of 38 equal to 1, turning it to $7800.
There's more than one reason we can't use otir. The text data is set as each letter is one byte, but the screen expects two bytes per tile. otir wouldn't give that extra 00 between each letter, and so it's useless in this case. We could just do it on our own with .asc "H e l l o ! " but it isn't good looking.
So, instead we had to make a loop. It's similar to before, except we also have to throw an extra zero at the VDP. To do this, we set a to 0. A fast way to do this is xor a, which compares a with the accumulator (a, so...itself) and sets it to 0 if it's equal. djnz - means "Decrement b, and if it isn't zero then go back to -".

This is something we'll cover later on, when we actually look at the VDP init data.

This is simple. Enables interrupts, waits a frame and jumps back just to wait another frame.

There's nothing interesting right here. I'm just requiring myself to post all the code.

I had covered earlier on that you should have some fun with the text, so if you weren't paying attention, then hopefully you are now.

While most of this is technical stuff that you shouldn't really worry about, what you should pay attention to is .db 100000,$81. Later on when we wanted to turn the screen on, we set the second bit, in the form of loading a with %01100000 and outing it to $bf, then loading a with $81 and outing it again. This is a more interesting part of how the VDP works. Also notice that VBlank interrupts are on. If they weren't then halt wouldn't wait a frame, and instead would wait for you to manually create an interrupt.

Notice that I was able to get the font data's size with a simple fsize. That's an advantage to the use of raw binary data. .ends is just a directive to end a section.

Yup, that's it. We've looked through the entire source. Before we begin making a slightly more advanced game, however, we'll need to learn some syntax! That will begin next time, in HTPTSMS Part 5: jp's 'n' jr's. Cya then.

No comments:

Post a Comment