10.12. Overlapping memory block

When all blocks of a segment are assembled, any overlaps are detected. Normally overlaps will give an error but you can allow overlap with the 'allowOverlap' parameter. This is useful if you want to patch files. Here is an example where the file "base.prg" is applied two changes and saved to the file "patched.prg":

        // Setup
        .file [name="patched.prg", segments="Base,Patch", allowOverlap]
        .segmentdef Base [prgFiles="data/base.prg"]
        .segmentdef Patch []

        // Patch Code 
        .segment Patch
        *=$3802 "Insert jmp"
        jmp $3fe0
        
        *=$38c2 "Insert lda #$ff"
        lda #$ff

The memory map looks like this:

Base-segment:
  $3800-$39ff base.prg

Patch-segment:
  $3802-$3804 Insert jmp
  $38c2-$38c3 Insert lda #$ff

In the above example we have a base segment with the original file and a patch segment with the modifications. They are combined in the intermediate segment generated by the file directive which has the allowOverlap parameter set.

Overlapping blocks are cut so the byte from the block with the highest priority are returned. The latest added blocks wins so since the 'Patch' segment lies after 'Base' in the segments list the patch code is chosen.