How to use readBinaryData method in pact-foundation-pact

Best JavaScript code snippet using pact-foundation-pact

savegame.js

Source:savegame.js Github

copy

Full Screen

...87 }88 return s;89}9091function readBinaryData(addr) {92 // The first 256 bytes of memory are copied to the screen area at 240 (0x40 here)93 // 00 - FF94 if(addr<0x100) {95 return saveGameData.charCodeAt(addr);96 }97 // 240 - 60098 if(addr>=0x240 && addr<0x600) {99 return saveGameData.charCodeAt(addr-0x240);100 }101 // 3BC1102 if(addr>=0x3BC1) {103 return saveGameData.charCodeAt(addr-0x3BC1+0x3C0);104 }105}106107108function getRoomDoors(rn) {109 var d = binData.read(0x3DB8+rn);110 //--UDNEWS111 ret = '--';112 if((d&32) != 0) ret=ret+'U';113 else ret=ret+'-';114 if((d&16) != 0) ret=ret+'D';115 else ret=ret+'-';116 if((d&8) != 0) ret=ret+'N';117 else ret=ret+'-';118 if((d&4) != 0) ret=ret+'E';119 else ret=ret+'-';120 if((d&2) != 0) ret=ret+'W';121 else ret=ret+'-';122 if((d&1) != 0) ret=ret+'S';123 else ret=ret+'-';124 return ret; 125}126127function getNeighborRoomNumber(rn,dir) {128 if(dir=='U') rn = rn - 64;129 else if(dir=='D') rn = rn + 64;130 else if(dir=='W') rn = rn - 1;131 else if(dir=='E') rn = rn + 1;132 else if(dir=='N') rn = rn - 8;133 else if(dir=='S') rn = rn + 8;134 if(rn>256) rn=rn-256;135 if(rn<0) rn=rn+256;136 return rn;137}138139var BETWEEN_ROOM_ACTIONS = {140 0x1AFB : 'A',141 0x1B20 : 'B',142 0x1B03 : 'C',143 0x1B06 : 'D',144 0x1B09 : 'E',145 0x1B34 : 'F',146 0x1B5F : 'G',147 0x1B43 : 'H',148 0x1B4A : 'I'149}150151var DIRS = {152 1 : 'S',153 2 : 'W',154 4 : 'E',155 8 : 'N',156 16 : 'D',157 32 : 'U'158}159160var OPPOSITE_DIR = {'U':'D', 'D':'U', 'N':'S', 'E':'W', 'W':'E', 'S':'N'};161162function getBetweenRoomAction(rn,dir) {163 var p = 0x3B4A;164 while(true) { 165 var a = binData.read(p);166 var b = binData.read(p+1);167 if(b==0) break;168 b = DIRS[b];169 var c = binData.read(p+2)*256 + binData.read(p+3);170 p += 4; 171 if((rn==a) && (dir==b)) { 172 a = BETWEEN_ROOM_ACTIONS[c];173 if(a=='A' || a=='C' || a=='D' || a=='E') {174 // These actions only trigger in the UP direction.175 // Strangely they appear on a few passages in other176 // directions. They could never trigger. We'll leave177 // them off the map. 178 if(dir!='U') continue;179 }180 return a;181 } 182 }183 // Just like the code ... run the list in the opposite travel direction184 var p = 0x3B4A;185 while(true) {186 var a = binData.read(p);187 var b = binData.read(p+1);188 if(b==0) break;189 b = DIRS[b];190 var c = binData.read(p+2)*256 + binData.read(p+3);191 p += 4; 192 a = getNeighborRoomNumber(a,b);193 b = OPPOSITE_DIR[b];194 if( (rn==a) && (dir==b)) {195 a = BETWEEN_ROOM_ACTIONS[c];196 if(a=='A' || a=='C' || a=='D' || a=='E') {197 // These actions only trigger in the UP direction.198 // Strangely they appear on a few passages in other199 // directions. They could never trigger. We'll leave200 // them off the map. 201 if(dir!='U') continue;202 }203 return a;204 } 205 }206 return '';207}208209function isEdge(rn,dir) {210 fn = ~~(rn / 64);211 x = (rn%64)%8;212 y = ~~((rn%64)/8);213 if(dir=='U') {214 return fn==0;215 } else if(dir=='D') {216 return fn==3;217 } else if(dir=='N') {218 return y==0;219 } else if(dir=='E') {220 return x==7;221 } else if(dir=='W') {222 return x==0;223 } else if(dir=='S') {224 return y==7;225 } 226}227228JUMPS = [229 [143, "PIT", 151, 128, 'D'],230 [151, "PIT", 143, 128, 'F'],231 [16, "POOL", 7, 128, 'F'],232 [17, "POOL", 16, 128, 'F'],233 [78, "CHASM", 86, 64, 'F'],234 [86, "CHASM", 78, 64, 'F'],235 [44, "PIT", 182, 10, 'S(10)'],236 [182, "PIT", 44, 20, 'S(20)'],237 [164, "PIT", 202, 160, 'D'],238 [133, "PIT", 203, 192, 'F'],239 [144, "", 133, 20, 'S(20)'],240 [203, "PIT", 202, 128, 'S(30)'],241 [213, "MIST", 212, 70, 'S(20)'],242 [212, "MIST", 213, 70, 'S(20)'],243 [35, "HOLE", 34, 150, 'S(40)'],244 [34, "PIT", 35, 120, 'S(20)'],245 [128, "UP", 64, 100, 'F'],246 [166, "UP", 102, 80, 'F'],247 [102, "UP", 38, 160, 'F'],248 [92, "DOWN", 156, 150, 'S(30)'],249 [70, "DOWN", 140, 80, 'S(20)'],250 [94, "DOWN", 158, 90, 'S(10)'],251 [64, "PIT", 128, 30, 'D'],252 [202, "DOWN", 162, 30, 'S(20)'],253 // Source address assigned along with enter-room-203 (small pit)254 [-1, "JUMP DOWN", 39,140,'F']255]256257function getJump(rn) {258 var i;259 for(i=0;i<JUMPS.length;++i) {260 if(JUMPS[i][0]==rn) {261 return 'Jump:' + JUMPS[i][1]+':'+JUMPS[i][2]+':'+JUMPS[i][3]+':'+JUMPS[i][4]; 262 }263 }264 return '';265}266267var saveGameData = [];268var SPELL_INFO = [269 {name: 'VETRA', learned: false, room: -1},270 {name: 'MITRA', learned: false, room: -1},271 {name: 'OKKAN', learned: false, room: -1},272 {name: 'AKHIROM', learned: false, room: -1},273 {name: 'NERGAL', learned: false, room: -1},274 {name: 'BELROG', learned: false, room: -1},275 {name: 'CROM', learned: false, room: -1},276 {name: 'ISHTAR', learned: false, room: -1} 277]278function getSpell(rn) {279 ret = '';280 for(var i=0;i<8;++i) {281 if(SPELL_INFO[i].room==rn && SPELL_INFO[i].learned==false) {282 ret = ret + SPELL_INFO[i].name+','; 283 }284 }285 return ret;286}287288var OBJECTS = [];289var OBJECT_NAMES = [290 "FOOD", "BOTTLE", "DAGGER", "MACE", "AX", "SWORD", "SHIELD", "FLUTE", "MUSHROOM", "PENDANT", "SCEPTER", "LAMP",291 "BASKET", "PARCHMENT", "VIAL", "URN", "TALISMAN", "SCROLL", "GOBLET", "SKULL", "SCARAB", "JEWELBOX", "TABLET", "ROPE", 292 "SPRITE", "TROGLODYTE", "SCORPION", "NYMPH", "SATYR", "MINOTAUR",293 "ORACLE", 294 "GOLD", "SILVER", "DIAMOND", "SPELLBOOK", "RUBY", "FLEECE", "TIARA", "POWDER", "AMULET", "POTION", "POWERRING", 295 "LIGHTRING","TRUTHRING", "CROWN", "OPAL", "SAPPHIRE"296]297function getObjectsInRoom(rn) { 298 ret = '';299 for(var i=0;i<OBJECTS.length;++i) {300 o = OBJECTS[i];301 if(o['in_pack'] || o['spell_creature'] || !o['accessible']) continue;302 if(o['room']==rn) {303 if(o['protected']) ret = ret + '*';304 ret = ret + o['name']+',';305 } 306 }307 return ret;308}309function getMonstersInRoom(rn) {310 ret = '';311 for(var i=0;i<OBJECTS.length;++i) {312 o = OBJECTS[i];313 if(!o['spell_creature'] || !o['accessible']) continue;314 if(o['name']=='ORACLE') continue;315 if(o['room']==rn) {316 ret = ret + o['name']+',';317 } 318 }319 return ret;320}321function isOracleInRoom(rn) {322 for(var i=0;i<OBJECTS.length;++i) {323 o = OBJECTS[i];324 if(o['name']!='ORACLE') continue;325 if(o['room']==rn) {326 return true;327 } 328 }329 return false;330}331332function truncList(s) {333 if(s.endsWith(',')) s=s.substring(0,s.length-1);334 return s;335}336337ENTER_ROOM_ACTIONS = {338 0x1B6D:'_a',339 0x1B70:'_b',340 0x1B73:'_c',341 0x1B9C:'_d',342 0x1BB3:'_e',343 0x1BB7:'_f',344 0x1BF9:'_g',345 0x1C15:'_h',346 0x1C2C:'_i',347 0x1C2F:'_j',348 0x1C32:'_k',349 0x1C35:'_l',350 0x1C38:'_m',351 0x1C3B:'_n',352 0x1C3E:'_o',353 0x1C41:'_p',354 0x1C68:'_q',355 0x1C7A:'_r',356 0x1C8D:'_s',357 0x1CA9:'_t',358 0x1CCC:'_u',359 0x1CF0:'_v',360 0x1D00:'_x',361 0x1D22:'_203',362 0x1D27:'_213',363 0x1CE0:'_32',364 0x1CD6:'_33',365 0x1BB4:'_z',366 0x1D2D:'_232'367}368369function getEnterRoomAction(rn) {370 ret = '';371 // These are hardcoded -- even if there is no save game372 if(rn==203) return '_203';373 if(rn==213) return '_213';374 if(rn==32) return '_32';375 if(rn==33) return '_33';376 if(rn==232) return '_232'; 377 for(var i=0;i<36;++i) {378 if(readBinaryData(0x3C8F+i*3)==rn) {379 var a = readBinaryData(0x3C8F+i*3+1)*256 + readBinaryData(0x3C8F+i*3+2);380 ret = ret + ENTER_ROOM_ACTIONS[a]+',';381 }382 }383 return ret;384}385386function findRawTextLine(lines,addr,i) {387 while(true) {388 if(lines[i].startsWith(addr+':')) {389 return i;390 }391 ++i;392 }393}394395function hexPad(val,n) {396 ret = val.toString(16).toUpperCase();397 while(ret.length<n) {398 ret = '0' + ret;399 }400 return ret;401}402403function getReplaceTarget(s) {404 var i = s.indexOf('{{');405 var j = s.indexOf('}}');406 return s.substring(i+2,j);407}408409function doReplaceTarget(s,k,v) {410 return s.replace('{{'+k+'}}',v);411}412413//ASCII to CoCo screen printable414var CHARMAP = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"+415 "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"+416 "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[~]~~"+417 "_!\"#$%&'()*+,-./0123456789:;<=>?"+418 "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"+419 "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"+420 "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"+421 "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";422423var NAMETABLE = {424 0x19 : 'Sprite',425 0x1A : 'Troglodyte',426 0x1B : 'Scorpion',427 0x1C : 'Nymph',428 0x1D : 'Satyr',429 0x1E : 'Minotaur',430 0x01 : 'Crypt',431 0x02 : 'Crypt of kings',432 0x03 : 'Enter-room-action _u',433 0x04 : 'Enter-room-action _33',434 0x05 : 'Small pit',435 0x06 : 'Ledge',436 0x07 : 'Hydra',437 0x08 : 'Pile of glowing rocks',438 0x09 : 'Eerie glow',439 0x0A : 'Packrat',440 0x0B : 'Enter-room-action _r',441}442443var PROTECTIONS = {444 0x1A: {445 name : 'TROGLODYTE',446 items : [447 '45 0B 38 FF ; AX, SCEPTER, MITRA',448 '23 7D FF ; SPELLBOOK, CROM',449 '43 07 3B FF ; DAGGER, SHIELD, NERGAL'450 ]451 },452 0x1D: {453 name : 'SATYR',454 items : [455 '46 3B FF ; SWORD, NERGAL',456 '44 2B 38 FF ; MACE, LIGHTRING, MITRA',457 '23 77 FF ; SPELLBOOK, VETAR',458 ]459 },460 0x1E: {461 name : 'MINOTAUR',462 items : [463 '46 07 2A FF ; SWORD, SHIELD, POWERRING',464 '44 0F 0B 38 FF ; MACE, VIAL, SCEPTER, MITRA',465 '45 3B FF ; AX, NERGAL',466 ]467 },468 0x1B: {469 name : 'SCORPION',470 items : [471 '48 3B FF ; FLUTE, NERGAL',472 '14 3D FF ; SKULL, CROM',473 '51 2A FF ; TALISMAN, POWERRING',474 ]475 },476 0x1C: {477 name : 'NYMPH',478 items : [479 '49 2C FF ; MUSHROOM, TRUTHRING',480 '41 0A FF ; FOOD, PENDANT',481 '48 39 FF ; FLUTE, OKKAN',482 ]483 },484 0x19 : {485 name : 'SPRITE',486 items : [487 '54 2A FF ; SKULL, POWERRING',488 '41 3B FF ; FOOD, NERGAL',489 '43 3A FF ; DAGGER, AKHIROM',490 ]491 },492 0x06: {493 name : 'SWORD',494 items : [495 '18 FF ; ROPE',496 '38 FF ; MITRA',497 '0E FF ; PARCHMENT',498 ]499 },500 0x0F: {501 name : 'VIAL',502 items : [503 '09 77 FF ; MUSHROOM, VETAR',504 '0E 38 FF ; PARCHMENT, MITRA',505 '11 38 FF ; TALISMAN, MITRA',506 ]507 },508 0x07: {509 name : 'SHIELD',510 items : [511 '06 FF ; SWORD',512 '04 FF ; MACE',513 '03 FF ; DAGGER',514 ]515 },516 0x14: {517 name : 'SKULL',518 items : [519 '11 0A FF ; TALISMAN, PENDANT',520 '39 FF ; OKKAN',521 '0B FF ; SCEPTER',522 ]523 },524 0x2A: {525 name : 'POWERRING',526 items : [527 '7C FF ; BELROG',528 '07 0B 0E 79 FF ; SHIELD, SCEPTER, PARCHMENT, OKKAN',529 '07 04 14 78 FF ; SHIELD, MACE, SKULL, MITRA',530 '07 06 7A F ; SHIELD, SWORD, AKHIROM',531 ]532 },533 0x2B: {534 name : 'LIGHTRING',535 items : [536 '2A 7D 11 FF ; POWERRING, CROM, TALISMAN',537 '2A 05 39 FF ; POWERRING, AX, OKKAN',538 '2A 18 7B FF ; POWERRING, ROPE, NERGAL',539 ]540 },541 0x2C: {542 name : 'TRUTHRING',543 items : [544 '2B 7D 0D FF ; LIGHTRING, CROM, BASKET',545 '2B 05 39 FF ; LIGHTRING, AX, OKKAN',546 '2B 08 7A FF ; LIGHTRING, FLUTE, AKHIROM',547 ]548 },549 0x23: {550 name : 'SPELLBOOK',551 items : [552 '14 08 FF ; SKULL, FLUTE',553 '0A 7D FF ; PENDANT, CROM',554 '09 13 7C FF ; MUSHROOM, GOBLET, BELROG',555 '2A 7B FF ; POWERRING, NERGAL',556 ]557 }558}559560function viewSaveFile(data) {561 562 // Reset from last viewing (if any)563 for(var i=0;i<8;++i) {564 SPELL_INFO[i].room = -1; 565 SPELL_INFO[i].learned = false;566 } 567 // Reset jump568 JUMPS[24][0] = -1;569 // Reset current and last room570 PLAYER = -1;571 LAST_ROOM = -1;572 // Reset objects573 OBJECTS = [];574 575 saveGameData = atob(data);576 577 if(saveGameData.length>0) {578 // Read the SPELL information579 for(i=0;i<8;++i) {580 SPELL_INFO[i].room = readBinaryData(0x3BC1+4*i+2); 581 if(readBinaryData(0x3BC1+4*i+3)!=0) { 582 SPELL_INFO[i].learned = true;583 }584 }585 // The random jump (last in the list)586 JUMPS[24][0] = readBinaryData(0x3C59);587 // Player588 PLAYER = readBinaryData(0);589 LAST_ROOM = readBinaryData(1);590 // Objects591 for(var x=0;x<OBJECT_NAMES.length;++x) {592 var co = {'name' : OBJECT_NAMES[x]};593 OBJECTS.push(co);594 co['room'] = readBinaryData(0x3CFC+x*3+0);595 var bits = readBinaryData(0x3CFC+x*3+2);596 co['in_pack'] = (bits&0x80)!=0;597 co['spell_creature'] = (bits&0x40)!=0;598 co['required'] = (bits&0x20)!=0;599 co['protected'] = (bits&0x10)!=0;600 co['fill_status'] = (bits>>2)&3;601 co['dead_creature'] = (bits&0x2)!=0;602 co['accessible'] = (bits&0x1)==0; 603 }604 $('#rawData').show();605 606 // Template for the raw data607 var rawt = $('#rawData').html().split('\n');608 609 // Fill out the engine memory (1 or 2 bytes)610 i = findRawTextLine(rawt,'0000',0);611 j = findRawTextLine(rawt,'0340',i);612 while(i!=j) {613 g = rawt[i];614 if(g[0]!='0') {615 ++i;616 continue;617 }618 p = parseInt(g.substring(0,4),16);619 a = readBinaryData(p);620 b = readBinaryData(p+1); 621 k = getReplaceTarget(g);622 if(k=='value1') {623 g = doReplaceTarget(g,k,hexPad(a,2));624 if(p<0xFF) {625 g = doReplaceTarget(g,'value2',hexPad(b,2));626 }627 if(a>127) {628 a = a -256;629 }630 a = a + 128;631 a = ''+a;632 while(a.length<3) a=a+' ';633 g = doReplaceTarget(g,'decode','Room '+a); 634 } else {635 // Must be mvalue_NN636 m = k.indexOf('_');637 z = parseInt(k.substring(m+1));638 s = '';639 while(z>0) {640 s = s + hexPad(readBinaryData(p),2)+' ';641 ++p;642 --z;643 }644 g = doReplaceTarget(g,k,s)645 }646 647 rawt[i] = g;648 ++i;649 }650 651 // Saved screen652 i = findRawTextLine(rawt,'0340',0);653 j = findRawTextLine(rawt,'3BC1',i);654 655 while(i!=j) {656 g = rawt[i];657 if(g[0]!='0') {658 ++i;659 continue;660 }661 p = parseInt(g.substring(0,4),16); 662 663 s = '';664 t = '';665 for(x=0;x<32;++x) {666 s = s + hexPad(readBinaryData(p+x),2)+' ';667 t = t + CHARMAP[readBinaryData(p+x)];668 }669 670 g = doReplaceTarget(g,'value',s);671 rawt[i] = doReplaceTarget(g,'decode',t);672 ++i;673 }674 675 // Spells676 p = 0x3BC1;677 for(j=0;j<8;++j) {678 g = rawt[i];679 a = readBinaryData(p+2);680 b = readBinaryData(p+3);681 g = doReplaceTarget(g,'value1',hexPad(a,2));682 g = doReplaceTarget(g,'value2',hexPad(b,2));683 dec = 'Room '+a+' ';684 if(b==0) {685 dec = dec + '(unlearned)';686 } else {687 dec = dec + '(LEARNED)';688 }689 rawt[i] = doReplaceTarget(g,'decode',dec);690 ++i;691 p = p + 4;692 }693 694 // Jump info695 i = findRawTextLine(rawt,'3C59',i);696 g = rawt[i];697 a = readBinaryData(0x3C59); 698 rn = ""+a;699 while(rn.length<3) rn=rn+' ';700 701 g = doReplaceTarget(g,'value',hexPad(a,2));702 rawt[i] = doReplaceTarget(g,'decode',rn);703 704 // Who holds what705 i = findRawTextLine(rawt,'3C6F',i);706 p = 0x3C6F;707 for(j=0;j<16;++j) {708 g = rawt[i];709 a = readBinaryData(p);710 g = doReplaceTarget(g,'value',hexPad(a,2)); 711 g = doReplaceTarget(g,'decode', NAMETABLE[a]);712 rawt[i] = g;713 ++i;714 p = p + 2;715 } 716 717 // Enter Room Actions718 i = findRawTextLine(rawt,'3C8F',i);719 j = findRawTextLine(rawt,'3CFB',i);720 721 while(i!=j) {722 g = rawt[i];723 if(g[0]!='3') {724 ++i;725 continue;726 }727 p = parseInt(g.substring(0,4),16);728 729 a = readBinaryData(p);730 g = doReplaceTarget(g,'value',hexPad(a,2));731 rn = ''+a;732 while(rn.length<3) rn=rn+' ';733 rawt[i] = doReplaceTarget(g,'decode',rn);734 ++i; 735 }736 737 // Objects738 i = findRawTextLine(rawt,'3CFC',i);739 j = findRawTextLine(rawt,'3DB6',i); 740 while(i!=j) {741 g = rawt[i];742 if(g[0]!='3') {743 ++i;744 continue;745 }746 p = parseInt(g.substring(0,4),16);747 748 a = readBinaryData(p);749 b = readBinaryData(p+2); 750 751 rn = ''+a;752 753 dec = 'Room '+rn;754 if((b&0x80)>0) {755 dec = dec + ', in backpack';756 } 757 if((b&0x40)>0) {758 dec = dec + ', spell or creature';759 } 760 if((b&0x20)>0) {761 dec = dec + ', required';762 } 763 if((b&0x10)>0) {764 dec = dec + ', protected';765 } 766 dec = dec + ', fill status '+((b>>2)&3);767 if((b&0x2)>0) {768 dec = dec + ', spell or dead creature';769 } 770 if((b&0x1)>0) {771 dec = dec + ', carried object or creature';772 } 773 774 g = doReplaceTarget(g,'value1',hexPad(a,2));775 g = doReplaceTarget(g,'value2',hexPad(b,2));776 777 rawt[i] = doReplaceTarget(g,'decode',dec); 778 ++i; 779 }780 781 // Blocked passages782 i = findRawTextLine(rawt,'3EB8',i);783 j = findRawTextLine(rawt,'3FB8',i); 784 while(i!=j) {785 g = rawt[i];786 if(g[0]!='3') {787 ++i;788 continue;789 }790 p = parseInt(g.substring(0,4),16);791 792 s = '';793 t = '';794 for(x=0;x<8;++x) {795 a = readBinaryData(p+x);796 s = s + hexPad(a,2)+' ';797 if((a&32)>0) {t=t+'U';} else {t=t+'.';}798 if((a&16)>0) {t=t+'D';} else {t=t+'.';}799 if((a&8)>0) {t=t+'N';} else {t=t+'.';}800 if((a&4)>0) {t=t+'E';} else {t=t+'.';}801 if((a&2)>0) {t=t+'W';} else {t=t+'.';}802 if((a&1)>0) {t=t+'S';} else {t=t+'.';}803 t = t + ' ';804 }805 806 rawt[i] = doReplaceTarget(g,'mvalue',s+'; '+t);807 ++i;808 }809 810 // Protection lists811 g = rawt.pop(); 812 rawt.pop(); // The placeholder address 3FB8:813 814 p = 0x3FB8; 815 for(x=0;x<14;++x) {816 u = hexPad(p,4)+': '817 b = readBinaryData(p++);818 u = u + hexPad(b,2);819 while(u.length<22) u = u +' '; 820 ob = PROTECTIONS[b];821 u = u + '; '+ob.name;822 if(x==0) u = '<span class="sg_value">'+ u;823 rawt.push(u);824 s = '';825 u = hexPad(p,4)+': ';826 while(true) {827 a = readBinaryData(p++);828 s = s + hexPad(a,2)+' ';829 if(a==0xFF) break;830 }831 u=u+s;832 for(y=0;y<ob.items.length;++y) {833 if(ob.items[y].startsWith(s)) {834 s = ob.items[y];835 break;836 }837 }838 while(u.length<22) u=u+' ';839 z = s.indexOf(';');840 u = u + '; ' + s.substring(z+1);841 rawt.push(u);842 }843 844 rawt.push(hexPad(p++,4)+': FF')845 846 if(p!=0x4000) {847 rawt.push('; Unused');848 u = hexPad(p,4)+':';849 while(p<0x4000) u = u + ' ' + hexPad(readBinaryData(p++),2);850 rawt.push(u);851 }852 853 rawt.push('<\span>');854 rawt.push(g);855 856 // Write the data857 g ='';858 for(i=0;i<rawt.length;++i) {859 g = g + rawt[i]+'\n';860 }861 $('#rawData').html(g);862 863 } else {864 $('#rawData').hide();865 } 866 867 // Fix scrolling for the map868 $('.content div').css('overflow','unset');869 870 var g = '<g transform="scale(0.70)">';871 var rn;872 var fn;873 var x,y,color;874 875 876 for(rn=0;rn<256;++rn) {877 fn = ~~(rn / 64);878 x = (rn%64)%8;879 y = ~~((rn%64)/8);880 881 subs = {882 x:(150+75)*x+100,883 y:(150+75)*y+100+2000*fn,884 description:ROOM_DESC[rn],885 room:rn,886 room_color: '#EEE',887 enter:'',888 enter_fill: 'red',889 up:'',890 down:'',891 monsters: '',892 jump_color:'black',893 jump:'',894 spell_fill: 'none', // 'green'895 spell: '',896 oracle_fill: 'none', // 'blue'897 oracle: '', // 'Oracle'898 objects:'',899 E_color: 'none',900 W_color: 'none',901 N_color: 'none',902 S_color: 'none',903 U_room: '',904 D_room: '',905 E_room: '',906 W_room: '',907 N_room : '',908 S_room : '',909 U_action : '',910 D_action : '',911 N_action : '',912 S_action : '', 913 E_action : '',914 W_action : '',915 block_1 : 'none',916 block_2 : 'none',917 block_up_fill : 'none',918 block_down_fill : 'none',919 block_north_fill : 'none',920 block_south_fill : 'none',921 block_east_fill : 'none',922 block_west_fill : 'none',923 }924 925 // Maze rooms colored differently926 if(ROOM_DESC[rn] == 'MAZE') {927 subs['room_color'] = '#CCC';928 }929 930 // Jumps931 var jump = getJump(rn);932 subs['jump'] = jump;933 if(jump==JUMPS[24]) {934 subs['jump_color'] = 'red';935 }936 937 // Passages and passage-actions938 var doors = getRoomDoors(rn); 939 var dirs = 'UDNEWS'; 940 for(var i=0;i<dirs.length;++i) {941 var c = dirs[i];942 var ndn = getNeighborRoomNumber(rn,c);943 var action = getBetweenRoomAction(rn,c);944 if( (c=='U' || c=='D')) {945 // Up and Down actions need a colon946 if(action!='') {947 action = ':'+action;948 }949 //if(ndn!='') {950 if(c=='U') {951 ndn = 'Up:'+ndn;952 } else {953 ndn = 'Down:'+ndn;954 }955 //}956 } 957 if(doors.indexOf(c)>=0) { 958 subs[c+'_action'] = action;959 if(c=='U' || c=='D' || isEdge(rn,c)) {960 subs[c+'_room'] = ndn;961 }962 subs[c+'_color'] = 'black'; 963 } 964 }965 966 // Spells967 subs['spell'] = truncList(getSpell(rn));968 if(subs['spell']!='') {969 subs['spell_fill'] = 'green';970 }971 972 // Player and last room (might be the same)973 if(rn==LAST_ROOM) {974 subs['room_color'] = '#EFE';975 }976 if(rn==PLAYER) {977 subs['room_color'] = '#CFC';978 }979 980 // Objects981 subs['objects'] = truncList(getObjectsInRoom(rn));982 983 // Monsters984 subs['monsters'] = truncList(getMonstersInRoom(rn));985 986 // Oracle987 if(isOracleInRoom(rn)) {988 subs['oracle'] = 'Oracle';989 subs['oracle_fill'] = 'blue';990 } 991 992 // Enter room actions 993 if(rn==213 || rn==32 || rn==33 || rn==203 || rn==232) {994 // These are fixed ... every game the same995 subs['enter_fill'] = 'black';996 }997 subs['enter'] = truncList(getEnterRoomAction(rn));998 999 // Blocked passages1000 1001 var bits = readBinaryData(0x3EB8+rn);1002 if(bits&0x20) subs['block_up_fill'] = '#FCC';1003 if(bits&0x10) subs['block_down_fill'] = '#FCC';1004 if(bits&0x08) subs['block_north_fill'] = '#FCC';1005 if(bits&0x04) subs['block_east_fill'] = '#FCC';1006 if(bits&0x02) subs['block_west_fill'] = '#FCC';1007 if(bits&0x01) subs['block_south_fill'] = '#FCC';1008 1009 // TODO data breakdown after map (put it in the HTML but hidden ... fill out and show) 1010 // TODO ability to pass in file in URL1011 1012 g = g + sub(GRAPHICS,subs); 1013 1014 }1015 ...

Full Screen

Full Screen

SFInputStreamBinary2.js

Source:SFInputStreamBinary2.js Github

copy

Full Screen

12function SFInputStreamBinary(buffer) {3 this.buffer = buffer;4 this.pos = 0;5 6};78 9SFInputStreamBinary.prototype["_getInt8"]=function(){10 var b = this._getByte(this.pos);11 return b > Math.pow(2, 7) - 1 ? b - Math.pow(2, 8) : b;12 };1314SFInputStreamBinary.prototype["_getByte"]=function(){15 var byte=this.buffer.charCodeAt(this.pos) & 0xff;16 this.pos++;17 return byte;18 };19 20SFInputStreamBinary.prototype["readString"]=function(){21 var length = this._getInt8();22 var value = '';23 for (var i = 0; i < length; ++i) {24 var char = this._getByte(this.pos);25 value += String.fromCharCode(char > 127 ? 65533 : char);26 }27 //alert("readString "+value);28 29 return value;30 };31 32SFInputStreamBinary.prototype["readName"]=function(){33 return this.readString();34 };3536SFInputStreamBinary.prototype["readByte"]=function(){37 var b_byte=this._getByte();38 //alert("readByte "+b_byte);39 return b_byte;40 };41 42SFInputStreamBinary.prototype["readShort"]=function(){43 var b1 = this._getByte(this.pos+0),44 b0 = this._getByte(this.pos+1);45 var b= (b1 << 8) + b0;46 var _short= b > Math.pow(2, 15) - 1 ? b - Math.pow(2, 16) : b;47 //alert("readShort "+_short);48 return _short;49 };505152SFInputStreamBinary.prototype["readInt"]=function(){53 var b3 = this._getByte(this.pos+0),54 b2 = this._getByte(this.pos+1),55 b1 = this._getByte(this.pos+2),56 b0 = this._getByte(this.pos+3);57 var b = (b3 * Math.pow(2, 24)) + (b2 << 16) + (b1 << 8) + b0;58 var _int= b > Math.pow(2, 31) - 1 ? b - Math.pow(2, 32) : b;59 //alert("readInt "+_int);60 return _int;61 };626364SFInputStreamBinary.prototype["readFloat"]=function(){65 var b0 = this._getByte(this.pos+0),66 b1 = this._getByte(this.pos+1),67 b2 = this._getByte(this.pos+2),68 b3 = this._getByte(this.pos+3),69 70 sign = 1 - (2 * (b0 >> 7)),71 exponent = (((b0 << 1) & 0xff) | (b1 >> 7)) - 127,72 mantissa = ((b1 & 0x7f) << 16) | (b2 << 8) | b3;73 74 if (exponent === 128) {75 if (mantissa !== 0) {76 return NaN;77 } else {78 return sign * Infinity;79 }80 }81 82 if (exponent === -127) { // Denormalized83 return sign * mantissa * Math.pow(2, -126 - 23);84 }85 86 return sign * (1 + mantissa * Math.pow(2, -23)) * Math.pow(2, exponent);87 };888990SFInputStreamBinary.prototype["readShorts"]=function(n){91 var array=new Array();92 for(var i=0;i<n;i++){93 array[i]=this.readShort();94 }95 return array;96 };9798SFInputStreamBinary.prototype["readInts"]=function(n){99 var array=new Array();100 for(var i=0;i<n;i++){101 array[i]=this.readInt();102 }103 return array;104 };105 106SFInputStreamBinary.prototype["readFloats"]=function(n){107 var array=new Array();108 for(var i=0;i<n;i++){109 array[i]=this.readFloat();110 }111 return array;112 };113 114SFInputStreamBinary.prototype["readBytes"]=function(n){115 var array=new Array();116 for(var i=0;i<n;i++){117 array[i]=this._getByte();118 }119 return array;120 };121122SFInputStreamBinary.prototype["readBinaryDataValue"]=function(bitSize){123 var byteSize = ((bitSize - 1) >> 3) + 1;124 125 var bytes = this.readBytes(byteSize);126 127 var value = 0;128 for (var j = 0; j < byteSize; j++) {129 var byteValue = bytes[ j];130 value += ((byteValue >= 0 ? byteValue : 256 + byteValue) << (8 * j));// is131 }132 133 //alert("readBinaryData "+bytes+" , value "+value);134 return value;135 };136 137SFInputStreamBinary.prototype["readBinaryData"]=function(n,bitSize){138 var byteSize = ((bitSize - 1) >> 3) + 1;139 var bytes = this.readBytes(n * byteSize);140 var data = new Array();141 142 for (var i = 0; i < n; i++) {143 var value = 0;144 for (var j = 0; j < byteSize; j++) {145 //read Bytes will extract positive values...146 //value += bytes[i * byteSize + j];147 var byteValue = bytes[i * byteSize + j];148 value += ((byteValue >= 0 ? byteValue : 256 + byteValue) << (8 * j));// is149 }150 data[i] = value;151 }152 153 //alert("readBinaryData (bytes )"+bytes);154 //alert("readBinaryData ("+n+","+bitSize+","+byteSize+")"+data);155 156 return data;157 };158 ...

Full Screen

Full Screen

parse-lidar-points.js

Source:parse-lidar-points.js Github

copy

Full Screen

...15 * Parse LiDar data (stored in velodyne_points dir),16 */17import {Parser as BinaryParser} from 'binary-parser';18const parser = new BinaryParser().floatle();19function readBinaryData(binary) {20 const res = [];21 for (let i = 0; i < binary.length; i = i + 4) {22 if (i + 4 > binary.length) {23 break;24 }25 const parsed = parser.parse(binary.slice(i, i + 4));26 res.push(parsed);27 }28 return res;29}30export function loadLidarData(data) {31 const binary = readBinaryData(data);32 const float = new Float32Array(binary);33 const size = Math.round(binary.length / 4);34 // We could return interleaved buffers, no conversion!35 const positions = new Array(size);36 const colors = new Array(size);37 for (let i = 0; i < size; i++) {38 positions[i] = float.subarray(i * 4, i * 4 + 3);39 const reflectance = Math.min(float[i * 4 + 3], 3);40 colors[i] = [80 + reflectance * 80, reflectance * 80, reflectance * 60];41 }42 return {positions, colors};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var pact = require('pact-foundation-pact-mock-service');2pact.readBinaryData('test2.txt', function(err, data) {3 if(err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var pact = require('pact-foundation-pact-mock-service');10pact.readBinaryData('test3.txt', function(err, data) {11 if(err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var pact = require('pact-foundation-pact-mock-service');18pact.readBinaryData('test4.txt', function(err, data) {19 if(err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var pact = require('pact-foundation-pact-mock-service');26pact.readBinaryData('test5.txt', function(err, data) {27 if(err) {28 console.log(err);29 } else {30 console.log(data);31 }32});

Full Screen

Using AI Code Generation

copy

Full Screen

1var pact = require('pact-foundation/pact-node');2var fs = require('fs');3var pactFile = pact.readBinaryData('test.pact');4fs.writeFile('test2.pact', pactFile, function(err) {5 if(err) {6 return console.log(err);7 }8 console.log("The file was saved!");9});10{"consumer":{"name":"Consumer"},"provider":{"name":"Provider"},"interactions":[{"description":"a request to retrieve a list of users","provider_state":"there are some users","request":{"method":"GET","path":"/users"},"response":{"status":200,"body":[{"id":1,"name":"John"},{"id":2,"name":"Paul"}]}}],"metadata":{"pactSpecification":{"version":"2.0.0"}}}11var fs = require('fs');12fs.writeFileSync('test2.pact', pact.readBinaryData('test.pact'));

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pact-foundation-pact automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful