src/mess/drivers/kim1.c
| r3316 | r3317 | |
| 61 | 61 | --------------------------------------------- |
| 62 | 62 | 0-7 bus PB0-7 bus PB0-7 |
| 63 | 63 | |
| 64 | |
| 65 | The cassette interface |
| 66 | ====================== |
| 67 | |
| 68 | The 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 |
| 70 | is encoded using 3 sequences of high and low tones. It always starts with a high |
| 71 | tone and ends with a low tone. The middle tone is high for a logic 0 and low for |
| 72 | 0 logic 1. |
| 73 | |
| 74 | These high and low tone signals are fed to a circuit containing a LM565 PLL and |
| 75 | a 311 comparator. For a high tone a 1 is passed to DB7 of 6530-U2 for a low tone |
| 76 | a 0 is passed. The KIM-1 software measures the time it takes for the signal to |
| 77 | change from 1 to 0. |
| 78 | |
| 79 | |
| 64 | 80 | ******************************************************************************/ |
| 65 | 81 | |
| 66 | 82 | #include "driver.h" |
| r3316 | r3317 | |
| 69 | 85 | #include "kim1.lh" |
| 70 | 86 | |
| 71 | 87 | |
| 72 | | static UINT8 u2_port_b; |
| 88 | static UINT8 kim1_u2_port_b; |
| 89 | static UINT8 kim1_311_output; |
| 90 | static UINT32 kim1_cassette_high_count; |
| 73 | 91 | static UINT8 kim1_led_time[6]; |
| 74 | 92 | |
| 75 | 93 | |
| r3316 | r3317 | |
| 140 | 158 | { |
| 141 | 159 | UINT8 data = 0xff; |
| 142 | 160 | |
| 143 | | switch( ( u2_port_b >> 1 ) & 0x0f ) |
| 161 | switch( ( kim1_u2_port_b >> 1 ) & 0x0f ) |
| 144 | 162 | { |
| 145 | 163 | case 0: |
| 146 | 164 | data = input_port_read(device->machine, "LINE0"); |
| r3316 | r3317 | |
| 158 | 176 | |
| 159 | 177 | static void kim1_u2_write_a(const device_config *device, UINT8 newdata, UINT8 olddata) |
| 160 | 178 | { |
| 161 | | UINT8 idx = ( u2_port_b >> 1 ) & 0x0f; |
| 179 | UINT8 idx = ( kim1_u2_port_b >> 1 ) & 0x0f; |
| 162 | 180 | |
| 163 | 181 | if ( idx >= 4 && idx < 10 ) |
| 164 | 182 | { |
| r3316 | r3317 | |
| 173 | 191 | |
| 174 | 192 | static UINT8 kim1_u2_read_b(const device_config *device, UINT8 olddata) |
| 175 | 193 | { |
| 176 | | double tap_val = cassette_input( device_list_find_by_tag( device->machine->config->devicelist, CASSETTE, "cassette" ) ); |
| 177 | | |
| 178 | 194 | if ( miot6530_portb_out_get(device) & 0x20 ) |
| 179 | 195 | return 0xFF; |
| 180 | 196 | |
| 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 ); |
| 183 | 198 | } |
| 184 | 199 | |
| 185 | 200 | |
| 186 | 201 | static void kim1_u2_write_b(const device_config *device, UINT8 newdata, UINT8 olddata) |
| 187 | 202 | { |
| 188 | | u2_port_b = newdata; |
| 203 | kim1_u2_port_b = newdata; |
| 189 | 204 | |
| 190 | 205 | if ( newdata & 0x20 ) |
| 191 | 206 | { |
| r3316 | r3317 | |
| 237 | 252 | }; |
| 238 | 253 | |
| 239 | 254 | |
| 255 | static 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 | |
| 240 | 275 | static TIMER_CALLBACK( kim1_update_leds ) |
| 241 | 276 | { |
| 242 | 277 | int i; |
| r3316 | r3317 | |
| 251 | 286 | } |
| 252 | 287 | |
| 253 | 288 | |
| 289 | static 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 | |
| 254 | 297 | static MACHINE_RESET( kim1 ) |
| 255 | 298 | { |
| 256 | 299 | int i; |
| 257 | 300 | |
| 258 | 301 | timer_pulse( ATTOTIME_IN_HZ(60), NULL, 0, kim1_update_leds ); |
| 302 | timer_pulse( ATTOTIME_IN_HZ(44100), NULL, 0, kim1_cassette_input ); |
| 259 | 303 | |
| 260 | 304 | for ( i = 0; i < 6; i++ ) |
| 261 | 305 | { |
| 262 | 306 | kim1_led_time[i] = 0; |
| 263 | 307 | } |
| 308 | |
| 309 | kim1_311_output = 0; |
| 310 | kim1_cassette_high_count = 0; |
| 264 | 311 | } |
| 265 | 312 | |
| 266 | 313 | |
| r3316 | r3317 | |
| 270 | 317 | MDRV_CPU_PROGRAM_MAP(kim1_map, 0) |
| 271 | 318 | MDRV_INTERLEAVE(1) |
| 272 | 319 | |
| 320 | MDRV_MACHINE_START( kim1 ) |
| 273 | 321 | MDRV_MACHINE_RESET( kim1 ) |
| 274 | 322 | |
| 275 | 323 | MDRV_MIOT6530_ADD( "miot_u2", 1000000, kim1_u2_miot6530_interface ) |
| r3316 | r3317 | |
| 348 | 396 | #endif |
| 349 | 397 | |
| 350 | 398 | /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT CONFIG COMPANY FULLNAME */ |
| 351 | | COMP( 1975, kim1, 0, 0, kim1, kim1, 0, 0, "MOS Technologies", "KIM-1" , 0) |
| 399 | COMP( 1975, kim1, 0, 0, kim1, kim1, 0, 0, "MOS Technologies", "KIM-1" , GAME_SUPPORTS_SAVE) |