1 /* 2 * mc6821core.h - Motorola MC6821 Emulation 3 * 4 * Written by 5 * groepaz <groepaz@gmx.net> 6 * 7 * This file is part of VICE, the Versatile Commodore Emulator. 8 * See README for copyright notice. 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 23 * 02111-1307 USA. 24 * 25 */ 26 27 #ifndef VICE_MC6821CORE_H_ 28 #define VICE_MC6821CORE_H_ 29 30 #include "types.h" 31 32 /* control register bit masks */ 33 34 #define MC6821_CTRL_IRQ1 0x80 35 #define MC6821_CTRL_IRQ2 0x40 36 #define MC6821_CTRL_C2DDR 0x20 37 #define MC6821_CTRL_C2MODE 0x18 38 #define MC6821_CTRL_REG 0x04 39 #define MC6821_CTRL_C1MODE 0x03 40 41 /* control register bits */ 42 43 #define MC6821_CTRL_C2_IN 0x00 44 #define MC6821_CTRL_C2_OUT 0x20 45 /* when C(A/B)2 is input */ 46 #define MC6821_CTRL_C2_IRQDIS 0x00 47 #define MC6821_CTRL_C2_IRQEN 0x08 48 #define MC6821_CTRL_C2_IRQHILO 0x00 49 #define MC6821_CTRL_C2_IRQLOHI 0x10 50 /* when C(A/B)2 is output */ 51 #define MC6821_CTRL_C2_STROBE_C 0x00 52 #define MC6821_CTRL_C2_STROBE_E 0x08 53 #define MC6821_CTRL_C2_RESET_C2 0x10 54 #define MC6821_CTRL_C2_SET_C2 0x18 55 56 #define MC6821_CTRL_REG_DDR 0x00 57 #define MC6821_CTRL_REG_DATA 0x04 58 59 #define MC6821_CTRL_C1_IRQDIS 0x00 60 #define MC6821_CTRL_C1_IRQEN 0x01 61 #define MC6821_CTRL_C1_IRQHILO 0x00 62 #define MC6821_CTRL_C1_IRQLOHI 0x02 63 64 typedef struct _mc6821_state { 65 uint8_t ctrlA; 66 uint8_t dataA; 67 uint8_t ddrA; 68 69 uint8_t ctrlB; 70 uint8_t dataB; 71 uint8_t ddrB; 72 73 int CA2; 74 int CA2state; 75 int CB2; 76 int CB2state; 77 78 /* hooks that set the i/o lines */ 79 void (*set_pa)(struct _mc6821_state*); 80 void (*set_pb)(struct _mc6821_state*); 81 82 /* TODO 83 void (*set_irqa)(struct _mc6821_state*); 84 void (*set_irqb)(struct _mc6821_state*); 85 */ 86 void (*set_ca2)(struct _mc6821_state*); 87 void (*set_cb2)(struct _mc6821_state*); 88 89 /* hooks that read the status of i/o lines */ 90 uint8_t (*get_pa)(struct _mc6821_state*); 91 uint8_t (*get_pb)(struct _mc6821_state*); 92 93 void *p; /* parent context that may be used by the hooks */ 94 } mc6821_state; 95 96 void mc6821core_reset(mc6821_state *ctx); 97 uint8_t mc6821core_read(mc6821_state *ctx, int port /* rs1 */, int reg /* rs0 */); 98 uint8_t mc6821core_peek(mc6821_state *ctx, int port /* rs1 */, int reg /* rs0 */); 99 void mc6821core_store(mc6821_state *ctx, int port /* rs1 */, int reg /* rs0 */, uint8_t data); 100 101 /* Signal values (for signaling edges on the control lines) */ 102 #define MC6821_SIGNAL_CA1 0 103 #define MC6821_SIGNAL_CA2 1 104 #define MC6821_SIGNAL_CB1 2 105 #define MC6821_SIGNAL_CB2 3 106 void mc6821core_set_signal(mc6821_state *ctx, int line); 107 108 struct snapshot_module_s; 109 110 int mc6821core_snapshot_write_data(mc6821_state *ctx, struct snapshot_module_s *m); 111 int mc6821core_snapshot_read_data(mc6821_state *ctx, struct snapshot_module_s *m); 112 113 #endif 114