Skip to content

Commit 386a8c4

Browse files
committed
*db/read *db/chunkparsers
read: - ATASCII and a couple of its options added (gods I should stop it with the hacking in of things) - the more narrow side trianglies I used to be using for some reason are now proper side trianglies. I hate that Github is showing some of these characters on blue square background, they've been around since long before unicode existed... chunkparsers: - Atari binary detection can now start from a user-specified offset. Obvious stuff...
1 parent ff878d8 commit 386a8c4

File tree

2 files changed

+41
-20
lines changed

2 files changed

+41
-20
lines changed

db/chunkparsers

+12-8
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ includeScript("read");
77

88
/**
99
* If it's an Amiga hunk file, parses it and tries to be strict in case of garbage past EoF.
10+
* @param {Int} baseofs - base offset from which to start parsing
1011
* @returns {Array} [nTotalSize,aBlockInfo,c] where:
11-
* - nTotalSize: -1 if the file is not an Atari DOS "binary save", otherwise the total expected size;
12+
* - nTotalSize: -1 if the file is not an Atari DOS "binary save", otherwise the total expected size (including baseofs);
1213
* - aBlockInfo: an Array with separate block types, offsets, and sizes, its length reflecting the number of hunks
1314
*/
14-
function parseAmigaHunks() {
15+
function parseAmigaHunks(baseofs) {
1516
//TODO check types, check reslibs, break off if invalid
16-
if(!X.c("000003F3")) return [-1, []]; //is it an Amiga hunk file?
17-
var p = 4, x = sz = i = reslibs = 0, info = [], load = true;
17+
if(typeof baseofs === "undefined") baseofs = 0;
18+
if(!X.c("000003F3",baseofs)) return [-1, []]; //is it an Amiga hunk file?
19+
var p = baseofs+4, x = sz = i = reslibs = 0, info = [], load = true;
1820
//library strings:
1921
while(p < X.Sz()) {
2022
x = X.U32(4,_BE); p += 4; if(!reslibs && x) load = false; if(x) reslibs++; else break; p += 4*x
@@ -33,16 +35,18 @@ function parseAmigaHunks() {
3335

3436
/**
3537
* If it's an Atari DOS block file, parses it and tries to be strict in case of garbage past EoF.
38+
* @param {Int} baseofs - base offset from which to start parsing
3639
* @returns {Array} [nTotalSize,aBlockInfo] where:
37-
* - nTotalSize: -1 if the file is not an Atari DOS "binary save", otherwise the total expected size;
40+
* - nTotalSize: -1 if the file is not an Atari DOS "binary save", otherwise the total expected size (including baseofs);
3841
* - aBlockInfo: an Array of arrays with each block's offsets and sizes, its length reflecting the number of blocks
3942
*/
40-
function parseAtariBinary() {
41-
if(!X.c("FFFF") || X.Sz() < 6) return [-1, []];
43+
function parseAtariBinary(baseofs) {
44+
if(typeof baseofs === "undefined") baseofs = 0;
45+
if(!X.c("FFFF",baseofs) || X.Sz() < baseofs+6) return [-1, []];
4246
var hksz = 0,
4347
RAM = [],
4448
hkinfo = [],
45-
p = 2;
49+
p = 2+baseofs;
4650
while(p+4 <= X.Sz() && p < 65520) {
4751
var ptr = X.U16(p);
4852
if(!hkinfo.length && ptr == 0xFFFF) { p += 2; ptr = X.U16(p) } // the subsequent blocks don't have to have a sig

db/read

+29-12
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ const CPRISCOS = "⌂"+
101101
" ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿"+
102102
"ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß"+
103103
"àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ";
104+
const CPATASCII = ['▶',
105+
'🖤','├','▊','┘','┤','┐','╱','╲','◤','▛','◥','▙','▟','▆',' ̄',
106+
'▜','♣','┌','─','┼','◘','▀','▐','┬','┴','▐','└','\n','↑','↓','←','→',
107+
'█','!','”','#','$','%','&','’','(',')','*','+',',','ー','.',
108+
'/','𝟶','𝟷','𝟸','𝟹','𝟺','𝟻','𝟼','𝟽','𝟾','𝟿',':',';','<','=','>','?',
109+
'@','𝙰','𝙱','𝙲','𝙳','𝙴','𝙵','𝙶','𝙷','𝙸','𝙹','𝙺','𝙻','𝙼','𝙽','𝙾',
110+
'𝙿','𝚀','𝚁','𝚂','𝚃','𝚄','𝚅','𝚆','𝚇','𝚈','𝚉','【','\\','】','^','_',
111+
'♦','𝚊','𝚋','𝚌','𝚍','𝚎','𝚏','𝚐','𝚑','𝚒','𝚓','𝚔','𝚕','𝚖','𝚗','𝚘',
112+
'𝚙','𝚚','𝚛','𝚜','𝚝','𝚞','𝚟','𝚠','𝚡','𝚢','𝚣','♠','-','↰','◁','▷']; //arrow up then NW (🢰) not included for UTF limitations
104113
const CPAtariST = "⌂"+
105114
"ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥ßƒ"+
106115
"áíóúñѪº¿⌐¬½¼¡«»ãõØøœŒÀÃÕ¨´†¶©®™"+
@@ -115,11 +124,14 @@ const CPSpeccy = ['©', //too SPECIAL with all the tokens-for-characters, gotta
115124
'𝙵𝙾𝚁𝙼𝙰𝚃 ','𝙼𝙾𝚅𝙴 ','𝙴𝚁𝙰𝚂𝙴 ','𝙾𝙿𝙴𝙽 # ','𝙲𝙻𝙾𝚂𝙴 # ','𝙼𝙴𝚁𝙶𝙴 ','𝚅𝙴𝚁𝙸𝙵𝚈 ', '𝙱𝙴𝙴𝙿 ','𝙲𝙸𝚁𝙲𝙻𝙴 ','𝙸𝙽𝙺 ','𝙿𝙰𝙿𝙴𝚁 ','𝙵𝙻𝙰𝚂𝙷 ','𝙱𝚁𝙸𝙶𝙷𝚃 ','𝙸𝙽𝚅𝙴𝚁𝚂𝙴 ','𝙾𝚅𝙴𝚁 ','𝙾𝚄𝚃 ', //D0~F
116125
'𝙻𝙿𝚁𝙸𝙽𝚃 ','𝙻𝙻𝙸𝚂𝚃 ','𝚂𝚃𝙾𝙿 ','𝚁𝙴𝙰𝙳 ','𝙳𝙰𝚃𝙰 ','𝚁𝙴𝚂𝚃𝙾𝚁𝙴 ','𝙽𝙴𝚆 ', '𝙱𝙾𝚁𝙳𝙴𝚁 ','𝙲𝙾𝙽𝚃𝙸𝙽𝚄𝙴 ','𝙳𝙸𝙼 ','𝚁𝙴𝙼 ','𝙵𝙾𝚁 ','𝙶𝙾 𝚃𝙾 ','𝙶𝙾 𝚂𝚄𝙱 ','𝙸𝙽𝙿𝚄𝚃 ','𝙻𝙾𝙰𝙳 ', //E0~F
117126
'𝙻𝙸𝚂𝚃 ','𝙻𝙴𝚃 ','𝙿𝙰𝚄𝚂𝙴 ','𝙽𝙴𝚇𝚃 ','𝙿𝙾𝙺𝙴 ','𝙿𝚁𝙸𝙽𝚃 ','𝙿𝙻𝙾𝚃 ', '𝚁𝚄𝙽 ','𝚂𝙰𝚅𝙴 ','𝚁𝙰𝙽𝙳𝙾𝙼𝙸𝚉𝙴 ','𝙸𝙵 ','𝙲𝙻𝚂','𝙳𝚁𝙰𝚆 ','𝙲𝙻𝙴𝙰𝚁 ','𝚁𝙴𝚃𝚄𝚁𝙽', '𝙲𝙾𝙿𝚈']; //F0~F
118-
const Chars0to1F = "・☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼"; //#0 is a small dot from Japanese
119-
const Chars0to1FLF = "・☺☻♥♦♣♠•◘○\x0A♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼";
120-
const Chars0to1FCRLF = "・☺☻♥♦♣♠•◘○\x0A♂♀\x0D♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼";
127+
const Chars0to1F = "・☺☻♥♦♣♠•◘○◙♂♀♪♫☼▶◀↕‼¶§▬↨↑↓→←∟↔▲▼"; //#0 is a small dot from Japanese
128+
const Chars0to1FLF = "・☺☻♥♦♣♠•◘○\x0A♂♀♪♫☼▶◀↕‼¶§▬↨↑↓→←∟↔▲▼";
129+
const Chars0to1FCRLF = "・☺☻♥♦♣♠•◘○\x0A♂♀\x0D♫☼▶◀↕‼¶§▬↨↑↓→←∟↔▲▼";
121130
const Chars0to1FSpeccy = "\0\1\2\3\4\5,📝⬅➡⬇⬆⌫\x0A№\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; //not mixing...
122-
131+
const Chars0to1FATASCII = "♥├◨┘┤┐/╲◢▗◣▝▘ ̄▂▖♣┌─┼•▄▎┬┴▌└␛↑↓←→";
132+
const Chars0to1FATASCII2 = "áùÑÉçôòì£ïüäöúóöÜâûîéèñêȧàȦ␛↑↓←→";
133+
const Chars0to1FATASCII_PL = "ŹąźćŚėöÖ£üߣłŃÓ√ĘśäÜĆĄŻÄż␛↑↓←→";
134+
const Chars0to1FAtariX = "áùÑÉçôòì£ïüäÖúóöÜâûîéèñêȧàȦË↑↓←→"
123135

124136
// a replacement for the duration of the regression in File.readBytes:
125137
function readU8Array(offset,length,ztospace) {
@@ -149,16 +161,21 @@ function decEncoding(ansi, dectbl, zstop, tbl01F) {
149161
else if(ansi[i] < 0x80)
150162
switch(ansi[i]) { // 7-bit variation processing
151163
case 0x0E: if(dectbl == JISX0201 || dectbl == KOI8R) bit8 = 0x80;
152-
else s += tbl01F[0xE]; break;
164+
else s += tbl01F[0xE]; break;
153165
case 0x0F: if(dectbl == JISX0201 || dectbl == KOI8R) bit8 = 0;
154-
else s += tbl01F[0xF]; break;
155-
case 0x5C: if(dectbl == JISX0201) s += "¥"; else s += "\\"; break;
156-
case 0x5E: if(dectbl == CPSpeccy) s += '↑'; else s += '^'; break;
157-
case 0x60: if(dectbl == CPSpeccy) s += '£'; else s += '`'; break;
158-
case 0x7E: if(dectbl == JISX0201) s += "‾"; else s += "~"; break;
166+
else s += tbl01F[0xF]; break;
167+
case 0x5C: if(dectbl == JISX0201) s += '¥'; else s += '\\'; break;
168+
case 0x5E: if(dectbl == CPSpeccy) s += '↑'; else s += '^'; break;
169+
case 0x60: if(dectbl == CPSpeccy) s += '£'; else s += '`'; break;
170+
case 0x7B: if(dectbl == CPATASCII)
171+
if(tbl01F == Chars0to1FATASCII2) s += 'Ä';
172+
else if(tbl01F == Chars0to1FATASCII_PL) s += ' '; //the Poles didn't need the spades without the other 3 :D
173+
else s += '♠';
174+
else s += '{'; break;
175+
case 0x7D: if(dectbl == CPATASCII) s += '↖'; else s += '}'; break; //arrow up then NW (🢰) not included for UTF limitations
176+
case 0x7E: if(dectbl == JISX0201) s += '‾'; else if(dectbl == CPATASCII) s += '◀'; else s += '~'; break;
159177
case 0x7F:
160-
if(dectbl != JISX0201) s += dectbl[0];
161-
else s += String.fromCharCode(bit8+ansi[i]); break;
178+
if(dectbl != JISX0201) s += dectbl[0]; else s += String.fromCharCode(bit8+ansi[i]); break;
162179
default:
163180
if(!bit8 && ansi[i] >= 0 && ansi[i] < 0x20) s += tbl01F[ansi[i]];
164181
else s += String.fromCharCode(bit8+ansi[i]);

0 commit comments

Comments
 (0)