Previous 15994 Revisions Next

r9206 Tuesday 21st September, 2010 at 09:53:04 UTC by Sandro Ronco
[PSION] Rewritten datapack support
[src/mess/drivers]psion.c

src/mess/drivers/psion.c
r9205r9206
55        Driver by Sandro Ronco
66
77        TODO:
8        - implement Datapack read/write interface
9        - add save state and NVRAM
8        - add save state
109        - dump CGROM of the HD44780
11        - move HD44780 implementation in a device
10      - emulate other devices in slot C(Comms Link, printer)
1211
1312        Note:
1413        - 4 lines display has an custom LCD controller derived from an HD66780
r9205r9206
2928
3029struct datapack
3130{
31   device_image_interface *image;
3232   UINT8 id;
3333   UINT8 len;
3434   UINT16 counter;
3535   UINT8 page;
36   UINT8 segment;
37   UINT8 control_lines;
3638   UINT8* data;
39
40   bool write_flag;
3741};
3842
3943static struct _psion
r9205r9206
4347   UINT8 *sys_register;
4448   UINT8 tcsr_value;
4549   UINT8 stby_pwr;
50   UINT8 pulse;
4651
4752   /* RAM/ROM banks */
4853   UINT8 *ram;
r9205r9206
5459   UINT8 rom_bank_count;
5560
5661   UINT8 port2_ddr;
62   UINT8 port2;
5763   UINT8 port6_ddr;
5864   UINT8 port6;
5965
r9205r9206
6369
6470/***********************************************
6571
72    Datapack
73
74***********************************************/
75
76UINT8 datapack_update(datapack *pack, UINT8 data)
77{
78   assert(pack != NULL);
79
80   if (pack->len == 0 || (pack->control_lines & 0x80))
81      return 0;
82
83   UINT32 pack_addr = pack->counter + ((pack->id & 0x04) ? 0x100 * pack->page : 0);
84
85   // if the datapack is 128k or more is treated as segmented
86   if (pack->len >= 0x10)
87      pack_addr += (pack->segment * 0x4000);
88
89   if (pack_addr < pack->len * 0x2000)
90   {
91      if ((pack->control_lines&0x08) && !(pack->control_lines & 0x02))
92      {
93         //write latched data
94         pack->data[pack_addr] = data;
95         pack->write_flag = true;
96      }
97      else if ((pack->control_lines&0x08) && (pack->control_lines & 0x02))
98      {
99         //write datapack segment
100         if (pack->len <= 0x10)
101            pack->segment = data & 0x07;
102         else if (pack->len <= 0x20)
103            pack->segment = data & 0x0f;
104         else if (pack->len <= 0x40)
105            pack->segment = data & 0x1f;
106         else if (pack->len <= 0x80)
107            pack->segment = data & 0x3f;
108         else
109            pack->segment = data;
110      }
111      else if (!(pack->control_lines&0x08) && !(pack->control_lines & 0x02))
112      {
113         //latch data
114         data = pack->data[pack_addr];
115      }
116      else if (!(pack->control_lines&0x08) && (pack->control_lines & 0x02))
117      {
118         //read datapack ID
119         if (pack->id & 0x02)
120            data = pack->data[0];
121         else
122            data = 1;
123      }
124   }
125
126   return data;
127}
128
129void datapack_control_lines_w(datapack *pack, UINT8 data)
130{
131   assert(pack != NULL);
132
133   if ((pack->control_lines & 0x01) != (data & 0x01))
134   {
135      pack->counter++;
136
137      if (pack->counter >= ((pack->id & 0x04) ? 0x100 : (pack->len * 0x2000)))
138         pack->counter = 0;
139   }
140
141   if ((pack->control_lines & 0x04) && !(data & 0x04))
142   {
143      pack->page++;
144
145      if (pack->page >= (pack->len * 0x2000) / 0x100)
146         pack->page = 0;
147   }
148
149   if (data & 0x02)
150   {
151      pack->counter = 0;
152      pack->page = 0;
153   }
154
155   pack->control_lines = data;
156}
157
158UINT8 datapack_control_lines_r(datapack *pack)
159{
160   assert(pack != NULL);
161
162   return pack->control_lines;
163}
164
165int datapack_load(device_image_interface &image, datapack &pack)
166{
167   running_machine *machine = image.device().machine;
168   char opk_head[6];
169   UINT8 pack_id, pack_len;
170
171   image.fread(opk_head, 6);
172   image.fread(&pack_id, 1);
173   image.fread(&pack_len, 1);
174
175   if(strcmp(opk_head, "OPK") || pack_len * 0x2000 < image.length() - 6)
176      return IMAGE_INIT_FAIL;
177
178   pack.image = &image;
179   pack.write_flag = false;
180   pack.id = pack_id;
181   pack.len = pack_len;
182   image.fseek(6, SEEK_SET);
183   pack.data = auto_alloc_array(machine, UINT8, pack.len * 0x2000);
184   memset(pack.data, 0xff, pack.len * 0x2000);
185   image.fread(pack.data, image.length() - 6);
186
187   /* load battery */
188   UINT8 *opk = auto_alloc_array(machine, UINT8, pack.len * 0x2000 + 6);
189   image.battery_load(opk, pack.len * 0x2000 + 6, 0xff);
190   if(!strncmp((char*)opk, "OPK", 3))
191      memcpy(pack.data, opk + 6, pack.len * 0x2000);
192
193   return IMAGE_INIT_PASS;
194}
195
196void datapack_unload(device_image_interface &image, datapack &pack)
197{
198   running_machine *machine = image.device().machine;
199
200   // save battery only if a write-access occurs
201   if (pack.len > 0 && pack.write_flag)
202   {
203      UINT8 opk_magic[6] = {'O', 'P', 'K', 0x00, 0x00, 0x00};
204      UINT8 *opk = auto_alloc_array(machine, UINT8, pack.len * 0x2000 + 6);
205
206      memcpy(opk, opk_magic, 6);
207      memcpy(opk + 6, pack.data, pack.len * 0x2000);
208
209      pack.image->battery_save(opk, pack.len * 0x2000 + 6);
210
211      auto_free(machine, opk);
212   }
213
214   auto_free(machine, pack.data);
215   pack.len = 0;
216}
217
218/***********************************************
219
66220    basic machine
67221
68222***********************************************/
r9205r9206
120274   return NULL;
121275}
122276
123void datapack_w(running_machine *machine, UINT8 data)
124{
125   //TODO
126}
127
128UINT8 datapack_r(running_machine *machine)
129{
130   struct datapack *pack = get_active_slot(machine, psion.port6);
131
132   if (pack != NULL && pack->len > 0 && !(psion.port6 & 0x80))
133   {
134      UINT32 pack_addr = pack->counter + ((pack->id & 0x04) ? 0x100 * pack->page : 0);
135
136      if (pack_addr < pack->len * 0x2000)
137         return pack->data[pack_addr];
138   }
139
140   return 0;
141}
142
143277WRITE8_HANDLER( hd63701_int_reg_w )
144278{
145279   switch (offset)
r9205r9206
149283      break;
150284   case 0x03:
151285      /* datapack i/o data bus */
152      datapack_w(space->machine, data);
286      if (psion.port2_ddr == 0xff)
287      {
288         datapack *pack = get_active_slot(space->machine, psion.port6);
289
290         if (pack)
291            psion.port2 = datapack_update(pack, data);
292         else
293            psion.port2 = data;
294      }
153295      break;
154296   case 0x08:
155297      psion.tcsr_value = data;
r9205r9206
172314        ---- --x- reset line
173315        ---- ---x clock line
174316        */
175      if (psion.port6_ddr == 0xff)
176317      {
177         struct datapack *pack = get_active_slot(space->machine, data);
318         psion.port6 = (data & psion.port6_ddr) | (psion.port6 & ~psion.port6_ddr);
319         datapack *pack = get_active_slot(space->machine, psion.port6);
178320
179321         if (pack != NULL)
180322         {
181            if ((psion.port6 & 0x01) != (data & 0x01))
182            {
183               pack->counter++;
184
185               if (pack->counter >= ((pack->id & 0x04) ? 0x100 : (pack->len * 0x2000)))
186                  pack->counter = 0;
187            }
188
189            if ((psion.port6 & 0x04) && !(data & 0x04))
190            {
191               pack->page++;
192
193               if (pack->page >= (pack->len * 0x2000) / 0x100)
194                  pack->page = 0;
195            }
196
197            if (psion.port6 & 0x02)
198            {
199               pack->counter = 0;
200               pack->page = 0;
201            }
323            datapack_control_lines_w(pack, psion.port6);
324            datapack_update(pack, psion.port2);
202325         }
203
204         psion.port6 = data;
205326      }
206327      break;
207328   }
r9205r9206
215336   {
216337   case 0x03:
217338      /* datapack i/o data bus */
218      return datapack_r(space->machine);
339      if (psion.port2_ddr == 0)
340      {
341         datapack *pack = get_active_slot(space->machine, psion.port6);
342
343         if (pack)
344            psion.port2 = datapack_update(pack, psion.port2);
345         else
346            psion.port2 = 0;
347
348         return psion.port2;
349      }
350      else
351         return 0;
219352   case 0x14:
220353      return (hd63701_internal_registers_r(space, offset)&0x7f) | (psion.stby_pwr<<7);
221354   case 0x15:
222355      /*
223356        x--- ---- ON key active high
224357        -xxx xx-- keys matrix active low
225        ---- --x- ??
358        ---- --x- pulse
226359        ---- ---x battery status
227360        */
228      return kb_read(space->machine) | input_port_read(space->machine, "BATTERY") | input_port_read(space->machine, "ON") | (psion.kb_counter == 0x7ff)<<1;
361      return kb_read(space->machine) | input_port_read(space->machine, "BATTERY") | input_port_read(space->machine, "ON") | (psion.kb_counter == 0x7ff)<<1 | psion.pulse<<1;
229362   case 0x17:
230      return psion.port6;
363      /* datapack control lines */
364      {
365         datapack *pack = get_active_slot(space->machine, psion.port6);
366
367         if (pack)
368            return datapack_control_lines_r(pack);
369         else
370            return psion.port6;
371      }
231372   case 0x08:
232373      hd63701_internal_registers_w(space, offset, psion.tcsr_value);
233374   default:
r9205r9206
250391      space->machine->device<cpu_device>("maincpu")->suspend(SUSPEND_REASON_HALT, 1);
251392      break;
252393   case 0x100:
253      //Pulse enable
394      psion.pulse = 1;
254395      break;
255396   case 0x140:
256      //Pulse disable
397      psion.pulse = 0;
257398      break;
258399   case 0x200:
259400      psion.kb_counter = 0;
r9205r9206
448589      PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("D [)]") PORT_CODE(KEYCODE_D)
449590INPUT_PORTS_END
450591
451int datapack_load(device_image_interface &image, struct datapack &pack)
452{
453   running_machine *machine = image.device().machine;
454   char opk_head[6];
455   UINT8 pack_id, pack_len;
456
457   image.fread(opk_head, 6);
458   image.fread(&pack_id, 1);
459   image.fread(&pack_len, 1);
460
461   if(strcmp(opk_head, "OPK") || pack_len * 0x2000 < image.length() - 6)
462      return IMAGE_INIT_FAIL;
463
464   pack.id = pack_id;
465   pack.len = pack_len;
466   image.fseek(6, SEEK_SET);
467   pack.data = auto_alloc_array(machine, UINT8, pack.len * 0x2000);
468   memset(pack.data, 0xff, pack.len * 0x2000);
469   image.fread(pack.data, image.length() - 6);
470
471   return IMAGE_INIT_PASS;
472}
473
474592static DEVICE_IMAGE_LOAD( psion_pack1 )
475593{
476594   return datapack_load(image, psion.pack1);
r9205r9206
478596
479597static DEVICE_IMAGE_UNLOAD( psion_pack1 )
480598{
481   auto_free(image.device().machine, psion.pack1.data);
482   memset(&psion.pack1, 0, sizeof(psion.pack1));
599   datapack_unload(image, psion.pack1);
483600}
484601
485602static DEVICE_IMAGE_LOAD( psion_pack2 )
r9205r9206
489606
490607static DEVICE_IMAGE_UNLOAD( psion_pack2 )
491608{
492   auto_free(image.device().machine, psion.pack2.data);
493   memset(&psion.pack2, 0, sizeof(psion.pack2));
609   datapack_unload(image, psion.pack2);
494610}
495611
496612static NVRAM_HANDLER( psion )
r9205r9206
558674   psion.kb_counter=0;
559675   psion.ram_bank=0;
560676   psion.rom_bank=0;
677   psion.pulse=0;
561678
562679   if (psion.rom_bank_count || psion.ram_bank_count)
563680      update_bank(machine);

Previous 15994 Revisions Next


© 1998-2018 The MESS Team