103 lines
1.8 KiB
Go
103 lines
1.8 KiB
Go
package dasmlbl
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
type Config struct {
|
|
Cpu string
|
|
InputName string
|
|
OutputName string
|
|
|
|
HexOffset int
|
|
InputOffset int
|
|
InputSize int
|
|
StartAddr int
|
|
Comments int
|
|
LabelBreak int
|
|
PageLength int
|
|
|
|
CommentColumn int
|
|
ArgumentColumn int
|
|
MnemonicColumn int
|
|
TextColumn int
|
|
|
|
NewlineAfterJMP bool
|
|
NewlineAfterRTS bool
|
|
|
|
Labels []Label
|
|
Ranges []Range
|
|
Segments []Segment
|
|
}
|
|
|
|
func (c *Config) Append(other *Config) {
|
|
c.Labels = append(c.Labels, other.Labels...)
|
|
c.Ranges = append(c.Ranges, other.Ranges...)
|
|
c.Segments = append(c.Segments, other.Segments...)
|
|
}
|
|
|
|
type Label struct {
|
|
Name string
|
|
Address int
|
|
Comment string
|
|
Size int
|
|
ParamSize int
|
|
}
|
|
|
|
func (l Label) Mlb(startRam, startRom int) string {
|
|
addr := l.Address
|
|
memType := "NesMemory"
|
|
if addr >= startRom {
|
|
addr -= startRom
|
|
memType = "NesPrgRom"
|
|
} else if addr >= startRam {
|
|
addr -= startRam
|
|
memType = "NesWorkRam"
|
|
}
|
|
|
|
addrStr := fmt.Sprintf("%04X", addr)
|
|
if l.Size > 1 {
|
|
addrStr = fmt.Sprintf("%04X-%04X", addr, addr+l.Size-1)
|
|
}
|
|
return fmt.Sprintf("%s:%s:%s:%s", memType, addrStr, l.Name, l.Comment)
|
|
}
|
|
|
|
type Range struct {
|
|
Name string
|
|
Comment string
|
|
Start int
|
|
End int
|
|
Type string
|
|
Unit int
|
|
AddrMode string
|
|
}
|
|
|
|
func (r Range) Mlb(startRam, startRom int) string {
|
|
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"
|
|
}
|
|
|
|
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 {
|
|
Name string
|
|
Start int
|
|
End int
|
|
}
|
|
|