dasm-assembler / dasm

Macro assembler with support for several 8-bit microprocessors

Home Page:https://dasm-assembler.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

add features from other Dasm forks like improved incbin

Thcm72 opened this issue · comments

I'm missing some nice additions from other Dasm forks like the ones from tlr or iAN CooG:

https://csdb.dk/release/?id=182815
http://iancoog.altervista.org/

For example:

  1. incbin directives may have offset and length.

incbin [,[,]]


FNAME eqm "file4.bin"
a:
incbin "file1.bin"
b:
incbin "file2.prg",2
incbin "file3.bin",0,16
incbin FNAME, 0, b-a

  1. add otuput of VICE compatible symbol lists

And a lot more was added and fixed.

While the whole point of open source is to allow people to fork the code and add their own features, I think the goal in the long run is to keep a single point of contact for distribution of dasm. I think the task here will be to identify the changes made in this version (of which I was totally unaware until now) and integrate anything that makes any sense into the current dasm.

My first thoughts, since it was branched 2.20.11, is to grab the source for both and do a diff. I may tackle that today.

My very first comment on this new code is the addition of this notice...

Copyright (c) 2009-2019 by Daniel Kahlin.

IMHO you just can't do that. You can't back-copyright stuff that isn't your creation, and is in the public domain.

On review, the codebase is changed too much to warrant spending time on trying to trace the individual issues.

In particular, a large number of changes have been made to adjust the code to the new author's personal style.

  1. variables names and function names have been changed nearly everywhere -- e.g., setspecial(...) --> set_special()
  2. all boolean comparisons have been changed to explicit rather than implicit -- e.g., if (tmp->flags & SYM_MACRO) --> if ((tmp->flags & SYM_MACRO) != 0), and for (s = sym; s; s = s->next) --> for (s = sym; s != NULL; s = s->next)
  3. many if not all function parameters have been changed to const where appropriate.
  4. booleans have become explicit rather than implicit. e.g., sym = eval(str, 0); -->. sym = eval(str, false);
  5. a memory leak has been introduced to correct a segfault

There's more. Just way too many changes for me to even consider hunting for the gold. The author has clearly put a lot of time into making this version, but I don't think what I see in the source is of much use to us at this stage.

I'm not saying all the changes made are wrong - but many are related to personal preference on style, not correctness or functionality. The new features seem to be obscured amongst all the other changes. My diff/comparison tool is a sea of red (changed) lines. I was unable, given a short time, to identify what the new features are.

I think if we want to merge the code, we need to approach the author and ask some questions. Also, perhaps that new copyright notice should be challenged! Copyright (c) 2019 would be fine. Not encompassing the 10 year period prior to that!

I'm not entirely sure who made the style changes, now. The SVN version 2.10.11 (which is numbered 2.20.12 internally) appears to be pre-PFH, so much of the mass of red may be because I'm comparing an incorrect version....?

Wouldn't it be ironic if I was the origin of those changes... LOL

Merging stuff might be too much work. Maybe integrating some ideas or additions like the incbin stuff might be easier. I switched from the old 2.10.11 an 2.10.12 to iAN CooGs version, because they had serious problems correctly assembling stuff using rorg rend.

I could not find ANY documentation in the likely places that list the additions/changes.
It's not in the readme, news, releases, or docs directory...
So, unless you know what you're looking for...?

