Skip to content

Commit dbd30c3

Browse files
author
Foerster-H
committed
Untokenizer extended to handle X16 tokens as well.
1 parent 5223966 commit dbd30c3

File tree

6 files changed

+63
-7
lines changed

6 files changed

+63
-7
lines changed

src/main/java/com/sixtyfour/cbmnative/shell/MoSpeedCL.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public static void main(String[] args) {
123123

124124
PlatformProvider platform = new Platform64();
125125
String appendix = ".prg";
126+
boolean multiByteTokens=false;
126127
if (cmds.containsKey("platform")) {
127128
String pl = cmds.get("platform");
128129
if (pl.equalsIgnoreCase("c64")) {
@@ -135,6 +136,7 @@ public static void main(String[] args) {
135136
platform = new PlatformX16();
136137
Basic.registerExtension(new X16Extensions());
137138
cfg.setNonDecimalNumbersAware(true);
139+
multiByteTokens=true;
138140
appendix = ".prg";
139141
} else if (pl.equalsIgnoreCase("ps")) {
140142
platform = new PlatformPs();
@@ -192,7 +194,7 @@ public static void main(String[] args) {
192194
System.out.println("Looks like a PRG file, trying to convert it...");
193195
byte[] data = Loader.loadBlob(srcFile);
194196
UnTokenizer unto = new UnTokenizer();
195-
src = unto.getText(data).toArray(new String[0]);
197+
src = unto.getText(data, multiByteTokens).toArray(new String[0]);
196198
System.out.println("PRG file converted into ASCII, proceeding!");
197199
srcFile = srcFile.replace(".prg", ".bas");
198200
} catch (Exception e) {

src/main/java/com/sixtyfour/parser/cbmnative/UnTokenizer.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
/**
1212
* Converts files in .PRG format back into ASCII by replacing the BASIC tokens
13-
* and such. Supports C64 and VIC 20 for now, not the X16's new commands.
13+
* and such. Supports C64 and VIC 20 BASIC V2 and the X16's extensions.
1414
*
1515
* @author EgonOlsen71
1616
*/
@@ -95,6 +95,26 @@ public class UnTokenizer {
9595
this.put(201, "RIGHT$");
9696
this.put(202, "MID$");
9797
this.put(203, "GO");
98+
99+
// X16-Extensions go here...this isn't really a good solution, it
100+
// would be better to make the extension itself fill this, but
101+
// I can't be bothered right now...
102+
this.put(0xCE86, "SCREEN");
103+
this.put(0xCE87, "PSET");
104+
this.put(0xCE8A, "RECT");
105+
this.put(0xCE88, "LINE");
106+
this.put(0xCE89, "FRAME");
107+
this.put(0xCE8B, "CHAR");
108+
this.put(0xCE8C, "MOUSE");
109+
this.put(0xCE8E, "MX");
110+
this.put(0xCE8F, "MY");
111+
this.put(0xCE90, "MB");
112+
this.put(0xCE84, "VPOKE");
113+
this.put(0xCE8D, "VPEEK");
114+
this.put(0xCE81, "DOS");
115+
this.put(0xCE80, "MON");
116+
this.put(0xCE82, "OLD");
117+
this.put(0xCE83, "GEOS");
98118
}
99119
};
100120

@@ -108,7 +128,7 @@ public UnTokenizer() {
108128
* @param program the file in binary
109129
* @return the ascii version of it
110130
*/
111-
public List<String> getText(byte[] program) {
131+
public List<String> getText(byte[] program, boolean multiByte) {
112132
List<String> lines = new ArrayList<>();
113133
StringBuilder line = new StringBuilder();
114134

@@ -134,14 +154,18 @@ public List<String> getText(byte[] program) {
134154
if (c == '"') {
135155
inString = !inString;
136156
}
137-
if (b < 128 || inString || b > 203) {
157+
if (b < 128 || inString || (b > 203 && (!multiByte || b!=206))) {
138158
if (inString && isSpecialChar(c)) {
139159
line.append(ControlCodes.getPlaceHolder(b));
140160
} else {
141161
line.append(convertChar(c));
142162
}
143163
} else {
144-
String token = TOKENS.get(b);
164+
String token = TOKENS.get(b);
165+
if (multiByte && b==206) {
166+
int mb = b*256+(program[(addr++) - start] & 0xff);
167+
token=TOKENS.get(mb);
168+
}
145169
if (token == null) {
146170
throw new RuntimeException("Unknown token: " + b);
147171
}

src/main/java/com/sixtyfour/runner/VisualMospeed.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ private void loadProgram() {
394394
Logger.log("Looks like a PRG file, trying to convert it...");
395395
byte[] data = Loader.loadBlob(srcFile);
396396
UnTokenizer unto = new UnTokenizer();
397-
code = unto.getText(data).toArray(new String[0]);
397+
code = unto.getText(data, true).toArray(new String[0]);
398398
Logger.log("PRG file converted into ASCII, proceeding!");
399399
srcFile = srcFile.replace(".prg", ".bas");
400400
} catch (Exception e) {

src/test/java/com/sixtyfour/test/UnTokenizerTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ public class UnTokenizerTest {
1414

1515
public static void main(String[] args) {
1616
testUnTokenizer();
17+
testUnTokenizerX16();
1718
}
1819

1920
public static void testUnTokenizer() {
2021
byte[] data = Loader.loadBlob("src/test/resources/prg/demo.prg");
2122
UnTokenizer unto = new UnTokenizer();
22-
List<String> res = unto.getText(data);
23+
List<String> res = unto.getText(data, false);
2324
res.forEach(p -> System.out.println(p));
2425
try (PrintWriter pw = new PrintWriter("src/test/resources/prg/demo.bas")) {
2526
for (String line : res) {
@@ -29,5 +30,19 @@ public static void testUnTokenizer() {
2930
throw new RuntimeException(e);
3031
}
3132
}
33+
34+
public static void testUnTokenizerX16() {
35+
byte[] data = Loader.loadBlob("src/test/resources/prg/cmds.prg");
36+
UnTokenizer unto = new UnTokenizer();
37+
List<String> res = unto.getText(data, true);
38+
res.forEach(p -> System.out.println(p));
39+
try (PrintWriter pw = new PrintWriter("src/test/resources/prg/cmds.bas")) {
40+
for (String line : res) {
41+
pw.println(line);
42+
}
43+
} catch (Exception e) {
44+
throw new RuntimeException(e);
45+
}
46+
}
3247

3348
}

src/test/resources/prg/cmds.bas

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
5 a=2
2+
10 screen a: rem ce 86
3+
20 pset a,a,a: rem ce 87
4+
30 rect a,a,a,a,a: rem ce 8a
5+
40 line a,a,a,a,a: rem ce 88
6+
50 frame a,a,a,a,a: rem ce 89
7+
60 char a,a,a,"a": rem ce 8b
8+
70 mouse a: rem ce 8c
9+
80 a=mx:a=my:a=mb: rem ce 8e, ce 8f, ce 90
10+
90 vpoke a,a,a: rem ce 84
11+
100 a=vpeek(a,a): rem ce 8d
12+
110 dos: rem ce 81
13+
120 mon: rem ce 80
14+
130 old: rem ce 82
15+
140 geos: rem ce 83

src/test/resources/prg/cmds.prg

323 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)