Atari cross compiling

4 10 2014

Today I had a small coding sprint to find out if I could compile assembler code and embed it in a C programm.

The sprint was successfull thanks to the work of:

  • saulot/nokturnal : created 2 articles about using gnu assembler and using virtual assembler to do the task.
  • Vincent Rivière’s: He created a tool chain for cross compiling for the Atari
  • Hatari team: I used the Hatari 1.8 Emulator to test the result

But I had some problems. The main one was that I forgot the leading tab or blank in the vasm assembler file, so I alsways got an error, that the memnonic was not found. Insane / .tSCc. helped me to find this minor error, thanks to him as well.

I also had think, that a complette example would be a great enhancement of soulot’s howto. So I put this example for both assembler in this article. First we setup our cross compiling environment.

Download and install tool chain

http://vincent.riviere.free.fr/soft/m68k-atari-mint/

Download and install Virtual Assembler

http://sun.hasenbraten.de/vasm/

Download and Install Hatari

Here a link to a former article of mine, which is still valid (beside the version numbers)
https://thornstot.wordpress.com/2014/01/23/hatari-1-7-installed-under-ubuntu-13-10/

GNU Assembler example

Link to soulots article: http://bus-error.nokturnal.pl/tiki-read_article.php?articleId=2

C Header: ex_gas.h

#ifndef PLUS_H
#define PLUS_H ;we want to include header once
#ifdef __cplusplus
extern "C" {
#endif
long plus(long a, long b);
#ifdef __cplusplus
}
#endif
#endif

C Code ex_gas.c

#include "ex_gas.h"
#include <stdio.h>
int main(int argc, char* argv[])
{
int a=0;
a=plus(2,1);
puts("Hello, world !");
return 0;
}

Assembler code ex_gas.s

 .globl _plus
_plus:
move.l 4(sp),d0
add.l 8(sp),d0
rts

Assemble
m68k-atari-mint-gcc -c ex_gas.s -Wa,-S -o ex_gas.o

Compile
m68k-atari-mint-gcc ex_gas.c ex_gas.o -o ex_gas.tos

 

Virtual Assembler example

Link to saulots article: http://bus-error.nokturnal.pl/tiki-read_article.php?articleId=1

C Header ex_vasm.h

#ifndef PLUS_H
#define PLUS_H ;we want to include header once
#ifdef __cplusplus
extern "C" {
#endif
void hello();
#ifdef __cplusplus
}
#endif
#endif

C Code ex_vasm.c

#include "ex_vasm.h"
#include <stdio.h>
int main(int argc, char* argv[])
{
int a=0;
hello();
puts("Hello, world !");
return 0;
}

Assembler code ex_vasm.s

Do not forget the leading tab in front of XDEF 🙂

 XDEF _hello
_hello:
movem.l d1-d2/a0-2,-(sp)
move.l #hi_msg,-(sp)
move.w #$09,-(sp)
trap #1
addq.l #6,sp
movem.l (sp)+,d1-d2/a0-2
rts
hi_msg:
dc.b "Hi from 68k!",$0d,$0a,$00

Assemble

vasmm68k_mot ex_vasm.s -Faout -quiet -x -m68000 -spaces -showopt -o ex_vasm.o

Compile

m68k-atari-mint-gcc ex_vasm.c ex_vasm.o -o ex_vasm.tos





Java Script Keyboard Input

3 07 2013

Today, I found a nice little Java Script library called keypress.js. It handles Keyboard events. I used it to rewrite the keyboard handling in “Heimholung” my actual project.

Before keypress I had these handlers:

addEventListener(“keydown”, function (e) {
keysDown[e.keyCode] = true;
}, false);addEventListener(“keyup”, function (e) {
delete keysDown[e.keyCode];
}, false);

Now I use keypress:

keypress.register_combo({
“keys”: “down”,
“on_keydown” : function(e) {
keysDown[e.keyCode]=true;
},

“on_keyup” : function(e) {
delete keysDown[e.keyCode];
},

“prevent_repeat”    : true,
});

 

After a while I got everything working. Most important was to have a function to wait until a key is pressed:

 

keypress.register_combo({
“keys”: “down”,
“on_keyup”: function(e) {
keypress.reset();
nextStateInit();
currentState.state=nextState;
},
“prevent_repeat”    : true,
});