Previous 15994 Revisions Next

r5344 Monday 3rd August, 2009 at 17:20:28 UTC by Jonathan Gevaryahu
[socrates] updated keyboard code (which doesn't really fix anything yet), added simulation of first speech readback (which is disabled in a define because it confuses the hell out of the socrates), added proper status reg read for vblank rather than using rand
[src/mess/drivers]socrates.c

src/mess/drivers/socrates.c
r5343r5344
66* 
77*  (driver structure copied from vtech1.c)
88TODO:
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
1011   hook up mouse
1112   add waitstates for ram access (lack of this causes the system to run way too fast)
1213   hook up cartridges using the bios system
1314   hook up sound regs
1415   find and hook up any timers/interrupt controls
15   find and document ports for speech synthesizer
1616   
1717
1818
r5343r5344
7777#include "socrates.lh"
7878//#include "sound/beep.h"
7979
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.
8082
8183/* Components */
8284
r5343r5344
9092UINT8 ram_bank;
9193UINT16 scroll_offset;
9294UINT8* videoram;
93//UINT8 kb_latch_low_old;
94//UINT8 kb_latch_high_old;
95UINT8 kb_latch_low;
96UINT8 kb_latch_high;
95UINT8 kb_latch_low[2];
96UINT8 kb_latch_high[2];
9797UINT8 kb_latch_mouse;
98UINT8 io40_latch;
99UINT8 hblankstate;
100UINT8 vblankstate;
101UINT8 speech_running;
102UINT8 speech_selftest;
103UINT32 speech_regs[8];
98104} socrates={ {0}};
99105
100106static void socrates_set_rom_bank( running_machine *machine )
r5343r5344
113119   static const char *const rownames[] = { "keyboard_40", "keyboard_41", "keyboard_42", "keyboard_43", "keyboard_44" };
114120   int row, keyvalue, powerof2;
115121   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;
118124   // next check for joypad buttons
119125   keyvalue = input_port_read(machine, "keyboard_jp");
120126   if (keyvalue != 0)
121127   {
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);
124130      return; // get out of this function; due to the way key priorities work, we're done here.
125131   }
126132   // next check for mouse movement.
r5343r5344
137143         {
138144            if ((keyvalue&(1<<powerof2)) == (1<<powerof2))
139145            {
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);
142148               return; // get out of the for loop; due to the way key priorities work, we're done here.
143149            }
144150         }
r5343r5344
147153   // no key was pressed... check if shift was hit then?
148154   if (shift != 0)
149155   {
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;
152158   }
153159}
154160
161static 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
155173MACHINE_RESET( socrates )
156174{
157175 socrates.rom_bank = 0xF3; // actually set semi-randomly on real console but we need to initialize it somewhere...
158176 socrates_set_rom_bank( machine );
159177 socrates.ram_bank = 0;  // the actual console sets it semi randomly on power up, and the bios cleans it up.
160178 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;
165183 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;
166197}
167198
168199DRIVER_INIT( socrates )
r5343r5344
209240
210241WRITE8_HANDLER( unknownlatch_30 ) // writes to i/o 0x3x do SOMETHING, possibly waitstate related (may halt cpu until vblank start?)
211242{
212logerror("write to i/o 0x30");
243logerror("write to i/o 0x30 of %x\n", data);
213244}
214245
215READ8_HANDLER( read_40 ) // read 0x4x, some sort of status reg
246READ8_HANDLER( status_and_speech ) // read 0x4x, some sort of status reg
216247{
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;
226283}
227284
228WRITE8_HANDLER( write_40 ) // write 0x4x
285WRITE8_HANDLER( speech_command ) // write 0x4x, some sort of bitfield; speech chip is probably hitachi hd38880 related but not exact, w/4 bit interface
229286{
230logerror("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);
231342}
232343
233344READ8_HANDLER( socrates_keyboard_low_r ) // keyboard code low
234345{
235346 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];
238349}
239350
240351READ8_HANDLER( socrates_keyboard_high_r ) // keyboard code high
241352{
242353 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];
245356}
246357
247WRITE8_HANDLER( socrates_keyboard_clear ) // keyboard latch clear (or show mouse coords next if they have updated)
358WRITE8_HANDLER( socrates_keyboard_clear ) // keyboard latch shift/clear
248359{
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;
266364}
267365
268WRITE8_HANDLER( unknown_6x ) // writes to i/o 0x6x happens on startup once, with 0x01. no idea what it does.
366WRITE8_HANDLER( reset_speech ) // reset speech synth
269367{
270logerror("write to i/o 0x60 of %x",data);
368socrates.speech_selftest = 0;
369socrates.speech_regs[0] = 0;
370socrates.speech_regs[1] = 0;
371socrates.speech_regs[2] = 0;
372socrates.speech_regs[3] = 0;
373socrates.speech_regs[4] = 0;
374socrates.speech_regs[5] = 0;
375socrates.speech_regs[6] = 0;
376socrates.speech_regs[7] = 0;
377logerror("write to i/o 0x60 of %x\n",data);
271378}
272379
273380/* stuff below belongs in video/socrates.c */
r5343r5344
490597   resulting screen line is one of 512 total offsets on 128-byte boundaries in the whole 64k ram
491598   */
492599   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 */
494601   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 */
495602   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  */
497604   AM_RANGE(0x70, 0xFF) AM_READ(read_f3) // nothing mapped here afaik
498605ADDRESS_MAP_END
499606
r5343r5344
690797static TIMER_CALLBACK( clear_irq_cb )
691798{
692799   cputag_set_input_line(machine, "maincpu", 0, CLEAR_LINE);
800   socrates.vblankstate = 0;
693801}
694802
695803static INTERRUPT_GEN( assert_irq )
r5343r5344
697805   cpu_set_input_line(device, 0, ASSERT_LINE);
698806   timer_set(device->machine, cpu_clocks_to_attotime(device, 144), NULL, 0, clear_irq_cb);
699807// 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;
700809}
701810
702811static MACHINE_DRIVER_START(socrates)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team