Indicator.java
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13: package xeij;
14:
15: import java.awt.*;
16: import java.awt.image.*;
17: import java.util.*;
18: import javax.swing.*;
19:
20: public class Indicator {
21:
22:
23:
24:
25: public static final int IND_MPU_X = 0;
26: public static final int IND_CLOCK_X = 10;
27: public static final int IND_RATIO_X = 19;
28: public static final int IND_COLS = 25;
29: public static final int IND_FONT_WIDTH = 6;
30: public static final int IND_FONT_HEIGHT = 8;
31: public static final int IND_PADDING_LEFT = 6;
32: public static final int IND_PADDING_RIGHT = 6;
33: public static final int IND_PADDING_TOP = 3;
34: public static final int IND_PADDING_BOTTOM = 2;
35: public static final int IND_WIDTH = IND_PADDING_LEFT + IND_FONT_WIDTH * IND_COLS + IND_PADDING_RIGHT;
36: public static final int IND_HEIGHT = IND_PADDING_TOP + IND_FONT_HEIGHT + IND_PADDING_BOTTOM;
37: public static final int IND_BACK_GROUND = LnF.LNF_RGB[0];
38: public static final int IND_COLOR_00 = LnF.LNF_RGB[14];
39: public static final int IND_COLOR_20 = 0xff00ffff;
40: public static final int IND_COLOR_40 = 0xff00ff00;
41: public static final int IND_COLOR_60 = 0xffffff00;
42: public static final int IND_COLOR_80 = 0xffff0000;
43:
44: public static int indLastMPU;
45:
46: public static BufferedImage indImage;
47: public static int[] indBitmap;
48: public static Box indBox;
49:
50: public static void indInit () {
51: indLastMPU = 0;
52:
53: indImage = new BufferedImage (IND_WIDTH, IND_HEIGHT, BufferedImage.TYPE_INT_RGB);
54: indBitmap = ((DataBufferInt) indImage.getRaster ().getDataBuffer ()).getData ();
55: Arrays.fill (indBitmap, IND_BACK_GROUND);
56: indBox = ComponentFactory.setFixedSize (
57: new Box (BoxLayout.LINE_AXIS) {
58: @Override public void paint (Graphics g) {
59: g.drawImage (indImage, 0, 0, null);
60: }
61: @Override protected void paintComponent (Graphics g) {
62: }
63: @Override protected void paintBorder (Graphics g) {
64: }
65: @Override protected void paintChildren (Graphics g) {
66: }
67: @Override public void update (Graphics g) {
68: }
69: },
70: IND_WIDTH, IND_HEIGHT);
71: }
72:
73: public static void indUpdate (double actualPercent) {
74:
75:
76:
77:
78: if (indLastMPU != XEiJ.currentMPU) {
79: indLastMPU = XEiJ.currentMPU;
80: int color = IND_COLOR_00;
81: String s = Model.mpuNameOf (XEiJ.currentMPU);
82: int l = s.length ();
83: for (int i = 0; i < 9; i++) {
84: indPutChar (IND_MPU_X + i, i < l ? s.charAt (i) : ' ', color);
85: }
86: }
87:
88: {
89: int color = IND_COLOR_00;
90: int t = XEiJ.FMT_BCD4[Math.max (0, Math.min (9999, (int) (10.0 * XEiJ.mpuCurrentMHz + 0.5)))];
91: indPutChar (IND_CLOCK_X + 0, t < 0x1000 ? ' ' : (t >> 12) + '0', color);
92: indPutChar (IND_CLOCK_X + 1, t < 0x0100 ? ' ' : ((t >> 8) & 15) + '0', color);
93: indPutChar (IND_CLOCK_X + 2, ((t >> 4) & 15) + '0', color);
94: indPutChar (IND_CLOCK_X + 3, '.', color);
95: indPutChar (IND_CLOCK_X + 4, ( t & 15) + '0', color);
96: indPutChar (IND_CLOCK_X + 5, 'M', color);
97: indPutChar (IND_CLOCK_X + 6, 'H', color);
98: indPutChar (IND_CLOCK_X + 7, 'z', color);
99: }
100:
101: {
102: int t = XEiJ.FMT_BCD4[Math.max (0, Math.min (9999, (int) (10.0 * actualPercent + 0.5)))];
103: int color = (t < 0x0200 ? IND_COLOR_00 :
104: t < 0x0400 ? IND_COLOR_20 :
105: t < 0x0600 ? IND_COLOR_40 :
106: t < 0x0800 ? IND_COLOR_60 :
107: IND_COLOR_80);
108: indPutChar (IND_RATIO_X + 0, t < 0x1000 ? ' ' : (t >> 12) + '0', color);
109: indPutChar (IND_RATIO_X + 1, t < 0x0100 ? ' ' : ((t >> 8) & 15) + '0', color);
110: indPutChar (IND_RATIO_X + 2, ((t >> 4) & 15) + '0', color);
111: indPutChar (IND_RATIO_X + 3, '.', color);
112: indPutChar (IND_RATIO_X + 4, ( t & 15) + '0', color);
113: indPutChar (IND_RATIO_X + 5, '%', color);
114: }
115: indBox.repaint ();
116: }
117:
118: public static void indPutChar (int col, int c, int color) {
119: if (IND_FONT_HEIGHT == 8) {
120: int src = IND_FONT_HEIGHT * c;
121: int dst = IND_PADDING_LEFT + IND_FONT_WIDTH * col + IND_WIDTH * IND_PADDING_TOP;
122: for (int v = 0; v < IND_FONT_HEIGHT; v++) {
123: int t = FontPage.Lcd.LCD6X8_FONT[src] << (32 - 8);
124: for (int u = 0; u < IND_FONT_WIDTH; u++) {
125: indBitmap[dst + u] = t < 0 ? color : IND_BACK_GROUND;
126: t <<= 1;
127: }
128: src++;
129: dst += IND_WIDTH;
130: }
131: } else {
132: int src = 0x00fef400 - 0x00fc0000 + IND_FONT_HEIGHT * c;
133: int dst = IND_PADDING_LEFT + IND_FONT_WIDTH * col + IND_WIDTH * IND_PADDING_TOP;
134: for (int v = 0; v < IND_FONT_HEIGHT; v++) {
135: int t = ROM.iplrom16scsi256[src] << (32 - 8);
136: for (int u = 0; u < IND_FONT_WIDTH; u++) {
137: indBitmap[dst + u] = t < 0 ? color : IND_BACK_GROUND;
138: t <<= 1;
139: }
140: src++;
141: dst += IND_WIDTH;
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: public static final char[] IND_ASCII_3X5 = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\u2482\u5a00\u5f7d\u3c9e\u5c9d\u6cae\u2400\u1491\u4494\u0aa8\u05d0\22\u01c0\2\u02a0\u7b6f\u2492\u73e7\u73cf\u5bc9\u79cf\u79ef\u7249\u7bef\u7bcf\u0410\u0412\u1511\u0e38\u4454\u6282\u2be3\u2bed\u6bae\u3923\u6b6e\u79e7\u79e4\u396b\u5bed\u7497\u124e\u5bad\u4927\u5fed\u6b6d\u2b6a\u6ba4\u2b7b\u6bad\u388e\u7492\u5b6f\u5b6a\u5bfd\u5aad\u5a92\u72a7\u3493\u0888\u6496\u2a00\7\u2200\u076b\u4d6e\u0723\u176b\u0773\u3e92\u3bce\u4d6d\u2092\u104e\u4bb5\u6492\u0dfd\u0d6d\u056a\u0d74\u0759\u0724\u068e\u2e91\u0b6b\u0b6a\u0bfb\u0a95\u0b54\u0e57\u1591\u2412\u44d4\u7000".toCharArray ();
724:
725: }