Previous 15994 Revisions Next

r5325 Friday 31st July, 2009 at 07:48:49 UTC by Jonathan Gevaryahu
[Socrates] Add interrupts (with semi-guessed timing), beginning of sound code. Game gets farther. Hacked cpu clock to run game at approximately correct speed, needs waitstates added for all ram accesses (and maybe for I/O also).
[src/mess/drivers]socrates.c

src/mess/drivers/socrates.c
r5324r5325
55*  with dumping help from Kevin 'kevtris' Horton
66* 
77*  (driver structure copied from vtech1.c)
8TODO: (practically everything!)
9   hook up ram banking
10   hook up rom banking
11   fix layout to sane dimensions
12   write renderer (composite ntsc fun!) and hook up scroll regs
8TODO:
9   add waitstates for ram access (lack of this causes the system to run way too fast)
1310   hook up cartridges using the bios system
1411   hook up sound regs
1512   find and hook up keyboard/mouse IR input
r5324r5325
7168        E        0x8000-0xbfff      0xc000-0xffff
7269        F        0xc000-0xffff      0xc000-0xffff
7370
74video output:
751. read byte at address in vram
762. compare the lower nybble >=8 or not
773. if 2 is false, go to 6; if it is true, go to 4
784. retrieve the value from ram address 0xFNLL where N is the nybble and LL is the low 8 bits of the current display line offset.
795. take this newly retrieved byte and shift the bits out to video in the order 4 5 6 7 0 1 2 3 at the 2048-pixels-per-line rate. go to 7.
806. take the retrieved byte and shift the bits out to video in the order 0 1 2 3 at the 1024-pixels-per-line rate.
817. compare the upper nybble >= 8 or not
828. if 7 is false, go to 11; if it is true, go to 9
839. retrieve the value from ram address 0xFNLL where N is the nybble and LL is the low 8 bits of the current display line offset.
8410. take this newly retrieved byte and shift the bits out to video in the order 4 5 6 7 0 1 2 3 at the 2048-pixels-per-line rate. go to 12.
8511. take the retrieved byte and shift the bits out to video in the order 4 5 6 7 at the 1024-pixels-per-line rate.
8612. are we in hblank? if we are not in hblank or hblank is now over, increment the vram address and go to 1. otherwise, just go to 1.
87
88Yes, the above means that all colors, shades, etc produced by video are entirely composite ntsc artifacts.
89
9071******************************************************************************/
9172
9273/* Core includes */
9374#include "driver.h"
9475#include "cpu/z80/z80.h"
9576#include "socrates.lh"
77#include "sound/beep.h"
9678
79
9780/* Components */
9881
9982/* Devices */
r5324r5325
134117    /* fill vram with its init powerup bit pattern, so startup has the checkerboard screen */
135118    for (i = 0; i < 0x10000; i++)
136119        gfx[i] = (((i&0x1)?0x00:0xFF)^((i&0x100)?0x00:0xff));
120// init sound channels to both be on lowest pitch and max volume
137121}
138122
139123READ8_HANDLER( socrates_rom_bank_r )
r5324r5325
290274
291275static VIDEO_START( socrates )
292276{
293// dunno what to do here if anything
294277   socrates.videoram = memory_region(machine, "vram");
295278   socrates.scroll_offset = 0;
296279}
r5324r5325
319302   return 0;
320303}
321304
305/* below belongs in sound/socrates.c */
306
307static WRITE8_HANDLER(socrates_sound_w)
308{
309   switch(offset)
310   {
311      case 0:
312      //beep_set_frequency(channel1, (int)((13982.6)/(data+1)));
313      break;
314      case 1:
315      //beep_set_frequency(channel2, (int)((13982.6)/(data+1)));
316      break;
317      case 2:
318      //beep_set_volume(channel1, data/4);
319      break;
320      case 3:
321      //beep_set_volume(channel2, data/8);
322      break;
323      case 4: case 5: case 6: case 7: default:
324      break;
325   }
326}
327
322328/******************************************************************************
323329 Address Maps
324330******************************************************************************/
r5324r5325
332338ADDRESS_MAP_END
333339
334340static ADDRESS_MAP_START(z80_io, ADDRESS_SPACE_IO, 8)
341   ADDRESS_MAP_UNMAP_HIGH
335342   ADDRESS_MAP_GLOBAL_MASK(0xff)
336343   AM_RANGE(0x00, 0x00) AM_READWRITE(socrates_rom_bank_r, socrates_rom_bank_w) AM_MIRROR(0x7) /* rom bank select - RW - 8 bits */
337344   AM_RANGE(0x08, 0x08) AM_READWRITE(socrates_ram_bank_r, socrates_ram_bank_w) AM_MIRROR(0x7) /* ram banks select - RW - 4 low bits; Format: 0b****HHLL where LL controls whether window 0 points at ram area: 0b00: 0x0000-0x3fff; 0b01: 0x4000-0x7fff; 0b10: 0x8000-0xbfff; 0b11: 0xc000-0xffff. HH controls the same thing for window 1 */
338   AM_RANGE(0x10, 0x17) AM_NOP AM_MIRROR (0x8) /* sound section:
345   AM_RANGE(0x10, 0x17) AM_WRITE(socrates_sound_w) AM_MIRROR (0x8) /* sound section:
339346        0x10 - W - frequency control for channel 1 (louder channel) - 01=high pitch, ff=low; time between 1->0/0->1 transitions = (XTAL_21_4772MHz/(512+256) / (freq_reg+1)) (note that this is double the actual frequency since each full low and high squarewave pulse is two transitions)
340347   0x11 - W - frequency control for channel 2 (softer channel) - 01=high pitch, ff=low; same equation as above
341348   0x12 - W - 0b****VVVV volume control for channel 1
r5324r5325
364371/******************************************************************************
365372 Machine Drivers
366373******************************************************************************/
374static TIMER_CALLBACK( clear_irq_cb )
375{
376   cputag_set_input_line(machine, "maincpu", 0, CLEAR_LINE);
377}
367378
379static INTERRUPT_GEN( assert_irq )
380{
381   cpu_set_input_line(device, 0, ASSERT_LINE);
382   timer_set(device->machine, cpu_clocks_to_attotime(device, 144), NULL, 0, clear_irq_cb);
383// 144 is a complete and total guess, need to properly measure how many clocks/microseconds the int line is high for.
384}
385
368386static MACHINE_DRIVER_START(socrates)
369387    /* basic machine hardware */
370    MDRV_CPU_ADD("maincpu", Z80, XTAL_21_4772MHz/6)  /* Toshiba TMPZ84C00AP @ 3.579545 MHz, verified, xtal is divided by 6 */
388    //MDRV_CPU_ADD("maincpu", Z80, XTAL_21_4772MHz/6)  /* Toshiba TMPZ84C00AP @ 3.579545 MHz, verified, xtal is divided by 6 */
389    MDRV_CPU_ADD("maincpu", Z80, XTAL_21_4772MHz/12)  /* HACK to make system run at roughly the right speed until waitstates are done */
371390    MDRV_CPU_PROGRAM_MAP(z80_mem)
372391    MDRV_CPU_IO_MAP(z80_io)
373392    MDRV_QUANTUM_TIME(HZ(60))
393    MDRV_CPU_VBLANK_INT("screen", assert_irq)
374394    //MDRV_MACHINE_START(socrates)
375395    MDRV_MACHINE_RESET(socrates)
376396
r5324r5325
389409
390410    /* sound hardware */
391411   //MDRV_SPEAKER_STANDARD_MONO("mono")
412   //MDRV_SOUND_ADD("beep", BEEP, 0)
413   //MDRV_SOUND_ADD("beep2", BEEP, 0)
392414   //MDRV_SOUND_ADD("soc_snd", SOCRATES, XTAL_21_4772MHz/(512+256)) /* this is correct, as strange as it sounds. */
393   //MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
415   //MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.15)
394416
395417
396418MACHINE_DRIVER_END

Previous 15994 Revisions Next


© 1998-2018 The MESS Team