static BYTE read_ciapa(cia_context_t *cia_context) { BYTE byte; BYTE val = 0xff; BYTE msk; BYTE m, tmp; int i; DBGA(("PA ddra:%02x pa:%02x ddrb:%02x pb:%02x ", cia_context->c_cia[CIA_DDRA], cia_context->c_cia[CIA_PRA], cia_context->c_cia[CIA_DDRB], cia_context->c_cia[CIA_PRB])); /* loop over columns, pull down all bits connected to a column which is output and active. */ msk = cia_context->old_pb & read_joyport_dig(JOYPORT_1); if (c64keyboard_active) { for (m = 0x1, i = 0; i < 8; m <<= 1, i++) { if (!(msk & m)) { tmp = matrix_get_active_columns_by_column(i); /* when scanning from port B to port A with inactive bits set to 1 in port B, ghostkeys will be eliminated (pulled high) if the matrix is connected to more 1 bits of port B. this does NOT happen when the respective bits are set to input. (see testprogs/CIA/ciaports) */ if (tmp & cia_context->c_cia[CIA_PRB] & cia_context->c_cia[CIA_DDRB]) { val &= ~rev_keyarr[i]; DBGA(("<force high %02x>", m)); } else { val &= ~matrix_get_active_rows_by_column(i); } } } } DBGA((" val:%02x", val)); /* loop over rows, pull down all bits connected to a row which is output and active. handles the case when port a is used for both input and output */ msk = cia_context->old_pa & read_joyport_dig(JOYPORT_2); if (c64keyboard_active) { for (m = 0x1, i = 0; i < 8; m <<= 1, i++) { if (!(msk & m)) { val &= ~matrix_get_active_rows_by_row(i); } } } DBGA((" val:%02x", val)); byte = (val & (cia_context->c_cia[CIA_PRA] | ~(cia_context->c_cia[CIA_DDRA]))) & read_joyport_dig(JOYPORT_2); DBGA((" out:%02x\n", byte)); return byte; }
static BYTE read_ciapa(cia_context_t *cia_context) { BYTE byte; BYTE val = 0xff; BYTE msk; BYTE m, tmp; int i; DBGA(("PA ddra:%02x pa:%02x ddrb:%02x pb:%02x ", cia_context->c_cia[CIA_DDRA], cia_context->c_cia[CIA_PRA], cia_context->c_cia[CIA_DDRB], cia_context->c_cia[CIA_PRB])); /* loop over columns, pull down all bits connected to a column which is output and active. */ msk = cia_context->old_pb & ~joystick_value[1]; for (m = 0x1, i = 0; i < 8; m <<= 1, i++) { if (!(msk & m)) { tmp = matrix_get_active_columns_by_column(i); /* when scanning from port B to port A with inactive bits set to 1 in port B, ghostkeys will be eliminated (pulled high) if the matrix is connected to more 1 bits of port B. this does NOT happen when the respective bits are set to input. (see testprogs/CIA/ciaports) */ if (tmp & cia_context->c_cia[CIA_PRB] & cia_context->c_cia[CIA_DDRB]) { val &= ~rev_keyarr[i]; DBGA(("<force high %02x>", m)); } else { val &= ~matrix_get_active_rows_by_column(i); } } } DBGA((" val:%02x", val)); /* loop over rows, pull down all bits connected to a row which is output and active. handles the case when port a is used for both input and output */ msk = cia_context->old_pa & ~joystick_value[2]; for (m = 0x1, i = 0; i < 8; m <<= 1, i++) { if (!(msk & m)) { val &= ~matrix_get_active_rows_by_row(i); } } DBGA((" val:%02x", val)); byte = (val & (cia_context->c_cia[CIA_PRA] | ~(cia_context->c_cia[CIA_DDRA]))) & ~joystick_value[2]; DBGA((" out:%02x\n", byte)); #ifdef HAVE_MOUSE if (_mouse_enabled && (mouse_port == 2)) { switch (mouse_type) { case MOUSE_TYPE_NEOS: byte &= neos_mouse_read(); break; case MOUSE_TYPE_SMART: byte &= smart_mouse_read(); break; case MOUSE_TYPE_ST: case MOUSE_TYPE_AMIGA: case MOUSE_TYPE_CX22: byte &= mouse_poll(); break; case MOUSE_TYPE_MICROMYS: byte &= micromys_mouse_read(); break; default: break; } } #endif return byte; }