2019-03-01 05:21:18 +00:00
|
|
|
export default function ApplesoftDump(mem)
|
2016-11-22 05:17:34 +00:00
|
|
|
{
|
|
|
|
var _mem = mem;
|
|
|
|
|
2019-01-09 08:51:25 +00:00
|
|
|
var LETTERS =
|
|
|
|
' ' +
|
|
|
|
' !"#$%&\'()*+,-./0123456789:;<=>?' +
|
|
|
|
'@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_' +
|
|
|
|
'`abcdefghijklmnopqrstuvwxyz{|}~ ';
|
2016-11-22 05:17:34 +00:00
|
|
|
var TOKENS = {
|
2019-01-09 08:51:25 +00:00
|
|
|
0x80: 'END',
|
|
|
|
0x81: 'FOR',
|
|
|
|
0x82: 'NEXT',
|
|
|
|
0x83: 'DATA',
|
|
|
|
0x84: 'INPUT',
|
|
|
|
0x85: 'DEL',
|
|
|
|
0x86: 'DIM',
|
|
|
|
0x87: 'READ',
|
|
|
|
0x88: 'GR',
|
|
|
|
0x89: 'TEXT',
|
|
|
|
0x8a: 'PR#',
|
|
|
|
0x8b: 'IN#',
|
|
|
|
0x8c: 'CALL',
|
|
|
|
0x8d: 'PLOT',
|
|
|
|
0x8e: 'HLIN',
|
|
|
|
0x8f: 'VLIN',
|
|
|
|
0x90: 'HGR2',
|
|
|
|
0x91: 'HGR',
|
|
|
|
0x92: 'HCOLOR=',
|
|
|
|
0x93: 'HPLOT',
|
|
|
|
0x94: 'DRAW',
|
|
|
|
0x95: 'XDRAW',
|
|
|
|
0x96: 'HTAB',
|
|
|
|
0x97: 'HOME',
|
|
|
|
0x98: 'ROT=',
|
|
|
|
0x99: 'SCALE=',
|
|
|
|
0x9a: 'SHLOAD',
|
|
|
|
0x9b: 'TRACE',
|
|
|
|
0x9c: 'NOTRACE',
|
|
|
|
0x9d: 'NORMAL',
|
|
|
|
0x9e: 'INVERSE',
|
|
|
|
0x9f: 'FLASH',
|
|
|
|
0xa0: 'COLOR=',
|
|
|
|
0xa1: 'POP=',
|
|
|
|
0xa2: 'VTAB',
|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|
0xd7: 'SCRN(',
|
|
|
|
0xd8: 'PDL',
|
|
|
|
0xd9: 'POS',
|
|
|
|
0xda: 'SQR',
|
|
|
|
0xdb: 'RND',
|
|
|
|
0xdc: 'LOG',
|
|
|
|
0xdd: 'EXP',
|
|
|
|
0xde: 'COS',
|
|
|
|
0xdf: 'SIN',
|
|
|
|
0xe0: 'TAN',
|
|
|
|
0xe1: 'ATN',
|
|
|
|
0xe2: 'PEEK',
|
|
|
|
0xe3: 'LEN',
|
|
|
|
0xe4: 'STR$',
|
|
|
|
0xe5: 'VAL',
|
|
|
|
0xe6: 'ASC',
|
|
|
|
0xe7: 'CHR$',
|
|
|
|
0xe8: 'LEFT$',
|
|
|
|
0xe9: 'RIGHT$',
|
|
|
|
0xea: 'MID$'
|
2016-11-22 05:17:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function readByte(addr) {
|
|
|
|
var page = addr >> 8,
|
|
|
|
off = addr & 0xff;
|
|
|
|
|
2019-12-30 03:13:59 +00:00
|
|
|
return _mem.read(page, off);
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function readWord(addr) {
|
|
|
|
var lsb, msb;
|
|
|
|
|
2019-12-03 02:55:01 +00:00
|
|
|
lsb = readByte(addr);
|
|
|
|
msb = readByte(addr + 1);
|
2019-01-09 08:51:25 +00:00
|
|
|
|
2016-11-22 05:17:34 +00:00
|
|
|
return (msb << 8) | lsb;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
toString: function () {
|
2019-01-09 08:51:25 +00:00
|
|
|
var str = '';
|
2016-11-22 05:17:34 +00:00
|
|
|
var start = readWord(0x67); // Start
|
|
|
|
var end = readWord(0xaf); // End of program
|
|
|
|
var addr = start;
|
|
|
|
do {
|
2019-01-09 08:51:25 +00:00
|
|
|
var line = '';
|
2016-11-22 05:17:34 +00:00
|
|
|
var next = readWord(addr);
|
|
|
|
addr += 2;
|
|
|
|
var lineno = readWord(addr);
|
|
|
|
addr += 2;
|
2019-01-09 08:51:25 +00:00
|
|
|
|
2016-11-22 05:17:34 +00:00
|
|
|
line += lineno;
|
2019-01-09 08:51:25 +00:00
|
|
|
line += ' ';
|
2016-11-22 05:17:34 +00:00
|
|
|
var val = false;
|
|
|
|
do {
|
|
|
|
if (addr < start || addr > end)
|
2019-01-09 08:51:25 +00:00
|
|
|
return str;
|
|
|
|
|
|
|
|
val = readByte(addr++);
|
2019-12-27 23:04:07 +00:00
|
|
|
if (val >= 0x80) {
|
2019-01-09 08:51:25 +00:00
|
|
|
line += ' ';
|
2016-11-22 05:17:34 +00:00
|
|
|
line += TOKENS[val];
|
2019-01-09 08:51:25 +00:00
|
|
|
line += ' ';
|
2016-11-22 05:17:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
line += LETTERS[val];
|
|
|
|
} while (val);
|
2019-01-09 08:51:25 +00:00
|
|
|
line += '\n';
|
2016-11-22 05:17:34 +00:00
|
|
|
str += line;
|
|
|
|
addr = next;
|
|
|
|
} while (addr && addr >= start && addr < end);
|
2019-01-09 08:51:25 +00:00
|
|
|
|
2016-11-22 05:17:34 +00:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
};
|
2019-01-09 08:51:25 +00:00
|
|
|
}
|