OSDN Git Service

[VM][WIP] Pre-process to apply new state framework.Still not buildable.
[csp-qt/common_source_project-fm7.git] / source / src / vm / ys6464a / display.cpp
1 /*
2         SHINKO SANGYO YS-6464A Emulator 'eYS-6464A'
3
4         Author : Takeda.Toshiya
5         Date   : 2009.12.30 -
6
7         [ display ]
8 */
9
10 #include "display.h"
11
12 static const int pat_7seg_led[40][28] = {
13         {0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0},
14         {0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
15         {0,0,0,0,0,6,6,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,2,2},
16         {0,0,0,0,0,6,6,6,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,2,2,2},
17         {0,0,0,0,0,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2},
18         {0,0,0,0,0,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2},
19         {0,0,0,0,0,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2},
20         {0,0,0,0,0,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2},
21         {0,0,0,0,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,0},
22         {0,0,0,0,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,0},
23         {0,0,0,0,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,0},
24         {0,0,0,0,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,0},
25         {0,0,0,0,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,0},
26         {0,0,0,0,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,0},
27         {0,0,0,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,0,0},
28         {0,0,0,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,0,0},
29         {0,0,0,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,0,0},
30         {0,0,0,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,0,0},
31         {0,0,0,6,6,6,0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,0,2,2,2,0,0},
32         {0,0,0,6,6,0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,0,2,2,0,0},
33         {0,0,5,5,0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,0,3,3,0,0,0},
34         {0,0,5,5,5,0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,0,3,3,3,0,0,0},
35         {0,0,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,3,0,0,0},
36         {0,0,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,3,0,0,0},
37         {0,0,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,3,0,0,0},
38         {0,0,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,3,0,0,0},
39         {0,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,3,0,0,0,0},
40         {0,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,3,0,0,0,0},
41         {0,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,3,0,0,0,0},
42         {0,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,3,0,0,0,0},
43         {0,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,3,0,0,0,0},
44         {0,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,3,0,0,0,0},
45         {5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,3,0,0,0,0,0},
46         {5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,3,0,0,0,0,0},
47         {5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,3,0,0,0,0,0},
48         {5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,3,0,0,0,0,0},
49         {5,5,5,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,3,3,3,0,0,0,0,0},
50         {5,5,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,3,3,0,8,8,8,0},
51         {0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,0,8,8,8,8,8},
52         {0,0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,0,0,0,8,8,8,0},
53 };
54
55 void DISPLAY::initialize()
56 {
57         memset(seg, 0, sizeof(seg));
58         pb = pc = 0;
59         
60         // register event
61         register_vline_event(this);
62 }
63
64 void DISPLAY::event_vline(int v, int clock)
65 {
66         if(!v) {
67                 memset(seg, 0, sizeof(seg));
68         }
69         switch(pc & 0xf0) {
70         case 0x80:
71         case 0x90:
72         case 0xa0:
73         case 0xb0:
74         case 0xc0:
75         case 0xd0:
76                 for(int i = 0; i < 8; i++) {
77                         if(~pb & (1 << i)) {
78                                 seg[(pc >> 4) & 7][i]++;
79                         }
80                 }
81                 break;
82         }
83 }
84
85 void DISPLAY::write_signal(int id, uint32_t data, uint32_t mask)
86 {
87         if(id == SIG_DISPLAY_PORT_B) {
88                 pb = data;
89         } else if(id == SIG_DISPLAY_PORT_C) {
90                 pc = data & 0xf0;
91         }
92 }
93
94 void DISPLAY::draw_screen()
95 {
96         // draw 7-seg LEDs
97         scrntype_t col_h, col_l;
98         scrntype_t col[9];
99         
100         col_h = RGB_COLOR(255, 0, 0);
101         col_l = RGB_COLOR(107, 0, 0);
102         col[0] = RGB_COLOR(38, 8, 0);
103         
104         for(int i = 0; i < 6; i++) {
105                 for(int j = 0; j < 8; j++) {
106                         col[j + 1] = (seg[i][j] > 8) ? col_h : col_l;
107                 }
108                 for(int y = 0; y < 40; y++) {
109                         scrntype_t* dest = emu->get_screen_buffer(vm_ranges[i].y + y) + vm_ranges[i].x;
110                         for(int x = 0; x < 28; x++) {
111                                 dest[x] = col[pat_7seg_led[y][x]];
112                         }
113                 }
114         }
115 }
116
117 #define STATE_VERSION   1
118
119 #include "../../statesub.h"
120
121 void DISPLAY::decl_state()
122 {
123         enter_decl_state(STATE_VERSION);
124         
125         DECL_STATE_ENTRY_2D_ARRAY(seg, 6, 8);
126         DECL_STATE_ENTRY_UINT8(pb);
127         DECL_STATE_ENTRY_UINT8(pc);
128         
129         leave_decl_state();
130 }
131
132 void DISPLAY::save_state(FILEIO* state_fio)
133 {
134         if(state_entry != NULL) {
135                 state_entry->save_state(state_fio);
136         }
137 //      state_fio->FputUint32(STATE_VERSION);
138 //      state_fio->FputInt32(this_device_id);
139         
140 //      state_fio->Fwrite(seg, sizeof(seg), 1);
141 //      state_fio->FputUint8(pb);
142 //      state_fio->FputUint8(pc);
143 }
144
145 bool DISPLAY::load_state(FILEIO* state_fio)
146 {
147         bool mb = false;
148         if(state_entry != NULL) {
149                 mb = state_entry->load_state(state_fio);
150         }
151         if(!mb) {
152                 return false;
153         }
154 //      if(state_fio->FgetUint32() != STATE_VERSION) {
155 //              return false;
156 //      }
157 //      if(state_fio->FgetInt32() != this_device_id) {
158 //              return false;
159 //      }
160 //      state_fio->Fread(seg, sizeof(seg), 1);
161 //      pb = state_fio->FgetUint8();
162 //      pc = state_fio->FgetUint8();
163         return true;
164 }
165
166 bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
167 {
168         if(!state_fio->StateCheckUint32(STATE_VERSION)) {
169                 return false;
170         }
171         if(!state_fio->StateCheckInt32(this_device_id)) {
172                 return false;
173         }
174         state_fio->StateBuffer(seg, sizeof(seg), 1);
175         state_fio->StateUint8(pb);
176         state_fio->StateUint8(pc);
177         return true;
178 }