fix: HGR2 tokenization bug

This commit is contained in:
April Ayres-Griffiths 2018-04-23 22:35:34 +10:00
parent 76dfc34fd2
commit 4479f21f0b
3 changed files with 60 additions and 31 deletions

View File

@ -566,27 +566,43 @@ func ApplesoftTokenize(lines []string) []byte {
linebuffer[0x03] = byte(ln / 0x100)
// PROCESS LINE
var lastKeyword string
for _, ch := range rest {
switch {
case inqq && ch != '"':
linebuffer = append(linebuffer, byte(ch))
lastKeyword = ""
continue
case ch == '"':
linebuffer = append(linebuffer, byte(ch))
lastKeyword = ""
inqq = !inqq
continue
case !inqq && breakingChar(ch):
linebuffer = append(linebuffer, []byte(chunk)...)
chunk = ""
linebuffer = append(linebuffer, byte(ch))
lastKeyword = ""
continue
}
chunk += string(ch)
if lastKeyword != "" {
code, ok := ApplesoftReverse[strings.ToUpper(lastKeyword+chunk)]
if ok {
linebuffer[len(linebuffer)-1] = byte(code)
lastKeyword = lastKeyword + chunk
chunk = ""
continue
}
}
code, ok := ApplesoftReverse[strings.ToUpper(chunk)]
if ok {
linebuffer = append(linebuffer, byte(code))
lastKeyword = chunk
chunk = ""
}
}

44
disk/atokens_test.go Normal file
View File

@ -0,0 +1,44 @@
package disk
import (
"strings"
"testing"
)
func TestHGR2Tokenise(t *testing.T) {
lines := []string{
"10 HGR2 : REM SOMETHING",
"20 REM SOMETHING ELSE",
}
a := ApplesoftTokenize(lines)
s := string(ApplesoftDetoks(a))
t.Logf("code: %s", s)
if !strings.Contains(s, "HGR2 ") {
t.Fatalf("Expected HGR2")
}
}
func TestHGRTokenise(t *testing.T) {
lines := []string{
"10 HGR : REM SOMETHING",
"20 REM SOMETHING ELSE",
}
a := ApplesoftTokenize(lines)
s := string(ApplesoftDetoks(a))
t.Logf("code: %s", s)
if !strings.Contains(s, "HGR ") {
t.Fatalf("Expected HGR")
}
}

View File

@ -1,31 +0,0 @@
package disk
import (
//"strings"
"testing"
)
import "fmt"
//import "os"
func TestDisk(t *testing.T) {
if STD_DISK_BYTES != 143360 {
t.Error(fmt.Sprintf("Wrong size got %d", STD_DISK_BYTES))
}
dsk, e := NewDSKWrapper("g19.dsk")
if e != nil {
t.Error(e)
}
fmt.Printf("Disk format is %d\n", dsk.Format)
_, fdlist, e := dsk.GetCatalogProDOSPathed(2, "GAMES", "")
for _, fd := range fdlist {
fmt.Printf("[%s]\n", fd.Name())
}
t.Fail()
}