SSJX.CO.UK
Browser Games | Cybiko | Amiga | Applications | Windows Games | Python | Guides | Site Map

Creating native Cybiko programs using the CyBornOS Tools

THIS GUIDE IS USED AT YOUR OWN RISK.

Credits

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.

1. Installing Cygwin

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.

2. Installing the Toolkit (compilers, assembler + linker)

This is simple, just extract the tools.zip into the root of the cygwin folder.

3. Adding the 'include' files and libs

Again fairly straight foreward, extract the cybiko.zip into the root of the cygwin folder.

4. Preparing our work area

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.

5. The Cybiko screen layout

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.

6a. First Program - Main()

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! 
}

6b. Setting up the display

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;

6c. Creating a test card

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;
}

6d. Displaying everything

We will now display our screen using the _displaynow() function

// Display everything
_displaynow(dis);

6e. Waiting to exit

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;
}

}

6f. The full program 'testcard.c'

Heres 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.

7. Creating the executable

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 Cybko SDK. We need to:

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'.

8. Transferring the .boot file to the Cybiko

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 13/6/2009

Support this site : Visit Play-Asia for games and accessories for new and classic games consoles!