Here are the changes from iAN CooGs Dasm which was special tailored for the c64 (from the dasm.doc:

VERSIONS:

v2.20.07b

  • 6502 made default and only one supported
  • removed support for other 68xxx cpus
  • PROCESSOR directive now is always ignored
  • default output name "a.prg" instead of inconsistent *nix style "a.out" :/
  • added check for "lsr a" to be interpreted as "lsr", same for asl/rol/ror
  • added "*=" , equivalent of "org" ; a space is required between *= and address
  • added mnemonic variations of illegal opcodes (axm/xaa etc.)

v2.20.07c

  • implemented SCRU/SCRL directives (like in C64ASM) to convert ascii->screencodes
  • rebuilt with OlafFreeFormat defined, to allow labels and mnemonics on any
    positions. Else, labels could be only defined in column1, and mnemonics had
    to be defined at least on column 2, for example:

label
value = $ff
lda #$00

Now can be written
label lda #00

v2.20.07d

  • OlafFreeFormat default, new param -H to select Hashformat

  • INCPRG implemented.
    INCBIN is for including raw binaries. To include c64 prgs, skipping the 2
    byte startaddress, use INCPRG.
    The file startaddress is normally ignored, use ORG to force loading to a
    different address from the current one. Address can be forced after the file
    name, in decimal or $hex notation, or a "L" to force reading and setting the
    new ORG from loadaddress. For example:

    *= $801
    incprg header.prg ; load header.prg at current address ($0801)

    incprg file1.prg ; load file1.prg at current address ($0801+header.prg len)

    incprg file2.prg,$1000 ; load file2.prg at $1000

    incprg koalapic.prg,L ; load koalapic.prg at original address ($6000)

v2.20.07e

  • parameter -t (lowercase) was used as tempdir, deprecated so i removed it
    parameter -t/-T now is used for Symbol Table sorting

  • Started modifications in function generate() to allow reversed origin address.
    Because DASM is generating .prg directly on disk, the lowest known/used
    origin address MUST be specified first, then all others can be freely set.

    for example:

    ALLOWED! NOT ALLOWED
    *= $0801 *= $c000
    *= $c000 *= $0801
    incprg ...
    *= $1000

    (See X*.ASM samples for more)

    a workaround will be done shortly.

v2.20.07f

  • including non-existant files could cause crashes, fixed
  • fixed reopening of destination prg during 2nd (and subsequent) compilation
    passes, that caused garbage and/or wrong filler byte between unused areas.
    Tested using *= $0801,$bd (fills unused mem with $bd instead of 0)

v2.20.07g
Bugs:

  • Crashed on too many passes (>16), the error was in the error message
    handler, trying to display a NULL pointer :-)

  • fixed another issue of bad filling between ORGs in case of forward reference
    to a new ORG. Under WinXP the filler seems always 0, but on W98 garbage was
    taken from the current disk sector. Simple example:

     *= $0801,$ea
     lda #$00
     sta label
     rts
     ;
     ; expect garbarge/zeroes here instead of filler byte
     ;
     *= $1000
    

    label
    byte 0

    Fixed this, there should be no more. :P

Interface:

  • Added ending address display at end of compile.
  • Reorganized the segments output in verbose mode. Should be more clear now.
  • Raised maxpasses to 32. Used for debug, but saw that was good in sources
    with many forward references (use of labels defined further in the source)
    As always can be changed with -p/-P parameter.

New / improved commands:

  • Fixed SCRU/SCRL behaviour on SCRL "@" that was truncating the string
  • Implemented ASC "string" (equivalent of .byte "string", no coversion
    From PC Ascii set is done)
  • Implemented PETC/TEXT "string" (converts ascii to petscii)
  • Removed END, can't find any use of it. Allows labels to be called end :)

v2.20.07h

  • Numbers starting with 0 (010,0777 etc) were interpreted as octal numbers.
    I felt this a little bit annoying when converting some 0-padded datas:
    BYTE 000,010,020,030
    BYTE 040,050,060,070
    should have been manually edited to
    BYTE 0, 10, 20, 30
    BYTE 40, 50, 60, 70
    Now those are treated as normal decimal numbers, and I created a new prefix
    for octal notation, '@' (@010 or @10) for those bothering to use such crap :P

  • added small cx.exe w/src for converting binaries to byte listings.
    usage:

    c:\path> cx mydata.bin > mydata.s

    then add to your source

    include mydata.s

v2.20.07i

  • Fixed opening of sources (main and INCLUDEd) in binary mode.
    This allows to read *nix style '\n' terminated lines without any other
    modification (Hi Ice00! :D)
  • Fixed a buffer overflow when reading lines longer than 255 bytes, in one
    particular case. I found a silly separator line in a source, like:

