#9619 - Domovoi - Mon Aug 11, 2003 12:32 am
Hi there. I'm testing some interrupt code I've been writing, and I noticed an oddity while doing so. I normally run my compiled code in BoycottAdvance (because it starts faster), but when I want to check tile data and such, I use VisualBoy Advance.
However, when I run the same .bin in both emulators, they don't yield the exact same result. BCA displays things fine, while VBA messes up the background map.
Here's what I'm doing: I wrote an interrupt handler in C, which scrolls background 0 (using he BG0VOFS register) to various positions when reaching certain scanlines. So at line 0 it's scrolled to a certain point, then at line 8 it's scrolled to somewhere else, then on 16, it is scrolled on the position 'it should be'. (in other words, the top two rows of tiles display something, and the rest of the screen is something else).
However, I need to store the position 'it should be' before I start moving the map around at lines 0 and 8, or I won't know where it should go on 16. So what I'm doing is I created a static variable in the interrupt handler, and at line 0, it stores the contents of BG0VOFS in that variable, and then sets BG0VOFS to its desired value. Later it sets BG0VOFS to another value, and when it reaches line 16, I need to put the map back where it was before; the value stored in the static variable.
It works like a charm on BCA. No problem whatsover. But on VBA, for some reason, I have to add 45 to the static variable, or the map won't be at the right position (the top two tiles are.) Of course, when I do that (which isn't a solution of course), it naturally looks messed up in BCA.
Does anyone have an idea what's going on here? I'm baffled by the fact that the two emulators yield different results. Now I can't tell wether my code is correct, because I don't know which emulator is the 'good' one. (I can't test on hardware, by the way.) Besides, if it turned out VBA -does- display it wrong... then that would render VBA useless.
Anyone know what's going on? Does BCA take certain liberties it shouldn't, or does VBA not support things it should? Or is there something else?
Edit: Could be handy to show you exactly what's happening... Here's the interrupt handler:
So, on lines 0, 8, 16, 144, and 152, it scrolls the map to a certain position, and sets REG_DISPSTAT to cause an interrupt on the next desired line. On line 0, the vertical offset might've been changed by user input, so it is saved to pos, and on line 16, it is read from pos again to scroll to that point.
Here's the .bin: http://baspaap.hypermart.net/GBAScroll2.bin
Try it out in BoycottAdvane and VisualBoyAdvance. (use left and right to scroll.) On BCA, it runs as I expected, but in VBA, the offset from line 16 to 144 is wrong. Anyone got an idea?
However, when I run the same .bin in both emulators, they don't yield the exact same result. BCA displays things fine, while VBA messes up the background map.
Here's what I'm doing: I wrote an interrupt handler in C, which scrolls background 0 (using he BG0VOFS register) to various positions when reaching certain scanlines. So at line 0 it's scrolled to a certain point, then at line 8 it's scrolled to somewhere else, then on 16, it is scrolled on the position 'it should be'. (in other words, the top two rows of tiles display something, and the rest of the screen is something else).
However, I need to store the position 'it should be' before I start moving the map around at lines 0 and 8, or I won't know where it should go on 16. So what I'm doing is I created a static variable in the interrupt handler, and at line 0, it stores the contents of BG0VOFS in that variable, and then sets BG0VOFS to its desired value. Later it sets BG0VOFS to another value, and when it reaches line 16, I need to put the map back where it was before; the value stored in the static variable.
It works like a charm on BCA. No problem whatsover. But on VBA, for some reason, I have to add 45 to the static variable, or the map won't be at the right position (the top two tiles are.) Of course, when I do that (which isn't a solution of course), it naturally looks messed up in BCA.
Does anyone have an idea what's going on here? I'm baffled by the fact that the two emulators yield different results. Now I can't tell wether my code is correct, because I don't know which emulator is the 'good' one. (I can't test on hardware, by the way.) Besides, if it turned out VBA -does- display it wrong... then that would render VBA useless.
Anyone know what's going on? Does BCA take certain liberties it shouldn't, or does VBA not support things it should? Or is there something else?
Edit: Could be handy to show you exactly what's happening... Here's the interrupt handler:
Code: |
void InterruptHandler() { if (REG_IF & INT_VCOUNT) { static unsigned short pos = 240; if (REG_VCOUNT == 0) { pos = REG_BG0VOFS; REG_BG0VOFS = 248; REG_DISPSTAT = 32 | (8 << 8); } else if (REG_VCOUNT == 8) { REG_BG0VOFS = 240; REG_DISPSTAT = 32 | (16 << 8); } else if (REG_VCOUNT == 16) { REG_BG0VOFS = pos; REG_DISPSTAT = 32 | (144 << 8); } else if (REG_VCOUNT == 144) { REG_BG0VOFS = 104; REG_DISPSTAT = 32 | (152 << 8); } else if (REG_VCOUNT == 152) { REG_BG0VOFS = 96; REG_DISPSTAT = 32; } REG_IF = INT_VCOUNT; } } |
So, on lines 0, 8, 16, 144, and 152, it scrolls the map to a certain position, and sets REG_DISPSTAT to cause an interrupt on the next desired line. On line 0, the vertical offset might've been changed by user input, so it is saved to pos, and on line 16, it is read from pos again to scroll to that point.
Here's the .bin: http://baspaap.hypermart.net/GBAScroll2.bin
Try it out in BoycottAdvane and VisualBoyAdvance. (use left and right to scroll.) On BCA, it runs as I expected, but in VBA, the offset from line 16 to 144 is wrong. Anyone got an idea?