mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2025-01-03 10:29:19 +00:00
Updated to use ApplesoftTokenizer.
This commit is contained in:
parent
09e6bf289b
commit
5799f4c0ea
@ -27,41 +27,10 @@ import java.io.PrintWriter;
|
||||
/**
|
||||
* Filter the given file as an Applesoft file.
|
||||
* <p>
|
||||
* Applesoft memory format:<br>
|
||||
* [Line]<br>
|
||||
* ...
|
||||
* [Line]<br>
|
||||
* <br>
|
||||
* where <Line> is:<br>
|
||||
* [Next addr - $0000 is end of program] (word)<br>
|
||||
* [Line no] (word)<br>
|
||||
* [Tokens and/or characters]<br>
|
||||
* [End-of-line marker: $00 bytes]
|
||||
* <p>
|
||||
* Date created: Nov 2, 2002 10:04:10 PM
|
||||
* @author: Rob Greene
|
||||
*/
|
||||
public class ApplesoftFileFilter implements FileFilter {
|
||||
private static String tokens[] = { // starts at $80
|
||||
" END ", " FOR ", " NEXT ", " DATA ", " INPUT ", " DEL ",
|
||||
" DIM ", " READ ", " GR ", " TEXT ", " PR# ", " IN# ",
|
||||
" CALL ", " PLOT ", " HLIN ", " VLIN ", " HGR2 ", " HGR ",
|
||||
" HCOLOR= ", " HPLOT ", " DRAW ", " XDRAW ", " HTAB ", " HOME ",
|
||||
" ROT= ", " SCALE= ", " SHLOAD ", " TRACE ", " NOTRACE ", " NORMAL ",
|
||||
" INVERSE ", " FLASH ", " COLOR= ", " POP ", " VTAB ", " HIMEM: ",
|
||||
" LOMEM: ", " ONERR ", " RESUME ", " RECALL ", " STORE ", " SPEED= ",
|
||||
" LET ", " GOTO ", " RUN ", " IF ", " RESTORE ", " & ",
|
||||
" GOSUB ", " RETURN ", " REM ", " STOP ", " ON ", " WAIT ",
|
||||
" LOAD ", " SAVE ", " DEF ", " POKE ", " PRINT ", " CONT ",
|
||||
" LIST ", " CLEAR ", " GET ", " NEW ", " TAB( ", " TO ",
|
||||
" FN ", " SPC( ", " THEN ", " AT ", " NOT ", " STEP ",
|
||||
" +", " -", " *", "/", " ^", " AND ",
|
||||
" OR ", " >", " =", " <", " SGN", " INT",
|
||||
" ABS", " USR", " FRE", " SCRN( ", " PDL", " POS",
|
||||
" SQR", " RND", " LOG", " EXP", " COS", " SIN",
|
||||
" TAN", " ATN", " PEEK", " LEN", " STR$", " VAL",
|
||||
" ASC", " CHR$", " LEFT$", " RIGHT$", " MID$ " };
|
||||
|
||||
/**
|
||||
* Constructor for ApplesoftFileFilter.
|
||||
*/
|
||||
@ -74,42 +43,29 @@ public class ApplesoftFileFilter implements FileFilter {
|
||||
* @see com.webcodepro.applecommander.storage.FileFilter#filter(FileEntry)
|
||||
*/
|
||||
public byte[] filter(FileEntry fileEntry) {
|
||||
byte[] fileData = fileEntry.getFileData();
|
||||
int offset = 0;
|
||||
ByteArrayOutputStream byteArray = new ByteArrayOutputStream(fileData.length * 2);
|
||||
ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
|
||||
PrintWriter printWriter = new PrintWriter(byteArray, true);
|
||||
while (offset < fileData.length) {
|
||||
int nextAddress = AppleUtil.getWordValue(fileData, offset);
|
||||
if (nextAddress == 0) break; // next address of 0 indicates end of program
|
||||
offset+= 2;
|
||||
int lineNumber = AppleUtil.getWordValue(fileData, offset);
|
||||
offset+= 2;
|
||||
printWriter.print(lineNumber);
|
||||
printWriter.print(' ');
|
||||
while (fileData[offset] != 0) {
|
||||
byte byt = fileData[offset++];
|
||||
if ((byt & 0x80) != 0) {
|
||||
int token = AppleUtil.getUnsignedByte(byt) - 0x80;
|
||||
if (token >= tokens.length) {
|
||||
printWriter.print("<UNKNOWN TOKEN>");
|
||||
} else {
|
||||
String tokenString = tokens[token];
|
||||
printWriter.print(tokenString);
|
||||
}
|
||||
ApplesoftTokenizer tokenizer = new ApplesoftTokenizer(fileEntry);
|
||||
boolean firstLine = true;
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
ApplesoftToken token = tokenizer.getNextToken();
|
||||
if (token == null) {
|
||||
break;
|
||||
} else if (token.isLineNumber()) {
|
||||
if (firstLine) {
|
||||
firstLine = false;
|
||||
} else {
|
||||
char ch = (char)byt;
|
||||
if (ch < 0x20) {
|
||||
printWriter.print("<CTRL-");
|
||||
printWriter.print((char)('@' + ch));
|
||||
printWriter.print(">");
|
||||
} else {
|
||||
printWriter.print(ch);
|
||||
}
|
||||
printWriter.println();
|
||||
}
|
||||
printWriter.print(token.getLineNumber());
|
||||
printWriter.print(" ");
|
||||
} else if (token.isToken()) {
|
||||
printWriter.print(token.getTokenString());
|
||||
} else {
|
||||
printWriter.print(token.getStringValue());
|
||||
}
|
||||
printWriter.println();
|
||||
offset++; // skip to next line
|
||||
}
|
||||
printWriter.close();
|
||||
return byteArray.toByteArray();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user