ssjx.co.uk
 Home of StormPlayer for Cybiko and other great programs
  Home | Cybiko : Cybiko Guides : Cvc Videos | CyBorn | Amiga | Windows Games| Games| Links

Creating a program using the CyBorn Tools

This guide was written by ssjx. (http://ssjx.co.uk) THIS GUIDE IS USED AT YOUR OWN RISK. 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 stragiht 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 file 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 Cybikos screen layout Before we start it's worth mentioning about the Cybiko screen. It is 4000 bytes, and each byte holds the colour information about 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:
  • 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 gets rid of the assembler files. In some of my more recent programs, i've put the crt0.s file into a seperate 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'. 8. Transfering 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.

 

 


Links that help support site
RPoints Buy from shops through RPoints and you can get money back. Includes Cdwow, Play.com, Dell and many other useful shops.
Top Cashback Just like RPoints except they pay higher amounts on some shops.
Play-Asia Very good online seller of games. They also stock a lot of retro games and consoles e.g. Saturn and Jaguar!

Unless indicated otherwise, all programs were created by me (ssjx). All programs and source are used at your own risk.
©2008 ssjx