src/mess/machine/upd1990a.c
| r4647 | r4648 | |
| 5 | 5 | NEC uPD1990AC CMOS Digital Integrated Circuit |
| 6 | 6 | Serial I/O Calendar & Clock |
| 7 | 7 | CMOS LSI |
| 8 | | |
| 9 | | Very preliminary emulation |
| 10 | | |
| 11 | | TODO: |
| 12 | | - implement Set Clock mode |
| 13 | | - implement TEST Mode |
| 14 | | - what about data_in? |
| 15 | 8 | |
| 16 | 9 | *********************************************************************/ |
| 17 | 10 | |
| 11 | /* |
| 12 | |
| 13 | TODO: |
| 14 | |
| 15 | - set clock mode |
| 16 | - test mode |
| 17 | - clock advance (currently it just reads the system time) |
| 18 | |
| 19 | */ |
| 20 | |
| 18 | 21 | #include "driver.h" |
| 19 | 22 | #include "upd1990a.h" |
| 20 | 23 | |
| 21 | | #define UPD1990AC_XTAL 32768 |
| 24 | /*************************************************************************** |
| 25 | PARAMETERS |
| 26 | ***************************************************************************/ |
| 22 | 27 | |
| 28 | #define LOG 0 |
| 29 | |
| 30 | enum |
| 31 | { |
| 32 | UPD1990A_MODE_REGISTER_HOLD = 0, |
| 33 | UPD1990A_MODE_SHIFT, |
| 34 | UPD1990A_MODE_TIME_SET, |
| 35 | UPD1990A_MODE_TIME_READ, |
| 36 | UPD1990A_MODE_TP_64HZ_SET, |
| 37 | UPD1990A_MODE_TP_256HZ_SET, |
| 38 | UPD1990A_MODE_TP_2048HZ_SET, |
| 39 | UPD1990A_MODE_TEST, |
| 40 | }; |
| 41 | |
| 23 | 42 | /*************************************************************************** |
| 24 | 43 | TYPE DEFINITIONS |
| 25 | 44 | ***************************************************************************/ |
| r4647 | r4648 | |
| 27 | 46 | typedef struct _upd1990a_t upd1990a_t; |
| 28 | 47 | struct _upd1990a_t |
| 29 | 48 | { |
| 49 | devcb_resolved_write_line out_data_func; |
| 30 | 50 | devcb_resolved_write_line out_tp_func; |
| 31 | 51 | |
| 32 | | UINT8 shift_reg[5]; /* 40 Bit Shift Register */ |
| 33 | | UINT8 data_in; |
| 34 | | UINT8 data_out; |
| 35 | | UINT8 shift_mode; |
| 36 | | UINT16 freq_divider; |
| 52 | UINT8 time_counter[5]; /* time counter */ |
| 53 | UINT8 shift_reg[5]; /* shift register */ |
| 54 | |
| 55 | int oe; /* output enable */ |
| 56 | int cs; /* chip select */ |
| 57 | int stb; /* strobe */ |
| 58 | int data_in; /* data in */ |
| 59 | int data_out; /* data out */ |
| 60 | int c; /* command */ |
| 61 | int clk; /* shift clock */ |
| 62 | int tp; /* time pulse */ |
| 37 | 63 | |
| 64 | /* timers */ |
| 65 | emu_timer *clock_timer; |
| 66 | emu_timer *data_out_timer; |
| 38 | 67 | emu_timer *tp_timer; |
| 39 | 68 | }; |
| 40 | 69 | |
| r4647 | r4648 | |
| 47 | 76 | assert(device != NULL); |
| 48 | 77 | assert(device->token != NULL); |
| 49 | 78 | assert(device->type == UPD1990A); |
| 50 | | |
| 51 | 79 | return (upd1990a_t *)device->token; |
| 52 | 80 | } |
| 53 | 81 | |
| r4647 | r4648 | |
| 58 | 86 | return (const upd1990a_interface *) device->static_config; |
| 59 | 87 | } |
| 60 | 88 | |
| 89 | INLINE UINT8 convert_to_bcd(int val) |
| 90 | { |
| 91 | return ((val / 10) << 4) | (val % 10); |
| 92 | } |
| 93 | |
| 61 | 94 | /*************************************************************************** |
| 62 | 95 | IMPLEMENTATION |
| 63 | 96 | ***************************************************************************/ |
| 64 | 97 | |
| 65 | | static UINT8 upd1990a_bcd( UINT8 val ) |
| 98 | /*------------------------------------------------- |
| 99 | upd1990a_oe_w - output enable write |
| 100 | -------------------------------------------------*/ |
| 101 | |
| 102 | WRITE_LINE_DEVICE_HANDLER( upd1990a_oe_w ) |
| 66 | 103 | { |
| 67 | | return ((val / 10) << 4) | (val % 10); |
| 104 | upd1990a_t *upd1990a = get_safe_token(device); |
| 105 | |
| 106 | upd1990a->oe = state; |
| 107 | |
| 108 | if (LOG) logerror("UPD1990A OE %u\n", state); |
| 68 | 109 | } |
| 69 | 110 | |
| 70 | | WRITE8_DEVICE_HANDLER( upd1990a_w ) |
| 111 | /*------------------------------------------------- |
| 112 | upd1990a_oe_w - output enable write |
| 113 | -------------------------------------------------*/ |
| 114 | |
| 115 | WRITE_LINE_DEVICE_HANDLER( upd1990a_cs_w ) |
| 71 | 116 | { |
| 72 | | UINT8 command = data & 0x07; |
| 73 | 117 | upd1990a_t *upd1990a = get_safe_token(device); |
| 74 | | mame_system_time curtime, *systime = &curtime; |
| 75 | | int i; |
| 76 | 118 | |
| 77 | | if (data & ~0x07) |
| 78 | | logerror("uPD1990AC expects only 3 bits data, found %d > 7\n", data); |
| 119 | upd1990a->cs = state; |
| 79 | 120 | |
| 80 | | mame_get_current_datetime(device->machine, &curtime); |
| 121 | if (LOG) logerror("UPD1990A CS %u\n", state); |
| 122 | } |
| 81 | 123 | |
| 82 | | /* |
| 83 | | c0 = command bit 0 |
| 84 | | c1 = command bit 1 |
| 85 | | c2 = command bit 2 |
| 124 | /*------------------------------------------------- |
| 125 | upd1990a_stb_w - strobe write |
| 126 | -------------------------------------------------*/ |
| 86 | 127 | |
| 87 | | c2 c1 c0 | Function |
| 88 | | ---------------------------- |
| 89 | | 0 0 0 | Register Hold (TEST Mode released) |
| 90 | | 0 0 1 | Register Shift |
| 91 | | 0 1 0 | Timer Set & Counter Hold |
| 92 | | 0 1 1 | Timer Read |
| 93 | | 1 0 0 | TP = 64Hz Set (TEST Mode released) |
| 94 | | 1 0 1 | TP = 256Hz Set (TEST Mode released) |
| 95 | | 1 1 0 | TP = 2048z Set (TEST Mode released) |
| 96 | | 1 1 1 | TEST Mode Set |
| 97 | | */ |
| 128 | WRITE_LINE_DEVICE_HANDLER( upd1990a_stb_w ) |
| 129 | { |
| 130 | upd1990a_t *upd1990a = get_safe_token(device); |
| 98 | 131 | |
| 99 | | switch (command) |
| 132 | if (LOG) logerror("UPD1990A STB %u\n", state); |
| 133 | |
| 134 | upd1990a->stb = state; |
| 135 | |
| 136 | if (upd1990a->cs && upd1990a->stb && !upd1990a->clk) |
| 100 | 137 | { |
| 101 | | case 0x00: |
| 102 | | upd1990a->shift_mode = 0; |
| 138 | switch (upd1990a->c) |
| 139 | { |
| 140 | case UPD1990A_MODE_REGISTER_HOLD: |
| 141 | if (LOG) logerror("UPD1990A Register Hold Mode\n"); |
| 142 | |
| 143 | /* enable time counter */ |
| 144 | timer_enable(upd1990a->clock_timer, 1); |
| 145 | |
| 146 | /* 1 Hz data out pulse */ |
| 147 | upd1990a->data_out = 1; |
| 148 | timer_adjust_periodic(upd1990a->data_out_timer, attotime_zero, 0, ATTOTIME_IN_HZ(1*2)); |
| 149 | |
| 150 | /* 64 Hz time pulse */ |
| 151 | timer_adjust_periodic(upd1990a->tp_timer, attotime_zero, 0, ATTOTIME_IN_HZ(64*2)); |
| 103 | 152 | break; |
| 104 | | case 0x01: |
| 105 | | upd1990a->shift_mode = 1; |
| 106 | | upd1990a->data_out = upd1990a->shift_reg[0] & 0x01; |
| 153 | |
| 154 | case UPD1990A_MODE_SHIFT: |
| 155 | if (LOG) logerror("UPD1990A Shift Mode\n"); |
| 156 | /* enable time counter */ |
| 157 | timer_enable(upd1990a->clock_timer, 1); |
| 158 | |
| 159 | /* 32 Hz time pulse */ |
| 160 | timer_adjust_periodic(upd1990a->tp_timer, attotime_zero, 0, ATTOTIME_IN_HZ(32*2)); |
| 107 | 161 | break; |
| 108 | | case 0x02: /* Set Clock */ |
| 109 | | upd1990a->shift_mode = 0; |
| 110 | | logerror("RTC Set Clock attempt\n"); |
| 111 | | /* Not implemented yet */ |
| 112 | | case 0x03: /* Read Clock */ |
| 113 | | upd1990a->shift_mode = 0; |
| 114 | | upd1990a->shift_reg[0] = upd1990a_bcd(systime->local_time.second); |
| 115 | | upd1990a->shift_reg[1] = upd1990a_bcd(systime->local_time.minute); |
| 116 | | upd1990a->shift_reg[2] = upd1990a_bcd(systime->local_time.hour); |
| 117 | | upd1990a->shift_reg[3] = upd1990a_bcd(systime->local_time.mday); |
| 118 | | upd1990a->shift_reg[4] = systime->local_time.weekday; |
| 119 | | upd1990a->shift_reg[4] |= systime->local_time.month << 4; |
| 120 | | for(i=0; i<5; i++) |
| 121 | | logerror("%d ", (upd1990a->shift_reg[i] & 0x0f) + ((upd1990a->shift_reg[i] & 0xf0)>>4)*10); |
| 122 | | logerror("\n"); |
| 162 | |
| 163 | case UPD1990A_MODE_TIME_SET: |
| 164 | { |
| 165 | int i; |
| 166 | |
| 167 | if (LOG) logerror("UPD1990A Time Set Mode not supported!\n"); |
| 168 | if (LOG) logerror("UPD1990A Shift Register %02x%02x%02x%02x%02x\n", upd1990a->shift_reg[4], upd1990a->shift_reg[3], upd1990a->shift_reg[2], upd1990a->shift_reg[1], upd1990a->shift_reg[0]); |
| 169 | |
| 170 | /* disable time counter */ |
| 171 | timer_enable(upd1990a->clock_timer, 0); |
| 172 | |
| 173 | /* load shift register data into time counter */ |
| 174 | for (i = 0; i < 5; i++) |
| 175 | { |
| 176 | upd1990a->time_counter[i] = upd1990a->shift_reg[i]; |
| 177 | } |
| 178 | |
| 179 | /* 32 Hz time pulse */ |
| 180 | timer_adjust_periodic(upd1990a->tp_timer, attotime_zero, 0, ATTOTIME_IN_HZ(32*2)); |
| 181 | } |
| 123 | 182 | break; |
| 124 | | case 0x04: |
| 125 | | upd1990a->freq_divider = 512; |
| 126 | | logerror("RTC Set TP 64Hz attempt\n"); |
| 183 | |
| 184 | case UPD1990A_MODE_TIME_READ: |
| 185 | { |
| 186 | mame_system_time curtime, *systime = &curtime; |
| 187 | int i; |
| 188 | |
| 189 | if (LOG) logerror("UPD1990A Time Read Mode\n"); |
| 190 | |
| 191 | /* enable time counter */ |
| 192 | timer_enable(upd1990a->clock_timer, 1); |
| 193 | |
| 194 | /* HACK: load time counter from system time */ |
| 195 | mame_get_current_datetime(device->machine, &curtime); |
| 196 | |
| 197 | upd1990a->time_counter[0] = convert_to_bcd(systime->local_time.second); |
| 198 | upd1990a->time_counter[1] = convert_to_bcd(systime->local_time.minute); |
| 199 | upd1990a->time_counter[2] = convert_to_bcd(systime->local_time.hour); |
| 200 | upd1990a->time_counter[3] = convert_to_bcd(systime->local_time.mday); |
| 201 | upd1990a->time_counter[4] = systime->local_time.weekday; |
| 202 | upd1990a->time_counter[4] |= systime->local_time.month << 4; |
| 203 | |
| 204 | /* load time counter data into shift register */ |
| 205 | for (i = 0; i < 5; i++) |
| 206 | { |
| 207 | upd1990a->shift_reg[i] = upd1990a->time_counter[i]; |
| 208 | } |
| 209 | |
| 210 | if (LOG) logerror("UPD1990A Shift Register %02x%02x%02x%02x%02x\n", upd1990a->shift_reg[4], upd1990a->shift_reg[3], upd1990a->shift_reg[2], upd1990a->shift_reg[1], upd1990a->shift_reg[0]); |
| 211 | |
| 212 | /* 512 Hz data out pulse */ |
| 213 | upd1990a->data_out = 1; |
| 214 | timer_adjust_periodic(upd1990a->data_out_timer, attotime_zero, 0, ATTOTIME_IN_HZ(512*2)); |
| 215 | |
| 216 | /* 32 Hz time pulse */ |
| 217 | timer_adjust_periodic(upd1990a->tp_timer, attotime_zero, 0, ATTOTIME_IN_HZ(32*2)); |
| 218 | } |
| 127 | 219 | break; |
| 128 | | case 0x05: |
| 129 | | upd1990a->freq_divider = 128; |
| 130 | | logerror("RTC Set TP 256Hz attempt\n"); |
| 220 | |
| 221 | case UPD1990A_MODE_TP_64HZ_SET: |
| 222 | if (LOG) logerror("UPD1990A TP = 64 Hz Set Mode\n"); |
| 223 | |
| 224 | /* 64 Hz time pulse */ |
| 225 | timer_adjust_periodic(upd1990a->tp_timer, attotime_zero, 0, ATTOTIME_IN_HZ(64*2)); |
| 131 | 226 | break; |
| 132 | | case 0x06: |
| 133 | | upd1990a->freq_divider = 16; |
| 134 | | logerror("RTC Set TP 2048Hz attempt\n"); |
| 227 | |
| 228 | case UPD1990A_MODE_TP_256HZ_SET: |
| 229 | if (LOG) logerror("UPD1990A TP = 256 Hz Set Mode\n"); |
| 230 | |
| 231 | /* 256 Hz time pulse */ |
| 232 | timer_adjust_periodic(upd1990a->tp_timer, attotime_zero, 0, ATTOTIME_IN_HZ(256*2)); |
| 135 | 233 | break; |
| 136 | | case 0x07: |
| 137 | | logerror("RTC TEST Mode attempt\n"); |
| 138 | | /* Not implemented yet */ |
| 139 | | break; |
| 140 | | } |
| 141 | 234 | |
| 142 | | if (command & 0x04 ) |
| 143 | | { |
| 144 | | UINT16 frequency = UPD1990AC_XTAL / upd1990a->freq_divider; |
| 235 | case UPD1990A_MODE_TP_2048HZ_SET: |
| 236 | if (LOG) logerror("UPD1990A TP = 2048 Hz Set Mode\n"); |
| 145 | 237 | |
| 146 | | logerror("TP freq %d \n", frequency); |
| 238 | /* 2048 Hz time pulse */ |
| 239 | timer_adjust_periodic(upd1990a->tp_timer, attotime_zero, 0, ATTOTIME_IN_HZ(2048*2)); |
| 240 | break; |
| 147 | 241 | |
| 148 | | timer_adjust_periodic(upd1990a->tp_timer, attotime_zero, 0, ATTOTIME_IN_HZ(frequency)); |
| 242 | case UPD1990A_MODE_TEST: |
| 243 | if (LOG) logerror("UPD1990A Test Mode not supported!\n"); |
| 244 | break; |
| 245 | } |
| 149 | 246 | } |
| 150 | 247 | } |
| 151 | 248 | |
| 249 | /*------------------------------------------------- |
| 250 | upd1990a_clk_w - shift clock write |
| 251 | -------------------------------------------------*/ |
| 152 | 252 | |
| 153 | | WRITE8_DEVICE_HANDLER( upd1990a_clk_w ) |
| 253 | WRITE_LINE_DEVICE_HANDLER( upd1990a_clk_w ) |
| 154 | 254 | { |
| 155 | 255 | upd1990a_t *upd1990a = get_safe_token(device); |
| 156 | 256 | |
| 157 | | if (upd1990a->shift_mode) |
| 257 | if (LOG) logerror("UPD1990A CLK %u\n", state); |
| 258 | |
| 259 | if (!upd1990a->clk && state) // rising edge |
| 158 | 260 | { |
| 159 | | /* Shift Register */ |
| 160 | | upd1990a->shift_reg[0] >>= 1; |
| 161 | | upd1990a->shift_reg[0] |= upd1990a->shift_reg[1] & 1 ? 0x80 : 0; |
| 162 | | upd1990a->shift_reg[1] >>= 1; |
| 163 | | upd1990a->shift_reg[1] |= upd1990a->shift_reg[2] & 1 ? 0x80 : 0; |
| 164 | | upd1990a->shift_reg[2] >>= 1; |
| 165 | | upd1990a->shift_reg[2] |= upd1990a->shift_reg[3] & 1 ? 0x80 : 0; |
| 166 | | upd1990a->shift_reg[3] >>= 1; |
| 167 | | upd1990a->shift_reg[3] |= upd1990a->shift_reg[4] & 1 ? 0x80 : 0; |
| 168 | | upd1990a->shift_reg[4] >>= 1; |
| 169 | | upd1990a->shift_reg[4] |= data & 0x10 ? 0x80 : 0; |
| 170 | | upd1990a->data_out = upd1990a->shift_reg[0] & 1; |
| 261 | if (upd1990a->c == UPD1990A_MODE_SHIFT) |
| 262 | { |
| 263 | if (upd1990a->oe) |
| 264 | { |
| 265 | upd1990a->data_out = BIT(upd1990a->shift_reg[0], 0); |
| 266 | |
| 267 | devcb_call_write_line(&upd1990a->out_data_func, upd1990a->data_out); |
| 268 | |
| 269 | if (LOG) logerror("UPD1990A DATA OUT %u\n", upd1990a->data_out); |
| 270 | } |
| 271 | |
| 272 | upd1990a->shift_reg[0] >>= 1; |
| 273 | upd1990a->shift_reg[0] |= (BIT(upd1990a->shift_reg[1], 0) << 7); |
| 274 | |
| 275 | upd1990a->shift_reg[1] >>= 1; |
| 276 | upd1990a->shift_reg[1] |= (BIT(upd1990a->shift_reg[2], 0) << 7); |
| 277 | |
| 278 | upd1990a->shift_reg[2] >>= 1; |
| 279 | upd1990a->shift_reg[2] |= (BIT(upd1990a->shift_reg[3], 0) << 7); |
| 280 | |
| 281 | upd1990a->shift_reg[3] >>= 1; |
| 282 | upd1990a->shift_reg[3] |= (BIT(upd1990a->shift_reg[4], 0) << 7); |
| 283 | |
| 284 | upd1990a->shift_reg[4] >>= 1; |
| 285 | upd1990a->shift_reg[4] |= (upd1990a->data_in << 7); |
| 286 | } |
| 171 | 287 | } |
| 288 | |
| 289 | upd1990a->clk = state; |
| 172 | 290 | } |
| 173 | 291 | |
| 174 | | READ8_DEVICE_HANDLER( upd1990a_data_out_r ) |
| 292 | /*------------------------------------------------- |
| 293 | upd1990a_c0_w - command bit 0 write |
| 294 | -------------------------------------------------*/ |
| 295 | |
| 296 | WRITE_LINE_DEVICE_HANDLER( upd1990a_c0_w ) |
| 175 | 297 | { |
| 176 | 298 | upd1990a_t *upd1990a = get_safe_token(device); |
| 177 | 299 | |
| 178 | | return upd1990a->data_out; |
| 300 | if (LOG) logerror("UPD1990A C0 %u\n", state); |
| 301 | upd1990a->c = (upd1990a->c & 0x06) | state; |
| 179 | 302 | } |
| 180 | 303 | |
| 304 | /*------------------------------------------------- |
| 305 | upd1990a_c1_w - command bit 1 write |
| 306 | -------------------------------------------------*/ |
| 307 | |
| 308 | WRITE_LINE_DEVICE_HANDLER( upd1990a_c1_w ) |
| 309 | { |
| 310 | upd1990a_t *upd1990a = get_safe_token(device); |
| 311 | |
| 312 | if (LOG) logerror("UPD1990A C1 %u\n", state); |
| 313 | upd1990a->c = (upd1990a->c & 0x05) | (state << 1); |
| 314 | } |
| 315 | |
| 316 | /*------------------------------------------------- |
| 317 | upd1990a_c2_w - command bit 2 write |
| 318 | -------------------------------------------------*/ |
| 319 | |
| 320 | WRITE_LINE_DEVICE_HANDLER( upd1990a_c2_w ) |
| 321 | { |
| 322 | upd1990a_t *upd1990a = get_safe_token(device); |
| 323 | |
| 324 | if (LOG) logerror("UPD1990A C2 %u\n", state); |
| 325 | upd1990a->c = (upd1990a->c & 0x03) | (state << 2); |
| 326 | } |
| 327 | |
| 328 | /*------------------------------------------------- |
| 329 | upd1990a_data_w - data input write |
| 330 | -------------------------------------------------*/ |
| 331 | |
| 332 | WRITE_LINE_DEVICE_HANDLER( upd1990a_data_w ) |
| 333 | { |
| 334 | upd1990a_t *upd1990a = get_safe_token(device); |
| 335 | |
| 336 | if (LOG) logerror("UPD1990A DATA IN %u\n", state); |
| 337 | upd1990a->data_in = state; |
| 338 | } |
| 339 | |
| 340 | /*------------------------------------------------- |
| 341 | TIMER_CALLBACK( clock_tick ) |
| 342 | -------------------------------------------------*/ |
| 343 | |
| 344 | static TIMER_CALLBACK( clock_tick ) |
| 345 | { |
| 346 | const device_config *device = ptr; |
| 347 | upd1990a_t *upd1990a = get_safe_token(device); |
| 348 | |
| 349 | // TODO: advance clock |
| 350 | } |
| 351 | |
| 352 | /*------------------------------------------------- |
| 353 | TIMER_CALLBACK( tp_tick ) |
| 354 | -------------------------------------------------*/ |
| 355 | |
| 181 | 356 | static TIMER_CALLBACK( tp_tick ) |
| 182 | 357 | { |
| 183 | 358 | const device_config *device = ptr; |
| 184 | 359 | upd1990a_t *upd1990a = get_safe_token(device); |
| 185 | 360 | |
| 186 | | devcb_call_write_line(&upd1990a->out_tp_func, ASSERT_LINE); |
| 187 | | devcb_call_write_line(&upd1990a->out_tp_func, CLEAR_LINE); |
| 361 | if (LOG) logerror("UPD1990A TP %u\n", upd1990a->tp); |
| 362 | |
| 363 | devcb_call_write_line(&upd1990a->out_tp_func, upd1990a->tp); |
| 364 | |
| 365 | upd1990a->tp = !upd1990a->tp; |
| 188 | 366 | } |
| 189 | 367 | |
| 190 | | /* Untested save state support */ |
| 191 | | static void upd1990a_register_state_save(const device_config *device) |
| 368 | /*------------------------------------------------- |
| 369 | TIMER_CALLBACK( data_out_tick ) |
| 370 | -------------------------------------------------*/ |
| 371 | |
| 372 | static TIMER_CALLBACK( data_out_tick ) |
| 192 | 373 | { |
| 193 | | upd1990a_t* upd1990a = get_safe_token( device ); |
| 374 | const device_config *device = ptr; |
| 375 | upd1990a_t *upd1990a = get_safe_token(device); |
| 194 | 376 | |
| 195 | | state_save_register_global_array(device->machine, upd1990a->shift_reg); |
| 196 | | state_save_register_global(device->machine, upd1990a->data_in); |
| 197 | | state_save_register_global(device->machine, upd1990a->data_out); |
| 198 | | state_save_register_global(device->machine, upd1990a->shift_mode); |
| 199 | | state_save_register_global(device->machine, upd1990a->freq_divider); |
| 377 | if (LOG) logerror("UPD1990A DATA OUT %u\n", upd1990a->data_out); |
| 378 | |
| 379 | devcb_call_write_line(&upd1990a->out_data_func, upd1990a->data_out); |
| 380 | |
| 381 | upd1990a->data_out = !upd1990a->data_out; |
| 200 | 382 | } |
| 201 | 383 | |
| 384 | /*------------------------------------------------- |
| 385 | DEVICE_START( upd1990a ) |
| 386 | -------------------------------------------------*/ |
| 387 | |
| 202 | 388 | static DEVICE_START( upd1990a ) |
| 203 | 389 | { |
| 204 | 390 | upd1990a_t *upd1990a = get_safe_token(device); |
| 205 | 391 | const upd1990a_interface *intf = get_interface(device); |
| 206 | 392 | |
| 207 | 393 | /* resolve callbacks */ |
| 394 | devcb_resolve_write_line(&upd1990a->out_data_func, &intf->out_data_func, device); |
| 208 | 395 | devcb_resolve_write_line(&upd1990a->out_tp_func, &intf->out_tp_func, device); |
| 209 | 396 | |
| 210 | 397 | /* create the timers */ |
| 398 | upd1990a->clock_timer = timer_alloc(device->machine, clock_tick, (void *)device); |
| 399 | timer_adjust_periodic(upd1990a->clock_timer, attotime_zero, 0, ATTOTIME_IN_HZ(device->clock / 32768)); |
| 400 | |
| 211 | 401 | upd1990a->tp_timer = timer_alloc(device->machine, tp_tick, (void *)device); |
| 212 | 402 | |
| 403 | upd1990a->data_out_timer = timer_alloc(device->machine, data_out_tick, (void *)device); |
| 404 | |
| 213 | 405 | /* register for state saving */ |
| 214 | | upd1990a_register_state_save(device); |
| 406 | state_save_register_global_array(device->machine, upd1990a->time_counter); |
| 407 | state_save_register_global_array(device->machine, upd1990a->shift_reg); |
| 408 | state_save_register_global(device->machine, upd1990a->oe); |
| 409 | state_save_register_global(device->machine, upd1990a->cs); |
| 410 | state_save_register_global(device->machine, upd1990a->stb); |
| 411 | state_save_register_global(device->machine, upd1990a->data_in); |
| 412 | state_save_register_global(device->machine, upd1990a->data_out); |
| 413 | state_save_register_global(device->machine, upd1990a->c); |
| 414 | state_save_register_global(device->machine, upd1990a->clk); |
| 415 | state_save_register_global(device->machine, upd1990a->tp); |
| 215 | 416 | } |
| 216 | 417 | |
| 217 | | static DEVICE_RESET( upd1990a ) |
| 218 | | { |
| 219 | | upd1990a_t *upd1990a = get_safe_token(device); |
| 418 | /*------------------------------------------------- |
| 419 | DEVICE_GET_INFO( upd1990a ) |
| 420 | -------------------------------------------------*/ |
| 220 | 421 | |
| 221 | | upd1990a->shift_reg[0] = 0x00; |
| 222 | | upd1990a->shift_reg[1] = 0x00; |
| 223 | | upd1990a->shift_reg[2] = 0x00; |
| 224 | | upd1990a->shift_reg[3] = 0x00; |
| 225 | | upd1990a->shift_reg[4] = 0x00; |
| 226 | | upd1990a->data_in = 0; |
| 227 | | upd1990a->data_out = 0; |
| 228 | | upd1990a->shift_mode = 0; |
| 229 | | upd1990a->freq_divider = 0; |
| 230 | | } |
| 231 | | |
| 232 | 422 | DEVICE_GET_INFO( upd1990a ) |
| 233 | 423 | { |
| 234 | 424 | switch (state) |
| r4647 | r4648 | |
| 236 | 426 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 237 | 427 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(upd1990a_t); break; |
| 238 | 428 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 239 | | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_TIMER; break; |
| 429 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 240 | 430 | |
| 241 | 431 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 242 | 432 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(upd1990a); break; |
| 243 | 433 | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 244 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(upd1990a); break; |
| 434 | case DEVINFO_FCT_RESET: /* Nothing */ break; |
| 245 | 435 | |
| 246 | 436 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 247 | 437 | case DEVINFO_STR_NAME: strcpy(info->s, "NEC uPD1990AC"); break; |
src/mess/drivers/kyocera.c
| r4647 | r4648 | |
| 17 | 17 | |
| 18 | 18 | To Do: |
| 19 | 19 | - Basically everything: |
| 20 | | * rtc (which also controls input reads) |
| 21 | 20 | * inputs (keyboards are different) |
| 22 | 21 | * sound |
| 23 | 22 | * cassettes |
| r4647 | r4648 | |
| 26 | 25 | * what are the differences between available BIOSes for trsm100 and olivm10? |
| 27 | 26 | * Tandy Model 200 support (video emulation completely different, but also |
| 28 | 27 | memory map & IO have to be adapted) |
| 29 | | * clean up driver and split machine & video parts |
| 28 | * clean up driver and split machine part |
| 30 | 29 | |
| 31 | 30 | - Find dumps of systems which could easily be added: |
| 32 | 31 | * Olivetti M10 US (diff BIOS than the European version, it might be the alt BIOS) |
| r4647 | r4648 | |
| 40 | 39 | |
| 41 | 40 | /* Core includes */ |
| 42 | 41 | #include "driver.h" |
| 42 | #include "includes/kyocera.h" |
| 43 | 43 | #include "cpu/i8085/i8085.h" |
| 44 | 44 | #include "machine/upd1990a.h" |
| 45 | 45 | #include "machine/8155pio.h" |
| 46 | 46 | |
| 47 | 47 | static UINT8 rom_page, ram_page; |
| 48 | | static UINT8 port_a, port_b, port_c; |
| 48 | static UINT8 port_a, port_b; |
| 49 | 49 | static UINT8 timer_lsb, timer_msb; |
| 50 | 50 | static UINT8 io_E8, io_A1, io_90, io_D0; |
| 51 | 51 | |
| 52 | | int pc8201_lcd_bank = 0; |
| 53 | | |
| 54 | | void lcd_bank_update( UINT16 bank ) |
| 55 | | { |
| 56 | | switch ( bank ) |
| 57 | | { |
| 58 | | case 0x000: pc8201_lcd_bank = 0; break; |
| 59 | | case 0x001: pc8201_lcd_bank = 1; break; |
| 60 | | case 0x002: pc8201_lcd_bank = 2; break; |
| 61 | | case 0x004: pc8201_lcd_bank = 3; break; |
| 62 | | case 0x008: pc8201_lcd_bank = 4; break; |
| 63 | | case 0x010: pc8201_lcd_bank = 5; break; |
| 64 | | case 0x020: pc8201_lcd_bank = 6; break; |
| 65 | | case 0x040: pc8201_lcd_bank = 7; break; |
| 66 | | case 0x080: pc8201_lcd_bank = 8; break; |
| 67 | | case 0x100: pc8201_lcd_bank = 9; break; |
| 68 | | case 0x200: pc8201_lcd_bank = 10; break; |
| 69 | | default: /*logerror("pc8201: bank update with unk bank = %d\n", bank);*/ break; |
| 70 | | } |
| 71 | | |
| 72 | | // logerror("pc8201: _lcd_bank = %i\n",pc8201_lcd_bank); |
| 73 | | } |
| 74 | | |
| 75 | 52 | /* WRITE HANDLERS */ |
| 76 | 53 | |
| 77 | 54 | // 0x90 PC-8201 only |
| 78 | 55 | static WRITE8_HANDLER( pc8201_io90_write ) |
| 79 | 56 | { |
| 80 | | if ((data & 0x10) != (io_90 & 0x10)) |
| 81 | | { |
| 82 | | const device_config *rtc = devtag_get_device(space->machine, "rtc"); |
| 83 | | upd1990a_w(rtc, offset, port_a); |
| 84 | | logerror("RTC write: %d\n", port_a); |
| 85 | | } |
| 57 | const device_config *rtc = devtag_get_device(space->machine, "rtc"); |
| 86 | 58 | |
| 59 | upd1990a_stb_w(rtc, BIT(data, 5)); |
| 60 | |
| 61 | |
| 87 | 62 | /* printer */ |
| 88 | 63 | // if ((data & 0x20) != (io_90 & 0x20)) |
| 89 | 64 | // WRITE port_a; |
| r4647 | r4648 | |
| 243 | 218 | 3 - Remote plug control signal */ |
| 244 | 219 | static WRITE8_HANDLER( ioE8_write ) |
| 245 | 220 | { |
| 246 | | /* Check for Clock Chip strobe */ |
| 247 | | if ((data & 0x04) != (io_E8 & 0x04)) |
| 248 | | { |
| 249 | | const device_config *rtc = devtag_get_device(space->machine, "rtc"); |
| 250 | | upd1990a_w(rtc, offset, port_a); |
| 251 | | logerror("RTC write: %d\n", port_a); |
| 252 | | } |
| 221 | const device_config *rtc = devtag_get_device(space->machine, "rtc"); |
| 253 | 222 | |
| 223 | upd1990a_stb_w(rtc, BIT(data, 2)); |
| 224 | |
| 254 | 225 | /* printer */ |
| 255 | 226 | // if ((data & 0x02) != (io_E8 & 0x02)) |
| 256 | 227 | // WRITE port_a; |
| r4647 | r4648 | |
| 269 | 240 | // io_E8 = data; |
| 270 | 241 | //} |
| 271 | 242 | |
| 272 | | |
| 273 | | UINT8 pc8201_lcd[11][256]; |
| 274 | | UINT8 pc8201_lcd_addr[10]; |
| 275 | | |
| 276 | | // 0xF0... |
| 277 | | static WRITE8_HANDLER( lcd_command_write ) |
| 278 | | { |
| 279 | | pc8201_lcd_addr[pc8201_lcd_bank] = data; |
| 280 | | /* logerror("pc8201: LCDCM = 0x%02x\n",data); */ |
| 281 | | } |
| 282 | | |
| 283 | | // 0xFF |
| 284 | | static WRITE8_HANDLER( lcd_data_write ) |
| 285 | | { |
| 286 | | UINT8 addr = pc8201_lcd_addr[pc8201_lcd_bank]++; |
| 287 | | pc8201_lcd[pc8201_lcd_bank][addr] = data; |
| 288 | | /* logerror("pc8201: LCD [%i][%02x] = 0x%02x\n",pc8201_lcd_bank,addr,data); */ |
| 289 | | } |
| 290 | | |
| 291 | 243 | static WRITE8_HANDLER( unk_write ) |
| 292 | 244 | { |
| 293 | 245 | logerror("pc8201 IO port w: %04x %02x\n", offset, data); |
| r4647 | r4648 | |
| 375 | 327 | return data; |
| 376 | 328 | } |
| 377 | 329 | |
| 378 | | // 0xF0... |
| 379 | | static READ8_HANDLER( lcd_status_read ) |
| 380 | | { |
| 381 | | /* logerror("pc8201: LCDST = 0\n"); */ |
| 382 | | return 0; /* currently we are always ready */ |
| 383 | | } |
| 384 | | |
| 385 | | // 0xFF |
| 386 | | static READ8_HANDLER( lcd_data_read ) |
| 387 | | { |
| 388 | | UINT8 addr = pc8201_lcd_addr[pc8201_lcd_bank]++; |
| 389 | | return pc8201_lcd[pc8201_lcd_bank][addr]; |
| 390 | | } |
| 391 | | |
| 392 | 330 | static READ8_HANDLER( unk_read ) |
| 393 | 331 | { |
| 394 | 332 | logerror("pc8201 IO port r: %04x\n", offset); |
| r4647 | r4648 | |
| 421 | 359 | AM_RANGE(0xd8, 0xd8) AM_READ( uart_read ) |
| 422 | 360 | AM_RANGE(0xe0, 0xe8) AM_READ( keyboard_read ) |
| 423 | 361 | AM_RANGE(0xe0, 0xe8) AM_READWRITE( keyboard_read, ioE8_write ) |
| 424 | | AM_RANGE(0xfe, 0xfe) AM_READWRITE( lcd_status_read, lcd_command_write ) /* LCD status / command */ |
| 425 | | AM_RANGE(0xff, 0xff) AM_READWRITE( lcd_data_read, lcd_data_write ) /* LCD data */ |
| 362 | AM_RANGE(0xfe, 0xfe) AM_READWRITE( kyo85_lcd_status_r, kyo85_lcd_command_w ) |
| 363 | AM_RANGE(0xff, 0xff) AM_READWRITE( kyo85_lcd_data_r, kyo85_lcd_data_w ) |
| 426 | 364 | ADDRESS_MAP_END |
| 427 | 365 | |
| 428 | 366 | static ADDRESS_MAP_START( pc8201_io, ADDRESS_SPACE_IO, 8 ) |
| r4647 | r4648 | |
| 434 | 372 | AM_RANGE(0xd8, 0xd8) AM_READ( uart_read ) |
| 435 | 373 | AM_RANGE(0xe0, 0xe8) AM_READ( keyboard_read ) |
| 436 | 374 | // AM_RANGE(0xe0, 0xe8) AM_READWRITE( keyboard_read, ioE8_write ) |
| 437 | | AM_RANGE(0xfe, 0xfe) AM_READWRITE( lcd_status_read, lcd_command_write ) /* LCD status / command */ |
| 438 | | AM_RANGE(0xff, 0xff) AM_READWRITE( lcd_data_read, lcd_data_write ) /* LCD data */ |
| 375 | AM_RANGE(0xfe, 0xfe) AM_READWRITE( kyo85_lcd_status_r, kyo85_lcd_command_w ) |
| 376 | AM_RANGE(0xff, 0xff) AM_READWRITE( kyo85_lcd_data_r, kyo85_lcd_data_w ) |
| 439 | 377 | ADDRESS_MAP_END |
| 440 | 378 | |
| 441 | 379 | static ADDRESS_MAP_START( trs200_io, ADDRESS_SPACE_IO, 8 ) |
| r4647 | r4648 | |
| 449 | 387 | AM_RANGE(0xd0, 0xdf) AM_READWRITE( trs200_bank_read, trs200_bank_write ) |
| 450 | 388 | AM_RANGE(0xe0, 0xe8) AM_READ( keyboard_read ) |
| 451 | 389 | // AM_RANGE(0xe0, 0xe8) AM_READWRITE( keyboard_read, ioE8_write ) |
| 452 | | AM_RANGE(0xfe, 0xfe) AM_READWRITE( lcd_status_read, lcd_command_write ) /* LCD status / command */ |
| 453 | | AM_RANGE(0xff, 0xff) AM_READWRITE( lcd_data_read, lcd_data_write ) /* LCD data */ |
| 390 | AM_RANGE(0xfe, 0xfe) AM_READWRITE( kyo85_lcd_status_r, kyo85_lcd_command_w ) |
| 391 | AM_RANGE(0xff, 0xff) AM_READWRITE( kyo85_lcd_data_r, kyo85_lcd_data_w ) |
| 454 | 392 | ADDRESS_MAP_END |
| 455 | 393 | |
| 456 | | |
| 457 | | // pasted from PX-4. to be fixed!! |
| 458 | | static PALETTE_INIT( kyo85 ) |
| 459 | | { |
| 460 | | palette_set_color(machine, 0, MAKE_RGB(138, 146, 148)); |
| 461 | | palette_set_color(machine, 1, MAKE_RGB(92, 83, 88)); |
| 462 | | } |
| 463 | | |
| 464 | | static VIDEO_UPDATE( kyo85 ) |
| 465 | | { |
| 466 | | int x,y; |
| 467 | | int bank; |
| 468 | | int row,col; |
| 469 | | int addr; |
| 470 | | int yoff; |
| 471 | | unsigned char b; |
| 472 | | |
| 473 | | int pen1,pen0; |
| 474 | | |
| 475 | | pen0 = screen->machine->pens[0]; |
| 476 | | pen1 = screen->machine->pens[1]; |
| 477 | | |
| 478 | | for (y=0;y<64;y+=8) |
| 479 | | { |
| 480 | | for (x=0;x<240;x++) |
| 481 | | { |
| 482 | | bank = x/50; |
| 483 | | row = x%50; |
| 484 | | col = y/8; |
| 485 | | if (col>3) |
| 486 | | { |
| 487 | | col -= 4; |
| 488 | | bank+= 5; |
| 489 | | } |
| 490 | | |
| 491 | | addr = col*64 + row; |
| 492 | | |
| 493 | | b = pc8201_lcd[bank+1][addr]; |
| 494 | | |
| 495 | | /*logerror("pc8201: vid [%i][%02x] = 0x%02x (%i,%i)\n",bank,addr,b,x,y); */ |
| 496 | | |
| 497 | | for (yoff = 0; yoff < 8; yoff++) |
| 498 | | { |
| 499 | | *BITMAP_ADDR16(bitmap, y+yoff, x ) = ((b & (1 << yoff)) == (1 << yoff)) ? pen0 : pen1; |
| 500 | | } |
| 501 | | |
| 502 | | } |
| 503 | | } |
| 504 | | |
| 505 | | return 0; |
| 506 | | } |
| 507 | | |
| 508 | | |
| 509 | 394 | /************************************************************************** |
| 510 | 395 | |
| 511 | 396 | Keyboard |
| r4647 | r4648 | |
| 715 | 600 | |
| 716 | 601 | static MACHINE_START( kyo85 ) |
| 717 | 602 | { |
| 603 | const device_config *rtc = devtag_get_device(machine, "rtc"); |
| 604 | |
| 605 | upd1990a_cs_w(rtc, 1); |
| 606 | upd1990a_oe_w(rtc, 1); |
| 718 | 607 | } |
| 719 | 608 | |
| 720 | 609 | static MACHINE_RESET( kyo85 ) |
| r4647 | r4648 | |
| 723 | 612 | ram_page = -1; |
| 724 | 613 | port_a = 0; |
| 725 | 614 | port_b = 0; |
| 726 | | port_c = 0; |
| 727 | 615 | timer_lsb = 0; |
| 728 | 616 | timer_msb = 0; |
| 729 | 617 | io_E8 = 0; |
| r4647 | r4648 | |
| 732 | 620 | io_90 = 0; |
| 733 | 621 | } |
| 734 | 622 | |
| 623 | static int upd1990a_data; |
| 624 | |
| 625 | static WRITE_LINE_DEVICE_HANDLER( kyocera_upd1990a_data_w ) |
| 626 | { |
| 627 | upd1990a_data = state; |
| 628 | } |
| 629 | |
| 735 | 630 | static UPD1990A_INTERFACE( kyocera_upd1990a_intf ) |
| 736 | 631 | { |
| 632 | DEVCB_LINE(kyocera_upd1990a_data_w), |
| 737 | 633 | DEVCB_CPU_INPUT_LINE("maincpu", I8085_RST75_LINE) |
| 738 | 634 | }; |
| 739 | 635 | |
| 740 | 636 | static READ8_DEVICE_HANDLER( kyocera_8155_port_c_r ) |
| 741 | 637 | { |
| 742 | | const device_config *rtc = devtag_get_device(device->machine, "rtc"); |
| 743 | | port_c = (port_c & ~0x01) | upd1990a_data_out_r(rtc, offset); |
| 638 | /* |
| 639 | |
| 640 | bit description |
| 744 | 641 | |
| 745 | | return port_c; |
| 746 | | /* |
| 747 | | Bits: |
| 748 | | 0 - Serial data input from clock chip |
| 749 | | 1 - Busy (not) signal from printer |
| 750 | | 2 - Busy signal from printer |
| 751 | | 3 - Data from BCR |
| 752 | | 4 - CTS (not) line from RS232 |
| 753 | | 5 - DSR (not) line from RS232 |
| 754 | | 6-7 - Not avaiable on 8155 */ |
| 642 | 0 serial data input from clock chip |
| 643 | 1 _BUSY signal from printer |
| 644 | 2 BUSY signal from printer |
| 645 | 3 data from BCR |
| 646 | 4 _CTS from RS232 |
| 647 | 5 _DSR from RS232 |
| 648 | |
| 649 | */ |
| 650 | UINT8 data = 0; |
| 651 | |
| 652 | data |= upd1990a_data; |
| 653 | // data |= centronics_not_busy_r(centronics) << 1; |
| 654 | // data |= centronics_busy_r(centronics) << 2; |
| 655 | |
| 656 | return data; |
| 755 | 657 | } |
| 756 | 658 | |
| 757 | 659 | static WRITE8_DEVICE_HANDLER( kyocera_8155_port_a_w ) |
| 758 | 660 | { |
| 661 | const device_config *rtc = devtag_get_device(device->machine, "rtc"); |
| 662 | |
| 759 | 663 | port_a = data; |
| 760 | | lcd_bank_update( port_a | ((port_b & 3) << 8) ); |
| 664 | kyo85_set_lcd_bank( port_a | ((port_b & 3) << 8) ); |
| 761 | 665 | |
| 762 | 666 | /* |
| 763 | 667 | The first 5 bits of this port is used to control the 1990 real time clock chip. |
| r4647 | r4648 | |
| 768 | 672 | 2 - C2 |
| 769 | 673 | 3 - Clock |
| 770 | 674 | 4 - Serial data into clock chip */ |
| 771 | | if ((data & 0x08) != (port_a & 0x08)) |
| 772 | | { |
| 773 | | const device_config *rtc = devtag_get_device(device->machine, "rtc"); |
| 774 | | upd1990a_clk_w(rtc, offset, data); |
| 775 | | logerror("CLK write %d\n", data); |
| 776 | | } |
| 675 | |
| 676 | upd1990a_c0_w(rtc, BIT(data, 0)); |
| 677 | upd1990a_c1_w(rtc, BIT(data, 1)); |
| 678 | upd1990a_c2_w(rtc, BIT(data, 2)); |
| 679 | upd1990a_clk_w(rtc, BIT(data, 3)); |
| 680 | upd1990a_data_w(rtc, BIT(data, 4)); |
| 777 | 681 | } |
| 778 | 682 | |
| 779 | 683 | static WRITE8_DEVICE_HANDLER( kyocera_8155_port_b_w ) |
| r4647 | r4648 | |
| 791 | 695 | 6 - DTR (not) line for RS232 |
| 792 | 696 | 7 - RTS (not) line for RS232 */ |
| 793 | 697 | port_b = data; |
| 794 | | lcd_bank_update( port_a | ((port_b & 3) << 8) ); |
| 698 | kyo85_set_lcd_bank( port_a | ((port_b & 3) << 8) ); |
| 795 | 699 | } |
| 796 | 700 | |
| 797 | 701 | static PIO8155_INTERFACE( kyocera_8155_intf ) |
| r4647 | r4648 | |
| 826 | 730 | MDRV_PALETTE_LENGTH(2) |
| 827 | 731 | MDRV_PALETTE_INIT(kyo85) |
| 828 | 732 | |
| 733 | MDRV_VIDEO_START(kyo85) |
| 829 | 734 | MDRV_VIDEO_UPDATE(kyo85) |
| 830 | 735 | |
| 831 | 736 | /* sound hardware */ |