Previous 15994 Revisions Next

r14705 Tuesday 6th March, 2012 at 12:29:53 UTC by Miodrag Milanović
last one (nw)
[src/mess/includes]hp48.h
[src/mess/machine]hp48.c

src/mess/machine/hp48.c
r14704r14705
3737#define   HP48_MODULE_MASK_KNOWN   1
3838#define HP48_MODULE_CONFIGURED   2
3939
40/* port specification */
41struct hp48_port_config
42{
43   int port;                 /* port index: 0 or 1 (for port 1 and 2) */
44   int module;               /* memory module where the port is visible */
45   int max_size;             /* maximum size, in bytes 128 KB or 4 GB */
46
47   /* device instance names */
48   const char* brief_name;
49   const char* name;
50
51};
52
53
5440/***************************************************************************
5541    GLOBAL VARIABLES & CONSTANTS
5642***************************************************************************/
r14704r14705
985971/* ----- card images ------ */
986972
987973/* port information configurations */
988const struct hp48_port_config hp48sx_port1_config = { 0, 2,    128*1024, "p1", "port1" };
989const struct hp48_port_config hp48sx_port2_config = { 1, 3,    128*1024, "p2", "port2" };
990const struct hp48_port_config hp48gx_port1_config = { 0, 3,    128*1024, "p1", "port1" };
991const struct hp48_port_config hp48gx_port2_config = { 1, 4, 4*1024*1024, "p2", "port2" };
974const struct hp48_port_interface hp48sx_port1_config = { 0, 2,    128*1024 };
975const struct hp48_port_interface hp48sx_port2_config = { 1, 3,    128*1024 };
976const struct hp48_port_interface hp48gx_port1_config = { 0, 3,    128*1024 };
977const struct hp48_port_interface hp48gx_port2_config = { 1, 4, 4*1024*1024 };
992978
979const device_type HP48_PORT = &device_creator<hp48_port_image_device>;
980
993981/* helper for load and create */
994static void hp48_fill_port( device_t* image )
982void hp48_port_image_device::hp48_fill_port()
995983{
996   hp48_state *state = image->machine().driver_data<hp48_state>();
997   struct hp48_port_config* conf = (struct hp48_port_config*) image->static_config();
984   hp48_state *state = machine().driver_data<hp48_state>();
985   struct hp48_port_interface* conf = (struct hp48_port_interface*) static_config();
998986   int size = state->m_port_size[conf->port];
999   LOG(( "hp48_fill_port: %s module=%i size=%i rw=%i\n", conf->name, conf->module, size, state->m_port_write[conf->port] ));
987   LOG(( "hp48_fill_port: %s module=%i size=%i rw=%i\n", tag(), conf->module, size, state->m_port_write[conf->port] ));
1000988   state->m_port_data[conf->port] = (UINT8*)malloc( 2 * size );
1001989   memset( state->m_port_data[conf->port], 0, 2 * size );
1002990   state->m_modules[conf->module].off_mask = 2 * (( size > 128 * 1024 ) ? 128 * 1024 : size) - 1;
r14704r14705
1011999}
10121000
10131001/* helper for start and unload */
1014static void hp48_unfill_port( device_t* image )
1002void hp48_port_image_device::hp48_unfill_port()
10151003{
1016   hp48_state *state = image->machine().driver_data<hp48_state>();
1017   struct hp48_port_config* conf = (struct hp48_port_config*) image->static_config();
1004   hp48_state *state = machine().driver_data<hp48_state>();
1005   struct hp48_port_interface* conf = (struct hp48_port_interface*) static_config();
10181006   state->m_modules[conf->module].off_mask = 0x00fff;  /* 2 KB */
10191007   state->m_modules[conf->module].read     = NULL;
10201008   state->m_modules[conf->module].write    = NULL;
r14704r14705
10221010}
10231011
10241012
1025static DEVICE_IMAGE_LOAD( hp48_port )
1013bool hp48_port_image_device::call_load()
10261014{
1027   hp48_state *state = image.device().machine().driver_data<hp48_state>();
1028   struct hp48_port_config* conf = (struct hp48_port_config*) image.device().static_config();
1029   int size = image.length();
1015   hp48_state *state = machine().driver_data<hp48_state>();
1016   struct hp48_port_interface* conf = (struct hp48_port_interface*)static_config();
1017   int size = length();
10301018   if ( size == 0 ) size = conf->max_size; /* default size */
10311019
10321020   /* check size */
10331021   if ( (size < 32*1024) || (size > conf->max_size) || (size & (size-1)) )
10341022   {
1035      logerror( "hp48: image size for %s should be a power of two between %i and %i\n", conf->name, 32*1024, conf->max_size );
1023      logerror( "hp48: image size for %s should be a power of two between %i and %i\n", tag(), 32*1024, conf->max_size );
10361024      return IMAGE_INIT_FAIL;
10371025   }
10381026
10391027   state->m_port_size[conf->port] = size;
1040   state->m_port_write[conf->port] = !image.is_readonly();
1041   hp48_fill_port( image );
1042   image.fread(state->m_port_data[conf->port], state->m_port_size[conf->port] );
1028   state->m_port_write[conf->port] = !is_readonly();
1029   hp48_fill_port( );
1030   fread(state->m_port_data[conf->port], state->m_port_size[conf->port] );
10431031   hp48_decode_nibble( state->m_port_data[conf->port], state->m_port_data[conf->port], state->m_port_size[conf->port] );
10441032   return IMAGE_INIT_PASS;
10451033}
10461034
1047static DEVICE_IMAGE_CREATE( hp48_port )
1035bool hp48_port_image_device::call_create(int format_type, option_resolution *format_options)
10481036{
1049   hp48_state *state = image.device().machine().driver_data<hp48_state>();
1050   struct hp48_port_config* conf = (struct hp48_port_config*) image.device().static_config();
1037   hp48_state *state = machine().driver_data<hp48_state>();
1038   struct hp48_port_interface* conf = (struct hp48_port_interface*) static_config();
10511039   int size = conf->max_size;
10521040   /* XXX defaults to max_size; get user-specified size instead */
10531041
r14704r14705
10551043   /* size must be a power of 2 between 32K and max_size */
10561044   if ( (size < 32*1024) || (size > conf->max_size) || (size & (size-1)) )
10571045   {
1058      logerror( "hp48: image size for %s should be a power of two between %i and %i\n", conf->name, 32*1024, conf->max_size );
1046      logerror( "hp48: image size for %s should be a power of two between %i and %i\n", tag(), 32*1024, conf->max_size );
10591047      return IMAGE_INIT_FAIL;
10601048   }
10611049
10621050   state->m_port_size[conf->port] = size;
10631051   state->m_port_write[conf->port] = 1;
1064   hp48_fill_port( image );
1052   hp48_fill_port();
10651053   return IMAGE_INIT_PASS;
10661054}
10671055
1068static DEVICE_IMAGE_UNLOAD( hp48_port )
1056void hp48_port_image_device::call_unload()
10691057{
1070   hp48_state *state = image.device().machine().driver_data<hp48_state>();
1071   struct hp48_port_config* conf = (struct hp48_port_config*) image.device().static_config();
1058   hp48_state *state = machine().driver_data<hp48_state>();
1059   struct hp48_port_interface* conf = (struct hp48_port_interface*) static_config();
10721060   LOG(( "hp48_port image unload: %s size=%i rw=%i\n",
1073         conf->name, state->m_port_size[conf->port] ,state->m_port_write[conf->port] ));
1061         tag(), state->m_port_size[conf->port] ,state->m_port_write[conf->port] ));
10741062   if ( state->m_port_write[conf->port] )
10751063   {
10761064      hp48_encode_nibble( state->m_port_data[conf->port], state->m_port_data[conf->port], state->m_port_size[conf->port] );
1077      image.fseek( 0, SEEK_SET );
1078      image.fwrite( state->m_port_data[conf->port], state->m_port_size[conf->port] );
1065      fseek( 0, SEEK_SET );
1066      fwrite( state->m_port_data[conf->port], state->m_port_size[conf->port] );
10791067   }
10801068   free( state->m_port_data[conf->port] );
1081   hp48_unfill_port( image );
1069   hp48_unfill_port();
10821070   hp48_apply_modules(state);
10831071}
10841072
1085static DEVICE_START( hp48_port )
1073void hp48_port_image_device::device_start()
10861074{
1087   hp48_unfill_port( device );
1075   hp48_unfill_port();
10881076}
10891077
1090DEVICE_GET_INFO( hp48_port )
1078hp48_port_image_device::hp48_port_image_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
1079    : device_t(mconfig, HP48_PORT, "HP48 memory card", tag, owner, clock),
1080     device_image_interface(mconfig, *this)
10911081{
1092   struct hp48_port_config* conf = device ? (struct hp48_port_config*) device->static_config() : NULL;
1093   switch ( state )
1094   {
1095   case DEVINFO_INT_TOKEN_BYTES:                 info->i = 1;                                               break;
1096   case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                                               break;
1097   case DEVINFO_INT_IMAGE_TYPE:                 info->i = IO_MEMCARD;                                      break;
1098   case DEVINFO_INT_IMAGE_READABLE:              info->i = 1;                                               break;
1099   case DEVINFO_INT_IMAGE_WRITEABLE:         info->i = 1;                                               break;
1100   case DEVINFO_INT_IMAGE_CREATABLE:         info->i = 1;                                               break;
1101   case DEVINFO_FCT_START:                    info->start = DEVICE_START_NAME( hp48_port );              break;
1102   case DEVINFO_FCT_IMAGE_LOAD:            info->f = (genf *) DEVICE_IMAGE_LOAD_NAME( hp48_port );    break;
1103   case DEVINFO_FCT_IMAGE_UNLOAD:            info->f = (genf *) DEVICE_IMAGE_UNLOAD_NAME( hp48_port );  break;
1104   case DEVINFO_FCT_IMAGE_CREATE:            info->f = (genf *) DEVICE_IMAGE_CREATE_NAME( hp48_port );  break;
1105   case DEVINFO_STR_IMAGE_BRIEF_INSTANCE_NAME:   strcpy(info->s, conf ? conf->brief_name : "");                    break;
1106   case DEVINFO_STR_IMAGE_INSTANCE_NAME:         strcpy(info->s, conf ? conf->name : "");                          break;
1107   case DEVINFO_STR_NAME:                   strcpy( info->s, "HP48 memory card");                            break;
1108   case DEVINFO_STR_FAMILY:                      strcpy(info->s, "HP48 memory card");                            break;
1109   case DEVINFO_STR_SOURCE_FILE:            strcpy(info->s, __FILE__);                                        break;
1110   case DEVINFO_STR_IMAGE_FILE_EXTENSIONS:         strcpy(info->s, "crd");                                           break;
1111   }
11121082}
11131083
1084void hp48_port_image_device::device_config_complete()
1085{   
1086   update_names(HP48_PORT, "port", "p");
1087}
11141088
1115
1116
11171089/***************************************************************************
11181090    MACHINES
11191091***************************************************************************/
r14704r14705
12651237{
12661238   hp48_machine_start( machine, HP48_GP );
12671239}
1268
1269DEFINE_LEGACY_IMAGE_DEVICE(HP48_PORT, hp48_port);
src/mess/includes/hp48.h
r14704r14705
123123
124124/****************************** cards ********************************/
125125
126struct hp48_port_config;
126/* port specification */
127struct hp48_port_interface
128{
129   int port;                 /* port index: 0 or 1 (for port 1 and 2) */
130   int module;               /* memory module where the port is visible */
131   int max_size;             /* maximum size, in bytes 128 KB or 4 GB */
132};
127133
128extern const struct hp48_port_config hp48sx_port1_config;
129extern const struct hp48_port_config hp48sx_port2_config;
130extern const struct hp48_port_config hp48gx_port1_config;
131extern const struct hp48_port_config hp48gx_port2_config;
134class hp48_port_image_device :   public device_t,
135                        public device_image_interface,
136                        public hp48_port_interface
137{
138public:
139   // construction/destruction
140   hp48_port_image_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
132141
133DECLARE_LEGACY_IMAGE_DEVICE(HP48_PORT, hp48_port);
142   // image-level overrides
143   virtual iodevice_t image_type() const { return IO_MEMCARD; }
134144
145   virtual bool is_readable()  const { return 1; }
146   virtual bool is_writeable() const { return 1; }
147   virtual bool is_creatable() const { return 1; }
148   virtual bool must_be_loaded() const { return 0; }
149   virtual bool is_reset_on_load() const { return 0; }
150   virtual const char *image_interface() const { return NULL; }
151   virtual const char *file_extensions() const { return "crd"; }
152   virtual const option_guide *create_option_guide() const { return NULL; }
153   
154   virtual bool call_load();
155   virtual void call_unload();
156   virtual bool call_create(int format_type, option_resolution *format_options);   
157protected:
158   // device-level overrides
159    virtual void device_config_complete();
160   virtual void device_start();
161private:
162   void hp48_fill_port();
163   void hp48_unfill_port();
164};
165
166extern const struct hp48_port_interface hp48sx_port1_config;
167extern const struct hp48_port_interface hp48sx_port2_config;
168extern const struct hp48_port_interface hp48gx_port1_config;
169extern const struct hp48_port_interface hp48gx_port2_config;
170
171// device type definition
172extern const device_type HP48_PORT;
173
135174#define MCFG_HP48_PORT_ADD(_tag, _intrf) \
136175   MCFG_DEVICE_ADD(_tag, HP48_PORT, 0) \
137176   MCFG_DEVICE_CONFIG(_intrf)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team