Hectic days so I dont have as much time to blog as I used to. Also found a new interest in electronics (total newbie, but i love it) so I jump from one thing to the next.

NodeJS, assembly and virtual machine

Whenever I have time I try to work as much on Smart Mobile Studio as I can. I keep working at a steady pace on the RTL.

At the same time I am also making headway on the assembler written in Smart Pascal. It is quite important for some of the future plans, and to be perfectly honest – it’s pretty cool! Basically I have mixed classic Acorn, MC68030 and x86 assembly language, adapted it to JavaScript (so no pointers, only references and offsets). The instruction set is fairly standard:

Unlike Java or CLR, this one is register oriented. One of the major weaknesses of Java is how it pushes everything on the stack, making calls slower than it has to be.

32 data agnostic cpu registers

stack and frame

Program counter (PC)

Variable management

Inline constants

Asm compiles to codesegment assembly format Support for const resource chunk Instance frame oriented



The instruction set thus far is very fundamental. It contains instructions you will find on any processor (more or less).

Parameters always start with the destination (destination, source). Most instructions support all 3 modus operandi (register, constant or resource identifier and inline data).

Inline data instructs the cpu to read a data segment directly following the instruction. For example, this is a perfectly valid assembly snippet:

LDD R0, "This is a string " MOV R1, R0 ADD R0, R1 ; r0 now contains "This is a string This is a string"

You can however put that string (which is a constant) into the resource chunk of the bytecode format. Then you can reference it by id:

; here presuming the string has the id $200 LDC R0, C[$200] MOV R1, R0 ADD R0, R1 ; Same result as above

Alloc [identifier]

Free [identifier]

LD.C [register], [resource id]

LD.V [register], [variable id]

LD.D [register], [inline data]

PSH.C [resource id]

PSH.R [register]

PSH.D [inline data]

POP.R [register]

POP.V [variable id]

MOV.R [register], [register]

MOV.V [variable id], [register]

MOV.D [variable id], [inline data]

ADD.C [register], [resource id]

ADD.V [register], [variable id]

ADD.D [register], [inline data]

SUB.C [register], [resource id]

SUB.V [register], [variable id]

SUB.D [register], [inline data]

JSL [offset]

JSE [register], [offset]

BNE [offset]

BEQ [offset]

RTS

NOOP

CMP.C [register], [resource id]

CMP.V [register], [variable id]

CMP.D [register], [inline data]

MUL.R [register], [register]

MUL.C [register], [resource id]

MUL.D [register], [inline data]

DIV.R [register], [register]

DIV.C [register], [resource id]

DIV.D [register], [inline data]

AND.R [register], [register]

AND.C [register], [resource id]

AND.D [register], [inline data]

OR.R [register], [register]

OR.C [register], [resource id]

OR.D [register], [inline data]

NOT.R [register], [register]

NOT.C [register], [resource id]

NOT.D [register], [inline data]

MULDIV.R [register], [register]

MULDIV.C [register], [resource id]

MULDIV.D [register], [inline data]

XOR.R [register], [register]

XOR.C [register], [resource id]

XOR.D [register], [inline data]

LSR.R [register], [register]

LSR.C [register], [resource id]

LSR.D [register], [inline data]

LSL.R [register], [register]

LSL.C [register], [resource id]

LSL.D [register], [inline data]

MOD.R [register], [register]

MOD.C [register], [resource id]

MOD.D [register], [inline data]

SYSCALL [method id]

The second half is the disassembler – and naturally the most important: namely the CPU or virtual machine. Like the disassembler this decodes the instruction bits and executes each instruction accordingly. At high speeds i might add.

So, what on earth is that good for you ask? Well, I have written it in a way that makes it easy to port it to Delphi and Freepascal. So if you are into creating programming languages, game engines, portable services, emulators or whatnot — then this is a very handy piece of tech.

Once you have a working virtual-machine, you can build the high-level language on top of that. And the fact that its portable and you can execute the code inside your Smart Mobile Studio applications, your NodeJS services — or Windows, Linux and OS X (as long as freepascal is there, you are good), that opens up for some interesting ideas.

Pastafari PI

Those that read my blog know that I absolutely love retro machines. Atari, Commodore 64, Amiga, Acorn — I love them all. I grew up with Zx81, Speccy, C64 and Amiga – so naturally I have so many fun memories with these systems that it’s bound to influence me as an adult.

Now I had a broken Amiga 500 in the basement, and I figured — why fork out $200+ for a PITop or some other solution when I can actually do a retro-mod myself.

After all, distros like Amibian (debian based linux) boot straight into the emulated Amiga environment. And the speed is phenomenal! The PI 3 emulates the Amiga 3.2 times faster than the most high-end Amiga ever created. With overclocking we are looking at speeds up to 4 times faster than a juiced up Amiga 4000\ 060 (!)

Well, it’s not finished yet, but I have basically cut the case and made room for a fancy ADX gaming keyboard with sexy led lighting. I had to solder the keyboard controller to make it fit onto the Amiga keyboard back-plate – and also cut the keyboard quite heavily.

The idea is that when I have all the internals working – i will do a lot of epoxy and plastic work to make it look more authentic. Right now it looks very rough and rugged, but it runs like a dream!

I also bought a cheap 2.5″ multi sd-card reader. That came with an internal USB motherboard socket sadly — so I had to cut and do some soldering to make it into a normal external USB connector. And now it just plugs into the PI.

I also adapted the floppy-drive input on the side of the Amiga, so the SD-card reader now sits in place where the original 2.5″ floppydrive once lived.

I’m just waiting for the sd-card extender circuit so i can adapt the front of the Amiga and have the SD-card slot for the PI there. This will make it a snap to change sd-card whenever I want to use another operating system. Im also soldering up a reset and shutdown switch that will also be on the front (that thin region just above the keyboard).

To experienced technicians this no doubt look like a complete mess – but this is my first ever electronic “hands-on” project. I havent touched a soldering pen since highschool, so it was nerve-wreaking digging into the keyboard controller.

The final step is naturally to do some plastic work. I bought a good dose of epoxy for this. Once that is done I have to sand everything down and make the cuts straight and better looking.

And then finally I can give it two coats of black spray paint, and that final coat of transparent paint for hardening. And voila — I’ll have a pretty cool rig to test and work with my Raspberry PI 3!