Add Business BASIC viewer support

This commit is contained in:
2008-12-16 05:07:36 +00:00
parent 48480e2444
commit ec5c2b84b7
8 changed files with 601 additions and 0 deletions

View File

@ -0,0 +1,86 @@
/*
* AppleCommander - An Apple ][ image utility.
* Copyright (C) 2002, 2008 by Robert Greene
* robgreene at users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.webcodepro.applecommander.storage.filters;
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import com.webcodepro.applecommander.storage.FileEntry;
import com.webcodepro.applecommander.storage.FileFilter;
import com.webcodepro.applecommander.util.BusinessBASICToken;
import com.webcodepro.applecommander.util.BusinessBASICTokenizer;
/**
* Filter the given file as an Apple /// Business BASIC file.
* <p>
* Date created: Dec 15, 2008 11:12:10 PM
* @author David Schmidt
*/
public class BusinessBASICFileFilter implements FileFilter {
/**
* Constructor for BusinessBASICFileFilter.
*/
public BusinessBASICFileFilter() {
super();
}
/**
* Process the given FileEntry and return a text image of the Business BASIC file.
* @see com.webcodepro.applecommander.storage.FileFilter#filter(FileEntry)
*/
public byte[] filter(FileEntry fileEntry) {
System.out.println("BusinessBASICFileFilter.filter() entry.");
ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
PrintWriter printWriter = new PrintWriter(byteArray, true);
BusinessBASICTokenizer tokenizer = new BusinessBASICTokenizer(fileEntry);
boolean firstLine = true;
while (tokenizer.hasMoreTokens()) {
BusinessBASICToken token = tokenizer.getNextToken();
if (token == null) {
break;
} else if (token.isLineNumber()) {
if (firstLine) {
firstLine = false;
} else {
printWriter.println();
}
printWriter.print(token.getLineNumber());
printWriter.print(" "); //$NON-NLS-1$
} else if (token.isToken()) {
printWriter.print(token.getTokenString());
} else {
printWriter.print(token.getStringValue());
}
}
printWriter.close();
return byteArray.toByteArray();
}
/**
* Give suggested file name.
*/
public String getSuggestedFileName(FileEntry fileEntry) {
String fileName = fileEntry.getFilename().trim();
if (!fileName.toLowerCase().endsWith(".ba3")) { //$NON-NLS-1$
fileName = fileName + ".ba3"; //$NON-NLS-1$
}
return fileName;
}
}

View File

@ -36,6 +36,7 @@ import com.webcodepro.applecommander.storage.filters.AppleWorksWordProcessorFile
import com.webcodepro.applecommander.storage.filters.ApplesoftFileFilter;
import com.webcodepro.applecommander.storage.filters.AssemblySourceFileFilter;
import com.webcodepro.applecommander.storage.filters.BinaryFileFilter;
import com.webcodepro.applecommander.storage.filters.BusinessBASICFileFilter;
import com.webcodepro.applecommander.storage.filters.GraphicsFileFilter;
import com.webcodepro.applecommander.storage.filters.IntegerBasicFileFilter;
import com.webcodepro.applecommander.storage.filters.TextFileFilter;
@ -471,6 +472,8 @@ public class ProdosFileEntry extends ProdosCommonEntry implements FileEntry {
return new AssemblySourceFileFilter();
}
return new TextFileFilter();
case 0x09: // BA3
return new BusinessBASICFileFilter();
case 0xb0: // SRC
return new TextFileFilter();
case 0x19: // ADB

View File

