-
Notifications
You must be signed in to change notification settings - Fork 1
/
sketch.js
361 lines (330 loc) · 10.8 KB
/
sketch.js
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
358
359
360
361
//const Uint8Array ima_disco_1bpp [2] = {1,2};
var font; //TVOUT font global
const cabecera_font=3;
const cabecera_imagen=2;
const font_4x5_1bpp=new Array(
4,//Pixels ancho cada letra
5,//Pixels alto cada letra
20,//ancho en bytes de cada linea multiplo de 8, Es 156 pixels
0xB3,0xB3,0x11,0x95,0x1D,0x57,0x55,0xB3,0xB3,0x91,0x55,0x55,0x51,0x17,0x1B,0xB3,0x39,0x19,0x1B,0xBF,
0x55,0x55,0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0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFC,0x1F,0xFF,0xFF,
0xFF,0xFF,0xF8,0x0F,0xFF,0xFF,
0xFF,0xFF,0xF0,0x07,0xFF,0xFF,
0xFF,0xFF,0xC0,0x01,0xFF,0xFF,
0xFF,0xFF,0x80,0x80,0xFF,0xFF,
0xFF,0xFF,0x01,0xC0,0x7F,0xFF,
0xFF,0xFC,0x06,0x30,0x1F,0xFF,
0xFF,0xF8,0x0C,0x18,0x0F,0xFF,
0xFF,0xF0,0x18,0x0C,0x07,0xFF,
0xFF,0xC0,0x60,0x03,0x01,0xFF,
0xFF,0x80,0xC0,0x01,0x80,0xFF,
0xFF,0x01,0x80,0x01,0xC0,0x7F,
0xFC,0x06,0x00,0x00,0x30,0x1F,
0xF8,0x0C,0x00,0x00,0x18,0x0F,
0xF0,0x18,0x00,0x00,0x0C,0x07,
0xC0,0x60,0x00,0x00,0x03,0x01,
0x80,0xC0,0x00,0x00,0x01,0x80,
0x81,0x80,0x00,0x00,0x00,0xC0,
0xEF,0x80,0x00,0x00,0x00,0xFB,
0xFF,0x80,0x00,0x00,0x00,0xFF,
0xFF,0x80,0x07,0xF0,0x00,0xFF,
0xFF,0x80,0x07,0xF0,0x00,0xFF,
0xFF,0x80,0x07,0xF0,0x00,0xFF,
0xFF,0x80,0x07,0xF0,0x00,0xFF,
0xFF,0x80,0x07,0xF0,0x00,0xFF,
0xFF,0x80,0x07,0xF0,0x00,0xFF,
0xFF,0x80,0x07,0xF0,0x00,0xFF,
0xFF,0x80,0x07,0xF0,0x00,0xFF,
0xFF,0xF5,0xB7,0xF3,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
);*/
const ancho_screen=84; //Con 2 bits de color es multiplo de 8 84*2=168/8=21 bytes por linea
const alto_screen=48;
const ancho_byte_screen=21; //Dividir (84*2)/8 para 2 bits de color
const tope_byte_screen=1008; //ancho_byte_screen*alto_screen
var screen=new Array(tope_byte_screen);
//var screen = new Uint8Array((ancho_screen*alto_screen*2)/8);
//var screen=new Array((ancho_screen*alto_screen*2)/8);
//var screen=new Array(ancho_byte_screen*alto_screen);
//var screen_real = new Uint8Array((ancho*alto)); //buffer pantalla real1
//var buffer = new ArrayBuffer(8);
//TVOUT select font
function select_font(f){
font=f;
}
//TVOUT print char
function print_char(x,y,c){
//c -= pgm_read_byte(font+2);
//bitmap(x,y,font,(c*pgm_read_byte(font+1))+3,pgm_read_byte(font),pgm_read_byte(font+1));
var codeChar=(c.charCodeAt()-65);
var divEntera=Math.floor((codeChar*font[0])/8);
var resto=((codeChar*font[0])%8);
//console.log('Entera '+divEntera);
//console.log('Resto '+resto);
var offsetDestino=(y*ancho_byte_screen)+(x*2/8);
//console.log('off '+offsetDestino);
var aux=0;
var aux_destino=0;
for (var i=0;i<(font[1]);i++){
aux=font[divEntera+(i*font[2])+cabecera_font];
//console.log(aux);
if ((aux&0x10)==0x10) aux_destino=0x03; else aux_destino=0;
if ((aux&0x20)==0x20) aux_destino|=0x0C;
if ((aux&0x40)==0x40) aux_destino|=0x30;
if ((aux&0x80)==0x80) aux_destino|=0xC0;
screen[offsetDestino]=aux_destino;
if ((font[0])>4)
{
if ((aux&0x01)==0x01) aux_destino=0x03; else aux_destino=0;
if ((aux&0x02)==0x02) aux_destino|=0x0C;
if ((aux&0x04)==0x04) aux_destino|=0x30;
if ((aux&0x08)==0x08) aux_destino|=0xC0;
screen[offsetDestino+1]=aux_destino;
}
offsetDestino+=ancho_byte_screen;
//console.log('off '+offsetDestino);
//console.log(offsetDestino+(i*ancho_screen/8));
}
}
//Version optimizada solo para fuente nibble 4x5
function print_char4x5(x,y,c,color){
var codeChar=(c.charCodeAt()-65);
if (codeChar<0) codeChar=32;
var divEntera=Math.floor(codeChar>>1);
var resto=(codeChar&1);
var offsetDestino=(y*ancho_byte_screen)+(x>>2);
var aux=0;
var aux_destino=0;
for (var i=0;i<5;i++){
if (codeChar==32)
aux=0xFF;
else
aux=font[divEntera+(i*font[2])+cabecera_font];
if (resto==0){
if ((aux&0x10)==0x10) aux_destino=0x03; else aux_destino=0;
if ((aux&0x20)==0x20) aux_destino|=0x0C;
if ((aux&0x40)==0x40) aux_destino|=0x30;
if ((aux&0x80)==0x80) aux_destino|=0xC0;
}
else{
if ((aux&0x01)==0x01) aux_destino=0x03; else aux_destino=0;
if ((aux&0x02)==0x02) aux_destino|=0x0C;
if ((aux&0x04)==0x04) aux_destino|=0x30;
if ((aux&0x08)==0x08) aux_destino|=0xC0;
}
if (color==0){
aux_destino=~aux_destino;
}
screen[offsetDestino]=aux_destino;
offsetDestino+=ancho_byte_screen;
}
if (color==0) aux_destino=0x00;
else aux_destino=0xFF;
screen[offsetDestino]=aux_destino;
}
//Version optimizada solo para fuente nibble 4x5
function print_4x5(x,y,str,color){
for (var i=0;i<str.length;i++){
print_char4x5(x+(i*4),y,str.charAt(i),color);
}
}
function byteString(n) {
if (n < 0 || n > 255 || n % 1 !== 0) {
throw new Error(n + ' does not fit in a byte');
}
return ('000000000' + n.toString(2)).substr(-8);
}
function Put_Imagen1to2(imagen)
{
var ancho=((ima_disco_1bpp[0])>>3);
//console.log(ancho);
var alto= ima_disco_1bpp[1];
//console.log(alto);
var cont_destino=0;
var aux;
var aux_destino;
var tope = ancho*alto;
var linea_screen=0;
//var cad='';
for (var i=0;i<tope;i++)
{
aux= ima_disco_1bpp[i+cabecera_imagen];
//cad=cad+'|'+byteString(aux);
//cad=cad+byteString(aux);
if ((aux&0x10)==0x10) aux_destino=0x03; else aux_destino=0;
if ((aux&0x20)==0x20) aux_destino|=0x0C;
if ((aux&0x40)==0x40) aux_destino|=0x30;
if ((aux&0x80)==0x80) aux_destino|=0xC0;
screen[cont_destino]=aux_destino;
cont_destino++;
if ((aux&0x01)==0x01) aux_destino=0x03; else aux_destino=0;
if ((aux&0x02)==0x02) aux_destino|=0x0C;
if ((aux&0x04)==0x04) aux_destino|=0x30;
if ((aux&0x08)==0x08) aux_destino|=0xC0;
screen[cont_destino]=aux_destino;
cont_destino++;
if (((i+1)%ancho==0)&&(i>0)){
linea_screen++;
//cont_destino=(linea_screen*21);
cont_destino=(linea_screen*ancho_byte_screen);
//cad+='\n';
}
}
/*cad='';
for (var i=0;i<(ancho_screen*alto_screen*2/8);i++)
{
//cad+='|'+byteString(screen[i]);
cad+=byteString(screen[i]);
if (((i+1)%21==0)&&(i>0)){
cad+='\n';
}
}*/
//console.log(cad);
}
function PaintPantallaReal(){
var tope= ancho_screen*alto_screen*2/8; //1008
var aux=0;
var aux_destino=0;
var x_ini=10;
var y_ini=10;
var x_destino=0;
var y_destino=0;
//var cad='';
strokeWeight(3);
for (var i=0;i<tope;i++)
{
aux=screen[i];
if ((aux&0xC0)==0xC0){aux_destino=0xFF;}else{aux_destino=0;}
//console.log(aux_destino);
stroke(aux_destino,aux_destino,aux_destino);
//point(x_destino+x_ini,y_destino+y_ini);
rect(x_destino+x_ini,y_destino+y_ini,0,0);
x_destino+=4;
//cad=cad+byteString(aux_destino);
if ((aux&0x30)==0x30){aux_destino=0xFF;}else{aux_destino=0;}
//point(x_destino+x_ini,y_destino+y_ini);
stroke(aux_destino,aux_destino,aux_destino);
rect(x_destino+x_ini,y_destino+y_ini,0,0);
x_destino+=4;
//cad=cad+byteString(aux_destino);
//console.log(aux_destino);
if ((aux&0x0C)==0x0C){aux_destino=0xFF;}else{aux_destino=0;}
stroke(aux_destino,aux_destino,aux_destino);
//point(x_destino+x_ini,y_destino+y_ini);
rect(x_destino+x_ini,y_destino+y_ini,0,0);
x_destino+=4;
//cad=cad+byteString(aux_destino);
if ((aux&0x03)==0x03){aux_destino=0xFF;}else{aux_destino=0;}
stroke(aux_destino,aux_destino,aux_destino);
rect(x_destino+x_ini,y_destino+y_ini,0,0);
x_destino+=4;
//cad=cad+byteString(aux_destino);
if (((i+1)%21==0)&&(i>0)){
x_destino=0;
y_destino+=4;
//cad+='\n';
}
}
//console.log(cad);
/* var cad;
//console.log(tope);
for (i=0;i<tope;i++)
{
cad+=screen[i]+"|";
}
//console.log(cad);*/
}
/*function Prueba(){
screen[0]=0xF0;
screen[1]=0;
screen[2]=0xFF;
screen[3]=0;
screen[4]=0xFF;
}*/
function ClearScreen(){
//var tope=ancho_screen*alto_screen*2/8; //1008
for (var i=0;i<tope_byte_screen;i++) screen[i]=0;
}
function setup() {
//createCanvas(710, 400);
var cnv=createCanvas(displayWidth, displayHeight);
var x=84;
var y=0;
cnv.position(x,y);
//background(255, 0, 200);
}
function draw() {
//var escalaX=displayWidth/360;
//var escalaY=displayWidth/340;
//scale(escalaX,escalaY);
background(200);
fill(127);
stroke(0);
ClearScreen();
//Prueba();
//Put_Imagen1to2(ima_disco_1bpp);
select_font(font_4x5_1bpp);
//print_char(0,0,'A');
//print_char4x5(0,0,'E');
print_4x5(0,0, 'DISKMAG EXILIUM VERSI',0);
print_4x5(0,6, ' SE TRATA DE UNA PRI',1);
print_4x5(0,12,'MERA VERSION DISPONIB',1);
print_4x5(0,18,'LE PARA DESCARGAR POR',1);
print_4x5(0,24,'MEDIO DE INTERNET ',1);
print_4x5(0,30,'LOS CREADORES DE LA M',1);
print_4x5(0,36,'MISMA NO SE HACEN RES',1);
print_4x5(0,42,'PONSABLES DE LOS COME',1);
PaintPantallaReal();
stroke(0);
//line(342, 10, 342, 200);
}