English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

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

 
Join Date: Apr 2018
Location: Wales, UK
Age: 36
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:

Code:
echo "Hello EAB from Nim!"
Makes:



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.

Code:
import "amiga/exec"
Alert(0x12345678)


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
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 3,665
I suddenly became a lot more interested in Nim.
idrougge is offline  
Old 14 September 2018, 15:59   #3
Locutus
Registered User

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

 
Join Date: Apr 2018
Location: Wales, UK
Age: 36
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

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)
const COLOR_WBENCH_BG : UWORD = (0xAAA)

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
Locutus
Registered User

 
Join Date: Jul 2014
Location: Finland
Posts: 868
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
betajaen
Registered User

 
Join Date: Apr 2018
Location: Wales, UK
Age: 36
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, 26 views)
betajaen is offline  
Old 08 November 2018, 04:50   #7
Vairn
The Grim-Button

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

Seems like a cool little scripting language.
Vairn 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 22:37.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.
Page generated in 0.09472 seconds with 16 queries