1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-07-13 14:29:23 +00:00
6502bench/SourceGen/SGTestData/Source/20042-address-changes.S
Andy McFadden 99cd0d3ac1 Improve handling of C64 PRG header
C64 PRG files are pretty common.  Their salient feature is that they
start with a 16-bit value that is used as the load address.  The
value is commonly generated by the assembler itself, rather than
explicitly added to the source file.

Not all assemblers know what a PRG file is, and some of them handle
it in ways that are difficult to guarantee in SourceGen.  ACME adds
the 16-bit header when the output file name ends in ".prg", cc65
uses a modified config file, 64tass uses a different command-line
option, and Merlin 32 has no idea what they are.

This change adds PRG file detection and handling to the 64tass code
generator.  Doing so required making a few changes to the gen/asm
interfaces, because we now need to have the generator pass additional
flags to the assembler, and sometimes we need code generation to
start somewhere other than offset zero.  Overall the changes were
pretty minor.

The 20042-address-changes test needed a 6502-only variant.  A new test
(20040-address-changes) has been added and given a PRG header.  As
part of this change the 65816 variant was changed to use addresses
in bank 2, which uncovered a code generation bug that this change
also fixes.

The 64tass --long-address flag doesn't appear to be necessary for
files <= 65536 bytes long, so we no longer emit it for those.

(issue #90)
2020-10-17 16:45:13 -07:00

118 lines
2.8 KiB
ArmAsm

; Copyright 2018 faddenSoft. All Rights Reserved.
; See the LICENSE.txt file for distribution terms (Apache 2.0).
;
; Assembler: Merlin 32
; 65816 version
org $1000
clc
xce
sep #$ff ;set all flags
mx %11
jsr one
jsr three_p ;should land inside one
jmp nextthing
org $1100
one bit one
one_p lda #$11
ldx #$11
ldy #$11
per one_p
bra one_p
org $1100
two bit two
lda #$22
two_p ldx #$22
ldy #$22
per two_p
jmp two_p
org $1100
three bit three
lda #$33
ldx #$33
three_p ldy #$33
per three_p
bra three_p
org $2000
nextthing
bit nextthing
beq :fwd-8 ;should just appear as hex since it's outside
bra :fwd ;BRA across org segments
org $2020
:fwd bit :fwd
beq offend ;branch off the end of the address area into dead space
brl endcheck ; (which wouldn't be dead without the org)
nop
offend
org $2080
endcheck
bit endcheck
lda offend-1 ;touch bytes at the ends, and one byte before/after
jsr offend-1
lda offend
jsr offend
lda endcheck-1
jsr endcheck-1
lda endcheck
jsr endcheck
lda $00
beq :midinst
dfb $ad ;LDA abs
org $2100
:midinst dfb $ea,$ea
jmp pastdata
org $2800
dw *
ds 16 ;EDIT: put an org change in the middle
org $2820
ds 16
org $3000
pastdata
bit pastdata
lda #$44
ldx #$44
ldy #$44
brl :fwd
dfb $00 ;put user label here or next inst
:datend dfb $01
org $3100
dfb $02 ;data target should NOT get merged with previous user label
:fwd
bit :fwd
lda :datend-1
lda :datend
lda :datend+1
lda :datend+2
lda :fwd-1
beq :more
dfb $ea,$ea ;EDIT: mark as inline data
org $3180
dfb $00,$01
:more bit :more
; xref edge case test: make sure adjustment shown is based on address
lda label1
lda label2 ;EDIT: set operand to sym=label1
lda label3 ;EDIT: set operand to sym=label1
bra label3
label1 nop
label2 nop
org $3200
label3 bit label3
dfb $00,$01 ;EDIT: mark as inline data to test execution off end