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,4,4,4,4,4,4,4,4,4,4,0,3,3,3,0},
69 {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},
70 {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}
73 static const int pat_8bit_led[17][17] = {
74 {0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0},
75 {0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0},
76 {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
77 {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
78 {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
79 {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
80 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
81 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
82 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
83 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
84 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
85 {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
86 {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
87 {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
88 {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
89 {0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0},
90 {0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0}
93 void DISPLAY::initialize()
95 memset(seg, 0, sizeof(seg));
97 pio_7seg = pio_8bit = 0;
100 register_vline_event(this);
103 void DISPLAY::event_vline(int v, int clock)
106 memset(seg, 0, sizeof(seg));
108 for(int i = 0; i < 6; i++) {
109 if(pio_7seg & (1 << i)) {
110 for(int j = 0; j < 7; j++) {
111 if(ls373 & (1 << j)) {
119 void DISPLAY::write_signal(int id, uint32_t data, uint32_t mask)
121 if(id == SIG_DISPLAY_7SEG_LED) {
122 if((pio_7seg & 0x80) && !(data & 0x80)) {
123 ls373 = pio_7seg & 0x7f;
126 } else if(id == SIG_DISPLAY_8BIT_LED) {
131 void DISPLAY::draw_screen()
134 scrntype_t col_h, col_l;
137 col_h = RGB_COLOR(255, 0, 0);
138 col_l = RGB_COLOR(107, 0, 0);
139 col[0] = RGB_COLOR(82, 8, 16);
141 for(int i = 0; i < 6; i++) {
142 for(int j = 0; j < 7; j++) {
143 col[j + 1] = (seg[i][j] > 8) ? col_h : col_l;
145 for(int y = 0; y < 58; y++) {
146 scrntype_t* dest = emu->get_screen_buffer(vm_ranges[i].y + y) + vm_ranges[i].x;
147 for(int x = 0; x < 34; x++) {
148 dest[x] = col[pat_7seg_led[y][x]];
152 for(int i = 0; i < 8; i++) {
153 col[1] = (pio_8bit & (1 << i)) ? col_h : col_l;
154 for(int y = 0; y < 17; y++) {
155 scrntype_t* dest = emu->get_screen_buffer(vm_ranges[i + 6].y + y) + vm_ranges[i + 6].x;
156 for(int x = 0; x < 17; x++) {
157 dest[x] = col[pat_8bit_led[y][x]];
163 #define STATE_VERSION 1
165 bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
167 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
170 if(!state_fio->StateCheckInt32(this_device_id)) {
173 state_fio->StateBuffer(seg, sizeof(seg), 1);
174 state_fio->StateUint8(ls373);
175 state_fio->StateUint8(pio_7seg);
176 state_fio->StateUint8(pio_8bit);