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/:
mkdir bin
bin/dasm2lbl: **/*.go
bin/dasm2lbl: config.go lex.go parse.go 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)
}
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 {
@ -73,11 +67,25 @@ type Range struct {
}
func (r Range) Mlb(startRam, startRom int) string {
addr := fmt.Sprintf("%04X", r.Start)
if r.End - r.Start > 1 {
addr = fmt.Sprintf("%04X-%04X", r.Start, r.End)
start := r.Start
end := 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 {

View File

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