Menu

[r790]: / jcpc.js  Maximize  Restore  History

Download this file

357 lines (347 with data), 8.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
gc= [0x04,0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00];
cr= [0x3f,0x28,0x00,0x00,0x26,0x00,0x19,0x00,0x00,0x07,0x00,0x00,0x30,0x00,0x00,0x00];
pl= [];
lut0= [];
lut1= [];
data= [];
m= []; // memory
mw= [[],[],[],[]]; // [new Uint8Array(16384),new Uint8Array(16384),new Uint8Array(16384),new Uint8Array(16384), new Uint8Array(16384),new Uint8Array(16384),new Uint8Array(16384),new Uint8Array(16384)]
kb= [255,255,255,255,255,255,255,255,255,255]; // keyboard state
ks= [255,255,255,255,255,255,255,255,255,255]; // keyboard state playback
kc= [255,255,255,255,255,255,255,255, // keyboard codes
0x97,// 8 del qwerty backspace
localStorage.ft & 2
? 0x94
: 0x84, // 9 tab
255,255,255,
0x22,// 13 enter
255,255,
0x25,// 16 caps
0x27,// 17 ctrl
255, // 18 qwerty alt
255,
0x86,// 20 caps lock
255,255,255,255,255,255,
0x82,// 27 esc
255,255,255,255,
0x57,// 32 space
255,255,255,255,
localStorage.ft & 2
? 0x92
: 0x10,// cursor left
localStorage.ft & 2
? 0x90
: 0x00,// cursor up
localStorage.ft & 2
? 0x93
: 0x01,// cursor right
localStorage.ft & 2
? 0x91
: 0x02,// cursor down
255,255,255,255,
0x11,// 45 COPY querty Ins
0x20,// 46 CLR qwerty Del
255,
0x40,// 0 (48)
0x80,// 1
0x81,// 2
0x71,// 3
0x70,// 4
0x61,// 5
0x60,// 6
0x51,// 7
0x50,// 8
0x41,// 9
255,255,255,255,255,255,255,
0x85,// A (65)
0x66,// B
0x76,// C
0x75,// D
0x72,// E
0x65,// F
0x64,// G
0x54,// H
0x43,// I
0x55,// J
0x45,// K
0x44,// L
0x46,// M
0x56,// N
0x42,// O
0x33,// P
0x83,// Q
0x62,// R
0x74,// S
0x63,// T
0x52,// U
0x67,// V
0x73,// W
0x77,// X
0x53,// Y
0x87,// Z (90)
255,255,255,255,255,
0x17,// 96 F0 qwerty NumKey0
0x15,// 97 F1 qwerty NumKey1
0x16,// 98 F2 qwerty NumKey2
0x05,// 99 F3 qwerty NumKey3
0x24,// 100 F4 qwerty NumKey4
0x14,// 101 F5 qwerty NumKey5
0x04,// 102 F6 qwerty NumKey6
0x12,// 103 F7 qwerty NumKey7
0x13,// 104 F8 qwerty NumKey8
0x03,// 105 F9 qwerty NumKey9
255,
0x06,// 107 ENTER qwerty NumKey+
255,
255,
0x07,// 110 F. qwerty NumKey.
255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,
0x35,// 186 ; qwerty :
0x30,// 187 ^ qwerty =
0x47,// 188 ,
0x31,// 189 -
0x37,// 190 .
0x36,// 191 /
0x32,// 192 @ qwerty `
255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,
0x21,// 219 [
0x26,// 220 \
0x23,// 221 ]
0x34];// 222 ' qwerty ;
function run() {
paintScreen();
vsync= 1;
while(st < 128) // 2 scanlines
//cond(),
r++,
g[m[pc>>14&3][pc++&16383]]();
st-= 128;
z80interrupt();
while(st < 896) // 14 scanlines
//cond(),
r++,
g[m[pc>>14&3][pc++&16383]]();
st-= 896;
vsync= 0;
while(st < 2432) // 38 scanlines
//cond(),
r++,
g[m[pc>>14&3][pc++&16383]]();
st-= 2432;
z80interrupt();
for (vs= 0; vs<4; vs++){
while(st < 3328) // 4*52 scanlines
//cond(),
r++,
g[m[pc>>14&3][pc++&16383]]();
st-= 3328;
z80interrupt();
}
while(st < 3200) // 50 scanlines
//cond(),
r++,
g[m[pc>>14&3][pc++&16383]]();
st-= 3200;
if( pbt ){
if( !frc-- ){
do{
t= pb[pbc]>>8;
(pb[pbc]&255)!=255 && (ks[t>>3]^= 1 << (t&7));
frc= pb[++pbc]&255;
} while( pbc<pbt && !(frc&255) )
if(pbc==pbt)
// console.log(frc),
tim.innerHTML= '',
pbt= 0;
else
frc--;
}
}
else{
for ( t= 0; t<80; t++ )
if( (kb[t>>3] ^ ks[t>>3]) & (1 << (t&7)) )
pb[pbc++]= frc | t<<8,
frc= 0;
if( ++frc == 255 )
pb[pbc++]= frc,
frc= 0;
for ( t= 0; t<10; t++ )
ks[t]= kb[t];
}
if (!(++flash & 15))
titul(),
time= nt;
}
function handleDragOver(ev) {
ev.stopPropagation();
ev.preventDefault();
}
function kdown(ev) {
var code= kc[ev.keyCode];
if( code<255 )
kb[code>>4]&= ~(1 << (code & 0x07));
switch( ev.keyCode ){
case 112: // F1
if( f1= ~f1 ){
if( trein==32000 )
clearInterval(interval);
else
node.onaudioprocess= audioprocess0;
dv.style.display= he.style.display= 'block';
}
else{
if( trein==32000 )
interval= setInterval(run, 20);
else
node.onaudioprocess= audioprocess;
dv.style.display= he.style.display= 'none';
}
break;
case 113: // F2
kc[9]^= 0x10;
kc[37]^= 0x82;
kc[38]^= 0x90;
kc[39]^= 0x92;
kc[40]^= 0x93;
alert((localStorage.ft^= 2) & 2
? 'Joystick enabled on Cursors + Tab'
: 'Joystick disabled');
self.focus();
break;
case 114: // F3
pbt && (
pbt= 0,
tim.innerHTML= '',
frc= (pb[pbc]&255)-frc);
frcs= frc;
pbcs= pbc;
f3++;
localStorage.save= wm();
break;
case 115: // F4
if( pbt ){
if( trein==32000 )
clearInterval(interval);
else
node.onaudioprocess= audioprocess0;
ajax('snaps/'+params.slice(0,-3)+'sna', -1);
}
else
frc= frcs,
pbc= pbcs,
f4++,
rm(localStorage.save);
break;
case 116: // F5
return 1;
case 117: // F6
if( !pbt ){
if( trein==32000 )
clearInterval(interval);
else
node.onaudioprocess= audioprocess0;
t= wm()+String.fromCharCode(f3)+String.fromCharCode(f4)+param+String.fromCharCode(255);
while( pbc )
t+= String.fromCharCode(pb[--pbc]);
ajax('record.php', t);
document.documentElement.innerHTML= 'Please wait...';
}
break;
case 118: // F7
localStorage.ft= +localStorage.ft+8 % 24;
t= 1;
rotapal();
break;
case 119: // F8
m[0]= rom[pc= 0];
break;
case 120: // F9
cv.setAttribute('style', 'image-rendering:'+( (localStorage.ft^= 1) & 1
? 'optimizeSpeed'
: '' ));
onresize();
alert(localStorage.ft & 1
? 'Nearest neighbor scaling'
: 'Bilinear scaling');
self.focus();
break;
case 121: // F10
o= wm();
u= new Uint8Array(o.length);
for ( j=0; j<o.length; j++ )
u[j]= o.charCodeAt(j);
ir.src= URL.createObjectURL(new Blob([u.buffer], {type: 'application/octet-binary'}));
alert('Snapshot saved.\nRename the file (without extension) to .SNA.');
self.focus();
break;
case 122: // F11
return 1;
case 123: // F12
alert('Sound '+ ( (localStorage.ft^= 4) & 4
? 'en'
: 'dis' ) +'abled');
self.focus();
}
if( !ev.metaKey )
return false;
}
function kup(ev) {
var code= kc[ev.keyCode];
if( code<255 )
kb[code>>4]|= 1 << (code & 0x07);
if( !ev.metaKey )
return false;
}
function kpress(ev) {
if( ev.keyCode==116 || ev.keyCode==122 )
return 1;
if( !ev.metaKey )
return false;
}
function audioprocess0(e){
data= e.outputBuffer.getChannelData(0);
j= 0;
while( j<1024 )
data[j++]= 0;
}
function audioprocess(e){
run();
data= e.outputBuffer.getChannelData(0);
j= 0;
if( localStorage.ft & 4 )
while( j<1024 ) // 48000/1024= 46.875 19968/1024= 19.5. 19.5/4=5
aymute(),
aymute(),
data[j++]= aystep();
else
while( j<1024 )
data[j++]= 0;
}
function rt(f){
rm(f);
pbcs= pbc= pbt;
frcs= frc= f.charCodeAt(255);
f3++;
localStorage.save= wm();
tim.innerHTML= '';
pbt= 0;
if( trein==32000 )
interval= setInterval(run, 20);
else
node.onaudioprocess= audioprocess;
}
function rever32(a){
return a>>24&0x000000ff
| a>> 8&0x0000ff00
| a<< 8&0x00ff0000
| a<<24&0xff000000;
}