English Amiga Board

Go Back   English Amiga Board > Coders > Coders. General

Thread Tools
Old 14 September 2018, 13:03   #1
Registered User

Join Date: Apr 2018
Location: Wales, UK
Age: 37
Posts: 76
Amiga Development using Nim

Hello all,

This is some work to allow Nim nim-lang.org programs being run on the Amiga. This isn't a port of Nim compiler to the Amiga, but more of a port the Amiga libraries and architecture being used in Nim, which then can be used on the Amiga.

Nim is one of the newer emerging languages, it can 'transpile' into C really efficiently and well. So I like to think of it as C but with a lot of cool stuff on top. It supports multiple architectures, and claims to support Amiga - although it's a little wrong in some parts, and some code is missing.

I've added in the missing bits for it to compile, and have a semi-manual tool chain working. It has garbage collection built in, but I'm using one of the simpler garbage collectors than the standard one.

Anyway, once compiled to C, then I use VBCC (on Windows) to turn it into an Amiga executable.

For example:

echo "Hello EAB from Nim!"

I've started to port some of the Amiga NDK over. Nim comes with a c2nim converter for headers, and for the most part it works really well. I only have exec in, but you can do cool things like this.

import "amiga/exec"

Once I've got more of a complete system, I'll be happy to publish to github.
betajaen is offline  
Old 14 September 2018, 15:53   #2
Registered User
Join Date: Sep 2007
Location: Stockholm
Posts: 3,929
I suddenly became a lot more interested in Nim.
idrougge is offline  
Old 14 September 2018, 15:59   #3
Registered User

Join Date: Jul 2014
Location: Finland
Posts: 979
Oh thats superdupercool.
Locutus is offline  
Old 15 September 2018, 14:23   #4
Registered User

Join Date: Apr 2018
Location: Wales, UK
Age: 37
Posts: 76
I ported over 'hardware' part of the 3.9 NDK yesterday. It's just one NIM file with a load of constants and struct definitions.

So I had a go at rewriting 'moveline' by Wei-ju Wu, to see if I could play with some hardware stuff. Turns out you can.

It's a bit messy with the register part. I need to turn those into Macros, but it works really well. No assembly required!

Preview (Click for video!)

The Code

import "amiga/exec"
import "amiga/hardware"

{.emit: "volatile NU8 *ciaa_pra = (volatile NU8 *) 0xbfe001;".}
var ciaa_pra {.nodecl, importc.}: ptr UBYTE

{.emit: "volatile NU8 *custom_vhposr = (volatile NU8 *) 0xdff006;".}
var custom_vhposr {.nodecl, importc.}: ptr UBYTE

const PRA_FIR0_BIT : uint8 = 1 shl 6
const COLOR_WHITE : UWORD = (0x0fff)

var pos  : int = 0xac
var incr : int = 1

while( (ciaa_pra[] and PRA_FIR0_BIT ) != 0):           # while lmb is not down
  while(  custom_vhposr[] != 0xff ): discard           # wait for vblank
  while(  cast[int](custom_vhposr[]) != pos):  discard # wait until position reached
  custom.color[0] = COLOR_WHITE
  while(  cast[int](custom_vhposr[]) == pos): discard  # wait while on the target position
  custom.color[0] = COLOR_WBENCH_BG

  if (pos >= 0xf0):
    incr = -incr
  elif (pos <= 0x40):
    incr = -incr

  pos += incr
betajaen is offline  
Old 15 September 2018, 14:29   #5
Registered User

Join Date: Jul 2014
Location: Finland
Posts: 979
Do you have a repo somewhere i can clone? I'd like to play with Nim :-)
Locutus is offline  
Old 15 September 2018, 14:43   #6
Registered User

Join Date: Apr 2018
Location: Wales, UK
Age: 37
Posts: 76
Nothing official yet. But I'll upload what I have here.

Just install nim normally. I actually installed it to C:nim/

You'll need the Windows version of VBCC to compile, otherwise you'll have to transfer the contents of nimcache over to an Amiga (which then needs VBCC to compile).

You build via 'build.bat', and then if your using VBCC on windows, there is a build.bat in nimcache as well. It needs a special nimbase.h file, with some changes (just to fool the preprocessor and help VBCC compile it).

The Amiga module is a separate folder, and needs to go somewhere else. If you install nim properly, the nimble package manager should be okay with it, but for the nim programs to see it you need to go into the directory, and do; 'nimble develop' which it should see it, as it isn't in the official package manger system.

Apart from that, have a look at 'beamline'. It contains the source and what I showed up above. Only exec and hardware are in. It also contains the important build scripts (making sure it uses the regions garbage collector, big endian, etc.) and patches for it to compile (os_alloc, ansi_c and panicoverride in particular).

I'm really really new to nim and to C programming on the Amiga (although I'm pretty good at Blitz/AMOS now). So some questions, I probably won't be able to answer.

I'll put up an official repo soon though. Have fun!
Attached Files
File Type: zip nim-for-amiga-15-0-18.zip (53.6 KB, 76 views)
betajaen is offline  
Old 08 November 2018, 04:50   #7
The Grim-Button

Vairn's Avatar
Join Date: Jan 2008
Location: Melbourne Australia
Age: 38
Posts: 408
Did you ever get further with this?

Seems like a cool little scripting language.
Vairn is offline  
Old 20 November 2018, 15:49   #8
Registered User

osz's Avatar
Join Date: Nov 2018
Location: Oldenburg (Germany)
Posts: 2
This is really very cool!

I've found a package of "nim bindings to OS 3 API" on GitHub: https://github.com/Nadrin/nim-amigaos

But I don't know if there is any connection to betajaen and I haven't tried it yet.
osz is offline  

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Amiga Development on AmigaOS 3.1... Panthros Amiga scene 3 08 January 2017 22:52
Amiga development freehand Retrogaming General Discussion 4 18 April 2010 18:53
Amiga software development tootoid Amiga scene 22 21 March 2007 19:12
Next-gen Amiga development LaundroMat Coders. General 3 05 October 2002 01:30
Amiga - future development? LUKas007 Amiga scene 244 21 September 2002 13:55

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +2. The time now is 13:06.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.07139 seconds with 14 queries