b-flat Admintastic

Joined: 20 Jan 2007 Posts: 315
|
Posted: Sat Apr 26, 2008 2:23 pm Post subject: Calculator ASM to Computer ASM converter (java) |
|
|
As everyone who has frequently uses the compiler knows, it is annoying to convert from the calculator version of Assembly code to the computer friendly version.
Thus, I wrote a converter in java that will convert between the file types. Unfortunately, I don't know how to run java outside of an IDE, so if you want to use it, you will have to download an IDE such as TextPad. The idea is to use it in conjunction with The Source Coder 2 from Cemetech
Features:
* removes extra :s at the beginning of lines
* reformats all b_calls into the proper format
* changes HEX statements into normal .db statements
* converts comments correctly (i.e. > to ; )
* saves the file as a .asm file (you can easily modify the program to make it .z80 if you want instead)
* assumes files to be .txt files if no extension is given
* Creates an error log of any errors encountered (currently, only local labels, which I don't think are in the released version anyway)
If anyone wants anything else added, please post.
| Code: | import java.util.Scanner;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.HashMap;
public class CalcTOASM
{
static String InputFileName;
static Scanner in;
static FileReader file;
static Scanner reader;
static PrintWriter out;
static String SaveFileName;
static String nextLine;
static String temp;
static HashMap mappy;
static String ErrorLog = "Errors:" + "\n";
static int line=2;
public static void main(String[] args)
{
makemappy();
System.out.println("Enter File Name: ");
in = new Scanner(System.in);
InputFileName = in.next();
if(InputFileName.indexOf(".")==-1)
{
SaveFileName = InputFileName + ".asm";
InputFileName = InputFileName + ".txt";
}
else
{
SaveFileName = InputFileName.substring(0,InputFileName.indexOf(".")) + ".asm";
}
try
{
file = new FileReader(InputFileName);
}
catch(java.io.FileNotFoundException e)
{
System.out.println("The file could not be found");
System.exit(1);
}
reader = new Scanner(file);
System.out.println(SaveFileName);
nextLine = reader.nextLine();
try
{
out = new PrintWriter(SaveFileName);
}
catch(java.io.FileNotFoundException e)
{
System.out.println("This error cannot occur.");
}
if(nextLine.equalsIgnoreCase(":DEFHDR.HDR"))
{
out.println(".nolist+");
out.println("#include \"ti83plus.inc\"");
out.println(".list");
out.println(".org $9D93");
out.println(".db t2ByteTok, tAsmCmp");
}
while(reader.hasNext())
{
nextLine = reader.nextLine();
System.out.println(nextLine);
if(nextLine.substring(0,1).equals(":"))
nextLine = nextLine.substring(1);
if(!nextLine.equals(""))
{
if(nextLine.indexOf("BCALL")!=-1)
{
if(nextLine.indexOf(";")!=-1)
{
temp = " " + nextLine.substring(nextLine.indexOf(";"));
}
else
{
temp = "";
}
nextLine = "b_call(" + mappy.get(nextLine.substring(6)) + ")" + temp;
}
if(nextLine.substring(0,1).equals(">"))
{
nextLine = ";" + nextLine.substring(1);
}
if(nextLine.indexOf("HEX")==0)
{
temp = ".db ";
for(int i=4; i<nextLine.length(); i+=2)
{
temp = temp + "$" + nextLine.substring(i,i+2) + ",";
}
nextLine = temp.substring(0,temp.length()-1);
}
out.println(nextLine);
if(nextLine.indexOf("{")!=-1)
ErrorLog = ErrorLog + "\n" + "Line " + line + " - temporary label (^) refered to";
if(nextLine.indexOf("^:")==0)
ErrorLog = ErrorLog + "\n" + "Line " + line + " - temporary label (^)";
}
else
{
out.println("");
}
line++;
}
out.println(".end");
out.println(".end");
out.close();
System.out.println(ErrorLog + "\n" + "----Saved as " + SaveFileName + "----");
}
public static void makemappy()
{
mappy = new HashMap();
mappy.put("ANSNAME","_AnsName");
mappy.put("ARCUNARC","_Arc_Unarc");
mappy.put("BUFCPY","_BufCpy");
mappy.put("CHKFINDSYM","_ChkFindSym");
mappy.put("CLRLCD","_ClrLCD");
mappy.put("CLRLCDFULL","_ClrLCDFull");
mappy.put("CLRSCRN","_ClrScrn");
mappy.put("CLRSCRNFULL","_ClrScrnFull");
mappy.put("CONVOP1","_ConvOP1");
mappy.put("CPHLDE","_CpHLDE");
mappy.put("CREATEAPPVAR","_CreateAppVar");
mappy.put("CREATEPROG","_CreateProg");
mappy.put("CREATEPROTPROG","_CreateProtProg");
mappy.put("CREATESTRING","_CreateString");
mappy.put("CURSORON","_CursorOn");
mappy.put("DARKLINE","_DarkLine");
mappy.put("DATASIZE","_DataSize");
mappy.put("DELVAR","_DelVar");
mappy.put("DISPHL","_DispHL");
mappy.put("DISPDONE","_DispDone");
mappy.put("DISPLAYOP1","_DispOP1");
mappy.put("DIVHLBY10","_DivHLBy10");
mappy.put("DIVHLBYA","_DivHLByA");
mappy.put("ERRARGUMENT","_ErrArgument");
mappy.put("ERRDATATYPE","_ErrDataType");
mappy.put("ERRUNDEFINED","_ErrUndefined");
mappy.put("FINDALPHDN","_FindAlphaDn");
mappy.put("FINDALPHUP","_FindAlphaUp");
mappy.put("FINDSYM","_FindSym");
mappy.put("FORCEFULLSCREEN","_ForceFullScreen");
mappy.put("FORMREAL","_FormReal");
mappy.put("GETCSC","_GetCSC");
mappy.put("GETKEY","_GetKey");
mappy.put("GETKEYRETOFF","_GetKeyRetOff");
mappy.put("GRBUFCPY","_GrBufCpy");
mappy.put("HOMEUP","_HomeUp");
mappy.put("IPOINT","_IPoint");
mappy.put("LDHLIND","_LdHLind");
mappy.put("MEMCHK","_MemChk");
mappy.put("MOV9TOOP1","_Mov9ToOP1");
mappy.put("MOV9TOOP2","_Mov9TOOP2");
mappy.put("NEWLINE","_NewLine");
mappy.put("OP1TOOP2","_OP1ToOP2");
mappy.put("OP2TOOP1","_OP2ToOP1");
mappy.put("POPREALO1","_PopRealO1");
mappy.put("PUSHREALO1","_PushRealO1");
mappy.put("PUTC","_PutC");
mappy.put("PUTMAP","_PutMap");
mappy.put("PUTS","_PutS");
mappy.put("PUTTOKSTRING","_PutTokString");
mappy.put("RUNINDICOFF","_RunIndicOff");
mappy.put("RUNINDICON","_RunIndicOn");
mappy.put("RCLANS","_RclAns");
mappy.put("RCLX","_RclX");
mappy.put("RCLY","_RCLY");
mappy.put("SETXXOP1","_SetXXOP1");
mappy.put("SETXXOP2","_SetXXOP2");
mappy.put("SETXXXXOP2","_SetXXXXOP2");
mappy.put("SRCHVLSTDN","_SrchVLstDn");
mappy.put("SRCHVLSTUP","_SrchVLstUp");
mappy.put("STOX","_StoX");
mappy.put("STOY","_StoY");
mappy.put("STOANS","_StoAns");
mappy.put("VPUTS","_VPutS");
mappy.put("VPUTMAP","_VPutMap");
mappy.put("ZEROOP1","_ZeroOp1");
mappy.put("ZEROOP2","_ZeroOp2");
mappy.put("ZEROOP3","_ZeroOp3");
mappy.put("APPBACKUPSCREEN","appBackUpScreen");
}
} |
ALSO, IF YOU ARE A JAVA NOOB, PLEASE SAVE THE FILE AS CalcTOASM.java!!! _________________ Outside The Box Programming
Progress:
Nibls With Music: 100% - Download it!
COTOR: 1%
MathProgram 2.6: 100% - Download it! |
|