Previous 15994 Revisions Next

r9676 Saturday 27th November, 2010 at 15:27:06 UTC by Nathan Woods
More stuff. [Atari Ace]
[src/mess/drivers]pasopia.c pc6001.c pc88va.c pc98.c pcw16.c pippin.c poly88.c primo.c ptcsol.c sapi1.c smc777.c special.c ti85.c ut88.c vector06.c z1013.c z88.c
[src/mess/includes]pcw16.h poly88.h primo.h sapi1.h special.h ti85.h ut88.h vector06.h z1013.h z88.h
[src/mess/machine]dgn_beta.c poly88.c primo.c sapi1.c special.c ti85.c ut88.c vector06.c vectrex.c z1013.c
[src/mess/video]pcw16.c poly88.c primo.c sapi1.c special.c ti85.c ut88.c vector06.c z1013.c z88.c

src/mess/machine/dgn_beta.c
r9675r9676
10881088   state->d_pia1_pa_last = 0x00;
10891089   state->d_pia1_pb_last = 0x00;
10901090   state->RowShifter = 0x00;         /* shift register to select row */
1091   state->Keyrow = 0x00;            /* state->Keyboard row being shifted out */
1091   state->Keyrow = 0x00;            /* Keyboard row being shifted out */
10921092   state->d_pia0_pb_last = 0x00;      /* Last byte output to pia0 port b */
10931093   state->d_pia0_cb2_last = 0x00;      /* Last state of CB2 */
10941094
src/mess/machine/vector06.c
r9675r9676
1515#include "includes/vector06.h"
1616#include "devices/messram.h"
1717
18UINT8 vector06_keyboard_mask;
19UINT8 vector06_color_index;
20UINT8 vector06_video_mode;
2118
2219
2320static READ8_DEVICE_HANDLER( vector06_8255_portb_r )
2421{
22   vector06_state *state = device->machine->driver_data<vector06_state>();
2523   UINT8 key = 0xff;
26   if ((vector06_keyboard_mask & 0x01)!=0) { key &= input_port_read(device->machine,"LINE0"); }
27   if ((vector06_keyboard_mask & 0x02)!=0) { key &= input_port_read(device->machine,"LINE1"); }
28   if ((vector06_keyboard_mask & 0x04)!=0) { key &= input_port_read(device->machine,"LINE2"); }
29   if ((vector06_keyboard_mask & 0x08)!=0) { key &= input_port_read(device->machine,"LINE3"); }
30   if ((vector06_keyboard_mask & 0x10)!=0) { key &= input_port_read(device->machine,"LINE4"); }
31   if ((vector06_keyboard_mask & 0x20)!=0) { key &= input_port_read(device->machine,"LINE5"); }
32   if ((vector06_keyboard_mask & 0x40)!=0) { key &= input_port_read(device->machine,"LINE6"); }
33   if ((vector06_keyboard_mask & 0x80)!=0) { key &= input_port_read(device->machine,"LINE7"); }
24   if ((state->keyboard_mask & 0x01)!=0) { key &= input_port_read(device->machine,"LINE0"); }
25   if ((state->keyboard_mask & 0x02)!=0) { key &= input_port_read(device->machine,"LINE1"); }
26   if ((state->keyboard_mask & 0x04)!=0) { key &= input_port_read(device->machine,"LINE2"); }
27   if ((state->keyboard_mask & 0x08)!=0) { key &= input_port_read(device->machine,"LINE3"); }
28   if ((state->keyboard_mask & 0x10)!=0) { key &= input_port_read(device->machine,"LINE4"); }
29   if ((state->keyboard_mask & 0x20)!=0) { key &= input_port_read(device->machine,"LINE5"); }
30   if ((state->keyboard_mask & 0x40)!=0) { key &= input_port_read(device->machine,"LINE6"); }
31   if ((state->keyboard_mask & 0x80)!=0) { key &= input_port_read(device->machine,"LINE7"); }
3432   return key;
3533}
3634
r9675r9676
4644
4745static WRITE8_DEVICE_HANDLER (vector06_8255_porta_w )
4846{
49   vector06_keyboard_mask = data ^ 0xff;
47   vector06_state *state = device->machine->driver_data<vector06_state>();
48   state->keyboard_mask = data ^ 0xff;
5049}
5150
5251static void vector06_set_video_mode(running_machine *machine, int width) {
r9675r9676
6160
6261static WRITE8_DEVICE_HANDLER (vector06_8255_portb_w )
6362{
64   vector06_color_index = data & 0x0f;
65   if ((data & 0x10) != vector06_video_mode)
63   vector06_state *state = device->machine->driver_data<vector06_state>();
64   state->color_index = data & 0x0f;
65   if ((data & 0x10) != state->video_mode)
6666   {
67      vector06_video_mode = data & 0x10;
68      vector06_set_video_mode(device->machine,(vector06_video_mode==0x10) ? 512 : 256);
67      state->video_mode = data & 0x10;
68      vector06_set_video_mode(device->machine,(state->video_mode==0x10) ? 512 : 256);
6969   }
7070}
7171
7272WRITE8_HANDLER(vector06_color_set)
7373{
74   vector06_state *state = space->machine->driver_data<vector06_state>();
7475   UINT8 r = (data & 7) << 5;
7576   UINT8 g = ((data >> 3) & 7) << 5;
7677   UINT8 b = ((data >>6) & 3) << 6;
77   palette_set_color( space->machine, vector06_color_index, MAKE_RGB(r,g,b) );
78   palette_set_color( space->machine, state->color_index, MAKE_RGB(r,g,b) );
7879}
7980
80static UINT8 romdisk_msb;
81static UINT8 romdisk_lsb;
8281
8382static READ8_DEVICE_HANDLER (vector06_romdisk_portb_r )
8483{
84   vector06_state *state = device->machine->driver_data<vector06_state>();
8585   UINT8 *romdisk = memory_region(device->machine, "maincpu") + 0x18000;
86   UINT16 addr = (romdisk_msb*256+romdisk_lsb) & 0x7fff;
86   UINT16 addr = (state->romdisk_msb*256+state->romdisk_lsb) & 0x7fff;
8787   return romdisk[addr];
8888}
8989
9090static WRITE8_DEVICE_HANDLER (vector06_romdisk_porta_w )
9191{
92   romdisk_lsb = data;
92   vector06_state *state = device->machine->driver_data<vector06_state>();
93   state->romdisk_lsb = data;
9394}
9495
9596static WRITE8_DEVICE_HANDLER (vector06_romdisk_portc_w )
9697{
97   romdisk_msb = data;
98   vector06_state *state = device->machine->driver_data<vector06_state>();
99   state->romdisk_msb = data;
98100}
99101
100102I8255A_INTERFACE( vector06_ppi8255_2_interface )
r9675r9676
136138
137139}
138140
139static UINT8 vblank_state = 0;
140141INTERRUPT_GEN( vector06_interrupt )
141142{
142   vblank_state++;
143   if (vblank_state>1) vblank_state=0;
144   cpu_set_input_line(device,0,vblank_state ? HOLD_LINE : CLEAR_LINE);
143   vector06_state *state = device->machine->driver_data<vector06_state>();
144   state->vblank_state++;
145   if (state->vblank_state>1) state->vblank_state=0;
146   cpu_set_input_line(device,0,state->vblank_state ? HOLD_LINE : CLEAR_LINE);
145147
146148}
147149
r9675r9676
178180
179181MACHINE_RESET( vector06 )
180182{
183   vector06_state *state = machine->driver_data<vector06_state>();
181184   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
182185
183186   cpu_set_irq_callback(machine->device("maincpu"), vector06_irq_callback);
r9675r9676
191194   memory_set_bankptr(machine, "bank3", messram_get_ptr(machine->device("messram")) + 0x8000);
192195   memory_set_bankptr(machine, "bank4", messram_get_ptr(machine->device("messram")) + 0x8000);
193196
194   vector06_keyboard_mask = 0;
195   vector06_color_index = 0;
196   vector06_video_mode = 0;
197   state->keyboard_mask = 0;
198   state->color_index = 0;
199   state->video_mode = 0;
197200}
src/mess/machine/sapi1.c
r9675r9676
1111#include "cpu/i8085/i8085.h"
1212#include "includes/sapi1.h"
1313
14static UINT8 sapi1_keyboard_mask;
1514
1615/* Driver initialization */
1716DRIVER_INIT(sapi1)
r9675r9676
2019
2120MACHINE_RESET( sapi1 )
2221{
23   sapi1_keyboard_mask = 0;
22   sapi1_state *state = machine->driver_data<sapi1_state>();
23   state->keyboard_mask = 0;
2424}
2525
2626MACHINE_START(sapi1)
r9675r9676
2929
3030READ8_HANDLER (sapi1_keyboard_r )
3131{
32   sapi1_state *state = space->machine->driver_data<sapi1_state>();
3233   UINT8 key = 0xff;
33   if ((sapi1_keyboard_mask & 0x01)!=0) { key &= input_port_read(space->machine,"LINE0"); }
34   if ((sapi1_keyboard_mask & 0x02)!=0) { key &= input_port_read(space->machine,"LINE1"); }
35   if ((sapi1_keyboard_mask & 0x04)!=0) { key &= input_port_read(space->machine,"LINE2"); }
36   if ((sapi1_keyboard_mask & 0x08)!=0) { key &= input_port_read(space->machine,"LINE3"); }
37   if ((sapi1_keyboard_mask & 0x10)!=0) { key &= input_port_read(space->machine,"LINE4"); }
34   if ((state->keyboard_mask & 0x01)!=0) { key &= input_port_read(space->machine,"LINE0"); }
35   if ((state->keyboard_mask & 0x02)!=0) { key &= input_port_read(space->machine,"LINE1"); }
36   if ((state->keyboard_mask & 0x04)!=0) { key &= input_port_read(space->machine,"LINE2"); }
37   if ((state->keyboard_mask & 0x08)!=0) { key &= input_port_read(space->machine,"LINE3"); }
38   if ((state->keyboard_mask & 0x10)!=0) { key &= input_port_read(space->machine,"LINE4"); }
3839   return key;
3940}
4041WRITE8_HANDLER(sapi1_keyboard_w )
4142{
42   sapi1_keyboard_mask = (data ^ 0xff ) & 0x1f;
43   sapi1_state *state = space->machine->driver_data<sapi1_state>();
44   state->keyboard_mask = (data ^ 0xff ) & 0x1f;
4345}
4446
src/mess/machine/poly88.c
r9675r9676
1212#include "devices/cassette.h"
1313#include "machine/serial.h"
1414
15static UINT8 intr = 0;
16static UINT8 last_code = 0;
17static UINT8 int_vector = 0;
18static emu_timer * poly88_cassette_timer;
19static emu_timer * poly88_usart_timer;
20static int previous_level;
21static int clk_level;
22static int clk_level_tape;
2315
2416static TIMER_CALLBACK(poly88_usart_timer_callback)
2517{
26   int_vector = 0xe7;
18   poly88_state *state = machine->driver_data<poly88_state>();
19   state->int_vector = 0xe7;
2720   cpu_set_input_line(machine->device("maincpu"), 0, HOLD_LINE);
2821}
2922
3023WRITE8_HANDLER(poly88_baud_rate_w)
3124{
25   poly88_state *state = space->machine->driver_data<poly88_state>();
3226   logerror("poly88_baud_rate_w %02x\n",data);
33   poly88_usart_timer = timer_alloc(space->machine, poly88_usart_timer_callback, NULL);
34   timer_adjust_periodic(poly88_usart_timer, attotime_zero, 0, ATTOTIME_IN_HZ(300));
27   state->usart_timer = timer_alloc(space->machine, poly88_usart_timer_callback, NULL);
28   timer_adjust_periodic(state->usart_timer, attotime_zero, 0, ATTOTIME_IN_HZ(300));
3529
3630}
3731
r9675r9676
4943
5044static TIMER_CALLBACK(keyboard_callback)
5145{
46   poly88_state *state = machine->driver_data<poly88_state>();
5247   static const char *const keynames[] = { "LINE0", "LINE1", "LINE2", "LINE3", "LINE4", "LINE5", "LINE6" };
5348
5449   int i;
r9675r9676
124119         }
125120      }
126121   }
127   if (key_code==0 && last_code !=0){
128      int_vector = 0xef;
122   if (key_code==0 && state->last_code !=0){
123      state->int_vector = 0xef;
129124      cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE);
130125   } else {
131      last_code = key_code;
126      state->last_code = key_code;
132127   }
133128}
134129
135130static IRQ_CALLBACK (poly88_irq_callback)
136131{
137   return int_vector;
132   poly88_state *state = device->machine->driver_data<poly88_state>();
133   return state->int_vector;
138134}
139135
140136
r9675r9676
147143
148144static TIMER_CALLBACK(poly88_cassette_timer_callback)
149145{
146   poly88_state *state = machine->driver_data<poly88_state>();
150147   int data;
151148   int current_level;
152149
r9675r9676
156153      /* tape reading */
157154      if (cassette_get_state(machine->device("cassette"))&CASSETTE_PLAY)
158155      {
159               if (clk_level_tape)
156               if (state->clk_level_tape)
160157               {
161                  previous_level = (cassette_input(machine->device("cassette")) > 0.038) ? 1 : 0;
162                  clk_level_tape = 0;
158                  state->previous_level = (cassette_input(machine->device("cassette")) > 0.038) ? 1 : 0;
159                  state->clk_level_tape = 0;
163160               }
164161               else
165162               {
166163                  current_level = (cassette_input(machine->device("cassette")) > 0.038) ? 1 : 0;
167164
168                  if (previous_level!=current_level)
165                  if (state->previous_level!=current_level)
169166                  {
170                     data = (!previous_level && current_level) ? 1 : 0;
167                     data = (!state->previous_level && current_level) ? 1 : 0;
171168//data = current_level;
172169                     set_out_data_bit(poly88_cassette_serial_connection.State, data);
173170                     serial_connection_out(machine, &poly88_cassette_serial_connection);
174171                     msm8251_receive_clock(machine->device("uart"));
175172
176                     clk_level_tape = 1;
173                     state->clk_level_tape = 1;
177174                  }
178175               }
179176      }
r9675r9676
182179      if (cassette_get_state(machine->device("cassette"))&CASSETTE_RECORD)
183180      {
184181         data = get_in_data_bit(poly88_cassette_serial_connection.input_state);
185         data ^= clk_level_tape;
182         data ^= state->clk_level_tape;
186183         cassette_output(machine->device("cassette"), data&0x01 ? 1 : -1);
187184
188         if (!clk_level_tape)
185         if (!state->clk_level_tape)
189186            msm8251_transmit_clock(machine->device("uart"));
190187
191         clk_level_tape = clk_level_tape ? 0 : 1;
188         state->clk_level_tape = state->clk_level_tape ? 0 : 1;
192189
193190         return;
194191      }
195192
196      clk_level_tape = 1;
193      state->clk_level_tape = 1;
197194
198      if (!clk_level)
195      if (!state->clk_level)
199196         msm8251_transmit_clock(machine->device("uart"));
200      clk_level = clk_level ? 0 : 1;
197      state->clk_level = state->clk_level ? 0 : 1;
201198//  }
202199}
203200
r9675r9676
209206
210207DRIVER_INIT ( poly88 )
211208{
212   previous_level = 0;;
213   clk_level = clk_level_tape = 1;
214   poly88_cassette_timer = timer_alloc(machine, poly88_cassette_timer_callback, NULL);
215   timer_adjust_periodic(poly88_cassette_timer, attotime_zero, 0, ATTOTIME_IN_HZ(600));
209   poly88_state *state = machine->driver_data<poly88_state>();
210   state->previous_level = 0;;
211   state->clk_level = state->clk_level_tape = 1;
212   state->cassette_timer = timer_alloc(machine, poly88_cassette_timer_callback, NULL);
213   timer_adjust_periodic(state->cassette_timer, attotime_zero, 0, ATTOTIME_IN_HZ(600));
216214
217215   serial_connection_init(machine, &poly88_cassette_serial_connection);
218216   serial_connection_set_in_callback(machine, &poly88_cassette_serial_connection, poly88_cassette_write);
r9675r9676
222220
223221MACHINE_RESET(poly88)
224222{
223   poly88_state *state = machine->driver_data<poly88_state>();
225224   cpu_set_irq_callback(machine->device("maincpu"), poly88_irq_callback);
226   intr = 0;
227   last_code = 0;
225   state->intr = 0;
226   state->last_code = 0;
228227
229228   timer_set(machine,  attotime_zero, NULL, 0, setup_machine_state );
230229}
231230
232231INTERRUPT_GEN( poly88_interrupt )
233232{
234   int_vector = 0xf7;
233   poly88_state *state = device->machine->driver_data<poly88_state>();
234   state->int_vector = 0xf7;
235235   cpu_set_input_line(device, 0, HOLD_LINE);
236236}
237237static void poly88_usart_rxready (running_device *device, int state)
238238{
239   //int_vector = 0xe7;
239   //poly88_state *drvstate = device->machine->driver_data<poly88_state>();
240   //drvstate->int_vector = 0xe7;
240241   //cpu_set_input_line(device, 0, HOLD_LINE);
241242}
242243const msm8251_interface poly88_usart_interface=
r9675r9676
248249
249250READ8_HANDLER(poly88_keyboard_r)
250251{
251   UINT8 retVal = last_code;
252   poly88_state *state = space->machine->driver_data<poly88_state>();
253   UINT8 retVal = state->last_code;
252254   cputag_set_input_line(space->machine, "maincpu", 0, CLEAR_LINE);
253   last_code = 0x00;
255   state->last_code = 0x00;
254256   return retVal;
255257}
256258
src/mess/machine/z1013.c
r9675r9676
1010#include "includes/z1013.h"
1111#include "cpu/z80/z80.h"
1212
13static UINT8 z1013_keyboard_line;
14static UINT8 z1013_keyboard_part;
1513
1614/* Driver initialization */
1715DRIVER_INIT(z1013)
r9675r9676
2018
2119MACHINE_RESET( z1013 )
2220{
21   z1013_state *state = machine->driver_data<z1013_state>();
2322   cpu_set_reg(machine->device("maincpu"), Z80_PC, 0xF000);
24   z1013_keyboard_part = 0;
25   z1013_keyboard_line = 0;
23   state->keyboard_part = 0;
24   state->keyboard_line = 0;
2625}
2726
2827WRITE8_HANDLER(z1013_keyboard_w) {
29   z1013_keyboard_line   = data;
28   z1013_state *state = space->machine->driver_data<z1013_state>();
29   state->keyboard_line   = data;
3030}
3131
3232static READ8_DEVICE_HANDLER (z1013_port_b_r)
3333{
34   z1013_state *state = device->machine->driver_data<z1013_state>();
3435   static const char *const keynames[] = {
3536      "LINE0", "LINE1", "LINE2", "LINE3",
3637      "LINE4", "LINE5", "LINE6", "LINE7"
3738   };
38   UINT8 data = input_port_read(device->machine, keynames[z1013_keyboard_line & 7]);
39   if (z1013_keyboard_part==0x10) {
39   UINT8 data = input_port_read(device->machine, keynames[state->keyboard_line & 7]);
40   if (state->keyboard_part==0x10) {
4041      return (data >> 4) & 0x0f;
4142   } else {
4243      return data & 0x0f;
r9675r9676
4546
4647static WRITE8_DEVICE_HANDLER (z1013_port_b_w)
4748{
48   z1013_keyboard_part = data;
49   z1013_state *state = device->machine->driver_data<z1013_state>();
50   state->keyboard_part = data;
4951}
5052const z80pio_interface z1013_z80pio_intf =
5153{
src/mess/machine/primo.c
r9675r9676
2424#include "devices/cartslot.h"
2525
2626
27static UINT8 primo_port_FD = 0x00;
28static int primo_nmi = 0;
2927
3028/*******************************************************************************
3129
r9675r9676
3533
3634INTERRUPT_GEN( primo_vblank_interrupt )
3735{
38   if (primo_nmi)
36   primo_state *state = device->machine->driver_data<primo_state>();
37   if (state->nmi)
3938      cpu_set_input_line(device, INPUT_LINE_NMI, PULSE_LINE);
4039}
4140
r9675r9676
4746
4847static void primo_update_memory(running_machine *machine)
4948{
49   primo_state *state = machine->driver_data<primo_state>();
5050   address_space* space = cputag_get_address_space(machine, "maincpu",ADDRESS_SPACE_PROGRAM);
51   switch (primo_port_FD & 0x03)
51   switch (state->port_FD & 0x03)
5252   {
5353      case 0x00:   /* Original ROM */
5454         memory_unmap_write(space, 0x0000, 0x3fff, 0, 0);
r9675r9676
6767         memory_set_bankptr(machine,"bank1", memory_region(machine, "maincpu")+0x18000);
6868         break;
6969   }
70   logerror ("Memory update: %02x\n", primo_port_FD);
70   logerror ("Memory update: %02x\n", state->port_FD);
7171}
7272
7373/*******************************************************************************
r9675r9676
135135
136136WRITE8_HANDLER( primo_ki_1_w )
137137{
138   primo_state *state = space->machine->driver_data<primo_state>();
138139   running_device *speaker = space->machine->device("speaker");
139140   // bit 7 - NMI generator enable/disable
140   primo_nmi = (data & 0x80) ? 1 : 0;
141   state->nmi = (data & 0x80) ? 1 : 0;
141142
142143   // bit 6 - joystick register shift (not emulated)
143144
r9675r9676
148149
149150   // bit 3 - display buffer
150151   if (data & 0x08)
151      primo_video_memory_base |= 0x2000;
152      state->video_memory_base |= 0x2000;
152153   else
153      primo_video_memory_base &= 0xdfff;
154      state->video_memory_base &= 0xdfff;
154155
155156   // bit 2 - V.24 (1) / tape control (not emulated)
156157
r9675r9676
197198
198199WRITE8_HANDLER( primo_FD_w )
199200{
201   primo_state *state = space->machine->driver_data<primo_state>();
200202   if (!input_port_read(space->machine, "MEMORY_EXPANSION"))
201203   {
202      primo_port_FD = data;
204      state->port_FD = data;
203205      primo_update_memory(space->machine);
204206   }
205207}
r9675r9676
210212
211213*******************************************************************************/
212214
213static void primo_common_driver_init (void)
215static void primo_common_driver_init (primo_state *state)
214216{
215   primo_port_FD = 0x00;
217   state->port_FD = 0x00;
216218}
217219
218220DRIVER_INIT( primo32 )
219221{
220   primo_common_driver_init();
221   primo_video_memory_base = 0x6800;
222   primo_state *state = machine->driver_data<primo_state>();
223   primo_common_driver_init(state);
224   state->video_memory_base = 0x6800;
222225}
223226
224227DRIVER_INIT( primo48 )
225228{
226   primo_common_driver_init();
227   primo_video_memory_base = 0xa800;
229   primo_state *state = machine->driver_data<primo_state>();
230   primo_common_driver_init(state);
231   state->video_memory_base = 0xa800;
228232}
229233
230234DRIVER_INIT( primo64 )
231235{
232   primo_common_driver_init();
233   primo_video_memory_base = 0xe800;
236   primo_state *state = machine->driver_data<primo_state>();
237   primo_common_driver_init(state);
238   state->video_memory_base = 0xe800;
234239}
235240
236241/*******************************************************************************
r9675r9676
241246
242247static void primo_common_machine_init (running_machine *machine)
243248{
249   primo_state *state = machine->driver_data<primo_state>();
244250   if (input_port_read(machine, "MEMORY_EXPANSION"))
245      primo_port_FD = 0x00;
251      state->port_FD = 0x00;
246252   primo_update_memory(machine);
247253   machine->device("maincpu")->set_clock_scale(input_port_read(machine, "CPU_CLOCK") ? 1.5 : 1.0);
248254}
r9675r9676
268274
269275static void primo_setup_pss (running_machine *machine, UINT8* snapshot_data, UINT32 snapshot_size)
270276{
277   primo_state *state = machine->driver_data<primo_state>();
271278   int i;
272279   running_device *speaker = machine->device("speaker");
273280
r9675r9676
292299   /* IO ports */
293300
294301   // KI-1 bit 7 - NMI generator enable/disable
295   primo_nmi = (snapshot_data[30] & 0x80) ? 1 : 0;
302   state->nmi = (snapshot_data[30] & 0x80) ? 1 : 0;
296303
297304   // KI-1 bit 4 - speaker
298305   speaker_level_w(speaker, (snapshot_data[30]&0x10)>>4);
src/mess/machine/ti85.c
r9675r9676
2727   TI_86
2828};
2929
30static UINT8 ti_calculator_model;
3130
32UINT8 ti85_timer_interrupt_mask;
33static UINT8 ti85_timer_interrupt_status;
3431
35static UINT8 ti85_ON_interrupt_mask;
36static UINT8 ti85_ON_interrupt_status;
37static UINT8 ti85_ON_pressed;
3832
39static UINT8 ti8x_memory_page_1;
40static UINT8 ti8x_memory_page_2;
4133
42UINT8 ti85_LCD_memory_base;
43UINT8 ti85_LCD_contrast;
44UINT8 ti85_LCD_status;
45static UINT8 ti85_LCD_mask;
4634
47static UINT8 ti85_power_mode;
48static UINT8 ti85_keypad_mask;
4935
50static UINT8 ti85_video_buffer_width;
51static UINT8 ti85_interrupt_speed;
52static UINT8 ti85_port4_bit0;
5336
54static UINT8 ti81_port_7_data;
5537
56static UINT8 *ti8x_ram = NULL;
5738
58static UINT8 ti85_PCR;
5939
60static UINT8 ti85_red_out = 0x00;
61static UINT8 ti85_white_out = 0x00;
6240
63static UINT8 ti82_video_mode;
64static UINT8 ti82_video_x;
65static UINT8 ti82_video_y;
66static UINT8 ti82_video_dir;
67static UINT8 ti82_video_scroll;
68static UINT8 ti82_video_bit;
69static UINT8 ti82_video_col;
70static UINT8 ti8x_port2;
71static UINT8 ti83p_port4;
72UINT8 ti82_video_buffer[0x300];
7341
7442
7543static TIMER_CALLBACK(ti85_timer_callback)
7644{
45   ti85_state *state = machine->driver_data<ti85_state>();
7746   if (input_port_read(machine, "ON") & 0x01)
7847   {
79      if (ti85_ON_interrupt_mask && !ti85_ON_pressed)
48      if (state->ON_interrupt_mask && !state->ON_pressed)
8049      {
8150         cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE);
82         ti85_ON_interrupt_status = 1;
83         if (!ti85_timer_interrupt_mask) ti85_timer_interrupt_mask = 1;
51         state->ON_interrupt_status = 1;
52         if (!state->timer_interrupt_mask) state->timer_interrupt_mask = 1;
8453      }
85      ti85_ON_pressed = 1;
54      state->ON_pressed = 1;
8655      return;
8756   }
8857   else
89      ti85_ON_pressed = 0;
90   if (ti85_timer_interrupt_mask)
58      state->ON_pressed = 0;
59   if (state->timer_interrupt_mask)
9160   {
9261      cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE);
93      ti85_timer_interrupt_status = 1;
62      state->timer_interrupt_status = 1;
9463   }
9564}
9665
9766static void update_ti85_memory (running_machine *machine)
9867{
99   memory_set_bankptr(machine, "bank2",memory_region(machine, "maincpu") + 0x010000 + 0x004000*ti8x_memory_page_1);
68   ti85_state *state = machine->driver_data<ti85_state>();
69   memory_set_bankptr(machine, "bank2",memory_region(machine, "maincpu") + 0x010000 + 0x004000*state->ti8x_memory_page_1);
10070}
10171
10272static void update_ti83p_memory (running_machine *machine)
10373{
74   ti85_state *state = machine->driver_data<ti85_state>();
10475   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
10576
106   if (ti8x_memory_page_1 & 0x40)
77   if (state->ti8x_memory_page_1 & 0x40)
10778   {
108      if (ti83p_port4 & 1)
79      if (state->ti83p_port4 & 1)
10980      {
11081
111         memory_set_bankptr(machine, "bank3", ti8x_ram + 0x004000*(ti8x_memory_page_1&0x01));
82         memory_set_bankptr(machine, "bank3", state->ti8x_ram + 0x004000*(state->ti8x_memory_page_1&0x01));
11283         memory_install_write_bank(space, 0x8000, 0xbfff, 0, 0, "bank3");
11384      }
11485      else
11586      {
116         memory_set_bankptr(machine, "bank2", ti8x_ram + 0x004000*(ti8x_memory_page_1&0x01));
87         memory_set_bankptr(machine, "bank2", state->ti8x_ram + 0x004000*(state->ti8x_memory_page_1&0x01));
11788         memory_install_write_bank(space, 0x4000, 0x7fff, 0, 0, "bank2");
11889      }
11990   }
12091   else
12192   {
122      if (ti83p_port4 & 1)
93      if (state->ti83p_port4 & 1)
12394      {
124         memory_set_bankptr(machine, "bank3", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(ti8x_memory_page_1&0x1f));
95         memory_set_bankptr(machine, "bank3", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(state->ti8x_memory_page_1&0x1f));
12596         memory_unmap_write(space, 0x8000, 0xbfff, 0, 0);
12697      }
12798      else
12899      {
129         memory_set_bankptr(machine, "bank2", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(ti8x_memory_page_1&0x1f));
100         memory_set_bankptr(machine, "bank2", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(state->ti8x_memory_page_1&0x1f));
130101         memory_unmap_write(space, 0x4000, 0x7fff, 0, 0);
131102      }
132103   }
133104
134   if (ti8x_memory_page_2 & 0x40)
105   if (state->ti8x_memory_page_2 & 0x40)
135106   {
136      if (ti83p_port4 & 1)
107      if (state->ti83p_port4 & 1)
137108      {
138         memory_set_bankptr(machine, "bank4", ti8x_ram + 0x004000*(ti8x_memory_page_2&0x01));
109         memory_set_bankptr(machine, "bank4", state->ti8x_ram + 0x004000*(state->ti8x_memory_page_2&0x01));
139110         memory_install_write_bank(space, 0xc000, 0xffff, 0, 0, "bank4");
140111      }
141112      else
142113      {
143         memory_set_bankptr(machine, "bank3", ti8x_ram + 0x004000*(ti8x_memory_page_2&0x01));
114         memory_set_bankptr(machine, "bank3", state->ti8x_ram + 0x004000*(state->ti8x_memory_page_2&0x01));
144115         memory_install_write_bank(space, 0x8000, 0xbfff, 0, 0, "bank3");
145116      }
146117
147118   }
148119   else
149120   {
150      if (ti83p_port4 & 1)
121      if (state->ti83p_port4 & 1)
151122      {
152         memory_set_bankptr(machine, "bank4", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(ti8x_memory_page_2&0x1f));
123         memory_set_bankptr(machine, "bank4", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(state->ti8x_memory_page_2&0x1f));
153124         memory_unmap_write(space, 0xc000, 0xffff, 0, 0);
154125      }
155126      else
156127      {
157         memory_set_bankptr(machine, "bank3", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(ti8x_memory_page_2&0x1f));
128         memory_set_bankptr(machine, "bank3", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(state->ti8x_memory_page_2&0x1f));
158129         memory_unmap_write(space, 0x8000, 0xbfff, 0, 0);
159130      }
160131   }
r9675r9676
162133
163134static void update_ti86_memory (running_machine *machine)
164135{
136   ti85_state *state = machine->driver_data<ti85_state>();
165137   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
166138
167   if (ti8x_memory_page_1 & 0x40)
139   if (state->ti8x_memory_page_1 & 0x40)
168140   {
169      memory_set_bankptr(machine, "bank2", ti8x_ram + 0x004000*(ti8x_memory_page_1&0x07));
141      memory_set_bankptr(machine, "bank2", state->ti8x_ram + 0x004000*(state->ti8x_memory_page_1&0x07));
170142      memory_install_write_bank(space, 0x4000, 0x7fff, 0, 0, "bank2");
171143   }
172144   else
173145   {
174      memory_set_bankptr(machine, "bank2", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(ti8x_memory_page_1&0x0f));
146      memory_set_bankptr(machine, "bank2", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(state->ti8x_memory_page_1&0x0f));
175147      memory_unmap_write(space, 0x4000, 0x7fff, 0, 0);
176148   }
177149
178   if (ti8x_memory_page_2 & 0x40)
150   if (state->ti8x_memory_page_2 & 0x40)
179151   {
180      memory_set_bankptr(machine, "bank3", ti8x_ram + 0x004000*(ti8x_memory_page_2&0x07));
152      memory_set_bankptr(machine, "bank3", state->ti8x_ram + 0x004000*(state->ti8x_memory_page_2&0x07));
181153      memory_install_write_bank(space, 0x8000, 0xbfff, 0, 0, "bank3");
182154   }
183155   else
184156   {
185      memory_set_bankptr(machine, "bank3", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(ti8x_memory_page_2&0x0f));
157      memory_set_bankptr(machine, "bank3", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(state->ti8x_memory_page_2&0x0f));
186158      memory_unmap_write(space, 0x8000, 0xbfff, 0, 0);
187159   }
188160
r9675r9676
194166
195167MACHINE_START( ti81 )
196168{
169   ti85_state *state = machine->driver_data<ti85_state>();
197170   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
198171   UINT8 *mem = memory_region(machine, "maincpu");
199172
200   ti85_timer_interrupt_mask = 0;
201   ti85_timer_interrupt_status = 0;
202   ti85_ON_interrupt_mask = 0;
203   ti85_ON_interrupt_status = 0;
204   ti85_ON_pressed = 0;
205   ti85_power_mode = 0;
206   ti85_keypad_mask = 0;
207   ti8x_memory_page_1 = 0;
208   ti85_LCD_memory_base = 0;
209   ti85_LCD_status = 0;
210   ti85_LCD_mask = 0;
211   ti85_video_buffer_width = 0;
212   ti85_interrupt_speed = 0;
213   ti85_port4_bit0 = 0;
214   ti81_port_7_data = 0;
173   state->timer_interrupt_mask = 0;
174   state->timer_interrupt_status = 0;
175   state->ON_interrupt_mask = 0;
176   state->ON_interrupt_status = 0;
177   state->ON_pressed = 0;
178   state->power_mode = 0;
179   state->keypad_mask = 0;
180   state->ti8x_memory_page_1 = 0;
181   state->LCD_memory_base = 0;
182   state->LCD_status = 0;
183   state->LCD_mask = 0;
184   state->video_buffer_width = 0;
185   state->interrupt_speed = 0;
186   state->port4_bit0 = 0;
187   state->ti81_port_7_data = 0;
215188
216   if (ti_calculator_model == TI_81)
189   if (state->ti_calculator_model == TI_81)
217190      memset(mem+0x8000, 0, sizeof(unsigned char)*0x8000);
218191
219   ti_calculator_model = TI_81;
192   state->ti_calculator_model = TI_81;
220193
221194   timer_pulse(machine, ATTOTIME_IN_HZ(200), NULL, 0, ti85_timer_callback);
222195
r9675r9676
228201
229202MACHINE_START( ti82 )
230203{
204   ti85_state *state = machine->driver_data<ti85_state>();
231205   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
232206   UINT8 *mem = memory_region(machine, "maincpu");
233207
234   ti85_timer_interrupt_mask = 0;
235   ti85_timer_interrupt_status = 0;
236   ti85_ON_interrupt_mask = 0;
237   ti85_ON_interrupt_status = 0;
238   ti85_ON_pressed = 0;
239   ti8x_memory_page_1 = 0;
240   ti85_LCD_status = 0;
241   ti85_LCD_mask = 0;
242   ti85_power_mode = 0;
243   ti85_keypad_mask = 0;
244   ti85_video_buffer_width = 0;
245   ti85_interrupt_speed = 0;
246   ti85_port4_bit0 = 0;
247   ti82_video_mode = 0;
248   ti82_video_x = 0;
249   ti82_video_y = 0;
250   ti82_video_dir = 0;
251   ti82_video_scroll = 0;
252   ti82_video_bit = 0;
253   ti82_video_col = 0;
254   memset(ti82_video_buffer, 0x00, 0x300);
208   state->timer_interrupt_mask = 0;
209   state->timer_interrupt_status = 0;
210   state->ON_interrupt_mask = 0;
211   state->ON_interrupt_status = 0;
212   state->ON_pressed = 0;
213   state->ti8x_memory_page_1 = 0;
214   state->LCD_status = 0;
215   state->LCD_mask = 0;
216   state->power_mode = 0;
217   state->keypad_mask = 0;
218   state->video_buffer_width = 0;
219   state->interrupt_speed = 0;
220   state->port4_bit0 = 0;
221   state->ti82_video_mode = 0;
222   state->ti82_video_x = 0;
223   state->ti82_video_y = 0;
224   state->ti82_video_dir = 0;
225   state->ti82_video_scroll = 0;
226   state->ti82_video_bit = 0;
227   state->ti82_video_col = 0;
228   memset(state->ti82_video_buffer, 0x00, 0x300);
255229
256   if (ti_calculator_model == TI_82)
230   if (state->ti_calculator_model == TI_82)
257231      memset(mem+0x8000, 0, sizeof(unsigned char)*0x8000);
258232
259   ti_calculator_model = TI_82;
233   state->ti_calculator_model = TI_82;
260234
261235   timer_pulse(machine, ATTOTIME_IN_HZ(200), NULL, 0, ti85_timer_callback);
262236
r9675r9676
269243
270244MACHINE_START( ti85 )
271245{
246   ti85_state *state = machine->driver_data<ti85_state>();
272247   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
273248   UINT8 *mem = memory_region(machine, "maincpu");
274249
275   ti85_timer_interrupt_mask = 0;
276   ti85_timer_interrupt_status = 0;
277   ti85_ON_interrupt_mask = 0;
278   ti85_ON_interrupt_status = 0;
279   ti85_ON_pressed = 0;
280   ti8x_memory_page_1 = 0;
281   ti85_LCD_memory_base = 0;
282   ti85_LCD_status = 0;
283   ti85_LCD_mask = 0;
284   ti85_power_mode = 0;
285   ti85_keypad_mask = 0;
286   ti85_video_buffer_width = 0;
287   ti85_interrupt_speed = 0;
288   ti85_port4_bit0 = 0;
250   state->timer_interrupt_mask = 0;
251   state->timer_interrupt_status = 0;
252   state->ON_interrupt_mask = 0;
253   state->ON_interrupt_status = 0;
254   state->ON_pressed = 0;
255   state->ti8x_memory_page_1 = 0;
256   state->LCD_memory_base = 0;
257   state->LCD_status = 0;
258   state->LCD_mask = 0;
259   state->power_mode = 0;
260   state->keypad_mask = 0;
261   state->video_buffer_width = 0;
262   state->interrupt_speed = 0;
263   state->port4_bit0 = 0;
289264
290   if (ti_calculator_model == TI_85)
265   if (state->ti_calculator_model == TI_85)
291266      memset(mem+0x8000, 0, sizeof(unsigned char)*0x8000);
292267
293   ti_calculator_model = TI_85;
268   state->ti_calculator_model = TI_85;
294269
295270   timer_pulse(machine, ATTOTIME_IN_HZ(200), NULL, 0, ti85_timer_callback);
296271
r9675r9676
303278
304279MACHINE_RESET( ti85 )
305280{
306   ti85_red_out = 0x00;
307   ti85_white_out = 0x00;
308   ti85_PCR = 0xc0;
281   ti85_state *state = machine->driver_data<ti85_state>();
282   state->red_out = 0x00;
283   state->white_out = 0x00;
284   state->PCR = 0xc0;
309285}
310286
311287
312288MACHINE_START( ti83p )
313289{
290   ti85_state *state = machine->driver_data<ti85_state>();
314291   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
315292   UINT8 *mem = memory_region(machine, "maincpu");
316293
317   ti85_timer_interrupt_mask = 0;
318   ti85_timer_interrupt_status = 0;
319   ti85_ON_interrupt_mask = 0;
320   ti85_ON_interrupt_status = 0;
321   ti85_ON_pressed = 0;
322   ti8x_memory_page_1 = 0;
323   ti8x_memory_page_2 = 0;
324   ti85_LCD_memory_base = 0;
325   ti85_LCD_status = 0;
326   ti85_LCD_mask = 0;
327   ti85_power_mode = 0;
328   ti85_keypad_mask = 0;
329   ti85_video_buffer_width = 0;
330   ti85_interrupt_speed = 0;
331   ti85_port4_bit0 = 0;
332   ti82_video_mode = 0;
333   ti82_video_x = 0;
334   ti82_video_y = 0;
335   ti82_video_dir = 0;
336   ti82_video_scroll = 0;
337   ti82_video_bit = 0;
338   ti82_video_col = 0;
339   memset(ti82_video_buffer, 0x00, 0x300);
294   state->timer_interrupt_mask = 0;
295   state->timer_interrupt_status = 0;
296   state->ON_interrupt_mask = 0;
297   state->ON_interrupt_status = 0;
298   state->ON_pressed = 0;
299   state->ti8x_memory_page_1 = 0;
300   state->ti8x_memory_page_2 = 0;
301   state->LCD_memory_base = 0;
302   state->LCD_status = 0;
303   state->LCD_mask = 0;
304   state->power_mode = 0;
305   state->keypad_mask = 0;
306   state->video_buffer_width = 0;
307   state->interrupt_speed = 0;
308   state->port4_bit0 = 0;
309   state->ti82_video_mode = 0;
310   state->ti82_video_x = 0;
311   state->ti82_video_y = 0;
312   state->ti82_video_dir = 0;
313   state->ti82_video_scroll = 0;
314   state->ti82_video_bit = 0;
315   state->ti82_video_col = 0;
316   memset(state->ti82_video_buffer, 0x00, 0x300);
340317
341   ti8x_ram = auto_alloc_array(machine, UINT8, 32*1024);
318   state->ti8x_ram = auto_alloc_array(machine, UINT8, 32*1024);
342319   {
343320      memory_unmap_write(space, 0x0000, 0x3fff, 0, 0);
344321      memory_unmap_write(space, 0x4000, 0x7fff, 0, 0);
r9675r9676
347324      memory_set_bankptr(machine, "bank1", mem + 0x010000);
348325      memory_set_bankptr(machine, "bank2", mem + 0x010000);
349326      memory_set_bankptr(machine, "bank3", mem + 0x010000);
350      memory_set_bankptr(machine, "bank4", ti8x_ram);
327      memory_set_bankptr(machine, "bank4", state->ti8x_ram);
351328
352      if (ti_calculator_model == TI_83p)
353         memset(ti8x_ram, 0, sizeof(unsigned char)*32*1024);
329      if (state->ti_calculator_model == TI_83p)
330         memset(state->ti8x_ram, 0, sizeof(unsigned char)*32*1024);
354331
355332//      memset(mem + 0x83000, 0xff, 0x1000);
356333
357      ti_calculator_model = TI_83p;
334      state->ti_calculator_model = TI_83p;
358335
359336      timer_pulse(machine, ATTOTIME_IN_HZ(200), NULL, 0, ti85_timer_callback);
360337   }
r9675r9676
363340
364341MACHINE_START( ti86 )
365342{
343   ti85_state *state = machine->driver_data<ti85_state>();
366344   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
367345   UINT8 *mem = memory_region(machine, "maincpu");
368346
369   ti85_timer_interrupt_mask = 0;
370   ti85_timer_interrupt_status = 0;
371   ti85_ON_interrupt_mask = 0;
372   ti85_ON_interrupt_status = 0;
373   ti85_ON_pressed = 0;
374   ti8x_memory_page_1 = 0;
375   ti8x_memory_page_2 = 0;
376   ti85_LCD_memory_base = 0;
377   ti85_LCD_status = 0;
378   ti85_LCD_mask = 0;
379   ti85_power_mode = 0;
380   ti85_keypad_mask = 0;
381   ti85_video_buffer_width = 0;
382   ti85_interrupt_speed = 0;
383   ti85_port4_bit0 = 0;
347   state->timer_interrupt_mask = 0;
348   state->timer_interrupt_status = 0;
349   state->ON_interrupt_mask = 0;
350   state->ON_interrupt_status = 0;
351   state->ON_pressed = 0;
352   state->ti8x_memory_page_1 = 0;
353   state->ti8x_memory_page_2 = 0;
354   state->LCD_memory_base = 0;
355   state->LCD_status = 0;
356   state->LCD_mask = 0;
357   state->power_mode = 0;
358   state->keypad_mask = 0;
359   state->video_buffer_width = 0;
360   state->interrupt_speed = 0;
361   state->port4_bit0 = 0;
384362
385   ti8x_ram = auto_alloc_array(machine, UINT8, 128*1024);
363   state->ti8x_ram = auto_alloc_array(machine, UINT8, 128*1024);
386364   {
387365      memory_unmap_write(space, 0x0000, 0x3fff, 0, 0);
388366
389367      memory_set_bankptr(machine, "bank1", mem + 0x010000);
390368      memory_set_bankptr(machine, "bank2", mem + 0x014000);
391369
392      memory_set_bankptr(machine, "bank4", ti8x_ram);
370      memory_set_bankptr(machine, "bank4", state->ti8x_ram);
393371
394      if (ti_calculator_model == TI_86)
395         memset(ti8x_ram, 0, sizeof(unsigned char)*128*1024);
372      if (state->ti_calculator_model == TI_86)
373         memset(state->ti8x_ram, 0, sizeof(unsigned char)*128*1024);
396374
397      ti_calculator_model = TI_86;
375      state->ti_calculator_model = TI_86;
398376
399377      timer_pulse(machine, ATTOTIME_IN_HZ(200), NULL, 0, ti85_timer_callback);
400378   }
r9675r9676
410388
411389READ8_HANDLER ( ti8x_keypad_r )
412390{
391   ti85_state *state = space->machine->driver_data<ti85_state>();
413392   int data = 0xff;
414393   int port;
415394   int bit;
416395   static const char *const bitnames[] = { "BIT0", "BIT1", "BIT2", "BIT3", "BIT4", "BIT5", "BIT6", "BIT7" };
417396
418   if (ti85_keypad_mask == 0x7f) return data;
397   if (state->keypad_mask == 0x7f) return data;
419398
420399   for (bit = 0; bit < 7; bit++)
421400   {
422      if (~ti85_keypad_mask&(0x01<<bit))
401      if (~state->keypad_mask&(0x01<<bit))
423402      {
424403         for (port = 0; port < 8; port++)
425404         {
r9675r9676
437416
438417 READ8_HANDLER ( ti85_port_0003_r )
439418{
419   ti85_state *state = space->machine->driver_data<ti85_state>();
440420   int data = 0;
441421
442   if (ti85_LCD_status)
443      data |= ti85_LCD_mask;
444   if (ti85_ON_interrupt_status)
422   if (state->LCD_status)
423      data |= state->LCD_mask;
424   if (state->ON_interrupt_status)
445425      data |= 0x01;
446   if (ti85_timer_interrupt_status)
426   if (state->timer_interrupt_status)
447427      data |= 0x04;
448   if (!ti85_ON_pressed)
428   if (!state->ON_pressed)
449429      data |= 0x08;
450   ti85_ON_interrupt_status = 0;
451   ti85_timer_interrupt_status = 0;
430   state->ON_interrupt_status = 0;
431   state->timer_interrupt_status = 0;
452432   return data;
453433}
454434
r9675r9676
459439
460440 READ8_HANDLER ( ti85_port_0005_r )
461441{
462   return ti8x_memory_page_1;
442   ti85_state *state = space->machine->driver_data<ti85_state>();
443   return state->ti8x_memory_page_1;
463444}
464445
465446READ8_HANDLER ( ti85_port_0006_r )
466447{
467   return ti85_power_mode;
448   ti85_state *state = space->machine->driver_data<ti85_state>();
449   return state->power_mode;
468450}
469451
470452READ8_HANDLER ( ti85_port_0007_r )
471453{
454   ti85_state *state = space->machine->driver_data<ti85_state>();
472455   running_device *ti85serial = space->machine->device("ti85serial");
473456
474457   ti85_update_serial(ti85serial);
475   return (ti85_white_out<<3)
476      | (ti85_red_out<<2)
477      | ((ti85serial_white_in(ti85serial,0)&(1-ti85_white_out))<<1)
478      | (ti85serial_red_in(ti85serial,0)&(1-ti85_red_out))
479      | ti85_PCR;
458   return (state->white_out<<3)
459      | (state->red_out<<2)
460      | ((ti85serial_white_in(ti85serial,0)&(1-state->white_out))<<1)
461      | (ti85serial_red_in(ti85serial,0)&(1-state->red_out))
462      | state->PCR;
480463}
481464
482465READ8_HANDLER ( ti82_port_0000_r )
r9675r9676
486469
487470 READ8_HANDLER ( ti82_port_0002_r )
488471{
489   return ti8x_port2;
472   ti85_state *state = space->machine->driver_data<ti85_state>();
473   return state->ti8x_port2;
490474}
491475
492476 READ8_HANDLER ( ti82_port_0010_r )
r9675r9676
496480
497481 READ8_HANDLER ( ti82_port_0011_r )
498482{
483   ti85_state *state = space->machine->driver_data<ti85_state>();
499484    UINT8* ti82_video;
500485   UINT8 ti82_port11;
501486
502   if(ti82_video_dir == 4)
503      ++ti82_video_y;
504   if(ti82_video_dir == 5)
505      --ti82_video_y;
506   if(ti82_video_dir == 6)
507      ++ti82_video_x;
508   if(ti82_video_dir == 7)
509      --ti82_video_x;
487   if(state->ti82_video_dir == 4)
488      ++state->ti82_video_y;
489   if(state->ti82_video_dir == 5)
490      --state->ti82_video_y;
491   if(state->ti82_video_dir == 6)
492      ++state->ti82_video_x;
493   if(state->ti82_video_dir == 7)
494      --state->ti82_video_x;
510495
511   if(ti82_video_mode)
512      ti82_port11 = ti82_video_buffer[(12*ti82_video_y)+ti82_video_x];
496   if(state->ti82_video_mode)
497      ti82_port11 = state->ti82_video_buffer[(12*state->ti82_video_y)+state->ti82_video_x];
513498   else
514499   {
515      ti82_video_col = ti82_video_x * 6;
516      ti82_video_bit = ti82_video_col & 7;
517      ti82_video = &ti82_video_buffer[(ti82_video_y*12)+(ti82_video_col>>3)];
518      ti82_port11 = ((((*ti82_video)<<8)+ti82_video[1])>>(10-ti82_video_bit));
500      state->ti82_video_col = state->ti82_video_x * 6;
501      state->ti82_video_bit = state->ti82_video_col & 7;
502      ti82_video = &state->ti82_video_buffer[(state->ti82_video_y*12)+(state->ti82_video_col>>3)];
503      ti82_port11 = ((((*ti82_video)<<8)+ti82_video[1])>>(10-state->ti82_video_bit));
519504   }
520505
521   if(ti82_video_dir == 4)
522      ti82_video_y-=2;
523   if(ti82_video_dir == 5)
524      ti82_video_y+=2;
525   if(ti82_video_dir == 6)
526      ti82_video_x-=2;
527   if(ti82_video_dir == 7)
528      ti82_video_x+=2;
506   if(state->ti82_video_dir == 4)
507      state->ti82_video_y-=2;
508   if(state->ti82_video_dir == 5)
509      state->ti82_video_y+=2;
510   if(state->ti82_video_dir == 6)
511      state->ti82_video_x-=2;
512   if(state->ti82_video_dir == 7)
513      state->ti82_video_x+=2;
529514
530   ti82_video_x &= 15;
531   ti82_video_y &= 63;
515   state->ti82_video_x &= 15;
516   state->ti82_video_y &= 63;
532517
533518   return ti82_port11;
534519}
535520
536521READ8_HANDLER ( ti86_port_0005_r )
537522{
538   return ti8x_memory_page_1;
523   ti85_state *state = space->machine->driver_data<ti85_state>();
524   return state->ti8x_memory_page_1;
539525}
540526
541527 READ8_HANDLER ( ti86_port_0006_r )
542528{
543   return ti8x_memory_page_2;
529   ti85_state *state = space->machine->driver_data<ti85_state>();
530   return state->ti8x_memory_page_2;
544531}
545532
546533READ8_HANDLER ( ti83_port_0000_r )
547534{
548   return ((ti8x_memory_page_1 & 0x08) << 1) | 0x0C;
535   ti85_state *state = space->machine->driver_data<ti85_state>();
536   return ((state->ti8x_memory_page_1 & 0x08) << 1) | 0x0C;
549537}
550538
551539 READ8_HANDLER ( ti83_port_0002_r )
552540{
553   return ti8x_port2;
541   ti85_state *state = space->machine->driver_data<ti85_state>();
542   return state->ti8x_port2;
554543}
555544
556545 READ8_HANDLER ( ti83_port_0003_r )
557546{
547   ti85_state *state = space->machine->driver_data<ti85_state>();
558548   int data = 0;
559549
560   if (ti85_LCD_status)
561      data |= ti85_LCD_mask;
562   if (ti85_ON_interrupt_status)
550   if (state->LCD_status)
551      data |= state->LCD_mask;
552   if (state->ON_interrupt_status)
563553      data |= 0x01;
564   if (!ti85_ON_pressed)
554   if (!state->ON_pressed)
565555      data |= 0x08;
566   ti85_ON_interrupt_status = 0;
567   ti85_timer_interrupt_status = 0;
556   state->ON_interrupt_status = 0;
557   state->timer_interrupt_status = 0;
568558   return data;
569559}
570560
571561 READ8_HANDLER ( ti83p_port_0002_r )
572562{
573   return ti8x_port2|3;
563   ti85_state *state = space->machine->driver_data<ti85_state>();
564   return state->ti8x_port2|3;
574565}
575566
576567WRITE8_HANDLER ( ti81_port_0007_w )
577568{
578   ti81_port_7_data = data;
569   ti85_state *state = space->machine->driver_data<ti85_state>();
570   state->ti81_port_7_data = data;
579571}
580572
581573WRITE8_HANDLER ( ti85_port_0000_w )
582574{
583   ti85_LCD_memory_base = data;
575   ti85_state *state = space->machine->driver_data<ti85_state>();
576   state->LCD_memory_base = data;
584577}
585578
586579WRITE8_HANDLER ( ti8x_keypad_w )
587580{
588   ti85_keypad_mask = data&0x7f;
581   ti85_state *state = space->machine->driver_data<ti85_state>();
582   state->keypad_mask = data&0x7f;
589583}
590584
591585WRITE8_HANDLER ( ti85_port_0002_w )
592586{
593   ti85_LCD_contrast = data&0x1f;
587   ti85_state *state = space->machine->driver_data<ti85_state>();
588   state->LCD_contrast = data&0x1f;
594589}
595590
596591WRITE8_HANDLER ( ti85_port_0003_w )
597592{
598   if (ti85_LCD_status && !(data&0x08))   ti85_timer_interrupt_mask = 0;
599   ti85_ON_interrupt_mask = data&0x01;
600//  ti85_timer_interrupt_mask = data&0x04;
601   ti85_LCD_mask = data&0x02;
602   ti85_LCD_status = data&0x08;
593   ti85_state *state = space->machine->driver_data<ti85_state>();
594   if (state->LCD_status && !(data&0x08))   state->timer_interrupt_mask = 0;
595   state->ON_interrupt_mask = data&0x01;
596//  state->timer_interrupt_mask = data&0x04;
597   state->LCD_mask = data&0x02;
598   state->LCD_status = data&0x08;
603599}
604600
605601WRITE8_HANDLER ( ti85_port_0004_w )
606602{
607   ti85_video_buffer_width = (data>>3)&0x03;
608   ti85_interrupt_speed = (data>>1)&0x03;
609   ti85_port4_bit0 = data&0x01;
603   ti85_state *state = space->machine->driver_data<ti85_state>();
604   state->video_buffer_width = (data>>3)&0x03;
605   state->interrupt_speed = (data>>1)&0x03;
606   state->port4_bit0 = data&0x01;
610607}
611608
612609WRITE8_HANDLER ( ti85_port_0005_w )
613610{
614   ti8x_memory_page_1 = data;
611   ti85_state *state = space->machine->driver_data<ti85_state>();
612   state->ti8x_memory_page_1 = data;
615613   update_ti85_memory(space->machine);
616614}
617615
618616WRITE8_HANDLER ( ti85_port_0006_w )
619617{
620   ti85_power_mode = data;
618   ti85_state *state = space->machine->driver_data<ti85_state>();
619   state->power_mode = data;
621620}
622621
623622WRITE8_HANDLER ( ti85_port_0007_w )
624623{
624   ti85_state *state = space->machine->driver_data<ti85_state>();
625625   running_device *speaker = space->machine->device("speaker");
626626   running_device *ti85serial = space->machine->device("ti85serial");
627627
628628   speaker_level_w(speaker, ( (data>>2)|(data>>3) ) & 0x01);
629   ti85_red_out=(data>>2)&0x01;
630   ti85_white_out=(data>>3)&0x01;
631   ti85serial_red_out( ti85serial, 0, ti85_red_out );
632   ti85serial_white_out( ti85serial, 0, ti85_white_out );
629   state->red_out=(data>>2)&0x01;
630   state->white_out=(data>>3)&0x01;
631   ti85serial_red_out( ti85serial, 0, state->red_out );
632   ti85serial_white_out( ti85serial, 0, state->white_out );
633633   ti85_update_serial(ti85serial);
634   ti85_PCR = data&0xf0;
634   state->PCR = data&0xf0;
635635}
636636
637637WRITE8_HANDLER ( ti86_port_0005_w )
638638{
639   ti8x_memory_page_1 = data&((data&0x40)?0x47:0x4f);
639   ti85_state *state = space->machine->driver_data<ti85_state>();
640   state->ti8x_memory_page_1 = data&((data&0x40)?0x47:0x4f);
640641   update_ti86_memory(space->machine);
641642}
642643
643644WRITE8_HANDLER ( ti86_port_0006_w )
644645{
645   ti8x_memory_page_2 = data&((data&0x40)?0x47:0x4f);
646   ti85_state *state = space->machine->driver_data<ti85_state>();
647   state->ti8x_memory_page_2 = data&((data&0x40)?0x47:0x4f);
646648   update_ti86_memory(space->machine);
647649}
648650
r9675r9676
653655
654656WRITE8_HANDLER ( ti82_port_0002_w )
655657{
656   ti8x_memory_page_1 = (data & 0x07);
658   ti85_state *state = space->machine->driver_data<ti85_state>();
659   state->ti8x_memory_page_1 = (data & 0x07);
657660   update_ti85_memory(space->machine);
658   ti8x_port2 = data;
661   state->ti8x_port2 = data;
659662}
660663
661664WRITE8_HANDLER ( ti82_port_0010_w )
662665{
666   ti85_state *state = space->machine->driver_data<ti85_state>();
663667   if (data == 0x00 || data == 0x01)
664      ti82_video_mode = data;
668      state->ti82_video_mode = data;
665669   if (data >= 0x04 && data <= 0x07)
666      ti82_video_dir = data;
670      state->ti82_video_dir = data;
667671   if (data >= 0x20 && data <= 0x30)
668      ti82_video_x = data - 0x20;
672      state->ti82_video_x = data - 0x20;
669673   if (data >= 0x40 && data <= 0x7F)
670      ti82_video_scroll = data - 0x40;
674      state->ti82_video_scroll = data - 0x40;
671675   if (data >= 0x80 && data <= 0xBF)
672      ti82_video_y = data - 0x80;
676      state->ti82_video_y = data - 0x80;
673677   if (data >= 0xD8)
674      ti85_LCD_contrast = data - 0xD8;
678      state->LCD_contrast = data - 0xD8;
675679}
676680
677681WRITE8_HANDLER ( ti82_port_0011_w )
678682{
683   ti85_state *state = space->machine->driver_data<ti85_state>();
679684   UINT8* ti82_video;
680685
681   if(ti82_video_mode)
682      ti82_video_buffer[(12*ti82_video_y)+ti82_video_x] = data;
686   if(state->ti82_video_mode)
687      state->ti82_video_buffer[(12*state->ti82_video_y)+state->ti82_video_x] = data;
683688   else
684689   {
685690      data = data<<0x02;
686      ti82_video_col = ti82_video_x * 6;
687      ti82_video_bit = ti82_video_col & 0x07;
688      ti82_video = &ti82_video_buffer[(ti82_video_y*12)+(ti82_video_col>>3)];
689      *ti82_video = (*ti82_video & ~(0xFC>>ti82_video_bit)) | (data>>ti82_video_bit);
690      if(ti82_video_bit>0x02)
691         ti82_video[1] = (ti82_video[1] & ~(0xFC<<(8-ti82_video_bit))) | (data<<(8-ti82_video_bit));
691      state->ti82_video_col = state->ti82_video_x * 6;
692      state->ti82_video_bit = state->ti82_video_col & 0x07;
693      ti82_video = &state->ti82_video_buffer[(state->ti82_video_y*12)+(state->ti82_video_col>>3)];
694      *ti82_video = (*ti82_video & ~(0xFC>>state->ti82_video_bit)) | (data>>state->ti82_video_bit);
695      if(state->ti82_video_bit>0x02)
696         ti82_video[1] = (ti82_video[1] & ~(0xFC<<(8-state->ti82_video_bit))) | (data<<(8-state->ti82_video_bit));
692697   }
693698
694   if(ti82_video_dir == 0x04)
695      --ti82_video_y;
696   if(ti82_video_dir == 0x05)
697      ++ti82_video_y;
698   if(ti82_video_dir == 0x06)
699      --ti82_video_x;
700   if(ti82_video_dir == 0x07)
701      ++ti82_video_x;
699   if(state->ti82_video_dir == 0x04)
700      --state->ti82_video_y;
701   if(state->ti82_video_dir == 0x05)
702      ++state->ti82_video_y;
703   if(state->ti82_video_dir == 0x06)
704      --state->ti82_video_x;
705   if(state->ti82_video_dir == 0x07)
706      ++state->ti82_video_x;
702707
703   ti82_video_x &= 15;
704   ti82_video_y &= 63;
708   state->ti82_video_x &= 15;
709   state->ti82_video_y &= 63;
705710}
706711
707712WRITE8_HANDLER ( ti83_port_0000_w )
708713{
709   ti8x_memory_page_1 = (ti8x_memory_page_1 & 7) | ((data & 16) >> 1);
714   ti85_state *state = space->machine->driver_data<ti85_state>();
715   state->ti8x_memory_page_1 = (state->ti8x_memory_page_1 & 7) | ((data & 16) >> 1);
710716   update_ti85_memory(space->machine);
711717}
712718
713719WRITE8_HANDLER ( ti83_port_0002_w )
714720{
715   ti8x_memory_page_1 = (ti8x_memory_page_1 & 8) | (data & 7);
721   ti85_state *state = space->machine->driver_data<ti85_state>();
722   state->ti8x_memory_page_1 = (state->ti8x_memory_page_1 & 8) | (data & 7);
716723   update_ti85_memory(space->machine);
717   ti8x_port2 = data;
724   state->ti8x_port2 = data;
718725}
719726
720727WRITE8_HANDLER ( ti83_port_0003_w )
721728{
722      if (ti85_LCD_status && !(data&0x08))   ti85_timer_interrupt_mask = 0;
723      ti85_ON_interrupt_mask = data&0x01;
724      //ti85_timer_interrupt_mask = data&0x04;
725      ti85_LCD_mask = data&0x02;
726      ti85_LCD_status = data&0x08;
729   ti85_state *state = space->machine->driver_data<ti85_state>();
730      if (state->LCD_status && !(data&0x08))   state->timer_interrupt_mask = 0;
731      state->ON_interrupt_mask = data&0x01;
732      //state->timer_interrupt_mask = data&0x04;
733      state->LCD_mask = data&0x02;
734      state->LCD_status = data&0x08;
727735}
728736
729737WRITE8_HANDLER ( ti83p_port_0002_w )
730738{
731   ti8x_port2 = data;
739   ti85_state *state = space->machine->driver_data<ti85_state>();
740   state->ti8x_port2 = data;
732741}
733742
734743WRITE8_HANDLER ( ti83p_port_0003_w )
735744{
736   ti85_LCD_mask = (data&0x08) >> 2;
737   ti85_ON_interrupt_mask = data & 0x01;
745   ti85_state *state = space->machine->driver_data<ti85_state>();
746   state->LCD_mask = (data&0x08) >> 2;
747   state->ON_interrupt_mask = data & 0x01;
738748}
739749
740750WRITE8_HANDLER ( ti83p_port_0004_w )
741751{
742   if ((data & 1) && !(ti83p_port4 & 1))
752   ti85_state *state = space->machine->driver_data<ti85_state>();
753   if ((data & 1) && !(state->ti83p_port4 & 1))
743754   {
744      ti8x_memory_page_1 = 0x1f;
745      ti8x_memory_page_2 = 0x1f;
755      state->ti8x_memory_page_1 = 0x1f;
756      state->ti8x_memory_page_2 = 0x1f;
746757   }
747   else if (!(data & 1) && (ti83p_port4 & 1))
758   else if (!(data & 1) && (state->ti83p_port4 & 1))
748759   {
749      ti8x_memory_page_1 = 0x1f;
750      ti8x_memory_page_2 = 0x40;
760      state->ti8x_memory_page_1 = 0x1f;
761      state->ti8x_memory_page_2 = 0x40;
751762   }
752763   update_ti83p_memory(space->machine);
753   ti83p_port4 = data;
764   state->ti83p_port4 = data;
754765}
755766
756767WRITE8_HANDLER ( ti83p_port_0006_w )
757768{
758   ti8x_memory_page_1 = data & ((data&0x40) ? 0x41 : 0x5f);
769   ti85_state *state = space->machine->driver_data<ti85_state>();
770   state->ti8x_memory_page_1 = data & ((data&0x40) ? 0x41 : 0x5f);
759771   update_ti83p_memory(space->machine);
760772}
761773
762774WRITE8_HANDLER ( ti83p_port_0007_w )
763775{
764   ti8x_memory_page_2 = data & ((data&0x40) ? 0x41 : 0x5f);
776   ti85_state *state = space->machine->driver_data<ti85_state>();
777   state->ti8x_memory_page_2 = data & ((data&0x40) ? 0x41 : 0x5f);
765778   update_ti83p_memory(space->machine);
766779}
767780
768781WRITE8_HANDLER ( ti83p_port_0010_w )
769782{
783   ti85_state *state = space->machine->driver_data<ti85_state>();
770784   if (data == 0x00 || data == 0x01)
771      ti82_video_mode = data;
785      state->ti82_video_mode = data;
772786   if (data == 0x02 || data == 0x03)
773      ti85_LCD_status = data - 0x02;
787      state->LCD_status = data - 0x02;
774788   if (data >= 0x04 && data <= 0x07)
775      ti82_video_dir = data;
789      state->ti82_video_dir = data;
776790   if (data >= 0x20 && data <= 0x30)
777      ti82_video_x = data - 0x20;
791      state->ti82_video_x = data - 0x20;
778792   if (data >= 0x40 && data <= 0x7F)
779      ti82_video_scroll = data - 0x40;
793      state->ti82_video_scroll = data - 0x40;
780794   if (data >= 0x80 && data <= 0xBF)
781      ti82_video_y = data - 0x80;
795      state->ti82_video_y = data - 0x80;
782796   if (data >= 0xc8)
783      ti85_LCD_contrast = data - 0xc8;
797      state->LCD_contrast = data - 0xc8;
784798
785799}
786800
787801/* NVRAM functions */
788802NVRAM_HANDLER( ti83p )
789803{
804   ti85_state *state = machine->driver_data<ti85_state>();
790805   if (read_or_write)
791806   {
792      mame_fwrite(file, ti8x_ram, sizeof(unsigned char)*32*1024);
807      mame_fwrite(file, state->ti8x_ram, sizeof(unsigned char)*32*1024);
793808   }
794809   else
795810   {
796811         if (file)
797812         {
798            mame_fread(file, ti8x_ram, sizeof(unsigned char)*32*1024);
813            mame_fread(file, state->ti8x_ram, sizeof(unsigned char)*32*1024);
799814            cpu_set_reg(machine->device("maincpu"), Z80_PC,0x0c59);
800815         }
801816         else
802            memset(ti8x_ram, 0, sizeof(unsigned char)*32*1024);
817            memset(state->ti8x_ram, 0, sizeof(unsigned char)*32*1024);
803818   }
804819}
805820
806821NVRAM_HANDLER( ti86 )
807822{
823   ti85_state *state = machine->driver_data<ti85_state>();
808824   if (read_or_write)
809825   {
810      mame_fwrite(file, ti8x_ram, sizeof(unsigned char)*128*1024);
826      mame_fwrite(file, state->ti8x_ram, sizeof(unsigned char)*128*1024);
811827   }
812828   else
813829   {
814830         if (file)
815831         {
816            mame_fread(file, ti8x_ram, sizeof(unsigned char)*128*1024);
832            mame_fread(file, state->ti8x_ram, sizeof(unsigned char)*128*1024);
817833            cpu_set_reg(machine->device("maincpu"), Z80_PC,0x0c59);
818834         }
819835         else
820            memset(ti8x_ram, 0, sizeof(unsigned char)*128*1024);
836            memset(state->ti8x_ram, 0, sizeof(unsigned char)*128*1024);
821837   }
822838}
823839
r9675r9676
882898
883899static void ti85_setup_snapshot (running_machine *machine, UINT8 * data)
884900{
901   ti85_state *state = machine->driver_data<ti85_state>();
885902   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
886903   int i;
887904   unsigned char lo,hi;
r9675r9676
893910   for (i = 0; i < 0x8000; i++)
894911      space->write_byte(i + 0x8000, data[i+0x94]);
895912
896   ti85_keypad_mask = hdw[0x00]&0x7f;
913   state->keypad_mask = hdw[0x00]&0x7f;
897914
898   ti8x_memory_page_1 = hdw[0x08]&0xff;
915   state->ti8x_memory_page_1 = hdw[0x08]&0xff;
899916   update_ti85_memory(machine);
900917
901   ti85_power_mode = hdw[0x14]&0xff;
918   state->power_mode = hdw[0x14]&0xff;
902919
903920   lo = hdw[0x28] & 0x0ff;
904921   hi = hdw[0x29] & 0x0ff;
905   ti85_LCD_memory_base = (((hi << 8) | lo)-0xc000)>>8;
922   state->LCD_memory_base = (((hi << 8) | lo)-0xc000)>>8;
906923
907   ti85_LCD_status = hdw[0x2c]&0xff ? 0 : 0x08;
908   if (ti85_LCD_status) ti85_LCD_mask = 0x02;
924   state->LCD_status = hdw[0x2c]&0xff ? 0 : 0x08;
925   if (state->LCD_status) state->LCD_mask = 0x02;
909926
910   ti85_LCD_contrast = hdw[0x30]&0xff;
927   state->LCD_contrast = hdw[0x30]&0xff;
911928
912   ti85_timer_interrupt_mask = !hdw[0x38];
913   ti85_timer_interrupt_status = 0;
929   state->timer_interrupt_mask = !hdw[0x38];
930   state->timer_interrupt_status = 0;
914931
915   ti85_ON_interrupt_mask = !ti85_LCD_status && ti85_timer_interrupt_status;
916   ti85_ON_interrupt_status = 0;
917   ti85_ON_pressed = 0;
932   state->ON_interrupt_mask = !state->LCD_status && state->timer_interrupt_status;
933   state->ON_interrupt_status = 0;
934   state->ON_pressed = 0;
918935
919   ti85_video_buffer_width = 0x02;
920   ti85_interrupt_speed = 0x03;
936   state->video_buffer_width = 0x02;
937   state->interrupt_speed = 0x03;
921938}
922939
923940static void ti86_setup_snapshot (running_machine *machine, UINT8 * data)
924941{
942   ti85_state *state = machine->driver_data<ti85_state>();
925943   unsigned char lo,hi;
926944   unsigned char * hdw = data + 0x20000 + 0x94;
927945
928946   ti8x_snapshot_setup_registers (machine, data);
929947
930948   /* Memory dump */
931   memcpy(ti8x_ram, data+0x94, 0x20000);
949   memcpy(state->ti8x_ram, data+0x94, 0x20000);
932950
933   ti85_keypad_mask = hdw[0x00]&0x7f;
951   state->keypad_mask = hdw[0x00]&0x7f;
934952
935   ti8x_memory_page_1 = hdw[0x04]&0xff ? 0x40 : 0x00;
936   ti8x_memory_page_1 |= hdw[0x08]&0x0f;
953   state->ti8x_memory_page_1 = hdw[0x04]&0xff ? 0x40 : 0x00;
954   state->ti8x_memory_page_1 |= hdw[0x08]&0x0f;
937955
938   ti8x_memory_page_2 = hdw[0x0c]&0xff ? 0x40 : 0x00;
939   ti8x_memory_page_2 |= hdw[0x10]&0x0f;
956   state->ti8x_memory_page_2 = hdw[0x0c]&0xff ? 0x40 : 0x00;
957   state->ti8x_memory_page_2 |= hdw[0x10]&0x0f;
940958
941959   update_ti86_memory(machine);
942960
943961   lo = hdw[0x2c] & 0x0ff;
944962   hi = hdw[0x2d] & 0x0ff;
945   ti85_LCD_memory_base = (((hi << 8) | lo)-0xc000)>>8;
963   state->LCD_memory_base = (((hi << 8) | lo)-0xc000)>>8;
946964
947   ti85_LCD_status = hdw[0x30]&0xff ? 0 : 0x08;
948   if (ti85_LCD_status) ti85_LCD_mask = 0x02;
965   state->LCD_status = hdw[0x30]&0xff ? 0 : 0x08;
966   if (state->LCD_status) state->LCD_mask = 0x02;
949967
950   ti85_LCD_contrast = hdw[0x34]&0xff;
968   state->LCD_contrast = hdw[0x34]&0xff;
951969
952   ti85_timer_interrupt_mask = !hdw[0x3c];
953   ti85_timer_interrupt_status = 0;
970   state->timer_interrupt_mask = !hdw[0x3c];
971   state->timer_interrupt_status = 0;
954972
955   ti85_ON_interrupt_mask = !ti85_LCD_status && ti85_timer_interrupt_status;
956   ti85_ON_interrupt_status = 0;
957   ti85_ON_pressed = 0;
973   state->ON_interrupt_mask = !state->LCD_status && state->timer_interrupt_status;
974   state->ON_interrupt_status = 0;
975   state->ON_pressed = 0;
958976
959   ti85_video_buffer_width = 0x02;
960   ti85_interrupt_speed = 0x03;
977   state->video_buffer_width = 0x02;
978   state->interrupt_speed = 0x03;
961979}
962980
963981SNAPSHOT_LOAD( ti8x )
964982{
983   ti85_state *state = image.device().machine->driver_data<ti85_state>();
965984   int expected_snapshot_size = 0;
966985   UINT8 *ti8x_snapshot_data;
967986
968   switch (ti_calculator_model)
987   switch (state->ti_calculator_model)
969988   {
970989      case TI_85: expected_snapshot_size = TI85_SNAPSHOT_SIZE; break;
971990      case TI_86: expected_snapshot_size = TI86_SNAPSHOT_SIZE; break;
r9675r9676
9841003
9851004   image.fread( ti8x_snapshot_data, snapshot_size);
9861005
987   switch (ti_calculator_model)
1006   switch (state->ti_calculator_model)
9881007   {
9891008      case TI_85: ti85_setup_snapshot(image.device().machine, ti8x_snapshot_data); break;
9901009      case TI_86: ti86_setup_snapshot(image.device().machine, ti8x_snapshot_data); break;
src/mess/machine/vectrex.c
r9675r9676
8484      return IMAGE_INIT_FAIL;
8585   }
8686
87   /* If VIA T2 starts, reset state->refresh timer.
87   /* If VIA T2 starts, reset refresh timer.
8888       This is the best strategy for most games. */
8989   state->reset_refresh = 1;
9090
src/mess/machine/special.c
r9675r9676
1919#include "devices/messram.h"
2020#include "devices/flopdrv.h"
2121
22static UINT8 specimx_color;
23UINT8 *specimx_colorram;
24static running_device *specimx_audio;
2522
26static int specialist_8255_porta;
27static int specialist_8255_portb;
28static int specialist_8255_portc;
2923
3024/* Driver initialization */
3125DRIVER_INIT(special)
r9675r9676
5246
5347static READ8_DEVICE_HANDLER (specialist_8255_portb_r )
5448{
49   special_state *state = device->machine->driver_data<special_state>();
5550
5651   int dat = 0;
5752   double level;
5853
59   if ((specialist_8255_porta & 0x01)==0) dat ^= (input_port_read(device->machine, "LINE0") ^ 0xff);
60   if ((specialist_8255_porta & 0x02)==0) dat ^= (input_port_read(device->machine, "LINE1") ^ 0xff);
61   if ((specialist_8255_porta & 0x04)==0) dat ^= (input_port_read(device->machine, "LINE2") ^ 0xff);
62   if ((specialist_8255_porta & 0x08)==0) dat ^= (input_port_read(device->machine, "LINE3") ^ 0xff);
63   if ((specialist_8255_porta & 0x10)==0) dat ^= (input_port_read(device->machine, "LINE4") ^ 0xff);
64   if ((specialist_8255_porta & 0x20)==0) dat ^= (input_port_read(device->machine, "LINE5") ^ 0xff);
65   if ((specialist_8255_porta & 0x40)==0) dat ^= (input_port_read(device->machine, "LINE6") ^ 0xff);
66   if ((specialist_8255_porta & 0x80)==0) dat ^= (input_port_read(device->machine, "LINE7") ^ 0xff);
67   if ((specialist_8255_portc & 0x01)==0) dat ^= (input_port_read(device->machine, "LINE8") ^ 0xff);
68   if ((specialist_8255_portc & 0x02)==0) dat ^= (input_port_read(device->machine, "LINE9") ^ 0xff);
69   if ((specialist_8255_portc & 0x04)==0) dat ^= (input_port_read(device->machine, "LINE10") ^ 0xff);
70   if ((specialist_8255_portc & 0x08)==0) dat ^= (input_port_read(device->machine, "LINE11") ^ 0xff);
54   if ((state->specialist_8255_porta & 0x01)==0) dat ^= (input_port_read(device->machine, "LINE0") ^ 0xff);
55   if ((state->specialist_8255_porta & 0x02)==0) dat ^= (input_port_read(device->machine, "LINE1") ^ 0xff);
56   if ((state->specialist_8255_porta & 0x04)==0) dat ^= (input_port_read(device->machine, "LINE2") ^ 0xff);
57   if ((state->specialist_8255_porta & 0x08)==0) dat ^= (input_port_read(device->machine, "LINE3") ^ 0xff);
58   if ((state->specialist_8255_porta & 0x10)==0) dat ^= (input_port_read(device->machine, "LINE4") ^ 0xff);
59   if ((state->specialist_8255_porta & 0x20)==0) dat ^= (input_port_read(device->machine, "LINE5") ^ 0xff);
60   if ((state->specialist_8255_porta & 0x40)==0) dat ^= (input_port_read(device->machine, "LINE6") ^ 0xff);
61   if ((state->specialist_8255_porta & 0x80)==0) dat ^= (input_port_read(device->machine, "LINE7") ^ 0xff);
62   if ((state->specialist_8255_portc & 0x01)==0) dat ^= (input_port_read(device->machine, "LINE8") ^ 0xff);
63   if ((state->specialist_8255_portc & 0x02)==0) dat ^= (input_port_read(device->machine, "LINE9") ^ 0xff);
64   if ((state->specialist_8255_portc & 0x04)==0) dat ^= (input_port_read(device->machine, "LINE10") ^ 0xff);
65   if ((state->specialist_8255_portc & 0x08)==0) dat ^= (input_port_read(device->machine, "LINE11") ^ 0xff);
7166
7267   dat = (dat  << 2) ^0xff;
7368   if (input_port_read(device->machine, "LINE12")!=0xff) dat ^= 0x02;
r9675r9676
9186
9287static WRITE8_DEVICE_HANDLER (specialist_8255_porta_w )
9388{
94   specialist_8255_porta = data;
89   special_state *state = device->machine->driver_data<special_state>();
90   state->specialist_8255_porta = data;
9591}
9692
9793static WRITE8_DEVICE_HANDLER (specialist_8255_portb_w )
9894{
99   specialist_8255_portb = data;
95   special_state *state = device->machine->driver_data<special_state>();
96   state->specialist_8255_portb = data;
10097}
10198static WRITE8_DEVICE_HANDLER (specialist_8255_portc_w )
10299{
100   special_state *state = device->machine->driver_data<special_state>();
103101   running_device *dac_device = device->machine->device("dac");
104102
105   specialist_8255_portc = data;
103   state->specialist_8255_portc = data;
106104
107105   cassette_output(device->machine->device("cassette"),data & 0x80 ? 1 : -1);
108106
r9675r9676
149147
150148static WRITE8_HANDLER( video_memory_w )
151149{
150   special_state *state = space->machine->driver_data<special_state>();
152151   messram_get_ptr(space->machine->device("messram"))[0x9000 + offset] = data;
153   specimx_colorram[offset]  = specimx_color;
152   state->specimx_colorram[offset]  = state->specimx_color;
154153}
155154
156155WRITE8_HANDLER (specimx_video_color_w )
157156{
158   specimx_color = data;
157   special_state *state = space->machine->driver_data<special_state>();
158   state->specimx_color = data;
159159}
160160
161161READ8_HANDLER (specimx_video_color_r )
162162{
163   return specimx_color;
163   special_state *state = space->machine->driver_data<special_state>();
164   return state->specimx_color;
164165}
165166
166167static void specimx_set_bank(running_machine *machine, int i,int data)
r9675r9676
211212
212213static WRITE_LINE_DEVICE_HANDLER( specimx_pit8253_out0_changed )
213214{
214   specimx_set_input( specimx_audio, 0, state );
215   special_state *drvstate = device->machine->driver_data<special_state>();
216   specimx_set_input( drvstate->specimx_audio, 0, state );
215217}
216218
217219
218220
219221static WRITE_LINE_DEVICE_HANDLER(specimx_pit8253_out1_changed)
220222{
221   specimx_set_input( specimx_audio, 1, state );
223   special_state *drvstate = device->machine->driver_data<special_state>();
224   specimx_set_input( drvstate->specimx_audio, 1, state );
222225}
223226
224227
225228
226229static WRITE_LINE_DEVICE_HANDLER(specimx_pit8253_out2_changed)
227230{
228   specimx_set_input( specimx_audio, 2, state );
231   special_state *drvstate = device->machine->driver_data<special_state>();
232   specimx_set_input( drvstate->specimx_audio, 2, state );
229233}
230234
231235
r9675r9676
253257
254258MACHINE_START( specimx )
255259{
256   specimx_audio = machine->device("custom");
260   special_state *state = machine->driver_data<special_state>();
261   state->specimx_audio = machine->device("custom");
257262}
258263
259264static TIMER_CALLBACK( setup_pit8253_gates )
r9675r9676
267272
268273MACHINE_RESET( specimx )
269274{
275   special_state *state = machine->driver_data<special_state>();
270276   specimx_set_bank(machine, 2,0x00); // Initiali load ROM disk
271   specimx_color = 0x70;
277   state->specimx_color = 0x70;
272278   timer_set(machine,  attotime_zero, NULL, 0, setup_pit8253_gates );
273279   running_device *fdc = machine->device("wd1793");
274280   wd17xx_set_pause_time(fdc,12);
r9675r9676
299305/*
300306    Erik
301307*/
302static UINT8 RR_register;
303static UINT8 RC_register;
304308
305309static void erik_set_bank(running_machine *machine)
306310{
307   UINT8 bank1 = (RR_register & 3);
308   UINT8 bank2 = ((RR_register >> 2) & 3);
309   UINT8 bank3 = ((RR_register >> 4) & 3);
310   UINT8 bank4 = ((RR_register >> 6) & 3);
311   special_state *state = machine->driver_data<special_state>();
312   UINT8 bank1 = (state->RR_register & 3);
313   UINT8 bank2 = ((state->RR_register >> 2) & 3);
314   UINT8 bank3 = ((state->RR_register >> 4) & 3);
315   UINT8 bank4 = ((state->RR_register >> 6) & 3);
311316   UINT8 *mem = memory_region(machine, "maincpu");
312317   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
313318
r9675r9676
376381
377382DRIVER_INIT( erik )
378383{
379   erik_color_1 = 0;
380   erik_color_2 = 0;
381   erik_background = 0;
384   special_state *state = machine->driver_data<special_state>();
385   state->erik_color_1 = 0;
386   state->erik_color_2 = 0;
387   state->erik_background = 0;
382388}
383389
384390MACHINE_RESET( erik )
385391{
386   RR_register = 0x00;
387   RC_register = 0x00;
392   special_state *state = machine->driver_data<special_state>();
393   state->RR_register = 0x00;
394   state->RC_register = 0x00;
388395   erik_set_bank(machine);
389396}
390397
391398READ8_HANDLER ( erik_rr_reg_r )
392399{
393   return RR_register;
400   special_state *state = space->machine->driver_data<special_state>();
401   return state->RR_register;
394402}
395403WRITE8_HANDLER( erik_rr_reg_w )
396404{
397   RR_register = data;
405   special_state *state = space->machine->driver_data<special_state>();
406   state->RR_register = data;
398407   erik_set_bank(space->machine);
399408}
400409
401410READ8_HANDLER ( erik_rc_reg_r )
402411{
403   return RC_register;
412   special_state *state = space->machine->driver_data<special_state>();
413   return state->RC_register;
404414}
405415
406416
407417WRITE8_HANDLER( erik_rc_reg_w )
408418{
409   RC_register = data;
410   erik_color_1 =  RC_register & 7;
411   erik_color_2 =  (RC_register >> 3) & 7;
412   erik_background = ((RC_register  >> 6 ) & 1) + ((RC_register  >> 7 ) & 1) * 4;
419   special_state *state = space->machine->driver_data<special_state>();
420   state->RC_register = data;
421   state->erik_color_1 =  state->RC_register & 7;
422   state->erik_color_2 =  (state->RC_register >> 3) & 7;
423   state->erik_background = ((state->RC_register  >> 6 ) & 1) + ((state->RC_register  >> 7 ) & 1) * 4;
413424}
414425
415426READ8_HANDLER ( erik_disk_reg_r )
src/mess/machine/ut88.c
r9675r9676
1414#include "machine/i8255a.h"
1515#include "includes/ut88.h"
1616
17static int ut88_keyboard_mask;
1817
1918/* Driver initialization */
2019DRIVER_INIT(ut88)
r9675r9676
2827
2928static READ8_DEVICE_HANDLER (ut88_8255_portb_r )
3029{
30   ut88_state *state = device->machine->driver_data<ut88_state>();
3131   UINT8 key = 0xff;
32   if ((ut88_keyboard_mask & 0x01)!=0) { key &= input_port_read(device->machine,"LINE0"); }
33   if ((ut88_keyboard_mask & 0x02)!=0) { key &= input_port_read(device->machine,"LINE1"); }
34   if ((ut88_keyboard_mask & 0x04)!=0) { key &= input_port_read(device->machine,"LINE2"); }
35   if ((ut88_keyboard_mask & 0x08)!=0) { key &= input_port_read(device->machine,"LINE3"); }
36   if ((ut88_keyboard_mask & 0x10)!=0) { key &= input_port_read(device->machine,"LINE4"); }
37   if ((ut88_keyboard_mask & 0x20)!=0) { key &= input_port_read(device->machine,"LINE5"); }
38   if ((ut88_keyboard_mask & 0x40)!=0) { key &= input_port_read(device->machine,"LINE6"); }
39   if ((ut88_keyboard_mask & 0x80)!=0) { key &= input_port_read(device->machine,"LINE7"); }
32   if ((state->keyboard_mask & 0x01)!=0) { key &= input_port_read(device->machine,"LINE0"); }
33   if ((state->keyboard_mask & 0x02)!=0) { key &= input_port_read(device->machine,"LINE1"); }
34   if ((state->keyboard_mask & 0x04)!=0) { key &= input_port_read(device->machine,"LINE2"); }
35   if ((state->keyboard_mask & 0x08)!=0) { key &= input_port_read(device->machine,"LINE3"); }
36   if ((state->keyboard_mask & 0x10)!=0) { key &= input_port_read(device->machine,"LINE4"); }
37   if ((state->keyboard_mask & 0x20)!=0) { key &= input_port_read(device->machine,"LINE5"); }
38   if ((state->keyboard_mask & 0x40)!=0) { key &= input_port_read(device->machine,"LINE6"); }
39   if ((state->keyboard_mask & 0x80)!=0) { key &= input_port_read(device->machine,"LINE7"); }
4040   return key;
4141}
4242
r9675r9676
4747
4848static WRITE8_DEVICE_HANDLER (ut88_8255_porta_w )
4949{
50   ut88_keyboard_mask = data ^ 0xff;
50   ut88_state *state = device->machine->driver_data<ut88_state>();
51   state->keyboard_mask = data ^ 0xff;
5152}
5253
5354I8255A_INTERFACE( ut88_ppi8255_interface )
r9675r9676
6768
6869MACHINE_RESET( ut88 )
6970{
71   ut88_state *state = machine->driver_data<ut88_state>();
7072   timer_set(machine, ATTOTIME_IN_USEC(10), NULL, 0, ut88_reset);
7173   memory_set_bank(machine, "bank1", 1);
72   ut88_keyboard_mask = 0;
74   state->keyboard_mask = 0;
7375}
7476
7577
r9675r9676
121123   return key;
122124}
123125
124static int lcd_digit[6];
125126
126127WRITE8_HANDLER( ut88mini_write_led )
127128{
129   ut88_state *state = space->machine->driver_data<ut88_state>();
128130      switch(offset) {
129         case 0  : lcd_digit[4] = (data >> 4) & 0x0f;
130                        lcd_digit[5] = data & 0x0f;
131         case 0  : state->lcd_digit[4] = (data >> 4) & 0x0f;
132                        state->lcd_digit[5] = data & 0x0f;
131133                        break;
132         case 1  : lcd_digit[2] = (data >> 4) & 0x0f;
133                        lcd_digit[3] = data & 0x0f;
134         case 1  : state->lcd_digit[2] = (data >> 4) & 0x0f;
135                        state->lcd_digit[3] = data & 0x0f;
134136                        break;
135         case 2  : lcd_digit[0] = (data >> 4) & 0x0f;
136                        lcd_digit[1] = data & 0x0f;
137         case 2  : state->lcd_digit[0] = (data >> 4) & 0x0f;
138                        state->lcd_digit[1] = data & 0x0f;
137139                        break;
138140      }
139141}
r9675r9676
148150
149151static TIMER_CALLBACK( update_display )
150152{
153   ut88_state *state = machine->driver_data<ut88_state>();
151154   int i;
152155   for (i=0;i<6;i++) {
153      output_set_digit_value(i, hex_to_7seg[lcd_digit[i]]);
156      output_set_digit_value(i, hex_to_7seg[state->lcd_digit[i]]);
154157   }
155158}
156159
r9675r9676
166169
167170MACHINE_RESET( ut88mini )
168171{
169   lcd_digit[0] = lcd_digit[1] = lcd_digit[2] = 0;
170   lcd_digit[3] = lcd_digit[4] = lcd_digit[5] = 0;
172   ut88_state *state = machine->driver_data<ut88_state>();
173   state->lcd_digit[0] = state->lcd_digit[1] = state->lcd_digit[2] = 0;
174   state->lcd_digit[3] = state->lcd_digit[4] = state->lcd_digit[5] = 0;
171175}
172176
src/mess/video/z88.c
r9675r9676
1010#include "devices/messram.h"
1111#include "includes/z88.h"
1212
13static int frame_number = 0;
14static int flash_invert = 0;
1513
1614INLINE void z88_plot_pixel(bitmap_t *bitmap, int x, int y, UINT32 color)
1715{
r9675r9676
139137
140138VIDEO_EOF( z88 )
141139{
142   frame_number++;
143   if (frame_number >= 50)
140   z88_state *state = machine->driver_data<z88_state>();
141   state->frame_number++;
142   if (state->frame_number >= 50)
144143   {
145      frame_number = 0;
146      flash_invert = !flash_invert;
144      state->frame_number = 0;
145      state->flash_invert = !state->flash_invert;
147146   }
148147}
149148
r9675r9676
156155***************************************************************************/
157156VIDEO_UPDATE( z88 )
158157{
158   //z88_state *state = screen->machine->driver_data<z88_state>();
159159   int x,y;
160160   unsigned char *ptr = z88_convert_address(screen->machine, z88_blink.sbf);
161161   unsigned char *stored_ptr = ptr;
r9675r9676
204204
205205//          if (byte1 & Z88_SCR_HW_FLS)
206206//          {
207//              if (flash_invert)
207//              if (state->flash_invert)
208208//              {
209209//                  pen1 = pen0;
210210//              }
src/mess/video/pcw16.c
r9675r9676
22#include "includes/pcw16.h"
33#include "devices/messram.h"
44
5int pcw16_colour_palette[16];
6int pcw16_video_control;
75
86/* 16 colours, + 1 for border */
97static const unsigned short pcw16_colour_table[PCW16_NUM_COLOURS] =
r9675r9676
6664}
6765
6866/* 640, 1 bit per pixel */
69static void pcw16_vh_decode_mode0(bitmap_t *bitmap, int x, int y, unsigned char byte)
67static void pcw16_vh_decode_mode0(pcw16_state *state, bitmap_t *bitmap, int x, int y, unsigned char byte)
7068{
7169   int b;
7270   int local_byte;
r9675r9676
7573
7674   local_byte = byte;
7775
78   cols[0] = pcw16_colour_palette[0];
79   cols[1] = pcw16_colour_palette[1];
76   cols[0] = state->colour_palette[0];
77   cols[1] = state->colour_palette[1];
8078
8179   px = x;
8280   for (b=0; b<8; b++)
r9675r9676
8987}
9088
9189/* 320, 2 bits per pixel */
92static void pcw16_vh_decode_mode1(bitmap_t *bitmap, int x, int y, unsigned char byte)
90static void pcw16_vh_decode_mode1(pcw16_state *state, bitmap_t *bitmap, int x, int y, unsigned char byte)
9391{
9492   int b;
9593   int px;
r9675r9676
9896
9997   for (b=0; b<3; b++)
10098   {
101      cols[b] = pcw16_colour_palette[b];
99      cols[b] = state->colour_palette[b];
102100   }
103101
104102   local_byte = byte;
r9675r9676
120118}
121119
122120/* 160, 4 bits per pixel */
123static void pcw16_vh_decode_mode2(bitmap_t *bitmap, int x, int y, unsigned char byte)
121static void pcw16_vh_decode_mode2(pcw16_state *state, bitmap_t *bitmap, int x, int y, unsigned char byte)
124122{
125123   int px;
126124   int b;
127125   int local_byte;
128126   int cols[2];
129127
130   cols[0] = pcw16_colour_palette[0];
131   cols[1] = pcw16_colour_palette[1];
128   cols[0] = state->colour_palette[0];
129   cols[1] = state->colour_palette[1];
132130   local_byte = byte;
133131
134132   px = x;
r9675r9676
158156***************************************************************************/
159157VIDEO_UPDATE( pcw16 )
160158{
159   pcw16_state *state = screen->machine->driver_data<pcw16_state>();
161160   unsigned char *pScanLine = (unsigned char *)messram_get_ptr(screen->machine->device("messram")) + 0x0fc00;   //0x03c00;  //0x020FC00;
162161
163162   int y;
r9675r9676
165164
166165   int border_colour;
167166
168   border_colour = pcw16_video_control & 31;
167   border_colour = state->video_control & 31;
169168
170169   /* reverse video? */
171   if (pcw16_video_control & (1<<7))
170   if (state->video_control & (1<<7))
172171   {
173172      /* colour 0 and colour 1 need to be inverted? - what happens in mode 1 and 2 - ignored? or is bit 1 toggled,
174173        or is whole lot toggled? */
175174
176175      /* force border to be colour 1 */
177      border_colour = pcw16_colour_palette[1];
176      border_colour = state->colour_palette[1];
178177   }
179178
180   if ((pcw16_video_control & (1<<6))==0)
179   if ((state->video_control & (1<<6))==0)
181180   {
182181      /* blank */
183182      rectangle rect;
r9675r9676
247246            {
248247               case 0:
249248               {
250                  pcw16_vh_decode_mode0(bitmap,x,y+PCW16_BORDER_HEIGHT,byte);
249                  pcw16_vh_decode_mode0(state, bitmap, x, y+PCW16_BORDER_HEIGHT, byte);
251250               }
252251               break;
253252
254253               case 1:
255254               {
256                  pcw16_vh_decode_mode1(bitmap, x,y+PCW16_BORDER_HEIGHT, byte);
255                  pcw16_vh_decode_mode1(state, bitmap, x, y+PCW16_BORDER_HEIGHT, byte);
257256               }
258257               break;
259258
260259               case 3:
261260               case 2:
262261               {
263                  pcw16_vh_decode_mode2(bitmap, x, y+PCW16_BORDER_HEIGHT, byte);
262                  pcw16_vh_decode_mode2(state, bitmap, x, y+PCW16_BORDER_HEIGHT, byte);
264263               }
265264               break;
266265            }
src/mess/video/vector06.c
r9675r9676
1717
1818VIDEO_UPDATE( vector06 )
1919{
20   vector06_state *state = screen->machine->driver_data<vector06_state>();
2021   UINT8 code1,code2,code3,code4;
2122   UINT8 col;
2223   int y, x, b,draw_y;
2324
24   int width = (vector06_video_mode==0x00) ? 256 : 512;
25   int width = (state->video_mode==0x00) ? 256 : 512;
2526   rectangle screen_area = {0,width+64-1,0,256+64-1};
2627   // fill border color
27   bitmap_fill(bitmap, &screen_area, vector06_color_index);
28   bitmap_fill(bitmap, &screen_area, state->color_index);
2829
2930   // draw image
3031   for (x = 0; x < 32; x++)
r9675r9676
3233      for (y = 0; y < 256; y++)
3334      {
3435         // port A form 8255 also used as scroll
35         draw_y = ((255-y-vector06_keyboard_mask) & 0xff) +32;
36         draw_y = ((255-y-state->keyboard_mask) & 0xff) +32;
3637         code1 = messram_get_ptr(screen->machine->device("messram"))[0x8000 + x*256 + y];
3738         code2 = messram_get_ptr(screen->machine->device("messram"))[0xa000 + x*256 + y];
3839         code3 = messram_get_ptr(screen->machine->device("messram"))[0xc000 + x*256 + y];
r9675r9676
4041         for (b = 0; b < 8; b++)
4142         {
4243            col = ((code1 >> b) & 0x01) * 8 + ((code2 >> b) & 0x01) * 4 + ((code3 >> b) & 0x01)* 2+ ((code4 >> b) & 0x01);
43            if (vector06_video_mode==0x00) {
44            if (state->video_mode==0x00) {
4445               *BITMAP_ADDR16(bitmap, draw_y, x*8+(7-b)+32) =  col;
4546            } else {
4647               *BITMAP_ADDR16(bitmap, draw_y, x*16+(7-b)*2+1+32) =  ((code2 >> b) & 0x01) * 2;
src/mess/video/sapi1.c
r9675r9676
8484   0x0e,0x11,0x01,0x02,0x04,0x00,0x04,0x00  // ?
8585};
8686
87static UINT8 refresh_counter;
88UINT8* sapi_video_ram;
8987
9088VIDEO_START( sapi1 )
9189{
92   refresh_counter = 0;
90   sapi1_state *state = machine->driver_data<sapi1_state>();
91   state->refresh_counter = 0;
9392}
9493
9594VIDEO_UPDATE( sapi1 )
9695{
96   sapi1_state *state = screen->machine->driver_data<sapi1_state>();
9797   int x,y,j,b;
9898  UINT16 addr;
9999  int xpos;
r9675r9676
104104      xpos = 0;
105105      for(x = 0; x < 40; x++ )
106106      {
107         UINT8 code = sapi_video_ram[addr + x];
107         UINT8 code = state->sapi_video_ram[addr + x];
108108         UINT8 attr = (code >> 6) & 3;
109109         code &= 0x3f;
110110         for(j = 0; j < 9; j++ )
r9675r9676
114114            UINT8 val;
115115            if (j==8) {
116116               if (attr==2) {
117                  val = (refresh_counter & 0x20) ? 1 : 0;
117                  val = (state->refresh_counter & 0x20) ? 1 : 0;
118118               } else {
119119                  val = 0;
120120               }
121121            } else {
122122               val = (MHB2501[code*8 + j] >> (5-b)) & 1;
123123               if (attr==1) {
124                  val = (refresh_counter & 0x20) ? val : 0;
124                  val = (state->refresh_counter & 0x20) ? val : 0;
125125               }
126126            }
127127            if(attr==3) {
r9675r9676
136136         if (xpos>=6*40) break;
137137      }
138138   }
139   refresh_counter++;
139   state->refresh_counter++;
140140   return 0;
141141}
142142
src/mess/video/special.c
r9675r9676
1111#include "includes/special.h"
1212#include "devices/messram.h"
1313
14UINT8 *specialist_video_ram;
1514
1615
1716VIDEO_START( special )
r9675r9676
2019
2120VIDEO_UPDATE( special )
2221{
22   special_state *state = screen->machine->driver_data<special_state>();
2323  UINT8 code;
2424   int y, x, b;
2525
r9675r9676
2727   {
2828      for (y = 0; y < 256; y++)
2929      {
30         code = specialist_video_ram[y + x*256];
30         code = state->specialist_video_ram[y + x*256];
3131         for (b = 7; b >= 0; b--)
3232         {
3333            *BITMAP_ADDR16(bitmap, y, x*8+(7-b)) =  (code >> b) & 0x01;
r9675r9676
4242
4343VIDEO_UPDATE( specialp )
4444{
45   special_state *state = screen->machine->driver_data<special_state>();
4546  UINT8 code;
4647   int y, x, b;
4748
r9675r9676
4950   {
5051      for (y = 0; y < 256; y++)
5152      {
52         code = specialist_video_ram[y + x*256];
53         code = state->specialist_video_ram[y + x*256];
5354         for (b = 7; b >= 0; b--)
5455         {
5556            *BITMAP_ADDR16(bitmap, y, x*8+(7-b)) =  (code >> b) & 0x01;
r9675r9676
8788
8889VIDEO_START( specimx )
8990{
90   specimx_colorram = auto_alloc_array(machine, UINT8, 0x3000);
91   memset(specimx_colorram,0x70,0x3000);
91   special_state *state = machine->driver_data<special_state>();
92   state->specimx_colorram = auto_alloc_array(machine, UINT8, 0x3000);
93   memset(state->specimx_colorram,0x70,0x3000);
9294}
9395
9496VIDEO_UPDATE( specimx )
9597{
98   special_state *state = screen->machine->driver_data<special_state>();
9699   UINT8 code,color;
97100   int y, x, b;
98101
r9675r9676
101104      for (y = 0; y < 256; y++)
102105      {
103106         code = messram_get_ptr(screen->machine->device("messram"))[0x9000 + y + x*256];
104         color = specimx_colorram[y + x*256];
107         color = state->specimx_colorram[y + x*256];
105108         for (b = 7; b >= 0; b--)
106109         {
107110
r9675r9676
128131   palette_set_colors(machine, 0, erik_palette, ARRAY_LENGTH(erik_palette));
129132}
130133
131UINT8 erik_color_1;
132UINT8 erik_color_2;
133UINT8 erik_background;
134134
135135VIDEO_START( erik )
136136{
r9675r9676
138138
139139VIDEO_UPDATE( erik )
140140{
141   special_state *state = screen->machine->driver_data<special_state>();
141142  UINT8 code1;
142143  UINT8 code2;
143144  UINT8 color1,color2;
r9675r9676
157158
158159         for (b = 7; b >= 0; b--)
159160         {
160            color1 = ((code1 >> b) & 0x01)==0 ? erik_background : erik_color_1;
161            color2 = ((code2 >> b) & 0x01)==0 ? erik_background : erik_color_2;
161            color1 = ((code1 >> b) & 0x01)==0 ? state->erik_background : state->erik_color_1;
162            color2 = ((code2 >> b) & 0x01)==0 ? state->erik_background : state->erik_color_2;
162163            *BITMAP_ADDR16(bitmap, y, x*8+(7-b)) =  color1 | color2;
163164         }
164165      }
src/mess/video/poly88.c
r9675r9676
99#include "emu.h"
1010#include "includes/poly88.h"
1111
12UINT8* poly88_video_ram;
13
1412static const UINT8 mcm6571a[] =
1513{
1614   0x00,0x00,0x00,0x00,0x31,0x4A,0x44,0x4A,0x31,// 0
r9675r9676
181179
182180VIDEO_UPDATE( poly88 )
183181{
182   poly88_state *state = screen->machine->driver_data<poly88_state>();
184183   int x,y,j,b;
185184   UINT16 addr;
186185   int xpos;
r9675r9676
192191      xpos = 0;
193192      for(x = 0; x < 64; x++ )
194193      {
195         UINT8 code = poly88_video_ram[addr + x];
194         UINT8 code = state->video_ram[addr + x];
196195         if ((code & 0x80)==0) {
197196            for(j = 0; j < 15; j++ )
198197            {
src/mess/video/ut88.c
r9675r9676
1010#include "emu.h"
1111#include "includes/ut88.h"
1212
13UINT8 *ut88_video_ram;
1413
1514const gfx_layout ut88_charlayout =
1615{
r9675r9676
2928
3029VIDEO_UPDATE( ut88 )
3130{
31   ut88_state *state = screen->machine->driver_data<ut88_state>();
3232   int x,y;
3333
3434   for(y = 0; y < 28; y++ )
3535   {
3636      for(x = 0; x < 64; x++ )
3737      {
38         int code = ut88_video_ram[ x + y*64 ] & 0x7f;
39         int attr = ut88_video_ram[ x+1 + y*64 ] & 0x80;
38         int code = state->video_ram[ x + y*64 ] & 0x7f;
39         int attr = state->video_ram[ x+1 + y*64 ] & 0x80;
4040         drawgfx_opaque(bitmap, NULL, screen->machine->gfx[0],  code | attr, 0, 0,0, x*8,y*8);
4141      }
4242   }
src/mess/video/z1013.c
r9675r9676
1010#include "emu.h"
1111#include "includes/z1013.h"
1212
13UINT8 *z1013_video_ram;
1413
1514VIDEO_START( z1013 )
1615{
r9675r9676
1817
1918VIDEO_UPDATE( z1013 )
2019{
20   z1013_state *state = screen->machine->driver_data<z1013_state>();
2121   UINT8 code, line;
2222   int y, x, b,i;
2323   UINT8 *gfx = memory_region(screen->machine, "gfx1");
r9675r9676
2626   {
2727      for(x = 0; x < 32; x++ )
2828      {
29         code = z1013_video_ram[x + y*32];
29         code = state->video_ram[x + y*32];
3030         for (i = 0; i < 8; i++)
3131         {
3232            line = gfx[code*8 + i];
src/mess/video/primo.c
r9675r9676
1111#include "emu.h"
1212#include "includes/primo.h"
1313
14UINT16 primo_video_memory_base;
1514
1615
1716static void primo_draw_scanline(running_machine *machine,bitmap_t *bitmap, int primo_scanline)
1817{
18   primo_state *state = machine->driver_data<primo_state>();
1919   int x, i;
2020   UINT8 data;
2121
r9675r9676
2323   UINT16 *scanline = BITMAP_ADDR16(bitmap, primo_scanline, 0);
2424
2525   /* address of current line in Primo video memory */
26   const UINT8* primo_video_ram_line = (const UINT8*)cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM)->get_read_ptr(primo_video_memory_base + 32 * primo_scanline);
26   const UINT8* primo_video_ram_line = (const UINT8*)cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM)->get_read_ptr(state->video_memory_base + 32 * primo_scanline);
2727
2828   for (x=0; x<256; x+=8)
2929   {
src/mess/video/ti85.c
r9675r9676
3838#define TI73_SCREEN_Y_SIZE     64
3939#define TI73_NUMBER_OF_FRAMES      6
4040
41static int ti_video_memory_size;
42static int ti_screen_x_size;
43static int ti_screen_y_size;
44static int ti_number_of_frames;
4541
46static UINT8 * ti85_frames;
4742
4843static const unsigned char ti85_colors[32*7][3] =
4944{
r9675r9676
119114
120115PALETTE_INIT( ti85 )
121116{
117   ti85_state *state = machine->driver_data<ti85_state>();
122118   UINT8 i, j, r, g, b;
123119
124120   machine->colortable = colortable_alloc(machine, 224);
r9675r9676
135131
136132   if (!strncmp(machine->gamedrv->name, "ti81", 4))
137133   {
138      ti_video_memory_size = TI81_VIDEO_MEMORY_SIZE;
139      ti_screen_x_size = TI81_SCREEN_X_SIZE;
140      ti_screen_y_size = TI81_SCREEN_Y_SIZE;
141      ti_number_of_frames = TI81_NUMBER_OF_FRAMES;
134      state->ti_video_memory_size = TI81_VIDEO_MEMORY_SIZE;
135      state->ti_screen_x_size = TI81_SCREEN_X_SIZE;
136      state->ti_screen_y_size = TI81_SCREEN_Y_SIZE;
137      state->ti_number_of_frames = TI81_NUMBER_OF_FRAMES;
142138   }
143139   else if (!strncmp(machine->gamedrv->name, "ti85", 4))
144140   {
145      ti_video_memory_size = TI85_VIDEO_MEMORY_SIZE;
146      ti_screen_x_size = TI85_SCREEN_X_SIZE;
147      ti_screen_y_size = TI85_SCREEN_Y_SIZE;
148      ti_number_of_frames = TI85_NUMBER_OF_FRAMES;
141      state->ti_video_memory_size = TI85_VIDEO_MEMORY_SIZE;
142      state->ti_screen_x_size = TI85_SCREEN_X_SIZE;
143      state->ti_screen_y_size = TI85_SCREEN_Y_SIZE;
144      state->ti_number_of_frames = TI85_NUMBER_OF_FRAMES;
149145   }
150146   else if (!strncmp(machine->gamedrv->name, "ti82", 4))
151147   {
152      ti_video_memory_size = TI82_VIDEO_MEMORY_SIZE;
153      ti_screen_x_size = TI82_SCREEN_X_SIZE;
154      ti_screen_y_size = TI82_SCREEN_Y_SIZE;
155      ti_number_of_frames = TI82_NUMBER_OF_FRAMES;
148      state->ti_video_memory_size = TI82_VIDEO_MEMORY_SIZE;
149      state->ti_screen_x_size = TI82_SCREEN_X_SIZE;
150      state->ti_screen_y_size = TI82_SCREEN_Y_SIZE;
151      state->ti_number_of_frames = TI82_NUMBER_OF_FRAMES;
156152   }
157153   else if (!strncmp(machine->gamedrv->name, "ti83p", 5))
158154   {
159      ti_video_memory_size = TI83_VIDEO_MEMORY_SIZE;
160      ti_screen_x_size = TI83_SCREEN_X_SIZE;
161      ti_screen_y_size = TI83_SCREEN_Y_SIZE;
162      ti_number_of_frames = TI83_NUMBER_OF_FRAMES;
155      state->ti_video_memory_size = TI83_VIDEO_MEMORY_SIZE;
156      state->ti_screen_x_size = TI83_SCREEN_X_SIZE;
157      state->ti_screen_y_size = TI83_SCREEN_Y_SIZE;
158      state->ti_number_of_frames = TI83_NUMBER_OF_FRAMES;
163159   }
164160   else if (!strncmp(machine->gamedrv->name, "ti83", 4))
165161   {
166      ti_video_memory_size = TI83_VIDEO_MEMORY_SIZE;
167      ti_screen_x_size = TI83_SCREEN_X_SIZE;
168      ti_screen_y_size = TI83_SCREEN_Y_SIZE;
169      ti_number_of_frames = TI83_NUMBER_OF_FRAMES;
162      state->ti_video_memory_size = TI83_VIDEO_MEMORY_SIZE;
163      state->ti_screen_x_size = TI83_SCREEN_X_SIZE;
164      state->ti_screen_y_size = TI83_SCREEN_Y_SIZE;
165      state->ti_number_of_frames = TI83_NUMBER_OF_FRAMES;
170166   }
171167   else if (!strncmp(machine->gamedrv->name, "ti86", 4))
172168   {
173      ti_video_memory_size = TI86_VIDEO_MEMORY_SIZE;
174      ti_screen_x_size = TI86_SCREEN_X_SIZE;
175      ti_screen_y_size = TI86_SCREEN_Y_SIZE;
176      ti_number_of_frames = TI86_NUMBER_OF_FRAMES;
169      state->ti_video_memory_size = TI86_VIDEO_MEMORY_SIZE;
170      state->ti_screen_x_size = TI86_SCREEN_X_SIZE;
171      state->ti_screen_y_size = TI86_SCREEN_Y_SIZE;
172      state->ti_number_of_frames = TI86_NUMBER_OF_FRAMES;
177173   }
178174   else if (!strncmp(machine->gamedrv->name, "ti73", 4))
179175   {
180      ti_video_memory_size = TI73_VIDEO_MEMORY_SIZE;
181      ti_screen_x_size = TI73_SCREEN_X_SIZE;
182      ti_screen_y_size = TI73_SCREEN_Y_SIZE;
183      ti_number_of_frames = TI73_NUMBER_OF_FRAMES;
176      state->ti_video_memory_size = TI73_VIDEO_MEMORY_SIZE;
177      state->ti_screen_x_size = TI73_SCREEN_X_SIZE;
178      state->ti_screen_y_size = TI73_SCREEN_Y_SIZE;
179      state->ti_number_of_frames = TI73_NUMBER_OF_FRAMES;
184180   }
185181   else
186182   {
r9675r9676
188184      return;
189185   }
190186
191   ti85_frames = auto_alloc_array_clear(machine, UINT8, ti_number_of_frames*ti_video_memory_size);
187   state->frames = auto_alloc_array_clear(machine, UINT8, state->ti_number_of_frames*state->ti_video_memory_size);
192188}
193189
194190VIDEO_START( ti85 )
r9675r9676
197193
198194VIDEO_UPDATE( ti85 )
199195{
196   ti85_state *state = screen->machine->driver_data<ti85_state>();
200197   address_space *space = cputag_get_address_space(screen->machine, "maincpu", ADDRESS_SPACE_PROGRAM);
201198   int x,y,b;
202199   int brightnes;
203200   int lcdmem;
204201
205   if (!ti85_LCD_status || !ti85_timer_interrupt_mask)
202   if (!state->LCD_status || !state->timer_interrupt_mask)
206203   {
207      for (y=0; y<ti_screen_y_size; y++)
208         for (x=0; x<ti_screen_x_size; x++)
204      for (y=0; y<state->ti_screen_y_size; y++)
205         for (x=0; x<state->ti_screen_x_size; x++)
209206            for (b=0; b<8; b++)
210               *BITMAP_ADDR16(bitmap, y, x*8+b) = ti85_palette[ti85_LCD_contrast&0x1f][6];
207               *BITMAP_ADDR16(bitmap, y, x*8+b) = ti85_palette[state->LCD_contrast&0x1f][6];
211208      return 0;
212209   }
213210
214   lcdmem =  ((ti85_LCD_memory_base & 0x3F) + 0xc0) << 0x08;
211   lcdmem =  ((state->LCD_memory_base & 0x3F) + 0xc0) << 0x08;
215212
216   memcpy (ti85_frames, ti85_frames+ti_video_memory_size, sizeof (UINT8) * (ti_number_of_frames-1) * ti_video_memory_size);
213   memcpy (state->frames, state->frames+state->ti_video_memory_size, sizeof (UINT8) * (state->ti_number_of_frames-1) * state->ti_video_memory_size);
217214
218        for (y=0; y<ti_screen_y_size; y++)
219      for (x=0; x<ti_screen_x_size; x++)
220         *(ti85_frames+(ti_number_of_frames-1)*ti_video_memory_size+y*ti_screen_x_size+x) = space->read_byte(lcdmem+y*ti_screen_x_size+x);
215        for (y=0; y<state->ti_screen_y_size; y++)
216      for (x=0; x<state->ti_screen_x_size; x++)
217         *(state->frames+(state->ti_number_of_frames-1)*state->ti_video_memory_size+y*state->ti_screen_x_size+x) = space->read_byte(lcdmem+y*state->ti_screen_x_size+x);
221218
222       for (y=0; y<ti_screen_y_size; y++)
223      for (x=0; x<ti_screen_x_size; x++)
219       for (y=0; y<state->ti_screen_y_size; y++)
220      for (x=0; x<state->ti_screen_x_size; x++)
224221         for (b=0; b<8; b++)
225222         {
226            brightnes = ((*(ti85_frames+0*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01)
227                 + ((*(ti85_frames+1*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01)
228                 + ((*(ti85_frames+2*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01)
229                 + ((*(ti85_frames+3*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01)
230                 + ((*(ti85_frames+4*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01)
231                 + ((*(ti85_frames+5*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01);
223            brightnes = ((*(state->frames+0*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01)
224                 + ((*(state->frames+1*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01)
225                 + ((*(state->frames+2*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01)
226                 + ((*(state->frames+3*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01)
227                 + ((*(state->frames+4*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01)
228                 + ((*(state->frames+5*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01);
232229
233            *BITMAP_ADDR16(bitmap, y, x*8+b) = ti85_palette[ti85_LCD_contrast&0x1f][brightnes];
230            *BITMAP_ADDR16(bitmap, y, x*8+b) = ti85_palette[state->LCD_contrast&0x1f][brightnes];
234231         }
235232   return 0;
236233}
237234
238235VIDEO_UPDATE( ti82 )
239236{
237   ti85_state *state = screen->machine->driver_data<ti85_state>();
240238   //for now use the ti85_palette
241239
242240   int x,y,b;
243241   int brightnes;
244242
245   if (!ti85_LCD_status || !ti85_timer_interrupt_mask)
243   if (!state->LCD_status || !state->timer_interrupt_mask)
246244   {
247      for (y=0; y<ti_screen_y_size; y++)
248         for (x=0; x<ti_screen_x_size; x++)
245      for (y=0; y<state->ti_screen_y_size; y++)
246         for (x=0; x<state->ti_screen_x_size; x++)
249247            for (b=0; b<8; b++)
250               *BITMAP_ADDR16(bitmap, y, x*8+b) = ti85_palette[ti85_LCD_contrast&0x1f][6];
248               *BITMAP_ADDR16(bitmap, y, x*8+b) = ti85_palette[state->LCD_contrast&0x1f][6];
251249      return 0;
252250   }
253251
254   memcpy (ti85_frames, ti85_frames+ti_video_memory_size, sizeof (UINT8) * (ti_number_of_frames-1) * ti_video_memory_size);
252   memcpy (state->frames, state->frames+state->ti_video_memory_size, sizeof (UINT8) * (state->ti_number_of_frames-1) * state->ti_video_memory_size);
255253
256        for (y=0; y<ti_screen_y_size; y++)
257      for (x=0; x<ti_screen_x_size; x++)
258         *(ti85_frames+(ti_number_of_frames-1)*ti_video_memory_size+y*ti_screen_x_size+x) = ti82_video_buffer[ y*ti_screen_x_size+x];
254        for (y=0; y<state->ti_screen_y_size; y++)
255      for (x=0; x<state->ti_screen_x_size; x++)
256         *(state->frames+(state->ti_number_of_frames-1)*state->ti_video_memory_size+y*state->ti_screen_x_size+x) = state->ti82_video_buffer[ y*state->ti_screen_x_size+x];
259257
260       for (y=0; y<ti_screen_y_size; y++)
261      for (x=0; x<ti_screen_x_size; x++)
258       for (y=0; y<state->ti_screen_y_size; y++)
259      for (x=0; x<state->ti_screen_x_size; x++)
262260         for (b=0; b<8; b++)
263261         {
264            brightnes = ((*(ti85_frames+0*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01)
265                 + ((*(ti85_frames+1*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01)
266                 + ((*(ti85_frames+2*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01)
267                 + ((*(ti85_frames+3*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01)
268                 + ((*(ti85_frames+4*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01)
269                 + ((*(ti85_frames+5*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01);
262            brightnes = ((*(state->frames+0*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01)
263                 + ((*(state->frames+1*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01)
264                 + ((*(state->frames+2*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01)
265                 + ((*(state->frames+3*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01)
266                 + ((*(state->frames+4*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01)
267                 + ((*(state->frames+5*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01);
270268
271            *BITMAP_ADDR16(bitmap, y, x*8+b) = ti85_palette[ti85_LCD_contrast&0x1f][brightnes];
269            *BITMAP_ADDR16(bitmap, y, x*8+b) = ti85_palette[state->LCD_contrast&0x1f][brightnes];
272270         }
273271   return 0;
274272}
src/mess/includes/z88.h
r9675r9676
7676};
7777
7878
79class z88_state : public driver_device
80{
81public:
82   z88_state(running_machine &machine, const driver_device_config_base &config)
83      : driver_device(machine, config) { }
84
85   int frame_number;
86   int flash_invert;
87};
88
89
7990/*----------- defined in drivers/z88.c -----------*/
8091
8192extern struct blink_hw z88_blink;
src/mess/includes/pcw16.h
r9675r9676
1818#define PCW16_SCREEN_HEIGHT   (PCW16_DISPLAY_HEIGHT  + (PCW16_BORDER_HEIGHT<<1))
1919
2020
21class pcw16_state : public driver_device
22{
23public:
24   pcw16_state(running_machine &machine, const driver_device_config_base &config)
25      : driver_device(machine, config) { }
26
27   unsigned long interrupt_counter;
28   int banks[4];
29   int _4_bit_port;
30   int fdc_int_code;
31   int system_status;
32   char *mem_ptr[4];
33   unsigned char keyboard_data_shift;
34   int keyboard_parity_table[256];
35   int keyboard_bits;
36   int keyboard_bits_output;
37   int keyboard_state;
38   int keyboard_previous_state;
39   unsigned char rtc_seconds;
40   unsigned char rtc_minutes;
41   unsigned char rtc_hours;
42   unsigned char rtc_days_max;
43   unsigned char rtc_days;
44   unsigned char rtc_months;
45   unsigned char rtc_years;
46   unsigned char rtc_control;
47   unsigned char rtc_256ths_seconds;
48   int previous_fdc_int_state;
49   int colour_palette[16];
50   int video_control;
51};
52
53
2154/*----------- defined in video/pcw16.c -----------*/
2255
23extern int pcw16_colour_palette[16];
24extern int pcw16_video_control;
25
2656extern PALETTE_INIT( pcw16 );
2757extern VIDEO_START( pcw16 );
2858extern VIDEO_UPDATE( pcw16 );
src/mess/includes/vector06.h
r9675r9676
99
1010#include "machine/i8255a.h"
1111
12class vector06_state : public driver_device
13{
14public:
15   vector06_state(running_machine &machine, const driver_device_config_base &config)
16      : driver_device(machine, config) { }
17
18   UINT8 keyboard_mask;
19   UINT8 color_index;
20   UINT8 video_mode;
21   UINT8 romdisk_msb;
22   UINT8 romdisk_lsb;
23   UINT8 vblank_state;
24};
25
26
1227/*----------- defined in machine/vector06.c -----------*/
1328
1429extern const i8255a_interface vector06_ppi8255_interface;
r9675r9676
2742extern WRITE8_HANDLER(vector06_color_set);
2843extern WRITE8_HANDLER(vector06_disc_w);
2944
30extern UINT8 vector06_keyboard_mask;
31extern UINT8 vector06_color_index;
32extern UINT8 vector06_video_mode;
3345
3446/*----------- defined in video/vector06.c -----------*/
3547
src/mess/includes/sapi1.h
r9675r9676
77#ifndef SAPI_1_H_
88#define SAPI_1_H_
99
10class sapi1_state : public driver_device
11{
12public:
13   sapi1_state(running_machine &machine, const driver_device_config_base &config)
14      : driver_device(machine, config) { }
15
16   UINT8* sapi_video_ram;
17   UINT8 keyboard_mask;
18   UINT8 refresh_counter;
19};
20
21
1022/*----------- defined in machine/sapi1.c -----------*/
1123
1224extern DRIVER_INIT( sapi1 );
r9675r9676
1729extern WRITE8_HANDLER(sapi1_keyboard_w );
1830
1931/*----------- defined in video/sapi1.c -----------*/
20extern UINT8* sapi_video_ram;
2132
2233extern VIDEO_START( sapi1 );
2334extern VIDEO_UPDATE( sapi1 );
src/mess/includes/special.h
r9675r9676
1010#include "machine/i8255a.h"
1111#include "machine/pit8253.h"
1212
13class special_state : public driver_device
14{
15public:
16   special_state(running_machine &machine, const driver_device_config_base &config)
17      : driver_device(machine, config) { }
18
19   UINT8 *specimx_colorram;
20   UINT8 erik_color_1;
21   UINT8 erik_color_2;
22   UINT8 erik_background;
23   UINT8 *specialist_video_ram;
24   UINT8 specimx_color;
25   running_device *specimx_audio;
26   int specialist_8255_porta;
27   int specialist_8255_portb;
28   int specialist_8255_portc;
29   UINT8 RR_register;
30   UINT8 RC_register;
31};
32
33
1334/*----------- defined in machine/special.c -----------*/
1435
15extern UINT8 *specimx_colorram;
1636extern const struct pit8253_config specimx_pit8253_intf;
1737extern const i8255a_interface specialist_ppi8255_interface;
1838
r9675r9676
4565
4666/*----------- defined in video/special.c -----------*/
4767
48extern UINT8 erik_color_1;
49extern UINT8 erik_color_2;
50extern UINT8 erik_background;
51
52extern UINT8 *specialist_video_ram;
53
5468VIDEO_START( special );
5569VIDEO_UPDATE( special );
5670
src/mess/includes/poly88.h
r9675r9676
99#include "machine/msm8251.h"
1010#include "devices/snapquik.h"
1111
12class poly88_state : public driver_device
13{
14public:
15   poly88_state(running_machine &machine, const driver_device_config_base &config)
16      : driver_device(machine, config) { }
17
18   UINT8 *video_ram;
19   UINT8 intr;
20   UINT8 last_code;
21   UINT8 int_vector;
22   emu_timer * cassette_timer;
23   emu_timer * usart_timer;
24   int previous_level;
25   int clk_level;
26   int clk_level_tape;
27};
28
29
1230/*----------- defined in machine/poly88.c -----------*/
1331
1432DRIVER_INIT(poly88);
r9675r9676
2543
2644/*----------- defined in video/poly88.c -----------*/
2745
28extern UINT8 *poly88_video_ram;
29
3046extern VIDEO_START( poly88 );
3147extern VIDEO_UPDATE( poly88 );
3248
src/mess/includes/ut88.h
r9675r9676
99
1010#include "machine/i8255a.h"
1111
12class ut88_state : public driver_device
13{
14public:
15   ut88_state(running_machine &machine, const driver_device_config_base &config)
16      : driver_device(machine, config) { }
17
18   UINT8 *video_ram;
19   int keyboard_mask;
20   int lcd_digit[6];
21};
22
23
1224/*----------- defined in machine/ut88.c -----------*/
1325
1426extern const i8255a_interface ut88_ppi8255_interface;
r9675r9676
2840
2941/*----------- defined in video/ut88.c -----------*/
3042
31extern UINT8 *ut88_video_ram;
3243extern const gfx_layout ut88_charlayout;
3344
3445extern VIDEO_START( ut88 );
src/mess/includes/z1013.h
r9675r9676
1111#include "devices/snapquik.h"
1212
1313
14class z1013_state : public driver_device
15{
16public:
17   z1013_state(running_machine &machine, const driver_device_config_base &config)
18      : driver_device(machine, config) { }
19
20   UINT8 *video_ram;
21   UINT8 keyboard_line;
22   UINT8 keyboard_part;
23};
24
25
1426/*----------- defined in machine/z1013.c -----------*/
1527
1628extern const z80pio_interface z1013_z80pio_intf;
r9675r9676
2436extern SNAPSHOT_LOAD( z1013 );
2537
2638/*----------- defined in video/z1013.c -----------*/
27extern UINT8 *z1013_video_ram;
2839
2940VIDEO_START( z1013 );
3041VIDEO_UPDATE( z1013 );
src/mess/includes/primo.h
r9675r9676
1010#include "devices/snapquik.h"
1111
1212
13class primo_state : public driver_device
14{
15public:
16   primo_state(running_machine &machine, const driver_device_config_base &config)
17      : driver_device(machine, config) { }
18
19   UINT16 video_memory_base;
20   UINT8 port_FD;
21   int nmi;
22};
23
24
1325/*----------- defined in machine/primo.c -----------*/
1426
1527extern READ8_HANDLER ( primo_be_1_r );
r9675r9676
3042/*----------- defined in video/primo.c -----------*/
3143
3244extern VIDEO_UPDATE( primo );
33extern UINT16 primo_video_memory_base;
3445
3546
3647#endif /* PRIMO_H_ */
src/mess/includes/ti85.h
r9675r9676
1010#include "devices/snapquik.h"
1111
1212
13class ti85_state : public driver_device
14{
15public:
16   ti85_state(running_machine &machine, const driver_device_config_base &config)
17      : driver_device(machine, config),
18        m_nvram(*this, "nvram") { }
19
20   optional_shared_ptr<UINT8>   m_nvram;
21   UINT8 LCD_memory_base;
22   UINT8 LCD_contrast;
23   UINT8 LCD_status;
24   UINT8 timer_interrupt_mask;
25   UINT8 ti82_video_buffer[0x300];
26   UINT8 ti_calculator_model;
27   UINT8 timer_interrupt_status;
28   UINT8 ON_interrupt_mask;
29   UINT8 ON_interrupt_status;
30   UINT8 ON_pressed;
31   UINT8 ti8x_memory_page_1;
32   UINT8 ti8x_memory_page_2;
33   UINT8 LCD_mask;
34   UINT8 power_mode;
35   UINT8 keypad_mask;
36   UINT8 video_buffer_width;
37   UINT8 interrupt_speed;
38   UINT8 port4_bit0;
39   UINT8 ti81_port_7_data;
40   UINT8 *ti8x_ram;
41   UINT8 PCR;
42   UINT8 red_out;
43   UINT8 white_out;
44   UINT8 ti82_video_mode;
45   UINT8 ti82_video_x;
46   UINT8 ti82_video_y;
47   UINT8 ti82_video_dir;
48   UINT8 ti82_video_scroll;
49   UINT8 ti82_video_bit;
50   UINT8 ti82_video_col;
51   UINT8 ti8x_port2;
52   UINT8 ti83p_port4;
53   int ti_video_memory_size;
54   int ti_screen_x_size;
55   int ti_screen_y_size;
56   int ti_number_of_frames;
57   UINT8 * frames;
58};
59
60
1361/*----------- defined in machine/ti85.c -----------*/
1462
15extern UINT8 ti85_LCD_memory_base;
16extern UINT8 ti85_LCD_contrast;
17extern UINT8 ti85_LCD_status;
18extern UINT8 ti85_timer_interrupt_mask;
19extern UINT8 ti82_video_buffer[0x300];
20
2163MACHINE_START( ti81 );
2264MACHINE_START( ti82 );
2365MACHINE_START( ti85 );
src/mess/drivers/pc6001.c
r9675r9676
133133#include "devices/cartslot.h"
134134#include "formats/p6001_cas.h"
135135
136static UINT8 *pc6001_ram;
137static UINT8 *pc6001_video_ram;
138static UINT8 irq_vector = 0x00;
139static UINT8 cas_switch,sys_latch;
140static UINT8 timer_irq_mask;
141static UINT32 cas_offset;
142static UINT32 cas_maxsize;
143static emu_timer *timer_irq_timer;
144static UINT16 timer_hz_div;
136
137class pc6001_state : public driver_device
138{
139public:
140   pc6001_state(running_machine &machine, const driver_device_config_base &config)
141      : driver_device(machine, config) { }
142
143   UINT8 *ram;
144   UINT8 *video_ram;
145   UINT8 irq_vector;
146   UINT8 cas_switch;
147   UINT8 sys_latch;
148   UINT8 timer_irq_mask;
149   UINT32 cas_offset;
150   UINT32 cas_maxsize;
151   emu_timer *timer_irq_timer;
152   UINT16 timer_hz_div;
153   UINT8 ex_vram_bank;
154   UINT8 bgcol_bank;
155   UINT8 exgfx_text_mode;
156   UINT8 exgfx_bitmap_mode;
157   UINT8 exgfx_2bpp_mode;
158   UINT8 bank_r0;
159   UINT8 bank_r1;
160   UINT8 gfx_bank_on;
161   UINT8 bank_w;
162   UINT8 bank_opt;
163   UINT8 timer_irq_mask2;
164   UINT8 timer_irq_vector;
165   UINT32 cgrom_bank_addr;
166   UINT8 sr_video_mode;
167   UINT8 port_c_8255;
168   UINT8 cur_keycode;
169   UINT8 sr_bank_r[8];
170   UINT8 sr_bank_w[8];
171   UINT8 kludge;
172   UINT32 old_key1;
173   UINT32 old_key2;
174   UINT32 old_key3;
175};
176
177
145178/* PC6001mk2 specific */
146static UINT8 ex_vram_bank, bgcol_bank,exgfx_text_mode,exgfx_bitmap_mode,exgfx_2bpp_mode;
147static UINT8 bank_r0,bank_r1,gfx_bank_on,bank_w,bank_opt;
148static UINT8 timer_irq_mask2, timer_irq_vector;
149static UINT32 cgrom_bank_addr;
150179/* PC6001SR specific */
151static UINT8 sr_video_mode;
152180
153181#define IRQ_LOG (0)
154182
155183static VIDEO_START( pc6001 )
156184{
185   pc6001_state *state = machine->driver_data<pc6001_state>();
157186   #if 0
158187   m6847_config cfg;
159188
r9675r9676
164193   cfg.get_char_rom = pc6001_get_char_rom;
165194   m6847_init(machine, &cfg);
166195   #endif
167   pc6001_video_ram = auto_alloc_array(machine, UINT8, 0x4000);
196   state->video_ram = auto_alloc_array(machine, UINT8, 0x4000);
168197}
169198
170199/* this is known as gfx mode 4 */
171200static void draw_gfx_mode4(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int attr)
172201{
202   pc6001_state *state = machine->driver_data<pc6001_state>();
173203   int x,y,xi;
174204   int fgcol,color;
175205   int col_setting;
r9675r9676
191221   {
192222      for(x=0;x<32;x++)
193223      {
194         int tile = pc6001_video_ram[(x+(y*32))+0x200];
224         int tile = state->video_ram[(x+(y*32))+0x200];
195225
196226         if(col_setting == 0x00) //monochrome
197227         {
r9675r9676
222252
223253static void draw_bitmap_2bpp(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect, int attr)
224254{
255   pc6001_state *state = machine->driver_data<pc6001_state>();
225256   int color,x,y,xi,yi;
226257
227258   int shrink_x = 2*4;
r9675r9676
233264   {
234265      for(x=0;x<w;x++)
235266      {
236         int tile = pc6001_video_ram[(x+(y*32))+0x200];
267         int tile = state->video_ram[(x+(y*32))+0x200];
237268
238269         for(yi=0;yi<shrink_y;yi++)
239270         {
r9675r9676
343374
344375static void pc6001_screen_draw(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect, int has_mc6847)
345376{
377   pc6001_state *state = machine->driver_data<pc6001_state>();
346378   int x,y;
347379   int tile,attr;
348380
349   attr = pc6001_video_ram[0];
381   attr = state->video_ram[0];
350382
351383   draw_border(machine,bitmap,cliprect,attr,has_mc6847);
352384
r9675r9676
367399      {
368400         for(x=0;x<32;x++)
369401         {
370            tile = pc6001_video_ram[(x+(y*32))+0x200];
371            attr = pc6001_video_ram[(x+(y*32)) & 0x1ff];
402            tile = state->video_ram[(x+(y*32))+0x200];
403            attr = state->video_ram[(x+(y*32)) & 0x1ff];
372404
373405            if(attr & 0x40)
374406            {
r9675r9676
392424
393425static VIDEO_UPDATE( pc6001m2 )
394426{
427   pc6001_state *state = screen->machine->driver_data<pc6001_state>();
395428   int x,y,tile,attr;
396429
397430   /* note: bitmap mode have priority over everything else, check American Truck */
398   if(exgfx_bitmap_mode)
431   if(state->exgfx_bitmap_mode)
399432   {
400433      int count,color,i;
401434
r9675r9676
419452                    color |= pal_num[(pen[0] & 3) | ((pen[1] & 3) << 2)];
420453                    */
421454
422               pen[0] = pc6001_video_ram[count+0x0000] >> (6-i*2) & 3;
423               pen[1] = pc6001_video_ram[count+0x2000] >> (6-i*2) & 3;
455               pen[0] = state->video_ram[count+0x0000] >> (6-i*2) & 3;
456               pen[1] = state->video_ram[count+0x2000] >> (6-i*2) & 3;
424457
425458               color = 0x10;
426459               color |= ((pen[0] & 1) << 2);
r9675r9676
438471         }
439472      }
440473   }
441   else if(exgfx_2bpp_mode)
474   else if(state->exgfx_2bpp_mode)
442475   {
443476      int count,color,i;
444477
r9675r9676
459492                    color |= pal_num[(pen[0] & 1) | ((pen[1] & 1) << 1)];
460493                    */
461494
462               pen[0] = pc6001_video_ram[count+0x0000] >> (7-i) & 1;
463               pen[1] = pc6001_video_ram[count+0x2000] >> (7-i) & 1;
495               pen[0] = state->video_ram[count+0x0000] >> (7-i) & 1;
496               pen[1] = state->video_ram[count+0x2000] >> (7-i) & 1;
464497
465               if(bgcol_bank & 4) //PC-6001 emulation mode
498               if(state->bgcol_bank & 4) //PC-6001 emulation mode
466499               {
467500                  color = 0x08;
468501                  color |= (pen[0]) | (pen[1]<<1);
469                  color |= (bgcol_bank & 1) << 2;
502                  color |= (state->bgcol_bank & 1) << 2;
470503               }
471504               else //Mk-2 mode
472505               {
473506                  color = 0x10;
474507                  color |= ((pen[0] & 1) << 2);
475508                  color |= ((pen[1] & 1) >> 0);
476                  color |= ((bgcol_bank & 1) << 1);
477                  color |= ((bgcol_bank & 2) << 2);
509                  color |= ((state->bgcol_bank & 1) << 1);
510                  color |= ((state->bgcol_bank & 2) << 2);
478511               }
479512
480513               if ((x+i) <= screen->visible_area().max_x && (y) <= screen->visible_area().max_y)
r9675r9676
486519      }
487520
488521   }
489   else if(exgfx_text_mode)
522   else if(state->exgfx_text_mode)
490523   {
491524      int xi,yi,pen,fgcol,bgcol,color;
492525      UINT8 *gfx_data = memory_region(screen->machine, "gfx1");
r9675r9676
502535                ---- xxxx fg color
503536                Note that the exgfx banks a different gfx ROM
504537                */
505            tile = pc6001_video_ram[(x+(y*40))+0x400] + 0x200;
506            attr = pc6001_video_ram[(x+(y*40)) & 0x3ff];
538            tile = state->video_ram[(x+(y*40))+0x400] + 0x200;
539            attr = state->video_ram[(x+(y*40)) & 0x3ff];
507540            tile+= ((attr & 0x80) << 1);
508541
509542            for(yi=0;yi<12;yi++)
r9675r9676
513546                  pen = gfx_data[(tile*0x10)+yi]>>(7-xi) & 1;
514547
515548                  fgcol = (attr & 0x0f) + 0x10;
516                  bgcol = ((attr & 0x70) >> 4) + 0x10 + ((bgcol_bank & 2) << 2);
549                  bgcol = ((attr & 0x70) >> 4) + 0x10 + ((state->bgcol_bank & 2) << 2);
517550
518551                  color = pen ? fgcol : bgcol;
519552
r9675r9676
526559   }
527560   else
528561   {
529      attr = pc6001_video_ram[0];
562      attr = state->video_ram[0];
530563      pc6001_screen_draw(screen->machine,bitmap,cliprect,0);
531564   }
532565
r9675r9676
535568
536569static VIDEO_UPDATE( pc6001sr )
537570{
571   pc6001_state *state = screen->machine->driver_data<pc6001_state>();
538572   int x,y,tile,attr;
539573   int xi,yi,pen,fgcol,bgcol,color;
540574   UINT8 *gfx_data = memory_region(screen->machine, "gfx1");
541575
542576
543   if(sr_video_mode & 8) // text mode
577   if(state->sr_video_mode & 8) // text mode
544578   {
545579      for(y=0;y<20;y++)
546580      {
547581         for(x=0;x<40;x++)
548582         {
549            tile = pc6001_video_ram[(x+(y*40))*2+0];
550            attr = pc6001_video_ram[(x+(y*40))*2+1];
583            tile = state->video_ram[(x+(y*40))*2+0];
584            attr = state->video_ram[(x+(y*40))*2+1];
551585            tile+= ((attr & 0x80) << 1);
552586
553587            for(yi=0;yi<12;yi++)
r9675r9676
557591                  pen = gfx_data[(tile*0x10)+yi]>>(7-xi) & 1;
558592
559593                  fgcol = (attr & 0x0f) + 0x10;
560                  bgcol = ((attr & 0x70) >> 4) + 0x10 + ((bgcol_bank & 2) << 2);
594                  bgcol = ((attr & 0x70) >> 4) + 0x10 + ((state->bgcol_bank & 2) << 2);
561595
562596                  color = pen ? fgcol : bgcol;
563597
r9675r9676
578612      {
579613         for(x=0;x<320;x+=4)
580614         {
581            color = pc6001_video_ram[count] & 0x0f;
615            color = state->video_ram[count] & 0x0f;
582616
583617            if ((x+0) <= screen->visible_area().max_x && (y+0) <= screen->visible_area().max_y)
584618               *BITMAP_ADDR16(bitmap, (y+0), (x+0)) = screen->machine->pens[color+0x10];
585619
586            color = (pc6001_video_ram[count] & 0xf0) >> 4;
620            color = (state->video_ram[count] & 0xf0) >> 4;
587621
588622            if ((x+1) <= screen->visible_area().max_x && (y+0) <= screen->visible_area().max_y)
589623               *BITMAP_ADDR16(bitmap, (y+0), (x+1)) = screen->machine->pens[color+0x10];
590624
591            color = pc6001_video_ram[count+1] & 0x0f;
625            color = state->video_ram[count+1] & 0x0f;
592626
593627            if ((x+2) <= screen->visible_area().max_x && (y+0) <= screen->visible_area().max_y)
594628               *BITMAP_ADDR16(bitmap, (y+0), (x+2)) = screen->machine->pens[color+0x10];
595629
596            color = (pc6001_video_ram[count+1] & 0xf0) >> 4;
630            color = (state->video_ram[count+1] & 0xf0) >> 4;
597631
598632            if ((x+3) <= screen->visible_area().max_x && (y+0) <= screen->visible_area().max_y)
599633               *BITMAP_ADDR16(bitmap, (y+0), (x+3)) = screen->machine->pens[color+0x10];
600634
601            color = pc6001_video_ram[count+2] & 0x0f;
635            color = state->video_ram[count+2] & 0x0f;
602636
603637            if ((x+0) <= screen->visible_area().max_x && (y+1) <= screen->visible_area().max_y)
604638               *BITMAP_ADDR16(bitmap, (y+1), (x+0)) = screen->machine->pens[color+0x10];
605639
606            color = (pc6001_video_ram[count+2] & 0xf0) >> 4;
640            color = (state->video_ram[count+2] & 0xf0) >> 4;
607641
608642            if ((x+1) <= screen->visible_area().max_x && (y+1) <= screen->visible_area().max_y)
609643               *BITMAP_ADDR16(bitmap, (y+1), (x+1)) = screen->machine->pens[color+0x10];
610644
611            color = pc6001_video_ram[count+3] & 0x0f;
645            color = state->video_ram[count+3] & 0x0f;
612646
613647            if ((x+2) <= screen->visible_area().max_x && (y+1) <= screen->visible_area().max_y)
614648               *BITMAP_ADDR16(bitmap, (y+1), (x+2)) = screen->machine->pens[color+0x10];
615649
616            color = (pc6001_video_ram[count+3] & 0xf0) >> 4;
650            color = (state->video_ram[count+3] & 0xf0) >> 4;
617651
618652            if ((x+3) <= screen->visible_area().max_x && (y+1) <= screen->visible_area().max_y)
619653               *BITMAP_ADDR16(bitmap, (y+1), (x+3)) = screen->machine->pens[color+0x10];
r9675r9676
629663
630664static WRITE8_HANDLER ( pc6001_system_latch_w )
631665{
666   pc6001_state *state = space->machine->driver_data<pc6001_state>();
632667   UINT16 startaddr[] = {0xC000, 0xE000, 0x8000, 0xA000 };
633668
634   pc6001_video_ram =  pc6001_ram + startaddr[(data >> 1) & 0x03] - 0x8000;
669   state->video_ram =  state->ram + startaddr[(data >> 1) & 0x03] - 0x8000;
635670
636   if((!(sys_latch & 8)) && data & 0x8) //PLAY tape cmd
671   if((!(state->sys_latch & 8)) && data & 0x8) //PLAY tape cmd
637672   {
638      cas_switch = 1;
673      state->cas_switch = 1;
639674      //cassette_change_state(space->machine->device("cass" ),CASSETTE_MOTOR_ENABLED,CASSETTE_MASK_MOTOR);
640675      //cassette_change_state(space->machine->device("cass" ),CASSETTE_PLAY,CASSETTE_MASK_UISTATE);
641676   }
642   if((sys_latch & 8) && ((data & 0x8) == 0)) //STOP tape cmd
677   if((state->sys_latch & 8) && ((data & 0x8) == 0)) //STOP tape cmd
643678   {
644      cas_switch = 0;
679      state->cas_switch = 0;
645680      //cassette_change_state(space->machine->device("cass" ),CASSETTE_MOTOR_DISABLED,CASSETTE_MASK_MOTOR);
646681      //cassette_change_state(space->machine->device("cass" ),CASSETTE_STOPPED,CASSETTE_MASK_UISTATE);
647      //irq_vector = 0x00;
682      //state->irq_vector = 0x00;
648683      //cputag_set_input_line(space->machine,"maincpu", 0, ASSERT_LINE);
649684   }
650685
651   sys_latch = data;
652   timer_irq_mask = data & 1;
686   state->sys_latch = data;
687   state->timer_irq_mask = data & 1;
653688   //printf("%02x\n",data);
654689}
655690
656691#if 0
657692static ATTR_CONST UINT8 pc6001_get_attributes(running_machine *machine, UINT8 c,int scanline, int pos)
658693{
694   pc6001_state *state = machine->driver_data<pc6001_state>();
659695   UINT8 result = 0x00;
660   UINT8 val = pc6001_video_ram [(scanline / 12) * 0x20 + pos];
696   UINT8 val = state->video_ram [(scanline / 12) * 0x20 + pos];
661697
662698   if (val & 0x01) {
663699      result |= M6847_INV;
r9675r9676
671707
672708static const UINT8 *pc6001_get_video_ram(running_machine *machine, int scanline)
673709{
674   return pc6001_video_ram +0x0200+ (scanline / 12) * 0x20;
710   pc6001_state *state = machine->driver_data<pc6001_state>();
711   return state->video_ram +0x0200+ (scanline / 12) * 0x20;
675712}
676713
677714static UINT8 pc6001_get_char_rom(running_machine *machine, UINT8 ch, int line)
r9675r9676
681718}
682719#endif
683720
684static UINT8 port_c_8255,cur_keycode;
685721
686722static READ8_DEVICE_HANDLER(nec_ppi8255_r)
687723{
724   pc6001_state *state = device->machine->driver_data<pc6001_state>();
688725   if (offset==2)
689      return port_c_8255;
726      return state->port_c_8255;
690727   else if(offset==0)
691728   {
692729      UINT8 res;
693      res = cur_keycode;
694      //cur_keycode = 0;
730      res = state->cur_keycode;
731      //state->cur_keycode = 0;
695732      return res;
696733   }
697734
r9675r9676
700737
701738static WRITE8_DEVICE_HANDLER(nec_ppi8255_w)
702739{
740   pc6001_state *state = device->machine->driver_data<pc6001_state>();
703741   if (offset==3)
704742   {
705743      if(data & 1)
706         port_c_8255 |=   1<<((data>>1)&0x07);
744         state->port_c_8255 |=   1<<((data>>1)&0x07);
707745      else
708         port_c_8255 &= ~(1<<((data>>1)&0x07));
746         state->port_c_8255 &= ~(1<<((data>>1)&0x07));
709747
710748      switch(data) {
711           case 0x08: port_c_8255 |= 0x88; break;
712           case 0x09: port_c_8255 &= 0xf7; break;
713           case 0x0c: port_c_8255 |= 0x28; break;
714           case 0x0d: port_c_8255 &= 0xf7; break;
749           case 0x08: state->port_c_8255 |= 0x88; break;
750           case 0x09: state->port_c_8255 &= 0xf7; break;
751           case 0x0c: state->port_c_8255 |= 0x28; break;
752           case 0x0d: state->port_c_8255 &= 0xf7; break;
715753           default: break;
716754      }
717755
718      port_c_8255 |= 0xa8;
756      state->port_c_8255 |= 0xa8;
719757
720758      {
721759         UINT8 *gfx_data = memory_region(device->machine, "gfx1");
r9675r9676
737775   AM_RANGE(0x0000, 0x3fff) AM_ROM AM_WRITENOP
738776   AM_RANGE(0x4000, 0x5fff) AM_ROM AM_REGION("cart_img",0)
739777   AM_RANGE(0x6000, 0x7fff) AM_ROMBANK("bank1")
740   AM_RANGE(0x8000, 0xffff) AM_RAM AM_BASE(&pc6001_ram)
778   AM_RANGE(0x8000, 0xffff) AM_RAM AM_BASE_MEMBER(pc6001_state, ram)
741779ADDRESS_MAP_END
742780
743781static ADDRESS_MAP_START( pc6001_io , ADDRESS_SPACE_IO, 8)
r9675r9676
932970
933971static WRITE8_HANDLER( pc6001m2_bank_r0_w )
934972{
973   pc6001_state *state = space->machine->driver_data<pc6001_state>();
935974   UINT8 *ROM = memory_region(space->machine, "maincpu");
936975   UINT8 *gfx_data = memory_region(space->machine, "gfx1");
937976
938977//  bankaddress = 0x10000 + (0x4000 * ((data & 0x40)>>6));
939978//  memory_set_bankptr(space->machine, 1, &ROM[bankaddress]);
940979
941   bank_r0 = data;
980   state->bank_r0 = data;
942981
943//  printf("%02x BANK | %02x\n",data,bank_opt);
944   memory_set_bankptr(space->machine, "bank1", &ROM[banksw_table_r0[(data & 0xf)+(bank_opt*0x10)][0]]);
945   memory_set_bankptr(space->machine, "bank2", &ROM[banksw_table_r0[(data & 0xf)+(bank_opt*0x10)][1]]);
946   memory_set_bankptr(space->machine, "bank3", &ROM[banksw_table_r0[((data & 0xf0)>>4)+(bank_opt*0x10)][2]]);
947   if(!gfx_bank_on)
948      memory_set_bankptr(space->machine, "bank4", &ROM[banksw_table_r0[((bank_r0 & 0xf0)>>4)+(bank_opt*0x10)][3]]);
982//  printf("%02x BANK | %02x\n",data,state->bank_opt);
983   memory_set_bankptr(space->machine, "bank1", &ROM[banksw_table_r0[(data & 0xf)+(state->bank_opt*0x10)][0]]);
984   memory_set_bankptr(space->machine, "bank2", &ROM[banksw_table_r0[(data & 0xf)+(state->bank_opt*0x10)][1]]);
985   memory_set_bankptr(space->machine, "bank3", &ROM[banksw_table_r0[((data & 0xf0)>>4)+(state->bank_opt*0x10)][2]]);
986   if(!state->gfx_bank_on)
987      memory_set_bankptr(space->machine, "bank4", &ROM[banksw_table_r0[((state->bank_r0 & 0xf0)>>4)+(state->bank_opt*0x10)][3]]);
949988   else
950      memory_set_bankptr(space->machine, "bank4", &gfx_data[cgrom_bank_addr]);
989      memory_set_bankptr(space->machine, "bank4", &gfx_data[state->cgrom_bank_addr]);
951990}
952991
953992static WRITE8_HANDLER( pc6001m2_bank_r1_w )
954993{
994   pc6001_state *state = space->machine->driver_data<pc6001_state>();
955995   UINT8 *ROM = memory_region(space->machine, "maincpu");
956996
957997//  bankaddress = 0x10000 + (0x4000 * ((data & 0x40)>>6));
958998//  memory_set_bankptr(space->machine, 1, &ROM[bankaddress]);
959999
960   bank_r1 = data;
1000   state->bank_r1 = data;
9611001
9621002//  printf("%02x BANK\n",data);
963   memory_set_bankptr(space->machine, "bank5", &ROM[banksw_table_r1[(data & 0xf)+(bank_opt*0x10)][0]]);
964   memory_set_bankptr(space->machine, "bank6", &ROM[banksw_table_r1[(data & 0xf)+(bank_opt*0x10)][1]]);
965   memory_set_bankptr(space->machine, "bank7", &ROM[banksw_table_r1[((data & 0xf0)>>4)+(bank_opt*0x10)][2]]);
966   memory_set_bankptr(space->machine, "bank8", &ROM[banksw_table_r1[((data & 0xf0)>>4)+(bank_opt*0x10)][3]]);
1003   memory_set_bankptr(space->machine, "bank5", &ROM[banksw_table_r1[(data & 0xf)+(state->bank_opt*0x10)][0]]);
1004   memory_set_bankptr(space->machine, "bank6", &ROM[banksw_table_r1[(data & 0xf)+(state->bank_opt*0x10)][1]]);
1005   memory_set_bankptr(space->machine, "bank7", &ROM[banksw_table_r1[((data & 0xf0)>>4)+(state->bank_opt*0x10)][2]]);
1006   memory_set_bankptr(space->machine, "bank8", &ROM[banksw_table_r1[((data & 0xf0)>>4)+(state->bank_opt*0x10)][3]]);
9671007}
9681008
9691009static WRITE8_HANDLER( pc6001m2_bank_w0_w )
9701010{
971   bank_w = data;
1011   pc6001_state *state = space->machine->driver_data<pc6001_state>();
1012   state->bank_w = data;
9721013}
9731014
9741015static WRITE8_HANDLER( pc6001m2_opt_bank_w )
9751016{
1017   pc6001_state *state = space->machine->driver_data<pc6001_state>();
9761018   UINT8 *ROM = memory_region(space->machine, "maincpu");
9771019   UINT8 *gfx_data = memory_region(space->machine, "gfx1");
9781020
r9675r9676
9821024    2 - KANJI ROM bank 1
9831025    3 - TVROM / VOICE ROM
9841026    */
985   bank_opt = data & 3;
1027   state->bank_opt = data & 3;
9861028
987   memory_set_bankptr(space->machine, "bank1", &ROM[banksw_table_r0[(bank_r0 & 0xf)+(bank_opt*0x10)][0]]);
988   memory_set_bankptr(space->machine, "bank2", &ROM[banksw_table_r0[(bank_r0 & 0xf)+(bank_opt*0x10)][1]]);
989   memory_set_bankptr(space->machine, "bank3", &ROM[banksw_table_r0[((bank_r0 & 0xf0)>>4)+(bank_opt*0x10)][2]]);
990   if(!gfx_bank_on)
991      memory_set_bankptr(space->machine, "bank4", &ROM[banksw_table_r0[((bank_r0 & 0xf0)>>4)+(bank_opt*0x10)][3]]);
1029   memory_set_bankptr(space->machine, "bank1", &ROM[banksw_table_r0[(state->bank_r0 & 0xf)+(state->bank_opt*0x10)][0]]);
1030   memory_set_bankptr(space->machine, "bank2", &ROM[banksw_table_r0[(state->bank_r0 & 0xf)+(state->bank_opt*0x10)][1]]);
1031   memory_set_bankptr(space->machine, "bank3", &ROM[banksw_table_r0[((state->bank_r0 & 0xf0)>>4)+(state->bank_opt*0x10)][2]]);
1032   if(!state->gfx_bank_on)
1033      memory_set_bankptr(space->machine, "bank4", &ROM[banksw_table_r0[((state->bank_r0 & 0xf0)>>4)+(state->bank_opt*0x10)][3]]);
9921034   else
993      memory_set_bankptr(space->machine, "bank4", &gfx_data[cgrom_bank_addr]);
994   memory_set_bankptr(space->machine, "bank4", &ROM[banksw_table_r0[((bank_r0 & 0xf0)>>4)+(bank_opt*0x10)][3]]);
995   memory_set_bankptr(space->machine, "bank5", &ROM[banksw_table_r1[(bank_r1 & 0xf)+(bank_opt*0x10)][0]]);
996   memory_set_bankptr(space->machine, "bank6", &ROM[banksw_table_r1[(bank_r1 & 0xf)+(bank_opt*0x10)][1]]);
997   memory_set_bankptr(space->machine, "bank7", &ROM[banksw_table_r1[((bank_r1 & 0xf0)>>4)+(bank_opt*0x10)][2]]);
998   memory_set_bankptr(space->machine, "bank8", &ROM[banksw_table_r1[((bank_r1 & 0xf0)>>4)+(bank_opt*0x10)][3]]);
1035      memory_set_bankptr(space->machine, "bank4", &gfx_data[state->cgrom_bank_addr]);
1036   memory_set_bankptr(space->machine, "bank4", &ROM[banksw_table_r0[((state->bank_r0 & 0xf0)>>4)+(state->bank_opt*0x10)][3]]);
1037   memory_set_bankptr(space->machine, "bank5", &ROM[banksw_table_r1[(state->bank_r1 & 0xf)+(state->bank_opt*0x10)][0]]);
1038   memory_set_bankptr(space->machine, "bank6", &ROM[banksw_table_r1[(state->bank_r1 & 0xf)+(state->bank_opt*0x10)][1]]);
1039   memory_set_bankptr(space->machine, "bank7", &ROM[banksw_table_r1[((state->bank_r1 & 0xf0)>>4)+(state->bank_opt*0x10)][2]]);
1040   memory_set_bankptr(space->machine, "bank8", &ROM[banksw_table_r1[((state->bank_r1 & 0xf0)>>4)+(state->bank_opt*0x10)][3]]);
9991041
10001042}
10011043
1002static WRITE8_HANDLER( work_ram0_w ) { UINT8 *ROM = memory_region(space->machine, "maincpu"); ROM[offset+((bank_w & 0x01) ? WRAM(0) : EXWRAM(0))] = data; }
1003static WRITE8_HANDLER( work_ram1_w ) { UINT8 *ROM = memory_region(space->machine, "maincpu"); ROM[offset+((bank_w & 0x01) ? WRAM(1) : EXWRAM(1))] = data; }
1004static WRITE8_HANDLER( work_ram2_w ) { UINT8 *ROM = memory_region(space->machine, "maincpu"); ROM[offset+((bank_w & 0x04) ? WRAM(2) : EXWRAM(2))] = data; }
1005static WRITE8_HANDLER( work_ram3_w ) { UINT8 *ROM = memory_region(space->machine, "maincpu"); ROM[offset+((bank_w & 0x04) ? WRAM(3) : EXWRAM(3))] = data; }
1006static WRITE8_HANDLER( work_ram4_w ) { UINT8 *ROM = memory_region(space->machine, "maincpu"); ROM[offset+((bank_w & 0x10) ? WRAM(4) : EXWRAM(4))] = data; }
1007static WRITE8_HANDLER( work_ram5_w ) { UINT8 *ROM = memory_region(space->machine, "maincpu"); ROM[offset+((bank_w & 0x10) ? WRAM(5) : EXWRAM(5))] = data; }
1008static WRITE8_HANDLER( work_ram6_w ) { UINT8 *ROM = memory_region(space->machine, "maincpu"); ROM[offset+((bank_w & 0x40) ? WRAM(6) : EXWRAM(6))] = data; }
1009static WRITE8_HANDLER( work_ram7_w ) { UINT8 *ROM = memory_region(space->machine, "maincpu"); ROM[offset+((bank_w & 0x40) ? WRAM(7) : EXWRAM(7))] = data; }
1044static WRITE8_HANDLER( work_ram0_w )
1045{
1046   pc6001_state *state = space->machine->driver_data<pc6001_state>();
1047   UINT8 *ROM = memory_region(space->machine, "maincpu");
1048   ROM[offset+((state->bank_w & 0x01) ? WRAM(0) : EXWRAM(0))] = data;
1049}
10101050
1051static WRITE8_HANDLER( work_ram1_w )
1052{
1053   pc6001_state *state = space->machine->driver_data<pc6001_state>();
1054   UINT8 *ROM = memory_region(space->machine, "maincpu");
1055   ROM[offset+((state->bank_w & 0x01) ? WRAM(1) : EXWRAM(1))] = data;
1056}
1057
1058static WRITE8_HANDLER( work_ram2_w )
1059{
1060   pc6001_state *state = space->machine->driver_data<pc6001_state>();
1061   UINT8 *ROM = memory_region(space->machine, "maincpu");
1062   ROM[offset+((state->bank_w & 0x04) ? WRAM(2) : EXWRAM(2))] = data;
1063}
1064
1065static WRITE8_HANDLER( work_ram3_w )
1066{
1067   pc6001_state *state = space->machine->driver_data<pc6001_state>();
1068   UINT8 *ROM = memory_region(space->machine, "maincpu");
1069   ROM[offset+((state->bank_w & 0x04) ? WRAM(3) : EXWRAM(3))] = data;
1070}
1071
1072static WRITE8_HANDLER( work_ram4_w )
1073{
1074   pc6001_state *state = space->machine->driver_data<pc6001_state>();
1075   UINT8 *ROM = memory_region(space->machine, "maincpu");
1076   ROM[offset+((state->bank_w & 0x10) ? WRAM(4) : EXWRAM(4))] = data;
1077}
1078
1079static WRITE8_HANDLER( work_ram5_w )
1080{
1081   pc6001_state *state = space->machine->driver_data<pc6001_state>();
1082   UINT8 *ROM = memory_region(space->machine, "maincpu");
1083   ROM[offset+((state->bank_w & 0x10) ? WRAM(5) : EXWRAM(5))] = data;
1084}
1085
1086static WRITE8_HANDLER( work_ram6_w )
1087{
1088   pc6001_state *state = space->machine->driver_data<pc6001_state>(); UINT8 *ROM = memory_region(space->machine, "maincpu"); ROM[offset+((state->bank_w & 0x40) ? WRAM(6) : EXWRAM(6))] = data;
1089}
1090
1091static WRITE8_HANDLER( work_ram7_w )
1092{
1093   pc6001_state *state = space->machine->driver_data<pc6001_state>(); UINT8 *ROM = memory_region(space->machine, "maincpu"); ROM[offset+((state->bank_w & 0x40) ? WRAM(7) : EXWRAM(7))] = data;
1094}
1095
1096
10111097static WRITE8_DEVICE_HANDLER(necmk2_ppi8255_w)
10121098{
1099   pc6001_state *state = device->machine->driver_data<pc6001_state>();
10131100   if (offset==3)
10141101   {
10151102      if(data & 1)
1016         port_c_8255 |=   1<<((data>>1)&0x07);
1103         state->port_c_8255 |=   1<<((data>>1)&0x07);
10171104      else
1018         port_c_8255 &= ~(1<<((data>>1)&0x07));
1105         state->port_c_8255 &= ~(1<<((data>>1)&0x07));
10191106
10201107      switch(data) {
1021           case 0x08: port_c_8255 |= 0x88; break;
1022           case 0x09: port_c_8255 &= 0xf7; break;
1023           case 0x0c: port_c_8255 |= 0x28; break;
1024           case 0x0d: port_c_8255 &= 0xf7; break;
1108           case 0x08: state->port_c_8255 |= 0x88; break;
1109           case 0x09: state->port_c_8255 &= 0xf7; break;
1110           case 0x0c: state->port_c_8255 |= 0x28; break;
1111           case 0x0d: state->port_c_8255 &= 0xf7; break;
10251112           default: break;
10261113      }
10271114
1028      port_c_8255 |= 0xa8;
1115      state->port_c_8255 |= 0xa8;
10291116
10301117      {
10311118         UINT8 *ROM = memory_region(device->machine, "maincpu");
r9675r9676
10351122
10361123         if((data & 0x0f) == 0x05)
10371124         {
1038            gfx_bank_on = 0;
1039            memory_set_bankptr(device->machine, "bank4", &ROM[banksw_table_r0[((bank_r0 & 0xf0)>>4)+(bank_opt*0x10)][3]]);
1125            state->gfx_bank_on = 0;
1126            memory_set_bankptr(device->machine, "bank4", &ROM[banksw_table_r0[((state->bank_r0 & 0xf0)>>4)+(state->bank_opt*0x10)][3]]);
10401127         }
10411128         if((data & 0x0f) == 0x04)
10421129         {
1043            gfx_bank_on = 1;
1044            memory_set_bankptr(device->machine, "bank4", &gfx_data[cgrom_bank_addr]);
1130            state->gfx_bank_on = 1;
1131            memory_set_bankptr(device->machine, "bank4", &gfx_data[state->cgrom_bank_addr]);
10451132         }
10461133      }
10471134   }
r9675r9676
10501137
10511138static void vram_bank_change(running_machine *machine,UINT8 vram_bank)
10521139{
1140   pc6001_state *state = machine->driver_data<pc6001_state>();
10531141   UINT8 *work_ram = memory_region(machine, "maincpu");
10541142
10551143//  popmessage("%02x",vram_bank);
10561144
10571145   switch(vram_bank & 0x66)
10581146   {
1059      case 0x00: pc6001_video_ram = work_ram + 0x8000 + 0x28000; break; //4 color mode
1060      case 0x02: pc6001_video_ram = work_ram + 0xc000 + 0x28000; break;
1061      case 0x04: pc6001_video_ram = work_ram + 0x8000 + 0x28000; break;
1062      case 0x06: pc6001_video_ram = work_ram + 0xc000 + 0x28000; break;
1063      case 0x20: pc6001_video_ram = work_ram + 0xc000 + 0x28000; break; //4 color mode
1064      case 0x22: pc6001_video_ram = work_ram + 0xe000 + 0x28000; break;
1065      case 0x24: pc6001_video_ram = work_ram + 0xc000 + 0x28000; break;
1066      case 0x26: pc6001_video_ram = work_ram + 0xe000 + 0x28000; break;
1067      case 0x40: pc6001_video_ram = work_ram + 0x0000 + 0x28000; break; //4 color mode
1068      case 0x42: pc6001_video_ram = work_ram + 0x8000 + 0x28000; break;
1069      case 0x44: pc6001_video_ram = work_ram + 0x0000 + 0x28000; break;
1070      case 0x46: pc6001_video_ram = work_ram + 0x8000 + 0x28000; break;
1071      case 0x60: pc6001_video_ram = work_ram + 0x4000 + 0x28000; break; //4 color mode
1072      case 0x62: pc6001_video_ram = work_ram + 0xa000 + 0x28000; break;
1073      case 0x64: pc6001_video_ram = work_ram + 0x4000 + 0x28000; break;
1074      case 0x66: pc6001_video_ram = work_ram + 0xa000 + 0x28000; break;
1147      case 0x00: state->video_ram = work_ram + 0x8000 + 0x28000; break; //4 color mode
1148      case 0x02: state->video_ram = work_ram + 0xc000 + 0x28000; break;
1149      case 0x04: state->video_ram = work_ram + 0x8000 + 0x28000; break;
1150      case 0x06: state->video_ram = work_ram + 0xc000 + 0x28000; break;
1151      case 0x20: state->video_ram = work_ram + 0xc000 + 0x28000; break; //4 color mode
1152      case 0x22: state->video_ram = work_ram + 0xe000 + 0x28000; break;
1153      case 0x24: state->video_ram = work_ram + 0xc000 + 0x28000; break;
1154      case 0x26: state->video_ram = work_ram + 0xe000 + 0x28000; break;
1155      case 0x40: state->video_ram = work_ram + 0x0000 + 0x28000; break; //4 color mode
1156      case 0x42: state->video_ram = work_ram + 0x8000 + 0x28000; break;
1157      case 0x44: state->video_ram = work_ram + 0x0000 + 0x28000; break;
1158      case 0x46: state->video_ram = work_ram + 0x8000 + 0x28000; break;
1159      case 0x60: state->video_ram = work_ram + 0x4000 + 0x28000; break; //4 color mode
1160      case 0x62: state->video_ram = work_ram + 0xa000 + 0x28000; break;
1161      case 0x64: state->video_ram = work_ram + 0x4000 + 0x28000; break;
1162      case 0x66: state->video_ram = work_ram + 0xa000 + 0x28000; break;
10751163   }
10761164}
10771165
10781166static WRITE8_HANDLER ( pc6001m2_system_latch_w )
10791167{
1080   if((!(sys_latch & 8)) && data & 0x8) //PLAY tape cmd
1168   pc6001_state *state = space->machine->driver_data<pc6001_state>();
1169   if((!(state->sys_latch & 8)) && data & 0x8) //PLAY tape cmd
10811170   {
1082      cas_switch = 1;
1171      state->cas_switch = 1;
10831172      //cassette_change_state(space->machine->device("cass" ),CASSETTE_MOTOR_ENABLED,CASSETTE_MASK_MOTOR);
10841173      //cassette_change_state(space->machine->device("cass" ),CASSETTE_PLAY,CASSETTE_MASK_UISTATE);
10851174   }
1086   if((sys_latch & 8) && ((data & 0x8) == 0)) //STOP tape cmd
1175   if((state->sys_latch & 8) && ((data & 0x8) == 0)) //STOP tape cmd
10871176   {
1088      cas_switch = 0;
1177      state->cas_switch = 0;
10891178      //cassette_change_state(space->machine->device("cass" ),CASSETTE_MOTOR_DISABLED,CASSETTE_MASK_MOTOR);
10901179      //cassette_change_state(space->machine->device("cass" ),CASSETTE_STOPPED,CASSETTE_MASK_UISTATE);
1091      //irq_vector = 0x00;
1180      //state->irq_vector = 0x00;
10921181      //cputag_set_input_line(space->machine,"maincpu", 0, ASSERT_LINE);
10931182   }
10941183
1095   sys_latch = data;
1184   state->sys_latch = data;
10961185
1097   timer_irq_mask = data & 1;
1098   vram_bank_change(space->machine,(ex_vram_bank & 0x06) | ((sys_latch & 0x06) << 4));
1186   state->timer_irq_mask = data & 1;
1187   vram_bank_change(space->machine,(state->ex_vram_bank & 0x06) | ((state->sys_latch & 0x06) << 4));
10991188
11001189   //printf("%02x B0\n",data);
11011190}
r9675r9676
11031192
11041193static WRITE8_HANDLER( pc6001m2_vram_bank_w )
11051194{
1195   pc6001_state *state = space->machine->driver_data<pc6001_state>();
11061196//  UINT32 startaddr[] = {WRAM(6), WRAM(6), WRAM(0), WRAM(4) };
11071197
1108   ex_vram_bank = data;
1109   vram_bank_change(space->machine,(ex_vram_bank & 0x06) | ((sys_latch & 0x06) << 4));
1198   state->ex_vram_bank = data;
1199   vram_bank_change(space->machine,(state->ex_vram_bank & 0x06) | ((state->sys_latch & 0x06) << 4));
11101200
1111   exgfx_text_mode = ((data & 2) == 0);
1112   cgrom_bank_addr = (data & 2) ? 0x0000 : 0x2000;
1201   state->exgfx_text_mode = ((data & 2) == 0);
1202   state->cgrom_bank_addr = (data & 2) ? 0x0000 : 0x2000;
11131203
1114   exgfx_bitmap_mode = (data & 8);
1115   exgfx_2bpp_mode = ((data & 6) == 0);
1204   state->exgfx_bitmap_mode = (data & 8);
1205   state->exgfx_2bpp_mode = ((data & 6) == 0);
11161206
11171207   {
11181208      /* Apparently bitmap modes changes the screen res to 320 x 200 */
r9675r9676
11201210         rectangle visarea = space->machine->primary_screen->visible_area();
11211211         int y_height;
11221212
1123         y_height = (exgfx_bitmap_mode || exgfx_2bpp_mode) ? 200 : 240;
1213         y_height = (state->exgfx_bitmap_mode || state->exgfx_2bpp_mode) ? 200 : 240;
11241214
11251215         visarea.min_x = visarea.min_y = 0;
11261216         visarea.max_y = (y_height) - 1;
r9675r9676
11321222
11331223//  popmessage("%02x",data);
11341224
1135//  pc6001_video_ram = work_ram + startaddr[(data >> 1) & 0x03];
1225//  state->video_ram = work_ram + startaddr[(data >> 1) & 0x03];
11361226}
11371227
11381228static WRITE8_HANDLER( pc6001m2_col_bank_w )
11391229{
1140   bgcol_bank = (data & 7);
1230   pc6001_state *state = space->machine->driver_data<pc6001_state>();
1231   state->bgcol_bank = (data & 7);
11411232}
11421233
11431234/* voice synth is a NEC uPD7752 sound chip (currently unemulated) */
r9675r9676
11811272
11821273static WRITE8_HANDLER( pc6001m2_0xf3_w )
11831274{
1275   pc6001_state *state = space->machine->driver_data<pc6001_state>();
11841276   /*
11851277    x--- ---- M1 (?) wait setting
11861278    -x-- ---- ROM wait setting
r9675r9676
11911283    ---- --x- custom irq 2 mask
11921284    ---- ---x custom irq 1 mask
11931285    */
1194   timer_irq_mask2 = data & 4;
1286   state->timer_irq_mask2 = data & 4;
11951287}
11961288
11971289static TIMER_CALLBACK(audio_callback)
11981290{
1199   if(cas_switch == 0 && ((timer_irq_mask == 0) || (timer_irq_mask2 == 0)))
1291   pc6001_state *state = machine->driver_data<pc6001_state>();
1292   if(state->cas_switch == 0 && ((state->timer_irq_mask == 0) || (state->timer_irq_mask2 == 0)))
12001293   {
1201      if(IRQ_LOG) printf("Timer IRQ called %02x\n",timer_irq_vector);
1202      irq_vector = timer_irq_vector;
1294      if(IRQ_LOG) printf("Timer IRQ called %02x\n",state->timer_irq_vector);
1295      state->irq_vector = state->timer_irq_vector;
12031296      cputag_set_input_line(machine,"maincpu", 0, ASSERT_LINE);
12041297   }
12051298}
r9675r9676
12071300
12081301static WRITE8_HANDLER( pc6001m2_timer_adj_w )
12091302{
1210   timer_hz_div = data;
1211   attotime period = ATTOTIME_IN_HZ((487.5*4)/(timer_hz_div+1));
1212   timer_adjust_periodic(timer_irq_timer, period,  0, period);
1303   pc6001_state *state = space->machine->driver_data<pc6001_state>();
1304   state->timer_hz_div = data;
1305   attotime period = ATTOTIME_IN_HZ((487.5*4)/(state->timer_hz_div+1));
1306   timer_adjust_periodic(state->timer_irq_timer, period,  0, period);
12131307}
12141308
12151309static WRITE8_HANDLER( pc6001m2_timer_irqv_w )
12161310{
1217   timer_irq_vector = data;
1311   pc6001_state *state = space->machine->driver_data<pc6001_state>();
1312   state->timer_irq_vector = data;
12181313}
12191314
12201315static READ8_HANDLER( pc6001m2_bank_r0_r )
12211316{
1222   return bank_r0;
1317   pc6001_state *state = space->machine->driver_data<pc6001_state>();
1318   return state->bank_r0;
12231319}
12241320
12251321static READ8_HANDLER( pc6001m2_bank_r1_r )
12261322{
1227   return bank_r1;
1323   pc6001_state *state = space->machine->driver_data<pc6001_state>();
1324   return state->bank_r1;
12281325}
12291326
12301327static READ8_HANDLER( pc6001m2_bank_w0_r )
12311328{
1232   return bank_w;
1329   pc6001_state *state = space->machine->driver_data<pc6001_state>();
1330   return state->bank_w;
12331331}
12341332
12351333static ADDRESS_MAP_START(pc6001m2_map, ADDRESS_SPACE_PROGRAM, 8)
r9675r9676
13251423ADDRESS_MAP_END
13261424
13271425/* PC-6001 SR */
1328static UINT8 sr_bank_r[8],sr_bank_w[8];
13291426
13301427#define SR_SYSROM_1(_v_) \
13311428   0x10000+(0x1000*_v_) \
r9675r9676
13531450
13541451static READ8_HANDLER( pc6001sr_bank_rn_r )
13551452{
1356   return sr_bank_r[offset];
1453   pc6001_state *state = space->machine->driver_data<pc6001_state>();
1454   return state->sr_bank_r[offset];
13571455}
13581456
13591457static WRITE8_HANDLER( pc6001sr_bank_rn_w )
13601458{
1459   pc6001_state *state = space->machine->driver_data<pc6001_state>();
13611460   const char* bank_name[8] = { "bank1","bank2","bank3", "bank4", "bank5", "bank6", "bank7", "bank8" };
13621461   UINT8 *ROM = memory_region(space->machine, "maincpu");
13631462   UINT8 bank_num;
13641463
1365   sr_bank_r[offset] = data;
1464   state->sr_bank_r[offset] = data;
13661465   bank_num = data & 0x0f;
13671466
13681467   switch(data & 0xf0)
r9675r9676
13801479
13811480static READ8_HANDLER( pc6001sr_bank_wn_r )
13821481{
1383   return sr_bank_w[offset];
1482   pc6001_state *state = space->machine->driver_data<pc6001_state>();
1483   return state->sr_bank_w[offset];
13841484}
13851485
13861486static WRITE8_HANDLER( pc6001sr_bank_wn_w )
13871487{
1388   sr_bank_w[offset] = data;
1488   pc6001_state *state = space->machine->driver_data<pc6001_state>();
1489   state->sr_bank_w[offset] = data;
13891490}
13901491
13911492#define SR_WRAM_BANK_W(_v_) \
13921493{ \
1494   pc6001_state *state = space->machine->driver_data<pc6001_state>(); \
13931495   UINT8 *ROM = memory_region(space->machine, "maincpu"); \
13941496   UINT8 bank_num; \
1395   bank_num = sr_bank_w[_v_] & 0x0f; \
1396   if((sr_bank_w[_v_] & 0xf0) != 0x20) \
1497   bank_num = state->sr_bank_w[_v_] & 0x0f; \
1498   if((state->sr_bank_w[_v_] & 0xf0) != 0x20) \
13971499      ROM[offset+(SR_WRAM0(bank_num))] = data; \
13981500   else \
13991501      ROM[offset+(SR_EXRAM0(bank_num))] = data; \
r9675r9676
14101512
14111513static WRITE8_HANDLER( pc6001sr_mode_w )
14121514{
1413   sr_video_mode = data;
1515   pc6001_state *state = space->machine->driver_data<pc6001_state>();
1516   state->sr_video_mode = data;
14141517
14151518   if(data & 1)
14161519      assert("PC-6001SR in Mk-2 compatibility mode not yet supported!\n");
r9675r9676
14181521
14191522static WRITE8_HANDLER( pc6001sr_vram_bank_w )
14201523{
1524   pc6001_state *state = space->machine->driver_data<pc6001_state>();
14211525   UINT8 *work_ram = memory_region(space->machine, "maincpu");
14221526
1423   pc6001_video_ram = work_ram + 0x70000 + ((data & 0x0f)*0x1000);
1527   state->video_ram = work_ram + 0x70000 + ((data & 0x0f)*0x1000);
14241528}
14251529
14261530static WRITE8_HANDLER ( pc6001sr_system_latch_w )
14271531{
1428   if((!(sys_latch & 8)) && data & 0x8) //PLAY tape cmd
1532   pc6001_state *state = space->machine->driver_data<pc6001_state>();
1533   if((!(state->sys_latch & 8)) && data & 0x8) //PLAY tape cmd
14291534   {
1430      cas_switch = 1;
1535      state->cas_switch = 1;
14311536      //cassette_change_state(space->machine->device("cass" ),CASSETTE_MOTOR_ENABLED,CASSETTE_MASK_MOTOR);
14321537      //cassette_change_state(space->machine->device("cass" ),CASSETTE_PLAY,CASSETTE_MASK_UISTATE);
14331538   }
1434   if((sys_latch & 8) && ((data & 0x8) == 0)) //STOP tape cmd
1539   if((state->sys_latch & 8) && ((data & 0x8) == 0)) //STOP tape cmd
14351540   {
1436      cas_switch = 0;
1541      state->cas_switch = 0;
14371542      //cassette_change_state(space->machine->device("cass" ),CASSETTE_MOTOR_DISABLED,CASSETTE_MASK_MOTOR);
14381543      //cassette_change_state(space->machine->device("cass" ),CASSETTE_STOPPED,CASSETTE_MASK_UISTATE);
1439      //irq_vector = 0x00;
1544      //state->irq_vector = 0x00;
14401545      //cputag_set_input_line(space->machine,"maincpu", 0, ASSERT_LINE);
14411546   }
14421547
1443   sys_latch = data;
1548   state->sys_latch = data;
14441549
1445   timer_irq_mask = data & 1;
1446   //vram_bank_change(space->machine,(ex_vram_bank & 0x06) | ((sys_latch & 0x06) << 4));
1550   state->timer_irq_mask = data & 1;
1551   //vram_bank_change(space->machine,(state->ex_vram_bank & 0x06) | ((state->sys_latch & 0x06) << 4));
14471552
14481553   //printf("%02x B0\n",data);
14491554}
14501555
14511556static WRITE8_DEVICE_HANDLER(necsr_ppi8255_w)
14521557{
1558   pc6001_state *state = device->machine->driver_data<pc6001_state>();
14531559   if (offset==3)
14541560   {
14551561      if(data & 1)
1456         port_c_8255 |=   1<<((data>>1)&0x07);
1562         state->port_c_8255 |=   1<<((data>>1)&0x07);
14571563      else
1458         port_c_8255 &= ~(1<<((data>>1)&0x07));
1564         state->port_c_8255 &= ~(1<<((data>>1)&0x07));
14591565
14601566      switch(data) {
1461           case 0x08: port_c_8255 |= 0x88; break;
1462           case 0x09: port_c_8255 &= 0xf7; break;
1463           case 0x0c: port_c_8255 |= 0x28; break;
1464           case 0x0d: port_c_8255 &= 0xf7; break;
1567           case 0x08: state->port_c_8255 |= 0x88; break;
1568           case 0x09: state->port_c_8255 &= 0xf7; break;
1569           case 0x0c: state->port_c_8255 |= 0x28; break;
1570           case 0x0d: state->port_c_8255 &= 0xf7; break;
14651571           default: break;
14661572      }
14671573
1468      port_c_8255 |= 0xa8;
1574      state->port_c_8255 |= 0xa8;
14691575
14701576      if(0)
14711577      {
r9675r9676
16871793
16881794static INTERRUPT_GEN( pc6001_interrupt )
16891795{
1690   cur_keycode = check_joy_press(device->machine);
1796   pc6001_state *state = device->machine->driver_data<pc6001_state>();
1797   state->cur_keycode = check_joy_press(device->machine);
16911798   if(IRQ_LOG) printf("Stick IRQ called 0x16\n");
1692   irq_vector = 0x16;
1799   state->irq_vector = 0x16;
16931800   cpu_set_input_line(device, 0, ASSERT_LINE);
16941801}
16951802
16961803static INTERRUPT_GEN( pc6001sr_interrupt )
16971804{
1698   static UINT8 kludge;
1805   pc6001_state *state = device->machine->driver_data<pc6001_state>();
1806   state->kludge^= 1;
16991807
1700   kludge^= 1;
1701
1702   cur_keycode = check_joy_press(device->machine);
1808   state->cur_keycode = check_joy_press(device->machine);
17031809   if(IRQ_LOG) printf("VRTC IRQ called 0x16\n");
1704   irq_vector = (kludge) ? 0x22 : 0x16;
1810   state->irq_vector = (state->kludge) ? 0x22 : 0x16;
17051811   cpu_set_input_line(device, 0, ASSERT_LINE);
17061812}
17071813
17081814static IRQ_CALLBACK ( pc6001_irq_callback )
17091815{
1816   pc6001_state *state = device->machine->driver_data<pc6001_state>();
17101817   cpu_set_input_line(device, 0, CLEAR_LINE);
1711   return irq_vector;
1818   return state->irq_vector;
17121819}
17131820
17141821static READ8_DEVICE_HANDLER (pc6001_8255_porta_r )
r9675r9676
18521959
18531960static TIMER_CALLBACK(cassette_callback)
18541961{
1855   if(cas_switch == 1)
1962   pc6001_state *state = machine->driver_data<pc6001_state>();
1963   if(state->cas_switch == 1)
18561964   {
18571965      #if 0
18581966      static UINT8 cas_data_i = 0x80,cas_data_poll;
1859      //cur_keycode = gfx_data[cas_offset++];
1967      //state->cur_keycode = gfx_data[state->cas_offset++];
18601968      if(cassette_input(machine->device("cass")) > 0.03)
18611969         cas_data_poll|= cas_data_i;
18621970      else
18631971         cas_data_poll&=~cas_data_i;
18641972      if(cas_data_i == 1)
18651973      {
1866         cur_keycode = cas_data_poll;
1974         state->cur_keycode = cas_data_poll;
18671975         cas_data_i = 0x80;
18681976         /* data ready, poll irq */
1869         irq_vector = 0x08;
1977         state->irq_vector = 0x08;
18701978         cputag_set_input_line(machine,"maincpu", 0, ASSERT_LINE);
18711979      }
18721980      else
r9675r9676
18741982      #else
18751983         UINT8 *cas_data = memory_region(machine, "cas");
18761984
1877         cur_keycode = cas_data[cas_offset++];
1878         popmessage("%04x %04x",cas_offset,cas_maxsize);
1879         if(cas_offset > cas_maxsize)
1985         state->cur_keycode = cas_data[state->cas_offset++];
1986         popmessage("%04x %04x",state->cas_offset,state->cas_maxsize);
1987         if(state->cas_offset > state->cas_maxsize)
18801988         {
1881            cas_offset = 0;
1882            cas_switch = 0;
1989            state->cas_offset = 0;
1990            state->cas_switch = 0;
18831991            if(IRQ_LOG) printf("Tape-E IRQ 0x12\n");
1884            irq_vector = 0x12;
1992            state->irq_vector = 0x12;
18851993            cputag_set_input_line(machine,"maincpu", 0, ASSERT_LINE);
18861994         }
18871995         else
18881996         {
18891997            if(IRQ_LOG) printf("Tape-D IRQ 0x08\n");
1890            irq_vector = 0x08;
1998            state->irq_vector = 0x08;
18911999            cputag_set_input_line(machine,"maincpu", 0, ASSERT_LINE);
18922000         }
18932001      #endif
r9675r9676
18962004
18972005static TIMER_CALLBACK(keyboard_callback)
18982006{
2007   pc6001_state *state = machine->driver_data<pc6001_state>();
18992008   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
19002009   UINT32 key1 = input_port_read(machine,"key1");
19012010   UINT32 key2 = input_port_read(machine,"key2");
19022011   UINT32 key3 = input_port_read(machine,"key3");
1903   static UINT32 old_key1,old_key2,old_key3;
19042012//  UINT8 p1_key = input_port_read(machine, "P1");;
19052013
1906   if(cas_switch == 0)
2014   if(state->cas_switch == 0)
19072015   {
1908      if((key1 != old_key1) || (key2 != old_key2) || (key3 != old_key3))
2016      if((key1 != state->old_key1) || (key2 != state->old_key2) || (key3 != state->old_key3))
19092017      {
1910         cur_keycode = check_keyboard_press(space->machine);
2018         state->cur_keycode = check_keyboard_press(space->machine);
19112019         if(IRQ_LOG) printf("KEY IRQ 0x02\n");
1912         irq_vector = 0x02;
2020         state->irq_vector = 0x02;
19132021         cputag_set_input_line(machine,"maincpu", 0, ASSERT_LINE);
1914         old_key1 = key1;
1915         old_key2 = key2;
1916         old_key3 = key3;
2022         state->old_key1 = key1;
2023         state->old_key2 = key2;
2024         state->old_key3 = key3;
19172025      }
19182026      #if 0
19192027      else /* joypad polling */
19202028      {
1921         cur_keycode = check_joy_press(space->machine);
1922         if(cur_keycode)
2029         state->cur_keycode = check_joy_press(space->machine);
2030         if(state->cur_keycode)
19232031         {
1924            irq_vector = 0x16;
2032            state->irq_vector = 0x16;
19252033            cputag_set_input_line(machine,"maincpu", 0, ASSERT_LINE);
19262034         }
19272035      }
r9675r9676
19312039
19322040static MACHINE_START(pc6001)
19332041{
2042   pc6001_state *state = machine->driver_data<pc6001_state>();
19342043   /* TODO: accurate timing on this */
19352044   timer_pulse(machine, ATTOTIME_IN_HZ(250), NULL, 0, keyboard_callback);
19362045
19372046   timer_pulse(machine, ATTOTIME_IN_HZ(1200/12), NULL, 0, cassette_callback); //1200 bauds / (1 start bit -> 8 data bits -> 3 stop bits)
19382047
1939   timer_hz_div = 3;
2048   state->timer_hz_div = 3;
19402049   {
1941      attotime period = ATTOTIME_IN_HZ((487.5*4)/(timer_hz_div+1));
1942      timer_irq_timer = timer_alloc(machine, audio_callback, NULL);
1943      timer_adjust_periodic(timer_irq_timer, period,  0, period);
2050      attotime period = ATTOTIME_IN_HZ((487.5*4)/(state->timer_hz_div+1));
2051      state->timer_irq_timer = timer_alloc(machine, audio_callback, NULL);
2052      timer_adjust_periodic(state->timer_irq_timer, period,  0, period);
19442053   }
19452054}
19462055
19472056static MACHINE_RESET(pc6001)
19482057{
2058   pc6001_state *state = machine->driver_data<pc6001_state>();
19492059   UINT8 *work_ram = memory_region(machine, "maincpu");
19502060
1951   pc6001_video_ram =  work_ram + 0xc000;
2061   state->video_ram =  work_ram + 0xc000;
19522062
1953   port_c_8255=0;
2063   state->port_c_8255=0;
19542064
19552065   cpu_set_irq_callback(machine->device("maincpu"),pc6001_irq_callback);
1956   cas_switch = 0;
1957   cas_offset = 0;
1958   timer_irq_mask = 1;
1959   timer_irq_mask2 = 1;
1960   timer_irq_vector = 0x06; // actually vector is fixed in plain PC-6001
1961   timer_hz_div = 3;
2066   state->cas_switch = 0;
2067   state->cas_offset = 0;
2068   state->timer_irq_mask = 1;
2069   state->timer_irq_mask2 = 1;
2070   state->timer_irq_vector = 0x06; // actually vector is fixed in plain PC-6001
2071   state->timer_hz_div = 3;
19622072}
19632073
19642074static MACHINE_RESET(pc6001m2)
19652075{
2076   pc6001_state *state = machine->driver_data<pc6001_state>();
19662077   UINT8 *work_ram = memory_region(machine, "maincpu");
19672078
1968   pc6001_video_ram = work_ram + 0xc000 + 0x28000;
2079   state->video_ram = work_ram + 0xc000 + 0x28000;
19692080
1970   port_c_8255=0;
2081   state->port_c_8255=0;
19712082
19722083   cpu_set_irq_callback(machine->device("maincpu"),pc6001_irq_callback);
1973   cas_switch = 0;
1974   cas_offset = 0;
2084   state->cas_switch = 0;
2085   state->cas_offset = 0;
19752086
19762087   /* set default bankswitch */
19772088   {
19782089      UINT8 *ROM = memory_region(machine, "maincpu");
1979      bank_r0 = 0x71;
2090      state->bank_r0 = 0x71;
19802091      memory_set_bankptr(machine, "bank1", &ROM[BASICROM(0)]);
19812092      memory_set_bankptr(machine, "bank2", &ROM[BASICROM(1)]);
19822093      memory_set_bankptr(machine, "bank3", &ROM[EXROM(0)]);
19832094      memory_set_bankptr(machine, "bank4", &ROM[EXROM(1)]);
1984      bank_r1 = 0xdd;
2095      state->bank_r1 = 0xdd;
19852096      memory_set_bankptr(machine, "bank5", &ROM[WRAM(4)]);
19862097      memory_set_bankptr(machine, "bank6", &ROM[WRAM(5)]);
19872098      memory_set_bankptr(machine, "bank7", &ROM[WRAM(6)]);
19882099      memory_set_bankptr(machine, "bank8", &ROM[WRAM(7)]);
1989      bank_opt = 0x02; //tv rom
1990      bank_w = 0x50; //enable write to work ram 4,5,6,7
1991      gfx_bank_on = 0;
2100      state->bank_opt = 0x02; //tv rom
2101      state->bank_w = 0x50; //enable write to work ram 4,5,6,7
2102      state->gfx_bank_on = 0;
19922103   }
19932104
1994   timer_irq_mask = 1;
1995   timer_irq_mask2 = 1;
1996   timer_irq_vector = 0x06;
2105   state->timer_irq_mask = 1;
2106   state->timer_irq_mask2 = 1;
2107   state->timer_irq_vector = 0x06;
19972108}
19982109
19992110static MACHINE_RESET(pc6001sr)
20002111{
2112   pc6001_state *state = machine->driver_data<pc6001_state>();
20012113   UINT8 *work_ram = memory_region(machine, "maincpu");
20022114
2003   pc6001_video_ram = work_ram + 0x70000;
2115   state->video_ram = work_ram + 0x70000;
20042116
2005   port_c_8255=0;
2117   state->port_c_8255=0;
20062118
20072119   cpu_set_irq_callback(machine->device("maincpu"),pc6001_irq_callback);
2008   cas_switch = 0;
2009   cas_offset = 0;
2120   state->cas_switch = 0;
2121   state->cas_offset = 0;
20102122
20112123   /* set default bankswitch */
20122124   {
20132125      UINT8 *ROM = memory_region(machine, "maincpu");
2014      sr_bank_r[0] = 0xf8; memory_set_bankptr(machine, "bank1", &ROM[SR_SYSROM_1(0x08)]);
2015      sr_bank_r[1] = 0xfa; memory_set_bankptr(machine, "bank2", &ROM[SR_SYSROM_1(0x0a)]);
2016      sr_bank_r[2] = 0xb0; memory_set_bankptr(machine, "bank3", &ROM[SR_EXROM1(0x00)]);
2017      sr_bank_r[3] = 0xc0; memory_set_bankptr(machine, "bank4", &ROM[SR_EXROM0(0x00)]);
2018      sr_bank_r[4] = 0x08; memory_set_bankptr(machine, "bank5", &ROM[SR_WRAM0(0x08)]);
2019      sr_bank_r[5] = 0x0a; memory_set_bankptr(machine, "bank6", &ROM[SR_WRAM0(0x0a)]);
2020      sr_bank_r[6] = 0x0c; memory_set_bankptr(machine, "bank7", &ROM[SR_WRAM0(0x0c)]);
2021      sr_bank_r[7] = 0x0e; memory_set_bankptr(machine, "bank8", &ROM[SR_WRAM0(0x0e)]);
2022//      bank_opt = 0x02; //tv rom
2126      state->sr_bank_r[0] = 0xf8; memory_set_bankptr(machine, "bank1", &ROM[SR_SYSROM_1(0x08)]);
2127      state->sr_bank_r[1] = 0xfa; memory_set_bankptr(machine, "bank2", &ROM[SR_SYSROM_1(0x0a)]);
2128      state->sr_bank_r[2] = 0xb0; memory_set_bankptr(machine, "bank3", &ROM[SR_EXROM1(0x00)]);
2129      state->sr_bank_r[3] = 0xc0; memory_set_bankptr(machine, "bank4", &ROM[SR_EXROM0(0x00)]);
2130      state->sr_bank_r[4] = 0x08; memory_set_bankptr(machine, "bank5", &ROM[SR_WRAM0(0x08)]);
2131      state->sr_bank_r[5] = 0x0a; memory_set_bankptr(machine, "bank6", &ROM[SR_WRAM0(0x0a)]);
2132      state->sr_bank_r[6] = 0x0c; memory_set_bankptr(machine, "bank7", &ROM[SR_WRAM0(0x0c)]);
2133      state->sr_bank_r[7] = 0x0e; memory_set_bankptr(machine, "bank8", &ROM[SR_WRAM0(0x0e)]);
2134//      state->bank_opt = 0x02; //tv rom
20232135
20242136      /* enable default work RAM writes */
2025      sr_bank_w[0] = 0x00;
2026      sr_bank_w[1] = 0x02;
2027      sr_bank_w[2] = 0x04;
2028      sr_bank_w[3] = 0x06;
2029      sr_bank_w[4] = 0x08;
2030      sr_bank_w[5] = 0x0a;
2031      sr_bank_w[6] = 0x0c;
2032      sr_bank_w[7] = 0x0e;
2137      state->sr_bank_w[0] = 0x00;
2138      state->sr_bank_w[1] = 0x02;
2139      state->sr_bank_w[2] = 0x04;
2140      state->sr_bank_w[3] = 0x06;
2141      state->sr_bank_w[4] = 0x08;
2142      state->sr_bank_w[5] = 0x0a;
2143      state->sr_bank_w[6] = 0x0c;
2144      state->sr_bank_w[7] = 0x0e;
20332145
2034      gfx_bank_on = 0;
2146      state->gfx_bank_on = 0;
20352147   }
20362148
2037   timer_irq_mask = 1;
2038   timer_irq_mask2 = 1;
2039   timer_irq_vector = 0x06;
2149   state->timer_irq_mask = 1;
2150   state->timer_irq_mask2 = 1;
2151   state->timer_irq_vector = 0x06;
20402152}
20412153
20422154static const rgb_t defcolors[] =
r9675r9676
21062218
21072219static DEVICE_IMAGE_LOAD( pc6001_cass )
21082220{
2221   pc6001_state *state = image.device().machine->driver_data<pc6001_state>();
21092222   UINT8 *cas = memory_region(image.device().machine, "cas");
21102223   UINT32 size;
21112224
r9675r9676
21162229      return IMAGE_INIT_FAIL;
21172230   }
21182231
2119   cas_maxsize = size;
2232   state->cas_maxsize = size;
21202233
21212234   return IMAGE_INIT_PASS;
21222235}
r9675r9676
21522265
21532266#define PC6001_MAIN_CLOCK 7987200
21542267
2155static MACHINE_CONFIG_START( pc6001, driver_device )
2268static MACHINE_CONFIG_START( pc6001, pc6001_state )
21562269   /* basic machine hardware */
21572270   MDRV_CPU_ADD("maincpu",Z80, PC6001_MAIN_CLOCK / 2) // ~4 Mhz
21582271   MDRV_CPU_PROGRAM_MAP(pc6001_map)
src/mess/drivers/pc88va.c
r9675r9676
2525#include "machine/upd765.h"
2626#include "sound/2203intf.h"
2727
28static UINT16 *palram;
29static UINT16 bank_reg;
30static UINT16 screen_ctrl_reg;
31static UINT8 timer3_io_reg;
32static emu_timer *t3_mouse_timer;
33static struct
28typedef struct
3429{
3530   UINT16 tvram_vreg_offset;
3631   UINT16 attr_offset;
r9675r9676
4439   UINT16 cur_pos_x,cur_pos_y;
4540   UINT8 curn;
4641   UINT8 curn_blink;
47}tsp;
48static UINT16 video_pri_reg[2];
42} tsp_t;
4943
50static UINT8 backupram_wp;
5144
45class pc88va_state : public driver_device
46{
47public:
48   pc88va_state(running_machine &machine, const driver_device_config_base &config)
49      : driver_device(machine, config) { }
50
51   UINT16 *palram;
52   UINT16 bank_reg;
53   UINT16 screen_ctrl_reg;
54   UINT8 timer3_io_reg;
55   emu_timer *t3_mouse_timer;
56   tsp_t tsp;
57   UINT16 video_pri_reg[2];
58   UINT8 backupram_wp;
59   UINT8 cmd;
60   UINT8 buf_size;
61   UINT8 buf_index;
62   UINT8 buf_ram[16];
63   UINT8 portc_test;
64};
65
66
5267static VIDEO_START( pc88va )
5368{
5469
r9675r9676
5671
5772static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect)
5873{
74   pc88va_state *state = machine->driver_data<pc88va_state>();
5975   UINT16 *tvram = (UINT16 *)memory_region(machine, "tvram");
6076   int offs,i;
6177
62   offs = tsp.spr_offset;
78   offs = state->tsp.spr_offset;
6379   for(i=0;i<(0x100);i+=(8))
6480   {
6581      int xp,yp,sw,md,xsize,ysize,spda,fg_col,bc;
r9675r9676
165181
166182static void draw_text(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect)
167183{
184   pc88va_state *state = machine->driver_data<pc88va_state>();
168185   UINT8 *tvram = memory_region(machine, "tvram");
169186   UINT8 *kanji = memory_region(machine, "kanji");
170187   int xi,yi;
r9675r9676
179196   UINT8 fg_col,bg_col,secret,reverse,blink,dwidc,dwid,uline,hline;
180197   UINT8 screen_fg_col,screen_bg_col;
181198
182   count = (tvram[tsp.tvram_vreg_offset+0] | tvram[tsp.tvram_vreg_offset+1] << 8);
199   count = (tvram[state->tsp.tvram_vreg_offset+0] | tvram[state->tsp.tvram_vreg_offset+1] << 8);
183200
184   attr_mode = tvram[tsp.tvram_vreg_offset+0xa] & 0x1f;
201   attr_mode = tvram[state->tsp.tvram_vreg_offset+0xa] & 0x1f;
185202   /* Note: bug in docs has the following two reversed */
186   screen_fg_col = (tvram[tsp.tvram_vreg_offset+0xb] & 0xf0) >> 4;
187   screen_bg_col = tvram[tsp.tvram_vreg_offset+0xb] & 0x0f;
203   screen_fg_col = (tvram[state->tsp.tvram_vreg_offset+0xb] & 0xf0) >> 4;
204   screen_bg_col = tvram[state->tsp.tvram_vreg_offset+0xb] & 0x0f;
188205
189206   for(y=0;y<13;y++)
190207   {
r9675r9676
196213
197214         tile_num = calc_kanji_rom_addr(jis1,jis2,x,y);
198215
199         attr = (tvram[count+tsp.attr_offset] & 0x00ff);
216         attr = (tvram[count+state->tsp.attr_offset] & 0x00ff);
200217
201218         fg_col = bg_col = reverse = blink = secret = dwidc = dwid = uline = hline = 0;
202219
r9675r9676
345362
346363static VIDEO_UPDATE( pc88va )
347364{
365   pc88va_state *state = screen->machine->driver_data<pc88va_state>();
348366   UINT8 pri,cur_pri_lv;
349367   UINT32 screen_pri;
350368   bitmap_fill(bitmap, cliprect, 0);
351369
352   if(tsp.disp_on == 0) // don't bother if we are under DSPOFF command
370   if(state->tsp.disp_on == 0) // don't bother if we are under DSPOFF command
353371      return 0;
354372
355373   /*
356   video_pri_reg[0]
374   state->video_pri_reg[0]
357375   xxxx ---- ---- ---- priority 3
358376   ---- xxxx ---- ---- priority 2
359377   ---- ---- xxxx ---- priority 1
360378   ---- ---- ---- xxxx priority 0
361   video_pri_reg[1]
379   state->video_pri_reg[1]
362380   ---- ---- xxxx ---- priority 5
363381   ---- ---- ---- xxxx priority 4
364382
365383   Note that orthogonality level is actually REVERSED than the level number it indicates, so we have to play a little with the data for an easier usage ...
366384   */
367385
368   screen_pri = (video_pri_reg[1] & 0x00f0) >> 4; // priority 5
369   screen_pri|= (video_pri_reg[1] & 0x000f) << 4; // priority 4
370   screen_pri|= (video_pri_reg[0] & 0xf000) >> 4; // priority 3
371   screen_pri|= (video_pri_reg[0] & 0x0f00) << 4; // priority 2
372   screen_pri|= (video_pri_reg[0] & 0x00f0) << 12; // priority 1
373   screen_pri|= (video_pri_reg[0] & 0x000f) << 20; // priority 0
386   screen_pri = (state->video_pri_reg[1] & 0x00f0) >> 4; // priority 5
387   screen_pri|= (state->video_pri_reg[1] & 0x000f) << 4; // priority 4
388   screen_pri|= (state->video_pri_reg[0] & 0xf000) >> 4; // priority 3
389   screen_pri|= (state->video_pri_reg[0] & 0x0f00) << 4; // priority 2
390   screen_pri|= (state->video_pri_reg[0] & 0x00f0) << 12; // priority 1
391   screen_pri|= (state->video_pri_reg[0] & 0x000f) << 20; // priority 0
374392
375393   for(pri=0;pri<6;pri++)
376394   {
r9675r9676
388406            switch(cur_pri_lv & 3) // (palette color mode)
389407            {
390408               case 0: draw_text(screen->machine,bitmap,cliprect); break;
391               case 1: if(tsp.spr_on) { draw_sprites(screen->machine,bitmap,cliprect); } break;
409               case 1: if(state->tsp.spr_on) { draw_sprites(screen->machine,bitmap,cliprect); } break;
392410               case 2: /* A = graphic 0 */ break;
393411               case 3: /* B = graphic 1 */ break;
394412            }
r9675r9676
401419
402420static READ16_HANDLER( sys_mem_r )
403421{
404   switch((bank_reg & 0xf00) >> 8)
422   pc88va_state *state = space->machine->driver_data<pc88va_state>();
423   switch((state->bank_reg & 0xf00) >> 8)
405424   {
406425      case 0: // select bus slot
407426         return 0xffff;
r9675r9676
426445         UINT16 *knj_ram = (UINT16 *)memory_region(space->machine, "kanji");
427446         UINT32 knj_offset;
428447
429         knj_offset = (offset + (((bank_reg & 0x100) >> 8)*0x20000));
448         knj_offset = (offset + (((state->bank_reg & 0x100) >> 8)*0x20000));
430449
431450         /* 0x00000 - 0x3ffff Kanji ROM 1*/
432451         /* 0x40000 - 0x4ffff Kanji ROM 2*/
r9675r9676
442461         UINT16 *dic_rom = (UINT16 *)memory_region(space->machine, "dictionary");
443462         UINT32 dic_offset;
444463
445         dic_offset = (offset + (((bank_reg & 0x100) >> 8)*0x20000));
464         dic_offset = (offset + (((state->bank_reg & 0x100) >> 8)*0x20000));
446465
447466         return dic_rom[dic_offset];
448467      }
r9675r9676
453472
454473static WRITE16_HANDLER( sys_mem_w )
455474{
456   switch((bank_reg & 0xf00) >> 8)
475   pc88va_state *state = space->machine->driver_data<pc88va_state>();
476   switch((state->bank_reg & 0xf00) >> 8)
457477   {
458478      case 0: // select bus slot
459479         break;
r9675r9676
478498         UINT16 *knj_ram = (UINT16 *)memory_region(space->machine, "kanji");
479499         UINT32 knj_offset;
480500
481         knj_offset = ((offset) + (((bank_reg & 0x100) >> 8)*0x20000));
501         knj_offset = ((offset) + (((state->bank_reg & 0x100) >> 8)*0x20000));
482502
483503         if(knj_offset >= 0x50000/2 && knj_offset <= 0x53fff/2) // TODO: there's an area that can be write protected
484504         {
r9675r9676
520540   return 0x00;
521541}
522542
523static UINT8 cmd,buf_size,buf_index;
524static UINT8 buf_ram[16];
525543
526544#define SYNC   0x10
527545#define DSPON  0x12
r9675r9676
539557
540558static WRITE8_HANDLER( idp_command_w )
541559{
560   pc88va_state *state = space->machine->driver_data<pc88va_state>();
542561   switch(data)
543562   {
544563      /* 0x10 - SYNC: sets CRTC values */
545      case SYNC:   cmd = SYNC;  buf_size = 14; buf_index = 0; break;
564      case SYNC:   state->cmd = SYNC;  state->buf_size = 14; state->buf_index = 0; break;
546565
547566      /* 0x12 - DSPON: set DiSPlay ON and set up tvram table vreg */
548      case DSPON:  cmd = DSPON; buf_size = 3;  buf_index = 0; break;
567      case DSPON:  state->cmd = DSPON; state->buf_size = 3;  state->buf_index = 0; break;
549568
550569      /* 0x13 - DSPOFF: set DiSPlay OFF */
551      case DSPOFF: cmd = DSPOFF; tsp.disp_on = 0; break;
570      case DSPOFF: state->cmd = DSPOFF; state->tsp.disp_on = 0; break;
552571
553572      /* 0x14 - DSPDEF: set DiSPlay DEFinitions */
554      case DSPDEF: cmd = DSPDEF; buf_size = 6; buf_index = 0; break;
573      case DSPDEF: state->cmd = DSPDEF; state->buf_size = 6; state->buf_index = 0; break;
555574
556575      /* 0x15 - CURDEF: set CURsor DEFinition */
557      case CURDEF: cmd = CURDEF; buf_size = 1; buf_index = 0; break;
576      case CURDEF: state->cmd = CURDEF; state->buf_size = 1; state->buf_index = 0; break;
558577
559578      /* 0x16 - ACTSCR: ??? */
560      case ACTSCR: cmd = ACTSCR; buf_size = 1; buf_index = 0; break;
579      case ACTSCR: state->cmd = ACTSCR; state->buf_size = 1; state->buf_index = 0; break;
561580
562581      /* 0x15 - CURS: set CURSor position */
563      case CURS:   cmd = CURS;   buf_size = 4; buf_index = 0; break;
582      case CURS:   state->cmd = CURS;   state->buf_size = 4; state->buf_index = 0; break;
564583
565584      /* 0x8c - EMUL: set 3301 EMULation */
566      case EMUL:   cmd = EMUL;   buf_size = 4; buf_index = 0; break;
585      case EMUL:   state->cmd = EMUL;   state->buf_size = 4; state->buf_index = 0; break;
567586
568587      /* 0x88 - EXIT: ??? */
569      case EXIT:   cmd = EXIT; break;
588      case EXIT:   state->cmd = EXIT; break;
570589
571590      /* 0x82 - SPRON: set SPRite ON */
572      case SPRON:  cmd = SPRON;  buf_size = 3; buf_index = 0; break;
591      case SPRON:  state->cmd = SPRON;  state->buf_size = 3; state->buf_index = 0; break;
573592
574593      /* 0x83 - SPROFF: set SPRite OFF */
575      case SPROFF: cmd = SPROFF; tsp.spr_on = 0; break;
594      case SPROFF: state->cmd = SPROFF; state->tsp.spr_on = 0; break;
576595
577596      /* 0x85 - SPRSW: ??? */
578      case SPRSW:  cmd = SPRSW;  buf_size = 1; buf_index = 0; break;
597      case SPRSW:  state->cmd = SPRSW;  state->buf_size = 1; state->buf_index = 0; break;
579598
580599      /* 0x81 - SPROV: set SPRite OVerflow information */
581600      /*
r9675r9676
583602      --x- ---- Sprite Collision flag
584603      ---x xxxx First sprite that caused Sprite Over event
585604      */
586      case SPROV:  cmd = SPROV; /* TODO: where it returns the info? */ break;
605      case SPROV:  state->cmd = SPROV; /* TODO: where it returns the info? */ break;
587606
588607      /* TODO: 0x89 shouldn't trigger, should be one of the above commands */
589      default:   cmd = 0x00; printf("PC=%05x: Unknown IDP %02x cmd set\n",cpu_get_pc(space->cpu),data); break;
608      default:   state->cmd = 0x00; printf("PC=%05x: Unknown IDP %02x cmd set\n",cpu_get_pc(space->cpu),data); break;
590609   }
591610}
592611
r9675r9676
601620/* TODO: very preliminary, needs something showable first */
602621static void execute_sync_cmd(running_machine *machine)
603622{
623   pc88va_state *state = machine->driver_data<pc88va_state>();
604624   /*
605625      ???? ???? [0] - unknown
606626      ???? ???? [1] - unknown
r9675r9676
628648   //printf("V border end: %d\n",(sync_cmd[0xc]));
629649   //printf("V blank end: %d\n",(sync_cmd[0xd]));
630650
631   x_vis_area = buf_ram[4] * 4;
632   y_vis_area = (buf_ram[0xa])|((buf_ram[0xb] & 0x40)<<2);
651   x_vis_area = state->buf_ram[4] * 4;
652   y_vis_area = (state->buf_ram[0xa])|((state->buf_ram[0xb] & 0x40)<<2);
633653
634654   visarea.min_x = 0;
635655   visarea.min_y = 0;
r9675r9676
648668
649669static void execute_dspon_cmd(running_machine *machine)
650670{
671   pc88va_state *state = machine->driver_data<pc88va_state>();
651672   /*
652673   [0] text table offset (hi word)
653674   [1] unknown
654675   [2] unknown
655676   */
656   tsp.tvram_vreg_offset = buf_ram[0] << 8;
657   tsp.disp_on = 1;
677   state->tsp.tvram_vreg_offset = state->buf_ram[0] << 8;
678   state->tsp.disp_on = 1;
658679}
659680
660681static void execute_dspdef_cmd(running_machine *machine)
661682{
683   pc88va_state *state = machine->driver_data<pc88va_state>();
662684   /*
663685   [0] attr offset (lo word)
664686   [1] attr offset (hi word)
r9675r9676
667689   [4] hline vertical position
668690   [5] blink number
669691   */
670   tsp.attr_offset = buf_ram[0] | buf_ram[1] << 8;
671   tsp.pitch = (buf_ram[2] & 0xf0) >> 4;
672   tsp.line_height = buf_ram[3] + 1;
673   tsp.h_line_pos = buf_ram[4];
674   tsp.blink = (buf_ram[5] & 0xf8) >> 3;
692   state->tsp.attr_offset = state->buf_ram[0] | state->buf_ram[1] << 8;
693   state->tsp.pitch = (state->buf_ram[2] & 0xf0) >> 4;
694   state->tsp.line_height = state->buf_ram[3] + 1;
695   state->tsp.h_line_pos = state->buf_ram[4];
696   state->tsp.blink = (state->buf_ram[5] & 0xf8) >> 3;
675697}
676698
677699static void execute_curdef_cmd(running_machine *machine)
678700{
701   pc88va_state *state = machine->driver_data<pc88va_state>();
679702   /*
680703   xxxx x--- [0] Sprite Cursor number (sprite RAM entry)
681704   ---- --x- [0] show cursor bit (actively modifies the spriteram entry)
r9675r9676
683706   */
684707
685708   /* TODO: needs basic sprite emulation */
686   tsp.curn = (buf_ram[0] & 0xf8);
687   tsp.curn_blink = (buf_ram[0] & 1);
709   state->tsp.curn = (state->buf_ram[0] & 0xf8);
710   state->tsp.curn_blink = (state->buf_ram[0] & 1);
688711
689   tsp_sprite_enable(machine, 0xa0000 + tsp.spr_offset + tsp.curn, (buf_ram[0] & 2) << 8);
712   tsp_sprite_enable(machine, 0xa0000 + state->tsp.spr_offset + state->tsp.curn, (state->buf_ram[0] & 2) << 8);
690713}
691714
692715static void execute_actscr_cmd(running_machine *machine)
693716{
717   //pc88va_state *state = machine->driver_data<pc88va_state>();
694718   /*
695719   This command assigns a strip where the cursor is located.
696720   xxxx xxxx [0] strip ID * 32 (???)
697721   */
698722
699723   /* TODO: no idea about this command */
700   //printf("ACTSCR: %02x\n",buf_ram[0]);
724   //printf("ACTSCR: %02x\n",state->buf_ram[0]);
701725}
702726
703727static void execute_curs_cmd(running_machine *machine)
704728{
729   pc88va_state *state = machine->driver_data<pc88va_state>();
705730   /*
706731   [0] Cursor Position Y (lo word)
707732   [1] Cursor Position Y (hi word)
r9675r9676
709734   [3] Cursor Position X (hi word)
710735   */
711736
712   tsp.cur_pos_y = buf_ram[0] | buf_ram[1] << 8;
713   tsp.cur_pos_x = buf_ram[2] | buf_ram[3] << 8;
737   state->tsp.cur_pos_y = state->buf_ram[0] | state->buf_ram[1] << 8;
738   state->tsp.cur_pos_x = state->buf_ram[2] | state->buf_ram[3] << 8;
714739}
715740
716741static void execute_emul_cmd(running_machine *machine)
r9675r9676
728753
729754static void execute_spron_cmd(running_machine *machine)
730755{
756   pc88va_state *state = machine->driver_data<pc88va_state>();
731757   /*
732758   [0] Sprite Table Offset (hi word)
733759   [1] (unknown / reserved)
r9675r9676
735761   ---- --x- [2] MG: all sprites are 2x zoomed vertically when 1
736762   ---- ---x [2] GR: 1 to enable the group collision detection
737763   */
738   tsp.spr_offset = buf_ram[0] << 8;
739   tsp.spr_on = 1;
740   printf("SPR TABLE %02x %02x %02x\n",buf_ram[0],buf_ram[1],buf_ram[2]);
764   state->tsp.spr_offset = state->buf_ram[0] << 8;
765   state->tsp.spr_on = 1;
766   printf("SPR TABLE %02x %02x %02x\n",state->buf_ram[0],state->buf_ram[1],state->buf_ram[2]);
741767}
742768
743769static void execute_sprsw_cmd(running_machine *machine)
744770{
771   pc88va_state *state = machine->driver_data<pc88va_state>();
745772   /*
746773   Toggle an individual sprite in the sprite ram entry
747774   [0] xxxx x--- target sprite number
748775   [0] ---- --x- sprite off/on switch
749776   */
750777
751   tsp_sprite_enable(machine, 0xa0000 + tsp.spr_offset + (buf_ram[0] & 0xf8), (buf_ram[0] & 2) << 8);
778   tsp_sprite_enable(machine, 0xa0000 + state->tsp.spr_offset + (state->buf_ram[0] & 0xf8), (state->buf_ram[0] & 2) << 8);
752779}
753780
754781static WRITE8_HANDLER( idp_param_w )
755782{
756   if(cmd == DSPOFF || cmd == EXIT || cmd == SPROFF || cmd == SPROV) // no param commands
783   pc88va_state *state = space->machine->driver_data<pc88va_state>();
784   if(state->cmd == DSPOFF || state->cmd == EXIT || state->cmd == SPROFF || state->cmd == SPROV) // no param commands
757785      return;
758786
759   buf_ram[buf_index] = data;
760   buf_index++;
787   state->buf_ram[state->buf_index] = data;
788   state->buf_index++;
761789
762   if(buf_index >= buf_size)
790   if(state->buf_index >= state->buf_size)
763791   {
764      buf_index = 0;
765      switch(cmd)
792      state->buf_index = 0;
793      switch(state->cmd)
766794      {
767795         case SYNC:       execute_sync_cmd(space->machine);    break;
768796         case DSPON:    execute_dspon_cmd(space->machine);    break;
r9675r9676
783811
784812static WRITE16_HANDLER( palette_ram_w )
785813{
814   pc88va_state *state = space->machine->driver_data<pc88va_state>();
786815   int r,g,b;
787   COMBINE_DATA(&palram[offset]);
816   COMBINE_DATA(&state->palram[offset]);
788817
789   b = (palram[offset] & 0x001e) >> 1;
790   r = (palram[offset] & 0x03c0) >> 6;
791   g = (palram[offset] & 0x7800) >> 11;
818   b = (state->palram[offset] & 0x001e) >> 1;
819   r = (state->palram[offset] & 0x03c0) >> 6;
820   g = (state->palram[offset] & 0x7800) >> 11;
792821
793822   palette_set_color_rgb(space->machine,offset,pal4bit(r),pal4bit(g),pal4bit(b));
794823}
r9675r9676
805834
806835static READ16_HANDLER( bios_bank_r )
807836{
808   return bank_reg;
837   pc88va_state *state = space->machine->driver_data<pc88va_state>();
838   return state->bank_reg;
809839}
810840
811841static WRITE16_HANDLER( bios_bank_w )
812842{
843   pc88va_state *state = space->machine->driver_data<pc88va_state>();
813844   /*
814845   -x-- ---- ---- ---- SMM (compatibility mode)
815846   ---x ---- ---- ---- GMSP (VRAM drawing Mode)
r9675r9676
818849   ---- ---- ---- xxxx RBC0 (0xe0000 - 0xeffff ROM bank)
819850   */
820851   if ((mem_mask&0xffff) == 0xffff)
821      bank_reg = data;
852      state->bank_reg = data;
822853   else if ((mem_mask & 0xffff) == 0xff00)
823      bank_reg = (data & 0xff00) | (bank_reg & 0x00ff);
854      state->bank_reg = (data & 0xff00) | (state->bank_reg & 0x00ff);
824855   else if ((mem_mask & 0xffff) == 0x00ff)
825      bank_reg = (data & 0x00ff) | (bank_reg & 0xff00);
856      state->bank_reg = (data & 0x00ff) | (state->bank_reg & 0xff00);
826857
827858
828859   /* RBC1 */
829860   {
830861      UINT8 *ROM10 = memory_region(space->machine, "rom10");
831862
832      if((bank_reg & 0xe0) == 0x00)
833         memory_set_bankptr(space->machine, "rom10_bank", &ROM10[(bank_reg & 0x10) ? 0x10000 : 0x00000]);
863      if((state->bank_reg & 0xe0) == 0x00)
864         memory_set_bankptr(space->machine, "rom10_bank", &ROM10[(state->bank_reg & 0x10) ? 0x10000 : 0x00000]);
834865   }
835866
836867   /* RBC0 */
837868   {
838869      UINT8 *ROM00 = memory_region(space->machine, "rom00");
839870
840      memory_set_bankptr(space->machine, "rom00_bank", &ROM00[(bank_reg & 0xf)*0x10000]); // TODO: docs says that only 0 - 5 are used, dunno why ...
871      memory_set_bankptr(space->machine, "rom00_bank", &ROM00[(state->bank_reg & 0xf)*0x10000]); // TODO: docs says that only 0 - 5 are used, dunno why ...
841872   }
842873}
843874
r9675r9676
859890
860891static WRITE16_HANDLER( backupram_wp_1_w )
861892{
862   backupram_wp = 1;
893   pc88va_state *state = space->machine->driver_data<pc88va_state>();
894   state->backupram_wp = 1;
863895}
864896
865897static WRITE16_HANDLER( backupram_wp_0_w )
866898{
867   backupram_wp = 0;
899   pc88va_state *state = space->machine->driver_data<pc88va_state>();
900   state->backupram_wp = 0;
868901}
869902
870903static READ8_HANDLER( hdd_status_r )
r9675r9676
938971
939972static READ16_HANDLER( screen_ctrl_r )
940973{
941   return screen_ctrl_reg;
974   pc88va_state *state = space->machine->driver_data<pc88va_state>();
975   return state->screen_ctrl_reg;
942976}
943977
944978static WRITE16_HANDLER( screen_ctrl_w )
945979{
946   screen_ctrl_reg = data;
980   pc88va_state *state = space->machine->driver_data<pc88va_state>();
981   state->screen_ctrl_reg = data;
947982}
948983
949984static TIMER_CALLBACK( t3_mouse_callback )
950985{
951   if(timer3_io_reg & 0x80)
986   pc88va_state *state = machine->driver_data<pc88va_state>();
987   if(state->timer3_io_reg & 0x80)
952988   {
953989      pic8259_ir5_w(machine->device("pic8259_slave"), 1);
954      timer_adjust_oneshot(t3_mouse_timer, ATTOTIME_IN_HZ(120 >> (timer3_io_reg & 3)), 0);
990      timer_adjust_oneshot(state->t3_mouse_timer, ATTOTIME_IN_HZ(120 >> (state->timer3_io_reg & 3)), 0);
955991   }
956992}
957993
958994static WRITE8_HANDLER( timer3_ctrl_reg_w )
959995{
996   pc88va_state *state = space->machine->driver_data<pc88va_state>();
960997   /*
961998   x--- ---- MINTEN (TCU irq enable)
962999   ---- --xx general purpose timer 3 interval (120, 60, 30, 15)
9631000   */
964   timer3_io_reg = data;
1001   state->timer3_io_reg = data;
9651002
9661003   if(data & 0x80)
967      timer_adjust_oneshot(t3_mouse_timer, ATTOTIME_IN_HZ(120 >> (timer3_io_reg & 3)), 0);
1004      timer_adjust_oneshot(state->t3_mouse_timer, ATTOTIME_IN_HZ(120 >> (state->timer3_io_reg & 3)), 0);
9681005   else
9691006   {
9701007      pic8259_ir5_w(space->machine->device("pic8259_slave"), 0);
971      timer_adjust_oneshot(t3_mouse_timer, attotime_never, 0);
1008      timer_adjust_oneshot(state->t3_mouse_timer, attotime_never, 0);
9721009   }
9731010}
9741011
9751012static WRITE16_HANDLER( video_pri_w )
9761013{
977   COMBINE_DATA(&video_pri_reg[offset]);
1014   pc88va_state *state = space->machine->driver_data<pc88va_state>();
1015   COMBINE_DATA(&state->video_pri_reg[offset]);
9781016}
9791017
9801018static READ8_HANDLER( backupram_dsw_r )
r9675r9676
10561094   AM_RANGE(0x0220, 0x023f) AM_RAM // Frame buffer 1 control parameter
10571095   AM_RANGE(0x0240, 0x025f) AM_RAM // Frame buffer 2 control parameter
10581096   AM_RANGE(0x0260, 0x027f) AM_RAM // Frame buffer 3 control parameter
1059   AM_RANGE(0x0300, 0x033f) AM_RAM_WRITE(palette_ram_w) AM_BASE(&palram) // Palette RAM (xBBBBxRRRRxGGGG format)
1097   AM_RANGE(0x0300, 0x033f) AM_RAM_WRITE(palette_ram_w) AM_BASE_MEMBER(pc88va_state, palram) // Palette RAM (xBBBBxRRRRxGGGG format)
10601098
10611099//   AM_RANGE(0x0500, 0x05ff) GVRAM
10621100//   AM_RANGE(0x1000, 0xfeff) user area (???)
r9675r9676
13141352
13151353static READ8_DEVICE_HANDLER( fdd_portc_r )
13161354{
1317   static UINT8 test1,test2;
1355   pc88va_state *state = device->machine->driver_data<pc88va_state>();
1356   state->portc_test^=5;
13181357
1319   test1^=4;
1320   test2^=1;
1321
1322   return 0xff ^ test1 ^ test2;
1358   return 0xff ^ state->portc_test;
13231359}
13241360
13251361static WRITE8_DEVICE_HANDLER( fdd_porta_w )
r9675r9676
14281464
14291465static MACHINE_START( pc88va )
14301466{
1467   pc88va_state *state = machine->driver_data<pc88va_state>();
14311468   cpu_set_irq_callback(machine->device("maincpu"), pc88va_irq_callback);
14321469
1433   t3_mouse_timer = timer_alloc(machine, t3_mouse_callback, 0);
1434   timer_adjust_oneshot(t3_mouse_timer, attotime_never, 0);
1470   state->t3_mouse_timer = timer_alloc(machine, t3_mouse_callback, 0);
1471   timer_adjust_oneshot(state->t3_mouse_timer, attotime_never, 0);
14351472}
14361473
14371474static MACHINE_RESET( pc88va )
14381475{
1476   pc88va_state *state = machine->driver_data<pc88va_state>();
14391477   UINT8 *ROM00 = memory_region(machine, "rom00");
14401478   UINT8 *ROM10 = memory_region(machine, "rom10");
14411479
14421480   memory_set_bankptr(machine, "rom10_bank", &ROM10[0x00000]);
14431481   memory_set_bankptr(machine, "rom00_bank", &ROM00[0x00000]);
14441482
1445   bank_reg = 0x4100;
1446   backupram_wp = 1;
1483   state->bank_reg = 0x4100;
1484   state->backupram_wp = 1;
14471485
14481486   /* default palette */
14491487   {
r9675r9676
14521490         palette_set_color_rgb(machine,i,pal1bit((i & 2) >> 1),pal1bit((i & 4) >> 2),pal1bit(i & 1));
14531491   }
14541492
1455   tsp.tvram_vreg_offset = 0;
1493   state->tsp.tvram_vreg_offset = 0;
14561494}
14571495
14581496static INTERRUPT_GEN( pc88va_vrtc_irq )
r9675r9676
15321570   NULL
15331571};
15341572
1535static MACHINE_CONFIG_START( pc88va, driver_device )
1573static MACHINE_CONFIG_START( pc88va, pc88va_state )
15361574
15371575   MDRV_CPU_ADD("maincpu", V30, 8000000)        /* 8 MHz */
15381576   MDRV_CPU_PROGRAM_MAP(pc88va_map)
src/mess/drivers/smc777.c
r9675r9676
2222#include "formats/basicdsk.h"
2323#include "devices/flopdrv.h"
2424
25static UINT16 cursor_addr,cursor_raster;
26static UINT8 keyb_press,keyb_press_flag;
27static UINT8 backdrop_pen;
28static UINT8 display_reg;
29static UINT8 *smc777_wram;
3025
26class smc777_state : public driver_device
27{
28public:
29   smc777_state(running_machine &machine, const driver_device_config_base &config)
30      : driver_device(machine, config) { }
31
32   UINT16 cursor_addr;
33   UINT16 cursor_raster;
34   UINT8 keyb_press;
35   UINT8 keyb_press_flag;
36   UINT8 backdrop_pen;
37   UINT8 display_reg;
38   UINT8 *wram;
39   int addr_latch;
40   UINT8 fdc_irq_flag;
41   UINT8 fdc_drq_flag;
42   UINT8 system_data;
43   struct { UINT8 r,g,b; } pal;
44};
45
46
47
3148#define CRTC_MIN_X 10
3249#define CRTC_MIN_Y 10
3350
r9675r9676
3754
3855static VIDEO_UPDATE( smc777 )
3956{
57   smc777_state *state = screen->machine->driver_data<smc777_state>();
4058   int x,y,yi;
4159   UINT16 count;
4260   UINT8 *vram = memory_region(screen->machine, "vram");
r9675r9676
4462   UINT8 *gram = memory_region(screen->machine, "fbuf");
4563   int x_width;
4664
47   bitmap_fill(bitmap, cliprect, screen->machine->pens[backdrop_pen+0x10]);
65   bitmap_fill(bitmap, cliprect, screen->machine->pens[state->backdrop_pen+0x10]);
4866
49   x_width = (display_reg & 0x80) ? 80 : 160;
67   x_width = (state->display_reg & 0x80) ? 80 : 160;
5068
5169   count = 0x0000;
5270
r9675r9676
7694
7795   count = 0x0000;
7896
79   x_width = (display_reg & 0x80) ? 40 : 80;
97   x_width = (state->display_reg & 0x80) ? 40 : 80;
8098
8199   for(y=0;y<25;y++)
82100   {
r9675r9676
104122         drawgfx_transpen(bitmap,cliprect,screen->machine->gfx[0],tile,color,0,0,x*8+CRTC_MIN_X,y*8+CRTC_MIN_Y,0);
105123
106124         // draw cursor
107         if(cursor_addr == count)
125         if(state->cursor_addr == count)
108126         {
109127            int xc,yc,cursor_on;
110128
111129            cursor_on = 0;
112            switch(cursor_raster & 0x60)
130            switch(state->cursor_raster & 0x60)
113131            {
114132               case 0x00: cursor_on = 1; break; //always on
115133               case 0x20: cursor_on = 0; break; //always off
r9675r9676
119137
120138            if(cursor_on)
121139            {
122               for(yc=0;yc<(8-(cursor_raster & 7));yc++)
140               for(yc=0;yc<(8-(state->cursor_raster & 7));yc++)
123141               {
124142                  for(xc=0;xc<8;xc++)
125143                  {
r9675r9676
129147            }
130148         }
131149
132         (display_reg & 0x80) ? count+=2 : count++;
150         (state->display_reg & 0x80) ? count+=2 : count++;
133151      }
134152   }
135153
r9675r9676
138156
139157static WRITE8_HANDLER( smc777_6845_w )
140158{
141   static int addr_latch;
142
159   smc777_state *state = space->machine->driver_data<smc777_state>();
143160   if(offset == 0)
144161   {
145      addr_latch = data;
162      state->addr_latch = data;
146163      //mc6845_address_w(space->machine->device("crtc"), 0,data);
147164   }
148165   else
149166   {
150167      /* FIXME: this should be inside the MC6845 core! */
151      if(addr_latch == 0x0a)
152         cursor_raster = data;
153      else if(addr_latch == 0x0e)
154         cursor_addr = ((data<<8) & 0x3f00) | (cursor_addr & 0xff);
155      else if(addr_latch == 0x0f)
156         cursor_addr = (cursor_addr & 0x3f00) | (data & 0xff);
168      if(state->addr_latch == 0x0a)
169         state->cursor_raster = data;
170      else if(state->addr_latch == 0x0e)
171         state->cursor_addr = ((data<<8) & 0x3f00) | (state->cursor_addr & 0xff);
172      else if(state->addr_latch == 0x0f)
173         state->cursor_addr = (state->cursor_addr & 0x3f00) | (data & 0xff);
157174
158175      //mc6845_register_w(space->machine->device("crtc"), 0,data);
159176   }
r9675r9676
241258   fbuf[vram_index | offset*0x100] = data;
242259}
243260
244static UINT8 fdc_irq_flag;
245static UINT8 fdc_drq_flag;
246261
247262static void check_floppy_inserted(running_machine *machine)
248263{
r9675r9676
261276
262277static READ8_HANDLER( smc777_fdc1_r )
263278{
279   smc777_state *state = space->machine->driver_data<smc777_state>();
264280   running_device* dev = space->machine->device("fdc");
265281
266282   check_floppy_inserted(space->machine);
r9675r9676
276292      case 0x03:
277293         return wd17xx_data_r(dev,offset);
278294      case 0x04: //irq / drq status
279         //popmessage("%02x %02x\n",fdc_irq_flag,fdc_drq_flag);
295         //popmessage("%02x %02x\n",state->fdc_irq_flag,state->fdc_drq_flag);
280296
281         return (fdc_irq_flag ? 0x80 : 0x00) | (fdc_drq_flag ? 0x00 : 0x40);
297         return (state->fdc_irq_flag ? 0x80 : 0x00) | (state->fdc_drq_flag ? 0x00 : 0x40);
282298   }
283299
284300   return 0x00;
r9675r9676
316332
317333static WRITE_LINE_DEVICE_HANDLER( smc777_fdc_intrq_w )
318334{
319   fdc_irq_flag = state;
335   smc777_state *drvstate = device->machine->driver_data<smc777_state>();
336   drvstate->fdc_irq_flag = state;
320337//  cputag_set_input_line(device->machine, "maincpu", 0, (state) ? ASSERT_LINE : CLEAR_LINE);
321338}
322339
323340static WRITE_LINE_DEVICE_HANDLER( smc777_fdc_drq_w )
324341{
325   fdc_drq_flag = state;
342   smc777_state *drvstate = device->machine->driver_data<smc777_state>();
343   drvstate->fdc_drq_flag = state;
326344}
327345
328346
329347static READ8_HANDLER( key_r )
330348{
349   smc777_state *state = space->machine->driver_data<smc777_state>();
331350   UINT8 res;
332351
333352   if(offset == 1) //keyboard status
334      return (0xfc) | keyb_press_flag;
353      return (0xfc) | state->keyb_press_flag;
335354
336   keyb_press_flag = 0;
337   res = keyb_press;
338//  keyb_press = 0xff;
355   state->keyb_press_flag = 0;
356   res = state->keyb_press;
357//  state->keyb_press = 0xff;
339358
340359   return res;
341360}
342361
343362static WRITE8_HANDLER( border_col_w )
344363{
345   backdrop_pen = data & 0xf;
364   smc777_state *state = space->machine->driver_data<smc777_state>();
365   state->backdrop_pen = data & 0xf;
346366}
347367
348static UINT8 system_data;
349368
350369static READ8_HANDLER( system_input_r )
351370{
352   return system_data;
371   smc777_state *state = space->machine->driver_data<smc777_state>();
372   return state->system_data;
353373}
354374
355375static WRITE8_HANDLER( system_output_w )
356376{
377   smc777_state *state = space->machine->driver_data<smc777_state>();
357378   /*
358379    ---x --- beep
359380    all the rest is unknown at current time
360381    */
361   system_data = data;
382   state->system_data = data;
362383   beep_set_state(space->machine->device("beeper"),data & 0x10);
363384}
364385
r9675r9676
369390
370391static WRITE8_HANDLER( smc777_ramdac_w )
371392{
372   static UINT8 pal_index,gradient_index,r,g,b;
393   smc777_state *state = space->machine->driver_data<smc777_state>();
394   UINT8 pal_index,gradient_index;
373395   pal_index = cpu_get_reg(space->machine->device("maincpu"), Z80_B) & 0xf;
374396   gradient_index = (cpu_get_reg(space->machine->device("maincpu"), Z80_B) & 0x30) >> 4;
375397
376398   switch(gradient_index)
377399   {
378      case 0: r = data; palette_set_color_rgb(space->machine, pal_index+0x10, r,g,b); break;
379      case 1: g = data; palette_set_color_rgb(space->machine, pal_index+0x10, r,g,b); break;
380      case 2: b = data; palette_set_color_rgb(space->machine, pal_index+0x10, r,g,b); break;
400      case 0: state->pal.r = data; palette_set_color_rgb(space->machine, pal_index+0x10, state->pal.r, state->pal.g, state->pal.b); break;
401      case 1: state->pal.g = data; palette_set_color_rgb(space->machine, pal_index+0x10, state->pal.r, state->pal.g, state->pal.b); break;
402      case 2: state->pal.b = data; palette_set_color_rgb(space->machine, pal_index+0x10, state->pal.r, state->pal.g, state->pal.b); break;
381403   }
382404}
383405
384406static READ8_HANDLER( display_reg_r )
385407{
386   return display_reg;
408   smc777_state *state = space->machine->driver_data<smc777_state>();
409   return state->display_reg;
387410}
388411
389412static WRITE8_HANDLER( display_reg_w )
390413{
414   smc777_state *state = space->machine->driver_data<smc777_state>();
391415   /*
392416    x--- ---- width 80 / 40 switch (0 = 640 x 200 1 = 320 x 200)
393417    ---- -x-- mode select?
394418    */
395419
396420   {
397      if((display_reg & 0x80) != (data & 0x80))
421      if((state->display_reg & 0x80) != (data & 0x80))
398422      {
399423         rectangle visarea = space->machine->primary_screen->visible_area();
400424         int x_width;
r9675r9676
409433      }
410434   }
411435
412   display_reg = data;
436   state->display_reg = data;
413437}
414438
415439static ADDRESS_MAP_START(smc777_mem, ADDRESS_SPACE_PROGRAM, 8)
416440   ADDRESS_MAP_UNMAP_HIGH
417   AM_RANGE(0x0000, 0xffff) AM_RAM AM_BASE(&smc777_wram)
441   AM_RANGE(0x0000, 0xffff) AM_RAM AM_BASE_MEMBER(smc777_state, wram)
418442ADDRESS_MAP_END
419443
420444static ADDRESS_MAP_START( smc777_io , ADDRESS_SPACE_IO, 8)
r9675r9676
568592
569593static TIMER_CALLBACK( keyboard_callback )
570594{
595   smc777_state *state = machine->driver_data<smc777_state>();
571596   const char* portnames[3] = { "key1","key2","key3" };
572597   int i,port_i,scancode;
573598   //UINT8 keymod = input_port_read(machine,"key_modifiers") & 0x1f;
r9675r9676
594619//                      scancode = 0x3d;
595620//                  }
596621//              }
597            keyb_press = scancode;
598            keyb_press_flag = 1;
622            state->keyb_press = scancode;
623            state->keyb_press_flag = 1;
599624            return;
600625         }
601626         scancode++;
r9675r9676
605630
606631static MACHINE_START(smc777)
607632{
633   smc777_state *state = machine->driver_data<smc777_state>();
608634   UINT8 *rom = memory_region(machine, "bios");
609635   int i;
610636
611637   for(i=0;i<0x4000;i++)
612      smc777_wram[i] = rom[i];
638      state->wram[i] = rom[i];
613639
614640   timer_pulse(machine, ATTOTIME_IN_HZ(240/32), NULL, 0, keyboard_callback);
615641   beep_set_frequency(machine->device("beeper"),300); //guesswork
r9675r9676
699725   NULL
700726};
701727
702static MACHINE_CONFIG_START( smc777, driver_device )
728static MACHINE_CONFIG_START( smc777, smc777_state )
703729    /* basic machine hardware */
704730    MDRV_CPU_ADD("maincpu",Z80, XTAL_4MHz) //4,028 Mhz!
705731    MDRV_CPU_PROGRAM_MAP(smc777_mem)
src/mess/drivers/pc98.c
r9675r9676
231231#include "machine/8237dma.h"
232232#include "machine/pic8259.h"
233233
234static UINT32 *pc9801_vram;
235static UINT32 *gfx_bitmap_ram;
236static UINT32 *work_ram_banked;
237static UINT8 ems_bank;
238static UINT8 wram_bank;
239234
235class pc98_state : public driver_device
236{
237public:
238   pc98_state(running_machine &machine, const driver_device_config_base &config)
239      : driver_device(machine, config) { }
240240
241   UINT32 *pc9801_vram;
242   UINT32 *gfx_bitmap_ram;
243   UINT32 *work_ram_banked;
244   UINT8 ems_bank;
245   UINT8 wram_bank;
246   UINT8 rom_bank;
247   UINT8 gate_a20;
248   UINT8 wram_latch_reg;
249   UINT8 portb_tmp;
250   int dma_channel;
251   UINT8 dma_offset[2][4];
252   UINT8 at_pages[0x10];
253};
254
255
256
241257static VIDEO_START( pc9801 )
242258{
243   gfx_bitmap_ram = auto_alloc_array(machine, UINT32, 0x18000*2);
244   work_ram_banked = auto_alloc_array(machine, UINT32, 0x2000*0xfe); //shouldn't be here
259   pc98_state *state = machine->driver_data<pc98_state>();
260   state->gfx_bitmap_ram = auto_alloc_array(machine, UINT32, 0x18000*2);
261   state->work_ram_banked = auto_alloc_array(machine, UINT32, 0x2000*0xfe); //shouldn't be here
245262}
246263
247264/*
r9675r9676
256273
257274static VIDEO_UPDATE( pc9801 )
258275{
276   pc98_state *state = screen->machine->driver_data<pc98_state>();
259277//  const gfx_element *gfx = screen->machine->gfx[0];
260278   int y,x;
261279   int yi,xi;
r9675r9676
271289            {
272290               int tile,attr,pen[3],pen_mask,color;
273291
274               tile = (pc9801_vram[(x+y*40)] & 0x00ff0000) >> 16;
275               attr = (pc9801_vram[((x+y*40)+0x2000/4)] & 0x00ff0000) >> 16;
292               tile = (state->pc9801_vram[(x+y*40)] & 0x00ff0000) >> 16;
293               attr = (state->pc9801_vram[((x+y*40)+0x2000/4)] & 0x00ff0000) >> 16;
276294
277295               pen_mask = (attr & 0xe0)>>5;
278296
r9675r9676
288306               if(((x*2+1)*8+xi)<screen->machine->primary_screen->visible_area().max_x && (y*8+yi)<screen->machine->primary_screen->visible_area().max_y)
289307                  *BITMAP_ADDR16(bitmap, y*8+yi, (x*2+1)*8+xi) = screen->machine->pens[color];
290308
291               tile = (pc9801_vram[(x+y*40)] & 0x000000ff) >> 0;
292               attr = (pc9801_vram[((x+y*40)+0x2000/4)] & 0x000000ff) >> 0;
309               tile = (state->pc9801_vram[(x+y*40)] & 0x000000ff) >> 0;
310               attr = (state->pc9801_vram[((x+y*40)+0x2000/4)] & 0x000000ff) >> 0;
293311
294312               pen_mask = (attr & 0xe0)>>5;
295313
r9675r9676
427445      crtc_cmd_w(space,0,data);
428446}
429447
430static UINT8 rom_bank;
431448
432449static WRITE8_HANDLER( ems_sel_w )
433450{
451   pc98_state *state = space->machine->driver_data<pc98_state>();
434452//  printf("%02x %02x\n",offset,data);
435453
436454   if(offset == 1)
r9675r9676
439457
440458      if(data == 0x00 || data == 0x10)
441459      {
442         rom_bank = 1;
460         state->rom_bank = 1;
443461         memory_set_bankptr(space->machine, "bank1", &ROM[0x20000]);
444462      }
445463
446464      if(data == 0x02 || data == 0x12)
447465      {
448         rom_bank = 0;
466         state->rom_bank = 0;
449467         memory_set_bankptr(space->machine, "bank1", &ROM[0x00000]);
450468      }
451469   }
r9675r9676
453471   if(offset == 3)
454472   {
455473      if(data == 0x22)
456         ems_bank = 1;
474         state->ems_bank = 1;
457475      if(data == 0x20)
458         ems_bank = 0;
476         state->ems_bank = 0;
459477      //printf("%02x %02x\n",offset,data);
460478   }
461479}
462480
463481static WRITE8_HANDLER( rom_bank_w )
464482{
483   pc98_state *state = space->machine->driver_data<pc98_state>();
465484   UINT8 *ROM = memory_region(space->machine, "cpudata");
466485
467//  printf("%08x %04x %08x\n",ROM[offset+(rom_bank*0x20000/4)],offset+(rom_bank*0x20000/4),data);
486//  printf("%08x %04x %08x\n",ROM[offset+(state->rom_bank*0x20000/4)],offset+(state->rom_bank*0x20000/4),data);
468487
469488   /* NOP any attempt to write on ROM (TODO: why it's overwriting here anyway? Doesn't make sense...) */
470   if((rom_bank == 0 && offset < 0x8000) || (rom_bank == 1 && offset < 0x18000))
471      ROM[offset+(rom_bank*0x20000)] = data;
489   if((state->rom_bank == 0 && offset < 0x8000) || (state->rom_bank == 1 && offset < 0x18000))
490      ROM[offset+(state->rom_bank*0x20000)] = data;
472491}
473492
474493static READ8_HANDLER( port_70_r )
r9675r9676
520539   }
521540}
522541
523static UINT8 gate_a20;
524542
525543static READ8_HANDLER( port_f0_r )
526544{
545   pc98_state *state = space->machine->driver_data<pc98_state>();
527546   if(offset == 0x02)
528      return (gate_a20 ^ 1) | 0x2e;
547      return (state->gate_a20 ^ 1) | 0x2e;
529548   else if(offset == 0x06)
530      return (gate_a20 ^ 1) | 0x5e;
549      return (state->gate_a20 ^ 1) | 0x5e;
531550
532551   return 0x00;
533552}
534553
535554static WRITE8_HANDLER( port_f0_w )
536555{
556   pc98_state *state = space->machine->driver_data<pc98_state>();
537557   if(offset == 0x00)
538558   {
539559      //cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_RESET, PULSE_LINE);
r9675r9676
541561
542562   if(offset == 0x02)
543563   {
544      gate_a20 = 1;
545      cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_A20, gate_a20);
564      state->gate_a20 = 1;
565      cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_A20, state->gate_a20);
546566   }
547567   if(offset == 0x06)
548568   {
549569      if(data == 0x02)
550570      {
551         gate_a20 = 1;
552         cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_A20, gate_a20);
571         state->gate_a20 = 1;
572         cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_A20, state->gate_a20);
553573      }
554574      else if(data == 0x03)
555575      {
556         gate_a20 = 0;
557         cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_A20, gate_a20);
576         state->gate_a20 = 0;
577         cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_A20, state->gate_a20);
558578      }
559579   }
560580}
561581
562static UINT8 wram_latch_reg;
563582
564583static READ8_HANDLER( wram_sel_r )
565584{
566   return (wram_bank << 1) | wram_latch_reg;
585   pc98_state *state = space->machine->driver_data<pc98_state>();
586   return (state->wram_bank << 1) | state->wram_latch_reg;
567587}
568588
569589static WRITE8_HANDLER( wram_sel_w )
570590{
571   wram_bank = (data & 0xfe) >> 1;
572   wram_latch_reg = data & 1; //<- correct?
573   //printf("%02x\n",wram_bank);
591   pc98_state *state = space->machine->driver_data<pc98_state>();
592   state->wram_bank = (data & 0xfe) >> 1;
593   state->wram_latch_reg = data & 1; //<- correct?
594   //printf("%02x\n",state->wram_bank);
574595}
575596
576597static READ8_HANDLER( pc98_mouse_r )
r9675r9676
582603   return 0xff;
583604}
584605
585static READ32_HANDLER( gfx_bitmap_ram_r ) { return gfx_bitmap_ram[offset+ems_bank*0x18000/4]; }
586static WRITE32_HANDLER( gfx_bitmap_ram_w ) { COMBINE_DATA(&gfx_bitmap_ram[offset+ems_bank*0x18000/4]); }
606static READ32_HANDLER( gfx_bitmap_ram_r )
607{
608   pc98_state *state = space->machine->driver_data<pc98_state>();
609   return state->gfx_bitmap_ram[offset+state->ems_bank*0x18000/4];
610}
587611
588static READ32_HANDLER( wram_bank_r ) { return work_ram_banked[offset+wram_bank*0x2000/4]; }
589static WRITE32_HANDLER( wram_bank_w ) { COMBINE_DATA(&work_ram_banked[offset+wram_bank*0x2000/4]); }
612static WRITE32_HANDLER( gfx_bitmap_ram_w )
613{
614   pc98_state *state = space->machine->driver_data<pc98_state>();
615   COMBINE_DATA(&state->gfx_bitmap_ram[offset+state->ems_bank*0x18000/4]);
616}
590617
591static READ32_HANDLER( wram_ide_r ) { return work_ram_banked[offset+4*0x2000/4]; } //todo: ide hookup & calculate the correct bank number here
592static WRITE32_HANDLER( wram_ide_w ) { COMBINE_DATA(&work_ram_banked[offset+4*0x2000/4]); }
618static READ32_HANDLER( wram_bank_r )
619{
620   pc98_state *state = space->machine->driver_data<pc98_state>();
621   return state->work_ram_banked[offset+state->wram_bank*0x2000/4];
622}
593623
624static WRITE32_HANDLER( wram_bank_w )
625{
626   pc98_state *state = space->machine->driver_data<pc98_state>();
627   COMBINE_DATA(&state->work_ram_banked[offset+state->wram_bank*0x2000/4]);
628}
629
630static READ32_HANDLER( wram_ide_r ) //todo: ide hookup & calculate the correct bank number here
631{
632   pc98_state *state = space->machine->driver_data<pc98_state>();
633   return state->work_ram_banked[offset+4*0x2000/4];
634}
635
636static WRITE32_HANDLER( wram_ide_w )
637{
638   pc98_state *state = space->machine->driver_data<pc98_state>();
639   COMBINE_DATA(&state->work_ram_banked[offset+4*0x2000/4]);
640}
641
594642static ADDRESS_MAP_START( pc9801_mem, ADDRESS_SPACE_PROGRAM, 32)
595643   AM_RANGE(0x00000000, 0x0007ffff) AM_RAM
596644   AM_RANGE(0x00080000, 0x0009ffff) AM_READWRITE(wram_bank_r,wram_bank_w)
597   AM_RANGE(0x000a0000, 0x000a3fff) AM_RAM AM_BASE(&pc9801_vram) //vram + attr
645   AM_RANGE(0x000a0000, 0x000a3fff) AM_RAM AM_BASE_MEMBER(pc98_state, pc9801_vram) //vram + attr
598646   AM_RANGE(0x000a4000, 0x000a4fff) AM_RAM //cg window
599647   AM_RANGE(0x000a5000, 0x000a7fff) AM_RAM //??? (presumably another work ram bank)
600648   AM_RANGE(0x000a8000, 0x000bffff) AM_READWRITE(gfx_bitmap_ram_r,gfx_bitmap_ram_w)
r9675r9676
687735#include "cpu/i386/i386priv.h"
688736
689737
738
690739static MACHINE_RESET(pc9801)
691740{
741   pc98_state *state = machine->driver_data<pc98_state>();
692742   UINT8 *ROM = memory_region(machine, "cpudata");
693743
694744   cpu_set_irq_callback(machine->device("maincpu"), irq_callback);
695745
696746   cputag_set_input_line(machine, "maincpu", INPUT_LINE_A20, 0);
697747
698   gate_a20 = 0;
748   state->gate_a20 = 0;
699749   cpu_set_reg(machine->device("maincpu"), I386_EIP, 0xffff0+0x10000);
700750
701751   memory_set_bankptr(machine, "bank1", &ROM[0x20000]);
702752
703   wram_bank = 0;
704   rom_bank = 1;
753   state->wram_bank = 0;
754   state->rom_bank = 1;
705755}
706756
707757/*************************************************************
r9675r9676
765815
766816static READ8_DEVICE_HANDLER( pc98_portb_r )
767817{
768   static UINT8 tmp;
769
770   tmp ^= 1; //<- actually related to the RTC somehow
818   pc98_state *state = device->machine->driver_data<pc98_state>();
819   state->portb_tmp ^= 1; //<- actually related to the RTC somehow
771820   //printf("PPI Port B read\n");
772   return 0xf8 | tmp; //bit 2 seems used for error stuff (returns parity error or ems error on different spots), don't know the real use of it...
821   return 0xf8 | state->portb_tmp; //bit 2 seems used for error stuff (returns parity error or ems error on different spots), don't know the real use of it...
773822}
774823
775824static READ8_DEVICE_HANDLER( pc98_portc_r )
r9675r9676
860909      palette_set_color_rgb(machine, i+0x000, pal1bit(i >> 1), pal1bit(i >> 2), pal1bit(i >> 0));
861910}
862911
863static int dma_channel;
864static UINT8 dma_offset[2][4];
865912
866913#if 0
867static UINT8 at_pages[0x10];
868914
869915
870916static READ8_HANDLER(at_page8_r)
871917{
872   UINT8 data = at_pages[offset % 0x10];
918   pc98_state *state = space->machine->driver_data<pc98_state>();
919   UINT8 data = state->at_pages[offset % 0x10];
873920
874921   switch(offset % 8) {
875922   case 1:
876      data = dma_offset[(offset / 8) & 1][2];
923      data = state->dma_offset[(offset / 8) & 1][2];
877924      break;
878925   case 2:
879      data = dma_offset[(offset / 8) & 1][3];
926      data = state->dma_offset[(offset / 8) & 1][3];
880927      break;
881928   case 3:
882      data = dma_offset[(offset / 8) & 1][1];
929      data = state->dma_offset[(offset / 8) & 1][1];
883930      break;
884931   case 7:
885      data = dma_offset[(offset / 8) & 1][0];
932      data = state->dma_offset[(offset / 8) & 1][0];
886933      break;
887934   }
888935   return data;
r9675r9676
891938
892939static WRITE8_HANDLER(at_page8_w)
893940{
894   at_pages[offset % 0x10] = data;
941   pc98_state *state = space->machine->driver_data<pc98_state>();
942   state->at_pages[offset % 0x10] = data;
895943
896944   switch(offset % 8) {
897945   case 1:
898      dma_offset[(offset / 8) & 1][2] = data;
946      state->dma_offset[(offset / 8) & 1][2] = data;
899947      break;
900948   case 2:
901      dma_offset[(offset / 8) & 1][3] = data;
949      state->dma_offset[(offset / 8) & 1][3] = data;
902950      break;
903951   case 3:
904      dma_offset[(offset / 8) & 1][1] = data;
952      state->dma_offset[(offset / 8) & 1][1] = data;
905953      break;
906954   case 7:
907      dma_offset[(offset / 8) & 1][0] = data;
955      state->dma_offset[(offset / 8) & 1][0] = data;
908956      break;
909957   }
910958}
r9675r9676
921969
922970static READ8_HANDLER( pc_dma_read_byte )
923971{
924   offs_t page_offset = (((offs_t) dma_offset[0][dma_channel]) << 16)
972   pc98_state *state = space->machine->driver_data<pc98_state>();
973   offs_t page_offset = (((offs_t) state->dma_offset[0][state->dma_channel]) << 16)
925974      & 0xFF0000;
926975
927976   return space->read_byte(page_offset + offset);
r9675r9676
930979
931980static WRITE8_HANDLER( pc_dma_write_byte )
932981{
933   offs_t page_offset = (((offs_t) dma_offset[0][dma_channel]) << 16)
982   pc98_state *state = space->machine->driver_data<pc98_state>();
983   offs_t page_offset = (((offs_t) state->dma_offset[0][state->dma_channel]) << 16)
934984      & 0xFF0000;
935985
936986   space->write_byte(page_offset + offset, data);
r9675r9676
938988
939989static void set_dma_channel(running_device *device, int channel, int state)
940990{
941   if (!state) dma_channel = channel;
991   pc98_state *drvstate = device->machine->driver_data<pc98_state>();
992   if (!state) drvstate->dma_channel = channel;
942993}
943994
944995static WRITE_LINE_DEVICE_HANDLER( pc_dack0_w ) { set_dma_channel(device, 0, state); }
r9675r9676
9591010
9601011/* I suspect the dump for pc9801 comes from a i386 later model... the original machine would use a i8086 @ 5Mhz CPU (see notes at top) */
9611012/* More investigations are required, but in the meanwhile I set a I386 as main CPU */
962static MACHINE_CONFIG_START( pc9801, driver_device )
1013static MACHINE_CONFIG_START( pc9801, pc98_state )
9631014   /* basic machine hardware */
9641015   MDRV_CPU_ADD("maincpu", I386, 16000000)
9651016   MDRV_CPU_PROGRAM_MAP(pc9801_mem)
src/mess/drivers/pippin.c
r9675r9676
3333#include "devices/chd_cd.h"
3434#include "sound/cdda.h"
3535
36
37class pippin_state : public driver_device
38{
39public:
40   pippin_state(running_machine &machine, const driver_device_config_base &config)
41      : driver_device(machine, config) { }
42
43   UINT16 unk1_test;
44   UINT8 portb_data;
45};
46
47
3648static READ64_HANDLER( unk1_r )
3749{
38   static UINT16 test;
50   pippin_state *state = space->machine->driver_data<pippin_state>();
51   state->unk1_test ^= 0x0400; //PC=ff808760
3952
40   test ^= 0x0400; //PC=ff808760
41
42   return test << 16 | 0;
53   return state->unk1_test << 16 | 0;
4354}
4455
4556static READ64_HANDLER( unk2_r )
r9675r9676
5061   return 0;
5162}
5263
53static UINT8 portb_data;
5464
5565static READ64_HANDLER( adb_portb_r )
5666{
67   pippin_state *state = space->machine->driver_data<pippin_state>();
5768   if(ACCESSING_BITS_56_63)
5869   {
59      if(portb_data == 0x10)
70      if(state->portb_data == 0x10)
6071         return (UINT64)0x08 << 56;
6172
62      if(portb_data == 0x38)   //fff04c80
73      if(state->portb_data == 0x38)   //fff04c80
6374         return (UINT64)0x20 << 56; //almost sure this is wrong
6475
65      //printf("PORTB R %02x\n",portb_data);
76      //printf("PORTB R %02x\n",state->portb_data);
6677
6778
6879      return 0;
r9675r9676
7384
7485static WRITE64_HANDLER( adb_portb_w )
7586{
87   pippin_state *state = space->machine->driver_data<pippin_state>();
7688   if(ACCESSING_BITS_56_63)
7789   {
78      portb_data = (UINT64)data >> 56;
90      state->portb_data = (UINT64)data >> 56;
7991   }
8092}
8193
r9675r9676
125137    return 0;
126138}
127139
128static MACHINE_CONFIG_START( pippin, driver_device )
140static MACHINE_CONFIG_START( pippin, pippin_state )
129141    /* basic machine hardware */
130142    MDRV_CPU_ADD("maincpu",PPC603, 66000000)
131143    MDRV_CPU_PROGRAM_MAP(pippin_mem)
src/mess/drivers/vector06.c
r9675r9676
167167};
168168
169169/* Machine driver */
170static MACHINE_CONFIG_START( vector06, driver_device )
170static MACHINE_CONFIG_START( vector06, vector06_state )
171171  /* basic machine hardware */
172172   MDRV_CPU_ADD("maincpu", I8080, 3000000)
173173//  MDRV_CPU_ADD("maincpu", Z80, 3000000)
src/mess/drivers/sapi1.c
r9675r9676
2323   //AM_RANGE(0x2800, 0x2bff) AM_NOP // PORT 1
2424   //AM_RANGE(0x2c00, 0x2fff) AM_NOP // PORT 2
2525   //AM_RANGE(0x3000, 0x33ff) AM_NOP // 3214
26   AM_RANGE(0x3800, 0x3fff) AM_RAM AM_BASE(&sapi_video_ram) // AND-1 (video RAM)
26   AM_RANGE(0x3800, 0x3fff) AM_RAM AM_BASE_MEMBER(sapi1_state, sapi_video_ram) // AND-1 (video RAM)
2727   AM_RANGE(0x4000, 0x7fff) AM_RAM // REM-1
2828ADDRESS_MAP_END
2929
r9675r9676
9494INPUT_PORTS_END
9595
9696/* Machine driver */
97static MACHINE_CONFIG_START( sapi1, driver_device )
97static MACHINE_CONFIG_START( sapi1, sapi1_state )
9898   /* basic machine hardware */
9999   MDRV_CPU_ADD("maincpu", I8080, 2000000)
100100   MDRV_CPU_PROGRAM_MAP(sapi1_mem)
r9675r9676
122122   MDRV_RAM_DEFAULT_SIZE("64K")
123123MACHINE_CONFIG_END
124124
125static MACHINE_CONFIG_START( sapizps3, driver_device )
125static MACHINE_CONFIG_START( sapizps3, sapi1_state )
126126   /* basic machine hardware */
127127   MDRV_CPU_ADD("maincpu", Z80, 2000000)
128128   MDRV_CPU_PROGRAM_MAP(sapizps3_mem)
src/mess/drivers/poly88.c
r9675r9676
2020   AM_RANGE(0x1000, 0x1fff) AM_ROM // System Expansion area
2121   AM_RANGE(0x2000, 0x3fff) AM_RAM // Minimal user RAM area
2222   AM_RANGE(0x4000, 0xf7ff) AM_RAM
23   AM_RANGE(0xf800, 0xfbff) AM_RAM AM_BASE(&poly88_video_ram) // Video RAM
23   AM_RANGE(0xf800, 0xfbff) AM_RAM AM_BASE_MEMBER(poly88_state, video_ram) // Video RAM
2424ADDRESS_MAP_END
2525
2626static ADDRESS_MAP_START( poly88_io , ADDRESS_SPACE_IO, 8)
r9675r9676
3737   AM_RANGE(0x0000, 0x03ff) AM_ROM // Monitor ROM
3838   AM_RANGE(0x0400, 0x0bff) AM_ROM // Disk System ROM
3939   AM_RANGE(0x0c00, 0x0fff) AM_RAM // System RAM
40   AM_RANGE(0x1800, 0x1bff) AM_RAM AM_BASE(&poly88_video_ram) // Video RAM
40   AM_RANGE(0x1800, 0x1bff) AM_RAM AM_BASE_MEMBER(poly88_state, video_ram) // Video RAM
4141   AM_RANGE(0x2000, 0xffff) AM_RAM // RAM
4242ADDRESS_MAP_END
4343
r9675r9676
144144};
145145
146146
147static MACHINE_CONFIG_START( poly88, driver_device )
147static MACHINE_CONFIG_START( poly88, poly88_state )
148148    /* basic machine hardware */
149149    MDRV_CPU_ADD("maincpu",I8080, 1853000)
150150    MDRV_CPU_PROGRAM_MAP(poly88_mem)
src/mess/drivers/z1013.c
r9675r9676
1515/* Address maps */
1616static ADDRESS_MAP_START(z1013_mem, ADDRESS_SPACE_PROGRAM, 8)
1717    AM_RANGE( 0x0000, 0xefff ) AM_RAM
18    AM_RANGE( 0xec00, 0xefff ) AM_RAM AM_BASE(&z1013_video_ram)
18    AM_RANGE( 0xec00, 0xefff ) AM_RAM AM_BASE_MEMBER(z1013_state, video_ram)
1919    AM_RANGE( 0xf000, 0xffff ) AM_ROM //  ROM
2020ADDRESS_MAP_END
2121
r9675r9676
166166
167167
168168/* Machine driver */
169static MACHINE_CONFIG_START( z1013, driver_device )
169static MACHINE_CONFIG_START( z1013, z1013_state )
170170   /* basic machine hardware */
171171   MDRV_CPU_ADD("maincpu", Z80, XTAL_1MHz )
172172   MDRV_CPU_PROGRAM_MAP(z1013_mem)
src/mess/drivers/primo.c
r9675r9676
251251   { NULL}
252252};
253253
254static MACHINE_CONFIG_START( primoa32, driver_device )
254static MACHINE_CONFIG_START( primoa32, primo_state )
255255   /* basic machine hardware */
256256   MDRV_CPU_ADD( "maincpu", Z80, 2500000 )
257257   MDRV_CPU_PROGRAM_MAP( primo32_mem)
src/mess/drivers/ti85.c
r9675r9676
486486      PORT_DIPSETTING( 0x00, "Low Battery" )
487487INPUT_PORTS_END
488488
489class ti_state : public driver_device
490{
491public:
492   ti_state(running_machine &machine, const driver_device_config_base &config)
493      : driver_device(machine, config),
494        m_nvram(*this, "nvram") { }
495
496   optional_shared_ptr<UINT8>   m_nvram;
497};
498
499489/* machine definition */
500static MACHINE_CONFIG_START( ti81, ti_state )
490static MACHINE_CONFIG_START( ti81, ti85_state )
501491   /* basic machine hardware */
502492   MDRV_CPU_ADD("maincpu", Z80, 2000000)        /* 2 MHz */
503493   MDRV_CPU_PROGRAM_MAP(ti81_mem)
src/mess/drivers/z88.c
r9675r9676
736736   PORT_BIT(0x001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH)                     PORT_CHAR('\xA3') PORT_CHAR('~')
737737INPUT_PORTS_END
738738
739static MACHINE_CONFIG_START( z88, driver_device )
739static MACHINE_CONFIG_START( z88, z88_state )
740740   /* basic machine hardware */
741741   MDRV_CPU_ADD("maincpu", Z80, 3276800)
742742   MDRV_CPU_PROGRAM_MAP(z88_mem)
src/mess/drivers/pcw16.c
r9675r9676
107107#include "devices/messram.h"
108108
109109// interrupt counter
110static unsigned long pcw16_interrupt_counter;
111110/* controls which bank of 2mb address space is paged into memory */
112static int pcw16_banks[4];
113111
114112// output of 4-bit port from Anne ASIC
115static int pcw16_4_bit_port;
116113// code defining which INT fdc is connected to
117static int pcw16_fdc_int_code;
118114// interrupt bits
119115// bit 7: ??
120116// bit 6: fdc
r9675r9676
123119// bit 2: Vsync state
124120// bit 1: keyboard int
125121// bit 0: Display ints
126static int pcw16_system_status;
127122
128123// debugging - write ram as seen by cpu
129124static void pcw16_refresh_ints(running_machine *machine)
130125{
126   pcw16_state *state = machine->driver_data<pcw16_state>();
131127   /* any bits set excluding vsync */
132   if ((pcw16_system_status & (~0x04))!=0)
128   if ((state->system_status & (~0x04))!=0)
133129   {
134130      cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE);
135131   }
r9675r9676
142138
143139static TIMER_CALLBACK(pcw16_timer_callback)
144140{
141   pcw16_state *state = machine->driver_data<pcw16_state>();
145142   /* do not increment past 15 */
146   if (pcw16_interrupt_counter!=15)
143   if (state->interrupt_counter!=15)
147144   {
148      pcw16_interrupt_counter++;
145      state->interrupt_counter++;
149146      /* display int */
150      pcw16_system_status |= (1<<0);
147      state->system_status |= (1<<0);
151148   }
152149
153   if (pcw16_interrupt_counter!=0)
150   if (state->interrupt_counter!=0)
154151   {
155152      pcw16_refresh_ints(machine);
156153   }
r9675r9676
166163
167164static WRITE8_HANDLER(pcw16_palette_w)
168165{
169   pcw16_colour_palette[offset & 0x0f] = data & 31;
166   pcw16_state *state = space->machine->driver_data<pcw16_state>();
167   state->colour_palette[offset & 0x0f] = data & 31;
170168}
171169
172static char *pcw16_mem_ptr[4];
173170
174171static const char *pcw16_write_handler_dram[4] =
175172{
r9675r9676
195192/* read flash0 */
196193static int pcw16_flash0_bank_handler_r(running_machine *machine, int bank, int offset)
197194{
195   pcw16_state *state = machine->driver_data<pcw16_state>();
198196   intel_e28f008sa_device *flash = machine->device<intel_e28f008sa_device>("flash0");
199   int flash_offset = (pcw16_banks[bank]<<14) | offset;   
197   int flash_offset = (state->banks[bank]<<14) | offset;   
200198   return flash->read(flash_offset);
201199}
202200
203201/* read flash1 */
204202static int pcw16_flash1_bank_handler_r(running_machine *machine, int bank, int offset)
205203{
204   pcw16_state *state = machine->driver_data<pcw16_state>();
206205   intel_e28f008sa_device *flash = machine->device<intel_e28f008sa_device>("flash1");
207   int flash_offset = ((pcw16_banks[bank]&0x03f)<<14) | offset;
206   int flash_offset = ((state->banks[bank]&0x03f)<<14) | offset;
208207
209208   return flash->read(flash_offset);
210209}
r9675r9676
270269/* write flash0 */
271270static void pcw16_flash0_bank_handler_w(running_machine *machine, int bank, int offset, int data)
272271{
272   pcw16_state *state = machine->driver_data<pcw16_state>();
273273   intel_e28f008sa_device *flash = machine->device<intel_e28f008sa_device>("flash0");
274274
275   int flash_offset = (pcw16_banks[bank]<<14) | offset;
275   int flash_offset = (state->banks[bank]<<14) | offset;
276276
277277   flash->write(flash_offset, data);
278278}
r9675r9676
280280/* read flash1 */
281281static void pcw16_flash1_bank_handler_w(running_machine *machine, int bank, int offset, int data)
282282{
283   pcw16_state *state = machine->driver_data<pcw16_state>();
283284   intel_e28f008sa_device *flash = machine->device<intel_e28f008sa_device>("flash1");
284285
285   int flash_offset = ((pcw16_banks[bank]&0x03f)<<14) | offset;
286   int flash_offset = ((state->banks[bank]&0x03f)<<14) | offset;
286287
287288   flash->write(flash_offset,data);
288289}
r9675r9676
406407
407408static void pcw16_update_bank(running_machine *machine, int bank)
408409{
410   pcw16_state *state = machine->driver_data<pcw16_state>();
409411   unsigned char *mem_ptr = messram_get_ptr(machine->device("messram"));
410412   int bank_id = 0;
411413   int bank_offs = 0;
r9675r9676
413415   char bank2[10];
414416
415417   /* get memory bank */
416   bank_id = pcw16_banks[bank];
418   bank_id = state->banks[bank];
417419
418420
419421   if ((bank_id & 0x080)==0)
r9675r9676
452454   }
453455
454456   mem_ptr = mem_ptr + ((bank_id - bank_offs)<<14);
455   pcw16_mem_ptr[bank] = (char*)mem_ptr;
457   state->mem_ptr[bank] = (char*)mem_ptr;
456458   sprintf(bank1,"bank%d",(bank+1));
457459   sprintf(bank2,"bank%d",(bank+5));
458460   memory_set_bankptr(machine, bank1, mem_ptr);
r9675r9676
499501
500502static  READ8_HANDLER(pcw16_bankhw_r)
501503{
504   pcw16_state *state = space->machine->driver_data<pcw16_state>();
502505//  logerror("bank r: %d \n", offset);
503506
504   return pcw16_banks[offset];
507   return state->banks[offset];
505508}
506509
507510static WRITE8_HANDLER(pcw16_bankhw_w)
508511{
512   pcw16_state *state = space->machine->driver_data<pcw16_state>();
509513   //logerror("bank w: %d block: %02x\n", offset, data);
510514
511   pcw16_banks[offset] = data;
515   state->banks[offset] = data;
512516
513517   pcw16_update_memory(space->machine);
514518}
515519
516520static WRITE8_HANDLER(pcw16_video_control_w)
517521{
522   pcw16_state *state = space->machine->driver_data<pcw16_state>();
518523   //logerror("video control w: %02x\n", data);
519524
520   pcw16_video_control = data;
525   state->video_control = data;
521526}
522527
523528/* PCW16 KEYBOARD */
524529
525530//unsigned char pcw16_keyboard_status;
526static unsigned char pcw16_keyboard_data_shift;
527531
528532
529533
r9675r9676
540544#define PCW16_KEYBOARD_CLOCK (1<<0)
541545
542546/* parity table. Used to set parity bit in keyboard status register */
543static int pcw16_keyboard_parity_table[256];
544547
545static int pcw16_keyboard_bits = 0;
546static int pcw16_keyboard_bits_output = 0;
547548
548static int pcw16_keyboard_state = 0;
549static int pcw16_keyboard_previous_state=0;
550static void pcw16_keyboard_reset(void);
549static void pcw16_keyboard_reset(pcw16_state *state);
551550static void pcw16_keyboard_int(running_machine *, int);
552551
553552static void pcw16_keyboard_init(running_machine *machine)
554553{
554   pcw16_state *state = machine->driver_data<pcw16_state>();
555555   int i;
556556   int b;
557557
r9675r9676
572572         data = data>>1;
573573      }
574574
575      pcw16_keyboard_parity_table[i] = sum & 0x01;
575      state->keyboard_parity_table[i] = sum & 0x01;
576576   }
577577
578578
579579   /* clear int */
580580   pcw16_keyboard_int(machine, 0);
581581   /* reset state */
582   pcw16_keyboard_state = 0;
582   state->keyboard_state = 0;
583583   /* reset ready for transmit */
584   pcw16_keyboard_reset();
584   pcw16_keyboard_reset(state);
585585}
586586
587static void pcw16_keyboard_refresh_outputs(void)
587static void pcw16_keyboard_refresh_outputs(pcw16_state *state)
588588{
589589   /* generate output bits */
590   pcw16_keyboard_bits_output = pcw16_keyboard_bits;
590   state->keyboard_bits_output = state->keyboard_bits;
591591
592592   /* force clock low? */
593   if (pcw16_keyboard_state & PCW16_KEYBOARD_FORCE_KEYBOARD_CLOCK)
593   if (state->keyboard_state & PCW16_KEYBOARD_FORCE_KEYBOARD_CLOCK)
594594   {
595      pcw16_keyboard_bits_output &= ~PCW16_KEYBOARD_CLOCK;
595      state->keyboard_bits_output &= ~PCW16_KEYBOARD_CLOCK;
596596   }
597597}
598598
599static void pcw16_keyboard_set_clock_state(int state)
599static void pcw16_keyboard_set_clock_state(pcw16_state *drvstate, int state)
600600{
601   pcw16_keyboard_bits &= ~PCW16_KEYBOARD_CLOCK;
601   drvstate->keyboard_bits &= ~PCW16_KEYBOARD_CLOCK;
602602
603603   if (state)
604604   {
605      pcw16_keyboard_bits |= PCW16_KEYBOARD_CLOCK;
605      drvstate->keyboard_bits |= PCW16_KEYBOARD_CLOCK;
606606   }
607607
608   pcw16_keyboard_refresh_outputs();
608   pcw16_keyboard_refresh_outputs(drvstate);
609609}
610610
611611static void pcw16_keyboard_int(running_machine *machine, int state)
612612{
613   pcw16_system_status &= ~(1<<1);
613   pcw16_state *drvstate = machine->driver_data<pcw16_state>();
614   drvstate->system_status &= ~(1<<1);
614615
615616   if (state)
616617   {
617      pcw16_system_status |= (1<<1);
618      drvstate->system_status |= (1<<1);
618619   }
619620
620621   pcw16_refresh_ints(machine);
621622}
622623
623static void pcw16_keyboard_reset(void)
624static void pcw16_keyboard_reset(pcw16_state *state)
624625{
625626   /* clock set to high */
626   pcw16_keyboard_set_clock_state(1);
627   pcw16_keyboard_set_clock_state(state, 1);
627628}
628629
629630/* interfaces to a pc-at keyboard */
630631static READ8_HANDLER(pcw16_keyboard_data_shift_r)
631632{
632   //logerror("keyboard data shift r: %02x\n", pcw16_keyboard_data_shift);
633   pcw16_keyboard_state &= ~(PCW16_KEYBOARD_BUSY_STATUS);
633   pcw16_state *state = space->machine->driver_data<pcw16_state>();
634   //logerror("keyboard data shift r: %02x\n", state->keyboard_data_shift);
635   state->keyboard_state &= ~(PCW16_KEYBOARD_BUSY_STATUS);
634636
635637   pcw16_keyboard_int(space->machine, 0);
636638   /* reset for reception */
637   pcw16_keyboard_reset();
639   pcw16_keyboard_reset(state);
638640
639641   /* read byte */
640   return pcw16_keyboard_data_shift;
642   return state->keyboard_data_shift;
641643}
642644
643645/* if force keyboard clock is low it is safe to send */
644static int pcw16_keyboard_can_transmit(void)
646static int pcw16_keyboard_can_transmit(pcw16_state *state)
645647{
646648   /* clock is not forced low */
647649   /* and not busy - i.e. not already sent a char */
648   return ((pcw16_keyboard_bits_output & PCW16_KEYBOARD_CLOCK)!=0);
650   return ((state->keyboard_bits_output & PCW16_KEYBOARD_CLOCK)!=0);
649651}
650652
651653#ifdef UNUSED_FUNCTION
r9675r9676
658660/* signal a code has been received */
659661static void pcw16_keyboard_signal_byte_received(running_machine *machine, int data)
660662{
663   pcw16_state *state = machine->driver_data<pcw16_state>();
661664   /* clear clock */
662   pcw16_keyboard_set_clock_state(0);
665   pcw16_keyboard_set_clock_state(state, 0);
663666
664667   /* set code in shift register */
665   pcw16_keyboard_data_shift = data;
668   state->keyboard_data_shift = data;
666669   /* busy */
667   pcw16_keyboard_state |= PCW16_KEYBOARD_BUSY_STATUS;
670   state->keyboard_state |= PCW16_KEYBOARD_BUSY_STATUS;
668671
669672   /* initialise start, stop and parity bits */
670   pcw16_keyboard_state &= ~PCW16_KEYBOARD_START_BIT_MASK;
671   pcw16_keyboard_state |=PCW16_KEYBOARD_STOP_BIT_MASK;
673   state->keyboard_state &= ~PCW16_KEYBOARD_START_BIT_MASK;
674   state->keyboard_state |=PCW16_KEYBOARD_STOP_BIT_MASK;
672675
673676   /* "Keyboard data has odd parity, so the parity bit in the
674677    status register should only be set when the shift register
675678    data itself has even parity. */
676679
677   pcw16_keyboard_state &= ~PCW16_KEYBOARD_PARITY_MASK;
680   state->keyboard_state &= ~PCW16_KEYBOARD_PARITY_MASK;
678681
679682   /* if data has even parity, set parity bit */
680   if ((pcw16_keyboard_parity_table[data])==0)
681      pcw16_keyboard_state |= PCW16_KEYBOARD_PARITY_MASK;
683   if ((state->keyboard_parity_table[data])==0)
684      state->keyboard_state |= PCW16_KEYBOARD_PARITY_MASK;
682685
683686   pcw16_keyboard_int(machine, 1);
684687}
r9675r9676
686689
687690static WRITE8_HANDLER(pcw16_keyboard_data_shift_w)
688691{
692   pcw16_state *state = space->machine->driver_data<pcw16_state>();
689693   //logerror("Keyboard Data Shift: %02x\n", data);
690694   /* writing to shift register clears parity */
691695   /* writing to shift register clears start bit */
692   pcw16_keyboard_state &= ~(
696   state->keyboard_state &= ~(
693697      PCW16_KEYBOARD_PARITY_MASK |
694698      PCW16_KEYBOARD_START_BIT_MASK);
695699
696700   /* writing to shift register sets stop bit */
697   pcw16_keyboard_state |= PCW16_KEYBOARD_STOP_BIT_MASK;
701   state->keyboard_state |= PCW16_KEYBOARD_STOP_BIT_MASK;
698702
699   pcw16_keyboard_data_shift = data;
703   state->keyboard_data_shift = data;
700704
701705}
702706
703707static  READ8_HANDLER(pcw16_keyboard_status_r)
704708{
709   pcw16_state *state = space->machine->driver_data<pcw16_state>();
705710   /* bit 2,3 are bits 8 and 9 of vdu pointer */
706   return (pcw16_keyboard_state &
711   return (state->keyboard_state &
707712      (PCW16_KEYBOARD_PARITY_MASK |
708713       PCW16_KEYBOARD_STOP_BIT_MASK |
709714       PCW16_KEYBOARD_START_BIT_MASK |
r9675r9676
714719
715720static WRITE8_HANDLER(pcw16_keyboard_control_w)
716721{
722   pcw16_state *state = space->machine->driver_data<pcw16_state>();
717723   //logerror("Keyboard control w: %02x\n",data);
718724
719   pcw16_keyboard_previous_state = pcw16_keyboard_state;
725   state->keyboard_previous_state = state->keyboard_state;
720726
721727   /* if set, set parity */
722728   if (data & 0x080)
723729   {
724      pcw16_keyboard_state |= PCW16_KEYBOARD_PARITY_MASK;
730      state->keyboard_state |= PCW16_KEYBOARD_PARITY_MASK;
725731   }
726732
727733   /* clear read/write bits */
728   pcw16_keyboard_state &=
734   state->keyboard_state &=
729735      ~(PCW16_KEYBOARD_FORCE_KEYBOARD_CLOCK |
730736         PCW16_KEYBOARD_TRANSMIT_MODE);
731737   /* set read/write bits from data */
732   pcw16_keyboard_state |= (data & 0x03);
738   state->keyboard_state |= (data & 0x03);
733739
734740   if (data & PCW16_KEYBOARD_RESET_INTERFACE)
735741   {
736      pcw16_keyboard_reset();
742      pcw16_keyboard_reset(state);
737743   }
738744
739745   if (data & PCW16_KEYBOARD_TRANSMIT_MODE)
740746   {
741747      /* force clock changed */
742      if (((pcw16_keyboard_state^pcw16_keyboard_previous_state) & PCW16_KEYBOARD_FORCE_KEYBOARD_CLOCK)!=0)
748      if (((state->keyboard_state^state->keyboard_previous_state) & PCW16_KEYBOARD_FORCE_KEYBOARD_CLOCK)!=0)
743749      {
744750         /* just cleared? */
745         if ((pcw16_keyboard_state & PCW16_KEYBOARD_FORCE_KEYBOARD_CLOCK)==0)
751         if ((state->keyboard_state & PCW16_KEYBOARD_FORCE_KEYBOARD_CLOCK)==0)
746752         {
747753
748754            /* write */
749755            /* busy */
750            pcw16_keyboard_state |= PCW16_KEYBOARD_BUSY_STATUS;
756            state->keyboard_state |= PCW16_KEYBOARD_BUSY_STATUS;
751757            /* keyboard takes data */
752            at_keyboard_write(space->machine,pcw16_keyboard_data_shift);
758            at_keyboard_write(space->machine,state->keyboard_data_shift);
753759            /* set clock low - no furthur transmissions */
754            pcw16_keyboard_set_clock_state(0);
760            pcw16_keyboard_set_clock_state(state, 0);
755761            /* set int */
756762            pcw16_keyboard_int(space->machine, 1);
757763         }
r9675r9676
760766
761767   }
762768
763   if (((pcw16_keyboard_state^pcw16_keyboard_previous_state) & PCW16_KEYBOARD_TRANSMIT_MODE)!=0)
769   if (((state->keyboard_state^state->keyboard_previous_state) & PCW16_KEYBOARD_TRANSMIT_MODE)!=0)
764770   {
765      if ((pcw16_keyboard_state & PCW16_KEYBOARD_TRANSMIT_MODE)==0)
771      if ((state->keyboard_state & PCW16_KEYBOARD_TRANSMIT_MODE)==0)
766772      {
767         if ((pcw16_system_status & (1<<1))!=0)
773         if ((state->system_status & (1<<1))!=0)
768774         {
769775            pcw16_keyboard_int(space->machine, 0);
770776         }
771777      }
772778   }
773779
774   pcw16_keyboard_refresh_outputs();
780   pcw16_keyboard_refresh_outputs(state);
775781}
776782
777783
778784static TIMER_CALLBACK(pcw16_keyboard_timer_callback)
779785{
786   pcw16_state *state = machine->driver_data<pcw16_state>();
780787   at_keyboard_polling();
781   if (pcw16_keyboard_can_transmit())
788   if (pcw16_keyboard_can_transmit(state))
782789   {
783790      int data;
784791
r9675r9676
796803   }
797804}
798805
799static unsigned char rtc_seconds;
800static unsigned char rtc_minutes;
801static unsigned char rtc_hours;
802static unsigned char rtc_days_max;
803static unsigned char rtc_days;
804static unsigned char rtc_months;
805static unsigned char rtc_years;
806static unsigned char rtc_control;
807static unsigned char rtc_256ths_seconds;
808806
809807static const int rtc_days_in_each_month[]=
810808{
r9675r9676
827825   29, 28, 28, 28
828826};
829827
830static void rtc_setup_max_days(void)
828static void rtc_setup_max_days(pcw16_state *state)
831829{
832830   /* february? */
833   if (rtc_months == 2)
831   if (state->rtc_months == 2)
834832   {
835833      /* low two bits of year select number of days in february */
836      rtc_days_max = rtc_days_in_february[rtc_years & 0x03];
834      state->rtc_days_max = rtc_days_in_february[state->rtc_years & 0x03];
837835   }
838836   else
839837   {
840      rtc_days_max = (unsigned char)rtc_days_in_each_month[rtc_months];
838      state->rtc_days_max = (unsigned char)rtc_days_in_each_month[state->rtc_months];
841839   }
842840}
843841
844842static TIMER_CALLBACK(rtc_timer_callback)
845843{
844   pcw16_state *state = machine->driver_data<pcw16_state>();
846845   int fraction_of_second;
847846
848847   /* halt counter? */
849   if ((rtc_control & 0x01)!=0)
848   if ((state->rtc_control & 0x01)!=0)
850849   {
851850      /* no */
852851
853852      /* increment 256th's of a second register */
854      fraction_of_second = rtc_256ths_seconds+1;
853      fraction_of_second = state->rtc_256ths_seconds+1;
855854      /* add bit 8 = overflow */
856      rtc_seconds+=(fraction_of_second>>8);
855      state->rtc_seconds+=(fraction_of_second>>8);
857856      /* ensure counter is in range 0-255 */
858      rtc_256ths_seconds = fraction_of_second & 0x0ff;
857      state->rtc_256ths_seconds = fraction_of_second & 0x0ff;
859858   }
860859
861   if (rtc_seconds>59)
860   if (state->rtc_seconds>59)
862861   {
863      rtc_seconds = 0;
862      state->rtc_seconds = 0;
864863
865      rtc_minutes++;
864      state->rtc_minutes++;
866865
867      if (rtc_minutes>59)
866      if (state->rtc_minutes>59)
868867      {
869         rtc_minutes = 0;
868         state->rtc_minutes = 0;
870869
871         rtc_hours++;
870         state->rtc_hours++;
872871
873         if (rtc_hours>23)
872         if (state->rtc_hours>23)
874873         {
875            rtc_hours = 0;
874            state->rtc_hours = 0;
876875
877            rtc_days++;
876            state->rtc_days++;
878877
879            if (rtc_days>rtc_days_max)
878            if (state->rtc_days > state->rtc_days_max)
880879            {
881               rtc_days = 1;
880               state->rtc_days = 1;
882881
883               rtc_months++;
882               state->rtc_months++;
884883
885               if (rtc_months>12)
884               if (state->rtc_months>12)
886885               {
887                  rtc_months = 1;
886                  state->rtc_months = 1;
888887
889888                  /* 7 bit year counter */
890                  rtc_years = (rtc_years + 1) & 0x07f;
889                  state->rtc_years = (state->rtc_years + 1) & 0x07f;
891890
892891               }
893892
894               rtc_setup_max_days();
893               rtc_setup_max_days(state);
895894            }
896895
897896         }
r9675r9676
903902
904903static  READ8_HANDLER(rtc_year_invalid_r)
905904{
906   /* year in lower 7 bits. RTC Invalid status is rtc_control bit 0
905   pcw16_state *state = space->machine->driver_data<pcw16_state>();
906   /* year in lower 7 bits. RTC Invalid status is state->rtc_control bit 0
907907    inverted */
908   return (rtc_years & 0x07f) | (((rtc_control & 0x01)<<7)^0x080);
908   return (state->rtc_years & 0x07f) | (((state->rtc_control & 0x01)<<7)^0x080);
909909}
910910
911911static  READ8_HANDLER(rtc_month_r)
912912{
913   return rtc_months;
913   pcw16_state *state = space->machine->driver_data<pcw16_state>();
914   return state->rtc_months;
914915}
915916
916917static  READ8_HANDLER(rtc_days_r)
917918{
918   return rtc_days;
919   pcw16_state *state = space->machine->driver_data<pcw16_state>();
920   return state->rtc_days;
919921}
920922
921923static  READ8_HANDLER(rtc_hours_r)
922924{
923   return rtc_hours;
925   pcw16_state *state = space->machine->driver_data<pcw16_state>();
926   return state->rtc_hours;
924927}
925928
926929static  READ8_HANDLER(rtc_minutes_r)
927930{
928   return rtc_minutes;
931   pcw16_state *state = space->machine->driver_data<pcw16_state>();
932   return state->rtc_minutes;
929933}
930934
931935static  READ8_HANDLER(rtc_seconds_r)
932936{
933   return rtc_seconds;
937   pcw16_state *state = space->machine->driver_data<pcw16_state>();
938   return state->rtc_seconds;
934939}
935940
936941static  READ8_HANDLER(rtc_256ths_seconds_r)
937942{
938   return rtc_256ths_seconds;
943   pcw16_state *state = space->machine->driver_data<pcw16_state>();
944   return state->rtc_256ths_seconds;
939945}
940946
941947static WRITE8_HANDLER(rtc_control_w)
942948{
949   pcw16_state *state = space->machine->driver_data<pcw16_state>();
943950   /* write control */
944   rtc_control = data;
951   state->rtc_control = data;
945952}
946953
947954static WRITE8_HANDLER(rtc_seconds_w)
948955{
956   pcw16_state *state = space->machine->driver_data<pcw16_state>();
949957   /* TODO: Writing register could cause next to increment! */
950   rtc_seconds = data;
958   state->rtc_seconds = data;
951959}
952960
953961static WRITE8_HANDLER(rtc_minutes_w)
954962{
963   pcw16_state *state = space->machine->driver_data<pcw16_state>();
955964   /* TODO: Writing register could cause next to increment! */
956   rtc_minutes = data;
965   state->rtc_minutes = data;
957966}
958967
959968static WRITE8_HANDLER(rtc_hours_w)
960969{
970   pcw16_state *state = space->machine->driver_data<pcw16_state>();
961971   /* TODO: Writing register could cause next to increment! */
962   rtc_hours = data;
972   state->rtc_hours = data;
963973}
964974
965975static WRITE8_HANDLER(rtc_days_w)
966976{
977   pcw16_state *state = space->machine->driver_data<pcw16_state>();
967978   /* TODO: Writing register could cause next to increment! */
968   rtc_days = data;
979   state->rtc_days = data;
969980}
970981
971982static WRITE8_HANDLER(rtc_month_w)
972983{
984   pcw16_state *state = space->machine->driver_data<pcw16_state>();
973985   /* TODO: Writing register could cause next to increment! */
974   rtc_months = data;
986   state->rtc_months = data;
975987
976   rtc_setup_max_days();
988   rtc_setup_max_days(state);
977989}
978990
979991
980992static WRITE8_HANDLER(rtc_year_w)
981993{
994   pcw16_state *state = space->machine->driver_data<pcw16_state>();
982995   /* TODO: Writing register could cause next to increment! */
983   rtc_hours = data;
996   state->rtc_hours = data;
984997
985   rtc_setup_max_days();
998   rtc_setup_max_days(state);
986999}
9871000
988static int previous_fdc_int_state;
9891001
9901002static void pcw16_trigger_fdc_int(running_machine *machine)
9911003{
1004   pcw16_state *drvstate = machine->driver_data<pcw16_state>();
9921005   int state;
9931006
994   state = pcw16_system_status & (1<<6);
1007   state = drvstate->system_status & (1<<6);
9951008
996   switch (pcw16_fdc_int_code)
1009   switch (drvstate->fdc_int_code)
9971010   {
9981011      /* nmi */
9991012      case 0:
r9675r9676
10041017            is cleared this will not cause another nmi */
10051018         /* I'll emulate it like this to be sure */
10061019
1007         if (state!=previous_fdc_int_state)
1020         if (state!=drvstate->previous_fdc_int_state)
10081021         {
10091022            if (state)
10101023            {
r9675r9676
10281041         break;
10291042   }
10301043
1031   previous_fdc_int_state = state;
1044   drvstate->previous_fdc_int_state = state;
10321045}
10331046
10341047static READ8_HANDLER(pcw16_system_status_r)
10351048{
1049   pcw16_state *state = space->machine->driver_data<pcw16_state>();
10361050//  logerror("system status r: \n");
10371051
1038   return pcw16_system_status | (input_port_read(space->machine, "EXTRA") & 0x04);
1052   return state->system_status | (input_port_read(space->machine, "EXTRA") & 0x04);
10391053}
10401054
10411055static READ8_HANDLER(pcw16_timer_interrupt_counter_r)
10421056{
1057   pcw16_state *state = space->machine->driver_data<pcw16_state>();
10431058   int data;
10441059
1045   data = pcw16_interrupt_counter;
1060   data = state->interrupt_counter;
10461061
1047   pcw16_interrupt_counter = 0;
1062   state->interrupt_counter = 0;
10481063   /* clear display int */
1049   pcw16_system_status &= ~(1<<0);
1064   state->system_status &= ~(1<<0);
10501065
10511066   pcw16_refresh_ints(space->machine);
10521067
r9675r9676
10561071
10571072static WRITE8_HANDLER(pcw16_system_control_w)
10581073{
1074   pcw16_state *state = space->machine->driver_data<pcw16_state>();
10591075   running_device *speaker = space->machine->device("beep");
10601076   //logerror("0x0f8: function: %d\n",data);
10611077
r9675r9676
10771093      /* connect IRQ6 input to /NMI */
10781094      case 0x02:
10791095      {
1080         pcw16_fdc_int_code = 0;
1096         state->fdc_int_code = 0;
10811097      }
10821098      break;
10831099
10841100      /* connect IRQ6 input to /INT */
10851101      case 0x03:
10861102      {
1087         pcw16_fdc_int_code = 1;
1103         state->fdc_int_code = 1;
10881104      }
10891105      break;
10901106
10911107      /* dis-connect IRQ6 input from /NMI and /INT */
10921108      case 0x04:
10931109      {
1094         pcw16_fdc_int_code = 2;
1110         state->fdc_int_code = 2;
10951111      }
10961112      break;
10971113
r9675r9676
11431159         /* bit 5 - green/red led (1==green)*/
11441160         /* bit 4 - monitor on/off (1==on) */
11451161
1146         pcw16_4_bit_port = data>>4;
1162         state->_4_bit_port = data>>4;
11471163
11481164
11491165      }
r9675r9676
11901206
11911207static void pcw16_fdc_interrupt(running_machine *machine, int state)
11921208{
1209   pcw16_state *drvstate = machine->driver_data<pcw16_state>();
11931210   /* IRQ6 */
11941211   /* bit 6 of PCW16 system status indicates floppy ints */
1195   pcw16_system_status &= ~(1<<6);
1212   drvstate->system_status &= ~(1<<6);
11961213
11971214   if (state)
11981215   {
1199      pcw16_system_status |= (1<<6);
1216      drvstate->system_status |= (1<<6);
12001217   }
12011218
12021219   pcw16_trigger_fdc_int(machine);
r9675r9676
12161233};
12171234
12181235
1219static INS8250_INTERRUPT( pcw16_com_interrupt_1 ) {
1220   pcw16_system_status &= ~(1 << 4);
1236static INS8250_INTERRUPT( pcw16_com_interrupt_1 )
1237{
1238   pcw16_state *drvstate = device->machine->driver_data<pcw16_state>();
1239   drvstate->system_status &= ~(1 << 4);
12211240
12221241   if ( state ) {
1223      pcw16_system_status |= (1 << 4);
1242      drvstate->system_status |= (1 << 4);
12241243   }
12251244
12261245   pcw16_refresh_ints(device->machine);
r9675r9676
12291248
12301249static INS8250_INTERRUPT( pcw16_com_interrupt_2 )
12311250{
1232   pcw16_system_status &= ~(1 << 3);
1251   pcw16_state *drvstate = device->machine->driver_data<pcw16_state>();
1252   drvstate->system_status &= ~(1 << 3);
12331253
12341254   if ( state ) {
1235      pcw16_system_status |= (1 << 3);
1255      drvstate->system_status |= (1 << 3);
12361256   }
12371257
12381258   pcw16_refresh_ints(device->machine);
r9675r9676
13091329
13101330static void pcw16_reset(running_machine *machine)
13111331{
1332   pcw16_state *state = machine->driver_data<pcw16_state>();
13121333   /* initialise defaults */
1313   pcw16_fdc_int_code = 2;
1334   state->fdc_int_code = 2;
13141335   /* clear terminal count */
13151336   pc_fdc_set_tc_state(machine, 0);
13161337   /* select first rom page */
1317   pcw16_banks[0] = 0;
1338   state->banks[0] = 0;
13181339   pcw16_update_memory(machine);
13191340
13201341   /* temp rtc setup */
1321   rtc_seconds = 0;
1322   rtc_minutes = 0;
1323   rtc_hours = 0;
1324   rtc_days_max = 0;
1325   rtc_days = 1;
1326   rtc_months = 1;
1327   rtc_years = 0;
1328   rtc_control = 1;
1329   rtc_256ths_seconds = 0;
1342   state->rtc_seconds = 0;
1343   state->rtc_minutes = 0;
1344   state->rtc_hours = 0;
1345   state->rtc_days_max = 0;
1346   state->rtc_days = 1;
1347   state->rtc_months = 1;
1348   state->rtc_years = 0;
1349   state->rtc_control = 1;
1350   state->rtc_256ths_seconds = 0;
13301351
13311352   pcw16_keyboard_init(machine);
13321353}
r9675r9676
13341355
13351356static MACHINE_START( pcw16 )
13361357{
1358   pcw16_state *state = machine->driver_data<pcw16_state>();
13371359   running_device *speaker = machine->device("beep");
1338   pcw16_system_status = 0;
1339   pcw16_interrupt_counter = 0;
1360   state->system_status = 0;
1361   state->interrupt_counter = 0;
13401362
13411363   /* video ints */
13421364   timer_pulse(machine, ATTOTIME_IN_USEC(5830), NULL, 0,pcw16_timer_callback);
r9675r9676
13941416   NULL
13951417};
13961418
1397static MACHINE_CONFIG_START( pcw16, driver_device )
1419static MACHINE_CONFIG_START( pcw16, pcw16_state )
13981420   /* basic machine hardware */
13991421   MDRV_CPU_ADD("maincpu", Z80, 16000000)
14001422   MDRV_CPU_PROGRAM_MAP(pcw16_map)
src/mess/drivers/pasopia.c
r9675r9676
1919#include "sound/sn76496.h"
2020#include "video/mc6845.h"
2121
22static UINT8 vram_sel,mio_sel;
23static UINT8 *p7_pal;
24static UINT8 bank_reg;
25static UINT16 cursor_addr;
26static UINT8 cursor_blink,cursor_raster;
27static UINT8 plane_reg,attr_data,attr_wrap,attr_latch,pal_sel,x_width,gfx_mode;
2822
29static UINT8 nmi_mask,nmi_enable_reg,nmi_trap,nmi_reset;
23class pasopia_state : public driver_device
24{
25public:
26   pasopia_state(running_machine &machine, const driver_device_config_base &config)
27      : driver_device(machine, config) { }
3028
29   UINT8 vram_sel;
30   UINT8 mio_sel;
31   UINT8 *p7_pal;
32   UINT8 bank_reg;
33   UINT16 cursor_addr;
34   UINT8 cursor_blink;
35   UINT8 cursor_raster;
36   UINT8 plane_reg;
37   UINT8 attr_data;
38   UINT8 attr_wrap;
39   UINT8 attr_latch;
40   UINT8 pal_sel;
41   UINT8 x_width;
42   UINT8 gfx_mode;
43   UINT8 nmi_mask;
44   UINT8 nmi_enable_reg;
45   UINT8 nmi_trap;
46   UINT8 nmi_reset;
47   UINT16 pac2_index[2];
48   UINT32 kanji_index;
49   UINT8 pac2_bank_select;
50   int addr_latch;
51};
52
53
54
55
3156#define VDP_CLOCK XTAL_3_579545MHz/4
3257
3358static VIDEO_START( paso7 )
3459{
35   p7_pal = auto_alloc_array(machine, UINT8, 0x10);
60   pasopia_state *state = machine->driver_data<pasopia_state>();
61   state->p7_pal = auto_alloc_array(machine, UINT8, 0x10);
3662}
3763
3864#define keyb_press(_val_,_charset_) \
r9675r9676
153179
154180static void draw_tv_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int width)
155181{
182   pasopia_state *state = machine->driver_data<pasopia_state>();
156183   UINT8 *vram = memory_region(machine, "vram");
157184   int x,y/*,xi,yi*/;
158185   int count;
r9675r9676
170197         drawgfx_transpen(bitmap,cliprect,machine->gfx[0],tile,color & 7,0,0,x*8,y*8,0);
171198
172199         // draw cursor
173         if(cursor_addr*8 == count)
200         if(state->cursor_addr*8 == count)
174201         {
175202            int xc,yc,cursor_on;
176203
177204            cursor_on = 0;
178            switch(cursor_raster & 0x60)
205            switch(state->cursor_raster & 0x60)
179206            {
180207               case 0x00: cursor_on = 1; break; //always on
181208               case 0x20: cursor_on = 0; break; //always off
r9675r9676
185212
186213            if(cursor_on)
187214            {
188               for(yc=0;yc<(8-(cursor_raster & 7));yc++)
215               for(yc=0;yc<(8-(state->cursor_raster & 7));yc++)
189216               {
190217                  for(xc=0;xc<8;xc++)
191218                  {
r9675r9676
201228
202229static void draw_mixed_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int width)
203230{
231   pasopia_state *state = machine->driver_data<pasopia_state>();
204232   UINT8 *vram = memory_region(machine, "vram");
205233   UINT8 *gfx_data = memory_region(machine,"font");
206234   int x,y,xi,yi;
r9675r9676
249277         }
250278
251279         // draw cursor
252         if(cursor_addr*8 == count)
280         if(state->cursor_addr*8 == count)
253281         {
254282            int xc,yc,cursor_on;
255283
256284            cursor_on = 0;
257            switch(cursor_raster & 0x60)
285            switch(state->cursor_raster & 0x60)
258286            {
259287               case 0x00: cursor_on = 1; break; //always on
260288               case 0x20: cursor_on = 0; break; //always off
r9675r9676
264292
265293            if(cursor_on)
266294            {
267               for(yc=0;yc<(8-(cursor_raster & 7));yc++)
295               for(yc=0;yc<(8-(state->cursor_raster & 7));yc++)
268296               {
269297                  for(xc=0;xc<8;xc++)
270298                  {
r9675r9676
281309
282310static VIDEO_UPDATE( paso7 )
283311{
312   pasopia_state *state = screen->machine->driver_data<pasopia_state>();
284313   int width;
285314
286315   bitmap_fill(bitmap, cliprect, screen->machine->pens[0]);
287316
288317   fake_keyboard_data(screen->machine);
289318
290   width = x_width ? 80 : 40;
319   width = state->x_width ? 80 : 40;
291320
292   if(gfx_mode)
321   if(state->gfx_mode)
293322      draw_mixed_screen(screen->machine,bitmap,cliprect,width);
294323   else
295324   {
r9675r9676
302331
303332static READ8_HANDLER( vram_r )
304333{
334   pasopia_state *state = space->machine->driver_data<pasopia_state>();
305335   UINT8 *vram = memory_region(space->machine, "vram");
306336   UINT8 res;
307337
308   if(vram_sel == 0)
338   if(state->vram_sel == 0)
309339   {
310340      UINT8 *work_ram = memory_region(space->machine, "maincpu");
311341
312342      return work_ram[offset+0x8000];
313343   }
314344
315   if(pal_sel && (plane_reg & 0x70) == 0x00)
316      return p7_pal[offset & 0xf];
345   if(state->pal_sel && (state->plane_reg & 0x70) == 0x00)
346      return state->p7_pal[offset & 0xf];
317347
318348   res = 0xff;
319349
320   if((plane_reg & 0x11) == 0x11)
350   if((state->plane_reg & 0x11) == 0x11)
321351      res &= vram[offset | 0x0000];
322   if((plane_reg & 0x22) == 0x22)
352   if((state->plane_reg & 0x22) == 0x22)
323353      res &= vram[offset | 0x4000];
324   if((plane_reg & 0x44) == 0x44)
354   if((state->plane_reg & 0x44) == 0x44)
325355   {
326356      res &= vram[offset | 0x8000];
327      attr_latch = vram[offset | 0xc000] & 0x87;
357      state->attr_latch = vram[offset | 0xc000] & 0x87;
328358   }
329359
330360   return res;
r9675r9676
332362
333363static WRITE8_HANDLER( vram_w )
334364{
365   pasopia_state *state = space->machine->driver_data<pasopia_state>();
335366   UINT8 *vram = memory_region(space->machine, "vram");
336367
337   if(vram_sel)
368   if(state->vram_sel)
338369   {
339      if(pal_sel && (plane_reg & 0x70) == 0x00)
370      if(state->pal_sel && (state->plane_reg & 0x70) == 0x00)
340371      {
341         p7_pal[offset & 0xf] = data & 0xf;
372         state->p7_pal[offset & 0xf] = data & 0xf;
342373         return;
343374      }
344375
345      if(plane_reg & 0x10)
346         vram[(offset & 0x3fff) | 0x0000] = (plane_reg & 1) ? data : 0xff;
347      if(plane_reg & 0x20)
348         vram[(offset & 0x3fff) | 0x4000] = (plane_reg & 2) ? data : 0xff;
349      if(plane_reg & 0x40)
376      if(state->plane_reg & 0x10)
377         vram[(offset & 0x3fff) | 0x0000] = (state->plane_reg & 1) ? data : 0xff;
378      if(state->plane_reg & 0x20)
379         vram[(offset & 0x3fff) | 0x4000] = (state->plane_reg & 2) ? data : 0xff;
380      if(state->plane_reg & 0x40)
350381      {
351         vram[(offset & 0x3fff) | 0x8000] = (plane_reg & 4) ? data : 0xff;
352         attr_latch = attr_wrap ? attr_latch : attr_data;
353         vram[(offset & 0x3fff) | 0xc000] = attr_latch;
382         vram[(offset & 0x3fff) | 0x8000] = (state->plane_reg & 4) ? data : 0xff;
383         state->attr_latch = state->attr_wrap ? state->attr_latch : state->attr_data;
384         vram[(offset & 0x3fff) | 0xc000] = state->attr_latch;
354385      }
355386   }
356387   else
r9675r9676
363394
364395static WRITE8_HANDLER( pasopia7_memory_ctrl_w )
365396{
397   pasopia_state *state = space->machine->driver_data<pasopia_state>();
366398   UINT8 *work_ram = memory_region(space->machine, "maincpu");
367399   UINT8 *basic = memory_region(space->machine, "basic");
368400
r9675r9676
383415         break;
384416   }
385417
386   bank_reg = data & 3;
387   vram_sel = data & 4;
388   mio_sel = data & 8;
418   state->bank_reg = data & 3;
419   state->vram_sel = data & 4;
420   state->mio_sel = data & 8;
389421
390422   // bank4 is always RAM
391423
392//   printf("%02x\n",vram_sel);
424//   printf("%02x\n",state->vram_sel);
393425}
394426
395427#if 0
r9675r9676
399431}
400432#endif
401433
402static UINT16 pac2_index[2];
403static UINT32 kanji_index;
404static UINT8 pac2_bank_select;
405434
406435static WRITE8_HANDLER( pac2_w )
407436{
437   pasopia_state *state = space->machine->driver_data<pasopia_state>();
408438   /*
409439    select register:
410440    4 = ram1;
r9675r9676
414444    anything else is nop
415445    */
416446
417   if(pac2_bank_select == 3 || pac2_bank_select == 4)
447   if(state->pac2_bank_select == 3 || state->pac2_bank_select == 4)
418448   {
419449      switch(offset)
420450      {
421         case 0:   pac2_index[(pac2_bank_select-3) & 1] = (pac2_index[(pac2_bank_select-3) & 1] & 0x7f00) | (data & 0xff); break;
422         case 1: pac2_index[(pac2_bank_select-3) & 1] = (pac2_index[(pac2_bank_select-3) & 1] & 0xff) | ((data & 0x7f) << 8); break;
451         case 0:   state->pac2_index[(state->pac2_bank_select-3) & 1] = (state->pac2_index[(state->pac2_bank_select-3) & 1] & 0x7f00) | (data & 0xff); break;
452         case 1: state->pac2_index[(state->pac2_bank_select-3) & 1] = (state->pac2_index[(state->pac2_bank_select-3) & 1] & 0xff) | ((data & 0x7f) << 8); break;
423453         case 2: // PAC2 RAM write
424454         {
425455            UINT8 *pac2_ram;
426456
427            pac2_ram = memory_region(space->machine, ((pac2_bank_select-3) & 1) ? "rampac2" : "rampac1");
457            pac2_ram = memory_region(space->machine, ((state->pac2_bank_select-3) & 1) ? "rampac2" : "rampac1");
428458
429            pac2_ram[pac2_index[(pac2_bank_select-3) & 1]] = data;
459            pac2_ram[state->pac2_index[(state->pac2_bank_select-3) & 1]] = data;
430460         }
431461      }
432462   }
433   else if(pac2_bank_select == 2) // kanji ROM
463   else if(state->pac2_bank_select == 2) // kanji ROM
434464   {
435465      switch(offset)
436466      {
437         case 0: kanji_index = (kanji_index & 0x1ff00) | ((data & 0xff) << 0); break;
438         case 1: kanji_index = (kanji_index & 0x100ff) | ((data & 0xff) << 8); break;
439         case 2: kanji_index = (kanji_index & 0x0ffff) | ((data & 0x01) << 16); break;
467         case 0: state->kanji_index = (state->kanji_index & 0x1ff00) | ((data & 0xff) << 0); break;
468         case 1: state->kanji_index = (state->kanji_index & 0x100ff) | ((data & 0xff) << 8); break;
469         case 2: state->kanji_index = (state->kanji_index & 0x0ffff) | ((data & 0x01) << 16); break;
440470      }
441471   }
442472
r9675r9676
447477         // ...
448478      }
449479      else
450         pac2_bank_select = data & 7;
480         state->pac2_bank_select = data & 7;
451481   }
452482}
453483
454484static READ8_HANDLER( pac2_r )
455485{
486   pasopia_state *state = space->machine->driver_data<pasopia_state>();
456487   if(offset == 2)
457488   {
458      if(pac2_bank_select == 3 || pac2_bank_select == 4)
489      if(state->pac2_bank_select == 3 || state->pac2_bank_select == 4)
459490      {
460491         UINT8 *pac2_ram;
461492
462         pac2_ram = memory_region(space->machine, ((pac2_bank_select-3) & 1) ? "rampac2" : "rampac1");
493         pac2_ram = memory_region(space->machine, ((state->pac2_bank_select-3) & 1) ? "rampac2" : "rampac1");
463494
464         return pac2_ram[pac2_index[(pac2_bank_select-3) & 1]];
495         return pac2_ram[state->pac2_index[(state->pac2_bank_select-3) & 1]];
465496      }
466      else if(pac2_bank_select == 2)
497      else if(state->pac2_bank_select == 2)
467498      {
468499         UINT8 *kanji_rom = memory_region(space->machine, "kanji");
469500
470         return kanji_rom[kanji_index];
501         return kanji_rom[state->kanji_index];
471502      }
472503      else
473504      {
474         printf("%02x\n",pac2_bank_select);
505         printf("%02x\n",state->pac2_bank_select);
475506      }
476507   }
477508
r9675r9676
488519
489520static WRITE8_HANDLER( pasopia7_6845_w )
490521{
491   static int addr_latch;
492
522   pasopia_state *state = space->machine->driver_data<pasopia_state>();
493523   if(offset == 0)
494524   {
495      addr_latch = data;
525      state->addr_latch = data;
496526      mc6845_address_w(space->machine->device("crtc"), 0,data);
497527   }
498528   else
499529   {
500530      /* FIXME: this should be inside the MC6845 core! */
501      if(addr_latch == 0x0a)
502         cursor_raster = data;
503      if(addr_latch == 0x0e)
504         cursor_addr = ((data<<8) & 0x3f00) | (cursor_addr & 0xff);
505      else if(addr_latch == 0x0f)
506         cursor_addr = (cursor_addr & 0x3f00) | (data & 0xff);
531      if(state->addr_latch == 0x0a)
532         state->cursor_raster = data;
533      if(state->addr_latch == 0x0e)
534         state->cursor_addr = ((data<<8) & 0x3f00) | (state->cursor_addr & 0xff);
535      else if(state->addr_latch == 0x0f)
536         state->cursor_addr = (state->cursor_addr & 0x3f00) | (data & 0xff);
507537
508538      mc6845_register_w(space->machine->device("crtc"), 0,data);
509539
510540      /* double pump the pixel clock if we are in 640 x 200 mode */
511      mc6845_set_clock(space->machine->device("crtc"), (x_width) ? VDP_CLOCK*2 : VDP_CLOCK);
541      mc6845_set_clock(space->machine->device("crtc"), (state->x_width) ? VDP_CLOCK*2 : VDP_CLOCK);
512542   }
513543}
514544
515545static void pasopia_nmi_trap(running_machine *machine)
516546{
517   if(nmi_enable_reg)
547   pasopia_state *state = machine->driver_data<pasopia_state>();
548   if(state->nmi_enable_reg)
518549   {
519      nmi_trap |= 2;
550      state->nmi_trap |= 2;
520551
521      if(nmi_mask == 0)
552      if(state->nmi_mask == 0)
522553         cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, ASSERT_LINE);
523554   }
524555}
525556
526557static READ8_HANDLER( pasopia7_io_r )
527558{
559   pasopia_state *state = space->machine->driver_data<pasopia_state>();
528560   UINT16 io_port;
529561
530   if(mio_sel)
562   if(state->mio_sel)
531563   {
532564      address_space *ram_space = cputag_get_address_space(space->machine, "maincpu", ADDRESS_SPACE_PROGRAM);
533565
534      mio_sel = 0;
566      state->mio_sel = 0;
535567      //printf("%08x\n",offset);
536568      //return 0x0d; // hack: this is used for reading the keyboard data, we can fake it a little ... (modify fda4)
537569      return ram_space->read_byte(offset);
r9675r9676
568600
569601static WRITE8_HANDLER( pasopia7_io_w )
570602{
603   pasopia_state *state = space->machine->driver_data<pasopia_state>();
571604   UINT16 io_port;
572605
573   if(mio_sel)
606   if(state->mio_sel)
574607   {
575608      address_space *ram_space = cputag_get_address_space(space->machine, "maincpu", ADDRESS_SPACE_PROGRAM);
576      mio_sel = 0;
609      state->mio_sel = 0;
577610      ram_space->write_byte(offset, data);
578611      return;
579612   }
r9675r9676
712745
713746static READ8_DEVICE_HANDLER( crtc_portb_r )
714747{
748   pasopia_state *state = device->machine->driver_data<pasopia_state>();
715749   // --x- ---- vsync bit
716750   // ---x ---- lcd dip-sw
717751   // ---- x--- disp bit
r9675r9676
719753   UINT8 vdisp = (device->machine->primary_screen->vpos() < (lcd_bit ? 200 : 28)) ? 0x08 : 0x00; //TODO: check LCD vpos trigger
720754   UINT8 vsync = vdisp ? 0x00 : 0x20;
721755
722   return 0x40 | (attr_latch & 0x87) | vsync | vdisp | (lcd_bit << 4);
756   return 0x40 | (state->attr_latch & 0x87) | vsync | vdisp | (lcd_bit << 4);
723757}
724758
725759static WRITE8_DEVICE_HANDLER( screen_mode_w )
726760{
761   pasopia_state *state = device->machine->driver_data<pasopia_state>();
727762   if(data & 0x5f)
728763      printf("GFX MODE %02x\n",data);
729764
730   x_width = data & 0x20;
731   gfx_mode = data & 0x80;
765   state->x_width = data & 0x20;
766   state->gfx_mode = data & 0x80;
732767
733//   printf("%02x\n",gfx_mode);
768//   printf("%02x\n",state->gfx_mode);
734769}
735770
736771static WRITE8_DEVICE_HANDLER( plane_reg_w )
737772{
773   pasopia_state *state = device->machine->driver_data<pasopia_state>();
738774   //if(data & 0x11)
739775   //printf("PLANE %02x\n",data);
740   plane_reg = data;
776   state->plane_reg = data;
741777}
742778
743779static WRITE8_DEVICE_HANDLER( video_attr_w )
744780{
781   pasopia_state *state = device->machine->driver_data<pasopia_state>();
745782   //printf("VIDEO ATTR %02x | TEXT_PAGE %02x\n",data & 0xf,data & 0x70);
746   attr_data = (data & 0x7) | ((data & 0x8)<<4);
783   state->attr_data = (data & 0x7) | ((data & 0x8)<<4);
747784}
748785
749786//#include "debugger.h"
750787
751788static WRITE8_DEVICE_HANDLER( video_misc_w )
752789{
790   pasopia_state *state = device->machine->driver_data<pasopia_state>();
753791   /*
754792        --x- ---- blinking
755793        ---x ---- attribute wrap
r9675r9676
761799//      printf("VIDEO MISC %02x\n",data);
762800//      debugger_break(device->machine);
763801//  }
764   cursor_blink = data & 0x20;
765   attr_wrap = data & 0x10;
766//  pal_sel = data & 0x02;
802   state->cursor_blink = data & 0x20;
803   state->attr_wrap = data & 0x10;
804//  state->pal_sel = data & 0x02;
767805}
768806
769807static WRITE8_DEVICE_HANDLER( nmi_mask_w )
770808{
809   pasopia_state *state = device->machine->driver_data<pasopia_state>();
771810   /*
772811    --x- ---- (related to the data rec)
773812    ---x ---- data rec out
r9675r9676
778817
779818   if(data & 1)
780819   {
781      nmi_reset &= ~4;
782      nmi_trap &= ~2;
820      state->nmi_reset &= ~4;
821      state->nmi_trap &= ~2;
783822      //cputag_set_input_line(device->machine, "maincpu", INPUT_LINE_NMI, CLEAR_LINE); //guess
784823   }
785824
r9675r9676
793832
794833static READ8_DEVICE_HANDLER( nmi_reg_r )
795834{
835   pasopia_state *state = device->machine->driver_data<pasopia_state>();
796836   //printf("C\n");
797   return 0xfc | bank_reg;//mame_rand(device->machine);
837   return 0xfc | state->bank_reg;//mame_rand(device->machine);
798838}
799839
800840static WRITE8_DEVICE_HANDLER( nmi_reg_w )
801841{
842   pasopia_state *state = device->machine->driver_data<pasopia_state>();
802843   /*
803844        x--- ---- NMI mask
804845        -x-- ---- NMI enable trap on PPI8255 2 r/w
805846    */
806   nmi_mask = data & 0x80;
807   nmi_enable_reg = data & 0x40;
847   state->nmi_mask = data & 0x80;
848   state->nmi_enable_reg = data & 0x40;
808849}
809850
810851static READ8_DEVICE_HANDLER( nmi_porta_r )
r9675r9676
814855
815856static READ8_DEVICE_HANDLER( nmi_portb_r )
816857{
817   return 0xf9 | nmi_trap | nmi_reset;
858   pasopia_state *state = device->machine->driver_data<pasopia_state>();
859   return 0xf9 | state->nmi_trap | state->nmi_reset;
818860}
819861
820862static I8255A_INTERFACE( ppi8255_intf_0 )
r9675r9676
849891
850892static MACHINE_RESET( paso7 )
851893{
894   pasopia_state *state = machine->driver_data<pasopia_state>();
852895   UINT8 *bios = memory_region(machine, "maincpu");
853896
854897   memory_set_bankptr(machine, "bank1", bios + 0x10000);
r9675r9676
856899//  memory_set_bankptr(machine, "bank3", bios + 0x10000);
857900//  memory_set_bankptr(machine, "bank4", bios + 0x10000);
858901
859   nmi_reset |= 4;
902   state->nmi_reset |= 4;
860903}
861904
862905static PALETTE_INIT( pasopia7 )
r9675r9676
881924      palette_set_color_rgb(machine, i+0x020, pal1bit(i >> 1), pal1bit(i >> 2), pal1bit(i >> 0));
882925}
883926
884static MACHINE_CONFIG_START( paso7, driver_device )
927static MACHINE_CONFIG_START( paso7, pasopia_state )
885928    /* basic machine hardware */
886929    MDRV_CPU_ADD("maincpu",Z80, XTAL_4MHz)
887930    MDRV_CPU_PROGRAM_MAP(paso7_mem)
src/mess/drivers/special.c
r9675r9676
2828static ADDRESS_MAP_START(specialist_mem, ADDRESS_SPACE_PROGRAM, 8)
2929   AM_RANGE( 0x0000, 0x2fff ) AM_RAMBANK("bank1") // First bank
3030    AM_RANGE( 0x3000, 0x8fff ) AM_RAM  // RAM
31    AM_RANGE( 0x9000, 0xbfff ) AM_RAM  AM_BASE(&specialist_video_ram) // Video RAM
31    AM_RANGE( 0x9000, 0xbfff ) AM_RAM  AM_BASE_MEMBER(special_state, specialist_video_ram) // Video RAM
3232    AM_RANGE( 0xc000, 0xf000 ) AM_ROM  // System ROM
3333    AM_RANGE( 0xf000, 0xf700 ) AM_NOP
3434    AM_RANGE( 0xf800, 0xffff ) AM_READWRITE(specialist_keyboard_r,specialist_keyboard_w) // 8255 for keyboard
r9675r9676
3737static ADDRESS_MAP_START(specialp_mem, ADDRESS_SPACE_PROGRAM, 8)
3838   AM_RANGE( 0x0000, 0x2fff ) AM_RAMBANK("bank1") // First bank
3939    AM_RANGE( 0x3000, 0x7fff ) AM_RAM  // RAM
40    AM_RANGE( 0x8000, 0xbfff ) AM_RAM  AM_BASE(&specialist_video_ram) // Video RAM
40    AM_RANGE( 0x8000, 0xbfff ) AM_RAM  AM_BASE_MEMBER(special_state, specialist_video_ram) // Video RAM
4141    AM_RANGE( 0xc000, 0xf000 ) AM_ROM  // System ROM
4242    AM_RANGE( 0xf000, 0xf700 ) AM_NOP
4343    AM_RANGE( 0xf800, 0xffff ) AM_READWRITE(specialist_keyboard_r,specialist_keyboard_w) // 8255 for keyboard
r9675r9676
410410};
411411
412412/* Machine driver */
413static MACHINE_CONFIG_START( special, driver_device )
413static MACHINE_CONFIG_START( special, special_state )
414414    /* basic machine hardware */
415415    MDRV_CPU_ADD("maincpu", I8080, 2000000)
416416    MDRV_CPU_PROGRAM_MAP(specialist_mem)
r9675r9676
486486   MDRV_RAM_DEFAULT_VALUE(0x00)
487487MACHINE_CONFIG_END
488488
489static MACHINE_CONFIG_START( erik, driver_device )
489static MACHINE_CONFIG_START( erik, special_state )
490490    /* basic machine hardware */
491491    MDRV_CPU_ADD("maincpu", Z80, 4000000)
492492    MDRV_CPU_PROGRAM_MAP(erik_mem)
src/mess/drivers/ut88.c
r9675r9676
3333   AM_RANGE( 0x0000, 0x07ff ) AM_RAMBANK("bank1") // First bank
3434    AM_RANGE( 0x0800, 0xdfff ) AM_RAM  // RAM
3535    AM_RANGE( 0xe000, 0xe7ff ) AM_RAM  // Video RAM (not used)
36    AM_RANGE( 0xe800, 0xefff ) AM_RAM  AM_BASE(&ut88_video_ram) // Video RAM
36    AM_RANGE( 0xe800, 0xefff ) AM_RAM  AM_BASE_MEMBER(ut88_state, video_ram) // Video RAM
3737    AM_RANGE( 0xf400, 0xf7ff ) AM_RAM  // System RAM
3838    AM_RANGE( 0xf800, 0xffff ) AM_ROM  // System ROM
3939ADDRESS_MAP_END
r9675r9676
175175};
176176
177177/* Machine driver */
178static MACHINE_CONFIG_START( ut88, driver_device )
178static MACHINE_CONFIG_START( ut88, ut88_state )
179179   /* basic machine hardware */
180180    MDRV_CPU_ADD("maincpu", I8080, 2000000)
181181    MDRV_CPU_PROGRAM_MAP(ut88_mem)
r9675r9676
208208   MDRV_CASSETTE_ADD( "cassette", ut88_cassette_config )
209209MACHINE_CONFIG_END
210210
211static MACHINE_CONFIG_START( ut88mini, driver_device )
211static MACHINE_CONFIG_START( ut88mini, ut88_state )
212212   /* basic machine hardware */
213213    MDRV_CPU_ADD("maincpu", I8080, 2000000)
214214    MDRV_CPU_PROGRAM_MAP(ut88mini_mem)
src/mess/drivers/ptcsol.c
r9675r9676
2929#include "machine/terminal.h"
3030#include "devices/messram.h"
3131
32static UINT8 sol20_fa;
33static UINT8 sol20_fc;
34static UINT8 sol20_fe;
35static const UINT8 *FNT;
36static const UINT8 *videoram;
3732
33class ptcsol_state : public driver_device
34{
35public:
36   ptcsol_state(running_machine &machine, const driver_device_config_base &config)
37      : driver_device(machine, config) { }
38
39   UINT8 sol20_fa;
40   UINT8 sol20_fc;
41   UINT8 sol20_fe;
42   const UINT8 *FNT;
43   const UINT8 *videoram;
44   UINT8 framecnt;
45};
46
47
48
3849static READ8_HANDLER( sol20_fa_r )
3950{
40   return sol20_fa;
51   ptcsol_state *state = space->machine->driver_data<ptcsol_state>();
52   return state->sol20_fa;
4153}
4254
4355static READ8_HANDLER( sol20_fc_r )
4456{
45   sol20_fa = 0xff;
46   return sol20_fc;
57   ptcsol_state *state = space->machine->driver_data<ptcsol_state>();
58   state->sol20_fa = 0xff;
59   return state->sol20_fc;
4760}
4861
4962static WRITE8_HANDLER( sol20_fe_w )
5063{
51   sol20_fe = data;
64   ptcsol_state *state = space->machine->driver_data<ptcsol_state>();
65   state->sol20_fe = data;
5266}
5367
5468static ADDRESS_MAP_START( sol20_mem, ADDRESS_SPACE_PROGRAM, 8)
r9675r9676
8397
8498static MACHINE_RESET( sol20 )
8599{
86   sol20_fa=0xff;
87   sol20_fe=0;
100   ptcsol_state *state = machine->driver_data<ptcsol_state>();
101   state->sol20_fa=0xff;
102   state->sol20_fe=0;
88103}
89104
90105static VIDEO_START( sol20 )
91106{
92   FNT = memory_region(machine, "chargen");
93   videoram = memory_region(machine, "maincpu")+0xcc00;
107   ptcsol_state *state = machine->driver_data<ptcsol_state>();
108   state->FNT = memory_region(machine, "chargen");
109   state->videoram = memory_region(machine, "maincpu")+0xcc00;
94110}
95111
96112static VIDEO_UPDATE( sol20 )
97113{
114   ptcsol_state *state = screen->machine->driver_data<ptcsol_state>();
98115/* visible screen is 64 x 16, with start position controlled by scroll register */
99   static UINT8 framecnt=0;
100116   UINT8 y,ra,chr,gfx;
101117   UINT16 sy=0,ma,x,inv;
102118
103   framecnt++;
119   state->framecnt++;
104120
105   ma = sol20_fe << 6; // scroll register
121   ma = state->sol20_fe << 6; // scroll register
106122
107123   for (y = 0; y < 16; y++)
108124   {
r9675r9676
112128
113129         for (x = ma; x < ma + 64; x++)
114130         {
115            chr = videoram[x & 0x3ff];
131            chr = state->videoram[x & 0x3ff];
116132            inv = 0;
117133
118134            /* Take care of flashing characters */
119            if ((chr & 0x80) && (framecnt & 0x08))
135            if ((chr & 0x80) && (state->framecnt & 0x08))
120136               inv ^= 0xff;
121137
122138            chr &= 0x7f;
r9675r9676
126142            else
127143            if (ra < 10)
128144
129               gfx = FNT[(chr<<4) | (ra-1) ] ^ inv;
145               gfx = state->FNT[(chr<<4) | (ra-1) ] ^ inv;
130146            else
131147               gfx = inv;
132148
r9675r9676
148164
149165static WRITE8_DEVICE_HANDLER( sol20_kbd_put )
150166{
151   sol20_fa &= 0xfe;
152   sol20_fc = data;
167   ptcsol_state *state = device->machine->driver_data<ptcsol_state>();
168   state->sol20_fa &= 0xfe;
169   state->sol20_fc = data;
153170}
154171
155172static GENERIC_TERMINAL_INTERFACE( sol20_terminal_intf )
r9675r9676
157174   DEVCB_HANDLER(sol20_kbd_put)
158175};
159176
160static MACHINE_CONFIG_START( sol20, driver_device )
177static MACHINE_CONFIG_START( sol20, ptcsol_state )
161178   /* basic machine hardware */
162179   MDRV_CPU_ADD("maincpu",I8080, XTAL_14_31818MHz/7)
163180   MDRV_CPU_PROGRAM_MAP(sol20_mem)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team