It was a race condition. If a program attempts to alter one of the DS’ DMA addresses whilst that DMA channel has an operation in progress, the DMA channel goes bonkers and doesn’t carry out either operation. This generally isn’t a problem when we work with VRAM, but the SuperBitmap works with main memory which is notably slower. The SuperBitmap’s DMA instructions were treading on each other’s feet.
I’ve added a new macro into woopsifuncs.h - “DMA_Active()“. This returns true if the DMA channel is still active, and false if not. All of the SuperBitmap functions now wait until the DMA channel is inactive before releasing control of the DS back to the rest of the code, which finally seems to have solved the problem. I hope.
I’ve also added DMA_Copy2(), DMA_Force2() and DMA_Active2() macros, which are identical to the original functions except that they work with the second DMA channel. The original functions work with the third channel (there are four channels, but they are named using a zero-based convention and the “first” channel is correctly termed the “zero” channel).
Having the SDL version available is a massive help when trying to track down tricky bugs. The first thing I’ve done with it is get the MultiLineTextBox working with the ScrollingPanel. The debug console can now be scrolled up to reveal previous lines of text; it stores up to 50 lines in its buffer. There are a couple of newly-introduced bugs in the textbox, though - vertical alignments other than “top” don’t work, and scrolling at a particular pace seems to cause the occasional line to be incompletely drawn.
Some neat Xcode features I’ve discovered:
- Built-in SVN client. Haven’t tried it yet, though.
- Word completion, browser address bar style.
- Hit “Escape” to bring up a Visual Studio-esque word list.
- The “restart” button in the debugger - which resets the exe back to its initial state - is a great idea.
- Variable display is always visible by default in the debugger; no mucking about hovering over things in order to work out what their values are.
- The “fix” button in the debugger compiles any changes you’ve made to the code and patches the exe as it is running - no need to restart and get back to the same state. Superb.
- The debugger’s callstack browser.
- Code folding.
- Generated class diagrams.
- MallocDebug! Excellent idea.
- Leaks! An even better idea. I found one leak in the TextViewer, but (astonishingly) everything else seems water tight.
There’s loads of good stuff in here. The “Instruments” panel is a spectacularly good feature, especially when you remember that Xcode is a freebie with the OS. Digging around in all of these new toys has left me wondering how I’ve managed to write 500K of code without a debugger.