Previous 15994 Revisions Next

r11960 Wednesday 15th June, 2011 at 19:11:45 UTC by Curt Coder
[MPZ80] Implemented interrupt and trap logic. Won't run with the debugger enabled until refactored to use direct updates. (nw)
[src/mess/drivers]mpz80.c
[src/mess/includes]mpz80.h

src/mess/includes/mpz80.h
r11959r11960
2626        m_maincpu(*this, Z80_TAG),
2727        m_ram(*this, RAM_TAG),
2828        m_terminal(*this, TERMINAL_TAG),
29        m_s100(*this, S100_TAG)
29        m_s100(*this, S100_TAG),
30        m_nmi(1),
31        m_pint(1),
32        m_int_pend(0),
33        m_pretrap(0),
34        m_trap(0),
35        m_trap_ctr(0),
36        m_trap_reset(0),
37        m_trap_void(1),
38        m_trap_halt(1),
39        m_trap_int(1),
40        m_trap_stop(1),
41        m_trap_aux(1)
3042   { }
3143
3244   required_device<cpu_device> m_maincpu;
r11959r11960
3749   virtual void machine_start();
3850   virtual void machine_reset();
3951   
40   inline UINT32 get_address(UINT16 offset);
52   inline offs_t get_address(offs_t offset);
53   inline offs_t get_io_address(offs_t offset);
54   
55   inline void check_traps();
56   inline void check_interrupt();
4157
4258   DECLARE_READ8_MEMBER( mmu_r );
4359   DECLARE_WRITE8_MEMBER( mmu_w );
r11959r11960
5268   DECLARE_WRITE8_MEMBER( task_w );
5369   DECLARE_WRITE8_MEMBER( mask_w );
5470   DECLARE_WRITE8_MEMBER( terminal_w );
71   DECLARE_WRITE_LINE_MEMBER( s100_pint_w );
72   DECLARE_WRITE_LINE_MEMBER( s100_nmi_w );
5573   
5674   // memory state
75   UINT32 m_addr;
5776   UINT8 *m_map_ram;
5877   UINT8 m_task;
5978   UINT8 m_mask;
79
80   // interrupt state
81   int m_nmi;
82   int m_pint;
83   int m_int_pend;
84   
85   // trap state
86   UINT8 m_pretrap_addr;
87   UINT8 m_trap_addr;
88   UINT8 m_status;
89   int m_pretrap;
90   int m_trap;
91   int m_trap_ctr;
92   int m_trap_reset;
93   int m_trap_void;
94   int m_trap_halt;
95   int m_trap_int;
96   int m_trap_stop;
97   int m_trap_aux;
6098};
6199
62100#endif
src/mess/drivers/mpz80.c
r11959r11960
1111    TODO:
1212
1313   - trap logic
14      - reset trap
14      - trap reset
15      - trap stop
16      - trap aux
17      - trap halt
18      - trap int
19      - trap void
20      - in/out trap
21      - read/write trap
22      - exec trap
1523   - memory management
1624      - task RAM
1725      - mapping RAM
r11959r11960
5462   FULL_ACCESS
5563};
5664
65#define TASK0   ((m_task & 0x0f) == 0)
66
5767#define R10   0x04
5868
5969
r11959r11960
7080
7181
7282//**************************************************************************
83//  INTERRUPTS
84//**************************************************************************
85
86//-------------------------------------------------
87//  check_traps -
88//-------------------------------------------------
89
90inline void mpz80_state::check_traps()
91{
92   m_pretrap = !(m_trap_int & m_trap_halt & m_trap_stop & m_trap_aux);
93   
94   if (m_pretrap)
95   {
96      // latch trap condition
97      m_status = m_trap_void;
98      m_status |= m_trap_halt << 2;
99      m_status |= m_trap_int << 3;
100      m_status |= m_trap_stop << 4;
101      m_status |= m_trap_aux << 5;
102     
103      // latch trap address
104      m_pretrap_addr = ((m_addr >> 8) & 0xf0) | (m_pretrap_addr >> 4);
105   }
106}
107
108
109//-------------------------------------------------
110//  check_interrupt -
111//-------------------------------------------------
112
113inline void mpz80_state::check_interrupt()
114{
115   int tint_enbl = (m_mask & MASK_TINT_ENBL) ? 1 : 0;
116   int sint_enbl = (m_mask & MASK_SINT_ENBL) ? 0 : 1;
117
118   m_int_pend = !(m_nmi & m_pint);
119   m_trap_int = !(m_int_pend & tint_enbl);
120   
121   int z80irq = CLEAR_LINE;
122   int z80nmi = CLEAR_LINE;
123   
124   if (TASK0)
125   {
126      if (!m_pint && !sint_enbl) z80irq = ASSERT_LINE;
127      if (!m_nmi && !sint_enbl) z80nmi = ASSERT_LINE;
128   }
129   else
130   {
131      if (!m_pint && !tint_enbl) z80irq = ASSERT_LINE;
132      if (!m_nmi && !tint_enbl) z80nmi = ASSERT_LINE;
133   }
134   
135   m_maincpu->set_input_line(INPUT_LINE_IRQ0, z80irq);
136   m_maincpu->set_input_line(INPUT_LINE_NMI, z80nmi);
137   
138   check_traps();
139}
140
141
142
143//**************************************************************************
73144//  MEMORY MANAGEMENT
74145//**************************************************************************
75146
r11959r11960
77148//  get_address -
78149//-------------------------------------------------
79150
80inline UINT32 mpz80_state::get_address(UINT16 offset)
151inline offs_t mpz80_state::get_address(offs_t offset)
81152{
82153   UINT16 map_addr = ((m_task & 0x0f) << 5) | (offset >> 11);
83154   UINT8 map = m_map_ram[map_addr];
r11959r11960
96167
97168READ8_MEMBER( mpz80_state::mmu_r )
98169{
99   UINT32 addr = get_address(offset);
170   m_addr = get_address(offset);
171   UINT8 *rom = machine().region(Z80_TAG)->base();
100172   UINT8 data = 0;
173   
174   if (m_pretrap)
175   {
176      m_pretrap = 0;
177      m_trap = 1;
101178     
102   if (((m_task & 0x0f) == 0) && (addr < 0x1000))
179      // latch trap address
180      m_pretrap_addr = ((m_addr >> 8) & 0xf0) | (m_pretrap_addr >> 4);
181      m_trap_addr = m_pretrap_addr;
182   }
183   
184   if (!m_trap_void || !m_trap_halt || m_trap)
103185   {
104      if (addr < 0x400)
186      UINT16 rom_addr = (m_trap_reset << 10) | 0x3f0 | m_trap_ctr;
187      data = rom[rom_addr];
188      m_trap_ctr++;
189     
190      if (m_trap_ctr == 15)
105191      {
192         m_trap = 0;
193      }
194   }
195   else if (TASK0 && (m_addr < 0x1000))
196   {
197      if (m_addr < 0x400)
198      {
106199         UINT8 *ram = ram_get_ptr(m_ram);
107         data = ram[addr & 0x3ff];
200         data = ram[m_addr & 0x3ff];
108201      }
109      else if (addr == 0x400)
202      else if (m_addr == 0x400)
110203      {
111204         data = trap_addr_r(space, 0);
112205      }
113      else if (addr == 0x401)
206      else if (m_addr == 0x401)
114207      {
115208         data = keyboard_r(space, 0);
116209      }
117      else if (addr == 0x402)
210      else if (m_addr == 0x402)
118211      {
119212         data = switch_r(space, 0);
120213      }
121      else if (addr == 0x403)
214      else if (m_addr == 0x403)
122215      {
123216         data = status_r(space, 0);
124217      }
125      else if (addr >= 0x600 && addr < 0x800)
218      else if (m_addr >= 0x600 && m_addr < 0x800)
126219      {
127220         // TODO this might change the map RAM contents
128221      }
129      else if (addr < 0xc00)
222      else if (m_addr < 0xc00)
130223      {
131         UINT8 *rom = machine().region(Z80_TAG)->base();
132         data = rom[addr & 0x7ff];
224         UINT16 rom_addr = (m_trap_reset << 10) | (m_addr & 0x3ff);
225         data = rom[rom_addr];
226         printf("rom %03x\n", rom_addr);
133227      }
134228      else
135229      {
136         logerror("Unmapped LOCAL read at %06x\n", addr);
230         logerror("Unmapped LOCAL read at %06x\n", m_addr);
137231      }
138232   }
139233   else
140234   {
141      data = m_s100->smemr_r(space, offset);
235      data = m_s100->smemr_r(space, m_addr);
142236   }
143237   
144238   return data;
r11959r11960
151245
152246WRITE8_MEMBER( mpz80_state::mmu_w )
153247{
154   UINT32 addr = get_address(offset);
248   m_addr = get_address(offset);
155249
156   if (((m_task & 0x0f) == 0) && (addr < 0x1000))
250   if (TASK0 && (m_addr < 0x1000))
157251   {
158      if (addr < 0x400)
252      if (m_addr < 0x400)
159253      {
160254         UINT8 *ram = ram_get_ptr(m_ram);
161         ram[addr & 0x3ff] = data;
255         ram[m_addr & 0x3ff] = data;
162256      }
163      else if (addr == 0x400)
257      else if (m_addr == 0x400)
164258      {
165259         disp_seg_w(space, 0, data);
166260      }
167      else if (addr == 0x401)
261      else if (m_addr == 0x401)
168262      {
169263         disp_col_w(space, 0, data);
170264      }
171      else if (addr == 0x402)
265      else if (m_addr == 0x402)
172266      {
173267         task_w(space, 0, data);
174268      }
175      else if (addr == 0x403)
269      else if (m_addr == 0x403)
176270      {
177271         mask_w(space, 0, data);
178272      }
179      else if (addr >= 0x600 && addr < 0x800)
273      else if (m_addr >= 0x600 && m_addr < 0x800)
180274      {
181         m_map_ram[addr - 0x600] = data;
275         m_map_ram[m_addr - 0x600] = data;
182276      }
183277      else
184278      {
185         logerror("Unmapped LOCAL write at %06x\n", addr);
279         logerror("Unmapped LOCAL write at %06x\n", m_addr);
186280      }
187281   }
188282   else
189283   {
190      m_s100->mwrt_w(space, offset, data);
284      m_s100->mwrt_w(space, m_addr, data);
191285   }
192286}
193287
194288
195289//-------------------------------------------------
196//  mmu_io_r -
290//  get_io_address -
197291//-------------------------------------------------
198292
199READ8_MEMBER( mpz80_state::mmu_io_r )
293inline offs_t mpz80_state::get_io_address(offs_t offset)
200294{
201295   if (m_mask & MASK_ZIO_MODE)
202296   {
r11959r11960
204298      offset = ((offset << 8) & 0xff00) | (offset & 0xff);
205299   }
206300   
207   return m_s100->sinp_r(space, offset);
301   return offset;
208302}
209303
210304
211305//-------------------------------------------------
306//  mmu_io_r -
307//-------------------------------------------------
308
309READ8_MEMBER( mpz80_state::mmu_io_r )
310{
311   return m_s100->sinp_r(space, get_io_address(offset));
312}
313
314
315//-------------------------------------------------
212316//  mmu_io_w -
213317//-------------------------------------------------
214318
215319WRITE8_MEMBER( mpz80_state::mmu_io_w )
216320{
217   if (m_mask & MASK_ZIO_MODE)
218   {
219      // echo port address onto upper address lines (8080 emulation)
220      offset = ((offset << 8) & 0xff00) | (offset & 0xff);
221   }
222   
223   m_s100->sout_w(space, offset, data);
321   m_s100->sout_w(space, get_io_address(offset), data);
224322}
225323
226324
r11959r11960
245343     
246344   */
247345
248   return 0;
346   return m_trap_addr;
249347}
250348
251349
r11959r11960
270368     
271369   */
272370
273   return 0;
371   return m_status;
274372}
275373
276374
r11959r11960
296394   */
297395   
298396   m_task = data;
397   
398   m_trap_reset = 1;
399   check_traps();
299400}
300401
301402
r11959r11960
377478
378479   UINT8 data = 0;
379480   
380   // switches
481   // trap reset
482   data |= m_trap_reset;
483   
484   // interrupt pending
485   data |= m_int_pend << 1;
486   
487   // boot address
381488   data |= input_port_read(machine(), "16C") & 0xfc;
382489   
383490   return data;
r11959r11960
576683//  S100_INTERFACE( s100_intf )
577684//-------------------------------------------------
578685
686WRITE_LINE_MEMBER( mpz80_state::s100_pint_w )
687{
688   m_pint = (state == ASSERT_LINE) ? 0 : 1;
689   
690   check_interrupt();
691}
692
693WRITE_LINE_MEMBER( mpz80_state::s100_nmi_w )
694{
695   if (state == ASSERT_LINE)
696   {
697      m_nmi = 0;
698   }
699   
700   check_interrupt();
701}
579702static S100_INTERFACE( s100_intf )
580703{
581   DEVCB_CPU_INPUT_LINE(Z80_TAG, INPUT_LINE_IRQ0),
704   DEVCB_DRIVER_LINE_MEMBER(mpz80_state, s100_pint_w),
582705   DEVCB_NULL,
583706   DEVCB_NULL,
584707   DEVCB_NULL,
r11959r11960
622745
623746void mpz80_state::machine_reset()
624747{
748   m_trap_reset = 0;
749   m_trap_ctr = 0;
750   m_trap = 1;
751   
752   m_nmi = 1;
753   
754   check_interrupt();
625755}
626756
627757

Previous 15994 Revisions Next


© 1998-2018 The MESS Team