xxxxxxxxxxxxxxxxxxxxx[etc over 256chars]xxx:

the ":" probably means it was expected to be interpreted as a label (OMG!)
If the line was a comment starting with ";" the overflow would happen with
slightly longer lines, but would happen anyway.
Lines are now trimmed to 254 bytes after read, which are MORE than enough in
a 6510 asm source! :)

v2.20.07j

  • parser now accepts indexed addressing with spaces beteen "," and register.
    For example:
    LDA ($FF), Y
    LDA (zplabel) , y
    LDA ( zplabel ), Y
    LDA LABEL, X
    etc.
  • ORG form *=$xxxx (without spaces) now accepted.
    Internally it's interpreted like * = $xxxx by inserting the missing spaces.
    Same goes for labels definitions: label=$xxxx becomes label = $xxxx and
    will be parsed correctly
  • *= pseudo-op removed due to previous fix, no more need of it.
  • in list file (-l) there was no reference to Relative Org (RORG) address.
    Made a couple of hacks to print RORG address next to the current ORG.
  • Fixed a SegFault when listing and input source line was >MAXLINE chars.
  • Similarly another SegFault trying to increase MAXLINE is fixed.
    Now MAXLINE can be set more than 256, I set the limit to 2048 in asm.h
  • Adapted for compilation under Linux by Eregil
  • Updated CX to v0.2, -s parameter added to skip loadaddres on prgs.

v2.20.07k

  • Implemented SCRUR/SCRLR to generate reversed screencodes (reqd by MTR/Viruz)

v2.20.07-iAN-rev-L 20080508

  • Fixed error message on parameters -o, -s, -l when the required filename
    was not supplied

  • Fixed error message in case of too many passes

  • Added Vice-compatible symbol tables, to be loaded in Vice monitor.
    With parameter -t2 now symbols dumped with -s will be in this format:

    al C:$080a .eop
    al C:$080b .sys
    al C:$080d .loop1
    [etc]

    you can load the label definitions in vicemonitor with: ll "file"

v2.20.07-iAN-rev-M 20141107

  • incbin now also accepts 2 parameters: offset and size
    Requested by THCM/Oxyron, code borrowed and adapted from TLR/Viceteam dasm.

v2.20.07-iAN-rev-N 20160125

  • local labels for VICE format slightly improved, previously they were dumped
    how DASM treats them internally, but VICE don't like them. Example

      *=$1000
    

main subroutine
ldx #$00
.loop inx
bne .loop
rts

this produced a symbol list like this:

al C:$1000 .main
al C:$1002 .1.loop

the extra "1." is added by DASM internally to distinguish local labels that can
have the same name repeated in the source. VICE doesn't like either labels
starting with numbers or containing a '.', so I've added an '' before the number
and also replaced the extra '.' with '
', now creating this output:

al C:$1000 .main
al C:$1002 ._1_loop

Here the ones from TLR:

README.tlr

