
    Building V810 GCC cross compiler on Cygwin/Linux 
      for Nintendo Virtual Boy based development

              Origional V810 port from 
     http://hp.vector.co.jp/authors/VA007898/pcfxga/

===== Changelog =====
03/26/07 - new build script and fixed link bugs
03/26/06 - fixed vb.ld script
03/24/06 - Initial release

===== ToDo =====
 - Implement heap and enable it with compiler directive
 - enable printf, etc
 - Fix up GDB, in particular implement the GDB loader

===== Setup Environment =====
install cygwin with:
  make, gcc, flex, patch, tar, gzip, autoconfig, gperf, bison
  and reboot if upgrading cygwin

Ok here is how it works on Suse 9.3 and cygwin.  You might be tempted
to build the whole thing as root but don't, it wont work on Suse
because root does not map /user to the path.

You can perform the following, or just run ./make_v810.sh and it will do everything for you.

----------------------------

Assuming that you have the folowing files in a directory:
 binutils-2.10.tar.gz
 binutils-2.10-v810patch1021.gz
 gcc-2.95.2.tar.gz
 gcc-2.95.2-v810patch0927.gz
 newlib-1.10.0.tar.gz
 gdb-5.0.tar.gz
 gdb-5.0-v810patch1021.gz
 binutils-2.10-vb_v810patch-02
 gcc-2.95.2-vb_v810patch-01
 newlib-1.10.0-vb_v810patch-01
 make_v810.sh

Open a terminal and cd to that directory and exicute the following:

#Build Binutils
tar zxvf binutils-2.10.tar.gz
cd binutils-2.10
gzip -dc ../binutils-2.10-v810patch1021.gz | patch -p1
cat ../binutils-2.10-vb_v810patch-02 | patch -p1
cd ..
mkdir binutil_build
cd binutil_build
../binutils-2.10/configure --target=v810 --prefix=/usr/local
make all install
cd ..

# Build a minimal GCC 
tar zxvf gcc-2.95.2.tar.gz
cd gcc-2.95.2
gzip -dc ../gcc-2.95.2-v810patch0927.gz | patch -p1
cat ../gcc-2.95.2-vb_v810patch-01 | patch -p1
cd ..
mkdir gcc_build
cd gcc_build
../gcc-2.95.2/configure --target=v810 --prefix=/usr/local \
   --enable-languages=c --without-headers --with-newlib
make all install
cd ..

# Build Newlib
# if this fails thain dos2unix the newlib folder
tar xzvf newlib-1.10.0.tar.gz
cd newlib-1.10.0
cat ../newlib-1.10.0-vb_v810patch-01 | patch -p1
cd ..
mkdir newlib_build
cd newlib_build
../newlib-1.10.0/configure --target=v810 --prefix=/usr/local 
make all install
cd ..

# Build GCC again with no restrictions
cd gcc_build
../gcc-2.95.2/configure --target=v810 --prefix=/usr/local \
   --enable-languages=c
make all install
cd ..

# Optionaly Build GDB (not fully implemented)
tar zxvf gdb-5.0.tar.gz
cd gdb-5.0
gzip -dc ../gdb-5.0-v810patch1021.gz | patch -p1
cd ..
mkdir gdb_build
cd gdb_build
../gdb-5.0/configure --target=v810 --prefix=/usr/local
make all install
cd ..

//cleanup
to save space you can remove the build directory's now
$ rm -r * //caution, will delete everything in the current directory!!! 

===== Compiling VB programs =====

//to build a project
$ v810-gcc -O -I. *.c -o test.elf
$ v810-objcopy -O binary test.elf test.vb

// if you want to see the memory layout and assembly
$ v810-objdump -S test.elf >test.asm
$ v810-objdump -t test.elf >sections.txt

===== Interupt Handlers =====
To create an interupt handler just define a function as described below.  Your handler
will automaticaly be called when the given interupt fires.  If you do not define a
handler, a default handler will be provided.  You do not need to do anything at the end
of the fn, a return handler will take care of returning form the interrupt.  Just as a
side note, by default you can not have more thain one interrupt firring at a time.  If
you want to handle multiple interrupts you have to add in some extra assembly code.  See
the NEC v810 developers manual for more information.

 void key_vector(void)   // Controller Interrupt Handler
 void tim_vector(void)   // Timer Interrupt Handler
 void cro_vector(void)   // Expantion Port Interupt Handler
 void com_vector(void)   // Link Port Interrupt Handler
 void vpu_vector(void)   // Video Retrace Interrupt Handler

===== Linker Scripts =====
The two files crt0.o and vb.ld are combined to define the memory space on the virtual 
boy.  The crt0.o is built form the file crt0.s and contains the initialization code and
boot loader.  vb.ld on the other hand tells the linker how to combine the librarys/heap/data/and stack memory.  I'f yo want to define your own crt0.o or vb.ld files, for example to enable the heap, follow theas instructions.

By default crt0.s lives in:
   newlib-1.10.0/newlib/libc/sys/sysnecv810/crt0.s
and is built when newlib is built.  You can override it at any time by compiling your
own crt0.o:
  v810-as -o crt0.o crt0.s
  cp crt0.o  /usr/local/v810/lib

By default vb.ld lives in
   binutils-2.10/ld/scripttempl/v810.sc
And is built into v810-ld when binutils gets built.  You can override it by
copying it to
  /usr/local/v810/lib/vb.ld

or if you want you can override both with the -T command line option:
  v810-gcc -T/path_to/vb.ld -T/path_to/crt0.o -o output.elf
  v810-objcopy -O binary output.elf output.vb

I included the source to Parasites padder program, you can use this to change the
size of the vb binary.  The only reason you would need to use this would be to resize
the rom to fit in your hardware eprom cartrige.

