From f31b7f5822d147da836886a2335e147c1707923b Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Fri, 18 Oct 2019 16:19:42 -0700 Subject: [PATCH] Fix constants declared with MULTI_MASK The masks should only be applied to address symbols. We were rejecting constants that didn't match the pattern. --- SourceGen/DefSymbol.cs | 5 ++- SourceGen/PlatformSymbols.cs | 2 +- SourceGen/RuntimeData/Help/advanced.html | 43 +++++++++++++------ SourceGen/RuntimeData/Help/intro.html | 10 +++-- .../SGTestData/2021-external-symbols-1.sym65 | 3 ++ 5 files changed, 44 insertions(+), 19 deletions(-) diff --git a/SourceGen/DefSymbol.cs b/SourceGen/DefSymbol.cs index 265e9e4..ccb9233 100644 --- a/SourceGen/DefSymbol.cs +++ b/SourceGen/DefSymbol.cs @@ -235,7 +235,10 @@ namespace SourceGen { Debug.Assert(((int)direction & ~(int)DirectionFlags.ReadWrite) == 0); Direction = direction; - MultiMask = multiMask; + // constants don't have masks + if (type != Type.Constant) { + MultiMask = multiMask; + } Tag = tag; } diff --git a/SourceGen/PlatformSymbols.cs b/SourceGen/PlatformSymbols.cs index 63a593d..337e354 100644 --- a/SourceGen/PlatformSymbols.cs +++ b/SourceGen/PlatformSymbols.cs @@ -198,7 +198,7 @@ namespace SourceGen { } } - if (parseOk && multiMask != null) { + if (parseOk && multiMask != null && !isConst) { // We need to ensure that all possible values fit within the mask. // We don't test AddressValue here, because it's okay for the // canonical value to be outside the masked range. diff --git a/SourceGen/RuntimeData/Help/advanced.html b/SourceGen/RuntimeData/Help/advanced.html index 1a92ed5..d12731b 100644 --- a/SourceGen/RuntimeData/Help/advanced.html +++ b/SourceGen/RuntimeData/Help/advanced.html @@ -87,27 +87,43 @@ RAM, ROM, and I/O registers appear at multiple addresses. The hardware looks for certain address lines to be set or clear, and if the pattern matches, another set of bits is examined to determine which register or RAM address is being accessed.

+

This is expressed in symbol files with the MULTI_MASK statement. +Address symbol declarations that follow have the mask set applied. Symbols +whose addresses don't fit the pattern cause a warning and will be +ignored. Constants are not affected.

-

For example, suppose the access pattern for a set of registers is -???0 ??1? 1??x xxxx (where '?' can be any value, 0/1 must -be that value, and 'x' means the bit is used to determine the register). -So any value between $0280-029f matches, as does $23c0-23df, but +

The mask set is best explained with an example. Suppose the address +pattern for a set of registers is ???0 ??1? 1??x xxxx +(where '?' can be any value, 0/1 must be that value, and 'x' means the bit +is used to determine the register). +So any address between $0280-029F matches, as does $23C0-23DF, but $0480 and $1280 don't. The register number is found in the low five bits.

The corresponding MULTI_MASK line, with values specifed in binary, would be:

-
*MULTI_MASK %0001001010000000 %0000001010000000 %0000000000011111
+
  *MULTI_MASK %0001001010000000 %0000001010000000 %0000000000011111

The values are CompareMask, CompareValue, and AddressMask. To determine if an address is in the register set, we check to see if (address & CompareMask) == CompareValue. If so, we can extract the register number with (address & AddressMask).

We don't want to have a huge collection of equates at the top of the -file, so whatever value is used in the symbol declaration is considered -the "canonical" value. All other matching values are expressed as an -offset.

-

All values must fall between 0 and $00FFFFFF. The set bits in +generated source file, so whatever value is used in the symbol declaration +is considered the "canonical" value. All other matching values are output +with an offset.

+

All mask values must fall between 0 and $00FFFFFF. The set bits in CompareMask and AddressMask must not overlap, and CompareValue must not have any bits set that aren't also set in CompareMask.

+

If an address can be mapped to a masked value and an unmasked value, +the unmasked value takes precedence for exact matches. In the example +above, if you declare REG1 @ $0281 outside the MULTI_MASK +declaration, the disassembler will use REG1 for all operands +that reference $0281. If other code accesses the same register as $23C1, +the symbol established for the masked value will be used instead.

+

If there are multiple masked values for a given address, the precedence +is undefined.

+

To disable the MULTI_MASK and resume normal declarations, write the +tag without arguments: +

  *MULTI_MASK

Creating a Project-Specific Symbol File

@@ -119,13 +135,14 @@ Make sure you create it in the same directory where your project file (the file that ends with ".dis65") lives. Add a *SYNOPSIS, then add the desired symbols.

Finally, add it to your project. Select Edit > Project Properties, -switch to the Symbol Files tab, click Add Symbol Files, and select your -symbol file. It should appear in the list with a "PROJ:" prefix.

+switch to the Symbol Files tab, click Add Symbol Files from Project, and +select your symbol file. It should appear in the list with a +"PROJ:" prefix.

If an example helps, the A2-Amper-fdraw project in the Examples directory has a project-local symbol file, called "fdraw-exports". -(Amper-fdraw provides an Applesoft BASIC interface to the machine-language -fdraw library.)

+(fdraw-exports is a list of exported symbols from the fdraw library, +for which Amper-fdraw provides an Applesoft BASIC interface.)

NOTE: in the current version of SourceGen, changes to .sym65 files are not detected automatically. Closing and re-opening the project diff --git a/SourceGen/RuntimeData/Help/intro.html b/SourceGen/RuntimeData/Help/intro.html index cd5eb1e..a98258a 100644 --- a/SourceGen/RuntimeData/Help/intro.html +++ b/SourceGen/RuntimeData/Help/intro.html @@ -61,10 +61,12 @@ something that people actually want.

Fundamental Concepts

The next few sections present some general concepts and terminology. The -rest of the documentation assumes you've read and understood this. It will -be helpful if you already understand something about the 6502 instruction -set and assembly-language programming, but disassembling other programs is -actually a pretty good way to learn how to code in assembly.

+rest of the documentation assumes you've read and understood this.

+

It will be helpful if you already understand something about the 6502 +instruction set and assembly-language programming, but disassembling +other programs is actually a pretty good way to learn how to code in +assembly. You will need to be familiar with hexadecimal numbers and +general programming concepts to make sense of anything, however.

About 6502 Code

diff --git a/SourceGen/SGTestData/2021-external-symbols-1.sym65 b/SourceGen/SGTestData/2021-external-symbols-1.sym65 index c11e471..cdaaa98 100644 --- a/SourceGen/SGTestData/2021-external-symbols-1.sym65 +++ b/SourceGen/SGTestData/2021-external-symbols-1.sym65 @@ -82,6 +82,9 @@ MultiWrite > $c005 3 ;$c005/6/7, write-only ; Test: read C003 C004 C005 C006 C007 ; Test: write C004 C005 C006 C007 C008 +; try a non-matching constant; should be accepted without complaint +MultiConst = $4567 + ; ; Invalid values. These cause a warning at load time, and the symbol will