This document describes a set of patches for dasm written by tlr.
They are based on dasm-2.20.11-r323
(r323 in the Subversion repository at http://dasm-dillon.sourceforge.net/)

1: Forced operands now really force. Previously a .z wouldn't hard set
the instruction size to 2, leading to strange problems in some cases.

before:
sta.z $1000 -> 8D 00 10 STA $1000
now:
sta.z $1000 -> Error!

It would also lead to problems with code in zero page.
The code below would previously fail with:
test2.asm (5): error: Label mismatch...
--> i1 0023


    processor 6502
    org       $0020
    inc.z     i1+1

i1:
lda #0
rts

2: Forced extensions try to keep the addressing mode of the instruction.
This affects extensions b,z,d and w,e,a.
Using extensions like .wx, .wy and similar will override the addressing
mode like in previous versions.

before:
ldx.w $24,y -> AE 24 00 LDX $0024
now:
ldx.w $24,y -> BE 24 00 LDX $0024,Y

3: C64 DTV2/3 instruction support

processor DTV
bra ($12)
sac # ($32)
sir # ($42)

4: Filenames for include directives may be symbols.

include, incdir, incbin now takes symbols as arguments.
This means unquoted strings are no longer allowed.
The symbol must be defined at the time of the include statement.


FNAME eqm "file2.i"
include "file1.i"
include FNAME

5: incbin directives may have offset and length.

incbin [,[,]]


FNAME eqm "file4.bin"
a:
incbin "file1.bin"
b:
incbin "file2.prg",2
incbin "file3.bin",0,16
incbin FNAME, 0, b-a

dasm-tlr started out as a set of patches for dasm based on dasm-2.20.11-r323
(r323 in the Subversion repository at http://dasm-dillon.sourceforge.net/)

I've done these improvements mainly to suit my own needs but I'm providing
the code for others to use.

+----------------------------------+
| DIFFERENCES to dasm-2.20.11-r323 |
+----------------------------------+

1: Forced operands now really force. Previously a .z wouldn't hard set
the instruction size to 2, leading to strange problems in some cases.

before:
sta.z $1000 -> 8D 00 10 STA $1000
now:
sta.z $1000 -> Error!

It would also lead to problems with code in zero page.
The code below would previously fail with:
test2.asm (5): error: Label mismatch...
--> i1 0023


    processor 6502
    org       $0020
    inc.z     i1+1

i1:
lda #0
rts

2: Forced extensions try to keep the addressing mode of the instruction.
This affects extensions b,z,d and w,e,a.
Using extensions like .wx, .wy and similar will override the addressing
mode like in previous versions.

before:
ldx.w $24,y -> AE 24 00 LDX $0024
now:
ldx.w $24,y -> BE 24 00 LDX $0024,Y

3: C64 DTV2/3 instruction support

processor DTV
bra ($12)
sac # ($32)
sir # ($42)

4: Filenames for include directives may be symbols.

include, incdir, incbin now takes symbols as arguments.
This means unquoted strings are no longer allowed.
The symbol must be defined at the time of the include statement.


FNAME eqm "file2.i"
include "file1.i"
include FNAME

5: incbin directives may have offset and length.

incbin [,[,]]


FNAME eqm "file4.bin"
a:
incbin "file1.bin"
b:
incbin "file2.prg",2
incbin "file3.bin",0,16
incbin FNAME, 0, b-a

6: files may be included from the command line using the '-i' option

7: include/incbin/incdir are now searching relative to the location of
the current source file (-r1). This behaviour can be reverted using -r0.
Note: This only works correctly when using '/' as path separator.
(you should be doing this anyway or else the source will not
assemble on anything else than Windows)

8: include/incbin now fails on missing files. Setting -m0 will ignore
missing files with a warning.

9: unary '^' takes 24-bit msb.

dasm-2.20.11-r323-20191016-tlr (20191016) tlr
- no more random segfaults on "ERR" pseudo ops (at the
expense of some memory leakage in that case)
- unary '^' takes 24-bit msb
- unary '+' is allowed
- include/incbin will fail on missing files by default. -m0 will
ignore with a warning
- include/incbin files are now searched relative to the location of
the current source file
- incdir statements are now relative to the location of the current
source file
- relative behaviour can be disabled using -r0
- added -i command line option to include files from the command line
- corrected behaviour of the -I command line option. (it previously
required redundant quoting in many cases)
- added required include file as pointed out by TCE
- corrected size of strlist to make dasm compile for 64-bit targets
- improved consistency of shell exit status
- corrected problem making repeat/repend within macros unsafe on some
64-bit targets
- added experimental wrapper xdasm to handle various exporting options

TY. Great info and useful for discussion of what to import/include for a merge.

I got info from tlr which might be useful:

In my first 2009 release ( dasm-2.20.11-r323-20090221-tlr ), the r323 version that everything was originally forked from is included unmodified. That may be useful for Andrew to help in extracting relevant patches.

https://csdb.dk/release/?id=103250