Bitwise Bytefoolish
Introduction
In Bitwise Bytefoolish two players (or one player against an computer played oppenent) will in turn manipulate a byte to match their goal value. Once the byte matches the goal value of a player that player wins the game!
The concept of the game is rather simple. This is on purpose. When entering a new platform, the gameboy in this case, the learning curve can be quite steep in the beginning. That's why it is best to keep the scope of your first project small.Project set up
When developing for the gameboy you can choose between two languages: C and assembly.1 Most compilers will compile assmebly to the machine language understood by the gameboy. The Small Device C Compiler (SDCC) used by GBDK2020 is no different.2 However, the output of the compiler in this project will not be the complete game just yet. In the old days it was common to split the compilation of your application in parts called object files. Those object files would then be linked into one whole application by a linker. The adventage of this method is that when the developer makes a small change in the code only that part of the application had to be compiled again. That was a huge timesaver back in the day!
For this project I have choosen to use GBDK2020. It is the current goto for C programming on the gameboy. Using a higher level language like C lowers the entry bar not only for me, but also for many other developers that might want to join. And when the abstraction of the C language poses technical difficulties writing optimized assembly is still an option.
First I have installed GBDK2020 locally. Secondly I configured my IDE VS Code. It is important is to include the path to the GBDK2020 libraries. Otherwise IntelliSense will not understand what I am doing.
Thirdly I created the make.bat file. For each C or assembly file a line like below is used to compile it into an object file.
The instruction can be broken down as follow:
- d:\gbdk\bin\lcc
- Location of the lcc compiler. It is found in the bin folder of your GBDK2020 installation. It is this application we do a call upon.
- -Wa-l
- Generate assemlber listing file.
- -Wl-m
- Generate linker map file.
- -Wl-j
- Enables NoICE output for sdldgb: the SDCC linker for the gameboy.
- -DUSE_SFR_FOR_REG
- Don't use a Special Functions Registry for registry.
- -c
- Compile only
- -o
- Leave the output in 'file'
- main.c
- Path to the C or assembly file
- main.o
- Path to the object file
At the last line we link all object files together into one .gb file. Note that there is no -c parameter. The object files already contain the to machine language compiled code.
Fourthly I created the .gitignore file. In the make.bat we instruct lcc to generate lots of files. Most of them are for debugging purposes. Let's exclude those from source control. It can always be generated anew when needed.
Fifthly I added a package.json. I already had Node.js installed on my local machine and so do many other developers with VS Code. I added the make.bat as compile script. Self made pre-compile scripts can later be added when the necessity arises.
First iteration
[...]