1 var SCREEN_WIDTH = 320;
\r
2 var SCREEN_HEIGHT = 400;
\r
3 var FRAME_BUFFER_WIDTH = 384;
\r
4 var FRAME_BUFFER_HEIGHT = 400;
\r
6 var COLOURS_PER_ENTRY = 3;
\r
7 var DPII = (3.1415926535*2.0);
\r
10 var g_au8FrameBuffer = new Uint8Array(FRAME_BUFFER_WIDTH * FRAME_BUFFER_HEIGHT);
\r
11 var s_abSelectedPlanes = [ false, false, false, false ];
\r
12 var s_nLineCompareY = 0;
\r
13 var s_nHorizontalScrollOffset = 0;
\r
14 var s_au8Palette = new Uint8Array(256 * COLOURS_PER_ENTRY);
\r
15 var frame_count = 0;
\r
22 var dtau = new Array();
\r
23 var fadepal = new Uint8Array(768 * 2);
\r
24 var cop_fadepal_SelectedPaletteIndex = 0;
\r
25 var anSelfModifyOffsets = new Uint16Array(5 * 84);
\r
27 // [NK 8/1/2014] The assembly code assumes the tables are sequential in memory,
\r
28 // [NK 8/1/2014] so merge them into one array to be safe.
\r
29 var psini = new Uint8Array(16384 + (8192 * 2) + (8192 * 2));
\r
30 var psini_DataView = new DataView(psini.buffer);
\r
31 var ptau = new Uint8Array(256);
\r
32 var pals = new Uint16Array(6 * 768);
\r
33 var pals_DataView = new DataView(pals.buffer);
\r
36 var timetable=[64*6*2-45,64*6*4-45,64*6*5-45,64*6*6-45,64*6*7+90,0];
\r
39 var l1=1000, l2=2000, l3=3000, l4=4000;
\r
40 var k1=3500, k2=2300, k3=3900, k4=3670;
\r
42 var il1=1000, il2=2000, il3=3000, il4=4000;
\r
43 var ik1=3500, ik2=2300, ik3=3900, ik4=3670;
\r
45 var inittable = new Array();
\r
46 var IsComplete = false;
\r
48 //--------------------------------------------------------------------------------------
\r
49 // Variable wrappers
\r
51 function Palette_WriteByte(nOffset, u8Byte)
\r
53 s_au8Palette[nOffset] = u8Byte;
\r
56 function Palette_ReadByte(nOffset)
\r
58 return s_au8Palette[nOffset];
\r
61 function FrameBuffer_WriteByte(nOffset, u8Byte)
\r
63 g_au8FrameBuffer[nOffset] = u8Byte;
\r
66 function FrameBuffer_ReadByte(nOffset)
\r
68 return g_au8FrameBuffer[nOffset];
\r
71 function lsini16_GetOffset()
\r
73 return 16384 + (8192 * 2);
\r
76 function lsini4_GetOffset()
\r
81 function cop_fadepal_SetSelectedPaletteIndex(nIndex)
\r
83 cop_fadepal_SelectedPaletteIndex = nIndex;
\r
86 function cop_fadepal_ReadWord(nByteOffset)
\r
88 // Advance to the currently selected palette.
\r
89 nByteOffset += (cop_fadepal_SelectedPaletteIndex * 768 * 2);
\r
91 return pals_DataView.getUint16(nByteOffset);
\r
94 function fadepal_ReadByte(nByteOffset)
\r
96 return fadepal[nByteOffset];
\r
99 function fadepal_WriteByte(nByteOffset, nValue)
\r
101 fadepal[nByteOffset] = nValue;
\r
104 function lsini4_WriteWord(nIndex, nValue)
\r
106 var nByteOffset = lsini4_GetOffset() + (nIndex * 2);
\r
107 psini_WriteWord(nByteOffset, nValue);
\r
110 function lsini16_WriteWord(nIndex, nValue)
\r
112 var nByteOffset = lsini16_GetOffset() + (nIndex * 2);
\r
113 psini_WriteWord(nByteOffset, nValue);
\r
116 function psini_WriteByte(nIndex, nValue)
\r
118 psini[nIndex] = nValue;
\r
121 function psini_ReadByte(nIndex, nValue)
\r
123 return psini[nIndex];
\r
126 function psini_WriteWord(nByteOffset, nValue) {
\r
127 psini_DataView.setUint16(nByteOffset, nValue);
\r
130 function psini_ReadWord(nByteOffset, nValue) {
\r
131 return psini_DataView.getUint16(nByteOffset);
\r
134 function ptau_WriteByte(nIndex, nValue)
\r
136 ptau[nIndex] = nValue;
\r
139 function ptau_ReadByte(nIndex)
\r
141 return ptau[nIndex];
\r
144 function pal_WriteWord(nByteOffset, nWord)
\r
146 pals_DataView.setUint16(nByteOffset, nWord);
\r
149 function pal_ReadWord(nByteOffset)
\r
151 return pals_DataView.getUint16(nByteOffset);
\r
154 function fadepal_Clear()
\r
156 for (var i = 0; i < 768; i++)
\r
162 function fadepal_ClearToWhite() {
\r
163 for (var i = 0; i < 768; i++) {
\r
168 function anSelfModifyOffsets_ReadWord(nOffset)
\r
170 return anSelfModifyOffsets[nOffset];
\r
173 function anSelfModifyOffsets_WriteWord(nOffset, nValue)
\r
175 anSelfModifyOffsets[nOffset] = nValue;
\r
178 //--------------------------------------------------------------------------------------
\r
181 function SDL_SetPixel(x, y, color)
\r
183 var pixels = image.data;
\r
184 var nOffset = (((y * 320) + x) * 4);
\r
185 pixels[nOffset] = (color >> 0) & 0xFF;
\r
187 pixels[nOffset] = (color >> 8) & 0xFF;
\r
189 pixels[nOffset] = (color >> 16) & 0xFF;
\r
191 pixels[nOffset] = 0xFF;
\r
195 function SDL_SetPixelColours(x, y, nRed, nGreen, nBlue)
\r
197 var pixels = image.data;
\r
198 var nOffset = (((y * 320) + x) * 4);
\r
199 pixels[nOffset] = (nRed) & 0xFF;
\r
201 pixels[nOffset] = (nGreen) & 0xFF;
\r
203 pixels[nOffset] = (nBlue) & 0xFF;
\r
205 pixels[nOffset] = 0xFF;
\r
209 //--------------------------------------------------------------------------------------
\r
212 function VGA_SelectBitPlanes02()
\r
214 s_abSelectedPlanes[0] = true;
\r
215 s_abSelectedPlanes[1] = false;
\r
216 s_abSelectedPlanes[2] = true;
\r
217 s_abSelectedPlanes[3] = false;
\r
220 function VGA_SelectBitPlanes13()
\r
222 s_abSelectedPlanes[0] = false;
\r
223 s_abSelectedPlanes[1] = true;
\r
224 s_abSelectedPlanes[2] = false;
\r
225 s_abSelectedPlanes[3] = true;
\r
228 function VGA_SelectBitPlanes0123()
\r
230 s_abSelectedPlanes[0] = true;
\r
231 s_abSelectedPlanes[1] = true;
\r
232 s_abSelectedPlanes[2] = true;
\r
233 s_abSelectedPlanes[3] = true;
\r
236 function VGA_WriteDword(nOffset, uValue)
\r
238 // For each selected plane, calculate 4 pixel offsets and write 4 bytes.
\r
239 // nOffset = 0, 4, 8, etc
\r
241 for (var nPlaneIndex = 0; nPlaneIndex < PLANE_COUNT; nPlaneIndex++)
\r
243 if (s_abSelectedPlanes[nPlaneIndex])
\r
245 for (var nPixelIndex = 0; nPixelIndex < 4; nPixelIndex++)
\r
247 // Get byte to write.
\r
248 var u8Byte = (uValue >> (nPixelIndex * 8)) & 0xFF;
\r
250 // Calculate offset.
\r
251 var nFrameBufferOffset = nPlaneIndex + (nOffset * 4) + (nPixelIndex * 4);
\r
254 FrameBuffer_WriteByte(nFrameBufferOffset, u8Byte);
\r
260 function VGA_SetLineCompare(nY)
\r
262 s_nLineCompareY = nY;
\r
265 function VGA_SetPaletteEntry(nIndex, u8Red, u8Green, u8Blue)
\r
269 nOffset = (nIndex * 3) + 0;
\r
270 Palette_WriteByte(nOffset, u8Red);
\r
272 nOffset = (nIndex * 3) + 1;
\r
273 Palette_WriteByte(nOffset, u8Green);
\r
275 nOffset = (nIndex * 3) + 2;
\r
276 Palette_WriteByte(nOffset, u8Blue);
\r
279 function VGA_ShowFrameBuffer()
\r
284 var nFirstLineIndex = (s_nLineCompareY + 1);
\r
286 // Plot the palettised frame buffer.
\r
287 var nFrameBufferOffset = 0;
\r
289 for (var nY = nFirstLineIndex; nY < SCREEN_HEIGHT; nY++)
\r
291 for (var nX = 0; nX < SCREEN_WIDTH; nX++)
\r
293 //ASSERT(nX + s_nHorizontalScrollOffset < FRAME_BUFFER_WIDTH);
\r
294 var nPaletteIndex = FrameBuffer_ReadByte(nFrameBufferOffset + nX + s_nHorizontalScrollOffset);
\r
296 var nPaletteOffset = 0;
\r
297 nPaletteOffset = (nPaletteIndex * 3) + 0;
\r
298 var nRed = Palette_ReadByte(nPaletteOffset);
\r
299 nPaletteOffset = (nPaletteIndex * 3) + 1;
\r
300 var nGreen = Palette_ReadByte(nPaletteOffset);
\r
301 nPaletteOffset = (nPaletteIndex * 3) + 2;
\r
302 var nBlue = Palette_ReadByte(nPaletteOffset);
\r
304 // [NK 12/1/2014] VGA colours range from 0 - 63 inclusive, but
\r
305 // [NK 12/1/2014] SDL colours range from 0 - 255 inclusive, so
\r
306 // [NK 12/1/2014] account for this here.
\r
318 SDL_SetPixelColours(nX, nY, nRed, nGreen, nBlue);
\r
321 nFrameBufferOffset += FRAME_BUFFER_WIDTH;
\r
325 function VGA_SetHorizontalScrollOffset(nOffset)
\r
327 s_nHorizontalScrollOffset = nOffset;
\r
330 function VGA_UploadPalette(Palette)
\r
332 var Source = new Uint8Array(Palette.buffer, 0, 768);
\r
333 var Destination = s_au8Palette;
\r
334 Destination.set(Source);
\r
337 //--------------------------------------------------------------------------------------
\r
340 function tw_setrgbpalette(pal, r, g, b)
\r
342 VGA_SetPaletteEntry(pal, r, g, b);
\r
345 //--------------------------------------------------------------------------------------
\r
348 function plzline(y, vseg)
\r
350 // vseg represented a segment, so multiply by sixteen (shift left by 4)
\r
351 // to convert into an offset.
\r
352 var nVgaYOffset = vseg * 16;
\r
356 3,2,1,0,7,6,5,4,11,10,9,8,15,14,13,12,19,18,17,16,23,22,21,20,27,26,25,24,31,30,29,28,35,34,33,32,39,38,37,36,43,42,41,40,47,46,45,44,51,50,49,48,55,54,53,52,59,58,57,56,63,62,61,60,67,66,65,64,71,70,69,68,75,74,73,72,79,78,77,76,83,82,81,80
\r
364 for (var nIndex = 0; nIndex < nCount; nIndex++)
\r
366 var ccc = cccTable[nIndex];
\r
368 if ((ccc & 1) == 1)
\r
370 var nByteOffset = 0;
\r
373 nByteOffset = (y * 2) + anSelfModifyOffsets_ReadWord((2 * 84) + ccc);
\r
374 nByteOffset &= 0xFFFF;
\r
375 bx = psini_ReadWord(nByteOffset);
\r
377 nByteOffset = bx + anSelfModifyOffsets_ReadWord((1 * 84) + ccc);
\r
378 nByteOffset &= 0xFFFF;
\r
379 ah = psini_ReadByte(nByteOffset);
\r
381 nByteOffset = (y * 2) + anSelfModifyOffsets_ReadWord((4 * 84) + ccc);
\r
382 nByteOffset &= 0xFFFF;
\r
383 bx = psini_ReadWord(nByteOffset);
\r
385 nByteOffset = bx + (y * 2) + anSelfModifyOffsets_ReadWord((3 * 84) + ccc);
\r
386 nByteOffset &= 0xFFFF;
\r
387 ah += psini_ReadByte(nByteOffset);
\r
392 var nByteOffset = 0;
\r
395 nByteOffset = (y * 2) + anSelfModifyOffsets_ReadWord((2 * 84) + ccc);
\r
396 nByteOffset &= 0xFFFF;
\r
397 bx = psini_ReadWord(nByteOffset);
\r
399 nByteOffset = bx + anSelfModifyOffsets_ReadWord((1 * 84) + ccc);
\r
400 nByteOffset &= 0xFFFF;
\r
401 al = psini_ReadByte(nByteOffset);
\r
403 nByteOffset = (y * 2) + anSelfModifyOffsets_ReadWord((4 * 84) + ccc);
\r
404 nByteOffset &= 0xFFFF;
\r
405 bx = psini_ReadWord(nByteOffset);
\r
407 nByteOffset = bx + (y * 2) + anSelfModifyOffsets_ReadWord((3 * 84) + ccc);
\r
408 nByteOffset &= 0xFFFF;
\r
409 al += psini_ReadByte(nByteOffset);
\r
413 if ((ccc & 3) == 2)
\r
415 eax = (ah << 8) | (al << 0);
\r
419 if ((ccc & 3) == 0)
\r
421 eax |= (ah << 8) | (al << 0);
\r
423 VGA_WriteDword(nVgaYOffset + ccc, eax);
\r
430 function setplzparas(c1, c2, c3, c4)
\r
432 var psiniOffset = 0;
\r
433 var lsini16Offset = lsini16_GetOffset();
\r
434 var lsini4Offset = lsini4_GetOffset();
\r
436 for (var ccc = 0; ccc < 84; ccc++)
\r
438 var lc1 = c1 + psiniOffset + (ccc * 8);
\r
440 anSelfModifyOffsets_WriteWord((1 * 84) + ccc, lc1);
\r
442 var lc2 = (c2 * 2) + lsini16Offset - (ccc * 8) + (80 * 8);
\r
444 anSelfModifyOffsets_WriteWord((2 * 84) + ccc, lc2);
\r
446 var lc3 = c3 + psiniOffset - (ccc * 4) + (80 * 4);
\r
448 anSelfModifyOffsets_WriteWord((3 * 84) + ccc, lc3);
\r
450 var lc4 = (c4 * 2) + lsini4Offset + (ccc * 32);
\r
452 anSelfModifyOffsets_WriteWord((4 * 84) + ccc, lc4);
\r
458 function set_plzstart(start)
\r
460 VGA_SetLineCompare(start);
\r
466 //--------------------------------------------------------------------------------------
\r
469 function init_copper()
\r
471 for (var ccc = 0; ccc < 65; ccc++)
\r
473 dtau[ccc] = Math.floor(ccc * ccc / 4 * 43 / 128 + 60);
\r
479 function close_copper()
\r
484 function pompota() {
\r
486 // [NK 18/1/2014] Disable this for now, as it looks a bit jittery.
\r
489 // [nk] This function toggles the horizontal split point every frame
\r
490 // [nk] between line 60 and 61, along with the horizontal offset.
\r
491 // [nk] (since set_plzstart == 60, it's splitting at the top of the plasma)
\r
492 VGA_SetLineCompare(60);
\r
497 if ((pompi & 1) != 0)
\r
499 // [NK 12/1/2014] Moving the starting line up and down each alternate frame
\r
500 // [NK 12/1/2014] doesn't look good in windowed mode.
\r
501 // [NK 13/1/2014] Seems to work okay in fullscreen mode though.
\r
502 //VGA_SetLineCompare(61);
\r
527 function initpparas()
\r
544 if (cop_drop <= 64)
\r
546 VGA_SetLineCompare(dtau[cop_drop]);
\r
550 var bShouldFade = false;
\r
552 // [NK 18/1/2014] Hack for looping back to the first plasma.
\r
553 if ((cop_drop == 65) && (ttptr == 0)) {
\r
557 if (cop_drop >= 256)
\r
560 else if (cop_drop >= 128)
\r
562 bShouldFade = true;
\r
564 else if (cop_drop > 96)
\r
567 else //if (cop_drop > 64)
\r
569 bShouldFade = true;
\r
574 // [NK 15/1/2014] cop_pal always points to fadepal, so just upload fadepal.
\r
575 //cop_pal = fadepal;
\r
578 if (cop_drop == 65)
\r
580 VGA_SetLineCompare(400);
\r
585 VGA_SetLineCompare(60);
\r
587 // [NK 9/1/2014] I think it's using 8.8 fixed point numbers to fade the palette.
\r
588 var cop_fadepalIndex = 0;
\r
589 var pfadepalIndex = 0;
\r
591 for (var nIndex = 0; nIndex < (768 / 16); nIndex++)
\r
593 for (var ccc = 0; ccc < 16; ccc++)
\r
595 // var al = cop_fadepal_ReadByte(cop_fadepalIndex + (ccc * 2));
\r
597 // var ah = cop_fadepal_ReadByte(cop_fadepalIndex + (ccc * 2) + 1);
\r
599 // [NK 17/1/2014] Read cop_fadepal as words, rather than bytes,
\r
600 // [NK 17/1/2014] to avoid endian issues.
\r
601 var ax = cop_fadepal_ReadWord(cop_fadepalIndex + (ccc * 2));
\r
602 var al = ax & 0xFF;
\r
603 var ah = (ax >> 8) & 0xFF;
\r
605 var nOldValue = fadepal_ReadByte(pfadepalIndex + ccc + 768);
\r
608 var t = fadepal_ReadByte(pfadepalIndex + ccc + 768);
\r
612 fadepal_WriteByte(pfadepalIndex + ccc + 768, t);
\r
614 var nNewValue = fadepal_ReadByte(pfadepalIndex + ccc + 768);
\r
619 if (nNewValue < nOldValue)
\r
624 t = fadepal_ReadByte(pfadepalIndex + ccc);
\r
628 fadepal_WriteByte(pfadepalIndex + ccc, t);
\r
631 cop_fadepalIndex += 32;
\r
632 pfadepalIndex += 16;
\r
643 // [nk] just before retrace
\r
646 // There is also assembly code to set the first pixel of
\r
647 // display memory here, but it may not be necessary.
\r
649 VGA_SetHorizontalScrollOffset(cop_scrl);
\r
655 // [nk] Don't think this is used.
\r
661 // [NK 15/1/2014] cop_pal always points to fadepal, so just upload fadepal.
\r
662 //VGA_UploadPalette(cop_pal);
\r
663 VGA_UploadPalette(fadepal);
\r
676 //--------------------------------------------------------------------------------------
\r
679 function dis_exit()
\r
684 var s_nFrameCount = 0;
\r
685 function dis_getmframe()
\r
688 return s_nFrameCount;
\r
691 function init_plz()
\r
695 // [NK 8/1/2014] Instead of writing the tables as assembly files,
\r
696 // [NK 8/1/2014] just use them directly in C++.
\r
698 for(var a=0;a<1024*16;a++)
\r
702 lsini4_WriteWord(a, (Math.sin(a * DPII / 4096) * 55 + Math.sin(a * DPII / 4096 * 5) * 8 + Math.sin(a * DPII / 4096 * 15) * 2 + 64) * 8);
\r
703 lsini16_WriteWord(a, (Math.sin(a * DPII / 4096) * 55 + Math.sin(a * DPII / 4096 * 4) * 5 + Math.sin(a * DPII / 4096 * 17) * 3 + 64) * 16);
\r
705 psini_WriteByte(a, Math.sin(a * DPII / 4096) * 55 + Math.sin(a * DPII / 4096 * 6) * 5 + Math.sin(a * DPII / 4096 * 21) * 4 + 64);
\r
708 for(var a=1;a<=128;a++)
\r
710 ptau_WriteByte(a, Math.cos(a * DPII / 128 + 3.1415926535) * 31 + 32);
\r
714 cop_start=96*(682-400);
\r
717 for(var a=0;a<256;a++) tw_setrgbpalette(a,63,63,63);
\r
720 var nPalOffset = ((0 * 768) + 3) * 2;
\r
723 pal_WriteWord(nPalOffset, ptau_ReadByte(a)); nPalOffset += 2;
\r
724 pal_WriteWord(nPalOffset, ptau_ReadByte(0)); nPalOffset += 2;
\r
725 pal_WriteWord(nPalOffset, ptau_ReadByte(0)); nPalOffset += 2;
\r
729 pal_WriteWord(nPalOffset, ptau_ReadByte(63 - a)); nPalOffset += 2;
\r
730 pal_WriteWord(nPalOffset, ptau_ReadByte(0)); nPalOffset += 2;
\r
731 pal_WriteWord(nPalOffset, ptau_ReadByte(0)); nPalOffset += 2;
\r
735 pal_WriteWord(nPalOffset, ptau_ReadByte(0)); nPalOffset += 2;
\r
736 pal_WriteWord(nPalOffset, ptau_ReadByte(0)); nPalOffset += 2;
\r
737 pal_WriteWord(nPalOffset, ptau_ReadByte(a)); nPalOffset += 2;
\r
741 pal_WriteWord(nPalOffset, ptau_ReadByte(a)); nPalOffset += 2;
\r
742 pal_WriteWord(nPalOffset, ptau_ReadByte(0)); nPalOffset += 2;
\r
743 pal_WriteWord(nPalOffset, ptau_ReadByte(63 - a)); nPalOffset += 2;
\r
747 nPalOffset = ((1 * 768) + 3) * 2;
\r
750 pal_WriteWord(nPalOffset, ptau_ReadByte(a)); nPalOffset += 2;
\r
751 pal_WriteWord(nPalOffset, ptau_ReadByte(0)); nPalOffset += 2;
\r
752 pal_WriteWord(nPalOffset, ptau_ReadByte(0)); nPalOffset += 2;
\r
756 pal_WriteWord(nPalOffset, ptau_ReadByte(63 - a)); nPalOffset += 2;
\r
757 pal_WriteWord(nPalOffset, ptau_ReadByte(0)); nPalOffset += 2;
\r
758 pal_WriteWord(nPalOffset, ptau_ReadByte(a)); nPalOffset += 2;
\r
762 pal_WriteWord(nPalOffset, ptau_ReadByte(0)); nPalOffset += 2;
\r
763 pal_WriteWord(nPalOffset, ptau_ReadByte(a)); nPalOffset += 2;
\r
764 pal_WriteWord(nPalOffset, ptau_ReadByte(63 - a)); nPalOffset += 2;
\r
768 pal_WriteWord(nPalOffset, ptau_ReadByte(a)); nPalOffset += 2;
\r
769 pal_WriteWord(nPalOffset, ptau_ReadByte(63)); nPalOffset += 2;
\r
770 pal_WriteWord(nPalOffset, ptau_ReadByte(a)); nPalOffset += 2;
\r
774 nPalOffset = ((3 * 768) + 3) * 2;
\r
777 pal_WriteWord(nPalOffset, ptau_ReadByte(a)); nPalOffset += 2;
\r
778 pal_WriteWord(nPalOffset, ptau_ReadByte(0)); nPalOffset += 2;
\r
779 pal_WriteWord(nPalOffset, ptau_ReadByte(0)); nPalOffset += 2;
\r
783 pal_WriteWord(nPalOffset, ptau_ReadByte(63)); nPalOffset += 2;
\r
784 pal_WriteWord(nPalOffset, ptau_ReadByte(a)); nPalOffset += 2;
\r
785 pal_WriteWord(nPalOffset, ptau_ReadByte(a)); nPalOffset += 2;
\r
789 pal_WriteWord(nPalOffset, ptau_ReadByte(63-a)); nPalOffset += 2;
\r
790 pal_WriteWord(nPalOffset, ptau_ReadByte(63-a)); nPalOffset += 2;
\r
791 pal_WriteWord(nPalOffset, ptau_ReadByte(63)); nPalOffset += 2;
\r
795 pal_WriteWord(nPalOffset, ptau_ReadByte(0)); nPalOffset += 2;
\r
796 pal_WriteWord(nPalOffset, ptau_ReadByte(0)); nPalOffset += 2;
\r
797 pal_WriteWord(nPalOffset, ptau_ReadByte(63)); nPalOffset += 2;
\r
801 nPalOffset = ((2 * 768) + 3) * 2;
\r
804 pal_WriteWord(nPalOffset, ptau_ReadByte(0)/2); nPalOffset += 2;
\r
805 pal_WriteWord(nPalOffset, ptau_ReadByte(0)/2); nPalOffset += 2;
\r
806 pal_WriteWord(nPalOffset, ptau_ReadByte(0)/2); nPalOffset += 2;
\r
810 pal_WriteWord(nPalOffset, ptau_ReadByte(a)/2); nPalOffset += 2;
\r
811 pal_WriteWord(nPalOffset, ptau_ReadByte(a)/2); nPalOffset += 2;
\r
812 pal_WriteWord(nPalOffset, ptau_ReadByte(a)/2); nPalOffset += 2;
\r
816 pal_WriteWord(nPalOffset, ptau_ReadByte(63-a)/2); nPalOffset += 2;
\r
817 pal_WriteWord(nPalOffset, ptau_ReadByte(63-a)/2); nPalOffset += 2;
\r
818 pal_WriteWord(nPalOffset, ptau_ReadByte(63-a)/2); nPalOffset += 2;
\r
822 pal_WriteWord(nPalOffset, ptau_ReadByte(0)/2); nPalOffset += 2;
\r
823 pal_WriteWord(nPalOffset, ptau_ReadByte(0)/2); nPalOffset += 2;
\r
824 pal_WriteWord(nPalOffset, ptau_ReadByte(0)/2); nPalOffset += 2;
\r
829 nPalOffset = ((4 * 768) + 3) * 2;
\r
832 pal_WriteWord(nPalOffset, ptau_ReadByte(63-a*64/75)); nPalOffset += 2;
\r
833 pal_WriteWord(nPalOffset, ptau_ReadByte(63-a*64/75)); nPalOffset += 2;
\r
834 pal_WriteWord(nPalOffset, ptau_ReadByte(63-a*64/75)); nPalOffset += 2;
\r
838 pal_WriteWord(nPalOffset, 0); nPalOffset += 2;
\r
839 pal_WriteWord(nPalOffset, 0); nPalOffset += 2;
\r
840 pal_WriteWord(nPalOffset, 0); nPalOffset += 2;
\r
844 pal_WriteWord(nPalOffset, ptau_ReadByte(a*64/75)*8/10); nPalOffset += 2;
\r
845 pal_WriteWord(nPalOffset, ptau_ReadByte(a*64/75)*9/10); nPalOffset += 2;
\r
846 pal_WriteWord(nPalOffset, ptau_ReadByte(a*64/75)); nPalOffset += 2;
\r
850 for(var a=0;a<768;a++)
\r
852 var n = pal_ReadWord(nPalOffset);
\r
856 pal_WriteWord(nPalOffset, n);
\r
860 for(var a=768;a<768*5;a++)
\r
862 var n = pal_ReadWord(nPalOffset);
\r
865 pal_WriteWord(nPalOffset, n);
\r
874 if(dis_getmframe()>timetable[ttptr])
\r
881 // [NK 18/1/2014] Loop back to the first plasma again.
\r
885 fadepal_ClearToWhite();
\r
889 cop_fadepal_SetSelectedPaletteIndex(curpal++);
\r
891 il1=inittable[ttptr][0];
\r
892 il2=inittable[ttptr][1];
\r
893 il3=inittable[ttptr][2];
\r
894 il4=inittable[ttptr][3];
\r
895 ik1=inittable[ttptr][4];
\r
896 ik2=inittable[ttptr][5];
\r
897 ik3=inittable[ttptr][6];
\r
898 ik4=inittable[ttptr][7];
\r
900 // if (curpal == 5 && cop_drop > 64) {
\r
904 VGA_SelectBitPlanes02();
\r
906 setplzparas(k1,k2,k3,k4);
\r
907 for(y=0;y<MAXY;y+=2)
\r
909 setplzparas(l1,l2,l3,l4);
\r
910 for(y=1;y<MAXY;y+=2)
\r
913 VGA_SelectBitPlanes13();
\r
915 setplzparas(k1,k2,k3,k4);
\r
916 for(y=1;y<MAXY;y+=2)
\r
918 setplzparas(l1,l2,l3,l4);
\r
919 for(y=0;y<MAXY;y+=2)
\r
922 VGA_ShowFrameBuffer();
\r
926 // set_plzstart(500);
\r
931 //--------------------------------------------------------------------------------------
\r
937 inittable[0] = [1000,2000,3000,4000,3500,2300,3900,3670];
\r
938 inittable[1] = [1000,2000,4000,4000,1500,2300,3900,1670];
\r
939 inittable[2] = [3500,1000,3000,1000,3500,3300,2900,2670];
\r
940 inittable[3] = [1000,2000,3000,4000,3500,2300,3900,3670];
\r
941 inittable[4] = [1000,2000,3000,4000,3500,2300,3900,3670];
\r
942 inittable[5] = [1000,2000,3000,4000,3500,2300,3900,3670];
\r
947 cop_fadepal_SetSelectedPaletteIndex(curpal++);
\r
951 //--------------------------------------------------------------------------------------
\r
952 // HTML5 specific code
\r
954 window.onload = function () {
\r
955 document.getElementsByTagName("body")[0].className = "js";
\r
961 var context = null;
\r
967 var canvasId = "canvas";
\r
971 canvas = canvasId ? document.getElementById(canvasId) : null;
\r
972 fps = fpsId ? document.getElementById(fpsId) : null;
\r
974 if (canvas && canvas.getContext) {
\r
975 // canvas.width = width = window.innerWidth;
\r
976 // canvas.height = height = window.innerHeight;
\r
977 canvas.width = 320;
\r
978 canvas.height = 400;
\r
980 context = canvas.getContext("2d");
\r
982 if (context.createImageData) {
\r
983 image = context.createImageData(canvas.width, canvas.height);
\r
984 } else if (context.getImageData) {
\r
985 image = context.getImageData(0, 0, canvas.width, canvas.height);
\r
988 image = { 'width': canvas.width, 'height': canvas.height,
\r
989 'data': new Array(canvas.width * canvas.height * 4)
\r
993 for (i = 0; i < image.data.length; i++) {
\r
994 image.data[i] = 255;
\r
1004 // Clear to black.
\r
1005 length = 320 * 400;
\r
1007 for (var i = 0; i < length; i++) {
\r
1008 image.data[p] = 0;
\r
1010 image.data[p] = 0;
\r
1012 image.data[p] = 0;
\r
1014 image.data[p] = 0xFF;
\r
1018 IsComplete = plz();
\r
1026 // var x = (window.innerWidth - 320) / 2;
\r
1027 // var y = (window.innerHeight - 400) / 2;
\r
1029 context.putImageData(image, x, y);
\r
1033 var start, elapsed, sleep, target;
\r
1034 start = new Date().getTime();
\r
1036 // check if the canvas has been resized
\r
1037 // if ((canvas.clientWidth / 8) != width ||
\r
1038 // (canvas.clientHeight / 8) != height) {
\r
1042 if (!IsComplete) {
\r
1046 // calculate stable FPS
\r
1047 elapsed = new Date().getTime() - start;
\r
1049 target = 1000 / 60;
\r
1051 // calculate sleep and schedule next tick
\r
1052 sleep = target - elapsed;
\r
1055 } else if (sleep > 1000) {
\r
1060 setTimeout(tick, sleep);
\r
1063 function start() {
\r
1064 lastTick = new Date().getTime();
\r
1068 if (init()) tick();
\r