Branches can go between 129 bytes forward and 126 bytes backwards, and 197 bytes forward is out of range.

Ah ok, thanks lidnariq!! Why is it limited to 129 bytes forward? It uses positive and negative numbers maybe... so oh ok, windows 10 calculator in programmer's mode is fantastic!! So if... how does that work? How does it differentiate between forwards and backwards? Well, it must use positive and negative numbers... I remember it using negative numbers when it went backwards. But 129 is 1000 0001 and 126 is 0111 1110... but it's confusing to me beyond the fact that those two numbers are inverses. Help? *NVM tepples answered!

tepples wrote:

That's 129 bytes forward or 126 bytes backward from the address of the branch instruction's opcode. The apparent imbalance is because the offset is actually measured from the address of the opcode that would be executed if the branch were not taken, and it has the typical range of an 8-bit signed integer: 127 bytes forward or 128 bytes backward.

I'm trying to get a new screen to load when our lady reaches the top of the screen (oY == 00). Almost everything works; as soon as oY reaches 00, currFloor is decremented and stairs is jsred. Stairs tries to disable vblank by anding my copy of $2000 with #01111111b. Then see is jsred correctly.

The only problem is that see never finishes because a vblank is activated and see is called again... the hex editor shows the stack is constantly decremented because see keeps being run because vblanks keep being called.

My function see sets up the screens before the game starts. It works wonderfully. Do you have any advice for me to turn off vblanks successfully? I have found where the wiki advises reading $2002 before turning on bit 7 of $2000, but I`m trying to turn bit 7 of $2000 off.

I'm of the opinion that it's better to leave NMIs always on and control what happens each vblank entirely in software. You can even use the shadow $2001 register to detect when rendering is off, in which case the vblank handler skips all code related to the PPU (after updating register $2001 with the shadow value, that is), so it doesn't interfere with any PPU operations the main thread may be doing (e.g. large updates between levels), but still updates the APU so that music and sound effects aren't interrupted by screen transitions.

If you wanted to disable rendering for a big update using this method, you'd first change the $2001 shadow value, and then wait for vblank (using whatever communication system you have between the main thread and the NMI thread), when $2001 will effectively be written to and rendering will be disabled. From then on you can update VRAM freely (keep in mind that palette and OAM updates should only take place during vblank, to completely avoid colorful glitches and OAM corruption), because the NMI thread will know not to do any PPU operations other than copying the shadow $2001 value to register $2001, a write that should be harmless even if it interrupts other PPU operations the main thread might be doing.

So I need to wait for NMI so soft2001shadow can be copied to $2001 because then rendering will be disabled. And that will help me to be able to run see in the main thread! That`s so cool!

Is it ok to just set $2001 each vblank without checking first to see if I can? All the pointless cycles wasted; it makes me so happy to not waste cycles. Thank you tokumaru for all of your wisdom you share.

Is it ok to just set $2001 each vblank without checking first to see if I can?

As far as I know, yes. Writing to $2001 shouldn't have any undesirable side effects, even if it happens in the middle of other PPU operations. But you do need to test whether rendering is on or off to decide whether to do other potentially dangerous PPU operations (updating VRAM, setting the scroll, etc.). Your NMI handler could contain something like this:

Is it ok to just set $2001 each vblank without checking first to see if I can?

As far as I know, yes. Writing to $2001 shouldn't have any undesirable side effects, even if it happens in the middle of other PPU operations. But you do need to test whether rendering is on or off to decide whether to do other potentially dangerous PPU operations (updating VRAM, setting the scroll, etc.). Your NMI handler could contain something like this:

Thank you tokumaru for this extra help! Someone recommended I name my 2001 shadow variable soft2001; I also like your PPUMaskShadow but soft2001 is less characters. That won't affect the ROM size, but it will cause my trace log files to be smaller when I want to write the variable name before its address; that helps me to quickly read through certain sections of code when I return to the file.

edit: I made a mistake. I posted somewhere that trace log files would be smaller if they were recorded before hitting frame 1000, but that isn't true because there are 6 characters allotted for the frame #. If it is frame 1 then there's a "1" followed by five spaces. I didn't notice this when I made that untrue statement; I'm sorry. I'm using FCEUX 2.2.2

The reason why ($XX, x) is rarely used is because it can't index the target data in any way. Once the address of the pointer is calculated ($XX + x) and the pointer is used, the target is a single byte. There's no way to access any bytes after that one. If you do wish to access the next bytes, you have to manipulate the pointer itself (INC the lower byte, if it overflows INC the higher byte), which is terribly slow.

But if you do have an array of pointers, such as one pointer for each sound channel, and you only consume a few bytes per frame, 10.02 cycles per increment (INC ptr,x BNE :+ INC ptr+1,x : ) isn't too much slower than 5.02 cycles per increment for (d),y (INY BNE :+ INC ptr+1 : ).

Who is online

Users browsing this forum: Yahoo [Bot] and 7 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum