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

Advertisements




NonConForm State Engine for Java Script. The first example

3 10 2014

I started to port my NonConForm library from the Falcon to Python a while ago. Now I started to port it to JavaScript as well. Today the state engine, the heart of the gaming menu framework is finished.

Here the first example:


-------------------------------------------------
declare states
-------------------------------------------------
var stGame = new NcfState("Game");
var tFinishFromGame = new NcfTransition("FinishFromGame","End",function() {});
stGame.addTransition(tFinishFromGame);
Ncf.addState(stGame);
-------------------------------------------------
define view
-------------------------------------------------
Ncf.getState("Game").setView(
function() {
Ncf.log("View");
Ncf.transit("FinishFromGame");
}
)
-------------------------------------------------
define controller
-------------------------------------------------
Ncf.getState("Game").setController(
function() {
Ncf.log("Controller");
Ncf.transit("FinishFromGame");
}
)
-------------------------------------------------
start engine
-------------------------------------------------
Ncf.setDebugMode(true);
Ncf.init(50,"Game");

and here is the output

initialize NonConForm
—————————–
start NonConForm state engine
—————————–
Leaving:Start
|——————Transit to——————|:Game
Entering:Game
NonConForm main loop started
Main Loop
View
Controller
Leaving:Game
|——————Transit to——————|:End
—————————–
finishing NonConForm
—————————–
NonConForm main loop stopped