@ -47,12 +47,14 @@ import com.webcodepro.applecommander.storage.filters.AppleWorksSpreadSheetFileFi
import com.webcodepro.applecommander.storage.filters.AppleWorksWordProcessorFileFilter;
import com.webcodepro.applecommander.storage.filters.ApplesoftFileFilter;
import com.webcodepro.applecommander.storage.filters.AssemblySourceFileFilter;
import com.webcodepro.applecommander.storage.filters.BusinessBASICFileFilter;
import com.webcodepro.applecommander.storage.filters.GraphicsFileFilter;
import com.webcodepro.applecommander.storage.filters.IntegerBasicFileFilter;
import com.webcodepro.applecommander.storage.filters.PascalTextFileFilter;
import com.webcodepro.applecommander.storage.filters.TextFileFilter;
import com.webcodepro.applecommander.ui.UiBundle;
import com.webcodepro.applecommander.ui.swt.filteradapter.ApplesoftFilterAdapter;
import com.webcodepro.applecommander.ui.swt.filteradapter.BusinessBASICFilterAdapter;
import com.webcodepro.applecommander.ui.swt.filteradapter.FilterAdapter;
import com.webcodepro.applecommander.ui.swt.filteradapter.GraphicsFilterAdapter;
import com.webcodepro.applecommander.ui.swt.filteradapter.HexFilterAdapter;
@ -169,6 +171,11 @@ public class FileViewerWindow {
textBundle.get("FileViewerWindow.ApplesoftTooltip"), //$NON-NLS-1$
imageManager.get(ImageManager.ICON_VIEW_AS_BASIC_PROGRAM)
));
nativeFilterAdapterMap.put(BusinessBASICFileFilter.class,
new BusinessBASICFilterAdapter(this, textBundle.get("FileViewerWindow.ApplesoftButton"), //$NON-NLS-1$
textBundle.get("FileViewerWindow.ApplesoftTooltip"), //$NON-NLS-1$
imageManager.get(ImageManager.ICON_VIEW_AS_BASIC_PROGRAM)
));
nativeFilterAdapterMap.put(AppleWorksDataBaseFileFilter.class,
new TextFilterAdapter(this, textBundle.get("FileViewerWindow.DatabaseButton"), //$NON-NLS-1$
textBundle.get("FileViewerWindow.DatabaseTooltip"), //$NON-NLS-1$

View File

@ -0,0 +1,110 @@
/*
* AppleCommander - An Apple ][ image utility.
* Copyright (C) 2002-2004 by Robert Greene
* robgreene at users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.webcodepro.applecommander.ui.swt.filteradapter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import com.webcodepro.applecommander.ui.swt.FileViewerWindow;
import com.webcodepro.applecommander.ui.swt.util.contentadapter.StyledTextAdapter;
import com.webcodepro.applecommander.util.BusinessBASICToken;
import com.webcodepro.applecommander.util.BusinessBASICTokenizer;
import com.webcodepro.applecommander.util.BusinessBASICTokenizer;
/**
* Provides a view of a syntax-colored Apple /// Business BASIC program listing.
*
* @author Rob Greene
*/
public class BusinessBASICFilterAdapter extends FilterAdapter {
private StyledText styledText;
public BusinessBASICFilterAdapter(FileViewerWindow window, String text, String toolTipText, Image image) {
super(window, text, toolTipText, image);
}
public void display() {
if (styledText == null) {
createStyledText();
}
Point size = styledText.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
getComposite().setContent(styledText);
getComposite().setExpandHorizontal(true);
getComposite().setExpandVertical(true);
getComposite().setMinWidth(size.x);
getComposite().setMinHeight(size.y);
getComposite().getContent().addListener(SWT.KeyUp, getToolbarCommandHandler());
setContentTypeAdapter(new StyledTextAdapter(styledText, getFileEntry().getFilename()));
}
public void dispose() {
styledText.dispose();
}
protected void createStyledText() {
styledText = new StyledText(getComposite(), SWT.NONE);
styledText.setForeground(getBlackColor());
styledText.setFont(getCourierFont());
styledText.setEditable(false);
BusinessBASICTokenizer tokenizer = new BusinessBASICTokenizer(getFileEntry());
boolean firstLine = true;
while (tokenizer.hasMoreTokens()) {
BusinessBASICToken token = tokenizer.getNextToken();
if (token == null) {
continue; // should be end of program...
} else if (token.isLineNumber()) {
if (firstLine) {
firstLine = false;
} else {
styledText.append("\n"); //$NON-NLS-1$
}
styledText.append(Integer.toString(token.getLineNumber()));
styledText.append(" "); //$NON-NLS-1$
} else if (token.isCommandSeparator() || token.isExpressionSeparator()) {
styledText.append(token.getStringValue());
} else if (token.isEndOfCommand()) {
styledText.append("\n"); //$NON-NLS-1$
} else if (token.isString()) {
int caretOffset = styledText.getCharCount();
styledText.append(token.getStringValue());
StyleRange styleRange = new StyleRange();
styleRange.start = caretOffset;
styleRange.length = token.getStringValue().length();
styleRange.foreground = getGreenColor();
styledText.setStyleRange(styleRange);
} else if (token.isToken()) {
int caretOffset = styledText.getCharCount();
styledText.append(token.getTokenString());
StyleRange styleRange = new StyleRange();
styleRange.start = caretOffset;
styleRange.length = token.getTokenString().length();
//styleRange.fontStyle = SWT.BOLD;
styleRange.foreground = getBlueColor();
styledText.setStyleRange(styleRange);
}
}
}
}

View File

@ -128,6 +128,16 @@ public class AppleUtil {
return value & 0xff;
}
/**
* Extract out an unsigned byte as an int.
* All Java bytes are signed; need to convert to an int
* and remove the sign.
*/
public static int getUnsignedByte(byte[] buffer, int offset) {
if (offset+1 > buffer.length) return 0;
else return getUnsignedByte(buffer[offset]);
}
/**
* Count the number of bits set in a byte.
*/

View File

@ -0,0 +1,93 @@
package com.webcodepro.applecommander.util;
/**
* Represents an Apple /// Business BASIC Token.
* @see com.webcodepro.applecommander.util.ApplesoftTokenizer
* @author David Schmidt
*/
public class BusinessBASICToken {
private int lineNumber;
private byte tokenValue;
private String tokenString;
private String stringValue;
public BusinessBASICToken(int lineNumber) {
this.lineNumber = lineNumber;
}
public BusinessBASICToken(byte tokenValue, String tokenString) {
this.tokenValue = tokenValue;
this.tokenString = tokenString;
}
public BusinessBASICToken(String stringValue) {
this.stringValue = stringValue;
}
public boolean isCommandSeparator() {
return ":".equals(stringValue); //$NON-NLS-1$
}
public boolean isLineNumber() {
return !isToken() && !isString();
}
public boolean isEndOfCommand() {
return isLineNumber() || isCommandSeparator();
}
public boolean isToken() {
return tokenString != null;
}
public boolean isString() {
return stringValue != null;
}
public boolean isExpressionSeparator() {
return isCommandSeparator()
|| ",".equals(stringValue) //$NON-NLS-1$
|| ";".equals(stringValue); //$NON-NLS-1$
}
/**
* Get the line number.
*/
public int getLineNumber() {
return lineNumber;
}
/**
* Get the string value.
*/
public String getStringValue() {
return stringValue;
}
/**
* Get the token.
*/
public String getTokenString() {
return tokenString;
}
/**
* Get the token.
*/
public byte getTokenValue() {
return tokenValue;
}
/**
* Render the token as a useful String.
*/
public String toString() {
if (isLineNumber()) {
return Integer.toString(getLineNumber());
} else if (isToken()) {
return getTokenString() + " " + Integer.toHexString(getTokenValue()); //$NON-NLS-1$
} else {
return getStringValue();
}
}
}

View File

@ -0,0 +1,156 @@
/*
* AppleCommander - An Apple ][ image utility.
* Copyright (C) 2008 by David Schmidt
* robgreene at users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.webcodepro.applecommander.util;
import com.webcodepro.applecommander.storage.FileEntry;
/**
* Tokenize the given file as an Apple /// Business BASCIC file.
* <p>
* Apple /// Business BASIC memory format:<br>
* [Line]<br>
* ...
* [Line]<br>
* <br>
* where [Line] is:<br>
* [Offset to next line - $0000 is end of program] (byte)<br>
* [Line no] (word)<br>
* [Tokens and/or characters]<br>
* [End-of-line marker: $00 bytes]
* <p>
* Date created: Dec 15, 2008 11:17:04 PM
* @author David Schmidt
*/
public class BusinessBASICTokenizer {
private static String tokens[] = { // starts at $80
" END ", " FOR ", " NEXT ", " INPUT ", " OUTPUT ", " DIM ", " READ ", " WRITE ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" OPEN ", " CLOSE ", " *error* ", " TEXT ", " *error* ", " *error* ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " *error* ", " *error* ", " WINDOW ", " INVOKE ", " PERFORM ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" FRE ", " HPOS ", " VPOS ", " ERRLIN ", " ERR ", " KBD ", " EOF ", " TIME$ ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" DATE$ ", " PREFIX$ ", " EXFN. ", " EXFN%. ", " OUTREC ", " INDENT ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " POP ", " HOME ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" SUB$( ", " OFF ", " TRACE ", " NOTRACE ", " NORMAL ", " INVERSE ", " SCALE( ", " RESUME ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " LET ", " GOTO ", " IF ", " RESTORE ", " SWAP ", " GOSUB ", " RETURN ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" REM ", " STOP ", " ON ", " *error* ", " LOAD ", " SAVE ", " DELETE ", " RUN ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" RENAME ", " LOCK ", " UNLOCK ", " CREATE ", " EXEC ", " CHAIN ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " CATALOG ", " *error* ", " *error* ", " DATA ", " IMAGE ", " CAT ", " DEF ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " PRINT ", " DEL ", " ELSE ", " CONT ", " LIST ", " CLEAR ", " GET ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" NEW ", " TAB ", " TO ", " SPC( ", " USING ", " THEN ", " *error* ", " MOD ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" STEP ", " AND ", " OR ", " EXTENSION "," DIV ", " *error* ", " FN ", " NOT ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " tf7 ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" TAB( ", " TO ", " SPC( ", " USING ", " THEN ", " *error* ", " MOD ", " STEP ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" AND ", " OR ", " EXTENSION "," DIV ", " *error* ", " FN ", " NOT ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " *error* ", " *error* ", " *error* ", " AS ", " SGN( ", " INT( ", " ABS( ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " TYP( ", " REC( ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " PDL( ", " BUTTON( ", " SQR( ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" RND( ", " LOG( ", " EXP( ", " COS( ", " SIN( ", " TAN( ", " ATN( ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " *error* ", " *error* ", " STR$( ", " HEX$( ", " CHR$( ", " LEN( ", " VAL( ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" ASC( ", " TEN( ", " *error* ", " *error* ", " CONV( ", " CONV&( ", " CONV$( ", " CONV%( ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" LEFT$( ", " RIGHT$( ", " MID$( ", " INSTR$( ", " *error* ", " *error* ", " *error* ", " *error* "};//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
private byte[] fileData;
private int offset = 2;
private int nextAddress = -1;
/**
* Constructor for BusinessBASICTokenizer.
*/
public BusinessBASICTokenizer(FileEntry fileEntry) {
this(fileEntry.getFileData());
}
/**
* Constructor for BusinessBASICTokenizer.
*/
public BusinessBASICTokenizer(byte[] fileData) {
this.fileData = fileData;
}
/**
* Indicates if there are more tokens in the Business BASIC program.
*/
public boolean hasMoreTokens() {
return (offset < fileData.length);
}
/**
* Answer with the next token in the Business BASIC program. This may be
* code, string pieces, line numbers.
*/
public BusinessBASICToken getNextToken() {
if (hasMoreTokens()) {
if (nextAddress == -1) {
nextAddress = AppleUtil.getUnsignedByte(fileData, offset);
offset+= 1;
if (nextAddress == 0) {
// At end of file, ensure we don't try to continue processing...
offset = fileData.length;
return null;
}
int lineNumber = AppleUtil.getWordValue(fileData, offset);
offset+= 2;
return new BusinessBASICToken(lineNumber);
}
byte byt = fileData[offset++];
if (byt == 0) {
nextAddress = -1;
return getNextToken();
} else if ((byt & 0x80) != 0) {
int token = AppleUtil.getUnsignedByte(byt) - 0x80;
if (token == 0x7f) {
// Shift to the lower part of the table
byt = fileData[offset++];
token = AppleUtil.getUnsignedByte(byt);
}
if (token >= tokens.length) {
return new BusinessBASICToken(byt, "<UNKNOWN TOKEN>"); //$NON-NLS-1$
}
return new BusinessBASICToken(byt, tokens[token]);
} else if (byt == ':' || byt == ';' || byt == ',' || byt == '^'
|| byt == '+' || byt == '-' || byt == '*' || byt == '/') {
return new BusinessBASICToken(new String(new byte[] { byt }));
} else {
StringBuffer string = new StringBuffer();
while (true) {
char ch = (char)byt;
if (ch < 0x20) {
string.append("<CTRL-"); //$NON-NLS-1$
string.append((char)('@' + ch));
string.append('>');
} else {
string.append(ch);
}
byt = fileData[offset];
// FIXME: This is a hack to break on ":", ",", ";" but will fail on strings
if ((byt & 0x80) != 0 || byt == 0
|| byt == 0x3a || byt == 0x2c || byt == 0x3b) {
break;
}
offset++;
}
return new BusinessBASICToken(string.toString());
}
}
return null;
}
}

View File

@ -0,0 +1,136 @@
/*
* AppleCommander - An Apple ][ image utility.
* Copyright (C) 2003 by Robert Greene
* robgreene at users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.webcodepro.applecommander.util;
/**
* This class contains all Applesoft tokens.
* Note that invalid source characters (&amp;, &lt;, etc)
* are spelled out.
* @author Rob
*/
public interface BusinessBASICTokens {
public static final byte END = (byte) 0x80;
public static final byte FOR = (byte) 0x81;
public static final byte NEXT = (byte) 0x82;
public static final byte DATA = (byte) 0x83;
public static final byte INPUT = (byte) 0x84;
public static final byte DEL = (byte) 0x85;
public static final byte DIM = (byte) 0x86;
public static final byte READ = (byte) 0x87;
public static final byte GR = (byte) 0x88;
public static final byte TEXT = (byte) 0x89;
public static final byte PRnbr = (byte) 0x8a;
public static final byte INnbr = (byte) 0x8b;
public static final byte CALL = (byte) 0x8c;
public static final byte PLOT = (byte) 0x8d;
public static final byte HLIN = (byte) 0x8e;
public static final byte VLIN = (byte) 0x8f;
public static final byte HGR2 = (byte) 0x90;
public static final byte HGR = (byte) 0x91;
public static final byte HCOLOR = (byte) 0x92;
public static final byte HPLOT = (byte) 0x93;
public static final byte DRAW = (byte) 0x94;
public static final byte XDRAW = (byte) 0x95;
public static final byte HTAB = (byte) 0x96;
public static final byte HOME = (byte) 0x97;
public static final byte ROT = (byte) 0x98;
public static final byte SCALE = (byte) 0x99;
public static final byte SHLOAD = (byte) 0x9a;
public static final byte TRACE = (byte) 0x9b;
public static final byte NOTRACE = (byte) 0x9c;
public static final byte NORMAL = (byte) 0x9d;
public static final byte INVERSE = (byte) 0x9e;
public static final byte FLASH = (byte) 0x9f;
public static final byte COLOR = (byte) 0xa0;
public static final byte POP = (byte) 0xa1;
public static final byte VTAB = (byte) 0xa2;
public static final byte HIMEM = (byte) 0xa3;
public static final byte LOMEM = (byte) 0xa4;
public static final byte ONERR = (byte) 0xa5;
public static final byte RESUME = (byte) 0xa6;
public static final byte RECALL = (byte) 0xa7;
public static final byte STORE = (byte) 0xa8;
public static final byte SPEED = (byte) 0xa9;
public static final byte LET = (byte) 0xaa;
public static final byte GOTO = (byte) 0xab;
public static final byte RUN = (byte) 0xac;
public static final byte IF = (byte) 0xad;
public static final byte RESTORE = (byte) 0xae;
public static final byte AMPERSAND = (byte) 0xaf;
public static final byte GOSUB = (byte) 0xb0;
public static final byte RETURN = (byte) 0xb1;
public static final byte REM = (byte) 0xb2;
public static final byte STOP = (byte) 0xb3;
public static final byte ON = (byte) 0xb4;
public static final byte WAIT = (byte) 0xb5;
public static final byte LOAD = (byte) 0xb6;
public static final byte SAVE = (byte) 0xb7;
public static final byte DEF = (byte) 0xb8;
public static final byte POKE = (byte) 0xb9;
public static final byte PRINT = (byte) 0xba;
public static final byte CONT = (byte) 0xbb;
public static final byte LIST = (byte) 0xbc;
public static final byte CLEAR = (byte) 0xbd;
public static final byte GET = (byte) 0xbe;
public static final byte NEW = (byte) 0xbf;
public static final byte TAB = (byte) 0xc0;
public static final byte TO = (byte) 0xc1;
public static final byte FN = (byte) 0xc2;
public static final byte SPC = (byte) 0xc3;
public static final byte THEN = (byte) 0xc4;
public static final byte AT = (byte) 0xc5;
public static final byte NOT = (byte) 0xc6;
public static final byte STEP = (byte) 0xc7;
public static final byte PLUS = (byte) 0xc8;
public static final byte MINUS = (byte) 0xc9;
public static final byte MULTIPLY = (byte) 0xca;
public static final byte DIVIDE = (byte) 0xcb;
public static final byte POWER = (byte) 0xcc;
public static final byte AND = (byte) 0xcd;
public static final byte OR = (byte) 0xce;
public static final byte GREATERTHAN = (byte) 0xcf;
public static final byte EQUALS = (byte) 0xd0;
public static final byte LESSTHAN = (byte) 0xd1;
public static final byte SGN = (byte) 0xd2;
public static final byte INT = (byte) 0xd3;
public static final byte ABS = (byte) 0xd4;
public static final byte USR = (byte) 0xd5;
public static final byte FRE = (byte) 0xd6;
public static final byte SCRN = (byte) 0xd7;
public static final byte PDL = (byte) 0xd8;
public static final byte POS = (byte) 0xd9;
public static final byte SQR = (byte) 0xda;
public static final byte RND = (byte) 0xdb;
public static final byte LOG = (byte) 0xdc;
public static final byte EXP = (byte) 0xdd;
public static final byte COS = (byte) 0xde;
public static final byte SIN = (byte) 0xdf;
public static final byte TAN = (byte) 0xe0;
public static final byte ATN = (byte) 0xe1;
public static final byte PEEK = (byte) 0xe2;
public static final byte LEN = (byte) 0xe3;
public static final byte STR$ = (byte) 0xe4;
public static final byte VAL = (byte) 0xe5;
public static final byte ASC = (byte) 0xe6;
public static final byte CHR$ = (byte) 0xe7;
public static final byte LEFT$ = (byte) 0xe8;
public static final byte RIGHT$ = (byte) 0xe9;
public static final byte MID$ = (byte) 0xea;
}