Previous 15994 Revisions Next

r10973 Tuesday 29th March, 2011 at 07:19:25 UTC by Sandro Ronco
[TI82] Added serial support (Receive only)
[src/mess/drivers]ti85.c
[src/mess/formats]ti85_ser.c ti85_ser.h
[src/mess/machine]ti85.c

src/mess/machine/ti85.c
r10972r10973
464464
465465READ8_HANDLER ( ti82_port_0000_r )
466466{
467   return 0xff; // TODO
467   ti85_state *state = space->machine->driver_data<ti85_state>();
468   device_t *ti85serial = space->machine->device("ti82serial");;
469
470   ti85_update_serial(ti85serial);
471   return (state->white_out<<3)
472      | (state->red_out<<2)
473      | ((ti85serial_white_in(ti85serial,0)&(1-state->white_out))<<1)
474      | (ti85serial_red_in(ti85serial,0)&(1-state->red_out))
475      | state->PCR;
468476}
469477
470478 READ8_HANDLER ( ti82_port_0002_r )
r10972r10973
650658
651659WRITE8_HANDLER ( ti82_port_0000_w )
652660{
653   // TODO
661   ti85_state *state = space->machine->driver_data<ti85_state>();
662   device_t *speaker = space->machine->device("speaker");
663   device_t *ti85serial = space->machine->device("ti82serial");
664
665   speaker_level_w(speaker,( (data>>2)|(data>>3) )&0x01 );
666   state->red_out=(data>>2)&0x01;
667   state->white_out=(data>>3)&0x01;
668   ti85serial_red_out( ti85serial, 0, state->red_out );
669   ti85serial_white_out( ti85serial, 0, state->white_out );
670   ti85_update_serial(ti85serial);
671   state->PCR = data&0xf0;
654672}
655673
656674WRITE8_HANDLER ( ti82_port_0002_w )
src/mess/formats/ti85_ser.c
r10972r10973
4242#define TI85_PC_END_PACKET_SIZE   4
4343
4444static const UINT8 ti85_pc_ok_packet[] = {0x05, 0x56, 0x00, 0x00};
45static const UINT8 ti82_pc_ok_packet[] = {0x02, 0x56, 0x00, 0x00};
4546static const UINT8 ti86_pc_ok_packet[] = {0x06, 0x56, 0x00, 0x00};
4647static const UINT8 ti85_pc_continue_packet[] = {0x05, 0x09, 0x00, 0x00};
48static const UINT8 ti82_pc_continue_packet[] = {0x02, 0x09, 0x00, 0x00};
4749static const UINT8 ti86_pc_continue_packet[] = {0x06, 0x09, 0x00, 0x00};
4850static const UINT8 ti85_pc_screen_request_packet[] = {0x05, 0x6d, 0x00, 0x00};
4951static const UINT8 ti85_pc_end_packet[] = {0x05, 0x92, 0x00, 0x00};
52static const UINT8 ti82_pc_end_packet[] = {0x02, 0x92, 0x00, 0x00};
5053static const UINT8 ti86_pc_end_packet[] = {0x06, 0x92, 0x00, 0x00};
5154
5255static const UINT8 ti85_file_signature[] = {0x2a, 0x2a, 0x54, 0x49, 0x38, 0x35, 0x2a, 0x2a, 0x1a, 0x0c, 0x00};
56static const UINT8 ti82_file_signature[] = {0x2a, 0x2a, 0x54, 0x49, 0x38, 0x32, 0x2a, 0x2a, 0x1a, 0x0a, 0x00};
5357static const UINT8 ti86_file_signature[] = {0x2a, 0x2a, 0x54, 0x49, 0x38, 0x36, 0x2a, 0x2a, 0x1a, 0x0a, 0x00};
5458
5559typedef struct {
r10972r10973
112116INLINE ti85serial_state *get_token(device_t *device)
113117{
114118   assert(device != NULL);
115   assert((device->type() == TI85SERIAL) || (device->type() == TI86SERIAL));
119   assert((device->type() == TI82SERIAL) || (device->type() == TI85SERIAL) || (device->type() == TI86SERIAL));
116120   return (ti85serial_state *) downcast<legacy_device_base *>(device)->token();
117121}
118122
r10972r10973
204208}
205209
206210
207static void ti85_variables_read (const UINT8 * ti85_data, unsigned int ti85_data_size, ti85_entry * ti85_entries)
211static void ti85_variables_read (device_t *device, const UINT8 * ti85_data, unsigned int ti85_data_size, ti85_entry * ti85_entries)
208212{
209213   unsigned int pos, i=0;
210214
r10972r10973
214218      ti85_entries[i].head_size = ti85_data[pos+0x00] + ti85_data[pos+0x01]*256;
215219      ti85_entries[i].data_size = ti85_data[pos+0x02] + ti85_data[pos+0x03]*256;
216220      ti85_entries[i].type = ti85_data[pos+0x04];
217      ti85_entries[i].name_size = ti85_data[pos+0x05];
221      ti85_entries[i].name_size = (device->type() == TI82SERIAL) ? 8 : ti85_data[pos+0x05];
218222      ti85_entries[i].offset = pos;
219223      pos += ti85_entries[i].head_size+ti85_entries[i].data_size+4;
220224      i++;
r10972r10973
319323   ti85serial_state *ti85serial = get_token( device );
320324   UINT16 i;
321325   UINT16 number_of_entries;
326   UINT8 backup_id = (device->type() == TI85SERIAL || device->type() == TI86SERIAL) ? 0x1d : 0x13;
322327
323328   ti85_entry* ti85_entries = NULL;
324329
r10972r10973
328333   if (device->type() == TI85SERIAL)
329334      if (strncmp((char *) file_data, (char *) ti85_file_signature, 11))
330335         return 0;
336   if (device->type() == TI82SERIAL)
337      if (strncmp((char *) file_data, (char *) ti82_file_signature, 11))
338         return 0;
331339   if (device->type() == TI86SERIAL)
332340      if (strncmp((char *) file_data, (char *) ti86_file_signature, 11))
333341         return 0;
r10972r10973
335343   /*Serial stream preparing*/
336344   serial_data->end = NULL;
337345
338   number_of_entries = (file_data[0x3b]==0x1d) ? 3 : ti85_variables_count(file_data, file_size);
346   number_of_entries = (file_data[0x3b]==backup_id) ? 3 : ti85_variables_count(file_data, file_size);
339347   if (!number_of_entries) return 0;
340348
341349   serial_data->variables = (ti85_serial_variable*)malloc(sizeof(ti85_serial_variable)*number_of_entries);
r10972r10973
353361   ti85_entries = (ti85_entry*) malloc (sizeof(ti85_entry)*number_of_entries);
354362   if (!ti85_entries) return 0;
355363
356   if (file_data[0x3b]==0x1d)
364   if (file_data[0x3b]==backup_id)
357365   {
358366      ti85serial->transfer_type = TI85_SEND_BACKUP;
359367      ti85_backup_read (file_data, file_size, ti85_entries);
r10972r10973
361369   else
362370   {
363371      ti85serial->transfer_type = TI85_SEND_VARIABLES;
364      ti85_variables_read (file_data, file_size, ti85_entries);
372      ti85_variables_read (device, file_data, file_size, ti85_entries);
365373   }
366374   for (i=0; i<number_of_entries; i++)
367375   {
368376      /*Header packet*/
369      if (file_data[0x3b]==0x1d)
377      if (file_data[0x3b]==backup_id)
370378      {
371379         if (!i)
372380         {
r10972r10973
415423            free (ti85_entries);
416424            return 0;
417425         }
418         serial_data->variables[i].header_size = (10+ti85_entries[i].name_size)*8;
419426
420         if (device->type() == TI85SERIAL)
421            temp_data_to_convert[0] = 0x05;   //PC to TI-85
422         if (device->type() == TI86SERIAL)
423            temp_data_to_convert[0] = 0x06;   //PC to TI-86
424         temp_data_to_convert[1] = 0x06;   //header
425         temp_data_to_convert[2] = (4+ti85_entries[i].name_size)&0x00ff;
426         temp_data_to_convert[3] = ((4+ti85_entries[i].name_size)&0xff00)>>8;
427         temp_data_to_convert[4] = (ti85_entries[i].data_size)&0x00ff;
428         temp_data_to_convert[5] = ((ti85_entries[i].data_size)&0xff00)>>8;
429         temp_data_to_convert[6] = ti85_entries[i].type;
430         temp_data_to_convert[7] = ti85_entries[i].name_size;
431         memcpy(temp_data_to_convert+8, file_data+ti85_entries[i].offset+0x06, ti85_entries[i].name_size);
432         checksum = ti85_calculate_checksum(temp_data_to_convert+4,ti85_entries[i].name_size+4);
433         temp_data_to_convert[10+ti85_entries[i].name_size-2] = checksum&0x00ff;
434         temp_data_to_convert[10+ti85_entries[i].name_size-1] = (checksum&0xff00)>>8;
435         ti85_convert_data_to_stream(temp_data_to_convert, 10+ti85_entries[i].name_size, serial_data->variables[i].header);
427         if (device->type() == TI85SERIAL || device->type() == TI86SERIAL)
428         {
429            serial_data->variables[i].header_size = (10+ti85_entries[i].name_size)*8;
430
431            if (device->type() == TI85SERIAL)
432               temp_data_to_convert[0] = 0x05;   //PC to TI-85
433            if (device->type() == TI86SERIAL)
434               temp_data_to_convert[0] = 0x06;   //PC to TI-86
435            temp_data_to_convert[1] = 0x06;   //header
436            temp_data_to_convert[2] = (4+ti85_entries[i].name_size)&0x00ff;
437            temp_data_to_convert[3] = ((4+ti85_entries[i].name_size)&0xff00)>>8;
438            temp_data_to_convert[4] = (ti85_entries[i].data_size)&0x00ff;
439            temp_data_to_convert[5] = ((ti85_entries[i].data_size)&0xff00)>>8;
440            temp_data_to_convert[6] = ti85_entries[i].type;
441            temp_data_to_convert[7] = ti85_entries[i].name_size;
442            memcpy(temp_data_to_convert+8, file_data+ti85_entries[i].offset+0x06, ti85_entries[i].name_size);
443            checksum = ti85_calculate_checksum(temp_data_to_convert+4,ti85_entries[i].name_size+4);
444            temp_data_to_convert[10+ti85_entries[i].name_size-2] = checksum&0x00ff;
445            temp_data_to_convert[10+ti85_entries[i].name_size-1] = (checksum&0xff00)>>8;
446            ti85_convert_data_to_stream(temp_data_to_convert, 10+ti85_entries[i].name_size, serial_data->variables[i].header);
447         }
448
449         if (device->type() == TI82SERIAL)
450         {
451            serial_data->variables[i].header_size = (9+ti85_entries[i].name_size)*8;
452
453            temp_data_to_convert[0] = 0x02;   //PC to TI-82
454            temp_data_to_convert[1] = 0x06;   //header
455            temp_data_to_convert[2] = (3+ti85_entries[i].name_size)&0x00ff;
456            temp_data_to_convert[3] = ((3+ti85_entries[i].name_size)&0xff00)>>8;
457            temp_data_to_convert[4] = (ti85_entries[i].data_size)&0x00ff;
458            temp_data_to_convert[5] = ((ti85_entries[i].data_size)&0xff00)>>8;
459            temp_data_to_convert[6] = ti85_entries[i].type;
460            memcpy(temp_data_to_convert+7, file_data+ti85_entries[i].offset+0x05, ti85_entries[i].name_size);
461            checksum = ti85_calculate_checksum(temp_data_to_convert+4,ti85_entries[i].name_size+3);
462            temp_data_to_convert[9+ti85_entries[i].name_size-2] = checksum&0x00ff;
463            temp_data_to_convert[9+ti85_entries[i].name_size-1] = (checksum&0xff00)>>8;
464            ti85_convert_data_to_stream(temp_data_to_convert, 9+ti85_entries[i].name_size, serial_data->variables[i].header);
465         }
466
436467         free(temp_data_to_convert);
437468      }
438469
r10972r10973
445476      }
446477      if (device->type() == TI85SERIAL)
447478         ti85_convert_data_to_stream(ti85_pc_ok_packet, TI85_PC_OK_PACKET_SIZE, serial_data->variables[i].ok);
479      if (device->type() == TI82SERIAL)
480         ti85_convert_data_to_stream(ti82_pc_ok_packet, TI85_PC_OK_PACKET_SIZE, serial_data->variables[i].ok);
448481      if (device->type() == TI86SERIAL)
449482         ti85_convert_data_to_stream(ti86_pc_ok_packet, TI85_PC_OK_PACKET_SIZE, serial_data->variables[i].ok);
450483      serial_data->variables[i].ok_size = TI85_PC_OK_PACKET_SIZE*8;
r10972r10973
467500
468501      if (device->type() == TI85SERIAL)
469502         temp_data_to_convert[0] = 0x05;   //PC to TI-85
503      if (device->type() == TI82SERIAL)
504         temp_data_to_convert[0] = 0x02;   //PC to TI-82
470505      if (device->type() == TI86SERIAL)
471506         temp_data_to_convert[0] = 0x06;   //PC to TI-86
472507      temp_data_to_convert[1] = 0x15;   //data
473508      temp_data_to_convert[2] = (ti85_entries[i].data_size)&0x00ff;
474509      temp_data_to_convert[3] = ((ti85_entries[i].data_size)&0xff00)>>8;
475      if (file_data[0x3b]==0x1d)
510
511      UINT8 name_start = (device->type() == TI82SERIAL) ? 5 : 6;
512      if (file_data[0x3b]==backup_id)
476513         memcpy(temp_data_to_convert+4, file_data+ti85_entries[i].offset, ti85_entries[i].data_size);
477514      else
478         memcpy(temp_data_to_convert+4, file_data+ti85_entries[i].offset+0x06+ti85_entries[i].name_size+0x02, ti85_entries[i].data_size);
515         memcpy(temp_data_to_convert+4, file_data+ti85_entries[i].offset+name_start+ti85_entries[i].name_size+0x02, ti85_entries[i].data_size);
516
479517      checksum = ti85_calculate_checksum(temp_data_to_convert+4,ti85_entries[i].data_size);
480518      temp_data_to_convert[6+ti85_entries[i].data_size-2] = checksum&0x00ff;
481519      temp_data_to_convert[6+ti85_entries[i].data_size-1] = (checksum&0xff00)>>8;
r10972r10973
493531   }
494532   if (device->type() == TI85SERIAL)
495533      ti85_convert_data_to_stream(ti85_pc_end_packet, TI85_PC_END_PACKET_SIZE, serial_data->end);
534   if (device->type() == TI82SERIAL)
535      ti85_convert_data_to_stream(ti82_pc_end_packet, TI85_PC_END_PACKET_SIZE, serial_data->end);
496536   if (device->type() == TI86SERIAL)
497537      ti85_convert_data_to_stream(ti86_pc_end_packet, TI85_PC_END_PACKET_SIZE, serial_data->end);
498538   serial_data->end_size = TI85_PC_END_PACKET_SIZE*8;
r10972r10973
894934
895935            if (filerr == FILERR_NONE)
896936            {
897               var_file.write(ti85serial->var_file_data, ti85serial->var_file_size);               
937               var_file.write(ti85serial->var_file_data, ti85serial->var_file_size);
898938               free (ti85serial->var_file_data);
899939               ti85serial->var_file_data = NULL;
900940               ti85serial->var_file_size = 0;
r10972r10973
10311071               ti85serial->backup_file_data[0x42+0x06+ti85serial->backup_data_size[0]+ti85serial->backup_data_size[1]+ti85serial->backup_data_size[2]] = ti85_calculate_checksum(ti85serial->backup_file_data+0x37, 0x42+ti85serial->backup_data_size[0]+ti85serial->backup_data_size[1]+ti85serial->backup_data_size[2]+0x06-0x37)&0x00ff;
10321072               ti85serial->backup_file_data[0x42+0x06+ti85serial->backup_data_size[0]+ti85serial->backup_data_size[1]+ti85serial->backup_data_size[2]+0x01] = (ti85_calculate_checksum(ti85serial->backup_file_data+0x37, 0x42+ti85serial->backup_data_size[0]+ti85serial->backup_data_size[1]+ti85serial->backup_data_size[2]+0x06-0x37)&0xff00)>>8;
10331073               sprintf (backup_file_name, "%08d.85b", ti85serial->backup_file_number);
1034               
1074
10351075               emu_file backup_file(device->machine->options().memcard_directory(), OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE);
10361076               filerr = backup_file.open(backup_file_name);
1037               
1077
10381078               if (filerr == FILERR_NONE)
10391079               {
10401080                  backup_file.write(ti85serial->backup_file_data, 0x42+0x06+ti85serial->backup_data_size[0]+ti85serial->backup_data_size[1]+ti85serial->backup_data_size[2]+0x02);
r10972r10973
10961136         {
10971137            ti85_convert_stream_to_data (ti85serial->receive_buffer, 1030*8, ti85serial->receive_data);
10981138            sprintf (image_file_name, "%08d.85i", ti85serial->image_file_number);
1099           
1139
11001140            emu_file image_file(device->machine->options().memcard_directory(), OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE);
11011141            filerr = image_file.open(image_file_name);
1102           
1142
11031143            if (filerr == FILERR_NONE)
11041144            {
11051145               image_file_data = (UINT8*)malloc (0x49+1008);
r10972r10973
11281168               memcpy(image_file_data+0x47, ti85serial->receive_data+4, 1008);
11291169               image_file_data[1008+0x49-2] = ti85_calculate_checksum(image_file_data+0x37, 1008+0x10)&0x00ff;
11301170               image_file_data[1008+0x49-1] = (ti85_calculate_checksum(image_file_data+0x37, 1008+0x10)&0xff00)>>8;
1131               image_file.write(image_file_data, 1008+0x49);               
1171               image_file.write(image_file_data, 1008+0x49);
11321172               free(image_file_data);
11331173               ti85serial->image_file_number++;
11341174            }
r10972r10973
13621402}
13631403
13641404
1405DEVICE_GET_INFO( ti82serial )
1406{
1407   switch ( state )
1408   {
1409   case DEVINFO_STR_NAME:                     strcpy(info->s, "TI82 Serial");                                       break;
1410   case DEVINFO_STR_IMAGE_FILE_EXTENSIONS:         strcpy(info->s, "82p,82s,82i,82n,82c,82l,82k,82m,82v,82d,82e,82r,82g");         break;
1411   default:                              DEVICE_GET_INFO_CALL( ti85serial );
1412   }
1413}
1414
1415
13651416DEVICE_GET_INFO( ti86serial )
13661417{
13671418   switch ( state )
r10972r10973
13731424}
13741425
13751426DEFINE_LEGACY_IMAGE_DEVICE(TI85SERIAL, ti85serial);
1427DEFINE_LEGACY_IMAGE_DEVICE(TI82SERIAL, ti82serial);
13761428DEFINE_LEGACY_IMAGE_DEVICE(TI86SERIAL, ti86serial);
src/mess/formats/ti85_ser.h
r10972r10973
44
55
66DECLARE_LEGACY_IMAGE_DEVICE(TI85SERIAL, ti85serial);
7DECLARE_LEGACY_IMAGE_DEVICE(TI82SERIAL, ti82serial);
78DECLARE_LEGACY_IMAGE_DEVICE(TI86SERIAL, ti86serial);
89
910extern void ti85_update_serial(device_t *device);
r10972r10973
1112#define MCFG_TI85SERIAL_ADD( _tag ) \
1213      MCFG_DEVICE_ADD( _tag, TI85SERIAL, 0 )
1314
15#define MCFG_TI82SERIAL_ADD( _tag ) \
16      MCFG_DEVICE_ADD( _tag, TI82SERIAL, 0 )
17
1418#define MCFG_TI86SERIAL_ADD( _tag ) \
1519      MCFG_DEVICE_ADD( _tag, TI86SERIAL, 0 )
1620
src/mess/drivers/ti85.c
r10972r10973
546546
547547   MCFG_MACHINE_START( ti82 )
548548   MCFG_MACHINE_RESET( ti85 )
549   
549
550550   MCFG_SCREEN_MODIFY("screen")
551551   MCFG_SCREEN_UPDATE( ti82 )
552
553   MCFG_SPEAKER_STANDARD_MONO("mono")
554   MCFG_SOUND_ADD("speaker", SPEAKER_SOUND, 0)
555   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
556
557   MCFG_TI82SERIAL_ADD( "ti82serial" )
552558MACHINE_CONFIG_END
553559
554560static MACHINE_CONFIG_DERIVED( ti83, ti81 )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team