Sunday, August 17, 2014

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

Keep that source file open, because it's time we dive into what all is going on in the code!

Now, I may have placed almost 100 lines of comments inside the code, but there's a large change you still don't understand exactly what's going on in some places. So let's go piece by piece. You most likely won't need to read every little bit of this post, but if there's something you don't understand then this will be a nice place to head back to for tips.

I had started off a little lazy, without thinking to give too good an explanation of what goes on inside the memory map and rom bank map. So here's a little bit of information.
See, the rom is built up of banks containing data. You can only see so much of one bank at a time on the SMS, which is why later on you'll be learning the concept of paging. Each bank comes with the exact same slots, located in the memory map. Slot 0 is the main code, and slot 1 is the ram built into the console. You'll learn why ram gets its own slot later on.

We won't be getting into this, as, well, it's true. SDSC is something that was originally made on the SMSPower forums, and these days people use it just to stay organized. If you make a rom smaller than 32 kilobytes, you can't use an .sdsctag, which is fine.

This clearly wasn't explained too well. See, the standard ASCII table goes from " " to "~". Our font does the same thing. Since " " is equal to 0 in .db (raw data) format and "!" is equal to 1, we can easily say .asc "Hi" and it would be automatically translated to its corresponding numerical values. Isn't WLA wonderful sometimes?

There isn't much to say about this, as it's true. .bank 0 slot 0 puts the following code in bank 0 and slot 0. Need I say more?

Now THIS is one big chunk of data. .org $0 puts the following code at location 0, which is simple. di does what the comments say. Keep in mind, however, that this is only true if VBlank interrupts are turned on. We'll cover this later on.

This is a little complicated. Remember earlier, when we used ld sp, $dff0? Well, $dff0 is the location where af's data will be pushed to, and popped back out of. It's called the stack, and man will it come in handy. $bf is the hardware port for the VDP's control, and it's where interrupts are basically made. in a,[$bf] is placing the port's data into a, which tells the VDP that the interrupt has been handled. Not doing this could cause bad things to happen, but I'd rather you try that out on your own time.

Ever wonder what happens when you press the pause button on the SMS? Me neither. What happens, though, is that the system goes to $66, and placing retn there is basically saying to go back to the code that was being run before. So, basically nothing.

There's not much to say about this. It's true.

Do you recognize $bf from earlier? Yup, I know I do. It's VDP stuff. VDPInitEnd-VDPInit basically subtracts the end of the init code from the beginning, which loads b with the exact amount of bytes that need to be loaded into the hardware port $bf.


Is anyone else kind of coded out right now? I know I am, so let's go ahead and split this up into 2 parts. I suggest you read over this a few times. Anyway, see you next time, in HTPTSMS Part 4: A Look Into The Depths [2].

No comments:

Post a Comment