diff --git a/SourceGen/AsmGen/AsmAcme.cs b/SourceGen/AsmGen/AsmAcme.cs index 9eefc9e..7667bbf 100644 --- a/SourceGen/AsmGen/AsmAcme.cs +++ b/SourceGen/AsmGen/AsmAcme.cs @@ -523,19 +523,28 @@ namespace SourceGen.AsmGen { // IGenerator public void OutputOrgDirective(int offset, int address) { - // For the first one, set the "real" PC. For all subsequent directives, set the - // "pseudo" PC. + // If there's only one address range, just set the "real" PC. If there's more + // than one we can run out of space if the source file has a chunk in high memory + // followed by a chunk in low memory, because the "real" PC determines when the + // 64KB bank is overrun. if (offset == 0) { - OutputLine("*", "=", SourceFormatter.FormatHexValue(address, 4), string.Empty); - } else { - if (mInPseudoPcBlock) { - // close previous block - OutputLine(string.Empty, CLOSE_PSEUDOPC, string.Empty, string.Empty); + // first one + if (Project.AddrMap.Count == 1) { + OutputLine("*", "=", SourceFormatter.FormatHexValue(address, 4), string.Empty); + return; + } else { + // set the real PC to address zero to ensure we get a full 64KB + OutputLine("*", "=", SourceFormatter.FormatHexValue(0, 4), string.Empty); } - OutputLine(string.Empty, sDataOpNames.OrgDirective, - SourceFormatter.FormatHexValue(address, 4) + " {", string.Empty); - mInPseudoPcBlock = true; } + + if (mInPseudoPcBlock) { + // close previous block + OutputLine(string.Empty, CLOSE_PSEUDOPC, string.Empty, string.Empty); + } + OutputLine(string.Empty, sDataOpNames.OrgDirective, + SourceFormatter.FormatHexValue(address, 4) + " {", string.Empty); + mInPseudoPcBlock = true; } // IGenerator diff --git a/SourceGen/SGTestData/Expected/2004-numeric-types_acme.S b/SourceGen/SGTestData/Expected/2004-numeric-types_acme.S index 69ed4b0..5912ce9 100644 --- a/SourceGen/SGTestData/Expected/2004-numeric-types_acme.S +++ b/SourceGen/SGTestData/Expected/2004-numeric-types_acme.S @@ -1,7 +1,8 @@ ;Project file was edited to get all big-endian data types, and to have an ;incorrect .junk alignment directive. !cpu 6502 -* = $1000 +* = $0000 + !pseudopc $1000 { bit L1448 jsr L14A8 nop @@ -60,6 +61,7 @@ LABEL !hex 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff !fill 2,$dd ;incorrect alignment !align 255,0,$00 !fill 8,$82 + } ;!pseudopc !pseudopc $1408 { !fill 8,$82 ;note no-op .ORG !fill 8,$83 diff --git a/SourceGen/SGTestData/Expected/2007-labels-and-symbols_acme.S b/SourceGen/SGTestData/Expected/2007-labels-and-symbols_acme.S index f766091..85e248c 100644 --- a/SourceGen/SGTestData/Expected/2007-labels-and-symbols_acme.S +++ b/SourceGen/SGTestData/Expected/2007-labels-and-symbols_acme.S @@ -1,5 +1,6 @@ ;ACME can't handle 65816 code that lives outside bank zero -* = $012345 +* = $0000 + !pseudopc $012345 { !hex 18fbe230a9cda9dda90da9eda9fea92da9ffa929a910a9e9a90fa945a923a901 !hex f4edfef44523f40100f45634f41200f4edfef44523f40100f45634f41200a5ce !hex adce00afce0000adecfeafecfe00adeefeafeefe00ad4623af462301ad4423af @@ -22,3 +23,4 @@ !hex 656172206f6e20746865206669727374206c696e652e20205468652071756963 !hex 6b2062726f776e20666f78206a756d7073206f76657220746865206c617a7920 !hex 646f67732ea97aa959a934c230a97b56a95a34a9341260 + } ;!pseudopc diff --git a/SourceGen/SGTestData/Expected/2008-address-changes_acme.S b/SourceGen/SGTestData/Expected/2008-address-changes_acme.S index 92ab9c3..2baae7f 100644 --- a/SourceGen/SGTestData/Expected/2008-address-changes_acme.S +++ b/SourceGen/SGTestData/Expected/2008-address-changes_acme.S @@ -1,5 +1,6 @@ !cpu 65816 -* = $1000 +* = $0000 + !pseudopc $1000 { !as !rs clc @@ -9,6 +10,7 @@ jsr L1107 jmp L2000 + } ;!pseudopc !pseudopc $1100 { L1100 bit L1100 L1103 lda #$11 diff --git a/SourceGen/SGTestData/Expected/2009-branches-and-banks_acme.S b/SourceGen/SGTestData/Expected/2009-branches-and-banks_acme.S index dd06c38..e175d1e 100644 --- a/SourceGen/SGTestData/Expected/2009-branches-and-banks_acme.S +++ b/SourceGen/SGTestData/Expected/2009-branches-and-banks_acme.S @@ -1,6 +1,8 @@ ;ACME can't handle 65816 code that lives outside bank zero -* = $1000 +* = $0000 + !pseudopc $1000 { !hex 18fbe2304c00002c0000a500a503d0ba30b862b5ff7006826d00000102a51482 !hex a5ff2c80005c0000442cc0ff823d00cf000044af000044ad0000a50030f562b2 !hex ffd0b082a9ff1700170044cfc0ff44f005303c8239005c0020002c0020f41700 !hex f44400d003dc1300ea201220201520200f202256341260 + } ;!pseudopc diff --git a/SourceGen/SGTestData/Expected/2010-target-adjustment_acme.S b/SourceGen/SGTestData/Expected/2010-target-adjustment_acme.S index 8b907b0..a5e15f2 100644 --- a/SourceGen/SGTestData/Expected/2010-target-adjustment_acme.S +++ b/SourceGen/SGTestData/Expected/2010-target-adjustment_acme.S @@ -1,5 +1,6 @@ !cpu 65816 -* = $1000 +* = $0000 + !pseudopc $1000 { !as !rs load11 lda #$11 @@ -48,6 +49,7 @@ load11 lda #$11 !byte $80 @dat81 !byte $81 + } ;!pseudopc !pseudopc $2000 { @L2000 !byte $82 !byte $83 diff --git a/SourceGen/SGTestData/Expected/2014-label-dp_acme.S b/SourceGen/SGTestData/Expected/2014-label-dp_acme.S index 1c0befd..a42e645 100644 --- a/SourceGen/SGTestData/Expected/2014-label-dp_acme.S +++ b/SourceGen/SGTestData/Expected/2014-label-dp_acme.S @@ -1,6 +1,7 @@ ;6502bench SourceGen v1.1.0-dev1 !cpu 65816 -* = $1000 +* = $0000 + !pseudopc $1000 { !as !rs sec @@ -286,6 +287,7 @@ L11FC cmp+2 L0086,x sbc+2 L0086,x inc+2 L0086,x sbc+3 L0089,x + } ;!pseudopc !pseudopc $0080 { L0080 bit+1 @L0082 @L0082 bit+1 @L0082 diff --git a/SourceGen/SGTestData/Expected/2019-local-variables_acme.S b/SourceGen/SGTestData/Expected/2019-local-variables_acme.S index f755693..228e817 100644 --- a/SourceGen/SGTestData/Expected/2019-local-variables_acme.S +++ b/SourceGen/SGTestData/Expected/2019-local-variables_acme.S @@ -5,7 +5,8 @@ CONST_ZERO = $f0 ;project const PROJ_ZERO = $00 ;project addr PROJ_ONE = $01 ;project addr -* = $1000 +* = $0000 + !pseudopc $1000 { !as !rs ldy PROJ_ZERO @@ -187,6 +188,7 @@ L103C lda #$fe jsr DPCODE rts + } ;!pseudopc !pseudopc $0080 { DPCODE nop lda+1 DPCODE diff --git a/SourceGen/SGTestData/Expected/2022-extension-scripts_acme.S b/SourceGen/SGTestData/Expected/2022-extension-scripts_acme.S index a34f758..9426863 100644 --- a/SourceGen/SGTestData/Expected/2022-extension-scripts_acme.S +++ b/SourceGen/SGTestData/Expected/2022-extension-scripts_acme.S @@ -3,7 +3,8 @@ PrintInlineL1String = $011000 PrintInlineL2String = $012000 PrintInlineDciString = $013000 -* = $1000 +* = $0000 + !pseudopc $1000 { !as !rs clc @@ -92,6 +93,7 @@ Next1 jsr L10BA !fill 300,$00 + } ;!pseudopc !pseudopc $1800 { L1800 jsr PrintInlineNullString per $8778 diff --git a/SourceGen/SGTestData/Expected/2024-ui-edge-cases_acme.S b/SourceGen/SGTestData/Expected/2024-ui-edge-cases_acme.S index b714551..e5abe21 100644 --- a/SourceGen/SGTestData/Expected/2024-ui-edge-cases_acme.S +++ b/SourceGen/SGTestData/Expected/2024-ui-edge-cases_acme.S @@ -1,8 +1,10 @@ !cpu 6502 -* = $2000 +* = $0000 + !pseudopc $2000 { jmp L2100 !text "hello, " ;string should be split by no-op addr change + } ;!pseudopc !pseudopc $200a { !text "world" !byte $80