-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdisplayfunc.h
800 lines (738 loc) · 20.4 KB
/
displayfunc.h
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
#include <math.h>
#include <stdlib.h>
//#define ENABLE_TRIANGLES
/* CPKI AttinyStreamGfxApi & TinyMultiOs, Version 0.9.2
see
https://www.youtube.com/watch?v=WNJQXsJqSbM
Copyright (c) 2022
Görg Pflug & CPKI Gmbh, www.cpki.de . All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
All advertising materials mentioning features or use of this software must display the following acknowledgement: “This product includes software developed by the CPKI Gmbh, Görg Pflug and its contributors.”
Neither the name of the Cpki GmbH nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY Görg Pflug, CPKI Gmbh AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
Version:
0.8.1 faster
0.8 Filled Triangle drawing
0.5 faster, support functions, Consistent API, engine-interleaved I2C, propper line-drawing-api
much better 3D-Performance
0.4 Prelimary Support for Arduino-Wire, performance worse than on attiny85
0.3 Compatible with C++, compiles in Microchip Studio and Arduino, most samples still untested
added .INO example for Arduino
0.2 Multiple Consoles
0.2.1 ASCII Font Support
define: ENABLE_FONT_BASIC
"Low Quality" Halftoning, saves 64 bytes, faster, for some use cases "low quality" halftoning might even look better
define: ENABLE_LOW_QUALITY_HALFTONE
Halftoning gets disabled Automatically when not using layers or pixel callback, faster, saves 64 byte
*/
#ifndef ENABLE_WIRE
#define INTERLEAVE
#endif
#pragma GCC push_options
#ifndef DISABLE_OFAST
#pragma GCC optimize ("Ofast")
#endif
#ifndef ENABLE_LAYERS
#ifndef PIXEL_CALLBACK
#define DISABLE_HALFTONE
#endif
#endif
#ifndef GfxApiLayerGetNextByteInlineHack
#define GfxApiLayerGetNextByteInlineHack
u8 select_dither=0;
const u8 _ordered_dither_matrix_simulated_annealing[] PROGMEM=
{
13,48,19,56,6,22,62,41,
30,24,43,0,36,51,10,31,
2,53,11,58,15,27,44,17,
40,42,21,38,47,8,34,54,
14,63,49,4,23,61,20,5,
45,35,9,59,28,1,50,32,
18,52,60,16,55,12,25,57,
29,7,39,26,33,46,37,3,
/*
// this seems to be the best matrix for vector drawing
52,10,59,2,36,9,34,3,
20,38,23,49,19,62,22,48,
61,5,54,11,43,4,40,12,
25,42,17,46,27,57,18,45,
53,1,58,32,15,33,50,8,
21,31,39,7,63,0,30,37,
6,56,13,47,16,44,14,60,
41,24,35,29,55,26,51,28,
*/
}; // ordered dither matrix generated by simulated annealing
// gcc is too stupid to inline this function..... because it is compiled on O3...
// so split.... but we want to define it only once, because the display function can potentially be included multiple times
// one should check this for the sprites too, the compiler pushed loads of variables.
static inline s8 __attribute__((always_inline)) GfxApiLayerGetNextByte (GfxApiCompressedLayer *g)
{
if (g->SkipCounter)
{
g->SkipCounter--;
return 0;
} else return _GfxApiLayerGetNextByte(g);
}
#ifdef ENABLE_LINEDRAWING
void _setpixel(u8 x,u8 y,u8 *linebuffer)
{
y-=96;
if(y&(~63))return;//y-clipping
unsigned char x_seg = x & 0xf8;
if (x_seg != _cur_seg)
return;
//static u8 cnt;
linebuffer[y] |=1<<(x&7);
//linebuffer[10]=cnt++;
}
static unsigned char _need_clear=1;//,_clear_start=0,_clear_end=0;
// Bresenham
static inline void _line(u8 x0, u8 y0, u8 x1, u8 y1,unsigned char *linebuffer) {
if((x0&0xf8)>_cur_seg+7) return ; // links grösser als cur seg... raus...
if((x1&0xf8)<_cur_seg) return ; // rechts ist kleiner als das akute segment....raus...die linie
// kann das segment nicht schneiden
_need_clear=1;
s8 dx = abs(x1-x0);//, sx = x0<x1 ? 1 : -1;
s8 dy = -abs(y1-y0), sy = y0<y1 ? 1 : -1;
int err = 0+dx+dy, e2;
for(;;){
_setpixel(x0,y0,linebuffer);
if ((x0==x1) && (y0==y1)) return;
e2 = 2*err;
if (e2 >= dy) { err += dy; x0++; } /* e_xy+e_x > 0 */
if (e2 <= dx) { err += dx; y0 += sy; } /* e_xy+e_y < 0 */
}
}
static inline void _hline(u8 x0, u8 y0, u8 x1, u8 c, u8 *linebuffer) {
y0-=96;
if(x0>x1)swapu8(x0,x1);
if(y0&(~63))return;//y-clipping
if((x0&0xf8)>_cur_seg+7) return ; // links grösser als cur seg... raus...
if((x1&0xf8)<_cur_seg) return ; // rechts ist kleiner als das akute segment....raus...die linie
// kann das segment nicht schneiden
_need_clear=1;
// if(_clear_start>y0)_clear_start=y0;
// if(_clear_end<y0)_clear_end=y0;
//_clear_start=0;
//_clear_end=63;
if(x0<_cur_seg)x0=_cur_seg;
if(x1>_cur_seg+7)x1=_cur_seg+7;
x0-=_cur_seg;
x1-=_cur_seg;
u8 a=1<<x0;
static const u8 hl[8] PROGMEM ={1,1+2,1+2+4,1+2+4+8,1+2+4+8+16,1+2+4+8+16+32,1+2+4+8+16+32+64,1+2+4+8+16+32+64+128}
;
u8 l=pgm_read_byte(&hl[x1-x0])<<x0;
u8 mask=~l;
// c&=l;
linebuffer[y0]=(linebuffer[y0]&mask);//|c;
u8 y_add=(y0&7)*8;
u16 addr=(u16)&_ordered_dither_matrix_simulated_annealing[(x0&7)+y_add];
u8 bit=1<<x0;
for(;x0!=x1+1;x0++,addr++,bit<<=1)if(pgm_read_byte(addr)>c) linebuffer[y0]|=bit;
}
#ifdef ENABLE_CIRCLES
void drawCircle(int xc, int yc, int x, int y,u8 *linebuffer,u8 pat)
{
_hline(xc-x,yc+y,xc+x,pat,linebuffer);
_hline(xc-x,yc-y,xc+x,pat,linebuffer);
_hline(xc+y,yc+x,xc-y,pat,linebuffer);
_hline(xc+y,yc-x,xc-y,pat,linebuffer);
}
void fillCircle(u8 xc,u8 yc,u8 r,u8 pat,u8*linebuffer)
{
if(((xc-r)&0xf8)>_cur_seg+7) return ; // links grösser als cur seg... raus...
if(((xc+r)&0xf8)<_cur_seg) return ; // rechts ist kleiner als das akute segment....raus...die linie
// kann das segment nicht schneiden
_need_clear=1;
int x = 0, y = r;
int d = 3 - 2 * r;
drawCircle(xc, yc, x, y,linebuffer,pat);
while (y >= x)
{
x++;
if (d > 0)
{
y--;
d = d + 4 * (x - y) + 10;
}
else
d = d + 4 * x + 6;
drawCircle(xc, yc, x, y,linebuffer,pat);
}
}
#endif
#ifdef ENABLE_TRIANGLES
// triangle code was once based on https://www.avrfreaks.net/sites/default/files/triangles.c , https://www.avrfreaks.net/forum/algorithm-draw-filled-triangle
void fillTriangle(u8 x1,u8 y1,u8 x2,u8 y2,u8 x3,u8 y3, u8 c,u8*linebuffer) {
u8 t1x,t2x,y,minx,maxx,t1xp,t2xp;
u8 change=0;
minx=x1;
if(x2<minx)minx=x2;
if(x3<minx)minx=x3;
maxx=x1;
if(x2>maxx)maxx=x2;
if(x3>maxx)maxx=x3;
if((minx&0xf8)>_cur_seg+7) return ; // links grösser als cur seg... raus...
if((maxx&0xf8)<_cur_seg) return ; // rechts ist kleiner als das akute segment....raus...die linie
s8 signx1,signx2,dx1,dy1,dx2,dy2;
u8 e1,e2;
// Sort vertices
if (y1>y2)
{
swapu8(y1,y2);
swapu8(x1,x2);
}
if (y1>y3)
{
swapu8(y1,y3);
swapu8(x1,x3);
}
if (y2>y3)
{
swapu8(y2,y3);
swapu8(x2,x3);
}
t1x=x1;
t2x=x1;
y=y1; // Starting points
dx1 = (s8)(x2 - x1);
if(dx1<0)
{
dx1=-dx1;
signx1=-1;
}
else
signx1=1;
dy1 = (s8)(y2 - y1);
dx2 = (s8)(x3 - x1);
if(dx2<0)
{
dx2=-dx2;
signx2=-1;
}
else signx2=1;
dy2 = (s8)(y3 - y1);
if (dy1 > dx1)
{ // swap values
swapu8(dx1,dy1);
change|=1;// = true;
}
if (dy2 > dx2)
{ // swap values
swapu8(dy2,dx2);
change|=2;// = true;
}
e2 = (u8)(dx2>>1);
// Flat top, just process the second half
if(y1==y2) goto next;
e1 = (u8)(dx1>>1);
for (u8 i = 0; i < dx1;)
{
t1xp=0; t2xp=0;
if(t1x<t2x)
{
minx=t1x;
maxx=t2x;
}
else
{
minx=t2x;
maxx=t1x;
}
// process first line until y value is about to change
while(i<dx1)
{
i++;
e1 += dy1;
while (e1 >= dx1)
{
e1 -= dx1;
if (change&1)
t1xp=signx1;
else
goto next1;
}
if (change&1) break;
t1x += signx1;
}
// Move line
next1:
// process second line until y value is about to change
while (1)
{
e2 += dy2;
while (e2 >= dx2) {
e2 -= dx2;
if (change&2)
t2xp=signx2;
else
goto next2;
}
if (change&2)
break;
t2x += signx2;
}
next2:
if(minx>t1x) minx=t1x;
if(minx>t2x) minx=t2x;
if(maxx<t1x) maxx=t1x;
if(maxx<t2x) maxx=t2x;
_hline(minx,y, maxx, c,linebuffer); // Draw line from min to max points found on the y
// Now increase y
if(!(change&1)) t1x += signx1;
t1x+=t1xp;
if(!(change&2)) t2x += signx2;
t2x+=t2xp;
y += 1;
if(y==y2) break;
}
next:
// Second half
dx1 = (s8)(x3 - x2);
if(dx1<0)
{
dx1=-dx1;
signx1=-1;
}
else
signx1=1;
dy1 = (s8)(y3 - y2);
t1x=x2;
if (dy1 > dx1)
{ // swap values
swapu8(dy1,dx1);
change|=1;// = true;
}
else
change&=2;//false;
e1 = (u8)(dx1>>1);
for (u8 i = 0; i<=dx1; i++)
{
t1xp=0; t2xp=0;
if(t1x<t2x)
{
minx=t1x;
maxx=t2x;
}
else
{
minx=t2x;
maxx=t1x;
}
// process first line until y value is about to change
while(i<dx1) {
e1 += dy1;
while (e1 >= dx1)
{
e1 -= dx1;
if (change&1)
{
t1xp=signx1;
break;
}
else
goto next3;
}
if (change&1)
break;
t1x += signx1;
if(i<dx1) i++;
}
next3:
// process second line until y value is about to change
while (t2x!=x3)
{
e2 += dy2;
while (e2 >= dx2)
{
e2 -= dx2;
if(change&2)
t2xp=signx2;
else
goto next4;
}
if (change&2)
break;
t2x += signx2;
}
next4:
if(minx>t1x) minx=t1x;
if(minx>t2x) minx=t2x;
if(maxx<t1x) maxx=t1x;
if(maxx<t2x) maxx=t2x;
_hline(minx,y, maxx, c,linebuffer); // Draw line from min to max points found on the y
// Now increase y
if(!(change&1)) t1x += signx1;
t1x+=t1xp;
if(!(change&2)) t2x += signx2;
t2x+=t2xp;
y += 1;
if(y>y3) return;
}
}
#endif
#endif
#endif
static void DISPLAYFUNC (
GfxApiCompressedLayer * layers,
u8 fade,
GfxApiSprite * Sprites,
u8 * screen
#ifdef ENABLE_CONSOLE0_FONT_SWITCHING
,long long font_adress_console_0
#endif
#ifdef ENABLE_SECOND_CONSOLE
,u8 * screen2,
s16 zoomX,
s16 zoomY,
s16 scrollX,
s16 scrollY
#endif
#ifdef ENABLE_SECOND_CONSOLE_AFFINE
,s16 zoomX2,
s16 zoomY2
#endif
)
{
#ifdef ENABLE_ATTINY_POWER_MANAGER
if(low_power_screen_disable)
{
_manage_battery();
return;
}
#endif
#ifdef INTERLEAVE
u8 i2c_data_out;
#endif
select_dither+=64;
if (select_dither==64*4)select_dither=0;
#ifdef ENABLE_WIRE
u8 wire_cnt=0;
#else
u8 clock_i2c=0;
#endif
#ifdef ENABLE_LINEDRAWING
u8 linebuffer[64];
memset(linebuffer,0,sizeof(linebuffer));
reorder_lines();
#endif
#ifdef ENABLE_LAYERS
u16 layers_constant_counter=0;
#endif
#ifdef ENABLE_SPRITES
u16 sprites_constant_counter=0;
#endif
u8 x_pos_screen;
os_gfx_start_display_transfer();
#ifndef DISABLE_HALFTONE
#ifndef ENABLE_LOW_QUALITY_HALFTONE
#ifndef ENABLE_ORDERED_DITHERING
s8 error_right[64];
memset(error_right,0,sizeof(error_right));
#endif
#endif
s8 layersum=0;
#endif
#ifdef ENABLE_SECOND_CONSOLE
s16 second_console_x=scrollX;
#endif
#ifdef ENABLE_SECOND_CONSOLE_AFFINE
s16 second_console_y0=scrollY;
#endif
for (x_pos_screen = 0; x_pos_screen < 128; x_pos_screen++
#ifdef ENABLE_SECOND_CONSOLE
,second_console_x+=zoomX
#endif
#ifdef ENABLE_SECOND_CONSOLE_AFFINE
,second_console_y0+=zoomY2
#endif
)
{
#ifdef ENABLE_LINEDRAWING
u8 line_cur_bit = 1<<(x_pos_screen&7);
if((x_pos_screen&7)==0)
{ // clear linebuffer for 8x64 block and fill with lines
if(_need_clear)
{
_need_clear=0;
memset(linebuffer, 0,64);
// _clear_start=64,_clear_end=0;
}
_cur_seg=(x_pos_screen&0xf8)+64;
for(u8 i=0;i<_gfx_linepos;i+=4)
_line(_gfx_points_of_lines[i], _gfx_points_of_lines[i+1], _gfx_points_of_lines[i+2], _gfx_points_of_lines[i+3],linebuffer);
#ifdef ENABLE_TRIANGLES
for(u8 i=_gfx_linepos;i<_gfx_linepos+_gfx_tripos;i+=8)
{
fillTriangle(_gfx_points_of_lines[i], _gfx_points_of_lines[i+1], _gfx_points_of_lines[i+2], _gfx_points_of_lines[i+3],_gfx_points_of_lines[i+4], _gfx_points_of_lines[i+5],_gfx_points_of_lines[i+6],linebuffer);
}
#endif
#ifdef ENABLE_CIRCLES
#ifndef ENABLE_TRIANGLES
#define _gfx_tripos 0
#endif
for(u8 i=_gfx_linepos+_gfx_tripos;i<_gfx_linepos+_gfx_circlepos+_gfx_tripos;i+=4)
{
fillCircle(_gfx_points_of_lines[i], _gfx_points_of_lines[i+1], _gfx_points_of_lines[i+2], _gfx_points_of_lines[i+3],linebuffer);
}
#ifndef ENABLE_TRIANGLES
#undef _gfx_tripos
#endif
#endif
}
#endif
#ifdef ENABLE_CONSOLE
u8 charpos = x_pos_screen >> 3;
#endif
#ifdef ENABLE_SECOND_CONSOLE
#ifndef ENABLE_SECOND_CONSOLE_AFFINE
u8 charpos_second_con = (second_console_x>>11);
// if(charpos_second_con>SECOND_CONSOLE_LINE_LENGTH)charpos_second_con=SECOND_CONSOLE_LINE_LENGTH-1;
s16 second_console_y=scrollY;
#else
s16 second_console_y=second_console_y0;
s16 second_console_x_affine=second_console_x;
#endif
#endif
u8 or_bit=1;
#ifndef ENABLE_ORDERED_DITHERING
s8 propagte_error=0;
#endif
u8 block_8_px=0;
u8 y_pos_screen;
#ifdef ENABLE_ORDERED_DITHERING
u8 ordered_dither_y=0;
u8 ordered_dither_x=(x_pos_screen&7)<<3;
#endif
for (y_pos_screen = 0; y_pos_screen < 64; y_pos_screen++
)
{
#ifdef INTERLEAVE
if(clock_i2c)
{
if(i2c_data_out&0x80)
{
os_i2c_sda_high();
}
else
{
os_i2c_sda_low();
}
i2c_data_out<<=1;
os_i2c_scl_high();
}
#endif
#ifndef DISABLE_HALFTONE
#ifndef PIXEL_CALLBACK
s8 background_pixel=0;
#else
s8 background_pixel=PIXEL_CALLBACK (x_pos_screen,y_pos_screen);
#endif
layersum=background_pixel;
#endif
#ifdef ENABLE_LAYERS
if(!layers_constant_counter)
{
u8 i;
for(i=0;i<NR_LAYERS;i++)
layers[i].PixelValue += GfxApiLayerGetNextByte(&layers[i]);
}
else layers_constant_counter--;
// change to implement different combination logic for the layers
#ifndef LAYERS_COLORKEY
#ifndef SUBTRACT_LAYER0
layersum+=layers[0].PixelValue>>fade;
#else
layersum-=layers[0].PixelValue>>fade;
#endif
#endif
#ifndef LAYERS_COLORKEY
for(u8 i=1;i<NR_LAYERS;i++)
layersum+=layers[i].PixelValue;
#else
for(u8 i=0;i<NR_LAYERS;i++)if(layers[i].PixelValue)
layersum=layers[i].PixelValue;
#endif
#endif
#ifndef DISABLE_HALFTONE
if(layersum<0)layersum=0;
if(layersum>63)layersum=63;
#ifndef ENABLE_ORDERED_DITHERING
#ifndef ENABLE_LOW_QUALITY_HALFTONE
propagte_error+=layersum+error_right[y_pos_screen];
#else
propagte_error+=layersum;
#endif
if (propagte_error > 31)block_8_px |= or_bit, propagte_error-=63;
#ifndef ENABLE_LOW_QUALITY_HALFTONE
propagte_error/=2;
error_right[y_pos_screen]=propagte_error;
#endif
#endif
#endif
#ifdef ENABLE_ORDERED_DITHERING
if (pgm_read_byte(&_ordered_dither_matrix_simulated_annealing[ordered_dither_y+ordered_dither_x])>layersum)block_8_px |= or_bit;
ordered_dither_y++;
#endif
#ifdef ENABLE_SPRITES
if(!sprites_constant_counter)
{
u8 i;
for(i=0;i<NR_SPRITES;i++)
if(GfxApiReadSprite(&Sprites[i]))block_8_px|=or_bit;
}else sprites_constant_counter--;
#endif
#ifdef ENABLE_SECOND_CONSOLE
#ifndef ENABLE_SECOND_CONSOLE_AFFINE
if((y_pos_screen>=SECOND_CONSOLE_LINE_START)&&((y_pos_screen)<SECOND_CONSOLE_LINE_END))
{
u8 the_char = (screen2[charpos_second_con +SECOND_CONSOLE_LINE_LENGTH* (((second_console_y>>8))>>3)]);
// u8 the_char = (screen2[charpos_second_con +SECOND_CONSOLE_LINE_LENGTH* (((second_console_y>>8)-SECOND_CONSOLE_LINE_START)>>3)]);
const u8 font_block8=pgm_read_byte(&os_font[((int)the_char << 3) + ( (second_console_x>>8) & 7)]);
if(font_block8 & (1<<((second_console_y>>8)&7)))
block_8_px|=or_bit;
// if(y_pos_screen&1)
// block_8_px|=or_bit;
second_console_y+=zoomY;
}
#else
if((y_pos_screen>=SECOND_CONSOLE_LINE_START)&&((y_pos_screen)<SECOND_CONSOLE_LINE_END))
{
u8 charpos_second_con = (second_console_x_affine>>11);
if(charpos_second_con>SECOND_CONSOLE_LINE_LENGTH)charpos_second_con=SECOND_CONSOLE_LINE_LENGTH-1;
u8 the_char = (screen2[charpos_second_con +(SECOND_CONSOLE_LINE_LENGTH)* (((second_console_y>>8))>>3)]);
const u8 font_block8=pgm_read_byte(&os_font[((int)the_char << 3) + ( (second_console_x_affine>>8) & 7)]);
if(font_block8 & (1<<((second_console_y>>8)&7)))
block_8_px|=or_bit;
second_console_y+=zoomY;
second_console_x_affine+=zoomX2;
}
#endif
#endif
#ifdef ENABLE_LINEDRAWING
if(linebuffer[y_pos_screen]&line_cur_bit)block_8_px|=or_bit;;
#endif
or_bit<<=1;
#ifdef INTERLEAVE
if(clock_i2c) // we use the render engine as "delay loop" for the i2c...
{
// os_i2c_dbg_high();
os_i2c_scl_low();
}
#endif
if(!or_bit)
{
#ifndef ENABLE_WIRE
if(clock_i2c)
{
os_i2c_sda_high();
os_i2c_scl_high();
asm volatile("nop");
asm volatile("nop");
asm volatile("nop");
asm volatile("nop");
os_i2c_scl_low();
// os_i2c_dbg_low();
}
#endif
#ifdef ENABLE_ORDERED_DITHERING
ordered_dither_y=0;
#endif
or_bit=1;
#ifdef ENABLE_CONSOLE
if((y_pos_screen>=CONSOLE_LINE_START)&&(y_pos_screen<CONSOLE_LINE_END))
{
u8 the_char = (screen[charpos +16* ((y_pos_screen-CONSOLE_LINE_START)>>3)]);
#ifdef ENABLE_CONSOLE0_FONT_SWITCHING
long long addr=pgm_get_far_address(os_font);
addr+=((long long)the_char << 3) + (x_pos_screen & 7);
addr+=font_adress_console_0;
#endif
#ifdef ENABLE_CONSOLE_BIT7_INVERT
u8 xor_mask=(the_char&0x80)?255:0;
the_char&=0x7f;
#endif
block_8_px |=
#ifndef ENABLE_CONSOLE0_FONT_SWITCHING
pgm_read_byte(&os_font[((int)the_char << 3) + (x_pos_screen & 7)])
#else
pgm_read_byte_far(addr)
#endif
#ifdef ENABLE_CONSOLE_BIT7_INVERT
^xor_mask
#endif
;
}
#endif
#ifdef INTERLEAVE
i2c_data_out=block_8_px;
clock_i2c=1;
#else
os_i2c_write_byte(block_8_px);
#endif
block_8_px = 0;
#ifdef ENABLE_LAYERS
if(!layers_constant_counter)
{
u16 min=layers[0].SkipCounter;
u8 i;
for(i=1;i<NR_LAYERS;i++)
{
if(layers[i].SkipCounter<min)min=layers[i].SkipCounter;
}
if(min)
{
layers_constant_counter=min;
for(i=0;i<NR_LAYERS;i++)
layers[i].SkipCounter-=layers_constant_counter;
}
}
#endif
#ifdef ENABLE_SPRITES
if(!sprites_constant_counter)
{
u16 min=Sprites[0].SkipCounter;
u8 i;
for(i=1;i<NR_SPRITES;i++)
{
if(Sprites[i].SkipCounter<min)min=Sprites[i].SkipCounter;
}
if(min)
{
sprites_constant_counter=min;
for(i=0;i<NR_SPRITES;i++)
Sprites[i].SkipCounter-=sprites_constant_counter;
}
}
#endif
} // ende 8 pixel block
} // ende y schleife
#ifdef ENABLE_WIRE
wire_cnt++;
if (wire_cnt==3)
{
wire_cnt=0;
Wire.endTransmission();
Wire.beginTransmission(WIRE_SCREEN_ADDRESS);
Wire.write(0x40);
}
#endif
} // ende x schleife
#ifdef INTERLEAVE
os_i2c_write_byte(i2c_data_out);
#endif
os_i2c_stop();
#ifdef ENABLE_ATTINY_POWER_MANAGER
_manage_battery();
#endif
}
#undef INTERLEAVE
#ifdef DISABLE_HALFTONE
#undef DISABLE_HALFTONE
#endif
#undef STRINGNIZE
#undef STRINGNIZE_NX
#pragma GCC pop_options