Previous 15994 Revisions Next

r2839 Tuesday 10th June, 2008 at 22:40:33 UTC by Hobie Troxell
[HP48] Updated the four main HP48 calculator models (S, SX, G, GX). Now able
to run some software and function. See drivers/hp48.c for a TODO list. (Antoine Mine)
[src/mess]mess.mak messdriv.c
[src/mess/devices]kermit.c* kermit.h* xmodem.c* xmodem.h*
[src/mess/drivers]hp48.c
[src/mess/includes]hp48.h
[src/mess/machine]hp48.c
[src/mess/video]hp48.c

src/mess/devices/xmodem.c
r0r2839
1/* XMODEM protocol implementation.
2
3   Transfer between an emulated machine and an image using the XMODEM protocol.
4
5   Used in the HP48 G/GX emulation.
6
7   Based on the "Xmodem protol specification" by Ward Christensen.
8
9   Does not support any extension (such as 16-bit CRC, 1K packet size,
10   batchs, YMODEM, ZMODEM).
11
12   Author: Antoine Mine'
13   Date: 29/03/2008
14 */
15
16#include "driver.h"
17#include "xmodem.h"
18
19
20/* debugging */
21#define VERBOSE          0
22
23#define LOG(x)  do { if (VERBOSE) logerror x; } while (0)
24
25
26/* XMODEM protocol bytes */
27#define XMODEM_SOH 0x01  /* data packet header */
28#define XMODEM_EOT 0x04  /* end of transmission */
29#define XMODEM_ACK 0x06  /* acknowledge (packet received) */
30#define XMODEM_NAK 0x15  /* not-acknowledge (10-second timeout) */
31#define XMODEM_CAN 0x18  /* cancel */
32
33/* XMODEM protocol is:
34
35   sender        receiver
36
37            <--   <NAK>
38   packet   -->
39            <--   <ACK>
40            ...
41   packet   -->
42            <--   <ACK>
43   <EOT>    -->
44            <--   <ACK>
45
46   and packet is:  <SOH> <id> <0xff-id> <data0> ... <data127> <checksum>
47   
48   <id> is 1 for the first packet, 2 for the 2d, etc...
49   <checksum> is the sum of <data0> to <data127> modulo 256
50
51   there are always 128 bytes of data in a packet, so, any file transfered is
52   rounded to a multiple of 128 bytes, using 0-filler
53*/
54
55
56/* our state */
57#define XMODEM_NOIMAGE    0
58#define XMODEM_IDLE       1
59#define XMODEM_SENDING    2 /* image to emulated machine */
60#define XMODEM_RECEIVING  3 /* emulated machine to image */
61
62typedef struct {
63
64   UINT8   block[132];          /* 3-byte header + 128-byte block + checksum */
65   UINT32  id;                  /* block id, starting at 1 */
66   UINT16  pos;                 /* position in block, including header */
67   UINT8   state;               /* one of XMODEM_ */
68   
69   const device_config* image;  /* underlying image */
70
71   emu_timer* timer;            /* used to send periodic NAKs */
72
73   running_machine *machine;
74
75   xmodem_config* conf;
76
77} xmodem;
78
79
80
81/* compute checksum of the data part of the packet, i.e., sum modulo 256 */
82static UINT8 xmodem_chksum( xmodem* state )
83{
84   UINT8 sum = 0;
85   int i;
86   for ( i = 0; i < 128; i++ ) sum += state->block[ i + 3 ];
87   return sum;
88}
89
90/* fills state->block with the data for packet number state->id
91   returns != 0 if fail or end of file
92*/
93static int xmodem_make_send_block( xmodem* state )
94{
95   if ( ! state->image ) return -1;
96   memset( state->block + 3, 0, 128 );
97   if ( image_fseek( state->image, (state->id - 1) * 128, SEEK_SET ) ) return -1;
98   if ( image_fread( state->image, state->block + 3, 128 ) <= 0 ) return -1;
99   state->block[0] = XMODEM_SOH;
100   state->block[1] = state->id & 0xff;
101   state->block[2] = 0xff - state->block[1];
102   state->block[131] = xmodem_chksum( state );
103   return 0;
104}
105
106/* checks the received state->block packet and stores the data in the image
107   returns != 0 if fail (bad packet or bad image)
108 */
109static int xmodem_get_receive_block( xmodem* state )
110{
111   int next_id = state->id + 1;
112   if ( ! state->image ) return -1;
113   if ( ! image_is_writable( state->image ) ) return -1;
114   if ( state->block[0] != XMODEM_SOH ) return -1;
115   if ( state->block[1] != 0xff - state->block[2] ) return -1;
116   if ( state->block[131] != xmodem_chksum( state ) ) return -1;
117   if ( state->block[1] != (next_id & 0xff) ) return -1;
118   if ( image_fseek( state->image, (next_id - 1) * 128, SEEK_SET ) ) return -1;
119   if ( image_fwrite( state->image, state->block + 3, 128 ) != 128 ) return -1;
120   return 0;
121}
122
123/* the outside (us) sends a byte to the emulated machine */
124static void xmodem_send_byte( xmodem* state, UINT8 data )
125{
126   if ( state->conf && state->conf->send )
127   {
128      state->conf->send( state->machine, data );
129   }
130}
131
132static void xmodem_send_packet_byte( xmodem* state )
133{
134   assert( state->pos < 132 );
135   xmodem_send_byte( state, state->block[ state->pos ] );
136   state->pos++;
137}
138
139
140static TIMER_CALLBACK( xmodem_nak_cb )
141{
142   xmodem* state = (xmodem*) ptr;
143   if ( state->state != XMODEM_IDLE ) return;
144   LOG(( "xmodem: sending NAK keep-alive\n" ));
145   xmodem_send_byte( state, XMODEM_NAK );
146}
147
148static void xmodem_make_idle( xmodem* state )
149{
150   LOG(( "xmodem: entering idle state\n" ));
151   state->state = XMODEM_IDLE;
152   state->id = 0;
153   state->pos = 0;
154        /* When idle, we send NAK periodically to tell the emulated machine that we are
155      always ready to receive.
156      The 2 sec start time is here so that the machine does not get NAK instead of
157      ACK or EOT as the last byte of a transfer.
158    */
159   timer_adjust_periodic( state->timer, ATTOTIME_IN_SEC( 2 ), 0, ATTOTIME_IN_SEC( 2 ) );
160}
161
162/* emulated machine has read the last byte we sent */
163void xmodem_byte_transmitted( const device_config *device )
164{
165   xmodem* state = (xmodem*) device->token;
166   if ( (state->state == XMODEM_SENDING) && (state->pos < 132) )
167   {
168      /* send next byte */
169      xmodem_send_packet_byte( state );
170   }
171}
172
173/* emulated machine sends a byte to the outside (us) */
174void xmodem_receive_byte( const device_config *device, UINT8 data )
175{
176   xmodem* state = (xmodem*) device->token;
177   switch ( state->state )
178   {
179
180   case XMODEM_NOIMAGE:
181      break;
182
183   case XMODEM_IDLE:
184      if ( data == XMODEM_NAK )
185      {
186         /* start sending */
187         LOG(( "xmodem: got NAK, start sending\n" ));
188         state->id = 1;
189         if ( xmodem_make_send_block( state ) )
190         {
191            /* error */
192            LOG(( "xmodem: nothing to send, sending NAK\n" ));
193            xmodem_send_byte( state, XMODEM_NAK );
194            xmodem_make_idle( state );
195         }
196         else
197         {
198            /* send first packet */
199            state->state = XMODEM_SENDING;
200            state->pos = 0;
201            xmodem_send_packet_byte( state );
202         }
203         break;
204      }
205      else if ( data == XMODEM_SOH )
206      {
207         /* start receiving */
208         LOG(( "xmodem: got SOH, start receiving\n" ));
209         state->state = XMODEM_RECEIVING;
210         state->block[ 0 ] = data;
211         state->pos = 1;
212         state->id = 0;
213      }
214      else
215      {
216         LOG(( "xmodem: ignored data %02x while idle\n", data ));
217      }
218      break;
219
220   case XMODEM_SENDING:
221      if ( (data != XMODEM_NAK) && (data != XMODEM_ACK) )
222      {
223         /* error */
224         LOG(( "xmodem: invalid date %02x while sending, sending CAN\n", data ));
225         xmodem_send_byte( state, XMODEM_CAN );
226         xmodem_make_idle( state );
227         break;
228      }
229      if ( data == XMODEM_ACK )
230      {
231         /* send next packet */
232         state->id++;
233         LOG(( "xmodem: got ACK, sending next packet (%i)\n", state->id ));
234         if ( xmodem_make_send_block( state ) )
235         {
236            /* end of file */
237            LOG(( "xmodem: no more packet, sending EOT\n" ));
238            xmodem_send_byte( state, XMODEM_EOT );
239            xmodem_make_idle( state );
240            break;
241         }
242
243      }
244      else
245      {
246         /* empty - resend last packet */
247         LOG(( "xmodem: got NAK, resending packet %i\n", state->id ));
248      }
249      state->pos = 0;
250      xmodem_send_packet_byte( state );
251      break;
252
253
254   case XMODEM_RECEIVING:
255      assert( state->pos < 132 );
256      state->block[ state->pos ] = data;
257      state->pos++;
258      if ( state->pos == 1 )
259      {
260         /* header byte */
261         if ( data == XMODEM_EOT )
262         {
263            /* end of file */
264            LOG(( "xmodem: got EOT, stop receiving\n" ));
265            xmodem_send_byte( state, XMODEM_ACK );
266            xmodem_make_idle( state );
267            break;
268         }
269      }
270      else if ( state->pos == 132 )
271      {
272         LOG(( "xmodem: received packet %i\n", state->id ));
273         /* end of block */
274         if ( xmodem_get_receive_block( state ) )
275         {
276            /* error */
277            LOG(( "xmodem: packet is invalid, sending NAK\n" ));
278            xmodem_send_byte( state, XMODEM_NAK );
279         }
280         else
281         {
282            /* ok */
283            LOG(( "xmodem: packet is valid, sending ACK\n" ));
284            xmodem_send_byte( state, XMODEM_ACK );
285            state->id++;
286         }
287         state->pos = 0;
288      }
289      break;
290
291   }
292}
293
294static DEVICE_START( xmodem )
295{
296   xmodem* state = (xmodem*) device->token;
297   LOG(( "xmodem: start\n" ));
298   state->state = XMODEM_NOIMAGE;
299   state->image = NULL;
300   state->conf = (xmodem_config*) device->static_config;
301   state->machine = device->machine;
302   state->timer = timer_alloc( xmodem_nak_cb, state );
303}
304
305static DEVICE_RESET( xmodem )
306{
307   xmodem* state = (xmodem*) device->token;
308   LOG(( "xmodem: reset\n" ));
309   if ( state->state != XMODEM_NOIMAGE ) xmodem_make_idle( state );
310}
311
312static DEVICE_IMAGE_LOAD( xmodem )
313{
314   xmodem* state = (xmodem*) image->token;
315   LOG(( "xmodem: image load\n" ));
316   state->image = image;
317   xmodem_make_idle( state );
318   return INIT_PASS;
319}
320
321static DEVICE_IMAGE_CREATE( xmodem )
322{
323   xmodem* state = (xmodem*) image->token;
324   LOG(( "xmodem: image create\n" ));
325   state->image = image;
326   xmodem_make_idle( state );
327   return INIT_PASS;
328}
329
330static DEVICE_IMAGE_UNLOAD( xmodem )
331{
332   xmodem* state = (xmodem*) image->token;
333   LOG(( "xmodem: image unload\n" ));
334   state->state = XMODEM_NOIMAGE;
335   state->image = NULL;
336}
337
338DEVICE_GET_INFO( xmodem )
339
340{
341   switch ( state ) {
342   case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof( xmodem );                              break;
343   case DEVINFO_INT_INLINE_CONFIG_BYTES:       info->i = 0;                                             break;
344   case DEVINFO_INT_CLASS:                       info->i = DEVICE_CLASS_PERIPHERAL;                       break;
345   case DEVINFO_INT_IMAGE_TYPE:               info->i = IO_SERIAL;                                     break;
346   case DEVINFO_INT_IMAGE_READABLE:            info->i = 1;                                             break;
347   case DEVINFO_INT_IMAGE_WRITEABLE:       info->i = 1;                                             break;
348   case DEVINFO_INT_IMAGE_CREATABLE:       info->i = 1;                                             break;
349   case DEVINFO_FCT_START:                       info->start = DEVICE_START_NAME( xmodem );               break;
350   case DEVINFO_FCT_RESET:                       info->reset = DEVICE_RESET_NAME( xmodem );               break;
351   case DEVINFO_FCT_IMAGE_LOAD:          info->f = (genf *) DEVICE_IMAGE_LOAD_NAME( xmodem );     break;
352   case DEVINFO_FCT_IMAGE_UNLOAD:          info->f = (genf *) DEVICE_IMAGE_UNLOAD_NAME( xmodem );   break;
353   case DEVINFO_FCT_IMAGE_CREATE:          info->f = (genf *) DEVICE_IMAGE_CREATE_NAME( xmodem );   break;
354   case DEVINFO_STR_IMAGE_BRIEF_INSTANCE_NAME: info->s = "x";                                        break;
355   case DEVINFO_STR_IMAGE_INSTANCE_NAME:
356   case DEVINFO_STR_NAME:                  info->s = "xmodem";                                        break;
357   case DEVINFO_STR_FAMILY:                    info->s = "serial protocol";                        break;
358   case DEVINFO_STR_SOURCE_FILE:          info->s = __FILE__;                                      break;
359   case DEVINFO_STR_IMAGE_FILE_EXTENSIONS:       info->s = "";                                            break;
360   }
361}
362
src/mess/devices/kermit.c
r0r2839
1/* Kermit protocol implementation.
2
3   Transfer between an emulated machine and an image using the kermit protocol.
4
5   Used in the HP48 S/SX/G/GX emulation.
6
7   Based on the 'KERMIT PROTOCOL MANUAL', Sixth Edition, by Frank da Cruz,
8   Columbia University Center for Computing Activities, New York, June 1986.
9   Available at: http://www-vs.informatik.uni-ulm.de/teach/ws05/rn1/Kermit%20Protocol.pdf
10
11   Used in the HP48 S/SX/G/GX emulation.
12   For HP48 specific kermit notes, see http://www.columbia.edu/kermit/hp48.html
13
14   Only the basic protocol is implemented.
15   The following features are NOT supported:
16   - 8-bit quoting (QBIN)
17   - 2- or 3-byte checksums (only 1-byte supported)
18   - repeat count
19   - file attribute packets
20   - sliding window
21   - extended length packets
22   - server mode
23
24   Author: Antoine Mine'
25   Date: 29/03/2008
26 */
27
28
29#include "driver.h"
30#include "kermit.h"
31
32
33/* debugging */
34#define VERBOSE          0
35
36#define LOG(x)  do { if (VERBOSE) logerror x; } while (0)
37
38/* protocol bytes */
39#define KERMIT_SOH 0x01 /* (default) start of header */
40
41/* packet types */
42#define KERMIT_DATA 'D'  /* data packet */
43#define KERMIT_ACK  'Y'  /* acknowledge */
44#define KERMIT_NAK  'N'  /* negative acknowledge */
45#define KERMIT_SEND 'S'  /* send initiate (exchange parameters) */
46#define KERMIT_EOT  'B'  /* break transmission */
47#define KERMIT_FILE 'F'  /* file header */
48#define KERMIT_EOF  'Z'  /* end of file */
49#define KERMIT_ERR  'E'  /* error */
50
51#define KERMIT_QCTL  '#' /* default escape character */
52#define KERMIT_EOL   15  /* default terminator: carriage-return  */
53#define KERMIT_MAXL  80  /* default maximum packet length */
54
55/* protocol state, to drive action */
56#define KERMIT_IDLE       0  /* nothing to do */
57#define KERMIT_RESET      1  /* reset after sending the last packet */
58#define KERMIT_RECEIVE    2  /* receiving */
59#define KERMIT_SEND_DATA  3  /* sending data */
60#define KERMIT_SEND_EOF   4  /* sending EOF */
61#define KERMIT_SEND_EOT   5  /* sendinf EOT */
62
63/* packet retry parameters */
64#define KERMIT_MAX_RETRIES  5
65#define KERMIT_RETRY_DELAY  ATTOTIME_IN_SEC( 10 )
66
67/* packet format is:
68
69   <mark> <len> <seq> <type> <data0> ... <datan> <check>
70
71   - <mark>  KERMIT_SOH
72   - <len>   number of bytes after <len> (max=94), plus 32
73   - <seq>   sequence number, modulo 63, plus 32
74   - <type>  one of KERMIT_ packet types
75   - <data>  payload, with control characters escaped with KERMIT_QCTL
76   - <check> checksum, from <len> to <datan>, excluding <mark>
77
78   the packet may be followed by arbitrary (non KERMIT_SOH) data, not counted
79   in <len>, <check>, and not interpreted
80   there is generally at least one KERMIT_EOL
81*/
82
83typedef struct {
84
85   UINT8   pin[1024];     /* packet received */
86   UINT8   pout[1024];    /* packet sent */
87   UINT32  seq;           /* sequence number, starting at 0 */
88   UINT16  posin;         /* position in pin */
89   UINT16  posout;        /* position in pout */
90   UINT16  nbout;         /* size of pout */
91   
92   UINT8   state;         /* current protocol state */
93   UINT8   retries;       /* packet retries remaining */
94
95   /* (relevant) configuration information, sent in S and D packet */
96   UINT8   maxl; /* max packet length (value of <len>) */
97   UINT8   npad; /* number of padding characters before packet */
98   UINT8   padc; /* padding character */
99   UINT8   eol;  /* character to add after packet */
100   UINT8   qctl; /* escape character */
101
102   emu_timer* resend;           /* auto-resend packet */
103
104   const device_config* image;  /* underlying image */
105
106   running_machine *machine;
107   kermit_config* conf;
108
109} kermit;
110
111
112static int kermit_is_char( UINT8 data )
113{
114   return data >= 32 && data <= 126;
115}
116
117
118static  UINT8 kermit_tochar( UINT8 data )
119{
120   if ( data > 94 )
121   {
122      logerror( "kermit: tochar: %i not in the range 0-94\n", data );
123   }
124   return data + 32;
125}
126
127static UINT8 kermit_unchar( UINT8 data )
128{
129   if ( data < 32 || data > 126 )
130   {
131      logerror( "kermit: unchar: %i not in the range 32-126\n", data );
132   }
133   return data - 32;
134}
135
136#define kermit_ctl(x) ((x) ^ 0x40)
137
138static int kermit_is_ctl( UINT8 x )
139{
140   x &= 0x7f;
141   return (x < 32) || (x == 127);
142}
143
144static UINT8 kermit_checksum( UINT8* packet )
145{
146   int i, len = kermit_unchar( packet[1] );
147   UINT8 sum = 0;
148   for ( i = 0; i < len; i++ )
149      sum += packet[ i + 1 ];
150   sum = kermit_tochar( (sum + (sum >> 6)) & 63 );
151   return sum;
152}
153
154/* starts sending a new packet */
155static void kermit_start_sending( kermit* state )
156{
157   int i;
158   
159   for (i=1;i<state->nbout;i++)
160      if (kermit_is_ctl(state->pout[i]))
161         logerror( "send: not char %i at pos %i\n", state->pout[i], i  );
162
163   if ( state->nbout <= 0 ) return;
164
165   /* prepend padding and append eol */
166   if ( state->npad > 0 )
167   {
168      memmove( state->pout + state->npad, state->pout, state->nbout );
169      memset( state->pout, state->padc, state->npad );
170      state->nbout += state->npad;
171   }
172   state->pout[ state->nbout ] = state->eol;
173   state->nbout++;
174
175   if ( state->conf && state->conf->send )
176   {
177      state->conf->send( state->machine, state->pout[ 0 ] );
178   }
179   state->posout = 1;
180
181   state->retries = KERMIT_MAX_RETRIES;
182   timer_adjust_periodic( state->resend, KERMIT_RETRY_DELAY, 0, KERMIT_RETRY_DELAY );
183}
184
185static void kermit_reset( kermit* state );
186
187static void kermit_resend( kermit* state )
188{
189   if ( state->nbout == 0 ) return;
190   if ( state->retries <= 0 )
191   {
192      kermit_reset( state );
193      return;
194   }
195   
196   if ( state->conf && state->conf->send )
197   {
198      state->conf->send( state->machine, state->pout[ 0 ] );
199   }
200   state->posout = 1;
201   state->retries--;
202   LOG(( "kermit: resend packet (%i tries left)\n", state->retries ));
203}
204
205/* resend packet periodically */
206static TIMER_CALLBACK( kermit_resend_cb )
207{
208   kermit* state = (kermit*) ptr;
209   if ( state->posout >= state->nbout)
210   {
211      kermit_resend( state );
212   }
213}
214
215/* fetches image data and wrap it into a kermit data packet */
216static void kermit_send_data_packet( kermit* state )
217{
218   int len;
219   LOG(( "kermit: send data packet\n" ));
220   for ( len = 2; len < state->maxl-2; len++ )
221   {
222      UINT8 c;
223      if ( image_feof( state->image ) ) break;
224      c = image_fgetc( state->image );
225      if ( kermit_is_ctl( c ) )
226      {
227         /* escape control char */
228         state->pout[ 2 + len ] = state->qctl;
229         len++;
230         state->pout[ 2 + len ] = kermit_ctl( c );
231      }
232      else if ( (c & 0x7f) == state->qctl )
233      {
234         /* escape escape char */
235         state->pout[ 2 + len ] = state->qctl;
236         len++;
237         state->pout[ 2 + len ] = c;
238      }
239      else
240      {
241         state->pout[ 2 + len ] = c;
242      }
243   }
244   state->pout[ 0 ] = KERMIT_SOH;
245   state->pout[ 1 ] = kermit_tochar( len + 1 );
246   state->pout[ 2 ] = kermit_tochar( state->seq & 63 );
247   state->pout[ 3 ] = KERMIT_DATA;
248   state->pout[ 2 + len ] = kermit_checksum( state->pout );
249   state->nbout = len + 3;
250   kermit_start_sending( state );
251}
252
253/* write data from packet to the image */
254static void kermit_write_data_packet( kermit* state )
255{
256   int i, len = kermit_unchar( state->pin[1] );
257   LOG(( "kermit: received data pack, len=%i\n", len ));
258   for ( i = 4; i <= len; i++ )
259   {
260      UINT8 c = state->pin[i];
261      if ( (c /*& 0x7f*/) == state->qctl )
262      {
263         /* unescape */
264         i++;
265         c = state->pin[i];
266         if ( kermit_is_ctl( kermit_ctl( c ) ) )
267         {
268            c = kermit_ctl( c );
269         }
270      }
271      image_fwrite( state->image, &c, 1 );
272   }
273}
274
275/* validate received packet and acquire seq number, <0 if error */
276static int kermit_validate_packet( kermit* state )
277{
278   int len;
279   if ( state->pin[ 0 ] != KERMIT_SOH ) return -1;
280   if ( !kermit_is_char( state->pin[1] ) ) return -1;
281   if ( !kermit_is_char( state->pin[2] ) ) return -1;
282   len = kermit_unchar( state->pin[1] );
283   if ( state->pin[ 1 + len ] != kermit_checksum( state->pin ) ) return -1;
284   return 0;
285}
286
287/* interpret configuration packet, <0 if error */
288static int kermit_get_conf( kermit* state )
289{
290   int len = kermit_unchar( state->pin[1] );
291   if ( len >= 4 ) state->maxl = kermit_unchar( state->pin[ 4 ] );
292   if ( len >= 6 ) state->npad = kermit_unchar( state->pin[ 6 ] );
293   if ( len >= 7 ) state->padc = kermit_ctl( state->pin[ 7 ] );
294   if ( len >= 8 ) state->eol  = kermit_unchar( state->pin[ 8 ] );
295   if ( len >= 9 ) state->qctl = state->pin[ 9 ];
296   
297   LOG(( "kermit: get conf: len=%i, maxl=%i, npad=%i, padc=%i, eol=%i, qctl=%i\n",
298         len, state->maxl, state->npad, state->padc, state->eol, state->qctl ));
299
300   /* validation */
301   if ( state->maxl < 10 || state->maxl > 94 ) return -1;
302   return 0;
303}
304
305/* create a configuration packet, with header h */
306static void kermit_send_conf_packet( kermit* state, UINT8 h )
307{
308   LOG(( "kermit: send conf packet of type %c\n", h ));
309   state->seq = 0;
310   state->pout[  0 ] = KERMIT_SOH;
311   state->pout[  1 ] = kermit_tochar( 13 );
312   state->pout[  2 ] = kermit_tochar( state->seq & 63 );
313   state->pout[  3 ] = h;
314   state->pout[  4 ] = kermit_tochar( state->maxl );   /* maxl */
315   state->pout[  5 ] = kermit_tochar( 1 );             /* time: 1 sec */
316   state->pout[  6 ] = kermit_tochar( state->npad );   /* npad */
317   state->pout[  7 ] = kermit_ctl( state->padc );      /* padc */
318   state->pout[  8 ] = kermit_tochar( state->eol );    /* eol */
319   state->pout[  9 ] = state->qctl;                    /* qtcl */
320   state->pout[ 10 ] = 'N';                            /* qbin: no 8-bit quoting */
321   state->pout[ 11 ] = '1';                            /* chkt: single character checksum */
322   state->pout[ 12 ] = ' ';                            /* rept: no repeat count */
323   state->pout[ 13 ] = kermit_tochar( 0 );             /* capas: no capabilities */
324   state->pout[ 14 ] = kermit_checksum( state->pout );
325   state->nbout = 15;
326   kermit_start_sending( state );
327}
328
329/* sends a packet with no data */
330static void kermit_send_simple_packet( kermit* state, UINT8 h  )
331{
332   LOG(( "kermit: send empty packet of type %c, seq=%i\n", h, state->seq & 63 ));
333   state->pout[ 0 ] = KERMIT_SOH;
334   state->pout[ 1 ] = kermit_tochar( 3 );
335   state->pout[ 2 ] = kermit_tochar( state->seq & 63 );
336   state->pout[ 3 ] = h;
337   state->pout[ 4 ] = kermit_checksum( state->pout );
338   state->nbout = 5;
339   kermit_start_sending( state );
340}
341
342/* sends a packet with string data */
343static void kermit_send_string_packet( kermit* state, UINT8 h, const char* data )
344{
345   int i, len;
346   LOG(( "kermit: send string packet of type %c, data=%s, seq=%i\n", h, data, state->seq & 63 ));
347   for ( len = i = 0; (len < state->maxl - 5) && data[i]; i++  )
348   {
349      char c = data[i];
350      if ( kermit_is_char( c ) && ( c != '_' ) && ( c != ' ' ) )
351      {
352        state->pout[ 4 + len ] = c;
353        len++;
354      }
355   }
356   state->pout[ 0 ] = KERMIT_SOH;
357   state->pout[ 1 ] = kermit_tochar( len + 3 );
358   state->pout[ 2 ] = kermit_tochar( state->seq & 63 );
359   state->pout[ 3 ] = h;
360   state->pout[ 4 + len ] = kermit_checksum( state->pout );
361   state->nbout = len + 5;
362   kermit_start_sending( state );
363}
364
365/* extract the string contained in received packet */
366static char* kermit_string_in_packet( kermit* state )
367{
368   int len = kermit_unchar( state->pin[1] );
369   state->pin[ len + 1 ] = 0;
370   return (char*) state->pin + 4;
371}
372
373static void kermit_reset( kermit* state )
374{
375   /* default config */
376   state->maxl = KERMIT_MAXL;
377   state->npad = 0;
378   state->padc = 0;
379   state->eol  = KERMIT_EOL;
380   state->qctl = KERMIT_QCTL;
381
382   state->retries = KERMIT_MAX_RETRIES;
383   state->posin   = 0;
384   state->posout  = 0;
385   state->nbout   = 0;
386   state->state   = KERMIT_IDLE;
387   state->seq     = 0;
388
389   if ( state->image )
390   {
391      image_fseek( state->image, SEEK_SET, 0 );
392   }
393
394   timer_adjust_periodic( state->resend, attotime_never, 0, attotime_never );
395}
396
397/* emulated machine sends a byte to the outside (us) */
398void kermit_receive_byte( const device_config *device, UINT8 data )
399{
400   kermit* state = (kermit*) device->token;
401   
402   LOG(( "get %i %2x %c (%i)\n", data, data, data, state->posin ));
403 
404   /* get SOH */
405   if ( (data == KERMIT_SOH) && (state->posin <= 1) )
406   {
407      state->pin[ 0 ] = data;
408      state->posin = 1;   
409   }
410
411   /* get packet contents */
412   else if ( state->posin > 0 )
413   {
414      if ( state->posin >= sizeof( state->pout ) )
415      {
416         LOG(( "kermit: too many bytes received\n" ));
417         state->posin = 0;
418         kermit_send_simple_packet( state, KERMIT_NAK );
419         return;
420      }
421
422      if (kermit_is_ctl(data))
423         logerror( "received: not char %i at pos %i\n", data, state->posin  );
424
425      state->pin[ state->posin ] = data;
426      state->posin++;
427
428      if ( state->posin > 5 )
429      {
430         int len, seq, typ;
431         if ( !kermit_is_char( state->pin[1] ) ||
432              (kermit_unchar( state->pin[1] ) < 3) ||
433              (kermit_unchar( state->pin[1] ) > state->maxl) )
434         {
435            LOG(( "kermit: invalid packet size %i-32, not in 3-%i\n", state->pin[1], state->maxl ));
436            kermit_resend( state );
437            return;
438         }
439
440         len = kermit_unchar( state->pin[1] );
441
442         if ( state->posin >= len + 2 )
443         {
444            /* got packet! */
445            state->posin = 0;
446            if ( kermit_validate_packet( state ) )
447            {
448               LOG(( "kermit: invalid packet\n" ));
449               kermit_resend( state );
450               return;
451            }
452
453            typ = state->pin[3];
454            seq = kermit_unchar( state->pin[2] );
455
456            LOG(( "kermit: received packet type=%c, seq=%i, len=%i\n",  typ, seq, len ));
457
458            if ( !state->image )
459            {
460               kermit_send_string_packet( state, KERMIT_ERR, "NO IMAGE" );
461               return;
462            }
463
464
465            switch ( typ )
466            {
467
468            /* receiving */
469
470            case KERMIT_SEND:
471               kermit_get_conf( state );
472               if ( state->maxl >= KERMIT_MAXL )
473               {
474                  state->maxl = KERMIT_MAXL;
475               }
476               kermit_send_conf_packet( state, KERMIT_ACK );
477               state->state = KERMIT_RECEIVE;
478               break;
479
480            case KERMIT_FILE:
481               LOG(( "kermit: got file name '%s'\n", kermit_string_in_packet( state ) ));
482               state->seq = seq;
483               kermit_send_simple_packet( state, KERMIT_ACK );
484               break;
485
486            case KERMIT_DATA:
487            case KERMIT_EOF:
488               if ( seq == ((state->seq + 1) & 63) )
489               {
490                  /* next packet */
491                  if ( typ == KERMIT_DATA )
492                  {
493                     kermit_write_data_packet( state );
494                  }
495                  state->seq = seq;
496                  kermit_send_simple_packet( state, KERMIT_ACK );
497               }
498               else if ( seq == (state->seq & 63) )
499               {
500                  /* same packet */
501                  kermit_send_simple_packet( state, KERMIT_ACK );
502               }
503               else
504               {
505                  /* unexpected sequence number */
506                  LOG(( "kermit: got seq=%i, expected %i\n", seq, (state->seq + 1) & 63 ));
507                  state->seq++;
508                  kermit_send_simple_packet( state, KERMIT_NAK );
509                  state->seq--;
510               }
511               break;
512
513            case KERMIT_EOT:
514               /* send ack and reset */
515               state->seq = seq;
516               kermit_send_simple_packet( state, KERMIT_ACK );
517               state->state = KERMIT_RESET;
518               break;
519
520
521                                /* sending */
522
523            case KERMIT_NAK:
524            case KERMIT_ACK:
525
526               if ( (typ == KERMIT_NAK) && (seq == 0) && (state->state == KERMIT_IDLE) )
527               {
528                  /* transfer start */
529                  kermit_send_conf_packet( state, KERMIT_SEND );
530                  break;
531               }
532
533               if ( ((seq == (state->seq & 63)) && (typ == KERMIT_ACK)) ||
534                    ((seq == ((state->seq + 1) & 63)) && (typ == KERMIT_NAK)) )
535               {
536                  /* send next packet */
537
538                  state->seq = state->seq + 1;
539                 
540                  switch ( state->state )
541                  {
542                  case KERMIT_IDLE:
543                     /* get conf & send file name */
544                     kermit_get_conf( state );
545                     kermit_send_string_packet( state, KERMIT_FILE, image_basename( state->image ) );
546                     state->state = KERMIT_SEND_DATA;;
547                     break;
548                     
549                  case KERMIT_SEND_DATA:
550                     /* send next data packet or EOF */
551                     if ( image_feof( state->image ) )
552                     {
553                        kermit_send_simple_packet( state, KERMIT_EOF );
554                        state->state = KERMIT_SEND_EOF;
555                     }
556                     else
557                     {
558                        kermit_send_data_packet( state );   
559                     }
560                     break;
561                     
562                  case KERMIT_SEND_EOF:
563                           /* send EOT */
564                     kermit_send_simple_packet( state, KERMIT_EOT );
565                     state->state = KERMIT_SEND_EOT;
566                     break;
567                     
568                  case KERMIT_SEND_EOT:
569                     /* reset */
570                     kermit_reset( state );
571                     state->state = KERMIT_RESET;
572                     break;
573                     
574                  }
575               }
576
577               else if ( (seq == (state->seq & 63)) && (typ == KERMIT_NAK) )
578               {
579                  /* resend last packet */
580                  kermit_resend( state );
581               }
582               else
583               {
584                  /* bad */
585                  LOG(( "kermit: expected to send %i, got seq=%i\n", (state->seq + 1) & 63, seq ));
586                  kermit_reset( state );
587               }
588               break;
589               
590                                /* errors */
591
592            case KERMIT_ERR:
593               LOG(( "kermit: got error '%s'\n", kermit_string_in_packet( state ) ));
594               state->seq = seq;
595               kermit_reset( state );
596               break;
597
598            default:
599               LOG(( "kermit: ignoring packet type %c\n", state->pin[ 3 ] ));
600               /* no abort, just ignoring */
601            }
602         }
603      }
604   }
605}
606
607void kermit_byte_transmitted( const device_config *device )
608{
609   kermit* state = (kermit*) device->token;
610
611   LOG(( "transmitted %i %2x %c, %i / %i\n", state->pout[ state->posout-1 ], state->pout[ state->posout-1 ], state->pout[ state->posout-1 ], state->posout - 1, state->nbout - 1 ));
612
613   /* at end of packet */
614   if ( state->posout >= state->nbout )
615   {
616      if ( state->state == KERMIT_RESET )
617      {
618         kermit_reset( state );
619      }
620      return;
621   }
622
623   if ( state->conf && state->conf->send )
624   {
625      state->conf->send( state->machine, state->pout[ state->posout ] );
626   }
627   state->posout++;
628}
629
630static DEVICE_START( kermit )
631{
632   kermit* state = (kermit*) device->token;
633   LOG(( "kermit: start\n" ));
634   state->image = NULL;
635   state->conf = (kermit_config*) device->static_config;
636   state->machine = device->machine;
637   state->resend = timer_alloc( kermit_resend_cb, state );
638   kermit_reset( state );
639}
640
641static DEVICE_RESET( kermit )
642{
643   kermit* state = (kermit*) device->token;
644   LOG(( "kermit: reset\n" ));
645   kermit_reset( state );
646}
647
648static DEVICE_IMAGE_LOAD( kermit )
649{
650   kermit* state = (kermit*) image->token;
651   LOG(( "kermit: image load\n" ));
652   state->image = image;
653   kermit_reset( state );
654   return INIT_PASS;
655}
656
657static DEVICE_IMAGE_CREATE( kermit )
658{
659   kermit* state = (kermit*) image->token;
660   LOG(( "kermit: image create\n" ));
661   state->image = image;
662   kermit_reset( state );
663   return INIT_PASS;
664}
665
666static DEVICE_IMAGE_UNLOAD( kermit )
667{
668   kermit* state = (kermit*) image->token;
669   LOG(( "kermit: image unload\n" ));
670   state->image = NULL;
671   kermit_reset( state );
672}
673
674DEVICE_GET_INFO( kermit )
675
676{
677   switch ( state ) {
678   case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof( kermit );                              break;
679   case DEVINFO_INT_INLINE_CONFIG_BYTES:       info->i = 0;                                             break;
680   case DEVINFO_INT_CLASS:                       info->i = DEVICE_CLASS_PERIPHERAL;                       break;
681   case DEVINFO_INT_IMAGE_TYPE:               info->i = IO_SERIAL;                                     break;
682   case DEVINFO_INT_IMAGE_READABLE:            info->i = 1;                                             break;
683   case DEVINFO_INT_IMAGE_WRITEABLE:       info->i = 1;                                             break;
684   case DEVINFO_INT_IMAGE_CREATABLE:       info->i = 1;                                             break;
685   case DEVINFO_FCT_START:                       info->start = DEVICE_START_NAME( kermit );               break;
686   case DEVINFO_FCT_RESET:                       info->reset = DEVICE_RESET_NAME( kermit );               break;
687   case DEVINFO_FCT_IMAGE_LOAD:          info->f = (genf *) DEVICE_IMAGE_LOAD_NAME( kermit );     break;
688   case DEVINFO_FCT_IMAGE_UNLOAD:          info->f = (genf *) DEVICE_IMAGE_UNLOAD_NAME( kermit );   break;
689   case DEVINFO_FCT_IMAGE_CREATE:          info->f = (genf *) DEVICE_IMAGE_CREATE_NAME( kermit );   break;
690   case DEVINFO_STR_IMAGE_BRIEF_INSTANCE_NAME: info->s = "k";                                        break;
691   case DEVINFO_STR_IMAGE_INSTANCE_NAME:
692   case DEVINFO_STR_NAME:                  info->s = "kermit";                                        break;
693   case DEVINFO_STR_FAMILY:                    info->s = "serial protocol";                        break;
694   case DEVINFO_STR_SOURCE_FILE:          info->s = __FILE__;                                      break;
695   case DEVINFO_STR_IMAGE_FILE_EXTENSIONS:       info->s = "";                                            break;
696   }
697}
698
src/mess/devices/xmodem.h
r0r2839
1/* XMODEM protocol implementation.
2
3   Transfer between an emulated machine and an image using the XMODEM protocol.
4
5   Used in the HP48 G/GX emulation.
6
7   Author: Antoine Mine'
8   Date: 29/03/2008
9 */
10
11#include "timer.h"
12#include "image.h"
13
14
15#define XMODEM DEVICE_GET_INFO_NAME( xmodem )
16
17
18typedef struct {
19
20  /* called by XMODEM when it wants to send a byte to the emulated machine */
21  void (*send)( running_machine *machine, UINT8 data );
22 
23} xmodem_config;
24
25
26
27extern DEVICE_GET_INFO( xmodem );
28
29
30/* call when the emulated machine has read the last byte sent by
31   XMODEM through the send call-back */
32extern void xmodem_byte_transmitted( const device_config *device );
33
34/* call when the emulated machine sends a byte to XMODEM */
35extern void xmodem_receive_byte( const device_config *device, UINT8 data );
src/mess/devices/kermit.h
r0r2839
1/* Kermit protocol implementation.
2
3   Transfer between an emulated machine and an image using the kermit protocol.
4
5   Used in the HP48 S/SX/G/GX emulation.
6
7   Author: Antoine Mine'
8   Date: 29/03/2008
9 */
10
11#include "timer.h"
12#include "image.h"
13
14
15#define KERMIT DEVICE_GET_INFO_NAME( kermit )
16
17
18typedef struct {
19
20  /* called by Kermit when it wants to send a byte to the emulated machine */
21  void (*send)( running_machine *machine, UINT8 data );
22 
23} kermit_config;
24
25
26
27extern DEVICE_GET_INFO( kermit );
28
29
30/* call this when the emulated machine has read the last byte sent by
31   Kermit through the send call-back */
32extern void kermit_byte_transmitted( const device_config *device );
33
34/* call this when the emulated machine sends a byte to Kermit */
35extern void kermit_receive_byte( const device_config *device, UINT8 data );
src/mess/includes/hp48.h
r2838r2839
1/*****************************************************************************
2 *
3 * includes/hp48.h
4 *
5 ****************************************************************************/
1/**********************************************************************
62
7#ifndef HP48_H_
8#define HP48_H_
3  Copyright (C) Antoine Mine' 2008
94
5   Hewlett Packard HP48 S/SX & G/GX
106
11#define KEY_A input_port_read_indexed(machine, 0)&0x80
12#define KEY_B input_port_read_indexed(machine, 0)&0x40
13#define KEY_C input_port_read_indexed(machine, 0)&0x20
14#define KEY_D input_port_read_indexed(machine, 0)&0x10
15#define KEY_E input_port_read_indexed(machine, 0)&8
16#define KEY_F input_port_read_indexed(machine, 0)&4
17#define KEY_G input_port_read_indexed(machine, 0)&2
18#define KEY_H input_port_read_indexed(machine, 0)&1
19#define KEY_I input_port_read_indexed(machine, 1)&0x80
20#define KEY_J input_port_read_indexed(machine, 1)&0x40
21#define KEY_K input_port_read_indexed(machine, 1)&0x20
22#define KEY_L input_port_read_indexed(machine, 1)&0x10
23#define KEY_M input_port_read_indexed(machine, 1)&8
24#define KEY_N input_port_read_indexed(machine, 1)&4
25#define KEY_O input_port_read_indexed(machine, 1)&2
26#define KEY_P input_port_read_indexed(machine, 1)&1
27#define KEY_Q input_port_read_indexed(machine, 2)&0x80
28#define KEY_R input_port_read_indexed(machine, 2)&0x40
29#define KEY_S input_port_read_indexed(machine, 2)&0x20
30#define KEY_T input_port_read_indexed(machine, 2)&0x10
31#define KEY_U input_port_read_indexed(machine, 2)&8
32#define KEY_V input_port_read_indexed(machine, 2)&4
33#define KEY_W input_port_read_indexed(machine, 2)&2
34#define KEY_X input_port_read_indexed(machine, 2)&1
35#define KEY_ENTER input_port_read_indexed(machine, 3)&0x80
36#define KEY_Y input_port_read_indexed(machine, 3)&0x40
37#define KEY_Z input_port_read_indexed(machine, 3)&0x20
38#define KEY_DEL input_port_read_indexed(machine, 3)&0x10
39#define KEY_LEFT input_port_read_indexed(machine, 3)&8
40#define KEY_ALPHA input_port_read_indexed(machine, 3)&4
41#define KEY_7 input_port_read_indexed(machine, 3)&2
42#define KEY_8 input_port_read_indexed(machine, 3)&1
43#define KEY_9 input_port_read_indexed(machine, 4)&0x80
44#define KEY_DIVIDE input_port_read_indexed(machine, 4)&0x40
45#define KEY_ORANGE input_port_read_indexed(machine, 4)&0x20
46#define KEY_4 input_port_read_indexed(machine, 4)&0x10
47#define KEY_5 input_port_read_indexed(machine, 4)&8
48#define KEY_6 input_port_read_indexed(machine, 4)&4
49#define KEY_MULTIPLY input_port_read_indexed(machine, 4)&2
50#define KEY_BLUE input_port_read_indexed(machine, 4)&1
51#define KEY_1 input_port_read_indexed(machine, 5)&0x80
52#define KEY_2 input_port_read_indexed(machine, 5)&0x40
53#define KEY_3 input_port_read_indexed(machine, 5)&0x20
54#define KEY_MINUS input_port_read_indexed(machine, 5)&0x10
55#define KEY_ON input_port_read_indexed(machine, 5)&8
56#define KEY_0 input_port_read_indexed(machine, 5)&4
57#define KEY_POINT input_port_read_indexed(machine, 5)&2
58#define KEY_SPC input_port_read_indexed(machine, 5)&1
59#define KEY_PLUS input_port_read_indexed(machine, 6)&0x80
7**********************************************************************/
608
9/***************************************************************************
10    MACROS
11***************************************************************************/
6112
62/*----------- defined in machine/hp48.c -----------*/
13/* read from I/O memory */
14#define HP48_IO_4(x)   (hp48_io[(x)])
15#define HP48_IO_8(x)   (hp48_io[(x)] | (hp48_io[(x)+1] << 4))
16#define HP48_IO_12(x)  (hp48_io[(x)] | (hp48_io[(x)+1] << 4) | (hp48_io[(x)+2] << 8))
17#define HP48_IO_20(x)  (hp48_io[(x)] | (hp48_io[(x)+1] << 4) | (hp48_io[(x)+2] << 8) | \
18                  (hp48_io[(x)+3] << 12) | (hp48_io[(x)+4] << 16))
6319
64typedef struct {
65   int data[0x40];
66   UINT16 crc;
67   UINT32 timer2;
68} HP48_HARDWARE;
69extern HP48_HARDWARE hp48_hardware;
7020
71extern UINT8 *hp48_ram, *hp48_card1, *hp48_card2;
72void hp48_mem_reset(running_machine *machine);
73void hp48_mem_config(running_machine *machine, int v);
74void hp48_mem_unconfig(running_machine *machine, int v);
75int hp48_mem_id(running_machine *machine);
76void hp48_crc(running_machine *machine, int adr, int data);
77int hp48_in(running_machine *machine);
78void hp48_out(running_machine *machine, int v);
7921
80DRIVER_INIT( hp48s );
81DRIVER_INIT( hp48g );
82MACHINE_RESET( hp48 );
22/***************************************************************************
23    GLOBAL VARIABLES & CONSTANTS
24***************************************************************************/
8325
84WRITE8_HANDLER( hp48_write );
85READ8_HANDLER( hp48_read );
26/* I/O memory */
27extern UINT8 hp48_io[64];
8628
87WRITE8_HANDLER( hp48_mem_w );
8829
89/*----------- defined in video/hp48.c -----------*/
9030
91extern const unsigned short hp48_colortable[0x20][2];
31/***************************************************************************
32    FUNCTION PROTOTYPES
33***************************************************************************/
9234
93extern PALETTE_INIT( hp48 );
94extern VIDEO_START( hp48 );
95extern VIDEO_UPDATE( hp48 );
9635
36/************************ Saturn's I/O *******************************/
9737
98#endif /* HP48_H_ */
38/* memory controller */
39void hp48_mem_reset( running_machine* machine );
40void hp48_mem_config( running_machine* machine, int v );
41void hp48_mem_unconfig( running_machine* machine, int v );
42int  hp48_mem_id( running_machine* machine );
43
44/* CRC computation */
45void hp48_mem_crc( running_machine* machine, int addr, int data );
46
47/* IN/OUT registers */
48int  hp48_reg_in( running_machine* machine );
49void hp48_reg_out( running_machine* machine, int v );
50
51/* keybord interrupt system */
52void hp48_rsi( running_machine* machine );
53
54
55/***************************** serial ********************************/
56
57extern void hp48_rs232_start_recv_byte( running_machine *machine, UINT8 data );
58
59
60/****************************** video ********************************/
61
62extern VIDEO_UPDATE ( hp48 );
63extern PALETTE_INIT ( hp48 );
64
65
66/****************************** cards ********************************/
67
68struct hp48_port_config;
69
70extern struct hp48_port_config hp48sx_port1_config;
71extern struct hp48_port_config hp48sx_port2_config;
72extern struct hp48_port_config hp48gx_port1_config;
73extern struct hp48_port_config hp48gx_port2_config;
74
75extern DEVICE_GET_INFO( hp48_port );
76
77#define HP48_PORT DEVICE_GET_INFO_NAME( hp48_port )
78
79
80/****************************** machine ******************************/
81
82extern DRIVER_INIT( hp48 );
83
84extern MACHINE_START( hp48s  );
85extern MACHINE_START( hp48sx );
86extern MACHINE_START( hp48g  );
87extern MACHINE_START( hp48gx );
88
89extern MACHINE_RESET( hp48 );
src/mess/video/hp48.c
r2838r2839
1/**********************************************************************
2
3  Copyright (C) Antoine Mine' 2008
4
5   Hewlett Packard HP48 S/SX & G/GX
6
7**********************************************************************/
8
19#include "driver.h"
10#include "timer.h"
11#include "state.h"
12#include "device.h"
13
214#include "includes/hp48.h"
315
4static const UINT8 hp48_palette[] =
5{
6   49,70,64,   /* background */
7   40,35,55,   /* symbol color */
8   49,72,73,   /* lcd light */
9   37,42,64   /* lcd dark */
10};
1116
17/***************************************************************************
18    DEBUGGING
19***************************************************************************/
1220
13PALETTE_INIT( hp48 )
14{
15   int i;
1621
17   for ( i = 0; i < 4; i++ ) {
18      palette_set_color_rgb( machine, i, hp48_palette[i*3], hp48_palette[i*3+1], hp48_palette[i*3+2] );
19   }
20}
22#define VERBOSE       0
2123
24#define LOG(x)  do { if (VERBOSE) logerror x; } while (0)
2225
23VIDEO_START( hp48 )
24{
25    videoram_size = 6 * 2 + 24;
26    videoram = (UINT8*) auto_malloc (videoram_size);
27}
2826
2927
30typedef const char *HP48_FIGURE;
28/***************************************************************************
29    GLOBAL VARIABLES & CONSTANTS
30***************************************************************************/
3131
32static void hp48_draw_special(bitmap_t *bitmap,int x, int y, const HP48_FIGURE figure, int color)
32/* base colors */
33static int hp48_bg_color[3] = { 136, 147, 109 };  /* yellow */
34static int hp48_fg_color[3] = {   0,   0,  64 };  /* dark blue */
35
36/* color mixing */
37#define mix(c1,c2,x) (c1)*(1-(x))+(c2)*(x)
38#define mix2(i,x) mix(hp48_bg_color[i],hp48_fg_color[i],x)
39
40/* screen image averaging */
41#define HP48_NB_SCREENS 3
42static UINT8  hp48_screens[ HP48_NB_SCREENS ][ 64 ][ 144 ];
43static int    hp48_cur_screen;
44
45
46
47/***************************************************************************
48    FUNCTIONS
49***************************************************************************/
50
51PALETTE_INIT ( hp48 )
3352{
34   int j, xi=0;
35   for (j=0; figure[j]; j++) {
36      switch (figure[j]) {
37      case '1':
38         *BITMAP_ADDR16(bitmap, y, x+xi) = color;
39         xi++;
40         break;
41      case ' ':
42         xi++;
43         break;
44      case '\r':
45         xi=0;
46         y++;
47         break;
48      };
53   int i;
54   for ( i = 0; i < 255; i++ )
55   {
56      float c = i/255.;
57      palette_set_color( machine, i, MAKE_ARGB( 0, mix2(0,c), mix2(1,c), mix2(2,c) ) );
4958   }
5059}
5160
5261
53#define LCD_LINES (hp48_hardware.data[0x28]|((hp48_hardware.data[0x29]&3)<<4)
5462
63/* The screen is organised as follows:
5564
56static const HP48_FIGURE hp48_orange={
57   "11111111111\r"
58   "111 1111111\r"
59   "11  1111111\r"
60   "1         1\r"
61   "11  11111 1\r"
62   "111 11111 1\r"
63   "111111111 1"
64}, hp48_blue= {
65   "11111111111\r"
66   "1111111 111\r"
67   "1111111  11\r"
68   "1         1\r"
69   "1 11111  11\r"
70   "1 11111 111\r"
71   "1 111111111"
72}, hp48_alpha= {
73   "          1\r"
74   "   11111 1\r"
75   "  1     1\r"
76   " 1      1\r"
77   " 1      1\r"
78   " 1     11\r"
79   "  11111  1"
80}, hp48_alarm= {
81   "  1       1\r"
82   " 1  1   1  1\r"
83   "1  1  1  1  1\r"
84   "1  1 111 1  1\r"
85   "1  1  1  1  1\r"
86   " 1  1   1  1\r"
87   "  1       1"
88}, hp48_busy= {
89   "11111111\r"
90   " 1    1\r"
91   "  1  1\r"
92   "   11\r"
93   "  1  1\r"
94   " 1    1\r"
95   "11111111"
96}, hp48_transmit={
97   " 11\r"
98   "1  1   1\r"
99   "    1   1\r"
100   "1111111111\r"
101   "    1   1\r"
102   "1  1   1\r"
103   " 11"
104};
10565
106#define DOWN 98
107#define RIGHT 40
108#define LCD_ENABLE (hp48_hardware.data[0]&8)
109#define LCD_VERTICAL_OFFSET (hp48_hardware.data[0]&7)
110#define LCD_MAIN_BASE_ADDRESS (hp48_hardware.data[0x20]|(hp48_hardware.data[0x21]<<4)\
111      |(hp48_hardware.data[0x22]<<8)|(hp48_hardware.data[0x23]<<12)\
112      |(hp48_hardware.data[0x24]<<16))
113#define LCD_MENU_BASE_ADDRESS (hp48_hardware.data[0x30]|(hp48_hardware.data[0x31]<<4)\
114      |(hp48_hardware.data[0x32]<<8)|(hp48_hardware.data[0x33]<<12)\
115      |(hp48_hardware.data[0x34]<<16))
116#define LCD_MAIN_SIZE (hp48_hardware.data[0x28]|(hp48_hardware.data[0x29]<<4))
11766
118#define LCD_LINE_OFFSET (hp48_hardware.data[0x25]|(hp48_hardware.data[0x26]<<4)\
119      |(hp48_hardware.data[0x27]<<8))
67            announciators
12068
121VIDEO_UPDATE( hp48 )
69        ----------------------      ^       ^
70       |                      |     |       |
71       |                      |     |       |
72       |                      |     |       |
73       |                      |  M lines    |
74       |      main screen     |     |       |
75       |                      |     |       |
76       |                      |     |    64 lines
77       |                      |     |       |
78       |                      |     |       |
79       |----------------------|     -       |
80       |                      |     |       |
81       |        menu          |  m lines    |
82       |                      |     |       |
83        ----------------------      v       v
84
85       <----- 131 columns ---->
86
87
88
89        The LCD is 131x64 pixels and has two components:
90   - a main screen
91   - a menu screen
92
93   The main height (M) and the menu height (m) can be changed with the constraints:
94   - m+M=64
95   - M>=2
96
97   Pixels are 1-bit, packed in memory.
98
99   The start address of both screens can be changed independently
100   (this allows smooth, pixel-precise vertical scrooling of both parts).
101   They must be even addresses (in nibbles).
102
103   The stride (offset in nibbles between two scanlines) can be changed for the main screen.   
104   It must be even.
105   It is fixed to 34 for the menu screen.
106   
107   The bit offset for the first column of the main screen can be changed
108   (this allows smooth, pixel-precise horizontal scrooling).
109   It is always 0 for the menu screen.
110
111   Above the LCD, there are 6 annonciators that can be independently turned
112   on and off (and independetly from the LCD).
113   They are not handled here, but through output_set_value.
114 */
115
116
117/*
118        In theory, the LCD is monorchrome, with a global adjustable contrast (32 levels).
119   However, by switching between screens at each refresh (64 Hz), one can achieve the
120   illusion of grayscale, with moderate flickering.
121   This technique was very widespread.
122   We emulate it by simply averaging between the last few (HP48_NB_SCREENS) frames.
123   
124   HP48_NB_SCREENS should be a multiple of the period of screen flips to avoid
125   flickering in the emulation.
126 */
127
128
129#define draw_pixel                     \
130   hp48_screens[ hp48_cur_screen ][ y ][ xp + 8 ] = (data & 1) ? fg : 0; \
131   xp++;                        \
132   data >>= 1
133
134#define draw_quart               \
135   UINT8 data = program_read_byte( addr );   \
136   draw_pixel; draw_pixel; draw_pixel; draw_pixel;
137
138
139VIDEO_UPDATE ( hp48 )
122140{
123   int x, y, i, p, data, max_y;
124//   int contrast=(hp48_hardware.data[1]|((hp48_hardware.data[2]&1)<<4));
141   int x, y, xp, i, addr;
142   int display       = HP48_IO_4(0) >> 3;           /* 1=on, 0=off */
143   int left_margin   = HP48_IO_4(0) & 7;            /* 0..7 pixels for main bitmap */
144   int contrast      = HP48_IO_8(1) & 0x1f;         /* 0..31 */
145   int refresh       = HP48_IO_4(3) >> 3;           /* vertical refresh */
146   int bitmap_start  = HP48_IO_20(0x20) & ~1;       /* main bitmap address */
147   int right_margin  = HP48_IO_12(0x25) & ~1;       /* -2048..2046 nibbles for main bitmap */
148   int last_line     = HP48_IO_8(0x28) & 0x3f;      /* 2..63 lines of main bitmap before menu */
149   int menu_start    = HP48_IO_20(0x30) & ~1;       /* menu bitmap address */
125150
126   i = LCD_MAIN_BASE_ADDRESS;
127   max_y = MIN(64, LCD_MAIN_SIZE + 1 );
128   if ( max_y < 3 ) {
129      max_y = 64;
151   int fg = contrast + 1;
152
153   LOG(( "%f hp48 video_update called: ", attotime_to_double(timer_get_time()) ));
154
155   if ( !display || refresh )
156   {
157      LOG(( "display off\n" ));
158      bitmap_fill( bitmap, NULL, 0 );
159      return 0;     
130160   }
131161
132   i = LCD_MAIN_BASE_ADDRESS;
133   for (y=0; y< max_y; y++) {
134      int j = ( LCD_VERTICAL_OFFSET & 4 ? 1 : 0 );
135      p = LCD_VERTICAL_OFFSET & 0x03;
136      data = program_read_byte( i + j );
137      for (x=0; x<131; x++) {
138         *BITMAP_ADDR16(bitmap, DOWN + y, RIGHT + x) = ( ( data << p ) & 0x08 ) ? 3 : 2;
139         p++;
140         if ( p > 3 ) {
141            j++;
142            data = program_read_byte( i + j );
143            p = 0;
144         }
162   /* correcting factors */
163   if ( right_margin & 0x800 ) right_margin -= 0x1000;
164   if ( last_line <= 1 ) last_line = 0x3f;
165
166   LOG(( "on=%i lmargin=%i rmargin=%i contrast=%i start=%05x lline=%i menu=%05x\n",
167         display, left_margin, right_margin, contrast, bitmap_start, last_line, menu_start ));
168
169   /* draw main bitmap */
170   addr = bitmap_start;
171   for ( y = 0; y <= last_line; y++ )
172   {
173      xp = -left_margin;
174      for ( x = 0; x < 34; x++, addr++ )
175      {
176         draw_quart;
145177      }
146      i += 34 + LCD_LINE_OFFSET;
178      addr += (right_margin + (left_margin / 4) + 1) & ~1;
147179   }
148180
149   i = LCD_MENU_BASE_ADDRESS;
150   for ( ; y < 64; y++ ) {
151      int j = 0;
152      p = 0;
153      data = program_read_byte( i + j );
154      for ( x = 0; x < 131; x++ ) {
155         *BITMAP_ADDR16(bitmap, DOWN + y, RIGHT + x) = ( ( data << p ) & 0x08 ) ? 3 : 2;
156         p++;
157         if ( p > 3 ) {
158            j++;
159            data = program_read_byte( i + j );
160            p = 0;
161         }
181   /* draw menu bitmap */
182   addr = menu_start;
183   for ( ; y <= 0x3f; y++ )
184   {
185      xp = 0;
186      for ( x = 0; x < 34; x++, addr++ )
187      {
188         draw_quart;
162189      }
163      i += 34;
164190   }
165191
166   hp48_draw_special(bitmap,RIGHT+12,DOWN-13,hp48_orange,
167                 hp48_hardware.data[0xb]&1?1:1);
168   hp48_draw_special(bitmap,RIGHT+57,DOWN-13,hp48_blue,
169                 hp48_hardware.data[0xb]&2?1:0);
170   hp48_draw_special(bitmap,RIGHT+102,DOWN-13,hp48_alpha,
171                 hp48_hardware.data[0xb]&4?1:0);
172   hp48_draw_special(bitmap,RIGHT+147,DOWN-13,hp48_alarm,
173                 hp48_hardware.data[0xb]&8?1:0);
174   hp48_draw_special(bitmap,RIGHT+192,DOWN-13,hp48_busy,
175                 hp48_hardware.data[0xc]&1?1:0);
176   hp48_draw_special(bitmap,RIGHT+237,DOWN-13,hp48_transmit,
177                 hp48_hardware.data[0xc]&2?1:0);
192   /* draw averaged frames */
193   for ( y = 0; y < 64; y++ )
194   {
195      for ( x = 0; x < 131; x++ )
196      {
197         int acc = 0;
198         for ( i = 0; i < HP48_NB_SCREENS; i++ )
199         {
200            acc += hp48_screens[ i ][ y ][ x+8 ];
201         }
202         acc = (acc * 255) / (33 * HP48_NB_SCREENS);
203         *BITMAP_ADDR16( bitmap, y, x ) = acc;
204      }     
205   }
206
207   hp48_cur_screen = (hp48_cur_screen + 1) % HP48_NB_SCREENS;
208
178209   return 0;
179210}
src/mess/messdriv.c
r2838r2839
735735TESTDRIVER( comquest )   /* Comquest Plus German                        */
736736
737737   /* Hewlett Packard */
738TESTDRIVER( hp48s )      /* HP48 S/SX                              */
739TESTDRIVER( hp48g )      /* HP48 G/GX                              */
738   DRIVER( hp48s )      /* HP48 S */
739   DRIVER( hp48sx )   /* HP48 SX */
740   DRIVER( hp48g )      /* HP48 G */
741   DRIVER( hp48gx )   /* HP48 GX */
740742
741743   /* SpectraVideo */
742744   DRIVER( svi318 )   /* SVI-318 (PAL)                           */
src/mess/machine/hp48.c
r2838r2839
1/**********************************************************************
2
3  Copyright (C) Antoine Mine' 2008
4
5   Hewlett Packard HP48 S/SX & G/GX
6
7**********************************************************************/
8
19#include "driver.h"
10#include "timer.h"
11#include "state.h"
12#include "device.h"
13#include "sound/dac.h"
14#include "cpu/saturn/saturn.h"
215
16#include "devices/xmodem.h"
17#include "devices/kermit.h"
18
319#include "includes/hp48.h"
420
5/*
6  0
7  1bc
8  1fc6
9  1fe3 configure memory
10   2248
11   2256
12  201a power control register loaded (currently 1!)
13  202e
14   26fd copies 0x36 nibbles from 701c to 700a !
15    c192 ram address into d0
16   11fc
17   2494
18   1929
19    13437
20 */
2121
22enum {
23   HP48_ROM,
24   HP48_CARD1,
25   HP48_CARD2,
26   HP48_RAM,
27   HP48_HDW,
28   HP48_END
29};
22/***************************************************************************
23    DEBUGGING
24***************************************************************************/
3025
3126
27#define VERBOSE          0
28#define VERBOSE_SERIAL   0
3229
30#define LOG(x)  do { if (VERBOSE) logerror x; } while (0)
31#define LOG_SERIAL(x)  do { if (VERBOSE_SERIAL) logerror x; } while (0)
3332
3433
3534
36UINT8 *hp48_ram, *hp48_card1, *hp48_card2;
37static int out;
35/***************************************************************************
36    TYPE DEFINITIONS
37***************************************************************************/
3838
39#define HDW 0
40#define RAM 1
41#define CARD2 2
42#define CARD1 3
43#define NCE3
44#define ROM 4
45static struct {
46   int state;
47   struct {
48      int realsize,
49         adr,/* a11..a0 ignored */
50         size;/* a19..a12 comparator select, 1 means address line must match adr */
51   } mem[5];
52} hp48s= {
53   0,
54   {
55      { 32 }, // no size configure, only a4..a0 ignored
56      { 128*1024 }, //s 32kb, sx 128kb
57      { 32*1024 }, // card2 32 kb or 128kb
58      { 32*1024 }, // card1 32 kb or 128kb
59      { 256*1024, 0 } // not configurable, always visible
60   }
61};
39/* model */
40typedef enum {
41   HP48_S,
42   HP48_SX,
43   HP48_G,
44   HP48_GX,
45} hp48_models;
6246
63static struct {
64   UINT8   *base;
65   UINT8   type;
66} hp48_banks[129];
47/* memory module configuration */
48typedef struct
49{
50   /* static part */
51   UINT32 off_mask;             /* offset bit-mask, indicates the real size */
52   read8_machine_func read;
53   write8_machine_func write;
54   void* data;                  /* non-NULL for banks */
6755
68// to do support weired comparator settings
69static void hp48_config(running_machine *machine)
56   /* configurable part */
57   UINT8  state;                /* one of HP48_MODULE_ */
58   UINT32 base;                 /* base address */
59   UINT32 mask;                 /* often improperly called size, it is an address select mask */
60
61} hp48_module;
62
63
64/* state field in hp48_module */
65#define HP48_MODULE_UNCONFIGURED 0
66#define   HP48_MODULE_MASK_KNOWN   1
67#define HP48_MODULE_CONFIGURED   2
68
69/* port specification */
70struct hp48_port_config
7071{
71   static const read8_machine_func read_handlers[11] = { 0, SMH_BANK1, SMH_BANK2, SMH_BANK3, SMH_BANK4, SMH_BANK5, SMH_BANK6, SMH_BANK7, SMH_BANK8, SMH_BANK9, SMH_BANK10 };
72   int i, begin_bank, end_bank, begin, end, mem_type, bank;
72   int port;                 /* port index: 0 or 1 (for port 1 and 2) */
73   int module;               /* memory module where the port is visible */
74   int max_size;             /* maximum size, in bytes 128 KB or 4 GB */
7375
74   /* Determine the current memory map */
76   /* device instance names */
77   const char* brief_name;
78   const char* name;
7579
76   /* Lowest priority is ROM */
77   for ( i = 0; i < 128; i++ ) {
78      hp48_banks[i].base = memory_region( REGION_CPU1 ) + i * 0x2000;
79      hp48_banks[i].type = HP48_ROM;
80   }
81   hp48_banks[128].type = HP48_END;
80};
8281
83   /* Next priority is CARD1 */
84   if ( hp48s.mem[CARD1].adr != -1 ) {
85      logerror("hp48_config CARD1 should be configured\n");
86      begin_bank = ( ( hp48s.mem[CARD1].adr & ~( hp48s.mem[CARD1].size - 1 ) ) >> 13 ) & 0x7F;
87      end_bank = begin_bank | ( ( hp48s.mem[CARD1].size - 1 ) >> 13 );
88      for ( i = begin_bank; i <= end_bank; i++ ) {
89         hp48_banks[i].base = hp48_card1 + i * 0x2000;
90         hp48_banks[i].type = HP48_CARD1;
91      }
92      logerror("CARD1 begin = %02X, end = %02X\n", begin_bank, end_bank);
93   }
9482
95   /* Next priority is CARD2 */
96   if ( hp48s.mem[CARD2].adr != -1 ) {
97      logerror("hp48_config CARD2 should be configured\n");
98      begin_bank = ( ( hp48s.mem[CARD2].adr & ~( hp48s.mem[CARD2].size - 1 ) ) >> 13 ) & 0x7F;
99      end_bank = begin_bank | ( ( hp48s.mem[CARD2].size - 1 ) >> 13 );
100      for ( i = begin_bank; i <= end_bank; i++ ) {
101         hp48_banks[i].base = hp48_card2 + i * 0x2000;
102         hp48_banks[i].type = HP48_CARD2;
103      }
104      logerror("CARD2 begin = %02X, end = %02X\n", begin_bank, end_bank);
83/***************************************************************************
84    GLOBAL VARIABLES & CONSTANTS
85***************************************************************************/
86
87/* current HP48 model */
88static hp48_models hp48_model;
89
90#define HP48_G_SERIES ((hp48_model==HP48_G) || (hp48_model==HP48_GX))
91#define HP48_S_SERIES ((hp48_model==HP48_S) || (hp48_model==HP48_SX))
92#define HP48_X_SERIES ((hp48_model==HP48_SX) || (hp48_model==HP48_GX))
93#define HP48_GX_MODEL (hp48_model==HP48_GX)
94
95/* OUT register from SATURN (actually 12-bit) */
96static UINT16 hp48_out;
97
98/* keyboard interrupt */
99static UINT8 hp48_kdn;
100
101/* from highest to lowest priority: HDW, NCE2, CE1, CE2, NCE3, NCE1 */
102static hp48_module hp48_modules[6];
103
104static const char* hp48_module_names[6] =
105  { "HDW (I/O)", "NCE2 (RAM)", "CE1", "CE2", "NCE3", "NCE1 (ROM)" };
106
107/* values returned by C=ID */
108static const UINT8 hp48_module_mask_id[6] = { 0x00, 0x03, 0x05, 0x07, 0x01, 0x00 };
109static const UINT8 hp48_module_addr_id[6] = { 0x19, 0xf4, 0xf6, 0xf8, 0xf2, 0x00 };
110
111/* RAM/ROM extensions, GX/SX only (each UINT8 stores one nibble)
112   port1: SX/GX: 32/128 KB
113   port2: SX:32/128KB, GX:128/512/4096 KB
114 */
115static UINT32 hp48_port_size[2];
116static UINT8  hp48_port_write[2];
117static UINT8* hp48_port_data[2];
118static UINT32 hp48_bank_switch;
119
120
121/* I/O memory (each UINT8 stores one nibble) */
122UINT8 hp48_io[64]; /* 64 nibbles */
123static UINT32 hp48_io_addr; /* to known when to disable crc */
124
125/* CRC state */
126static UINT16 hp48_crc;
127
128/* timers state */
129static UINT8   hp48_timer1;
130static UINT32  hp48_timer2;
131
132#ifdef CHARDEV
133#include "devices/chardev.h"
134static chardev* hp48_chardev;
135#endif
136
137
138/***************************************************************************
139    FUNCTIONS
140***************************************************************************/
141
142static void hp48_apply_modules( running_machine *machine, void* param );
143
144
145/* ---------------- serial --------------------- */
146
147#define RS232_DELAY ATTOTIME_IN_USEC( 300 )
148
149/* end of receive event */
150static TIMER_CALLBACK( hp48_rs232_byte_recv_cb )
151{   
152   LOG_SERIAL(( "%f hp48_rs232_byte_recv_cb: end of receive, data=%02x\n",
153           attotime_to_double(timer_get_time()), param ));
154
155   hp48_io[0x14] = param & 0xf; /* receive zone */
156   hp48_io[0x15] = param >> 4;
157   hp48_io[0x11] &= ~2; /* clear byte receiving */
158   hp48_io[0x11] |= 1;  /* set byte received */
159
160   /* interrupt */
161   if ( hp48_io[0x10] & 2 )
162   {
163      cpunum_set_input_line( machine, 0, SATURN_IRQ_LINE, PULSE_LINE );
105164   }
165}
106166
107   /* Next priority is RAM */
108   if ( hp48s.mem[RAM].adr != -1 ) {
109      logerror("hp48_config RAM should be configured\n");
110      begin_bank = ( ( hp48s.mem[RAM].adr & ~( hp48s.mem[RAM].size - 1 ) ) >> 13 ) & 0x7F;
111      end_bank = begin_bank | ( ( hp48s.mem[RAM].size - 1 ) >> 13 );
112      for ( i = begin_bank; i <= end_bank; i++ ) {
113         hp48_banks[i].base = hp48_ram + i * 0x2000;
114         hp48_banks[i].type = HP48_RAM;
115      }
116      logerror("RAM begin = %02X, end = %02X\n", begin_bank, end_bank);
167/* outside world initiates a receive event */
168void hp48_rs232_start_recv_byte( running_machine *machine, UINT8 data )
169{
170   LOG_SERIAL(( "%f hp48_rs232_start_recv_byte: start receiving, data=%02x\n",
171           attotime_to_double(timer_get_time()), data ));
172
173   hp48_io[0x11] |= 2;  /* set byte receiving */
174   
175   /* interrupt */
176   if ( hp48_io[0x10] & 1 )
177   {
178      cpunum_set_input_line( machine, 0, SATURN_IRQ_LINE, PULSE_LINE );
117179   }
118180
119   /* Highest priority is HDW */
181   /* schedule end of reception */
182   timer_set( RS232_DELAY, NULL, data, hp48_rs232_byte_recv_cb );
183}
120184
121   /* Set up dynamic bank configuration */
122   bank = 1;
123   begin_bank = end_bank = 0;
124   mem_type = hp48_banks[begin_bank].type;
125   for ( i = 1; i < 129; i++ ) {
126      if ( hp48_banks[i].type != mem_type ) {
127         begin = begin_bank << 13;
128         end = ( end_bank << 13 ) | 0x1FFF;
129185
130         memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, begin, end, 0, 0, read_handlers[bank] );
131         memory_set_bankptr( bank, hp48_banks[begin_bank].base );
186/* end of send event */
187static TIMER_CALLBACK( hp48_rs232_byte_sent_cb )
188{   
189   const device_config *xmodem = device_list_find_by_tag( machine->config->devicelist, XMODEM, "rs232-x" );
190   const device_config *kermit = device_list_find_by_tag( machine->config->devicelist, KERMIT, "rs232-k" );
132191
133         bank++;
134         begin_bank = i;
135         mem_type = hp48_banks[i].type;
136      }
137      end_bank = i;
192   LOG_SERIAL(( "%f hp48_rs232_byte_sent_cb: end of send, data=%02x\n",
193           attotime_to_double(timer_get_time()), param ));
194
195   hp48_io[0x12] &= ~3; /* clear byte sending and buffer full */
196
197   /* interrupt */
198   if ( hp48_io[0x10] & 4 )
199   {
200      cpunum_set_input_line( machine, 0, SATURN_IRQ_LINE, PULSE_LINE );
138201   }
139202
140   if ( hp48s.mem[HDW].adr != -1 ) {
141      memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, hp48s.mem[HDW].adr&~0x3f,
142                         hp48s.mem[HDW].adr|0x3f, 0, 0, hp48_read);
143//      memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, hp48s.mem[HDW].adr&~0x3f,
144//                          hp48s.mem[HDW].adr|0x3f, 0, 0, hp48_write);
203   /* protocol action */
204   if ( xmodem && image_exists( xmodem ) ) xmodem_receive_byte( xmodem, param );
205   else if ( kermit && image_exists( kermit ) ) kermit_receive_byte( kermit, param );
206#ifdef CHARDEV
207   else chardev_out( hp48_chardev, param );
208#endif
209}
210
211/* CPU initiates a send event */
212static void hp48_rs232_send_byte( running_machine *machine )
213{
214   const device_config *xmodem = device_list_find_by_tag( machine->config->devicelist, XMODEM, "rs232-x" );
215   const device_config *kermit = device_list_find_by_tag( machine->config->devicelist, KERMIT, "rs232-k" );
216   
217   UINT8 data = HP48_IO_8(0x16); /* byte to send */
218
219   LOG_SERIAL(( "%05x %f hp48_rs232_send_byte: start sending, data=%02x\n",
220           activecpu_get_previouspc(), attotime_to_double(timer_get_time()), data ));
221
222   hp48_io[0x12] |= 3;           /* set byte sending and send buffer full */
223
224   /* schedule transmission */
225   if ( (xmodem && image_exists( xmodem )) || (kermit && image_exists( kermit )) )
226   {
227      timer_set( RS232_DELAY, NULL, data, hp48_rs232_byte_sent_cb );
145228   }
229#ifdef CHARDEV
230   else
231   {
232      chardev_out( hp48_chardev, data );
233   }
234#endif
146235}
147236
148WRITE8_HANDLER( hp48_mem_w ) {
149   int   bank = ( offset >> 13 ) & 0x7F;
150   //logerror("hp48_mem_w: offset = %06X, data = %02X\n", offset, data );
151237
152   /* Check for write to HDW */
153   if ( hp48s.mem[HDW].adr != -1 && offset >= hp48s.mem[HDW].adr && offset < hp48s.mem[HDW].adr + 0x40 ) {
154      hp48_write( machine, offset & 0x3F, data );
155   } else {
156      switch( hp48_banks[bank].type ) {
157      case HP48_RAM:
158         //logerror("RAM write\n");
159         hp48_banks[bank].base[offset & 0x1FFF] = data;
160         break;
161      case HP48_CARD1:
162         //logerror("CARD1 write\n");
163         hp48_banks[bank].base[offset & 0x1FFF] = data;
164         break;
165      case HP48_CARD2:
166         //logerror("CARD2 write\n");
167         hp48_banks[bank].base[offset & 0x1FFF] = data;
168         break;
169      }
238#ifdef CHARDEV
239
240static TIMER_CALLBACK( hp48_chardev_byte_recv_cb )
241{
242   UINT8 data = chardev_in( hp48_chardev );
243
244   LOG_SERIAL(( "%f hp48_chardev_byte_recv_cb: end of receive, data=%02x\n",
245           attotime_to_double(timer_get_time()), data ));
246
247   hp48_io[0x14] = data & 0xf; /* receive zone */
248   hp48_io[0x15] = data >> 4;
249   hp48_io[0x11] &= ~2; /* clear byte receiving */
250   hp48_io[0x11] |= 1;  /* set byte received */
251
252   /* interrupt */
253   if ( hp48_io[0x10] & 2 )
254   {
255      cpunum_set_input_line( machine, 0, SATURN_IRQ_LINE, PULSE_LINE );
170256   }
171257}
172258
173/* priority on the bus
174   hdw, ram, ce2, ce1, nce3, rom */
175void hp48_mem_reset(running_machine *machine)
259static void hp48_chardev_start_recv_byte( running_machine *machine, chardev_err status )
176260{
177   int i;
178   hp48s.state=0;
261   if ( status != CHARDEV_OK ) return;
179262
180   for (i=0; i+1< sizeof(hp48s.mem)/sizeof(hp48s.mem[0]); i++) {
181      hp48s.mem[i].adr=-1;
263   LOG_SERIAL(( "%f hp48_chardev_start_recv_byte: start receiving\n",
264           attotime_to_double(timer_get_time()) ));
265
266   hp48_io[0x11] |= 2;  /* set byte receiving */
267   
268   /* interrupt */
269   if ( hp48_io[0x10] & 1 )
270   {
271      cpunum_set_input_line( machine, 0, SATURN_IRQ_LINE, PULSE_LINE );
182272   }
183   hp48_config(machine);
273
274   /* schedule end of reception */
275   timer_set( RS232_DELAY, NULL, 0, hp48_chardev_byte_recv_cb );
184276}
185277
186void hp48_mem_config(running_machine *machine, int v)
278static void hp48_chardev_ready_to_send( running_machine *machine )
187279{
188   logerror("hp48_mem_config called\n");
189   if (hp48s.mem[HDW].adr==-1) {
190      logerror("Configuring HDW at %06X\n", v );
191      hp48s.mem[HDW].adr=v;
192      hp48_config(machine);
193   } else if (hp48s.mem[RAM].adr==-1) {
194      if (hp48s.state==0) {
195         v = 0x100000 - v;
196         hp48s.mem[RAM].size=v;
197         logerror("Setting RAM size to %06X\n", v );
198         hp48s.state++;
199      } else {
200         logerror("Configuring RAM at %06X\n", v );
201         hp48s.mem[RAM].adr=v;
202         hp48s.state=0;
203         hp48_config(machine);
204      }
205   } else if (hp48s.mem[CARD1].adr==-1) {
206      if (hp48s.state==0) {
207         v = 0x100000 - v;
208         hp48s.mem[CARD1].size=v;
209         hp48s.state++;
210      } else {
211         logerror("Configuring CARD1 at %06X\n", v );
212         hp48s.mem[CARD1].adr=v;
213         hp48s.state=0;
214         hp48_config(machine);
215      }
216   } else if (hp48s.mem[CARD2].adr==-1) {
217      if (hp48s.state==0) {
218         v = 0x100000 - v;
219         hp48s.mem[CARD2].size=v;
220         hp48s.state++;
221      } else {
222         logerror("Configuring CARD2 at %06X\n", v );
223         hp48s.mem[CARD2].adr=v;
224         hp48s.state=0;
225         hp48_config(machine);
226      }
280   hp48_io[0x12] &= ~3;     
281
282   /* interrupt */
283   if ( hp48_io[0x10] & 4 )
284   {
285      cpunum_set_input_line( machine, 0, SATURN_IRQ_LINE, PULSE_LINE );
227286   }
228287}
229288
230void hp48_mem_unconfig(running_machine *machine, int v)
289static const chardev_interface hp48_chardev_iface =
290{ hp48_chardev_start_recv_byte, hp48_chardev_ready_to_send };
291
292#endif
293
294
295/* ------ Saturn's IN / OUT registers ---------- */
296
297
298/* CPU sets OUT register (keyboard + beeper) */
299void hp48_reg_out( running_machine* machine, int out )
231300{
232   int i;
233   for (i=0; i+1< sizeof(hp48s.mem)/sizeof(hp48s.mem[0]); i++) {
234      if (hp48s.mem[i].adr==v) {
235         hp48s.mem[i].adr=-1;
236         hp48s.state=0;
237         hp48_config(machine);
238         break;
239      }
301   LOG(( "%05x %f hp48_reg_out: %03x\n",
302         activecpu_get_previouspc(), attotime_to_double(timer_get_time()), out ));
303
304   /* bits 0-8: keyboard lines */
305   hp48_out = out & 0x1ff;
306   
307   /* bits 9-10: unused */
308   
309   /* bit 11: beeper */
310   DAC_data_w( 0, (out & 0x800) ? 0x80 : 00 );
311}
312
313static int hp48_get_in( running_machine *machine )
314{
315   int in = 0;
316
317   /* regular keys */
318   if ( (hp48_out >> 0) & 1 ) in |= input_port_read( machine, "LINE0" );
319   if ( (hp48_out >> 1) & 1 ) in |= input_port_read( machine, "LINE1" );
320   if ( (hp48_out >> 2) & 1 ) in |= input_port_read( machine, "LINE2" );
321   if ( (hp48_out >> 3) & 1 ) in |= input_port_read( machine, "LINE3" );
322   if ( (hp48_out >> 4) & 1 ) in |= input_port_read( machine, "LINE4" );
323   if ( (hp48_out >> 5) & 1 ) in |= input_port_read( machine, "LINE5" );
324   if ( (hp48_out >> 6) & 1 ) in |= input_port_read( machine, "LINE6" );
325   if ( (hp48_out >> 7) & 1 ) in |= input_port_read( machine, "LINE7" );
326   if ( (hp48_out >> 8) & 1 ) in |= input_port_read( machine, "LINE8" );
327   
328   /* on key */
329   in |= input_port_read( machine, "ON" );
330
331   return in;
332}
333
334/* CPU reads IN register (keyboard) */
335int hp48_reg_in( running_machine* machine )
336{
337   int in = hp48_get_in( machine );
338   LOG(( "%05x %f hp48_reg_in: %04x\n",
339         activecpu_get_previouspc(), attotime_to_double(timer_get_time()), in ));
340   return in;
341}
342
343/* key detect */
344static void hp48_update_kdn( running_machine *machine )
345{   
346   int in = hp48_get_in( machine );
347
348   /* interrupt on raising edge */
349   if ( in && !hp48_kdn )
350   {
351      LOG(( "%f hp48_update_kdn: interrupt\n", attotime_to_double(timer_get_time()) ));
352      hp48_io[0x19] |= 8;                                              /* service request */
353      cpunum_set_input_line( machine, 0, SATURN_WAKEUP_LINE, PULSE_LINE );     /* wake-up */
354      cpunum_set_input_line( machine, 0, SATURN_IRQ_LINE, PULSE_LINE );      /* interrupt */
240355   }
356
357   hp48_kdn = (in!=0);
241358}
242359
243#define HDW_ID_ADR 0x19
244#define RAM_ID_SIZE 3
245#define RAM_ID_ADR 0xf4
246#define CE1_ID_SIZE 5
247#define CE1_ID_ADR 0xf6
248#define CE2_ID_SIZE 7
249#define CE2_ID_ADR 0xf8
250#define NCE3_ID_SIZE 1
251#define NCE3_ID_ADR 0xf2
252int hp48_mem_id(running_machine *machine)
360/* periodic keyboard polling, generates an interrupt */
361static TIMER_CALLBACK( hp48_kbd_cb )
253362{
254   if (hp48s.mem[HDW].adr==-1) {
255      return (hp48s.mem[HDW].adr&~0x3f)|HDW_ID_ADR;
256    } else if (hp48s.mem[RAM].adr==-1) {
257      if (hp48s.state==0) return (hp48s.mem[RAM].size&~0xff)|RAM_ID_SIZE;
258      else return (hp48s.mem[RAM].size&~0xff)|RAM_ID_ADR;
259    } else if (hp48s.mem[CARD1].adr==-1) {
260      if (hp48s.state==0) return (hp48s.mem[CARD1].size&~0xff)|RAM_ID_SIZE;
261      else return (hp48s.mem[CARD1].size&~0xff)|RAM_ID_ADR;
262    } else if (hp48s.mem[CARD2].adr==-1) {
263      if (hp48s.state==0) return (hp48s.mem[CARD2].size&~0xff)|RAM_ID_SIZE;
264      else return (hp48s.mem[CARD2].size&~0xff)|RAM_ID_ADR;
363   /* NMI for ON key */
364   if ( input_port_read( machine, "ON" ) )
365   {
366      LOG(( "%f hp48_kbd_cb: keyboard interrupt, on key\n",
367            attotime_to_double(timer_get_time()) ));   
368      hp48_io[0x19] |= 8;                                          /* set service request */
369      cpunum_set_input_line( machine, 0, SATURN_WAKEUP_LINE, PULSE_LINE );     /* wake-up */
370      cpunum_set_input_line( machine, 0, SATURN_NMI_LINE, PULSE_LINE );      /* interrupt */
371      return;
265372   }
266   return 0;
373
374        /* regular keys */
375   hp48_update_kdn( machine );
267376}
268377
269#define TIMER1_VALUE hp48_hardware.data[0x37]
270HP48_HARDWARE hp48_hardware={
271   {0}
272};
378/* RSI opcode */
379void hp48_rsi( running_machine *machine )
380{
381   LOG(( "%05x %f hp48_rsi\n", activecpu_get_previouspc(), attotime_to_double(timer_get_time()) ));
273382
274void hp48_crc(running_machine *machine, int adr, int data)
383   /* enables interrupts on key repeat
384      (normally, there is only one interrupt, when the key is pressed)
385   */
386   hp48_kdn = 0;
387}
388
389
390/* ------------- annonciators ------------ */
391
392static void hp48_update_annunciators( running_machine *machine, void* param )
275393{
276   if ((hp48s.mem[HDW].adr==-1)
277      ||(adr<(hp48s.mem[HDW].adr&~0x3f))
278      ||(adr>(hp48s.mem[HDW].adr|0x3f)) )
279      hp48_hardware.crc=(hp48_hardware.crc >> 4)
280         ^ (((hp48_hardware.crc ^ data) & 0xf) * 0x1081);
281   else
282      hp48_hardware.crc=(hp48_hardware.crc >> 4)
283         ^ ((hp48_hardware.crc& 0xf) * 0x1081);
394   /* bit 0: left shift
395      bit 1: right shift
396      bit 2: alpha
397      bit 3: alert
398      bit 4: busy
399      bit 5: transmit
400      bit 7: master enable
401   */
402   int markers = HP48_IO_8(0xb);
403   output_set_value( "lshift0",   (markers & 0x81) == 0x81 );
404   output_set_value( "rshift0",   (markers & 0x82) == 0x82 );
405   output_set_value( "alpha0",    (markers & 0x84) == 0x84 );
406   output_set_value( "alert0",    (markers & 0x88) == 0x88 );
407   output_set_value( "busy0",     (markers & 0x90) == 0x90 );
408   output_set_value( "transmit0", (markers & 0xb0) == 0xb0 );
284409}
285410
286WRITE8_HANDLER( hp48_write )
411
412/* ------------- I/O registers ----------- */
413
414/* Some part of the I/O registers are simple r/w registers. We store them in hp48_io.
415   Special cases are registers that:
416   - have a different meaning on read and write
417   - perform some action on read / write
418 */
419
420static WRITE8_HANDLER ( hp48_io_w )
287421{
288   switch (offset) {
289      //lcd
290   case 0: case 1: case 2: case 3:
291   case 0xb: case 0xc:
292      hp48_hardware.data[offset]=data;
422   LOG(( "%05x %f hp48_io_w: off=%02x data=%x\n",
423         activecpu_get_previouspc(), attotime_to_double(timer_get_time()), offset, data ));
424
425   switch( offset )
426   {
427
428   /* CRC register */
429   case 0x04: hp48_crc = (hp48_crc & 0xfff0) | data; break;
430   case 0x05: hp48_crc = (hp48_crc & 0xff0f) | (data << 4); break;
431   case 0x06: hp48_crc = (hp48_crc & 0xf0ff) | (data << 8); break;
432   case 0x07: hp48_crc = (hp48_crc & 0x0fff) | (data << 12); break;
433
434   /* annunciators */
435   case 0x0b:
436   case 0x0c:
437      hp48_io[offset] = data;
438      hp48_update_annunciators( machine, NULL );
293439      break;
294   case 0x20: case 0x21: case 0x22: case 0x23: case 0x24:
295   case 0x25: case 0x26: case 0x27:
296   case 0x28: case 0x29: //wo
297   case 0x30: case 0x31: case 0x32: case 0x33: case 0x34:
298      hp48_hardware.data[offset]=data;
440
441   /* cntrl ROM */
442   case 0x29:
443   {
444      int old_cntrl = hp48_io[offset] & 8;
445      hp48_io[offset] = data;
446      if ( old_cntrl != (data & 8) )
447      {
448         hp48_apply_modules( machine, NULL );
449      }
299450      break;
300      // uart
301   case 0xd: case 0x10: case 0x11: case 0x12:
302   case 0x13: //w0
303   case 0x14: case 0x15: //r0
304   case 0x16: case 0x17: //w0
305      hp48_hardware.data[offset]=data;
451   }
452
453   /* timers */
454   case 0x37: hp48_timer1 = data; break;
455   case 0x38: hp48_timer2 = (hp48_timer2 & 0xfffffff0) | data; break;
456   case 0x39: hp48_timer2 = (hp48_timer2 & 0xffffff0f) | (data << 4); break;
457   case 0x3a: hp48_timer2 = (hp48_timer2 & 0xfffff0ff) | (data << 8); break;
458   case 0x3b: hp48_timer2 = (hp48_timer2 & 0xffff0fff) | (data << 12); break;
459   case 0x3c: hp48_timer2 = (hp48_timer2 & 0xfff0ffff) | (data << 16); break;
460   case 0x3d: hp48_timer2 = (hp48_timer2 & 0xff0fffff) | (data << 20); break;
461   case 0x3e: hp48_timer2 = (hp48_timer2 & 0xf0ffffff) | (data << 24); break;
462   case 0x3f: hp48_timer2 = (hp48_timer2 & 0x0fffffff) | (data << 28); break;
463
464   /* cards */
465   case 0x0e:
466      LOG(( "%05x: card control write %02x\n", activecpu_get_previouspc(), data ));
467      /* bit 0: software interrupt */
468      if ( data & 1 )
469      {
470         LOG(( "%f hp48_io_w: software interrupt requested\n",
471               attotime_to_double(timer_get_time()) ));
472         cpunum_set_input_line( machine, 0, SATURN_IRQ_LINE, PULSE_LINE );
473         data &= ~1;
474      }
475
476      /* XXX not implemented
477          bit 1: card test?
478       */
479
480      hp48_io[0x0e] = data;
306481      break;
307      // infrared serial
308   case 0x1a: case 0x1c: case 0x1d:
309      hp48_hardware.data[offset]=data;
482
483   case 0x0f:
484      LOG(( "%05x: card info write %02x\n", activecpu_get_previouspc(), data ));
485      hp48_io[0x0f] = data;
310486      break;
311      // timers
312   case 0x2e: case 0x2f:
313   case 0x37:
314   case 0x38: hp48_hardware.timer2=(hp48_hardware.timer2&~0xf)|data;break;
315   case 0x39: hp48_hardware.timer2=(hp48_hardware.timer2&~0xf0)|(data<<4);break;
316   case 0x3a: hp48_hardware.timer2=(hp48_hardware.timer2&~0xf00)|(data<<8);break;
317   case 0x3b: hp48_hardware.timer2=(hp48_hardware.timer2&~0xf000)|(data<<12);break;
318   case 0x3c: hp48_hardware.timer2=(hp48_hardware.timer2&~0xf0000)|(data<<16);break;
319   case 0x3d: hp48_hardware.timer2=(hp48_hardware.timer2&~0xf00000)|(data<<20);break;
320   case 0x3e: hp48_hardware.timer2=(hp48_hardware.timer2&~0xf000000)|(data<<24);break;
321   case 0x3f: hp48_hardware.timer2=(hp48_hardware.timer2&~0xf0000000)|(data<<28);break;
322      hp48_hardware.data[offset]=data;
487
488   /* serial */
489   case 0x13:
490      hp48_io[0x11] &= ~4; /* clear error status */
323491      break;
324       // cards
325   case 0xe:case 0xf:
326      hp48_hardware.data[offset]=data;
492   case 0x16:
493      /* first nibble of sent data */
494      hp48_io[offset] = data;
327495      break;
328   case 4: // crc low
329      hp48_hardware.data[offset]=data;
330      hp48_hardware.crc=(hp48_hardware.crc&~0xf)|data;
496   case 0x17:
497      /* second nibble of sent data */
498      hp48_io[offset] = data;
499      hp48_rs232_send_byte( machine );
331500      break;
332   case 5: // crc high
333      hp48_hardware.data[offset]=data;
334      hp48_hardware.crc=(hp48_hardware.crc&~0xf0)|(data<<4);
335      break;
336   case 6: // crc high
337      hp48_hardware.data[offset]=data;
338      hp48_hardware.crc=(hp48_hardware.crc&~0xf00)|(data<<8);
339      break;
340   case 7:
341      hp48_hardware.data[offset]=data;
342      hp48_hardware.crc=(hp48_hardware.crc&~0xf000)|(data<<12);
343      break;
344   case 8: //power state
345      hp48_hardware.data[offset]=data;
346      break;
347   case 9: // power control
348      // 0 rst input
349      // 1 grst input
350      // 2 enable very low batterie interrupt
351      // 3 enable low batterie interrupt
352      hp48_hardware.data[offset]=data;
353      break;
354   case 0xa: //ro chip mode
355      hp48_hardware.data[offset]=data;
356      break;
357   case 0x18: case 0x19: //lsb of service request
358      hp48_hardware.data[offset]=data;
359      break;
360   case 0x1b: // base nibble offset
361      hp48_hardware.data[offset]=data;
362      break;
363   case 0x1e: // scratch pad, used by the interrupt handler
364      hp48_hardware.data[offset]=data;
365      break;
366   case 0x1f: // IRAM@ 7 for s/sx, 8 for g/gx
367      hp48_hardware.data[offset]=data;
368      break;
369   default: //temporary for better debugging, write of ro registers
370      hp48_hardware.data[offset]=data;
501
502   /* XXX not implemented:
503
504      - 0x0d: RS232c speed:
505         bits 0-2: speed
506                  000 = 1200 bauds
507           010 = 2400 bauds
508           100 = 4800 bauds
509           110 = 9600 bauds
510              bit 3: ?
511
512           - 0x1a: I/R input
513              bit 0: irq
514         bit 1: irq enable
515         bit 2: 1=RS232c mode 0=direct mode
516         bit 3: receiving
517
518      - 0x1c: I/R output control
519         bit 0: buffer full
520         bit 1: transmitting
521         bit 2: irq enable on buffer empty
522         bit 3: led on (direct mode)
523
524      - 0x1d: I/R output buffer
525   */
526
527   default: hp48_io[offset] = data;
371528   }
529
372530}
373531
374 READ8_HANDLER( hp48_read )
532
533static READ8_HANDLER ( hp48_io_r )
375534{
376   int data=0;
377   switch (offset) {
378      // lcd
379   case 0: case 1: case 2: case 3:
380   case 9:
381      data=1; //reset
535   UINT8 data = 0;
536
537   switch( offset )
538   {
539     
540   /* CRC register */
541   case 0x04: data = hp48_crc & 0xf; break;
542   case 0x05: data = (hp48_crc >> 4) & 0xf; break;
543   case 0x06: data = (hp48_crc >> 8) & 0xf; break;
544   case 0x07: data = (hp48_crc >> 12) & 0xf; break;
545
546   /* battery test */
547   case 0x08:
548      data = 0;
549      if ( hp48_io[0x9] & 8 ) /* test enable */
550      {
551         /* XXX not implemented:
552            bit 3: battery in port 2           
553            bit 2: battery in port 1
554          */
555         switch ( input_port_read( machine, "BATTERY" ) )
556         {
557         case 1: data = 2; break; /* low */
558         case 2: data = 3; break; /* low | critical */
559         }
560      }
382561      break;
383   case 0xb: case 0xc:
384      data=hp48_hardware.data[offset];
562
563   /* remaining lines in main bitmap */
564   case 0x28:
565   case 0x29:
566   {
567      int last_line = HP48_IO_8(0x28) & 0x3f; /* last line of main bitmap before menu */
568      int cur_line = video_screen_get_vpos( machine->primary_screen );
569      if ( last_line <= 1 ) last_line = 0x3f;
570      data = ( cur_line >= 0 && cur_line <= last_line ) ? last_line - cur_line : 0;
571      if ( offset == 0x29 )
572      {
573         data >>= 4;
574         data |= HP48_IO_8(0x29) & 0xc0;
575      }
576      else
577      {
578         data &= 0xf;
579      }
385580      break;
386   case 0x28: // ro line count / rasterline?
581   }
582
583   /* timers */
584   case 0x37: data = hp48_timer1; break;
585   case 0x38: data = hp48_timer2 & 0xf; break;
586   case 0x39: data = (hp48_timer2 >> 4) & 0xf; break;
587   case 0x3a: data = (hp48_timer2 >> 8) & 0xf; break;
588   case 0x3b: data = (hp48_timer2 >> 12) & 0xf; break;
589   case 0x3c: data = (hp48_timer2 >> 16) & 0xf; break;
590   case 0x3d: data = (hp48_timer2 >> 20) & 0xf; break;
591   case 0x3e: data = (hp48_timer2 >> 24) & 0xf; break;
592   case 0x3f: data = (hp48_timer2 >> 28) & 0xf; break;
593
594   /* serial */
595   case 0x15:
596   {
597                /* second nibble of received data */
598
599      const device_config *xmodem = device_list_find_by_tag( machine->config->devicelist, XMODEM, "rs232-x" );
600      const device_config *kermit = device_list_find_by_tag( machine->config->devicelist, KERMIT, "rs232-k" );
601
602      hp48_io[0x11] &= ~1;  /* clear byte received */
603      data = hp48_io[offset];
604     
605      /* protocol action */
606      if ( xmodem && image_exists( xmodem ) ) xmodem_byte_transmitted( xmodem );
607      else if ( kermit && image_exists( kermit ) ) kermit_byte_transmitted( kermit );
387608      break;
388   case 0x29: // ro line count / rasterline?
609   }
610
611   /* cards */
612   case 0x0e: /* detection */
613      data = hp48_io[0x0e];
614      LOG(( "%05x: card control read %02x\n", activecpu_get_previouspc(), data ));
389615      break;
390      // cards
391   case 0xe:case 0xf:
392      data=hp48_hardware.data[offset];
616   case 0x0f: /* card info */
617      data = 0;
618      if ( HP48_G_SERIES )
619      {
620         if ( hp48_port_size[1] ) data |= 1;
621         if ( hp48_port_size[0] ) data |= 2;
622         if ( hp48_port_size[1] && hp48_port_write[1] ) data |= 4;
623         if ( hp48_port_size[0] && hp48_port_write[0] ) data |= 8;
624      }
625      else
626      {
627         if ( hp48_port_size[0] ) data |= 1;
628         if ( hp48_port_size[1] ) data |= 2;
629         if ( hp48_port_size[0] && hp48_port_write[0] ) data |= 4;
630         if ( hp48_port_size[1] && hp48_port_write[1] ) data |= 8;
631      }
632      LOG(( "%05x: card info read %02x\n", activecpu_get_previouspc(), data ));
393633      break;
394   case 4: data=hp48_hardware.crc&0xf;break;
395   case 5: data=(hp48_hardware.crc>>4)&0xf;break;
396   case 6: data=(hp48_hardware.crc>>8)&0xf;break;
397   case 7: data=(hp48_hardware.crc>>12)&0xf;break;
398   case 0x38: data=hp48_hardware.timer2&0xf;break;
399   case 0x39: data=(hp48_hardware.timer2>>4)&0xf;break;
400   case 0x3a: data=(hp48_hardware.timer2>>8)&0xf;break;
401   case 0x3b: data=(hp48_hardware.timer2>>12)&0xf;break;
402   case 0x3c: data=(hp48_hardware.timer2>>16)&0xf;break;
403   case 0x3d: data=(hp48_hardware.timer2>>20)&0xf;break;
404   case 0x3e: data=(hp48_hardware.timer2>>24)&0xf;break;
405   case 0x3f: data=(hp48_hardware.timer2>>28)&0xf;break;
406   default: //temporary for better debugging, read of wo registers
407      data=hp48_hardware.data[offset];
634
635
636   default: data = hp48_io[offset];
408637   }
638
639   LOG(( "%05x %f hp48_io_r: off=%02x data=%x\n",
640         activecpu_get_previouspc(), attotime_to_double(timer_get_time()), offset, data ));
409641   return data;
410642}
411643
412static TIMER_CALLBACK(hp48_timer)
644
645/* ---------- GX's bank switcher --------- */
646
647static READ8_HANDLER ( hp48_bank_r )
413648{
414   static int delay=256;
415   if (--delay==0) {
416      delay=256;
417      TIMER1_VALUE=(TIMER1_VALUE-1)&0xf;
418      if (TIMER1_VALUE==0) {
419      }
649   /* bit 0: ignored, bits 2-5: bank number, bit 6: enable */
650   offset &= 0x7e;
651   if ( hp48_bank_switch != offset )
652   {
653      LOG(( "%05x %f hp48_bank_r: off=%03x\n", activecpu_get_previouspc(), attotime_to_double(timer_get_time()), offset ));
654      hp48_bank_switch = offset;
655      hp48_apply_modules( machine, NULL );
420656   }
421   hp48_hardware.timer2--;
422   if (hp48_hardware.timer2==0) {
657   return 0;
658}
659
660
661/* ---------------- timers --------------- */
662
663static TIMER_CALLBACK( hp48_timer1_cb )
664{
665   if ( !(hp48_io[0x2f] & 1) ) return; /* timer enable */
666
667   hp48_timer1 = (hp48_timer1 - 1) & 0xf;
668
669   /* wake-up on carry */
670   if ( (hp48_io[0x2e] & 4) && (hp48_timer1 == 0xf) )
671   {
672      LOG(( "wake-up on timer1\n" ));
673      hp48_io[0x2e] |= 8;                                      /* set service request */
674      hp48_io[0x18] |= 4;                                      /* set service request */
675      cpunum_set_input_line( machine, 0, SATURN_WAKEUP_LINE, PULSE_LINE ); /* wake-up */
423676   }
677   /* interrupt on carry */
678   if ( (hp48_io[0x2e] & 2) && (hp48_timer1 == 0xf) )
679   {
680      LOG(( "generate timer1 interrupt\n" ));
681      hp48_io[0x2e] |= 8; /* set service request */
682      hp48_io[0x18] |= 4; /* set service request */
683      cpunum_set_input_line(machine, 0, SATURN_NMI_LINE, PULSE_LINE);
684   }
424685}
425686
426void hp48_out(running_machine *machine, int v)
687static TIMER_CALLBACK( hp48_timer2_cb )
427688{
428   out=v;
689   if ( !(hp48_io[0x2f] & 1) ) return; /* timer enable */
690
691   hp48_timer2 = (hp48_timer2 - 1) & 0xffffffff;
692
693   /* wake-up on carry */
694   if ( (hp48_io[0x2f] & 4) && (hp48_timer2 == 0xffffffff) )
695   {
696      LOG(( "wake-up on timer2\n" ));
697      hp48_io[0x2f] |= 8;                                      /* set service request */
698      hp48_io[0x18] |= 4;                                      /* set service request */
699      cpunum_set_input_line( machine, 0, SATURN_WAKEUP_LINE, PULSE_LINE ); /* wake-up */
700   }
701   /* interrupt on carry */
702   if ( (hp48_io[0x2f] & 2) && (hp48_timer2 == 0xffffffff) )
703   {
704      LOG(( "generate timer2 interrupt\n" ));
705      hp48_io[0x2f] |= 8;                                      /* set service request */
706      hp48_io[0x18] |= 4;                                      /* set service request */
707      cpunum_set_input_line(machine, 0, SATURN_NMI_LINE, PULSE_LINE);
708   }
429709}
430710
431int hp48_in(running_machine *machine)
711
712
713
714/* --------- memory controller ----------- */
715
716/*
717   Clark (S series) and York (G series) CPUs have 6 daisy-chainedmodules
718
719
720   <-- highest --------- priority ------------- lowest -->
721
722   CPU ---------------------------------------------------
723            |      |      |          |          |        |
724           HDW    NCE2   CE1        CE2        NCE3     NCE1
725
726
727   However, controller usage is different in both series:
728
729
730      controller     S series        G series
731                    (Clark CPU)     (York CPU)
732
733         HDW         I/O RAM          I/O RAM
734        NCE2           RAM              RAM
735         CE1           port1        bank switcher
736         CE2           port2           port1
737        NCE3          unused           port2
738        NCE1           ROM              ROM
739
740
741   - NCE1 (ROM) cannot be configured, it is always visible at addresses
742   00000-7ffff not covered by higher priority modules.
743
744   - only the address of HDW (I/O) can be configured, its size is constant
745   (64 nibbles)
746
747   - other modules can have their address & size set
748
749 */
750
751
752/* remap all modules according to hp48_modules */
753static void hp48_apply_modules( running_machine *machine, void* param )
432754{
433   int data=0;
434#if 1
435   if (out&0x100) {
436      if (KEY_B) data|=0x10;
437      if (KEY_C) data|=8;
438      if (KEY_D) data|=4;
439      if (KEY_E) data|=2;
440      if (KEY_F) data|=1;
755   int i;
756   int nce2_enable = 1;
757
758   hp48_io_addr = 0x100000;
759
760   if ( HP48_G_SERIES )
761   {
762      /* port 2 bank switch */
763      if ( hp48_port_size[1] > 0 )
764      {
765         int off = (hp48_bank_switch << 16) % hp48_port_size[1];
766         hp48_modules[4].data = hp48_port_data[1] + off;
767      }
768
769      /* ROM A19 (hi 256 KB) / NCE2 (port 2) control switch */
770      if ( hp48_io[0x29] & 8 )
771      {
772         /* A19 */
773         hp48_modules[5].off_mask = 0xfffff;
774         nce2_enable = 0;
775      }
776      else
777      {
778         /* NCE2 */
779         hp48_modules[5].off_mask = 0x7ffff;
780         nce2_enable = hp48_bank_switch >> 6;
781      }
441782   }
442   if (out&0x80) {
443      if (KEY_H) data|=0x10;
444      if (KEY_I) data|=8;
445      if (KEY_J) data|=4;
446      if (KEY_K) data|=2;
447      if (KEY_L) data|=1;
783
784   /* S series ROM mapping compatibility */
785   if ( HP48_S_SERIES || !(hp48_io[0x29] & 8) )
786   {
787      hp48_modules[5].off_mask = 0x7ffff;
448788   }
449   if (out&0x40) {
450      if (KEY_N) data|=0x10;
451      if (KEY_O) data|=8;
452      if (KEY_P) data|=4;
453      if (KEY_Q) data|=2;
454      if (KEY_R) data|=1;
789   else
790   {
791      hp48_modules[5].off_mask = 0xfffff;
455792   }
456   if (out&0x20) {
457      if (KEY_T) data|=0x10;
458      if (KEY_U) data|=8;
459      if (KEY_V) data|=4;
460      if (KEY_W) data|=2;
461      if (KEY_X) data|=1;
793
794   /* from lowest to highest priority */
795   for ( i = 5; i >= 0; i-- )
796   {
797      UINT32 select_mask = hp48_modules[i].mask;
798      UINT32 nselect_mask = ~select_mask & 0xfffff;
799      UINT32 base = hp48_modules[i].base;
800      UINT32 off_mask = hp48_modules[i].off_mask;
801      UINT32 mirror = nselect_mask & ~off_mask;
802      UINT32 end = base + (off_mask & nselect_mask);
803
804      if ( hp48_modules[i].state != HP48_MODULE_CONFIGURED ) continue;
805
806      if ( (i == 4) && !nce2_enable ) continue;
807
808      /* our code assumes that the 20-bit select_mask is all 1s followed by all 0s */
809      if ( nselect_mask & (nselect_mask+1) )
810      {
811         logerror( "hp48_mem_config: invalid mask %05x for module %s\n",
812              select_mask, hp48_module_names[i] );
813         continue;
814      }
815      memory_install_read8_handler( machine, 0, ADDRESS_SPACE_PROGRAM, base, end, 0, mirror, hp48_modules[i].read );
816      memory_install_write8_handler( machine, 0, ADDRESS_SPACE_PROGRAM, base, end, 0, mirror, hp48_modules[i].write );
817
818      LOG(( "hp48_mem_config: module %s configured at %05x-%05x, mirror %05x\n",
819            hp48_module_names[i], base, end, mirror ));
820
821      if ( hp48_modules[i].data )
822      {
823         memory_set_bankptr( i, hp48_modules[i].data );
824      }
825
826      if ( i == 0 )
827      {
828         hp48_io_addr = base;
829      }
462830   }
463   if (out&0x10) {
464      if (KEY_ON) data|=0x20;
465      if (KEY_ENTER) data|=0x10;
466      if (KEY_Y) data|=8;
467      if (KEY_Z) data|=4;
468      if (KEY_DEL) data|=2;
469      if (KEY_LEFT) data|=1;
831}
832
833
834/* reset the configuration */
835static void hp48_reset_modules( running_machine *machine )
836{
837   int i;
838   /* fixed size for HDW */
839   hp48_modules[0].state = HP48_MODULE_MASK_KNOWN;
840   hp48_modules[0].mask = 0xfffc0;
841   /* unconfigure NCE2, CE1, CE2, NCE3 */
842   for ( i = 1; i < 5; i++ )
843   {
844      hp48_modules[i].state = HP48_MODULE_UNCONFIGURED;
470845   }
471   if (out&8) {
472      if (KEY_ALPHA) data|=0x20;
473      if (KEY_S) data|=0x10;
474      if (KEY_7) data|=8;
475      if (KEY_8) data|=4;
476      if (KEY_9) data|=2;
477      if (KEY_DIVIDE) data|=1;
846
847   /* fixed configuration for NCE1 */
848   hp48_modules[5].state = HP48_MODULE_CONFIGURED;
849   hp48_modules[5].base = 0;
850   hp48_modules[5].mask = 0;
851
852   hp48_apply_modules( machine, NULL );
853}
854
855
856/* RESET opcode */
857void hp48_mem_reset( running_machine* machine )
858{
859   LOG(( "%05x %f hp48_mem_reset\n", activecpu_get_previouspc(), attotime_to_double(timer_get_time()) ));
860   hp48_reset_modules( machine );
861}
862
863
864/* CONFIG opcode */
865void hp48_mem_config( running_machine* machine, int v )
866{   
867   int i;
868
869   LOG(( "%05x %f hp48_mem_config: %05x\n", activecpu_get_previouspc(), attotime_to_double(timer_get_time()), v ));
870
871   /* find the highest priority unconfigured module (except non-configurable NCE1)... */
872   for ( i = 0; i < 5; i++ )
873   {
874      /* ... first call sets the address mask */
875      if ( hp48_modules[i].state == HP48_MODULE_UNCONFIGURED )
876      {
877         hp48_modules[i].mask = v & 0xff000;
878         hp48_modules[i].state = HP48_MODULE_MASK_KNOWN;
879         break;
880      }
881
882      /* ... second call sets the base address */
883      if ( hp48_modules[i].state == HP48_MODULE_MASK_KNOWN )
884      {
885         hp48_modules[i].base = v & hp48_modules[i].mask;
886         hp48_modules[i].state = HP48_MODULE_CONFIGURED;
887         LOG(( "hp48_mem_config: module %s configured base=%05x, mask=%05x\n",
888               hp48_module_names[i], hp48_modules[i].base, hp48_modules[i].mask ));
889         hp48_apply_modules( machine, NULL );
890         break;
891      }
478892   }
479   if (out&4) {
480      if (KEY_ORANGE) data|=0x20;
481      if (KEY_G) data|=0x10;
482      if (KEY_4) data|=8;
483      if (KEY_5) data|=4;
484      if (KEY_6) data|=2;
485      if (KEY_MULTIPLY) data|=1;
893}
894
895
896/* UNCFG opcode */
897void hp48_mem_unconfig( running_machine* machine, int v )
898{   
899   int i;
900   LOG(( "%05x %f hp48_mem_unconfig: %05x\n", activecpu_get_previouspc(), attotime_to_double(timer_get_time()), v ));
901
902   /* find the highest priority fully configured module at address v (except NCE1)... */
903   for ( i = 0; i < 5; i++ )
904   {
905      /* ... and unconfigure it */
906      if ( hp48_modules[i].state == HP48_MODULE_CONFIGURED &&
907           (hp48_modules[i].base == (v & hp48_modules[i].mask)) )
908      {
909         hp48_modules[i].state = i> 0 ? HP48_MODULE_UNCONFIGURED : HP48_MODULE_MASK_KNOWN;
910         LOG(( "hp48_mem_unconfig: module %s\n", hp48_module_names[i] ));
911         hp48_apply_modules( machine, NULL );
912         break;
913      }
486914   }
487   if (out&2) {
488      if (KEY_BLUE) data|=0x20;
489      if (KEY_A) data|=0x10;
490      if (KEY_1) data|=8;
491      if (KEY_2) data|=4;
492      if (KEY_3) data|=2;
493      if (KEY_MINUS) data|=1;
915}
916
917
918/* C=ID opcode */
919int  hp48_mem_id( running_machine* machine )
920{
921   int i;
922   int data = 0; /* 0 = everything is configured */
923
924   /* find the highest priority unconfigured module (except NCE1)... */
925   for ( i = 0; i < 5; i++ )
926   {
927      /* ... mask need to be configured */
928      if ( hp48_modules[i].state == HP48_MODULE_UNCONFIGURED )
929      {
930         data = hp48_module_mask_id[i] | (hp48_modules[i].mask & ~0xff);
931         break;
932      }
933
934      /* ... address need to be configured */
935      if ( hp48_modules[i].state == HP48_MODULE_MASK_KNOWN )
936      {
937         data = hp48_module_addr_id[i] | (hp48_modules[i].base & ~0x3f);
938         break;
939      }
494940   }
495   if (out&1) {
496      if (KEY_M) data|=0x10;
497      if (KEY_0) data|=8;
498      if (KEY_POINT) data|=4;
499      if (KEY_SPC) data|=2;
500      if (KEY_PLUS) data|=1;
941
942   LOG(( "%05x %f hp48_mem_id = %02x\n",
943         activecpu_get_previouspc(), attotime_to_double(timer_get_time()), data ));
944
945   return data; /* everything is configured */
946}
947
948
949
950/* --------- CRC ---------- */
951
952/* each memory read by the CPU updates the internal CRC state */
953void hp48_mem_crc( running_machine* machine, int addr, int data )
954{
955   /* no CRC for I/O RAM */
956   if ( addr >= hp48_io_addr && addr < hp48_io_addr + 0x40 ) return;
957
958   hp48_crc = (hp48_crc >> 4) ^ (((hp48_crc ^ data) & 0xf) * 0x1081);
959}
960
961
962
963/* ------ utilities ------- */
964
965
966/* decodes size bytes into 2*size nibbles (lowest significant first) */
967static void hp48_decode_nibble( UINT8* dst, UINT8* src, int size )
968{
969   int i;
970   for ( i=size-1; i >= 0; i-- )
971   {
972      dst[2*i+1] = src[i] >> 4;
973      dst[2*i] = src[i] & 0xf;
501974   }
502#else
503   if (out&0x100) data|=input_port_read_indexed(machine, 0);
504   if (out&0x080) data|=input_port_read_indexed(machine, 1);
505   if (out&0x040) data|=input_port_read_indexed(machine, 2);
506   if (out&0x020) data|=input_port_read_indexed(machine, 3);
507   if (out&0x010) data|=input_port_read_indexed(machine, 4);
508   if (out&0x008) data|=input_port_read_indexed(machine, 5);
509   if (out&0x004) data|=input_port_read_indexed(machine, 6);
510   if (out&0x002) data|=input_port_read_indexed(machine, 7);
511   if (out&0x001) data|=input_port_read_indexed(machine, 8);
512#endif
513   return data;
514975}
515976
516DRIVER_INIT( hp48s )
977/* inverse of hp48_decode_nibble  */
978static void hp48_encode_nibble( UINT8* dst, UINT8* src, int size )
517979{
518   int i,j,t;
519   UINT8 *mem=memory_region(REGION_CPU1);
520   for (i=0x3ffff,j=0x7fffe; i>=0;i--,j-=2) {
521      t=mem[i];
522      mem[j+1]=t>>4;
523      mem[j]=t&0xf;
980   int i;
981   for ( i=0; i < size; i++ )
982   {
983      dst[i] = (src[2*i] & 0xf) | (src[2*i+1] << 4);
524984   }
525   memset(mem+0x80000, 0, 0x80000); //unused area must be 0!
526   memset(mem+0x140000, 0, 0x40000); //unused area must be 0!
527   memset(mem+0x180000, 0, 0x40000); //unused area must be 0!
985}
528986
529   hp48_ram=memory_region(REGION_CPU1)+0x100000;
530   hp48_card1=memory_region(REGION_CPU1)+0x140000;
531   hp48_card2=memory_region(REGION_CPU1)+0x180000;
532987
533   timer_pulse(ATTOTIME_IN_HZ(8192), NULL, 0, hp48_timer);
988
989/* ----- card images ------ */
990
991/* port information configurations */
992struct hp48_port_config hp48sx_port1_config = { 0, 2,    128*1024, "p1", "port1" };
993struct hp48_port_config hp48sx_port2_config = { 1, 3,    128*1024, "p2", "port2" };
994struct hp48_port_config hp48gx_port1_config = { 0, 3,    128*1024, "p1", "port1" };
995struct hp48_port_config hp48gx_port2_config = { 1, 4, 4*1024*1024, "p2", "port2" };
996
997/* helper for load and create */
998static void hp48_fill_port( const device_config* image )
999{
1000   struct hp48_port_config* conf = (struct hp48_port_config*) image->static_config;
1001   int size = hp48_port_size[conf->port];
1002   LOG(( "hp48_fill_port: %s module=%i size=%i rw=%i\n", conf->name, conf->module, size, hp48_port_write[conf->port] ));
1003   hp48_port_data[conf->port] = malloc( 2 * size );
1004   memset( hp48_port_data[conf->port], 0, 2 * size );
1005   hp48_modules[conf->module].off_mask = 2 * (( size > 128 * 1024 ) ? 128 * 1024 : size) - 1;
1006   hp48_modules[conf->module].read     = SMH_BANK(conf->module);
1007   hp48_modules[conf->module].write    = hp48_port_write[conf->port] ? (void*)SMH_BANK(conf->module) : SMH_NOP;
1008   hp48_modules[conf->module].data     = hp48_port_data[conf->port];
1009   hp48_apply_modules( image->machine, NULL );
5341010}
5351011
536DRIVER_INIT( hp48g )
1012/* helper for start and unload */
1013static void hp48_unfill_port( const device_config* image )
5371014{
538   int i,j,t;
539   UINT8 *mem=memory_region(REGION_CPU1);
540   UINT8 *gfx=memory_region(REGION_GFX1);
1015   struct hp48_port_config* conf = (struct hp48_port_config*) image->static_config;
1016   hp48_modules[conf->module].off_mask = 0x00fff;  /* 2 KB */
1017   hp48_modules[conf->module].read     = SMH_UNMAP;
1018   hp48_modules[conf->module].write    = SMH_UNMAP;
1019   hp48_modules[conf->module].data     = NULL;
1020}
5411021
542   for (i=0x7ffff,j=0xffffe; i>=0;i--,j-=2) {
543      t=mem[i];
544      mem[j]=t>>4;
545      mem[j+1]=t&0xf;
1022
1023static DEVICE_IMAGE_LOAD( hp48_port )
1024{
1025   struct hp48_port_config* conf = (struct hp48_port_config*) image->static_config;
1026   int size = image_length( image );
1027   if ( size == 0 ) size = conf->max_size; /* default size */
1028
1029   /* check size */
1030   if ( (size < 32*1024) || (size > conf->max_size) || (size & (size-1)) )
1031   {
1032      logerror( "hp48: image size for %s should be a power of two between %i and %i\n", conf->name, 32*1024, conf->max_size );
1033      return INIT_FAIL;
5461034   }
547   for (i=0; i<256; i++) gfx[i]=i;
5481035
549   hp48_ram=memory_region(REGION_CPU1)+0x100000;
550   hp48_card1=memory_region(REGION_CPU1)+0x140000;
551   hp48_card2=memory_region(REGION_CPU1)+0x180000;
1036   hp48_port_size[conf->port] = size;
1037   hp48_port_write[conf->port] = image_is_writable( image );
1038   hp48_fill_port( image );
1039   image_fread( image, hp48_port_data[conf->port], hp48_port_size[conf->port] );
1040   hp48_decode_nibble( hp48_port_data[conf->port], hp48_port_data[conf->port], hp48_port_size[conf->port] );
1041   return INIT_PASS;
1042}
5521043
553   timer_pulse(ATTOTIME_IN_HZ(8192), NULL, 0, hp48_timer);
1044static DEVICE_IMAGE_CREATE( hp48_port )
1045{
1046   struct hp48_port_config* conf = (struct hp48_port_config*) image->static_config;
1047   int size = conf->max_size;
1048        /* XXX defaults to max_size; get user-specified size instead */
1049
1050   /* check size */
1051   /* size must be a power of 2 between 32K and max_size */
1052   if ( (size < 32*1024) || (size > conf->max_size) || (size & (size-1)) )
1053   {
1054      logerror( "hp48: image size for %s should be a power of two between %i and %i\n", conf->name, 32*1024, conf->max_size );
1055      return INIT_FAIL;
1056   }   
1057
1058   hp48_port_size[conf->port] = size;   
1059   hp48_port_write[conf->port] = 1;
1060   hp48_fill_port( image );
1061   return INIT_PASS;
5541062}
5551063
1064static DEVICE_IMAGE_UNLOAD( hp48_port )
1065{
1066   struct hp48_port_config* conf = (struct hp48_port_config*) image->static_config;
1067   LOG(( "hp48_port image unload: %s size=%i rw=%i\n",
1068         conf->name, hp48_port_size[conf->port] ,hp48_port_write[conf->port] ));
1069   if ( hp48_port_write[conf->port] )
1070   {
1071      hp48_encode_nibble( hp48_port_data[conf->port], hp48_port_data[conf->port], hp48_port_size[conf->port] );
1072      image_fseek( image, 0, SEEK_SET );
1073      image_fwrite( image, hp48_port_data[conf->port], hp48_port_size[conf->port] );
1074   }
1075   free( hp48_port_data[conf->port] );
1076   hp48_unfill_port( image );
1077   hp48_apply_modules( image->machine, NULL );
1078}
1079
1080static DEVICE_START( hp48_port )
1081{
1082   hp48_unfill_port( device );
1083}
1084
1085DEVICE_GET_INFO( hp48_port )
1086{
1087   struct hp48_port_config* conf = device ? (struct hp48_port_config*) device->static_config : NULL;
1088   switch ( state )
1089   {
1090   case DEVINFO_INT_TOKEN_BYTES:                 info->i = 1;                                               break;
1091   case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                                               break;
1092   case DEVINFO_INT_CLASS:                         info->i = DEVICE_CLASS_PERIPHERAL;                         break;
1093   case DEVINFO_INT_IMAGE_TYPE:                 info->i = IO_MEMCARD;                                      break;
1094   case DEVINFO_INT_IMAGE_READABLE:              info->i = 1;                                               break;
1095   case DEVINFO_INT_IMAGE_WRITEABLE:         info->i = 1;                                               break;
1096   case DEVINFO_INT_IMAGE_CREATABLE:         info->i = 1;                                               break;
1097   case DEVINFO_FCT_START:                    info->start = DEVICE_START_NAME( hp48_port );              break;
1098   case DEVINFO_FCT_IMAGE_LOAD:            info->f = (genf *) DEVICE_IMAGE_LOAD_NAME( hp48_port );    break;
1099   case DEVINFO_FCT_IMAGE_UNLOAD:            info->f = (genf *) DEVICE_IMAGE_UNLOAD_NAME( hp48_port );  break;
1100   case DEVINFO_FCT_IMAGE_CREATE:            info->f = (genf *) DEVICE_IMAGE_CREATE_NAME( hp48_port );  break;
1101   case DEVINFO_STR_IMAGE_BRIEF_INSTANCE_NAME:   info->s = conf ? conf->brief_name : "";                    break;
1102   case DEVINFO_STR_IMAGE_INSTANCE_NAME:         info->s = conf ? conf->name : "";                          break;
1103   case DEVINFO_STR_NAME:                    info->s = "HP48 memory card";                            break;
1104   case DEVINFO_STR_FAMILY:                      info->s = "HP48 memory card";                            break;
1105   case DEVINFO_STR_SOURCE_FILE:            info->s = __FILE__;                                        break;
1106   case DEVINFO_STR_IMAGE_FILE_EXTENSIONS:         info->s = "crd";                                           break;
1107   }
1108}
1109
1110
1111
1112
1113/***************************************************************************
1114    MACHINES
1115***************************************************************************/
1116
1117DRIVER_INIT( hp48 )
1118{
1119   int i;
1120   LOG(( "hp48: driver init called\n" ));
1121   for ( i = 0; i < 6; i++ )
1122   {
1123      hp48_modules[i].off_mask = 0x00fff;  /* 2 KB */
1124      hp48_modules[i].read     = SMH_UNMAP;
1125      hp48_modules[i].write    = SMH_UNMAP;
1126      hp48_modules[i].data     = NULL;
1127   }
1128   hp48_port_size[0] = 0;
1129   hp48_port_size[1] = 0;
1130}
1131
5561132MACHINE_RESET( hp48 )
5571133{
558   hp48_mem_reset(machine);
1134   LOG(( "hp48: machine reset called\n" ));
1135   hp48_reset_modules( machine );
1136   hp48_update_annunciators( machine, NULL );
5591137}
1138
1139static void hp48_machine_start( running_machine *machine, hp48_models model )
1140{
1141   UINT8* rom, *ram;
1142   int ram_size, rom_size, i;
1143
1144   LOG(( "hp48_machine_start: model %i\n", model ));
1145
1146   hp48_model = model;
1147
1148   /* internal RAM */
1149   ram_size = HP48_GX_MODEL ? (128 * 1024) : (32 * 1024);
1150   generic_nvram_size = 2 * ram_size;
1151   generic_nvram = auto_malloc( generic_nvram_size );
1152   ram = (UINT8*) generic_nvram;
1153   memset( generic_nvram, 0, generic_nvram_size );
1154
1155   /* ROM load */
1156   rom_size = HP48_S_SERIES ? (256 * 1024) : (512 * 1024);
1157   rom = auto_malloc( 2 * rom_size );
1158   hp48_decode_nibble( rom, memory_region( REGION_CPU1 ), rom_size );
1159
1160   /* init state */
1161   memset( generic_nvram, 0, generic_nvram_size );
1162   memset( hp48_io, 0, sizeof( hp48_io ) );
1163   hp48_out = 0;
1164   hp48_kdn = 0;
1165   hp48_crc = 0;
1166   hp48_timer1 = 0;
1167   hp48_timer2 = 0;
1168   hp48_bank_switch = 0;
1169
1170   /* static module configuration */
1171
1172   /* I/O RAM */
1173   hp48_modules[0].off_mask = 0x0003f;  /* 32 B */
1174   hp48_modules[0].read     = hp48_io_r;
1175   hp48_modules[0].write    = hp48_io_w;
1176
1177   /* internal RAM */
1178   hp48_modules[1].off_mask = 2 * ram_size - 1;
1179   hp48_modules[1].read     = SMH_BANK1;
1180   hp48_modules[1].write    = SMH_BANK1;
1181   hp48_modules[1].data     = ram;
1182
1183   if ( HP48_G_SERIES )
1184   {
1185                /* bank switcher */
1186      hp48_modules[2].off_mask = 0x00fff;  /* 2 KB */
1187      hp48_modules[2].read     = hp48_bank_r;
1188   }
1189
1190   /* ROM */
1191   hp48_modules[5].off_mask = 2 * rom_size - 1;
1192   hp48_modules[5].read     = SMH_BANK5;
1193   hp48_modules[5].data     = rom;
1194
1195   /* timers */
1196   timer_pulse( ATTOTIME_IN_HZ( 16 ),   NULL, 0, hp48_timer1_cb );
1197   timer_pulse( ATTOTIME_IN_HZ( 8192 ), NULL, 0, hp48_timer2_cb );
1198
1199   /* 1ms keyboard polling */
1200   timer_pulse( ATTOTIME_IN_MSEC( 1 ), NULL, 0, hp48_kbd_cb );
1201
1202   /* save state */
1203   state_save_register_global( hp48_out );
1204   state_save_register_global( hp48_kdn );
1205   state_save_register_global( hp48_io_addr );
1206   state_save_register_global( hp48_crc );
1207   state_save_register_global( hp48_timer1 );
1208   state_save_register_global( hp48_timer2 );
1209   state_save_register_global( hp48_bank_switch );
1210   for ( i = 0; i < 6; i++ )
1211   {
1212      state_save_register_item( "globals", i, hp48_modules[i].state );
1213      state_save_register_item( "globals", i, hp48_modules[i].base );
1214      state_save_register_item( "globals", i, hp48_modules[i].mask );
1215   }
1216   state_save_register_global_array( hp48_io );
1217   state_save_register_global_pointer( generic_nvram, generic_nvram_size );
1218
1219   state_save_register_postload( machine, hp48_update_annunciators, NULL );
1220   state_save_register_postload( machine, hp48_apply_modules, NULL );
1221
1222#ifdef CHARDEV
1223   /* direct I/O */
1224   hp48_chardev = chardev_open_pty( machine, &hp48_chardev_iface );
1225#endif
1226}
1227
1228
1229MACHINE_START( hp48s )
1230{
1231   hp48_machine_start( machine, HP48_S );
1232}
1233
1234
1235MACHINE_START( hp48sx )
1236{
1237   hp48_machine_start( machine, HP48_SX );
1238}
1239
1240
1241MACHINE_START( hp48g )
1242{
1243   hp48_machine_start( machine, HP48_G );
1244}
1245
1246MACHINE_START( hp48gx )
1247{
1248   hp48_machine_start( machine, HP48_GX );
1249}
1250
src/mess/mess.mak
r2838r2839
996996$(MESSOBJ)/hp48.a:     \
997997   $(MESS_MACHINE)/hp48.o     \
998998   $(MESS_VIDEO)/hp48.o     \
999   $(MESS_DRIVERS)/hp48.o
999   $(MESS_DRIVERS)/hp48.o \
1000   $(MESS_DEVICES)/xmodem.o \
1001   $(MESS_DEVICES)/kermit.o \
10001002
10011003$(MESSOBJ)/aquarius.a: \
10021004   $(MESS_DRIVERS)/aquarius.o   \
src/mess/drivers/hp48.c
r2838r2839
1/******************************************************************************
2 hp48
3 Peter.Trauner@jk.uni-linz.ac.at May 2000
4******************************************************************************/
1/**********************************************************************
52
3  Copyright (C) Antoine Mine' 2008
4
5   Hewlett Packard HP48 S/SX & G/GX
6
7**********************************************************************/
8
69#include "driver.h"
10#include "timer.h"
11#include "state.h"
12#include "device.h"
13
14#include "devices/xmodem.h"
15#include "devices/kermit.h"
716#include "cpu/saturn/saturn.h"
817
918#include "includes/hp48.h"
1019
11/* hp28s
12 0-0x3ffff rom
13 0xc0000- 0xcffff ram also mapped at 0xd0000-0xdffff */
20/* TODO:
21   - IR I/O port
22   - HP48 to HP48 serial connection
23   - set card size when creating a new card image
24   - some bits I/O RAM not implemented
25   - printer
26   - more accurate timing (accurate SATURN cycles, speedup when screen is off)
27   - save-state: figure what RAM to store & where (currently, when exiting,
28   base RAM is saved as nvram, RAM in expansion ports is saved as image,
29   IO RAM is & CPU state are discarded; save-state saves base & IO RAM,
30   CPU state, but not expansion port RAM)
31*/
1432
15static ADDRESS_MAP_START(hp48_mem, ADDRESS_SPACE_PROGRAM, 8)
16   AM_RANGE( 0x00000, 0xfffff) AM_ROM AM_WRITE( hp48_mem_w ) // configured at runtime, complexe mmu
17ADDRESS_MAP_END
1833
34/*
35  HP48: graphical calculators by Hewlett Packard.
1936
20static INPUT_PORTS_START( hp48s )
21#if 1
22   PORT_START
23   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("        A") PORT_CODE(KEYCODE_A)
24   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("        B") PORT_CODE(KEYCODE_B)
25   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("        C") PORT_CODE(KEYCODE_C)
26   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("        D") PORT_CODE(KEYCODE_D)
27   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("        E") PORT_CODE(KEYCODE_E)
28   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("        F") PORT_CODE(KEYCODE_F)
29   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("MTH     G       PRINT") PORT_CODE(KEYCODE_G)
30   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("PRG     H       I/0") PORT_CODE(KEYCODE_H)
31   PORT_START
32   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("CST     I       MODES") PORT_CODE(KEYCODE_I)
33   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("VAR     J       MEMORY") PORT_CODE(KEYCODE_J)
34   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("up      K       LIBRARY") PORT_CODE(KEYCODE_K) PORT_CODE(KEYCODE_UP)
35   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("NXT     L       PREV") PORT_CODE(KEYCODE_L)
36   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("'       M       UP      HOME") PORT_CODE(KEYCODE_M)
37   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("STO     N       DEF     RCL") PORT_CODE(KEYCODE_N)
38   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("EVAL    O       ->Q     ->NUM") PORT_CODE(KEYCODE_P)
39   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("left    P       GRAPH") PORT_CODE(KEYCODE_P) PORT_CODE(KEYCODE_LEFT)
40   PORT_START
41   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("down    Q       REVIEW") PORT_CODE(KEYCODE_Q) PORT_CODE(KEYCODE_DOWN)
42   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("right   R       SWAP") PORT_CODE(KEYCODE_R) PORT_CODE(KEYCODE_RIGHT)
43   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("SIN     S       ASIN    a") PORT_CODE(KEYCODE_S)
44   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("COS     T       ACOS    Integral") PORT_CODE(KEYCODE_T)
45   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("TAN     U       ATAN    sum") PORT_CODE(KEYCODE_U)
46   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("sqrt    V       square  root") PORT_CODE(KEYCODE_V)
47   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("power   W       10^x    LOG") PORT_CODE(KEYCODE_W)
48   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("1/x     X       e^x     LN") PORT_CODE(KEYCODE_X)
49   PORT_START
50   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("ENTER           EQUATION MATRIX") PORT_CODE(KEYCODE_ENTER) PORT_CODE(KEYCODE_ENTER_PAD)
51   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("+/-     Y       EDIT    VISIT") PORT_CODE(KEYCODE_Y)
52   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("EEX     Z       2D      3D") PORT_CODE(KEYCODE_Z)
53   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("DEL             PURGE") PORT_CODE(KEYCODE_DEL)
54   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("<--             DROP    CLR") PORT_CODE(KEYCODE_BACKSPACE)
55   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("alpha           USR     ENTRY") PORT_CODE(KEYCODE_LSHIFT) PORT_CODE(KEYCODE_RSHIFT)
56   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("7               SOLVE") PORT_CODE(KEYCODE_7) PORT_CODE(KEYCODE_7_PAD)
57   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("8               PLOT") PORT_CODE(KEYCODE_8) PORT_CODE(KEYCODE_8_PAD)
58   PORT_START
59   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("9               ALGEBRA") PORT_CODE(KEYCODE_9) PORT_CODE(KEYCODE_9_PAD)
60   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("divide          ()      #") PORT_CODE(KEYCODE_SLASH) PORT_CODE(KEYCODE_SLASH_PAD)
61   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("orange") PORT_CODE(KEYCODE_LCONTROL) PORT_CODE(KEYCODE_RCONTROL)
62   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("4               TIME") PORT_CODE(KEYCODE_4) PORT_CODE(KEYCODE_4_PAD)
63   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("5               STAT") PORT_CODE(KEYCODE_5) PORT_CODE(KEYCODE_5_PAD)
64   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("6               UNITS") PORT_CODE(KEYCODE_6) PORT_CODE(KEYCODE_6_PAD)
65   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("*               []      _") PORT_CODE(KEYCODE_BACKSPACE) PORT_CODE(KEYCODE_ASTERISK)
66   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("blue") PORT_CODE(KEYCODE_LALT) PORT_CODE(KEYCODE_RALT)
67   PORT_START
68   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("1               RAD     POLAR") PORT_CODE(KEYCODE_1) PORT_CODE(KEYCODE_1_PAD)
69   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("2               STACK   ARG") PORT_CODE(KEYCODE_2) PORT_CODE(KEYCODE_2_PAD)
70   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("3               CMD     MENU") PORT_CODE(KEYCODE_3) PORT_CODE(KEYCODE_3_PAD)
71   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("-               <<>>    \"\"") PORT_CODE(KEYCODE_MINUS) PORT_CODE(KEYCODE_MINUS_PAD)
72   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("ON              CONT    OFF") PORT_CODE(KEYCODE_F1)
73   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("0               =       ->") PORT_CODE(KEYCODE_0) PORT_CODE(KEYCODE_0_PAD)
74   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME(".               ,       enter") PORT_CODE(KEYCODE_STOP) PORT_CODE(KEYCODE_DEL_PAD)
75   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("SPC             Pi      angle") PORT_CODE(KEYCODE_SPACE)
76   PORT_START
77   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("+               {}      ::") PORT_CODE(KEYCODE_EQUALS) PORT_CODE(KEYCODE_PLUS_PAD)
37  Two main series: S series & G series.
38  Each series is subdivised into an 'expandable' model (SX,GX) and a
39  cheaper 'non-expandable' model (S,G).
7840
79#else
80   PORT_START
81   PORT_BIT ( 0x20, 0,     IPT_UNUSED )
82   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("B") PORT_CODE(KEYCODE_F2)
83   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("C") PORT_CODE(KEYCODE_F3)
84   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("D") PORT_CODE(KEYCODE_F4)
85   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("E") PORT_CODE(KEYCODE_F5)
86   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("F") PORT_CODE(KEYCODE_F6)
87   PORT_START
88   PORT_BIT ( 0x20, 0,     IPT_UNUSED )
89   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("PRG") PORT_CODE(KEYCODE_A)
90   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("CST") PORT_CODE(KEYCODE_B)
91   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("VAR") PORT_CODE(KEYCODE_C)
92   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("up") PORT_CODE(KEYCODE_UP)
93   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("NXT") PORT_CODE(KEYCODE_D)
94   PORT_START
95   PORT_BIT ( 0x20, 0,     IPT_UNUSED )
96   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("STO") PORT_CODE(KEYCODE_E)
97   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("EVL") PORT_CODE(KEYCODE_F)
98   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("left") PORT_CODE(KEYCODE_LEFT)
99   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("down") PORT_CODE(KEYCODE_DOWN)
100   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("right") PORT_CODE(KEYCODE_RIGHT)
101   PORT_START
102   PORT_BIT ( 0x20, 0,     IPT_UNUSED )
103   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("COS")
104   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("TAN") PORT_CODE(KEYCODE_H)
105   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("sqt") PORT_CODE(KEYCODE_LEFT)
106   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("pwr") PORT_CODE(KEYCODE_DOWN)
107   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("inv") PORT_CODE(KEYCODE_RIGHT)
108   PORT_START
109   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME(DEF_STR( On)) PORT_CODE(KEYCODE_NUMLOCK)
110   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("ENT") PORT_CODE(KEYCODE_I)
111   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("+/-") PORT_CODE(KEYCODE_MINUS)
112   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("EEX") PORT_CODE(KEYCODE_LEFT)
113   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("DEL") PORT_CODE(KEYCODE_BACKSPACE)
114   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("<==") PORT_CODE(KEYCODE_ENTER_PAD)
115   PORT_START
116   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("alp") PORT_CODE(KEYCODE_LALT)
117   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("SIN") PORT_CODE(KEYCODE_J)
118   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("7") PORT_CODE(KEYCODE_7_PAD)
119   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("8") PORT_CODE(KEYCODE_8_PAD)
120   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("9") PORT_CODE(KEYCODE_9_PAD)
121   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("/") PORT_CODE(KEYCODE_SLASH_PAD)
122   PORT_START
123   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("yel") PORT_CODE(KEYCODE_LSHIFT)
124   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("MTH") PORT_CODE(KEYCODE_K)
125   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("4") PORT_CODE(KEYCODE_4_PAD)
126   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("5") PORT_CODE(KEYCODE_5_PAD)
127   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("6") PORT_CODE(KEYCODE_6_PAD)
128   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("*") PORT_CODE(KEYCODE_ASTERISK)
129   PORT_START
130   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("blu") PORT_CODE(KEYCODE_LSHIFT)
131   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("A") PORT_CODE(KEYCODE_F1)
132   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("1") PORT_CODE(KEYCODE_1_PAD)
133   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("2") PORT_CODE(KEYCODE_2_PAD)
134   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("3") PORT_CODE(KEYCODE_3_PAD)
135   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("-") PORT_CODE(KEYCODE_MINUS_PAD)
136   PORT_START
137   PORT_BIT ( 0x20, 0,     IPT_UNUSED )
138   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("'") PORT_CODE(KEYCODE_L)
139   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("0") PORT_CODE(KEYCODE_0_PAD)
140   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME(".") PORT_CODE(KEYCODE_DEL_PAD)
141   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("SPC") PORT_CODE(KEYCODE_SPACE)
142   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("+") PORT_CODE(KEYCODE_PLUS_PAD)
143#endif
41  Timeline:
42  - 1990-03-06 HP48SX (discontinued in ????)
43  - 1991-04-02 HP48S  (discontinued in 1993)
44  - 1993-06-01 HP48G  (discontinued in 1999)
45               HP48GX (discontinued in 2003)
46
47  Common characteristics:
48  - HP family name: Charlemagne
49  - CPU: Saturn, 4-bit processor, chip version: 1LT8
50  - BUS:
51      . 20-bit address bus
52      . nibble (4-bit) addressable
53      => 512 KB address space (i.e., 1 Mnibbles)
54      . daisy-chained modules
55  - Screen: 131x64 LCD, 2-color, 64 Hz refresh
56  - Keyboard: 49 keys
57  - IR I/O port
58  - 4-wire serial I/O port
59  - 1-bit beeper
60  - Power-source: 3 AAA cells
61  - Continuous memory
62
63
64  S series specific:
65  - Clarke IC
66  - clock speed: 2Mhz
67  - 256 KB ROM (various revisions, identical in S and SX)
68
69  - S model specific:
70    + Codename: Shorty
71    + 32 KB RAM base, not expandable (in theory)
72    + no expansion port
73
74  - SX model specific:
75    + Codename: Charlemagne
76    + 32 KB base RAM, expandable to 288 KB
77    + 2 expansion ports (port 1 and port 2)
78      up to 128 KB RAM per port, can be merged with base RAM
79
80  G series specific:
81  - Yorke IC
82  - clock speed: ~4Mhz
83  - 512 KB ROM (various revisions, identical in G and GX)
84
85  - G model specific:
86    + Codename: Alcuin
87    + 32 KB RAM, not expandable (in theory!)
88    + no expansion port
89
90  - GX model specific:
91    + Codename: Hammer
92    + 128 KB base RAM, expandable up to 4 MB (banked)
93    + 2 expansion ports
94      . port 1: up to 128 KB RAM, can be merged with base RAM
95      . port 2: up to   4 MB RAM, in 32 banks of 128 KB, cannot be merged
96
97*/
98
99
100/*
101   More about memory.
102
103   The base RAM is treated as NVRAM: stored in a .nv file in your nvram
104   directory.
105   When first starting the emulator, or after nvram file has been deleted,
106   you'll get a "Try to recover memory?". This is expected.
107   Answer NO (F key): there is nothing to recover, but it will setup the
108   system-reserved RAM part correctly.
109   If the emulator is shut down properly (i.e., when the calculator is
110   not busy), the message should not appear next time it is run.
111   All the variables and port 0 should be conserved (in the .nv file),
112   but not the stack.
113   Stopping and restarting the emulator loosely corresponds to hitting the
114   reset button.
115
116   Expansion RAMs are treated as images, not NVRAM.
117   The -p1 (resp. -p2) image option allows mapping some file to port 1
118   (resp. port 2).
119   The file size should be between 32 KB and 128 KB (or 4 GB for port 2 on GX)
120   and be a power of two.
121*/
122
123
124/*
125  More about serial connection.
126
127  Normally, files are exchanged by serial connection to a computer running a
128  kermit communication program (xmodem is also allowed for the G/GX).
129  We emulate both the serial link and the communication program.
130  Thus, the emulated HP48 can directly upload/download image files.
131  The -k image option corresponds to the kermit protocol (SEND and RECV
132  commands on the HP48).
133  The -x image option corresponds to the xmodem protocol (XSEND and XRECV
134  commands on the HP48).
135*/
136
137
138
139/*
140
141  References:
142
143  - Voyage au centre de la HP48 S/SX, by Paul Courbis & Sébastien Lalande
144    (English version: HP48 machine language - a journey to the center
145     of the HP48 s/sx)
146    available at http://www.courbis.com
147
148  - Voyage au centre de la HP48 G/GX, by Paul Courbis
149    available at http://www.courbis.com
150
151  - Guide to the Saturn Processor (With HP48 Applications)
152    by Matthew Mastracci
153
154  - Introduction to Saturn Assembly Language
155    by Gilbert Fernandes
156
157  - http://www.hpcalc.org/
158
159*/
160
161
162
163
164/**************************** inputs *******************************/
165
166/*  KEYBOARD
167    --------
168
169    keyboard layout (all models)
170
171   -------------------------------------------------
172   |   A   |   B   |   C   |   D   |   E   |   F   |
173   |-------+-------+-------+-------+-------+-------|
174   |  MTH  |  PRG  |  CST  |  VAR  |   up  |  NXT  |
175   |-------+-------+-------+-------+-------+-------|
176   |   '   |  STO  |  EVAL |  left | down  | right |
177   |-------+-------+-------+-------+-------+-------|
178   |  SIN  |  COS  |  TAN  |  sqrt |  y^x  |  1/x  |
179   |---------------+-------+-------+-------+-------|
180   |     ENTER     |  +/-  |  EEX  |  DEL  |  <=   |
181   |-----------------------------------------------|
182   |  alpha  |   7    |    8   |    9    |    /    |
183   |---------+--------+--------+---------+---------|
184   |   red   |   4    |    5   |    6    |    *    |
185   |---------+--------+--------+---------+---------|
186   |  green  |   1    |    2   |    3    |    -    |
187   |---------+--------+--------+---------+---------|
188   |   ON    |   0    |    .   |   SPC   |    +    |
189   -------------------------------------------------
190
191   * 49 keys
192   * including 3 modifier keys:
193     - a  blue/green shift (upper right)
194     - an orange/red shift (upper left)
195     - a  white alpha key (lower right)
196
197   Difference between G and S series: a few red and blue shifted keys.
198 
199*/
200
201/* S/SX */
202static INPUT_PORTS_START( hp48sx_kbd )
203
204        PORT_START_TAG( "LINE0" ) /* OUT = 0x001 */
205
206   PORT_BIT  ( 1, IP_ACTIVE_HIGH, IPT_KEYBOARD )
207   PORT_NAME ( "+      { }  : :" )
208   PORT_CODE ( KEYCODE_EQUALS )
209   PORT_CODE ( KEYCODE_PLUS_PAD )
210
211   PORT_BIT  ( 2, IP_ACTIVE_HIGH, IPT_KEYBOARD )
212   PORT_NAME ( "SPC    \xCF\x80 \xE2\x88\xA1" /* pi, angle */ )
213   PORT_CODE ( KEYCODE_SPACE )
214
215   PORT_BIT  ( 4, IP_ACTIVE_HIGH, IPT_KEYBOARD )
216   PORT_NAME ( ".      ,  \xE2\x86\xb5" /* return arrow */ )
217   PORT_CODE ( KEYCODE_STOP )
218
219   PORT_BIT  ( 8, IP_ACTIVE_HIGH, IPT_KEYBOARD )
220   PORT_NAME ( "0      =  \xE2\x86\x92" /* right arrow */ )
221   PORT_CODE ( KEYCODE_0 )
222   PORT_CODE ( KEYCODE_0_PAD )
223
224   PORT_BIT  ( 16, IP_ACTIVE_HIGH, IPT_KEYBOARD )
225   PORT_NAME ( "'  M   UP  HOME" )
226   PORT_CODE ( KEYCODE_QUOTE )
227   PORT_CODE ( KEYCODE_M )
228
229        PORT_BIT ( 0xffe0, 0, IPT_UNUSED )
230
231
232        PORT_START_TAG( "LINE1" ) /* OUT = 0x002 */
233
234   PORT_BIT  ( 1, IP_ACTIVE_HIGH, IPT_KEYBOARD )
235        PORT_NAME ( "-      << >>  \" \"" )
236   PORT_CODE ( KEYCODE_MINUS )
237   PORT_CODE ( KEYCODE_MINUS_PAD )
238
239   PORT_BIT  ( 2, IP_ACTIVE_HIGH, IPT_KEYBOARD )
240   PORT_NAME ( "3      CMD  MENU" )
241   PORT_CODE ( KEYCODE_3 )
242   PORT_CODE ( KEYCODE_3_PAD )
243
244   PORT_BIT  ( 4, IP_ACTIVE_HIGH, IPT_KEYBOARD )
245   PORT_NAME ( "2      STACK ARG" )
246   PORT_CODE ( KEYCODE_2 )
247   PORT_CODE ( KEYCODE_2_PAD )
248
249   PORT_BIT  ( 8, IP_ACTIVE_HIGH, IPT_KEYBOARD )
250   PORT_NAME ( "1       RAD POLAR" )
251   PORT_CODE ( KEYCODE_1 )
252   PORT_CODE ( KEYCODE_1_PAD )
253
254   PORT_BIT  ( 16, IP_ACTIVE_HIGH, IPT_KEYBOARD )
255   PORT_NAME ( "A" )
256   PORT_CODE ( KEYCODE_A )
257
258   PORT_BIT  ( 32, IP_ACTIVE_HIGH, IPT_KEYBOARD )
259        PORT_NAME ( "right shift" )
260   PORT_CODE ( KEYCODE_RSHIFT )
261
262        PORT_BIT ( 0xffc0, 0, IPT_UNUSED )
263
264
265        PORT_START_TAG( "LINE2" ) /* OUT = 0x004 */
266
267   PORT_BIT  ( 1, IP_ACTIVE_HIGH, IPT_KEYBOARD )
268   PORT_NAME ( "*      [ ]     _" )
269   PORT_CODE ( KEYCODE_ASTERISK )
270   PORT_CODE ( KEYCODE_CLOSEBRACE )
271
272   PORT_BIT  ( 2, IP_ACTIVE_HIGH, IPT_KEYBOARD )
273   PORT_NAME ( "6              UNITS" )
274   PORT_CODE ( KEYCODE_6_PAD )
275   PORT_CODE ( KEYCODE_6 )
276
277   PORT_BIT  ( 4, IP_ACTIVE_HIGH, IPT_KEYBOARD )
278   PORT_NAME ( "5              STAT" )
279   PORT_CODE ( KEYCODE_5_PAD )
280   PORT_CODE ( KEYCODE_5 )
281
282   PORT_BIT  ( 8, IP_ACTIVE_HIGH, IPT_KEYBOARD )
283   PORT_NAME ( "4              TIME" )
284   PORT_CODE ( KEYCODE_4_PAD )
285   PORT_CODE ( KEYCODE_4 )
286
287   PORT_BIT  ( 16, IP_ACTIVE_HIGH, IPT_KEYBOARD )
288   PORT_NAME ( "MTH   G  PRINT")
289   PORT_CODE ( KEYCODE_G )
290
291   PORT_BIT  ( 32, IP_ACTIVE_HIGH, IPT_KEYBOARD )
292        PORT_NAME ( "left shift" )
293   PORT_CODE ( KEYCODE_LSHIFT )
294
295   PORT_BIT ( 0xffc0, 0, IPT_UNUSED )
296
297
298        PORT_START_TAG( "LINE3" ) /* OUT = 0x008 */
299
300   PORT_BIT  ( 1, IP_ACTIVE_HIGH, IPT_KEYBOARD )
301   PORT_NAME ( "/      ( )     #" )
302   PORT_CODE ( KEYCODE_SLASH )
303   PORT_CODE ( KEYCODE_SLASH_PAD )
304
305   PORT_BIT  ( 2, IP_ACTIVE_HIGH, IPT_KEYBOARD )
306   PORT_NAME ( "9              ALGEBRA" )
307   PORT_CODE ( KEYCODE_9_PAD )
308   PORT_CODE ( KEYCODE_9 )
309
310   PORT_BIT  ( 4, IP_ACTIVE_HIGH, IPT_KEYBOARD )
311   PORT_NAME ( "8              PLOT" )
312   PORT_CODE ( KEYCODE_8_PAD )
313   PORT_CODE ( KEYCODE_8 )
314
315   PORT_BIT  ( 8, IP_ACTIVE_HIGH, IPT_KEYBOARD )
316   PORT_NAME ( "7              SOLVE" )
317   PORT_CODE ( KEYCODE_7_PAD )
318   PORT_CODE ( KEYCODE_7 )
319
320   PORT_BIT  ( 16, IP_ACTIVE_HIGH, IPT_KEYBOARD )
321   PORT_NAME ( "SIN   S  ASIN  \xE2\x88\x82" /* delta */ )
322   PORT_CODE ( KEYCODE_S )
323
324   PORT_BIT  ( 32, IP_ACTIVE_HIGH, IPT_KEYBOARD )
325        PORT_NAME ( "\xCE\xB1       USER ENTRY" /* alpha */ )
326   PORT_CODE ( KEYCODE_LALT )
327
328   PORT_BIT ( 0xffc0, 0, IPT_UNUSED )
329
330
331        PORT_START_TAG( "LINE4" ) /* OUT = 0x010 */
332
333   PORT_BIT  ( 1, IP_ACTIVE_HIGH, IPT_KEYBOARD )
334        PORT_NAME (" \xE2\x87\x90       DROP  CLR" /* double left arrow */ )
335   PORT_CODE ( KEYCODE_BACKSPACE )
336
337   PORT_BIT  ( 2, IP_ACTIVE_HIGH, IPT_KEYBOARD )
338   PORT_NAME ( "DEL        PURGE" )
339   PORT_CODE ( KEYCODE_DEL )
340   PORT_CODE ( KEYCODE_DEL_PAD )
341
342   PORT_BIT  ( 4, IP_ACTIVE_HIGH, IPT_KEYBOARD )
343   PORT_NAME ( "EEX  Z   2D   3D" )
344   PORT_CODE ( KEYCODE_Z )
345
346   PORT_BIT  ( 8, IP_ACTIVE_HIGH, IPT_KEYBOARD )
347   PORT_NAME ( "+/-  Y   EDIT  VISIT" )
348   PORT_CODE ( KEYCODE_Y )
349
350   PORT_BIT  ( 16, IP_ACTIVE_HIGH, IPT_KEYBOARD )
351   PORT_NAME ( "ENTER     EQUATION MATRIX")
352   PORT_CODE ( KEYCODE_ENTER )
353   PORT_CODE ( KEYCODE_ENTER_PAD )
354
355   PORT_BIT ( 0xffe0, 0, IPT_UNUSED )
356
357
358        PORT_START_TAG( "LINE5" ) /* OUT = 0x020 */
359
360   PORT_BIT  ( 1, IP_ACTIVE_HIGH, IPT_KEYBOARD )
361   PORT_NAME ( "1/x  X   e^x   LN" )
362   PORT_CODE ( KEYCODE_X )
363
364   PORT_BIT  ( 2, IP_ACTIVE_HIGH, IPT_KEYBOARD )
365   PORT_NAME ( "y^x  W   10^x  LOG" )
366   PORT_CODE ( KEYCODE_W )
367
368   PORT_BIT  ( 4, IP_ACTIVE_HIGH, IPT_KEYBOARD )
369        PORT_NAME ( "\xE2\x88\x9A  V   x^2  sqrt(x,y)" /* square root */ )
370   PORT_CODE ( KEYCODE_V )
371
372   PORT_BIT  ( 8, IP_ACTIVE_HIGH, IPT_KEYBOARD )
373   PORT_NAME ( "TAN  U   ATAN  \xE2\x88\x91" /* sum */ )
374   PORT_CODE ( KEYCODE_U )
375
376   PORT_BIT  ( 16, IP_ACTIVE_HIGH, IPT_KEYBOARD )
377   PORT_NAME ( "COS  T   ACOS  \xE2\x88\xAB" /* integral */ )
378   PORT_CODE ( KEYCODE_T )
379
380        PORT_BIT ( 0xffe0, 0, IPT_UNUSED )
381
382
383        PORT_START_TAG( "LINE6" ) /* OUT = 0x040 */
384
385   PORT_BIT  ( 1, IP_ACTIVE_HIGH, IPT_KEYBOARD )
386        PORT_NAME ( "\xE2\x86\x92  R        SWAP" /* right arrow */ )
387   PORT_CODE ( KEYCODE_RIGHT )
388   PORT_CODE ( KEYCODE_R )
389
390   PORT_BIT  ( 2, IP_ACTIVE_HIGH, IPT_KEYBOARD )
391        PORT_NAME ( "\xE2\x86\x93  Q        REVIEW" /* down arrow */ )
392   PORT_CODE ( KEYCODE_DOWN )
393   PORT_CODE ( KEYCODE_Q)
394
395   PORT_BIT  ( 4, IP_ACTIVE_HIGH, IPT_KEYBOARD )
396        PORT_NAME ( "\xE2\x86\x90  P        GRAPH" /* left arrow */ )
397   PORT_CODE ( KEYCODE_LEFT )
398   PORT_CODE ( KEYCODE_P )
399
400   PORT_BIT  ( 8, IP_ACTIVE_HIGH, IPT_KEYBOARD )
401   PORT_NAME ( "EVAL O   \xE2\x86\x92NUM UNDO" )
402   PORT_CODE ( KEYCODE_O )
403
404   PORT_BIT  ( 16, IP_ACTIVE_HIGH, IPT_KEYBOARD )
405   PORT_NAME ( "STO  N   DEF   RCL" )
406   PORT_CODE ( KEYCODE_N )
407
408        PORT_BIT ( 0xffe0, 0, IPT_UNUSED )
409
410
411        PORT_START_TAG( "LINE7" ) /* OUT = 0x080 */
412
413   PORT_BIT  ( 1, IP_ACTIVE_HIGH, IPT_KEYBOARD )
414   PORT_NAME ( "NXT  L   PREV" )
415   PORT_CODE ( KEYCODE_L )
416
417   PORT_BIT  ( 2, IP_ACTIVE_HIGH, IPT_KEYBOARD )
418        PORT_NAME ( "\xE2\x86\x91  K        LIBRARY" /* up arrow */ )
419   PORT_CODE ( KEYCODE_UP )
420   PORT_CODE ( KEYCODE_K )
421
422   PORT_BIT  ( 4, IP_ACTIVE_HIGH, IPT_KEYBOARD )
423   PORT_NAME ( "VAR  J         MEMORY" )
424   PORT_CODE ( KEYCODE_J )
425
426   PORT_BIT  ( 8, IP_ACTIVE_HIGH, IPT_KEYBOARD )
427   PORT_NAME ( "CST  I         MODES" )
428   PORT_CODE ( KEYCODE_I )
429
430   PORT_BIT  ( 16, IP_ACTIVE_HIGH, IPT_KEYBOARD )
431   PORT_NAME ( "PRG  H         I/O" )
432   PORT_CODE ( KEYCODE_H )
433
434        PORT_BIT ( 0xffe0, 0, IPT_UNUSED )
435
436
437        PORT_START_TAG( "LINE8" ) /* OUT = 0x100 */
438
439   PORT_BIT  ( 1, IP_ACTIVE_HIGH, IPT_KEYBOARD )
440   PORT_NAME ( "F" )
441   PORT_CODE ( KEYCODE_F )
442
443   PORT_BIT  ( 2, IP_ACTIVE_HIGH, IPT_KEYBOARD )
444   PORT_NAME ( "E" )
445   PORT_CODE ( KEYCODE_E )
446
447   PORT_BIT  ( 4, IP_ACTIVE_HIGH, IPT_KEYBOARD )
448   PORT_NAME ( "D" )
449   PORT_CODE ( KEYCODE_D )
450
451   PORT_BIT  ( 8, IP_ACTIVE_HIGH, IPT_KEYBOARD )
452   PORT_NAME ( "C" )
453   PORT_CODE ( KEYCODE_C )
454
455   PORT_BIT  ( 16, IP_ACTIVE_HIGH, IPT_KEYBOARD )
456   PORT_NAME ( "B" )
457   PORT_CODE ( KEYCODE_B )
458
459        PORT_BIT ( 0xffe0, 0, IPT_UNUSED )
460
461
462        PORT_START_TAG( "ON" ) /* ON key, appears on all OUT lines */
463
464   PORT_BIT  ( 0x8000, IP_ACTIVE_HIGH, IPT_KEYBOARD )
465   PORT_NAME ( "ON  CANCEL CONT OFF" )
466   PORT_CODE ( KEYCODE_ESC )
467   PORT_CODE ( KEYCODE_HOME )
468
469        PORT_BIT ( 0x7fff, 0, IPT_UNUSED )
470
144471INPUT_PORTS_END
145472
146473
147static const gfx_layout hp48_charlayout =
148{
149   2,16,
150   256,                                    /* 256 characters */
151   1,                      /* 1 bits per pixel */
152   { 0 },                  /* no bitplanes; 1 bit per pixel */
153   /* x offsets */
154   { 0,0 },
155   /* y offsets */
156   {
157      7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0
158   },
159   1*8
160};
161474
162static GFXDECODE_START( hp48 )
163   GFXDECODE_ENTRY( REGION_GFX1, 0x0000, hp48_charlayout, 0, 2 )
164GFXDECODE_END
475/* G/GX */
476static INPUT_PORTS_START( hp48gx_kbd )
165477
166static const SATURN_CONFIG config={
167   hp48_out, hp48_in,
478        PORT_START_TAG( "LINE0" ) /* OUT = 0x001 */
479
480   PORT_BIT  ( 1, IP_ACTIVE_HIGH, IPT_KEYBOARD )
481   PORT_NAME ( "+      { }  : :" )
482   PORT_CODE ( KEYCODE_EQUALS )
483   PORT_CODE ( KEYCODE_PLUS_PAD )
484
485   PORT_BIT  ( 2, IP_ACTIVE_HIGH, IPT_KEYBOARD )
486   PORT_NAME ( "SPC    \xCF\x80 \xE2\x88\xA1" /* pi, angle */ )
487   PORT_CODE ( KEYCODE_SPACE )
488
489   PORT_BIT  ( 4, IP_ACTIVE_HIGH, IPT_KEYBOARD )
490   PORT_NAME ( ".      ,  \xE2\x86\xb5" /* return arrow */ )
491   PORT_CODE ( KEYCODE_STOP )
492
493   PORT_BIT  ( 8, IP_ACTIVE_HIGH, IPT_KEYBOARD )
494   PORT_NAME ( "0      =  \xE2\x86\x92" /* right arrow */ )
495   PORT_CODE ( KEYCODE_0 )
496   PORT_CODE ( KEYCODE_0_PAD )
497
498   PORT_BIT  ( 16, IP_ACTIVE_HIGH, IPT_KEYBOARD )
499   PORT_NAME ( "'  M   UP  HOME" )
500   PORT_CODE ( KEYCODE_QUOTE )
501   PORT_CODE ( KEYCODE_M )
502
503        PORT_BIT ( 0xffe0, 0, IPT_UNUSED )
504
505
506        PORT_START_TAG( "LINE1" ) /* OUT = 0x002 */
507
508   PORT_BIT  ( 1, IP_ACTIVE_HIGH, IPT_KEYBOARD )
509        PORT_NAME ( "-      << >>  \" \"" )
510   PORT_CODE ( KEYCODE_MINUS )
511   PORT_CODE ( KEYCODE_MINUS_PAD )
512
513   PORT_BIT  ( 2, IP_ACTIVE_HIGH, IPT_KEYBOARD )
514   PORT_NAME ( "3             EQ LIB" )
515   PORT_CODE ( KEYCODE_3 )
516   PORT_CODE ( KEYCODE_3_PAD )
517
518   PORT_BIT  ( 4, IP_ACTIVE_HIGH, IPT_KEYBOARD )
519   PORT_NAME ( "2             LIBRARY" )
520   PORT_CODE ( KEYCODE_2 )
521   PORT_CODE ( KEYCODE_2_PAD )
522
523   PORT_BIT  ( 8, IP_ACTIVE_HIGH, IPT_KEYBOARD )
524   PORT_NAME ( "1             I/O" )
525   PORT_CODE ( KEYCODE_1 )
526   PORT_CODE ( KEYCODE_1_PAD )
527
528   PORT_BIT  ( 16, IP_ACTIVE_HIGH, IPT_KEYBOARD )
529   PORT_NAME ( "A" )
530   PORT_CODE ( KEYCODE_A )
531
532   PORT_BIT  ( 32, IP_ACTIVE_HIGH, IPT_KEYBOARD )
533        PORT_NAME ( "right shift" )
534   PORT_CODE ( KEYCODE_RSHIFT )
535
536        PORT_BIT ( 0xffc0, 0, IPT_UNUSED )
537
538
539        PORT_START_TAG( "LINE2" ) /* OUT = 0x004 */
540
541   PORT_BIT  ( 1, IP_ACTIVE_HIGH, IPT_KEYBOARD )
542   PORT_NAME ( "*      [ ]     _" )
543   PORT_CODE ( KEYCODE_ASTERISK )
544   PORT_CODE ( KEYCODE_CLOSEBRACE )
545
546   PORT_BIT  ( 2, IP_ACTIVE_HIGH, IPT_KEYBOARD )
547   PORT_NAME ( "6              UNITS" )
548   PORT_CODE ( KEYCODE_6_PAD )
549   PORT_CODE ( KEYCODE_6 )
550
551   PORT_BIT  ( 4, IP_ACTIVE_HIGH, IPT_KEYBOARD )
552   PORT_NAME ( "5              STAT" )
553   PORT_CODE ( KEYCODE_5_PAD )
554   PORT_CODE ( KEYCODE_5 )
555
556   PORT_BIT  ( 8, IP_ACTIVE_HIGH, IPT_KEYBOARD )
557   PORT_NAME ( "4              TIME" )
558   PORT_CODE ( KEYCODE_4_PAD )
559   PORT_CODE ( KEYCODE_4 )
560
561   PORT_BIT  ( 16, IP_ACTIVE_HIGH, IPT_KEYBOARD )
562   PORT_NAME ( "MTH   G  RAD   POLAR")
563   PORT_CODE ( KEYCODE_G )
564
565   PORT_BIT  ( 32, IP_ACTIVE_HIGH, IPT_KEYBOARD )
566        PORT_NAME ( "left shift" )
567   PORT_CODE ( KEYCODE_LSHIFT )
568
569   PORT_BIT ( 0xffc0, 0, IPT_UNUSED )
570
571
572        PORT_START_TAG( "LINE3" ) /* OUT = 0x008 */
573
574   PORT_BIT  ( 1, IP_ACTIVE_HIGH, IPT_KEYBOARD )
575   PORT_NAME ( "/      ( )     #" )
576   PORT_CODE ( KEYCODE_SLASH )
577   PORT_CODE ( KEYCODE_SLASH_PAD )
578
579   PORT_BIT  ( 2, IP_ACTIVE_HIGH, IPT_KEYBOARD )
580   PORT_NAME ( "9              SYMBOLIC" )
581   PORT_CODE ( KEYCODE_9_PAD )
582   PORT_CODE ( KEYCODE_9 )
583
584   PORT_BIT  ( 4, IP_ACTIVE_HIGH, IPT_KEYBOARD )
585   PORT_NAME ( "8              PLOT" )
586   PORT_CODE ( KEYCODE_8_PAD )
587   PORT_CODE ( KEYCODE_8 )
588
589   PORT_BIT  ( 8, IP_ACTIVE_HIGH, IPT_KEYBOARD )
590   PORT_NAME ( "7              SOLVE" )
591   PORT_CODE ( KEYCODE_7_PAD )
592   PORT_CODE ( KEYCODE_7 )
593
594   PORT_BIT  ( 16, IP_ACTIVE_HIGH, IPT_KEYBOARD )
595   PORT_NAME ( "SIN   S  ASIN  \xE2\x88\x82" /* delta */ )
596   PORT_CODE ( KEYCODE_S )
597
598   PORT_BIT  ( 32, IP_ACTIVE_HIGH, IPT_KEYBOARD )
599        PORT_NAME ( "\xCE\xB1       USER ENTRY" /* alpha */ )
600   PORT_CODE ( KEYCODE_LALT )
601
602   PORT_BIT ( 0xffc0, 0, IPT_UNUSED )
603
604
605        PORT_START_TAG( "LINE4" ) /* OUT = 0x010 */
606
607   PORT_BIT  ( 1, IP_ACTIVE_HIGH, IPT_KEYBOARD )
608        PORT_NAME (" \xE2\x87\x90       DROP" /* double left arrow */ )
609   PORT_CODE ( KEYCODE_BACKSPACE )
610
611   PORT_BIT  ( 2, IP_ACTIVE_HIGH, IPT_KEYBOARD )
612   PORT_NAME ( "DEL            CLEAR" )
613   PORT_CODE ( KEYCODE_DEL )
614   PORT_CODE ( KEYCODE_DEL_PAD )
615
616   PORT_BIT  ( 4, IP_ACTIVE_HIGH, IPT_KEYBOARD )
617   PORT_NAME ( "EEX  Z   PURG  ARG" )
618   PORT_CODE ( KEYCODE_Z )
619
620   PORT_BIT  ( 8, IP_ACTIVE_HIGH, IPT_KEYBOARD )
621   PORT_NAME ( "+/-  Y   EDIT  CMD" )
622   PORT_CODE ( KEYCODE_Y )
623
624   PORT_BIT  ( 16, IP_ACTIVE_HIGH, IPT_KEYBOARD )
625   PORT_NAME ( "ENTER     EQUATION MATRIX")
626   PORT_CODE ( KEYCODE_ENTER )
627   PORT_CODE ( KEYCODE_ENTER_PAD )
628
629   PORT_BIT ( 0xffe0, 0, IPT_UNUSED )
630
631
632        PORT_START_TAG( "LINE5" ) /* OUT = 0x020 */
633
634   PORT_BIT  ( 1, IP_ACTIVE_HIGH, IPT_KEYBOARD )
635   PORT_NAME ( "1/x  X   e^x   LN" )
636   PORT_CODE ( KEYCODE_X )
637
638   PORT_BIT  ( 2, IP_ACTIVE_HIGH, IPT_KEYBOARD )
639   PORT_NAME ( "y^x  W   10^x  LOG" )
640   PORT_CODE ( KEYCODE_W )
641
642   PORT_BIT  ( 4, IP_ACTIVE_HIGH, IPT_KEYBOARD )
643        PORT_NAME ( "\xE2\x88\x9A  V   x^2  sqrt(x,y)" /* square root */ )
644   PORT_CODE ( KEYCODE_V )
645
646   PORT_BIT  ( 8, IP_ACTIVE_HIGH, IPT_KEYBOARD )
647   PORT_NAME ( "TAN  U   ATAN  \xE2\x88\x91" /* sum */ )
648   PORT_CODE ( KEYCODE_U )
649
650   PORT_BIT  ( 16, IP_ACTIVE_HIGH, IPT_KEYBOARD )
651   PORT_NAME ( "COS  T   ACOS  \xE2\x88\xAB" /* integral */ )
652   PORT_CODE ( KEYCODE_T )
653
654        PORT_BIT ( 0xffe0, 0, IPT_UNUSED )
655
656
657        PORT_START_TAG( "LINE6" ) /* OUT = 0x040 */
658
659   PORT_BIT  ( 1, IP_ACTIVE_HIGH, IPT_KEYBOARD )
660        PORT_NAME ( "\xE2\x86\x92  R        SWAP" /* right arrow */ )
661   PORT_CODE ( KEYCODE_RIGHT )
662   PORT_CODE ( KEYCODE_R )
663
664   PORT_BIT  ( 2, IP_ACTIVE_HIGH, IPT_KEYBOARD )
665        PORT_NAME ( "\xE2\x86\x93  Q        VIEW" /* down arrow */ )
666   PORT_CODE ( KEYCODE_DOWN )
667   PORT_CODE ( KEYCODE_Q)
668
669   PORT_BIT  ( 4, IP_ACTIVE_HIGH, IPT_KEYBOARD )
670        PORT_NAME ( "\xE2\x86\x90  P        PICTURE" /* left arrow */ )
671   PORT_CODE ( KEYCODE_LEFT )
672   PORT_CODE ( KEYCODE_P )
673
674   PORT_BIT  ( 8, IP_ACTIVE_HIGH, IPT_KEYBOARD )
675   PORT_NAME ( "EVAL O   \xE2\x86\x92NUM UNDO" )
676   PORT_CODE ( KEYCODE_O )
677
678   PORT_BIT  ( 16, IP_ACTIVE_HIGH, IPT_KEYBOARD )
679   PORT_NAME ( "STO  N   DEF   RCL" )
680   PORT_CODE ( KEYCODE_N )
681
682        PORT_BIT ( 0xffe0, 0, IPT_UNUSED )
683
684
685        PORT_START_TAG( "LINE7" ) /* OUT = 0x080 */
686
687   PORT_BIT  ( 1, IP_ACTIVE_HIGH, IPT_KEYBOARD )
688   PORT_NAME ( "NXT  L   PREV  MENU" )
689   PORT_CODE ( KEYCODE_L )
690
691   PORT_BIT  ( 2, IP_ACTIVE_HIGH, IPT_KEYBOARD )
692        PORT_NAME ( "\xE2\x86\x91  K          STACK" /* up arrow */ )
693   PORT_CODE ( KEYCODE_UP )
694   PORT_CODE ( KEYCODE_K )
695
696   PORT_BIT  ( 4, IP_ACTIVE_HIGH, IPT_KEYBOARD )
697   PORT_NAME ( "VAR  J         MEMORY" )
698   PORT_CODE ( KEYCODE_J )
699
700   PORT_BIT  ( 8, IP_ACTIVE_HIGH, IPT_KEYBOARD )
701   PORT_NAME ( "CST  I         MODES" )
702   PORT_CODE ( KEYCODE_I )
703
704   PORT_BIT  ( 16, IP_ACTIVE_HIGH, IPT_KEYBOARD )
705   PORT_NAME ( "PRG  H         CHARS" )
706   PORT_CODE ( KEYCODE_H )
707
708        PORT_BIT ( 0xffe0, 0, IPT_UNUSED )
709
710
711        PORT_START_TAG( "LINE8" ) /* OUT = 0x100 */
712
713   PORT_BIT  ( 1, IP_ACTIVE_HIGH, IPT_KEYBOARD )
714   PORT_NAME ( "F" )
715   PORT_CODE ( KEYCODE_F )
716
717   PORT_BIT  ( 2, IP_ACTIVE_HIGH, IPT_KEYBOARD )
718   PORT_NAME ( "E" )
719   PORT_CODE ( KEYCODE_E )
720
721   PORT_BIT  ( 4, IP_ACTIVE_HIGH, IPT_KEYBOARD )
722   PORT_NAME ( "D" )
723   PORT_CODE ( KEYCODE_D )
724
725   PORT_BIT  ( 8, IP_ACTIVE_HIGH, IPT_KEYBOARD )
726   PORT_NAME ( "C" )
727   PORT_CODE ( KEYCODE_C )
728
729   PORT_BIT  ( 16, IP_ACTIVE_HIGH, IPT_KEYBOARD )
730   PORT_NAME ( "B" )
731   PORT_CODE ( KEYCODE_B )
732
733        PORT_BIT ( 0xffe0, 0, IPT_UNUSED )
734
735
736        PORT_START_TAG( "ON" ) /* ON key, appears on all OUT lines */
737
738   PORT_BIT  ( 0x8000, IP_ACTIVE_HIGH, IPT_KEYBOARD )
739   PORT_NAME ( "ON  CANCEL CONT OFF" )
740   PORT_CODE ( KEYCODE_ESC )
741   PORT_CODE ( KEYCODE_HOME )
742
743        PORT_BIT ( 0x7fff, 0, IPT_UNUSED )
744
745INPUT_PORTS_END
746
747
748
749/*  BATTERY
750    -------
751 */
752
753static INPUT_PORTS_START( hp48_battery )
754        PORT_START_TAG( "BATTERY" )
755        PORT_CONFNAME ( 0x03, 0, "Battery status" )
756        PORT_CONFSETTING ( 0x00, DEF_STR( Normal ) )
757        PORT_CONFSETTING ( 0x01, DEF_STR( Low ) )
758        PORT_CONFSETTING ( 0x02, "Very low" )
759INPUT_PORTS_END
760
761
762
763/*  MAIN
764    -----
765 */
766
767static INPUT_PORTS_START( hp48sx )
768        PORT_INCLUDE( hp48sx_kbd )
769        PORT_INCLUDE( hp48_battery )
770INPUT_PORTS_END
771
772static INPUT_PORTS_START( hp48gx )
773        PORT_INCLUDE( hp48gx_kbd )
774        PORT_INCLUDE( hp48_battery )
775INPUT_PORTS_END
776
777
778
779
780/**************************** I/O **********************************/
781
782static xmodem_config hp48_xmodem_rs232_conf = { &hp48_rs232_start_recv_byte };
783static kermit_config hp48_kermit_rs232_conf = { &hp48_rs232_start_recv_byte };
784
785
786/**************************** ROMs *********************************/
787
788/* In ROMs, nibbles are packed into bytes, the lowest significant nibble in each byte
789   has the lowest address on the HP.
790
791   Note that some ROMs you can find on the Internet has the reverse the two nibbles.
792   First byte should read 32 in hexa, not 23.
793 */
794
795
796/* These ROMS are common to the G and GX models.
797   The ROM detects whether it runs a G or a GX by simply testing the memory:
798   if there are 32 KB (i.e., addresses wraps-around at 0x10000), it is a G; if there are
799   128 KB, it is a GX.
800   When a G is detected, some specially optimized routines may be used (they use the fact that
801   no extension may be physically present).
802 */
803ROM_START ( hp48gx )
804        ROM_REGION( 0x80000, REGION_CPU1, 0 )
805
806   /* latest revision (preferred) */
807   ROM_SYSTEM_BIOS( 0, "r", "Version R" )
808   ROMX_LOAD( "gxrom-r",
809         0x00000, 0x80000,
810         CRC(00ee1a62) SHA1(5705fc9ea791916c4456ac35e22275862411db9b),
811         ROM_BIOS(1) )
812     
813   /* now in chronological order, from first revision */
814   
815        ROM_SYSTEM_BIOS( 1, "k", "Version K" )
816   ROMX_LOAD( "gxrom-k",
817         0x00000, 0x80000,
818         CRC(bdd5d2ee) SHA1(afa1498238e991b1e3d07fb8b4c227b115f7bcc1),
819         ROM_BIOS(2) )
820
821   ROM_SYSTEM_BIOS( 2, "l", "Version L" )
822   ROMX_LOAD( "gxrom-l",
823         0x00000, 0x80000,
824         CRC(70958e6b) SHA1(8eebac69ff804086247b989bf320e57a2d8a59a7),
825         ROM_BIOS(3) )
826
827   ROM_SYSTEM_BIOS( 3, "m", "Version M" )
828   ROMX_LOAD( "gxrom-m",
829         0x00000, 0x80000,
830         CRC(e21a09e4) SHA1(09932d543594e459eeb94a79654168cd15e79a87),
831         ROM_BIOS(4) )
832
833   /* there does not seem to exist an N revision? */
834   
835   ROM_SYSTEM_BIOS( 4, "p", "Version P" )
836   ROMX_LOAD( "gxrom-p",
837         0x00000, 0x80000,
838         CRC(022d46df) SHA1(877a536865641f096212d1ce7296f580afbd6a2d),
839         ROM_BIOS(5) )
840ROM_END
841
842#define rom_hp48g rom_hp48gx
843
844
845/* These ROMS are common to the S and SX models.
846   The only difference is that, the S beeing later, it was only shipped with revisions
847   E and later.
848
849   (Note that G/GX revisions start at K, after the S/S revisions ends...)
850 */
851
852ROM_START ( hp48sx )
853        ROM_REGION( 0x40000, REGION_CPU1, 0 )
854
855   /* latest revision (preferred) */
856   ROM_SYSTEM_BIOS( 0, "j", "Version J" )
857   ROMX_LOAD( "sxrom-j",
858         0x00000, 0x40000,
859         CRC(1a6378ef) SHA1(5235f5379f1fd7edfe9bb6bf466b60d279163e73),
860         ROM_BIOS(1) )
861
862   /* now in chronological order, from first revision */
863
864   ROM_SYSTEM_BIOS( 1, "a", "Version A" )
865   ROMX_LOAD( "sxrom-a",
866         0x00000, 0x40000,
867         CRC(a87696c7) SHA1(3271b103ad99254d069e20171beb418ace72cc90),
868         ROM_BIOS(2) )
869
870   ROM_SYSTEM_BIOS( 2, "b", "Version B" )
871   ROMX_LOAD( "sxrom-b",
872         0x00000, 0x40000,
873         CRC(034f6ce4) SHA1(acd256f2efee868ce402008f4131d94b312e60bc),
874         ROM_BIOS(3) )
875
876
877   ROM_SYSTEM_BIOS( 3, "c", "Version C" )
878   ROMX_LOAD( "sxrom-c",
879         0x00000, 0x40000,
880         CRC(a9a0279d) SHA1(fee852d43ae6941d07a9d0d31f37e68e4f9051b1),
881         ROM_BIOS(4) )
882
883
884   ROM_SYSTEM_BIOS( 4, "d", "Version D" )
885   ROMX_LOAD( "sxrom-d",
886         0x00000, 0x40000,
887         CRC(f8f5dc58) SHA1(3be5f895f4c731fd4c863237c7342cab4e8c42b1),
888         ROM_BIOS(5) )
889
890
891   ROM_SYSTEM_BIOS( 5, "e", "Version E" )
892   ROMX_LOAD( "sxrom-e",
893         0x00000, 0x40000,
894         CRC(704ffa08) SHA1(0d498d135bf729c1d775cce522528837729e2e94),
895         ROM_BIOS(6) )
896
897   /* no F, G, H, I revisions? */
898
899ROM_END
900
901#define rom_hp48s rom_hp48sx
902
903
904/**************************** memory *******************************/
905
906/* In memory, nibbles are unpacked: one nibble at each address.
907   This is due to the way the SATURN emulation is done.
908   As a consequence only the 4 lower bits of each byte is used, the 4 higher
909   bits being zeros.
910   Another consequence is that ROMs must be unpacked before use.
911
912   Because of the complex memory manager, actual address mapping is done at
913   run-time.
914 */
915
916static ADDRESS_MAP_START ( hp48, ADDRESS_SPACE_PROGRAM, 8 )
917 
918   AM_RANGE( 0x00000, 0xfffff ) AM_NOP /* configured at run-time */
919
920ADDRESS_MAP_END
921
922
923
924/********************** Saturn's I/O *******************************/
925
926static const SATURN_CONFIG hp48_config = {
927   hp48_reg_out, hp48_reg_in,
168928   hp48_mem_reset, hp48_mem_config, hp48_mem_unconfig, hp48_mem_id,
169   hp48_crc
929   hp48_mem_crc,
930   hp48_rsi
170931};
171932
172933
173static MACHINE_DRIVER_START( hp48s )
174   /* basic machine hardware */
175   MDRV_CPU_ADD_TAG("main", SATURN, 4000000)      /* 2 MHz */
176   MDRV_CPU_PROGRAM_MAP(hp48_mem, 0)
177   MDRV_CPU_CONFIG(config)
178   MDRV_INTERLEAVE(1)
934/*************************** layout ********************************/
179935
180   MDRV_MACHINE_RESET( hp48 )
936static const char layout_hp48gx[] = "hp48gx";
937static const char layout_hp48g [] = "hp48g";
938static const char layout_hp48sx[] = "hp48sx";
939static const char layout_hp48s [] = "hp48s";
181940
182   /* video hardware (well, actually there was no video ;) */
183   /* scanned with 300 dpi, scaled x 55%, y 55% for perfect display 2x2 pixels */
184   MDRV_SCREEN_ADD("main", LCD)
185   MDRV_SCREEN_REFRESH_RATE(64)
186   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
187   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
188   MDRV_SCREEN_SIZE(339, 775)
189   MDRV_SCREEN_VISIBLE_AREA(0, 339-1, 0, 775-1)
190   MDRV_GFXDECODE( hp48 )
191   MDRV_PALETTE_LENGTH( 4 )
192   MDRV_PALETTE_INIT( hp48 )
193941
194   MDRV_VIDEO_START( hp48 )
195   MDRV_VIDEO_UPDATE( hp48 )
942/*************************** driver ********************************/
943
944
945
946static MACHINE_DRIVER_START ( hp48_common )
947
948   MDRV_MACHINE_RESET ( hp48 )
949
950   /* cpu */
951        MDRV_CPU_ADD_TAG ( "main", SATURN, 3937007 ) /* almost 4 MHz */
952        MDRV_CPU_PROGRAM_MAP ( hp48, 0 )
953        MDRV_CPU_CONFIG( hp48_config )
954 
955        /* memory */
956        MDRV_NVRAM_HANDLER( generic_0fill )
957   
958   /* video */
959        MDRV_SCREEN_ADD( "main", RASTER )
960   MDRV_SCREEN_REFRESH_RATE( 64 )
961        MDRV_SCREEN_VBLANK_TIME(0)
962        MDRV_INTERLEAVE ( 0 )
963        MDRV_SCREEN_FORMAT( BITMAP_FORMAT_INDEXED16 )
964        MDRV_SCREEN_SIZE ( 131, 64 )
965        MDRV_SCREEN_VISIBLE_AREA( 0, 130, 0, 63 )
966        MDRV_PALETTE_LENGTH( 256 ) /* monochrome, but with varying contrast and grayscale */
967        MDRV_PALETTE_INIT( hp48 )
968        MDRV_VIDEO_UPDATE( hp48 )
969     
970        /* sound */
971        MDRV_SPEAKER_STANDARD_MONO( "mono" )
972        MDRV_SOUND_ADD ( DAC, 0 )
973        MDRV_SOUND_ROUTE( ALL_OUTPUTS, "mono", 1.) /* 1-bit beeper */
974
196975MACHINE_DRIVER_END
197976
977static MACHINE_DRIVER_START ( hp48gx )
198978
199static MACHINE_DRIVER_START( hp48g )
200   MDRV_IMPORT_FROM( hp48s )
201   MDRV_CPU_REPLACE( "main", SATURN, 8000000 )      /* 4 MHz */
202   MDRV_CPU_PROGRAM_MAP(hp48_mem, 0)
203   MDRV_CPU_CONFIG(config)
979        MDRV_IMPORT_FROM    ( hp48_common )
980   MDRV_MACHINE_START  ( hp48gx )
981        MDRV_DEFAULT_LAYOUT ( layout_hp48gx )
982
983        /* expansion ports */
984        MDRV_DEVICE_ADD     ( "port1", HP48_PORT )
985        MDRV_DEVICE_CONFIG  ( hp48gx_port1_config )
986        MDRV_DEVICE_ADD     ( "port2", HP48_PORT )
987        MDRV_DEVICE_CONFIG  ( hp48gx_port2_config )
988
989        /* serial I/O */
990        MDRV_DEVICE_ADD( "rs232-x", XMODEM )
991        MDRV_DEVICE_CONFIG( hp48_xmodem_rs232_conf )
992        MDRV_DEVICE_ADD( "rs232-k", KERMIT )
993        MDRV_DEVICE_CONFIG( hp48_kermit_rs232_conf )
994
204995MACHINE_DRIVER_END
205996
206ROM_START(hp48s)
207   ROM_REGION(0x1c0000,REGION_CPU1, 0)
208   /* version at 0x7fff0 little endian 6 characters */
209   /* 0x3fff8 in byte wide rom */
210   ROM_SYSTEM_BIOS( 0, "sxrom-a",  "sxrom-a" )
211   ROMX_LOAD("sxrom-a", 0x00000, 0x40000, CRC(a87696c7) SHA1(3271b103ad99254d069e20171beb418ace72cc90), ROM_BIOS(1) )
212   ROM_SYSTEM_BIOS( 1, "sxrom-b",  "sxrom-b" )
213   ROMX_LOAD("sxrom-b", 0x00000, 0x40000, CRC(034f6ce4) SHA1(acd256f2efee868ce402008f4131d94b312e60bc), ROM_BIOS(2) )
214   ROM_SYSTEM_BIOS( 2, "sxrom-c",  "sxrom-c" )
215   ROMX_LOAD("sxrom-c", 0x00000, 0x40000, CRC(a9a0279d) SHA1(fee852d43ae6941d07a9d0d31f37e68e4f9051b1), ROM_BIOS(3) )
216   ROM_SYSTEM_BIOS( 3, "sxrom-d",  "sxrom-d" )
217   ROMX_LOAD("sxrom-d", 0x00000, 0x40000, CRC(6e71244e) SHA1(893f29abd17434db7da986b27dc10c48f458d3aa), ROM_BIOS(4) )
218   ROM_SYSTEM_BIOS( 4, "sxrom-e",  "sxrom-e" )
219   ROMX_LOAD("sxrom-e", 0x00000, 0x40000, CRC(704ffa08) SHA1(0d498d135bf729c1d775cce522528837729e2e94), ROM_BIOS(5) )
220   ROM_SYSTEM_BIOS( 5, "sxrom-ea",  "sxrom-e(Alternate)")
221   ROMX_LOAD("sxrom-ea", 0x00000, 0x40000, CRC(d4f1390b) SHA1(f6be01a05aedefa8a285d480e33458447cf2bdaa), ROM_BIOS(6) )// differences only in the hardware window
222   ROM_SYSTEM_BIOS( 6, "sxrom-f",    "sxrom-f")
223   ROMX_LOAD("sxrom-f", 0x00000, 0x40000, NO_DUMP, ROM_BIOS(7) )
224   ROM_SYSTEM_BIOS( 7, "sxrom-j",  "sxrom-j" )
225   ROMX_LOAD("sxrom-j", 0x00000, 0x40000, CRC(1a6378ef) SHA1(5235f5379f1fd7edfe9bb6bf466b60d279163e73), ROM_BIOS(8) )
226//  ROM_SYSTEM_BIOS( 8, "rom.sx",  "bad version e dump" )
227//  ROMX_LOAD("rom.sx", 0x00000, 0x40000, CRC(5619ccaf), ROM_BIOS(9) ) //revision E bad dump
228   ROM_REGION(0x100,REGION_GFX1,0)
229ROM_END
997static MACHINE_DRIVER_START ( hp48g )
230998
231ROM_START(hp48g)
232   ROM_REGION(0x580000,REGION_CPU1, 0)
233   /* version at 0x7ffbf little endian 6 characters */
234   ROM_SYSTEM_BIOS( 0, "gxrom-k",  "gxrom-k" )
235   ROMX_LOAD("gxrom-k", 0x00000, 0x80000, CRC(bdd5d2ee) SHA1(afa1498238e991b1e3d07fb8b4c227b115f7bcc1), ROM_BIOS(1) )
236   ROM_SYSTEM_BIOS( 1, "gxrom-l",  "gxrom-l" )
237   ROMX_LOAD("gxrom-l", 0x00000, 0x80000, CRC(70958e6b) SHA1(8eebac69ff804086247b989bf320e57a2d8a59a7), ROM_BIOS(2) )
238   ROM_SYSTEM_BIOS( 2, "gxrom-m",  "gxrom-m" )
239   ROMX_LOAD("gxrom-m", 0x00000, 0x80000, CRC(e21a09e4) SHA1(09932d543594e459eeb94a79654168cd15e79a87), ROM_BIOS(3) )
240   ROM_SYSTEM_BIOS( 3, "gxrom-p",  "gxrom-p" )
241   ROMX_LOAD("gxrom-p", 0x00000, 0x80000, CRC(27f90428) SHA1(b98312716ff81b9b439002c2ec7a07b9808440fb), ROM_BIOS(4) )
242   ROM_SYSTEM_BIOS( 4, "gxrom-r",  "gxrom-r" )
243   ROMX_LOAD("gxrom-r", 0x00000, 0x80000, CRC(00ee1a62) SHA1(5705fc9ea791916c4456ac35e22275862411db9b), ROM_BIOS(5) )
244   ROM_REGION(0x100,REGION_GFX1,0)
245ROM_END
999        MDRV_IMPORT_FROM    ( hp48_common )
1000   MDRV_MACHINE_START  ( hp48g )
1001        MDRV_DEFAULT_LAYOUT ( layout_hp48g )
2461002
247/*    YEAR  NAME    PARENT  COMPAT  MACHINE INPUT   INIT    CONFIG  COMPANY             FULLNAME    FLAGS */
248COMP( 1989, hp48s,  0,      0,      hp48s,  hp48s,  hp48s,  NULL,   "Hewlett Packard",  "HP48S/SX", GAME_NOT_WORKING )
249COMP( 1993, hp48g,  0,      0,      hp48g,  hp48s,  hp48g,  NULL,   "Hewlett Packard",  "HP48G/GX", GAME_NOT_WORKING )
1003        /* serial I/O */
1004        MDRV_DEVICE_ADD( "rs232-x", XMODEM )
1005        MDRV_DEVICE_CONFIG( hp48_xmodem_rs232_conf )
1006        MDRV_DEVICE_ADD( "rs232-k", KERMIT )
1007        MDRV_DEVICE_CONFIG( hp48_kermit_rs232_conf )
1008
1009MACHINE_DRIVER_END
1010
1011
1012static MACHINE_DRIVER_START ( hp48sx )
1013
1014        MDRV_IMPORT_FROM    ( hp48_common )
1015        MDRV_CPU_REPLACE    ( "main", SATURN, 2000000 )
1016   MDRV_MACHINE_START  ( hp48sx )
1017        MDRV_DEFAULT_LAYOUT ( layout_hp48sx )
1018
1019        /* expansion ports */
1020        MDRV_DEVICE_ADD     ( "port1", HP48_PORT )
1021        MDRV_DEVICE_CONFIG  ( hp48sx_port1_config )
1022        MDRV_DEVICE_ADD     ( "port2", HP48_PORT )
1023        MDRV_DEVICE_CONFIG  ( hp48sx_port2_config )
1024
1025        /* serial I/O */
1026        MDRV_DEVICE_ADD( "rs232-k", KERMIT )
1027        MDRV_DEVICE_CONFIG( hp48_kermit_rs232_conf )
1028
1029MACHINE_DRIVER_END
1030
1031static MACHINE_DRIVER_START ( hp48s )
1032
1033        MDRV_IMPORT_FROM    ( hp48_common )
1034        MDRV_CPU_REPLACE    ( "main", SATURN, 2000000 )
1035   MDRV_MACHINE_START  ( hp48s )
1036        MDRV_DEFAULT_LAYOUT ( layout_hp48s )
1037
1038        /* serial I/O */
1039        MDRV_DEVICE_ADD( "rs232-k", KERMIT )
1040        MDRV_DEVICE_CONFIG( hp48_kermit_rs232_conf )
1041
1042MACHINE_DRIVER_END
1043
1044
1045
1046
1047COMP ( 1990, hp48sx, 0     , 0, hp48sx, hp48sx, hp48, NULL, "Hewlett Packard", "HP48SX", 0 )
1048COMP ( 1991, hp48s , hp48sx, 0, hp48s,  hp48sx, hp48, NULL, "Hewlett Packard", "HP48S", 0 )
1049COMP ( 1993, hp48gx, 0     , 0, hp48gx, hp48gx, hp48, NULL, "Hewlett Packard", "HP48GX", 0 )
1050COMP ( 1993, hp48g , hp48gx, 0, hp48g,  hp48gx, hp48, NULL, "Hewlett Packard", "HP48G", 0 )
1051

Previous 15994 Revisions Next


© 1998-2018 The MESS Team