Author Topic: BASM: Best ASseMbler in my desk room.  (Read 1448 times)

0 Members and 1 Guest are viewing this topic.

Offline krusty

  • CPC464
  • **
  • Posts: 12
    • Awards
BASM: Best ASseMbler in my desk room.
« on: 15:21, 06 October 21 »
Hello,
these last months, I have worked on the Benediction cross ASseMbler that will be used in our next production.I have not yet tested it in real-world conditions, so ATM I have truly no idea of its efficiency/usability.
I write this message to let anyone give it some try and provide me feedback to fix potential bugs and eventually bring more features for its real official release.I guess the official release will be accompanied by a graphic version of basm for those that are not yet ready to use command line tools.


Its aim is not to replace rasm that is a really fast and good assembler. But it can be used in contexts where rasm cannot play. BTW it is not 100%compatible with rasm code.

Of course, there is no documentation ready yet, but you can get most of its possibilities in the files named good_xxx.asm of this directory https://github.com/cpcsdk/rust.cpclib/tree/master/basm/tests/asm.
Among what is not (yet) available for rasm you can check the section, basic, or iterate examples.
Note that basm uses two assembling passes by default, but can stop at the first pass if there is no need to do another one or add additional ones if necessary (which makes the ifused example compatible with basm but not rasm)

Here is its usage

USAGE:
    basm.exe [FLAGS] [OPTIONS] <--inline <INLINE>|INPUT> [--]

FLAGS:
        --basic               Request a Basic header (the very first instruction has to be the LOCOMOTIVE directive.
        --binary              Request a binary header
    -i, --case-insensitive    Configure the assembler to be case insensitive.
        --db                  Write a db list on screen (usefull to get the value of an opcode)
        --snapshot            Generate a snapshot
        --Werror              Warning are considered to be errors
    -h, --help                Prints help information
    -V, --version             Prints version information

OPTIONS:
    -I, --include <INCLUDE_DIRECTORIES>...    Provide additional directories used to search files.
        --inline <INLINE>                     Z80 code is provided inline
        --lst <LISTING_OUTPUT>                Filename of the listing output.
    -l <LOAD_SYMBOLS>...                      Load symbols from the given file
    -o, --output <OUTPUT>                     Filename of the output.
        --sym <SYMBOLS_OUTPUT>                Filename of the output symbols file.

ARGS:
    <INPUT>    Input file to read.


I have included the current windows release here https://ufile.io/rbg1k0es : for those that want to build it themselves, the sources are available here and the command is here https://www.cpcwiki.eu/forum/programming/basm-best-assembler-in-my-desk-room/msg207962/#msg207962

Feel free to create issues here https://github.com/cpcsdk/rust.cpclib/issues or post a message in the forum if it does not assemble your code as you expect (and provide a minimum asm code that reproduce it).
« Last Edit: 09:11, 10 October 21 by krusty »
like
3
Members reacted like:
ComSoft6128,menegator,eliot,

Offline roudoudou

  • 6128 Plus
  • ******
  • Posts: 1.154
  • Country: fr
    • urban exploration
    • Awards
Re: BASM: Best ASseMbler in my desk room.
« Reply #1 on: 15:37, 06 October 21 »
People should hurry up for 《char》asm name  (basm, zasm, rasm, sjasm, vasm, tasm, dasm, ...)


Congratz for this first public release
« Last Edit: 16:58, 06 October 21 by roudoudou »
like
1
Members reacted like:
GUNHED,
use RASM, the best assembler ever made :p

I will survive

Offline zhulien

  • 6128 Plus
  • ******
  • Posts: 917
  • Country: au
  • aka Vorax
    • 8bitology
    • Awards
Re: BASM: Best ASseMbler in my desk room.
« Reply #2 on: 16:32, 06 October 21 »
liked... what happened to the like button anyway?
like
0
No reactions

Offline Targhan

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.426
  • Country: fr
    • Awards
Re: BASM: Best ASseMbler in my desk room.
« Reply #3 on: 23:57, 06 October 21 »
Cool. But I don't think I would switch to yet another assembler... unless you can show me things you can do better than Rasm!
like
0
No reactions
Targhan/Arkos

Arkos Tracker 2.0.1 now released! - Follow the news on Twitter!
Disark - A cross-platform Z80 disassembler/source converter
FDC Tool 1.1 - Read Amsdos files without the system

Imperial Mahjong
Orion Prime

Offline Sid_

  • CPC664
  • ***
  • Posts: 134
  • Country: fr
    • Awards
Re: BASM: Best ASseMbler in my desk room.
« Reply #4 on: 11:43, 07 October 21 »
Hi Krusty,
where can I find the sources to compile it on macOS and linux ?


Offline krusty_benediction

  • CPC6128
  • ****
  • Posts: 209
  • Country: fr
    • Awards
Re: BASM: Best ASseMbler in my desk room.
« Reply #5 on: 18:41, 07 October 21 »
Cool. But I don't think I would switch to yet another assembler... unless you can show me things you can do better than Rasm!
I do not know what to answer ;)If you are happy of your workflow with rasm, there is no reason to change.
If you want to use additional features, such as those I presented in the first post, there is an interest to use basm.

