THIS GUIDE IS USED AT YOUR OWN RISK.
The CyBornOS system was created by Steve Gotthardt. For more information on the CyBorn project check out the forums on DevCybiko and the sourceforge homepage.
To run the tools, you must have Cygwin environment installed. I found this part to be the trickiest, you need to download the setup program and select a base install and add the 'binutils'. You may as well get 'make' but it will not be used in this guide.
If all goes well you should get a Cygwin folder that is about 9meg in size.
This is simple, just extract the tools.zip into the root of the cygwin folder.
Again fairly straight forward, extract the Cybiko.zip into the root of the cygwin folder.
In the Cybiko folder created from step 3, create another folder called 'first'. This is where we will create our first program.
To compile our program we need a few files from the CyBorn example, go the cybiko/cyborn folder and copy the following:
crt0.s
cybikoboot.ld
Paste them into the 'first' folder.
Before we start it's worth mentioning about the Cybiko screen. It is 4000 bytes, and each byte holds the colour information for 4 pixels. Therefore, each row on the screen is 40 bytes.
Most graphical work done will probably involve directly poking the display memory.
First we will create the main function, all the program will go between the curly brackets.
#include "2245s.h"
#include "lowlevel.h"
int main(int argc, char *argv[])
{
// Our program will go here!
}
We need to allocate 4000 byte for our display, we will modify this and then eventually display it.
// Allocate our screen memory static unsigned char dis[4000]; // We will also need a variable later int i;
We are going to draw 4 bars across the screen, the size in pixels is 160x25. This is 1000 bytes (160x25/4).
The '0x' means that the number is in hex.
0xAA = 10101010 in binary
0x55 = 01010101 in binary
// First bar (invisible..) for(i=0;i<1000;i++) { dis[i]=0x00; } // Second bar, starting 1000 bytes later for(i=1000;i<2000;i++) { dis[i]=0x55; } // Third bar for(i=2000;i<3000;i++) { dis[i]=0xAA; } // Last bar for(i=3000;i<4000;i++) { dis[i]=0xff; }
The code above is clear, but we may as well optimise it by getting rid of some of the loops.
// Draw our bars
for(i=0;i<1000;i++)
{
dis[i]=0x00;
dis[i+1000]=0x55;
dis[i+2000]=0xaa;
dis[i+3000]=0xff;
}
We will now display our screen using the _displaynow() function
// Display everything
_displaynow(dis);
Now we've display our screen, the only thing left is to wait for the user to press escape to exit the program. We do this by waiting in an infinite for loop.
//Wait for escape to be pressed for(;;) { // The next line is a low level way of seeing if escape has been pressed if (!(P1.PORT.BYTE & 0x08)) { //break out of the for loop break; } }
Here is the complete program:
#include "2245s.h" #include "lowlevel.h" int main(int argc, char *argv[]) { // Allocate our screen memory static unsigned char dis[4000]; // We will also need a variable later int i; // Draw our bars for(i=0;i<1000;i++) { dis[i]=0x00; dis[i+1000]=0x55; dis[i+2000]=0xaa; dis[i+3000]=0xff; } // Display everything _displaynow(dis); //Wait for escape to be pressed for(;;) { if (!(P1.PORT.BYTE & 0x08)) { break; } } }
This program should be saved into the 'first' folder that we created earlier.
To turn our program into a boot file that will run on the Cybiko. We need to compile it. This is a little more complex than using the Cybiko SDK. We need to:
Convert the C program to Assembly
/tools/bin/h8300-hms-gcc.exe *.c -I ../include -S -ms
Assemble the generate assembly file, and the crt0.o file that came with the Cyborn SDK. Note how crt0.s is assembled to 0crt.s, the zero in front ensures that it is the first file to be linked. If the program has more .c files, they would added to the end of the list.
/tools/bin/h8300-hms-as.exe -W crt0.s -o 0crt.o /tools/bin/h8300-hms-as.exe testcard.s -o testcard.o
Link this program files and the cyborn files together. This gives us our object.
/tools/bin/h8300-hms-ld.exe -T cybikoboot.ld *.o ../lib/libcyborn.a --relax -o testcard.boot
Convert the object into a usable .boot file.
/tools/bin/h8300-hms-objcopy.exe testcard.boot -O binary -I coff-h8300
Remove any unwanted files created above. The following removes the assembler files. In some of my more recent programs, I have put the crt0.s file into a separate folder inside the project folder. Then you can remove all the newly create objects as well using rm *.o *.s
rm *.s
This can be summed as .c > .s >.o >.boot
To do this you can use 'make' but I have been using a batch file to automate the above process.
echo 'C to Assembly..' /tools/bin/h8300-hms-gcc.exe *.c -I ../include -S -ms echo 'Assembling..' /tools/bin/h8300-hms-as.exe -W crt0.s -o 0crt.o /tools/bin/h8300-hms-as.exe testcard.s -o testcard.o echo 'Linking...' /tools/bin/h8300-hms-ld.exe -T cybikoboot.ld *.o ../lib/libcyborn.a --relax -o testcard.boot echo 'Object..' /tools/bin/h8300-hms-objcopy.exe testcard.boot -O binary -I coff-h8300 echo 'Clean up' rm *.s
Save the above as 'make.bat'. Run this from the bash command line using 'bash make.bat'.
Using the Cybiko console, click on the 'Boot' button. Now chose the .boot file you want to send, in this case 'testcard.boot'. You will now be prompted to reboot the Cybiko by pressing the reboot button on screen.
When you do this the Cybiko will restart and then transfer and run the .boot file. All being well, the new boot file should run!
If you escape from the program (or reset if the program crashes), the Cybiko will reboot back to the normal desktop.
Updated 20/04/2024
Updated 13/6/2009