Add memory types to ranges; Collapse code ranges

- Add memory types to Ranges, just like how Labels have them.
- If a range is of type "code", treat it as a single-byte range and do
  not output an address range to the MLB.
This commit is contained in:
Zorchenhimer 2025-12-27 11:14:54 -05:00
parent 1374167b0f
commit a8eb708d39
Signed by: Zorchenhimer
GPG Key ID: 70A1AB767AAB9C20
3 changed files with 24 additions and 13 deletions

View File

@ -4,5 +4,5 @@ all: bin/dasm2lbl
bin/: bin/:
mkdir bin mkdir bin
bin/dasm2lbl: **/*.go bin/dasm2lbl: config.go lex.go parse.go cmd/main.go
go build -o $@ cmd/main.go go build -o $@ cmd/main.go

View File

@ -54,12 +54,6 @@ func (l Label) Mlb(startRam, startRom int) string {
addrStr = fmt.Sprintf("%04X-%04X", l.Address, l.Address+l.Size-1) addrStr = fmt.Sprintf("%04X-%04X", l.Address, l.Address+l.Size-1)
} }
return fmt.Sprintf("%s:%s:%s:%s", memType, addrStr, l.Name, l.Comment) return fmt.Sprintf("%s:%s:%s:%s", memType, addrStr, l.Name, l.Comment)
//addr := fmt.Sprintf("%04X", l.Address)
//if l.Size > 1 {
// addr = fmt.Sprintf("%04X-%04X", l.Address, l.Address+l.Size-1)
//}
//return fmt.Sprintf("NesMemory:%s:%s:%s", addr, l.Name, l.Comment)
} }
type Range struct { type Range struct {
@ -73,11 +67,25 @@ type Range struct {
} }
func (r Range) Mlb(startRam, startRom int) string { func (r Range) Mlb(startRam, startRom int) string {
addr := fmt.Sprintf("%04X", r.Start) start := r.Start
if r.End - r.Start > 1 { end := r.End
addr = fmt.Sprintf("%04X-%04X", r.Start, r.End)
memType := "NesMemory"
if start >= startRom {
start -= startRom
end -= startRom
memType = "NesPrgRom"
} else if start >= startRam {
start -= startRam
end -= startRam
memType = "NesWorkRam"
} }
return fmt.Sprintf("NesMemory:%s:%s:%s", addr, r.Name, r.Comment)
addr := fmt.Sprintf("%04X", start)
if r.End - r.Start > 1 && r.Type != "code" {
addr = fmt.Sprintf("%04X-%04X", start, end)
}
return fmt.Sprintf("%s:%s:%s:%s", memType, addr, r.Name, r.Comment)
} }
type Segment struct { type Segment struct {

View File

@ -102,8 +102,11 @@ func (p *Parser) parseRange() error {
} }
case "type", "addrmode": case "type", "addrmode":
p.next() itm = p.next()
// just consume it if itm.typ != lex_Ident {
return fmt.Errorf("%s requires ident: %s", itm.val, itm)
}
rng.Type = itm.val
case "start", "end", "unit": case "start", "end", "unit":
typ := itm.val typ := itm.val