Offline krusty_benediction

  • CPC6128
  • ****
  • Posts: 209
  • Country: fr
    • Awards
Re: BASM: Best ASseMbler in my desk room.
« Reply #6 on: 18:44, 07 October 21 »

Hi Krusty,
where can I find the sources to compile it on macOS and linux ?

At the moment, basm is buried in my CPC toolbox. I may change that later and ease the installation procedure.
So you just need to clone the repository https://github.com/cpcsdk/rust.cpclib and use the command line of first post


See https://www.cpcwiki.eu/forum/programming/basm-best-assembler-in-my-desk-room/msg207962/#msg207962

Offline Targhan

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.426
  • Country: fr
    • Awards
Re: BASM: Best ASseMbler in my desk room.
« Reply #7 on: 00:38, 08 October 21 »
The Section looks interesting, though I don't think I would ever use it (doesn't it clutter the code?).
like
0
No reactions
Targhan/Arkos

Arkos Tracker 2.0.1 now released! - Follow the news on Twitter!
Disark - A cross-platform Z80 disassembler/source converter
FDC Tool 1.1 - Read Amsdos files without the system

Imperial Mahjong
Orion Prime

Offline krusty_benediction

  • CPC6128
  • ****
  • Posts: 209
  • Country: fr
    • Awards
Re: BASM: Best ASseMbler in my desk room.
« Reply #8 on: 09:25, 08 October 21 »
The Section looks interesting, though I don't think I would ever use it (doesn't it clutter the code?).
I think it is clean and nice for moderated size projects as you can provide some kind of semantic to your memory area in one place instead of relying on assertions to manually check if you write code in forbidden zones (and I am pretty sure it would be more unreadable for assertions in some code I have in mind).
I think it is wonderful for generated code where data and code are interleaved (think about a demo effect that use 100÷ of line to line splitting memory area and the rest for the demo effect). You can simplify the generator by letting basm doing the checks (instead of the generator that would have to know the size of generated code) and by generating separately data source and code source wheras thé would be mixed once assembled.
Finally it can ease writing a some ugly stuff that would have been useful for me when writing crtc (for example to have some code in an effect source code injected in the demo system area, instead of putting it in the demo system source)
I have not yet intensively tested this directive, but I will surely use it intensively in my next project

Offline krusty_benediction

  • CPC6128
  • ****
  • Posts: 209
  • Country: fr
    • Awards
Re: BASM: Best ASseMbler in my desk room.
« Reply #9 on: 09:07, 10 October 21 »
Hi Krusty,
where can I find the sources to compile it on macOS and linux ?
Hi have updated a bit the repo; so the previous answer is no more correct. Here is the new one:
git clone https://github.com/cpcsdk/rust.cpclib.git
cd rust.cpclib/basm && cargo install --path=. --bin=basm

Offline krusty

  • CPC464
  • **
  • Posts: 12
    • Awards
Re: BASM: Best ASseMbler in my desk room.
« Reply #10 on: 13:17, 15 October 21 »
I guess it is becoming usable. The following piece of code is assembled by basm version on github that generates the accompanying snapshot. I'll search how to delegate to github the construction of windows/linux/mac binaries after each commit (if someone already masters that, help is welcomed)


    macro KILL_SYSTEM
        di
            ld hl, $c9fb
            ld ($38), hl
            ld sp, $4000
        ei
    endm

    macro WAIT_VSYNC
        ld b, $f5
@loop
        in a, (c)
        rra
        jr nc, @loop
    endm

    macro WAIT_VSYNC_STRICT
        ld b, $f5
