-/*\r
- Gijutsu-Hyoron-Sha Babbage-2nd Emulator 'eBabbage-2nd'\r
-\r
- Author : Takeda.Toshiya\r
- Date : 2009.12.26 -\r
-\r
- [ display ]\r
-*/\r
-\r
-#include "display.h"\r
-#include "../../fileio.h"\r
-\r
-static const int pat_7seg_led[58][34] = {\r
- {0,6,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,2},\r
- {0,6,6,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,2,2},\r
- {0,6,6,6,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,2,2,2},\r
- {0,6,6,6,6,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,2,2,2,2},\r
- {0,6,6,6,6,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,2,2,2,2},\r
- {0,6,6,6,6,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,2,2,2,2},\r
- {0,6,6,6,6,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,2,2,2,2},\r
- {0,6,6,6,6,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,2,2,2,2},\r
- {0,6,6,6,6,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,2,2,2,2},\r
- {0,6,6,6,6,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,2,2,2,2},\r
- {0,6,6,6,6,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,2,2,2,2},\r
- {0,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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- memset(seg, 0, sizeof(seg));\r
- ls373 = 0;\r
- pio_7seg = pio_8bit = 0;\r
- \r
- // register event\r
- register_vline_event(this);\r
-}\r
-\r
-void DISPLAY::event_vline(int v, int clock)\r
-{\r
- if(!v) {\r
- memset(seg, 0, sizeof(seg));\r
- }\r
- for(int i = 0; i < 6; i++) {\r
- if(pio_7seg & (1 << i)) {\r
- for(int j = 0; j < 7; j++) {\r
- if(ls373 & (1 << j)) {\r
- seg[i][j]++;\r
- }\r
- }\r
- }\r
- }\r
-}\r
-\r
-void DISPLAY::write_signal(int id, uint32 data, uint32 mask)\r
-{\r
- if(id == SIG_DISPLAY_7SEG_LED) {\r
- if((pio_7seg & 0x80) && !(data & 0x80)) {\r
- ls373 = pio_7seg & 0x7f;\r
- }\r
- pio_7seg = data;\r
- } else if(id == SIG_DISPLAY_8BIT_LED) {\r
- pio_8bit = data;\r
- }\r
-}\r
-\r
-void DISPLAY::draw_screen()\r
-{\r
- // draw leds\r
- scrntype col_h, col_l;\r
- scrntype col[8];\r
- \r
- col_h = RGB_COLOR(255, 0, 0);\r
- col_l = RGB_COLOR(107, 0, 0);\r
- col[0] = RGB_COLOR(82, 8, 16);\r
- \r
- for(int i = 0; i < 6; i++) {\r
- for(int j = 0; j < 7; j++) {\r
- col[j + 1] = (seg[i][j] > 8) ? col_h : col_l;\r
- }\r
- for(int y = 0; y < 58; y++) {\r
- scrntype* dest = emu->screen_buffer(leds[i].y + y) + leds[i].x;\r
- for(int x = 0; x < 34; x++) {\r
- dest[x] = col[pat_7seg_led[y][x]];\r
- }\r
- }\r
- }\r
- for(int i = 0; i < 8; i++) {\r
- col[1] = (pio_8bit & (1 << i)) ? col_h : col_l;\r
- for(int y = 0; y < 17; y++) {\r
- scrntype* dest = emu->screen_buffer(leds[i + 6].y + y) + leds[i + 6].x;\r
- for(int x = 0; x < 17; x++) {\r
- dest[x] = col[pat_8bit_led[y][x]];\r
- }\r
- }\r
- }\r
-}\r
-\r
+/*
+ Gijutsu-Hy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,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,3,3,3,0},
+ {5,5,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,3,3,0},
+ {5,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,3,0}
+};
+
+static const int pat_8bit_led[17][17] = {
+ {0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0},
+ {0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0},
+ {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
+ {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
+ {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
+ {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
+ {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
+ {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
+ {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
+ {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
+ {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
+ {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
+ {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
+ {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
+ {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
+ {0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0},
+ {0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0}
+};
+
+void DISPLAY::initialize()
+{
+ memset(seg, 0, sizeof(seg));
+ ls373 = 0;
+ pio_7seg = pio_8bit = 0;
+
+ // register event
+ register_vline_event(this);
+}
+
+void DISPLAY::event_vline(int v, int clock)
+{
+ if(!v) {
+ memset(seg, 0, sizeof(seg));
+ }
+ for(int i = 0; i < 6; i++) {
+ if(pio_7seg & (1 << i)) {
+ for(int j = 0; j < 7; j++) {
+ if(ls373 & (1 << j)) {
+ seg[i][j]++;
+ }
+ }
+ }
+ }
+}
+
+void DISPLAY::write_signal(int id, uint32_t data, uint32_t mask)
+{
+ if(id == SIG_DISPLAY_7SEG_LED) {
+ if((pio_7seg & 0x80) && !(data & 0x80)) {
+ ls373 = pio_7seg & 0x7f;
+ }
+ pio_7seg = data;
+ } else if(id == SIG_DISPLAY_8BIT_LED) {
+ pio_8bit = data;
+ }
+}
+
+void DISPLAY::draw_screen()
+{
+ // draw 7-seg LEDs
+ scrntype_t col_h, col_l;
+ scrntype_t col[8];
+
+ col_h = RGB_COLOR(255, 0, 0);
+ col_l = RGB_COLOR(107, 0, 0);
+ col[0] = RGB_COLOR(82, 8, 16);
+
+ for(int i = 0; i < 6; i++) {
+ for(int j = 0; j < 7; j++) {
+ col[j + 1] = (seg[i][j] > 8) ? col_h : col_l;
+ }
+ for(int y = 0; y < 58; y++) {
+ scrntype_t* dest = emu->get_screen_buffer(vm_ranges[i].y + y) + vm_ranges[i].x;
+ for(int x = 0; x < 34; x++) {
+ dest[x] = col[pat_7seg_led[y][x]];
+ }
+ }
+ }
+ for(int i = 0; i < 8; i++) {
+ col[1] = (pio_8bit & (1 << i)) ? col_h : col_l;
+ for(int y = 0; y < 17; y++) {
+ scrntype_t* dest = emu->get_screen_buffer(vm_ranges[i + 6].y + y) + vm_ranges[i + 6].x;
+ for(int x = 0; x < 17; x++) {
+ dest[x] = col[pat_8bit_led[y][x]];
+ }
+ }
+ }
+}
+
+#define STATE_VERSION 1
+
+bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
+{
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
+ }
+ if(!state_fio->StateCheckInt32(this_device_id)) {
+ return false;
+ }
+ state_fio->StateBuffer(seg, sizeof(seg), 1);
+ state_fio->StateUint8(ls373);
+ state_fio->StateUint8(pio_7seg);
+ state_fio->StateUint8(pio_8bit);
+ return true;
+}
+}