Back to development page
Using the Gnu C Compiler and ARM assembler for the HP49G+.
LAST MODIFICATION: 09/09/2005
Most of the information on HPGCC is outdated, please go to the HPGCC main page at
HPGCC homepage for recent news.
The latest official release of HPGCC with examples can be found
on HPGCC homepage.
Currently, i just maintain an up-to-date windows installer (see below) and historical information for people interested.
Some programs done with HPGCC:
15/05/2005: LChess by Chris Smith in thumb arm for Rom 2.0.
15/05/2005: Tetris in thumb arm for Rom 2.0 (faster...) by me.
15/05/2005: Space Dementia II, updated for Rom 2.0 Copyright Thibault Chevallier, sources on his homepage.
01/10/2004: Tetris for Rom 1.23 by me.
Some screenshots of what You can do with hpgcc...
17/06/2005: Space Dementia Intro.
17/06/2005: Space Dementia Ship selection.
17/06/2005: Space Dementia in-game.
17/06/2005: Space Dementia in-game.
17/06/2005: My balcony (with some flowers).
17/06/2005: My girlfriend's flower.
The latest experimental Setup packages (windows self-installer) are
Note: if you already have cygwin installed, YOU MUST copy your current
cygwin1.dll from your cygwin/bin directory to hpgcc's arm-hp/bin directory.
If you have an old installation (before june 2005), the package might be subject to a critical bug during the
uninstall. Please install a current package OVER it, or simply delete the folder.
How to compile a simple example with the Windows Setup:
An installation tutorial is provided inside the package,
or it can be read here.
First, open a project file (*.pnproj) with the Programmer's Notepad, for example arm-hp/examples/games/games.pnproj.
Then, double click on a .c file in the project window to open a source file (for example: tetris.c).
Go to the Tool menu, select Make clean to remove any .hp files or .o object files that can be in the directory.
Finally, select Tool menu/Make this .hp to build the hp file (here it is tetris.hp).
Transfer the file to your calculator, put the string on the stack and lunch the arm program with the ArmToolBox
from Claudio Lapilli (you can find it in arm-hp/ARMToolBox/SETUP.BIN).
Any valuable feedback is welcome at:
Here is some old information.
This page only shows early work done on how to compile (very) simple C files with gcc
so that can be run on a HP49.
This page is intended to help people writing C/ASM progs with their PC using the GNU tools.
This is not a compiled page of the excellent web page of Al Borowski.
Every single piece of information comes from it or from the HP48 newsgroup.
I simply urge you to check Al's page since you can grab a lot of information about
how ARM is working and how you can program the HP49 in ARM assembly.
A first step to HP-gcc: converting elf format to A>CP format: elf2hp tool
You'll need some files tools to make compilation easier.
The ld script to replace the default ld's one.
The elf converter&loader (with globals).
For multiple files compilation, follow the next steps:
- for windows: go to a working directory (c:\arm-hp\hp for example), put the files inside.
for linux: put the files in your working directory.
- Compile your C sources :
C:\arm-hp\hp> arm-elf-gcc.exe -c file1.c file2.c -mtune=arm920t -mcpu=arm920t -mlittle-endian -soft-float -mapcs-32 -fpic -mpic-register=r10 -msingle-pic-base -fomit-frame-pointer -O3
For linux, use 'arm-gcc-elf' instead of 'arm-elf-gcc.exe' (naming ...). '-mtune=arm920t -mcpu=arm920t -mlittle-endian -soft-float' are processor specific
flags. '-mapcs-32 -fpic -mpic-register=r10 -msingle-pic-base -fomit-frame-pointer' are for position-independant code generation,
you MUST use these flags (at least) to produce elf2hp compliant code. Finally there is the O3 optimization flag.
- use the linker for elf format:
C:>arm-elf-ld.exe -T MMUld.script -nodefaultlibs -nostdlib -static file1.o file2.o -o prog.exe
The main entry point must be a
void _start() function in file1.o or file2.o. You can add your own
library (containing globals or others hardware relative things like hpge) by
adding your 'libmylib.a' to the command line. '-T MMUld.script -nodefaultlibs -nostdlib -static' flags are
used to produce the final elf executable with only the required code (no standard library, static
Convert the exe file to obtain a HP string containing the binary:
C:>elf2hp.exe prog.exe prog.hp
You can use the [-v] flag to see the output and entry points table. The [-vt] flag
can be used to keep the temporary files during the process (this is for debugging
Send it to the HP49 and use the ARM launcher
("A>CP" version from Claudio, see Al's page). You can also use
the ARM Toolbox from Claudio (doc included).
You CAN'T launch an ARM-based program made with gcc from Flash ROM. This is due to writing
permission needed at the begining of the code (entries relocation). Currently, the program
must be launched from RAM to avoid crashes.
The first tries of using gcc were explained here. This page
explains the issues that appears when using elf format, and it propose a very simple
arm binary code to HP string converter (with "A>CP" header).
A second version of the document was written, it was taking a step further by
using a small tool, the HPpatch tool. This patch allows to start
a main() entry function.
This page presents the current development stage of elf2hp, a utility to convert arm-elf
binary to a hp string with "A>CP" header.
What elf2hp does ?
Registers Save&Load :
Al said that R0-R12 should be saved. For that, arm asm code is put at the begining of your
elf executable and branch to your main function. The registers are restored at the end.
Relocate sections of elf file :
As some might knows, the elf format specifies how a file is to be loaded in memory. The elf
standard gives names to particular sections: .text is the code (read only), .rodata is some
read only data, .data is initialized read-write data, .bss is a 0'd block to be used by the
program. Elf2hp insert a portion of code that does the address translation for you. That's
why you must use the previous flags during the compilation/linking.
A note for linux users: how to connect their HP to the usb port
If your usb_serial module is very up-to date (25 april 05), the HP should be
detected by the usb module. If not, load the module this way:
modprobe usbserial vendor=0x03f0 product=0x0121
Now, using dmesg, you should read this:
usb 2-1: new full speed USB device using address 7
usbserial 2-1:1.0: Generic converter detected
usb 2-1: Generic converter now attached to ttyUSB0 (or usb/tts/0 for devfs)
In case you don't have the /dev/ttyUSB0, try this:
mknod /dev/ttyUSB0 c 188 0
Then, the /dev/ttyUSB0 port is ready for serial transfer.
Daniel Herring has prepared the following
People that want to build there own Xmodem client can look
at this old post.
You can download a compiled Tetris example for the hp on this link.
For more details on source code, screen io, keys, ... see the HPGCC homepage.
Feel free to email me at:
Have fun with your hp49g+!