Previous 199869 Revisions Next

r21426 Sunday 24th February, 2013 at 21:05:14 UTC by Wilbert Pol
(MESS) thomson.c: Started moving a few things into the driver data. (nw)
[src/mess/drivers]thomson.c
[src/mess/includes]thomson.h
[src/mess/machine]thomflop.c thomflop.h thomson.c
[src/mess/video]thomson.c

trunk/src/mess/drivers/thomson.c
r21425r21426
297297
298298static ADDRESS_MAP_START ( to7, AS_PROGRAM, 8, thomson_state )
299299
300   AM_RANGE ( 0x0000, 0x3fff ) AM_READ_BANK ( THOM_CART_BANK ) AM_WRITE_LEGACY(to7_cartridge_w ) /* 4 * 16 KB */
301   AM_RANGE ( 0x4000, 0x5fff ) AM_READ_BANK ( THOM_VRAM_BANK ) AM_WRITE_LEGACY(to7_vram_w )
300   AM_RANGE ( 0x0000, 0x3fff ) AM_READ_BANK ( THOM_CART_BANK ) AM_WRITE(to7_cartridge_w ) /* 4 * 16 KB */
301   AM_RANGE ( 0x4000, 0x5fff ) AM_READ_BANK ( THOM_VRAM_BANK ) AM_WRITE(to7_vram_w )
302302   AM_RANGE ( 0x6000, 0x7fff ) AM_RAMBANK   ( THOM_BASE_BANK ) /* 1 * 8 KB */
303303   AM_RANGE ( 0x8000, 0xbfff ) AM_NOP       /* 16 KB (for extension) */
304304   AM_RANGE ( 0xc000, 0xdfff ) AM_NOP       /*  8 KB (for extension) */
r21425r21426
306306   AM_RANGE ( 0xe7c0, 0xe7c7 ) AM_DEVREADWRITE_LEGACY("mc6846", mc6846_r, mc6846_w)
307307   AM_RANGE ( 0xe7c8, 0xe7cb ) AM_DEVREADWRITE( "pia_0", pia6821_device, read_alt, write_alt )
308308   AM_RANGE ( 0xe7cc, 0xe7cf ) AM_DEVREADWRITE( "pia_1", pia6821_device, read_alt, write_alt )
309   AM_RANGE ( 0xe7d0, 0xe7df ) AM_READWRITE_LEGACY(to7_floppy_r, to7_floppy_w )
309   AM_RANGE ( 0xe7d0, 0xe7df ) AM_READWRITE(to7_floppy_r, to7_floppy_w )
310310   AM_RANGE ( 0xe7e0, 0xe7e3 ) AM_DEVREADWRITE( "pia_2", pia6821_device, read_alt, write_alt )
311311   AM_RANGE ( 0xe7e8, 0xe7eb ) AM_DEVREADWRITE( "acia",  mos6551_device, read, write )
312   AM_RANGE ( 0xe7f2, 0xe7f3 ) AM_READWRITE_LEGACY(to7_midi_r, to7_midi_w )
312   AM_RANGE ( 0xe7f2, 0xe7f3 ) AM_READWRITE(to7_midi_r, to7_midi_w )
313313   AM_RANGE ( 0xe7f8, 0xe7fb ) AM_DEVREADWRITE( "pia_3", pia6821_device, read_alt, write_alt )
314   AM_RANGE ( 0xe7fe, 0xe7ff ) AM_READWRITE_LEGACY(to7_modem_mea8000_r, to7_modem_mea8000_w )
314   AM_RANGE ( 0xe7fe, 0xe7ff ) AM_READWRITE(to7_modem_mea8000_r, to7_modem_mea8000_w )
315315   AM_RANGE ( 0xe800, 0xffff ) AM_ROM       /* system bios  */
316316
317317/* 0x10000 - 0x1ffff: 64 KB external ROM cartridge */
r21425r21426
563563   PORT_INCLUDE ( to7 )
564564INPUT_PORTS_END
565565
566static WRITE_LINE_DEVICE_HANDLER(thomson_index_callback)
567{
568    device->machine().driver_data<thomson_state>()->thomson_index_callback(device, state);
569}
570
571
566572static const floppy_interface thomson_floppy_interface =
567573{
568574   DEVCB_LINE(thomson_index_callback),
r21425r21426
615621
616622static MACHINE_CONFIG_START( to7, thomson_state )
617623
618   MCFG_MACHINE_START ( to7 )
619   MCFG_MACHINE_RESET ( to7 )
624   MCFG_MACHINE_START_OVERRIDE( thomson_state, to7 )
625   MCFG_MACHINE_RESET_OVERRIDE( thomson_state, to7 )
620626
621627/* cpu */
622628   MCFG_CPU_ADD ( "maincpu", M6809, 1000000 )
r21425r21426
628634   MCFG_SCREEN_SIZE ( THOM_TOTAL_WIDTH * 2, THOM_TOTAL_HEIGHT )
629635   MCFG_SCREEN_VISIBLE_AREA ( 0, THOM_TOTAL_WIDTH * 2 - 1,
630636            0, THOM_TOTAL_HEIGHT - 1 )
631   MCFG_SCREEN_UPDATE_STATIC ( thom )
632   MCFG_SCREEN_VBLANK_STATIC ( thom )
637   MCFG_SCREEN_UPDATE_DRIVER( thomson_state, screen_update_thom )
638   MCFG_SCREEN_VBLANK_DRIVER( thomson_state, thom_vblank )
633639
634640   MCFG_PALETTE_LENGTH ( 4097 ) /* 12-bit color + transparency */
635641   MCFG_PALETTE_INIT ( thom )
636   MCFG_VIDEO_START ( thom )
642   MCFG_VIDEO_START_OVERRIDE( thomson_state, thom )
637643   MCFG_DEFAULT_LAYOUT( layout_thomson )
638644
639645/* sound */
r21425r21426
758764
759765static ADDRESS_MAP_START ( to770, AS_PROGRAM, 8, thomson_state )
760766
761   AM_RANGE ( 0x0000, 0x3fff ) AM_READ_BANK ( THOM_CART_BANK) AM_WRITE_LEGACY(to7_cartridge_w ) /* 4 * 16 KB */
762   AM_RANGE ( 0x4000, 0x5fff ) AM_READ_BANK ( THOM_VRAM_BANK) AM_WRITE_LEGACY(to770_vram_w )
767   AM_RANGE ( 0x0000, 0x3fff ) AM_READ_BANK ( THOM_CART_BANK) AM_WRITE(to7_cartridge_w ) /* 4 * 16 KB */
768   AM_RANGE ( 0x4000, 0x5fff ) AM_READ_BANK ( THOM_VRAM_BANK) AM_WRITE(to770_vram_w )
763769   AM_RANGE ( 0x6000, 0x9fff ) AM_RAMBANK   ( THOM_BASE_BANK ) /* 16 KB */
764770   AM_RANGE ( 0xa000, 0xdfff ) AM_RAMBANK   ( THOM_RAM_BANK )  /* 6 * 16 KB */
765771   AM_RANGE ( 0xe000, 0xe7bf ) AM_ROMBANK   ( THOM_FLOP_BANK )
766772   AM_RANGE ( 0xe7c0, 0xe7c7 ) AM_DEVREADWRITE_LEGACY("mc6846", mc6846_r, mc6846_w)
767773   AM_RANGE ( 0xe7c8, 0xe7cb ) AM_DEVREADWRITE( "pia_0", pia6821_device, read_alt, write_alt )
768774   AM_RANGE ( 0xe7cc, 0xe7cf ) AM_DEVREADWRITE( "pia_1", pia6821_device, read_alt, write_alt )
769   AM_RANGE ( 0xe7d0, 0xe7df ) AM_READWRITE_LEGACY(to7_floppy_r, to7_floppy_w )
775   AM_RANGE ( 0xe7d0, 0xe7df ) AM_READWRITE(to7_floppy_r, to7_floppy_w )
770776   AM_RANGE ( 0xe7e0, 0xe7e3 ) AM_DEVREADWRITE( "pia_2", pia6821_device, read_alt, write_alt )
771   AM_RANGE ( 0xe7e4, 0xe7e7 ) AM_READWRITE_LEGACY(to770_gatearray_r, to770_gatearray_w )
777   AM_RANGE ( 0xe7e4, 0xe7e7 ) AM_READWRITE(to770_gatearray_r, to770_gatearray_w )
772778   AM_RANGE ( 0xe7e8, 0xe7eb ) AM_DEVREADWRITE( "acia",  mos6551_device, read, write )
773   AM_RANGE ( 0xe7f2, 0xe7f3 ) AM_READWRITE_LEGACY(to7_midi_r, to7_midi_w )
779   AM_RANGE ( 0xe7f2, 0xe7f3 ) AM_READWRITE(to7_midi_r, to7_midi_w )
774780   AM_RANGE ( 0xe7f8, 0xe7fb ) AM_DEVREADWRITE( "pia_3", pia6821_device, read_alt, write_alt )
775   AM_RANGE ( 0xe7fe, 0xe7ff ) AM_READWRITE_LEGACY(to7_modem_mea8000_r, to7_modem_mea8000_w )
781   AM_RANGE ( 0xe7fe, 0xe7ff ) AM_READWRITE(to7_modem_mea8000_r, to7_modem_mea8000_w )
776782   AM_RANGE ( 0xe800, 0xffff ) AM_ROM       /* system bios  */
777783
778784/* 0x10000 - 0x1ffff: 64 KB external ROM cartridge */
r21425r21426
861867/* ------------ driver ------------ */
862868
863869static MACHINE_CONFIG_DERIVED( to770, to7 )
864   MCFG_MACHINE_START ( to770 )
865   MCFG_MACHINE_RESET ( to770 )
870   MCFG_MACHINE_START_OVERRIDE( thomson_state, to770 )
871   MCFG_MACHINE_RESET_OVERRIDE( thomson_state, to770 )
866872
867873   MCFG_CPU_MODIFY( "maincpu" )
868874   MCFG_CPU_PROGRAM_MAP ( to770)
r21425r21426
951957
952958static ADDRESS_MAP_START ( mo5, AS_PROGRAM, 8, thomson_state )
953959
954   AM_RANGE ( 0x0000, 0x1fff ) AM_READ_BANK ( THOM_VRAM_BANK ) AM_WRITE_LEGACY(to770_vram_w )
960   AM_RANGE ( 0x0000, 0x1fff ) AM_READ_BANK ( THOM_VRAM_BANK ) AM_WRITE(to770_vram_w )
955961   AM_RANGE ( 0x2000, 0x9fff ) AM_RAMBANK   ( THOM_BASE_BANK )
956962   AM_RANGE ( 0xa000, 0xa7bf ) AM_ROMBANK   ( THOM_FLOP_BANK )
957963   AM_RANGE ( 0xa7c0, 0xa7c3 ) AM_DEVREADWRITE( "pia_0", pia6821_device, read_alt, write_alt )
958   AM_RANGE ( 0xa7cb, 0xa7cb ) AM_WRITE_LEGACY(mo5_ext_w )
964   AM_RANGE ( 0xa7cb, 0xa7cb ) AM_WRITE(mo5_ext_w )
959965   AM_RANGE ( 0xa7cc, 0xa7cf ) AM_DEVREADWRITE( "pia_1", pia6821_device, read_alt, write_alt )
960   AM_RANGE ( 0xa7d0, 0xa7df ) AM_READWRITE_LEGACY(to7_floppy_r, to7_floppy_w )
966   AM_RANGE ( 0xa7d0, 0xa7df ) AM_READWRITE(to7_floppy_r, to7_floppy_w )
961967   AM_RANGE ( 0xa7e0, 0xa7e3 ) AM_DEVREADWRITE( "pia_2", pia6821_device, read_alt, write_alt )
962   AM_RANGE ( 0xa7e4, 0xa7e7 ) AM_READWRITE_LEGACY(mo5_gatearray_r, mo5_gatearray_w )
968   AM_RANGE ( 0xa7e4, 0xa7e7 ) AM_READWRITE(mo5_gatearray_r, mo5_gatearray_w )
963969   AM_RANGE ( 0xa7e8, 0xa7eb ) AM_DEVREADWRITE( "acia",  mos6551_device, read, write )
964   AM_RANGE ( 0xa7f2, 0xa7f3 ) AM_READWRITE_LEGACY(to7_midi_r, to7_midi_w )
970   AM_RANGE ( 0xa7f2, 0xa7f3 ) AM_READWRITE(to7_midi_r, to7_midi_w )
965971   AM_RANGE ( 0xa7fe, 0xa7ff ) AM_DEVREADWRITE_LEGACY("mea8000", mea8000_r, mea8000_w)
966   AM_RANGE ( 0xb000, 0xefff ) AM_READ_BANK ( THOM_CART_BANK) AM_WRITE_LEGACY(mo5_cartridge_w )
972   AM_RANGE ( 0xb000, 0xefff ) AM_READ_BANK ( THOM_CART_BANK) AM_WRITE(mo5_cartridge_w )
967973   AM_RANGE ( 0xf000, 0xffff ) AM_ROM       /* system bios */
968974
969975/* 0x10000 - 0x1ffff: 16 KB integrated BASIC / 64 KB external cartridge */
r21425r21426
10451051/* ------------ driver ------------ */
10461052
10471053static MACHINE_CONFIG_DERIVED( mo5, to7 )
1048   MCFG_MACHINE_START ( mo5 )
1049   MCFG_MACHINE_RESET ( mo5 )
1054   MCFG_MACHINE_START_OVERRIDE( thomson_state, mo5 )
1055   MCFG_MACHINE_RESET_OVERRIDE( thomson_state, mo5 )
10501056
10511057   MCFG_CPU_MODIFY( "maincpu" )
10521058   MCFG_CPU_PROGRAM_MAP ( mo5)
r21425r21426
11531159
11541160static ADDRESS_MAP_START ( to9, AS_PROGRAM, 8, thomson_state )
11551161
1156   AM_RANGE ( 0x0000, 0x3fff ) AM_READ_BANK ( THOM_CART_BANK ) AM_WRITE_LEGACY(to9_cartridge_w )/* 4 * 16 KB */
1157   AM_RANGE ( 0x4000, 0x5fff ) AM_READ_BANK ( THOM_VRAM_BANK ) AM_WRITE_LEGACY(to770_vram_w )
1162   AM_RANGE ( 0x0000, 0x3fff ) AM_READ_BANK ( THOM_CART_BANK ) AM_WRITE(to9_cartridge_w )/* 4 * 16 KB */
1163   AM_RANGE ( 0x4000, 0x5fff ) AM_READ_BANK ( THOM_VRAM_BANK ) AM_WRITE(to770_vram_w )
11581164   AM_RANGE ( 0x6000, 0x9fff ) AM_RAMBANK   ( THOM_BASE_BANK ) /* 16 KB */
11591165   AM_RANGE ( 0xa000, 0xdfff ) AM_RAMBANK   ( THOM_RAM_BANK )  /* 10 * 16 KB */
11601166   AM_RANGE ( 0xe000, 0xe7bf ) AM_ROMBANK   ( THOM_FLOP_BANK )
11611167   AM_RANGE ( 0xe7c0, 0xe7c7 ) AM_DEVREADWRITE_LEGACY("mc6846", mc6846_r, mc6846_w)
11621168   AM_RANGE ( 0xe7c8, 0xe7cb ) AM_DEVREADWRITE( "pia_0", pia6821_device, read_alt, write_alt)
11631169   AM_RANGE ( 0xe7cc, 0xe7cf ) AM_DEVREADWRITE( "pia_1", pia6821_device, read_alt, write_alt)
1164   AM_RANGE ( 0xe7d0, 0xe7d9 ) AM_READWRITE_LEGACY(to9_floppy_r, to9_floppy_w )
1165   AM_RANGE ( 0xe7da, 0xe7dd ) AM_READWRITE_LEGACY(to9_vreg_r, to9_vreg_w )
1166   AM_RANGE ( 0xe7de, 0xe7df ) AM_READWRITE_LEGACY(to9_kbd_r, to9_kbd_w )
1167   AM_RANGE ( 0xe7e4, 0xe7e7 ) AM_READWRITE_LEGACY(to9_gatearray_r, to9_gatearray_w )
1170   AM_RANGE ( 0xe7d0, 0xe7d9 ) AM_READWRITE(to9_floppy_r, to9_floppy_w )
1171   AM_RANGE ( 0xe7da, 0xe7dd ) AM_READWRITE(to9_vreg_r, to9_vreg_w )
1172   AM_RANGE ( 0xe7de, 0xe7df ) AM_READWRITE(to9_kbd_r, to9_kbd_w )
1173   AM_RANGE ( 0xe7e4, 0xe7e7 ) AM_READWRITE(to9_gatearray_r, to9_gatearray_w )
11681174   AM_RANGE ( 0xe7e8, 0xe7eb ) AM_DEVREADWRITE( "acia",  mos6551_device, read, write )
1169/*   AM_RANGE ( 0xe7f0, 0xe7f7 ) AM_READWRITE_LEGACY(to9_ieee_r, to9_ieee_w ) */
1170   AM_RANGE ( 0xe7f2, 0xe7f3 ) AM_READWRITE_LEGACY(to7_midi_r, to7_midi_w )
1175/*   AM_RANGE ( 0xe7f0, 0xe7f7 ) AM_READWRITE(to9_ieee_r, to9_ieee_w ) */
1176   AM_RANGE ( 0xe7f2, 0xe7f3 ) AM_READWRITE(to7_midi_r, to7_midi_w )
11711177   AM_RANGE ( 0xe7f8, 0xe7fb ) AM_DEVREADWRITE( "pia_3", pia6821_device, read_alt, write_alt)
1172   AM_RANGE ( 0xe7fe, 0xe7ff ) AM_READWRITE_LEGACY(to7_modem_mea8000_r, to7_modem_mea8000_w )
1178   AM_RANGE ( 0xe7fe, 0xe7ff ) AM_READWRITE(to7_modem_mea8000_r, to7_modem_mea8000_w )
11731179   AM_RANGE ( 0xe800, 0xffff ) AM_ROM       /* system bios  */
11741180
11751181/* 0x10000 - 0x1ffff:  64 KB external ROM cartridge */
r21425r21426
13861392/* ------------ driver ------------ */
13871393
13881394static MACHINE_CONFIG_DERIVED( to9, to7 )
1389   MCFG_MACHINE_START ( to9 )
1390   MCFG_MACHINE_RESET ( to9 )
1395   MCFG_MACHINE_START_OVERRIDE( thomson_state, to9 )
1396   MCFG_MACHINE_RESET_OVERRIDE( thomson_state, to9 )
13911397
13921398   MCFG_CPU_MODIFY( "maincpu" )
13931399   MCFG_CPU_PROGRAM_MAP ( to9)
r21425r21426
14761482
14771483static ADDRESS_MAP_START ( to8, AS_PROGRAM, 8, thomson_state )
14781484
1479   AM_RANGE ( 0x0000, 0x3fff ) AM_READ_BANK ( THOM_CART_BANK) AM_WRITE_LEGACY(to8_cartridge_w ) /* 4 * 16 KB */
1480   AM_RANGE ( 0x4000, 0x5fff ) AM_READ_BANK ( THOM_VRAM_BANK) AM_WRITE_LEGACY(to770_vram_w )
1481   AM_RANGE ( 0x6000, 0x7fff ) AM_READ_BANK ( TO8_SYS_LO) AM_WRITE_LEGACY(to8_sys_lo_w )
1482   AM_RANGE ( 0x8000, 0x9fff ) AM_READ_BANK ( TO8_SYS_HI) AM_WRITE_LEGACY(to8_sys_hi_w )
1483   AM_RANGE ( 0xa000, 0xbfff ) AM_READ_BANK ( TO8_DATA_LO) AM_WRITE_LEGACY(to8_data_lo_w )
1484   AM_RANGE ( 0xc000, 0xdfff ) AM_READ_BANK ( TO8_DATA_HI) AM_WRITE_LEGACY(to8_data_hi_w )
1485   AM_RANGE ( 0x0000, 0x3fff ) AM_READ_BANK ( THOM_CART_BANK) AM_WRITE(to8_cartridge_w ) /* 4 * 16 KB */
1486   AM_RANGE ( 0x4000, 0x5fff ) AM_READ_BANK ( THOM_VRAM_BANK) AM_WRITE(to770_vram_w )
1487   AM_RANGE ( 0x6000, 0x7fff ) AM_READ_BANK ( TO8_SYS_LO) AM_WRITE(to8_sys_lo_w )
1488   AM_RANGE ( 0x8000, 0x9fff ) AM_READ_BANK ( TO8_SYS_HI) AM_WRITE(to8_sys_hi_w )
1489   AM_RANGE ( 0xa000, 0xbfff ) AM_READ_BANK ( TO8_DATA_LO) AM_WRITE(to8_data_lo_w )
1490   AM_RANGE ( 0xc000, 0xdfff ) AM_READ_BANK ( TO8_DATA_HI) AM_WRITE(to8_data_hi_w )
14851491   AM_RANGE ( 0xe000, 0xe7bf ) AM_ROMBANK   ( THOM_FLOP_BANK ) /* 2 * 2 KB */
14861492   AM_RANGE ( 0xe7c0, 0xe7c7 ) AM_DEVREADWRITE_LEGACY("mc6846", mc6846_r, mc6846_w)
14871493   AM_RANGE ( 0xe7c8, 0xe7cb ) AM_DEVREADWRITE( "pia_0", pia6821_device, read_alt, write_alt)
14881494   AM_RANGE ( 0xe7cc, 0xe7cf ) AM_DEVREADWRITE( "pia_1", pia6821_device, read_alt, write_alt)
1489   AM_RANGE ( 0xe7d0, 0xe7d9 ) AM_READWRITE_LEGACY(to8_floppy_r, to8_floppy_w )
1490   AM_RANGE ( 0xe7da, 0xe7dd ) AM_READWRITE_LEGACY(to8_vreg_r, to8_vreg_w )
1491   AM_RANGE ( 0xe7e4, 0xe7e7 ) AM_READWRITE_LEGACY(to8_gatearray_r, to8_gatearray_w )
1495   AM_RANGE ( 0xe7d0, 0xe7d9 ) AM_READWRITE(to8_floppy_r, to8_floppy_w )
1496   AM_RANGE ( 0xe7da, 0xe7dd ) AM_READWRITE(to8_vreg_r, to8_vreg_w )
1497   AM_RANGE ( 0xe7e4, 0xe7e7 ) AM_READWRITE(to8_gatearray_r, to8_gatearray_w )
14921498   AM_RANGE ( 0xe7e8, 0xe7eb ) AM_DEVREADWRITE( "acia",  mos6551_device, read, write )
1493/*   AM_RANGE ( 0xe7f0, 0xe7f7 ) AM_READWRITE_LEGACY(to9_ieee_r, to9_ieee_w ) */
1494   AM_RANGE ( 0xe7f2, 0xe7f3 ) AM_READWRITE_LEGACY(to7_midi_r, to7_midi_w )
1499/*   AM_RANGE ( 0xe7f0, 0xe7f7 ) AM_READWRITE(to9_ieee_r, to9_ieee_w ) */
1500   AM_RANGE ( 0xe7f2, 0xe7f3 ) AM_READWRITE(to7_midi_r, to7_midi_w )
14951501   AM_RANGE ( 0xe7f8, 0xe7fb ) AM_DEVREADWRITE( "pia_3", pia6821_device, read_alt, write_alt)
1496   AM_RANGE ( 0xe7fe, 0xe7ff ) AM_READWRITE_LEGACY(to7_modem_mea8000_r, to7_modem_mea8000_w )
1502   AM_RANGE ( 0xe7fe, 0xe7ff ) AM_READWRITE(to7_modem_mea8000_r, to7_modem_mea8000_w )
14971503   AM_RANGE ( 0xe800, 0xffff ) AM_ROMBANK   ( TO8_BIOS_BANK ) /* 2 * 6 KB */
14981504
14991505/* 0x10000 - 0x1ffff: 64 KB external ROM cartridge */
r21425r21426
16031609/* ------------ driver ------------ */
16041610
16051611static MACHINE_CONFIG_DERIVED( to8, to7 )
1606   MCFG_MACHINE_START ( to8 )
1607   MCFG_MACHINE_RESET ( to8 )
1612   MCFG_MACHINE_START_OVERRIDE( thomson_state, to8 )
1613   MCFG_MACHINE_RESET_OVERRIDE( thomson_state, to8 )
16081614
16091615   MCFG_CPU_MODIFY( "maincpu" )
16101616   MCFG_CPU_PROGRAM_MAP ( to8)
r21425r21426
16711677
16721678static ADDRESS_MAP_START ( to9p, AS_PROGRAM, 8, thomson_state )
16731679
1674   AM_RANGE ( 0x0000, 0x3fff ) AM_READ_BANK ( THOM_CART_BANK) AM_WRITE_LEGACY(to8_cartridge_w ) /* 4 * 16 KB */
1675   AM_RANGE ( 0x4000, 0x5fff ) AM_READ_BANK ( THOM_VRAM_BANK) AM_WRITE_LEGACY(to770_vram_w )
1676   AM_RANGE ( 0x6000, 0x7fff ) AM_READ_BANK ( TO8_SYS_LO) AM_WRITE_LEGACY(to8_sys_lo_w )
1677   AM_RANGE ( 0x8000, 0x9fff ) AM_READ_BANK ( TO8_SYS_HI) AM_WRITE_LEGACY(to8_sys_hi_w )
1678   AM_RANGE ( 0xa000, 0xbfff ) AM_READ_BANK ( TO8_DATA_LO) AM_WRITE_LEGACY(to8_data_lo_w )
1679   AM_RANGE ( 0xc000, 0xdfff ) AM_READ_BANK ( TO8_DATA_HI) AM_WRITE_LEGACY(to8_data_hi_w )
1680   AM_RANGE ( 0x0000, 0x3fff ) AM_READ_BANK ( THOM_CART_BANK) AM_WRITE(to8_cartridge_w ) /* 4 * 16 KB */
1681   AM_RANGE ( 0x4000, 0x5fff ) AM_READ_BANK ( THOM_VRAM_BANK) AM_WRITE(to770_vram_w )
1682   AM_RANGE ( 0x6000, 0x7fff ) AM_READ_BANK ( TO8_SYS_LO) AM_WRITE(to8_sys_lo_w )
1683   AM_RANGE ( 0x8000, 0x9fff ) AM_READ_BANK ( TO8_SYS_HI) AM_WRITE(to8_sys_hi_w )
1684   AM_RANGE ( 0xa000, 0xbfff ) AM_READ_BANK ( TO8_DATA_LO) AM_WRITE(to8_data_lo_w )
1685   AM_RANGE ( 0xc000, 0xdfff ) AM_READ_BANK ( TO8_DATA_HI) AM_WRITE(to8_data_hi_w )
16801686   AM_RANGE ( 0xe000, 0xe7bf ) AM_ROMBANK   ( THOM_FLOP_BANK ) /* 2 * 2 KB */
16811687   AM_RANGE ( 0xe7c0, 0xe7c7 ) AM_DEVREADWRITE_LEGACY("mc6846", mc6846_r, mc6846_w)
16821688   AM_RANGE ( 0xe7c8, 0xe7cb ) AM_DEVREADWRITE( "pia_0", pia6821_device, read_alt, write_alt)
16831689   AM_RANGE ( 0xe7cc, 0xe7cf ) AM_DEVREADWRITE( "pia_1", pia6821_device, read_alt, write_alt)
1684   AM_RANGE ( 0xe7d0, 0xe7d9 ) AM_READWRITE_LEGACY(to8_floppy_r, to8_floppy_w )
1685   AM_RANGE ( 0xe7da, 0xe7dd ) AM_READWRITE_LEGACY(to8_vreg_r, to8_vreg_w )
1686   AM_RANGE ( 0xe7de, 0xe7df ) AM_READWRITE_LEGACY(to9_kbd_r, to9_kbd_w )
1687   AM_RANGE ( 0xe7e4, 0xe7e7 ) AM_READWRITE_LEGACY(to8_gatearray_r, to8_gatearray_w )
1690   AM_RANGE ( 0xe7d0, 0xe7d9 ) AM_READWRITE(to8_floppy_r, to8_floppy_w )
1691   AM_RANGE ( 0xe7da, 0xe7dd ) AM_READWRITE(to8_vreg_r, to8_vreg_w )
1692   AM_RANGE ( 0xe7de, 0xe7df ) AM_READWRITE(to9_kbd_r, to9_kbd_w )
1693   AM_RANGE ( 0xe7e4, 0xe7e7 ) AM_READWRITE(to8_gatearray_r, to8_gatearray_w )
16881694   AM_RANGE ( 0xe7e8, 0xe7eb ) AM_DEVREADWRITE( "acia",  mos6551_device, read, write )
1689/*   AM_RANGE ( 0xe7f0, 0xe7f7 ) AM_READWRITE_LEGACY(to9_ieee_r, to9_ieee_w ) */
1690   AM_RANGE ( 0xe7f2, 0xe7f3 ) AM_READWRITE_LEGACY(to7_midi_r, to7_midi_w )
1695/*   AM_RANGE ( 0xe7f0, 0xe7f7 ) AM_READWRITE(to9_ieee_r, to9_ieee_w ) */
1696   AM_RANGE ( 0xe7f2, 0xe7f3 ) AM_READWRITE(to7_midi_r, to7_midi_w )
16911697   AM_RANGE ( 0xe7f8, 0xe7fb ) AM_DEVREADWRITE( "pia_3", pia6821_device, read_alt, write_alt)
1692   AM_RANGE ( 0xe7fe, 0xe7ff ) AM_READWRITE_LEGACY(to7_modem_mea8000_r, to7_modem_mea8000_w )
1698   AM_RANGE ( 0xe7fe, 0xe7ff ) AM_READWRITE(to7_modem_mea8000_r, to7_modem_mea8000_w )
16931699   AM_RANGE ( 0xe800, 0xffff ) AM_ROMBANK   ( TO8_BIOS_BANK ) /* 2 * 6 KB */
16941700
16951701/* 0x10000 - 0x1ffff: 64 KB external ROM cartridge */
r21425r21426
17501756/* ------------ driver ------------ */
17511757
17521758static MACHINE_CONFIG_DERIVED( to9p, to7 )
1753   MCFG_MACHINE_START ( to9p )
1754   MCFG_MACHINE_RESET ( to9p )
1759   MCFG_MACHINE_START_OVERRIDE( thomson_state, to9p )
1760   MCFG_MACHINE_RESET_OVERRIDE( thomson_state, to9p )
17551761
17561762   MCFG_CPU_MODIFY( "maincpu" )
17571763   MCFG_CPU_PROGRAM_MAP ( to9p)
r21425r21426
18331839
18341840static ADDRESS_MAP_START ( mo6, AS_PROGRAM, 8, thomson_state )
18351841
1836   AM_RANGE ( 0x0000, 0x1fff ) AM_READ_BANK ( THOM_VRAM_BANK) AM_WRITE_LEGACY(to770_vram_w )
1837   AM_RANGE ( 0x2000, 0x3fff ) AM_READ_BANK ( TO8_SYS_LO) AM_WRITE_LEGACY(to8_sys_lo_w )
1838   AM_RANGE ( 0x4000, 0x5fff ) AM_READ_BANK ( TO8_SYS_HI) AM_WRITE_LEGACY(to8_sys_hi_w )
1839   AM_RANGE ( 0x6000, 0x7fff ) AM_READ_BANK ( TO8_DATA_LO) AM_WRITE_LEGACY(to8_data_lo_w )
1840   AM_RANGE ( 0x8000, 0x9fff ) AM_READ_BANK ( TO8_DATA_HI) AM_WRITE_LEGACY(to8_data_hi_w )
1842   AM_RANGE ( 0x0000, 0x1fff ) AM_READ_BANK ( THOM_VRAM_BANK) AM_WRITE(to770_vram_w )
1843   AM_RANGE ( 0x2000, 0x3fff ) AM_READ_BANK ( TO8_SYS_LO) AM_WRITE(to8_sys_lo_w )
1844   AM_RANGE ( 0x4000, 0x5fff ) AM_READ_BANK ( TO8_SYS_HI) AM_WRITE(to8_sys_hi_w )
1845   AM_RANGE ( 0x6000, 0x7fff ) AM_READ_BANK ( TO8_DATA_LO) AM_WRITE(to8_data_lo_w )
1846   AM_RANGE ( 0x8000, 0x9fff ) AM_READ_BANK ( TO8_DATA_HI) AM_WRITE(to8_data_hi_w )
18411847   AM_RANGE ( 0xa000, 0xa7bf ) AM_ROMBANK   ( THOM_FLOP_BANK )
18421848   AM_RANGE ( 0xa7c0, 0xa7c3 ) AM_DEVREADWRITE( "pia_0", pia6821_device, read_alt, write_alt)
1843   AM_RANGE ( 0xa7cb, 0xa7cb ) AM_WRITE_LEGACY(mo6_ext_w )
1849   AM_RANGE ( 0xa7cb, 0xa7cb ) AM_WRITE(mo6_ext_w )
18441850   AM_RANGE ( 0xa7cc, 0xa7cf ) AM_DEVREADWRITE( "pia_1", pia6821_device, read_alt, write_alt)
1845   AM_RANGE ( 0xa7d0, 0xa7d9 ) AM_READWRITE_LEGACY(to7_floppy_r, to7_floppy_w )
1846   AM_RANGE ( 0xa7da, 0xa7dd ) AM_READWRITE_LEGACY(mo6_vreg_r, mo6_vreg_w )
1847   AM_RANGE ( 0xa7e4, 0xa7e7 ) AM_READWRITE_LEGACY(mo6_gatearray_r, mo6_gatearray_w )
1851   AM_RANGE ( 0xa7d0, 0xa7d9 ) AM_READWRITE(to7_floppy_r, to7_floppy_w )
1852   AM_RANGE ( 0xa7da, 0xa7dd ) AM_READWRITE(mo6_vreg_r, mo6_vreg_w )
1853   AM_RANGE ( 0xa7e4, 0xa7e7 ) AM_READWRITE(mo6_gatearray_r, mo6_gatearray_w )
18481854   AM_RANGE ( 0xa7e8, 0xa7eb ) AM_DEVREADWRITE( "acia",  mos6551_device, read, write )
1849/*   AM_RANGE ( 0xa7f0, 0xa7f7 ) AM_READWRITE_LEGACY(to9_ieee_r, to9_ieee_w )*/
1850   AM_RANGE ( 0xa7f2, 0xa7f3 ) AM_READWRITE_LEGACY(to7_midi_r, to7_midi_w )
1855/*   AM_RANGE ( 0xa7f0, 0xa7f7 ) AM_READWRITE(to9_ieee_r, to9_ieee_w )*/
1856   AM_RANGE ( 0xa7f2, 0xa7f3 ) AM_READWRITE(to7_midi_r, to7_midi_w )
18511857   AM_RANGE ( 0xa7fe, 0xa7ff ) AM_DEVREADWRITE_LEGACY("mea8000", mea8000_r, mea8000_w)
18521858   AM_RANGE ( 0xb000, 0xefff ) AM_ROMBANK   ( THOM_CART_BANK )
1853                        AM_WRITE_LEGACY(mo6_cartridge_w )
1859                        AM_WRITE(mo6_cartridge_w )
18541860   AM_RANGE ( 0xf000, 0xffff ) AM_ROMBANK   ( TO8_BIOS_BANK )
18551861
18561862/* 0x10000 - 0x1ffff: 64 KB external ROM cartridge */
r21425r21426
20802086/* ------------ driver ------------ */
20812087
20822088static MACHINE_CONFIG_DERIVED( mo6, to7 )
2083   MCFG_MACHINE_START ( mo6 )
2084   MCFG_MACHINE_RESET ( mo6 )
2089   MCFG_MACHINE_START_OVERRIDE( thomson_state, mo6 )
2090   MCFG_MACHINE_RESET_OVERRIDE( thomson_state, mo6 )
20852091
20862092   MCFG_CPU_MODIFY( "maincpu" )
20872093   MCFG_CPU_PROGRAM_MAP ( mo6)
r21425r21426
21462152
21472153static ADDRESS_MAP_START ( mo5nr, AS_PROGRAM, 8, thomson_state )
21482154
2149   AM_RANGE ( 0x0000, 0x1fff ) AM_READ_BANK ( THOM_VRAM_BANK) AM_WRITE_LEGACY(to770_vram_w )
2150   AM_RANGE ( 0x2000, 0x3fff ) AM_READ_BANK ( TO8_SYS_LO) AM_WRITE_LEGACY(to8_sys_lo_w )
2151   AM_RANGE ( 0x4000, 0x5fff ) AM_READ_BANK ( TO8_SYS_HI) AM_WRITE_LEGACY(to8_sys_hi_w )
2152   AM_RANGE ( 0x6000, 0x7fff ) AM_READ_BANK ( TO8_DATA_LO) AM_WRITE_LEGACY(to8_data_lo_w )
2153   AM_RANGE ( 0x8000, 0x9fff ) AM_READ_BANK ( TO8_DATA_HI) AM_WRITE_LEGACY(to8_data_hi_w )
2155   AM_RANGE ( 0x0000, 0x1fff ) AM_READ_BANK ( THOM_VRAM_BANK) AM_WRITE(to770_vram_w )
2156   AM_RANGE ( 0x2000, 0x3fff ) AM_READ_BANK ( TO8_SYS_LO) AM_WRITE(to8_sys_lo_w )
2157   AM_RANGE ( 0x4000, 0x5fff ) AM_READ_BANK ( TO8_SYS_HI) AM_WRITE(to8_sys_hi_w )
2158   AM_RANGE ( 0x6000, 0x7fff ) AM_READ_BANK ( TO8_DATA_LO) AM_WRITE(to8_data_lo_w )
2159   AM_RANGE ( 0x8000, 0x9fff ) AM_READ_BANK ( TO8_DATA_HI) AM_WRITE(to8_data_hi_w )
21542160   AM_RANGE ( 0xa000, 0xa7bf ) AM_ROMBANK   ( THOM_FLOP_BANK )
21552161   AM_RANGE ( 0xa7c0, 0xa7c3 ) AM_DEVREADWRITE( "pia_0", pia6821_device, read_alt, write_alt)
2156   AM_RANGE ( 0xa7cb, 0xa7cb ) AM_WRITE_LEGACY(mo6_ext_w )
2162   AM_RANGE ( 0xa7cb, 0xa7cb ) AM_WRITE(mo6_ext_w )
21572163   AM_RANGE ( 0xa7cc, 0xa7cf ) AM_DEVREADWRITE( "pia_1", pia6821_device, read_alt, write_alt)
2158   AM_RANGE ( 0xa7d0, 0xa7d9 ) AM_READWRITE_LEGACY(mo5nr_net_r, mo5nr_net_w )
2159   AM_RANGE ( 0xa7da, 0xa7dd ) AM_READWRITE_LEGACY(mo6_vreg_r, mo6_vreg_w )
2164   AM_RANGE ( 0xa7d0, 0xa7d9 ) AM_READWRITE(mo5nr_net_r, mo5nr_net_w )
2165   AM_RANGE ( 0xa7da, 0xa7dd ) AM_READWRITE(mo6_vreg_r, mo6_vreg_w )
21602166   AM_RANGE ( 0xa7e1, 0xa7e1 ) AM_DEVREADWRITE("centronics", centronics_device, read, write)
2161   AM_RANGE ( 0xa7e3, 0xa7e3 ) AM_READWRITE_LEGACY(mo5nr_prn_r, mo5nr_prn_w )
2162   AM_RANGE ( 0xa7e4, 0xa7e7 ) AM_READWRITE_LEGACY(mo6_gatearray_r, mo6_gatearray_w )
2167   AM_RANGE ( 0xa7e3, 0xa7e3 ) AM_READWRITE(mo5nr_prn_r, mo5nr_prn_w )
2168   AM_RANGE ( 0xa7e4, 0xa7e7 ) AM_READWRITE(mo6_gatearray_r, mo6_gatearray_w )
21632169   AM_RANGE ( 0xa7e8, 0xa7eb ) AM_DEVREADWRITE( "acia",  mos6551_device, read, write )
2164/*   AM_RANGE ( 0xa7f0, 0xa7f7 ) AM_READWRITE_LEGACY(to9_ieee_r, to9_ieee_w ) */
2165   AM_RANGE ( 0xa7f2, 0xa7f3 ) AM_READWRITE_LEGACY(to7_midi_r, to7_midi_w )
2170/*   AM_RANGE ( 0xa7f0, 0xa7f7 ) AM_READWRITE(to9_ieee_r, to9_ieee_w ) */
2171   AM_RANGE ( 0xa7f2, 0xa7f3 ) AM_READWRITE(to7_midi_r, to7_midi_w )
21662172   AM_RANGE ( 0xa7f8, 0xa7fb ) AM_DEVREADWRITE( "pia_3", pia6821_device, read_alt, write_alt)
21672173   AM_RANGE ( 0xa7fe, 0xa7ff ) AM_DEVREADWRITE_LEGACY("mea8000", mea8000_r, mea8000_w)
2168   AM_RANGE ( 0xb000, 0xefff ) AM_READ_BANK ( THOM_CART_BANK) AM_WRITE_LEGACY(mo6_cartridge_w ) /* 4 * 16 KB */
2174   AM_RANGE ( 0xb000, 0xefff ) AM_READ_BANK ( THOM_CART_BANK) AM_WRITE(mo6_cartridge_w ) /* 4 * 16 KB */
21692175   AM_RANGE ( 0xf000, 0xffff ) AM_ROMBANK   ( TO8_BIOS_BANK )
21702176
21712177/* 0x10000 - 0x1ffff: 64 KB external ROM cartridge */
r21425r21426
23072313/* ------------ driver ------------ */
23082314
23092315static MACHINE_CONFIG_DERIVED( mo5nr, to7 )
2310   MCFG_MACHINE_START ( mo5nr )
2311   MCFG_MACHINE_RESET ( mo5nr )
2316   MCFG_MACHINE_START_OVERRIDE( thomson_state, mo5nr )
2317   MCFG_MACHINE_RESET_OVERRIDE( thomson_state, mo5nr )
23122318
23132319   MCFG_CPU_MODIFY( "maincpu" )
23142320   MCFG_CPU_PROGRAM_MAP ( mo5nr)
trunk/src/mess/machine/thomflop.c
r21425r21426
8080
8181
8282/* build an identifier, with header & space */
83static int thom_floppy_make_addr( chrn_id id, UINT8* dst, int sector_size )
83int thomson_state::thom_floppy_make_addr( chrn_id id, UINT8* dst, int sector_size )
8484{
8585   if ( sector_size == 128 )
8686   {
r21425r21426
115115
116116
117117/* build a sector, with header & space */
118static int thom_floppy_make_sector( device_t* img, chrn_id id, UINT8* dst, int sector_size )
118int thomson_state::thom_floppy_make_sector( device_t* img, chrn_id id, UINT8* dst, int sector_size )
119119{
120120   if ( sector_size == 128 )
121121   {
r21425r21426
146146
147147
148148/* build a whole track */
149static int thom_floppy_make_track( device_t* img, UINT8* dst, int sector_size, int side )
149int thomson_state::thom_floppy_make_track( device_t* img, UINT8* dst, int sector_size, int side )
150150{
151151   UINT8 space = ( sector_size == 128 ) ? 0xff : 0;
152152   UINT8* org = dst;
r21425r21426
210210
211211
212212/* build an identifier, with header */
213static int thom_qdd_make_addr( int sector, UINT8* dst )
213int thomson_state::thom_qdd_make_addr( int sector, UINT8* dst )
214214{
215215   dst[  0 ] = 0xa5;
216216   dst[  1 ] = sector >> 8;
r21425r21426
222222
223223
224224/* build a sector, with header */
225static int thom_qdd_make_sector( device_t* img, int sector, UINT8* dst )
225int thomson_state::thom_qdd_make_sector( device_t* img, int sector, UINT8* dst )
226226{
227227   int i;
228228   dst[ 0 ] = 0x5a;
r21425r21426
236236
237237
238238/* build a whole disk */
239static int thom_qdd_make_disk ( device_t* img, UINT8* dst )
239int thomson_state::thom_qdd_make_disk ( device_t* img, UINT8* dst )
240240{
241241   UINT8* org = dst;
242242   int i;
r21425r21426
271271
272272
273273
274static READ8_HANDLER ( to7_5p14_r )
274READ8_MEMBER( thomson_state::to7_5p14_r )
275275{
276   device_t *fdc = space.machine().device("wd2793");
276   device_t *fdc = machine().device("wd2793");
277277
278278   if ( offset < 4 )
279279      return wd17xx_r( fdc, space, offset );
280280   else if ( offset == 8 )
281281      return to7_5p14_select;
282282   else
283      logerror ( "%f $%04x to7_5p14_r: invalid read offset %i\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), offset );
283      logerror ( "%f $%04x to7_5p14_r: invalid read offset %i\n", machine().time().as_double(), m_maincpu->pc(), offset );
284284   return 0;
285285}
286286
287287
288288
289static WRITE8_HANDLER( to7_5p14_w )
289WRITE8_HANDLER( thomson_state::to7_5p14_w )
290290{
291   device_t *fdc = space.machine().device("wd2793");
291   device_t *fdc = machine().device("wd2793");
292292   if ( offset < 4 )
293293      wd17xx_w( fdc, space, offset, data );
294294   else if ( offset == 8 )
r21425r21426
304304      case 4: drive = 2; side = 0; break;
305305      case 5: drive = 3; side = 1; break;
306306      default:
307         logerror( "%f $%04x to7_5p14_w: invalid drive select pattern $%02X\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data );
307         logerror( "%f $%04x to7_5p14_w: invalid drive select pattern $%02X\n", machine().time().as_double(), m_maincpu->pc(), data );
308308      }
309309
310310      wd17xx_dden_w(fdc, BIT(data, 7));
r21425r21426
313313
314314      if ( drive != -1 )
315315      {
316         thom_floppy_active( space.machine(), 0 );
316         thom_floppy_active( 0 );
317317         wd17xx_set_drive( fdc, drive );
318318         wd17xx_set_side( fdc, side );
319319         LOG(( "%f $%04x to7_5p14_w: $%02X set drive=%i side=%i density=%s\n",
320               space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(),
320               machine().time().as_double(), m_maincpu->pc(),
321321               data, drive, side, (BIT(data, 7) ? "FM" : "MFM")));
322322      }
323323   }
324324   else
325325      logerror ( "%f $%04x to7_5p14_w: invalid write offset %i (data=$%02X)\n",
326            space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), offset, data );
326            machine().time().as_double(), m_maincpu->pc(), offset, data );
327327}
328328
329329
330330
331static void to7_5p14_reset( running_machine &machine )
331void thomson_state::to7_5p14_reset()
332332{
333   device_t *fdc = machine.device("wd2793");
333   device_t *fdc = machine().device("wd2793");
334334   LOG(( "to7_5p14_reset: CD 90-640 controller\n" ));
335335   wd17xx_reset(fdc);
336336}
337337
338338
339339
340static void to7_5p14_init( running_machine &machine )
340void thomson_state::to7_5p14_init()
341341{
342342   LOG(( "to7_5p14_init: CD 90-640 controller\n" ));
343   state_save_register_global( machine, to7_5p14_select );
343   state_save_register_global( machine(), to7_5p14_select );
344344}
345345
346346
r21425r21426
359359
360360
361361
362static READ8_HANDLER ( to7_5p14sd_r )
362READ8_MEMBER( thomson_state::to7_5p14sd_r )
363363{
364364   if ( offset < 8 )
365      return mc6843_r( space.machine().device("mc6843"), space, offset );
365      return mc6843_r( machine().device("mc6843"), space, offset );
366366   else if ( offset >= 8 && offset <= 9 )
367367      return to7_5p14sd_select;
368368   else
369      logerror ( "%f $%04x to7_5p14sd_r: invalid read offset %i\n",  space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), offset );
369      logerror ( "%f $%04x to7_5p14sd_r: invalid read offset %i\n",  machine().time().as_double(), m_maincpu->pc(), offset );
370370   return 0;
371371}
372372
373373
374374
375static WRITE8_HANDLER( to7_5p14sd_w )
375WRITE8_MEMBER( thomson_state::to7_5p14sd_w )
376376{
377377   if ( offset < 8 )
378      mc6843_w( space.machine().device("mc6843"), space, offset, data );
378      mc6843_w( machine().device("mc6843"), space, offset, data );
379379   else if ( offset >= 8 && offset <= 9 )
380380   {
381381      /* drive select */
r21425r21426
406406
407407      if ( drive != -1 )
408408      {
409         thom_floppy_active( space.machine(), 0 );
410         mc6843_set_drive( space.machine().device("mc6843"), drive );
411         mc6843_set_side( space.machine().device("mc6843"), side );
409         thom_floppy_active( 0 );
410         mc6843_set_drive( machine().device("mc6843"), drive );
411         mc6843_set_side( machine().device("mc6843"), side );
412412         LOG(( "%f $%04x to7_5p14sd_w: $%02X set drive=%i side=%i\n",
413               space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data, drive, side ));
413               machine().time().as_double(), m_maincpu->pc(), data, drive, side ));
414414      }
415415   }
416416   else
417417      logerror ( "%f $%04x to7_5p14sd_w: invalid write offset %i (data=$%02X)\n",
418            space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), offset, data );
418            machine().time().as_double(), m_maincpu->pc(), offset, data );
419419}
420420
421static void to7_5p14_index_pulse_callback( device_t *controller,device_t *image, int state )
421void thomson_state::to7_5p14_index_pulse_callback( device_t *controller,device_t *image, int state )
422422{
423   mc6843_set_index_pulse( image->machine().device("mc6843"), state );
423   mc6843_set_index_pulse( machine().device("mc6843"), state );
424424}
425425
426static void to7_5p14sd_reset( running_machine &machine )
426void thomson_state::to7_5p14sd_reset()
427427{
428428   int i;
429429   LOG(( "to7_5p14sd_reset: CD 90-015 controller\n" ));
430   for ( i = 0; i < floppy_get_count( machine ); i++ )
430   for ( i = 0; i < floppy_get_count( machine() ); i++ )
431431   {
432      device_t * img = floppy_get_device( machine, i );
432      device_t * img = floppy_get_device( machine(), i );
433433      if (img) {
434434         floppy_drive_set_ready_state( img, FLOPPY_DRIVE_READY, 0 );
435435         floppy_drive_set_rpm( img, 300. );
r21425r21426
444444
445445
446446
447static void to7_5p14sd_init( running_machine &machine )
447void thomson_state::to7_5p14sd_init()
448448{
449449   LOG(( "to7_5p14sd_init: CD 90-015 controller\n" ));
450   state_save_register_global( machine, to7_5p14sd_select );
450   state_save_register_global( machine(), to7_5p14sd_select );
451451}
452452
453453
r21425r21426
520520
521521
522522
523static void to7_qdd_index_pulse_cb ( device_t *controller,device_t *image, int state )
523void thomson_state::to7_qdd_index_pulse_cb( device_t *controller,device_t *image, int state )
524524{
525525   to7qdd->index_pulse = state;
526526
r21425r21426
532532      to7qdd->data_size = 0;
533533   }
534534
535   VLOG(( "%f to7_qdd_pulse_cb: state=%i\n", image->machine().time().as_double(), state ));
535   VLOG(( "%f to7_qdd_pulse_cb: state=%i\n", machine().time().as_double(), state ));
536536}
537537
538538
539539
540static device_t * to7_qdd_image ( running_machine &machine )
540device_t * thomson_state::to7_qdd_image()
541541{
542   return floppy_get_device( machine, 0 );
542   return floppy_get_device( machine(), 0 );
543543}
544544
545545
546546
547547/* update MC6852 status register */
548static void to7_qdd_stat_update( running_machine &machine )
548void thomson_state::to7_qdd_stat_update()
549549{
550550   /* byte-ready */
551551   to7qdd->status |= QDD_S_RDA | QDD_S_TDRA;
r21425r21426
553553      to7qdd->status |= QDD_S_PE;
554554
555555   /* write-protect */
556   if (floppy_wpt_r(to7_qdd_image(machine)) == CLEAR_LINE)
556   if (floppy_wpt_r(to7_qdd_image()) == CLEAR_LINE)
557557      to7qdd->status |= QDD_S_NCTS;
558558
559559   /* sticky reset conditions */
r21425r21426
577577
578578
579579
580static UINT8 to7_qdd_read_byte( running_machine &machine )
580UINT8 thomson_state::to7_qdd_read_byte()
581581{
582582   UINT8 data;
583583
584584   /* rebuild disk if needed */
585585   if ( !to7qdd->data_size )
586586   {
587      to7qdd->data_size = thom_qdd_make_disk( to7_qdd_image(machine), to7qdd->data );
587      to7qdd->data_size = thom_qdd_make_disk( to7_qdd_image(), to7qdd->data );
588588      assert( to7qdd->data_idx < sizeof( to7qdd->data ) );
589589   }
590590
r21425r21426
594594      data = to7qdd->data[ to7qdd->data_idx ];
595595
596596   VLOG(( "%f $%04x to7_qdd_read_byte: RDATA off=%i/%i data=$%02X\n",
597         machine.time().as_double(), machine.device("maincpu")->safe_pcbase(),
597         machine().time().as_double(), m_maincpu->pc(),
598598         to7qdd->data_idx, to7qdd->data_size, data ));
599599
600600   to7qdd->data_idx++;
r21425r21426
610610   * CPU write id field and data field => format
611611   * CPU write data field after it has read an id field => sector write
612612   */
613static void to7_qdd_write_byte( running_machine &machine, UINT8 data )
613void thomson_state::to7_qdd_write_byte( UINT8 data )
614614{
615615   int i;
616616
617617   /* rebuild disk if needed */
618618   if ( !to7qdd->data_size )
619619   {
620      to7qdd->data_size = thom_qdd_make_disk( to7_qdd_image(machine), to7qdd->data );
620      to7qdd->data_size = thom_qdd_make_disk( to7_qdd_image(), to7qdd->data );
621621      assert( to7qdd->data_idx < sizeof( to7qdd->data ) );
622622   }
623623
r21425r21426
634634      to7qdd->data_idx++;
635635
636636      VLOG (( "%f $%04x to7_qdd_write_byte: got $%02X offs=%i-%i\n",
637         machine.time().as_double(), machine.device("maincpu")->safe_pcbase(), data,
637         machine().time().as_double(), m_maincpu->pc(), data,
638638         to7qdd->start_idx, to7qdd->data_idx ));
639639
640640      /* end of tentative id field */
r21425r21426
647647         UINT8 filler = 0xff;
648648
649649         LOG(( "%f $%04x to7_qdd_write_byte: got id field for sector=%i\n",
650               machine.time().as_double(), machine.device("maincpu")->safe_pcbase(), sector ));
650               machine().time().as_double(), m_maincpu->pc(), sector ));
651651
652         floppy_drive_format_sector( to7_qdd_image(machine),
652         floppy_drive_format_sector( to7_qdd_image(),
653653                     0, sector, 0, 0, sector, 128, filler );
654                  thom_floppy_active( machine, 1 );
654                  thom_floppy_active( 1 );
655655         to7qdd->start_idx = to7qdd->data_idx;
656656      }
657657
r21425r21426
676676            int sector = (int) to7qdd->data[ i + 1 ] * 256 + (int) to7qdd->data[ i + 2 ];
677677
678678            LOG(( "%f $%04x to7_qdd_write_byte: goto data field for sector=%i\n",
679                  machine.time().as_double(), machine.device("maincpu")->safe_pcbase(), sector ));
679                  machine().time().as_double(), m_maincpu->pc(), sector ));
680680
681            floppy_drive_write_sector_data( to7_qdd_image(machine), 0, sector, to7qdd->data + to7qdd->start_idx + 1, 128, 0 );
682                        thom_floppy_active( machine, 1 );
681            floppy_drive_write_sector_data( to7_qdd_image(), 0, sector, to7qdd->data + to7qdd->start_idx + 1, 128, 0 );
682                        thom_floppy_active( 1 );
683683         }
684684
685685         to7qdd->start_idx = to7qdd->data_idx;
r21425r21426
691691
692692
693693
694static READ8_HANDLER ( to7_qdd_r )
694READ8_MEMBER( thomson_state::to7_qdd_r )
695695{
696696   switch ( offset )
697697   {
698698   case 0: /* MC6852 status */
699      to7_qdd_stat_update(space.machine());
699      to7_qdd_stat_update();
700700      VLOG(( "%f $%04x to7_qdd_r: STAT=$%02X irq=%i pe=%i ovr=%i und=%i tr=%i rd=%i ncts=%i\n",
701            space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), to7qdd->status,
701            machine().time().as_double(), m_maincpu->pc(), to7qdd->status,
702702            to7qdd->status & QDD_S_IRQ  ? 1 : 0,
703703            to7qdd->status & QDD_S_PE   ? 1 : 0,
704704            to7qdd->status & QDD_S_OVR  ? 1 : 0,
r21425r21426
710710
711711   case 1: /* MC6852 data input => read byte from disk */
712712      to7qdd->status &= ~(QDD_S_RDA | QDD_S_PE | QDD_S_OVR);
713      to7_qdd_stat_update(space.machine());
714      return to7_qdd_read_byte(space.machine());
713      to7_qdd_stat_update();
714      return to7_qdd_read_byte();
715715
716716   case 8: /* floppy status */
717717   {
718718      UINT8 data = 0;
719      device_image_interface* img = dynamic_cast<device_image_interface *>(to7_qdd_image(space.machine()));
719      device_image_interface* img = dynamic_cast<device_image_interface *>(to7_qdd_image());
720720      if ( ! img->exists() )
721721         data |= 0x40; /* disk present */
722722      if ( to7qdd->index_pulse )
723723         data |= 0x80; /* disk start */
724      VLOG(( "%f $%04x to7_qdd_r: STATUS8 $%02X\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data ));
724      VLOG(( "%f $%04x to7_qdd_r: STATUS8 $%02X\n", machine().time().as_double(), m_maincpu->pc(), data ));
725725      return data;
726726   }
727727
728728   default:
729      logerror ( "%f $%04x to7_qdd_r: invalid read offset %i\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), offset );
729      logerror ( "%f $%04x to7_qdd_r: invalid read offset %i\n", machine().time().as_double(), m_maincpu->pc(), offset );
730730      return 0;
731731   }
732732}
733733
734734
735735
736static WRITE8_HANDLER( to7_qdd_w )
736WRITE8_MEMBER( thomson_state::to7_qdd_w )
737737{
738738   switch ( offset )
739739   {
r21425r21426
745745         to7qdd->status &= ~(QDD_S_TDRA | QDD_S_TUF);
746746
747747      to7qdd->ctrl1 = ( data & ~(QDD_C1_RRESET | QDD_C1_TRESET) ) |( data &  (QDD_C1_RRESET | QDD_C1_TRESET) & to7qdd->ctrl1 );
748      to7_qdd_stat_update(space.machine());
748      to7_qdd_stat_update();
749749      VLOG(( "%f $%04x to7_qdd_w: CTRL1=$%02X reset=%c%c %s%sirq=%c%c\n",
750            space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data,
750            machine().time().as_double(), m_maincpu->pc(), data,
751751            data & QDD_C1_RRESET ? 'r' : '-', data & QDD_C1_TRESET ? 't' : '-',
752752            data & QDD_C1_STRIPSYNC ? "strip-sync " : "",
753753            data & QDD_C1_CLRSYNC ? "clear-sync " : "",
r21425r21426
770770         parity = par[ (data >> 3) & 7 ];
771771         to7_qdd_stat_update(space.machine());
772772         VLOG(( "%f $%04x to7_qdd_w: CTRL2=$%02X bits=%i par=%s blen=%i under=%s%s\n",
773               space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data,
773               machine().time().as_double(), m_maincpu->pc(), data,
774774               bits, parname[ parity ], data & QDD_C2_BLEN ? 1 : 2,
775775               data & QDD_C2_TSYNC ? "sync" : "ff",
776776               data & QDD_C2_EIE ? "irq-err" : "" ));
r21425r21426
786786            to7qdd->status &= ~QDD_S_TUF;
787787         if ( data & QDD_C3_CLRCTS )
788788            to7qdd->status &= ~QDD_S_NCTS;
789         to7_qdd_stat_update(space.machine());
789         to7_qdd_stat_update();
790790         VLOG(( "%f $%04x to7_qdd_w: CTRL3=$%02X %s%ssync-len=%i sync-mode=%s\n",
791               space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data,
791               machine().time().as_double(), m_maincpu->pc(), data,
792792               data & QDD_C3_CLRTUF ? "clr-tuf " : "",
793793               data & QDD_C3_CLRCTS ? "clr-cts " : "",
794794               data & QDD_C3_SYNCLEN ? 1 : 2,
r21425r21426
796796         break;
797797
798798      case 2: /* MC6852 sync code => write byte to disk */
799         to7_qdd_write_byte( space.machine(), data );
799         to7_qdd_write_byte( data );
800800         break;
801801
802802      case 3: /* MC6852 data out => does not seem to be used */
803         VLOG(( "%f $%04x to7_qdd_w: ignored WDATA=$%02X\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data ));
803         VLOG(( "%f $%04x to7_qdd_w: ignored WDATA=$%02X\n", machine().time().as_double(), m_maincpu->pc(), data ));
804804         break;
805805
806806      }
r21425r21426
808808
809809   case 8: /* set drive */
810810      to7qdd->drive = data;
811      VLOG(( "%f $%04x to7_qdd_w: DRIVE=$%02X\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data ));
811      VLOG(( "%f $%04x to7_qdd_w: DRIVE=$%02X\n", machine().time().as_double(), m_maincpu->pc(), data ));
812812      break;
813813
814814   case 12: /* motor pulse ? */
815      thom_floppy_active( space.machine(), 0 );
816      VLOG(( "%f $%04x to7_qdd_w: MOTOR=$%02X\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data ));
815      thom_floppy_active( 0 );
816      VLOG(( "%f $%04x to7_qdd_w: MOTOR=$%02X\n", machine().time().as_double(), m_maincpu->pc(), data ));
817817      break;
818818
819819   default:
820      logerror ( "%f $%04x to7_qdd_w: invalid write offset %i (data=$%02X)\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), offset, data );
820      logerror ( "%f $%04x to7_qdd_w: invalid write offset %i (data=$%02X)\n", machine().time().as_double(), m_maincpu->pc(), offset, data );
821821   }
822822}
823823
824824
825825
826static void to7_qdd_reset( running_machine &machine )
826void thomson_state::to7_qdd_reset()
827827{
828828   int i;
829829   LOG(( "to7_qdd_reset: CQ 90-028 controller\n" ));
830830
831   for ( i = 0; i < floppy_get_count( machine ); i++ )
831   for ( i = 0; i < floppy_get_count( machine() ); i++ )
832832   {
833      device_t * img = floppy_get_device( machine, i );
833      device_t * img = floppy_get_device( machine(), i );
834834      if (img) {
835835         floppy_drive_set_ready_state( img, FLOPPY_DRIVE_READY, 0 );
836836
r21425r21426
847847   to7qdd->ctrl2 &= 0x7c; /* clear EIE, PC2-PC1 */
848848   to7qdd->ctrl3 &= 0xfe; /* internal sync */
849849   to7qdd->drive = 0;
850   to7_qdd_stat_update(machine);
850   to7_qdd_stat_update();
851851}
852852
853853
854854
855static void to7_qdd_init( running_machine &machine )
855void thomson_state::to7_qdd_init()
856856{
857857   LOG(( "to7_qdd_init: CQ 90-028 controller\n" ));
858858
859   to7qdd = auto_alloc(machine, to7qdd_t);
859   to7qdd = auto_alloc(machine(), to7qdd_t);
860860
861   state_save_register_global( machine, to7qdd->status );
862   state_save_register_global( machine, to7qdd->ctrl1 );
863   state_save_register_global( machine, to7qdd->ctrl2 );
864   state_save_register_global( machine, to7qdd->ctrl3 );
865   state_save_register_global( machine, to7qdd->drive );
866   state_save_register_global( machine, to7qdd->data_idx );
867   state_save_register_global( machine, to7qdd->start_idx );
868   state_save_register_global( machine, to7qdd->data_size );
869   state_save_register_global( machine, to7qdd->data_crc );
870   state_save_register_global( machine, to7qdd->index_pulse );
871   state_save_register_global_array( machine, to7qdd->data );
861   state_save_register_global( machine(), to7qdd->status );
862   state_save_register_global( machine(), to7qdd->ctrl1 );
863   state_save_register_global( machine(), to7qdd->ctrl2 );
864   state_save_register_global( machine(), to7qdd->ctrl3 );
865   state_save_register_global( machine(), to7qdd->drive );
866   state_save_register_global( machine(), to7qdd->data_idx );
867   state_save_register_global( machine(), to7qdd->start_idx );
868   state_save_register_global( machine(), to7qdd->data_size );
869   state_save_register_global( machine(), to7qdd->data_crc );
870   state_save_register_global( machine(), to7qdd->index_pulse );
871   state_save_register_global_array( machine(), to7qdd->data );
872872}
873873
874874
r21425r21426
932932
933933
934934
935static device_t * thmfc_floppy_image ( running_machine &machine )
935device_t * thomson_state::thmfc_floppy_image()
936936{
937   return floppy_get_device( machine, thmfc1->drive );
937   return floppy_get_device( machine(), thmfc1->drive );
938938}
939939
940940
941941
942static int thmfc_floppy_is_qdd ( device_image_interface *image )
942int thomson_state::thmfc_floppy_is_qdd ( device_image_interface *image )
943943{
944944   if (image==NULL) return 0;
945945   if (!image->exists()) return 0;
r21425r21426
948948
949949
950950
951static void thmfc_floppy_index_pulse_cb ( device_t *controller,device_t *image, int state )
951void thomson_state::thmfc_floppy_index_pulse_cb ( device_t *controller,device_t *image, int state )
952952{
953   if ( image != thmfc_floppy_image(image->machine()))
953   if ( image != thmfc_floppy_image())
954954      return;
955955
956956   if ( thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(image)))
r21425r21426
973973         thmfc1->data_raw_idx = 0;
974974   }
975975
976   VLOG(( "%f thmfc_floppy_index_pulse_cb: state=%i\n", image->machine().time().as_double(), state ));
976   VLOG(( "%f thmfc_floppy_index_pulse_cb: state=%i\n", machine().time().as_double(), state ));
977977}
978978
979979
980980
981static int thmfc_floppy_find_sector ( running_machine &machine, chrn_id* dst )
981int thomson_state::thmfc_floppy_find_sector( chrn_id* dst )
982982{
983   device_t* img = thmfc_floppy_image(machine);
983   device_t* img = thmfc_floppy_image();
984984   chrn_id id;
985985   int r = 0;
986986
r21425r21426
10141014
10151015
10161016/* complete command (by read, write, or timeout) */
1017static void thmfc_floppy_cmd_complete( running_machine &machine )
1017void thomson_state::thmfc_floppy_cmd_complete()
10181018{
10191019   LOG (( "%f thmfc_floppy_cmd_complete_cb: cmd=%i off=%i/%i/%i\n",
1020         machine.time().as_double(), thmfc1->op, thmfc1->data_idx,
1020         machine().time().as_double(), thmfc1->op, thmfc1->data_idx,
10211021         thmfc1->data_finish - 1, thmfc1->data_size - 1 ));
10221022
10231023   if ( thmfc1->op == THMFC1_OP_WRITE_SECT )
10241024   {
1025      device_t * img = thmfc_floppy_image(machine);
1025      device_t * img = thmfc_floppy_image();
10261026      floppy_drive_write_sector_data( img, thmfc1->side, thmfc1->sector_id, thmfc1->data + 3, thmfc1->data_size - 3, 0 );
1027            thom_floppy_active( machine, 1 );
1027            thom_floppy_active( 1 );
10281028   }
10291029   thmfc1->op = THMFC1_OP_RESET;
10301030   thmfc1->stat0 |= THMFC1_STAT0_FINISHED;
r21425r21426
10351035
10361036
10371037
1038static TIMER_CALLBACK( thmfc_floppy_cmd_complete_cb )
1038TIMER_CALLBACK_MEMBER( thomson_state::thmfc_floppy_cmd_complete_cb )
10391039{
1040   thmfc_floppy_cmd_complete( machine );
1040   thmfc_floppy_cmd_complete();
10411041}
10421042
10431043
10441044
10451045/* intelligent read: show just one field, skip header */
1046static UINT8 thmfc_floppy_read_byte ( running_machine &machine )
1046UINT8 thomson_state::thmfc_floppy_read_byte()
10471047{
10481048   UINT8 data = thmfc1->data[ thmfc1->data_idx ];
10491049
10501050   VLOG(( "%f $%04x thmfc_floppy_read_byte: off=%i/%i/%i data=$%02X\n",
1051         machine.time().as_double(), machine.device("maincpu")->safe_pcbase(),
1051         machine().time().as_double(), m_maincpu->pc(),
10521052         thmfc1->data_idx, thmfc1->data_finish - 1, thmfc1->data_size - 1,
10531053         data ));
10541054
10551055   if ( thmfc1->data_idx >= thmfc1->data_size - 1 )
1056      thmfc_floppy_cmd_complete( machine );
1056      thmfc_floppy_cmd_complete();
10571057   else
10581058      thmfc1->data_idx++;
10591059
r21425r21426
10661066
10671067
10681068/* dumb read: show whole track with field headers and gaps  */
1069static UINT8 thmfc_floppy_raw_read_byte ( running_machine &machine )
1069UINT8 thomson_state::thmfc_floppy_raw_read_byte()
10701070{
10711071   UINT8 data;
10721072
10731073   /* rebuild track if needed */
10741074   if ( ! thmfc1->data_raw_size )
10751075   {
1076      if ( thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(thmfc_floppy_image(machine))))
1076      if ( thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(thmfc_floppy_image())))
10771077         /* QDD: track = whole disk */
1078         thmfc1->data_raw_size = thom_qdd_make_disk ( thmfc_floppy_image(machine), thmfc1->data );
1078         thmfc1->data_raw_size = thom_qdd_make_disk ( thmfc_floppy_image(), thmfc1->data );
10791079      else
10801080      {
10811081         thmfc1->data_raw_idx = 0;
1082         thmfc1->data_raw_size = thom_floppy_make_track( thmfc_floppy_image(machine), thmfc1->data,
1082         thmfc1->data_raw_size = thom_floppy_make_track( thmfc_floppy_image(), thmfc1->data,
10831083                           thmfc1->sector_size, thmfc1->side );
10841084      }
10851085      assert( thmfc1->data_raw_size < sizeof( thmfc1->data ) );
r21425r21426
10911091      data = thmfc1->data[ thmfc1->data_raw_idx ];
10921092
10931093   VLOG(( "%f $%04x thmfc_floppy_raw_read_byte: off=%i/%i data=$%02X\n",
1094         machine.time().as_double(), machine.device("maincpu")->safe_pcbase(),
1094         machine().time().as_double(), m_maincpu->pc(),
10951095         thmfc1->data_raw_idx, thmfc1->data_raw_size, data ));
10961096
10971097   thmfc1->data_raw_idx++;
r21425r21426
11021102
11031103
11041104/* QDD writing / formating */
1105static void thmfc_floppy_qdd_write_byte ( running_machine &machine, UINT8 data )
1105void thomson_state::thmfc_floppy_qdd_write_byte( UINT8 data )
11061106{
11071107   int i;
11081108
r21425r21426
11121112   {
11131113      if ( ! thmfc1->data_raw_size )
11141114      {
1115         thmfc1->data_raw_size = thom_qdd_make_disk ( thmfc_floppy_image(machine), thmfc1->data );
1115         thmfc1->data_raw_size = thom_qdd_make_disk ( thmfc_floppy_image(), thmfc1->data );
11161116         assert( thmfc1->data_raw_size < sizeof( thmfc1->data ) );
11171117      }
11181118
r21425r21426
11281128      }
11291129
11301130      VLOG (( "%f $%04x thmfc_floppy_qdd_write_byte: $%02X offs=%i-%i\n",
1131         machine.time().as_double(), machine.device("maincpu")->safe_pcbase(), data,
1131         machine().time().as_double(), m_maincpu->pc(), data,
11321132         thmfc1->data_idx,thmfc1->data_raw_idx ));
11331133
11341134      if ( thmfc1->data_raw_idx == thmfc1->data_idx + 3 &&
r21425r21426
11391139         int sector = (int) thmfc1->data[ thmfc1->data_idx ] * 256 + (int) thmfc1->data[ thmfc1->data_idx + 1 ];
11401140         UINT8 filler = 0xff;
11411141
1142         LOG(( "%f $%04x thmfc_floppy_qdd_write_byte: id field, sector=%i\n", machine.time().as_double(), machine.device("maincpu")->safe_pcbase(), sector ));
1142         LOG(( "%f $%04x thmfc_floppy_qdd_write_byte: id field, sector=%i\n", machine().time().as_double(), m_maincpu->pc(), sector ));
11431143
1144         floppy_drive_format_sector( thmfc_floppy_image(machine), 0, sector, 0, 0, sector, 128, filler );
1145                  thom_floppy_active( machine, 1 );
1144         floppy_drive_format_sector( thmfc_floppy_image(), 0, sector, 0, 0, sector, 128, filler );
1145         thom_floppy_active( 1 );
11461146         thmfc1->data_idx = 0;
11471147      }
11481148
r21425r21426
11631163         if ( i >= 0 )
11641164         {
11651165            /* got an id & a data field => write */
1166            device_t * img = thmfc_floppy_image(machine);
1166            device_t * img = thmfc_floppy_image();
11671167            int sector = (int) thmfc1->data[ i + 1 ] * 256 +
11681168               (int) thmfc1->data[ i + 2 ];
11691169
11701170            LOG(( "%f $%04x thmfc_floppy_qdd_write_byte: data field, sector=%i\n",
1171                  machine.time().as_double(), machine.device("maincpu")->safe_pcbase(), sector ));
1171                  machine().time().as_double(), m_maincpu->pc(), sector ));
11721172
11731173            floppy_drive_write_sector_data( img, 0, sector, thmfc1->data + thmfc1->data_idx, 128, 0 );
1174                        thom_floppy_active( machine, 1 );
1174            thom_floppy_active( 1 );
11751175         }
11761176
11771177         thmfc1->data_idx = 0;
r21425r21426
11831183   else
11841184   {
11851185      thmfc1->data_raw_idx++;
1186      VLOG (( "%f $%04x thmfc_floppy_qdd_write_byte: ignored $%02X\n", machine.time().as_double(), machine.device("maincpu")->safe_pcbase(), data ));
1186      VLOG (( "%f $%04x thmfc_floppy_qdd_write_byte: ignored $%02X\n", machine().time().as_double(), m_maincpu->pc(), data ));
11871187   }
11881188
11891189}
r21425r21426
11911191
11921192
11931193/* intelligent writing */
1194static void thmfc_floppy_write_byte ( running_machine &machine, UINT8 data )
1194void thomson_state::thmfc_floppy_write_byte( UINT8 data )
11951195{
11961196   VLOG (( "%f $%04x thmfc_floppy_write_byte: off=%i/%i data=$%02X\n",
1197      machine.time().as_double(), machine.device("maincpu")->safe_pcbase(),
1197      machine().time().as_double(), m_maincpu->pc(),
11981198      thmfc1->data_idx, thmfc1->data_size - 1, data ));
11991199
12001200   thmfc1->data_raw_size = 0;
12011201   thmfc1->data[ thmfc1->data_idx ] = data;
12021202   if ( thmfc1->data_idx >= thmfc1->data_size - 1 )
1203      thmfc_floppy_cmd_complete( machine );
1203      thmfc_floppy_cmd_complete();
12041204   else
12051205      thmfc1->data_idx++;
12061206}
12071207
12081208/* intelligent formatting */
1209static void thmfc_floppy_format_byte ( running_machine &machine, UINT8 data )
1209void thomson_state::thmfc_floppy_format_byte( UINT8 data )
12101210{
1211   VLOG (( "%f $%04x thmfc_floppy_format_byte: $%02X\n", machine.time().as_double(), machine.device("maincpu")->safe_pcbase(), data ));
1211   VLOG (( "%f $%04x thmfc_floppy_format_byte: $%02X\n", machine().time().as_double(), m_maincpu->pc(), data ));
12121212
12131213   thmfc1->data_raw_size = 0;
12141214
r21425r21426
12231223         if ( !memcmp ( thmfc1->data, header, sizeof( header ) ) )
12241224         {
12251225            /* got id field => format */
1226            device_t * img = thmfc_floppy_image(machine);
1226            device_t * img = thmfc_floppy_image();
12271227            UINT8 track  = thmfc1->data[4];
12281228            UINT8 side   = thmfc1->data[5];
12291229            UINT8 sector = thmfc1->data[6];
12301230            UINT8 length = thmfc1->data[7]; /* actually, log length */
12311231            UINT8 filler = 0xe5;            /* standard Thomson filler */
12321232                        chrn_id id;
1233                        if ( thmfc_floppy_find_sector( machine, &id ) )
1233                        if ( thmfc_floppy_find_sector( &id ) )
12341234                        {
12351235                              floppy_drive_format_sector( img, side, thmfc1->sector_id, track, thmfc1->side, sector, length, filler );
1236                              thom_floppy_active( machine, 1 );
1236                              thom_floppy_active( 1 );
12371237                        }
12381238         }
12391239
r21425r21426
12451245
12461246
12471247
1248READ8_HANDLER ( thmfc_floppy_r )
1248READ8_MEMBER( thomson_state::thmfc_floppy_r )
12491249{
12501250   switch ( offset )
12511251   {
12521252   case 0: /* STAT0 */
12531253      thmfc1->stat0 ^= THMFC1_STAT0_SYNCHRO | THMFC1_STAT0_BYTE_READY_POL;
1254      VLOG(( "%f $%04x thmfc_floppy_r: STAT0=$%02X\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), thmfc1->stat0 ));
1254      VLOG(( "%f $%04x thmfc_floppy_r: STAT0=$%02X\n", machine().time().as_double(), m_maincpu->pc(), thmfc1->stat0 ));
12551255      return thmfc1->stat0;
12561256
12571257   case 1: /* STAT1 */
12581258   {
12591259      UINT8 data = 0;
1260      device_image_interface * img = dynamic_cast<device_image_interface *>(thmfc_floppy_image(space.machine()));
1260      device_image_interface * img = dynamic_cast<device_image_interface *>(thmfc_floppy_image());
12611261      int flags = floppy_drive_get_flag_state( &img->device(), -1 );
12621262      if ( thmfc_floppy_is_qdd(img) )
12631263      {
r21425r21426
12831283         data |= 0x10;
12841284      if (!floppy_wpt_r(&img->device()))
12851285         data |= 0x04;
1286      VLOG(( "%f $%04x thmfc_floppy_r: STAT1=$%02X\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data ));
1286      VLOG(( "%f $%04x thmfc_floppy_r: STAT1=$%02X\n", machine().time().as_double(), m_maincpu->pc(), data ));
12871287      return data;
12881288   }
12891289
12901290   case 3: /* RDATA */
12911291
12921292      if ( thmfc1->op == THMFC1_OP_READ_SECT || thmfc1->op == THMFC1_OP_READ_ADDR )
1293         return thmfc_floppy_read_byte(space.machine());
1293         return thmfc_floppy_read_byte();
12941294      else
1295         return thmfc_floppy_raw_read_byte(space.machine());
1295         return thmfc_floppy_raw_read_byte();
12961296
12971297   case 6:
12981298      return 0;
r21425r21426
13011301   {
13021302      /* undocumented => emulate TO7 QDD controller ? */
13031303      UINT8 data = thmfc1->ipl << 7;
1304      VLOG(( "%f $%04x thmfc_floppy_r: STAT8=$%02X\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data ));
1304      VLOG(( "%f $%04x thmfc_floppy_r: STAT8=$%02X\n", machine().time().as_double(), m_maincpu->pc(), data ));
13051305      return data;
13061306   }
13071307
13081308   default:
1309      logerror ( "%f $%04x thmfc_floppy_r: invalid read offset %i\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), offset );
1309      logerror ( "%f $%04x thmfc_floppy_r: invalid read offset %i\n", machine().time().as_double(), m_maincpu->pc(), offset );
13101310      return 0;
13111311   }
13121312}
13131313
13141314
13151315
1316WRITE8_HANDLER ( thmfc_floppy_w )
1316WRITE8_MEMBER( thomson_state::thmfc_floppy_w )
13171317{
13181318   switch ( offset ) {
13191319   case 0: /* CMD0 */
13201320   {
13211321      int wsync = (data >> 4) & 1;
1322      int qdd = thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(thmfc_floppy_image(space.machine())));
1322      int qdd = thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(thmfc_floppy_image()));
13231323      chrn_id id;
13241324      thmfc1->formatting = (data >> 2) & 1;
13251325      LOG (( "%f $%04x thmfc_floppy_w: CMD0=$%02X dens=%s wsync=%i dsync=%i fmt=%i op=%i\n",
1326            space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data,
1326            machine().time().as_double(), m_maincpu->pc(), data,
13271327            (BIT(data, 5) ? "FM" : "MFM"),
13281328            wsync, (data >> 3) & 1,
13291329            thmfc1->formatting, data & 3 ));
r21425r21426
13411341      case THMFC1_OP_WRITE_SECT:
13421342         if ( qdd )
13431343            logerror( "thmfc_floppy_w: smart operation 1 not supported for QDD\n" );
1344         else if ( thmfc_floppy_find_sector( space.machine(), &id ) )
1344         else if ( thmfc_floppy_find_sector( &id ) )
13451345         {
13461346                        thmfc1->sector_id = id.data_id;
13471347            thmfc1->data_idx = 0;
r21425r21426
13561356      case THMFC1_OP_READ_ADDR:
13571357         if ( qdd )
13581358            logerror( "thmfc_floppy_w: smart operation 2 not supported for QDD\n" );
1359         else if ( thmfc_floppy_find_sector( space.machine(), &id ) )
1359         else if ( thmfc_floppy_find_sector( &id ) )
13601360         {
13611361            thmfc1->data_size =
13621362               thom_floppy_make_addr( id, thmfc1->data, thmfc1->sector_size );
r21425r21426
13721372      case THMFC1_OP_READ_SECT:
13731373         if ( qdd )
13741374            logerror( "thmfc_floppy_w: smart operation 3 not supported for QDD\n" );
1375         else if ( thmfc_floppy_find_sector( space.machine(), &id ) )
1375         else if ( thmfc_floppy_find_sector( &id ) )
13761376         {
13771377            thmfc1->data_size = thom_floppy_make_sector
1378               ( thmfc_floppy_image(space.machine()), id, thmfc1->data, thmfc1->sector_size );
1378               ( thmfc_floppy_image(), id, thmfc1->data, thmfc1->sector_size );
13791379            assert( thmfc1->data_size < sizeof( thmfc1->data ) );
13801380            thmfc1->data_finish = thmfc1->sector_size + 4;
13811381            thmfc1->data_idx = 1;
r21425r21426
13891389      /* synchronize to word, if needed (QDD only) */
13901390      if ( wsync && qdd ) {
13911391         if ( ! thmfc1->data_raw_size )
1392            thmfc1->data_raw_size = thom_qdd_make_disk ( thmfc_floppy_image(space.machine()), thmfc1->data );
1392            thmfc1->data_raw_size = thom_qdd_make_disk ( thmfc_floppy_image(), thmfc1->data );
13931393         while ( thmfc1->data_raw_idx < thmfc1->data_raw_size &&
13941394            thmfc1->data[ thmfc1->data_raw_idx ] != thmfc1->wsync )
13951395         {
r21425r21426
14081408      if ( thmfc1->sector_size > 256 )
14091409      {
14101410         logerror( "$%04x thmfc_floppy_w: sector size %i > 256 not handled\n",
1411               space.machine().device("maincpu")->safe_pcbase(), thmfc1->sector_size );
1411               m_maincpu->pc(), thmfc1->sector_size );
14121412         thmfc1->sector_size = 256;
14131413      }
14141414
14151415      LOG (( "%f $%04x thmfc_floppy_w: CMD1=$%02X sect-size=%i comp=%i head=%i\n",
1416            space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data,
1416            machine().time().as_double(), m_maincpu->pc(), data,
14171417            thmfc1->sector_size, (data >> 1) & 7, thmfc1->side ));
14181418      break;
14191419
r21425r21426
14241424      int seek = 0, motor;
14251425      thmfc1->drive = data & 2;
14261426
1427      img = thmfc_floppy_image(space.machine());
1427      img = thmfc_floppy_image();
14281428      if ( thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(img)))
14291429      {
14301430         motor = !(data & 0x40);
r21425r21426
14361436            seek = (data & 0x20) ? 1 : -1;
14371437         motor =  (data >> 2) & 1;
14381438         thmfc1->drive |= 1 ^ ((data >> 6) & 1);
1439                  img = thmfc_floppy_image(space.machine());
1439                  img = thmfc_floppy_image();
14401440      }
14411441
1442      thom_floppy_active( space.machine(), 0 );
1442      thom_floppy_active( 0 );
14431443
14441444      LOG (( "%f $%04x thmfc_floppy_w: CMD2=$%02X drv=%i step=%i motor=%i\n",
1445            space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data,
1445            machine().time().as_double(), m_maincpu->pc(), data,
14461446            thmfc1->drive, seek, motor ));
14471447
14481448      if ( seek )
r21425r21426
14631463
14641464   case 3: /* WDATA */
14651465      thmfc1->wsync = data;
1466      if ( thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(thmfc_floppy_image(space.machine()))))
1467         thmfc_floppy_qdd_write_byte( space.machine(), data );
1466      if ( thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(thmfc_floppy_image())))
1467         thmfc_floppy_qdd_write_byte( data );
14681468      else if ( thmfc1->op==THMFC1_OP_WRITE_SECT )
1469         thmfc_floppy_write_byte( space.machine(), data );
1469         thmfc_floppy_write_byte( data );
14701470      else if ( thmfc1->formatting )
1471         thmfc_floppy_format_byte( space.machine(), data );
1471         thmfc_floppy_format_byte( data );
14721472      else
14731473      {
14741474         /* TODO: implement other forms of raw track writing */
14751475         LOG (( "%f $%04x thmfc_floppy_w: ignored raw WDATA $%02X\n",
1476               space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data ));
1476               machine().time().as_double(), m_maincpu->pc(), data ));
14771477      }
14781478      break;
14791479
r21425r21426
14811481   case 4: /* WCLK (unemulated) */
14821482      /* clock configuration: FF for data, 0A for synchro */
14831483      LOG (( "%f $%04x thmfc_floppy_w: WCLK=$%02X (%s)\n",
1484            space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data,
1484            machine().time().as_double(), m_maincpu->pc(), data,
14851485            (data == 0xff) ? "data" : (data == 0x0A) ? "synchro" : "?" ));
14861486      break;
14871487
14881488   case 5: /* WSECT */
14891489      thmfc1->sector = data;
14901490      LOG (( "%f $%04x thmfc_floppy_w: WSECT=%i\n",
1491            space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data ));
1491            machine().time().as_double(), m_maincpu->pc(), data ));
14921492      break;
14931493
14941494   case 6: /* WTRCK */
14951495      thmfc1->track = data;
14961496      LOG (( "%f $%04x thmfc_floppy_w: WTRCK=%i (real=%i)\n",
1497            space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data,
1498            floppy_drive_get_current_track( thmfc_floppy_image(space.machine()) ) ));
1497            machine().time().as_double(), m_maincpu->pc(), data,
1498            floppy_drive_get_current_track( thmfc_floppy_image() ) ));
14991499      break;
15001500
15011501   case 7: /* WCELL */
15021502      /* precompensation (unemulated) */
15031503      LOG (( "%f $%04x thmfc_floppy_w: WCELL=$%02X\n",
1504            space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data ));
1504            machine().time().as_double(), m_maincpu->pc(), data ));
15051505      break;
15061506
15071507   default:
15081508      logerror ( "%f $%04x thmfc_floppy_w: invalid write offset %i (data=$%02X)\n",
1509            space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), offset, data );
1509            machine().time().as_double(), m_maincpu->pc(), offset, data );
15101510   }
15111511}
15121512
15131513
15141514
1515void thmfc_floppy_reset( running_machine &machine )
1515void thomson_state::thmfc_floppy_reset()
15161516{
15171517   int i;
15181518   LOG(( "thmfc_floppy_reset: THMFC1 controller\n" ));
15191519
1520   for ( i = 0; i < floppy_get_count( machine ); i++ )
1520   for ( i = 0; i < floppy_get_count( machine() ); i++ )
15211521   {
1522      device_t * img = floppy_get_device( machine, i );
1522      device_t * img = floppy_get_device( machine(), i );
15231523      if (img) {
15241524         floppy_drive_set_ready_state( img, FLOPPY_DRIVE_READY, 0 );
15251525         floppy_drive_seek( img, - floppy_drive_get_current_track( img ) );
r21425r21426
15451545
15461546
15471547
1548void thmfc_floppy_init( running_machine &machine )
1548void thomson_state::thmfc_floppy_init()
15491549{
15501550   LOG(( "thmfc_floppy_init: THMFC1 controller\n" ));
15511551
1552   thmfc1 = auto_alloc(machine, thmfc1_t);
1552   thmfc1 = auto_alloc(machine(), thmfc1_t);
15531553
1554   thmfc_floppy_cmd = machine.scheduler().timer_alloc(FUNC(thmfc_floppy_cmd_complete_cb));
1554   thmfc_floppy_cmd = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::thmfc_floppy_cmd_complete_cb),this));
15551555
1556   state_save_register_global( machine, thmfc1->op );
1557   state_save_register_global( machine, thmfc1->sector );
1558   state_save_register_global( machine, thmfc1->sector_id );
1559   state_save_register_global( machine, thmfc1->track );
1560   state_save_register_global( machine, thmfc1->side );
1561   state_save_register_global( machine, thmfc1->drive );
1562   state_save_register_global( machine, thmfc1->sector_size );
1563   state_save_register_global( machine, thmfc1->formatting );
1564   state_save_register_global( machine, thmfc1->ipl );
1565   state_save_register_global( machine, thmfc1->data_idx );
1566   state_save_register_global( machine, thmfc1->data_size );
1567   state_save_register_global( machine, thmfc1->data_finish );
1568   state_save_register_global( machine, thmfc1->stat0 );
1569   state_save_register_global( machine, thmfc1->data_raw_idx );
1570   state_save_register_global( machine, thmfc1->data_raw_size );
1571   state_save_register_global( machine, thmfc1->data_crc );
1572   state_save_register_global( machine, thmfc1->wsync );
1573   state_save_register_global_array( machine, thmfc1->data );
1556   state_save_register_global( machine(), thmfc1->op );
1557   state_save_register_global( machine(), thmfc1->sector );
1558   state_save_register_global( machine(), thmfc1->sector_id );
1559   state_save_register_global( machine(), thmfc1->track );
1560   state_save_register_global( machine(), thmfc1->side );
1561   state_save_register_global( machine(), thmfc1->drive );
1562   state_save_register_global( machine(), thmfc1->sector_size );
1563   state_save_register_global( machine(), thmfc1->formatting );
1564   state_save_register_global( machine(), thmfc1->ipl );
1565   state_save_register_global( machine(), thmfc1->data_idx );
1566   state_save_register_global( machine(), thmfc1->data_size );
1567   state_save_register_global( machine(), thmfc1->data_finish );
1568   state_save_register_global( machine(), thmfc1->stat0 );
1569   state_save_register_global( machine(), thmfc1->data_raw_idx );
1570   state_save_register_global( machine(), thmfc1->data_raw_size );
1571   state_save_register_global( machine(), thmfc1->data_crc );
1572   state_save_register_global( machine(), thmfc1->wsync );
1573   state_save_register_global_array( machine(), thmfc1->data );
15741574}
15751575
15761576
r21425r21426
15881588   no way to answer the request.
15891589*/
15901590
1591static TIMER_CALLBACK( ans4 )
1591TIMER_CALLBACK_MEMBER( thomson_state::ans4 )
15921592{
1593   LOG(( "%f ans4\n", machine.time().as_double() ));
1594   mc6854_set_cts( machine.device("mc6854"), 0 );
1593   LOG(( "%f ans4\n", machine().time().as_double() ));
1594   mc6854_set_cts( machine().device("mc6854"), 0 );
15951595}
15961596
1597static TIMER_CALLBACK( ans3 )
1597TIMER_CALLBACK_MEMBER( thomson_state::ans3 )
15981598{
1599   LOG(( "%f ans3\n", machine.time().as_double() ));
1600   mc6854_set_cts( machine.device("mc6854"), 1 );
1601   machine.scheduler().timer_set( attotime::from_usec( 100 ), FUNC(ans4));
1599   LOG(( "%f ans3\n", machine().time().as_double() ));
1600   mc6854_set_cts( machine().device("mc6854"), 1 );
1601   machine().scheduler().timer_set( attotime::from_usec( 100 ), timer_expired_delegate(FUNC(thomson_state::ans4),this));
16021602}
16031603
1604static TIMER_CALLBACK( ans2 )
1604TIMER_CALLBACK_MEMBER( thomson_state::ans2 )
16051605{
1606   LOG(( "%f ans2\n", machine.time().as_double() ));
1607   mc6854_set_cts( machine.device("mc6854"), 0 );
1608   machine.scheduler().timer_set( attotime::from_usec( 100 ), FUNC(ans3));
1606   LOG(( "%f ans2\n", machine().time().as_double() ));
1607   mc6854_set_cts( machine().device("mc6854"), 0 );
1608   machine().scheduler().timer_set( attotime::from_usec( 100 ), timer_expired_delegate(FUNC(thomson_state::ans3),this));
16091609}
16101610
1611static TIMER_CALLBACK( ans )
1611TIMER_CALLBACK_MEMBER( thomson_state::ans )
16121612{
1613   LOG(( "%f ans\n", machine.time().as_double() ));
1614   mc6854_set_cts( machine.device("mc6854"), 1 );
1615   machine.scheduler().timer_set( attotime::from_usec( 100 ), FUNC(ans2));
1613   LOG(( "%f ans\n", machine().time().as_double() ));
1614   mc6854_set_cts( machine().device("mc6854"), 1 );
1615   machine().scheduler().timer_set( attotime::from_usec( 100 ), timer_expired_delegate(FUNC(thomson_state::ans2),this));
16161616}
16171617/* consigne DKBOOT
16181618
r21425r21426
16531653
16541654   if ( data[1] == 0xff )
16551655   {
1656      thomson_state *state = device->machine().driver_data<thomson_state>();
16561657      LOG(( "to7_network_got_frame: %i phones %i\n", data[2], data[0] ));
1657      device->machine().scheduler().timer_set( attotime::from_usec( 100 ), FUNC(ans));
1658      device->machine().scheduler().timer_set( attotime::from_usec( 100 ), timer_expired_delegate(FUNC(thomson_state::ans),state));
16581659      mc6854_set_cts( device, 0 );
16591660   }
16601661   else if ( ! data[1] )
r21425r21426
16801681
16811682
16821683
1683static void to7_network_init( running_machine &machine )
1684void thomson_state::to7_network_init()
16841685{
16851686   LOG(( "to7_network_init: NR 07-005 network extension\n" ));
16861687   logerror( "to7_network_init: network not handled!\n" );
r21425r21426
16881689
16891690
16901691
1691static void to7_network_reset( running_machine &machine )
1692void thomson_state::to7_network_reset()
16921693{
16931694   LOG(( "to7_network_reset: NR 07-005 network extension\n" ));
1694   mc6854_set_cts( machine.device("mc6854"), 0 );
1695   mc6854_set_cts( machine.device("mc6854"), 1 );
1695   mc6854_set_cts( machine().device("mc6854"), 0 );
1696   mc6854_set_cts( machine().device("mc6854"), 1 );
16961697}
16971698
16981699
16991700
1700static READ8_HANDLER ( to7_network_r )
1701READ8_MEMBER( thomson_state::to7_network_r )
17011702{
17021703   if ( offset < 4 )
1703      return mc6854_r( space.machine().device("mc6854"), space, offset );
1704      return mc6854_r( machine().device("mc6854"), space, offset );
17041705
17051706   if ( offset == 8 )
17061707   {
17071708      /* network ID of the computer */
1708      UINT8 id = space.machine().root_device().ioport("fconfig")->read() >> 3;
1709      VLOG(( "%f $%04x to7_network_r: read id $%02X\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), id ));
1709      UINT8 id = ioport("fconfig")->read() >> 3;
1710      VLOG(( "%f $%04x to7_network_r: read id $%02X\n", machine().time().as_double(), m_maincpu->pc(), id ));
17101711      return id;
17111712   }
17121713
1713   logerror( "%f $%04x to7_network_r: invalid read offset %i\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), offset );
1714   logerror( "%f $%04x to7_network_r: invalid read offset %i\n", machine().time().as_double(), m_maincpu->pc(), offset );
17141715   return 0;
17151716}
17161717
17171718
17181719
1719static WRITE8_HANDLER ( to7_network_w )
1720WRITE8_MEMBER( thomson_state::to7_network_w )
17201721{
17211722   if ( offset < 4 )
1722      mc6854_w( space.machine().device("mc6854"), space, offset, data );
1723      mc6854_w( machine().device("mc6854"), space, offset, data );
17231724   else
17241725   {
17251726      logerror( "%f $%04x to7_network_w: invalid write offset %i (data=$%02X)\n",
1726            space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), offset, data );
1727            machine().time().as_double(), m_maincpu->pc(), offset, data );
17271728   }
17281729}
17291730
r21425r21426
17471748UINT8 to7_floppy_bank;
17481749
17491750
1750void to7_floppy_init ( running_machine &machine, void* base )
1751void thomson_state::to7_floppy_init( void* base )
17511752{
1752   machine.root_device().membank( THOM_FLOP_BANK )->configure_entries( 0, TO7_NB_FLOP_BANK, base, 0x800 );
1753   state_save_register_global( machine, to7_controller_type );
1754   state_save_register_global( machine, to7_floppy_bank );
1755   to7_5p14sd_init(machine);
1756   to7_5p14_init(machine);
1757   to7_qdd_init(machine);
1758   thmfc_floppy_init(machine);
1759   to7_network_init(machine);
1753   membank( THOM_FLOP_BANK )->configure_entries( 0, TO7_NB_FLOP_BANK, base, 0x800 );
1754   state_save_register_global( machine(), to7_controller_type );
1755   state_save_register_global( machine(), to7_floppy_bank );
1756   to7_5p14sd_init();
1757   to7_5p14_init();
1758   to7_qdd_init();
1759   thmfc_floppy_init();
1760   to7_network_init();
17601761}
17611762
17621763
17631764
1764void to7_floppy_reset ( running_machine &machine )
1765void thomson_state::to7_floppy_reset()
17651766{
1766   to7_controller_type = (machine.root_device().ioport("fconfig")->read() ) & 7;
1767   to7_controller_type = (ioport("fconfig")->read() ) & 7;
17671768
17681769   switch ( to7_controller_type )
17691770   {
17701771   case 1:
17711772      to7_floppy_bank = 1;
1772      to7_5p14sd_reset(machine);
1773      to7_5p14sd_reset();
17731774      break;
17741775
17751776   case 2:
17761777      to7_floppy_bank = 2;
1777      to7_5p14_reset(machine);
1778      to7_5p14_reset();
17781779      break;
17791780
17801781   case 3:
17811782      to7_floppy_bank = 3;
1782      thmfc_floppy_reset(machine);
1783      thmfc_floppy_reset();
17831784      break;
17841785
17851786   case 4:
17861787      to7_floppy_bank = 7;
1787      to7_qdd_reset(machine);
1788      to7_qdd_reset();
17881789      break;
17891790
17901791   case 5:
17911792      to7_floppy_bank = 8;
1792      to7_network_reset(machine);
1793      to7_network_reset();
17931794      break;
17941795
17951796   default:
r21425r21426
17971798      break;
17981799   }
17991800
1800   machine.root_device().membank( THOM_FLOP_BANK )->set_entry( to7_floppy_bank );
1801   membank( THOM_FLOP_BANK )->set_entry( to7_floppy_bank );
18011802}
18021803
18031804
18041805
1805READ8_HANDLER ( to7_floppy_r )
1806READ8_MEMBER( thomson_state::to7_floppy_r )
18061807{
18071808   switch ( to7_controller_type )
18081809   {
r21425r21426
18271828
18281829
18291830
1830WRITE8_HANDLER ( to7_floppy_w )
1831WRITE8_MEMBER( thomson_state::to7_floppy_w )
18311832{
18321833   switch ( to7_controller_type )
18331834   {
r21425r21426
18431844      if ( offset == 8 )
18441845      {
18451846         to7_floppy_bank = 3 + (data & 3);
1846         space.machine().root_device().membank( THOM_FLOP_BANK )->set_entry( to7_floppy_bank );
1847         membank( THOM_FLOP_BANK )->set_entry( to7_floppy_bank );
18471848         VLOG (( "to7_floppy_w: set CD 90-351 ROM bank to %i\n", data & 3 ));
18481849      }
18491850      else
r21425r21426
18701871
18711872
18721873
1873void to9_floppy_init( running_machine &machine, void* int_base, void* ext_base )
1874void thomson_state::to9_floppy_init( void* int_base, void* ext_base )
18741875{
1875   to7_floppy_init( machine, ext_base );
1876   machine.root_device().membank( THOM_FLOP_BANK )->configure_entry( TO7_NB_FLOP_BANK, int_base);
1876   to7_floppy_init( ext_base );
1877   membank( THOM_FLOP_BANK )->configure_entry( TO7_NB_FLOP_BANK, int_base);
18771878}
18781879
18791880
18801881
1881void to9_floppy_reset( running_machine &machine )
1882void thomson_state::to9_floppy_reset()
18821883{
1883   to7_floppy_reset(machine);
1884   to7_floppy_reset();
18841885   if ( THOM_FLOPPY_EXT )
18851886   {
18861887      LOG(( "to9_floppy_reset: external controller\n" ));
r21425r21426
18881889   else
18891890   {
18901891      LOG(( "to9_floppy_reset: internal controller\n" ));
1891      to7_5p14_reset(machine);
1892      machine.root_device().membank( THOM_FLOP_BANK )->set_entry( TO7_NB_FLOP_BANK );
1892      to7_5p14_reset();
1893      membank( THOM_FLOP_BANK )->set_entry( TO7_NB_FLOP_BANK );
18931894   }
18941895}
18951896
18961897
18971898
1898READ8_HANDLER ( to9_floppy_r )
1899READ8_MEMBER( thomson_state::to9_floppy_r )
18991900{
19001901   if ( THOM_FLOPPY_EXT )
19011902      return to7_floppy_r( space, offset );
r21425r21426
19031904      return  to7_5p14_r( space, offset, mem_mask );
19041905}
19051906
1906WRITE8_HANDLER ( to9_floppy_w )
1907WRITE8_MEMBER( thomson_state::to9_floppy_w )
19071908{
19081909   if ( THOM_FLOPPY_EXT )
19091910      to7_floppy_w( space, offset, data );
r21425r21426
19111912      to7_5p14_w( space, offset, data, mem_mask );
19121913}
19131914
1914WRITE_LINE_DEVICE_HANDLER(thomson_index_callback)
1915void thomson_state::thomson_index_callback(device_t *device, int state)
19151916{
19161917   switch ( to7_controller_type )
19171918   {
r21425r21426
19201921      break;
19211922
19221923   case 2:
1923      wd17xx_index_pulse_callback(device->machine().device("wd2793"), device, state);
1924      wd17xx_index_pulse_callback(machine().device("wd2793"), device, state);
19241925      break;
19251926
19261927   case 3:
r21425r21426
19351936      break;
19361937   }
19371938}
1939
trunk/src/mess/machine/thomflop.h
r21425r21426
3131
3232
3333/* external controllers */
34extern void to7_floppy_init  ( running_machine &machine, void* base );
35extern void to7_floppy_reset ( running_machine &machine );
36extern DECLARE_READ8_HANDLER  ( to7_floppy_r );
37extern DECLARE_WRITE8_HANDLER ( to7_floppy_w );
38
3934/* TO9 internal (WD2793) & external controllers */
40extern void to9_floppy_init  ( running_machine &machine, void* int_base, void* ext_base );
41extern void to9_floppy_reset ( running_machine &machine );
42extern DECLARE_READ8_HANDLER  ( to9_floppy_r );
43extern DECLARE_WRITE8_HANDLER ( to9_floppy_w );
44
4535/* TO8 internal (THMFC1) controller */
46extern void thmfc_floppy_init  ( running_machine &machine );
47extern void thmfc_floppy_reset ( running_machine &machine );
48extern DECLARE_READ8_HANDLER  ( thmfc_floppy_r );
49extern DECLARE_WRITE8_HANDLER ( thmfc_floppy_w );
5036
51extern WRITE_LINE_DEVICE_HANDLER(thomson_index_callback);
52
5337#endif /* THOMFLOP_H_ */
trunk/src/mess/machine/thomson.c
r21425r21426
3737/* It must be set accordingly in formats/thom_cas.c */
3838#define K7_SPEED_HACK 0
3939
40/* bank logging and optimisations */
41static int old_cart_bank;
42static int old_cart_bank_was_read_only;
43static int old_ram_bank;
44static int old_floppy_bank;
4540
46
47
48/********************* common cassette code ***************************/
49
50INLINE cassette_image_device* thom_cassette_img( running_machine &machine )
51{ return machine.device<cassette_image_device>(CASSETTE_TAG); }
52
5341/*-------------- TO7 ------------*/
5442
5543
r21425r21426
7563
7664#define TO7_BIT_LENGTH 0.001114
7765
78/* buffer storing demodulated bits, only for k7 and with speed hack */
79static UINT32 to7_k7_bitsize;
80static UINT8* to7_k7_bits;
81
82
8366/* 1-bit cassette input to the computer
8467   inside the controller, two frequency filters (adjusted to 6.3 and 4.5 kHz)
8568   and a comparator demodulate the raw signal into 0s and 1s.
8669*/
87static int to7_get_cassette ( running_machine &machine )
70int thomson_state::to7_get_cassette()
8871{
89   cassette_image_device* img = thom_cassette_img(machine);
90   if ( img->exists() )
72   if ( m_cassette->exists() )
9173   {
92      cassette_image* cass = img->get_image();
93      cassette_state state = img->get_state();
94      double pos = img->get_position();
74      cassette_image* cass = m_cassette->get_image();
75      cassette_state state = m_cassette->get_state();
76      double pos = m_cassette->get_position();
9577      int bitpos = pos / TO7_BIT_LENGTH;
9678
9779      if ( (state & CASSETTE_MASK_MOTOR) == CASSETTE_MOTOR_DISABLED )
9880         return 1;
9981
100      if ( K7_SPEED_HACK && to7_k7_bits )
82      if ( K7_SPEED_HACK && m_to7_k7_bits )
10183      {
10284         /* hack, feed existing bits */
103         if ( bitpos >= to7_k7_bitsize )
104            bitpos = to7_k7_bitsize -1;
85         if ( bitpos >= m_to7_k7_bitsize )
86            bitpos = m_to7_k7_bitsize -1;
10587         VLOG (( "$%04x %f to7_get_cassette: state=$%X pos=%f samppos=%i bit=%i\n",
106            machine.device("maincpu")->safe_pcbase(), machine.time().as_double(), state, pos, bitpos,
107            to7_k7_bits[ bitpos ] ));
108         return to7_k7_bits[ bitpos ];
88            m_maincpu->pc(), machine().time().as_double(), state, pos, bitpos,
89            m_to7_k7_bits[ bitpos ] ));
90         return m_to7_k7_bits[ bitpos ];
10991      }
11092      else
11193      {
r21425r21426
124106         }
125107         k = ( chg >= 13 ) ? 1 : 0;
126108         VLOG (( "$%04x %f to7_get_cassette: state=$%X pos=%f samppos=%i bit=%i (%i)\n",
127            machine.device("maincpu")->safe_pcbase(), machine.time().as_double(), state, pos, bitpos,
109            m_maincpu->pc(), machine().time().as_double(), state, pos, bitpos,
128110            k, chg ));
129111         return k;
130112      }
r21425r21426
137119
138120
139121/* 1-bit cassette output */
140static void to7_set_cassette ( running_machine &machine, int data )
122void thomson_state::to7_set_cassette( int data )
141123{
142   cassette_image_device* img = thom_cassette_img(machine);
143   img->output(data ? 1. : -1. );
124   m_cassette->output(data ? 1. : -1. );
144125}
145126
146127
147128
148static WRITE8_DEVICE_HANDLER ( to7_set_cassette_motor )
129WRITE8_MEMBER( thomson_state::to7_set_cassette_motor )
149130{
150   cassette_image_device* img = thom_cassette_img(space.machine());
151   cassette_state state =  img->get_state();
152   double pos = img->get_position();
131   cassette_state state =  m_cassette->get_state();
132   double pos = m_cassette->get_position();
153133
154134   LOG (( "$%04x %f to7_set_cassette_motor: cassette motor %s bitpos=%i\n",
155         space.machine().device("maincpu")->safe_pcbase(), img->machine().time().as_double(), data ? "off" : "on",
135         m_maincpu->pc(), machine().time().as_double(), data ? "off" : "on",
156136         (int) (pos / TO7_BIT_LENGTH) ));
157137
158138   if ( (state & CASSETTE_MASK_MOTOR) == CASSETTE_MOTOR_DISABLED && !data && pos > 0.3 )
159139   {
160140      /* rewind a little before starting the motor */
161      img->seek(-0.3, SEEK_CUR );
141      m_cassette->seek(-0.3, SEEK_CUR );
162142   }
163143
164   img->change_state(data ? CASSETTE_MOTOR_DISABLED : CASSETTE_MOTOR_ENABLED,CASSETTE_MASK_MOTOR );
144   m_cassette->change_state(data ? CASSETTE_MOTOR_DISABLED : CASSETTE_MOTOR_ENABLED,CASSETTE_MASK_MOTOR );
165145}
166146
167147
r21425r21426
184164#define MO5_HBIT_LENGTH (MO5_BIT_LENGTH / 2.)
185165
186166
187static int mo5_get_cassette ( running_machine &machine )
167int thomson_state::mo5_get_cassette()
188168{
189   cassette_image_device* img = thom_cassette_img(machine);
190   device_image_interface *image = dynamic_cast<device_image_interface *>(img);
191
192   if ( image->exists() )
169   if ( m_cassette->exists() )
193170   {
194      cassette_image* cass = img->get_image();
195      cassette_state state = img->get_state();
196      double pos = img->get_position();
171      cassette_image* cass = m_cassette->get_image();
172      cassette_state state = m_cassette->get_state();
173      double pos = m_cassette->get_position();
197174      INT32 hbit;
198175
199176      if ( (state & CASSETTE_MASK_MOTOR) == CASSETTE_MOTOR_DISABLED )
r21425r21426
203180      hbit = hbit >= 0;
204181
205182      VLOG (( "$%04x %f mo5_get_cassette: state=$%X pos=%f hbitpos=%i hbit=%i\n",
206         machine.device("maincpu")->safe_pcbase(), machine.time().as_double(), state, pos,
183         m_maincpu->pc(), machine().time().as_double(), state, pos,
207184         (int) (pos / MO5_HBIT_LENGTH), hbit ));
208185      return hbit;
209186   }
r21425r21426
213190
214191
215192
216static void mo5_set_cassette ( running_machine &machine, int data )
193void thomson_state::mo5_set_cassette( int data )
217194{
218   cassette_image_device* img = thom_cassette_img(machine);
219   img->output(data ? 1. : -1. );
195   m_cassette->output(data ? 1. : -1. );
220196}
221197
222198
223199
224static WRITE8_DEVICE_HANDLER ( mo5_set_cassette_motor )
200WRITE8_MEMBER( thomson_state::mo5_set_cassette_motor )
225201{
226   cassette_image_device* img = thom_cassette_img(space.machine());
227   cassette_state state = img->get_state();
228   double pos = img->get_position();
202   cassette_state state = m_cassette->get_state();
203   double pos = m_cassette->get_position();
229204
230205   LOG (( "$%04x %f mo5_set_cassette_motor: cassette motor %s hbitpos=%i\n",
231         space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), data ? "off" : "on",
206         m_maincpu->pc(), machine().time().as_double(), data ? "off" : "on",
232207         (int) (pos / MO5_HBIT_LENGTH) ));
233208
234209   if ( (state & CASSETTE_MASK_MOTOR) == CASSETTE_MOTOR_DISABLED &&  !data && pos > 0.3 )
235210   {
236211      /* rewind a little before starting the motor */
237      img->seek(-0.3, SEEK_CUR );
212      m_cassette->seek(-0.3, SEEK_CUR );
238213   }
239214
240   img->change_state(data ? CASSETTE_MOTOR_DISABLED : CASSETTE_MOTOR_ENABLED,CASSETTE_MASK_MOTOR );
215   m_cassette->change_state(data ? CASSETTE_MOTOR_DISABLED : CASSETTE_MOTOR_ENABLED,CASSETTE_MASK_MOTOR );
241216}
242217
243218
r21425r21426
250225/* ------------ IRQs ------------ */
251226
252227
253/* several devices on the same irqs */
254
255static UINT8 thom_irq;
256
257static UINT8 thom_firq;
258
259
260
261static void thom_set_irq ( running_machine &machine, int line, int state )
228void thomson_state::thom_set_irq( int line, int state )
262229{
263   int old = thom_irq;
230   int old = m_thom_irq;
264231
265232   if ( state )
266      thom_irq |= 1 << line;
233      m_thom_irq |= 1 << line;
267234   else
268      thom_irq &= ~(1 << line);
235      m_thom_irq &= ~(1 << line);
269236
270   if ( !old && thom_irq )
271      LOG_IRQ(( "%f thom_set_irq: irq line up %i\n", machine.time().as_double(), line ));
272   if ( old && !thom_irq )
273      LOG_IRQ(( "%f thom_set_irq: irq line down %i\n", machine.time().as_double(), line ));
237   if ( !old && m_thom_irq )
238      LOG_IRQ(( "%f thom_set_irq: irq line up %i\n", machine().time().as_double(), line ));
239   if ( old && !m_thom_irq )
240      LOG_IRQ(( "%f thom_set_irq: irq line down %i\n", machine().time().as_double(), line ));
274241
275   machine.device("maincpu")->execute().set_input_line(M6809_IRQ_LINE, thom_irq ? ASSERT_LINE : CLEAR_LINE);
242   m_maincpu->set_input_line(M6809_IRQ_LINE, m_thom_irq ? ASSERT_LINE : CLEAR_LINE);
276243}
277244
278245
279246
280static void thom_set_firq ( running_machine &machine, int line, int state )
247void thomson_state::thom_set_firq ( int line, int state )
281248{
282   int old = thom_irq;
249   int old = m_thom_firq;
283250
284251   if ( state )
285      thom_firq |= 1 << line;
252      m_thom_firq |= 1 << line;
286253   else
287      thom_firq &= ~(1 << line);
254      m_thom_firq &= ~(1 << line);
288255
289   if ( !old && thom_firq )
290      LOG_IRQ(( "%f thom_set_firq: firq line up %i\n", machine.time().as_double(), line ));
291   if ( old && !thom_firq )
292      LOG_IRQ(( "%f thom_set_firq: firq line down %i\n", machine.time().as_double(), line ));
256   if ( !old && m_thom_firq )
257      LOG_IRQ(( "%f thom_set_firq: firq line up %i\n", machine().time().as_double(), line ));
258   if ( old && !m_thom_firq )
259      LOG_IRQ(( "%f thom_set_firq: firq line down %i\n", machine().time().as_double(), line ));
293260
294   machine.device("maincpu")->execute().set_input_line(M6809_FIRQ_LINE, thom_firq ? ASSERT_LINE : CLEAR_LINE);
261   m_maincpu->set_input_line(M6809_FIRQ_LINE, m_thom_firq ? ASSERT_LINE : CLEAR_LINE);
295262}
296263
297264
298265
299static void thom_irq_reset ( running_machine &machine )
266void thomson_state::thom_irq_reset()
300267{
301   thom_irq = 0;
302   thom_firq = 0;
303   machine.device("maincpu")->execute().set_input_line(M6809_IRQ_LINE, CLEAR_LINE );
304   machine.device("maincpu")->execute().set_input_line(M6809_FIRQ_LINE, CLEAR_LINE );
268   m_thom_irq = 0;
269   m_thom_firq = 0;
270   m_maincpu->set_input_line(M6809_IRQ_LINE, CLEAR_LINE );
271   m_maincpu->set_input_line(M6809_FIRQ_LINE, CLEAR_LINE );
305272}
306273
307274
308275
309static void thom_irq_init ( running_machine &machine )
276void thomson_state::thom_irq_init()
310277{
311   state_save_register_global( machine, thom_irq );
312   state_save_register_global( machine, thom_firq );
278   save_item(NAME(m_thom_irq));
279   save_item(NAME(m_thom_firq));
313280}
314281
315282
316283
317static void thom_irq_0  ( running_machine &machine, int state )
284void thomson_state::thom_irq_0( int state )
318285{
319   thom_set_irq  ( machine, 0, state );
286   thom_set_irq( 0, state );
320287}
321288
322static WRITE_LINE_DEVICE_HANDLER( thom_dev_irq_0 )
289WRITE_LINE_MEMBER( thomson_state::thom_dev_irq_0 )
323290{
324   thom_irq_0( device->machine(), state );
291   thom_irq_0( state );
325292}
326293
327294
328295
329static WRITE_LINE_DEVICE_HANDLER( thom_irq_1 )
296WRITE_LINE_MEMBER( thomson_state::thom_irq_1 )
330297{
331   thom_set_irq  ( device->machine(), 1, state );
298   thom_set_irq  ( 1, state );
332299}
333300
334static void thom_irq_3  ( running_machine &machine, int state )
301void thomson_state::thom_irq_3( int state )
335302{
336   thom_set_irq  ( machine, 3, state );
303   thom_set_irq  ( 3, state );
337304}
338305
339static WRITE_LINE_DEVICE_HANDLER( thom_firq_1 )
306WRITE_LINE_MEMBER( thomson_state::thom_firq_1 )
340307{
341   thom_set_firq ( device->machine(), 1, state );
308   thom_set_firq ( 1, state );
342309}
343310
344static void thom_firq_2 ( running_machine &machine, int state )
311void thomson_state::thom_firq_2( int state )
345312{
346   thom_set_firq ( machine, 2, state );
313   thom_set_firq ( 2, state );
347314}
348315
349#ifdef CHARDEV
350static void thom_irq_4  ( running_machine &machine, int state )
316void thomson_state::thom_irq_4( int state )
351317{
352   thom_set_irq  ( machine, 4, state );
318   thom_set_irq  ( 4, state );
353319}
354#endif
355320
356321
357322/*
r21425r21426
370335
371336
372337
373static void thom_set_caps_led ( running_machine &machine, int led )
338void thomson_state::thom_set_caps_led( int led )
374339{
375340   output_set_value( "led0", led );
376341}
r21425r21426
390355
391356/***************************** TO7 / T9000 *************************/
392357
393
394
395/* ------------ cartridge ------------ */
396
397static UINT8 thom_cart_nb_banks; /* number of 16 KB banks (up to 4) */
398
399static UINT8 thom_cart_bank;     /* current bank */
400
401
402358DEVICE_IMAGE_LOAD_MEMBER( thomson_state, to7_cartridge )
403359{
404360   int i,j;
r21425r21426
413369
414370   /* get size & number of 16-KB banks */
415371   if ( size <= 0x04000 )
416      thom_cart_nb_banks = 1;
372      m_thom_cart_nb_banks = 1;
417373   else if ( size == 0x08000 )
418      thom_cart_nb_banks = 2;
374      m_thom_cart_nb_banks = 2;
419375   else if ( size == 0x10000 )
420      thom_cart_nb_banks = 4;
376      m_thom_cart_nb_banks = 4;
421377   else
422378   {
423379      astring errmsg;
r21425r21426
452408         name[i] = '?';
453409   }
454410
455   PRINT (( "to7_cartridge_load: cartridge \"%s\" banks=%i, size=%i\n", name, thom_cart_nb_banks, size ));
411   PRINT (( "to7_cartridge_load: cartridge \"%s\" banks=%i, size=%i\n", name, m_thom_cart_nb_banks, size ));
456412
457413   return IMAGE_INIT_PASS;
458414}
459415
460416
461417
462static void to7_update_cart_bank(running_machine &machine)
418void thomson_state::to7_update_cart_bank()
463419{
464   address_space& space = machine.device("maincpu")->memory().space(AS_PROGRAM);
420   address_space& space = m_maincpu->space(AS_PROGRAM);
465421   int bank = 0;
466   if ( thom_cart_nb_banks )
422   if ( m_thom_cart_nb_banks )
467423   {
468      bank = thom_cart_bank % thom_cart_nb_banks;
469      if ( bank != old_cart_bank && old_cart_bank < 0 )
470            {
471                  space.install_legacy_read_handler(0x0000, 0x0003, FUNC(to7_cartridge_r) );
472            }
473   }
474   if ( bank != old_cart_bank )
424      bank = m_thom_cart_bank % m_thom_cart_nb_banks;
425      if ( bank != m_old_cart_bank && m_old_cart_bank < 0 )
475426      {
476      machine.root_device().membank( THOM_CART_BANK )->set_entry( bank );
477      old_cart_bank = bank;
427         space.install_read_handler(0x0000, 0x0003, read8_delegate(FUNC(thomson_state::to7_cartridge_r),this) );
428      }
429   }
430   if ( bank != m_old_cart_bank )
431   {
432      membank( THOM_CART_BANK )->set_entry( bank );
433      m_old_cart_bank = bank;
478434      LOG_BANK(( "to7_update_cart_bank: CART is cartridge bank %i\n", bank ));
479435   }
480436}
481437
482438
483439
484static void to7_update_cart_bank_postload(running_machine *machine)
440void thomson_state::to7_update_cart_bank_postload()
485441{
486   to7_update_cart_bank(*machine);
442   to7_update_cart_bank();
487443}
488444
489445
490446
491447/* write signal to 0000-1fff generates a bank switch */
492WRITE8_HANDLER ( to7_cartridge_w )
448WRITE8_MEMBER( thomson_state::to7_cartridge_w )
493449{
494450   if ( offset >= 0x2000 )
495451      return;
496452
497   thom_cart_bank = offset & 3;
498   to7_update_cart_bank(space.machine());
453   m_thom_cart_bank = offset & 3;
454   to7_update_cart_bank();
499455}
500456
501457
502458
503459/* read signal to 0000-0003 generates a bank switch */
504READ8_HANDLER ( to7_cartridge_r )
460READ8_MEMBER( thomson_state::to7_cartridge_r )
505461{
506   UINT8* pos = space.machine().root_device().memregion( "maincpu" )->base() + 0x10000;
507   UINT8 data = pos[offset + (thom_cart_bank % thom_cart_nb_banks) * 0x4000];
462   UINT8* pos = memregion( "maincpu" )->base() + 0x10000;
463   UINT8 data = pos[offset + (m_thom_cart_bank % m_thom_cart_nb_banks) * 0x4000];
508464   if ( !space.debugger_access() )
509      {
510      thom_cart_bank = offset & 3;
511      to7_update_cart_bank(space.machine());
465   {
466      m_thom_cart_bank = offset & 3;
467      to7_update_cart_bank();
512468   }
513469   return data;
514470}
r21425r21426
519475
520476
521477
522static WRITE8_DEVICE_HANDLER ( to7_timer_port_out )
478WRITE8_MEMBER( thomson_state::to7_timer_port_out )
523479{
524   thom_set_mode_point( space.machine(), data & 1 );          /* bit 0: video bank switch */
525   thom_set_caps_led( space.machine(), (data & 8) ? 1 : 0 ) ; /* bit 3: keyboard led */
526   thom_set_border_color( space.machine(),
527               ((data & 0x10) ? 1 : 0) |           /* bits 4-6: border color */
528               ((data & 0x20) ? 2 : 0) |
529               ((data & 0x40) ? 4 : 0) );
480   thom_set_mode_point( data & 1 );          /* bit 0: video bank switch */
481   thom_set_caps_led( (data & 8) ? 1 : 0 ) ; /* bit 3: keyboard led */
482   thom_set_border_color( ((data & 0x10) ? 1 : 0) |           /* bits 4-6: border color */
483                          ((data & 0x20) ? 2 : 0) |
484                          ((data & 0x40) ? 4 : 0) );
530485}
531486
532487
533488
534static WRITE8_DEVICE_HANDLER ( to7_timer_cp2_out )
489WRITE8_MEMBER( thomson_state::to7_timer_cp2_out )
535490{
536   space.machine().device<dac_device>("buzzer")->write_unsigned8(data ? 0x80 : 0); /* 1-bit buzzer */
491   m_buzzer->write_unsigned8(data ? 0x80 : 0); /* 1-bit buzzer */
537492}
538493
539494
540495
541static READ8_DEVICE_HANDLER ( to7_timer_port_in )
496READ8_MEMBER( thomson_state::to7_timer_port_in )
542497{
543   int lightpen = (space.machine().root_device().ioport("lightpen_button")->read() & 1) ? 2 : 0;
544   int cass = to7_get_cassette(space.machine()) ? 0x80 : 0;
498   int lightpen = (ioport("lightpen_button")->read() & 1) ? 2 : 0;
499   int cass = to7_get_cassette() ? 0x80 : 0;
545500   return lightpen | cass;
546501}
547502
548503
549504
550static WRITE8_DEVICE_HANDLER ( to7_timer_tco_out )
505WRITE8_MEMBER( thomson_state::to7_timer_tco_out )
551506{
552507   /* 1-bit cassette output */
553   to7_set_cassette( space.machine(), data );
508   to7_set_cassette( data );
554509}
555510
556511
557512
558513const mc6846_interface to7_timer =
559514{
560   DEVCB_HANDLER(to7_timer_port_out), DEVCB_NULL, DEVCB_HANDLER(to7_timer_cp2_out),
561   DEVCB_HANDLER(to7_timer_port_in), DEVCB_HANDLER(to7_timer_tco_out),
562   DEVCB_LINE(thom_dev_irq_0)
515   DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_port_out),
516   DEVCB_NULL,
517   DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_cp2_out),
518   DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_port_in),
519   DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_tco_out),
520   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_dev_irq_0)
563521};
564522
565523
r21425r21426
567525/* ------------ lightpen automaton ------------ */
568526
569527
570
571static UINT8 to7_lightpen_step;
572
573static UINT8 to7_lightpen;
574
575
576
577static void to7_lightpen_cb ( running_machine &machine, int step )
528void thomson_state::to7_lightpen_cb( int step )
578529{
579   pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS );
580
581   if ( ! to7_lightpen )
530   if ( ! m_to7_lightpen )
582531      return;
583532
584   LOG_VIDEO(( "%f to7_lightpen_cb: step=%i\n", machine.time().as_double(), step ));
585   sys_pia->cb1_w( 1 );
586   sys_pia->cb1_w( 0 );
587   to7_lightpen_step = step;
533   LOG_VIDEO(( "%f to7_lightpen_cb: step=%i\n", machine().time().as_double(), step ));
534   m_pia_sys->cb1_w( 1 );
535   m_pia_sys->cb1_w( 0 );
536   m_to7_lightpen_step = step;
588537}
589538
590539
r21425r21426
593542
594543
595544
596static void to7_set_init ( running_machine &machine, int init )
545void thomson_state::to7_set_init( int init )
597546{
598   pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS );
599547   /* INIT signal wired to system PIA 6821 */
600548
601   LOG_VIDEO(( "%f to7_set_init: init=%i\n", machine.time().as_double(), init ));
602   sys_pia->ca1_w( init );
549   LOG_VIDEO(( "%f to7_set_init: init=%i\n", machine().time().as_double(), init ));
550   m_pia_sys->ca1_w( init );
603551}
604552
605553
r21425r21426
608556
609557
610558
611static WRITE8_DEVICE_HANDLER ( to7_sys_cb2_out )
559WRITE8_MEMBER( thomson_state::to7_sys_cb2_out )
612560{
613   to7_lightpen = !data;
561   m_to7_lightpen = !data;
614562}
615563
616564
617565
618static WRITE8_DEVICE_HANDLER ( to7_sys_portb_out )
566WRITE8_MEMBER( thomson_state::to7_sys_portb_out )
619567{
620568   /* value fetched in to7_sys_porta_in */
621569}
r21425r21426
626574
627575
628576
629static READ8_DEVICE_HANDLER ( to7_sys_porta_in )
577READ8_MEMBER( thomson_state::to7_sys_porta_in )
630578{
631   if ( to7_lightpen )
579   if ( m_to7_lightpen )
632580   {
633581      /* lightpen hi */
634      return to7_lightpen_gpl( space.machine(), TO7_LIGHTPEN_DECAL, to7_lightpen_step ) >> 8;
582      return to7_lightpen_gpl( TO7_LIGHTPEN_DECAL, m_to7_lightpen_step ) >> 8;
635583   }
636584   else
637585   {
638586      /* keyboard  */
639      int keyline = downcast<pia6821_device *>(device)->b_output();
587      int keyline = m_pia_sys->b_output();
640588      UINT8 val = 0xff;
641589      int i;
642590      static const char *const keynames[] = {
r21425r21426
647595      for ( i = 0; i < 8; i++ )
648596      {
649597         if ( ! (keyline & (1 << i)) )
650            val &= space.machine().root_device().ioport(keynames[i])->read();
598            val &= ioport(keynames[i])->read();
651599      }
652600      return val;
653601   }
r21425r21426
655603
656604
657605
658static READ8_DEVICE_HANDLER ( to7_sys_portb_in )
606READ8_MEMBER( thomson_state::to7_sys_portb_in )
659607{
660608   /* lightpen low */
661   return to7_lightpen_gpl( space.machine(), TO7_LIGHTPEN_DECAL, to7_lightpen_step ) & 0xff;
609   return to7_lightpen_gpl( TO7_LIGHTPEN_DECAL, m_to7_lightpen_step ) & 0xff;
662610}
663611
664612
665613
666614const pia6821_interface to7_pia6821_sys =
667615{
668   DEVCB_HANDLER(to7_sys_porta_in),
669   DEVCB_HANDLER(to7_sys_portb_in),
616   DEVCB_DRIVER_MEMBER(thomson_state, to7_sys_porta_in),
617   DEVCB_DRIVER_MEMBER(thomson_state, to7_sys_portb_in),
670618   DEVCB_NULL,
671619   DEVCB_NULL,
672620   DEVCB_NULL,
673621   DEVCB_NULL,
674622   DEVCB_NULL,
675   DEVCB_HANDLER(to7_sys_portb_out),
676   DEVCB_HANDLER(to7_set_cassette_motor),
677   DEVCB_HANDLER(to7_sys_cb2_out),
678   DEVCB_LINE(thom_firq_1),
679   DEVCB_LINE(thom_firq_1)
623   DEVCB_DRIVER_MEMBER(thomson_state, to7_sys_portb_out),
624   DEVCB_DRIVER_MEMBER(thomson_state, to7_set_cassette_motor),
625   DEVCB_DRIVER_MEMBER(thomson_state, to7_sys_cb2_out),
626   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1),
627   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1)
680628};
681629
682630
r21425r21426
695643
696644
697645
698enum to7_io_dev
699{
700   TO7_IO_NONE,
701   TO7_IO_CENTRONICS,
702   TO7_IO_RS232
703};
704
705646/* test whether a parallel or a serial device is connected: both cannot
706647   be exploited at the same time!
707648*/
708static to7_io_dev to7_io_mode( running_machine &machine )
649to7_io_dev thomson_state::to7_io_mode()
709650{
710   centronics_device *centronics = machine.device<centronics_device>("centronics");
711   device_image_interface *serial = dynamic_cast<device_image_interface *>(machine.device("cc90232"));
712
713   if (centronics->pe_r() == TRUE)
651   if (m_centronics->pe_r() == TRUE)
714652      return TO7_IO_CENTRONICS;
715   else if ( serial->exists())
653   else if ( m_serial->exists())
716654      return TO7_IO_RS232;
717655   return TO7_IO_NONE;
718656}
719657
720658
721659
722static WRITE_LINE_DEVICE_HANDLER( to7_io_ack )
660WRITE_LINE_MEMBER( thomson_state::to7_io_ack )
723661{
724   pia6821_device *io_pia = device->machine().device<pia6821_device>(THOM_PIA_IO);
725
726   io_pia->cb1_w( state);
727   //LOG_IO (( "%f to7_io_ack: CENTRONICS new state $%02X (ack=%i)\n", machine.time().as_double(), data, ack ));
662   m_pia_io->cb1_w( state);
663   //LOG_IO (( "%f to7_io_ack: CENTRONICS new state $%02X (ack=%i)\n", machine().time().as_double(), data, ack ));
728664}
729665
730666const device_type TO7_IO_LINE = &device_creator<to7_io_line_device>;
r21425r21426
767703   int dsr = ( m_input_state & SERIAL_STATE_DSR ) ? 0 : 1;
768704   int rd  = get_in_data_bit();
769705
770   if ( to7_io_mode(machine()) == TO7_IO_RS232 )
706   if ( machine().driver_data<thomson_state>()->to7_io_mode() == TO7_IO_RS232 )
771707      cts = m_input_state & SERIAL_STATE_CTS ? 0 : 1;
772708   else
773709      cts = !printer->busy_r();
774710
775   LOG_IO(( "$%04x %f to7_io_porta_in: mode=%i cts=%i, dsr=%i, rd=%i\n", machine().device("maincpu")->safe_pcbase(), machine().time().as_double(), to7_io_mode(machine()), cts, dsr, rd ));
711   LOG_IO(( "$%04x %f to7_io_porta_in: mode=%i cts=%i, dsr=%i, rd=%i\n", machine().device("maincpu")->safe_pcbase(), machine().time().as_double(), machine().driver_data<thomson_state>()->to7_io_mode(), cts, dsr, rd ));
776712
777713   return (dsr ? 0x20 : 0) | (cts ? 0x40 : 0) | (rd ? 0x80: 0);
778714}
779715
780716
781717
782static WRITE8_DEVICE_HANDLER( to7_io_portb_out )
718WRITE8_MEMBER( thomson_state::to7_io_portb_out )
783719{
784   centronics_device *printer = space.machine().device<centronics_device>("centronics");
720   LOG_IO(( "$%04x %f to7_io_portb_out: CENTRONICS set data=$%02X\n", m_maincpu->pc(), machine().time().as_double(), data ));
785721
786   LOG_IO(( "$%04x %f to7_io_portb_out: CENTRONICS set data=$%02X\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), data ));
787
788722   /* set 8-bit data */
789   printer->write( space.machine().driver_data()->generic_space(), 0, data);
723   m_centronics->write( space, 0, data);
790724}
791725
792726
793727
794static WRITE8_DEVICE_HANDLER( to7_io_cb2_out )
728WRITE8_MEMBER( thomson_state::to7_io_cb2_out )
795729{
796   centronics_device *printer = space.machine().device<centronics_device>("centronics");
730   LOG_IO(( "$%04x %f to7_io_cb2_out: CENTRONICS set strobe=%i\n", m_maincpu->pc(), machine().time().as_double(), data ));
797731
798   LOG_IO(( "$%04x %f to7_io_cb2_out: CENTRONICS set strobe=%i\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), data ));
799
800732   /* send STROBE to printer */
801   printer->strobe_w(data);
733   m_centronics->strobe_w(data);
802734}
803735
804736
r21425r21426
820752   DEVCB_NULL,
821753   DEVCB_NULL,
822754   DEVCB_DEVICE_MEMBER("to7_io", to7_io_line_device, porta_out),
823   DEVCB_HANDLER(to7_io_portb_out),
755   DEVCB_DRIVER_MEMBER(thomson_state, to7_io_portb_out),
824756   DEVCB_NULL,
825   DEVCB_HANDLER(to7_io_cb2_out),
826   DEVCB_LINE(thom_firq_1),
827   DEVCB_LINE(thom_firq_1)
757   DEVCB_DRIVER_MEMBER(thomson_state, to7_io_cb2_out),
758   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1),
759   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1)
828760};
829761
830762
831763const centronics_interface to7_centronics_config =
832764{
833   DEVCB_LINE(to7_io_ack),
765   DEVCB_DRIVER_LINE_MEMBER(thomson_state, to7_io_ack),
834766   DEVCB_NULL,
835767   DEVCB_NULL
836768};
r21425r21426
871803 */
872804
873805
874
875static UINT8 to7_modem_rx;
876
877static UINT8 to7_modem_tx;
878
879
880
881static void to7_modem_cb( device_t *device, int state )
806WRITE_LINE_MEMBER( thomson_state::to7_modem_cb )
882807{
883808   LOG(( "to7_modem_cb: called %i\n", state ));
884809}
r21425r21426
901826   DEVCB_NULL
902827};
903828
904static READ_LINE_DEVICE_HANDLER( to7_modem_rx_r )
829READ_LINE_MEMBER( thomson_state::to7_modem_rx_r )
905830{
906   return to7_modem_rx;
831   return m_to7_modem_rx;
907832}
908833
909static WRITE_LINE_DEVICE_HANDLER( to7_modem_tx_w )
834WRITE_LINE_MEMBER( thomson_state::to7_modem_tx_w )
910835{
911   to7_modem_tx = state;
836   m_to7_modem_tx = state;
912837}
913838
914839ACIA6850_INTERFACE( to7_modem )
915840{
916841   1200,
917842   1200, /* 1200 bauds, might be divided by 16 */
918   DEVCB_LINE(to7_modem_rx_r), /*&to7_modem_rx,*/
919   DEVCB_LINE(to7_modem_tx_w), /*&to7_modem_tx,*/
843   DEVCB_DRIVER_LINE_MEMBER(thomson_state, to7_modem_rx_r), /*&to7_modem_rx,*/
844   DEVCB_DRIVER_LINE_MEMBER(thomson_state, to7_modem_tx_w), /*&to7_modem_tx,*/
920845   DEVCB_NULL,
921846   DEVCB_NULL,
922847   DEVCB_NULL,
923   DEVCB_LINE(to7_modem_cb)
848   DEVCB_DRIVER_LINE_MEMBER(thomson_state, to7_modem_cb)
924849};
925850
926851
927852
928static void to7_modem_reset( running_machine &machine )
853void thomson_state::to7_modem_reset()
929854{
930855   LOG (( "to7_modem_reset called\n" ));
931   to7_modem_rx = 0;
932   to7_modem_tx = 0;
856   m_to7_modem_rx = 0;
857   m_to7_modem_tx = 0;
933858   /* pia_reset() is called in MACHINE_RESET */
934859   /* acia_6850 has no reset (?) */
935860}
936861
937862
938863
939static void to7_modem_init( running_machine &machine )
864void thomson_state::to7_modem_init()
940865{
941866   LOG (( "to7_modem_init: MODEM not implemented!\n" ));
942   state_save_register_global( machine, to7_modem_rx );
943   state_save_register_global( machine, to7_modem_tx );
867   save_item(NAME(m_to7_modem_rx));
868   save_item(NAME(m_to7_modem_tx));
944869}
945870
946871
r21425r21426
951876const mea8000_interface to7_speech = { "speech", DEVCB_NULL };
952877
953878
954READ8_HANDLER ( to7_modem_mea8000_r )
879READ8_MEMBER( thomson_state::to7_modem_mea8000_r )
955880{
956881   if ( space.debugger_access() )
957882      {
958883      return 0;
959884      }
960885
961   if ( space.machine().root_device().ioport("mconfig")->read() & 1 )
886   if ( ioport("mconfig")->read() & 1 )
962887   {
963      device_t* device = space.machine().device("mea8000" );
964      return mea8000_r( device, space, offset );
888      return mea8000_r( m_mea8000, space, offset );
965889   }
966890   else
967891   {
968      acia6850_device* acia = space.machine().device<acia6850_device>("acia6850" );
969892      switch (offset) {
970      case 0: return acia->status_read(space, offset );
971      case 1: return acia->data_read(space, offset );
893      case 0: return m_acia->status_read(space, offset );
894      case 1: return m_acia->data_read(space, offset );
972895      default: return 0;
973896      }
974897   }
r21425r21426
976899
977900
978901
979WRITE8_HANDLER ( to7_modem_mea8000_w )
902WRITE8_MEMBER( thomson_state::to7_modem_mea8000_w )
980903{
981   if ( space.machine().root_device().ioport("mconfig")->read() & 1 )
904   if ( ioport("mconfig")->read() & 1 )
982905   {
983      device_t* device = space.machine().device("mea8000" );
984      mea8000_w( device, space, offset, data );
906      mea8000_w( m_mea8000, space, offset, data );
985907   }
986908   else
987909   {
988      acia6850_device* acia = space.machine().device<acia6850_device>("acia6850" );
989910      switch (offset) {
990      case 0: acia->control_write( space, offset, data );
991      case 1: acia->data_write( space, offset, data );
911      case 0: m_acia->control_write( space, offset, data );
912      case 1: m_acia->data_write( space, offset, data );
992913      }
993914   }
994915}
r21425r21426
1012933#define TO7_GAME_POLL_PERIOD  attotime::from_usec( 500 )
1013934
1014935
1015
1016/* calls to7_game_update_cb periodically */
1017static emu_timer* to7_game_timer;
1018
1019static UINT8 to7_game_sound;
1020static UINT8 to7_game_mute;
1021
1022
1023936/* The mouse is a very simple phase quadrature one.
1024937   Each axis provides two 1-bit signals, A and B, that are toggled by the
1025938   axis rotation. The two signals are not in phase, so that whether A is
r21425r21426
1027940   This is similar Atari & Amiga mouses.
1028941   Returns: 0 0 0 0 0 0 YB XB YA XA
1029942 */
1030static UINT8 to7_get_mouse_signal( running_machine &machine )
943UINT8 thomson_state::to7_get_mouse_signal()
1031944{
1032945   UINT8 xa, xb, ya, yb;
1033   UINT16 dx = machine.root_device().ioport("mouse_x")->read(); /* x axis */
1034   UINT16 dy = machine.root_device().ioport("mouse_y")->read(); /* y axis */
946   UINT16 dx = ioport("mouse_x")->read(); /* x axis */
947   UINT16 dy = ioport("mouse_y")->read(); /* y axis */
1035948   xa = ((dx + 1) & 3) <= 1;
1036949   xb = (dx & 3) <= 1;
1037950   ya = ((dy + 1) & 3) <= 1;
r21425r21426
1041954
1042955
1043956
1044static void to7_game_sound_update ( running_machine &machine )
957void thomson_state::to7_game_sound_update()
1045958{
1046   machine.device<dac_device>("dac")->write_unsigned8(to7_game_mute ? 0 : (to7_game_sound << 2) );
959   m_dac->write_unsigned8(m_to7_game_mute ? 0 : (m_to7_game_sound << 2) );
1047960}
1048961
1049962
1050963
1051static READ8_DEVICE_HANDLER ( to7_game_porta_in )
964READ8_MEMBER( thomson_state::to7_game_porta_in )
1052965{
1053966   UINT8 data;
1054   if ( space.machine().root_device().ioport("config")->read() & 1 )
967   if ( ioport("config")->read() & 1 )
1055968   {
1056969      /* mouse */
1057      data = to7_get_mouse_signal(space.machine()) & 0x0c;             /* XB, YB */
1058      data |= space.machine().root_device().ioport("mouse_button")->read() & 3; /* buttons */
970      data = to7_get_mouse_signal() & 0x0c;             /* XB, YB */
971      data |= ioport("mouse_button")->read() & 3; /* buttons */
1059972   }
1060973   else
1061974   {
1062975      /* joystick */
1063      data = space.machine().root_device().ioport("game_port_directions")->read();
976      data = ioport("game_port_directions")->read();
1064977      /* bit 0=0 => P1 up      bit 4=0 => P2 up
1065978         bit 1=0 => P1 down    bit 5=0 => P2 down
1066979         bit 2=0 => P1 left    bit 6=0 => P2 left
r21425r21426
10891002
10901003
10911004
1092static READ8_DEVICE_HANDLER ( to7_game_portb_in )
1005READ8_MEMBER( thomson_state::to7_game_portb_in )
10931006{
10941007   UINT8 data;
1095   if ( space.machine().root_device().ioport("config")->read() & 1 )
1008   if ( ioport("config")->read() & 1 )
10961009   {
10971010      /* mouse */
1098      UINT8 mouse =  to7_get_mouse_signal(space.machine());
1011      UINT8 mouse =  to7_get_mouse_signal();
10991012      data = 0;
11001013      if ( mouse & 1 )
11011014         data |= 0x04; /* XA */
r21425r21426
11091022      /* bits 2-3: action buttons B (0=pressed) */
11101023      /* bits 4-5: unused (ouput) */
11111024      /* bits 0-1: unknown! */
1112      data = space.machine().root_device().ioport("game_port_buttons")->read();
1025      data = ioport("game_port_buttons")->read();
11131026   }
11141027   return data;
11151028}
11161029
11171030
11181031
1119static WRITE8_DEVICE_HANDLER ( to7_game_portb_out )
1032WRITE8_MEMBER( thomson_state::to7_game_portb_out )
11201033{
11211034   /* 6-bit DAC sound */
1122   to7_game_sound = data & 0x3f;
1123   to7_game_sound_update(space.machine());
1035   m_to7_game_sound = data & 0x3f;
1036   to7_game_sound_update();
11241037}
11251038
11261039
11271040
1128static WRITE8_DEVICE_HANDLER ( to7_game_cb2_out )
1041WRITE8_MEMBER( thomson_state::to7_game_cb2_out )
11291042{
11301043   /* undocumented */
11311044   /* some TO8 games (e.g.: F15) seem to write here a lot */
r21425r21426
11351048
11361049const pia6821_interface to7_pia6821_game =
11371050{
1138   DEVCB_HANDLER(to7_game_porta_in),
1139   DEVCB_HANDLER(to7_game_portb_in),
1051   DEVCB_DRIVER_MEMBER(thomson_state, to7_game_porta_in),
1052   DEVCB_DRIVER_MEMBER(thomson_state, to7_game_portb_in),
11401053   DEVCB_NULL,
11411054   DEVCB_NULL,
11421055   DEVCB_NULL,
11431056   DEVCB_NULL,
11441057   DEVCB_NULL,
1145   DEVCB_HANDLER(to7_game_portb_out),
1058   DEVCB_DRIVER_MEMBER(thomson_state, to7_game_portb_out),
11461059   DEVCB_NULL,
1147   DEVCB_HANDLER(to7_game_cb2_out),
1148   DEVCB_LINE(thom_irq_1),
1149   DEVCB_LINE(thom_irq_1)
1060   DEVCB_DRIVER_MEMBER(thomson_state, to7_game_cb2_out),
1061   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_irq_1),
1062   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_irq_1)
11501063};
11511064
11521065
11531066
11541067/* this should be called periodically */
1155static TIMER_CALLBACK(to7_game_update_cb)
1068TIMER_CALLBACK_MEMBER(thomson_state::to7_game_update_cb)
11561069{
1157   pia6821_device *game_pia = machine.device<pia6821_device>(THOM_PIA_GAME);
1158
1159   if ( machine.root_device().ioport("config")->read() & 1 )
1070   if ( ioport("config")->read() & 1 )
11601071   {
11611072      /* mouse */
1162      UINT8 mouse = to7_get_mouse_signal(machine);
1163      game_pia->ca1_w( (mouse & 1) ? 1 : 0 ); /* XA */
1164      game_pia->ca2_w( (mouse & 2) ? 1 : 0 ); /* YA */
1073      UINT8 mouse = to7_get_mouse_signal();
1074      m_pia_game->ca1_w( (mouse & 1) ? 1 : 0 ); /* XA */
1075      m_pia_game->ca2_w( (mouse & 2) ? 1 : 0 ); /* YA */
11651076   }
11661077   else
11671078   {
11681079      /* joystick */
1169      UINT8 in = machine.root_device().ioport("game_port_buttons")->read();
1170      game_pia->cb2_w( (in & 0x80) ? 1 : 0 ); /* P2 action A */
1171      game_pia->ca2_w( (in & 0x40) ? 1 : 0 ); /* P1 action A */
1172      game_pia->cb1_w( (in & 0x08) ? 1 : 0 ); /* P2 action B */
1173      game_pia->ca1_w( (in & 0x04) ? 1 : 0 ); /* P1 action B */
1080      UINT8 in = ioport("game_port_buttons")->read();
1081      m_pia_game->cb2_w( (in & 0x80) ? 1 : 0 ); /* P2 action A */
1082      m_pia_game->ca2_w( (in & 0x40) ? 1 : 0 ); /* P1 action A */
1083      m_pia_game->cb1_w( (in & 0x08) ? 1 : 0 ); /* P2 action B */
1084      m_pia_game->ca1_w( (in & 0x04) ? 1 : 0 ); /* P1 action B */
11741085      /* TODO:
11751086         it seems that CM 90-112 behaves differently
11761087         - ca1 is P1 action A, i.e., in & 0x40
r21425r21426
11851096
11861097
11871098
1188static void to7_game_init ( running_machine &machine )
1099void thomson_state::to7_game_init()
11891100{
11901101   LOG (( "to7_game_init called\n" ));
1191   to7_game_timer = machine.scheduler().timer_alloc(FUNC(to7_game_update_cb));
1192   to7_game_timer->adjust(TO7_GAME_POLL_PERIOD, 0, TO7_GAME_POLL_PERIOD);
1193   state_save_register_global( machine, to7_game_sound );
1194   state_save_register_global( machine, to7_game_mute );
1102   m_to7_game_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::to7_game_update_cb),this));
1103   m_to7_game_timer->adjust(TO7_GAME_POLL_PERIOD, 0, TO7_GAME_POLL_PERIOD);
1104   save_item(NAME(m_to7_game_sound));
1105   save_item(NAME(m_to7_game_mute));
11951106}
11961107
11971108
11981109
1199static void to7_game_reset ( running_machine &machine )
1110void thomson_state::to7_game_reset()
12001111{
1201   pia6821_device *game_pia = machine.device<pia6821_device>(THOM_PIA_GAME);
1202
12031112   LOG (( "to7_game_reset called\n" ));
1204   game_pia->ca1_w( 0 );
1205   to7_game_sound = 0;
1206   to7_game_mute = 0;
1207   to7_game_sound_update( machine );
1113   m_pia_game->ca1_w( 0 );
1114   m_to7_game_sound = 0;
1115   m_to7_game_mute = 0;
1116   to7_game_sound_update();
12081117}
12091118
12101119
r21425r21426
14281337
14291338
14301339
1431READ8_HANDLER ( to7_midi_r )
1340READ8_MEMBER( thomson_state::to7_midi_r )
14321341{
14331342   logerror( "to7_midi_r: not implemented\n" );
14341343   return 0;
r21425r21426
14361345
14371346
14381347
1439WRITE8_HANDLER ( to7_midi_w )
1348WRITE8_MEMBER( thomson_state::to7_midi_w )
14401349{
14411350   logerror( "to7_midi_w: not implemented\n" );
14421351}
14431352
14441353
14451354
1446static void to7_midi_reset( running_machine &machine )
1355void thomson_state::to7_midi_reset()
14471356{
14481357   logerror( "to7_midi_reset: not implemented\n" );
14491358}
14501359
14511360
14521361
1453static void to7_midi_init( running_machine &machine )
1362void thomson_state::to7_midi_init()
14541363{
14551364   logerror( "to7_midi_init: not implemented\n" );
14561365}
r21425r21426
14651374
14661375
14671376
1468MACHINE_RESET ( to7 )
1377MACHINE_RESET_MEMBER( thomson_state, to7 )
14691378{
1470   pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS );
1471
14721379   LOG (( "to7: machine reset called\n" ));
14731380
14741381   /* subsystems */
1475   thom_irq_reset(machine);
1476   to7_game_reset(machine);
1477   to7_floppy_reset(machine);
1478   to7_modem_reset(machine);
1479   to7_midi_reset(machine);
1382   thom_irq_reset();
1383   to7_game_reset();
1384   to7_floppy_reset();
1385   to7_modem_reset();
1386   to7_midi_reset();
14801387
14811388   /* video */
1482   thom_set_video_mode( machine, THOM_VMODE_TO770 );
1483   thom_set_init_callback( machine, to7_set_init );
1484   thom_set_lightpen_callback( machine, 3, to7_lightpen_cb );
1485   thom_set_mode_point( machine, 0 );
1486   thom_set_border_color( machine, 0 );
1487   sys_pia->cb1_w( 0 );
1389   thom_set_video_mode( THOM_VMODE_TO770 );
1390   m_thom_init_cb = &thomson_state::to7_set_init;
1391   m_thom_lightpen_cb = &thomson_state::to7_lightpen_cb;
1392   thom_set_lightpen_callback( 3 );
1393   thom_set_mode_point( 0 );
1394   thom_set_border_color( 0 );
1395   m_pia_sys->cb1_w( 0 );
14881396
14891397   /* memory */
1490   old_cart_bank = -1;
1491   to7_update_cart_bank(machine);
1398   m_old_cart_bank = -1;
1399   to7_update_cart_bank();
14921400   /* thom_cart_bank not reset */
14931401
14941402   /* lightpen */
1495   to7_lightpen = 0;
1403   m_to7_lightpen = 0;
14961404}
14971405
14981406
14991407
1500MACHINE_START ( to7 )
1408MACHINE_START_MEMBER( thomson_state, to7 )
15011409{
1502   address_space& space = machine.device("maincpu")->memory().space(AS_PROGRAM);
1503   UINT8* mem = machine.root_device().memregion("maincpu")->base();
1504   UINT8* ram = machine.device<ram_device>(RAM_TAG)->pointer();
1410   address_space& space = m_maincpu->space(AS_PROGRAM);
1411   UINT8* mem = memregion("maincpu")->base();
1412   UINT8* ram = m_ram->pointer();
15051413
15061414   LOG (( "to7: machine start called\n" ));
15071415
15081416   /* subsystems */
1509   thom_irq_init(machine);
1510   to7_game_init(machine);
1511   to7_floppy_init(machine, mem + 0x20000);
1512   to7_modem_init(machine);
1513   to7_midi_init(machine);
1417   thom_irq_init();
1418   to7_game_init();
1419   to7_floppy_init(mem + 0x20000);
1420   to7_modem_init();
1421   to7_midi_init();
15141422
15151423   /* memory */
1516   thom_cart_bank = 0;
1517   thom_vram = ram;
1518   machine.root_device().membank( THOM_BASE_BANK )->configure_entry( 0, ram + 0x4000);
1519   machine.root_device().membank( THOM_VRAM_BANK )->configure_entries( 0, 2, thom_vram, 0x2000 );
1520   machine.root_device().membank( THOM_CART_BANK )->configure_entries( 0, 4, mem + 0x10000, 0x4000 );
1521   machine.root_device().membank( THOM_BASE_BANK )->set_entry( 0 );
1522   machine.root_device().membank( THOM_VRAM_BANK )->set_entry( 0 );
1523   machine.root_device().membank( THOM_CART_BANK )->set_entry( 0 );
1424   m_thom_cart_bank = 0;
1425   m_thom_vram = ram;
1426   membank( THOM_BASE_BANK )->configure_entry( 0, ram + 0x4000);
1427   membank( THOM_VRAM_BANK )->configure_entries( 0, 2, m_thom_vram, 0x2000 );
1428   membank( THOM_CART_BANK )->configure_entries( 0, 4, mem + 0x10000, 0x4000 );
1429   membank( THOM_BASE_BANK )->set_entry( 0 );
1430   membank( THOM_VRAM_BANK )->set_entry( 0 );
1431   membank( THOM_CART_BANK )->set_entry( 0 );
15241432
1525   if ( machine.device<ram_device>(RAM_TAG)->size() > 24*1024 )
1433   if ( m_ram->size() > 24*1024 )
15261434   {
15271435      /* install 16 KB or 16 KB + 8 KB memory extensions */
15281436      /* BASIC instruction to see free memory: ?FRE(0) */
1529      int extram = machine.device<ram_device>(RAM_TAG)->size() - 24*1024;
1437      int extram = m_ram->size() - 24*1024;
15301438      space.install_write_bank(0x8000, 0x8000 + extram - 1, THOM_RAM_BANK);
15311439      space.install_read_bank(0x8000, 0x8000 + extram - 1, THOM_RAM_BANK );
1532      machine.root_device().membank( THOM_RAM_BANK )->configure_entry( 0, ram + 0x6000);
1533      machine.root_device().membank( THOM_RAM_BANK )->set_entry( 0 );
1440      membank( THOM_RAM_BANK )->configure_entry( 0, ram + 0x6000);
1441      membank( THOM_RAM_BANK )->set_entry( 0 );
15341442   }
15351443
15361444   /* force 2 topmost color bits to 1 */
1537   memset( thom_vram + 0x2000, 0xc0, 0x2000 );
1445   memset( m_thom_vram + 0x2000, 0xc0, 0x2000 );
15381446
15391447   /* save-state */
1540   state_save_register_global( machine, thom_cart_nb_banks );
1541   state_save_register_global( machine, thom_cart_bank );
1542   state_save_register_global( machine, to7_lightpen );
1543   state_save_register_global( machine, to7_lightpen_step );
1544   state_save_register_global_pointer( machine, (mem + 0x10000), 0x10000 );
1545   machine.save().register_postload(save_prepost_delegate(FUNC(to7_update_cart_bank_postload), &machine));
1448   save_item(NAME(m_thom_cart_nb_banks));
1449   save_item(NAME(m_thom_cart_bank));
1450   save_item(NAME(m_to7_lightpen));
1451   save_item(NAME(m_to7_lightpen_step));
1452   state_save_register_global_pointer( machine(), (mem + 0x10000), 0x10000 );
1453   machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to7_update_cart_bank_postload),this));
15461454}
15471455
15481456
r21425r21426
15551463
15561464
15571465
1558static WRITE8_DEVICE_HANDLER ( to770_sys_cb2_out )
1466WRITE8_MEMBER( thomson_state::to770_sys_cb2_out )
15591467{
15601468   /* video overlay: black pixels are transparent and show TV image underneath */
1561   LOG(( "$%04x to770_sys_cb2_out: video overlay %i\n", space.machine().device("maincpu")->safe_pcbase(), data ));
1469   LOG(( "$%04x to770_sys_cb2_out: video overlay %i\n", m_maincpu->pc(), data ));
15621470}
15631471
15641472
15651473
1566static READ8_DEVICE_HANDLER ( to770_sys_porta_in )
1474READ8_MEMBER( thomson_state::to770_sys_porta_in )
15671475{
15681476   /* keyboard */
15691477   static const char *const keynames[] = {
15701478      "keyboard_0", "keyboard_1", "keyboard_2", "keyboard_3",
15711479      "keyboard_4", "keyboard_5", "keyboard_6", "keyboard_7"
15721480   };
1573   int keyline = downcast<pia6821_device *>(device)->b_output() & 7;
1481   int keyline = m_pia_sys->b_output() & 7;
15741482
1575   return space.machine().root_device().ioport(keynames[7 - keyline])->read();
1483   return ioport(keynames[7 - keyline])->read();
15761484}
15771485
15781486
15791487
1580static void to770_update_ram_bank(running_machine &machine)
1488void thomson_state::to770_update_ram_bank()
15811489{
1582   pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS );
1583   address_space& space = machine.device("maincpu")->memory().space(AS_PROGRAM);
1584   UINT8 portb = sys_pia->port_b_z_mask();
1490   address_space& space = m_maincpu->space(AS_PROGRAM);
1491   UINT8 portb = m_pia_sys->port_b_z_mask();
15851492   int bank;
15861493
15871494   switch (portb & 0xf8)
r21425r21426
16041511      return;
16051512   }
16061513
1607   if ( bank != old_ram_bank )
1514   if ( bank != m_old_ram_bank )
1515   {
1516      if ( m_ram->size() == 128*1024 || bank < 2 )
16081517      {
1609      if ( machine.device<ram_device>(RAM_TAG)->size() == 128*1024 || bank < 2 )
1610            {
1611         machine.root_device().membank( THOM_RAM_BANK )->set_entry( bank );
1518         membank( THOM_RAM_BANK )->set_entry( bank );
16121519      }
1613            else
1614            {
1520      else
1521      {
16151522         /* RAM size is 48 KB only and unavailable bank
16161523          * requested */
16171524         space.nop_readwrite(0xa000, 0xdfff);
16181525      }
1619      old_ram_bank = bank;
1526      m_old_ram_bank = bank;
16201527      LOG_BANK(( "to770_update_ram_bank: RAM bank change %i\n", bank ));
16211528   }
16221529}
16231530
16241531
16251532
1626static void to770_update_ram_bank_postload(running_machine *machine)
1533void thomson_state::to770_update_ram_bank_postload()
16271534{
1628   to770_update_ram_bank(*machine);
1535   to770_update_ram_bank();
16291536}
16301537
16311538
16321539
1633static WRITE8_DEVICE_HANDLER ( to770_sys_portb_out )
1540WRITE8_MEMBER( thomson_state::to770_sys_portb_out )
16341541{
1635   to770_update_ram_bank(space.machine());
1542   to770_update_ram_bank();
16361543}
16371544
16381545
16391546
16401547const pia6821_interface to770_pia6821_sys =
16411548{
1642   DEVCB_HANDLER(to770_sys_porta_in),
1549   DEVCB_DRIVER_MEMBER(thomson_state, to770_sys_porta_in),
16431550   DEVCB_NULL,
16441551   DEVCB_NULL,
16451552   DEVCB_NULL,
16461553   DEVCB_NULL,
16471554   DEVCB_NULL,
16481555   DEVCB_NULL,
1649   DEVCB_HANDLER(to770_sys_portb_out),
1650   DEVCB_HANDLER(to7_set_cassette_motor),
1651   DEVCB_HANDLER(to770_sys_cb2_out),
1652   DEVCB_LINE(thom_firq_1),
1653   DEVCB_LINE(thom_firq_1)
1556   DEVCB_DRIVER_MEMBER(thomson_state, to770_sys_portb_out),
1557   DEVCB_DRIVER_MEMBER(thomson_state, to7_set_cassette_motor),
1558   DEVCB_DRIVER_MEMBER(thomson_state, to770_sys_cb2_out),
1559   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1),
1560   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1)
16541561};
16551562
16561563
r21425r21426
16591566
16601567
16611568
1662static WRITE8_DEVICE_HANDLER ( to770_timer_port_out )
1569WRITE8_MEMBER( thomson_state::to770_timer_port_out )
16631570{
1664   thom_set_mode_point( space.machine(), data & 1 );          /* bit 0: video bank switch */
1665   thom_set_caps_led( space.machine(), (data & 8) ? 1 : 0 ) ; /* bit 3: keyboard led */
1666   thom_set_border_color( space.machine(),
1667               ((data & 0x10) ? 1 : 0) |          /* 4-bit border color */
1668               ((data & 0x20) ? 2 : 0) |
1669               ((data & 0x40) ? 4 : 0) |
1670               ((data & 0x04) ? 0 : 8) );
1571   thom_set_mode_point( data & 1 );          /* bit 0: video bank switch */
1572   thom_set_caps_led( (data & 8) ? 1 : 0 ) ; /* bit 3: keyboard led */
1573   thom_set_border_color( ((data & 0x10) ? 1 : 0) |          /* 4-bit border color */
1574                          ((data & 0x20) ? 2 : 0) |
1575                          ((data & 0x40) ? 4 : 0) |
1576                          ((data & 0x04) ? 0 : 8) );
16711577}
16721578
16731579
16741580
16751581const mc6846_interface to770_timer =
16761582{
1677   DEVCB_HANDLER(to770_timer_port_out), DEVCB_NULL, DEVCB_HANDLER(to7_timer_cp2_out),
1678   DEVCB_HANDLER(to7_timer_port_in), DEVCB_HANDLER(to7_timer_tco_out),
1679   DEVCB_LINE(thom_dev_irq_0)
1583   DEVCB_DRIVER_MEMBER(thomson_state, to770_timer_port_out),
1584   DEVCB_NULL,
1585   DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_cp2_out),
1586   DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_port_in),
1587   DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_tco_out),
1588   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_dev_irq_0)
16801589};
16811590
16821591
r21425r21426
16851594
16861595
16871596
1688READ8_HANDLER ( to770_gatearray_r )
1597READ8_MEMBER( thomson_state::to770_gatearray_r )
16891598{
1690   struct thom_vsignal v = thom_get_vsignal(space.machine());
1691   struct thom_vsignal l = thom_get_lightpen_vsignal( space.machine(), TO7_LIGHTPEN_DECAL, to7_lightpen_step - 1, 0 );
1599   struct thom_vsignal v = thom_get_vsignal();
1600   struct thom_vsignal l = thom_get_lightpen_vsignal( TO7_LIGHTPEN_DECAL, m_to7_lightpen_step - 1, 0 );
16921601   int count, inil, init, lt3;
1693   count = to7_lightpen ? l.count : v.count;
1694   inil  = to7_lightpen ? l.inil  : v.inil;
1695   init  = to7_lightpen ? l.init  : v.init;
1696   lt3   = to7_lightpen ? l.lt3   : v.lt3;
1602   count = m_to7_lightpen ? l.count : v.count;
1603   inil  = m_to7_lightpen ? l.inil  : v.inil;
1604   init  = m_to7_lightpen ? l.init  : v.init;
1605   lt3   = m_to7_lightpen ? l.lt3   : v.lt3;
16971606
16981607   switch ( offset )
16991608   {
r21425r21426
17021611   case 2: return (lt3 << 7) | (inil << 6);
17031612   case 3: return (init << 7);
17041613   default:
1705      logerror( "$%04x to770_gatearray_r: invalid offset %i\n", space.machine().device("maincpu")->safe_pcbase(), offset );
1614      logerror( "$%04x to770_gatearray_r: invalid offset %i\n", m_maincpu->pc(), offset );
17061615      return 0;
17071616   }
17081617}
17091618
17101619
17111620
1712WRITE8_HANDLER ( to770_gatearray_w )
1621WRITE8_MEMBER( thomson_state::to770_gatearray_w )
17131622{
17141623   if ( ! offset )
1715      to7_lightpen = data & 1;
1624      m_to7_lightpen = data & 1;
17161625}
17171626
17181627
r21425r21426
17211630
17221631
17231632
1724MACHINE_RESET( to770 )
1633MACHINE_RESET_MEMBER( thomson_state, to770 )
17251634{
1726   pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS );
1727
17281635   LOG (( "to770: machine reset called\n" ));
17291636
17301637   /* subsystems */
1731   thom_irq_reset(machine);
1732   to7_game_reset(machine);
1733   to7_floppy_reset(machine);
1734   to7_modem_reset(machine);
1735   to7_midi_reset(machine);
1638   thom_irq_reset();
1639   to7_game_reset();
1640   to7_floppy_reset();
1641   to7_modem_reset();
1642   to7_midi_reset();
17361643
17371644   /* video */
1738   thom_set_video_mode( machine, THOM_VMODE_TO770 );
1739   thom_set_init_callback( machine, to7_set_init );
1740   thom_set_lightpen_callback( machine, 3, to7_lightpen_cb );
1741   thom_set_mode_point( machine, 0 );
1742   thom_set_border_color( machine, 8 );
1743   sys_pia->cb1_w( 0 );
1645   thom_set_video_mode( THOM_VMODE_TO770 );
1646   m_thom_init_cb = &thomson_state::to7_set_init;
1647   m_thom_lightpen_cb = &thomson_state::to7_lightpen_cb;
1648   thom_set_lightpen_callback( 3 );
1649   thom_set_mode_point( 0 );
1650   thom_set_border_color( 8 );
1651   m_pia_sys->cb1_w( 0 );
17441652
17451653   /* memory */
1746   old_ram_bank = -1;
1747   old_cart_bank = -1;
1748   to7_update_cart_bank(machine);
1749   to770_update_ram_bank(machine);
1654   m_old_ram_bank = -1;
1655   m_old_cart_bank = -1;
1656   to7_update_cart_bank();
1657   to770_update_ram_bank();
17501658   /* thom_cart_bank not reset */
17511659
17521660   /* lightpen */
1753   to7_lightpen = 0;
1661   m_to7_lightpen = 0;
17541662}
17551663
17561664
17571665
1758MACHINE_START ( to770 )
1666MACHINE_START_MEMBER( thomson_state, to770 )
17591667{
1760   UINT8* mem = machine.root_device().memregion("maincpu")->base();
1761   UINT8* ram = machine.device<ram_device>(RAM_TAG)->pointer();
1668   UINT8* mem = memregion("maincpu")->base();
1669   UINT8* ram = m_ram->pointer();
17621670
17631671   LOG (( "to770: machine start called\n" ));
17641672
17651673   /* subsystems */
1766   thom_irq_init(machine);
1767   to7_game_init(machine);
1768   to7_floppy_init( machine, mem + 0x20000 );
1769   to7_modem_init(machine);
1770   to7_midi_init(machine);
1674   thom_irq_init();
1675   to7_game_init();
1676   to7_floppy_init( mem + 0x20000 );
1677   to7_modem_init();
1678   to7_midi_init();
17711679
17721680   /* memory */
1773   thom_cart_bank = 0;
1774   thom_vram = ram;
1775   machine.root_device().membank( THOM_BASE_BANK )->configure_entry( 0, ram + 0x4000);
1776   machine.root_device().membank( THOM_RAM_BANK )->configure_entries( 0, 6, ram + 0x8000, 0x4000 );
1777   machine.root_device().membank( THOM_VRAM_BANK )->configure_entries( 0, 2, thom_vram, 0x2000 );
1778   machine.root_device().membank( THOM_CART_BANK )->configure_entries( 0, 4, mem + 0x10000, 0x4000 );
1779   machine.root_device().membank( THOM_BASE_BANK )->set_entry( 0 );
1780   machine.root_device().membank( THOM_RAM_BANK )->set_entry( 0 );
1781   machine.root_device().membank( THOM_VRAM_BANK )->set_entry( 0 );
1782   machine.root_device().membank( THOM_CART_BANK )->set_entry( 0 );
1681   m_thom_cart_bank = 0;
1682   m_thom_vram = ram;
1683   membank( THOM_BASE_BANK )->configure_entry( 0, ram + 0x4000);
1684   membank( THOM_RAM_BANK )->configure_entries( 0, 6, ram + 0x8000, 0x4000 );
1685   membank( THOM_VRAM_BANK )->configure_entries( 0, 2, m_thom_vram, 0x2000 );
1686   membank( THOM_CART_BANK )->configure_entries( 0, 4, mem + 0x10000, 0x4000 );
1687   membank( THOM_BASE_BANK )->set_entry( 0 );
1688   membank( THOM_RAM_BANK )->set_entry( 0 );
1689   membank( THOM_VRAM_BANK )->set_entry( 0 );
1690   membank( THOM_CART_BANK )->set_entry( 0 );
17831691
17841692   /* save-state */
1785   state_save_register_global( machine, thom_cart_nb_banks );
1786   state_save_register_global( machine, thom_cart_bank );
1787   state_save_register_global( machine, to7_lightpen );
1788   state_save_register_global( machine, to7_lightpen_step );
1789   state_save_register_global_pointer( machine, (mem + 0x10000), 0x10000 );
1790   machine.save().register_postload(save_prepost_delegate(FUNC(to770_update_ram_bank_postload), &machine));
1791   machine.save().register_postload(save_prepost_delegate(FUNC(to7_update_cart_bank_postload), &machine));
1693   save_item(NAME(m_thom_cart_nb_banks));
1694   save_item(NAME(m_thom_cart_bank));
1695   save_item(NAME(m_to7_lightpen));
1696   save_item(NAME(m_to7_lightpen_step));
1697   state_save_register_global_pointer( machine(), (mem + 0x10000), 0x10000 );
1698   machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to770_update_ram_bank_postload), this));
1699   machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to7_update_cart_bank_postload), this));
17921700}
17931701
17941702
r21425r21426
18011709
18021710
18031711
1804static void mo5_lightpen_cb ( running_machine &machine, int step )
1712void thomson_state::mo5_lightpen_cb( int step )
18051713{
1806   pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS );
1807
18081714   /* MO5 signals ca1 (TO7 signals cb1) */
1809   if ( ! to7_lightpen )
1715   if ( ! m_to7_lightpen )
18101716      return;
18111717
1812   sys_pia->ca1_w( 1 );
1813   sys_pia->ca1_w( 0 );
1814   to7_lightpen_step = step;
1718   m_pia_sys->ca1_w( 1 );
1719   m_pia_sys->ca1_w( 0 );
1720   m_to7_lightpen_step = step;
18151721}
18161722
18171723
r21425r21426
18221728*/
18231729
18241730
1825
1826static emu_timer* mo5_periodic_timer;
1827
1828
1829
1830static TIMER_CALLBACK(mo5_periodic_cb)
1731TIMER_CALLBACK_MEMBER(thomson_state::mo5_periodic_cb)
18311732{
1832   pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS );
1833
18341733   /* pulse */
1835   sys_pia->cb1_w( 1 );
1836   sys_pia->cb1_w( 0 );
1734   m_pia_sys->cb1_w( 1 );
1735   m_pia_sys->cb1_w( 0 );
18371736}
18381737
18391738
18401739
1841static void mo5_init_timer(running_machine &machine)
1740void thomson_state::mo5_init_timer()
18421741{
18431742   /* time is a little faster than 50 Hz to match video framerate */
1844   mo5_periodic_timer->adjust(attotime::zero, 0, attotime::from_usec( 19968 ));
1743   m_mo5_periodic_timer->adjust(attotime::zero, 0, attotime::from_usec( 19968 ));
18451744}
18461745
18471746
r21425r21426
18501749
18511750
18521751
1853static WRITE8_DEVICE_HANDLER ( mo5_sys_porta_out )
1752WRITE8_MEMBER( thomson_state::mo5_sys_porta_out )
18541753{
1855   thom_set_mode_point( space.machine(), data & 1 );       /* bit 0: video bank switch */
1856   thom_set_border_color( space.machine(), (data >> 1) & 15 ); /* bit 1-4: border color */
1857   mo5_set_cassette( space.machine(), (data & 0x40) ? 1 : 0 ); /* bit 6: cassette output */
1754   thom_set_mode_point( data & 1 );       /* bit 0: video bank switch */
1755   thom_set_border_color( (data >> 1) & 15 ); /* bit 1-4: border color */
1756   mo5_set_cassette( (data & 0x40) ? 1 : 0 ); /* bit 6: cassette output */
18581757}
18591758
18601759
18611760
1862static READ8_DEVICE_HANDLER ( mo5_sys_porta_in )
1761READ8_MEMBER( thomson_state::mo5_sys_porta_in )
18631762{
18641763   return
1865      (mo5_get_cassette(space.machine()) ? 0x80 : 0) |     /* bit 7: cassette input */
1866      ((space.machine().root_device().ioport("lightpen_button")->read() & 1) ? 0x20 : 0)
1764      (mo5_get_cassette() ? 0x80 : 0) |     /* bit 7: cassette input */
1765      ((ioport("lightpen_button")->read() & 1) ? 0x20 : 0)
18671766      /* bit 5: lightpen button */;
18681767}
18691768
18701769
18711770
1872static WRITE8_DEVICE_HANDLER ( mo5_sys_portb_out )
1771WRITE8_MEMBER( thomson_state::mo5_sys_portb_out )
18731772{
1874   space.machine().device<dac_device>("buzzer")->write_unsigned8((data & 1) ? 0x80 : 0); /* 1-bit buzzer */
1773   m_buzzer->write_unsigned8((data & 1) ? 0x80 : 0); /* 1-bit buzzer */
18751774}
18761775
18771776
18781777
1879static READ8_DEVICE_HANDLER ( mo5_sys_portb_in )
1778READ8_MEMBER( thomson_state::mo5_sys_portb_in )
18801779{
1881   UINT8 portb = downcast<pia6821_device *>(device)->b_output();
1780   UINT8 portb = m_pia_sys->b_output();
18821781   int col = (portb >> 1) & 7;       /* key column */
18831782   int lin = 7 - ((portb >> 4) & 7); /* key line */
18841783   static const char *const keynames[] = {
r21425r21426
18861785      "keyboard_4", "keyboard_5", "keyboard_6", "keyboard_7"
18871786   };
18881787
1889   return ( space.machine().root_device().ioport(keynames[lin])->read() & (1 << col) ) ? 0x80 : 0;
1788   return ( ioport(keynames[lin])->read() & (1 << col) ) ? 0x80 : 0;
18901789}
18911790
18921791
18931792
18941793const pia6821_interface mo5_pia6821_sys =
18951794{
1896   DEVCB_HANDLER(mo5_sys_porta_in),
1897   DEVCB_HANDLER(mo5_sys_portb_in),
1795   DEVCB_DRIVER_MEMBER(thomson_state, mo5_sys_porta_in),
1796   DEVCB_DRIVER_MEMBER(thomson_state, mo5_sys_portb_in),
18981797   DEVCB_NULL,
18991798   DEVCB_NULL,
19001799   DEVCB_NULL,
19011800   DEVCB_NULL,
1902   DEVCB_HANDLER(mo5_sys_porta_out),
1903   DEVCB_HANDLER(mo5_sys_portb_out),
1904   DEVCB_HANDLER(mo5_set_cassette_motor),
1801   DEVCB_DRIVER_MEMBER(thomson_state, mo5_sys_porta_out),
1802   DEVCB_DRIVER_MEMBER(thomson_state, mo5_sys_portb_out),
1803   DEVCB_DRIVER_MEMBER(thomson_state, mo5_set_cassette_motor),
19051804   DEVCB_NULL,
1906   DEVCB_LINE(thom_firq_1),
1907   DEVCB_LINE(thom_irq_1) /* WARNING: differs from TO7 ! */
1805   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1),
1806   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_irq_1) /* WARNING: differs from TO7 ! */
19081807};
19091808
19101809
r21425r21426
19171816
19181817
19191818
1920READ8_HANDLER ( mo5_gatearray_r )
1819READ8_MEMBER( thomson_state::mo5_gatearray_r )
19211820{
1922   struct thom_vsignal v = thom_get_vsignal(space.machine());
1923   struct thom_vsignal l = thom_get_lightpen_vsignal( space.machine(), MO5_LIGHTPEN_DECAL, to7_lightpen_step - 1, 0 );
1821   struct thom_vsignal v = thom_get_vsignal();
1822   struct thom_vsignal l = thom_get_lightpen_vsignal( MO5_LIGHTPEN_DECAL, m_to7_lightpen_step - 1, 0 );
19241823   int count, inil, init, lt3;
1925   count = to7_lightpen ? l.count : v.count;
1926   inil  = to7_lightpen ? l.inil  : v.inil;
1927   init  = to7_lightpen ? l.init  : v.init;
1928   lt3   = to7_lightpen ? l.lt3   : v.lt3;
1824   count = m_to7_lightpen ? l.count : v.count;
1825   inil  = m_to7_lightpen ? l.inil  : v.inil;
1826   init  = m_to7_lightpen ? l.init  : v.init;
1827   lt3   = m_to7_lightpen ? l.lt3   : v.lt3;
19291828
19301829   switch ( offset ) {
19311830   case 0: return (count >> 8) & 0xff;
r21425r21426
19331832   case 2: return (lt3 << 7) | (inil << 6);
19341833   case 3: return (init << 7);
19351834   default:
1936      logerror( "$%04x mo5_gatearray_r: invalid offset %i\n",  space.machine().device("maincpu")->safe_pcbase(), offset );
1835      logerror( "$%04x mo5_gatearray_r: invalid offset %i\n",  m_maincpu->pc(), offset );
19371836      return 0;
19381837   }
19391838}
19401839
19411840
19421841
1943WRITE8_HANDLER ( mo5_gatearray_w )
1842WRITE8_MEMBER( thomson_state::mo5_gatearray_w )
19441843{
19451844   if ( ! offset )
1946      to7_lightpen = data & 1;
1845      m_to7_lightpen = data & 1;
19471846}
19481847
19491848
r21425r21426
19521851
19531852
19541853
1955static UINT8 mo5_reg_cart; /* 0xa7cb bank switch */
1956
1957
1958
19591854DEVICE_IMAGE_LOAD_MEMBER( thomson_state, mo5_cartridge )
19601855{
1961   UINT8* pos = image.device().machine().root_device().memregion("maincpu")->base() + 0x10000;
1856   UINT8* pos = memregion("maincpu")->base() + 0x10000;
19621857   UINT64 size;
19631858   int i,j;
19641859   char name[129];
r21425r21426
19701865
19711866   /* get size & number of 16-KB banks */
19721867   if ( size > 32 && size <= 0x04000 )
1973      thom_cart_nb_banks = 1;
1868      m_thom_cart_nb_banks = 1;
19741869   else if ( size == 0x08000 )
1975      thom_cart_nb_banks = 2;
1870      m_thom_cart_nb_banks = 2;
19761871   else if ( size == 0x10000 )
1977      thom_cart_nb_banks = 4;
1872      m_thom_cart_nb_banks = 4;
19781873   else
19791874   {
19801875      astring errmsg;
r21425r21426
20091904      if ( name[i] < ' ' || name[i] >= 127 ) name[i] = '?';
20101905   }
20111906
2012   PRINT (( "mo5_cartridge_load: cartridge \"%s\" banks=%i, size=%u\n", name, thom_cart_nb_banks, (unsigned) size ));
1907   PRINT (( "mo5_cartridge_load: cartridge \"%s\" banks=%i, size=%u\n", name, m_thom_cart_nb_banks, (unsigned) size ));
20131908
20141909   return IMAGE_INIT_PASS;
20151910}
20161911
20171912
20181913
2019static void mo5_update_cart_bank(running_machine &machine)
1914void thomson_state::mo5_update_cart_bank()
20201915{
2021   address_space& space = machine.device("maincpu")->memory().space(AS_PROGRAM);
2022   int rom_is_ram = mo5_reg_cart & 4;
1916   address_space& space = m_maincpu->space(AS_PROGRAM);
1917   int rom_is_ram = m_mo5_reg_cart & 4;
20231918   int bank = 0;
20241919   int bank_is_read_only = 0;
20251920
20261921
2027   if ( rom_is_ram && thom_cart_nb_banks == 4 )
1922   if ( rom_is_ram && m_thom_cart_nb_banks == 4 )
20281923   {
20291924      /* 64 KB ROM from "JANE" cartridge */
2030      bank = mo5_reg_cart & 3;
2031      if ( bank != old_cart_bank )
2032            {
2033         if ( old_cart_bank < 0 || old_cart_bank > 3 )
2034                  {
1925      bank = m_mo5_reg_cart & 3;
1926      if ( bank != m_old_cart_bank )
1927      {
1928         if ( m_old_cart_bank < 0 || m_old_cart_bank > 3 )
1929         {
20351930            space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK);
20361931            space.nop_write( 0xb000, 0xefff);
20371932         }
r21425r21426
20411936   else if ( rom_is_ram )
20421937   {
20431938      /* 64 KB RAM from network extension */
2044      bank = 4 + ( mo5_reg_cart & 3 );
2045      bank_is_read_only = (( mo5_reg_cart & 8 ) == 0);
1939      bank = 4 + ( m_mo5_reg_cart & 3 );
1940      bank_is_read_only = (( m_mo5_reg_cart & 8 ) == 0);
20461941
2047      if ( bank != old_cart_bank || bank_is_read_only != old_cart_bank_was_read_only)
2048            {
2049                  if ( bank_is_read_only )
2050                  {
2051                        space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK);
2052                        space.nop_write( 0xb000, 0xefff );
2053                  }
2054                  else
2055                  {
2056                        space.install_readwrite_bank( 0xb000, 0xefff, THOM_CART_BANK);
2057                  }
2058                  LOG_BANK(( "mo5_update_cart_bank: CART is nanonetwork RAM bank %i (%s)\n",
2059                           mo5_reg_cart & 3,
2060                           bank_is_read_only ? "read-only":"read-write"));
2061                  old_cart_bank_was_read_only = bank_is_read_only;
2062            }
1942      if ( bank != m_old_cart_bank || bank_is_read_only != m_old_cart_bank_was_read_only)
1943      {
1944         if ( bank_is_read_only )
1945         {
1946            space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK);
1947            space.nop_write( 0xb000, 0xefff );
1948         }
1949         else
1950         {
1951            space.install_readwrite_bank( 0xb000, 0xefff, THOM_CART_BANK);
1952         }
1953         LOG_BANK(( "mo5_update_cart_bank: CART is nanonetwork RAM bank %i (%s)\n",
1954                  m_mo5_reg_cart & 3,
1955                  bank_is_read_only ? "read-only":"read-write"));
1956         m_old_cart_bank_was_read_only = bank_is_read_only;
1957      }
20631958   }
20641959   else
20651960   {
20661961      /* regular cartridge bank switch */
2067      if ( thom_cart_nb_banks )
1962      if ( m_thom_cart_nb_banks )
20681963      {
2069         bank = thom_cart_bank % thom_cart_nb_banks;
2070         if ( bank != old_cart_bank )
2071                  {
2072            if ( old_cart_bank < 0 )
2073                        {
1964         bank = m_thom_cart_bank % m_thom_cart_nb_banks;
1965         if ( bank != m_old_cart_bank )
1966         {
1967            if ( m_old_cart_bank < 0 )
1968            {
20741969               space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK);
2075               space.install_legacy_write_handler( 0xb000, 0xefff, FUNC(mo5_cartridge_w) );
2076               space.install_legacy_read_handler( 0xbffc, 0xbfff, FUNC(mo5_cartridge_r) );
1970               space.install_write_handler( 0xb000, 0xefff, write8_delegate(FUNC(thomson_state::mo5_cartridge_w),this) );
1971               space.install_read_handler( 0xbffc, 0xbfff, read8_delegate(FUNC(thomson_state::mo5_cartridge_r),this) );
20771972            }
20781973            LOG_BANK(( "mo5_update_cart_bank: CART is cartridge bank %i\n", bank ));
20791974         }
2080      } else
1975      }
1976      else
1977      {
20811978         /* internal ROM */
2082         if ( old_cart_bank != 0 )
1979         if ( m_old_cart_bank != 0 )
20831980                  {
20841981            space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK);
2085            space.install_legacy_write_handler( 0xb000, 0xefff, FUNC(mo5_cartridge_w) );
1982            space.install_write_handler( 0xb000, 0xefff, write8_delegate(FUNC(thomson_state::mo5_cartridge_w),this) );
20861983            LOG_BANK(( "mo5_update_cart_bank: CART is internal\n"));
20871984         }
1985      }
20881986   }
2089   if ( bank != old_cart_bank )
2090      {
2091      machine.root_device().membank( THOM_CART_BANK )->set_entry( bank );
2092      old_cart_bank = bank;
1987   if ( bank != m_old_cart_bank )
1988   {
1989      membank( THOM_CART_BANK )->set_entry( bank );
1990      m_old_cart_bank = bank;
20931991   }
20941992}
20951993
20961994
20971995
2098static void mo5_update_cart_bank_postload(running_machine *machine)
1996void thomson_state::mo5_update_cart_bank_postload()
20991997{
2100   mo5_update_cart_bank(*machine);
1998   mo5_update_cart_bank();
21011999}
21022000
21032001
21042002
21052003/* write signal to b000-cfff generates a bank switch */
2106WRITE8_HANDLER ( mo5_cartridge_w )
2004WRITE8_MEMBER( thomson_state::mo5_cartridge_w )
21072005{
21082006   if ( offset >= 0x2000 )
21092007      return;
21102008
2111   thom_cart_bank = offset & 3;
2112   mo5_update_cart_bank(space.machine());
2009   m_thom_cart_bank = offset & 3;
2010   mo5_update_cart_bank();
21132011}
21142012
21152013
21162014
21172015/* read signal to bffc-bfff generates a bank switch */
2118READ8_HANDLER ( mo5_cartridge_r )
2016READ8_MEMBER( thomson_state::mo5_cartridge_r )
21192017{
2120   UINT8* pos = space.machine().root_device().memregion( "maincpu" )->base() + 0x10000;
2121   UINT8 data = pos[offset + 0xbffc + (thom_cart_bank % thom_cart_nb_banks) * 0x4000];
2018   UINT8* pos = memregion( "maincpu" )->base() + 0x10000;
2019   UINT8 data = pos[offset + 0xbffc + (m_thom_cart_bank % m_thom_cart_nb_banks) * 0x4000];
21222020   if ( !space.debugger_access() )
2123      {
2124      thom_cart_bank = offset & 3;
2125      mo5_update_cart_bank(space.machine());
2021   {
2022      m_thom_cart_bank = offset & 3;
2023      mo5_update_cart_bank();
21262024   }
21272025   return data;
21282026}
r21425r21426
21302028
21312029
21322030/* 0xa7cb bank-switch register */
2133WRITE8_HANDLER ( mo5_ext_w )
2031WRITE8_MEMBER( thomson_state::mo5_ext_w )
21342032{
2135   mo5_reg_cart = data;
2136   mo5_update_cart_bank(space.machine());
2033   m_mo5_reg_cart = data;
2034   mo5_update_cart_bank();
21372035}
21382036
21392037
r21425r21426
21422040
21432041
21442042
2145MACHINE_RESET( mo5 )
2043MACHINE_RESET_MEMBER( thomson_state, mo5 )
21462044{
2147   pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS );
2148
21492045   LOG (( "mo5: machine reset called\n" ));
21502046
21512047   /* subsystems */
2152   thom_irq_reset(machine);
2153   sys_pia->set_port_a_z_mask(0x5f );
2154   to7_game_reset(machine);
2155   to7_floppy_reset(machine);
2156   to7_modem_reset(machine);
2157   to7_midi_reset(machine);
2158   mo5_init_timer(machine);
2048   thom_irq_reset();
2049   m_pia_sys->set_port_a_z_mask(0x5f );
2050   to7_game_reset();
2051   to7_floppy_reset();
2052   to7_modem_reset();
2053   to7_midi_reset();
2054   mo5_init_timer();
21592055
21602056   /* video */
2161   thom_set_video_mode( machine, THOM_VMODE_MO5 );
2162   thom_set_lightpen_callback( machine, 3, mo5_lightpen_cb );
2163   thom_set_mode_point( machine, 0 );
2164   thom_set_border_color( machine, 0 );
2165   sys_pia->ca1_w( 0 );
2057   thom_set_video_mode( THOM_VMODE_MO5 );
2058   m_thom_lightpen_cb = &thomson_state::mo5_lightpen_cb;
2059   thom_set_lightpen_callback( 3 );
2060   thom_set_mode_point( 0 );
2061   thom_set_border_color( 0 );
2062   m_pia_sys->ca1_w( 0 );
21662063
21672064   /* memory */
2168   old_cart_bank = -1;
2169   mo5_update_cart_bank(machine);
2065   m_old_cart_bank = -1;
2066   mo5_update_cart_bank();
21702067   /* mo5_reg_cart not reset */
21712068   /* thom_cart_bank not reset */
21722069
21732070   /* lightpen */
2174   to7_lightpen = 0;
2071   m_to7_lightpen = 0;
21752072}
21762073
21772074
21782075
2179MACHINE_START ( mo5 )
2076MACHINE_START_MEMBER( thomson_state, mo5 )
21802077{
2181   UINT8* mem = machine.root_device().memregion("maincpu")->base();
2182   UINT8* ram = machine.device<ram_device>(RAM_TAG)->pointer();
2078   UINT8* mem = memregion("maincpu")->base();
2079   UINT8* ram = m_ram->pointer();
21832080
21842081   LOG (( "mo5: machine start called\n" ));
21852082
21862083   /* subsystems */
2187   thom_irq_init(machine);
2188   to7_game_init(machine);
2189   to7_floppy_init( machine, mem + 0x20000 );
2190   to7_modem_init(machine);
2191   to7_midi_init(machine);
2192   mo5_periodic_timer = machine.scheduler().timer_alloc(FUNC(mo5_periodic_cb));
2084   thom_irq_init();
2085   to7_game_init();
2086   to7_floppy_init( mem + 0x20000 );
2087   to7_modem_init();
2088   to7_midi_init();
2089   m_mo5_periodic_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::mo5_periodic_cb),this));
21932090
21942091   /* memory */
2195   thom_cart_bank = 0;
2196   mo5_reg_cart = 0;
2197   thom_vram = ram;
2198   machine.root_device().membank( THOM_BASE_BANK )->configure_entry( 0, ram + 0x4000);
2199   machine.root_device().membank( THOM_CART_BANK )->configure_entries( 0, 4, mem + 0x10000, 0x4000 );
2200   machine.root_device().membank( THOM_CART_BANK )->configure_entries( 4, 4, ram + 0xc000, 0x4000 );
2201   machine.root_device().membank( THOM_VRAM_BANK )->configure_entries( 0, 2, thom_vram, 0x2000 );
2202   machine.root_device().membank( THOM_BASE_BANK )->set_entry( 0 );
2203   machine.root_device().membank( THOM_CART_BANK )->set_entry( 0 );
2204   machine.root_device().membank( THOM_VRAM_BANK )->set_entry( 0 );
2092   m_thom_cart_bank = 0;
2093   m_mo5_reg_cart = 0;
2094   m_thom_vram = ram;
2095   membank( THOM_BASE_BANK )->configure_entry( 0, ram + 0x4000);
2096   membank( THOM_CART_BANK )->configure_entries( 0, 4, mem + 0x10000, 0x4000 );
2097   membank( THOM_CART_BANK )->configure_entries( 4, 4, ram + 0xc000, 0x4000 );
2098   membank( THOM_VRAM_BANK )->configure_entries( 0, 2, m_thom_vram, 0x2000 );
2099   membank( THOM_BASE_BANK )->set_entry( 0 );
2100   membank( THOM_CART_BANK )->set_entry( 0 );
2101   membank( THOM_VRAM_BANK )->set_entry( 0 );
22052102
22062103   /* save-state */
2207   state_save_register_global( machine, thom_cart_nb_banks );
2208   state_save_register_global( machine, thom_cart_bank );
2209   state_save_register_global( machine, to7_lightpen );
2210   state_save_register_global( machine, to7_lightpen_step );
2211   state_save_register_global( machine, mo5_reg_cart );
2212   state_save_register_global_pointer( machine, (mem + 0x10000), 0x10000 );
2213   machine.save().register_postload(save_prepost_delegate(FUNC(mo5_update_cart_bank_postload), &machine));
2104   save_item(NAME(m_thom_cart_nb_banks));
2105   save_item(NAME(m_thom_cart_bank));
2106   save_item(NAME(m_to7_lightpen));
2107   save_item(NAME(m_to7_lightpen_step));
2108   save_item(NAME(m_mo5_reg_cart));
2109   state_save_register_global_pointer( machine(), (mem + 0x10000), 0x10000 );
2110   machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::mo5_update_cart_bank_postload), this));
22142111}
22152112
22162113
r21425r21426
22272124
22282125
22292126
2230WRITE8_HANDLER ( to9_ieee_w )
2127WRITE8_MEMBER( thomson_state::to9_ieee_w )
22312128{
2232   logerror( "$%04x %f to9_ieee_w: unhandled write $%02X to register %i\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), data, offset );
2129   logerror( "$%04x %f to9_ieee_w: unhandled write $%02X to register %i\n", m_maincpu->pc(), machine().time().as_double(), data, offset );
22332130}
22342131
22352132
22362133
2237READ8_HANDLER  ( to9_ieee_r )
2134READ8_MEMBER( thomson_state::to9_ieee_r )
22382135{
2239   logerror( "$%04x %f to9_ieee_r: unhandled read from register %i\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), offset );
2136   logerror( "$%04x %f to9_ieee_r: unhandled read from register %i\n", m_maincpu->pc(), machine().time().as_double(), offset );
22402137   return 0;
22412138}
22422139
r21425r21426
22502147
22512148
22522149
2253READ8_HANDLER ( to9_gatearray_r )
2150READ8_MEMBER( thomson_state::to9_gatearray_r )
22542151{
2255   struct thom_vsignal v = thom_get_vsignal(space.machine());
2256   struct thom_vsignal l = thom_get_lightpen_vsignal( space.machine(), TO9_LIGHTPEN_DECAL, to7_lightpen_step - 1, 0 );
2152   struct thom_vsignal v = thom_get_vsignal();
2153   struct thom_vsignal l = thom_get_lightpen_vsignal( TO9_LIGHTPEN_DECAL, m_to7_lightpen_step - 1, 0 );
22572154   int count, inil, init, lt3;
2258   count = to7_lightpen ? l.count : v.count;
2259   inil  = to7_lightpen ? l.inil  : v.inil;
2260   init  = to7_lightpen ? l.init  : v.init;
2261   lt3   = to7_lightpen ? l.lt3   : v.lt3;
2155   count = m_to7_lightpen ? l.count : v.count;
2156   inil  = m_to7_lightpen ? l.inil  : v.inil;
2157   init  = m_to7_lightpen ? l.init  : v.init;
2158   lt3   = m_to7_lightpen ? l.lt3   : v.lt3;
22622159
22632160   switch ( offset )
22642161   {
r21425r21426
22672164   case 2: return (lt3 << 7) | (inil << 6);
22682165   case 3: return (v.init << 7) | (init << 6); /* != TO7/70 */
22692166   default:
2270      logerror( "$%04x to9_gatearray_r: invalid offset %i\n", space.machine().device("maincpu")->safe_pcbase(), offset );
2167      logerror( "$%04x to9_gatearray_r: invalid offset %i\n", m_maincpu->pc(), offset );
22712168      return 0;
22722169   }
22732170}
22742171
22752172
22762173
2277WRITE8_HANDLER ( to9_gatearray_w )
2174WRITE8_MEMBER( thomson_state::to9_gatearray_w )
22782175{
22792176   if ( ! offset )
2280      to7_lightpen = data & 1;
2177      m_to7_lightpen = data & 1;
22812178}
22822179
22832180
r21425r21426
22862183
22872184
22882185
2289static UINT8 to9_palette_data[32];
2290
2291static UINT8 to9_palette_idx;
2292
2293
22942186/* style: 0 => TO9, 1 => TO8/TO9, 2 => MO6 */
2295static void to9_set_video_mode( running_machine &machine, UINT8 data, int style )
2187void thomson_state::to9_set_video_mode( UINT8 data, int style )
22962188{
22972189   switch ( data & 0x7f )
22982190   {
22992191   case 0x00:
23002192      if ( style == 2 )
2301         thom_set_video_mode( machine, THOM_VMODE_MO5 );
2193         thom_set_video_mode( THOM_VMODE_MO5 );
23022194      else if ( style == 1 )
2303         thom_set_video_mode( machine, THOM_VMODE_TO770 );
2195         thom_set_video_mode( THOM_VMODE_TO770 );
23042196      else
2305         thom_set_video_mode( machine, THOM_VMODE_TO9 );
2197         thom_set_video_mode( THOM_VMODE_TO9 );
23062198      break;
23072199
2308   case 0x21: thom_set_video_mode( machine, THOM_VMODE_BITMAP4 );     break;
2200   case 0x21: thom_set_video_mode( THOM_VMODE_BITMAP4 );     break;
23092201
2310   case 0x41: thom_set_video_mode( machine, THOM_VMODE_BITMAP4_ALT ); break;
2202   case 0x41: thom_set_video_mode( THOM_VMODE_BITMAP4_ALT ); break;
23112203
23122204   case 0x2a:
23132205      if ( style==0 )
2314         thom_set_video_mode( machine, THOM_VMODE_80_TO9 );
2206         thom_set_video_mode( THOM_VMODE_80_TO9 );
23152207      else
2316         thom_set_video_mode( machine, THOM_VMODE_80 );
2208         thom_set_video_mode( THOM_VMODE_80 );
23172209      break;
23182210
2319   case 0x7b: thom_set_video_mode( machine, THOM_VMODE_BITMAP16 );    break;
2211   case 0x7b: thom_set_video_mode( THOM_VMODE_BITMAP16 );    break;
23202212
2321   case 0x24: thom_set_video_mode( machine, THOM_VMODE_PAGE1 );       break;
2213   case 0x24: thom_set_video_mode( THOM_VMODE_PAGE1 );       break;
23222214
2323   case 0x25: thom_set_video_mode( machine, THOM_VMODE_PAGE2 );       break;
2215   case 0x25: thom_set_video_mode( THOM_VMODE_PAGE2 );       break;
23242216
2325   case 0x26: thom_set_video_mode( machine, THOM_VMODE_OVERLAY );     break;
2217   case 0x26: thom_set_video_mode( THOM_VMODE_OVERLAY );     break;
23262218
2327   case 0x3f: thom_set_video_mode( machine, THOM_VMODE_OVERLAY3 );    break;
2219   case 0x3f: thom_set_video_mode( THOM_VMODE_OVERLAY3 );    break;
23282220
23292221   default:
23302222      logerror( "to9_set_video_mode: unknown mode $%02X tr=%i phi=%i mod=%i\n", data, (data >> 5) & 3, (data >> 3) & 2, data & 7 );
r21425r21426
23332225
23342226
23352227
2336READ8_HANDLER  ( to9_vreg_r )
2228READ8_MEMBER( thomson_state::to9_vreg_r )
23372229{
23382230   switch ( offset )
23392231   {
23402232   case 0: /* palette data */
23412233   {
2342      UINT8 c =  to9_palette_data[ to9_palette_idx ];
2234      UINT8 c =  m_to9_palette_data[ m_to9_palette_idx ];
23432235      if ( !space.debugger_access() )
2344            {
2345         to9_palette_idx = ( to9_palette_idx + 1 ) & 31;
2346            }
2236      {
2237         m_to9_palette_idx = ( m_to9_palette_idx + 1 ) & 31;
2238      }
23472239      return c;
23482240   }
23492241
23502242   case 1: /* palette address */
2351      return to9_palette_idx;
2243      return m_to9_palette_idx;
23522244
23532245   case 2:
23542246   case 3:
r21425r21426
23622254
23632255
23642256
2365WRITE8_HANDLER ( to9_vreg_w )
2257WRITE8_MEMBER( thomson_state::to9_vreg_w )
23662258{
2367   LOG_VIDEO(( "$%04x %f to9_vreg_w: off=%i ($%04X) data=$%02X\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), offset, 0xe7da + offset, data ));
2259   LOG_VIDEO(( "$%04x %f to9_vreg_w: off=%i ($%04X) data=$%02X\n", m_maincpu->pc(), machine().time().as_double(), offset, 0xe7da + offset, data ));
23682260
23692261   switch ( offset )
23702262   {
23712263   case 0: /* palette data */
23722264   {
23732265      UINT16 color, idx;
2374      to9_palette_data[ to9_palette_idx ] = data;
2375      idx = to9_palette_idx / 2;
2376      color = to9_palette_data[ 2 * idx + 1 ];
2377      color = to9_palette_data[ 2 * idx ] | (color << 8);
2378      thom_set_palette( space.machine(), idx ^ 8, color & 0x1fff );
2266      m_to9_palette_data[ m_to9_palette_idx ] = data;
2267      idx = m_to9_palette_idx / 2;
2268      color = m_to9_palette_data[ 2 * idx + 1 ];
2269      color = m_to9_palette_data[ 2 * idx ] | (color << 8);
2270      thom_set_palette( idx ^ 8, color & 0x1fff );
23792271
2380      to9_palette_idx = ( to9_palette_idx + 1 ) & 31;
2272      m_to9_palette_idx = ( m_to9_palette_idx + 1 ) & 31;
23812273   }
23822274   break;
23832275
23842276   case 1: /* palette address */
2385      to9_palette_idx = data & 31;
2277      m_to9_palette_idx = data & 31;
23862278      break;
23872279
23882280   case 2: /* video mode */
2389      to9_set_video_mode( space.machine(), data, 0 );
2281      to9_set_video_mode( data, 0 );
23902282      break;
23912283
23922284   case 3: /* border color */
2393      thom_set_border_color( space.machine(), data & 15 );
2285      thom_set_border_color( data & 15 );
23942286      break;
23952287
23962288   default:
r21425r21426
24002292
24012293
24022294
2403static void to9_palette_init ( running_machine &machine )
2295void thomson_state::to9_palette_init()
24042296{
2405   to9_palette_idx = 0;
2406   memset( to9_palette_data, 0, sizeof( to9_palette_data ) );
2407   state_save_register_global( machine, to9_palette_idx );
2408   state_save_register_global_array( machine, to9_palette_data );
2297   m_to9_palette_idx = 0;
2298   memset( m_to9_palette_data, 0, sizeof( m_to9_palette_data ) );
2299   save_item(NAME(m_to9_palette_idx));
2300   state_save_register_global_array( machine(), m_to9_palette_data );
24092301}
24102302
24112303
r21425r21426
24132305/* ------------ RAM / ROM banking ------------ */
24142306
24152307
2416static UINT8 to9_soft_bank;
2417
2418
2419static void to9_update_cart_bank(running_machine &machine)
2308void thomson_state::to9_update_cart_bank()
24202309{
2421   address_space& space = machine.device("maincpu")->memory().space(AS_PROGRAM);
2310   address_space& space = m_maincpu->space(AS_PROGRAM);
24222311   int bank = 0;
2423   int slot = ( mc6846_get_output_port(machine.device("mc6846")) >> 4 ) & 3; /* bits 4-5: ROM bank */
2312   int slot = ( mc6846_get_output_port(m_mc6846) >> 4 ) & 3; /* bits 4-5: ROM bank */
24242313
24252314   switch ( slot )
24262315   {
24272316   case 0:
24282317      /* BASIC (64 KB) */
2429      bank = 4 + to9_soft_bank;
2430      if ( bank != old_cart_bank )
2431            {
2432         if ( old_cart_bank < 4)
2433                  {
2318      bank = 4 + m_to9_soft_bank;
2319      if ( bank != m_old_cart_bank )
2320      {
2321         if ( m_old_cart_bank < 4)
2322         {
24342323            space.install_read_bank( 0x0000, 0x3fff, THOM_CART_BANK );
2435                  }
2436         LOG_BANK(( "to9_update_cart_bank: CART is BASIC bank %i\n", to9_soft_bank ));
2324         }
2325         LOG_BANK(( "to9_update_cart_bank: CART is BASIC bank %i\n", m_to9_soft_bank ));
24372326      }
24382327      break;
24392328   case 1:
24402329      /* software 1 (32 KB) */
2441      bank = 8 + (to9_soft_bank & 1);
2442      if ( bank != old_cart_bank )
2443            {
2444         if ( old_cart_bank < 4)
2445                  {
2330      bank = 8 + (m_to9_soft_bank & 1);
2331      if ( bank != m_old_cart_bank )
2332      {
2333         if ( m_old_cart_bank < 4)
2334         {
24462335            space.install_read_bank( 0x0000, 0x3fff, THOM_CART_BANK );
2447                  }
2448         LOG_BANK(( "to9_update_cart_bank: CART is software 1 bank %i\n", to9_soft_bank ));
2336         }
2337         LOG_BANK(( "to9_update_cart_bank: CART is software 1 bank %i\n", m_to9_soft_bank ));
24492338      }
24502339      break;
24512340   case 2:
24522341      /* software 2 (32 KB) */
2453      bank = 10 + (to9_soft_bank & 1);
2454      if ( bank != old_cart_bank )
2455            {
2456         if ( old_cart_bank < 4)
2457                  {
2342      bank = 10 + (m_to9_soft_bank & 1);
2343      if ( bank != m_old_cart_bank )
2344      {
2345         if ( m_old_cart_bank < 4)
2346         {
24582347            space.install_read_bank( 0x0000, 0x3fff, THOM_CART_BANK );
2459                  }
2460         LOG_BANK(( "to9_update_cart_bank: CART is software 2 bank %i\n", to9_soft_bank ));
2348         }
2349         LOG_BANK(( "to9_update_cart_bank: CART is software 2 bank %i\n", m_to9_soft_bank ));
24612350      }
24622351      break;
24632352   case 3:
24642353      /* external cartridge */
2465      if ( thom_cart_nb_banks )
2354      if ( m_thom_cart_nb_banks )
24662355      {
2467         bank = thom_cart_bank % thom_cart_nb_banks;
2468         if ( bank != old_cart_bank )
2469                  {
2470            if ( old_cart_bank < 0 || old_cart_bank > 3 )
2471                        {
2356         bank = m_thom_cart_bank % m_thom_cart_nb_banks;
2357         if ( bank != m_old_cart_bank )
2358         {
2359            if ( m_old_cart_bank < 0 || m_old_cart_bank > 3 )
2360            {
24722361               space.install_read_bank( 0x0000, 0x3fff, THOM_CART_BANK );
2473               space.install_legacy_write_handler( 0x0000, 0x3fff, FUNC(to9_cartridge_w) );
2474               space.install_legacy_read_handler( 0x0000, 0x0003, FUNC(to9_cartridge_r) );
2362               space.install_write_handler( 0x0000, 0x3fff, write8_delegate(FUNC(thomson_state::to9_cartridge_w),this) );
2363               space.install_read_handler( 0x0000, 0x0003, read8_delegate(FUNC(thomson_state::to9_cartridge_r),this) );
24752364            }
2476            LOG_BANK(( "to9_update_cart_bank: CART is cartridge bank %i\n",  thom_cart_bank ));
2365            LOG_BANK(( "to9_update_cart_bank: CART is cartridge bank %i\n",  m_thom_cart_bank ));
24772366         }
2478      } else
2479         if ( old_cart_bank != 0 )
2480                  {
2367      }
2368      else
2369      {
2370         if ( m_old_cart_bank != 0 )
2371         {
24812372            space.nop_read( 0x0000, 0x3fff);
24822373            LOG_BANK(( "to9_update_cart_bank: CART is unmapped\n"));
24832374         }
2375      }
24842376      break;
24852377   }
2486   if ( bank != old_cart_bank )
2487      {
2488      machine.root_device().membank( THOM_CART_BANK )->set_entry( bank );
2489      old_cart_bank = bank;
2378   if ( bank != m_old_cart_bank )
2379   {
2380      membank( THOM_CART_BANK )->set_entry( bank );
2381      m_old_cart_bank = bank;
24902382   }
24912383}
24922384
24932385
24942386
2495static void to9_update_cart_bank_postload(running_machine *machine)
2387void thomson_state::to9_update_cart_bank_postload()
24962388{
2497   to9_update_cart_bank(*machine);
2389   to9_update_cart_bank();
24982390}
24992391
25002392
25012393
25022394/* write signal to 0000-1fff generates a bank switch */
2503WRITE8_HANDLER ( to9_cartridge_w )
2395WRITE8_MEMBER( thomson_state::to9_cartridge_w )
25042396{
2505   int slot = ( mc6846_get_output_port(space.machine().device("mc6846")) >> 4 ) & 3; /* bits 4-5: ROM bank */
2397   int slot = ( mc6846_get_output_port(m_mc6846) >> 4 ) & 3; /* bits 4-5: ROM bank */
25062398
25072399   if ( offset >= 0x2000 )
25082400      return;
25092401
25102402   if ( slot == 3 )
2511      thom_cart_bank = offset & 3;
2403      m_thom_cart_bank = offset & 3;
25122404   else
2513      to9_soft_bank = offset & 3;
2514   to9_update_cart_bank(space.machine());
2405      m_to9_soft_bank = offset & 3;
2406   to9_update_cart_bank();
25152407}
25162408
25172409
25182410
25192411/* read signal to 0000-0003 generates a bank switch */
2520READ8_HANDLER ( to9_cartridge_r )
2412READ8_MEMBER( thomson_state::to9_cartridge_r )
25212413{
2522   UINT8* pos = space.machine().root_device().memregion( "maincpu" )->base() + 0x10000;
2523   UINT8 data = pos[offset + (thom_cart_bank % thom_cart_nb_banks) * 0x4000];
2414   UINT8* pos = memregion( "maincpu" )->base() + 0x10000;
2415   UINT8 data = pos[offset + (m_thom_cart_bank % m_thom_cart_nb_banks) * 0x4000];
25242416   if ( !space.debugger_access() )
2525      {
2526      thom_cart_bank = offset & 3;
2527      to9_update_cart_bank(space.machine());
2417   {
2418      m_thom_cart_bank = offset & 3;
2419      to9_update_cart_bank();
25282420   }
25292421   return data;
25302422}
25312423
25322424
25332425
2534static void to9_update_ram_bank (running_machine &machine)
2426void thomson_state::to9_update_ram_bank()
25352427{
2536   pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS );
2537   address_space& space = machine.device("maincpu")->memory().space(AS_PROGRAM);
2538   UINT8 port = mc6846_get_output_port(machine.device("mc6846"));
2539   UINT8 portb = sys_pia->port_b_z_mask();
2428   address_space& space = m_maincpu->space(AS_PROGRAM);
2429   UINT8 port = mc6846_get_output_port(m_mc6846);
2430   UINT8 portb = m_pia_sys->port_b_z_mask();
25402431   UINT8 disk = ((port >> 2) & 1) | ((port >> 5) & 2); /* bits 6,2: RAM bank */
25412432   int bank;
25422433
r21425r21426
25612452      return;
25622453   }
25632454
2564   if ( old_ram_bank != bank )
2455   if ( m_old_ram_bank != bank )
2456   {
2457      if ( m_ram->size() == 192*1024 || bank < 6 )
25652458      {
2566      if ( machine.device<ram_device>(RAM_TAG)->size() == 192*1024 || bank < 6 )
2567            {
2568         machine.root_device().membank( THOM_RAM_BANK )->set_entry( bank );
2569            }
2459         membank( THOM_RAM_BANK )->set_entry( bank );
2460      }
25702461      else
2571            {
2462      {
25722463         space.nop_readwrite( 0xa000, 0xdfff);
2573            }
2574      old_ram_bank = bank;
2464      }
2465      m_old_ram_bank = bank;
25752466      LOG_BANK(( "to9_update_ram_bank: bank %i selected (pia=$%02X disk=%i)\n", bank, portb & 0xf8, disk ));
25762467   }
25772468}
25782469
25792470
25802471
2581static void to9_update_ram_bank_postload(running_machine *machine)
2472void thomson_state::to9_update_ram_bank_postload()
25822473{
2583   to9_update_ram_bank(*machine);
2474   to9_update_ram_bank();
25842475}
25852476
25862477
r21425r21426
26102501
26112502
26122503
2613static UINT8  to9_kbd_parity;  /* 0=even, 1=odd, 2=no parity */
2614static UINT8  to9_kbd_intr;    /* interrupt mode */
2615static UINT8  to9_kbd_in;      /* data from keyboard */
2616static UINT8  to9_kbd_status;  /* status */
2617static UINT8  to9_kbd_overrun; /* character lost */
2618
2619static UINT8  to9_kbd_periph;     /* peripherial mode */
2620static UINT8  to9_kbd_byte_count; /* byte-count in peripherial mode */
2621static UINT16 to9_mouse_x, to9_mouse_y;
2622
2623static UINT8  to9_kbd_last_key;  /* for key repetition */
2624static UINT16 to9_kbd_key_count;
2625
2626static UINT8  to9_kbd_caps;  /* caps-lock */
2627static UINT8  to9_kbd_pad;   /* keypad outputs special codes */
2628
2629static emu_timer* to9_kbd_timer;
2630
2631
2632
26332504/* quick keyboard scan */
2634static int to9_kbd_ktest ( running_machine &machine )
2505int thomson_state::to9_kbd_ktest()
26352506{
26362507   int line, bit;
26372508   UINT8 port;
r21425r21426
26422513
26432514   for ( line = 0; line < 10; line++ )
26442515   {
2645      port = machine.root_device().ioport(keynames[line])->read();
2516      port = ioport(keynames[line])->read();
26462517
26472518      if ( line == 7 || line == 9 )
26482519         port |= 1; /* shift & control */
r21425r21426
26582529
26592530
26602531
2661static void to9_kbd_update_irq ( running_machine &machine )
2532void thomson_state::to9_kbd_update_irq()
26622533{
2663   if ( (to9_kbd_intr & 4) && (to9_kbd_status & ACIA_6850_RDRF) )
2664      to9_kbd_status |= ACIA_6850_irq; /* byte received interrupt */
2534   if ( (m_to9_kbd_intr & 4) && (m_to9_kbd_status & ACIA_6850_RDRF) )
2535      m_to9_kbd_status |= ACIA_6850_irq; /* byte received interrupt */
26652536
2666   if ( (to9_kbd_intr & 4) && (to9_kbd_status & ACIA_6850_OVRN) )
2667      to9_kbd_status |= ACIA_6850_irq; /* overrun interrupt */
2537   if ( (m_to9_kbd_intr & 4) && (m_to9_kbd_status & ACIA_6850_OVRN) )
2538      m_to9_kbd_status |= ACIA_6850_irq; /* overrun interrupt */
26682539
2669   if ( (to9_kbd_intr & 3) == 1 && (to9_kbd_status & ACIA_6850_TDRE) )
2670      to9_kbd_status |= ACIA_6850_irq; /* ready to transmit interrupt */
2540   if ( (m_to9_kbd_intr & 3) == 1 && (m_to9_kbd_status & ACIA_6850_TDRE) )
2541      m_to9_kbd_status |= ACIA_6850_irq; /* ready to transmit interrupt */
26712542
2672   thom_irq_3( machine, to9_kbd_status & ACIA_6850_irq );
2543   thom_irq_3( m_to9_kbd_status & ACIA_6850_irq );
26732544}
26742545
26752546
26762547
2677READ8_HANDLER ( to9_kbd_r )
2548READ8_MEMBER( thomson_state::to9_kbd_r )
26782549{
26792550   /* ACIA 6850 registers */
26802551
r21425r21426
26912562      /* bit 7:     interrupt */
26922563
26932564      LOG_KBD(( "$%04x %f to9_kbd_r: status $%02X (rdrf=%i, tdre=%i, ovrn=%i, pe=%i, irq=%i)\n",
2694            space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), to9_kbd_status,
2695            (to9_kbd_status & ACIA_6850_RDRF) ? 1 : 0,
2696            (to9_kbd_status & ACIA_6850_TDRE) ? 1 : 0,
2697            (to9_kbd_status & ACIA_6850_OVRN) ? 1 : 0,
2698            (to9_kbd_status & ACIA_6850_PE) ? 1 : 0,
2699            (to9_kbd_status & ACIA_6850_irq) ? 1 : 0 ));
2700      return to9_kbd_status;
2565            m_maincpu->pc(), machine().time().as_double(), m_to9_kbd_status,
2566            (m_to9_kbd_status & ACIA_6850_RDRF) ? 1 : 0,
2567            (m_to9_kbd_status & ACIA_6850_TDRE) ? 1 : 0,
2568            (m_to9_kbd_status & ACIA_6850_OVRN) ? 1 : 0,
2569            (m_to9_kbd_status & ACIA_6850_PE) ? 1 : 0,
2570            (m_to9_kbd_status & ACIA_6850_irq) ? 1 : 0 ));
2571      return m_to9_kbd_status;
27012572
27022573   case 1: /* get input data */
27032574      if ( !space.debugger_access() )
27042575      {
2705         to9_kbd_status &= ~(ACIA_6850_irq | ACIA_6850_PE);
2706         if ( to9_kbd_overrun )
2707            to9_kbd_status |= ACIA_6850_OVRN;
2576         m_to9_kbd_status &= ~(ACIA_6850_irq | ACIA_6850_PE);
2577         if ( m_to9_kbd_overrun )
2578            m_to9_kbd_status |= ACIA_6850_OVRN;
27082579         else
2709            to9_kbd_status &= ~(ACIA_6850_OVRN | ACIA_6850_RDRF);
2710         to9_kbd_overrun = 0;
2711         LOG_KBD(( "$%04x %f to9_kbd_r: read data $%02X\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), to9_kbd_in ));
2712         to9_kbd_update_irq(space.machine());
2580            m_to9_kbd_status &= ~(ACIA_6850_OVRN | ACIA_6850_RDRF);
2581         m_to9_kbd_overrun = 0;
2582         LOG_KBD(( "$%04x %f to9_kbd_r: read data $%02X\n", m_maincpu->pc(), machine().time().as_double(), m_to9_kbd_in ));
2583         to9_kbd_update_irq();
27132584      }
2714      return to9_kbd_in;
2585      return m_to9_kbd_in;
27152586
27162587   default:
2717      logerror( "$%04x to9_kbd_r: invalid offset %i\n", space.machine().device("maincpu")->safe_pcbase(),  offset );
2588      logerror( "$%04x to9_kbd_r: invalid offset %i\n", m_maincpu->pc(),  offset );
27182589      return 0;
27192590   }
27202591}
27212592
27222593
27232594
2724WRITE8_HANDLER ( to9_kbd_w )
2595WRITE8_MEMBER( thomson_state::to9_kbd_w )
27252596{
27262597   /* ACIA 6850 registers */
27272598
r21425r21426
27322603      if ( (data & 3) == 3 )
27332604      {
27342605         /* reset */
2735         to9_kbd_overrun = 0;
2736         to9_kbd_status = ACIA_6850_TDRE;
2737         to9_kbd_intr = 0;
2738         LOG_KBD(( "$%04x %f to9_kbd_w: reset (data=$%02X)\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), data ));
2606         m_to9_kbd_overrun = 0;
2607         m_to9_kbd_status = ACIA_6850_TDRE;
2608         m_to9_kbd_intr = 0;
2609         LOG_KBD(( "$%04x %f to9_kbd_w: reset (data=$%02X)\n", m_maincpu->pc(), machine().time().as_double(), data ));
27392610      }
27402611      else
27412612      {
27422613         /* bits 2-4: parity */
27432614         if ( (data & 0x18) == 0x10 )
2744            to9_kbd_parity = 2;
2615            m_to9_kbd_parity = 2;
27452616         else
2746            to9_kbd_parity = (data >> 2) & 1;
2617            m_to9_kbd_parity = (data >> 2) & 1;
27472618         /* bits 5-6: interrupt on transmit */
27482619         /* bit 7:    interrupt on receive */
2749         to9_kbd_intr = data >> 5;
2620         m_to9_kbd_intr = data >> 5;
27502621
27512622         LOG_KBD(( "$%04x %f to9_kbd_w: set control to $%02X (parity=%i, intr in=%i out=%i)\n",
2752               space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(),
2753               data, to9_kbd_parity, to9_kbd_intr >> 2,
2754               (to9_kbd_intr & 3) ? 1 : 0 ));
2623               m_maincpu->pc(), machine().time().as_double(),
2624               data, m_to9_kbd_parity, m_to9_kbd_intr >> 2,
2625               (m_to9_kbd_intr & 3) ? 1 : 0 ));
27552626      }
2756      to9_kbd_update_irq(space.machine());
2627      to9_kbd_update_irq();
27572628      break;
27582629
27592630   case 1: /* output data */
2760      to9_kbd_status &= ~(ACIA_6850_irq | ACIA_6850_TDRE);
2761      to9_kbd_update_irq(space.machine());
2631      m_to9_kbd_status &= ~(ACIA_6850_irq | ACIA_6850_TDRE);
2632      to9_kbd_update_irq();
27622633      /* TODO: 1 ms delay here ? */
2763      to9_kbd_status |= ACIA_6850_TDRE; /* data transmit ready again */
2764      to9_kbd_update_irq(space.machine());
2634      m_to9_kbd_status |= ACIA_6850_TDRE; /* data transmit ready again */
2635      to9_kbd_update_irq();
27652636
27662637      switch ( data )
27672638      {
27682639      case 0xF8:
27692640         /* reset */
2770         to9_kbd_caps = 1;
2771         to9_kbd_periph = 0;
2772         to9_kbd_pad = 0;
2641         m_to9_kbd_caps = 1;
2642         m_to9_kbd_periph = 0;
2643         m_to9_kbd_pad = 0;
27732644         break;
27742645
2775      case 0xF9: to9_kbd_caps = 1;   break;
2776      case 0xFA: to9_kbd_caps = 0;   break;
2777      case 0xFB: to9_kbd_pad = 1;    break;
2778      case 0xFC: to9_kbd_pad = 0;    break;
2779      case 0xFD: to9_kbd_periph = 1; break;
2780      case 0xFE: to9_kbd_periph = 0; break;
2646      case 0xF9: m_to9_kbd_caps = 1;   break;
2647      case 0xFA: m_to9_kbd_caps = 0;   break;
2648      case 0xFB: m_to9_kbd_pad = 1;    break;
2649      case 0xFC: m_to9_kbd_pad = 0;    break;
2650      case 0xFD: m_to9_kbd_periph = 1; break;
2651      case 0xFE: m_to9_kbd_periph = 0; break;
27812652
27822653      default:
2783         logerror( "$%04x %f to9_kbd_w: unknown kbd command %02X\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), data );
2654         logerror( "$%04x %f to9_kbd_w: unknown kbd command %02X\n", m_maincpu->pc(), machine().time().as_double(), data );
27842655      }
27852656
2786      thom_set_caps_led( space.machine(), !to9_kbd_caps );
2657      thom_set_caps_led( !m_to9_kbd_caps );
27872658
27882659      LOG(( "$%04x %f to9_kbd_w: kbd command %02X (caps=%i, pad=%i, periph=%i)\n",
2789            space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), data,
2790            to9_kbd_caps, to9_kbd_pad, to9_kbd_periph ));
2660            m_maincpu->pc(), machine().time().as_double(), data,
2661            m_to9_kbd_caps, m_to9_kbd_pad, m_to9_kbd_periph ));
27912662
27922663      break;
27932664
27942665   default:
2795      logerror( "$%04x to9_kbd_w: invalid offset %i (data=$%02X) \n", space.machine().device("maincpu")->safe_pcbase(), offset, data );
2666      logerror( "$%04x to9_kbd_w: invalid offset %i (data=$%02X) \n", m_maincpu->pc(), offset, data );
27962667   }
27972668}
27982669
r21425r21426
28022673   note: parity is not used as a checksum but to actually transmit a 9-th bit
28032674   of information!
28042675*/
2805static void to9_kbd_send ( running_machine &machine, UINT8 data, int parity )
2676void thomson_state::to9_kbd_send( UINT8 data, int parity )
28062677{
2807   if ( to9_kbd_status & ACIA_6850_RDRF )
2678   if ( m_to9_kbd_status & ACIA_6850_RDRF )
28082679   {
28092680      /* overrun will be set when the current valid byte is read */
2810      to9_kbd_overrun = 1;
2811      LOG_KBD(( "%f to9_kbd_send: overrun => drop data=$%02X, parity=%i\n", machine.time().as_double(), data, parity ));
2681      m_to9_kbd_overrun = 1;
2682      LOG_KBD(( "%f to9_kbd_send: overrun => drop data=$%02X, parity=%i\n", machine().time().as_double(), data, parity ));
28122683   }
28132684   else
28142685   {
28152686      /* valid byte */
2816      to9_kbd_in = data;
2817      to9_kbd_status |= ACIA_6850_RDRF; /* raise data received flag */
2818      if ( to9_kbd_parity == 2 || to9_kbd_parity == parity )
2819         to9_kbd_status &= ~ACIA_6850_PE; /* parity OK */
2687      m_to9_kbd_in = data;
2688      m_to9_kbd_status |= ACIA_6850_RDRF; /* raise data received flag */
2689      if ( m_to9_kbd_parity == 2 || m_to9_kbd_parity == parity )
2690         m_to9_kbd_status &= ~ACIA_6850_PE; /* parity OK */
28202691      else
2821         to9_kbd_status |= ACIA_6850_PE;  /* parity error */
2822      LOG_KBD(( "%f to9_kbd_send: data=$%02X, parity=%i, status=$%02X\n", machine.time().as_double(), data, parity, to9_kbd_status ));
2692         m_to9_kbd_status |= ACIA_6850_PE;  /* parity error */
2693      LOG_KBD(( "%f to9_kbd_send: data=$%02X, parity=%i, status=$%02X\n", machine().time().as_double(), data, parity, m_to9_kbd_status ));
28232694   }
2824   to9_kbd_update_irq(machine);
2695   to9_kbd_update_irq();
28252696}
28262697
28272698
r21425r21426
28662737
28672738
28682739/* returns the ASCII code for the key, or 0 for no key */
2869static int to9_kbd_get_key( running_machine &machine )
2740int thomson_state::to9_kbd_get_key()
28702741{
2871   int control = ! (machine.root_device().ioport("keyboard_7")->read() & 1);
2872   int shift   = ! (machine.root_device().ioport("keyboard_9")->read() & 1);
2742   int control = ! (ioport("keyboard_7")->read() & 1);
2743   int shift   = ! (ioport("keyboard_9")->read() & 1);
28732744   int key = -1, line, bit;
28742745   UINT8 port;
28752746   static const char *const keynames[] = {
r21425r21426
28792750
28802751   for ( line = 0; line < 10; line++ )
28812752   {
2882      port = machine.root_device().ioport(keynames[line])->read();
2753      port = ioport(keynames[line])->read();
28832754
28842755      if ( line == 7 || line == 9 )
28852756         port |= 1; /* shift & control */
r21425r21426
28962767
28972768   if ( key == -1 )
28982769   {
2899      to9_kbd_last_key = 0xff;
2900      to9_kbd_key_count = 0;
2770      m_to9_kbd_last_key = 0xff;
2771      m_to9_kbd_key_count = 0;
29012772      return 0;
29022773   }
29032774   else if ( key == 64 )
29042775   {
29052776      /* caps lock */
2906      if ( to9_kbd_last_key == key )
2777      if ( m_to9_kbd_last_key == key )
29072778         return 0; /* no repeat */
29082779
2909      to9_kbd_last_key = key;
2910      to9_kbd_caps = !to9_kbd_caps;
2911      thom_set_caps_led( machine, !to9_kbd_caps );
2780      m_to9_kbd_last_key = key;
2781      m_to9_kbd_caps = !m_to9_kbd_caps;
2782      thom_set_caps_led( !m_to9_kbd_caps );
29122783      return 0;
29132784   }
29142785   else
r21425r21426
29182789      if ( ! asc ) return 0;
29192790
29202791      /* keypad */
2921      if ( ! to9_kbd_pad ) {
2792      if ( ! m_to9_kbd_pad ) {
29222793         if ( asc >= 154 && asc <= 163 )
29232794            asc += '0' - 154;
29242795         else if ( asc == 164 )
r21425r21426
29282799      }
29292800
29302801      /* shifted letter */
2931      if ( asc >= 'A' && asc <= 'Z' && ( ! to9_kbd_caps ) && ( ! shift ) )
2802      if ( asc >= 'A' && asc <= 'Z' && ( ! m_to9_kbd_caps ) && ( ! shift ) )
29322803         asc += 'a' - 'A';
29332804
29342805      /* control */
29352806      if ( control )
29362807         asc &= ~0x40;
29372808
2938      if ( key == to9_kbd_last_key )
2809      if ( key == m_to9_kbd_last_key )
29392810      {
29402811         /* repeat */
2941         to9_kbd_key_count++;
2942         if ( to9_kbd_key_count < TO9_KBD_REPEAT_DELAY || (to9_kbd_key_count - TO9_KBD_REPEAT_DELAY) % TO9_KBD_REPEAT_PERIOD )
2812         m_to9_kbd_key_count++;
2813         if ( m_to9_kbd_key_count < TO9_KBD_REPEAT_DELAY || (m_to9_kbd_key_count - TO9_KBD_REPEAT_DELAY) % TO9_KBD_REPEAT_PERIOD )
29432814            return 0;
29442815         LOG_KBD(( "to9_kbd_get_key: repeat key $%02X '%c'\n", asc, asc ));
29452816         return asc;
29462817      }
2947      else {
2948         to9_kbd_last_key = key;
2949         to9_kbd_key_count = 0;
2818      else
2819      {
2820         m_to9_kbd_last_key = key;
2821         m_to9_kbd_key_count = 0;
29502822         LOG_KBD(( "to9_kbd_get_key: key down $%02X '%c'\n", asc, asc ));
29512823         return asc;
29522824      }
r21425r21426
29552827
29562828
29572829
2958static TIMER_CALLBACK(to9_kbd_timer_cb)
2830TIMER_CALLBACK_MEMBER(thomson_state::to9_kbd_timer_cb)
29592831{
2960   if ( to9_kbd_periph )
2832   if ( m_to9_kbd_periph )
29612833   {
29622834      /* peripherial mode: every 10 ms we send 4 bytes */
29632835
2964      switch ( to9_kbd_byte_count )
2836      switch ( m_to9_kbd_byte_count )
29652837      {
29662838      case 0: /* key */
2967         to9_kbd_send( machine, to9_kbd_get_key(machine), 0 );
2839         to9_kbd_send( to9_kbd_get_key(), 0 );
29682840         break;
29692841
29702842      case 1: /* x axis */
29712843      {
2972         int newx = machine.root_device().ioport("mouse_x")->read();
2973         UINT8 data = ( (newx - to9_mouse_x) & 0xf ) - 8;
2974         to9_kbd_send( machine, data, 1 );
2975         to9_mouse_x = newx;
2844         int newx = ioport("mouse_x")->read();
2845         UINT8 data = ( (newx - m_to9_mouse_x) & 0xf ) - 8;
2846         to9_kbd_send( data, 1 );
2847         m_to9_mouse_x = newx;
29762848         break;
29772849      }
29782850
29792851      case 2: /* y axis */
29802852      {
2981         int newy = machine.root_device().ioport("mouse_y")->read();
2982         UINT8 data = ( (newy - to9_mouse_y) & 0xf ) - 8;
2983         to9_kbd_send( machine, data, 1 );
2984         to9_mouse_y = newy;
2853         int newy = ioport("mouse_y")->read();
2854         UINT8 data = ( (newy - m_to9_mouse_y) & 0xf ) - 8;
2855         to9_kbd_send( data, 1 );
2856         m_to9_mouse_y = newy;
29852857         break;
29862858      }
29872859
29882860      case 3: /* axis overflow & buttons */
29892861      {
2990         int b = machine.root_device().ioport("mouse_button")->read();
2862         int b = ioport("mouse_button")->read();
29912863         UINT8 data = 0;
29922864         if ( b & 1 ) data |= 1;
29932865         if ( b & 2 ) data |= 4;
2994         to9_kbd_send( machine, data, 1 );
2866         to9_kbd_send( data, 1 );
29952867         break;
29962868      }
29972869
29982870      }
29992871
3000      to9_kbd_byte_count = ( to9_kbd_byte_count + 1 ) & 3;
3001      to9_kbd_timer->adjust(to9_kbd_byte_count ? TO9_KBD_BYTE_SPACE : TO9_KBD_END_SPACE);
2872      m_to9_kbd_byte_count = ( m_to9_kbd_byte_count + 1 ) & 3;
2873      m_to9_kbd_timer->adjust(m_to9_kbd_byte_count ? TO9_KBD_BYTE_SPACE : TO9_KBD_END_SPACE);
30022874   }
30032875   else
30042876   {
3005      int key = to9_kbd_get_key(machine);
2877      int key = to9_kbd_get_key();
30062878      /* keyboard mode: send a byte only if a key is down */
30072879      if ( key )
3008         to9_kbd_send( machine, key, 0 );
3009      to9_kbd_timer->adjust(TO9_KBD_POLL_PERIOD);
2880         to9_kbd_send( key, 0 );
2881      m_to9_kbd_timer->adjust(TO9_KBD_POLL_PERIOD);
30102882   }
30112883}
30122884
30132885
30142886
3015static void to9_kbd_reset ( running_machine &machine )
2887void thomson_state::to9_kbd_reset()
30162888{
30172889   LOG(( "to9_kbd_reset called\n" ));
3018   to9_kbd_overrun = 0;  /* no byte lost */
3019   to9_kbd_status = ACIA_6850_TDRE;  /* clear to transmit */
3020   to9_kbd_intr = 0;     /* interrupt disabled */
3021   to9_kbd_caps = 1;
3022   to9_kbd_periph = 0;
3023   to9_kbd_pad = 0;
3024   to9_kbd_byte_count = 0;
3025   thom_set_caps_led( machine, !to9_kbd_caps );
3026   to9_kbd_key_count = 0;
3027   to9_kbd_last_key = 0xff;
3028   to9_kbd_update_irq(machine);
3029   to9_kbd_timer->adjust(TO9_KBD_POLL_PERIOD);
2890   m_to9_kbd_overrun = 0;  /* no byte lost */
2891   m_to9_kbd_status = ACIA_6850_TDRE;  /* clear to transmit */
2892   m_to9_kbd_intr = 0;     /* interrupt disabled */
2893   m_to9_kbd_caps = 1;
2894   m_to9_kbd_periph = 0;
2895   m_to9_kbd_pad = 0;
2896   m_to9_kbd_byte_count = 0;
2897   thom_set_caps_led( !m_to9_kbd_caps );
2898   m_to9_kbd_key_count = 0;
2899   m_to9_kbd_last_key = 0xff;
2900   to9_kbd_update_irq();
2901   m_to9_kbd_timer->adjust(TO9_KBD_POLL_PERIOD);
30302902}
30312903
30322904
30332905
3034static void to9_kbd_init ( running_machine &machine )
2906void thomson_state::to9_kbd_init()
30352907{
30362908   LOG(( "to9_kbd_init called\n" ));
3037   to9_kbd_timer = machine.scheduler().timer_alloc(FUNC(to9_kbd_timer_cb));
3038   state_save_register_global( machine, to9_kbd_parity );
3039   state_save_register_global( machine, to9_kbd_intr );
3040   state_save_register_global( machine, to9_kbd_in );
3041   state_save_register_global( machine, to9_kbd_status );
3042   state_save_register_global( machine, to9_kbd_overrun );
3043   state_save_register_global( machine, to9_kbd_last_key );
3044   state_save_register_global( machine, to9_kbd_key_count );
3045   state_save_register_global( machine, to9_kbd_caps );
3046   state_save_register_global( machine, to9_kbd_periph );
3047   state_save_register_global( machine, to9_kbd_pad );
3048   state_save_register_global( machine, to9_kbd_byte_count );
3049   state_save_register_global( machine, to9_mouse_x );
3050   state_save_register_global( machine, to9_mouse_y );
2909   m_to9_kbd_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::to9_kbd_timer_cb),this));
2910   save_item(NAME(m_to9_kbd_parity));
2911   save_item(NAME(m_to9_kbd_intr));
2912   save_item(NAME(m_to9_kbd_in));
2913   save_item(NAME(m_to9_kbd_status));
2914   save_item(NAME(m_to9_kbd_overrun));
2915   save_item(NAME(m_to9_kbd_last_key));
2916   save_item(NAME(m_to9_kbd_key_count));
2917   save_item(NAME(m_to9_kbd_caps));
2918   save_item(NAME(m_to9_kbd_periph));
2919   save_item(NAME(m_to9_kbd_pad));
2920   save_item(NAME(m_to9_kbd_byte_count));
2921   save_item(NAME(m_to9_mouse_x));
2922   save_item(NAME(m_to9_mouse_y));
30512923}
30522924
30532925
r21425r21426
30562928/* afaik, P2-P7 are not connected, so, the warning about undefined 0xf0 can be safely ignored */
30572929
30582930
3059static READ8_DEVICE_HANDLER ( to9_sys_porta_in )
2931READ8_MEMBER( thomson_state::to9_sys_porta_in )
30602932{
3061   UINT8 ktest = to9_kbd_ktest(space.machine());
2933   UINT8 ktest = to9_kbd_ktest();
30622934
30632935   LOG_KBD(( "to9_sys_porta_in: ktest=%i\n", ktest ));
30642936
r21425r21426
30672939
30682940
30692941
3070static WRITE8_DEVICE_HANDLER ( to9_sys_porta_out )
2942WRITE8_MEMBER( thomson_state::to9_sys_porta_out )
30712943{
3072   centronics_device *printer = space.machine().device<centronics_device>("centronics");
3073   printer->write(space.machine().driver_data()->generic_space(), 0, data & 0xfe);
2944   m_centronics->write(space, 0, data & 0xfe);
30742945}
30752946
30762947
30772948
3078static WRITE8_DEVICE_HANDLER ( to9_sys_portb_out )
2949WRITE8_MEMBER( thomson_state::to9_sys_portb_out )
30792950{
3080   centronics_device *printer = space.machine().device<centronics_device>("centronics");
2951   m_centronics->d0_w(BIT(data, 0));
2952   m_centronics->strobe_w(BIT(data, 1));
30812953
3082   printer->d0_w(BIT(data, 0));
3083   printer->strobe_w(BIT(data, 1));
2954   to9_update_ram_bank();
30842955
3085   to9_update_ram_bank(space.machine());
3086
30872956   if ( data & 4 ) /* bit 2: video overlay (TODO) */
30882957      LOG(( "to9_sys_portb_out: video overlay not handled\n" ));
30892958}
r21425r21426
30922961
30932962const pia6821_interface to9_pia6821_sys =
30942963{
3095   DEVCB_HANDLER(to9_sys_porta_in),
2964   DEVCB_DRIVER_MEMBER(thomson_state, to9_sys_porta_in),
30962965   DEVCB_NULL,
30972966   DEVCB_NULL,
30982967   DEVCB_NULL,
30992968   DEVCB_NULL,
31002969   DEVCB_NULL,
3101   DEVCB_HANDLER(to9_sys_porta_out),
3102   DEVCB_HANDLER(to9_sys_portb_out),
3103   DEVCB_HANDLER(to7_set_cassette_motor),
2970   DEVCB_DRIVER_MEMBER(thomson_state, to9_sys_porta_out),
2971   DEVCB_DRIVER_MEMBER(thomson_state, to9_sys_portb_out),
2972   DEVCB_DRIVER_MEMBER(thomson_state, to7_set_cassette_motor),
31042973   DEVCB_NULL,
31052974   DEVCB_NULL,
3106   DEVCB_LINE(thom_firq_1)
2975   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1)
31072976};
31082977
31092978
r21425r21426
31142983
31152984
31162985
3117static WRITE8_DEVICE_HANDLER ( to9_timer_port_out )
2986WRITE8_MEMBER( thomson_state::to9_timer_port_out )
31182987{
3119   thom_set_mode_point( space.machine(), data & 1 ); /* bit 0: video bank */
3120   to9_update_ram_bank(space.machine());
3121   to9_update_cart_bank(space.machine());
2988   thom_set_mode_point( data & 1 ); /* bit 0: video bank */
2989   to9_update_ram_bank();
2990   to9_update_cart_bank();
31222991}
31232992
31242993
31252994
31262995const mc6846_interface to9_timer =
31272996{
3128   DEVCB_HANDLER(to9_timer_port_out), DEVCB_NULL, DEVCB_HANDLER(to7_timer_cp2_out),
3129   DEVCB_HANDLER(to7_timer_port_in), DEVCB_HANDLER(to7_timer_tco_out),
3130   DEVCB_LINE(thom_dev_irq_0)
2997   DEVCB_DRIVER_MEMBER(thomson_state, to9_timer_port_out),
2998   DEVCB_NULL,
2999   DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_cp2_out),
3000   DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_port_in),
3001   DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_tco_out),
3002   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_dev_irq_0)
31313003};
31323004
31333005
r21425r21426
31363008
31373009
31383010
3139MACHINE_RESET ( to9 )
3011MACHINE_RESET_MEMBER( thomson_state, to9 )
31403012{
3141   pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS );
3142
31433013   LOG (( "to9: machine reset called\n" ));
31443014
31453015   /* subsystems */
3146   thom_irq_reset(machine);
3147   sys_pia->set_port_a_z_mask( 0xfe );
3148   to7_game_reset(machine);
3149   to9_floppy_reset(machine);
3150   to9_kbd_reset(machine);
3151   to7_modem_reset(machine);
3152   to7_midi_reset(machine);
3016   thom_irq_reset();
3017   m_pia_sys->set_port_a_z_mask( 0xfe );
3018   to7_game_reset();
3019   to9_floppy_reset();
3020   to9_kbd_reset();
3021   to7_modem_reset();
3022   to7_midi_reset();
31533023
31543024   /* video */
3155   thom_set_video_mode( machine, THOM_VMODE_TO9 );
3156   thom_set_lightpen_callback( machine, 3, to7_lightpen_cb );
3157   thom_set_border_color( machine, 8 );
3158   thom_set_mode_point( machine, 0 );
3159   sys_pia->cb1_w( 0 );
3025   thom_set_video_mode( THOM_VMODE_TO9 );
3026   m_thom_lightpen_cb = &thomson_state::to7_lightpen_cb;
3027   thom_set_lightpen_callback( 3 );
3028   thom_set_border_color( 8 );
3029   thom_set_mode_point( 0 );
3030   m_pia_sys->cb1_w( 0 );
31603031
31613032   /* memory */
3162   old_ram_bank = -1;
3163   old_cart_bank = -1;
3164   to9_soft_bank = 0;
3165   to9_update_cart_bank(machine);
3166   to9_update_ram_bank(machine);
3033   m_old_ram_bank = -1;
3034   m_old_cart_bank = -1;
3035   m_to9_soft_bank = 0;
3036   to9_update_cart_bank();
3037   to9_update_ram_bank();
31673038   /* thom_cart_bank not reset */
31683039
31693040   /* lightpen */
3170   to7_lightpen = 0;
3041   m_to7_lightpen = 0;
31713042}
31723043
31733044
31743045
3175MACHINE_START ( to9 )
3046MACHINE_START_MEMBER( thomson_state, to9 )
31763047{
3177   UINT8* mem = machine.root_device().memregion("maincpu")->base();
3178   UINT8* ram = machine.device<ram_device>(RAM_TAG)->pointer();
3048   UINT8* mem = memregion("maincpu")->base();
3049   UINT8* ram = m_ram->pointer();
31793050
31803051   LOG (( "to9: machine start called\n" ));
31813052
31823053   /* subsystems */
3183   thom_irq_init(machine);
3184   to7_game_init(machine);
3185   to9_floppy_init( machine, mem + 0xe000, mem + 0x40000 );
3186   to9_kbd_init(machine);
3187   to9_palette_init(machine);
3188   to7_modem_init(machine);
3189   to7_midi_init(machine);
3054   thom_irq_init();
3055   to7_game_init();
3056   to9_floppy_init( mem + 0xe000, mem + 0x40000 );
3057   to9_kbd_init();
3058   to9_palette_init();
3059   to7_modem_init();
3060   to7_midi_init();
31903061
31913062   /* memory */
3192   thom_vram = ram;
3193   thom_cart_bank = 0;
3194   machine.root_device().membank( THOM_VRAM_BANK )->configure_entries( 0,  2, thom_vram, 0x2000 );
3195   machine.root_device().membank( THOM_CART_BANK )->configure_entries( 0, 12, mem + 0x10000, 0x4000 );
3196   machine.root_device().membank( THOM_BASE_BANK )->configure_entry( 0,  ram + 0x4000);
3197   machine.root_device().membank( THOM_RAM_BANK )->configure_entries( 0, 10, ram + 0x8000, 0x4000 );
3198   machine.root_device().membank( THOM_VRAM_BANK )->set_entry( 0 );
3199   machine.root_device().membank( THOM_CART_BANK )->set_entry( 0 );
3200   machine.root_device().membank( THOM_BASE_BANK )->set_entry( 0 );
3201   machine.root_device().membank( THOM_RAM_BANK )->set_entry( 0 );
3063   m_thom_vram = ram;
3064   m_thom_cart_bank = 0;
3065   membank( THOM_VRAM_BANK )->configure_entries( 0,  2, m_thom_vram, 0x2000 );
3066   membank( THOM_CART_BANK )->configure_entries( 0, 12, mem + 0x10000, 0x4000 );
3067   membank( THOM_BASE_BANK )->configure_entry( 0,  ram + 0x4000);
3068   membank( THOM_RAM_BANK )->configure_entries( 0, 10, ram + 0x8000, 0x4000 );
3069   membank( THOM_VRAM_BANK )->set_entry( 0 );
3070   membank( THOM_CART_BANK )->set_entry( 0 );
3071   membank( THOM_BASE_BANK )->set_entry( 0 );
3072   membank( THOM_RAM_BANK )->set_entry( 0 );
32023073
32033074   /* save-state */
3204   state_save_register_global( machine, thom_cart_nb_banks );
3205   state_save_register_global( machine, thom_cart_bank );
3206   state_save_register_global( machine, to7_lightpen );
3207   state_save_register_global( machine, to7_lightpen_step );
3208   state_save_register_global( machine, to9_soft_bank );
3209   state_save_register_global_pointer( machine, (mem + 0x10000), 0x10000 );
3210   machine.save().register_postload(save_prepost_delegate(FUNC(to9_update_ram_bank_postload), &machine));
3211   machine.save().register_postload(save_prepost_delegate(FUNC(to9_update_cart_bank_postload), &machine));
3075   save_item(NAME(m_thom_cart_nb_banks));
3076   save_item(NAME(m_thom_cart_bank));
3077   save_item(NAME(m_to7_lightpen));
3078   save_item(NAME(m_to7_lightpen_step));
3079   save_item(NAME(m_to9_soft_bank));
3080   state_save_register_global_pointer( machine(), (mem + 0x10000), 0x10000 );
3081   machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to9_update_ram_bank_postload), this));
3082   machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to9_update_cart_bank_postload), this));
32123083}
32133084
32143085
r21425r21426
32163087/***************************** TO8 *************************/
32173088
32183089
3219
3220UINT8 to8_data_vpage;
3221UINT8 to8_cart_vpage;
3222
3223
3224
32253090/* ------------ keyboard (6804) ------------ */
32263091
32273092/* The 6804 chip scans the keyboard and sends keycodes to the 6809.
r21425r21426
32553120
32563121
32573122
3258/* state */
3259static UINT8  to8_kbd_ack;       /* 1 = cpu inits / accepts transfers */
3260static UINT16 to8_kbd_data;      /* data to transmit */
3261static UINT16 to8_kbd_step;      /* transmission automaton state */
3262static UINT8  to8_kbd_last_key;  /* last key (for repetition) */
3263static UINT32 to8_kbd_key_count; /* keypress time (for repetition)  */
3264static UINT8  to8_kbd_caps;      /* caps lock */
3265
3266static emu_timer* to8_kbd_timer;   /* bit-send */
3267static emu_timer* to8_kbd_signal;  /* signal from CPU */
3268
3269
3270
32713123/* quick keyboard scan */
3272static int to8_kbd_ktest ( running_machine &machine )
3124int thomson_state::to8_kbd_ktest()
32733125{
32743126   int line, bit;
32753127   UINT8 port;
r21425r21426
32783130      "keyboard_5", "keyboard_6", "keyboard_7", "keyboard_8", "keyboard_9"
32793131   };
32803132
3281   if ( machine.root_device().ioport("config")->read() & 2 )
3133   if ( ioport("config")->read() & 2 )
32823134      return 0; /* disabled */
32833135
32843136   for ( line = 0; line < 10; line++ )
32853137   {
3286      port = machine.root_device().ioport(keynames[line])->read();
3138      port = ioport(keynames[line])->read();
32873139
32883140      if ( line == 7 || line == 9 )
32893141         port |= 1; /* shift & control */
r21425r21426
33013153
33023154
33033155/* keyboard scan & return keycode (or -1) */
3304static int to8_kbd_get_key( running_machine &machine )
3156int thomson_state::to8_kbd_get_key()
33053157{
3306   int control = (machine.root_device().ioport("keyboard_7")->read() & 1) ? 0 : 0x100;
3307   int shift   = (machine.root_device().ioport("keyboard_9")->read() & 1) ? 0 : 0x080;
3158   int control = (ioport("keyboard_7")->read() & 1) ? 0 : 0x100;
3159   int shift   = (ioport("keyboard_9")->read() & 1) ? 0 : 0x080;
33083160   int key = -1, line, bit;
33093161   UINT8 port;
33103162   static const char *const keynames[] = {
r21425r21426
33123164      "keyboard_5", "keyboard_6", "keyboard_7", "keyboard_8", "keyboard_9"
33133165   };
33143166
3315   if ( machine.root_device().ioport("config")->read() & 2 )
3167   if ( ioport("config")->read() & 2 )
33163168      return -1; /* disabled */
33173169
33183170   for ( line = 0; line < 10; line++ )
33193171   {
3320      port = machine.root_device().ioport(keynames[line])->read();
3172      port = ioport(keynames[line])->read();
33213173
33223174      if ( line == 7 || line == 9 )
33233175         port |= 1; /* shift & control */
r21425r21426
33343186
33353187   if ( key == -1 )
33363188   {
3337      to8_kbd_last_key = 0xff;
3338      to8_kbd_key_count = 0;
3189      m_to8_kbd_last_key = 0xff;
3190      m_to8_kbd_key_count = 0;
33393191      return -1;
33403192   }
33413193   else if ( key == 64 )
33423194   {
33433195      /* caps lock */
3344      if ( to8_kbd_last_key == key )
3196      if ( m_to8_kbd_last_key == key )
33453197         return -1; /* no repeat */
3346      to8_kbd_last_key = key;
3347      to8_kbd_caps = !to8_kbd_caps;
3348      if ( to8_kbd_caps )
3198      m_to8_kbd_last_key = key;
3199      m_to8_kbd_caps = !m_to8_kbd_caps;
3200      if ( m_to8_kbd_caps )
33493201         key |= 0x080; /* auto-shift */
3350      thom_set_caps_led( machine, !to8_kbd_caps );
3202      thom_set_caps_led( !m_to8_kbd_caps );
33513203      return key;
33523204   }
3353   else if ( key == to8_kbd_last_key )
3205   else if ( key == m_to8_kbd_last_key )
33543206   {
33553207      /* repeat */
3356      to8_kbd_key_count++;
3357      if ( to8_kbd_key_count < TO8_KBD_REPEAT_DELAY || (to8_kbd_key_count - TO8_KBD_REPEAT_DELAY) % TO8_KBD_REPEAT_PERIOD )
3208      m_to8_kbd_key_count++;
3209      if ( m_to8_kbd_key_count < TO8_KBD_REPEAT_DELAY || (m_to8_kbd_key_count - TO8_KBD_REPEAT_DELAY) % TO8_KBD_REPEAT_PERIOD )
33583210         return -1;
33593211      return key | shift | control;
33603212   }
33613213   else
33623214   {
3363      to8_kbd_last_key = key;
3364      to8_kbd_key_count = 0;
3215      m_to8_kbd_last_key = key;
3216      m_to8_kbd_key_count = 0;
33653217      return key | shift | control;
33663218   }
33673219}
r21425r21426
33763228*/
33773229
33783230/* keyboard automaton */
3379static void to8_kbd_timer_func(running_machine &machine)
3231void thomson_state::to8_kbd_timer_func()
33803232{
33813233   attotime d;
33823234
3383   LOG_KBD(( "%f to8_kbd_timer_cb: step=%i ack=%i data=$%03X\n", machine.time().as_double(), to8_kbd_step, to8_kbd_ack, to8_kbd_data ));
3235   LOG_KBD(( "%f to8_kbd_timer_cb: step=%i ack=%i data=$%03X\n", machine().time().as_double(), m_to8_kbd_step, m_to8_kbd_ack, m_to8_kbd_data ));
33843236
3385   if( ! to8_kbd_step )
3237   if( ! m_to8_kbd_step )
33863238   {
33873239      /* key polling */
3388      int k = to8_kbd_get_key(machine);
3240      int k = to8_kbd_get_key();
33893241      /* if not in transfer, send pulse from time to time
33903242         (helps avoiding CPU lock)
33913243      */
3392      if ( ! to8_kbd_ack )
3393         mc6846_set_input_cp1( machine.device("mc6846"), 0 );
3394      mc6846_set_input_cp1( machine.device("mc6846"), 1 );
3244      if ( ! m_to8_kbd_ack )
3245         mc6846_set_input_cp1( m_mc6846, 0 );
3246      mc6846_set_input_cp1( m_mc6846, 1 );
33953247
33963248      if ( k == -1 )
33973249         d = TO8_KBD_POLL_PERIOD;
r21425r21426
33993251      {
34003252         /* got key! */
34013253         LOG_KBD(( "to8_kbd_timer_cb: got key $%03X\n", k ));
3402         to8_kbd_data = k;
3403         to8_kbd_step = 1;
3254         m_to8_kbd_data = k;
3255         m_to8_kbd_step = 1;
34043256         d = attotime::from_usec( 100 );
34053257      }
34063258   }
3407   else if ( to8_kbd_step == 255 )
3259   else if ( m_to8_kbd_step == 255 )
34083260   {
34093261      /* timeout */
3410      to8_kbd_last_key = 0xff;
3411      to8_kbd_key_count = 0;
3412      to8_kbd_step = 0;
3413      mc6846_set_input_cp1( machine.device("mc6846"), 1 );
3262      m_to8_kbd_last_key = 0xff;
3263      m_to8_kbd_key_count = 0;
3264      m_to8_kbd_step = 0;
3265      mc6846_set_input_cp1( m_mc6846, 1 );
34143266      d = TO8_KBD_POLL_PERIOD;
34153267   }
3416   else if ( to8_kbd_step == 1 )
3268   else if ( m_to8_kbd_step == 1 )
34173269   {
34183270      /* schedule timeout waiting for ack to go down */
3419      mc6846_set_input_cp1( machine.device("mc6846"), 0 );
3420      to8_kbd_step = 255;
3271      mc6846_set_input_cp1( m_mc6846, 0 );
3272      m_to8_kbd_step = 255;
34213273      d = TO8_KBD_TIMEOUT;
34223274   }
3423   else if ( to8_kbd_step == 117 )
3275   else if ( m_to8_kbd_step == 117 )
34243276   {
34253277      /* schedule timeout  waiting for ack to go up */
3426      mc6846_set_input_cp1( machine.device("mc6846"), 0 );
3427      to8_kbd_step = 255;
3278      mc6846_set_input_cp1( m_mc6846, 0 );
3279      m_to8_kbd_step = 255;
34283280      d = TO8_KBD_TIMEOUT;
34293281   }
3430   else if ( to8_kbd_step & 1 )
3282   else if ( m_to8_kbd_step & 1 )
34313283   {
34323284      /* send silence between bits */
3433      mc6846_set_input_cp1( machine.device("mc6846"), 0 );
3285      mc6846_set_input_cp1( m_mc6846, 0 );
34343286      d = attotime::from_usec( 100 );
3435      to8_kbd_step++;
3287      m_to8_kbd_step++;
34363288   }
34373289   else
34383290   {
34393291      /* send bit */
3440      int bpos = 8 - ( (to8_kbd_step - 100) / 2);
3441      int bit = (to8_kbd_data >> bpos) & 1;
3442      mc6846_set_input_cp1( machine.device("mc6846"), 1 );
3292      int bpos = 8 - ( (m_to8_kbd_step - 100) / 2);
3293      int bit = (m_to8_kbd_data >> bpos) & 1;
3294      mc6846_set_input_cp1( m_mc6846, 1 );
34433295      d = attotime::from_usec( bit ? 56 : 38 );
3444      to8_kbd_step++;
3296      m_to8_kbd_step++;
34453297   }
3446   to8_kbd_timer->adjust(d);
3298   m_to8_kbd_timer->adjust(d);
34473299}
34483300
34493301
34503302
3451static TIMER_CALLBACK(to8_kbd_timer_cb)
3303TIMER_CALLBACK_MEMBER(thomson_state::to8_kbd_timer_cb)
34523304{
3453   to8_kbd_timer_func(machine);
3305   to8_kbd_timer_func();
34543306}
34553307
34563308
34573309
34583310/* cpu <-> keyboard hand-check */
3459static void to8_kbd_set_ack ( running_machine &machine, int data )
3311void thomson_state::to8_kbd_set_ack( int data )
34603312{
3461   if ( data == to8_kbd_ack )
3313   if ( data == m_to8_kbd_ack )
34623314      return;
3463   to8_kbd_ack = data;
3315   m_to8_kbd_ack = data;
34643316
34653317   if ( data )
34663318   {
3467      double len = to8_kbd_signal->elapsed( ).as_double() * 1000. - 2.;
3468      LOG_KBD(( "%f to8_kbd_set_ack: CPU end ack, len=%f\n", machine.time().as_double(), len ));
3469      if ( to8_kbd_data == 0xfff )
3319      double len = m_to8_kbd_signal->elapsed( ).as_double() * 1000. - 2.;
3320      LOG_KBD(( "%f to8_kbd_set_ack: CPU end ack, len=%f\n", machine().time().as_double(), len ));
3321      if ( m_to8_kbd_data == 0xfff )
34703322      {
34713323         /* end signal from CPU */
34723324         if ( len >= 0.6 && len <= 0.8 )
34733325         {
3474            LOG (( "%f to8_kbd_set_ack: INIT signal\n", machine.time().as_double() ));
3475            to8_kbd_last_key = 0xff;
3476            to8_kbd_key_count = 0;
3477            to8_kbd_caps = 1;
3326            LOG (( "%f to8_kbd_set_ack: INIT signal\n", machine().time().as_double() ));
3327            m_to8_kbd_last_key = 0xff;
3328            m_to8_kbd_key_count = 0;
3329            m_to8_kbd_caps = 1;
34783330            /* send back signal: TODO returned codes ? */
3479            to8_kbd_data = 0;
3480            to8_kbd_step = 0;
3481            to8_kbd_timer->adjust(attotime::from_msec( 1 ));
3331            m_to8_kbd_data = 0;
3332            m_to8_kbd_step = 0;
3333            m_to8_kbd_timer->adjust(attotime::from_msec( 1 ));
34823334         }
34833335         else
34843336         {
3485            to8_kbd_step = 0;
3486            to8_kbd_timer->adjust(TO8_KBD_POLL_PERIOD);
3337            m_to8_kbd_step = 0;
3338            m_to8_kbd_timer->adjust(TO8_KBD_POLL_PERIOD);
34873339            if ( len >= 1.2 && len <= 1.4 )
34883340            {
3489               LOG (( "%f to8_kbd_set_ack: CAPS on signal\n", machine.time().as_double() ));
3490               to8_kbd_caps = 1;
3341               LOG (( "%f to8_kbd_set_ack: CAPS on signal\n", machine().time().as_double() ));
3342               m_to8_kbd_caps = 1;
34913343            }
34923344            else if ( len >= 1.8 && len <= 2.0 )
34933345            {
3494               LOG (( "%f to8_kbd_set_ack: CAPS off signal\n", machine.time().as_double() ));
3495               to8_kbd_caps = 0;
3346               LOG (( "%f to8_kbd_set_ack: CAPS off signal\n", machine().time().as_double() ));
3347               m_to8_kbd_caps = 0;
34963348            }
34973349         }
3498         thom_set_caps_led( machine, !to8_kbd_caps );
3350         thom_set_caps_led( !m_to8_kbd_caps );
34993351      }
35003352      else
35013353      {
35023354         /* end key transmission */
3503         to8_kbd_step = 0;
3504         to8_kbd_timer->adjust(TO8_KBD_POLL_PERIOD);
3355         m_to8_kbd_step = 0;
3356         m_to8_kbd_timer->adjust(TO8_KBD_POLL_PERIOD);
35053357      }
35063358   }
35073359
35083360   else
35093361   {
3510      if ( to8_kbd_step == 255 )
3362      if ( m_to8_kbd_step == 255 )
35113363      {
35123364         /* CPU accepts key */
3513         to8_kbd_step = 99;
3514         to8_kbd_timer->adjust(attotime::from_usec( 400 ));
3365         m_to8_kbd_step = 99;
3366         m_to8_kbd_timer->adjust(attotime::from_usec( 400 ));
35153367      }
35163368      else
35173369      {
35183370         /* start signal from CPU */
3519         to8_kbd_data = 0xfff;
3520         to8_kbd_step = 91;
3521         to8_kbd_timer->adjust(attotime::from_usec( 400 ));
3522         to8_kbd_signal->adjust(attotime::never);
3371         m_to8_kbd_data = 0xfff;
3372         m_to8_kbd_step = 91;
3373         m_to8_kbd_timer->adjust(attotime::from_usec( 400 ));
3374         m_to8_kbd_signal->adjust(attotime::never);
35233375      }
3524      LOG_KBD(( "%f to8_kbd_set_ack: CPU ack, data=$%03X\n", machine.time().as_double(), to8_kbd_data ));
3376      LOG_KBD(( "%f to8_kbd_set_ack: CPU ack, data=$%03X\n", machine().time().as_double(), m_to8_kbd_data ));
35253377   }
35263378}
35273379
35283380
35293381
3530static void to8_kbd_reset ( running_machine &machine )
3382void thomson_state::to8_kbd_reset()
35313383{
3532   to8_kbd_last_key = 0xff;
3533   to8_kbd_key_count = 0;
3534   to8_kbd_step = 0;
3535   to8_kbd_data = 0;
3536   to8_kbd_ack = 1;
3537   to8_kbd_caps = 1;
3538   thom_set_caps_led( machine, !to8_kbd_caps );
3539   to8_kbd_timer_func(machine);
3384   m_to8_kbd_last_key = 0xff;
3385   m_to8_kbd_key_count = 0;
3386   m_to8_kbd_step = 0;
3387   m_to8_kbd_data = 0;
3388   m_to8_kbd_ack = 1;
3389   m_to8_kbd_caps = 1;
3390   thom_set_caps_led( !m_to8_kbd_caps );
3391   to8_kbd_timer_func();
35403392}
35413393
35423394
35433395
3544static void to8_kbd_init ( running_machine &machine )
3396void thomson_state::to8_kbd_init()
35453397{
3546   to8_kbd_timer = machine.scheduler().timer_alloc(FUNC(to8_kbd_timer_cb));
3547   to8_kbd_signal = machine.scheduler().timer_alloc(FUNC_NULL);
3548   state_save_register_global( machine, to8_kbd_ack );
3549   state_save_register_global( machine, to8_kbd_data );
3550   state_save_register_global( machine, to8_kbd_step );
3551   state_save_register_global( machine, to8_kbd_last_key );
3552   state_save_register_global( machine, to8_kbd_key_count );
3553   state_save_register_global( machine, to8_kbd_caps );
3398   m_to8_kbd_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::to8_kbd_timer_cb),this));
3399   m_to8_kbd_signal = machine().scheduler().timer_alloc(FUNC_NULL);
3400   save_item(NAME(m_to8_kbd_ack));
3401   save_item(NAME(m_to8_kbd_data));
3402   save_item(NAME(m_to8_kbd_step));
3403   save_item(NAME(m_to8_kbd_last_key));
3404   save_item(NAME(m_to8_kbd_key_count));
3405   save_item(NAME(m_to8_kbd_caps));
35543406}
35553407
35563408
35573409
35583410/* ------------ RAM / ROM banking ------------ */
35593411
3560static UINT8  to8_reg_ram;
3561static UINT8  to8_reg_cart;
3562static UINT8  to8_reg_sys1;
3563static UINT8  to8_reg_sys2;
3564static UINT8  to8_lightpen_intr;
3565static UINT8  to8_soft_select;
3566static UINT8  to8_soft_bank;
3567static UINT8  to8_bios_bank;
3568
3569
3570
3571static void to8_update_floppy_bank( running_machine &machine )
3412void thomson_state::to8_update_floppy_bank()
35723413{
3573   int bank = (to8_reg_sys1 & 0x80) ? to7_floppy_bank : (to8_bios_bank + TO7_NB_FLOP_BANK);
3414   int bank = (m_to8_reg_sys1 & 0x80) ? to7_floppy_bank : (m_to8_bios_bank + TO7_NB_FLOP_BANK);
35743415
3575   if ( bank != old_floppy_bank )
3576      {
3416   if ( bank != m_old_floppy_bank )
3417   {
35773418      LOG_BANK(( "to8_update_floppy_bank: floppy ROM is %s bank %i\n",
3578                     (to8_reg_sys1 & 0x80) ? "external" : "internal",
3419                     (m_to8_reg_sys1 & 0x80) ? "external" : "internal",
35793420                     bank % TO7_NB_FLOP_BANK ));
3580      machine.root_device().membank( THOM_FLOP_BANK )->set_entry( bank );
3581      old_floppy_bank = bank;
3421      membank( THOM_FLOP_BANK )->set_entry( bank );
3422      m_old_floppy_bank = bank;
35823423   }
35833424}
35843425
35853426
35863427
3587static void to8_update_floppy_bank_postload(running_machine *machine)
3428void thomson_state::to8_update_floppy_bank_postload()
35883429{
3589   to8_update_floppy_bank(*machine);
3430   to8_update_floppy_bank();
35903431}
35913432
35923433
35933434
3594static void to8_update_ram_bank (running_machine &machine)
3435void thomson_state::to8_update_ram_bank()
35953436{
3596   pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS );
3597   address_space& space = machine.device("maincpu")->memory().space(AS_PROGRAM);
3437   address_space& space = m_maincpu->space(AS_PROGRAM);
35983438   UINT8 bank = 0;
35993439
3600   if ( to8_reg_sys1 & 0x10 )
3440   if ( m_to8_reg_sys1 & 0x10 )
36013441   {
3602      bank = to8_reg_ram & 31;
3442      bank = m_to8_reg_ram & 31;
36033443   }
36043444   else
36053445   {
3606      UINT8 portb = sys_pia->port_b_z_mask();
3446      UINT8 portb = m_pia_sys->port_b_z_mask();
36073447
36083448      switch ( portb & 0xf8 )
36093449      {
r21425r21426
36283468       this is important if we map a bank that is also reachable by another,
36293469       undistorted space, such as cartridge, page 0 (video), or page 1
36303470   */
3631   if ( bank != old_ram_bank)
3471   if ( bank != m_old_ram_bank)
3472   {
3473      if (m_ram->size() == 512*1024 || m_to8_data_vpage < 16)
36323474      {
3633      if (machine.device<ram_device>(RAM_TAG)->size() == 512*1024 || to8_data_vpage < 16)
3634            {
3635         machine.root_device().membank( TO8_DATA_LO )->set_entry( bank );
3636         machine.root_device().membank( TO8_DATA_HI )->set_entry( bank );
3637      } else
3638            {
3475         membank( TO8_DATA_LO )->set_entry( bank );
3476         membank( TO8_DATA_HI )->set_entry( bank );
3477      }
3478      else
3479      {
36393480         /* RAM size is 256 KB only and unavailable
36403481          * bank requested */
36413482         space.nop_readwrite( 0xa000, 0xbfff);
36423483         space.nop_readwrite( 0xc000, 0xdfff);
36433484      }
3644      to8_data_vpage = bank;
3645      old_ram_bank = bank;
3646      LOG_BANK(( "to8_update_ram_bank: select bank %i (%s style)\n", bank, (to8_reg_sys1 & 0x10) ? "new" : "old"));
3485      m_to8_data_vpage = bank;
3486      m_old_ram_bank = bank;
3487      LOG_BANK(( "to8_update_ram_bank: select bank %i (%s style)\n", bank, (m_to8_reg_sys1 & 0x10) ? "new" : "old"));
36473488   }
36483489}
36493490
36503491
36513492
3652static void to8_update_ram_bank_postload(running_machine *machine)
3493void thomson_state::to8_update_ram_bank_postload()
36533494{
3654   to8_update_ram_bank(*machine);
3495   to8_update_ram_bank();
36553496}
36563497
36573498
36583499
3659static void to8_update_cart_bank (running_machine &machine)
3500void thomson_state::to8_update_cart_bank()
36603501{
3661   address_space& space = machine.device("maincpu")->memory().space(AS_PROGRAM);
3502   address_space& space = m_maincpu->space(AS_PROGRAM);
36623503   int bank = 0;
36633504   int bank_is_read_only = 0;
36643505
3665   if ( to8_reg_cart & 0x20 )
3506   if ( m_to8_reg_cart & 0x20 )
36663507   {
36673508      /* RAM space */
3668      to8_cart_vpage = to8_reg_cart & 31;
3669      bank = 8 + to8_cart_vpage;
3670      bank_is_read_only = (( to8_reg_cart & 0x40 ) == 0);
3671      if ( bank != old_cart_bank )
3672            {
3509      m_to8_cart_vpage = m_to8_reg_cart & 31;
3510      bank = 8 + m_to8_cart_vpage;
3511      bank_is_read_only = (( m_to8_reg_cart & 0x40 ) == 0);
3512      if ( bank != m_old_cart_bank )
3513      {
36733514         /* mapping to VRAM */
3674         if (machine.device<ram_device>(RAM_TAG)->size() == 512*1024 || to8_cart_vpage < 16)
3675                  {
3676            if (to8_cart_vpage < 4)
3677                        {
3678               if (old_cart_bank < 8 || old_cart_bank > 11)
3679                              {
3515         if (m_ram->size() == 512*1024 || m_to8_cart_vpage < 16)
3516         {
3517            if (m_to8_cart_vpage < 4)
3518            {
3519               if (m_old_cart_bank < 8 || m_old_cart_bank > 11)
3520               {
36803521                  space.install_read_bank( 0x0000, 0x3fff, THOM_CART_BANK );
36813522                  if ( bank_is_read_only )
3682                                    {
3523                  {
36833524                     space.nop_write( 0x0000, 0x3fff);
3684                                    }
3525                  }
36853526                  else
3686                                    {
3687                     space.install_legacy_write_handler( 0x0000, 0x3fff, FUNC(to8_vcart_w));
3688                                    }
3527                  {
3528                     space.install_write_handler( 0x0000, 0x3fff, write8_delegate(FUNC(thomson_state::to8_vcart_w),this));
3529                  }
36893530               }
36903531            }
3691                        else
3692                        {
3693               if (old_cart_bank < 12)
3694                              {
3532            else
3533            {
3534               if (m_old_cart_bank < 12)
3535               {
36953536                  if ( bank_is_read_only )
3696                                    {
3537                  {
36973538                     space.install_read_bank( 0x0000, 0x3fff, THOM_CART_BANK );
36983539                     space.nop_write( 0x0000, 0x3fff);
36993540                  }
3700                                    else
3701                                    {
3702                     space.install_readwrite_bank( 0x0000, 0x3fff,THOM_CART_BANK);
3703                                    }
3704                              }
3705                        }
3706         }
37073541                  else
37083542                  {
3543                     space.install_readwrite_bank( 0x0000, 0x3fff,THOM_CART_BANK);
3544                  }
3545               }
3546            }
3547         }
3548         else
3549         {
37093550            /* RAM size is 256 KB only and unavailable
37103551             * bank requested */
37113552            space.nop_readwrite( 0x0000, 0x3fff);
3712                  }
3553         }
37133554         LOG_BANK(( "to8_update_cart_bank: CART is RAM bank %i (%s)\n",
3714                           to8_cart_vpage,
3555                           m_to8_cart_vpage,
37153556                           bank_is_read_only ? "read-only":"read-write"));
37163557      }
37173558      else
3559      {
3560         if ( bank_is_read_only != m_old_cart_bank_was_read_only )
3561         {
3562            if ( bank_is_read_only )
37183563            {
3719                  if ( bank_is_read_only != old_cart_bank_was_read_only )
3720                  {
3721                        if ( bank_is_read_only )
3722                        {
3723                              space.nop_write( 0x0000, 0x3fff);
3724                        }
3725                        else
3726                        {
3727                              if (to8_cart_vpage < 4)
3728                              {
3729                                    space.install_legacy_write_handler( 0x0000, 0x3fff, FUNC(to8_vcart_w));
3730                              }
3731                              else
3732                              {
3733                                    space.install_readwrite_bank( 0x0000, 0x3fff, THOM_CART_BANK );
3734                              }
3735                        }
3736                        LOG_BANK(( "to8_update_cart_bank: update CART bank %i write status to %s\n",
3737                                 to8_cart_vpage,
3738                                 bank_is_read_only ? "read-only":"read-write"));
3739                  }
3564               space.nop_write( 0x0000, 0x3fff);
37403565            }
3741      old_cart_bank_was_read_only = bank_is_read_only;
3566            else
3567            {
3568               if (m_to8_cart_vpage < 4)
3569               {
3570                  space.install_write_handler( 0x0000, 0x3fff, write8_delegate(FUNC(thomson_state::to8_vcart_w),this));
3571               }
3572               else
3573               {
3574                  space.install_readwrite_bank( 0x0000, 0x3fff, THOM_CART_BANK );
3575               }
3576            }
3577            LOG_BANK(( "to8_update_cart_bank: update CART bank %i write status to %s\n",
3578                                 m_to8_cart_vpage,
3579                                 bank_is_read_only ? "read-only":"read-write"));
3580         }
3581      }
3582      m_old_cart_bank_was_read_only = bank_is_read_only;
37423583   }
37433584   else
37443585   {
3745      if ( to8_soft_select )
3586      if ( m_to8_soft_select )
37463587      {
37473588         /* internal software ROM space */
3748         bank = 4 + to8_soft_bank;
3749         if ( bank != old_cart_bank )
3750                  {
3751            if ( old_cart_bank < 4 || old_cart_bank > 7 )
3752                        {
3589         bank = 4 + m_to8_soft_bank;
3590         if ( bank != m_old_cart_bank )
3591         {
3592            if ( m_old_cart_bank < 4 || m_old_cart_bank > 7 )
3593            {
37533594               space.install_read_bank( 0x0000, 0x3fff, THOM_CART_BANK );
3754               space.install_legacy_write_handler( 0x0000, 0x3fff, FUNC(to8_cartridge_w) );
3595               space.install_write_handler( 0x0000, 0x3fff, write8_delegate(FUNC(thomson_state::to8_cartridge_w),this) );
37553596            }
3756            LOG_BANK(( "to8_update_cart_bank: CART is internal bank %i\n", to8_soft_bank ));
3597            LOG_BANK(( "to8_update_cart_bank: CART is internal bank %i\n", m_to8_soft_bank ));
37573598         }
37583599      }
37593600      else
37603601      {
37613602         /* external cartridge ROM space */
3762         if ( thom_cart_nb_banks )
3603         if ( m_thom_cart_nb_banks )
37633604         {
3764            bank = thom_cart_bank % thom_cart_nb_banks;
3765            if ( bank != old_cart_bank )
3766                        {
3767               if ( old_cart_bank < 0 || old_cart_bank > 3 )
3768                              {
3605            bank = m_thom_cart_bank % m_thom_cart_nb_banks;
3606            if ( bank != m_old_cart_bank )
3607            {
3608               if ( m_old_cart_bank < 0 || m_old_cart_bank > 3 )
3609               {
37693610                  space.install_read_bank( 0x0000, 0x3fff, THOM_CART_BANK );
3770                  space.install_legacy_write_handler( 0x0000, 0x3fff, FUNC(to8_cartridge_w) );
3771                  space.install_legacy_read_handler( 0x0000, 0x0003, FUNC(to8_cartridge_r) );
3611                  space.install_write_handler( 0x0000, 0x3fff, write8_delegate(FUNC(thomson_state::to8_cartridge_w),this) );
3612                  space.install_read_handler( 0x0000, 0x0003, read8_delegate(FUNC(thomson_state::to8_cartridge_r),this) );
37723613               }
37733614               LOG_BANK(( "to8_update_cart_bank: CART is external cartridge bank %i\n", bank ));
37743615            }
37753616         }
3776                  else
3777                  {
3778            if ( old_cart_bank != 0 )
3779                        {
3617         else
3618         {
3619            if ( m_old_cart_bank != 0 )
3620            {
37803621               space.nop_read( 0x0000, 0x3fff);
37813622               LOG_BANK(( "to8_update_cart_bank: CART is unmapped\n"));
37823623            }
3783                  }
3784            }
3624         }
37853625      }
3786   if ( bank != old_cart_bank )
3787      {
3788      machine.root_device().membank( THOM_CART_BANK )->set_entry( bank );
3789      old_cart_bank = bank;
37903626   }
3627   if ( bank != m_old_cart_bank )
3628   {
3629      membank( THOM_CART_BANK )->set_entry( bank );
3630      m_old_cart_bank = bank;
3631   }
37913632}
37923633
37933634
37943635
3795static void to8_update_cart_bank_postload(running_machine *machine)
3636void thomson_state::to8_update_cart_bank_postload()
37963637{
3797   to8_update_cart_bank(*machine);
3638   to8_update_cart_bank();
37983639}
37993640
38003641
38013642
38023643/* ROM bank switch */
3803WRITE8_HANDLER ( to8_cartridge_w )
3644WRITE8_MEMBER( thomson_state::to8_cartridge_w )
38043645{
38053646   if ( offset >= 0x2000 )
38063647      return;
38073648
3808   if ( to8_soft_select )
3809      to8_soft_bank = offset & 3;
3649   if ( m_to8_soft_select )
3650      m_to8_soft_bank = offset & 3;
38103651   else
3811      thom_cart_bank = offset & 3;
3652      m_thom_cart_bank = offset & 3;
38123653
3813   to8_update_cart_bank(space.machine());
3654   to8_update_cart_bank();
38143655}
38153656
38163657
38173658
38183659/* read signal to 0000-0003 generates a bank switch */
3819READ8_HANDLER ( to8_cartridge_r )
3660READ8_MEMBER( thomson_state::to8_cartridge_r )
38203661{
3821   UINT8* pos = space.machine().root_device().memregion( "maincpu" )->base() + 0x10000;
3822   UINT8 data = pos[offset + (thom_cart_bank % thom_cart_nb_banks) * 0x4000];
3662   UINT8* pos = memregion( "maincpu" )->base() + 0x10000;
3663   UINT8 data = pos[offset + (m_thom_cart_bank % m_thom_cart_nb_banks) * 0x4000];
38233664   if ( !space.debugger_access() )
3824      {
3825      thom_cart_bank = offset & 3;
3826      to8_update_cart_bank(space.machine());
3665   {
3666      m_thom_cart_bank = offset & 3;
3667      to8_update_cart_bank();
38273668   }
38283669   return data;
38293670}
r21425r21426
38333674
38343675
38353676
3836static void to8_floppy_init( running_machine &machine )
3677void thomson_state::to8_floppy_init()
38373678{
3838   UINT8* mem = machine.root_device().memregion("maincpu")->base();
3839   to7_floppy_init( machine, mem + 0x34000 );
3679   UINT8* mem = memregion("maincpu")->base();
3680   to7_floppy_init( mem + 0x34000 );
38403681}
38413682
38423683
38433684
3844static void to8_floppy_reset( running_machine &machine )
3685void thomson_state::to8_floppy_reset()
38453686{
3846   UINT8* mem = machine.root_device().memregion("maincpu")->base();
3847   to7_floppy_reset(machine);
3687   UINT8* mem = memregion("maincpu")->base();
3688   to7_floppy_reset();
38483689   if ( THOM_FLOPPY_INT )
3849      thmfc_floppy_reset(machine);
3850   machine.root_device().membank( THOM_FLOP_BANK )->configure_entries( TO7_NB_FLOP_BANK, 2, mem + 0x30000, 0x2000 );
3690      thmfc_floppy_reset();
3691   membank( THOM_FLOP_BANK )->configure_entries( TO7_NB_FLOP_BANK, 2, mem + 0x30000, 0x2000 );
38513692}
38523693
38533694
38543695
3855READ8_HANDLER ( to8_floppy_r )
3696READ8_MEMBER( thomson_state::to8_floppy_r )
38563697{
38573698   if ( space.debugger_access() )
38583699      return 0;
38593700
3860   if ( (to8_reg_sys1 & 0x80) && THOM_FLOPPY_EXT )
3701   if ( (m_to8_reg_sys1 & 0x80) && THOM_FLOPPY_EXT )
38613702      /* external controller */
38623703      return to7_floppy_r( space, offset );
3863   else if ( ! (to8_reg_sys1 & 0x80) && THOM_FLOPPY_INT )
3704   else if ( ! (m_to8_reg_sys1 & 0x80) && THOM_FLOPPY_INT )
38643705      /* internal controller */
38653706      return thmfc_floppy_r( space, offset );
38663707   else
r21425r21426
38703711
38713712
38723713
3873WRITE8_HANDLER ( to8_floppy_w )
3714WRITE8_MEMBER( thomson_state::to8_floppy_w )
38743715{
3875   if ( (to8_reg_sys1 & 0x80) && THOM_FLOPPY_EXT )
3716   if ( (m_to8_reg_sys1 & 0x80) && THOM_FLOPPY_EXT )
38763717      /* external controller */
38773718      to7_floppy_w( space, offset, data );
3878   else if ( ! (to8_reg_sys1 & 0x80) && THOM_FLOPPY_INT )
3719   else if ( ! (m_to8_reg_sys1 & 0x80) && THOM_FLOPPY_INT )
38793720      /* internal controller */
38803721      thmfc_floppy_w( space, offset, data );
38813722}
r21425r21426
38903731
38913732
38923733
3893READ8_HANDLER ( to8_gatearray_r )
3734READ8_MEMBER( thomson_state::to8_gatearray_r )
38943735{
3895   struct thom_vsignal v = thom_get_vsignal(space.machine());
3896   struct thom_vsignal l = thom_get_lightpen_vsignal( space.machine(), TO8_LIGHTPEN_DECAL, to7_lightpen_step - 1, 6 );
3736   struct thom_vsignal v = thom_get_vsignal();
3737   struct thom_vsignal l = thom_get_lightpen_vsignal( TO8_LIGHTPEN_DECAL, m_to7_lightpen_step - 1, 6 );
38973738   int count, inil, init, lt3;
38983739   UINT8 res;
3899   count = to7_lightpen ? l.count : v.count;
3900   inil  = to7_lightpen ? l.inil  : v.inil;
3901   init  = to7_lightpen ? l.init  : v.init;
3902   lt3   = to7_lightpen ? l.lt3   : v.lt3;
3740   count = m_to7_lightpen ? l.count : v.count;
3741   inil  = m_to7_lightpen ? l.inil  : v.inil;
3742   init  = m_to7_lightpen ? l.init  : v.init;
3743   lt3   = m_to7_lightpen ? l.lt3   : v.lt3;
39033744
39043745   switch ( offset )
39053746   {
39063747   case 0: /* system 2 / lightpen register 1 */
3907      if ( to7_lightpen )
3748      if ( m_to7_lightpen )
39083749         res = (count >> 8) & 0xff;
39093750      else
3910         res = to8_reg_sys2 & 0xf0;
3751         res = m_to8_reg_sys2 & 0xf0;
39113752      break;
39123753
39133754   case 1: /* ram register / lightpen register 2 */
3914      if ( to7_lightpen )
3755      if ( m_to7_lightpen )
39153756      {
39163757         if ( !space.debugger_access() )
39173758         {
3918            thom_firq_2( space.machine(), 0 );
3919            to8_lightpen_intr = 0;
3759            thom_firq_2( 0 );
3760            m_to8_lightpen_intr = 0;
39203761         }
39213762         res = count & 0xff;
39223763      }
39233764      else
3924         res = to8_reg_ram & 0x1f;
3765         res = m_to8_reg_ram & 0x1f;
39253766      break;
39263767
39273768   case 2: /* cartrige register / lightpen register 3 */
3928      if ( to7_lightpen )
3769      if ( m_to7_lightpen )
39293770         res = (lt3 << 7) | (inil << 6);
39303771      else
3931         res = to8_reg_cart;
3772         res = m_to8_reg_cart;
39323773      break;
39333774
39343775   case 3: /* lightpen register 4 */
3935      res = (v.init << 7) | (init << 6) | (v.inil << 5) | (to8_lightpen_intr << 1) | to7_lightpen;
3776      res = (v.init << 7) | (init << 6) | (v.inil << 5) | (m_to8_lightpen_intr << 1) | m_to7_lightpen;
39363777      break;
39373778
39383779   default:
3939      logerror( "$%04x to8_gatearray_r: invalid offset %i\n", space.machine().device("maincpu")->safe_pcbase(), offset );
3780      logerror( "$%04x to8_gatearray_r: invalid offset %i\n", m_maincpu->pc(), offset );
39403781      res = 0;
39413782   }
39423783
39433784   LOG_VIDEO(( "$%04x %f to8_gatearray_r: off=%i ($%04X) res=$%02X lightpen=%i\n",
3944         space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(),
3945         offset, 0xe7e4 + offset, res, to7_lightpen ));
3785         m_maincpu->pc(), machine().time().as_double(),
3786         offset, 0xe7e4 + offset, res, m_to7_lightpen ));
39463787
39473788   return res;
39483789}
39493790
39503791
39513792
3952WRITE8_HANDLER ( to8_gatearray_w )
3793WRITE8_MEMBER( thomson_state::to8_gatearray_w )
39533794{
39543795   LOG_VIDEO(( "$%04x %f to8_gatearray_w: off=%i ($%04X) data=$%02X\n",
3955         space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(),
3796         m_maincpu->pc(), machine().time().as_double(),
39563797         offset, 0xe7e4 + offset, data ));
39573798
39583799   switch ( offset )
39593800   {
39603801   case 0: /* switch */
3961      to7_lightpen = data & 1;
3802      m_to7_lightpen = data & 1;
39623803      break;
39633804
39643805   case 1: /* ram register */
3965      if ( to8_reg_sys1 & 0x10 )
3806      if ( m_to8_reg_sys1 & 0x10 )
39663807      {
3967         to8_reg_ram = data;
3968         to8_update_ram_bank(space.machine());
3808         m_to8_reg_ram = data;
3809         to8_update_ram_bank();
39693810      }
39703811      break;
39713812
39723813   case 2: /* cartridge register */
3973      to8_reg_cart = data;
3974      to8_update_cart_bank(space.machine());
3814      m_to8_reg_cart = data;
3815      to8_update_cart_bank();
39753816      break;
39763817
39773818   case 3: /* system register 1 */
3978      to8_reg_sys1 = data;
3979      to8_update_floppy_bank(space.machine());
3980      to8_update_ram_bank(space.machine());
3981      to8_update_cart_bank(space.machine());
3819      m_to8_reg_sys1 = data;
3820      to8_update_floppy_bank();
3821      to8_update_ram_bank();
3822      to8_update_cart_bank();
39823823      break;
39833824
39843825   default:
39853826      logerror( "$%04x to8_gatearray_w: invalid offset %i (data=$%02X)\n",
3986            space.machine().device("maincpu")->safe_pcbase(), offset, data );
3827            m_maincpu->pc(), offset, data );
39873828   }
39883829}
39893830
r21425r21426
39933834
39943835
39953836
3996READ8_HANDLER  ( to8_vreg_r )
3837READ8_MEMBER( thomson_state::to8_vreg_r )
39973838{
39983839   /* 0xe7dc from external floppy drive aliases the video gate-array */
3999   if ( ( offset == 3 ) && ( to8_reg_ram & 0x80 ) && ( to8_reg_sys1 & 0x80 ) )
3840   if ( ( offset == 3 ) && ( m_to8_reg_ram & 0x80 ) && ( m_to8_reg_sys1 & 0x80 ) )
40003841   {
40013842      if ( space.debugger_access() )
40023843         return 0;
r21425r21426
40113852   {
40123853   case 0: /* palette data */
40133854   {
4014      UINT8 c =  to9_palette_data[ to9_palette_idx ];
3855      UINT8 c =  m_to9_palette_data[ m_to9_palette_idx ];
40153856      if ( !space.debugger_access() )
4016            {
4017         to9_palette_idx = ( to9_palette_idx + 1 ) & 31;
4018            }
3857      {
3858         m_to9_palette_idx = ( m_to9_palette_idx + 1 ) & 31;
3859      }
40193860      return c;
40203861   }
40213862
40223863   case 1: /* palette address */
4023      return to9_palette_idx;
3864      return m_to9_palette_idx;
40243865
40253866   case 2:
40263867   case 3:
r21425r21426
40343875
40353876
40363877
4037WRITE8_HANDLER ( to8_vreg_w )
3878WRITE8_MEMBER( thomson_state::to8_vreg_w )
40383879{
40393880   LOG_VIDEO(( "$%04x %f to8_vreg_w: off=%i ($%04X) data=$%02X\n",
4040         space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(),
3881         m_maincpu->pc(), machine().time().as_double(),
40413882         offset, 0xe7da + offset, data ));
40423883
40433884   switch ( offset )
r21425r21426
40453886   case 0: /* palette data */
40463887   {
40473888      UINT16 color, idx;
4048      to9_palette_data[ to9_palette_idx ] = data;
4049      idx = to9_palette_idx / 2;
4050      color = to9_palette_data[ 2 * idx + 1 ];
4051      color = to9_palette_data[ 2 * idx ] | (color << 8);
4052      thom_set_palette( space.machine(), idx, color & 0x1fff );
4053      to9_palette_idx = ( to9_palette_idx + 1 ) & 31;
3889      m_to9_palette_data[ m_to9_palette_idx ] = data;
3890      idx = m_to9_palette_idx / 2;
3891      color = m_to9_palette_data[ 2 * idx + 1 ];
3892      color = m_to9_palette_data[ 2 * idx ] | (color << 8);
3893      thom_set_palette( idx, color & 0x1fff );
3894      m_to9_palette_idx = ( m_to9_palette_idx + 1 ) & 31;
40543895   }
40553896   break;
40563897
40573898   case 1: /* palette address */
4058      to9_palette_idx = data & 31;
3899      m_to9_palette_idx = data & 31;
40593900      break;
40603901
40613902   case 2: /* display register */
4062      to9_set_video_mode( space.machine(), data, 1 );
3903      to9_set_video_mode( data, 1 );
40633904      break;
40643905
40653906   case 3: /* system register 2 */
40663907      /* 0xe7dc from external floppy drive aliases the video gate-array */
4067      if ( ( offset == 3 ) && ( to8_reg_ram & 0x80 ) && ( to8_reg_sys1 & 0x80 ) )
3908      if ( ( offset == 3 ) && ( m_to8_reg_ram & 0x80 ) && ( m_to8_reg_sys1 & 0x80 ) )
40683909      {
40693910         if ( THOM_FLOPPY_EXT )
40703911            to7_floppy_w( space, 0xc, data );
40713912      }
40723913      else
40733914      {
4074         to8_reg_sys2 = data;
4075         thom_set_video_page( space.machine(), data >> 6 );
4076         thom_set_border_color( space.machine(), data & 15 );
3915         m_to8_reg_sys2 = data;
3916         thom_set_video_page( data >> 6 );
3917         thom_set_border_color( data & 15 );
40773918      }
40783919      break;
40793920
r21425r21426
40883929
40893930
40903931
4091static READ8_DEVICE_HANDLER ( to8_sys_porta_in )
3932READ8_MEMBER( thomson_state::to8_sys_porta_in )
40923933{
4093   int ktest = to8_kbd_ktest (space.machine());
3934   int ktest = to8_kbd_ktest();
40943935
4095   LOG_KBD(( "$%04x %f: to8_sys_porta_in ktest=%i\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), ktest ));
3936   LOG_KBD(( "$%04x %f: to8_sys_porta_in ktest=%i\n", m_maincpu->pc(), machine().time().as_double(), ktest ));
40963937
40973938   return ktest;
40983939}
40993940
41003941
41013942
4102static WRITE8_DEVICE_HANDLER ( to8_sys_portb_out )
3943WRITE8_MEMBER( thomson_state::to8_sys_portb_out )
41033944{
4104   centronics_device *printer = space.machine().device<centronics_device>("centronics");
3945   m_centronics->d0_w(BIT(data, 0));
3946   m_centronics->strobe_w(BIT(data, 1));
41053947
4106   printer->d0_w(BIT(data, 0));
4107   printer->strobe_w(BIT(data, 1));
3948   to8_update_ram_bank();
41083949
4109   to8_update_ram_bank(space.machine());
4110
41113950   if ( data & 4 ) /* bit 2: video overlay (TODO) */
41123951      LOG(( "to8_sys_portb_out: video overlay not handled\n" ));
41133952}
r21425r21426
41163955
41173956const pia6821_interface to8_pia6821_sys =
41183957{
4119   DEVCB_HANDLER(to8_sys_porta_in),
3958   DEVCB_DRIVER_MEMBER(thomson_state, to8_sys_porta_in),
41203959   DEVCB_NULL,
41213960   DEVCB_NULL,
41223961   DEVCB_NULL,
41233962   DEVCB_NULL,
41243963   DEVCB_NULL,
4125   DEVCB_HANDLER(to9_sys_porta_out),
4126   DEVCB_HANDLER(to8_sys_portb_out),
4127   DEVCB_HANDLER(to7_set_cassette_motor),
3964   DEVCB_DRIVER_MEMBER(thomson_state, to9_sys_porta_out),
3965   DEVCB_DRIVER_MEMBER(thomson_state, to8_sys_portb_out),
3966   DEVCB_DRIVER_MEMBER(thomson_state, to7_set_cassette_motor),
41283967   DEVCB_NULL,
41293968   DEVCB_NULL,
4130   DEVCB_LINE(thom_firq_1)
3969   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1)
41313970};
41323971
41333972
r21425r21426
41363975
41373976
41383977
4139static READ8_DEVICE_HANDLER ( to8_timer_port_in )
3978READ8_MEMBER( thomson_state::to8_timer_port_in )
41403979{
4141   centronics_device *printer = space.machine().device<centronics_device>("centronics");
4142   int lightpen = (space.machine().root_device().ioport("lightpen_button")->read() & 1) ? 2 : 0;
4143   int cass = to7_get_cassette(space.machine()) ? 0x80 : 0;
4144   int dtr = printer->busy_r() << 6;
4145   int lock = to8_kbd_caps ? 0 : 8; /* undocumented! */
3980   int lightpen = (ioport("lightpen_button")->read() & 1) ? 2 : 0;
3981   int cass = to7_get_cassette() ? 0x80 : 0;
3982   int dtr = m_centronics->busy_r() << 6;
3983   int lock = m_to8_kbd_caps ? 0 : 8; /* undocumented! */
41463984   return lightpen | cass | dtr | lock;
41473985}
41483986
41493987
41503988
4151static WRITE8_DEVICE_HANDLER ( to8_timer_port_out )
3989WRITE8_MEMBER( thomson_state::to8_timer_port_out )
41523990{
41533991   int ack = (data & 0x20) ? 1 : 0;       /* bit 5: keyboard ACK */
4154   to8_bios_bank = (data & 0x10) ? 1 : 0; /* bit 4: BIOS bank*/
4155   thom_set_mode_point( space.machine(), data & 1 );       /* bit 0: video bank switch */
4156   space.machine().root_device().membank( TO8_BIOS_BANK )->set_entry( to8_bios_bank );
4157   to8_soft_select = (data & 0x04) ? 1 : 0; /* bit 2: internal ROM select */
4158   to8_update_floppy_bank(space.machine());
4159   to8_update_cart_bank(space.machine());
4160   to8_kbd_set_ack(space.machine(), ack);
3992   m_to8_bios_bank = (data & 0x10) ? 1 : 0; /* bit 4: BIOS bank*/
3993   thom_set_mode_point( data & 1 );       /* bit 0: video bank switch */
3994   membank( TO8_BIOS_BANK )->set_entry( m_to8_bios_bank );
3995   m_to8_soft_select = (data & 0x04) ? 1 : 0; /* bit 2: internal ROM select */
3996   to8_update_floppy_bank();
3997   to8_update_cart_bank();
3998   to8_kbd_set_ack(ack);
41613999}
41624000
41634001
41644002
4165static WRITE8_DEVICE_HANDLER ( to8_timer_cp2_out )
4003WRITE8_MEMBER( thomson_state::to8_timer_cp2_out )
41664004{
41674005   /* mute */
4168   to7_game_mute = data;
4169   to7_game_sound_update(space.machine());
4006   m_to7_game_mute = data;
4007   to7_game_sound_update();
41704008}
41714009
41724010
41734011
41744012const mc6846_interface to8_timer =
41754013{
4176   DEVCB_HANDLER(to8_timer_port_out), DEVCB_NULL, DEVCB_HANDLER(to8_timer_cp2_out),
4177   DEVCB_HANDLER(to8_timer_port_in), DEVCB_HANDLER(to7_timer_tco_out),
4178   DEVCB_LINE(thom_dev_irq_0)
4014   DEVCB_DRIVER_MEMBER(thomson_state, to8_timer_port_out),
4015   DEVCB_NULL,
4016   DEVCB_DRIVER_MEMBER(thomson_state, to8_timer_cp2_out),
4017   DEVCB_DRIVER_MEMBER(thomson_state, to8_timer_port_in),
4018   DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_tco_out),
4019   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_dev_irq_0)
41794020};
41804021
41814022
r21425r21426
41854026
41864027
41874028/* direct connection to interrupt line instead of through a PIA */
4188static void to8_lightpen_cb ( running_machine &machine, int step )
4029void thomson_state::to8_lightpen_cb( int step )
41894030{
4190   if ( ! to7_lightpen )
4031   if ( ! m_to7_lightpen )
41914032      return;
41924033
4193   thom_firq_2( machine, 1 );
4194   to7_lightpen_step = step;
4195   to8_lightpen_intr = 1;
4034   thom_firq_2( 1 );
4035   m_to7_lightpen_step = step;
4036   m_to8_lightpen_intr = 1;
41964037}
41974038
41984039
r21425r21426
42014042
42024043
42034044
4204MACHINE_RESET ( to8 )
4045MACHINE_RESET_MEMBER( thomson_state, to8 )
42054046{
4206   pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS );
42074047   LOG (( "to8: machine reset called\n" ));
42084048
42094049   /* subsystems */
4210   thom_irq_reset(machine);
4211   sys_pia->set_port_a_z_mask( 0xfe );
4212   to7_game_reset(machine);
4213   to8_floppy_reset(machine);
4214   to8_kbd_reset(machine);
4215   to7_modem_reset(machine);
4216   to7_midi_reset(machine);
4050   thom_irq_reset();
4051   m_pia_sys->set_port_a_z_mask( 0xfe );
4052   to7_game_reset();
4053   to8_floppy_reset();
4054   to8_kbd_reset();
4055   to7_modem_reset();
4056   to7_midi_reset();
42174057
42184058   /* gate-array */
4219   to7_lightpen = 0;
4220   to8_reg_ram = 0;
4221   to8_reg_cart = 0;
4222   to8_reg_sys1 = 0;
4223   to8_reg_sys2 = 0;
4224   to8_lightpen_intr = 0;
4225   to8_soft_select = 0;
4059   m_to7_lightpen = 0;
4060   m_to8_reg_ram = 0;
4061   m_to8_reg_cart = 0;
4062   m_to8_reg_sys1 = 0;
4063   m_to8_reg_sys2 = 0;
4064   m_to8_lightpen_intr = 0;
4065   m_to8_soft_select = 0;
42264066
42274067   /* video */
4228   thom_set_video_mode( machine, THOM_VMODE_TO770 );
4229   thom_set_lightpen_callback( machine, 4, to8_lightpen_cb );
4230   thom_set_border_color( machine, 0 );
4231   thom_set_mode_point( machine, 0 );
4232   sys_pia->cb1_w( 0 );
4068   thom_set_video_mode( THOM_VMODE_TO770 );
4069   m_thom_lightpen_cb = &thomson_state::to8_lightpen_cb;
4070   thom_set_lightpen_callback( 4 );
4071   thom_set_border_color( 0 );
4072   thom_set_mode_point( 0 );
4073   m_pia_sys->cb1_w( 0 );
42334074
42344075   /* memory */
4235   old_ram_bank = -1;
4236   old_cart_bank = -1;
4237   old_cart_bank_was_read_only = 0;
4238   old_floppy_bank = -1;
4239   to8_cart_vpage = 0;
4240   to8_data_vpage = 0;
4241   to8_soft_bank = 0;
4242   to8_bios_bank = 0;
4243   to8_update_ram_bank(machine);
4244   to8_update_cart_bank(machine);
4245   to8_update_floppy_bank(machine);
4246   machine.root_device().membank( TO8_BIOS_BANK )->set_entry( 0 );
4076   m_old_ram_bank = -1;
4077   m_old_cart_bank = -1;
4078   m_old_cart_bank_was_read_only = 0;
4079   m_old_floppy_bank = -1;
4080   m_to8_cart_vpage = 0;
4081   m_to8_data_vpage = 0;
4082   m_to8_soft_bank = 0;
4083   m_to8_bios_bank = 0;
4084   to8_update_ram_bank();
4085   to8_update_cart_bank();
4086   to8_update_floppy_bank();
4087   membank( TO8_BIOS_BANK )->set_entry( 0 );
42474088   /* thom_cart_bank not reset */
42484089}
42494090
42504091
42514092
4252MACHINE_START ( to8 )
4093MACHINE_START_MEMBER( thomson_state, to8 )
42534094{
4254   UINT8* mem = machine.root_device().memregion("maincpu")->base();
4255   UINT8* ram = machine.device<ram_device>(RAM_TAG)->pointer();
4095   UINT8* mem = memregion("maincpu")->base();
4096   UINT8* ram = m_ram->pointer();
42564097
42574098   LOG (( "to8: machine start called\n" ));
42584099
42594100   /* subsystems */
4260   thom_irq_init(machine);
4261   to7_game_init(machine);
4262   to8_floppy_init(machine);
4263   to8_kbd_init(machine);
4264   to9_palette_init(machine);
4265   to7_modem_init(machine);
4266   to7_midi_init(machine);
4101   thom_irq_init();
4102   to7_game_init();
4103   to8_floppy_init();
4104   to8_kbd_init();
4105   to9_palette_init();
4106   to7_modem_init();
4107   to7_midi_init();
42674108
42684109   /* memory */
4269   thom_cart_bank = 0;
4270   thom_vram = ram;
4271   machine.root_device().membank( THOM_CART_BANK )->configure_entries( 0,  8, mem + 0x10000, 0x4000 );
4272   machine.root_device().membank( THOM_CART_BANK )->configure_entries( 8, 32, ram, 0x4000 );
4273   machine.root_device().membank( THOM_VRAM_BANK )->configure_entries( 0,  2, ram, 0x2000 );
4274   machine.root_device().membank( TO8_SYS_LO )->configure_entry( 0,  ram + 0x6000);
4275   machine.root_device().membank( TO8_SYS_HI )->configure_entry( 0,  ram + 0x4000);
4276   machine.root_device().membank( TO8_DATA_LO )->configure_entries( 0, 32, ram + 0x2000, 0x4000 );
4277   machine.root_device().membank( TO8_DATA_HI )->configure_entries( 0, 32, ram + 0x0000, 0x4000 );
4278   machine.root_device().membank( TO8_BIOS_BANK )->configure_entries( 0,  2, mem + 0x30800, 0x2000 );
4279   machine.root_device().membank( THOM_CART_BANK )->set_entry( 0 );
4280   machine.root_device().membank( THOM_VRAM_BANK )->set_entry( 0 );
4281   machine.root_device().membank( TO8_SYS_LO )->set_entry( 0 );
4282   machine.root_device().membank( TO8_SYS_HI )->set_entry( 0 );
4283   machine.root_device().membank( TO8_DATA_LO )->set_entry( 0 );
4284   machine.root_device().membank( TO8_DATA_HI )->set_entry( 0 );
4285   machine.root_device().membank( TO8_BIOS_BANK )->set_entry( 0 );
4110   m_thom_cart_bank = 0;
4111   m_thom_vram = ram;
4112   membank( THOM_CART_BANK )->configure_entries( 0,  8, mem + 0x10000, 0x4000 );
4113   membank( THOM_CART_BANK )->configure_entries( 8, 32, ram, 0x4000 );
4114   membank( THOM_VRAM_BANK )->configure_entries( 0,  2, ram, 0x2000 );
4115   membank( TO8_SYS_LO )->configure_entry( 0,  ram + 0x6000);
4116   membank( TO8_SYS_HI )->configure_entry( 0,  ram + 0x4000);
4117   membank( TO8_DATA_LO )->configure_entries( 0, 32, ram + 0x2000, 0x4000 );
4118   membank( TO8_DATA_HI )->configure_entries( 0, 32, ram + 0x0000, 0x4000 );
4119   membank( TO8_BIOS_BANK )->configure_entries( 0,  2, mem + 0x30800, 0x2000 );
4120   membank( THOM_CART_BANK )->set_entry( 0 );
4121   membank( THOM_VRAM_BANK )->set_entry( 0 );
4122   membank( TO8_SYS_LO )->set_entry( 0 );
4123   membank( TO8_SYS_HI )->set_entry( 0 );
4124   membank( TO8_DATA_LO )->set_entry( 0 );
4125   membank( TO8_DATA_HI )->set_entry( 0 );
4126   membank( TO8_BIOS_BANK )->set_entry( 0 );
42864127
42874128   /* save-state */
4288   state_save_register_global( machine, thom_cart_nb_banks );
4289   state_save_register_global( machine, thom_cart_bank );
4290   state_save_register_global( machine, to7_lightpen );
4291   state_save_register_global( machine, to7_lightpen_step );
4292   state_save_register_global( machine, to8_reg_ram );
4293   state_save_register_global( machine, to8_reg_cart );
4294   state_save_register_global( machine, to8_reg_sys1 );
4295   state_save_register_global( machine, to8_reg_sys2 );
4296   state_save_register_global( machine, to8_soft_select );
4297   state_save_register_global( machine, to8_soft_bank );
4298   state_save_register_global( machine, to8_bios_bank );
4299   state_save_register_global( machine, to8_lightpen_intr );
4300   state_save_register_global( machine, to8_data_vpage );
4301   state_save_register_global( machine, to8_cart_vpage );
4302   state_save_register_global_pointer( machine, (mem + 0x10000), 0x10000 );
4303   machine.save().register_postload(save_prepost_delegate(FUNC(to8_update_ram_bank_postload), &machine));
4304   machine.save().register_postload(save_prepost_delegate(FUNC(to8_update_cart_bank_postload), &machine));
4305   machine.save().register_postload(save_prepost_delegate(FUNC(to8_update_floppy_bank_postload), &machine));
4129   save_item(NAME(m_thom_cart_nb_banks));
4130   save_item(NAME(m_thom_cart_bank));
4131   save_item(NAME(m_to7_lightpen));
4132   save_item(NAME(m_to7_lightpen_step));
4133   save_item(NAME(m_to8_reg_ram));
4134   save_item(NAME(m_to8_reg_cart));
4135   save_item(NAME(m_to8_reg_sys1));
4136   save_item(NAME(m_to8_reg_sys2));
4137   save_item(NAME(m_to8_soft_select));
4138   save_item(NAME(m_to8_soft_bank));
4139   save_item(NAME(m_to8_bios_bank));
4140   save_item(NAME(m_to8_lightpen_intr));
4141   save_item(NAME(m_to8_data_vpage));
4142   save_item(NAME(m_to8_cart_vpage));
4143   state_save_register_global_pointer( machine(), (mem + 0x10000), 0x10000 );
4144   machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to8_update_ram_bank_postload), this));
4145   machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to8_update_cart_bank_postload), this));
4146   machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to8_update_floppy_bank_postload), this));
43064147}
43074148
43084149
r21425r21426
43174158
43184159const pia6821_interface to9p_pia6821_sys =
43194160{
4320   DEVCB_HANDLER(to9_sys_porta_in),
4161   DEVCB_DRIVER_MEMBER(thomson_state, to9_sys_porta_in),
43214162   DEVCB_NULL,
43224163   DEVCB_NULL,
43234164   DEVCB_NULL,
43244165   DEVCB_NULL,
43254166   DEVCB_NULL,
4326   DEVCB_HANDLER(to9_sys_porta_out),
4327   DEVCB_HANDLER(to8_sys_portb_out),
4328   DEVCB_HANDLER(to7_set_cassette_motor),
4167   DEVCB_DRIVER_MEMBER(thomson_state, to9_sys_porta_out),
4168   DEVCB_DRIVER_MEMBER(thomson_state, to8_sys_portb_out),
4169   DEVCB_DRIVER_MEMBER(thomson_state, to7_set_cassette_motor),
43294170   DEVCB_NULL,
43304171   DEVCB_NULL,
4331   DEVCB_LINE(thom_firq_1)
4172   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1)
43324173};
43334174
43344175
r21425r21426
43374178
43384179
43394180
4340static READ8_DEVICE_HANDLER ( to9p_timer_port_in )
4181READ8_MEMBER( thomson_state::to9p_timer_port_in )
43414182{
4342   centronics_device *printer = space.machine().device<centronics_device>("centronics");
4343   int lightpen = (space.machine().root_device().ioport("lightpen_button")->read() & 1) ? 2 : 0;
4344   int cass = to7_get_cassette(space.machine()) ? 0x80 : 0;
4345   int dtr = printer->busy_r() << 6;
4183   int lightpen = (ioport("lightpen_button")->read() & 1) ? 2 : 0;
4184   int cass = to7_get_cassette() ? 0x80 : 0;
4185   int dtr = m_centronics->busy_r() << 6;
43464186   return lightpen | cass | dtr;
43474187}
43484188
43494189
43504190
4351static WRITE8_DEVICE_HANDLER ( to9p_timer_port_out )
4191WRITE8_MEMBER( thomson_state::to9p_timer_port_out )
43524192{
43534193   int bios_bank = (data & 0x10) ? 1 : 0; /* bit 4: BIOS bank */
4354   thom_set_mode_point( space.machine(), data & 1 );       /* bit 0: video bank switch */
4355   space.machine().root_device().membank( TO8_BIOS_BANK )->set_entry( bios_bank );
4356   to8_soft_select = (data & 0x04) ? 1 : 0; /* bit 2: internal ROM select */
4357   to8_update_floppy_bank(space.machine());
4358   to8_update_cart_bank(space.machine());
4194   thom_set_mode_point( data & 1 );       /* bit 0: video bank switch */
4195   membank( TO8_BIOS_BANK )->set_entry( bios_bank );
4196   m_to8_soft_select = (data & 0x04) ? 1 : 0; /* bit 2: internal ROM select */
4197   to8_update_floppy_bank();
4198   to8_update_cart_bank();
43594199}
43604200
43614201
43624202
43634203const mc6846_interface to9p_timer =
43644204{
4365   DEVCB_HANDLER(to9p_timer_port_out), DEVCB_NULL, DEVCB_HANDLER(to8_timer_cp2_out),
4366   DEVCB_HANDLER(to9p_timer_port_in), DEVCB_HANDLER(to7_timer_tco_out),
4367   DEVCB_LINE(thom_dev_irq_0)
4205   DEVCB_DRIVER_MEMBER(thomson_state, to9p_timer_port_out),
4206   DEVCB_NULL,
4207   DEVCB_DRIVER_MEMBER(thomson_state, to8_timer_cp2_out),
4208   DEVCB_DRIVER_MEMBER(thomson_state, to9p_timer_port_in),
4209   DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_tco_out),
4210   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_dev_irq_0)
43684211};
43694212
43704213
r21425r21426
43734216
43744217
43754218
4376MACHINE_RESET ( to9p )
4219MACHINE_RESET_MEMBER( thomson_state, to9p )
43774220{
4378   pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS );
43794221   LOG (( "to9p: machine reset called\n" ));
43804222
43814223   /* subsystems */
4382   thom_irq_reset(machine);
4383   sys_pia->set_port_a_z_mask( 0xfe );
4384   to7_game_reset(machine);
4385   to8_floppy_reset(machine);
4386   to9_kbd_reset(machine);
4387   to7_modem_reset(machine);
4388   to7_midi_reset(machine);
4224   thom_irq_reset();
4225   m_pia_sys->set_port_a_z_mask( 0xfe );
4226   to7_game_reset();
4227   to8_floppy_reset();
4228   to9_kbd_reset();
4229   to7_modem_reset();
4230   to7_midi_reset();
43894231
43904232   /* gate-array */
4391   to7_lightpen = 0;
4392   to8_reg_ram = 0;
4393   to8_reg_cart = 0;
4394   to8_reg_sys1 = 0;
4395   to8_reg_sys2 = 0;
4396   to8_lightpen_intr = 0;
4397   to8_soft_select = 0;
4233   m_to7_lightpen = 0;
4234   m_to8_reg_ram = 0;
4235   m_to8_reg_cart = 0;
4236   m_to8_reg_sys1 = 0;
4237   m_to8_reg_sys2 = 0;
4238   m_to8_lightpen_intr = 0;
4239   m_to8_soft_select = 0;
43984240
43994241   /* video */
4400   thom_set_video_mode( machine, THOM_VMODE_TO770 );
4401   thom_set_lightpen_callback( machine, 4, to8_lightpen_cb );
4402   thom_set_border_color( machine, 0 );
4403   thom_set_mode_point( machine, 0 );
4404   sys_pia->cb1_w( 0 );
4242   thom_set_video_mode( THOM_VMODE_TO770 );
4243   m_thom_lightpen_cb = &thomson_state::to8_lightpen_cb;
4244   thom_set_lightpen_callback( 4 );
4245   thom_set_border_color( 0 );
4246   thom_set_mode_point( 0 );
4247   m_pia_sys->cb1_w( 0 );
44054248
44064249   /* memory */
4407   old_ram_bank = -1;
4408   old_cart_bank = -1;
4409   old_floppy_bank = -1;
4410   to8_cart_vpage = 0;
4411   to8_data_vpage = 0;
4412   to8_soft_bank = 0;
4413   to8_bios_bank = 0;
4414   to8_update_ram_bank(machine);
4415   to8_update_cart_bank(machine);
4416   to8_update_floppy_bank(machine);
4417   machine.root_device().membank( TO8_BIOS_BANK )->set_entry( 0 );
4250   m_old_ram_bank = -1;
4251   m_old_cart_bank = -1;
4252   m_old_floppy_bank = -1;
4253   m_to8_cart_vpage = 0;
4254   m_to8_data_vpage = 0;
4255   m_to8_soft_bank = 0;
4256   m_to8_bios_bank = 0;
4257   to8_update_ram_bank();
4258   to8_update_cart_bank();
4259   to8_update_floppy_bank();
4260   membank( TO8_BIOS_BANK )->set_entry( 0 );
44184261   /* thom_cart_bank not reset */
44194262}
44204263
44214264
44224265
4423MACHINE_START ( to9p )
4266MACHINE_START_MEMBER( thomson_state, to9p )
44244267{
4425   UINT8* mem = machine.root_device().memregion("maincpu")->base();
4426   UINT8* ram = machine.device<ram_device>(RAM_TAG)->pointer();
4268   UINT8* mem = memregion("maincpu")->base();
4269   UINT8* ram = m_ram->pointer();
44274270
44284271   LOG (( "to9p: machine start called\n" ));
44294272
44304273   /* subsystems */
4431   thom_irq_init(machine);
4432   to7_game_init(machine);
4433   to8_floppy_init( machine );
4434   to9_kbd_init(machine);
4435   to9_palette_init(machine);
4436   to7_modem_init(machine);
4437   to7_midi_init(machine);
4274   thom_irq_init();
4275   to7_game_init();
4276   to8_floppy_init();
4277   to9_kbd_init();
4278   to9_palette_init();
4279   to7_modem_init();
4280   to7_midi_init();
44384281
44394282   /* memory */
4440   thom_cart_bank = 0;
4441   thom_vram = ram;
4442   machine.root_device().membank( THOM_CART_BANK )->configure_entries( 0,  8, mem + 0x10000, 0x4000 );
4443   machine.root_device().membank( THOM_CART_BANK )->configure_entries( 8, 32, ram, 0x4000 );
4444   machine.root_device().membank( THOM_VRAM_BANK )->configure_entries( 0,  2, ram, 0x2000 );
4445   machine.root_device().membank( TO8_SYS_LO )->configure_entry( 0,  ram + 0x6000);
4446   machine.root_device().membank( TO8_SYS_HI )->configure_entry( 0,  ram + 0x4000);
4447   machine.root_device().membank( TO8_DATA_LO )->configure_entries( 0, 32, ram + 0x2000, 0x4000 );
4448   machine.root_device().membank( TO8_DATA_HI )->configure_entries( 0, 32, ram + 0x0000, 0x4000 );
4449   machine.root_device().membank( TO8_BIOS_BANK )->configure_entries( 0,  2, mem + 0x30800, 0x2000 );
4450   machine.root_device().membank( THOM_CART_BANK )->set_entry( 0 );
4451   machine.root_device().membank( THOM_VRAM_BANK )->set_entry( 0 );
4452   machine.root_device().membank( TO8_SYS_LO )->set_entry( 0 );
4453   machine.root_device().membank( TO8_SYS_HI )->set_entry( 0 );
4454   machine.root_device().membank( TO8_DATA_LO )->set_entry( 0 );
4455   machine.root_device().membank( TO8_DATA_HI )->set_entry( 0 );
4456   machine.root_device().membank( TO8_BIOS_BANK )->set_entry( 0 );
4283   m_thom_cart_bank = 0;
4284   m_thom_vram = ram;
4285   membank( THOM_CART_BANK )->configure_entries( 0,  8, mem + 0x10000, 0x4000 );
4286   membank( THOM_CART_BANK )->configure_entries( 8, 32, ram, 0x4000 );
4287   membank( THOM_VRAM_BANK )->configure_entries( 0,  2, ram, 0x2000 );
4288   membank( TO8_SYS_LO )->configure_entry( 0,  ram + 0x6000);
4289   membank( TO8_SYS_HI )->configure_entry( 0,  ram + 0x4000);
4290   membank( TO8_DATA_LO )->configure_entries( 0, 32, ram + 0x2000, 0x4000 );
4291   membank( TO8_DATA_HI )->configure_entries( 0, 32, ram + 0x0000, 0x4000 );
4292   membank( TO8_BIOS_BANK )->configure_entries( 0,  2, mem + 0x30800, 0x2000 );
4293   membank( THOM_CART_BANK )->set_entry( 0 );
4294   membank( THOM_VRAM_BANK )->set_entry( 0 );
4295   membank( TO8_SYS_LO )->set_entry( 0 );
4296   membank( TO8_SYS_HI )->set_entry( 0 );
4297   membank( TO8_DATA_LO )->set_entry( 0 );
4298   membank( TO8_DATA_HI )->set_entry( 0 );
4299   membank( TO8_BIOS_BANK )->set_entry( 0 );
44574300
44584301   /* save-state */
4459   state_save_register_global( machine, thom_cart_nb_banks );
4460   state_save_register_global( machine, thom_cart_bank );
4461   state_save_register_global( machine, to7_lightpen );
4462   state_save_register_global( machine, to7_lightpen_step );
4463   state_save_register_global( machine, to8_reg_ram );
4464   state_save_register_global( machine, to8_reg_cart );
4465   state_save_register_global( machine, to8_reg_sys1 );
4466   state_save_register_global( machine, to8_reg_sys2 );
4467   state_save_register_global( machine, to8_soft_select );
4468   state_save_register_global( machine, to8_soft_bank );
4469   state_save_register_global( machine, to8_bios_bank );
4470   state_save_register_global( machine, to8_lightpen_intr );
4471   state_save_register_global( machine, to8_data_vpage );
4472   state_save_register_global( machine, to8_cart_vpage );
4473   state_save_register_global_pointer( machine, (mem + 0x10000), 0x10000 );
4474   machine.save().register_postload(save_prepost_delegate(FUNC(to8_update_ram_bank_postload), &machine));
4475   machine.save().register_postload(save_prepost_delegate(FUNC(to8_update_cart_bank_postload), &machine));
4476   machine.save().register_postload(save_prepost_delegate(FUNC(to8_update_floppy_bank_postload), &machine));
4302   save_item(NAME(m_thom_cart_nb_banks));
4303   save_item(NAME(m_thom_cart_bank));
4304   save_item(NAME(m_to7_lightpen));
4305   save_item(NAME(m_to7_lightpen_step));
4306   save_item(NAME(m_to8_reg_ram));
4307   save_item(NAME(m_to8_reg_cart));
4308   save_item(NAME(m_to8_reg_sys1));
4309   save_item(NAME(m_to8_reg_sys2));
4310   save_item(NAME(m_to8_soft_select));
4311   save_item(NAME(m_to8_soft_bank));
4312   save_item(NAME(m_to8_bios_bank));
4313   save_item(NAME(m_to8_lightpen_intr));
4314   save_item(NAME(m_to8_data_vpage));
4315   save_item(NAME(m_to8_cart_vpage));
4316   state_save_register_global_pointer( machine(), (mem + 0x10000), 0x10000 );
4317   machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to8_update_ram_bank_postload), this));
4318   machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to8_update_cart_bank_postload), this));
4319   machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to8_update_floppy_bank_postload), this));
44774320}
44784321
44794322
r21425r21426
44864329
44874330
44884331
4489static void mo6_update_ram_bank ( running_machine &machine )
4332void thomson_state::mo6_update_ram_bank()
44904333{
44914334   UINT8 bank = 0;
44924335
4493   if ( to8_reg_sys1 & 0x10 )
4336   if ( m_to8_reg_sys1 & 0x10 )
44944337   {
4495      bank = to8_reg_ram & 7; /* 128 KB RAM only = 8 pages */
4338      bank = m_to8_reg_ram & 7; /* 128 KB RAM only = 8 pages */
44964339   }
4497   if ( bank != to8_data_vpage ) {
4498      machine.root_device().membank( TO8_DATA_LO )->set_entry( bank );
4499      machine.root_device().membank( TO8_DATA_HI )->set_entry( bank );
4500      to8_data_vpage = bank;
4501      old_ram_bank = bank;
4340   if ( bank != m_to8_data_vpage ) {
4341      membank( TO8_DATA_LO )->set_entry( bank );
4342      membank( TO8_DATA_HI )->set_entry( bank );
4343      m_to8_data_vpage = bank;
4344      m_old_ram_bank = bank;
45024345      LOG_BANK(( "mo6_update_ram_bank: select bank %i (new style)\n", bank ));
45034346   }
45044347}
45054348
45064349
45074350
4508static void mo6_update_ram_bank_postload(running_machine *machine)
4351void thomson_state::mo6_update_ram_bank_postload()
45094352{
4510   mo6_update_ram_bank(*machine);
4353   mo6_update_ram_bank();
45114354}
45124355
45134356
45144357
4515static void mo6_update_cart_bank (running_machine &machine)
4358void thomson_state::mo6_update_cart_bank()
45164359{
4517   pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS );
4518   address_space& space = machine.device("maincpu")->memory().space(AS_PROGRAM);
4519   int b = (sys_pia->a_output() >> 5) & 1;
4360   address_space& space = m_maincpu->space(AS_PROGRAM);
4361   int b = (m_pia_sys->a_output() >> 5) & 1;
45204362   int bank = 0;
45214363   int bank_is_read_only = 0;
45224364
45234365   // space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK );
45244366
4525   if ( ( ( to8_reg_sys1 & 0x40 ) && ( to8_reg_cart & 0x20 ) ) || ( ! ( to8_reg_sys1 & 0x40 ) && ( mo5_reg_cart & 4 ) ) )
4367   if ( ( ( m_to8_reg_sys1 & 0x40 ) && ( m_to8_reg_cart & 0x20 ) ) || ( ! ( m_to8_reg_sys1 & 0x40 ) && ( m_mo5_reg_cart & 4 ) ) )
45264368   {
45274369      /* RAM space */
4528      if ( to8_reg_sys1 & 0x40 )
4370      if ( m_to8_reg_sys1 & 0x40 )
45294371      {
45304372         /* use a7e6 */
4531         to8_cart_vpage = to8_reg_cart & 7; /* 128 KB RAM only = 8 pages */
4532         bank = 8 + to8_cart_vpage;
4533         bank_is_read_only = (( to8_reg_cart & 0x40 ) == 0);
4534         if ( bank != old_cart_bank )
4535                  {
4536            if (to8_cart_vpage < 4)
4537                        {
4538               if (old_cart_bank < 8 || old_cart_bank > 11)
4539                              {
4373         m_to8_cart_vpage = m_to8_reg_cart & 7; /* 128 KB RAM only = 8 pages */
4374         bank = 8 + m_to8_cart_vpage;
4375         bank_is_read_only = (( m_to8_reg_cart & 0x40 ) == 0);
4376         if ( bank != m_old_cart_bank )
4377         {
4378            if (m_to8_cart_vpage < 4)
4379            {
4380               if (m_old_cart_bank < 8 || m_old_cart_bank > 11)
4381               {
45404382                  space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK );
45414383                  if ( bank_is_read_only )
4542                                    {
4384                  {
45434385                     space.nop_write( 0xb000, 0xefff);
4544                                    }
4386                  }
45454387                  else
4546                                    {
4547                     space.install_legacy_write_handler( 0xb000, 0xefff, FUNC(to8_vcart_w));
4548                                    }
4388                  {
4389                     space.install_write_handler( 0xb000, 0xefff, write8_delegate(FUNC(thomson_state::to8_vcart_w),this));
4390                  }
45494391               }
45504392            }
4551                        else
4552                        {
4553               if (old_cart_bank < 12)
4554                              {
4393            else
4394            {
4395               if (m_old_cart_bank < 12)
4396               {
45554397                  if ( bank_is_read_only )
4556                                    {
4398                  {
45574399                     space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK );
45584400                     space.nop_write( 0xb000, 0xefff);
45594401                  }
4560                                    else
4561                                    {
4402                  else
4403                  {
45624404                     space.install_readwrite_bank( 0xb000, 0xefff,THOM_CART_BANK);
4563                                    }
4564                              }
4565                        }
4405                  }
4406               }
4407            }
45664408            LOG_BANK(( "mo6_update_cart_bank: CART is RAM bank %i (%s)\n",
4567               to8_cart_vpage,
4409               m_to8_cart_vpage,
45684410               bank_is_read_only ? "read-only":"read-write"));
45694411         }
4570         else if ( bank_is_read_only != old_cart_bank_was_read_only )
4571                  {
4412         else if ( bank_is_read_only != m_old_cart_bank_was_read_only )
4413         {
45724414            if ( bank_is_read_only )
4573                        {
4415            {
45744416               space.nop_write( 0xb000, 0xefff);
4575                        }
4417            }
45764418            else
4577                        {
4578               if (to8_cart_vpage < 4)
4579                              {
4580                  space.install_legacy_write_handler( 0xb000, 0xefff, FUNC(to8_vcart_w));
4581                              }
4419            {
4420               if (m_to8_cart_vpage < 4)
4421               {
4422                  space.install_write_handler( 0xb000, 0xefff, write8_delegate(FUNC(thomson_state::to8_vcart_w),this));
4423               }
45824424               else
4583                              {
4425               {
45844426                  space.install_readwrite_bank( 0xb000, 0xefff, THOM_CART_BANK );
4585                              }
4586                        }
4427               }
4428            }
45874429            LOG_BANK(( "mo6_update_cart_bank: update CART bank %i write status to %s\n",
4588                                 to8_cart_vpage,
4430                                 m_to8_cart_vpage,
45894431                                 bank_is_read_only ? "read-only":"read-write"));
45904432         }
4591         old_cart_bank_was_read_only = bank_is_read_only;
4433         m_old_cart_bank_was_read_only = bank_is_read_only;
45924434      }
4593      else if ( thom_cart_nb_banks == 4 )
4435      else if ( m_thom_cart_nb_banks == 4 )
45944436      {
45954437         /* "JANE"-style cartridge bank switching */
4596         bank = mo5_reg_cart & 3;
4597         if ( bank != old_cart_bank )
4598                  {
4599            if ( old_cart_bank < 0 || old_cart_bank > 3 )
4600                        {
4438         bank = m_mo5_reg_cart & 3;
4439         if ( bank != m_old_cart_bank )
4440         {
4441            if ( m_old_cart_bank < 0 || m_old_cart_bank > 3 )
4442            {
46014443               space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK );
46024444               space.nop_write( 0xb000, 0xefff);
46034445            }
r21425r21426
46074449      else
46084450      {
46094451         /* RAM from MO5 network extension */
4610         int bank_is_read_only = (( mo5_reg_cart & 8 ) == 0);
4611         to8_cart_vpage = (mo5_reg_cart & 3) | 4;
4612         bank = 8 + to8_cart_vpage;
4613         if ( bank != old_cart_bank )
4614                  {
4615            if ( old_cart_bank < 12 )
4616                        {
4452         int bank_is_read_only = (( m_mo5_reg_cart & 8 ) == 0);
4453         m_to8_cart_vpage = (m_mo5_reg_cart & 3) | 4;
4454         bank = 8 + m_to8_cart_vpage;
4455         if ( bank != m_old_cart_bank )
4456         {
4457            if ( m_old_cart_bank < 12 )
4458            {
46174459               if ( bank_is_read_only )
4618                              {
4460               {
46194461                  space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK);
46204462                  space.nop_write( 0xb000, 0xefff);
4621               } else
4622                              {
4463               }
4464               else
4465               {
46234466                  space.install_readwrite_bank( 0xb000, 0xefff, THOM_CART_BANK);
4624                              }
4467               }
46254468            }
46264469            LOG_BANK(( "mo6_update_cart_bank: CART is RAM bank %i (MO5 compat.) (%s)\n",
4627                                 to8_cart_vpage,
4470                                 m_to8_cart_vpage,
46284471                                 bank_is_read_only ? "read-only":"read-write"));
46294472         }
4630         else if ( bank_is_read_only != old_cart_bank_was_read_only )
4631                  {
4473         else if ( bank_is_read_only != m_old_cart_bank_was_read_only )
4474         {
46324475            if ( bank_is_read_only )
4633                        {
4476            {
46344477               space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK);
46354478               space.nop_write( 0xb000, 0xefff);
46364479            }
4637                        else
4638                        {
4480            else
4481            {
46394482               space.install_readwrite_bank( 0xb000, 0xefff, THOM_CART_BANK);
4640                        }
4483            }
46414484            LOG_BANK(( "mo5_update_cart_bank: update CART bank %i write status to %s\n",
4642                                 to8_cart_vpage,
4485                                 m_to8_cart_vpage,
46434486                                 bank_is_read_only ? "read-only":"read-write"));
46444487         }
4645         old_cart_bank_was_read_only = bank_is_read_only;
4488         m_old_cart_bank_was_read_only = bank_is_read_only;
46464489      }
46474490   }
46484491   else
46494492   {
46504493      /* ROM space */
4651      if ( to8_reg_sys2 & 0x20 )
4494      if ( m_to8_reg_sys2 & 0x20 )
46524495      {
46534496         /* internal ROM */
4654         if ( to8_reg_sys2 & 0x10)
4655                  {
4497         if ( m_to8_reg_sys2 & 0x10)
4498         {
46564499            bank = b + 6; /* BASIC 128 */
4657                  }
4500         }
46584501         else
4659                  {
4502         {
46604503            bank = b + 4;                      /* BASIC 1 */
4661                  }
4662         if ( bank != old_cart_bank )
4663                  {
4664            if ( old_cart_bank < 4 || old_cart_bank > 7 )
4665                        {
4504         }
4505         if ( bank != m_old_cart_bank )
4506         {
4507            if ( m_old_cart_bank < 4 || m_old_cart_bank > 7 )
4508            {
46664509               space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK);
4667               space.install_legacy_write_handler( 0xb000, 0xefff, FUNC(mo6_cartridge_w) );
4510               space.install_write_handler( 0xb000, 0xefff, write8_delegate(FUNC(thomson_state::mo6_cartridge_w),this) );
46684511            }
46694512            LOG_BANK(( "mo6_update_cart_bank: CART is internal ROM bank %i\n", b ));
46704513         }
r21425r21426
46724515      else
46734516      {
46744517         /* cartridge */
4675         if ( thom_cart_nb_banks )
4518         if ( m_thom_cart_nb_banks )
46764519         {
4677            bank = thom_cart_bank % thom_cart_nb_banks;
4678            if ( bank != old_cart_bank )
4679                        {
4680               if ( old_cart_bank < 0 || old_cart_bank > 3 )
4681                              {
4520            bank = m_thom_cart_bank % m_thom_cart_nb_banks;
4521            if ( bank != m_old_cart_bank )
4522            {
4523               if ( m_old_cart_bank < 0 || m_old_cart_bank > 3 )
4524               {
46824525                  space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK );
4683                  space.install_legacy_write_handler( 0xb000, 0xefff, FUNC(mo6_cartridge_w) );
4684                  space.install_legacy_read_handler( 0xbffc, 0xbfff, FUNC(mo6_cartridge_r) );
4526                  space.install_write_handler( 0xb000, 0xefff, write8_delegate(FUNC(thomson_state::mo6_cartridge_w),this) );
4527                  space.install_read_handler( 0xbffc, 0xbfff, read8_delegate(FUNC(thomson_state::mo6_cartridge_r),this) );
46854528               }
46864529               LOG_BANK(( "mo6_update_cart_bank: CART is external cartridge bank %i\n", bank ));
46874530            }
46884531         }
4689                  else
4690                  {
4691            if ( old_cart_bank != 0 )
4692                        {
4532         else
4533         {
4534            if ( m_old_cart_bank != 0 )
4535            {
46934536               space.nop_read( 0xb000, 0xefff );
46944537               LOG_BANK(( "mo6_update_cart_bank: CART is unmapped\n"));
46954538            }
4696                  }
4539         }
46974540      }
46984541   }
4699   if ( bank != old_cart_bank )
4542   if ( bank != m_old_cart_bank )
47004543      {
4701      machine.root_device().membank( THOM_CART_BANK )->set_entry( bank );
4702      machine.root_device().membank( TO8_BIOS_BANK )->set_entry( b );
4703      old_cart_bank = bank;
4544      membank( THOM_CART_BANK )->set_entry( bank );
4545      membank( TO8_BIOS_BANK )->set_entry( b );
4546      m_old_cart_bank = bank;
47044547   }
47054548}
47064549
47074550
47084551
4709static void mo6_update_cart_bank_postload(running_machine *machine)
4552void thomson_state::mo6_update_cart_bank_postload()
47104553{
4711   mo6_update_cart_bank(*machine);
4554   mo6_update_cart_bank();
47124555}
47134556
47144557
47154558
47164559/* write signal generates a bank switch */
4717WRITE8_HANDLER ( mo6_cartridge_w )
4560WRITE8_MEMBER( thomson_state::mo6_cartridge_w )
47184561{
47194562   if ( offset >= 0x2000 )
47204563      return;
47214564
4722   thom_cart_bank = offset & 3;
4723   mo6_update_cart_bank(space.machine());
4565   m_thom_cart_bank = offset & 3;
4566   mo6_update_cart_bank();
47244567}
47254568
47264569
47274570
47284571/* read signal generates a bank switch */
4729READ8_HANDLER ( mo6_cartridge_r )
4572READ8_MEMBER( thomson_state::mo6_cartridge_r )
47304573{
4731   UINT8* pos = space.machine().root_device().memregion( "maincpu" )->base() + 0x10000;
4732   UINT8 data = pos[offset + 0xbffc + (thom_cart_bank % thom_cart_nb_banks) * 0x4000];
4574   UINT8* pos = memregion( "maincpu" )->base() + 0x10000;
4575   UINT8 data = pos[offset + 0xbffc + (m_thom_cart_bank % m_thom_cart_nb_banks) * 0x4000];
47334576   if ( !space.debugger_access() )
4734      {
4735      thom_cart_bank = offset & 3;
4736      mo6_update_cart_bank(space.machine());
4577   {
4578      m_thom_cart_bank = offset & 3;
4579      mo6_update_cart_bank();
47374580   }
47384581   return data;
47394582}
47404583
47414584
47424585
4743WRITE8_HANDLER ( mo6_ext_w )
4586WRITE8_MEMBER( thomson_state::mo6_ext_w )
47444587{
47454588   /* MO5 network extension compatible */
4746   mo5_reg_cart = data;
4747   mo6_update_cart_bank(space.machine());
4589   m_mo5_reg_cart = data;
4590   mo6_update_cart_bank();
47484591}
47494592
47504593
r21425r21426
47544597/* similar to SX 90-018, but with a few differences: mute, printer */
47554598
47564599
4757static WRITE_LINE_DEVICE_HANDLER( mo6_centronics_busy )
4600WRITE_LINE_MEMBER( thomson_state::mo6_centronics_busy )
47584601{
4759   pia6821_device *game_pia = device->machine().device<pia6821_device>( THOM_PIA_GAME );
4760   game_pia->cb1_w(state);
4602   m_pia_game->cb1_w(state);
47614603}
47624604
47634605
47644606const centronics_interface mo6_centronics_config =
47654607{
47664608   DEVCB_NULL,
4767   DEVCB_LINE(mo6_centronics_busy),
4609   DEVCB_DRIVER_LINE_MEMBER(thomson_state, mo6_centronics_busy),
47684610   DEVCB_NULL
47694611};
47704612
47714613
4772static WRITE8_DEVICE_HANDLER ( mo6_game_porta_out )
4614WRITE8_MEMBER( thomson_state::mo6_game_porta_out )
47734615{
4774   centronics_device *printer = space.machine().device<centronics_device>("centronics");
4616   LOG (( "$%04x %f mo6_game_porta_out: CENTRONICS set data=$%02X\n", m_maincpu->pc(), machine().time().as_double(), data ));
47754617
4776   LOG (( "$%04x %f mo6_game_porta_out: CENTRONICS set data=$%02X\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), data ));
4777
47784618   /* centronics data */
4779   printer->write( space.machine().driver_data()->generic_space(), 0, data);
4619   m_centronics->write( space, 0, data);
47804620}
47814621
47824622
47834623
4784static WRITE8_DEVICE_HANDLER ( mo6_game_cb2_out )
4624WRITE8_MEMBER( thomson_state::mo6_game_cb2_out )
47854625{
4786   centronics_device *printer = space.machine().device<centronics_device>("centronics");
4626   LOG (( "$%04x %f mo6_game_cb2_out: CENTRONICS set strobe=%i\n", m_maincpu->pc(), machine().time().as_double(), data ));
47874627
4788   LOG (( "$%04x %f mo6_game_cb2_out: CENTRONICS set strobe=%i\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), data ));
4789
47904628   /* centronics strobe */
4791   printer->strobe_w(data);
4629   m_centronics->strobe_w(data);
47924630}
47934631
47944632
47954633
47964634const pia6821_interface mo6_pia6821_game =
47974635{
4798   DEVCB_HANDLER(to7_game_porta_in),
4799   DEVCB_HANDLER(to7_game_portb_in),
4636   DEVCB_DRIVER_MEMBER(thomson_state, to7_game_porta_in),
4637   DEVCB_DRIVER_MEMBER(thomson_state, to7_game_portb_in),
48004638   DEVCB_NULL,
48014639   DEVCB_NULL,
48024640   DEVCB_NULL,
48034641   DEVCB_NULL,
4804   DEVCB_HANDLER(mo6_game_porta_out),
4805   DEVCB_HANDLER(to7_game_portb_out),
4642   DEVCB_DRIVER_MEMBER(thomson_state, mo6_game_porta_out),
4643   DEVCB_DRIVER_MEMBER(thomson_state, to7_game_portb_out),
48064644   DEVCB_NULL,
4807   DEVCB_HANDLER(mo6_game_cb2_out),
4808   DEVCB_LINE(thom_irq_1),
4809   DEVCB_LINE(thom_irq_1)
4645   DEVCB_DRIVER_MEMBER(thomson_state, mo6_game_cb2_out),
4646   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_irq_1),
4647   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_irq_1)
48104648};
48114649
48124650
48134651
4814static TIMER_CALLBACK(mo6_game_update_cb)
4652TIMER_CALLBACK_MEMBER(thomson_state::mo6_game_update_cb)
48154653{
4816   pia6821_device *game_pia = machine.device<pia6821_device>(THOM_PIA_GAME);
4817
48184654   /* unlike the TO8, CB1 & CB2 are not connected to buttons */
4819   if ( machine.root_device().ioport("config")->read() & 1 )
4655   if ( ioport("config")->read() & 1 )
48204656   {
4821      UINT8 mouse = to7_get_mouse_signal(machine);
4822      game_pia->ca1_w( BIT(mouse, 0) ); /* XA */
4823      game_pia->ca2_w( BIT(mouse, 1) ); /* YA */
4657      UINT8 mouse = to7_get_mouse_signal();
4658      m_pia_game->ca1_w( BIT(mouse, 0) ); /* XA */
4659      m_pia_game->ca2_w( BIT(mouse, 1) ); /* YA */
48244660   }
48254661   else
48264662   {
48274663      /* joystick */
4828      UINT8 in = machine.root_device().ioport("game_port_buttons")->read();
4829      game_pia->ca1_w( BIT(in, 2) ); /* P1 action B */
4830      game_pia->ca2_w( BIT(in, 6) ); /* P1 action A */
4664      UINT8 in = ioport("game_port_buttons")->read();
4665      m_pia_game->ca1_w( BIT(in, 2) ); /* P1 action B */
4666      m_pia_game->ca2_w( BIT(in, 6) ); /* P1 action A */
48314667   }
48324668}
48334669
48344670
48354671
4836static void mo6_game_init ( running_machine &machine )
4672void thomson_state::mo6_game_init()
48374673{
48384674   LOG (( "mo6_game_init called\n" ));
4839   to7_game_timer = machine.scheduler().timer_alloc(FUNC(mo6_game_update_cb));
4840   to7_game_timer->adjust(TO7_GAME_POLL_PERIOD, 0, TO7_GAME_POLL_PERIOD);
4841   state_save_register_global( machine, to7_game_sound );
4842   state_save_register_global( machine, to7_game_mute );
4675   m_to7_game_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::mo6_game_update_cb),this));
4676   m_to7_game_timer->adjust(TO7_GAME_POLL_PERIOD, 0, TO7_GAME_POLL_PERIOD);
4677   save_item(NAME(m_to7_game_sound));
4678   save_item(NAME(m_to7_game_mute));
48434679}
48444680
48454681
48464682
4847static void mo6_game_reset ( running_machine &machine )
4683void thomson_state::mo6_game_reset()
48484684{
4849   pia6821_device *game_pia = machine.device<pia6821_device>(THOM_PIA_GAME);
48504685   LOG (( "mo6_game_reset called\n" ));
4851   game_pia->ca1_w( 0 );
4852   to7_game_sound = 0;
4853   to7_game_mute = 0;
4854   to7_game_sound_update(machine);
4686   m_pia_game->ca1_w( 0 );
4687   m_to7_game_sound = 0;
4688   m_to7_game_mute = 0;
4689   to7_game_sound_update();
48554690}
48564691
48574692
r21425r21426
48604695
48614696
48624697
4863static READ8_DEVICE_HANDLER ( mo6_sys_porta_in )
4698READ8_MEMBER( thomson_state::mo6_sys_porta_in )
48644699{
48654700   return
4866      (mo5_get_cassette(space.machine()) ? 0x80 : 0) |     /* bit 7: cassette input */
4701      (mo5_get_cassette() ? 0x80 : 0) |     /* bit 7: cassette input */
48674702      8 |                                   /* bit 3: kbd-line float up to 1 */
4868      ((space.machine().root_device().ioport("lightpen_button")->read() & 1) ? 2 : 0);
4703      ((ioport("lightpen_button")->read() & 1) ? 2 : 0);
48694704   /* bit 1: lightpen button */;
48704705}
48714706
48724707
48734708
4874static READ8_DEVICE_HANDLER ( mo6_sys_portb_in )
4709READ8_MEMBER( thomson_state::mo6_sys_portb_in )
48754710{
48764711   /* keyboard: 9 lines of 8 keys */
4877   UINT8 porta = downcast<pia6821_device *>(device)->a_output();
4878   UINT8 portb =downcast<pia6821_device *>(device)->b_output();
4712   UINT8 porta = m_pia_sys->a_output();
4713   UINT8 portb = m_pia_sys->b_output();
48794714   int col = (portb >> 4) & 7;    /* B bits 4-6: kbd column */
48804715   int lin = (portb >> 1) & 7;    /* B bits 1-3: kbd line */
48814716   static const char *const keynames[] = {
r21425r21426
48874722      lin = 8;     /* A bit 3: 9-th kbd line select */
48884723
48894724   return
4890      ( space.machine().root_device().ioport(keynames[lin])->read() & (1 << col) ) ?  0x80 : 0;
4725      ( ioport(keynames[lin])->read() & (1 << col) ) ?  0x80 : 0;
48914726   /* bit 7: key up */
48924727}
48934728
48944729
48954730
4896static WRITE8_DEVICE_HANDLER ( mo6_sys_porta_out )
4731WRITE8_MEMBER( thomson_state::mo6_sys_porta_out )
48974732{
4898   thom_set_mode_point( space.machine(),data & 1 );                /* bit 0: video bank switch */
4899   to7_game_mute = data & 4;                       /* bit 2: sound mute */
4900   thom_set_caps_led( space.machine(),(data & 16) ? 0 : 1 ) ;      /* bit 4: keyboard led */
4901   mo5_set_cassette( space.machine(), (data & 0x40) ? 1 : 0 );     /* bit 6: cassette output */
4902   mo6_update_cart_bank(space.machine());                  /* bit 5: rom bank */
4903   to7_game_sound_update(space.machine());
4733   thom_set_mode_point( data & 1 );                /* bit 0: video bank switch */
4734   m_to7_game_mute = data & 4;                       /* bit 2: sound mute */
4735   thom_set_caps_led( (data & 16) ? 0 : 1 ) ;      /* bit 4: keyboard led */
4736   mo5_set_cassette( (data & 0x40) ? 1 : 0 );     /* bit 6: cassette output */
4737   mo6_update_cart_bank();                  /* bit 5: rom bank */
4738   to7_game_sound_update();
49044739}
49054740
49064741
49074742
4908static WRITE8_DEVICE_HANDLER ( mo6_sys_portb_out )
4743WRITE8_MEMBER( thomson_state::mo6_sys_portb_out )
49094744{
4910   space.machine().device<dac_device>("buzzer")->write_unsigned8((data & 1) ? 0x80 : 0); /* bit 0: buzzer */
4745   m_buzzer->write_unsigned8((data & 1) ? 0x80 : 0); /* bit 0: buzzer */
49114746}
49124747
49134748
49144749
4915static WRITE8_DEVICE_HANDLER ( mo6_sys_cb2_out )
4750WRITE8_MEMBER( thomson_state::mo6_sys_cb2_out )
49164751{
49174752   /* SCART pin 8 = slow switch (?) */
49184753   LOG(( "mo6_sys_cb2_out: SCART slow switch set to %i\n", data ));
r21425r21426
49224757
49234758const pia6821_interface mo6_pia6821_sys =
49244759{
4925   DEVCB_HANDLER(mo6_sys_porta_in),
4926   DEVCB_HANDLER(mo6_sys_portb_in),
4760   DEVCB_DRIVER_MEMBER(thomson_state, mo6_sys_porta_in),
4761   DEVCB_DRIVER_MEMBER(thomson_state, mo6_sys_portb_in),
49274762   DEVCB_NULL,
49284763   DEVCB_NULL,
49294764   DEVCB_NULL,
49304765   DEVCB_NULL,
4931   DEVCB_HANDLER(mo6_sys_porta_out),
4932   DEVCB_HANDLER(mo6_sys_portb_out),
4933   DEVCB_HANDLER(mo5_set_cassette_motor),
4934   DEVCB_HANDLER(mo6_sys_cb2_out),
4935   DEVCB_LINE(thom_firq_1),
4936   DEVCB_LINE(thom_irq_1) /* differs from TO */
4766   DEVCB_DRIVER_MEMBER(thomson_state, mo6_sys_porta_out),
4767   DEVCB_DRIVER_MEMBER(thomson_state, mo6_sys_portb_out),
4768   DEVCB_DRIVER_MEMBER(thomson_state, mo5_set_cassette_motor),
4769   DEVCB_DRIVER_MEMBER(thomson_state, mo6_sys_cb2_out),
4770   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1),
4771   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_irq_1) /* differs from TO */
49374772};
49384773
49394774
r21425r21426
49444779
49454780
49464781
4947READ8_HANDLER ( mo6_gatearray_r )
4782READ8_MEMBER( thomson_state::mo6_gatearray_r )
49484783{
4949   struct thom_vsignal v = thom_get_vsignal(space.machine());
4950   struct thom_vsignal l = thom_get_lightpen_vsignal( space.machine(), MO6_LIGHTPEN_DECAL, to7_lightpen_step - 1, 6 );
4784   struct thom_vsignal v = thom_get_vsignal();
4785   struct thom_vsignal l = thom_get_lightpen_vsignal( MO6_LIGHTPEN_DECAL, m_to7_lightpen_step - 1, 6 );
49514786   int count, inil, init, lt3;
49524787   UINT8 res;
4953   count = to7_lightpen ? l.count : v.count;
4954   inil  = to7_lightpen ? l.inil  : v.inil;
4955   init  = to7_lightpen ? l.init  : v.init;
4956   lt3   = to7_lightpen ? l.lt3   : v.lt3;
4788   count = m_to7_lightpen ? l.count : v.count;
4789   inil  = m_to7_lightpen ? l.inil  : v.inil;
4790   init  = m_to7_lightpen ? l.init  : v.init;
4791   lt3   = m_to7_lightpen ? l.lt3   : v.lt3;
49574792
49584793   switch ( offset )
49594794   {
49604795   case 0: /* system 2 / lightpen register 1 */
4961      if ( to7_lightpen )
4796      if ( m_to7_lightpen )
49624797         res = (count >> 8) & 0xff;
49634798      else
4964         res = to8_reg_sys2 & 0xf0;
4799         res = m_to8_reg_sys2 & 0xf0;
49654800      break;
49664801
49674802   case 1: /* ram register / lightpen register 2 */
4968      if ( to7_lightpen )
4803      if ( m_to7_lightpen )
49694804      {
49704805         if ( !space.debugger_access() )
49714806         {
4972            thom_firq_2( space.machine(), 0 );
4973            to8_lightpen_intr = 0;
4807            thom_firq_2( 0 );
4808            m_to8_lightpen_intr = 0;
49744809         }
49754810         res =  count & 0xff;
49764811      }
49774812      else
4978         res = to8_reg_ram & 0x1f;
4813         res = m_to8_reg_ram & 0x1f;
49794814      break;
49804815
49814816   case 2: /* cartrige register / lightpen register 3 */
4982      if ( to7_lightpen )
4817      if ( m_to7_lightpen )
49834818         res = (lt3 << 7) | (inil << 6);
49844819      else
49854820         res = 0;
49864821      break;
49874822
49884823   case 3: /* lightpen register 4 */
4989      res = (v.init << 7) | (init << 6) | (v.inil << 5) | (to8_lightpen_intr << 1) | to7_lightpen;
4824      res = (v.init << 7) | (init << 6) | (v.inil << 5) | (m_to8_lightpen_intr << 1) | m_to7_lightpen;
49904825      break;
49914826
49924827   default:
4993      logerror( "$%04x mo6_gatearray_r: invalid offset %i\n", space.machine().device("maincpu")->safe_pcbase(), offset );
4828      logerror( "$%04x mo6_gatearray_r: invalid offset %i\n", m_maincpu->pc(), offset );
49944829      res = 0;
49954830   }
49964831
49974832   LOG_VIDEO(( "$%04x %f mo6_gatearray_r: off=%i ($%04X) res=$%02X lightpen=%i\n",
4998         space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(),
4999         offset, 0xa7e4 + offset, res, to7_lightpen ));
4833         m_maincpu->pc(), machine().time().as_double(),
4834         offset, 0xa7e4 + offset, res, m_to7_lightpen ));
50004835
50014836   return res;
50024837}
50034838
50044839
50054840
5006WRITE8_HANDLER ( mo6_gatearray_w )
4841WRITE8_MEMBER( thomson_state::mo6_gatearray_w )
50074842{
50084843   LOG_VIDEO(( "$%04x %f mo6_gatearray_w: off=%i ($%04X) data=$%02X\n",
5009         space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(),
4844         m_maincpu->pc(), machine().time().as_double(),
50104845         offset, 0xa7e4 + offset, data ));
50114846
50124847   switch ( offset )
50134848   {
50144849   case 0: /* switch */
5015      to7_lightpen = data & 1;
4850      m_to7_lightpen = data & 1;
50164851      break;
50174852
50184853   case 1: /* ram register */
5019      if ( to8_reg_sys1 & 0x10 )
4854      if ( m_to8_reg_sys1 & 0x10 )
50204855      {
5021         to8_reg_ram = data;
5022         mo6_update_ram_bank(space.machine());
4856         m_to8_reg_ram = data;
4857         mo6_update_ram_bank();
50234858      }
50244859      break;
50254860
50264861   case 2: /* cartridge register */
5027      to8_reg_cart = data;
5028      mo6_update_cart_bank(space.machine());
4862      m_to8_reg_cart = data;
4863      mo6_update_cart_bank();
50294864      break;
50304865
50314866   case 3: /* system register 1 */
5032      to8_reg_sys1 = data;
5033      mo6_update_ram_bank(space.machine());
5034      mo6_update_cart_bank(space.machine());
4867      m_to8_reg_sys1 = data;
4868      mo6_update_ram_bank();
4869      mo6_update_cart_bank();
50354870      break;
50364871
50374872   default:
5038      logerror( "$%04x mo6_gatearray_w: invalid offset %i (data=$%02X)\n", space.machine().device("maincpu")->safe_pcbase(), offset, data );
4873      logerror( "$%04x mo6_gatearray_w: invalid offset %i (data=$%02X)\n", m_maincpu->pc(), offset, data );
50394874   }
50404875}
50414876
r21425r21426
50444879
50454880
50464881
5047READ8_HANDLER ( mo6_vreg_r )
4882READ8_MEMBER( thomson_state::mo6_vreg_r )
50484883{
50494884   /* 0xa7dc from external floppy drive aliases the video gate-array */
5050   if ( ( offset == 3 ) && ( to8_reg_ram & 0x80 ) )
4885   if ( ( offset == 3 ) && ( m_to8_reg_ram & 0x80 ) )
50514886      {
50524887      if ( !space.debugger_access() )
50534888         return to7_floppy_r( space, 0xc );
r21425r21426
50714906
50724907
50734908
5074WRITE8_HANDLER ( mo6_vreg_w )
4909WRITE8_MEMBER( thomson_state::mo6_vreg_w )
50754910{
50764911   LOG_VIDEO(( "$%04x %f mo6_vreg_w: off=%i ($%04X) data=$%02X\n",
5077         space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(),
4912         m_maincpu->pc(), machine().time().as_double(),
50784913         offset, 0xa7da + offset, data ));
50794914
50804915   switch ( offset )
r21425r21426
50854920      return;
50864921
50874922   case 2: /* display / external floppy register */
5088      if ( ( to8_reg_sys1 & 0x80 ) && ( to8_reg_ram & 0x80 ) )
4923      if ( ( m_to8_reg_sys1 & 0x80 ) && ( m_to8_reg_ram & 0x80 ) )
50894924         to7_floppy_w( space, 0xc, data );
50904925      else
5091         to9_set_video_mode( space.machine(), data, 2 );
4926         to9_set_video_mode( data, 2 );
50924927      break;
50934928
50944929   case 3: /* system register 2 */
50954930      /* 0xa7dc from external floppy drive aliases the video gate-array */
5096      if ( ( offset == 3 ) && ( to8_reg_ram & 0x80 ) )
4931      if ( ( offset == 3 ) && ( m_to8_reg_ram & 0x80 ) )
50974932         to7_floppy_w( space, 0xc, data );
50984933      else
50994934      {
5100         to8_reg_sys2 = data;
5101         thom_set_video_page( space.machine(), data >> 6 );
5102         thom_set_border_color( space.machine(), data & 15 );
5103         mo6_update_cart_bank(space.machine());
4935         m_to8_reg_sys2 = data;
4936         thom_set_video_page( data >> 6 );
4937         thom_set_border_color( data & 15 );
4938         mo6_update_cart_bank();
51044939      }
51054940      break;
51064941
r21425r21426
51154950
51164951
51174952
5118MACHINE_RESET ( mo6 )
4953MACHINE_RESET_MEMBER( thomson_state, mo6 )
51194954{
5120   pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS );
51214955   LOG (( "mo6: machine reset called\n" ));
51224956
51234957   /* subsystems */
5124   thom_irq_reset(machine);
5125   sys_pia->set_port_a_z_mask( 0x75 );
5126   mo6_game_reset(machine);
5127   to7_floppy_reset(machine);
5128   to7_modem_reset(machine);
5129   to7_midi_reset(machine);
5130   mo5_init_timer(machine);
4958   thom_irq_reset();
4959   m_pia_sys->set_port_a_z_mask( 0x75 );
4960   mo6_game_reset();
4961   to7_floppy_reset();
4962   to7_modem_reset();
4963   to7_midi_reset();
4964   mo5_init_timer();
51314965
51324966   /* gate-array */
5133   to7_lightpen = 0;
5134   to8_reg_ram = 0;
5135   to8_reg_cart = 0;
5136   to8_reg_sys1 = 0;
5137   to8_reg_sys2 = 0;
5138   to8_lightpen_intr = 0;
4967   m_to7_lightpen = 0;
4968   m_to8_reg_ram = 0;
4969   m_to8_reg_cart = 0;
4970   m_to8_reg_sys1 = 0;
4971   m_to8_reg_sys2 = 0;
4972   m_to8_lightpen_intr = 0;
51394973
51404974   /* video */
5141   thom_set_video_mode( machine, THOM_VMODE_MO5 );
5142   thom_set_lightpen_callback( machine, 3, to8_lightpen_cb );
5143   thom_set_border_color( machine, 0 );
5144   thom_set_mode_point( machine, 0 );
5145   sys_pia->ca1_w( 0 );
4975   thom_set_video_mode( THOM_VMODE_MO5 );
4976   m_thom_lightpen_cb = &thomson_state::to8_lightpen_cb;
4977   thom_set_lightpen_callback( 3 );
4978   thom_set_border_color( 0 );
4979   thom_set_mode_point( 0 );
4980   m_pia_sys->ca1_w( 0 );
51464981
51474982   /* memory */
5148   old_ram_bank = -1;
5149   old_cart_bank = -1;
5150   to8_cart_vpage = 0;
5151   to8_data_vpage = 0;
5152   mo6_update_ram_bank(machine);
5153   mo6_update_cart_bank(machine);
4983   m_old_ram_bank = -1;
4984   m_old_cart_bank = -1;
4985   m_to8_cart_vpage = 0;
4986   m_to8_data_vpage = 0;
4987   mo6_update_ram_bank();
4988   mo6_update_cart_bank();
51544989   /* mo5_reg_cart not reset */
51554990   /* thom_cart_bank not reset */
51564991}
51574992
51584993
51594994
5160MACHINE_START ( mo6 )
4995MACHINE_START_MEMBER( thomson_state, mo6 )
51614996{
5162   UINT8* mem = machine.root_device().memregion("maincpu")->base();
5163   UINT8* ram = machine.device<ram_device>(RAM_TAG)->pointer();
4997   UINT8* mem = memregion("maincpu")->base();
4998   UINT8* ram = m_ram->pointer();
51644999
51655000   LOG (( "mo6: machine start called\n" ));
51665001
51675002   /* subsystems */
5168   thom_irq_init(machine);
5169   mo6_game_init(machine);
5170   to7_floppy_init( machine, mem + 0x30000 );
5171   to9_palette_init(machine);
5172   to7_modem_init(machine);
5173   to7_midi_init(machine);
5174   mo5_periodic_timer = machine.scheduler().timer_alloc(FUNC(mo5_periodic_cb));
5003   thom_irq_init();
5004   mo6_game_init();
5005   to7_floppy_init( mem + 0x30000 );
5006   to9_palette_init();
5007   to7_modem_init();
5008   to7_midi_init();
5009   m_mo5_periodic_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::mo5_periodic_cb),this));
51755010
51765011   /* memory */
5177   thom_cart_bank = 0;
5178   mo5_reg_cart = 0;
5179   thom_vram = ram;
5180   machine.root_device().membank( THOM_CART_BANK )->configure_entries( 0, 4, mem + 0x10000, 0x4000 );
5181   machine.root_device().membank( THOM_CART_BANK )->configure_entries( 4, 2, mem + 0x1f000, 0x4000 );
5182   machine.root_device().membank( THOM_CART_BANK )->configure_entries( 6, 2, mem + 0x28000, 0x4000 );
5183   machine.root_device().membank( THOM_CART_BANK )->configure_entries( 8, 8, ram, 0x4000 );
5184   machine.root_device().membank( THOM_VRAM_BANK )->configure_entries( 0, 2, ram, 0x2000 );
5185   machine.root_device().membank( TO8_SYS_LO )->configure_entry( 0, ram + 0x6000);
5186   machine.root_device().membank( TO8_SYS_HI )->configure_entry( 0, ram + 0x4000);
5187   machine.root_device().membank( TO8_DATA_LO )->configure_entries( 0, 8, ram + 0x2000, 0x4000 );
5188   machine.root_device().membank( TO8_DATA_HI )->configure_entries( 0, 8, ram + 0x0000, 0x4000 );
5189   machine.root_device().membank( TO8_BIOS_BANK )->configure_entries( 0, 2, mem + 0x23000, 0x4000 );
5190   machine.root_device().membank( THOM_CART_BANK )->set_entry( 0 );
5191   machine.root_device().membank( THOM_VRAM_BANK )->set_entry( 0 );
5192   machine.root_device().membank( TO8_SYS_LO )->set_entry( 0 );
5193   machine.root_device().membank( TO8_SYS_HI )->set_entry( 0 );
5194   machine.root_device().membank( TO8_DATA_LO )->set_entry( 0 );
5195   machine.root_device().membank( TO8_DATA_HI )->set_entry( 0 );
5196   machine.root_device().membank( TO8_BIOS_BANK )->set_entry( 0 );
5012   m_thom_cart_bank = 0;
5013   m_mo5_reg_cart = 0;
5014   m_thom_vram = ram;
5015   membank( THOM_CART_BANK )->configure_entries( 0, 4, mem + 0x10000, 0x4000 );
5016   membank( THOM_CART_BANK )->configure_entries( 4, 2, mem + 0x1f000, 0x4000 );
5017   membank( THOM_CART_BANK )->configure_entries( 6, 2, mem + 0x28000, 0x4000 );
5018   membank( THOM_CART_BANK )->configure_entries( 8, 8, ram, 0x4000 );
5019   membank( THOM_VRAM_BANK )->configure_entries( 0, 2, ram, 0x2000 );
5020   membank( TO8_SYS_LO )->configure_entry( 0, ram + 0x6000);
5021   membank( TO8_SYS_HI )->configure_entry( 0, ram + 0x4000);
5022   membank( TO8_DATA_LO )->configure_entries( 0, 8, ram + 0x2000, 0x4000 );
5023   membank( TO8_DATA_HI )->configure_entries( 0, 8, ram + 0x0000, 0x4000 );
5024   membank( TO8_BIOS_BANK )->configure_entries( 0, 2, mem + 0x23000, 0x4000 );
5025   membank( THOM_CART_BANK )->set_entry( 0 );
5026   membank( THOM_VRAM_BANK )->set_entry( 0 );
5027   membank( TO8_SYS_LO )->set_entry( 0 );
5028   membank( TO8_SYS_HI )->set_entry( 0 );
5029   membank( TO8_DATA_LO )->set_entry( 0 );
5030   membank( TO8_DATA_HI )->set_entry( 0 );
5031   membank( TO8_BIOS_BANK )->set_entry( 0 );
51975032
51985033   /* save-state */
5199   state_save_register_global( machine, thom_cart_nb_banks );
5200   state_save_register_global( machine, thom_cart_bank );
5201   state_save_register_global( machine, to7_lightpen );
5202   state_save_register_global( machine, to7_lightpen_step );
5203   state_save_register_global( machine, to8_reg_ram );
5204   state_save_register_global( machine, to8_reg_cart );
5205   state_save_register_global( machine, to8_reg_sys1 );
5206   state_save_register_global( machine, to8_reg_sys2 );
5207   state_save_register_global( machine, to8_lightpen_intr );
5208   state_save_register_global( machine, to8_data_vpage );
5209   state_save_register_global( machine, to8_cart_vpage );
5210   state_save_register_global( machine, mo5_reg_cart );
5211   state_save_register_global_pointer( machine, (mem + 0x10000), 0x10000 );
5212   machine.save().register_postload(save_prepost_delegate(FUNC(mo6_update_ram_bank_postload), &machine));
5213   machine.save().register_postload(save_prepost_delegate(FUNC(mo6_update_cart_bank_postload), &machine));
5034   save_item(NAME(m_thom_cart_nb_banks));
5035   save_item(NAME(m_thom_cart_bank));
5036   save_item(NAME(m_to7_lightpen));
5037   save_item(NAME(m_to7_lightpen_step));
5038   save_item(NAME(m_to8_reg_ram));
5039   save_item(NAME(m_to8_reg_cart));
5040   save_item(NAME(m_to8_reg_sys1));
5041   save_item(NAME(m_to8_reg_sys2));
5042   save_item(NAME(m_to8_lightpen_intr));
5043   save_item(NAME(m_to8_data_vpage));
5044   save_item(NAME(m_to8_cart_vpage));
5045   save_item(NAME(m_mo5_reg_cart));
5046   state_save_register_global_pointer( machine(), (mem + 0x10000), 0x10000 );
5047   machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::mo6_update_ram_bank_postload), this));
5048   machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::mo6_update_cart_bank_postload), this));
52145049}
52155050
52165051
r21425r21426
52235058
52245059
52255060
5226READ8_HANDLER ( mo5nr_net_r )
5061READ8_MEMBER( thomson_state::mo5nr_net_r )
52275062{
52285063   if ( space.debugger_access() )
52295064      return 0;
r21425r21426
52315066   if ( to7_controller_type )
52325067      return to7_floppy_r ( space, offset );
52335068
5234   logerror( "$%04x %f mo5nr_net_r: read from reg %i\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), offset );
5069   logerror( "$%04x %f mo5nr_net_r: read from reg %i\n", m_maincpu->pc(), machine().time().as_double(), offset );
52355070
52365071   return 0;
52375072}
52385073
52395074
52405075
5241WRITE8_HANDLER ( mo5nr_net_w )
5076WRITE8_MEMBER( thomson_state::mo5nr_net_w )
52425077{
52435078   if ( to7_controller_type )
52445079      to7_floppy_w ( space, offset, data );
52455080   else
52465081      logerror( "$%04x %f mo5nr_net_w: write $%02X to reg %i\n",
5247            space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), data, offset );
5082            m_maincpu->pc(), machine().time().as_double(), data, offset );
52485083}
52495084
52505085
r21425r21426
52555090*/
52565091
52575092
5258READ8_HANDLER( mo5nr_prn_r )
5093READ8_MEMBER( thomson_state::mo5nr_prn_r )
52595094{
5260   centronics_device *printer = space.machine().device<centronics_device>("centronics");
52615095   UINT8 result = 0;
52625096
5263   result |= !printer->busy_r() << 7;
5097   result |= !m_centronics->busy_r() << 7;
52645098
52655099   return result;
52665100}
52675101
52685102
5269WRITE8_HANDLER( mo5nr_prn_w )
5103WRITE8_MEMBER( thomson_state::mo5nr_prn_w )
52705104{
5271   centronics_device *printer = space.machine().device<centronics_device>("centronics");
5272
52735105   /* TODO: understand other bits */
5274   printer->strobe_w(BIT(data, 3));
5106   m_centronics->strobe_w(BIT(data, 3));
52755107}
52765108
52775109
r21425r21426
52805112
52815113
52825114
5283static READ8_DEVICE_HANDLER ( mo5nr_sys_portb_in )
5115READ8_MEMBER( thomson_state::mo5nr_sys_portb_in )
52845116{
52855117   /* keyboard: only 8 lines of 8 keys (MO6 has 9 lines) */
5286   UINT8 portb = downcast<pia6821_device *>(device)->b_output();
5118   UINT8 portb = m_pia_sys->b_output();
52875119   int col = (portb >> 4) & 7;    /* B bits 4-6: kbd column */
52885120   int lin = (portb >> 1) & 7;    /* B bits 1-3: kbd line */
52895121   static const char *const keynames[] = {
r21425r21426
52915123      "keyboard_4", "keyboard_5", "keyboard_6", "keyboard_7"
52925124   };
52935125
5294   return ( space.machine().root_device().ioport(keynames[lin])->read() & (1 << col) ) ? 0x80 : 0;
5126   return ( ioport(keynames[lin])->read() & (1 << col) ) ? 0x80 : 0;
52955127   /* bit 7: key up */
52965128}
52975129
52985130
52995131
5300static WRITE8_DEVICE_HANDLER ( mo5nr_sys_porta_out )
5132WRITE8_MEMBER( thomson_state::mo5nr_sys_porta_out )
53015133{
53025134   /* no keyboard LED */
5303   thom_set_mode_point( space.machine(), data & 1 );           /* bit 0: video bank switch */
5304   to7_game_mute = data & 4;                       /* bit 2: sound mute */
5305   mo5_set_cassette( space.machine(), (data & 0x40) ? 1 : 0 );     /* bit 6: cassette output */
5306   mo6_update_cart_bank(space.machine());                  /* bit 5: rom bank */
5307   to7_game_sound_update(space.machine());
5135   thom_set_mode_point( data & 1 );           /* bit 0: video bank switch */
5136   m_to7_game_mute = data & 4;                       /* bit 2: sound mute */
5137   mo5_set_cassette( (data & 0x40) ? 1 : 0 );     /* bit 6: cassette output */
5138   mo6_update_cart_bank();                  /* bit 5: rom bank */
5139   to7_game_sound_update();
53085140}
53095141
53105142
53115143
53125144const pia6821_interface mo5nr_pia6821_sys =
53135145{
5314   DEVCB_HANDLER(mo6_sys_porta_in),
5315   DEVCB_HANDLER(mo5nr_sys_portb_in),
5146   DEVCB_DRIVER_MEMBER(thomson_state, mo6_sys_porta_in),
5147   DEVCB_DRIVER_MEMBER(thomson_state, mo5nr_sys_portb_in),
53165148   DEVCB_NULL,
53175149   DEVCB_NULL,
53185150   DEVCB_NULL,
53195151   DEVCB_NULL,
5320   DEVCB_HANDLER(mo5nr_sys_porta_out),
5321   DEVCB_HANDLER(mo6_sys_portb_out),
5322   DEVCB_HANDLER(mo5_set_cassette_motor),
5323   DEVCB_HANDLER(mo6_sys_cb2_out),
5324   DEVCB_LINE(thom_firq_1),
5325   DEVCB_LINE(thom_irq_1) /* differs from TO */
5152   DEVCB_DRIVER_MEMBER(thomson_state, mo5nr_sys_porta_out),
5153   DEVCB_DRIVER_MEMBER(thomson_state, mo6_sys_portb_out),
5154   DEVCB_DRIVER_MEMBER(thomson_state, mo5_set_cassette_motor),
5155   DEVCB_DRIVER_MEMBER(thomson_state, mo6_sys_cb2_out),
5156   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1),
5157   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_irq_1) /* differs from TO */
53265158};
53275159
53285160
r21425r21426
53365168
53375169const pia6821_interface mo5nr_pia6821_game =
53385170{
5339   DEVCB_HANDLER(to7_game_porta_in),
5340   DEVCB_HANDLER(to7_game_portb_in),
5171   DEVCB_DRIVER_MEMBER(thomson_state, to7_game_porta_in),
5172   DEVCB_DRIVER_MEMBER(thomson_state, to7_game_portb_in),
53415173   DEVCB_NULL,
53425174   DEVCB_NULL,
53435175   DEVCB_NULL,
53445176   DEVCB_NULL,
5345   DEVCB_HANDLER(mo6_game_porta_out),
5346   DEVCB_HANDLER(to7_game_portb_out),
5177   DEVCB_DRIVER_MEMBER(thomson_state, mo6_game_porta_out),
5178   DEVCB_DRIVER_MEMBER(thomson_state, to7_game_portb_out),
53475179   DEVCB_NULL,
53485180   DEVCB_NULL,
5349   DEVCB_LINE(thom_irq_1),
5350   DEVCB_LINE(thom_irq_1)
5181   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_irq_1),
5182   DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_irq_1)
53515183};
53525184
53535185
53545186
5355static void mo5nr_game_init ( running_machine &machine )
5187void thomson_state::mo5nr_game_init()
53565188{
53575189   LOG (( "mo5nr_game_init called\n" ));
5358   to7_game_timer = machine.scheduler().timer_alloc(FUNC(mo6_game_update_cb));
5359   to7_game_timer->adjust( TO7_GAME_POLL_PERIOD, 0, TO7_GAME_POLL_PERIOD );
5360   state_save_register_global( machine, to7_game_sound );
5361   state_save_register_global( machine, to7_game_mute );
5190   m_to7_game_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::mo6_game_update_cb),this));
5191   m_to7_game_timer->adjust( TO7_GAME_POLL_PERIOD, 0, TO7_GAME_POLL_PERIOD );
5192   save_item(NAME(m_to7_game_sound));
5193   save_item(NAME(m_to7_game_mute));
53625194}
53635195
53645196
53655197
5366static void mo5nr_game_reset ( running_machine &machine )
5198void thomson_state::mo5nr_game_reset()
53675199{
5368   pia6821_device *game_pia = machine.device<pia6821_device>(THOM_PIA_GAME);
53695200   LOG (( "mo5nr_game_reset called\n" ));
5370   game_pia->ca1_w( 0 );
5371   to7_game_sound = 0;
5372   to7_game_mute = 0;
5373   to7_game_sound_update(machine);
5201   m_pia_game->ca1_w( 0 );
5202   m_to7_game_sound = 0;
5203   m_to7_game_mute = 0;
5204   to7_game_sound_update();
53745205}
53755206
53765207
r21425r21426
53795210
53805211
53815212
5382MACHINE_RESET ( mo5nr )
5213MACHINE_RESET_MEMBER( thomson_state, mo5nr )
53835214{
5384   pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS );
53855215   LOG (( "mo5nr: machine reset called\n" ));
53865216
53875217   /* subsystems */
5388   thom_irq_reset(machine);
5389   sys_pia->set_port_a_z_mask( 0x65 );
5390   mo5nr_game_reset(machine);
5391   to7_floppy_reset(machine);
5392   to7_modem_reset(machine);
5393   to7_midi_reset(machine);
5394   mo5_init_timer(machine);
5218   thom_irq_reset();
5219   m_pia_sys->set_port_a_z_mask( 0x65 );
5220   mo5nr_game_reset();
5221   to7_floppy_reset();
5222   to7_modem_reset();
5223   to7_midi_reset();
5224   mo5_init_timer();
53955225
53965226   /* gate-array */
5397   to7_lightpen = 0;
5398   to8_reg_ram = 0;
5399   to8_reg_cart = 0;
5400   to8_reg_sys1 = 0;
5401   to8_reg_sys2 = 0;
5402   to8_lightpen_intr = 0;
5227   m_to7_lightpen = 0;
5228   m_to8_reg_ram = 0;
5229   m_to8_reg_cart = 0;
5230   m_to8_reg_sys1 = 0;
5231   m_to8_reg_sys2 = 0;
5232   m_to8_lightpen_intr = 0;
54035233
54045234   /* video */
5405   thom_set_video_mode( machine, THOM_VMODE_MO5 );
5406   thom_set_lightpen_callback( machine, 3, to8_lightpen_cb );
5407   thom_set_border_color( machine, 0 );
5408   thom_set_mode_point( machine, 0 );
5409   sys_pia->ca1_w( 0 );
5235   thom_set_video_mode( THOM_VMODE_MO5 );
5236   m_thom_lightpen_cb = &thomson_state::to8_lightpen_cb;
5237   thom_set_lightpen_callback( 3 );
5238   thom_set_border_color( 0 );
5239   thom_set_mode_point( 0 );
5240   m_pia_sys->ca1_w( 0 );
54105241
54115242   /* memory */
5412   old_ram_bank = -1;
5413   old_cart_bank = -1;
5414   to8_cart_vpage = 0;
5415   to8_data_vpage = 0;
5416   mo6_update_ram_bank(machine);
5417   mo6_update_cart_bank(machine);
5243   m_old_ram_bank = -1;
5244   m_old_cart_bank = -1;
5245   m_to8_cart_vpage = 0;
5246   m_to8_data_vpage = 0;
5247   mo6_update_ram_bank();
5248   mo6_update_cart_bank();
54185249   /* mo5_reg_cart not reset */
54195250   /* thom_cart_bank not reset */
54205251}
54215252
54225253
54235254
5424MACHINE_START ( mo5nr )
5255MACHINE_START_MEMBER( thomson_state, mo5nr )
54255256{
5426   UINT8* mem = machine.root_device().memregion("maincpu")->base();
5427   UINT8* ram = machine.device<ram_device>(RAM_TAG)->pointer();
5257   UINT8* mem = memregion("maincpu")->base();
5258   UINT8* ram = m_ram->pointer();
54285259
54295260   LOG (( "mo5nr: machine start called\n" ));
54305261
54315262   /* subsystems */
5432   thom_irq_init(machine);
5433   mo5nr_game_init(machine);
5434   to7_floppy_init( machine, mem + 0x30000 );
5435   to9_palette_init(machine);
5436   to7_modem_init(machine);
5437   to7_midi_init(machine);
5438   mo5_periodic_timer = machine.scheduler().timer_alloc(FUNC(mo5_periodic_cb));
5263   thom_irq_init();
5264   mo5nr_game_init();
5265   to7_floppy_init( mem + 0x30000 );
5266   to9_palette_init();
5267   to7_modem_init();
5268   to7_midi_init();
5269   m_mo5_periodic_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::mo5_periodic_cb),this));
54395270
54405271   /* memory */
5441   thom_cart_bank = 0;
5442   mo5_reg_cart = 0;
5443   thom_vram = ram;
5444   machine.root_device().membank( THOM_CART_BANK )->configure_entries( 0, 4, mem + 0x10000, 0x4000 );
5445   machine.root_device().membank( THOM_CART_BANK )->configure_entries( 4, 2, mem + 0x1f000, 0x4000 );
5446   machine.root_device().membank( THOM_CART_BANK )->configure_entries( 6, 2, mem + 0x28000, 0x4000 );
5447   machine.root_device().membank( THOM_CART_BANK )->configure_entries( 8, 8, ram, 0x4000 );
5448   machine.root_device().membank( THOM_VRAM_BANK )->configure_entries( 0, 2, ram, 0x2000 );
5449   machine.root_device().membank( TO8_SYS_LO )->configure_entry( 0, ram + 0x6000);
5450   machine.root_device().membank( TO8_SYS_HI )->configure_entry( 0, ram + 0x4000);
5451   machine.root_device().membank( TO8_DATA_LO )->configure_entries( 0, 8, ram + 0x2000, 0x4000 );
5452   machine.root_device().membank( TO8_DATA_HI )->configure_entries( 0, 8, ram + 0x0000, 0x4000 );
5453   machine.root_device().membank( TO8_BIOS_BANK )->configure_entries( 0, 2, mem + 0x23000, 0x4000 );
5454   machine.root_device().membank( THOM_CART_BANK )->set_entry( 0 );
5455   machine.root_device().membank( THOM_VRAM_BANK )->set_entry( 0 );
5456   machine.root_device().membank( TO8_SYS_LO )->set_entry( 0 );
5457   machine.root_device().membank( TO8_SYS_HI )->set_entry( 0 );
5458   machine.root_device().membank( TO8_DATA_LO )->set_entry( 0 );
5459   machine.root_device().membank( TO8_DATA_HI )->set_entry( 0 );
5460   machine.root_device().membank( TO8_BIOS_BANK )->set_entry( 0 );
5272   m_thom_cart_bank = 0;
5273   m_mo5_reg_cart = 0;
5274   m_thom_vram = ram;
5275   membank( THOM_CART_BANK )->configure_entries( 0, 4, mem + 0x10000, 0x4000 );
5276   membank( THOM_CART_BANK )->configure_entries( 4, 2, mem + 0x1f000, 0x4000 );
5277   membank( THOM_CART_BANK )->configure_entries( 6, 2, mem + 0x28000, 0x4000 );
5278   membank( THOM_CART_BANK )->configure_entries( 8, 8, ram, 0x4000 );
5279   membank( THOM_VRAM_BANK )->configure_entries( 0, 2, ram, 0x2000 );
5280   membank( TO8_SYS_LO )->configure_entry( 0, ram + 0x6000);
5281   membank( TO8_SYS_HI )->configure_entry( 0, ram + 0x4000);
5282   membank( TO8_DATA_LO )->configure_entries( 0, 8, ram + 0x2000, 0x4000 );
5283   membank( TO8_DATA_HI )->configure_entries( 0, 8, ram + 0x0000, 0x4000 );
5284   membank( TO8_BIOS_BANK )->configure_entries( 0, 2, mem + 0x23000, 0x4000 );
5285   membank( THOM_CART_BANK )->set_entry( 0 );
5286   membank( THOM_VRAM_BANK )->set_entry( 0 );
5287   membank( TO8_SYS_LO )->set_entry( 0 );
5288   membank( TO8_SYS_HI )->set_entry( 0 );
5289   membank( TO8_DATA_LO )->set_entry( 0 );
5290   membank( TO8_DATA_HI )->set_entry( 0 );
5291   membank( TO8_BIOS_BANK )->set_entry( 0 );
54615292
54625293   /* save-state */
5463   state_save_register_global( machine, thom_cart_nb_banks );
5464   state_save_register_global( machine, thom_cart_bank );
5465   state_save_register_global( machine, to7_lightpen );
5466   state_save_register_global( machine, to7_lightpen_step );
5467   state_save_register_global( machine, to8_reg_ram );
5468   state_save_register_global( machine, to8_reg_cart );
5469   state_save_register_global( machine, to8_reg_sys1 );
5470   state_save_register_global( machine, to8_reg_sys2 );
5471   state_save_register_global( machine, to8_lightpen_intr );
5472   state_save_register_global( machine, to8_data_vpage );
5473   state_save_register_global( machine, to8_cart_vpage );
5474   state_save_register_global( machine, mo5_reg_cart );
5475   state_save_register_global_pointer( machine, (mem + 0x10000), 0x10000 );
5476   machine.save().register_postload(save_prepost_delegate(FUNC(mo6_update_ram_bank_postload), &machine));
5477   machine.save().register_postload(save_prepost_delegate(FUNC(mo6_update_cart_bank_postload), &machine));
5294   save_item(NAME(m_thom_cart_nb_banks));
5295   save_item(NAME(m_thom_cart_bank));
5296   save_item(NAME(m_to7_lightpen));
5297   save_item(NAME(m_to7_lightpen_step));
5298   save_item(NAME(m_to8_reg_ram));
5299   save_item(NAME(m_to8_reg_cart));
5300   save_item(NAME(m_to8_reg_sys1));
5301   save_item(NAME(m_to8_reg_sys2));
5302   save_item(NAME(m_to8_lightpen_intr));
5303   save_item(NAME(m_to8_data_vpage));
5304   save_item(NAME(m_to8_cart_vpage));
5305   save_item(NAME(m_mo5_reg_cart));
5306   state_save_register_global_pointer( machine(), (mem + 0x10000), 0x10000 );
5307   machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::mo6_update_ram_bank_postload), this));
5308   machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::mo6_update_cart_bank_postload), this));
54785309}
trunk/src/mess/video/thomson.c
r21425r21426
2626
2727/****************** dynamic screen size *****************/
2828
29/* We allow choosing dynamically:
30   - the border size
31   - whether we use 640 pixels or 320 pixels in an active row
32   (now this is automatically choosen by default for each frame)
33*/
3429
35
36
37static UINT16 thom_bwidth;
38static UINT16 thom_bheight;
39/* border size */
40
41
42static UINT8  thom_hires;
43/* 0 = low res: 320x200 active area (faster)
44   1 = hi res:  640x200 active area (can represent all video modes)
45*/
46
47
48static UINT8 thom_hires_better;
49/* 1 = a 640 mode was used in the last frame */
50
51
52
53static int thom_update_screen_size( running_machine &machine )
30int thomson_state::thom_update_screen_size()
5431{
55   screen_device *screen = machine.first_screen();
32   screen_device *screen = machine().first_screen();
5633   const rectangle &visarea = screen->visible_area();
57   UINT8 p = machine.root_device().ioport("vconfig")->read();
34   UINT8 p = ioport("vconfig")->read();
5835   int new_w, new_h, changed = 0;
5936
6037   switch ( p & 3 )
6138   {
62   case 0:  thom_bwidth = 56; thom_bheight = 47; break; /* as in original (?) */
63   case 1:  thom_bwidth = 16; thom_bheight = 16; break; /* small */
64   default: thom_bwidth =  0; thom_bheight =  0; break; /* none */
39   case 0:  m_thom_bwidth = 56; m_thom_bheight = 47; break; /* as in original (?) */
40   case 1:  m_thom_bwidth = 16; m_thom_bheight = 16; break; /* small */
41   default: m_thom_bwidth =  0; m_thom_bheight =  0; break; /* none */
6542   }
6643
6744   switch ( p & 0xc )
6845   {
69   case 0:  thom_hires = 0; break;                 /* low */
70   case 4:  thom_hires = 1; break;                 /* high */
71   default: thom_hires = thom_hires_better; break; /* auto */
46   case 0:  m_thom_hires = 0; break;                 /* low */
47   case 4:  m_thom_hires = 1; break;                 /* high */
48   default: m_thom_hires = m_thom_hires_better; break; /* auto */
7249   }
7350
74   new_w = ( 320 + thom_bwidth * 2 ) * ( thom_hires + 1 ) - 1;
75   new_h = ( 200 + thom_bheight * 2 ) /** (thom_hires + 1 )*/ - 1;
51   new_w = ( 320 + m_thom_bwidth * 2 ) * ( m_thom_hires + 1 ) - 1;
52   new_h = ( 200 + m_thom_bheight * 2 ) /** (m_thom_hires + 1 )*/ - 1;
7653   if ( ( visarea.max_x != new_w ) || ( visarea.max_y != new_h ) )
7754   {
7855      changed = 1;
79      machine.primary_screen->set_visible_area(0, new_w, 0, new_h );
56      machine().primary_screen->set_visible_area(0, new_w, 0, new_h );
8057   }
8158
8259   return changed;
r21425r21426
8663
8764/*********************** video timing ******************************/
8865
89/* we use our own video timing to precisely cope with VBLANK and HBLANK */
9066
91
92
93static emu_timer* thom_video_timer; /* time elapsed from beginning of frame */
94
95
96
9767/* elapsed time from beginning of frame, in us */
98INLINE unsigned thom_video_elapsed ( running_machine &machine )
68unsigned thomson_state::thom_video_elapsed()
9969{
10070   unsigned u;
101   attotime elapsed = thom_video_timer ->elapsed( );
71   attotime elapsed = m_thom_video_timer->elapsed();
10272   u = (elapsed * 1000000 ).seconds;
10373   if ( u >= 19968 )
10474      u = 19968;
r21425r21426
10777
10878
10979
110struct thom_vsignal thom_get_vsignal ( running_machine &machine )
80struct thom_vsignal thomson_state::thom_get_vsignal()
11181{
11282   struct thom_vsignal v;
113   int gpl = thom_video_elapsed( machine ) - 64 * THOM_BORDER_HEIGHT - 7;
83   int gpl = thom_video_elapsed() - 64 * THOM_BORDER_HEIGHT - 7;
11484   if ( gpl < 0 )
11585      gpl += 19968;
11686
r21425r21426
133103
134104
135105
136static void thom_get_lightpen_pos( running_machine &machine, int*x, int* y )
106void thomson_state::thom_get_lightpen_pos( int*x, int* y )
137107{
138   *x = machine.root_device().ioport("lightpen_x")->read();
139   *y = machine.root_device().ioport("lightpen_y")->read();
108   *x = ioport("lightpen_x")->read();
109   *y = ioport("lightpen_y")->read();
140110
141111   if ( *x < 0 )
142112      *x = 0;
r21425r21426
144114   if ( *y < 0 )
145115      *y = 0;
146116
147   if ( *x > 2 * thom_bwidth  + 319 )
148      *x = 2 * thom_bwidth  + 319;
117   if ( *x > 2 * m_thom_bwidth  + 319 )
118      *x = 2 * m_thom_bwidth  + 319;
149119
150   if ( *y > 2 * thom_bheight + 199 )
151      *y = 2 * thom_bheight + 199;
120   if ( *y > 2 * m_thom_bheight + 199 )
121      *y = 2 * m_thom_bheight + 199;
152122}
153123
154124
155125
156struct thom_vsignal thom_get_lightpen_vsignal ( running_machine &machine, int xdec, int ydec, int xdec2 )
126struct thom_vsignal thomson_state::thom_get_lightpen_vsignal( int xdec, int ydec, int xdec2 )
157127{
158128   struct thom_vsignal v;
159129   int x, y;
160130   int gpl;
161131
162   thom_get_lightpen_pos( machine, &x, &y );
163   x += xdec - thom_bwidth;
164   y += ydec - thom_bheight;
132   thom_get_lightpen_pos( &x, &y );
133   x += xdec - m_thom_bwidth;
134   y += ydec - m_thom_bheight;
165135
166136   gpl = (x >> 3) + y * 64;
167137   if ( gpl < 0 )
r21425r21426
188158
189159
190160
191/* number of lightpen call-backs per frame */
192static int thom_lightpen_nb;
193
194
195/* called thom_lightpen_nb times */
196static emu_timer *thom_lightpen_timer;
197
198
199/* lightpen callback function to call from timer */
200static void (*thom_lightpen_cb) ( running_machine &machine, int );
201
202
203
204void thom_set_lightpen_callback ( running_machine &machine, int nb, void (*cb) ( running_machine &machine, int step ) )
161void thomson_state::thom_set_lightpen_callback( int nb )
205162{
206   LOG (( "%f thom_set_lightpen_callback called\n", machine.time().as_double()));
207   thom_lightpen_nb = nb;
208   thom_lightpen_cb = cb;
163   LOG (( "%f thom_set_lightpen_callback called\n", machine().time().as_double()));
164   m_thom_lightpen_nb = nb;
209165}
210166
211static TIMER_CALLBACK( thom_lightpen_step )
167TIMER_CALLBACK_MEMBER( thomson_state::thom_lightpen_step )
212168{
213169   int step = param;
214170
215   if ( thom_lightpen_cb )
216      thom_lightpen_cb( machine, step );
171   if ( m_thom_lightpen_cb )
172      (this->*m_thom_lightpen_cb)( step );
217173
218   if ( step < thom_lightpen_nb )
219      thom_lightpen_timer->adjust(attotime::from_usec( 64 ), step + 1);
174   if ( step < m_thom_lightpen_nb )
175      m_thom_lightpen_timer->adjust(attotime::from_usec( 64 ), step + 1);
220176}
221177
222178
r21425r21426
242198/* ---------------- state & state changes ---------------- */
243199
244200
245
246UINT8* thom_vram; /* pointer to video memory */
247
248static emu_timer* thom_scanline_timer; /* scan-line udpate */
249
250static UINT16 thom_last_pal[16];   /* palette at last scanline start */
251static UINT16 thom_pal[16];        /* current palette */
252static UINT8  thom_pal_changed;    /* whether pal != old_pal */
253static UINT8  thom_border_index;   /* current border color index */
254
255/* the left and right border color for each row (including top and bottom
256   border rows); -1 means unchanged wrt last scanline
257*/
258static  INT16 thom_border_l[THOM_TOTAL_HEIGHT+1];
259static  INT16 thom_border_r[THOM_TOTAL_HEIGHT+1];
260
261
262/* active area, updated one scan-line at a time every 64us,
263   then blitted in SCREEN_UPDATE_IND16
264*/
265static UINT16 thom_vbody[640*200];
266
267static UINT8 thom_vmode; /* current vide mode */
268static UINT8 thom_vpage; /* current video page */
269
270/* this stores the video mode & page at each GPL in the current line
271   (-1 means unchanged)
272*/
273static INT16 thom_vmodepage[41];
274static UINT8 thom_vmodepage_changed;
275
276/* one dirty flag for each video memory line */
277static UINT8 thom_vmem_dirty[205];
278
279/* set to 1 if undirty scanlines need to be redrawn due to other video state
280   changes */
281static UINT8 thom_vstate_dirty;
282static UINT8 thom_vstate_last_dirty;
283
284
285
286201/* returns 1 if the mode is 640 pixel wide, 0 if it is 160 or 320 */
287static int thom_mode_is_hires( int mode )
202int thomson_state::thom_mode_is_hires( int mode )
288203{
289204   return ( mode == THOM_VMODE_80 ) || ( mode == THOM_VMODE_80_TO9 );
290205}
r21425r21426
292207
293208
294209/* either the border index or its palette entry has changed */
295static void thom_border_changed( running_machine &machine )
210void thomson_state::thom_border_changed()
296211{
297   unsigned l = thom_video_elapsed( machine );
212   unsigned l = thom_video_elapsed();
298213   unsigned y = l >> 6;
299214   unsigned x = l & 63;
300   unsigned color =  thom_pal[ thom_border_index ];
215   unsigned color =  m_thom_pal[ m_thom_border_index ];
301216
302217   if ( y >= THOM_TOTAL_HEIGHT )
303218   {
304219      /* end of page */
305      thom_border_r[ THOM_TOTAL_HEIGHT ] = color;
220      m_thom_border_r[ THOM_TOTAL_HEIGHT ] = color;
306221   }
307222   else if ( ! x )
308223   {
309224      /* start of line */
310      thom_border_l[ y ] = color;
311      thom_border_r[ y ] = color;
225      m_thom_border_l[ y ] = color;
226      m_thom_border_r[ y ] = color;
312227   }
313228   else if ( x <= 19 )
314229   {
r21425r21426
316231      /* NOTE: this makes the lower right part of the color picker blink
317232         in the TO8/TO9/TO9+, which actually happens on the real computer!
318233      */
319      thom_border_r[ y ] = color;
320      thom_border_l[ y + 1 ] = color;
234      m_thom_border_r[ y ] = color;
235      m_thom_border_l[ y + 1 ] = color;
321236   }
322237   else
323238   {
324239      /* end of line */
325      thom_border_l[ y + 1 ] = color;
326      thom_border_r[ y + 1 ] = color;
240      m_thom_border_l[ y + 1 ] = color;
241      m_thom_border_r[ y + 1 ] = color;
327242   }
328   thom_vstate_dirty = 1;
243   m_thom_vstate_dirty = 1;
329244}
330245
331246
332247
333248/* the video mode or page has changed */
334static void thom_gplinfo_changed( running_machine &machine )
249void thomson_state::thom_gplinfo_changed()
335250{
336   unsigned l = thom_video_elapsed( machine ) - THOM_BORDER_HEIGHT * 64 - 7;
251   unsigned l = thom_video_elapsed() - THOM_BORDER_HEIGHT * 64 - 7;
337252   unsigned y = l >> 6;
338253   unsigned x = l & 63;
339   int modepage = ((int)thom_vmode << 8) | thom_vpage;
254   int modepage = ((int)m_thom_vmode << 8) | m_thom_vpage;
340255   if ( y >= 200 || x>= 40 )
341      thom_vmodepage[ 40 ] = modepage;
256      m_thom_vmodepage[ 40 ] = modepage;
342257   else
343      thom_vmodepage[ x ] = modepage;
344   thom_vmodepage_changed = 1;
258      m_thom_vmodepage[ x ] = modepage;
259   m_thom_vmodepage_changed = 1;
345260}
346261
347262
348263
349void thom_set_border_color ( running_machine &machine, unsigned index )
264void thomson_state::thom_set_border_color( unsigned index )
350265{
351266   assert( index < 16 );
352   if ( index != thom_border_index )
267   if ( index != m_thom_border_index )
353268   {
354      LOG (( "thom_set_border_color: %i at line %i col %i\n", index, thom_video_elapsed( machine ) / 64, thom_video_elapsed( machine ) % 64  ));
355      thom_border_index = index;
356      thom_border_changed( machine );
269      LOG (( "thom_set_border_color: %i at line %i col %i\n", index, thom_video_elapsed() / 64, thom_video_elapsed() % 64  ));
270      m_thom_border_index = index;
271      thom_border_changed();
357272   }
358273}
359274
360275
361276
362void thom_set_palette ( running_machine &machine, unsigned index, UINT16 color )
277void thomson_state::thom_set_palette( unsigned index, UINT16 color )
363278{
364279   assert( index < 16 );
365280
366281   if ( color != 0x1000 )
367282      color &= 0xfff;
368283
369   if ( thom_pal[ index ] == color )
284   if ( m_thom_pal[ index ] == color )
370285      return;
371286
372   LOG (( "thom_set_palette: %i to %03x at line %i col %i\n", index, color, thom_video_elapsed( machine ) / 64, thom_video_elapsed( machine ) % 64  ));
287   LOG (( "thom_set_palette: %i to %03x at line %i col %i\n", index, color, thom_video_elapsed() / 64, thom_video_elapsed() % 64  ));
373288
374   thom_pal[ index ] = color;
375   if ( index == thom_border_index )
376      thom_border_changed( machine );
377   thom_pal_changed = 1;
378   thom_vstate_dirty = 1;
289   m_thom_pal[ index ] = color;
290   if ( index == m_thom_border_index )
291      thom_border_changed();
292   m_thom_pal_changed = 1;
293   m_thom_vstate_dirty = 1;
379294}
380295
381296
382297
383void thom_set_video_mode ( running_machine &machine, unsigned mode )
298void thomson_state::thom_set_video_mode( unsigned mode )
384299{
385300   assert( mode < THOM_VMODE_NB );
386301
387   if ( mode != thom_vmode )
302   if ( mode != m_thom_vmode )
388303   {
389      LOG (( "thom_set_video_mode: %i at line %i, col %i\n", mode, thom_video_elapsed( machine ) / 64, thom_video_elapsed( machine ) % 64 ));
390      thom_vmode = mode;
391      thom_gplinfo_changed( machine );
392      thom_vstate_dirty = 1;
393      thom_hires_better |= thom_mode_is_hires( mode );
304      LOG (( "thom_set_video_mode: %i at line %i, col %i\n", mode, thom_video_elapsed() / 64, thom_video_elapsed() % 64 ));
305      m_thom_vmode = mode;
306      thom_gplinfo_changed();
307      m_thom_vstate_dirty = 1;
308      m_thom_hires_better |= thom_mode_is_hires( mode );
394309   }
395310}
396311
397312
398313
399void thom_set_video_page ( running_machine &machine, unsigned page )
314void thomson_state::thom_set_video_page( unsigned page )
400315{
401316   assert( page < THOM_NB_PAGES )
402317      ;
403   if ( page != thom_vpage ) {
404      LOG (( "thom_set_video_page: %i at line %i col %i\n", page, thom_video_elapsed( machine ) / 64, thom_video_elapsed( machine ) % 64  ));
405      thom_vpage = page;
406      thom_gplinfo_changed( machine );
407      thom_vstate_dirty = 1;
318   if ( page != m_thom_vpage ) {
319      LOG (( "thom_set_video_page: %i at line %i col %i\n", page, thom_video_elapsed() / 64, thom_video_elapsed() % 64  ));
320      m_thom_vpage = page;
321      thom_gplinfo_changed();
322      m_thom_vstate_dirty = 1;
408323   }
409324}
410325
r21425r21426
414329
415330
416331
417typedef void ( *thom_scandraw ) ( running_machine &machine, UINT8* vram, UINT16* dst, UINT16* pal,
418               int org, int len );
332typedef void ( thomson_state::*thom_scandraw ) ( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
419333
420334
421335
422336#define UPDATE( name, res )                     \
423   static void name##_scandraw_##res ( running_machine &machine,  \
337   void thomson_state::name##_scandraw_##res ( \
424338                  UINT8* vram, UINT16* dst,   UINT16* pal, \
425339                  int org, int len )      \
426340   {                               \
r21425r21426
778692
779693
780694
781#define FUN(x) { x##_scandraw_8, x##_scandraw_16 }
695#define FUN(x) { &thomson_state::x##_scandraw_8, &thomson_state::x##_scandraw_16 }
782696
783697
784698static const thom_scandraw thom_scandraw_funcs[THOM_VMODE_NB][2] =
r21425r21426
793707/* called at the start of each scanline in the active area, just after
794708   left border (-1<=y<199), and also after the last scanline (y=199)
795709*/
796static TIMER_CALLBACK( thom_scanline_start )
710TIMER_CALLBACK_MEMBER( thomson_state::thom_scanline_start )
797711{
798712   int y = param;
799713
800714   /* update active-area */
801   if ( y >= 0 && (thom_vstate_dirty || thom_vstate_last_dirty || thom_vmem_dirty[y]) )
715   if ( y >= 0 && (m_thom_vstate_dirty || m_thom_vstate_last_dirty || m_thom_vmem_dirty[y]) )
802716   {
803717      int x = 0;
804718      while ( x < 40 )
805719      {
806720         int xx = x;
807         unsigned mode = thom_vmodepage[x] >> 8;
808         unsigned page = thom_vmodepage[x] & 0xff;
721         unsigned mode = m_thom_vmodepage[x] >> 8;
722         unsigned page = m_thom_vmodepage[x] & 0xff;
809723         assert( mode < THOM_VMODE_NB );
810724         assert( page < 4 );
811         if ( thom_vmodepage_changed )
812                  {
813                        do
725         if ( m_thom_vmodepage_changed )
726         {
727            do
814728            {
815729               xx++;
816730            }
817                        while ( xx < 40 && thom_vmodepage[xx] == -1 );
818                  }
731            while ( xx < 40 && m_thom_vmodepage[xx] == -1 );
732         }
819733         else
820                  {
734         {
821735            xx = 40;
822                  }
823         thom_scandraw_funcs[ mode ][ thom_hires ]
824            ( machine,
825               thom_vram + y * 40 + page * 0x4000,
826               thom_vbody + y * 320 * (thom_hires+1),
827               thom_last_pal, x, xx-x );
736         }
737         (this->*thom_scandraw_funcs[ mode ][ m_thom_hires ])
738            ( m_thom_vram + y * 40 + page * 0x4000,
739               m_thom_vbody + y * 320 * (m_thom_hires+1),
740               m_thom_last_pal, x, xx-x );
828741         x = xx;
829742      }
830      thom_vmem_dirty[y] = 0;
743      m_thom_vmem_dirty[y] = 0;
831744   }
832745
833746   /* prepare for next scanline */
834747   if ( y == 199 )
835      thom_scanline_timer->adjust(attotime::never);
748      m_thom_scanline_timer->adjust(attotime::never);
836749   else
837750   {
838      if ( thom_vmodepage_changed )
751      if ( m_thom_vmodepage_changed )
839752      {
840753         int x, m = 0;
841754         for ( x = 0; x <= 40; x++ )
842755         {
843            if ( thom_vmodepage[x] !=-1 )
756            if ( m_thom_vmodepage[x] !=-1 )
844757            {
845               m = thom_vmodepage[x];
846               thom_vmodepage[x] = -1;
758               m = m_thom_vmodepage[x];
759               m_thom_vmodepage[x] = -1;
847760            }
848761         }
849         thom_vmodepage[0] = m;
850         thom_vmodepage_changed = 0;
762         m_thom_vmodepage[0] = m;
763         m_thom_vmodepage_changed = 0;
851764      }
852765
853      if ( thom_pal_changed )
766      if ( m_thom_pal_changed )
854767      {
855         memcpy( thom_last_pal, thom_pal, 32 );
856         thom_pal_changed = 0;
768         memcpy( m_thom_last_pal, m_thom_pal, 32 );
769         m_thom_pal_changed = 0;
857770      }
858771
859      thom_scanline_timer->adjust(attotime::from_usec(64), y + 1);
772      m_thom_scanline_timer->adjust(attotime::from_usec(64), y + 1);
860773   }
861774}
862775
r21425r21426
865778/* -------------- misc --------------- */
866779
867780
781#define FLOP_STATE (m_thom_floppy_wcount ? 2 : m_thom_floppy_rcount ? 1 : 0)
868782
869static UINT32 thom_mode_point;
870783
871static UINT32 thom_floppy_wcount;
872static UINT32 thom_floppy_rcount;
873784
874#define FLOP_STATE (thom_floppy_wcount ? 2 : thom_floppy_rcount ? 1 : 0)
875
876
877
878void thom_set_mode_point ( running_machine &machine, int point )
785void thomson_state::thom_set_mode_point( int point )
879786{
880787   assert( point >= 0 && point <= 1 );
881   thom_mode_point = ( ! point ) * 0x2000;
882   machine.root_device().membank( THOM_VRAM_BANK )->set_entry( ! point );
788   m_thom_mode_point = ( ! point ) * 0x2000;
789   membank( THOM_VRAM_BANK )->set_entry( ! point );
883790}
884791
885792
886793
887void thom_floppy_active ( running_machine &machine, int write )
794void thomson_state::thom_floppy_active( int write )
888795{
889796   int fold = FLOP_STATE, fnew;
890797
891798   /* stays up for a few frames */
892799   if ( write )
893      thom_floppy_wcount = 25;
800      m_thom_floppy_wcount = 25;
894801   else
895      thom_floppy_rcount = 25;
802      m_thom_floppy_rcount = 25;
896803
897804   /* update icon */
898805   fnew = FLOP_STATE;
r21425r21426
906813
907814
908815
909SCREEN_UPDATE_IND16 ( thom )
816UINT32 thomson_state::screen_update_thom(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
910817{
911818   int y, ypos;
912   const int scale = thom_hires ? 2 : 1;
913   const int xbleft = thom_bwidth * scale;
914   const int xbright = ( thom_bwidth + THOM_ACTIVE_WIDTH ) * scale;
915   const int xright = ( thom_bwidth * 2 + THOM_ACTIVE_WIDTH ) * scale;
819   const int scale = m_thom_hires ? 2 : 1;
820   const int xbleft = m_thom_bwidth * scale;
821   const int xbright = ( m_thom_bwidth + THOM_ACTIVE_WIDTH ) * scale;
822   const int xright = ( m_thom_bwidth * 2 + THOM_ACTIVE_WIDTH ) * scale;
916823   const int xwidth = THOM_ACTIVE_WIDTH * scale;
917824   const int yup = THOM_BORDER_HEIGHT + THOM_ACTIVE_HEIGHT;
918   const int ybot = THOM_BORDER_HEIGHT + thom_bheight + 200;
919   UINT16* v = thom_vbody;
825   const int ybot = THOM_BORDER_HEIGHT + m_thom_bheight + 200;
826   UINT16* v = m_thom_vbody;
920827   pen_t border = 0;
921828   rectangle wrect(0, xright - 1, 0, 0);
922829   rectangle lrect(0, xbleft - 1, 0, 0);
923830   rectangle rrect(xbright, xright - 1, 0, 0);
924831
925   //LOG (( "%f thom: video update called\n", machine.time().as_double()));
832   //LOG (( "%f thom: video update called\n", machine().time().as_double()));
926833
927834   /* upper border */
928   for ( y = 0; y < THOM_BORDER_HEIGHT - thom_bheight; y++ )
835   for ( y = 0; y < THOM_BORDER_HEIGHT - m_thom_bheight; y++ )
929836   {
930      if ( thom_border_l[ y ] != -1 )
931         border = thom_border_l[ y ];
837      if ( m_thom_border_l[ y ] != -1 )
838         border = m_thom_border_l[ y ];
932839   }
933840   ypos = 0;
934841   while ( y < THOM_BORDER_HEIGHT )
935842   {
936      if ( thom_border_l[ y ] != -1 )
937         border = thom_border_l[ y ];
843      if ( m_thom_border_l[ y ] != -1 )
844         border = m_thom_border_l[ y ];
938845      wrect.min_y = ypos;
939846      do
940847      {
941848         y++;
942849         ypos ++ /* += scale */;
943850      }
944      while ( y < THOM_BORDER_HEIGHT && thom_border_l[ y ] == -1 );
851      while ( y < THOM_BORDER_HEIGHT && m_thom_border_l[ y ] == -1 );
945852      wrect.max_y = ypos - 1;
946853      bitmap.fill(border, wrect );
947854   }
r21425r21426
949856   /* left border */
950857   while ( y < yup )
951858   {
952      if ( thom_border_l[ y ] != -1 )
953         border = thom_border_l[ y ];
859      if ( m_thom_border_l[ y ] != -1 )
860         border = m_thom_border_l[ y ];
954861      lrect.min_y = ypos;
955862      do
956863      {
957864         y++;
958865         ypos ++ /* += scale */;
959866      }
960      while ( y < yup && thom_border_l[ y ] == -1 );
867      while ( y < yup && m_thom_border_l[ y ] == -1 );
961868      lrect.max_y = ypos - 1;
962869      bitmap.fill(border, lrect );
963870   }
r21425r21426
965872   /* lower border */
966873   while (y < ybot )
967874   {
968      if ( thom_border_l[ y ] != -1 )
969         border = thom_border_l[ y ];
875      if ( m_thom_border_l[ y ] != -1 )
876         border = m_thom_border_l[ y ];
970877      wrect.min_y = ypos;
971878      do
972879      {
973880         y++;
974881         ypos ++ /* += scale */;
975      } while ( y < ybot && thom_border_l[ y ] == -1 );
882      } while ( y < ybot && m_thom_border_l[ y ] == -1 );
976883      wrect.max_y = ypos - 1;
977884      bitmap.fill(border, wrect );
978885   }
979886
980887   /* right border */
981888   for ( y = 0; y < THOM_BORDER_HEIGHT; y++ ) {
982      if ( thom_border_r[ y ] != -1 )
983         border = thom_border_r[ y ];
889      if ( m_thom_border_r[ y ] != -1 )
890         border = m_thom_border_r[ y ];
984891   }
985   ypos = thom_bheight /* * scale */;
892   ypos = m_thom_bheight /* * scale */;
986893   while ( y < yup )
987894   {
988      if ( thom_border_r[ y ] != -1 )
989         border = thom_border_r[ y ];
895      if ( m_thom_border_r[ y ] != -1 )
896         border = m_thom_border_r[ y ];
990897      rrect.min_y = ypos;
991898      do
992899      {
993900         y++;
994901         ypos ++ /* += scale */;
995902      }
996      while ( y < yup && thom_border_r[ y ] == -1 );
903      while ( y < yup && m_thom_border_r[ y ] == -1 );
997904      rrect.max_y = ypos - 1;
998905      bitmap.fill(border, rrect );
999906   }
1000907
1001908   /* active area */
1002   ypos = thom_bheight /* * scale */;
909   ypos = m_thom_bheight /* * scale */;
1003910   for ( y = 0; y < 200; v += xwidth, y++ , ypos ++ /* += scale */ )
1004911   {
1005912      draw_scanline16( bitmap, xbleft, ypos, xwidth, v, NULL );
r21425r21426
1017924/* -------------- frame start ------------------ */
1018925
1019926
1020
1021static emu_timer *thom_init_timer;
1022
1023static void (*thom_init_cb) ( running_machine &machine, int init );
1024
1025
1026
1027void thom_set_init_callback ( running_machine &machine, void (*cb) ( running_machine &machine, int init ) )
927TIMER_CALLBACK_MEMBER( thomson_state::thom_set_init )
1028928{
1029   thom_init_cb = cb;
1030}
1031
1032
1033
1034static TIMER_CALLBACK( thom_set_init )
1035{
1036929   int init = param;
1037   LOG (( "%f thom_set_init: %i, at line %i col %i\n", machine.time().as_double(), init, thom_video_elapsed( machine ) / 64, thom_video_elapsed( machine ) % 64 ));
930   LOG (( "%f thom_set_init: %i, at line %i col %i\n", machine().time().as_double(), init, thom_video_elapsed() / 64, thom_video_elapsed() % 64 ));
1038931
1039   if ( thom_init_cb )
1040      thom_init_cb( machine, init );
932   if ( m_thom_init_cb )
933      (this->*m_thom_init_cb)( init );
1041934   if ( ! init )
1042      thom_init_timer->adjust(attotime::from_usec( 64 * THOM_ACTIVE_HEIGHT - 24 ), 1-init);
935      m_thom_init_timer->adjust(attotime::from_usec( 64 * THOM_ACTIVE_HEIGHT - 24 ), 1-init);
1043936}
1044937
1045938/* call this at the very beginning of each new frame */
1046SCREEN_VBLANK ( thom )
939void thomson_state::thom_vblank( screen_device &screen, bool state )
1047940{
1048941   // rising edge
1049   if (vblank_on)
942   if (state)
1050943   {
1051944      int fnew, fold = FLOP_STATE;
1052945      int i;
1053946      UINT16 b = 0;
1054      struct thom_vsignal l = thom_get_lightpen_vsignal( screen.machine(), 0, -1, 0 );
947      struct thom_vsignal l = thom_get_lightpen_vsignal( 0, -1, 0 );
1055948
1056      LOG (( "%f thom: video eof called\n", screen.machine().time().as_double() ));
949      LOG (( "%f thom: video eof called\n", machine().time().as_double() ));
1057950
1058951      /* floppy indicator count */
1059      if ( thom_floppy_wcount )
1060         thom_floppy_wcount--;
1061      if ( thom_floppy_rcount )
1062         thom_floppy_rcount--;
952      if ( m_thom_floppy_wcount )
953         m_thom_floppy_wcount--;
954      if ( m_thom_floppy_rcount )
955         m_thom_floppy_rcount--;
1063956      fnew = FLOP_STATE;
1064957      if ( fnew != fold )
1065958         output_set_value( "floppy", fnew );
r21425r21426
1067960      /* prepare state for next frame */
1068961      for ( i = 0; i <= THOM_TOTAL_HEIGHT; i++ )
1069962      {
1070         if ( thom_border_l[ i ] != -1 )
1071            b = thom_border_l[ i ];
1072         if ( thom_border_r[ i ] != -1 )
1073            b = thom_border_r[ i ];
963         if ( m_thom_border_l[ i ] != -1 )
964            b = m_thom_border_l[ i ];
965         if ( m_thom_border_r[ i ] != -1 )
966            b = m_thom_border_r[ i ];
1074967      }
1075      memset( thom_border_l, 0xff, sizeof( thom_border_l ) );
1076      memset( thom_border_r, 0xff, sizeof( thom_border_r ) );
1077      thom_border_l[ 0 ] = b;
1078      thom_border_r[ 0 ] = b;
1079      thom_vstate_last_dirty = thom_vstate_dirty;
1080      thom_vstate_dirty = 0;
968      memset( m_thom_border_l, 0xff, sizeof( m_thom_border_l ) );
969      memset( m_thom_border_r, 0xff, sizeof( m_thom_border_r ) );
970      m_thom_border_l[ 0 ] = b;
971      m_thom_border_r[ 0 ] = b;
972      m_thom_vstate_last_dirty = m_thom_vstate_dirty;
973      m_thom_vstate_dirty = 0;
1081974
1082975      /* schedule first init signal */
1083      thom_init_timer->adjust(attotime::from_usec( 64 * THOM_BORDER_HEIGHT + 7 ));
976      m_thom_init_timer->adjust(attotime::from_usec( 64 * THOM_BORDER_HEIGHT + 7 ));
1084977
1085978      /* schedule first lightpen signal */
1086979      l.line &= ~1; /* hack (avoid lock in MO6 palette selection) */
1087      thom_lightpen_timer->adjust(
980      m_thom_lightpen_timer->adjust(
1088981               attotime::from_usec( 64 * ( THOM_BORDER_HEIGHT + l.line - 2 ) + 16 ), 0);
1089982
1090983      /* schedule first active-area scanline call-back */
1091      thom_scanline_timer->adjust(attotime::from_usec( 64 * THOM_BORDER_HEIGHT + 7), -1);
984      m_thom_scanline_timer->adjust(attotime::from_usec( 64 * THOM_BORDER_HEIGHT + 7), -1);
1092985
1093986      /* reset video frame time */
1094      thom_video_timer->adjust(attotime::zero);
987      m_thom_video_timer->adjust(attotime::zero);
1095988
1096989      /* update screen size according to user options */
1097      if ( thom_update_screen_size( screen.machine() ) )
1098         thom_vstate_dirty = 1;
990      if ( thom_update_screen_size() )
991         m_thom_vstate_dirty = 1;
1099992
1100993      /* hi-res automatic */
1101      thom_hires_better = thom_mode_is_hires( thom_vmode );
994      m_thom_hires_better = thom_mode_is_hires( m_thom_vmode );
1102995   }
1103996}
1104997
r21425r21426
11221015
11231016
11241017
1125VIDEO_START ( thom )
1018VIDEO_START_MEMBER( thomson_state, thom )
11261019{
11271020   LOG (( "thom: video start called\n" ));
11281021
11291022   /* scan-line state */
1130   memcpy( thom_last_pal, thom_pal_init, 32 );
1131   memcpy( thom_pal, thom_pal_init, 32 );
1132   memset( thom_border_l, 0xff, sizeof( thom_border_l ) );
1133   memset( thom_border_r, 0xff, sizeof( thom_border_r ) );
1134   memset( thom_vbody, 0, sizeof( thom_vbody ) );
1135   memset( thom_vmodepage, 0xffff, sizeof( thom_vmodepage ) );
1136   memset( thom_vmem_dirty, 0, sizeof( thom_vmem_dirty ) );
1137   thom_border_l[ 0 ] = 0;
1138   thom_border_r[ 0 ] = 0;
1139   thom_vmodepage[ 0 ] = 0;
1140   thom_vmodepage_changed = 0;
1141   thom_vmode = 0;
1142   thom_vpage = 0;
1143   thom_border_index = 0;
1144   thom_vstate_dirty = 1;
1145   thom_vstate_last_dirty = 1;
1146   state_save_register_global_array(machine,  thom_last_pal );
1147   state_save_register_global_array(machine,  thom_pal );
1148   state_save_register_global_array(machine,  thom_border_l );
1149   state_save_register_global_array(machine,  thom_border_r );
1150   state_save_register_global_array(machine,  thom_vbody );
1151   state_save_register_global_array(machine,  thom_vmodepage );
1152   state_save_register_global_array(machine,  thom_vmem_dirty );
1153   state_save_register_global(machine,  thom_pal_changed );
1154   state_save_register_global(machine,  thom_vmodepage_changed );
1155   state_save_register_global(machine,  thom_vmode );
1156   state_save_register_global(machine,  thom_vpage );
1157   state_save_register_global(machine,  thom_border_index );
1158   state_save_register_global(machine,  thom_vstate_dirty );
1159   state_save_register_global(machine,  thom_vstate_last_dirty );
1023   memcpy( m_thom_last_pal, thom_pal_init, 32 );
1024   memcpy( m_thom_pal, thom_pal_init, 32 );
1025   memset( m_thom_border_l, 0xff, sizeof( m_thom_border_l ) );
1026   memset( m_thom_border_r, 0xff, sizeof( m_thom_border_r ) );
1027   memset( m_thom_vbody, 0, sizeof( m_thom_vbody ) );
1028   memset( m_thom_vmodepage, 0xffff, sizeof( m_thom_vmodepage ) );
1029   memset( m_thom_vmem_dirty, 0, sizeof( m_thom_vmem_dirty ) );
1030   m_thom_border_l[ 0 ] = 0;
1031   m_thom_border_r[ 0 ] = 0;
1032   m_thom_vmodepage[ 0 ] = 0;
1033   m_thom_vmodepage_changed = 0;
1034   m_thom_vmode = 0;
1035   m_thom_vpage = 0;
1036   m_thom_border_index = 0;
1037   m_thom_vstate_dirty = 1;
1038   m_thom_vstate_last_dirty = 1;
1039   save_pointer(NAME(m_thom_last_pal), sizeof(m_thom_last_pal));
1040   save_pointer(NAME(m_thom_pal), sizeof(m_thom_pal));
1041   save_pointer(NAME(m_thom_border_l), sizeof(m_thom_border_l));
1042   save_pointer(NAME(m_thom_border_r), sizeof(m_thom_border_r));
1043   save_pointer(NAME(m_thom_vbody), sizeof(m_thom_vbody));
1044   save_pointer(NAME(m_thom_vmodepage), sizeof(m_thom_vmodepage));
1045   save_pointer(NAME(m_thom_vmem_dirty), sizeof(m_thom_vmem_dirty));
1046   save_item(NAME(m_thom_pal_changed));
1047   save_item(NAME(m_thom_vmodepage_changed));
1048   save_item(NAME(m_thom_vmode));
1049   save_item(NAME(m_thom_vpage));
1050   save_item(NAME(m_thom_border_index));
1051   save_item(NAME(m_thom_vstate_dirty));
1052   save_item(NAME(m_thom_vstate_last_dirty));
11601053
1161   thom_mode_point = 0;
1162   state_save_register_global(machine,  thom_mode_point );
1163   machine.root_device().membank( THOM_VRAM_BANK )->set_entry( 0 );
1054   m_thom_mode_point = 0;
1055   save_item(NAME(m_thom_mode_point));
1056   membank( THOM_VRAM_BANK )->set_entry( 0 );
11641057
1165   thom_floppy_rcount = 0;
1166   thom_floppy_wcount = 0;
1167   state_save_register_global(machine,  thom_floppy_wcount );
1168   state_save_register_global(machine,  thom_floppy_rcount );
1058   m_thom_floppy_rcount = 0;
1059   m_thom_floppy_wcount = 0;
1060   save_item(NAME(m_thom_floppy_wcount));
1061   save_item(NAME(m_thom_floppy_rcount));
11691062   output_set_value( "floppy", 0 );
11701063
1171   thom_video_timer = machine.scheduler().timer_alloc(FUNC_NULL);
1064   m_thom_video_timer = machine().scheduler().timer_alloc(FUNC_NULL);
11721065
1173   thom_scanline_timer = machine.scheduler().timer_alloc(FUNC(thom_scanline_start));
1066   m_thom_scanline_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::thom_scanline_start),this));
11741067
1175   thom_lightpen_nb = 0;
1176   thom_lightpen_cb = NULL;
1177   thom_lightpen_timer = machine.scheduler().timer_alloc(FUNC(thom_lightpen_step));
1178   state_save_register_global(machine,  thom_lightpen_nb );
1068   m_thom_lightpen_nb = 0;
1069   m_thom_lightpen_cb = NULL;
1070   m_thom_lightpen_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::thom_lightpen_step),this));
1071   save_item(NAME(m_thom_lightpen_nb));
11791072
1180   thom_init_cb = NULL;
1181   thom_init_timer = machine.scheduler().timer_alloc(FUNC(thom_set_init));
1073   m_thom_init_cb = NULL;
1074   m_thom_init_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::thom_set_init),this));
11821075
1183   state_save_register_global(machine,  thom_bwidth );
1184   state_save_register_global(machine,  thom_bheight );
1185   state_save_register_global(machine,  thom_hires );
1186   state_save_register_global(machine,  thom_hires_better );
1076   save_item(NAME(m_thom_bwidth));
1077   save_item(NAME(m_thom_bheight));
1078   save_item(NAME(m_thom_hires));
1079   save_item(NAME(m_thom_hires_better));
11871080}
11881081
11891082
r21425r21426
12121105
12131106
12141107/* write to video memory through addresses 0x4000-0x5fff */
1215WRITE8_HANDLER ( to7_vram_w )
1108WRITE8_MEMBER( thomson_state::to7_vram_w )
12161109{
12171110   assert( offset < 0x2000 );
12181111   /* force two topmost color bits to 1 */
1219   if ( thom_mode_point )
1112   if ( m_thom_mode_point )
12201113      data |= 0xc0;
1221   if ( thom_vram[ offset + thom_mode_point ] == data )
1114   if ( m_thom_vram[ offset + m_thom_mode_point ] == data )
12221115      return;
1223   thom_vram[ offset + thom_mode_point ] = data;
1116   m_thom_vram[ offset + m_thom_mode_point ] = data;
12241117   /* dirty whole scanline */
1225   thom_vmem_dirty[ offset / 40 ] = 1;
1118   m_thom_vmem_dirty[ offset / 40 ] = 1;
12261119}
12271120
12281121
r21425r21426
12301123/* bits 0-13 : latched gpl of lightpen position */
12311124/* bit    14:  latched INIT */
12321125/* bit    15:  latched INIL */
1233unsigned to7_lightpen_gpl ( running_machine &machine, int decx, int decy )
1126unsigned thomson_state::to7_lightpen_gpl ( int decx, int decy )
12341127{
12351128   int x,y;
1236   thom_get_lightpen_pos( machine, &x, &y );
1237   x -= thom_bwidth;
1238   y -= thom_bheight;
1129   thom_get_lightpen_pos( &x, &y );
1130   x -= m_thom_bwidth;
1131   y -= m_thom_bheight;
12391132   if ( x < 0 || y < 0 || x >= 320 || y >= 200 )
12401133      return 0;
12411134   x += decx;
r21425r21426
12511144
12521145/* write to video memory through addresses 0x4000-0x5fff (TO)
12531146   or 0x0000-0x1fff (MO) */
1254WRITE8_HANDLER ( to770_vram_w )
1147WRITE8_MEMBER( thomson_state::to770_vram_w )
12551148{
12561149   assert( offset < 0x2000 );
1257   if ( thom_vram[ offset + thom_mode_point ] == data )
1150   if ( m_thom_vram[ offset + m_thom_mode_point ] == data )
12581151      return;
1259   thom_vram[ offset + thom_mode_point ] = data;
1152   m_thom_vram[ offset + m_thom_mode_point ] = data;
12601153   /* dirty whole scanline */
1261   thom_vmem_dirty[ offset / 40 ] = 1;
1154   m_thom_vmem_dirty[ offset / 40 ] = 1;
12621155}
12631156
12641157
r21425r21426
12701163
12711164/* write to video memory through system space (always page 1) */
12721165
1273WRITE8_HANDLER ( to8_sys_lo_w )
1166WRITE8_MEMBER( thomson_state::to8_sys_lo_w )
12741167{
1275   UINT8* dst = thom_vram + offset + 0x6000;
1168   UINT8* dst = m_thom_vram + offset + 0x6000;
12761169   assert( offset < 0x2000 );
12771170   if ( *dst == data )
12781171      return;
12791172   *dst = data;
12801173   /* dirty whole scanline */
1281   thom_vmem_dirty[ offset / 40 ] = 1;
1174   m_thom_vmem_dirty[ offset / 40 ] = 1;
12821175}
12831176
12841177
12851178
1286WRITE8_HANDLER ( to8_sys_hi_w )
1179WRITE8_MEMBER( thomson_state::to8_sys_hi_w )
12871180{
1288   UINT8* dst = thom_vram + offset + 0x4000;
1181   UINT8* dst = m_thom_vram + offset + 0x4000;
12891182   assert( offset < 0x2000 );
12901183   if ( *dst == data ) return;
12911184   *dst = data;
12921185   /* dirty whole scanline */
1293   thom_vmem_dirty[ offset / 40 ] = 1;
1186   m_thom_vmem_dirty[ offset / 40 ] = 1;
12941187}
12951188
12961189
12971190
12981191/* write to video memory through data space */
12991192
1300WRITE8_HANDLER ( to8_data_lo_w )
1193WRITE8_MEMBER( thomson_state::to8_data_lo_w )
13011194{
1302   UINT8* dst = thom_vram + offset + 0x4000 * to8_data_vpage + 0x2000;
1195   UINT8* dst = m_thom_vram + offset + 0x4000 * m_to8_data_vpage + 0x2000;
13031196   assert( offset < 0x2000 );
13041197   if ( *dst == data )
13051198      return;
13061199   *dst = data;
13071200   /* dirty whole scanline */
1308   if ( to8_data_vpage >= 4 )
1201   if ( m_to8_data_vpage >= 4 )
13091202      return;
1310   thom_vmem_dirty[ offset / 40 ] = 1;
1203   m_thom_vmem_dirty[ offset / 40 ] = 1;
13111204}
13121205
13131206
13141207
1315WRITE8_HANDLER ( to8_data_hi_w )
1208WRITE8_MEMBER( thomson_state::to8_data_hi_w )
13161209{
1317   UINT8* dst = thom_vram + offset + 0x4000 * to8_data_vpage;
1210   UINT8* dst = m_thom_vram + offset + 0x4000 * m_to8_data_vpage;
13181211   assert( offset < 0x2000 );
13191212   if ( *dst == data )
13201213      return;
13211214   *dst = data;
13221215   /* dirty whole scanline */
1323   if ( to8_data_vpage >= 4 )
1216   if ( m_to8_data_vpage >= 4 )
13241217      return;
1325   thom_vmem_dirty[ offset / 40 ] = 1;
1218   m_thom_vmem_dirty[ offset / 40 ] = 1;
13261219}
13271220
13281221
13291222
13301223/* write to video memory page through cartridge addresses space */
1331WRITE8_HANDLER ( to8_vcart_w )
1224WRITE8_MEMBER( thomson_state::to8_vcart_w )
13321225{
1333   UINT8* dst = thom_vram + offset + 0x4000 * to8_cart_vpage;
1226   UINT8* dst = m_thom_vram + offset + 0x4000 * m_to8_cart_vpage;
13341227   assert( offset < 0x4000 );
13351228   if ( *dst == data )
13361229      return;
13371230   *dst = data;
13381231   /* dirty whole scanline */
1339   if ( to8_cart_vpage >= 4  )
1232   if ( m_to8_cart_vpage >= 4  )
13401233      return;
1341   thom_vmem_dirty[ (offset & 0x1fff) / 40 ] = 1;
1234   m_thom_vmem_dirty[ (offset & 0x1fff) / 40 ] = 1;
13421235}
trunk/src/mess/includes/thomson.h
r21425r21426
2626#include "formats/thom_cas.h"
2727#include "formats/thom_dsk.h"
2828#include "machine/thomflop.h"
29#include "machine/ram.h"
2930
3031
31class thomson_state : public driver_device
32{
33public:
34   thomson_state(const machine_config &mconfig, device_type type, const char *tag)
35      : driver_device(mconfig, type, tag)
36   { }
37
38   DECLARE_DEVICE_IMAGE_LOAD_MEMBER( to7_cartridge );
39   DECLARE_DEVICE_IMAGE_LOAD_MEMBER( mo5_cartridge );
40};
41
42/*----------- defined in machine/thomson.c -----------*/
43
44/*************************** common ********************************/
45
4632/* 6821 PIAs */
4733#define THOM_PIA_SYS    "pia_0"  /* system PIA */
4834#define THOM_PIA_GAME   "pia_1"  /* music & game PIA (joypad + sound) */
r21425r21426
6046#define THOM_FLOP_BANK  "bank4" /* external floppy controller ROM */
6147#define THOM_BASE_BANK  "bank5" /* system RAM */
6248
63extern const pia6821_interface to7_pia6821_sys;
64extern const pia6821_interface to7_pia6821_io;
65extern const pia6821_interface to7_pia6821_modem;
66extern const pia6821_interface to7_pia6821_game;
67extern const pia6821_interface to770_pia6821_sys;
68extern const pia6821_interface mo5_pia6821_sys;
69extern const pia6821_interface to9_pia6821_sys;
70extern const pia6821_interface to8_pia6821_sys;
71extern const pia6821_interface to9p_pia6821_sys;
72extern const pia6821_interface mo6_pia6821_game;
73extern const pia6821_interface mo6_pia6821_sys;
74extern const pia6821_interface mo5nr_pia6821_sys;
75extern const pia6821_interface mo5nr_pia6821_game;
49/* bank-switching */
50#define TO8_SYS_LO      "bank5" /* system RAM low 2 Kb */
51#define TO8_SYS_HI      "bank6" /* system RAM hi 2 Kb */
52#define TO8_DATA_LO     "bank7" /* data RAM low 2 Kb */
53#define TO8_DATA_HI     "bank8" /* data RAM hi 2 Kb */
54#define TO8_BIOS_BANK   "bank9" /* BIOS ROM */
7655
77/***************************** TO7 / T9000 *************************/
7856
79/* cartridge bank-switching */
80extern DECLARE_WRITE8_HANDLER ( to7_cartridge_w );
81extern DECLARE_READ8_HANDLER  ( to7_cartridge_r );
57/* original screen dimension (may be different from emulated screen!) */
58#define THOM_ACTIVE_WIDTH  320
59#define THOM_BORDER_WIDTH   56
60#define THOM_ACTIVE_HEIGHT 200
61#define THOM_BORDER_HEIGHT  47
62#define THOM_TOTAL_WIDTH   432
63#define THOM_TOTAL_HEIGHT  294
8264
83/* dispatch MODEM or speech synthesis extension */
84extern DECLARE_READ8_HANDLER ( to7_modem_mea8000_r );
85extern DECLARE_WRITE8_HANDLER ( to7_modem_mea8000_w );
65/* Emulated screen dimension may be doubled to allow hi-res 640x200 mode.
66   Emulated screen can have smaller borders.
67 */
8668
87/* MIDI extension (actually an 6850 ACIA) */
88extern DECLARE_READ8_HANDLER  ( to7_midi_r );
89extern DECLARE_WRITE8_HANDLER ( to7_midi_w );
69/* maximum number of video pages:
70   1 for TO7 generation (including MO5)
71   4 for TO8 generation (including TO9, MO6)
72 */
73#define THOM_NB_PAGES 4
9074
91extern MACHINE_START ( to7 );
92extern MACHINE_RESET ( to7 );
75/* page 0 is banked */
76#define THOM_VRAM_BANK "bank1"
9377
94/* centronics */
95extern const centronics_interface to7_centronics_config;
96extern const centronics_interface mo6_centronics_config;
9778
98/* timer */
99extern const mc6846_interface to7_timer;
79struct thom_vsignal {
80   unsigned count;  /* pixel counter */
81   unsigned init;   /* 1 -> active vertical windos, 0 -> border/VBLANK */
82   unsigned inil;   /* 1 -> active horizontal window, 0 -> border/HBLANK */
83   unsigned lt3;    /* bit 3 of us counter */
84   unsigned line;   /* line counter */
85};
10086
101/* speech synthesis */
102extern const mea8000_interface to7_speech;
10387
104/* modem */
105extern const acia6850_interface to7_modem;
88enum to7_io_dev
89{
90   TO7_IO_NONE,
91   TO7_IO_CENTRONICS,
92   TO7_IO_RS232
93};
10694
10795
108/***************************** TO7/70 ******************************/
96class thomson_state : public driver_device
97{
98public:
99   thomson_state(const machine_config &mconfig, device_type type, const char *tag)
100      : driver_device(mconfig, type, tag)
101      , m_maincpu(*this, "maincpu")
102      , m_cassette(*this, CASSETTE_TAG)
103      , m_buzzer(*this, "buzzer")
104      , m_dac(*this, "dac")
105      , m_centronics(*this, "centronics")
106      , m_pia_sys(*this, THOM_PIA_SYS)
107      , m_pia_io(*this, THOM_PIA_IO)
108      , m_pia_game(*this, THOM_PIA_GAME)
109      , m_serial(*this, "cc90232")
110      , m_acia(*this, "acia6850")
111      , m_mea8000(*this, "mea8000")
112      , m_ram(*this, RAM_TAG)
113      , m_mc6846(*this, "mc6846")
114   { }
109115
110/* gate-array */
111extern DECLARE_READ8_HANDLER  ( to770_gatearray_r );
112extern DECLARE_WRITE8_HANDLER ( to770_gatearray_w );
116   DECLARE_DEVICE_IMAGE_LOAD_MEMBER( to7_cartridge );
117   DECLARE_DEVICE_IMAGE_LOAD_MEMBER( mo5_cartridge );
113118
114extern MACHINE_START ( to770 );
115extern MACHINE_RESET ( to770 );
119   DECLARE_WRITE8_MEMBER( to7_set_cassette_motor );
120   DECLARE_WRITE8_MEMBER( mo5_set_cassette_motor );
121   DECLARE_WRITE_LINE_MEMBER( thom_dev_irq_0 );
122   DECLARE_WRITE_LINE_MEMBER( thom_irq_1 );
123   DECLARE_WRITE_LINE_MEMBER( thom_firq_1 );
124   DECLARE_WRITE8_MEMBER( to7_cartridge_w );
125   DECLARE_READ8_MEMBER( to7_cartridge_r );
126   DECLARE_WRITE8_MEMBER( to7_timer_port_out );
127   DECLARE_WRITE8_MEMBER( to7_timer_cp2_out );
128   DECLARE_READ8_MEMBER( to7_timer_port_in );
129   DECLARE_WRITE8_MEMBER( to7_timer_tco_out );
130   DECLARE_WRITE8_MEMBER( to7_sys_cb2_out );
131   DECLARE_WRITE8_MEMBER( to7_sys_portb_out );
132   DECLARE_READ8_MEMBER( to7_sys_porta_in );
133   DECLARE_READ8_MEMBER( to7_sys_portb_in );
134   DECLARE_WRITE_LINE_MEMBER( to7_io_ack );
135   DECLARE_WRITE8_MEMBER( to7_io_portb_out );
136   DECLARE_WRITE8_MEMBER( to7_io_cb2_out );
137   DECLARE_WRITE_LINE_MEMBER( to7_modem_cb );
138   DECLARE_READ_LINE_MEMBER( to7_modem_rx_r );
139   DECLARE_WRITE_LINE_MEMBER( to7_modem_tx_w );
140   DECLARE_READ8_MEMBER( to7_modem_mea8000_r );
141   DECLARE_WRITE8_MEMBER( to7_modem_mea8000_w );
142   DECLARE_READ8_MEMBER( to7_game_porta_in );
143   DECLARE_READ8_MEMBER( to7_game_portb_in );
144   DECLARE_WRITE8_MEMBER( to7_game_portb_out );
145   DECLARE_WRITE8_MEMBER( to7_game_cb2_out );
146   TIMER_CALLBACK_MEMBER( to7_game_update_cb );
147   DECLARE_READ8_MEMBER( to7_midi_r );
148   DECLARE_WRITE8_MEMBER( to7_midi_w );
149   DECLARE_MACHINE_RESET( to7 );
150   DECLARE_MACHINE_START( to7 );
151   DECLARE_WRITE8_MEMBER( to770_sys_cb2_out );
152   DECLARE_READ8_MEMBER( to770_sys_porta_in );
153   void to7_update_cart_bank_postload();
154   void to770_update_ram_bank_postload();
155   DECLARE_WRITE8_MEMBER( to770_sys_portb_out );
156   DECLARE_WRITE8_MEMBER( to770_timer_port_out );
157   DECLARE_READ8_MEMBER( to770_gatearray_r );
158   DECLARE_WRITE8_MEMBER( to770_gatearray_w );
159   DECLARE_MACHINE_RESET( to770 );
160   DECLARE_MACHINE_START( to770 );
161   void to7_lightpen_cb( int step );
162   void mo5_lightpen_cb( int step );
163   TIMER_CALLBACK_MEMBER( mo5_periodic_cb );
164   DECLARE_WRITE8_MEMBER( mo5_sys_porta_out );
165   DECLARE_READ8_MEMBER( mo5_sys_porta_in );
166   DECLARE_WRITE8_MEMBER( mo5_sys_portb_out );
167   DECLARE_READ8_MEMBER( mo5_sys_portb_in );
168   DECLARE_READ8_MEMBER( mo5_gatearray_r );
169   DECLARE_WRITE8_MEMBER( mo5_gatearray_w );
170   void mo5_update_cart_bank_postload();
171   DECLARE_WRITE8_MEMBER( mo5_cartridge_w );
172   DECLARE_READ8_MEMBER( mo5_cartridge_r );
173   DECLARE_WRITE8_MEMBER( mo5_ext_w );
174   DECLARE_MACHINE_RESET( mo5 );
175   DECLARE_MACHINE_START( mo5 );
176   DECLARE_WRITE8_MEMBER( to9_ieee_w );
177   DECLARE_READ8_MEMBER( to9_ieee_r );
178   DECLARE_READ8_MEMBER( to9_gatearray_r );
179   DECLARE_WRITE8_MEMBER( to9_gatearray_w );
180   DECLARE_READ8_MEMBER( to9_vreg_r );
181   DECLARE_WRITE8_MEMBER( to9_vreg_w );
182   void to9_update_cart_bank_postload();
183   DECLARE_WRITE8_MEMBER( to9_cartridge_w );
184   DECLARE_READ8_MEMBER( to9_cartridge_r );
185   void to9_update_ram_bank_postload();
186   DECLARE_READ8_MEMBER( to9_kbd_r );
187   DECLARE_WRITE8_MEMBER( to9_kbd_w );
188   TIMER_CALLBACK_MEMBER( to9_kbd_timer_cb );
189   DECLARE_READ8_MEMBER( to9_sys_porta_in );
190   DECLARE_WRITE8_MEMBER( to9_sys_porta_out );
191   DECLARE_WRITE8_MEMBER( to9_sys_portb_out );
192   DECLARE_WRITE8_MEMBER( to9_timer_port_out );
193   DECLARE_MACHINE_RESET( to9 );
194   DECLARE_MACHINE_START( to9 );
195   TIMER_CALLBACK_MEMBER( to8_kbd_timer_cb );
196   void to8_update_floppy_bank_postload();
197   void to8_update_ram_bank_postload();
198   void to8_update_cart_bank_postload();
199   DECLARE_WRITE8_MEMBER( to8_cartridge_w );
200   DECLARE_READ8_MEMBER( to8_cartridge_r );
201   DECLARE_READ8_MEMBER( to8_floppy_r );
202   DECLARE_WRITE8_MEMBER( to8_floppy_w );
203   DECLARE_READ8_MEMBER( to8_gatearray_r );
204   DECLARE_WRITE8_MEMBER( to8_gatearray_w );
205   DECLARE_READ8_MEMBER( to8_vreg_r );
206   DECLARE_WRITE8_MEMBER( to8_vreg_w );
207   DECLARE_READ8_MEMBER( to8_sys_porta_in );
208   DECLARE_WRITE8_MEMBER( to8_sys_portb_out );
209   DECLARE_READ8_MEMBER( to8_timer_port_in );
210   DECLARE_WRITE8_MEMBER( to8_timer_port_out );
211   DECLARE_WRITE8_MEMBER( to8_timer_cp2_out );
212   void to8_lightpen_cb( int step );
213   DECLARE_MACHINE_RESET( to8 );
214   DECLARE_MACHINE_START( to8 );
215   DECLARE_READ8_MEMBER( to9p_timer_port_in );
216   DECLARE_WRITE8_MEMBER( to9p_timer_port_out );
217   DECLARE_MACHINE_RESET( to9p );
218   DECLARE_MACHINE_START( to9p );
219   void mo6_update_ram_bank_postload();
220   void mo6_update_cart_bank_postload();
221   DECLARE_WRITE8_MEMBER( mo6_cartridge_w );
222   DECLARE_READ8_MEMBER( mo6_cartridge_r );
223   DECLARE_WRITE8_MEMBER( mo6_ext_w );
224   DECLARE_WRITE_LINE_MEMBER( mo6_centronics_busy );
225   DECLARE_WRITE8_MEMBER( mo6_game_porta_out );
226   DECLARE_WRITE8_MEMBER( mo6_game_cb2_out );
227   TIMER_CALLBACK_MEMBER( mo6_game_update_cb );
228   DECLARE_READ8_MEMBER( mo6_sys_porta_in );
229   DECLARE_READ8_MEMBER( mo6_sys_portb_in );
230   DECLARE_WRITE8_MEMBER( mo6_sys_porta_out );
231   DECLARE_WRITE8_MEMBER( mo6_sys_portb_out );
232   DECLARE_WRITE8_MEMBER( mo6_sys_cb2_out );
233   DECLARE_READ8_MEMBER( mo6_gatearray_r );
234   DECLARE_WRITE8_MEMBER( mo6_gatearray_w );
235   DECLARE_READ8_MEMBER( mo6_vreg_r );
236   DECLARE_WRITE8_MEMBER( mo6_vreg_w );
237   DECLARE_MACHINE_RESET( mo6 );
238   DECLARE_MACHINE_START( mo6 );
239   DECLARE_READ8_MEMBER( mo5nr_net_r );
240   DECLARE_WRITE8_MEMBER( mo5nr_net_w );
241   DECLARE_READ8_MEMBER( mo5nr_prn_r );
242   DECLARE_WRITE8_MEMBER( mo5nr_prn_w );
243   DECLARE_READ8_MEMBER( mo5nr_sys_portb_in );
244   DECLARE_WRITE8_MEMBER( mo5nr_sys_porta_out );
245   DECLARE_MACHINE_RESET( mo5nr );
246   DECLARE_MACHINE_START( mo5nr );
247   to7_io_dev to7_io_mode();
116248
117extern const mc6846_interface to770_timer;
249   TIMER_CALLBACK_MEMBER( thom_lightpen_step );
250   TIMER_CALLBACK_MEMBER( thom_scanline_start );
251   UINT32 screen_update_thom(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
252   DECLARE_WRITE8_MEMBER( to7_vram_w );
253   DECLARE_WRITE8_MEMBER( to770_vram_w );
254   DECLARE_WRITE8_MEMBER( to8_sys_lo_w );
255   DECLARE_WRITE8_MEMBER( to8_sys_hi_w );
256   DECLARE_WRITE8_MEMBER( to8_data_lo_w );
257   DECLARE_WRITE8_MEMBER( to8_data_hi_w );
258   DECLARE_WRITE8_MEMBER( to8_vcart_w );
259   TIMER_CALLBACK_MEMBER( thom_set_init );
260   void to770_scandraw_16( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
261   void mo5_scandraw_16( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
262   void to9_scandraw_16( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
263   void bitmap4_scandraw_16( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
264   void bitmap4alt_scandraw_16( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
265   void bitmap16_scandraw_16( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
266   void mode80_scandraw_16( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
267   void mode80_to9_scandraw_16( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
268   void page1_scandraw_16( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
269   void page2_scandraw_16( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
270   void overlay_scandraw_16( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
271   void overlay3_scandraw_16( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
272   void to770_scandraw_8( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
273   void mo5_scandraw_8( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
274   void to9_scandraw_8( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
275   void bitmap4_scandraw_8( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
276   void bitmap4alt_scandraw_8( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
277   void bitmap16_scandraw_8( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
278   void mode80_scandraw_8( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
279   void mode80_to9_scandraw_8( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
280   void page1_scandraw_8( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
281   void page2_scandraw_8( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
282   void overlay_scandraw_8( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
283   void overlay3_scandraw_8( UINT8* vram, UINT16* dst, UINT16* pal, int org, int len );
284   void thom_vblank( screen_device &screen, bool state );
285   DECLARE_VIDEO_START( thom );
118286
119/***************************** MO5 ******************************/
287   DECLARE_READ8_MEMBER( to7_5p14_r );
288   DECLARE_WRITE8_MEMBER( to7_5p14_w );
289   DECLARE_READ8_MEMBER( to7_5p14sd_r );
290   DECLARE_WRITE8_MEMBER( to7_5p14sd_w );
291   DECLARE_READ8_MEMBER( to7_qdd_r );
292   DECLARE_WRITE8_MEMBER( to7_qdd_w );
293   TIMER_CALLBACK_MEMBER( thmfc_floppy_cmd_complete_cb );
294   DECLARE_READ8_MEMBER( thmfc_floppy_r );
295   DECLARE_WRITE8_MEMBER( thmfc_floppy_w );
296   TIMER_CALLBACK_MEMBER( ans4 );
297   TIMER_CALLBACK_MEMBER( ans3 );
298   TIMER_CALLBACK_MEMBER( ans2 );
299   TIMER_CALLBACK_MEMBER( ans );
300   DECLARE_READ8_MEMBER( to7_network_r );
301   DECLARE_WRITE8_MEMBER( to7_network_w );
302   DECLARE_READ8_MEMBER( to7_floppy_r );
303   DECLARE_WRITE8_MEMBER( to7_floppy_w );
304   DECLARE_READ8_MEMBER( to9_floppy_r );
305   DECLARE_WRITE8_MEMBER( to9_floppy_w );
306   void thomson_index_callback(device_t *device, int state);
120307
121/* gate-array */
122extern DECLARE_READ8_HANDLER  ( mo5_gatearray_r );
123extern DECLARE_WRITE8_HANDLER ( mo5_gatearray_w );
308protected:
309   required_device<cpu_device> m_maincpu;
310   required_device<cassette_image_device> m_cassette;
311   required_device<dac_device> m_buzzer;
312   required_device<dac_device> m_dac;
313   required_device<centronics_device> m_centronics;
314   required_device<pia6821_device> m_pia_sys;
315   optional_device<pia6821_device> m_pia_io;
316   required_device<pia6821_device> m_pia_game;
317   required_device<device_image_interface> m_serial;
318   required_device<acia6850_device> m_acia;
319   required_device<device_t> m_mea8000;
320   required_device<ram_device> m_ram;
321   optional_device<device_t> m_mc6846;
124322
125/* cartridge / extended RAM bank-switching */
126extern DECLARE_WRITE8_HANDLER ( mo5_ext_w );
127extern DECLARE_WRITE8_HANDLER ( mo5_cartridge_w );
128extern DECLARE_READ8_HANDLER  ( mo5_cartridge_r );
323   /* bank logging and optimisations */
324   int m_old_cart_bank;
325   int m_old_cart_bank_was_read_only;
326   int m_old_ram_bank;
327   int m_old_floppy_bank;
328   /* buffer storing demodulated bits, only for k7 and with speed hack */
329   UINT32 m_to7_k7_bitsize;
330   UINT8* m_to7_k7_bits;
331   /* several devices on the same irqs */
332   UINT8 m_thom_irq;
333   UINT8 m_thom_firq;
334   /* ------------ cartridge ------------ */
335   UINT8 m_thom_cart_nb_banks; /* number of 16 KB banks (up to 4) */
336   UINT8 m_thom_cart_bank;     /* current bank */
337   UINT8 m_to7_lightpen_step;
338   UINT8 m_to7_lightpen;
339   UINT8 m_to7_modem_rx;
340   UINT8 m_to7_modem_tx;
341   /* calls to7_game_update_cb periodically */
342   emu_timer* m_to7_game_timer;
343   UINT8 m_to7_game_sound;
344   UINT8 m_to7_game_mute;
345   emu_timer* m_mo5_periodic_timer;
346   UINT8 m_mo5_reg_cart; /* 0xa7cb bank switch */
347   UINT8 m_to9_palette_data[32];
348   UINT8 m_to9_palette_idx;
349   UINT8 m_to9_soft_bank;
350   UINT8  m_to9_kbd_parity;  /* 0=even, 1=odd, 2=no parity */
351   UINT8  m_to9_kbd_intr;    /* interrupt mode */
352   UINT8  m_to9_kbd_in;      /* data from keyboard */
353   UINT8  m_to9_kbd_status;  /* status */
354   UINT8  m_to9_kbd_overrun; /* character lost */
355   UINT8  m_to9_kbd_periph;     /* peripherial mode */
356   UINT8  m_to9_kbd_byte_count; /* byte-count in peripherial mode */
357   UINT16 m_to9_mouse_x;
358   UINT16 m_to9_mouse_y;
359   UINT8  m_to9_kbd_last_key;  /* for key repetition */
360   UINT16 m_to9_kbd_key_count;
361   UINT8  m_to9_kbd_caps;  /* caps-lock */
362   UINT8  m_to9_kbd_pad;   /* keypad outputs special codes */
363   emu_timer* m_to9_kbd_timer;
364   UINT8  m_to8_kbd_ack;       /* 1 = cpu inits / accepts transfers */
365   UINT16 m_to8_kbd_data;      /* data to transmit */
366   UINT16 m_to8_kbd_step;      /* transmission automaton state */
367   UINT8  m_to8_kbd_last_key;  /* last key (for repetition) */
368   UINT32 m_to8_kbd_key_count; /* keypress time (for repetition)  */
369   UINT8  m_to8_kbd_caps;      /* caps lock */
370   emu_timer* m_to8_kbd_timer;   /* bit-send */
371   emu_timer* m_to8_kbd_signal;  /* signal from CPU */
372   UINT8 m_to8_data_vpage;
373   UINT8 m_to8_cart_vpage;
374   UINT8  m_to8_reg_ram;
375   UINT8  m_to8_reg_cart;
376   UINT8  m_to8_reg_sys1;
377   UINT8  m_to8_reg_sys2;
378   UINT8  m_to8_lightpen_intr;
379   UINT8  m_to8_soft_select;
380   UINT8  m_to8_soft_bank;
381   UINT8  m_to8_bios_bank;
129382
130extern MACHINE_START ( mo5 );
131extern MACHINE_RESET ( mo5 );
383   /* We allow choosing dynamically:
384      - the border size
385      - whether we use 640 pixels or 320 pixels in an active row
386      (now this is automatically choosen by default for each frame)
387   */
388   UINT16 m_thom_bwidth;
389   UINT16 m_thom_bheight;
390   /* border size */
391   UINT8  m_thom_hires;
392   /* 0 = low res: 320x200 active area (faster)
393      1 = hi res:  640x200 active area (can represent all video modes)
394   */
395   UINT8 m_thom_hires_better;
396   /* 1 = a 640 mode was used in the last frame */
397   /* we use our own video timing to precisely cope with VBLANK and HBLANK */
398   emu_timer* m_thom_video_timer; /* time elapsed from beginning of frame */
399   /* number of lightpen call-backs per frame */
400   int m_thom_lightpen_nb;
401   /* called thom_lightpen_nb times */
402   emu_timer *m_thom_lightpen_timer;
403   /* lightpen callback function to call from timer */
404   void (thomson_state::*m_thom_lightpen_cb)(int step);
405   UINT8* m_thom_vram; /* pointer to video memory */
406   emu_timer* m_thom_scanline_timer; /* scan-line udpate */
407   UINT16 m_thom_last_pal[16];   /* palette at last scanline start */
408   UINT16 m_thom_pal[16];        /* current palette */
409   UINT8  m_thom_pal_changed;    /* whether pal != old_pal */
410   UINT8  m_thom_border_index;   /* current border color index */
411   /* the left and right border color for each row (including top and bottom
412      border rows); -1 means unchanged wrt last scanline
413   */
414   INT16 m_thom_border_l[THOM_TOTAL_HEIGHT+1];
415   INT16 m_thom_border_r[THOM_TOTAL_HEIGHT+1];
416   /* active area, updated one scan-line at a time every 64us,
417      then blitted in SCREEN_UPDATE_IND16
418   */
419   UINT16 m_thom_vbody[640*200];
420   UINT8 m_thom_vmode; /* current vide mode */
421   UINT8 m_thom_vpage; /* current video page */
422   /* this stores the video mode & page at each GPL in the current line
423      (-1 means unchanged)
424   */
425   INT16 m_thom_vmodepage[41];
426   UINT8 m_thom_vmodepage_changed;
427   /* one dirty flag for each video memory line */
428   UINT8 m_thom_vmem_dirty[205];
429   /* set to 1 if undirty scanlines need to be redrawn due to other video state
430      changes */
431   UINT8 m_thom_vstate_dirty;
432   UINT8 m_thom_vstate_last_dirty;
433   UINT32 m_thom_mode_point;
434   UINT32 m_thom_floppy_wcount;
435   UINT32 m_thom_floppy_rcount;
436   emu_timer *m_thom_init_timer;
437   void (thomson_state::*m_thom_init_cb)( int init );
132438
439   int to7_get_cassette();
440   void to7_set_cassette( int data );
441   int mo5_get_cassette();
442   void mo5_set_cassette( int data );
443   void thom_set_irq( int line, int state );
444   void thom_set_firq( int line, int state );
445   void thom_irq_reset();
446   void thom_irq_init();
447   void thom_irq_0( int state );
448   void thom_irq_3( int state );
449   void thom_firq_2( int state );
450   void thom_irq_4( int state );
451   void thom_set_caps_led( int led );
452   void to7_update_cart_bank();
453   void to7_set_init( int init );
454   void to7_modem_reset();
455   void to7_modem_init();
456   UINT8 to7_get_mouse_signal();
457   void to7_game_sound_update();
458   void to7_game_init();
459   void to7_game_reset();
460   void to7_midi_reset();
461   void to7_midi_init();
462   void to770_update_ram_bank();
463   void mo5_init_timer();
464   void mo5_update_cart_bank();
465   void to9_set_video_mode( UINT8 data, int style );
466   void to9_palette_init();
467   void to9_update_cart_bank();
468   void to9_update_ram_bank();
469   int to9_kbd_ktest();
470   void to9_kbd_update_irq();
471   void to9_kbd_send( UINT8 data, int parity );
472   int to9_kbd_get_key();
473   void to9_kbd_reset();
474   void to9_kbd_init();
475   int to8_kbd_ktest();
476   int to8_kbd_get_key();
477   void to8_kbd_timer_func();
478   void to8_kbd_set_ack( int data );
479   void to8_kbd_reset();
480   void to8_kbd_init();
481   void to8_update_floppy_bank();
482   void to8_update_ram_bank();
483   void to8_update_cart_bank();
484   void to8_floppy_init();
485   void to8_floppy_reset();
486   void mo6_update_ram_bank();
487   void mo6_update_cart_bank();
488   void mo6_game_init();
489   void mo6_game_reset();
490   void mo5nr_game_init();
491   void mo5nr_game_reset();
133492
134/***************************** TO9 ******************************/
493   int thom_update_screen_size();
494   unsigned thom_video_elapsed();
495   struct thom_vsignal thom_get_vsignal();
496   void thom_get_lightpen_pos( int*x, int* y );
497   struct thom_vsignal thom_get_lightpen_vsignal( int xdec, int ydec, int xdec2 );
498   void thom_set_lightpen_callback( int nb );
499   int thom_mode_is_hires( int mode );
500   void thom_border_changed();
501   void thom_gplinfo_changed();
502   void thom_set_border_color( unsigned index );
503   void thom_set_palette( unsigned index, UINT16 color );
504   void thom_set_video_mode( unsigned mode );
505   void thom_set_video_page( unsigned page );
506   void thom_set_mode_point( int point );
507   void thom_floppy_active( int write );
508   unsigned to7_lightpen_gpl( int decx, int decy );
135509
136/* IEEE extension */
137extern DECLARE_WRITE8_HANDLER ( to9_ieee_w );
138extern DECLARE_READ8_HANDLER  ( to9_ieee_r );
510   int thom_floppy_make_addr( chrn_id id, UINT8* dst, int sector_size );
511   int thom_floppy_make_sector( device_t* img, chrn_id id, UINT8* dst, int sector_size );
512   int thom_floppy_make_track( device_t* img, UINT8* dst, int sector_size, int side );
513   int thom_qdd_make_addr( int sector, UINT8* dst );
514   int thom_qdd_make_sector( device_t* img, int sector, UINT8* dst );
515   int thom_qdd_make_disk ( device_t* img, UINT8* dst );
516   void to7_5p14_reset();
517   void to7_5p14_init();
518   void to7_5p14_index_pulse_callback( device_t *controller,device_t *image, int state );
519   void to7_5p14sd_reset();
520   void to7_5p14sd_init();
521   void to7_qdd_index_pulse_cb( device_t *controller,device_t *image, int state );
522   device_t * to7_qdd_image();
523   void to7_qdd_stat_update();
524   UINT8 to7_qdd_read_byte();
525   void to7_qdd_write_byte( UINT8 data );
526   void to7_qdd_reset();
527   void to7_qdd_init();
528   device_t * thmfc_floppy_image();
529   int thmfc_floppy_is_qdd( device_image_interface *image );
530   void thmfc_floppy_index_pulse_cb( device_t *controller,device_t *image, int state );
531   int thmfc_floppy_find_sector( chrn_id* dst );
532   void thmfc_floppy_cmd_complete();
533   UINT8 thmfc_floppy_read_byte();
534   UINT8 thmfc_floppy_raw_read_byte();
535   void thmfc_floppy_qdd_write_byte( UINT8 data );
536   void thmfc_floppy_write_byte( UINT8 data );
537   void thmfc_floppy_format_byte( UINT8 data );
538   void thmfc_floppy_reset();
539   void thmfc_floppy_init();
540   void to7_network_init();
541   void to7_network_reset();
542   void to7_floppy_init( void* base );
543   void to7_floppy_reset();
544   void to9_floppy_init(void* int_base, void* ext_base);
545   void to9_floppy_reset();
546};
139547
140/* ROM bank-switching */
141extern DECLARE_WRITE8_HANDLER ( to9_cartridge_w );
142extern DECLARE_READ8_HANDLER  ( to9_cartridge_r );
548/*----------- defined in machine/thomson.c -----------*/
143549
144/* system gate-array */
145extern DECLARE_READ8_HANDLER  ( to9_gatearray_r );
146extern DECLARE_WRITE8_HANDLER ( to9_gatearray_w );
147
148/* video gate-array */
149extern DECLARE_READ8_HANDLER  ( to9_vreg_r );
150extern DECLARE_WRITE8_HANDLER ( to9_vreg_w );
151
152/* keyboard */
153extern DECLARE_READ8_HANDLER  ( to9_kbd_r );
154extern DECLARE_WRITE8_HANDLER ( to9_kbd_w );
155
156extern MACHINE_START ( to9 );
157extern MACHINE_RESET ( to9 );
158
550extern const pia6821_interface to7_pia6821_sys;
551extern const pia6821_interface to7_pia6821_io;
552extern const pia6821_interface to7_pia6821_modem;
553extern const pia6821_interface to7_pia6821_game;
554extern const pia6821_interface to770_pia6821_sys;
555extern const pia6821_interface mo5_pia6821_sys;
556extern const pia6821_interface to9_pia6821_sys;
557extern const pia6821_interface to8_pia6821_sys;
558extern const pia6821_interface to9p_pia6821_sys;
559extern const pia6821_interface mo6_pia6821_game;
560extern const pia6821_interface mo6_pia6821_sys;
561extern const pia6821_interface mo5nr_pia6821_sys;
562extern const pia6821_interface mo5nr_pia6821_game;
563extern const centronics_interface to7_centronics_config;
564extern const centronics_interface mo6_centronics_config;
565extern const mc6846_interface to7_timer;
566extern const mea8000_interface to7_speech;
567extern const acia6850_interface to7_modem;
568extern const mc6846_interface to770_timer;
159569extern const mc6846_interface to9_timer;
160570
161
162571/***************************** TO8 ******************************/
163572
164/* bank-switching */
165#define TO8_SYS_LO      "bank5" /* system RAM low 2 Kb */
166#define TO8_SYS_HI      "bank6" /* system RAM hi 2 Kb */
167#define TO8_DATA_LO     "bank7" /* data RAM low 2 Kb */
168#define TO8_DATA_HI     "bank8" /* data RAM hi 2 Kb */
169#define TO8_BIOS_BANK   "bank9" /* BIOS ROM */
170
171extern UINT8 to8_data_vpage;
172extern UINT8 to8_cart_vpage;
173
174extern DECLARE_WRITE8_HANDLER ( to8_cartridge_w );
175extern DECLARE_READ8_HANDLER  ( to8_cartridge_r );
176
177/* system gate-array */
178extern DECLARE_READ8_HANDLER  ( to8_gatearray_r );
179extern DECLARE_WRITE8_HANDLER ( to8_gatearray_w );
180
181/* video gate-array */
182extern DECLARE_READ8_HANDLER  ( to8_vreg_r );
183extern DECLARE_WRITE8_HANDLER ( to8_vreg_w );
184
185/* floppy */
186extern DECLARE_READ8_HANDLER  ( to8_floppy_r );
187extern DECLARE_WRITE8_HANDLER ( to8_floppy_w );
188
189extern MACHINE_START ( to8 );
190extern MACHINE_RESET ( to8 );
191
192573extern const mc6846_interface to8_timer;
193
194
195/***************************** TO9+ ******************************/
196
197extern MACHINE_START ( to9p );
198extern MACHINE_RESET ( to9p );
199
200574extern const mc6846_interface to9p_timer;
201575
202576
203/***************************** MO6 ******************************/
204
205extern DECLARE_READ8_HANDLER  ( mo6_cartridge_r );
206extern DECLARE_WRITE8_HANDLER ( mo6_cartridge_w );
207extern DECLARE_WRITE8_HANDLER ( mo6_ext_w );
208
209/* system gate-array */
210extern DECLARE_READ8_HANDLER  ( mo6_gatearray_r );
211extern DECLARE_WRITE8_HANDLER ( mo6_gatearray_w );
212
213/* video gate-array */
214extern DECLARE_READ8_HANDLER  ( mo6_vreg_r );
215extern DECLARE_WRITE8_HANDLER ( mo6_vreg_w );
216
217extern MACHINE_START ( mo6 );
218extern MACHINE_RESET ( mo6 );
219
220
221/***************************** MO5 NR ******************************/
222
223/* network */
224extern DECLARE_READ8_HANDLER  ( mo5nr_net_r );
225extern DECLARE_WRITE8_HANDLER ( mo5nr_net_w );
226
227/* printer */
228extern DECLARE_READ8_HANDLER  ( mo5nr_prn_r );
229extern DECLARE_WRITE8_HANDLER ( mo5nr_prn_w );
230
231extern MACHINE_START ( mo5nr );
232extern MACHINE_RESET ( mo5nr );
233
234
235577/*----------- defined in video/thomson.c -----------*/
236578
237579/*
r21425r21426
255597
256598/***************************** dimensions **************************/
257599
258/* original screen dimension (may be different from emulated screen!) */
259#define THOM_ACTIVE_WIDTH  320
260#define THOM_BORDER_WIDTH   56
261#define THOM_ACTIVE_HEIGHT 200
262#define THOM_BORDER_HEIGHT  47
263#define THOM_TOTAL_WIDTH   432
264#define THOM_TOTAL_HEIGHT  294
265600
266/* Emulated screen dimension may be doubled to allow hi-res 640x200 mode.
267   Emulated screen can have smaller borders.
268 */
269
270/* maximum number of video pages:
271   1 for TO7 generation (including MO5)
272   4 for TO8 generation (including TO9, MO6)
273 */
274#define THOM_NB_PAGES 4
275
276/* page 0 is banked */
277#define THOM_VRAM_BANK "bank1"
278
279extern UINT8* thom_vram;
280
281601/*********************** video signals *****************************/
282602
283struct thom_vsignal {
284   unsigned count;  /* pixel counter */
285   unsigned init;   /* 1 -> active vertical windos, 0 -> border/VBLANK */
286   unsigned inil;   /* 1 -> active horizontal window, 0 -> border/HBLANK */
287   unsigned lt3;    /* bit 3 of us counter */
288   unsigned line;   /* line counter */
289};
290
291/* current video position */
292extern struct thom_vsignal thom_get_vsignal ( running_machine &machine );
293
294
295/************************* lightpen ********************************/
296
297/* specific TO7 / T9000 lightpen code (no video gate-array) */
298extern unsigned to7_lightpen_gpl ( running_machine &machine, int decx, int decy );
299
300/* video position corresponding to lightpen (with some offset) */
301extern struct thom_vsignal thom_get_lightpen_vsignal ( running_machine &machine, int xdec, int ydec,
302                        int xdec2 );
303
304/* specify a lightpencall-back function, called nb times per frame */
305extern void thom_set_lightpen_callback ( running_machine &machine, int nb, void (*cb) ( running_machine &machine, int step ) );
306
307
308603/***************************** commons *****************************/
309604
310extern VIDEO_START  ( thom );
311extern SCREEN_UPDATE_IND16 ( thom );
312605extern PALETTE_INIT ( thom );
313extern SCREEN_VBLANK    ( thom );
314606
315/* pass video init signal */
316extern void thom_set_init_callback ( running_machine &machine, void (*cb) ( running_machine &machine, int init ) );
317607
318/* TO7 TO7/70 MO5 video bank switch */
319extern void thom_set_mode_point ( running_machine &machine, int point );
320
321/* set the palette index for the border color */
322extern void thom_set_border_color ( running_machine &machine, unsigned color );
323
324/* set one of 16 palette indices to one of 4096 colors */
325extern void thom_set_palette ( running_machine &machine, unsigned index, UINT16 color );
326
327
328608/* video modes */
329609#define THOM_VMODE_TO770       0
330610#define THOM_VMODE_MO5         1
r21425r21426
340620#define THOM_VMODE_80_TO9     11
341621#define THOM_VMODE_NB         12
342622
343/* change the current video-mode */
344extern void thom_set_video_mode ( running_machine &machine, unsigned mode );
345623
346/* select which video page shown among the 4 available */
347extern void thom_set_video_page ( running_machine &machine, unsigned page );
348
349/* to tell there is some floppy activity, stays up for a few frames */
350extern void thom_floppy_active ( running_machine &machine, int write );
351
352
353/***************************** TO7 / T9000 *************************/
354
355extern DECLARE_WRITE8_HANDLER ( to7_vram_w );
356
357
358/***************************** TO7/70 ******************************/
359
360extern DECLARE_WRITE8_HANDLER ( to770_vram_w );
361
362
363/***************************** TO8 ******************************/
364
365/* write to video memory through system space (always page 1) */
366DECLARE_WRITE8_HANDLER ( to8_sys_lo_w );
367DECLARE_WRITE8_HANDLER ( to8_sys_hi_w );
368
369/* write to video memory through data space */
370DECLARE_WRITE8_HANDLER ( to8_data_lo_w );
371DECLARE_WRITE8_HANDLER ( to8_data_hi_w );
372
373/* write to video memory page through cartridge addresses space */
374DECLARE_WRITE8_HANDLER ( to8_vcart_w );
375
376
377
378624class to7_io_line_device :  public device_t,
379625                     public device_serial_interface
380626{

Previous 199869 Revisions Next


© 1997-2024 The MAME Team