double cassette_image_device::get_position() { double position = m_position; if (is_motor_on()) position += (device().machine().time().as_double() - m_position_time)*m_speed*m_direction; return position; }
/* Turns the motor on if not */ static void motor_on(void) { //LOG("motor_on() called ...\n"); if ( !is_motor_on()) { //LOG("Switch on motor...\n"); outb_p(0x1c,FD_DOR); sleep(30); /* delay 300 milliseconds for motor on */ motoron = TRUE; } }
/* Truns the motor off if on */ static void motor_off (void) { //LOG("motor_off() called ...\n"); if (is_motor_on() ) { count_down = 30; /* start motor kill countdown: about 300 ms */ while(count_down) ; outb_p(0x0c,FD_DOR); motoron = FALSE; } }
std::string cassette_image_device::call_display() { const int ANIMATION_FPS = 1; std::string result; // only show the image when a cassette is loaded and the motor is on if (exists() && is_motor_on()) { int n; double position, length; cassette_state uistate; static const char *shapes[] = { u8"\u2500", u8"\u2572", u8"\u2502", u8"\u2571" }; // figure out where we are in the cassette position = get_position(); length = get_length(); uistate = (cassette_state)(get_state() & CASSETTE_MASK_UISTATE); // choose which frame of the animation we are at n = ((int)position / ANIMATION_FPS) % ARRAY_LENGTH(shapes); // play or record const char *status_icon = (uistate == CASSETTE_PLAY) ? u8"\u25BA" : u8"\u25CF"; // Since you can have anything in a BDF file, we will use crude ascii characters instead result = string_format("%s %s %02d:%02d (%04d) [%02d:%02d (%04d)]", shapes[n], // animation status_icon, // play or record ((int)position / 60), ((int)position % 60), (int)position, ((int)length / 60), ((int)length % 60), (int)length); // make sure tape stops at end when playing if ((m_state & CASSETTE_MASK_UISTATE) == CASSETTE_PLAY) { if (m_cassette) { if (get_position() > get_length()) { m_state = (cassette_state)((m_state & ~CASSETTE_MASK_UISTATE) | CASSETTE_STOPPED); } } } } return result; }
void cassette_image_device::update() { double cur_time = device().machine().time().as_double(); if (is_motor_on()) { double new_position = m_position + (cur_time - m_position_time)*m_speed*m_direction; switch(m_state & CASSETTE_MASK_UISTATE) { case CASSETTE_RECORD: cassette_put_sample(m_cassette, m_channel, m_position, new_position - m_position, m_value); break; case CASSETTE_PLAY: if ( m_cassette ) { cassette_get_sample(m_cassette, m_channel, new_position, 0.0, &m_value); /* See if reached end of tape */ double length = get_length(); if (new_position > length) { m_state = (cassette_state)(( m_state & ~CASSETTE_MASK_UISTATE ) | CASSETTE_STOPPED); new_position = length; } else if (new_position < 0) { m_state = (cassette_state)(( m_state & ~CASSETTE_MASK_UISTATE ) | CASSETTE_STOPPED); new_position = 0; } } break; } m_position = new_position; } m_position_time = cur_time; }
/* display a small tape icon, with the current position in the tape image */ void cassette_image_device::call_display() { char buf[65]; float x, y; int n; double position, length; cassette_state uistate; cassette_image_device *dev; static const UINT8 shapes[8] = { 0x2d, 0x5c, 0x7c, 0x2f, 0x2d, 0x20, 0x20, 0x20 }; /* abort if we should not be showing the image */ if (!exists()) return; if (!is_motor_on()) return; /* figure out where we are in the cassette */ position = get_position(); length = get_length(); uistate = (cassette_state)(get_state() & CASSETTE_MASK_UISTATE); /* choose a location on the screen */ x = 0.2f; y = 0.5f; cassette_device_iterator iter(device().machine().root_device()); for (dev = iter.first(); dev != nullptr && dev->tag()!=device().tag(); dev = iter.next()) y += 1; y *= device().machine().ui().get_line_height() + 2.0f * UI_BOX_TB_BORDER; /* choose which frame of the animation we are at */ n = ((int) position / ANIMATION_FPS) % ANIMATION_FRAMES; /* Since you can have anything in a BDF file, we will use crude ascii characters instead */ snprintf(buf, ARRAY_LENGTH(buf), "%c%c %c %02d:%02d (%04d) [%02d:%02d (%04d)]", #if 0 /* THE ANIMATION HASN'T WORKED SINCE 0.114 - LEFT HERE FOR REFERENCE */ /* NEVER SEEN THE PLAY / RECORD ICONS */ /* character pairs 2-3, 4-5, 6-7, 8-9 form little tape cassette images */ n * 2 + 2, /* cassette icon left */ n * 2 + 3, /* cassette icon right */ (uistate == CASSETTE_PLAY) ? 16 : 14, /* play or record icon */ #else shapes[n], /* cassette icon left */ shapes[n|4], /* cassette icon right */ (uistate == CASSETTE_PLAY) ? 0x50 : 0x52, /* play (P) or record (R) */ #endif ((int) position / 60), ((int) position % 60), (int) position, ((int) length / 60), ((int) length % 60), (int) length); // draw the cassette device().machine().ui().draw_text_box(&device().machine().render().ui_container(), buf, JUSTIFY_LEFT, x, y, UI_BACKGROUND_COLOR); // make sure tape stops at end when playing if ((m_state & CASSETTE_MASK_UISTATE) == CASSETTE_PLAY) { if ( m_cassette ) { if (position > length) { m_state = (cassette_state)(( m_state & ~CASSETTE_MASK_UISTATE ) | CASSETTE_STOPPED); } } } }