A demo of using a custom programming language I created - KLD - to create a demo for the Sega MegaDrive & SegaCD used in Mode 1 Type 2.
KLD was originally designed as a language to teach myself how to write a Pratt Parser (if you don't know what Pratt Parsers are, look them up - they're amazing and conceptually super simple).
Eventually, it evolved into a weird mashup between C, C++, and ActionScript 3 meant to help me code Sega MegaDrive homebrew in a higher level language than C.
The KLD compiler actually "compiles" the code into C code which can be fed directly into GCC (in this case, I feed it into the GCC that ships with SGDK). It does this by first parsing the KLD file and turning it into an abstract syntax tree. Then, it "compiles" the entire tree into C code (each expression in the tree has its own compile function which spits out a snippet of C).
KLD at the same time adds a lot of cool syntactic sugar on top of C. It adds support for modules, classes, inheritance, and more, adding a variety of OOP-style features to C.
In this example, I actually take advantage of the fact that it generates raw C code in order to compile a Sega MegaDrive ROM using SGDK. This particular example uses some modified code from the SpritesMind forums based on code by ChillyWilly to boot the SegaCD in so-called "Mode 1" (actually Mode 1 Type 2), which allows a cartridge-based game to control the CD peripheral. My program looks into RAM to try and locate the CD's bios, decompresses the BIOS, then loads a custom program into the CD's sub CPU program RAM. This custom program then sits and waits for commands from the MD side, in this case I issue a command which plays a particular track on a music CD.
This allows a game to play crystal-clear BGM tracks from a CD instead of using the console's limited FM synthesis. This technique was used in, for example, Pier Solar (although in that game it was optional and the game would fall back to FM synth, my ROM will display a warning message asking the user to install the CD peripheral and insert the game's music CD before rebooting).
I show booting this custom ROM in RetroArch (I have tried using Kega Fusion, but it doesn't seem to properly support my custom CUE sheet - this is not a problem with my ROM, but rather with the CUE sheet itself. A music CD ISO would not have the same problem).
Music used is "Graceful Resistance" by Dibur on SoundCloud: https://soundcloud.com/diburmusic/battle-theme-01-rpg