Previous 15994 Revisions Next

r3317 Wednesday 24th September, 2008 at 10:06:00 UTC by Wilbert Pol
[KIM1] Fixed cassette reading emulation.
[src/mess/drivers]kim1.c

src/mess/drivers/kim1.c
r3316r3317
6161        ---------------------------------------------
6262            0-7 bus PB0-7           bus PB0-7
6363
64
65The cassette interface
66======================
67
68The KIM-1 stores data on cassette using 2 frequencies: ~3700Hz (high) and ~2400Hz
69(low). A high tone is output for 9 cycles and a low tone for 6 cycles. A logic bit
70is encoded using 3 sequences of high and low tones. It always starts with a high
71tone and ends with a low tone. The middle tone is high for a logic 0 and low for
720 logic 1.
73
74These high and low tone signals are fed to a circuit containing a LM565 PLL and
75a 311 comparator. For a high tone a 1 is passed to DB7 of 6530-U2 for a low tone
76a 0 is passed. The KIM-1 software measures the time it takes for the signal to
77change from 1 to 0.
78
79
6480******************************************************************************/
6581
6682#include "driver.h"
r3316r3317
6985#include "kim1.lh"
7086
7187
72static UINT8      u2_port_b;
88static UINT8      kim1_u2_port_b;
89static UINT8      kim1_311_output;
90static UINT32      kim1_cassette_high_count;
7391static UINT8      kim1_led_time[6];
7492
7593
r3316r3317
140158{
141159   UINT8   data = 0xff;
142160
143   switch( ( u2_port_b >> 1 ) & 0x0f )
161   switch( ( kim1_u2_port_b >> 1 ) & 0x0f )
144162   {
145163   case 0:
146164      data = input_port_read(device->machine, "LINE0");
r3316r3317
158176
159177static void kim1_u2_write_a(const device_config *device, UINT8 newdata, UINT8 olddata)
160178{
161   UINT8 idx = ( u2_port_b >> 1 ) & 0x0f;
179   UINT8 idx = ( kim1_u2_port_b >> 1 ) & 0x0f;
162180
163181   if ( idx >= 4 && idx < 10 )
164182   {
r3316r3317
173191
174192static UINT8 kim1_u2_read_b(const device_config *device, UINT8 olddata)
175193{
176   double tap_val = cassette_input( device_list_find_by_tag( device->machine->config->devicelist, CASSETTE, "cassette" ) );
177
178194   if ( miot6530_portb_out_get(device) & 0x20 )
179195      return 0xFF;
180196
181//   printf("kim1_u2_read_b(): tap_val = %f\n", tap_val);
182   return 0x7F | ( tap_val >= 0.0 ? 0x80 : 0x00 );
197   return 0x7F | ( kim1_311_output ^ 0x80 );
183198}
184199
185200
186201static void kim1_u2_write_b(const device_config *device, UINT8 newdata, UINT8 olddata)
187202{
188   u2_port_b = newdata;
203   kim1_u2_port_b = newdata;
189204
190205   if ( newdata & 0x20 )
191206   {
r3316r3317
237252};
238253
239254
255static TIMER_CALLBACK( kim1_cassette_input )
256{
257   double tap_val = cassette_input( device_list_find_by_tag( machine->config->devicelist, CASSETTE, "cassette" ) );
258
259   if ( tap_val <= 0 )
260   {
261      if ( kim1_cassette_high_count )
262      {
263         kim1_311_output = ( kim1_cassette_high_count < 8 ) ? 0x80 : 0;
264         kim1_cassette_high_count = 0;
265      }
266   }
267
268   if ( tap_val > 0 )
269   {
270      kim1_cassette_high_count++;
271   }
272}
273
274
240275static TIMER_CALLBACK( kim1_update_leds )
241276{
242277   int i;
r3316r3317
251286}
252287
253288
289static MACHINE_START( kim1 )
290{
291   state_save_register_item( "kim1", 0, kim1_u2_port_b );
292   state_save_register_item( "kim1", 0, kim1_311_output );
293   state_save_register_item( "kim1", 0, kim1_cassette_high_count );
294}
295
296
254297static MACHINE_RESET( kim1 )
255298{
256299   int i;
257300
258301   timer_pulse( ATTOTIME_IN_HZ(60), NULL, 0, kim1_update_leds );
302   timer_pulse( ATTOTIME_IN_HZ(44100), NULL, 0, kim1_cassette_input );
259303
260304   for ( i = 0; i < 6; i++ )
261305   {
262306      kim1_led_time[i] = 0;
263307   }
308
309   kim1_311_output = 0;
310   kim1_cassette_high_count = 0;
264311}
265312
266313
r3316r3317
270317   MDRV_CPU_PROGRAM_MAP(kim1_map, 0)
271318   MDRV_INTERLEAVE(1)
272319
320   MDRV_MACHINE_START( kim1 )
273321   MDRV_MACHINE_RESET( kim1 )
274322
275323   MDRV_MIOT6530_ADD( "miot_u2", 1000000, kim1_u2_miot6530_interface )
r3316r3317
348396#endif
349397
350398/*    YEAR  NAME      PARENT    COMPAT  MACHINE   INPUT     INIT      CONFIG  COMPANY   FULLNAME */
351COMP( 1975, kim1,     0,       0,      kim1,     kim1,    0,        0,     "MOS Technologies",  "KIM-1" , 0)
399COMP( 1975, kim1,     0,       0,      kim1,     kim1,    0,        0,     "MOS Technologies",  "KIM-1" , GAME_SUPPORTS_SAVE)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team