@loop1
        in a, (c)
        rra
        jr c, @loop1
        WAIT_VSYNC (void)
    endm

    macro SET_CRTC reg, value
        ld bc, $bc00 + {reg} : out (c), c
        ld bc, $bd00 + {value} : out (c), c
    endm

BACKGROUND equ $54

    struct RASTER_BAR

ink1        db BACKGROUND ; space for ink1 of raster
ink2        db BACKGROUND
ink3        db BACKGROUND
ink4        db BACKGROUND
ink5        db BACKGROUND ; space for ink5 of raster

    endstruct
   
RASTER_HEIGHT equ RASTER_BAR

    org 0x4000

    KILL_SYSTEM (void)
    SET_CRTC 6, 0

    di
    WAIT_VSYNC_STRICT (void)
   
    call frame_loop
    jr $

frame_loop
        WAIT_VSYNC (void)


        ld b, 30
    .loop
            nop 64 - (duration(djnz .loop) + 1) ; duration of djnz is the one with no jump
        djnz .loop

        call show_raster
   
    jp frame_loop


show_raster

    ; manage the sine wave for the vertical position
    nop 15 
    ld hl, sine_curve
.curve_position equ $-2
    ld b, (hl)
    inc l
    ld (.curve_position), hl
.loop
    nop 64 - (duration(djnz .loop) + 1) ; duration of djnz is the one with no jump
    djnz .loop

    ; really display the raster bar
    ld bc, $7f10
    ld hl, raster_table.bar1
    out (c), c
   
    repeat RASTER_HEIGHT, loop

        ticker start @raster_line_duration
            ld a, (hl)
            out (c), a

            if {loop} != RASTER_HEIGHT
                inc hl
            endif
        ticker stop

        nop 64-@raster_line_duration

    endr
    ld a, BACKGROUND
    out (c), a

    ret

raster_table
.bar1
    RASTER_BAR $44, $55, $5C, $55, $44


    align 256
sine_curve
.height equ min(255, 312 - 30 - 8)

    repeat 256, i
        val set .height/2*cos({i}*360/256) + .height/2 + 1
        print {hex}$, "=", val
        db val
    endr





   

like
3
Members reacted like:
tronic,roudoudou,Targhan,

Offline Targhan

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.426
  • Country: fr
    • Awards
Re: BASM: Best ASseMbler in my desk room.
« Reply #11 on: 16:23, 15 October 21 »
I'll search how to delegate to github the construction of windows/linux/mac binaries after each commit
After each commit? Isn't that's a bit too much?
GitHub might have a CI available though, but it might not be free. For Arkos Tracker, I use a local CI (Jenkins).
like
0
No reactions
Targhan/Arkos

Arkos Tracker 2.0.1 now released! - Follow the news on Twitter!
Disark - A cross-platform Z80 disassembler/source converter
FDC Tool 1.1 - Read Amsdos files without the system

Imperial Mahjong
Orion Prime

Offline roudoudou

  • 6128 Plus
  • ******
  • Posts: 1.154
  • Country: fr
    • urban exploration
    • Awards
Re: BASM: Best ASseMbler in my desk room.
« Reply #12 on: 23:39, 15 October 21 »
After each commit? Isn't that's a bit too much?
isn't it the very common nightly build?
like
0
No reactions
use RASM, the best assembler ever made :p

I will survive

Offline krusty

  • CPC464
  • **
  • Posts: 12
    • Awards
Re: BASM: Best ASseMbler in my desk room.
« Reply #13 on: 11:16, 16 October 21 »
After each commit? Isn't that's a bit too much?
GitHub might have a CI available though, but it might not be free. For Arkos Tracker, I use a local CI (Jenkins).

I wanted to say push; but not it is not too much often for a hobbyist project I guess ;)
I am able to build with github (at least for Linux) but I have net succeded in publishing automatically.
like
0
No reactions

Offline krusty_benediction

  • CPC6128
  • ****
  • Posts: 209
  • Country: fr
    • Awards
