#44464 - Ultima2876 - Thu Jun 02, 2005 2:34 am
When I try to boot my game on GBA using 3/1 waitstates and the -O3 compiler optimisation in Devkitadvance, I get a strange display error (where the screen flashes random colours and patterns) and then a crash. Is this a known problem, or is it something to do with my initialisation code?
Code: |
//enable interrupts
REG_IME = 1;
//hblank setup
hblank_func = HBLANK_NONE;
REG_IE |= 0x0002; //enable Hblank Interrupt
REG_DISPSTAT |= 0x0010; //Hblank Interrupt
//timer setup
REG_TM3D = 0x8000;
REG_TM3CNT = 0x83;
//wait states
REG_WSCNT = (5 << 2) | (1 << 14);
//initialisation
kragInit( KRAG_INIT_MONO );
kramQualityMode(KRAM_QM_NORMAL);
kramSetMasterVol(128);
krapCallback((*krawall_callback)); |
#44465 - josath - Thu Jun 02, 2005 2:51 am
changing waitstates, or changing optimization stops it from crashing?
#44468 - tepples - Thu Jun 02, 2005 3:02 am
Turn OFF prefetch by removing the " | (1 << 14)". In my tests, prefetch is b0rken, as there are things that non-NDA people don't know about safety with prefetch turned on. Perhaps you have to write to WAITCNT (aka WSCNT) from code run in RAM or something.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#44469 - Ultima2876 - Thu Jun 02, 2005 3:06 am
Hmm.. turning off the prefetch doesnt seem to make a difference. It was enabling the optimisation that originally triggered it (the waitstate changing was fine before optimisation).
I've tried it with prefetch on and O3, that works fine. AS soon as I touch the waitstate timing itself though, it breaks.
The reason I'm so concerned and don't just ignore the -O3 flag or waitstates is because they both seem to increase my running speed a ton, and would like ot take advantage of both if possible...
#44475 - tepples - Thu Jun 02, 2005 3:20 am
Does -O2 work? Does -O work?
Usually if -O3 screws something up, you're missing a volatile somewhere in the part of your header files that defines macros for accessing registers.
Does it work if you put a delay loop (wait for a couple vblanks) before kragInit();
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#44481 - Ultima2876 - Thu Jun 02, 2005 4:01 am
No optimisation settings work, and I tried waiting 16 Vblanks - no difference.
I then tried compiling with the latest devkitARM, same settings. Apart from it complaining a bit about some out of range branches (to which I had to disable some of my collision code), no difference there either...
(as a note - it doesn't even seem to get past the waitstate setting code - I made it wait for a few million Vblanks to see what happened - no delays before I got the flashy colours =P)
#44524 - Ultima2876 - Thu Jun 02, 2005 4:35 pm
Update: It actually does appear to get past the waitstate setting code - in fact, it gets as far as my setting of the REG_DISPCNT register. I checked and this register was not declared as volatile - however, I changed that (and checked every other register to make sure they were volatile), but that didn't work either. I tried changing the mode that I change to (from mode 0), but again, no difference. I even tried commenting out all my code except the waitstate and display setting - no difference.
I tried putting the display setting code before the waitstate setting code - no difference again. Then I repeated all of these, double checked my registers and inserted delay loops between everything. No difference again, other than that the game displayed white for a few more seconds (due to a delay loop between setting the display mode and the waitstates).
Any more suggestions? X.x
EDIT: So you know, everything works fine (and fast enough) on all GBA emulators I've tried (the latest few VBA's, VBA CD, Boycott and no$)
#44528 - poslundc - Thu Jun 02, 2005 5:24 pm
I'm no expert at fiddling with the waitstate controller, but are you certain your flash cart supports the settings you've been trying? According to GBATEK, "third-party flashcards are reportedly running unstable with these settings".
Dan.
#44529 - Ultima2876 - Thu Jun 02, 2005 5:42 pm
I'm fairly sure it does, since it only started doing this with the -Ox optimisation settings... however, it's still possible that's the reason, in which case I'll just have to leave it at 4/2 waitstates and try to optimise my code more.
#44543 - tepples - Thu Jun 02, 2005 7:05 pm
The first couple models of Visoly Flash Advance carts were incompatible with 3/1 wait states. The newer ones (FA Turbo 256 and later) appear to work fine even with commercial games that use 3/1.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#44545 - Ultima2876 - Thu Jun 02, 2005 7:43 pm
My cart is a Flash2Advance Ultra 1 Gb. It's fairly recent - I got it for last christmas, and it wasn't out for much longer than that..
#44560 - tepples - Thu Jun 02, 2005 9:48 pm
F2A Ultra should be just fine.
Curious: Have you tried 4/1 wait state? And are you sure that the value you're writing refers to 3/1? The flash cards are stable at 3/1 but not at 2/1, another setting that the GBA memory controller supports.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#44569 - Ultima2876 - Thu Jun 02, 2005 11:33 pm
I've tried inputting it in different ways and triple checking it... I'm fairly positive I'm putting it in right.
0100000000010100
That's what I'm putting in there - in various forms (5<<2 | 1 << 14, 1 << 2 | 1<< 4 | 1 << 14, 0x4014).
As for 4/1 wait states - same problem x.x
Same with 3/2, as well, which I decided to try out of curiosity. My flash cart still works, by the way, I can compile without optimisations or disable the waitstate change and it works fine (despite some lag).
=/
#45108 - Miked0801 - Tue Jun 07, 2005 7:13 pm
A thought - perhaps this code is running in RAM somewhere and when optimizing occurs, your instruction is getting trounced. Try moving the code around a bit to see if it magically fixes itself - or try adding some filler code before the wait state call.