Interesting, my few additions would be to maybe qualify your comments on dynamic allocation some. Weather or not to use dynamic allocation in embedded systems is an argument that has been done to death. Personally I love it and use it all the time. I would first verify (maybe you have) that the underlying allocator is indeed a first-fit algorithm, and not something more complex like a slab/block allocator. We use these quite frequently on systems down to about 32kb of RAM with high uptime and no fragmentation whatsoever.
Also maybe go into the benefits of grouping your allocations and limiting them to initialization time only, and writing a wrapper utility to keep track of leaks. Most game programmers I have met have a horrible habits and understandings of system-level issues.
Sort of in-line with that, I would maybe steer people away from stack allocations. They are certainly useful but without a real solid understanding of scope or object lifetime it is asking for trouble. For instance, DMA transferring a stack object without waiting for the operation to finish can result in some seriously difficult to track down memory corruption issues if the stack descends back over your start address before the operation completes.
On the whole, looks very good though.
There is lots of stuff to get into I suppose. Admittedly I do embedded work and only have passing experience with the PSX, but some topics to consider:
Threading - models, cooperative, pre-emptive, how to implement, pitfalls, etc.
DMA - synchronization and pitfalls.
Caching - PSX's setup, how to utilize scratchpad, cached vs. non-cached segments, etc.
GPU model - how to keep the pipeline full, what to offload to the GPU, how to do so effectively.
Input - handling asyc input in a thread-safe manner.
Overlays - how this aligns with low-level system calls, resource usage, etc.
Maybe get into some system-level stuff as well, and talk about how to effectively manage resources. Also I don't see a lot of people cover sound output.
Really like to read your articles.
Thanks alot for the work!
I have seen a few times where the vsync handler or a root counter interrupt is used as a systick timer to get a scheduler and preemptive threading models working on it, but that may be off a bit into OS design rather than specifics to the Playstation.
That is more or less how you would execute code related to vsync interrupts (or anything else a root counter can provide), which usually gives you a robust base for specific tasks that need to be executed independently from program code and on a constant basis, say music trackers. Actual cooperative threading allows you to switch around code with ease and from any point of the code.
For example, you could have a main loop with just a bunch of system functions (pad, display swap, mdec playback, etc.) while a scheduler (i.e. thread tasks) executes game logic/rendering, async cd operations, and such.
To give an even better example:
- you have your game loop as task 0 executing as an infinite loop with a switch command at the end of said loop to pass on to the next task
- task 1 takes care of cd reads and switches task as soon as it enters a wait state.
You don't even need to add a million jumps to specific parts of either task because cooperative threading takes care of it and even restores the full state of your environment (i.e. no global variables required for local scope), meaning you can leave and go back with almost no need to change your logic.
I think we are saying the same thing essentially, what you do is offload your kernel's context switch routine to the interrupt fired by the vsync timer or the root counter and get the next task served up by whatever scheduler you wanted to write. I guess it depends on if you want determinism on both PAL and NTSC systems as to which interrupt source you select.
I can't remember if the library primitives for task switching could be called from an interrupt context or not, otherwise you would have to write a manual context switching routine as well.
Very impressive where did u learn all this
^ Loads of experimenting really.