Re: BASM: Best ASseMbler in my desk room.
« Reply #14 on: 22:10, 22 October 21 »
New directive supported (not deeply tested however): FUNCTION
      ;;
    ; The function `name` takes 3 arguments arg1, arg2, and arg3,
    ; uses a local variable
    ; and returns a value (the sum of the two arguments).
    ; No z80 code is allowed there, but it is possible to use some directives
    FUNCTION name, arg1, arg2, arg3

        IF {arg3} > 0
                  local1 = {arg1} + {arg2}
        ELSE
                  local1 = {arg1} - {arg2}
        ENDIF

        IF {arg1} > 2
            return local1
        ENDIF

        repeat 3
            local1 = local1+1
        rend

        return local1
       
    ENDFUNCTION
   
    ; Use the function name
    ld a, name(0, 1, 2)
    assert name(0, 1, 2) == 4
    assert name(3, 3, -2) == 0

Offline krusty_benediction

  • CPC6128
  • ****
  • Posts: 209
  • Country: fr
    • Awards
Re: BASM: Best ASseMbler in my desk room.
« Reply #15 on: 22:18, 22 October 21 »
Recursivity is even possible
    function fibo nb
        if {nb} == 0
            return 0
        else if {nb} == 1
            return 1
        else
            return fibo({nb}-1) + fibo({nb}-2)
        endif

    endfunction

    assert fibo(0) == 0
    assert fibo(1) == 1
    assert fibo(5) == 5
    assert fibo(10) == 55

Offline krusty_benediction

  • CPC6128
  • ****
  • Posts: 209
  • Country: fr
    • Awards
Re: BASM: Best ASseMbler in my desk room.
« Reply #16 on: 20:53, 05 November 21 »
Basm is now able to handle strings and list of expressions in addition to standard numeric values.It is now possible to create functions that generate a string of z80 code and assemble it.This add abilities to generate code in a more powerfull way than macros.
For example here is an extract of what is possible:

...
code = get_specialized_code(main_mask, screen_lines_order, sprite_lines_order, 0)binary = assemble(.code)
        db binary
        assert memory($-1) == 0xc9, string_concat("The routine does not end by RET!", code, binary)

       
        print code
with get_specialized_code a function written in the asm file that returns z80 code in a string and takes as input 3 lists and a numeric value.The generateds code is also printed in the terminal to quickly check what is generated

Offline GUNHED

  • 6128 Plus
  • ******
  • Posts: 2.899
  • Country: de
  • Reincarnation of TFM
    • FutureOS - The quickest OS for the CPC and Plus
    • Awards
Re: BASM: Best ASseMbler in my desk room.
« Reply #17 on: 21:08, 05 November 21 »
People should hurry up for 《char》asm name  (basm, zasm, rasm, sjasm, vasm, tasm, dasm, ...)


Can I call mine TASManian DEVil ??
like
1
Members reacted like:
roudoudou,
http://futureos.de --> Get the revolutionary FutureOS (Update: 2021.01.24)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.07.15)

Offline krusty_benediction

  • CPC6128
  • ****
  • Posts: 209
  • Country: fr
    • Awards
Re: BASM: Best ASseMbler in my desk room.
« Reply #18 on: 13:08, 11 November 21 »
Such syntax is now valid to ease number reading:
Quote
SCREEN_CONFIGURATION equ 0b00101100_00000000
(you can you any combination of _ and number)


Offline krusty_benediction

  • CPC6128
  • ****
  • Posts: 209
  • Country: fr
    • Awards
Re: BASM: Best ASseMbler in my desk room.
« Reply #19 on: 10:02, 18 November 21 »
I have finally been able to play with `github` actions to do continuous delivery.
You can find at this page https://github.com/cpcsdk/rust.cpclib/releases/tag/latest the executable for my various tools (including basm) that are updated after each push to the master branch.

The complete list of tools is (lots are probably barely usable at the moment as I implemented only what I needed at a specific moment, but I can update/fix on demand)
  • basm: z80 assembler. Fully usable for simple projects. Complex directives may not be deeply tested. Able to communicate with M4
  • bdasm: z80 disassembler. Requires still minor modifications to improve display of relative instructions
  • catalog: probably unfinished AMSDOS catalog manipulation
  • hideur: play with AMSDOS header files
  • imgconverter: PC to CPC image conversion. Used for CRTC demo. Some features (tiles ones for example) may not be finished. Able to communicate with M4
  • locomotive/ probably unfinished LOCOMOTIVE BASIC manipulation tool.
  • snapshot: SNA manipulation tool. Able to communicate with M4
  • visual-basm: Attempt to provide a GUI to basm. Could be useful to help people working with winape unable to switch to console tools