dmolony-DiskBrowser/src/com/bytezone/diskbrowser/infocom/Globals.java

72 lines
2.6 KiB
Java
Raw Permalink Normal View History

2015-06-01 09:35:51 +00:00
package com.bytezone.diskbrowser.infocom;
2019-04-22 04:35:50 +00:00
import java.util.ArrayList;
import java.util.List;
import com.bytezone.diskbrowser.infocom.Instruction.Operand;
2020-02-09 13:02:48 +00:00
// -----------------------------------------------------------------------------------//
2016-02-05 07:18:23 +00:00
class Globals extends InfocomAbstractFile
2020-02-09 13:02:48 +00:00
// -----------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
{
2019-04-22 04:35:50 +00:00
private static final int TOTAL_GLOBALS = 240;
private final Header header;
private final int globalsPtr, globalsSize;
private final int arrayPtr, arraySize;
private final List<List<Routine>> globalRoutines;
2015-06-01 09:35:51 +00:00
2020-02-09 13:02:48 +00:00
// ---------------------------------------------------------------------------------//
2019-04-22 04:35:50 +00:00
Globals (Header header)
2020-02-09 13:02:48 +00:00
// ---------------------------------------------------------------------------------//
2016-02-05 07:18:23 +00:00
{
super ("Globals", header.buffer);
this.header = header;
2015-06-01 09:35:51 +00:00
2016-02-05 07:18:23 +00:00
globalsPtr = header.globalsOffset;
globalsSize = TOTAL_GLOBALS * 2;
arrayPtr = globalsPtr + globalsSize;
arraySize = header.staticMemory - arrayPtr;
2015-06-01 09:35:51 +00:00
2016-02-05 07:18:23 +00:00
// add entries for AbstractFile.getHexDump ()
hexBlocks.add (new HexBlock (globalsPtr, globalsSize, "Globals:"));
hexBlocks.add (new HexBlock (arrayPtr, arraySize, "Arrays:"));
2019-04-22 04:35:50 +00:00
2020-01-13 00:05:32 +00:00
globalRoutines = new ArrayList<> (TOTAL_GLOBALS);
for (int i = 0; i < TOTAL_GLOBALS; i++)
2019-04-22 04:35:50 +00:00
globalRoutines.add (new ArrayList<> ());
}
2020-02-09 13:02:48 +00:00
// ---------------------------------------------------------------------------------//
2019-04-22 04:35:50 +00:00
void addRoutine (Routine routine, Operand operand)
2020-02-09 13:02:48 +00:00
// ---------------------------------------------------------------------------------//
2019-04-22 04:35:50 +00:00
{
2020-01-13 00:05:32 +00:00
List<Routine> list = globalRoutines.get (operand.value - 16);
2019-04-22 04:35:50 +00:00
if (!list.contains (routine))
list.add (routine);
2016-02-05 07:18:23 +00:00
}
2015-06-01 09:35:51 +00:00
2020-02-09 13:02:48 +00:00
// ---------------------------------------------------------------------------------//
2016-02-05 07:18:23 +00:00
@Override
public String getText ()
2020-02-09 13:02:48 +00:00
// ---------------------------------------------------------------------------------//
2016-02-05 07:18:23 +00:00
{
2019-04-22 04:35:50 +00:00
StringBuilder text = new StringBuilder ("GLB Value Routines\n");
2020-01-13 00:05:32 +00:00
for (int i = 0; i < TOTAL_GLOBALS; i++)
2016-02-05 07:18:23 +00:00
{
int value = header.getWord (globalsPtr + i * 2);
2020-01-13 00:05:32 +00:00
text.append (String.format ("G%03d %04X %03d ", i, value,
2019-04-22 04:35:50 +00:00
globalRoutines.get (i).size ()));
2016-02-05 07:18:23 +00:00
int address = value * 2;
if (address >= header.stringPointer && address < header.fileLength)
text.append (header.stringManager.stringAt (address) + "\n");
else
2019-04-22 04:35:50 +00:00
{
for (Routine routine : globalRoutines.get (i))
text.append (String.format ("%05X ", routine.startPtr));
text.append ("\n");
}
2016-02-05 07:18:23 +00:00
}
text.deleteCharAt (text.length () - 1);
return text.toString ();
}
2015-06-01 09:35:51 +00:00
}