src/mess/drivers/socrates.c
| r5343 | r5344 | |
| 6 | 6 | * |
| 7 | 7 | * (driver structure copied from vtech1.c) |
| 8 | 8 | TODO: |
| 9 | | fix glitches with keyboard input (can't spell "igloo" in scramble due to problem with double keys, letter entry in super painter doesn't work) |
| 9 | fix glitches with keyboard input (can't spell "igloo" in scramble due to problem with double keys, letter entry in super painter doesn't work) <- is this still true? |
| 10 | hook up hblank |
| 10 | 11 | hook up mouse |
| 11 | 12 | add waitstates for ram access (lack of this causes the system to run way too fast) |
| 12 | 13 | hook up cartridges using the bios system |
| 13 | 14 | hook up sound regs |
| 14 | 15 | find and hook up any timers/interrupt controls |
| 15 | | find and document ports for speech synthesizer |
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | |
| r5343 | r5344 | |
| 77 | 77 | #include "socrates.lh" |
| 78 | 78 | //#include "sound/beep.h" |
| 79 | 79 | |
| 80 | /* Defines */ |
| 81 | #undef EMULATE_SPEECH // tries miserably to emulate the speech chip readback. works for the first packet, which causes socrates to crash on the second one. |
| 80 | 82 | |
| 81 | 83 | /* Components */ |
| 82 | 84 | |
| r5343 | r5344 | |
| 90 | 92 | UINT8 ram_bank; |
| 91 | 93 | UINT16 scroll_offset; |
| 92 | 94 | UINT8* videoram; |
| 93 | | //UINT8 kb_latch_low_old; |
| 94 | | //UINT8 kb_latch_high_old; |
| 95 | | UINT8 kb_latch_low; |
| 96 | | UINT8 kb_latch_high; |
| 95 | UINT8 kb_latch_low[2]; |
| 96 | UINT8 kb_latch_high[2]; |
| 97 | 97 | UINT8 kb_latch_mouse; |
| 98 | UINT8 io40_latch; |
| 99 | UINT8 hblankstate; |
| 100 | UINT8 vblankstate; |
| 101 | UINT8 speech_running; |
| 102 | UINT8 speech_selftest; |
| 103 | UINT32 speech_regs[8]; |
| 98 | 104 | } socrates={ {0}}; |
| 99 | 105 | |
| 100 | 106 | static void socrates_set_rom_bank( running_machine *machine ) |
| r5343 | r5344 | |
| 113 | 119 | static const char *const rownames[] = { "keyboard_40", "keyboard_41", "keyboard_42", "keyboard_43", "keyboard_44" }; |
| 114 | 120 | int row, keyvalue, powerof2; |
| 115 | 121 | int shift = 0; |
| 116 | | // first check that the kb latch is clear; if it isn't, don't touch it! |
| 117 | | if ((socrates.kb_latch_low != 0) || (socrates.kb_latch_high != 1)) return; |
| 122 | // first check that the kb latch[1] is clear; if it isn't, don't touch it! |
| 123 | if ((socrates.kb_latch_low[1] != 0) || (socrates.kb_latch_high[1] != 1)) return; |
| 118 | 124 | // next check for joypad buttons |
| 119 | 125 | keyvalue = input_port_read(machine, "keyboard_jp"); |
| 120 | 126 | if (keyvalue != 0) |
| 121 | 127 | { |
| 122 | | socrates.kb_latch_low = (keyvalue & 0xFF0)>>4; |
| 123 | | socrates.kb_latch_high = 0x80 | (keyvalue & 0xF); |
| 128 | socrates.kb_latch_low[1] = (keyvalue & 0xFF0)>>4; |
| 129 | socrates.kb_latch_high[1] = 0x80 | (keyvalue & 0xF); |
| 124 | 130 | return; // get out of this function; due to the way key priorities work, we're done here. |
| 125 | 131 | } |
| 126 | 132 | // next check for mouse movement. |
| r5343 | r5344 | |
| 137 | 143 | { |
| 138 | 144 | if ((keyvalue&(1<<powerof2)) == (1<<powerof2)) |
| 139 | 145 | { |
| 140 | | socrates.kb_latch_low = (shift?0x50:0x40)+row; |
| 141 | | socrates.kb_latch_high = (0x80 | powerof2); |
| 146 | socrates.kb_latch_low[1] = (shift?0x50:0x40)+row; |
| 147 | socrates.kb_latch_high[1] = (0x80 | powerof2); |
| 142 | 148 | return; // get out of the for loop; due to the way key priorities work, we're done here. |
| 143 | 149 | } |
| 144 | 150 | } |
| r5343 | r5344 | |
| 147 | 153 | // no key was pressed... check if shift was hit then? |
| 148 | 154 | if (shift != 0) |
| 149 | 155 | { |
| 150 | | socrates.kb_latch_low = 0x50; |
| 151 | | socrates.kb_latch_high = 0x80; |
| 156 | socrates.kb_latch_low[1] = 0x50; |
| 157 | socrates.kb_latch_high[1] = 0x80; |
| 152 | 158 | } |
| 153 | 159 | } |
| 154 | 160 | |
| 161 | static void socrates_check_kb_latch( running_machine *machine ) // if kb[1] is full and kb[0] is not, shift [1] to [0] and clear [1] |
| 162 | { |
| 163 | if (((socrates.kb_latch_low[1] != 0) || (socrates.kb_latch_high[1] != 1)) && |
| 164 | ((socrates.kb_latch_low[0] == 0) && (socrates.kb_latch_high[0] == 1))) |
| 165 | { |
| 166 | socrates.kb_latch_low[0] = socrates.kb_latch_low[1]; |
| 167 | socrates.kb_latch_low[1] = 0; |
| 168 | socrates.kb_latch_high[0] = socrates.kb_latch_high[1]; |
| 169 | socrates.kb_latch_high[1] = 1; |
| 170 | } |
| 171 | } |
| 172 | |
| 155 | 173 | MACHINE_RESET( socrates ) |
| 156 | 174 | { |
| 157 | 175 | socrates.rom_bank = 0xF3; // actually set semi-randomly on real console but we need to initialize it somewhere... |
| 158 | 176 | socrates_set_rom_bank( machine ); |
| 159 | 177 | socrates.ram_bank = 0; // the actual console sets it semi randomly on power up, and the bios cleans it up. |
| 160 | 178 | socrates_set_ram_bank( machine ); |
| 161 | | //socrates.kb_latch_low_old = 0xFF; |
| 162 | | //socrates.kb_latch_high_old = 0x8F; |
| 163 | | socrates.kb_latch_low = 0xFF; |
| 164 | | socrates.kb_latch_high = 0x8F; |
| 179 | socrates.kb_latch_low[0] = 0xFF; |
| 180 | socrates.kb_latch_high[0] = 0x8F; |
| 181 | socrates.kb_latch_low[1] = 0x00; |
| 182 | socrates.kb_latch_high[1] = 0x01; |
| 165 | 183 | socrates.kb_latch_mouse = 0; |
| 184 | socrates.io40_latch = 0xf; |
| 185 | socrates.hblankstate = 0; |
| 186 | socrates.vblankstate = 0; |
| 187 | socrates.speech_running = 0; |
| 188 | socrates.speech_selftest = 0; // should be readback |
| 189 | socrates.speech_regs[0] = 0; |
| 190 | socrates.speech_regs[1] = 0; |
| 191 | socrates.speech_regs[2] = 0; |
| 192 | socrates.speech_regs[3] = 0; |
| 193 | socrates.speech_regs[4] = 0; |
| 194 | socrates.speech_regs[5] = 0; |
| 195 | socrates.speech_regs[6] = 0; |
| 196 | socrates.speech_regs[7] = 0; |
| 166 | 197 | } |
| 167 | 198 | |
| 168 | 199 | DRIVER_INIT( socrates ) |
| r5343 | r5344 | |
| 209 | 240 | |
| 210 | 241 | WRITE8_HANDLER( unknownlatch_30 ) // writes to i/o 0x3x do SOMETHING, possibly waitstate related (may halt cpu until vblank start?) |
| 211 | 242 | { |
| 212 | | logerror("write to i/o 0x30"); |
| 243 | logerror("write to i/o 0x30 of %x\n", data); |
| 213 | 244 | } |
| 214 | 245 | |
| 215 | | READ8_HANDLER( read_40 ) // read 0x4x, some sort of status reg |
| 246 | READ8_HANDLER( status_and_speech ) // read 0x4x, some sort of status reg |
| 216 | 247 | { |
| 217 | | // bit 7 - unknown, never seems to be set |
| 218 | | // bit 6 - unknown, usually set but occasionally clear |
| 219 | | // bit 5 - vblank? status, sometimes set sometimes clear |
| 220 | | // bit 4 - hblank? status, sometimes set sometimes clear |
| 221 | | // bit 3 - unknown, sometimes set sometimes clear |
| 222 | | // bit 2 - unknown, sometimes set sometimes clear |
| 223 | | // bit 1 - unknown, sometimes set sometimes clear |
| 224 | | // bit 0 - unknown, sometimes set sometimes clear |
| 225 | | return mame_rand(space->machine)&0x7f; |
| 248 | // bit 7 - speech status: high when speech is playing, low when it is not (or when speech cart is not present) |
| 249 | // bit 6 - unknown, usually set |
| 250 | // bit 5 - vblank status, high when not in vblank |
| 251 | // bit 4 - hblank status, high when not in hblank |
| 252 | // bit 3 - speech chip bit 3 |
| 253 | // bit 2 - speech chip bit 2 |
| 254 | // bit 1 - speech chip bit 1 |
| 255 | // bit 0 - speech chip bit 0 |
| 256 | #ifdef EMULATE_SPEECH |
| 257 | UINT8 selftestpattern[14] = { 0x3, 0x5, 0xa, 0x3, 0x5, 0xf, 0x4, 0x3, 0x4, 0x2, 0x5, 0x1, 0x4, 0x4 }; |
| 258 | #endif |
| 259 | int temp = 0; |
| 260 | temp |= (socrates.speech_running)?0x80:0; |
| 261 | temp |= 0x40; // unknown |
| 262 | temp |= (socrates.vblankstate)?0:0x20; |
| 263 | temp |= (socrates.hblankstate)?0:0x10; |
| 264 | switch(socrates.io40_latch&0xF0) |
| 265 | { |
| 266 | #ifdef EMULATE_SPEECH |
| 267 | case 0x60: // speech status 'read' register |
| 268 | temp |= selftestpattern[socrates.speech_selftest>>1]; |
| 269 | break; |
| 270 | case 0xE0: // speech status 'read' register w/CPE? line active |
| 271 | temp |= selftestpattern[socrates.speech_selftest>>1]; |
| 272 | break; |
| 273 | #else |
| 274 | case 0x60: case 0xE0: |
| 275 | break; |
| 276 | #endif |
| 277 | default: |
| 278 | temp |= socrates.io40_latch&0xF; |
| 279 | break; |
| 280 | } |
| 281 | logerror("read from i/o 0x4x of %x\n", temp); |
| 282 | return temp; |
| 226 | 283 | } |
| 227 | 284 | |
| 228 | | WRITE8_HANDLER( write_40 ) // write 0x4x |
| 285 | WRITE8_HANDLER( speech_command ) // write 0x4x, some sort of bitfield; speech chip is probably hitachi hd38880 related but not exact, w/4 bit interface |
| 229 | 286 | { |
| 230 | | logerror("write to i/o 0x4x of %x", data); |
| 287 | /* |
| 288 | // the high 4 bits of the write control which 'register' is written to, the low 4 bits are data (this is based on a readback test) |
| 289 | // 00-0f: readback: 70-7f |
| 290 | // 10-1f: readback: 70-7f |
| 291 | // 20-2f: readback: 70-7f |
| 292 | // 30-3f: readback: 70-7f |
| 293 | // 40-5f: readback: 70-7f |
| 294 | // 50-5f: readback: 70-7f |
| 295 | // 60-6f: readback: ALL 7f |
| 296 | // 70-7f: readback: 50, 71-7f (force vblank?) |
| 297 | // 80-8f: 80 starts speech reads as f0, rest read as 71-7f |
| 298 | // 90-9f: all 70-7f |
| 299 | // a0-af: 70-7f |
| 300 | // b0-bf: 70-7f |
| 301 | // c0-cf: 70-7f |
| 302 | // d0-df: 70-7f |
| 303 | // e0-ef: readback ALL 76 |
| 304 | // f0-ff: 70-7f |
| 305 | */ |
| 306 | /* all this really tells us is: 0x80 is the speech start command; |
| 307 | all commands are open bus on readback of 4 bits EXCEPT for 0x60 and 0xE0, which are the CTP active and inactive versions of the same command */ |
| 308 | /* following is hd38880 info: |
| 309 | microcomputer interface of hd38880 is usually 7 wires: |
| 310 | FP frame pulse, involved with READ command somehow |
| 311 | SYBS1 data line bit 0, bidirectional |
| 312 | SYBS2 data line bit 1, " |
| 313 | SYBS3 data line bit 2, " |
| 314 | SYBS4 data line bit 3, " |
| 315 | CTP Command pulse line, sort of a 'write' line |
| 316 | CMV More or less the 'command is being written' line which is active whenenever any command sequence is being written and during readback. |
| 317 | |
| 318 | The instructions which the hd38880 can be sent are: (msb first/to the left), blank instructions are invalid |
| 319 | 0000 (nop?, used as a dummy read/write during direction change??? invalid when used alone?) |
| 320 | 0001 |
| 321 | 0010 ADSET (Transfer address to "vsm-alike serial roms") <followed by 5 nybbles> |
| 322 | 0011 READ (read nybble) <bus changes from cpu->speechchip to speechchip->sys and you get as many nybbles as you pulse the CTP line for, address auto-increments> |
| 323 | 0100 INT1 (initialize 1) <followed by one nybble> |
| 324 | 0101 |
| 325 | 0110 INT2 (initialize 2) <followed by one nybble> |
| 326 | 0111 |
| 327 | 1000 SYSPD (set speed) <followed by one nybble> |
| 328 | 1001 |
| 329 | 1010 STOP |
| 330 | 1011 CONDT (Read state P1) <bus changes from cpu->speechchip to speechchip->sys and you get one nybble> |
| 331 | 1100 START |
| 332 | 1101 |
| 333 | 1110 SSTART (same as start but syspd speed is ignored and forced to be set to 9 (scale = 1.0)) |
| 334 | 1111 |
| 335 | */ |
| 336 | /* the socrates speech chip does not QUITE match the hd38880 though, but is very similar */ |
| 337 | |
| 338 | if (data==0x60) socrates.speech_selftest++; |
| 339 | if (socrates.speech_selftest > 14) socrates.speech_selftest = 0; |
| 340 | socrates.io40_latch = data; |
| 341 | logerror("write to i/o 0x4x of %x\n", data); |
| 231 | 342 | } |
| 232 | 343 | |
| 233 | 344 | READ8_HANDLER( socrates_keyboard_low_r ) // keyboard code low |
| 234 | 345 | { |
| 235 | 346 | socrates_update_kb( space->machine ); |
| 236 | | //return socrates.kb_latch_low_old; |
| 237 | | return socrates.kb_latch_low; |
| 347 | socrates_check_kb_latch( space->machine ); |
| 348 | return socrates.kb_latch_low[0]; |
| 238 | 349 | } |
| 239 | 350 | |
| 240 | 351 | READ8_HANDLER( socrates_keyboard_high_r ) // keyboard code high |
| 241 | 352 | { |
| 242 | 353 | socrates_update_kb( space->machine ); |
| 243 | | //return socrates.kb_latch_high_old; |
| 244 | | return socrates.kb_latch_high; |
| 354 | socrates_check_kb_latch( space->machine ); |
| 355 | return socrates.kb_latch_high[0]; |
| 245 | 356 | } |
| 246 | 357 | |
| 247 | | WRITE8_HANDLER( socrates_keyboard_clear ) // keyboard latch clear (or show mouse coords next if they have updated) |
| 358 | WRITE8_HANDLER( socrates_keyboard_clear ) // keyboard latch shift/clear |
| 248 | 359 | { |
| 249 | | if (socrates.kb_latch_mouse == 0) |
| 250 | | { |
| 251 | | //socrates.kb_latch_low_old = socrates.kb_latch_low; |
| 252 | | //socrates.kb_latch_high_old = socrates.kb_latch_high; |
| 253 | | socrates.kb_latch_low = 0; |
| 254 | | socrates.kb_latch_high = 1; |
| 255 | | } |
| 256 | | else |
| 257 | | { |
| 258 | | //socrates.kb_latch_low_old = socrates.kb_latch_mouse&0xFF; // y coord |
| 259 | | //socrates.kb_latch_high_old = (socrates.kb_latch_mouse&0xFF00)>>8; // x coord |
| 260 | | //socrates.kb_latch_low = 0; |
| 261 | | //socrates.kb_latch_high = 1; |
| 262 | | socrates.kb_latch_low = socrates.kb_latch_mouse&0xFF; // y coord |
| 263 | | socrates.kb_latch_high = (socrates.kb_latch_mouse&0xFF00)>>8; // x coord |
| 264 | | socrates.kb_latch_mouse = 0; |
| 265 | | } |
| 360 | socrates.kb_latch_low[0] = socrates.kb_latch_low[1]; |
| 361 | socrates.kb_latch_high[0] = socrates.kb_latch_high[1]; |
| 362 | socrates.kb_latch_low[1] = 0; |
| 363 | socrates.kb_latch_high[1] = 1; |
| 266 | 364 | } |
| 267 | 365 | |
| 268 | | WRITE8_HANDLER( unknown_6x ) // writes to i/o 0x6x happens on startup once, with 0x01. no idea what it does. |
| 366 | WRITE8_HANDLER( reset_speech ) // reset speech synth |
| 269 | 367 | { |
| 270 | | logerror("write to i/o 0x60 of %x",data); |
| 368 | socrates.speech_selftest = 0; |
| 369 | socrates.speech_regs[0] = 0; |
| 370 | socrates.speech_regs[1] = 0; |
| 371 | socrates.speech_regs[2] = 0; |
| 372 | socrates.speech_regs[3] = 0; |
| 373 | socrates.speech_regs[4] = 0; |
| 374 | socrates.speech_regs[5] = 0; |
| 375 | socrates.speech_regs[6] = 0; |
| 376 | socrates.speech_regs[7] = 0; |
| 377 | logerror("write to i/o 0x60 of %x\n",data); |
| 271 | 378 | } |
| 272 | 379 | |
| 273 | 380 | /* stuff below belongs in video/socrates.c */ |
| r5343 | r5344 | |
| 490 | 597 | resulting screen line is one of 512 total offsets on 128-byte boundaries in the whole 64k ram |
| 491 | 598 | */ |
| 492 | 599 | AM_RANGE(0x30, 0x30) AM_READWRITE(read_f3, unknownlatch_30) AM_MIRROR (0xf) /* unknown, write only. may relate to waitstate timing? */ |
| 493 | | AM_RANGE(0x40, 0x40) AM_READWRITE(read_40, write_40) AM_MIRROR(0xf) /* unknown, some sort of status/control register, speech may work through this. */ |
| 600 | AM_RANGE(0x40, 0x40) AM_READWRITE(status_and_speech, speech_command ) AM_MIRROR(0xf) /* reads status register for vblank/hblank/speech, also reads and writes speech module */ |
| 494 | 601 | AM_RANGE(0x50, 0x50) AM_READWRITE(socrates_keyboard_low_r, socrates_keyboard_clear) AM_MIRROR(0xE) /* Keyboard keycode low, latched on keypress, can be unlatched by writing anything here */ |
| 495 | 602 | AM_RANGE(0x51, 0x51) AM_READWRITE(socrates_keyboard_high_r, socrates_keyboard_clear) AM_MIRROR(0xE) /* Keyboard keycode high, latched as above, unlatches same as above */ |
| 496 | | AM_RANGE(0x60, 0x60) AM_READWRITE(read_f3, unknown_6x) AM_MIRROR(0xF) /* unknown, write only */ |
| 603 | AM_RANGE(0x60, 0x60) AM_READWRITE(read_f3, reset_speech) AM_MIRROR(0xF) /* reset the speech module */ |
| 497 | 604 | AM_RANGE(0x70, 0xFF) AM_READ(read_f3) // nothing mapped here afaik |
| 498 | 605 | ADDRESS_MAP_END |
| 499 | 606 | |
| r5343 | r5344 | |
| 690 | 797 | static TIMER_CALLBACK( clear_irq_cb ) |
| 691 | 798 | { |
| 692 | 799 | cputag_set_input_line(machine, "maincpu", 0, CLEAR_LINE); |
| 800 | socrates.vblankstate = 0; |
| 693 | 801 | } |
| 694 | 802 | |
| 695 | 803 | static INTERRUPT_GEN( assert_irq ) |
| r5343 | r5344 | |
| 697 | 805 | cpu_set_input_line(device, 0, ASSERT_LINE); |
| 698 | 806 | timer_set(device->machine, cpu_clocks_to_attotime(device, 144), NULL, 0, clear_irq_cb); |
| 699 | 807 | // 144 is a complete and total guess, need to properly measure how many clocks/microseconds the int line is high for. |
| 808 | socrates.vblankstate = 1; |
| 700 | 809 | } |
| 701 | 810 | |
| 702 | 811 | static MACHINE_DRIVER_START(socrates) |