2015-06-01 09:35:51 +00:00
|
|
|
package com.bytezone.diskbrowser.applefile;
|
|
|
|
|
|
|
|
public class MerlinSource extends AbstractFile
|
|
|
|
{
|
|
|
|
int ptr;
|
|
|
|
private static int[] tabs = { 12, 19, 35 };
|
|
|
|
private static int TAB_POS = tabs[2];
|
|
|
|
private final int recordLength;
|
|
|
|
private final int eof;
|
2017-02-01 21:15:30 +00:00
|
|
|
private boolean prodosFile;
|
2015-06-01 09:35:51 +00:00
|
|
|
|
|
|
|
// Source : Prodos text file
|
|
|
|
public MerlinSource (String name, byte[] buffer, int recordLength, int eof)
|
|
|
|
{
|
|
|
|
super (name, buffer);
|
|
|
|
this.eof = eof;
|
|
|
|
this.recordLength = recordLength;
|
2017-02-01 21:15:30 +00:00
|
|
|
prodosFile = true;
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Source : Dos binary file
|
2017-11-26 06:16:56 +00:00
|
|
|
public MerlinSource (String name, byte[] buffer, int loadAddress)
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
|
|
|
super (name, buffer);
|
|
|
|
this.eof = 0;
|
|
|
|
this.recordLength = 0;
|
2017-11-26 06:16:56 +00:00
|
|
|
this.loadAddress = loadAddress;
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getText ()
|
|
|
|
{
|
|
|
|
StringBuilder text = new StringBuilder ();
|
|
|
|
|
2017-02-01 21:15:30 +00:00
|
|
|
text.append ("Merlin source : " + name + "\n");
|
|
|
|
if (prodosFile)
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
|
|
|
text.append (String.format ("Record length : %,8d%n", recordLength));
|
2017-02-01 21:15:30 +00:00
|
|
|
text.append (String.format ("EOF (aux) : %,8d%n", eof));
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
|
|
|
else
|
2017-11-26 06:16:56 +00:00
|
|
|
{
|
|
|
|
text.append (String.format ("Buffer size : %04X %<,8d%n", buffer.length));
|
|
|
|
text.append (String.format ("Load address : %04X %<,8d%n", loadAddress));
|
|
|
|
}
|
2015-06-01 09:35:51 +00:00
|
|
|
text.append ("\n");
|
|
|
|
|
|
|
|
ptr = 0;
|
|
|
|
while (ptr < buffer.length && buffer[ptr] != 0)
|
|
|
|
text.append (getLine () + "\n");
|
|
|
|
if (text.length () > 0)
|
|
|
|
text.deleteCharAt (text.length () - 1);
|
|
|
|
return text.toString ();
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getLine ()
|
|
|
|
{
|
|
|
|
StringBuilder line = new StringBuilder ();
|
|
|
|
boolean comment = false;
|
|
|
|
boolean string = false;
|
|
|
|
while (ptr < buffer.length)
|
|
|
|
{
|
|
|
|
int val = buffer[ptr++] & 0x7F;
|
|
|
|
if (val == 0x0D)
|
|
|
|
break;
|
|
|
|
if (val == '*' && line.length () == 0)
|
|
|
|
comment = true;
|
|
|
|
if (val == '"')
|
|
|
|
string = !string;
|
|
|
|
if (val == ';' && !comment)
|
|
|
|
{
|
|
|
|
comment = true;
|
|
|
|
while (line.length () < TAB_POS)
|
|
|
|
line.append (' ');
|
|
|
|
}
|
|
|
|
if (val == ' ' && !comment && !string)
|
|
|
|
{
|
|
|
|
line = tab (line);
|
|
|
|
if (line.length () >= tabs[2])
|
|
|
|
comment = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
line.append ((char) val);
|
|
|
|
}
|
|
|
|
return line.toString ();
|
|
|
|
}
|
|
|
|
|
|
|
|
private StringBuilder tab (StringBuilder text)
|
|
|
|
{
|
|
|
|
int nextTab = 0;
|
|
|
|
for (int tab : tabs)
|
|
|
|
if (text.length () < tab)
|
|
|
|
{
|
|
|
|
nextTab = tab;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
while (text.length () < nextTab)
|
|
|
|
text.append (' ');
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
}
|