OSDN Git Service

[VM] TRY:Use namespace {VMNAME} to separate around VMs. This feature still apply...
[csp-qt/common_source_project-fm7.git] / source / src / vm / babbage2nd / display.cpp
1 /*
2         Gijutsu-Hyoron-Sha Babbage-2nd Emulator 'eBabbage-2nd'
3
4         Author : Takeda.Toshiya
5         Date   : 2009.12.26 -
6
7         [ display ]
8 */
9
10 #include "display.h"
11 namespace BABBAGE2ND {
12 static const int pat_7seg_led[58][34] = {
13         {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},
14         {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},
15         {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},
16         {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},
17         {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},
18         {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},
19         {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},
20         {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},
21         {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},
22         {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},
23         {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},
24         {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},
25         {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},
26         {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},
27         {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},
28         {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},
29         {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},
30         {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},
31         {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},
32         {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},
33         {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},
34         {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},
35         {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},
36         {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},
37         {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},
38         {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},
39         {0,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,0,0,2,2,2},
40         {0,6,6,0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,0,2,2},
41         {0,6,0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,0,2},
42         {5,0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,0,3,0},
43         {5,5,0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,0,3,3,0},
44         {5,5,5,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,3,3,3,0},
45         {5,5,5,5,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,3,3,3,3,0},
46         {5,5,5,5,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,3,3,3,3,0},
47         {5,5,5,5,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,3,3,3,3,0},
48         {5,5,5,5,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,3,3,3,3,0},
49         {5,5,5,5,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,3,3,3,3,0},
50         {5,5,5,5,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,3,3,3,3,0},
51         {5,5,5,5,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,3,3,3,3,0},
52         {5,5,5,5,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,3,3,3,3,0},
53         {5,5,5,5,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,3,3,3,3,0},
54         {5,5,5,5,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,3,3,3,3,0},
55         {5,5,5,5,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,3,3,3,3,0},
56         {5,5,5,5,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,3,3,3,3,0},
57         {5,5,5,5,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,3,3,3,3,0},
58         {5,5,5,5,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,3,3,3,3,0},
59         {5,5,5,5,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,3,3,3,3,0},
60         {5,5,5,5,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,3,3,3,3,0},
61         {5,5,5,5,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,3,3,3,3,0},
62         {5,5,5,5,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,3,3,3,3,0},
63         {5,5,5,5,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,3,3,3,3,0},
64         {5,5,5,5,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,3,3,3,3,0},
65         {5,5,5,5,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,3,3,3,3,0},
66         {5,5,5,5,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,3,3,3,3,0},
67         {5,5,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,0,3,3,3,3,0},
68         {5,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,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}
71 };
72
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}
91 };
92
93 void DISPLAY::initialize()
94 {
95         memset(seg, 0, sizeof(seg));
96         ls373 = 0;
97         pio_7seg = pio_8bit = 0;
98         
99         // register event
100         register_vline_event(this);
101 }
102
103 void DISPLAY::event_vline(int v, int clock)
104 {
105         if(!v) {
106                 memset(seg, 0, sizeof(seg));
107         }
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)) {
112                                         seg[i][j]++;
113                                 }
114                         }
115                 }
116         }
117 }
118
119 void DISPLAY::write_signal(int id, uint32_t data, uint32_t mask)
120 {
121         if(id == SIG_DISPLAY_7SEG_LED) {
122                 if((pio_7seg & 0x80) && !(data & 0x80)) {
123                         ls373 = pio_7seg & 0x7f;
124                 }
125                 pio_7seg = data;
126         } else if(id == SIG_DISPLAY_8BIT_LED) {
127                 pio_8bit = data;
128         }
129 }
130
131 void DISPLAY::draw_screen()
132 {
133         // draw 7-seg LEDs
134         scrntype_t col_h, col_l;
135         scrntype_t col[8];
136         
137         col_h = RGB_COLOR(255, 0, 0);
138         col_l = RGB_COLOR(107, 0, 0);
139         col[0] = RGB_COLOR(82, 8, 16);
140         
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;
144                 }
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]];
149                         }
150                 }
151         }
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]];
158                         }
159                 }
160         }
161 }
162
163 #define STATE_VERSION   1
164
165 bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
166 {
167         if(!state_fio->StateCheckUint32(STATE_VERSION)) {
168                 return false;
169         }
170         if(!state_fio->StateCheckInt32(this_device_id)) {
171                 return false;
172         }
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);
177         return true;
178 }
179 }