vasm.py: a mini-assembler for vCPU code

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice. No drama.
Post Reply
User avatar
marcelk
Posts: 490
Joined: 13 May 2018, 08:26

vasm.py: a mini-assembler for vCPU code

Post by marcelk » 08 Apr 2020, 13:38

I always wanted a stand-alone vCPU assembler that can produce .gt1 files. But I didn't want to put effort in writing a front end. So I took the principles from Core/asm.py and created Core/vasm.py. This is (the back end for) a symbolic vCPU assembler. For reference, with 103 lines it is smaller than gtemu.c, although that wasn't a goal.

As with asm.py, the idea is that you use Python syntax as your front end notation. We experimented a bit so that we can now fake indentation, a well-known problem of using Python for this purpose. The extension for these programs is .vasm.py . As an example, here is Blinky2.vasm.py:

Code: Select all

# Please build this from the Makefile
from vasm import *

p=0x30                          # User variables start from $30 in zero page

ORG(0x200)                      # User programs can start from $200
-               LDWI(0x800)     # Top left pixel
-               STW(p)          # Pointer variable p
L('Loop');      POKE(p)         # Update pixel
-               ADDI(1)         # Increment vAC
-               BRA('Loop')     # Loop forever

END(0x200)                      # Execution start address
You then create a .gt1 file with:

Code: Select all

$ make Apps/Blinky/Blinky2.gt1
It disassembles as expected:

Code: Select all

$ gt1dump.py -d Apps/Blinky/Blinky2.gt1 
* file: Apps/Blinky/Blinky2.gt1

0200  11 00 08          [vCPU] LDWI  $0800              |...|
0203  2b 30                    STW   $30                |+0|
0205  f0 30                    POKE  $30                |p0|
0207  e3 01                    ADDI  1                  |c.|
0209  90 03                    BRA   $0205              |..|
* 11 bytes

* start at $0200
This may be useful for those who don't want to learn GCL, but just want something light and semi-familiar. Don't forget you have all the power of Python at your finger tips, so you have macros with `def' and can evaluate expressions.

Bug reports and feature requests through GitHub please. I can foresee some tweaks, but I don't aspire to turn this into a castle.

User avatar
marcelk
Posts: 490
Joined: 13 May 2018, 08:26

Re: vasm.py: a mini-assembler for vCPU code

Post by marcelk » 10 Apr 2020, 20:54

From a different thread:
jbailey wrote:
10 Apr 2020, 04:40
Now we have a assembler to make software using the vCPU instructions, let the fun begin.
Of course since 2018 we already have a vCPU assembler, written in C++, as part of at67's simulator suite. Tetronis and Bricks were made with it.

I just needed something light and stand-alone for quick experimentation, and decided to check it in and let people know it's there as an option. I have no expectation that now all of the sudden new games emerge... But I'ld welcome that more than anything else of course :-).

at67
Posts: 201
Joined: 14 May 2018, 08:29

Re: vasm.py: a mini-assembler for vCPU code

Post by at67 » 11 Apr 2020, 04:10

marcelk wrote:
10 Apr 2020, 20:54
Of course since 2018 we already have a vCPU assembler, written in C++, as part of at67's simulator suite. Tetronis and Bricks were made with it.

I just needed something light and stand-alone for quick experimentation, and decided to check it in and let people know it's there as an option. I have no expectation that now all of the sudden new games emerge... But I'ld welcome that more than anything else of course :-).
The Assembler I produced is available as a standalone light weight console command under Windows and Linux as well as being embedded within the Emulator, the same as the BASIC compiler gtBASIC and all the other tools I have coded, (MIDI generation, etc).

i.e. You don't need to run the emulator if you just want to compile or assemble from the command line.

User avatar
marcelk
Posts: 490
Joined: 13 May 2018, 08:26

Re: vasm.py: a mini-assembler for vCPU code

Post by marcelk » 11 Apr 2020, 13:32

Although the Python macros are important to me, one reason vasm.py is there is to help another maker boot strap his software stack. I found that asm.py has grown too large to explain the concept. The small 2017 version was really single-person and single-purpose (to build ROMv1). I'm glad we normalised that version afterwards.

The best thing that came out of this exercise is the realisation that the ROM sources should have the extension .asm.py. That is more self-documenting that just .py, of which I know it confused some in the past.

It would be great if we can bring your vCPU assembler into Utils/, as we brainstormed some time ago. Hopefully as soon as you feel comfortable to announce beta status for the BASIC compiler?

at67
Posts: 201
Joined: 14 May 2018, 08:29

Re: vasm.py: a mini-assembler for vCPU code

Post by at67 » 12 Apr 2020, 04:10

marcelk wrote:
11 Apr 2020, 13:32
It would be great if we can bring your vCPU assembler into Utils/, as we brainstormed some time ago. Hopefully as soon as you feel comfortable to announce beta status for the BASIC compiler?
I've been happy with the state of the Assembler for a while now, full expression evaluation with floating point literal support, recursive includes, parameterised macros and with decent documentation it's ready to go.

But the compiler still needs some work, two dimensional arrays, sprites and sampled sound are the main culprits left to tackle. The real challenge is; thorough documentation.

Oh woe is me.

Post Reply