diff --git a/script/cdl.go b/script/cdl.go index 8b54852..2e08a14 100644 --- a/script/cdl.go +++ b/script/cdl.go @@ -7,6 +7,7 @@ import ( "strconv" "fmt" "slices" + "bytes" ) type CodeDataLog struct { @@ -166,8 +167,11 @@ func (cdl *CodeDataLog) setCode(addr int) { cdl.cache[addr] |= cdlCode } -func (cdl *CodeDataLog) doCache() error { +func (cdl *CodeDataLog) doCache(size int) error { cdl.cache = make(map[int]cdlBit) + for i := 0x6000; i < size+0x6000; i++ { + cdl.cache[i] = cdlUnknown + } for _, rng := range cdl.Code { start, err := strconv.ParseInt(rng.Start, 0, 32) @@ -215,15 +219,18 @@ func (cdl *CodeDataLog) doCache() error { } func CdlFromJson(r io.Reader) (*CodeDataLog, error) { + raw, err := io.ReadAll(r) + buf := bytes.NewReader(raw) + cdl := NewCDL() - dec := json.NewDecoder(r) - err := dec.Decode(cdl) + dec := json.NewDecoder(buf) + err = dec.Decode(cdl) if err != nil { return nil, err } //cdl.Data = []CdlRange{} - cdl.doCache() + cdl.doCache(len(raw)) return cdl, nil } diff --git a/script/parser.go b/script/parser.go index 78397a5..d6a692d 100644 --- a/script/parser.go +++ b/script/parser.go @@ -191,26 +191,19 @@ INNER: } // Add data tokens - for addr, bit := range p.script.CDL.cache { - if addr < 0x6002 { - continue - } + for addr := 0x6002; addr < len(rawinput)+0x6000; addr++ { + bit := p.script.CDL.cache[addr] // ignore code bytes if bit & cdlCode == cdlCode { continue } - // ignore labels outside the script's address range - if addr > len(rawinput)+0x6000 { - continue - } - if _, ok := p.script.Labels[addr]; ok { p.script.Tokens = append(p.script.Tokens, &Token{ Offset: addr, - Inline: []InlineVal{NewWordVal([]byte{rawinput[addr-0x6000], rawinput[addr+1-0x6000]})}, - IsVariable: true, + //Inline: []InlineVal{NewWordVal([]byte{rawinput[addr-0x6000], rawinput[addr+1-0x6000]})}, + //IsVariable: true, IsData: true, cdl: bit.String(), }) diff --git a/script/script.go b/script/script.go index ba969da..f5f83cb 100644 --- a/script/script.go +++ b/script/script.go @@ -44,12 +44,12 @@ func (s *Script) DebugCDL(filename string) error { return fmt.Errorf("origSize == 0") } - if s.CDL.cache == nil { - err := s.CDL.doCache() - if err != nil { - return fmt.Errorf("doCache() error: %w", err) - } - } + //if s.CDL.cache == nil { + // err := s.CDL.doCache() + // if err != nil { + // return fmt.Errorf("doCache() error: %w", err) + // } + //} dat := make([]byte, s.origSize) for i := 2; i < len(dat); i++ {