Previous 15994 Revisions Next

r3837 Tuesday 16th December, 2008 at 08:17:52 UTC by Miodrag Milanović
Removed some depicate.h dependency, and converted i8271 to device
[src/mess/drivers]amstrad.c atom.c bbc.c nc.c newbrain.c pcw.c pcw16.c sg1000.c sord.c x68k.c
[src/mess/includes]atom.h bbc.h coco.h
[src/mess/machine]at.c atom.c bbc.c bebox.c coco.c compis.c hd63450.c hd63450.h i8271.c i8271.h kc.c nec765.c nec765.h pc.c pc8801.c pc_fdc.c pc_fdc.h
[src/mess/video]apf.c coco.c m6847.c m6847.h pc_vga.c pc_vga.h vtech1.c

src/mess/video/coco.c
r3836r3837
1717***************************************************************************/
1818
1919#include "driver.h"
20#include "deprecat.h"
2120#include "machine/6821pia.h"
2221#include "machine/6883sam.h"
2322#include "video/m6847.h"
r3836r3837
4746
4847
4948
50static void coco_horizontal_sync_callback(int data)
49static void coco_horizontal_sync_callback(running_machine *machine, int data)
5150{
52   const address_space *space = cpu_get_address_space( Machine->cpu[0], ADDRESS_SPACE_PROGRAM );
51   const address_space *space = cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM );
5352
5453   pia_0_ca1_w(space, 0, data);
5554}
5655
5756
5857
59static void coco_field_sync_callback(int data)
58static void coco_field_sync_callback(running_machine *machine, int data)
6059{
61   const address_space *space = cpu_get_address_space( Machine->cpu[0], ADDRESS_SPACE_PROGRAM );
60   const address_space *space = cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM );
6261
6362   pia_0_cb1_w(space, 0, data);
6463}
src/mess/video/pc_vga.c
r3836r3837
584584               read_handler = SMH_NOP;
585585               write_handler = SMH_NOP;
586586            }
587            vga.vga_intf.map_vga_memory(0xA0000, 0xBFFFF, read_handler, write_handler);
587            vga.vga_intf.map_vga_memory(machine, 0xA0000, 0xBFFFF, read_handler, write_handler);
588588
589589            if (vga.vga_intf.vga_memory_bank != 0)
590590               memory_set_bankptr(machine,vga.vga_intf.vga_memory_bank, vga.memory);
591591            break;
592592         case 0x04:
593            vga.vga_intf.map_vga_memory(0xA0000, 0xAFFFF, read_handler, write_handler);
593            vga.vga_intf.map_vga_memory(machine, 0xA0000, 0xAFFFF, read_handler, write_handler);
594594            break;
595595         case 0x08:
596            vga.vga_intf.map_vga_memory(0xB0000, 0xB7FFF, read_handler, write_handler);
596            vga.vga_intf.map_vga_memory(machine, 0xB0000, 0xB7FFF, read_handler, write_handler);
597597            break;
598598         case 0x0C:
599            vga.vga_intf.map_vga_memory(0xB8000, 0xBFFFF, read_handler, write_handler);
599            vga.vga_intf.map_vga_memory(machine, 0xB8000, 0xBFFFF, read_handler, write_handler);
600600            break;
601601      }
602602   }
src/mess/video/pc_vga.h
r3836r3837
1919{
2020   /* VGA memory mapper */
2121   int vga_memory_bank;
22   void (*map_vga_memory)(offs_t begin, offs_t end, read8_space_func rh, write8_space_func wh);
22   void (*map_vga_memory)(running_machine *machine, offs_t begin, offs_t end, read8_space_func rh, write8_space_func wh);
2323
2424   /* VGA dipswitch (???) */
2525   read8_space_func read_dipswitch;
src/mess/video/m6847.c
r3836r3837
6464**********************************************************************/
6565
6666#include "driver.h"
67#include "deprecat.h"
6867#include "m6847.h"
6968
7069#include "debug/debugcpu.h"
r3836r3837
107106struct _m6847_vdg
108107{
109108   /* callbacks */
110   void (*horizontal_sync_callback)(int line);
111   void (*field_sync_callback)(int line);
109   void (*horizontal_sync_callback)(running_machine *machine,int line);
110   void (*field_sync_callback)(running_machine *machine,int line);
112111   UINT8 (*get_attributes)(UINT8 video_byte);
113112   const UINT8 *(*get_video_ram)(int scanline);
114113   int (*new_frame_callback)(void);   /* returns whether the M6847 is in charge of this frame */
r3836r3837
15741573 *
15751574 *************************************/
15761575
1577int m6847_get_horizontal_sync(void)
1576int m6847_get_horizontal_sync(running_machine *machine)
15781577{
15791578   attotime fire_time = timer_firetime(m6847->hs_fall_timer);
1580   return attotime_compare(fire_time, timer_get_time(Machine)) > 0;
1579   return attotime_compare(fire_time, timer_get_time(machine)) > 0;
15811580}
15821581
15831582
15841583
1585static void set_horizontal_sync(void)
1584static void set_horizontal_sync(running_machine *machine)
15861585{
15871586   attotime fire_time = timer_firetime(m6847->hs_fall_timer);
1588   int horizontal_sync = attotime_compare(fire_time, timer_get_time(Machine)) > 0;
1587   int horizontal_sync = attotime_compare(fire_time, timer_get_time(machine)) > 0;
15891588   if (m6847->horizontal_sync_callback)
1590      m6847->horizontal_sync_callback(!horizontal_sync);
1589      m6847->horizontal_sync_callback(machine, !horizontal_sync);
15911590}
15921591
15931592
15941593
1595int m6847_get_field_sync(void)
1594int m6847_get_field_sync(running_machine *machine)
15961595{
15971596   attotime fire_time = timer_firetime(m6847->fs_fall_timer);
1598   return attotime_compare(fire_time, timer_get_time(Machine)) > 0;
1597   return attotime_compare(fire_time, timer_get_time(machine)) > 0;
15991598}
16001599
16011600
16021601
1603static void set_field_sync(void)
1602static void set_field_sync(running_machine *machine)
16041603{
16051604   attotime fire_time = timer_firetime(m6847->fs_fall_timer);
1606   int field_sync = attotime_compare(fire_time, timer_get_time(Machine)) > 0;
1605   int field_sync = attotime_compare(fire_time, timer_get_time(machine)) > 0;
16071606   if (m6847->field_sync_callback)
1608      m6847->field_sync_callback(field_sync);
1607      m6847->field_sync_callback(machine,field_sync);
16091608}
16101609
16111610
r3836r3837
16211620   if (LOG_HS)
16221621      logerror("hs_fall(): time=%s\n", attotime_string(timer_get_time(machine), ATTOTIME_STRING_PRECISION));
16231622
1624   set_horizontal_sync();
1623   set_horizontal_sync(machine);
16251624}
16261625
16271626static TIMER_CALLBACK(hs_rise)
r3836r3837
16341633   timer_adjust_oneshot(m6847->hs_fall_timer,
16351634      attotime_make(0, m6847->horizontal_sync_period), 0);
16361635
1637   set_horizontal_sync();
1636   set_horizontal_sync(machine);
16381637   prepare_scanline(0);
16391638}
16401639
r3836r3837
16431642   if (LOG_FS)
16441643      logerror("fs_fall(): time=%s scanline=%d\n", attotime_string(timer_get_time(machine), ATTOTIME_STRING_PRECISION), get_scanline());
16451644
1646   set_field_sync();
1645   set_field_sync(machine);
16471646}
16481647
16491648static TIMER_CALLBACK(fs_rise)
r3836r3837
16621661   if (m6847->new_frame_callback)
16631662      m6847->using_custom = !m6847->new_frame_callback();
16641663
1665   set_field_sync();
1664   set_field_sync(machine);
16661665}
16671666
16681667
r3836r3837
18011800
18021801static STATE_POSTLOAD( m6847_postload )
18031802{
1804   set_field_sync();
1805   set_horizontal_sync();
1803   set_field_sync(machine);
1804   set_horizontal_sync(machine);
18061805   set_dirty();
18071806}
18081807
r3836r3837
20022001
20032002
20042003
2005UINT64 m6847_time(m6847_timing_type timing)
2004UINT64 m6847_time(running_machine *machine, m6847_timing_type timing)
20062005{
2007   attotime current_time = timer_get_time(Machine);
2006   attotime current_time = timer_get_time(machine);
20082007   attotime divisor = interval(timing);
20092008   return divide_mame_time(current_time, divisor);
20102009}
20112010
20122011
20132012
2014attotime m6847_time_until(m6847_timing_type timing, UINT64 target_time)
2013attotime m6847_time_until(running_machine *machine, m6847_timing_type timing, UINT64 target_time)
20152014{
20162015   attotime target_mame_time, current_time;
20172016   target_mame_time = attotime_mul(interval(timing), target_time);
2018   current_time = timer_get_time(Machine);
2017   current_time = timer_get_time(machine);
20192018
20202019   if (attotime_compare(target_mame_time, current_time) < 0)
20212020      fatalerror("m6847_time_until(): cannot target past times");
src/mess/video/m6847.h
r3836r3837
5151   int cpu0_timing_factor;
5252
5353   /* callbacks */
54   void (*horizontal_sync_callback)(int line);
55   void (*field_sync_callback)(int line);
54   void (*horizontal_sync_callback)(running_machine *machine, int line);
55   void (*field_sync_callback)(running_machine *machine,int line);
5656   UINT8 (*get_attributes)(UINT8 video_byte) ATTR_CONST;
5757   const UINT8 *(*get_video_ram)(int scanline);
5858
r3836r3837
7171void m6847_video_changed(void);
7272
7373/* sync */
74int m6847_get_horizontal_sync(void);
75int m6847_get_field_sync(void);
74int m6847_get_horizontal_sync(running_machine *machine);
75int m6847_get_field_sync(running_machine *machine);
7676
7777/* timing functions */
78UINT64 m6847_time(m6847_timing_type timing);
79attotime m6847_time_until(m6847_timing_type timing, UINT64 target_time);
78UINT64 m6847_time(running_machine *machine,m6847_timing_type timing);
79attotime m6847_time_until(running_machine *machine, m6847_timing_type timing, UINT64 target_time);
8080
8181/* CoCo 3 hooks */
8282attotime m6847_scanline_time(int scanline);
src/mess/video/apf.c
r3836r3837
33******************************************************************************/
44
55#include "driver.h"
6#include "deprecat.h"
76#include "video/m6847.h"
87#include "includes/apf.h"
98
r3836r3837
3130  return apf_video_ram[(character&0x1f)*0x10+line+0x200];
3231}
3332
34static void apf_vsync_int(int line)
33static void apf_vsync_int(running_machine *machine, int line)
3534{
3635   if (line)
3736      apf_ints |= 0x10;
3837   else
3938      apf_ints &= ~0x10;
40   apf_update_ints(Machine);
39   apf_update_ints(machine);
4140}
4241
4342
src/mess/video/vtech1.c
r3836r3837
2828******************************************************************************/
2929
3030#include "driver.h"
31#include "deprecat.h"
3231#include "includes/vtech1.h"
3332#include "video/m6847.h"
3433
r3836r3837
8786 * location 0038 HEX every 20ms.
8887 *
8988 */
90static void vtech1_field_sync_callback(int data)
89static void vtech1_field_sync_callback(running_machine *machine, int data)
9190{
9291   if (data)
93      cpu_set_input_line(Machine->cpu[0], 0, CLEAR_LINE);
92      cpu_set_input_line(machine->cpu[0], 0, CLEAR_LINE);
9493   else
95      cpu_set_input_line(Machine->cpu[0], 0, HOLD_LINE);
94      cpu_set_input_line(machine->cpu[0], 0, HOLD_LINE);
9695}
9796
9897
src/mess/includes/coco.h
r3836r3837
7171WRITE8_HANDLER ( coco3_cartridge_w );
7272offs_t coco3_mmu_translate(int bank, int offset);
7373WRITE8_HANDLER( coco_pia_1_w );
74void coco3_horizontal_sync_callback(int data);
75void coco3_field_sync_callback(int data);
74void coco3_horizontal_sync_callback(running_machine *machine,int data);
75void coco3_field_sync_callback(running_machine *machine,int data);
7676void coco3_gime_field_sync_callback(running_machine *machine);
7777
7878/* Compusense Dragon Plus board */
src/mess/includes/atom.h
r3836r3837
99
1010#include "devices/snapquik.h"
1111#include "machine/8255ppi.h"
12#include "machine/i8271.h"
1213
13
1414/*----------- defined in machine/atom.c -----------*/
1515
1616extern UINT8 atom_8255_porta;
1717extern UINT8 atom_8255_portc;
1818
1919extern const ppi8255_interface atom_8255_int;
20extern const i8271_interface atom_8271_interface;
2021
2122MACHINE_RESET( atom );
2223QUICKLOAD_LOAD( atom );
src/mess/includes/bbc.h
r3836r3837
1111#ifndef BBC_H_
1212#define BBC_H_
1313
14#include "machine/i8271.h"
1415#include "machine/upd7002.h"
1516
1617/*----------- defined in machine/bbc.c -----------*/
r3836r3837
9091
9192WRITE8_HANDLER ( BBC_SerialULA_w );
9293
94extern const i8271_interface bbc_i8271_interface;
9395extern const uPD7002_interface BBC_uPD7002;
9496
9597/*----------- defined in video/bbc.c -----------*/
src/mess/machine/coco.c
r3836r3837
902902
903903
904904
905void coco3_horizontal_sync_callback(int data)
905void coco3_horizontal_sync_callback(running_machine *machine,int data)
906906{
907   const address_space *space = cpu_get_address_space( Machine->cpu[0], ADDRESS_SPACE_PROGRAM );
907   const address_space *space = cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM );
908908
909909   pia_0_ca1_w(space, 0, data);
910   coco3_raise_interrupt(Machine, COCO3_INT_HBORD, data);
910   coco3_raise_interrupt(machine, COCO3_INT_HBORD, data);
911911}
912912
913913
914914
915void coco3_field_sync_callback(int data)
915void coco3_field_sync_callback(running_machine *machine,int data)
916916{
917   const address_space *space = cpu_get_address_space( Machine->cpu[0], ADDRESS_SPACE_PROGRAM );
917   const address_space *space = cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM );
918918
919919   pia_0_cb1_w(space, 0, data);
920920}
r3836r3837
20912091
20922092static emu_timer *coco3_gime_timer;
20932093
2094static void coco3_timer_reset(void)
2094static void coco3_timer_reset(running_machine *machine)
20952095{
20962096   /* reset the timer; take the value stored in $FF94-5 and start the timer ticking */
20972097   UINT64 current_time;
r3836r3837
21142114      timing = (coco3_gimereg[1] & 0x20) ? M6847_CLOCK : M6847_HSYNC;
21152115
21162116      /* determine the current time */
2117      current_time = m6847_time(timing);
2117      current_time = m6847_time(machine, timing);
21182118
21192119      /* calculate the time */
2120      target_time = m6847_time_until(timing, current_time + timer_value);
2120      target_time = m6847_time_until(machine, timing, current_time + timer_value);
21212121      if (LOG_TIMER)
21222122         logerror("coco3_reset_timer(): target_time=%g\n", attotime_to_double(target_time));
21232123
r3836r3837
21372137
21382138static TIMER_CALLBACK(coco3_timer_proc)
21392139{
2140   coco3_timer_reset();
2140   coco3_timer_reset(machine);
21412141   coco3_vh_blink();
21422142   coco3_raise_interrupt(machine, COCO3_INT_TMR, 1);
21432143   coco3_raise_interrupt(machine, COCO3_INT_TMR, 0);
r3836r3837
24262426         *        Bit 0 TR Task register select
24272427         */
24282428         coco3_mmu_update(space->machine, 0, 8);
2429         coco3_timer_reset();
2429         coco3_timer_reset(space->machine);
24302430         break;
24312431
24322432      case 2:
r3836r3837
24822482         *        Bits 4-7 Unused
24832483         *        Bits 0-3 High order four bits of the timer
24842484         */
2485         coco3_timer_reset();
2485         coco3_timer_reset(space->machine);
24862486         break;
24872487
24882488      case 5:
r3836r3837
25022502                             * thanks to John Kowalski for pointing me in the right
25032503                             * direction
25042504            */
2505            coco3_timer_reset();
2505            coco3_timer_reset(space->machine);
25062506                     }
25072507         break;
25082508
src/mess/machine/at.c
r3836r3837
391391
392392#define FDC_DMA 2
393393
394static void at_fdc_interrupt(int state)
394static void at_fdc_interrupt(running_machine *machine, int state)
395395{
396396   pic8259_set_irq_line(at_devices.pic8259_master, 6, state);
397397//if ( mess_ram[0x0490] == 0x74 )
r3836r3837
399399}
400400
401401
402static void at_fdc_dma_drq(int state, int read_)
402static void at_fdc_dma_drq(running_machine *machine, int state, int read_)
403403{
404404   dma8237_drq_write( at_devices.dma8237_1, FDC_DMA, state);
405405}
r3836r3837
677677
678678
679679
680static void at_map_vga_memory(offs_t begin, offs_t end, read8_space_func rh, write8_space_func wh)
680static void at_map_vga_memory(running_machine *machine, offs_t begin, offs_t end, read8_space_func rh, write8_space_func wh)
681681{
682682   int buswidth;
683   const address_space *space = cpu_get_address_space(Machine->cpu[0], ADDRESS_SPACE_PROGRAM);
684   buswidth = cpu_get_databus_width(Machine->cpu[0], ADDRESS_SPACE_PROGRAM);
683   const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM);
684   buswidth = cpu_get_databus_width(machine->cpu[0], ADDRESS_SPACE_PROGRAM);
685685   switch(buswidth)
686686   {
687687      case 8:
src/mess/machine/compis.c
r3836r3837
1313/*-------------------------------------------------------------------------*/
1414
1515#include "driver.h"
16#include "deprecat.h"
1716#include "cpu/i86/i186intf.h"
1817#include "video/i82720.h"
1918#include "machine/8255ppi.h"
r3836r3837
305304   }
306305}
307306
308static void compis_fdc_int(int state)
307static void compis_fdc_int(running_machine *machine,int state)
309308{
310309   /* No interrupt requests if iSBX-218A has DMA enabled */
311     if (!input_port_read(Machine, "DSW1") && state)
310     if (!input_port_read(machine, "DSW1") && state)
312311   {
313312      compis_osp_pic_irq(COMPIS_IRQ_SBX0_INT1);
314313   }
315314}
316315
317static void compis_fdc_dma_drq(int state, int read)
316static void compis_fdc_dma_drq(running_machine *machine,int state, int read)
318317{
319318   /* DMA requst if iSBX-218A has DMA enabled */
320     if (input_port_read(Machine, "DSW1") && state)
319     if (input_port_read(machine, "DSW1") && state)
321320   {
322321      //compis_dma_drq(state, read);
323322   }
r3836r3837
822821}
823822
824823
825static void internal_timer_update(int which,
824static void internal_timer_update(running_machine *machine,
825                          int which,
826826                                  int new_count,
827827                                  int new_maxA,
828828                                  int new_maxB,
r3836r3837
892892      diff = new_control ^ t->control;
893893      if (diff & 0x001c)
894894        logerror("%05X:ERROR! -unsupported timer mode %04X\n",
895            cpu_get_pc(Machine->cpu[0]),
895            cpu_get_pc(machine->cpu[0]),
896896            new_control);
897897
898898      /* if we have real changes, update things */
r3836r3837
980980}
981981
982982
983static void update_dma_control(int which, int new_control)
983static void update_dma_control(running_machine *machine, int which, int new_control)
984984{
985985   struct dma_state *d = &i186.dma[which];
986986   int diff;
r3836r3837
994994   diff = new_control ^ d->control;
995995   if (diff & 0x6811)
996996     logerror("%05X:ERROR! - unsupported DMA mode %04X\n",
997         cpu_get_pc(Machine->cpu[0]),
997         cpu_get_pc(machine->cpu[0]),
998998         new_control);
999999
10001000   /* if we're going live, set a timer */
r3836r3837
13221322      case 0x30:
13231323         if (LOG_PORTS) logerror("%05X:80186 Timer %d count = %04X\n", cpu_get_pc(space->cpu), (offset - 0x28) / 4, data16);
13241324         which = (offset - 0x28) / 4;
1325         internal_timer_update(which, data16, -1, -1, -1);
1325         internal_timer_update(space->machine,which, data16, -1, -1, -1);
13261326         break;
13271327
13281328      case 0x29:
r3836r3837
13301330      case 0x31:
13311331         if (LOG_PORTS) logerror("%05X:80186 Timer %d max A = %04X\n", cpu_get_pc(space->cpu), (offset - 0x29) / 4, data16);
13321332         which = (offset - 0x29) / 4;
1333         internal_timer_update(which, -1, data16, -1, -1);
1333         internal_timer_update(space->machine,which, -1, data16, -1, -1);
13341334         break;
13351335
13361336      case 0x2a:
13371337      case 0x2e:
13381338         if (LOG_PORTS) logerror("%05X:80186 Timer %d max B = %04X\n", cpu_get_pc(space->cpu), (offset - 0x2a) / 4, data16);
13391339         which = (offset - 0x2a) / 4;
1340         internal_timer_update(which, -1, -1, data16, -1);
1340         internal_timer_update(space->machine,which, -1, -1, data16, -1);
13411341         break;
13421342
13431343      case 0x2b:
r3836r3837
13451345      case 0x33:
13461346         if (LOG_PORTS) logerror("%05X:80186 Timer %d control = %04X\n", cpu_get_pc(space->cpu), (offset - 0x2b) / 4, data16);
13471347         which = (offset - 0x2b) / 4;
1348         internal_timer_update(which, -1, -1, -1, data16);
1348         internal_timer_update(space->machine,which, -1, -1, -1, data16);
13491349         break;
13501350
13511351      case 0x50:
r3836r3837
14361436         if (LOG_PORTS) logerror("%05X:80186 DMA%d control = %04X\n", cpu_get_pc(space->cpu), (offset - 0x65) / 8, data16);
14371437         which = (offset - 0x65) / 8;
14381438//         stream_update(dma_stream, 0);
1439         update_dma_control(which, data16);
1439         update_dma_control(space->machine, which, data16);
14401440         break;
14411441
14421442      case 0x7f:
src/mess/machine/nec765.c
r3836r3837
125125static int nec765_sector_count_complete(running_machine *machine);
126126static void nec765_increment_sector(running_machine *machine);
127127static void nec765_update_state(running_machine *machine);
128static void nec765_set_dma_drq(int state);
129static void nec765_set_int(int state);
128static void nec765_set_dma_drq(running_machine *machine,int state);
129static void nec765_set_int(running_machine *machine,int state);
130130
131131static NEC765 fdc;
132132static char nec765_data_buffer[32*1024];
r3836r3837
154154   }
155155   else
156156   {
157      image = nec765_iface.get_image(fdc.drive);
157      image = nec765_iface.get_image(machine, fdc.drive);
158158   }
159159   return image;
160160}
r3836r3837
305305   /* set drive and side */
306306   fdc.nec765_status[0] |= fdc.drive | (fdc.side<<2);
307307
308   nec765_set_int(0);
309   nec765_set_int(1);
308   nec765_set_int(machine,0);
309   nec765_set_int(machine,1);
310310
311311   fdc.nec765_flags &= ~NEC765_SEEK_ACTIVE;
312312}
r3836r3837
319319   timer_reset(fdc.seek_timer, attotime_never);
320320}
321321
322static void nec765_timer_func(int timer_type)
322static void nec765_timer_func(running_machine *machine, int timer_type)
323323{
324324   /* type 0 = data transfer mode in execution phase */
325325   if (fdc.timer_type == 0)
r3836r3837
336336      }
337337      else
338338      {
339         nec765_timer_func(fdc.timer_type);
339         nec765_timer_func(machine, fdc.timer_type);
340340      }
341341   }
342342   else if (fdc.timer_type==2)
r3836r3837
355355      case 17:   /* scan equal */
356356      case 19:   /* scan low or equal */
357357      case 29:   /* scan high or equal */
358         nec765_set_int(1);
358         nec765_set_int(machine,1);
359359         break;
360360
361361      default:
r3836r3837
372372      a int is generated per byte */
373373      if (fdc.nec765_flags & NEC765_DMA_MODE)
374374      {
375         nec765_set_dma_drq(1);
375         nec765_set_dma_drq(machine,1);
376376      }
377377      else
378378      {
379379         if (fdc.FDC_main & (1<<7))
380380         {
381381            /* set int to indicate data is ready */
382            nec765_set_int(1);
382            nec765_set_int(machine,1);
383383         }
384384      }
385385
r3836r3837
389389
390390static TIMER_CALLBACK(nec765_timer_callback)
391391{
392   nec765_timer_func(param);
392   nec765_timer_func(machine,param);
393393}
394394
395395/* after (32-27) the DRQ is set, then 27 us later, the int is set.
r3836r3837
398398effectively disabled by reading the data before the NMI int can be set.
399399*/
400400
401static void nec765_setup_timed_generic(int timer_type, attotime duration)
401static void nec765_setup_timed_generic(running_machine *machine, int timer_type, attotime duration)
402402{
403403   fdc.timer_type = timer_type;
404404
r3836r3837
408408   }
409409   else
410410   {
411      nec765_timer_func(fdc.timer_type);
411      nec765_timer_func(machine,fdc.timer_type);
412412      timer_reset(fdc.timer, attotime_never);
413413   }
414414}
415415
416416/* setup data request */
417static void nec765_setup_timed_data_request(int bytes)
417static void nec765_setup_timed_data_request(running_machine *machine, int bytes)
418418{
419419   /* setup timer to trigger in NEC765_DATA_RATE us */
420   nec765_setup_timed_generic(0, ATTOTIME_IN_USEC(32-27)   /*NEC765_DATA_RATE)*bytes*/);
420   nec765_setup_timed_generic(machine, 0, ATTOTIME_IN_USEC(32-27)   /*NEC765_DATA_RATE)*bytes*/);
421421}
422422
423423/* setup result data request */
424static void nec765_setup_timed_result_data_request(void)
424static void nec765_setup_timed_result_data_request(running_machine *machine)
425425{
426   nec765_setup_timed_generic(2, ATTOTIME_IN_USEC(NEC765_DATA_RATE*2));
426   nec765_setup_timed_generic(machine, 2, ATTOTIME_IN_USEC(NEC765_DATA_RATE*2));
427427}
428428
429429
r3836r3837
535535
536536
537537
538static void nec765_setup_execution_phase_read(char *ptr, int size)
538static void nec765_setup_execution_phase_read(running_machine *machine, char *ptr, int size)
539539{
540540   fdc.FDC_main |= 0x040;                     /* FDC->CPU */
541541
r3836r3837
544544   fdc.execution_phase_data = ptr;
545545   fdc.nec765_phase = NEC765_EXECUTION_PHASE_READ;
546546
547   nec765_setup_timed_data_request(1);
547   nec765_setup_timed_data_request(machine, 1);
548548}
549549
550static void nec765_setup_execution_phase_write(char *ptr, int size)
550static void nec765_setup_execution_phase_write(running_machine *machine, char *ptr, int size)
551551{
552552   fdc.FDC_main &= ~0x040;                     /* FDC->CPU */
553553
r3836r3837
557557   fdc.nec765_phase = NEC765_EXECUTION_PHASE_WRITE;
558558
559559   /* setup a data request with first byte */
560   nec765_setup_timed_data_request(1);
560   nec765_setup_timed_data_request(machine,1);
561561}
562562
563563
564static void nec765_setup_result_phase(int byte_count)
564static void nec765_setup_result_phase(running_machine *machine, int byte_count)
565565{
566566   fdc.FDC_main |= 0x040;                     /* FDC->CPU */
567567   fdc.FDC_main &= ~0x020;                    /* not execution phase */
r3836r3837
570570   fdc.nec765_transfer_bytes_remaining = byte_count;
571571   fdc.nec765_phase = NEC765_RESULT_PHASE;
572572
573   nec765_setup_timed_result_data_request();
573   nec765_setup_timed_result_data_request(machine);
574574}
575575
576576void nec765_idle(void)
r3836r3837
586586
587587
588588/* change flags */
589static void nec765_change_flags(unsigned int flags, unsigned int mask)
589static void nec765_change_flags(running_machine *machine,unsigned int flags, unsigned int mask)
590590{
591591   unsigned int new_flags;
592592   unsigned int changed_flags;
r3836r3837
601601
602602   /* if interrupt changed, call the handler */
603603   if ((changed_flags & NEC765_INT) && nec765_iface.interrupt)
604      nec765_iface.interrupt((fdc.nec765_flags & NEC765_INT) ? 1 : 0);
604      nec765_iface.interrupt(machine,(fdc.nec765_flags & NEC765_INT) ? 1 : 0);
605605
606606   /* if DRQ changed, call the handler */
607607   if ((changed_flags & NEC765_DMA_DRQ) && nec765_iface.dma_drq)
608      nec765_iface.dma_drq((fdc.nec765_flags & NEC765_DMA_DRQ) ? 1 : 0, fdc.FDC_main & (1<<6));
608      nec765_iface.dma_drq(machine,(fdc.nec765_flags & NEC765_DMA_DRQ) ? 1 : 0, fdc.FDC_main & (1<<6));
609609}
610610
611611
612612
613613/* set int output */
614static void nec765_set_int(int state)
614static void nec765_set_int(running_machine *machine, int state)
615615{
616616   if (LOG_INTERRUPT)
617617      logerror("nec765_set_int(): state=%d\n", state);
618   nec765_change_flags(state ? NEC765_INT : 0, NEC765_INT);
618   nec765_change_flags(machine, state ? NEC765_INT : 0, NEC765_INT);
619619}
620620
621621
622622
623623/* set dma request output */
624static void nec765_set_dma_drq(int state)
624static void nec765_set_dma_drq(running_machine *machine, int state)
625625{
626   nec765_change_flags(state ? NEC765_DMA_DRQ : 0, NEC765_DMA_DRQ);
626   nec765_change_flags(machine, state ? NEC765_DMA_DRQ : 0, NEC765_DMA_DRQ);
627627}
628628
629629
r3836r3837
670670      fdc.nec765_status[0] |= 8;
671671
672672   /* trigger an int */
673   nec765_set_int(1);
673   nec765_set_int(img->machine, 1);
674674}
675675
676676
r3836r3837
709709   old_state = fdc.nec765_flags;
710710
711711   /* clear drq */
712   nec765_set_dma_drq(0);
712   nec765_set_dma_drq(machine, 0);
713713
714714   fdc.nec765_flags &= ~NEC765_TC;
715715   if (state)
r3836r3837
892892   return 0;
893893}
894894
895static void nec765_read_complete(void)
895static void nec765_read_complete(running_machine *machine)
896896{
897897
898898/* causes problems!!! - need to fix */
r3836r3837
926926   fdc.nec765_result_bytes[5] = fdc.nec765_command_bytes[4]; /* R */
927927   fdc.nec765_result_bytes[6] = fdc.nec765_command_bytes[5]; /* N */
928928
929   nec765_setup_result_phase(7);
929   nec765_setup_result_phase(machine,7);
930930}
931931
932932static void nec765_read_data(running_machine *machine)
r3836r3837
946946      fdc.nec765_result_bytes[4] = fdc.nec765_command_bytes[3]; /* H */
947947      fdc.nec765_result_bytes[5] = fdc.nec765_command_bytes[4]; /* R */
948948      fdc.nec765_result_bytes[6] = fdc.nec765_command_bytes[5]; /* N */
949      nec765_setup_result_phase(7);
949      nec765_setup_result_phase(machine,7);
950950      return;
951951   }
952952
r3836r3837
974974               if (nec765_sector_count_complete(machine))
975975               {
976976                  /* read complete */
977                  nec765_read_complete();
977                  nec765_read_complete(machine);
978978                  return;
979979               }
980980
r3836r3837
992992         else
993993         {
994994            /* error in finding sector */
995            nec765_read_complete();
995            nec765_read_complete(machine);
996996            return;
997997         }
998998      }
r3836r3837
10061006
10071007      floppy_drive_read_sector_data(img, fdc.side, fdc.sector_id,nec765_data_buffer,data_size);
10081008
1009        nec765_setup_execution_phase_read(nec765_data_buffer, data_size);
1009        nec765_setup_execution_phase_read(machine,nec765_data_buffer, data_size);
10101010   }
10111011}
10121012
r3836r3837
10291029         fdc.nec765_result_bytes[4] = fdc.format_data[1];
10301030         fdc.nec765_result_bytes[5] = fdc.format_data[2];
10311031         fdc.nec765_result_bytes[6] = fdc.format_data[3];
1032         nec765_setup_result_phase(7);
1032         nec765_setup_result_phase(machine,7);
10331033
10341034      return;
10351035   }
10361036
1037    nec765_setup_execution_phase_write(&fdc.format_data[0], 4);
1037    nec765_setup_execution_phase_write(machine, &fdc.format_data[0], 4);
10381038}
10391039
10401040static void nec765_read_a_track(running_machine *machine)
r3836r3837
10711071
10721072   floppy_drive_read_sector_data(current_image(machine), fdc.side, fdc.sector_id,nec765_data_buffer,data_size);
10731073
1074   nec765_setup_execution_phase_read(nec765_data_buffer, data_size);
1074   nec765_setup_execution_phase_read(machine,nec765_data_buffer, data_size);
10751075}
10761076
10771077static int nec765_just_read_last_sector_on_track(running_machine *machine)
r3836r3837
10811081   return 0;
10821082}
10831083
1084static void nec765_write_complete(void)
1084static void nec765_write_complete(running_machine *machine)
10851085{
10861086
10871087/* causes problems!!! - need to fix */
r3836r3837
11151115    fdc.nec765_result_bytes[5] = fdc.nec765_command_bytes[4]; /* R */
11161116    fdc.nec765_result_bytes[6] = fdc.nec765_command_bytes[5]; /* N */
11171117
1118    nec765_setup_result_phase(7);
1118    nec765_setup_result_phase(machine,7);
11191119}
11201120
11211121
r3836r3837
11341134        fdc.nec765_result_bytes[4] = fdc.nec765_command_bytes[3]; /* H */
11351135        fdc.nec765_result_bytes[5] = fdc.nec765_command_bytes[4]; /* R */
11361136        fdc.nec765_result_bytes[6] = fdc.nec765_command_bytes[5]; /* N */
1137      nec765_setup_result_phase(7);
1137      nec765_setup_result_phase(machine,7);
11381138      return;
11391139   }
11401140
r3836r3837
11431143   {
11441144      fdc.nec765_status[1] |= NEC765_ST1_NOT_WRITEABLE;
11451145
1146      nec765_write_complete();
1146      nec765_write_complete(machine);
11471147      return;
11481148   }
11491149
r3836r3837
11531153
11541154      data_size = nec765_n_to_bytes(fdc.nec765_command_bytes[5]);
11551155
1156        nec765_setup_execution_phase_write(nec765_data_buffer, data_size);
1156        nec765_setup_execution_phase_write(machine,nec765_data_buffer, data_size);
11571157   }
11581158    else
11591159    {
1160        nec765_setup_result_phase(7);
1160        nec765_setup_result_phase(machine,7);
11611161    }
11621162}
11631163
r3836r3837
14041404               fdc.nec765_result_bytes[5] = fdc.nec765_command_bytes[4]; /* R */
14051405               fdc.nec765_result_bytes[6] = fdc.nec765_command_bytes[5]; /* N */
14061406
1407               nec765_setup_result_phase(7);
1407               nec765_setup_result_phase(machine,7);
14081408            }
14091409            else
14101410            {
r3836r3837
14341434               fdc.nec765_result_bytes[4] = fdc.format_data[1];
14351435               fdc.nec765_result_bytes[5] = fdc.format_data[2];
14361436               fdc.nec765_result_bytes[6] = fdc.format_data[3];
1437               nec765_setup_result_phase(7);
1437               nec765_setup_result_phase(machine,7);
14381438            }
14391439            else
14401440            {
r3836r3837
14621462            if (nec765_sector_count_complete(machine))
14631463            {
14641464               nec765_increment_sector(machine);
1465               nec765_write_complete();
1465               nec765_write_complete(machine);
14661466            }
14671467            else
14681468            {
r3836r3837
14821482            /* sector id == EOT */
14831483            if (nec765_sector_count_complete(machine) || nec765_read_data_stop())
14841484             {
1485               nec765_read_complete();
1485               nec765_read_complete(machine);
14861486            }
14871487            else
14881488            {
r3836r3837
15731573         case 17:   /* scan equal */
15741574         case 19:   /* scan low or equal */
15751575         case 29:   /* scan high or equal */
1576            nec765_set_int(0);
1576            nec765_set_int(machine, 0);
15771577            break;
15781578
15791579         default:
r3836r3837
16131613      else
16141614      {
16151615         /* trigger int */
1616         nec765_setup_timed_data_request(1);
1616         nec765_setup_timed_data_request(machine,1);
16171617      }
16181618      break;
16191619
r3836r3837
16801680      }
16811681      else
16821682      {
1683         nec765_setup_timed_data_request(1);
1683         nec765_setup_timed_data_request(machine,1);
16841684      }
16851685      break;
16861686   }
r3836r3837
16971697      {
16981698
16991699         /* reading the data byte clears the interrupt */
1700         nec765_set_int(CLEAR_LINE);
1700         nec765_set_int(space->machine,CLEAR_LINE);
17011701      }
17021702
17031703      /* reset data request */
r3836r3837
17291729      {
17301730
17311731         /* reading the data byte clears the interrupt */
1732         nec765_set_int(CLEAR_LINE);
1732         nec765_set_int(space->machine, CLEAR_LINE);
17331733      }
17341734
17351735      /* reset data request */
r3836r3837
17401740   }
17411741}
17421742
1743static void nec765_setup_invalid(void)
1743static void nec765_setup_invalid(running_machine *machine)
17441744{
17451745   fdc.command = 0;
17461746   fdc.nec765_result_bytes[0] = 0x080;
1747   nec765_setup_result_phase(1);
1747   nec765_setup_result_phase(machine,1);
17481748}
17491749
17501750static void nec765_setup_command(running_machine *machine)
r3836r3837
18321832
18331833         /* two side and fault not set but should be? */
18341834         fdc.nec765_result_bytes[0] = fdc.nec765_status[3];
1835         nec765_setup_result_phase(1);
1835         nec765_setup_result_phase(machine,1);
18361836         break;
18371837
18381838      case 0x07:          /* recalibrate */
r3836r3837
18941894               fdc.nec765_result_bytes[5] = id.R; /* R */
18951895               fdc.nec765_result_bytes[6] = id.N; /* N */
18961896
1897               nec765_setup_result_phase(7);
1897               nec765_setup_result_phase(machine,7);
18981898            }
18991899            else
19001900            {
r3836r3837
19261926         if (fdc.nec765_flags & NEC765_INT)
19271927         {
19281928            /* yes. Clear int */
1929            nec765_set_int(CLEAR_LINE);
1929            nec765_set_int(machine, CLEAR_LINE);
19301930
19311931            /* clear drive seek bits */
19321932            fdc.FDC_main &= ~(1 | 2 | 4 | 8);
r3836r3837
19371937            fdc.nec765_result_bytes[1] = fdc.pcn[fdc.drive];
19381938
19391939            /* return result */
1940            nec765_setup_result_phase(2);
1940            nec765_setup_result_phase(machine,2);
19411941         }
19421942         else
19431943         {
19441944            if(fdc.version == NEC72065 && (fdc.FDC_main & 0x0f) == 0x00)
19451945            {  // based on XM6
1946               nec765_setup_invalid();
1946               nec765_setup_invalid(machine);
19471947            }
19481948            else
19491949            {
r3836r3837
19531953               fdc.nec765_result_bytes[1] = fdc.pcn[fdc.drive];
19541954
19551955               /* return result */
1956               nec765_setup_result_phase(2);
1956               nec765_setup_result_phase(machine,2);
19571957            }
19581958         }
19591959         break;
r3836r3837
20422042         {
20432043            case NEC765A:
20442044            case NEC72065:
2045               nec765_setup_invalid();
2045               nec765_setup_invalid(machine);
20462046               break;
20472047
20482048            case NEC765B:
r3836r3837
20522052                  /* version */
20532053                  fdc.nec765_status[0] = 0x090;
20542054                  fdc.nec765_result_bytes[0] = fdc.nec765_status[0];
2055                  nec765_setup_result_phase(1);
2055                  nec765_setup_result_phase(machine,1);
20562056               }
20572057               break;
20582058
r3836r3837
20632063                  case 0x10:      /* version */
20642064                     fdc.nec765_status[0] = 0x90;
20652065                     fdc.nec765_result_bytes[0] = fdc.nec765_status[0];
2066                     nec765_setup_result_phase(1);
2066                     nec765_setup_result_phase(machine,1);
20672067                     break;
20682068
20692069                  case 0x13:      /* configure */
r3836r3837
20762076                     fdc.nec765_result_bytes[2] = fdc.pcn[2];
20772077                     fdc.nec765_result_bytes[3] = fdc.pcn[3];
20782078
2079                     nec765_setup_result_phase(10);
2079                     nec765_setup_result_phase(machine,10);
20802080                     break;
20812081
20822082                  case 0x12:      /* perpendicular mode */
r3836r3837
20842084                     break;
20852085
20862086                  case 0x14:      /* lock */
2087                     nec765_setup_result_phase(1);
2087                     nec765_setup_result_phase(machine,1);
20882088                     break;
20892089               }
20902090               break;
r3836r3837
20972097WRITE8_HANDLER(nec765_dack_w)
20982098{
20992099   /* clear request */
2100   nec765_set_dma_drq(CLEAR_LINE);
2100   nec765_set_dma_drq(space->machine, CLEAR_LINE);
21012101
21022102   /* write data */
21032103   nec765_data_w(space, offset, data);
r3836r3837
21062106READ8_HANDLER(nec765_dack_r)
21072107{
21082108   /* clear data request */
2109   nec765_set_dma_drq(CLEAR_LINE);
2109   nec765_set_dma_drq(space->machine,CLEAR_LINE);
21102110
21112111   /* read data */
21122112   return nec765_data_r(space, offset);
r3836r3837
21192119   nec765_idle();
21202120
21212121   /* set int low */
2122   nec765_set_int(0);
2122   nec765_set_int(machine, 0);
21232123   /* set dma drq output */
2124   nec765_set_dma_drq(0);
2124   nec765_set_dma_drq(machine,0);
21252125
21262126   /* tandy 100hx assumes that after NEC is reset, it is in DMA mode */
21272127   fdc.nec765_flags |= NEC765_DMA_MODE;
r3836r3837
21542154         fdc.nec765_status[0] |= 0x08;
21552155      }
21562156
2157      nec765_set_int(1);
2157      nec765_set_int(machine, 1);
21582158   }
21592159}
21602160
r3836r3837
21742174   {
21752175      fdc.nec765_flags |= NEC765_RESET;
21762176
2177      nec765_set_int(0);
2177      nec765_set_int(machine, 0);
21782178   }
21792179
21802180   /* reset changed state? */
src/mess/machine/nec765.h
r3836r3837
3434typedef struct nec765_interface
3535{
3636   /* interrupt issued */
37   void   (*interrupt)(int state);
37   void   (*interrupt)(running_machine *machine,int state);
3838
3939   /* dma data request */
40   void   (*dma_drq)(int state,int read_write);
40   void   (*dma_drq)(running_machine *machine,int state,int read_write);
4141
4242   /* image lookup */
43   const device_config *(*get_image)(int floppy_index);
43   const device_config *(*get_image)(running_machine *machine,int floppy_index);
4444} nec765_interface;
4545
4646/* init nec765 interface */
src/mess/machine/i8271.c
r3836r3837
44
55/* TODO:
66
7   - Scan commands
8   - Check the commands work properly using a BBC disc copier program
7    - Scan commands
8    - Check the commands work properly using a BBC disc copier program
99    - check if 0 is specified as number of sectors, how many sectors
1010    is actually transfered
11   - deleted data functions (error if data finds deleted data?)
11    - deleted data functions (error if data finds deleted data?)
1212*/
1313
1414
1515#include "driver.h"
16#include "deprecat.h"
1716#include "i8271.h"
1817#include "devices/flopdrv.h"
1918
19/* data request */
20#define I8271_FLAGS_DATA_REQUEST 0x01
21/* data direction. If 0x02, then it is from fdc to cpu, else
22it is from cpu to fdc */
23#define I8271_FLAGS_DATA_DIRECTION 0x02
2024
21I8271_STATE_t I8271_STATE;
25typedef struct _i8271_t i8271_t;
26struct _i8271_t
27{
28   int flags;
29   int state;
30   unsigned char Command;
31   unsigned char StatusRegister;
32   unsigned char CommandRegister;
33   unsigned char ResultRegister;
34   unsigned char ParameterRegister;
35   unsigned char ResetRegister;
36   unsigned char data;
2237
23static void i8271_command_execute(void);
24static void i8271_command_continue(void);
25static void i8271_command_complete(int result, int int_rq);
26static void i8271_data_request(void);
27static void i8271_timed_data_request(void);
38   /* number of parameters required after command is specified */
39   unsigned long ParameterCount;
40   /* number of parameters written so far */
41   unsigned long ParameterCountWritten;
42
43   unsigned char CommandParameters[8];
44
45   /* current track for each drive */
46   unsigned long   CurrentTrack[2];
47
48   /* 2 bad tracks for drive 0, followed by 2 bad tracks for drive 1 */
49   unsigned long   BadTracks[4];
50
51   /* mode special register */
52   unsigned long Mode;
53
54
55   /* drive outputs */
56   int drive;
57   int side;
58
59   /* drive control output special register */
60   int drive_control_output;
61   /* drive control input special register */
62   int drive_control_input;
63
64   unsigned long StepRate;
65   unsigned long HeadSettlingTime;
66   unsigned long IndexCountBeforeHeadUnload;
67   unsigned long HeadLoadTime;
68
69   /* id on disc to find */
70   int   ID_C;
71   int ID_H;
72   int ID_R;
73   int ID_N;
74
75   /* id of data for read/write */
76   int data_id;
77
78   int ExecutionPhaseTransferCount;
79   char *pExecutionPhaseData;
80   int ExecutionPhaseCount;
81
82   /* sector counter and id counter */
83   int Counter;
84
85   /* ==0, to cpu, !=0 =from cpu */
86   int data_direction;
87   const i8271_interface *intf;
88
89   void *data_timer;
90   void *command_complete_timer;
91};
92
93typedef enum
94{
95   I8271_STATE_EXECUTION_READ = 0,
96   I8271_STATE_EXECUTION_WRITE
97} I8271_STATE_t;
98
99/* commands accepted */
100#define I8271_COMMAND_SPECIFY                              0x035
101#define I8271_COMMAND_SEEK                                 0x029
102#define I8271_COMMAND_READ_DRIVE_STATUS                        0x02c
103#define I8271_COMMAND_READ_SPECIAL_REGISTER                     0x03d
104#define   I8271_COMMAND_WRITE_SPECIAL_REGISTER                  0x03a
105#define I8271_COMMAND_FORMAT                              0x023
106#define I8271_COMMAND_READ_ID                              0x01b
107#define I8271_COMMAND_READ_DATA_SINGLE_RECORD                  0x012
108#define I8271_COMMAND_READ_DATA_AND_DELETED_DATA_SINGLE_RECORD      0x016
109#define I8271_COMMAND_WRITE_DATA_SINGLE_RECORD                  0x00a
110#define I8271_COMMAND_WRITE_DELETED_DATA_SINGLE_RECORD            0x00e
111#define   I8271_COMMAND_VERIFY_DATA_AND_DELETED_DATA_SINGLE_RECORD   0x01e
112#define I8271_COMMAND_READ_DATA_MULTI_RECORD                  0x013
113#define I8271_COMMAND_READ_DATA_AND_DELETED_DATA_MULTI_RECORD      0x017
114#define I8271_COMMAND_WRITE_DATA_MULTI_RECORD                  0x00b
115#define I8271_COMMAND_WRITE_DELETED_DATA_MULTI_RECORD            0x00f
116#define   I8271_COMMAND_VERIFY_DATA_AND_DELETED_DATA_MULTI_RECORD      0x01f
117#define I8271_COMMAND_SCAN_DATA                              0x000
118#define I8271_COMMAND_SCAN_DATA_AND_DELETED_DATA               0x004
119
120/*
121#define I8271_COMMAND_READ_OPERATION                            (1<<4)
122#define I8271_COMMAND_DELETED_DATA                              (1<<2)
123#define I8271_COMMAND_MULTI_RECORD                              (1<<0)
124*/
125
126
127
128/* first parameter for specify command */
129#define I8271_SPECIFY_INITIALIZATION                        0x0d
130#define I8271_SPECIFY_LOAD_BAD_TRACKS_SURFACE_0                  0x010
131#define I8271_SPECIFY_LOAD_BAD_TRACKS_SURFACE_1                  0x018
132
133/* first parameter for read/write special register */
134#define I8271_SPECIAL_REGISTER_SCAN_SECTOR_NUMBER               0x06
135#define I8271_SPECIAL_REGISTER_SCAN_MSB_OF_COUNT               0x014
136#define I8271_SPECIAL_REGISTER_SCAN_LSB_OF_COUNT               0x013
137#define I8271_SPECIAL_REGISTER_SURFACE_0_CURRENT_TRACK            0x012
138#define I8271_SPECIAL_REGISTER_SURFACE_1_CURRENT_TRACK            0x01a
139#define I8271_SPECIAL_REGISTER_MODE_REGISTER                  0x017
140#define I8271_SPECIAL_REGISTER_DRIVE_CONTROL_OUTPUT_PORT         0x023
141#define I8271_SPECIAL_REGISTER_DRIVE_CONTROL_INPUT_PORT            0x022
142#define I8271_SPECIAL_REGISTER_SURFACE_0_BAD_TRACK_1            0x010
143#define I8271_SPECIAL_REGISTER_SURFACE_0_BAD_TRACK_2            0x011
144#define I8271_SPECIAL_REGISTER_SURFACE_1_BAD_TRACK_1            0x018
145#define I8271_SPECIAL_REGISTER_SURFACE_1_BAD_TRACK_2            0x019
146
147
148/* status register bits */
149#define I8271_STATUS_COMMAND_BUSY   0x080
150#define I8271_STATUS_COMMAND_FULL   0x040
151#define I8271_STATUS_PARAMETER_FULL   0x020
152#define I8271_STATUS_RESULT_FULL   0x010
153#define I8271_STATUS_INT_REQUEST   0x008
154#define I8271_STATUS_NON_DMA_REQUEST   0x004
155
156static void i8271_command_execute(const device_config *device);
157static void i8271_command_continue(const device_config *device);
158static void i8271_command_complete(const device_config *device,int result, int int_rq);
159static void i8271_data_request(const device_config *device);
160static void i8271_timed_data_request(const device_config *device);
28161/* locate sector for read/write operation */
29static int i8271_find_sector(void);
162static int i8271_find_sector(const device_config *device);
30163/* do a read operation */
31static void i8271_do_read(void);
32static void i8271_do_write(void);
33static void i8271_do_read_id(void);
34static void i8271_set_irq_state(int);
35static void i8271_set_dma_drq(void);
164static void i8271_do_read(const device_config *device);
165static void i8271_do_write(const device_config *device);
166static void i8271_do_read_id(const device_config *device);
167static void i8271_set_irq_state(const device_config *device,int);
168static void i8271_set_dma_drq(const device_config *device);
36169
37170static TIMER_CALLBACK(i8271_data_timer_callback);
38171static TIMER_CALLBACK(i8271_timed_command_complete_callback);
39172
40static char temp_buffer[16384];
41
42static I8271 i8271;
43
44173#define VERBOSE 0
45174
46175#define LOG(x) do { if (VERBOSE) logerror x; } while (0)
47176#define FDC_LOG(x) do { if (VERBOSE) logerror("I8271: %s\n",x); } while (0)
48177#define FDC_LOG_COMMAND(x) do { if (VERBOSE) logerror("I8271: COMMAND %s\n",x); } while (0)
49178
50static const device_config *current_image(void)
179static DEVICE_RESET( i8271 );
180
181INLINE i8271_t *get_safe_token(const device_config *device)
51182{
52   return image_from_devtype_and_index(IO_FLOPPY, i8271.drive);
183   assert(device != NULL);
184   assert(device->token != NULL);
185
186   return (i8271_t *)device->token;
53187}
54188
55void i8271_init(const i8271_interface *iface)
189
190static const device_config *current_image(const device_config *device)
56191{
57   memset(&i8271, 0, sizeof(I8271));
58
59   if (iface!=NULL)
60   {
61      memcpy(&i8271.fdc_interface, iface, sizeof(i8271_interface));
62   }
63   i8271.data_timer = timer_alloc(Machine, i8271_data_timer_callback, NULL);
64   i8271.command_complete_timer = timer_alloc(Machine, i8271_timed_command_complete_callback, NULL);
65   i8271.drive = 0;
66   i8271.pExecutionPhaseData = temp_buffer;
67
68    i8271_reset();
192   i8271_t *i8271 = get_safe_token(device);
193   return image_from_devtype_and_index(IO_FLOPPY, i8271->drive);
69194}
70195
71196
72static void i8271_seek_to_track(int track)
197static void i8271_seek_to_track(const device_config *device,int track)
73198{
74   const device_config *img = current_image();
75
199   const device_config *img = current_image(device);
200   i8271_t *i8271 = get_safe_token(device);
76201   if (track==0)
77202   {
78203      /* seek to track 0 */
r3836r3837
92217         floppy_drive_seek(img, -1);
93218      }
94219
95      i8271.CurrentTrack[i8271.drive] = 0;
220      i8271->CurrentTrack[i8271->drive] = 0;
96221
97222      /* failed to find track 0? */
98223      if (StepCount==0)
99224      {
100225         /* Completion Type: operator intervation probably required for recovery */
101226         /* Completion code: track 0 not found */
102         i8271.ResultRegister |= (2<<3) | 2<<1;
227         i8271->ResultRegister |= (2<<3) | 2<<1;
103228      }
104229
105230      /* step out - towards track 0 */
106      i8271.drive_control_output &=~(1<<2);
231      i8271->drive_control_output &=~(1<<2);
107232   }
108233   else
109234   {
r3836r3837
111236      signed int SignedTracks;
112237
113238      /* calculate number of tracks to seek */
114      SignedTracks = track - i8271.CurrentTrack[i8271.drive];
239      SignedTracks = track - i8271->CurrentTrack[i8271->drive];
115240
116241      /* step towards 0 */
117      i8271.drive_control_output &= ~(1<<2);
242      i8271->drive_control_output &= ~(1<<2);
118243
119244      if (SignedTracks>0)
120245      {
121246         /* step away from 0 */
122         i8271.drive_control_output |= (1<<2);
247         i8271->drive_control_output |= (1<<2);
123248      }
124249
125250
126251      /* seek to track 0 */
127252      floppy_drive_seek(img, SignedTracks);
128253
129      i8271.CurrentTrack[i8271.drive] = track;
254      i8271->CurrentTrack[i8271->drive] = track;
130255   }
131256}
132257
133258
134259static TIMER_CALLBACK(i8271_data_timer_callback)
135260{
261   const device_config *device = ptr;
262   i8271_t *i8271 = get_safe_token(device);
263
136264   /* ok, trigger data request now */
137   i8271_data_request();
265   i8271_data_request(device);
138266
139267   /* stop it */
140   timer_reset(i8271.data_timer, attotime_never);
268   timer_reset(i8271->data_timer, attotime_never);
141269}
142270
143271/* setup a timed data request - data request will be triggered in a few usecs time */
144static void i8271_timed_data_request(void)
272static void i8271_timed_data_request(const device_config *device)
145273{
146274   int usecs;
147
275   i8271_t *i8271 = get_safe_token(device);
148276   /* 64 for single density */
149277   usecs = 64;
150278
151279   /* set timers */
152   timer_reset(i8271.command_complete_timer, attotime_never);
153   timer_adjust_oneshot(i8271.data_timer, ATTOTIME_IN_USEC(usecs), 0);
280   timer_reset(i8271->command_complete_timer, attotime_never);
281   timer_adjust_oneshot(i8271->data_timer, ATTOTIME_IN_USEC(usecs), 0);
154282}
155283
156284
157285static TIMER_CALLBACK(i8271_timed_command_complete_callback)
158286{
159   i8271_command_complete(1,1);
287   const device_config *device = ptr;
288   i8271_t *i8271 = get_safe_token(device);
160289
290   i8271_command_complete(device,1,1);
291
161292   /* stop it, but don't allow it to be free'd */
162   timer_reset(i8271.command_complete_timer, attotime_never);
293   timer_reset(i8271->command_complete_timer, attotime_never);
163294}
164295
165296/* setup a irq to occur 128us later - in reality this would be much later, because the int would
166297come after reading the two CRC bytes at least! This function is used when a irq is required at
167298command completion. Required for read data and write data, where last byte could be missed! */
168static void i8271_timed_command_complete(void)
299static void i8271_timed_command_complete(const device_config *device)
169300{
170301   int usecs;
302   i8271_t *i8271 = get_safe_token(device);
171303
172304   /* 64 for single density - 2 crc bytes later*/
173305   usecs = 64*2;
174306
175307   /* set timers */
176   timer_reset(i8271.data_timer, attotime_never);
177   timer_adjust_oneshot(i8271.command_complete_timer, ATTOTIME_IN_USEC(usecs), 0);
308   timer_reset(i8271->data_timer, attotime_never);
309   timer_adjust_oneshot(i8271->command_complete_timer, ATTOTIME_IN_USEC(usecs), 0);
178310}
179311
180void i8271_reset()
312static void i8271_set_irq_state(const device_config *device,int state)
181313{
182   i8271.StatusRegister = 0;   //I8271_STATUS_INT_REQUEST | I8271_STATUS_NON_DMA_REQUEST;
183   i8271.Mode = 0x0c0; /* bits 0, 1 are initialized to zero */
184   i8271.ParameterCountWritten = 0;
185   i8271.ParameterCount = 0;
186
187   /* if timer is active remove */
188   timer_reset(i8271.command_complete_timer, attotime_never);
189   timer_reset(i8271.data_timer, attotime_never);
190
191   /* clear irq */
192   i8271_set_irq_state(0);
193   /* clear dma */
194   i8271_set_dma_drq();
195}
196
197static void i8271_set_irq_state(int state)
198{
199   i8271.StatusRegister &= ~I8271_STATUS_INT_REQUEST;
314   i8271_t *i8271 = get_safe_token(device);
315   i8271->StatusRegister &= ~I8271_STATUS_INT_REQUEST;
200316   if (state)
201317   {
202      i8271.StatusRegister |= I8271_STATUS_INT_REQUEST;
318      i8271->StatusRegister |= I8271_STATUS_INT_REQUEST;
203319   }
204320
205   if (i8271.fdc_interface.interrupt)
321   if (i8271->intf->interrupt)
206322   {
207      i8271.fdc_interface.interrupt((i8271.StatusRegister & I8271_STATUS_INT_REQUEST));
323      i8271->intf->interrupt(device, (i8271->StatusRegister & I8271_STATUS_INT_REQUEST));
208324   }
209325}
210326
211static void i8271_set_dma_drq(void)
327static void i8271_set_dma_drq(const device_config *device)
212328{
213   if (i8271.fdc_interface.dma_request)
329   i8271_t *i8271 = get_safe_token(device);
330   if (i8271->intf->dma_request)
214331   {
215      i8271.fdc_interface.dma_request((i8271.flags & I8271_FLAGS_DATA_REQUEST), (i8271.flags & I8271_FLAGS_DATA_DIRECTION));
332      i8271->intf->dma_request(device, (i8271->flags & I8271_FLAGS_DATA_REQUEST), (i8271->flags & I8271_FLAGS_DATA_DIRECTION));
216333   }
217334}
218335
219static void i8271_load_bad_tracks(int surface)
336static void i8271_load_bad_tracks(const device_config *device, int surface)
220337{
221   i8271.BadTracks[(surface<<1) + 0] = i8271.CommandParameters[1];
222   i8271.BadTracks[(surface<<1) + 1] = i8271.CommandParameters[2];
223   i8271.CurrentTrack[surface] = i8271.CommandParameters[3];
338   i8271_t *i8271 = get_safe_token(device);
339   i8271->BadTracks[(surface<<1) + 0] = i8271->CommandParameters[1];
340   i8271->BadTracks[(surface<<1) + 1] = i8271->CommandParameters[2];
341   i8271->CurrentTrack[surface] = i8271->CommandParameters[3];
224342}
225343
226static void i8271_write_bad_track(int surface, int track, int data)
344static void i8271_write_bad_track(const device_config *device, int surface, int track, int data)
227345{
228   i8271.BadTracks[(surface<<1) + (track-1)] = data;
346   i8271_t *i8271 = get_safe_token(device);
347   i8271->BadTracks[(surface<<1) + (track-1)] = data;
229348}
230349
231static void i8271_write_current_track(int surface, int track)
350static void i8271_write_current_track(const device_config *device,int surface, int track)
232351{
233   i8271.CurrentTrack[surface] = track;
352   i8271_t *i8271 = get_safe_token(device);
353   i8271->CurrentTrack[surface] = track;
234354}
235355
236static int i8271_read_current_track(int surface)
356static int i8271_read_current_track(const device_config *device,int surface)
237357{
238   return i8271.CurrentTrack[surface];
358   i8271_t *i8271 = get_safe_token(device);
359   return i8271->CurrentTrack[surface];
239360}
240361
241static int i8271_read_bad_track(int surface, int track)
362static int i8271_read_bad_track(const device_config *device,int surface, int track)
242363{
243   return i8271.BadTracks[(surface<<1) + (track-1)];
364   i8271_t *i8271 = get_safe_token(device);
365   return i8271->BadTracks[(surface<<1) + (track-1)];
244366}
245367
246static void i8271_get_drive(void)
368static void i8271_get_drive(const device_config *device)
247369{
370   i8271_t *i8271 = get_safe_token(device);
248371   /* &40 = drive 0 side 0 */
249372   /* &80 = drive 1 side 0 */
250373
251374
252375
253   if (i8271.CommandRegister & (1<<6))
376   if (i8271->CommandRegister & (1<<6))
254377   {
255      i8271.drive = 0;
378      i8271->drive = 0;
256379   }
257380
258   if (i8271.CommandRegister & (1<<7))
381   if (i8271->CommandRegister & (1<<7))
259382   {
260      i8271.drive = 1;
383      i8271->drive = 1;
261384   }
262385
263386}
264387
265static void i8271_check_all_parameters_written(void)
388static void i8271_check_all_parameters_written(const device_config *device)
266389{
267   if (i8271.ParameterCount == i8271.ParameterCountWritten)
390   i8271_t *i8271 = get_safe_token(device);
391   if (i8271->ParameterCount == i8271->ParameterCountWritten)
268392   {
269      i8271.StatusRegister &= ~I8271_STATUS_COMMAND_FULL;
393      i8271->StatusRegister &= ~I8271_STATUS_COMMAND_FULL;
270394
271      i8271_command_execute();
395      i8271_command_execute(device);
272396   }
273397}
274398
275399
276static void i8271_update_state(void)
400static void i8271_update_state(const device_config *device)
277401{
278   switch (i8271.state)
402   i8271_t *i8271 = get_safe_token(device);
403   switch (i8271->state)
279404   {
280405      /* fdc reading data and passing it to cpu which must read it */
281406      case I8271_STATE_EXECUTION_READ:
282407      {
283   //      /* if data request has been cleared, i.e. caused by a read of the register */
284   //      if ((i8271.flags & I8271_FLAGS_DATA_REQUEST)==0)
408   //      /* if data request has been cleared, i.e. caused by a read of the register */
409   //      if ((i8271->flags & I8271_FLAGS_DATA_REQUEST)==0)
285410         {
286411            /* setup data with byte */
287            i8271.data = i8271.pExecutionPhaseData[i8271.ExecutionPhaseCount];
412            i8271->data = i8271->pExecutionPhaseData[i8271->ExecutionPhaseCount];
288413
289/*            logerror("read data %02x\n", i8271.data); */
414/*              logerror("read data %02x\n", i8271->data); */
290415
291416            /* update counters */
292            i8271.ExecutionPhaseCount++;
293            i8271.ExecutionPhaseTransferCount--;
417            i8271->ExecutionPhaseCount++;
418            i8271->ExecutionPhaseTransferCount--;
294419
295         //   logerror("Count: %04x\n", i8271.ExecutionPhaseCount);
296         //   logerror("Remaining: %04x\n", i8271.ExecutionPhaseTransferCount);
420         //  logerror("Count: %04x\n", i8271->ExecutionPhaseCount);
421         //  logerror("Remaining: %04x\n", i8271->ExecutionPhaseTransferCount);
297422
298423            /* completed? */
299            if (i8271.ExecutionPhaseTransferCount==0)
424            if (i8271->ExecutionPhaseTransferCount==0)
300425            {
301426               /* yes */
302427
303         //      logerror("sector read complete!\n");
428         //      logerror("sector read complete!\n");
304429               /* continue command */
305               i8271_command_continue();
430               i8271_command_continue(device);
306431            }
307432            else
308433            {
309434               /* no */
310435
311436               /* issue data request */
312               i8271_timed_data_request();
437               i8271_timed_data_request(device);
313438            }
314439         }
315440      }
r3836r3837
319444      case I8271_STATE_EXECUTION_WRITE:
320445      {
321446         /* setup data with byte */
322         i8271.pExecutionPhaseData[i8271.ExecutionPhaseCount] = i8271.data;
447         i8271->pExecutionPhaseData[i8271->ExecutionPhaseCount] = i8271->data;
323448         /* update counters */
324         i8271.ExecutionPhaseCount++;
325         i8271.ExecutionPhaseTransferCount--;
449         i8271->ExecutionPhaseCount++;
450         i8271->ExecutionPhaseTransferCount--;
326451
327452         /* completed? */
328         if (i8271.ExecutionPhaseTransferCount==0)
453         if (i8271->ExecutionPhaseTransferCount==0)
329454         {
330455            /* yes */
331456
332457            /* continue command */
333            i8271_command_continue();
458            i8271_command_continue(device);
334459         }
335460         else
336461         {
337462            /* no */
338463
339464            /* issue data request */
340            i8271_timed_data_request();
465            i8271_timed_data_request(device);
341466         }
342467      }
343468      break;
r3836r3837
347472   }
348473}
349474
350static void i8271_initialise_execution_phase_read(int transfer_size)
475static void i8271_initialise_execution_phase_read(const device_config *device,int transfer_size)
351476{
477   i8271_t *i8271 = get_safe_token(device);
352478   /* read */
353   i8271.flags |= I8271_FLAGS_DATA_DIRECTION;
354   i8271.ExecutionPhaseCount = 0;
355   i8271.ExecutionPhaseTransferCount = transfer_size;
356   i8271.state = I8271_STATE_EXECUTION_READ;
479   i8271->flags |= I8271_FLAGS_DATA_DIRECTION;
480   i8271->ExecutionPhaseCount = 0;
481   i8271->ExecutionPhaseTransferCount = transfer_size;
482   i8271->state = I8271_STATE_EXECUTION_READ;
357483}
358484
359485
360static void i8271_initialise_execution_phase_write(int transfer_size)
486static void i8271_initialise_execution_phase_write(const device_config *device,int transfer_size)
361487{
488   i8271_t *i8271 = get_safe_token(device);
362489   /* write */
363   i8271.flags &= ~I8271_FLAGS_DATA_DIRECTION;
364   i8271.ExecutionPhaseCount = 0;
365   i8271.ExecutionPhaseTransferCount = transfer_size;
366   i8271.state = I8271_STATE_EXECUTION_WRITE;
490   i8271->flags &= ~I8271_FLAGS_DATA_DIRECTION;
491   i8271->ExecutionPhaseCount = 0;
492   i8271->ExecutionPhaseTransferCount = transfer_size;
493   i8271->state = I8271_STATE_EXECUTION_WRITE;
367494}
368495
369496/* for data transfers */
370static void i8271_data_request(void)
497static void i8271_data_request(const device_config *device)
371498{
372   i8271.flags |= I8271_FLAGS_DATA_REQUEST;
499   i8271_t *i8271 = get_safe_token(device);
500   i8271->flags |= I8271_FLAGS_DATA_REQUEST;
373501
374   if ((i8271.Mode & 0x01)!=0)
502   if ((i8271->Mode & 0x01)!=0)
375503   {
376504      /* non-dma */
377      i8271.StatusRegister |= I8271_STATUS_NON_DMA_REQUEST;
505      i8271->StatusRegister |= I8271_STATUS_NON_DMA_REQUEST;
378506      /* set int */
379      i8271_set_irq_state(1);
507      i8271_set_irq_state(device,1);
380508   }
381509   else
382510   {
383511      /* dma */
384      i8271.StatusRegister &= ~I8271_STATUS_NON_DMA_REQUEST;
512      i8271->StatusRegister &= ~I8271_STATUS_NON_DMA_REQUEST;
385513
386      i8271_set_dma_drq();
514      i8271_set_dma_drq(device);
387515   }
388516}
389517
390static void i8271_command_complete(int result, int int_rq)
518static void i8271_command_complete(const device_config *device,int result, int int_rq)
391519{
520   i8271_t *i8271 = get_safe_token(device);
392521   /* not busy, and not a execution phase data request in non-dma mode */
393   i8271.StatusRegister &= ~(I8271_STATUS_COMMAND_BUSY | I8271_STATUS_NON_DMA_REQUEST);
522   i8271->StatusRegister &= ~(I8271_STATUS_COMMAND_BUSY | I8271_STATUS_NON_DMA_REQUEST);
394523
395524   if (result)
396525   {
397      i8271.StatusRegister |= I8271_STATUS_RESULT_FULL;
526      i8271->StatusRegister |= I8271_STATUS_RESULT_FULL;
398527   }
399528
400529   if (int_rq)
401530   {
402531      /* trigger an int */
403      i8271_set_irq_state(1);
532      i8271_set_irq_state(device,1);
404533    }
405534
406535   /* correct?? */
407    i8271.drive_control_output &=~1;
536    i8271->drive_control_output &=~1;
408537}
409538
410539
411540/* for data transfers */
412static void i8271_clear_data_request(void)
541static void i8271_clear_data_request(const device_config *device)
413542{
414   i8271.flags &= ~I8271_FLAGS_DATA_REQUEST;
543   i8271_t *i8271 = get_safe_token(device);
544   i8271->flags &= ~I8271_FLAGS_DATA_REQUEST;
415545
416   if ((i8271.Mode & 0x01)!=0)
546   if ((i8271->Mode & 0x01)!=0)
417547   {
418548      /* non-dma */
419      i8271.StatusRegister &= ~I8271_STATUS_NON_DMA_REQUEST;
549      i8271->StatusRegister &= ~I8271_STATUS_NON_DMA_REQUEST;
420550      /* set int */
421      i8271_set_irq_state(0);
551      i8271_set_irq_state(device,0);
422552   }
423553   else
424554   {
425555      /* dma */
426      i8271_set_dma_drq();
556      i8271_set_dma_drq(device);
427557   }
428558}
429559
430560
431static void i8271_command_continue(void)
561static void i8271_command_continue(const device_config *device)
432562{
433   switch (i8271.Command)
563   i8271_t *i8271 = get_safe_token(device);
564   switch (i8271->Command)
434565   {
435566      case I8271_COMMAND_READ_DATA_MULTI_RECORD:
436567      case I8271_COMMAND_READ_DATA_SINGLE_RECORD:
437568      {
438569         /* completed all sectors? */
439         i8271.Counter--;
570         i8271->Counter--;
440571         /* increment sector id */
441         i8271.ID_R++;
572         i8271->ID_R++;
442573
443574         /* end command? */
444         if (i8271.Counter==0)
575         if (i8271->Counter==0)
445576         {
446577
447            i8271_timed_command_complete();
578            i8271_timed_command_complete(device);
448579            return;
449580         }
450581
451         i8271_do_read();
582         i8271_do_read(device);
452583      }
453584      break;
454585
r3836r3837
456587      case I8271_COMMAND_WRITE_DATA_SINGLE_RECORD:
457588      {
458589         /* put the buffer to the sector */
459         floppy_drive_write_sector_data(current_image(), i8271.side, i8271.data_id, i8271.pExecutionPhaseData, 1<<(i8271.ID_N+7),0);
590         floppy_drive_write_sector_data(current_image(device), i8271->side, i8271->data_id, i8271->pExecutionPhaseData, 1<<(i8271->ID_N+7),0);
460591
461592         /* completed all sectors? */
462         i8271.Counter--;
593         i8271->Counter--;
463594         /* increment sector id */
464         i8271.ID_R++;
595         i8271->ID_R++;
465596
466597         /* end command? */
467         if (i8271.Counter==0)
598         if (i8271->Counter==0)
468599         {
469600
470            i8271_timed_command_complete();
601            i8271_timed_command_complete(device);
471602            return;
472603         }
473604
474         i8271_do_write();
605         i8271_do_write(device);
475606      }
476607      break;
477608
478609      case I8271_COMMAND_READ_ID:
479610      {
480         i8271.Counter--;
611         i8271->Counter--;
481612
482         if (i8271.Counter==0)
613         if (i8271->Counter==0)
483614         {
484            i8271_timed_command_complete();
615            i8271_timed_command_complete(device);
485616            return;
486617         }
487618
488         i8271_do_read_id();
619         i8271_do_read_id(device);
489620      }
490621      break;
491622
r3836r3837
494625   }
495626}
496627
497static void i8271_do_read(void)
628static void i8271_do_read(const device_config *device)
498629{
630   i8271_t *i8271 = get_safe_token(device);
499631   /* find the sector */
500   if (i8271_find_sector())
632   if (i8271_find_sector(device))
501633   {
502634      /* get the sector into the buffer */
503      floppy_drive_read_sector_data(current_image(), i8271.side, i8271.data_id, i8271.pExecutionPhaseData, 1<<(i8271.ID_N+7));
635      floppy_drive_read_sector_data(current_image(device), i8271->side, i8271->data_id, i8271->pExecutionPhaseData, 1<<(i8271->ID_N+7));
504636
505637      /* initialise for reading */
506        i8271_initialise_execution_phase_read(1<<(i8271.ID_N+7));
638        i8271_initialise_execution_phase_read(device, 1<<(i8271->ID_N+7));
507639
508640      /* update state - gets first byte and triggers a data request */
509      i8271_timed_data_request();
641      i8271_timed_data_request(device);
510642      return;
511643   }
512644   LOG(("error getting sector data\n"));
513645
514   i8271_timed_command_complete();
646   i8271_timed_command_complete(device);
515647}
516648
517static void i8271_do_read_id(void)
649static void i8271_do_read_id(const device_config *device)
518650{
519651   chrn_id   id;
652   i8271_t *i8271 = get_safe_token(device);
520653
521654   /* get next id from disc */
522   floppy_drive_get_next_id(current_image(), i8271.side,&id);
655   floppy_drive_get_next_id(current_image(device), i8271->side,&id);
523656
524   i8271.pExecutionPhaseData[0] = id.C;
525   i8271.pExecutionPhaseData[1] = id.H;
526   i8271.pExecutionPhaseData[2] = id.R;
527   i8271.pExecutionPhaseData[3] = id.N;
657   i8271->pExecutionPhaseData[0] = id.C;
658   i8271->pExecutionPhaseData[1] = id.H;
659   i8271->pExecutionPhaseData[2] = id.R;
660   i8271->pExecutionPhaseData[3] = id.N;
528661
529   i8271_initialise_execution_phase_read(4);
662   i8271_initialise_execution_phase_read(device, 4);
530663}
531664
532665
533static void i8271_do_write(void)
666static void i8271_do_write(const device_config *device)
534667{
668   i8271_t *i8271 = get_safe_token(device);
535669   /* find the sector */
536   if (i8271_find_sector())
670   if (i8271_find_sector(device))
537671   {
538672      /* initialise for reading */
539        i8271_initialise_execution_phase_write(1<<(i8271.ID_N+7));
673        i8271_initialise_execution_phase_write(device,1<<(i8271->ID_N+7));
540674
541675      /* update state - gets first byte and triggers a data request */
542      i8271_timed_data_request();
676      i8271_timed_data_request(device);
543677      return;
544678   }
545679   LOG(("error getting sector data\n"));
546680
547   i8271_timed_command_complete();
681   i8271_timed_command_complete(device);
548682}
549683
550684
551685
552static int i8271_find_sector(void)
686static int i8271_find_sector(const device_config *device)
553687{
554   const device_config *img = current_image();
555//   int track_count_attempt;
688   const device_config *img = current_image(device);
689   i8271_t *i8271 = get_safe_token(device);
690//  int track_count_attempt;
556691
557//   track_count_attempt
692//  track_count_attempt
558693   /* find sector within one revolution of the disc - 2 index pulses */
559694
560695   /* number of times we have seen index hole */
r3836r3837
566701      chrn_id id;
567702
568703      /* get next id from disc */
569      if (floppy_drive_get_next_id(img, i8271.side,&id))
704      if (floppy_drive_get_next_id(img, i8271->side,&id))
570705      {
571706         /* tested on Amstrad CPC - All bytes must match, otherwise
572         a NO DATA error is reported */
573         if (id.R == i8271.ID_R)
707            a NO DATA error is reported */
708         if (id.R == i8271->ID_R)
574709         {
575710            /* TODO: Is this correct? What about bad tracks? */
576            if (id.C == i8271.CurrentTrack[i8271.drive])
711            if (id.C == i8271->CurrentTrack[i8271->drive])
577712            {
578               i8271.data_id = id.data_id;
713               i8271->data_id = id.data_id;
579714               return 1;
580715            }
581716            else
r3836r3837
599734
600735   /* completion type: command/drive error */
601736   /* completion code: sector not found */
602   i8271.ResultRegister |= (3<<3);
737   i8271->ResultRegister |= (3<<3);
603738
604739   return 0;
605740}
606741
607static void i8271_command_execute(void)
742static void i8271_command_execute(const device_config *device)
608743{
609   const device_config *img = current_image();
744   i8271_t *i8271 = get_safe_token(device);
745   const device_config *img = current_image(device);
610746
611747   /* clear it = good completion status */
612748   /* this will be changed if anything bad happens! */
613   i8271.ResultRegister = 0;
749   i8271->ResultRegister = 0;
614750
615   switch (i8271.Command)
751   switch (i8271->Command)
616752   {
617753      case I8271_COMMAND_SPECIFY:
618754      {
619         switch (i8271.CommandParameters[0])
755         switch (i8271->CommandParameters[0])
620756         {
621757            case 0x0d:
622758            {
623759               LOG(("Initialization\n"));
624               i8271.StepRate = i8271.CommandParameters[1];
625               i8271.HeadSettlingTime = i8271.CommandParameters[2];
626               i8271.IndexCountBeforeHeadUnload = (i8271.CommandParameters[3]>>4) & 0x0f;
627               i8271.HeadLoadTime = (i8271.CommandParameters[3] & 0x0f);
760               i8271->StepRate = i8271->CommandParameters[1];
761               i8271->HeadSettlingTime = i8271->CommandParameters[2];
762               i8271->IndexCountBeforeHeadUnload = (i8271->CommandParameters[3]>>4) & 0x0f;
763               i8271->HeadLoadTime = (i8271->CommandParameters[3] & 0x0f);
628764            }
629765            break;
630766
631767            case 0x010:
632768            {
633769               LOG(("Load bad Tracks Surface 0\n"));
634               i8271_load_bad_tracks(0);
770               i8271_load_bad_tracks(device,0);
635771
636772            }
637773            break;
r3836r3837
639775            case 0x018:
640776            {
641777               LOG(("Load bad Tracks Surface 1\n"));
642               i8271_load_bad_tracks(1);
778               i8271_load_bad_tracks(device,1);
643779
644780            }
645781            break;
646782         }
647783
648784         /* no result */
649         i8271_command_complete(0,0);
785         i8271_command_complete(device,0,0);
650786      }
651787      break;
652788
r3836r3837
655791         /* unknown - what is read when a special register that isn't allowed is specified? */
656792         int data = 0x0ff;
657793
658         switch (i8271.CommandParameters[0])
794         switch (i8271->CommandParameters[0])
659795         {
660796            case I8271_SPECIAL_REGISTER_MODE_REGISTER:
661797            {
662               data = i8271.Mode;
798               data = i8271->Mode;
663799            }
664800            break;
665801
666802            case I8271_SPECIAL_REGISTER_SURFACE_0_CURRENT_TRACK:
667803            {
668               data = i8271_read_current_track(0);
804               data = i8271_read_current_track(device, 0);
669805
670806            }
671807            break;
672808
673809            case I8271_SPECIAL_REGISTER_SURFACE_1_CURRENT_TRACK:
674810            {
675               data = i8271_read_current_track(1);
811               data = i8271_read_current_track(device, 1);
676812            }
677813            break;
678814
679815            case I8271_SPECIAL_REGISTER_SURFACE_0_BAD_TRACK_1:
680816            {
681               data = i8271_read_bad_track(0,1);
817               data = i8271_read_bad_track(device, 0,1);
682818            }
683819            break;
684820
685821            case I8271_SPECIAL_REGISTER_SURFACE_0_BAD_TRACK_2:
686822            {
687               data = i8271_read_bad_track(0,2);
823               data = i8271_read_bad_track(device, 0,2);
688824            }
689825            break;
690826
691827            case I8271_SPECIAL_REGISTER_SURFACE_1_BAD_TRACK_1:
692828            {
693               data = i8271_read_bad_track(1,1);
829               data = i8271_read_bad_track(device, 1,1);
694830            }
695831            break;
696832
697833            case I8271_SPECIAL_REGISTER_SURFACE_1_BAD_TRACK_2:
698834            {
699               data = i8271_read_bad_track(1,2);
835               data = i8271_read_bad_track(device, 1,2);
700836            }
701837            break;
702838
r3836r3837
704840            {
705841               FDC_LOG_COMMAND("Read Drive Control Output port\n");
706842
707               i8271_get_drive();
843               i8271_get_drive(device);
708844
709845               /* assumption: select bits reflect the select bits from the previous
710               command. i.e. read drive status */
711               data = (i8271.drive_control_output & ~0x0c0)
712                  | (i8271.CommandRegister & 0x0c0);
846                    command. i.e. read drive status */
847               data = (i8271->drive_control_output & ~0x0c0)
848                  | (i8271->CommandRegister & 0x0c0);
713849
714850
715851            }
r3836r3837
729865               FDC_LOG_COMMAND("Read Drive Control Input port\n");
730866
731867
732               i8271.drive_control_input = (1<<6) | (1<<2);
868               i8271->drive_control_input = (1<<6) | (1<<2);
733869
734870               /* bit 3 = 0 if write protected */
735871               if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_DISK_WRITE_PROTECTED))
736872               {
737                  i8271.drive_control_input |= (1<<3);
873                  i8271->drive_control_input |= (1<<3);
738874               }
739875
740876               /* bit 1 = 0 if head at track 0 */
741877               if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_HEAD_AT_TRACK_0))
742878               {
743                  i8271.drive_control_input |= (1<<1);
879                  i8271->drive_control_input |= (1<<1);
744880               }
745881
746882
747883               /* need to setup this register based on drive selected */
748               data = i8271.drive_control_input;
884               data = i8271->drive_control_input;
749885
750886
751887
r3836r3837
755891
756892         }
757893
758         i8271.ResultRegister = data;
894         i8271->ResultRegister = data;
759895
760         i8271_command_complete(1,0);
896         i8271_command_complete(device,1,0);
761897      }
762898      break;
763899
764900
765901      case I8271_COMMAND_WRITE_SPECIAL_REGISTER:
766902      {
767         switch (i8271.CommandParameters[0])
903         switch (i8271->CommandParameters[0])
768904         {
769905            case I8271_SPECIAL_REGISTER_MODE_REGISTER:
770906            {
771907               /* TODO: Check bits 6-7 and 5-2 are valid */
772               i8271.Mode = i8271.CommandParameters[1];
908               i8271->Mode = i8271->CommandParameters[1];
773909
774               if (i8271.Mode & 0x01)
910               if (i8271->Mode & 0x01)
775911               {
776912                  LOG(("Mode: Non-DMA\n"));
777913               }
r3836r3837
780916                  LOG(("Mode: DMA\n"));
781917               }
782918
783               if (i8271.Mode & 0x02)
919               if (i8271->Mode & 0x02)
784920               {
785921                  LOG(("Single actuator\n"));
786922               }
r3836r3837
794930            case I8271_SPECIAL_REGISTER_SURFACE_0_CURRENT_TRACK:
795931            {
796932               LOG(("Surface 0 Current Track\n"));
797               i8271_write_current_track(0, i8271.CommandParameters[1]);
933               i8271_write_current_track(device, 0, i8271->CommandParameters[1]);
798934            }
799935            break;
800936
801937            case I8271_SPECIAL_REGISTER_SURFACE_1_CURRENT_TRACK:
802938            {
803939               LOG(("Surface 1 Current Track\n"));
804               i8271_write_current_track(1, i8271.CommandParameters[1]);
940               i8271_write_current_track(device, 1, i8271->CommandParameters[1]);
805941            }
806942            break;
807943
808944            case I8271_SPECIAL_REGISTER_SURFACE_0_BAD_TRACK_1:
809945            {
810946               LOG(("Surface 0 Bad Track 1\n"));
811               i8271_write_bad_track(0, 1, i8271.CommandParameters[1]);
947               i8271_write_bad_track(device, 0, 1, i8271->CommandParameters[1]);
812948            }
813949            break;
814950
815951            case I8271_SPECIAL_REGISTER_SURFACE_0_BAD_TRACK_2:
816952            {
817953               LOG(("Surface 0 Bad Track 2\n"));
818               i8271_write_bad_track(0, 2,i8271.CommandParameters[1]);
954               i8271_write_bad_track(device, 0, 2,i8271->CommandParameters[1]);
819955            }
820956            break;
821957
r3836r3837
824960               LOG(("Surface 1 Bad Track 1\n"));
825961
826962
827               i8271_write_bad_track(1, 1, i8271.CommandParameters[1]);
963               i8271_write_bad_track(device, 1, 1, i8271->CommandParameters[1]);
828964            }
829965            break;
830966
r3836r3837
832968            {
833969               LOG(("Surface 1 Bad Track 2\n"));
834970
835               i8271_write_bad_track(1, 2, i8271.CommandParameters[1]);
971               i8271_write_bad_track(device, 1, 2, i8271->CommandParameters[1]);
836972            }
837973            break;
838974
839975            case I8271_SPECIAL_REGISTER_DRIVE_CONTROL_OUTPUT_PORT:
840976            {
841//               /* get drive selected */
842//               i8271.drive = (i8271.CommandParameters[1]>>6) & 0x03;
977//                  /* get drive selected */
978//                  i8271->drive = (i8271->CommandParameters[1]>>6) & 0x03;
843979
844980               FDC_LOG_COMMAND("Write Drive Control Output port\n");
845981
846982
847               if (i8271.CommandParameters[1] & 0x01)
983               if (i8271->CommandParameters[1] & 0x01)
848984               {
849985                  LOG(("Write Enable\n"));
850986               }
851               if (i8271.CommandParameters[1] & 0x02)
987               if (i8271->CommandParameters[1] & 0x02)
852988               {
853989                  LOG(("Seek/Step\n"));
854990               }
855               if (i8271.CommandParameters[1] & 0x04)
991               if (i8271->CommandParameters[1] & 0x04)
856992               {
857993                  LOG(("Direction\n"));
858994               }
859               if (i8271.CommandParameters[1] & 0x08)
995               if (i8271->CommandParameters[1] & 0x08)
860996               {
861997                  LOG(("Load Head\n"));
862998               }
863               if (i8271.CommandParameters[1] & 0x010)
999               if (i8271->CommandParameters[1] & 0x010)
8641000               {
8651001                  LOG(("Low head current\n"));
8661002               }
867               if (i8271.CommandParameters[1] & 0x020)
1003               if (i8271->CommandParameters[1] & 0x020)
8681004               {
8691005                  LOG(("Write Fault Reset\n"));
8701006               }
8711007
872               LOG(("Select %02x\n", (i8271.CommandParameters[1] & 0x0c0)>>6));
1008               LOG(("Select %02x\n", (i8271->CommandParameters[1] & 0x0c0)>>6));
8731009
8741010               /* get drive */
875               i8271_get_drive();
1011               i8271_get_drive(device);
8761012
8771013               /* on bbc dfs 09 this is the side select output */
878               i8271.side = (i8271.CommandParameters[1]>>5) & 0x01;
1014               i8271->side = (i8271->CommandParameters[1]>>5) & 0x01;
8791015
8801016               /* load head - on mini-sized drives this turns on the disc motor,
881               on standard-sized drives this loads the head and turns the motor on */
882               floppy_drive_set_motor_state(img, i8271.CommandParameters[1] & 0x08);
1017                    on standard-sized drives this loads the head and turns the motor on */
1018               floppy_drive_set_motor_state(img, i8271->CommandParameters[1] & 0x08);
8831019               floppy_drive_set_ready_state(img, 1, 1);
8841020
8851021               /* step pin changed? if so perform a step in the direction indicated */
886               if (((i8271.drive_control_output^i8271.CommandParameters[1]) & (1<<1))!=0)
1022               if (((i8271->drive_control_output^i8271->CommandParameters[1]) & (1<<1))!=0)
8871023               {
8881024                  /* step pin changed state? */
8891025
890                  if ((i8271.CommandParameters[1] & (1<<1))!=0)
1026                  if ((i8271->CommandParameters[1] & (1<<1))!=0)
8911027                  {
8921028                     signed int signed_tracks;
8931029
894                     if ((i8271.CommandParameters[1] & (1<<2))!=0)
1030                     if ((i8271->CommandParameters[1] & (1<<2))!=0)
8951031                     {
8961032                        signed_tracks = 1;
8971033                     }
r3836r3837
9041040                  }
9051041               }
9061042
907               i8271.drive_control_output = i8271.CommandParameters[1];
1043               i8271->drive_control_output = i8271->CommandParameters[1];
9081044
9091045
9101046            }
r3836r3837
9151051
9161052               FDC_LOG_COMMAND("Write Drive Control Input port\n");
9171053
918               //               i8271.drive_control_input = i8271.CommandParameters[1];
1054               //                  i8271->drive_control_input = i8271->CommandParameters[1];
9191055            }
9201056            break;
9211057
9221058         }
9231059
9241060         /* write doesn't supply a result */
925         i8271_command_complete(0,0);
1061         i8271_command_complete(device,0,0);
9261062      }
9271063      break;
9281064
r3836r3837
9301066      {
9311067         unsigned char status;
9321068
933         i8271_get_drive();
1069         i8271_get_drive(device);
9341070
9351071         /* no write fault */
9361072         status = 0;
r3836r3837
9601096            status |= (1<<1);
9611097         }
9621098
963         i8271.ResultRegister = status;
964         i8271_command_complete(1,0);
1099         i8271->ResultRegister = status;
1100         i8271_command_complete(device,1,0);
9651101
9661102      }
9671103      break;
9681104
9691105      case I8271_COMMAND_SEEK:
9701106      {
971         i8271_get_drive();
1107         i8271_get_drive(device);
9721108
9731109
974         i8271_seek_to_track(i8271.CommandParameters[0]);
1110         i8271_seek_to_track(device,i8271->CommandParameters[0]);
9751111
9761112         /* check for bad seek */
977         i8271_timed_command_complete();
1113         i8271_timed_command_complete(device);
9781114
9791115      }
9801116      break;
r3836r3837
9821118      case I8271_COMMAND_READ_DATA_MULTI_RECORD:
9831119      {
9841120         /* N value as stored in ID field */
985         i8271.ID_N = (i8271.CommandParameters[2]>>5) & 0x07;
1121         i8271->ID_N = (i8271->CommandParameters[2]>>5) & 0x07;
9861122
9871123         /* starting sector id */
988         i8271.ID_R = i8271.CommandParameters[1];
1124         i8271->ID_R = i8271->CommandParameters[1];
9891125
9901126         /* number of sectors to transfer */
991         i8271.Counter = i8271.CommandParameters[2] & 0x01f;
1127         i8271->Counter = i8271->CommandParameters[2] & 0x01f;
9921128
9931129
9941130         FDC_LOG_COMMAND("READ DATA MULTI RECORD");
9951131
996         LOG(("Sector Count: %02x\n", i8271.Counter));
997         LOG(("Track: %02x\n",i8271.CommandParameters[0]));
998         LOG(("Sector: %02x\n", i8271.CommandParameters[1]));
999         LOG(("Sector Length: %02x bytes\n", 1<<(i8271.ID_N+7)));
1132         LOG(("Sector Count: %02x\n", i8271->Counter));
1133         LOG(("Track: %02x\n",i8271->CommandParameters[0]));
1134         LOG(("Sector: %02x\n", i8271->CommandParameters[1]));
1135         LOG(("Sector Length: %02x bytes\n", 1<<(i8271->ID_N+7)));
10001136
1001         i8271_get_drive();
1137         i8271_get_drive(device);
10021138
10031139         if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY))
10041140         {
10051141            /* Completion type: operation intervention probably required for recovery */
10061142            /* Completion code: Drive not ready */
1007            i8271.ResultRegister = (2<<3);
1008            i8271_timed_command_complete();
1143            i8271->ResultRegister = (2<<3);
1144            i8271_timed_command_complete(device);
10091145         }
10101146         else
10111147         {
1012            i8271_seek_to_track(i8271.CommandParameters[0]);
1148            i8271_seek_to_track(device,i8271->CommandParameters[0]);
10131149
10141150
1015            i8271_do_read();
1151            i8271_do_read(device);
10161152         }
10171153
10181154      }
r3836r3837
10221158      {
10231159         FDC_LOG_COMMAND("READ DATA SINGLE RECORD");
10241160
1025         i8271.ID_N = 0;
1026         i8271.Counter = 1;
1027         i8271.ID_R = i8271.CommandParameters[1];
1161         i8271->ID_N = 0;
1162         i8271->Counter = 1;
1163         i8271->ID_R = i8271->CommandParameters[1];
10281164
1029         LOG(("Sector Count: %02x\n", i8271.Counter));
1030         LOG(("Track: %02x\n",i8271.CommandParameters[0]));
1031         LOG(("Sector: %02x\n", i8271.CommandParameters[1]));
1032         LOG(("Sector Length: %02x bytes\n", 1<<(i8271.ID_N+7)));
1165         LOG(("Sector Count: %02x\n", i8271->Counter));
1166         LOG(("Track: %02x\n",i8271->CommandParameters[0]));
1167         LOG(("Sector: %02x\n", i8271->CommandParameters[1]));
1168         LOG(("Sector Length: %02x bytes\n", 1<<(i8271->ID_N+7)));
10331169
1034         i8271_get_drive();
1170         i8271_get_drive(device);
10351171
10361172         if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY))
10371173         {
10381174            /* Completion type: operation intervention probably required for recovery */
10391175            /* Completion code: Drive not ready */
1040            i8271.ResultRegister = (2<<3);
1041            i8271_timed_command_complete();
1176            i8271->ResultRegister = (2<<3);
1177            i8271_timed_command_complete(device);
10421178         }
10431179         else
10441180         {
1045            i8271_seek_to_track(i8271.CommandParameters[0]);
1181            i8271_seek_to_track(device,i8271->CommandParameters[0]);
10461182
1047            i8271_do_read();
1183            i8271_do_read(device);
10481184         }
10491185
10501186      }
r3836r3837
10531189      case I8271_COMMAND_WRITE_DATA_MULTI_RECORD:
10541190      {
10551191         /* N value as stored in ID field */
1056         i8271.ID_N = (i8271.CommandParameters[2]>>5) & 0x07;
1192         i8271->ID_N = (i8271->CommandParameters[2]>>5) & 0x07;
10571193
10581194         /* starting sector id */
1059         i8271.ID_R = i8271.CommandParameters[1];
1195         i8271->ID_R = i8271->CommandParameters[1];
10601196
10611197         /* number of sectors to transfer */
1062         i8271.Counter = i8271.CommandParameters[2] & 0x01f;
1198         i8271->Counter = i8271->CommandParameters[2] & 0x01f;
10631199
10641200         FDC_LOG_COMMAND("READ DATA MULTI RECORD");
10651201
1066         LOG(("Sector Count: %02x\n", i8271.Counter));
1067         LOG(("Track: %02x\n",i8271.CommandParameters[0]));
1068         LOG(("Sector: %02x\n", i8271.CommandParameters[1]));
1069         LOG(("Sector Length: %02x bytes\n", 1<<(i8271.ID_N+7)));
1202         LOG(("Sector Count: %02x\n", i8271->Counter));
1203         LOG(("Track: %02x\n",i8271->CommandParameters[0]));
1204         LOG(("Sector: %02x\n", i8271->CommandParameters[1]));
1205         LOG(("Sector Length: %02x bytes\n", 1<<(i8271->ID_N+7)));
10701206
1071         i8271_get_drive();
1207         i8271_get_drive(device);
10721208
1073            i8271.drive_control_output &=~1;
1209            i8271->drive_control_output &=~1;
10741210
10751211         if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY))
10761212         {
10771213            /* Completion type: operation intervention probably required for recovery */
10781214            /* Completion code: Drive not ready */
1079            i8271.ResultRegister = (2<<3);
1080            i8271_timed_command_complete();
1215            i8271->ResultRegister = (2<<3);
1216            i8271_timed_command_complete(device);
10811217         }
10821218         else
10831219         {
r3836r3837
10851221            {
10861222               /* Completion type: operation intervention probably required for recovery */
10871223               /* Completion code: Drive write protected */
1088               i8271.ResultRegister = (2<<3) | (1<<1);
1089               i8271_timed_command_complete();
1224               i8271->ResultRegister = (2<<3) | (1<<1);
1225               i8271_timed_command_complete(device);
10901226            }
10911227            else
10921228            {
1093                    i8271.drive_control_output |=1;
1229                    i8271->drive_control_output |=1;
10941230
1095               i8271_seek_to_track(i8271.CommandParameters[0]);
1231               i8271_seek_to_track(device,i8271->CommandParameters[0]);
10961232
1097               i8271_do_write();
1233               i8271_do_write(device);
10981234            }
10991235         }
11001236      }
r3836r3837
11041240      {
11051241         FDC_LOG_COMMAND("WRITE DATA SINGLE RECORD");
11061242
1107         i8271.ID_N = 0;
1108         i8271.Counter = 1;
1109         i8271.ID_R = i8271.CommandParameters[1];
1243         i8271->ID_N = 0;
1244         i8271->Counter = 1;
1245         i8271->ID_R = i8271->CommandParameters[1];
11101246
11111247
1112         LOG(("Sector Count: %02x\n", i8271.Counter));
1113         LOG(("Track: %02x\n",i8271.CommandParameters[0]));
1114         LOG(("Sector: %02x\n", i8271.CommandParameters[1]));
1115         LOG(("Sector Length: %02x bytes\n", 1<<(i8271.ID_N+7)));
1116         i8271_get_drive();
1248         LOG(("Sector Count: %02x\n", i8271->Counter));
1249         LOG(("Track: %02x\n",i8271->CommandParameters[0]));
1250         LOG(("Sector: %02x\n", i8271->CommandParameters[1]));
1251         LOG(("Sector Length: %02x bytes\n", 1<<(i8271->ID_N+7)));
1252         i8271_get_drive(device);
11171253
1118            i8271.drive_control_output &=~1;
1254            i8271->drive_control_output &=~1;
11191255
11201256         if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY))
11211257         {
11221258            /* Completion type: operation intervention probably required for recovery */
11231259            /* Completion code: Drive not ready */
1124            i8271.ResultRegister = (2<<3);
1125            i8271_timed_command_complete();
1260            i8271->ResultRegister = (2<<3);
1261            i8271_timed_command_complete(device);
11261262         }
11271263         else
11281264         {
r3836r3837
11301266            {
11311267               /* Completion type: operation intervention probably required for recovery */
11321268               /* Completion code: Drive write protected */
1133               i8271.ResultRegister = (2<<3) | (1<<1);
1134               i8271_timed_command_complete();
1269               i8271->ResultRegister = (2<<3) | (1<<1);
1270               i8271_timed_command_complete(device);
11351271            }
11361272            else
11371273            {
11381274
1139                    i8271.drive_control_output |=1;
1275                    i8271->drive_control_output |=1;
11401276
1141               i8271_seek_to_track(i8271.CommandParameters[0]);
1277               i8271_seek_to_track(device,i8271->CommandParameters[0]);
11421278
1143               i8271_do_write();
1279               i8271_do_write(device);
11441280            }
11451281         }
11461282
r3836r3837
11521288      {
11531289         FDC_LOG_COMMAND("READ ID");
11541290
1155         LOG(("Track: %02x\n",i8271.CommandParameters[0]));
1156         LOG(("ID Field Count: %02x\n", i8271.CommandParameters[2]));
1291         LOG(("Track: %02x\n",i8271->CommandParameters[0]));
1292         LOG(("ID Field Count: %02x\n", i8271->CommandParameters[2]));
11571293
1158         i8271_get_drive();
1294         i8271_get_drive(device);
11591295
11601296         if (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY))
11611297         {
11621298            /* Completion type: operation intervention probably required for recovery */
11631299            /* Completion code: Drive not ready */
1164            i8271.ResultRegister = (2<<3);
1165            i8271_timed_command_complete();
1300            i8271->ResultRegister = (2<<3);
1301            i8271_timed_command_complete(device);
11661302         }
11671303         else
11681304         {
11691305
1170            i8271.Counter = i8271.CommandParameters[2];
1306            i8271->Counter = i8271->CommandParameters[2];
11711307
1172            i8271_seek_to_track(i8271.CommandParameters[0]);
1308            i8271_seek_to_track(device,i8271->CommandParameters[0]);
11731309
1174            i8271_do_read_id();
1310            i8271_do_read_id(device);
11751311         }
11761312      }
11771313      break;
r3836r3837
11841320
11851321
11861322
1187WRITE8_HANDLER(i8271_w)
1323WRITE8_DEVICE_HANDLER(i8271_w)
11881324{
1325   i8271_t *i8271 = get_safe_token(device);
11891326   switch (offset & 3)
11901327   {
11911328      case 0:
11921329      {
11931330         LOG(("I8271 W Command Register: %02x\n", data));
11941331
1195         i8271.CommandRegister = data;
1196         i8271.Command = i8271.CommandRegister & 0x03f;
1332         i8271->CommandRegister = data;
1333         i8271->Command = i8271->CommandRegister & 0x03f;
11971334
1198         i8271.StatusRegister |= I8271_STATUS_COMMAND_BUSY | I8271_STATUS_COMMAND_FULL;
1199         i8271.StatusRegister &= ~I8271_STATUS_PARAMETER_FULL | I8271_STATUS_RESULT_FULL;
1200         i8271.ParameterCountWritten = 0;
1335         i8271->StatusRegister |= I8271_STATUS_COMMAND_BUSY | I8271_STATUS_COMMAND_FULL;
1336         i8271->StatusRegister &= ~I8271_STATUS_PARAMETER_FULL | I8271_STATUS_RESULT_FULL;
1337         i8271->ParameterCountWritten = 0;
12011338
1202         switch (i8271.Command)
1339         switch (i8271->Command)
12031340         {
12041341            case I8271_COMMAND_SPECIFY:
12051342            {
12061343               FDC_LOG_COMMAND("SPECIFY");
12071344
1208               i8271.ParameterCount = 4;
1345               i8271->ParameterCount = 4;
12091346            }
12101347            break;
12111348
r3836r3837
12131350            {
12141351               FDC_LOG_COMMAND("SEEK");
12151352
1216               i8271.ParameterCount = 1;
1353               i8271->ParameterCount = 1;
12171354            }
12181355            break;
12191356
r3836r3837
12211358            {
12221359               FDC_LOG_COMMAND("READ DRIVE STATUS");
12231360
1224               i8271.ParameterCount = 0;
1361               i8271->ParameterCount = 0;
12251362            }
12261363            break;
12271364
r3836r3837
12291366            {
12301367               FDC_LOG_COMMAND("READ SPECIAL REGISTER");
12311368
1232               i8271.ParameterCount = 1;
1369               i8271->ParameterCount = 1;
12331370            }
12341371            break;
12351372
r3836r3837
12371374            {
12381375               FDC_LOG_COMMAND("WRITE SPECIAL REGISTER");
12391376
1240               i8271.ParameterCount = 2;
1377               i8271->ParameterCount = 2;
12411378            }
12421379            break;
12431380
12441381            case I8271_COMMAND_FORMAT:
12451382            {
1246               i8271.ParameterCount = 5;
1383               i8271->ParameterCount = 5;
12471384            }
12481385            break;
12491386
12501387            case I8271_COMMAND_READ_ID:
12511388            {
1252               i8271.ParameterCount = 3;
1389               i8271->ParameterCount = 3;
12531390
12541391            }
12551392            break;
r3836r3837
12611398            case I8271_COMMAND_WRITE_DELETED_DATA_SINGLE_RECORD:
12621399            case I8271_COMMAND_VERIFY_DATA_AND_DELETED_DATA_SINGLE_RECORD:
12631400            {
1264               i8271.ParameterCount = 2;
1401               i8271->ParameterCount = 2;
12651402            }
12661403            break;
12671404
r3836r3837
12711408            case I8271_COMMAND_WRITE_DELETED_DATA_MULTI_RECORD:
12721409            case I8271_COMMAND_VERIFY_DATA_AND_DELETED_DATA_MULTI_RECORD:
12731410            {
1274               i8271.ParameterCount = 3;
1411               i8271->ParameterCount = 3;
12751412            }
12761413            break;
12771414
12781415            case I8271_COMMAND_SCAN_DATA:
12791416            case I8271_COMMAND_SCAN_DATA_AND_DELETED_DATA:
12801417            {
1281               i8271.ParameterCount = 5;
1418               i8271->ParameterCount = 5;
12821419            }
12831420            break;
12841421
r3836r3837
12891426
12901427         }
12911428
1292         i8271_check_all_parameters_written();
1429         i8271_check_all_parameters_written(device);
12931430      }
12941431      break;
12951432
12961433      case 1:
12971434      {
12981435         LOG(("I8271 W Parameter Register: %02x\n",data));
1299         i8271.ParameterRegister = data;
1436         i8271->ParameterRegister = data;
13001437
1301         if (i8271.ParameterCount!=0)
1438         if (i8271->ParameterCount!=0)
13021439         {
1303            i8271.CommandParameters[i8271.ParameterCountWritten] = data;
1304            i8271.ParameterCountWritten++;
1440            i8271->CommandParameters[i8271->ParameterCountWritten] = data;
1441            i8271->ParameterCountWritten++;
13051442         }
13061443
1307         i8271_check_all_parameters_written();
1444         i8271_check_all_parameters_written(device);
13081445      }
13091446      break;
13101447
13111448      case 2:
13121449      {
13131450         LOG(("I8271 W Reset Register: %02x\n", data));
1314         if (((data ^ i8271.ResetRegister) & 0x01)!=0)
1451         if (((data ^ i8271->ResetRegister) & 0x01)!=0)
13151452         {
13161453            if ((data & 0x01)==0)
13171454            {
1318               i8271_reset();
1455               device_reset_i8271(device);
13191456            }
13201457         }
13211458
1322         i8271.ResetRegister = data;
1459         i8271->ResetRegister = data;
13231460
13241461
13251462      }
r3836r3837
13301467   }
13311468}
13321469
1333 READ8_HANDLER(i8271_r)
1470READ8_DEVICE_HANDLER(i8271_r)
13341471{
1472   i8271_t *i8271 = get_safe_token(device);
13351473   switch (offset & 3)
13361474   {
13371475      case 0:
13381476      {
13391477         /* bit 1,0 are zero other bits contain status data */
1340         i8271.StatusRegister &= ~0x03;
1341         LOG(("I8271 R Status Register: %02x\n",i8271.StatusRegister));
1342         return i8271.StatusRegister;
1478         i8271->StatusRegister &= ~0x03;
1479         LOG(("I8271 R Status Register: %02x\n",i8271->StatusRegister));
1480         return i8271->StatusRegister;
13431481      }
13441482
13451483      case 1:
13461484      {
13471485
1348         if ((i8271.StatusRegister & I8271_STATUS_COMMAND_BUSY)==0)
1486         if ((i8271->StatusRegister & I8271_STATUS_COMMAND_BUSY)==0)
13491487         {
13501488            /* clear IRQ */
1351            i8271_set_irq_state(0);
1489            i8271_set_irq_state(device,0);
13521490
1353            i8271.StatusRegister &= ~I8271_STATUS_RESULT_FULL;
1354            LOG(("I8271 R Result Register %02x\n",i8271.ResultRegister));
1355            return i8271.ResultRegister;
1491            i8271->StatusRegister &= ~I8271_STATUS_RESULT_FULL;
1492            LOG(("I8271 R Result Register %02x\n",i8271->ResultRegister));
1493            return i8271->ResultRegister;
13561494         }
13571495
13581496         /* not useful information when command busy */
r3836r3837
13691507
13701508
13711509/* to be completed! */
1372READ8_HANDLER(i8271_dack_r)
1510READ8_DEVICE_HANDLER(i8271_dack_r)
13731511{
1374   return i8271_data_r(space, offset);
1512   return i8271_data_r(device, offset);
13751513}
13761514
13771515/* to be completed! */
1378WRITE8_HANDLER(i8271_dack_w)
1516WRITE8_DEVICE_HANDLER(i8271_dack_w)
13791517{
1380   i8271_data_w(space, offset, data);
1518   i8271_data_w(device, offset, data);
13811519}
13821520
1383 READ8_HANDLER(i8271_data_r)
1521 READ8_DEVICE_HANDLER(i8271_data_r)
13841522{
1385   i8271_clear_data_request();
1523   i8271_t *i8271 = get_safe_token(device);
13861524
1387   i8271_update_state();
1525   i8271_clear_data_request(device);
13881526
1389  //  logerror("I8271 R data: %02x\n",i8271.data);
1527   i8271_update_state(device);
13901528
1529  //  logerror("I8271 R data: %02x\n",i8271->data);
13911530
1392   return i8271.data;
1531
1532   return i8271->data;
13931533}
13941534
1395WRITE8_HANDLER(i8271_data_w)
1535WRITE8_DEVICE_HANDLER(i8271_data_w)
13961536{
1397   i8271.data = data;
1537   i8271_t *i8271 = get_safe_token(device);
1538   i8271->data = data;
13981539
1399//    logerror("I8271 W data: %02x\n",i8271.data);
1540//    logerror("I8271 W data: %02x\n",i8271->data);
14001541
1401   i8271_clear_data_request();
1542   i8271_clear_data_request(device);
14021543
1403   i8271_update_state();
1544   i8271_update_state(device);
14041545}
14051546
1547
1548/* Device Interface */
1549
1550static DEVICE_START( i8271 )
1551{
1552   i8271_t *i8271 = get_safe_token(device);
1553   // validate arguments
1554
1555   assert(device != NULL);
1556   assert(device->tag != NULL);
1557   assert(strlen(device->tag) < 20);
1558   assert(device->static_config != NULL);
1559
1560   i8271->intf = device->static_config;
1561
1562   i8271->data_timer = timer_alloc(device->machine, i8271_data_timer_callback, (void *)device);
1563   i8271->command_complete_timer = timer_alloc(device->machine, i8271_timed_command_complete_callback, (void *)device);
1564   i8271->drive = 0;
1565   i8271->pExecutionPhaseData = auto_malloc(0x4000);
1566
1567   // register for state saving
1568   //state_save_register_item(device->machine, "i8271", device->tag, 0, i8271->number);
1569   return DEVICE_START_OK;
1570}
1571
1572static DEVICE_RESET( i8271 )
1573{
1574   i8271_t *i8271 = get_safe_token(device);
1575
1576   i8271->StatusRegister = 0;   //I8271_STATUS_INT_REQUEST | I8271_STATUS_NON_DMA_REQUEST;
1577   i8271->Mode = 0x0c0; /* bits 0, 1 are initialized to zero */
1578   i8271->ParameterCountWritten = 0;
1579   i8271->ParameterCount = 0;
1580
1581   /* if timer is active remove */
1582   timer_reset(i8271->command_complete_timer, attotime_never);
1583   timer_reset(i8271->data_timer, attotime_never);
1584
1585   /* clear irq */
1586   i8271_set_irq_state(device,0);
1587   /* clear dma */
1588   i8271_set_dma_drq(device);
1589
1590}
1591
1592static DEVICE_SET_INFO( i8271 )
1593{
1594   switch (state)
1595   {
1596      /* no parameters to set */
1597   }
1598}
1599
1600DEVICE_GET_INFO( i8271 )
1601{
1602   switch (state)
1603   {
1604      /* --- the following bits of info are returned as 64-bit signed integers --- */
1605      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(i8271_t);               break;
1606      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                        break;
1607      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_PERIPHERAL;         break;
1608
1609      /* --- the following bits of info are returned as pointers to data or functions --- */
1610      case DEVINFO_FCT_SET_INFO:                  info->set_info = DEVICE_SET_INFO_NAME(i8271); break;
1611      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(i8271);      break;
1612      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
1613      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(i8271);      break;
1614
1615      /* --- the following bits of info are returned as NULL-terminated strings --- */
1616      case DEVINFO_STR_NAME:                     info->s = "Intel 8271";                  break;
1617      case DEVINFO_STR_FAMILY:                  info->s = "Intel 8271";                  break;
1618      case DEVINFO_STR_VERSION:                  info->s = "1.0";                     break;
1619      case DEVINFO_STR_SOURCE_FILE:               info->s = __FILE__;                     break;
1620      case DEVINFO_STR_CREDITS:                  info->s = "Copyright MESS Team";         break;
1621   }
1622}
1623
1624
src/mess/machine/i8271.h
r3836r3837
77#ifndef I8271_H_
88#define I8271_H_
99
10/***************************************************************************
11    MACROS
12***************************************************************************/
1013
11/* data request */
12#define I8271_FLAGS_DATA_REQUEST 0x01
13/* data direction. If 0x02, then it is from fdc to cpu, else
14it is from cpu to fdc */
15#define I8271_FLAGS_DATA_DIRECTION 0x02
14#define I8271      DEVICE_GET_INFO_NAME(i8271)
1615
16/***************************************************************************
17    TYPE DEFINITIONS
18***************************************************************************/
1719
18/*----------- defined in machine/i8271.c -----------*/
19
20typedef enum
21{
22   I8271_STATE_EXECUTION_READ = 0,
23   I8271_STATE_EXECUTION_WRITE
24} I8271_STATE_t;
25
26extern I8271_STATE_t I8271_STATE;
27
28
2920typedef struct i8271_interface
3021{
31   void (*interrupt)(int state);
32   void (*dma_request)(int state, int read_);
22   void (*interrupt)(const device_config *device, int state);
23   void (*dma_request)(const device_config *device, int state, int read_);
3324} i8271_interface;
3425
35typedef struct I8271
36{
37   int flags;
38   int state;
39   unsigned char Command;
40   unsigned char StatusRegister;
41   unsigned char CommandRegister;
42   unsigned char ResultRegister;
43   unsigned char ParameterRegister;
44   unsigned char ResetRegister;
45   unsigned char data;
26/***************************************************************************
27    FUNCTION PROTOTYPES
28***************************************************************************/
4629
47   /* number of parameters required after command is specified */
48   unsigned long ParameterCount;
49   /* number of parameters written so far */
50   unsigned long ParameterCountWritten;
30/* device interface */
31DEVICE_GET_INFO( i8271 );
5132
52   unsigned char CommandParameters[8];
33READ8_DEVICE_HANDLER (i8271_r);
34WRITE8_DEVICE_HANDLER(i8271_w);
5335
54   /* current track for each drive */
55   unsigned long   CurrentTrack[2];
36READ8_DEVICE_HANDLER (i8271_dack_r);
37WRITE8_DEVICE_HANDLER(i8271_dack_w);
5638
57   /* 2 bad tracks for drive 0, followed by 2 bad tracks for drive 1 */
58   unsigned long   BadTracks[4];
39READ8_DEVICE_HANDLER (i8271_data_r);
40WRITE8_DEVICE_HANDLER(i8271_data_w);
5941
60   /* mode special register */
61   unsigned long Mode;
6242
43/***************************************************************************
44    DEVICE CONFIGURATION MACROS
45***************************************************************************/
6346
64   /* drive outputs */
65   int drive;
66   int side;
47#define MDRV_I8271_ADD(_tag, _intrf) \
48   MDRV_DEVICE_ADD(_tag, I8271) \
49   MDRV_DEVICE_CONFIG(_intrf)
6750
68   /* drive control output special register */
69   int drive_control_output;
70   /* drive control input special register */
71   int drive_control_input;
72
73   unsigned long StepRate;
74   unsigned long HeadSettlingTime;
75   unsigned long IndexCountBeforeHeadUnload;
76   unsigned long HeadLoadTime;
77
78   /* id on disc to find */
79   int   ID_C;
80   int ID_H;
81   int ID_R;
82   int ID_N;
83
84   /* id of data for read/write */
85   int data_id;
86
87   int ExecutionPhaseTransferCount;
88   char *pExecutionPhaseData;
89   int ExecutionPhaseCount;
90
91   /* sector counter and id counter */
92   int Counter;
93
94   /* ==0, to cpu, !=0 =from cpu */
95   int data_direction;
96   i8271_interface   fdc_interface;
97
98   void *data_timer;
99   void *command_complete_timer;
100} I8271;
101
102/* commands accepted */
103#define I8271_COMMAND_SPECIFY                              0x035
104#define I8271_COMMAND_SEEK                                 0x029
105#define I8271_COMMAND_READ_DRIVE_STATUS                        0x02c
106#define I8271_COMMAND_READ_SPECIAL_REGISTER                     0x03d
107#define   I8271_COMMAND_WRITE_SPECIAL_REGISTER                  0x03a
108#define I8271_COMMAND_FORMAT                              0x023
109#define I8271_COMMAND_READ_ID                              0x01b
110#define I8271_COMMAND_READ_DATA_SINGLE_RECORD                  0x012
111#define I8271_COMMAND_READ_DATA_AND_DELETED_DATA_SINGLE_RECORD      0x016
112#define I8271_COMMAND_WRITE_DATA_SINGLE_RECORD                  0x00a
113#define I8271_COMMAND_WRITE_DELETED_DATA_SINGLE_RECORD            0x00e
114#define   I8271_COMMAND_VERIFY_DATA_AND_DELETED_DATA_SINGLE_RECORD   0x01e
115#define I8271_COMMAND_READ_DATA_MULTI_RECORD                  0x013
116#define I8271_COMMAND_READ_DATA_AND_DELETED_DATA_MULTI_RECORD      0x017
117#define I8271_COMMAND_WRITE_DATA_MULTI_RECORD                  0x00b
118#define I8271_COMMAND_WRITE_DELETED_DATA_MULTI_RECORD            0x00f
119#define   I8271_COMMAND_VERIFY_DATA_AND_DELETED_DATA_MULTI_RECORD      0x01f
120#define I8271_COMMAND_SCAN_DATA                              0x000
121#define I8271_COMMAND_SCAN_DATA_AND_DELETED_DATA               0x004
122
123/*
124#define I8271_COMMAND_READ_OPERATION                            (1<<4)
125#define I8271_COMMAND_DELETED_DATA                              (1<<2)
126#define I8271_COMMAND_MULTI_RECORD                              (1<<0)
127*/
128
129
130
131/* first parameter for specify command */
132#define I8271_SPECIFY_INITIALIZATION                        0x0d
133#define I8271_SPECIFY_LOAD_BAD_TRACKS_SURFACE_0                  0x010
134#define I8271_SPECIFY_LOAD_BAD_TRACKS_SURFACE_1                  0x018
135
136/* first parameter for read/write special register */
137#define I8271_SPECIAL_REGISTER_SCAN_SECTOR_NUMBER               0x06
138#define I8271_SPECIAL_REGISTER_SCAN_MSB_OF_COUNT               0x014
139#define I8271_SPECIAL_REGISTER_SCAN_LSB_OF_COUNT               0x013
140#define I8271_SPECIAL_REGISTER_SURFACE_0_CURRENT_TRACK            0x012
141#define I8271_SPECIAL_REGISTER_SURFACE_1_CURRENT_TRACK            0x01a
142#define I8271_SPECIAL_REGISTER_MODE_REGISTER                  0x017
143#define I8271_SPECIAL_REGISTER_DRIVE_CONTROL_OUTPUT_PORT         0x023
144#define I8271_SPECIAL_REGISTER_DRIVE_CONTROL_INPUT_PORT            0x022
145#define I8271_SPECIAL_REGISTER_SURFACE_0_BAD_TRACK_1            0x010
146#define I8271_SPECIAL_REGISTER_SURFACE_0_BAD_TRACK_2            0x011
147#define I8271_SPECIAL_REGISTER_SURFACE_1_BAD_TRACK_1            0x018
148#define I8271_SPECIAL_REGISTER_SURFACE_1_BAD_TRACK_2            0x019
149
150
151/* status register bits */
152#define I8271_STATUS_COMMAND_BUSY   0x080
153#define I8271_STATUS_COMMAND_FULL   0x040
154#define I8271_STATUS_PARAMETER_FULL   0x020
155#define I8271_STATUS_RESULT_FULL   0x010
156#define I8271_STATUS_INT_REQUEST   0x008
157#define I8271_STATUS_NON_DMA_REQUEST   0x004
158
159/* initialise emulation */
160void i8271_init(const i8271_interface *);
161/* reset */
162void i8271_reset(void);
163
164 READ8_HANDLER(i8271_r);
165WRITE8_HANDLER(i8271_w);
166
167
168 READ8_HANDLER(i8271_dack_r);
169WRITE8_HANDLER(i8271_dack_w);
170
171 READ8_HANDLER(i8271_data_r);
172WRITE8_HANDLER(i8271_data_w);
173
174
17551#endif /* I8271_H_ */
src/mess/machine/pc8801.c
r3836r3837
1616***************************************************************************/
1717
1818#include "driver.h"
19#include "deprecat.h"
2019#include "machine/8255ppi.h"
2120#include "includes/pc8801.h"
2221#include "machine/nec765.h"
r3836r3837
802801}
803802
804803/* callback for /INT output from FDC */
805static void pc8801_fdc_interrupt(int state)
804static void pc8801_fdc_interrupt(running_machine *machine,int state)
806805{
807    cpu_set_input_line(Machine->cpu[1], 0, state ? HOLD_LINE : CLEAR_LINE);
806    cpu_set_input_line(machine->cpu[1], 0, state ? HOLD_LINE : CLEAR_LINE);
808807}
809808
810809/* callback for /DRQ output from FDC */
811static void pc8801_fdc_dma_drq(int state, int read_)
810static void pc8801_fdc_dma_drq(running_machine *machine,int state, int read_)
812811{
813812}
814813
src/mess/machine/atom.c
r3836r3837
1616
1717
1818#include "driver.h"
19#include "deprecat.h"
2019#include "machine/8255ppi.h"
2120#include "video/m6847.h"
2221#include "machine/i8271.h"
r3836r3837
137136
138137static int previous_i8271_int_state = 0;
139138
140static void atom_8271_interrupt_callback(int state)
139static void atom_8271_interrupt_callback(const device_config *device, int state)
141140{
142141   /* I'm assuming that the nmi is edge triggered */
143142   /* a interrupt from the fdc will cause a change in line state, and
r3836r3837
151150      {
152151         /* I'll pulse it because if I used hold-line I'm not sure
153152         it would clear - to be checked */
154         cpu_set_input_line(Machine->cpu[0], INPUT_LINE_NMI, PULSE_LINE);
153         cpu_set_input_line(device->machine->cpu[0], INPUT_LINE_NMI, PULSE_LINE);
155154      }
156155   }
157156
158157   previous_i8271_int_state = state;
159158}
160159
161static const struct i8271_interface atom_8271_interface=
160const i8271_interface atom_8271_interface=
162161{
163162   atom_8271_interrupt_callback,
164163   NULL
r3836r3837
244243   atom_8255_portb = 0xff;
245244   atom_8255_portc = 0xff;
246245
247   i8271_init(&atom_8271_interface);
248
249246   via_config(0, &atom_6522_interface);
250247   via_set_clock(0,1000000);
251248   via_reset();
r3836r3837
381378      atom_8255_portc |= (1<<4);
382379   }
383380
384   atom_8255_portc |= (m6847_get_field_sync() ? 0x00 : 0x80);
381   atom_8255_portc |= (m6847_get_field_sync(device->machine) ? 0x00 : 0x80);
385382   atom_8255_portc |= (input_port_read(device->machine, "KEY11") & 0x40);
386383   /* logerror("8255: Read port c (%02X)\n",atom_8255.atom_8255_portc); */
387384   return (atom_8255_portc);
r3836r3837
421418/* KT- I've assumed that the atom 8271 is linked in exactly the same way as on the bbc */
422419READ8_HANDLER(atom_8271_r)
423420{
421   device_config *i8271 = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, I8271, "i8271" );
422
424423   switch (offset)
425424   {
426425      case 0:
r3836r3837
428427      case 2:
429428      case 3:
430429         /* 8271 registers */
431         return i8271_r(space, offset);
430         return i8271_r(i8271, offset);
432431      case 4:
433         return i8271_data_r(space, offset);
432         return i8271_data_r(i8271, offset);
434433      default:
435434         break;
436435   }
r3836r3837
440439
441440WRITE8_HANDLER(atom_8271_w)
442441{
442   device_config *i8271 = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, I8271, "i8271" );
443
443444   switch (offset)
444445   {
445446      case 0:
r3836r3837
447448      case 2:
448449      case 3:
449450         /* 8271 registers */
450         i8271_w(space, offset, data);
451         i8271_w(i8271, offset, data);
451452         return;
452453      case 4:
453         i8271_data_w(space, offset, data);
454         i8271_data_w(i8271, offset, data);
454455         return;
455456      default:
456457         break;
src/mess/machine/pc_fdc.c
r3836r3837
1212**********************************************************************/
1313
1414#include "driver.h"
15#include "deprecat.h"
1615#include "machine/pc_fdc.h"
1716#include "machine/nec765.h"
1817#include "memconv.h"
r3836r3837
5655/* Prototypes */
5756
5857static TIMER_CALLBACK( watchdog_timeout );
59static void pc_fdc_hw_interrupt(int state);
60static void pc_fdc_hw_dma_drq(int,int);
61static const device_config *pc_fdc_get_image(int floppy_index);
58static void pc_fdc_hw_interrupt(running_machine *machine,int state);
59static void pc_fdc_hw_dma_drq(running_machine *machine,int,int);
60static const device_config *pc_fdc_get_image(running_machine *machine,int floppy_index);
6261
6362static const nec765_interface pc_fdc_nec765_interface =
6463{
r3836r3837
113112
114113
115114
116static const device_config *pc_fdc_get_image(int floppy_index)
115static const device_config *pc_fdc_get_image(running_machine *machine, int floppy_index)
117116{
118117   const device_config *image = NULL;
119118
120119   if (!fdc->fdc_interface.get_image)
121120   {
122      if (floppy_index < device_count(Machine, IO_FLOPPY))
121      if (floppy_index < device_count(machine, IO_FLOPPY))
123122         image = image_from_devtype_and_index(IO_FLOPPY, floppy_index);
124123   }
125124   else
r3836r3837
145144
146145
147146
148void pc_fdc_hw_interrupt(int state)
147void pc_fdc_hw_interrupt(running_machine *machine,int state)
149148{
150149   fdc->int_state = state;
151150
r3836r3837
155154
156155   /* send irq */
157156   if (fdc->fdc_interface.pc_fdc_interrupt)
158      fdc->fdc_interface.pc_fdc_interrupt(state);
157      fdc->fdc_interface.pc_fdc_interrupt(machine, state);
159158}
160159
161160
r3836r3837
190189
191190
192191
193void pc_fdc_hw_dma_drq(int state, int read_)
192void pc_fdc_hw_dma_drq(running_machine *machine, int state, int read_)
194193{
195194   fdc->dma_state = state;
196195   fdc->dma_read = read_;
r3836r3837
200199      return;
201200
202201   if (fdc->fdc_interface.pc_fdc_dma_drq)
203      fdc->fdc_interface.pc_fdc_dma_drq(state, read_);
202      fdc->fdc_interface.pc_fdc_dma_drq(machine,state, read_);
204203}
205204
206205
r3836r3837
275274   /* changing the DMA enable bit, will affect the dma drq state
276275   from reaching us - if dma is enabled this will send it through
277276   otherwise it will be ignored */
278   pc_fdc_hw_dma_drq(fdc->dma_state, fdc->dma_read);
277   pc_fdc_hw_dma_drq(machine, fdc->dma_state, fdc->dma_read);
279278
280279   /* changing the DMA enable bit, will affect the irq state
281280   from reaching us - if dma is enabled this will send it through
282281   otherwise it will be ignored */
283   pc_fdc_hw_interrupt(fdc->int_state);
282   pc_fdc_hw_interrupt(machine, fdc->int_state);
284283
285284   /* reset? */
286285   if ((fdc->digital_output_register & PC_FDC_FLAGS_DOR_FDC_ENABLED)==0)
r3836r3837
337336   /* Trigger a watchdog timeout signal */
338337   if ( fdc->fdc_interface.pc_fdc_interrupt )
339338   {
340      fdc->fdc_interface.pc_fdc_interrupt( 1 );
341      fdc->fdc_interface.pc_fdc_interrupt( 0 );
339      fdc->fdc_interface.pc_fdc_interrupt(machine, 1 );
340      fdc->fdc_interface.pc_fdc_interrupt(machine, 0 );
342341   }
343342}
344343
src/mess/machine/pc_fdc.h
r3836r3837
2828{
2929   NEC765_VERSION nec765_type;
3030   NEC765_RDY_PIN nec765_rdy_pin;
31   void (*pc_fdc_interrupt)(int);
32   void (*pc_fdc_dma_drq)(int,int);
31   void (*pc_fdc_interrupt)(running_machine*,int);
32   void (*pc_fdc_dma_drq)(running_machine*,int,int);
3333   const device_config *(*get_image)(int floppy_index);
3434};
3535
src/mess/machine/bebox.c
r3836r3837
402402
403403#define FDC_DMA 2
404404
405static void bebox_fdc_interrupt(int state)
405static void bebox_fdc_interrupt(running_machine *machine, int state)
406406{
407   bebox_set_irq_bit(Machine, 13, state);
407   bebox_set_irq_bit(machine, 13, state);
408408   if ( bebox_devices.pic8259_master ) {
409409      pic8259_set_irq_line(bebox_devices.pic8259_master, 6, state);
410410   }
411411}
412412
413413
414static void bebox_fdc_dma_drq(int state, int read_)
414static void bebox_fdc_dma_drq(running_machine *machine, int state, int read_)
415415{
416416   if ( bebox_devices.dma8237_1 ) {
417417      dma8237_drq_write(bebox_devices.dma8237_1, FDC_DMA, state);
r3836r3837
580580}
581581
582582
583static void bebox_map_vga_memory(offs_t begin, offs_t end, read8_space_func rh, write8_space_func wh)
583static void bebox_map_vga_memory(running_machine *machine, offs_t begin, offs_t end, read8_space_func rh, write8_space_func wh)
584584{
585   const address_space *space = cpu_get_address_space( Machine->cpu[0], ADDRESS_SPACE_PROGRAM );
585   const address_space *space = cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM );
586586
587587   read64_space_func rh64 = (rh == SMH_BANK4) ? SMH_BANK4 : bebox_vga_memory_r;
588588   write64_space_func wh64 = (wh == SMH_BANK4) ? SMH_BANK4 : bebox_vga_memory_w;
src/mess/machine/hd63450.c
r3836r3837
284284         {
285285            if(dmac->intf->dma_read[x])
286286            {
287               data = dmac->intf->dma_read[x](dmac->reg[x].mar);
287               data = dmac->intf->dma_read[x](device->machine,dmac->reg[x].mar);
288288               if(data == -1)
289289                  return;  // not ready to recieve data
290290               memory_write_byte(space,dmac->reg[x].mar,data);
r3836r3837
325325            if(dmac->intf->dma_write[x])
326326            {
327327               data = memory_read_byte(space,dmac->reg[x].mar);
328               dmac->intf->dma_write[x](dmac->reg[x].mar,data);
328               dmac->intf->dma_write[x](device->machine, dmac->reg[x].mar,data);
329329               datasize = 1;
330330            }
331331            else
r3836r3837
396396               cpu_set_input_line(device->machine->cpu[dmac->intf->cpu],INPUT_LINE_HALT,CLEAR_LINE);
397397
398398            if(dmac->intf->dma_end)
399               dmac->intf->dma_end(x,dmac->reg[x].ccr & 0x08);
399               dmac->intf->dma_end(device->machine,x,dmac->reg[x].ccr & 0x08);
400400         }
401401      }
402402}
src/mess/machine/pc.c
r3836r3837
10601060
10611061#define FDC_DMA 2
10621062
1063static void pc_fdc_interrupt(int state)
1063static void pc_fdc_interrupt(running_machine *machine, int state)
10641064{
10651065   if ( pc_devices.pic8259_master ) {
10661066      pic8259_set_irq_line(pc_devices.pic8259_master, 6, state);
10671067   }
10681068}
10691069
1070static void pc_fdc_dma_drq(int state, int read_)
1070static void pc_fdc_dma_drq(running_machine *machine, int state, int read_)
10711071{
10721072   dma8237_drq_write( pc_devices.dma8237, FDC_DMA, state);
10731073}
r3836r3837
12361236
12371237
12381238
1239static void pc_map_vga_memory(offs_t begin, offs_t end, read8_space_func rh, write8_space_func wh)
1239static void pc_map_vga_memory(running_machine *machine, offs_t begin, offs_t end, read8_space_func rh, write8_space_func wh)
12401240{
1241   const address_space *space = cpu_get_address_space( Machine->cpu[0], ADDRESS_SPACE_PROGRAM );
1241   const address_space *space = cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM );
12421242   int buswidth;
1243   buswidth = cpu_get_databus_width(Machine->cpu[0], ADDRESS_SPACE_PROGRAM);
1243   buswidth = cpu_get_databus_width(machine->cpu[0], ADDRESS_SPACE_PROGRAM);
12441244   switch(buswidth)
12451245   {
12461246      case 8:
src/mess/machine/hd63450.h
r3836r3837
1010   int cpu;
1111   attotime clock[4];
1212   attotime burst_clock[4];
13   void (*dma_end)(int channel,int irq);  // called when the DMA transfer ends
14   void (*dma_error)(int channel, int irq);  // called when a DMA transfer error occurs
15   int (*dma_read[4])(int addr);  // special read / write handlers for each channel
16   void (*dma_write[4])(int addr,int data);
13   void (*dma_end)(running_machine *machine,int channel,int irq);  // called when the DMA transfer ends
14   void (*dma_error)(running_machine *machine,int channel, int irq);  // called when a DMA transfer error occurs
15   int (*dma_read[4])(running_machine *machine,int addr);  // special read / write handlers for each channel
16   void (*dma_write[4])(running_machine *machine,int addr,int data);
1717};
1818
1919typedef struct _hd63450_regs hd63450_regs;
src/mess/machine/bbc.c
r3836r3837
13351335
13361336UPD7002_EOC(BBC_uPD7002_EOC)
13371337{
1338   via_0_cb1_w(cpu_get_address_space(Machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0,data);
1338   via_0_cb1_w(cpu_get_address_space(device->machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0,data);
13391339}
13401340
13411341const uPD7002_interface BBC_uPD7002 =
r3836r3837
15281528
15291529static int previous_i8271_int_state;
15301530
1531static void   bbc_i8271_interrupt(int state)
1531static void   bbc_i8271_interrupt(const device_config *device, int state)
15321532{
15331533   /* I'm assuming that the nmi is edge triggered */
15341534   /* a interrupt from the fdc will cause a change in line state, and
r3836r3837
15421542      {
15431543         /* I'll pulse it because if I used hold-line I'm not sure
15441544         it would clear - to be checked */
1545         cpu_set_input_line(cputag_get_cpu(Machine, "main"), INPUT_LINE_NMI,PULSE_LINE);
1545         cpu_set_input_line(cputag_get_cpu(device->machine, "main"), INPUT_LINE_NMI,PULSE_LINE);
15461546      }
15471547   }
15481548
r3836r3837
15501550}
15511551
15521552
1553static const i8271_interface bbc_i8271_interface=
1553const i8271_interface bbc_i8271_interface=
15541554{
15551555   bbc_i8271_interrupt,
15561556    NULL
r3836r3837
15591559
15601560static READ8_HANDLER( bbc_i8271_read )
15611561{
1562int ret;
1562   int ret;
1563   device_config *i8271 = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, I8271, "i8271" );
15631564   ret=0x0ff;
15641565   logerror("i8271 read %d  ",offset);
15651566   switch (offset)
r3836r3837
15691570      case 2:
15701571      case 3:
15711572         /* 8271 registers */
1572         ret=i8271_r(space, offset);
1573         ret=i8271_r(i8271, offset);
15731574         logerror("  %d\n",ret);
15741575         return ret;
15751576      case 4:
1576         ret=i8271_data_r(space, offset);
1577         ret=i8271_data_r(i8271, offset);
15771578         logerror("  %d\n",ret);
15781579         return ret;
15791580      default:
r3836r3837
15851586
15861587static WRITE8_HANDLER( bbc_i8271_write )
15871588{
1589   device_config *i8271 = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, I8271, "i8271" );
15881590   logerror("i8271 write  %d  %d\n",offset,data);
15891591
15901592   switch (offset)
r3836r3837
15941596      case 2:
15951597      case 3:
15961598         /* 8271 registers */
1597         i8271_w(space, offset, data);
1599         i8271_w(i8271, offset, data);
15981600         return;
15991601      case 4:
1600         i8271_data_w(space, offset, data);
1602         i8271_data_w(i8271, offset, data);
16011603         return;
16021604      default:
16031605         break;
r3836r3837
21682170   //switch (bbc_DFSType) {
21692171   //case 0:   case 1: case 2: case 3:
21702172      previous_i8271_int_state=0;
2171      i8271_init(&bbc_i8271_interface);
21722173   //   break;
21732174   //case 4: case 5: case 6:
21742175      previous_wd177x_int_state=1;
r3836r3837
22092210   /*set up the required disc controller*/
22102211   //switch (bbc_DFSType) {
22112212   //case 0:   case 1: case 2: case 3:
2212      i8271_reset();
22132213   //   break;
22142214   //case 4: case 5: case 6:
22152215       wd17xx_reset(machine);
src/mess/machine/kc.c
r3836r3837
209209
210210
211211/* callback for /INT output from FDC */
212static void kc85_fdc_interrupt(int state)
212static void kc85_fdc_interrupt(running_machine *machine, int state)
213213{
214214   kc85_disc_hw_input_gate &=~(1<<6);
215215   if (state)
r3836r3837
217217}
218218
219219/* callback for /DRQ output from FDC */
220static void kc85_fdc_dma_drq(int state, int read_)
220static void kc85_fdc_dma_drq(running_machine *machine, int state, int read_)
221221{
222222   kc85_disc_hw_input_gate &=~(1<<7);
223223   if (state)
src/mess/drivers/nc.c
r3836r3837
13221322};
13231323
13241324
1325static void nc200_fdc_interrupt(int state)
1325static void nc200_fdc_interrupt(running_machine *machine, int state)
13261326{
13271327#if 0
13281328    nc_irq_latch &=~(1<<5);
r3836r3837
13391339            nc_irq_status |=(1<<5);
13401340    }
13411341
1342    nc_update_interrupts(Machine);
1342    nc_update_interrupts(machine);
13431343}
13441344
13451345static const struct nec765_interface nc200_nec765_interface=
src/mess/drivers/sord.c
r3836r3837
1919 ******************************************************************************/
2020
2121#include "driver.h"
22#include "deprecat.h"
2322#include "video/tms9928a.h"
2423#include "sound/sn76496.h"
2524#include "cpu/z80/z80.h"
r3836r3837
152151ADDRESS_MAP_END
153152
154153/* nec765 data request is connected to interrupt of z80 inside fd5 interface */
155static void sord_fd5_fdc_interrupt(int state)
154static void sord_fd5_fdc_interrupt(running_machine *machine, int state)
156155{
157156   if (state)
158157   {
159      cpu_set_input_line(Machine->cpu[1], 0, HOLD_LINE);
158      cpu_set_input_line(machine->cpu[1], 0, HOLD_LINE);
160159   }
161160   else
162161   {
163      cpu_set_input_line(Machine->cpu[1], 0,CLEAR_LINE);
162      cpu_set_input_line(machine->cpu[1], 0,CLEAR_LINE);
164163   }
165164}
166165
src/mess/drivers/pcw16.c
r3836r3837
8989
9090/* Core includes */
9191#include "driver.h"
92#include "deprecat.h"
9392#include "includes/pcw16.h"
9493
9594/* Components */
r3836r3837
11891188   return pc_fdc_r(space, PC_FDC_DIGITIAL_INPUT_REGISTER);
11901189}
11911190
1192static void   pcw16_fdc_interrupt(int state)
1191static void   pcw16_fdc_interrupt(running_machine *machine, int state)
11931192{
11941193   /* IRQ6 */
11951194   /* bit 6 of PCW16 system status indicates floppy ints */
r3836r3837
12001199      pcw16_system_status |= (1<<6);
12011200   }
12021201
1203   pcw16_trigger_fdc_int(Machine);
1202   pcw16_trigger_fdc_int(machine);
12041203}
12051204
12061205static const struct pc_fdc_interface pcw16_fdc_interface=
src/mess/drivers/x68k.c
r3836r3837
118118*/
119119
120120#include "driver.h"
121#include "deprecat.h"
122121#include "cpu/m68000/m68000.h"
123122#include "machine/68901mfp.h"
124123#include "machine/8255ppi.h"
r3836r3837
832831   }
833832}
834833
835static void fdc_irq(int state)
834static void fdc_irq(running_machine *machine,int state)
836835{
837836   if((sys.ioc.irqstatus & 0x04) && state == ASSERT_LINE)
838837   {
r3836r3837
840839      sys.ioc.irqstatus |= 0x80;
841840      current_irq_line = 1;
842841      logerror("FDC: IRQ triggered\n");
843      cpu_set_input_line_and_vector(Machine->cpu[0],1,ASSERT_LINE,current_vector[1]);
842      cpu_set_input_line_and_vector(machine->cpu[0],1,ASSERT_LINE,current_vector[1]);
844843   }
845844}
846845
847static int x68k_fdc_read_byte(int addr)
846static int x68k_fdc_read_byte(running_machine *machine,int addr)
848847{
849848   int data = -1;
850849
851850   if(sys.fdc.drq_state != 0)
852      data = nec765_dack_r(cpu_get_address_space(Machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0);
851      data = nec765_dack_r(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0);
853852//  logerror("FDC: DACK reading\n");
854853   return data;
855854}
856855
857static void x68k_fdc_write_byte(int addr, int data)
856static void x68k_fdc_write_byte(running_machine *machine,int addr, int data)
858857{
859   nec765_dack_w(cpu_get_address_space(Machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0, data);
858   nec765_dack_w(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0, data);
860859}
861860
862static void fdc_drq(int state, int read_write)
861static void fdc_drq(running_machine *machine,int state, int read_write)
863862{
864863   sys.fdc.drq_state = state;
865864}
r3836r3837
14791478   cpu_set_input_line_and_vector(machine->cpu[0],3,ASSERT_LINE,current_vector[3]);
14801479}
14811480
1482static void x68k_dma_end(int channel,int irq)
1481static void x68k_dma_end(running_machine *machine, int channel,int irq)
14831482{
14841483   if(irq != 0)
14851484   {
1486      x68k_dma_irq(Machine, channel);
1485      x68k_dma_irq(machine, channel);
14871486   }
14881487}
14891488
1490static void x68k_dma_error(int channel, int irq)
1489static void x68k_dma_error(running_machine *machine, int channel, int irq)
14911490{
1492   const device_config *device = device_list_find_by_tag(Machine->config->devicelist, HD63450, "hd63450");
1491   const device_config *device = device_list_find_by_tag(machine->config->devicelist, HD63450, "hd63450");
14931492   if(irq != 0)
14941493   {
14951494      current_vector[3] = hd63450_get_error_vector(device,channel);
14961495      current_irq_line = 3;
1497      cpu_set_input_line_and_vector(Machine->cpu[0],3,ASSERT_LINE,current_vector[3]);
1496      cpu_set_input_line_and_vector(machine->cpu[0],3,ASSERT_LINE,current_vector[3]);
14981497   }
14991498}
15001499
src/mess/drivers/sg1000.c
r3836r3837
6565
6666#include "driver.h"
6767#include "includes/sg1000.h"
68#include "deprecat.h"
6968#include "devices/basicdsk.h"
7069#include "devices/cartslot.h"
7170#include "devices/cassette.h"
r3836r3837
696695};
697696
698697/* callback for /INT output from FDC */
699static void sf7000_fdc_interrupt(int state)
698static void sf7000_fdc_interrupt(running_machine *machine,int state)
700699{
701   sg1000_state *driver_state = Machine->driver_data; // TODO
700   sg1000_state *driver_state = machine->driver_data; // TODO
702701
703702   driver_state->fdc_irq = state;
704703}
src/mess/drivers/pcw.c
r3836r3837
9393  - emulation of other hardware...?
9494 ******************************************************************************/
9595#include "driver.h"
96#include "deprecat.h"
9796// nec765 interface
9897#include "machine/nec765.h"
9998#include "devices/dsk.h"
r3836r3837
105104#define VERBOSE 0
106105#define LOG(x) do { if (VERBOSE) logerror x; } while (0)
107106
108static void pcw_fdc_interrupt(int);
107static void pcw_fdc_interrupt(running_machine*,int);
109108
110109// pointer to pcw ram
111110unsigned int roller_ram_addr;
r3836r3837
214213}
215214
216215/* fdc interrupt callback. set/clear fdc int */
217static void pcw_fdc_interrupt(int state)
216static void pcw_fdc_interrupt(running_machine *machine,int state)
218217{
219218   pcw_system_status &= ~(1<<5);
220219
r3836r3837
224223      pcw_system_status |= (1<<5);
225224   }
226225
227   pcw_trigger_fdc_int(Machine);
226   pcw_trigger_fdc_int(machine);
228227}
229228
230229
r3836r3837
283282
284283
285284
286static void pcw_update_write_memory_block(int block, int bank)
285static void pcw_update_write_memory_block(running_machine *machine, int block, int bank)
287286{
288   memory_set_bankptr(Machine, block + 5, mess_ram + ((bank * 0x4000) % mess_ram_size));
287   memory_set_bankptr(machine, block + 5, mess_ram + ((bank * 0x4000) % mess_ram_size));
289288}
290289
291290
r3836r3837
307306      bank = data & 0x7f;
308307
309308      pcw_update_read_memory_block(machine, block, bank);
310      pcw_update_write_memory_block(block, bank);
309      pcw_update_write_memory_block(machine, block, bank);
311310   }
312311   else
313312   {
r3836r3837
355354      pcw_update_read_memory_block(machine, block, read_bank);
356355
357356      write_bank = data & 0x07;
358      pcw_update_write_memory_block(block, write_bank);
357      pcw_update_write_memory_block(machine, block, write_bank);
359358   }
360359
361360   /* if boot is active, page in fake ROM */
src/mess/drivers/atom.c
r3836r3837
280280   MDRV_QUICKLOAD_ADD(atom, "atm", 0)
281281
282282   MDRV_CASSETTE_ADD( "cassette", default_cassette_config )
283   
284   MDRV_I8271_ADD("i8271", atom_8271_interface)
283285MACHINE_DRIVER_END
284286
285287
src/mess/drivers/newbrain.c
r3836r3837
11#include "driver.h"
2#include "deprecat.h"
32#include "cpu/z80/z80daisy.h"
43#include "cpu/cop400/cop400.h"
54#include "machine/nec765.h"
r3836r3837
10991098   acia_interrupt
11001099};
11011100
1102static void newbrain_fdc_interrupt(int state)
1101static void newbrain_fdc_interrupt(running_machine *machine, int state)
11031102{
1104   newbrain_state *driver_state = Machine->driver_data;
1103   newbrain_state *driver_state = machine->driver_data;
11051104
11061105   driver_state->fdc_int = state;
11071106}
src/mess/drivers/amstrad.c
r3836r3837
428428   amstrad_ppi_portc_w    /* port C write */
429429};
430430
431static void aleste_interrupt(int state)
431static void aleste_interrupt(running_machine *machine,int state)
432432{
433433   if(state == CLEAR_LINE)
434434      aleste_fdc_int = 0;
src/mess/drivers/bbc.c
r3836r3837
752752   
753753   /* devices */
754754   MDRV_UPD7002_ADD("upd7002",BBC_uPD7002)
755   MDRV_I8271_ADD("i8271", bbc_i8271_interface)
755756MACHINE_DRIVER_END
756757
757758

Previous 15994 Revisions Next


© 1998-2018 The MESS Team