src/emu/cpu/h83002/h8speriph.c
| r12440 | r12441 | |
| 15 | 15 | #include "h8.h" |
| 16 | 16 | #include "h8priv.h" |
| 17 | 17 | |
| 18 | | #define LOG_LEVEL 1 |
| 19 | | #define _logerror(level,...) if (LOG_LEVEL > level) logerror(__VA_ARGS__) |
| 18 | #define VERBOSE_LEVEL ( 0 ) |
| 20 | 19 | |
| 21 | | //#define ENABLE_SCI_TIMER |
| 20 | INLINE void ATTR_PRINTF(3,4) verboselog( running_machine &machine, int n_level, const char *s_fmt, ...) |
| 21 | { |
| 22 | if (VERBOSE_LEVEL >= n_level) |
| 23 | { |
| 24 | va_list v; |
| 25 | char buf[32768]; |
| 26 | va_start( v, s_fmt); |
| 27 | vsprintf( buf, s_fmt, v); |
| 28 | va_end( v); |
| 29 | logerror( "%s: %s", machine.describe_context( ), buf); |
| 30 | } |
| 31 | } |
| 22 | 32 | |
| 33 | const UINT8 H8S_RESET_H8S_IO_224x[0x1C0] = // values from "e602100_h8s2245.pdf" |
| 34 | { |
| 35 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FE40 |
| 36 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FE50 |
| 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FE60 |
| 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FE70 |
| 39 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FE80 |
| 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FE90 |
| 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FEA0 |
| 42 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, // FEB0 |
| 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FEC0 |
| 44 | 0xFF, 0xFF, 0xFF, 0xFF, 0xD0, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FED0 |
| 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FEE0 |
| 46 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FEF0 |
| 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FF00 |
| 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FF10 |
| 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FF20 |
| 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x01, 0x00, 0x00, 0x3F, 0xFF, 0x00, 0x00, // FF30 |
| 51 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FF40 |
| 52 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FF50 |
| 53 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FF60 |
| 54 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x84, 0x00, 0xF2, 0x00, // FF70 |
| 55 | 0x00, 0xFF, 0x00, 0xFF, 0x84, 0x00, 0xF2, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x84, 0x00, 0xF2, 0x00, // FF80 |
| 56 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FF90 |
| 57 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FFA0 |
| 58 | 0x00, 0x00, 0x00, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FFB0 |
| 59 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FFC0 |
| 60 | 0x00, 0xC0, 0x00, 0x00, 0x40, 0xC0, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // FFD0 |
| 61 | 0x00, 0xC0, 0x00, 0x00, 0x40, 0xC0, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, // FFE0 |
| 62 | 0x00, 0xC0, 0x00, 0x00, 0x40, 0xC0, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, // FFF0 |
| 63 | }; |
| 64 | |
| 65 | const UINT8 H8S_RESET_H8S_IO_2323[0x1C0] = // values from "rej09b0220_h8s2329.pdf" |
| 66 | { |
| 67 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FE40 |
| 68 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FE50 |
| 69 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FE60 |
| 70 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FE70 |
| 71 | 0x00, 0xC0, 0x00, 0x00, 0x40, 0xC0, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // FE80 |
| 72 | 0x00, 0xC0, 0x00, 0x00, 0x40, 0xC0, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, // FE90 |
| 73 | 0x00, 0xC0, 0x00, 0x00, 0x40, 0xC0, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, // FEA0 |
| 74 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, // FEB0 |
| 75 | 0x00, 0x00, 0x00, 0x00, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x00, // FEC0 |
| 76 | 0xFF, 0xFF, 0xFF, 0xFF, 0xD0, 0x3C, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FED0 |
| 77 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FEE0 |
| 78 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FEF0 |
| 79 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FF00 |
| 80 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FF10 |
| 81 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FF20 |
| 82 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x01, 0x00, 0x00, 0x3F, 0xFF, 0x00, 0x00, // FF30 |
| 83 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FF40 |
| 84 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FF50 |
| 85 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FF60 |
| 86 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x84, 0x00, 0xF2, 0x00, // FF70 |
| 87 | 0x00, 0xFF, 0x00, 0xFF, 0x84, 0x00, 0xF2, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x84, 0x00, 0xF2, 0x00, // FF80 |
| 88 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FF90 |
| 89 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, // FFA0 |
| 90 | 0x00, 0x00, 0x00, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FFB0 |
| 91 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // FFC0 |
| 92 | 0x00, 0xC0, 0x00, 0x00, 0x40, 0xC0, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // FFD0 |
| 93 | 0x00, 0xC0, 0x00, 0x00, 0x40, 0xC0, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, // FFE0 |
| 94 | 0x00, 0xC0, 0x00, 0x00, 0x40, 0xC0, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, // FFF0 |
| 95 | }; |
| 96 | |
| 97 | #define SCR_TIE 0x80 |
| 98 | #define SCR_RIE 0x40 |
| 99 | #define SCR_TE 0x20 |
| 100 | #define SCR_RE 0x10 |
| 101 | |
| 102 | #define SSR_TDRE 0x80 |
| 103 | #define SSR_RDRF 0x40 |
| 104 | #define SSR_ORER 0x20 |
| 105 | #define SSR_FER 0x10 |
| 106 | #define SSR_PER 0x08 |
| 107 | #define SSR_TEND 0x04 |
| 108 | |
| 109 | #define SMR_CM 0x80 |
| 110 | #define SMR_CHR 0x40 |
| 111 | #define SMR_PE 0x20 |
| 112 | #define SMR_PM 0x10 |
| 113 | #define SMR_STOP 0x08 |
| 114 | #define SMR_MP 0x04 |
| 115 | #define SMR_CKS1 0x02 |
| 116 | #define SMR_CKS0 0x01 |
| 117 | |
| 118 | #define TCSR_CMFB 0x80 |
| 119 | #define TCSR_CMFA 0x40 |
| 120 | #define TCSR_OVF 0x20 |
| 121 | |
| 122 | #define TCR_CMIEB 0x80 |
| 123 | #define TCR_CMIEA 0x40 |
| 124 | #define TCR_OVIE 0x20 |
| 125 | |
| 126 | #define TSR_TCFD 0x80 |
| 127 | #define TSR_TCFU 0x20 |
| 128 | #define TSR_TCFV 0x10 |
| 129 | #define TSR_TGFD 0x08 |
| 130 | #define TSR_TGFC 0x04 |
| 131 | #define TSR_TGFB 0x02 |
| 132 | #define TSR_TGFA 0x01 |
| 133 | |
| 134 | #define TIER_TCIEU 0x20 |
| 135 | #define TIER_TCIEV 0x10 |
| 136 | #define TIER_TGIED 0x08 |
| 137 | #define TIER_TGIEC 0x04 |
| 138 | #define TIER_TGIEB 0x02 |
| 139 | #define TIER_TGIEA 0x01 |
| 140 | |
| 141 | #define DTC_MRA_MD_NORMAL 0 |
| 142 | #define DTC_MRA_MD_REPEAT 1 |
| 143 | #define DTC_MRA_MD_BLOCK 2 |
| 144 | |
| 145 | #define DTC_MRA_SM1 0x80 |
| 146 | #define DTC_MRA_SM0 0x40 |
| 147 | #define DTC_MRA_DM1 0x20 |
| 148 | #define DTC_MRA_DM0 0x10 |
| 149 | #define DTC_MRA_DTS 0x02 |
| 150 | |
| 151 | #define DTC_MRB_CHNE 0x80 |
| 152 | #define DTC_MRB_DISEL 0x40 |
| 153 | #define DTC_MRB_CHNS 0x20 |
| 154 | |
| 155 | #define DMABCRL_DTME1 0x80 |
| 156 | #define DMABCRL_DTE1 0x40 |
| 157 | #define DMABCRL_DTME0 0x20 |
| 158 | #define DMABCRL_DTE0 0x10 |
| 159 | #define DMABCRL_DTIE1B 0x08 |
| 160 | #define DMABCRL_DTIE1A 0x04 |
| 161 | #define DMABCRL_DTIE0B 0x02 |
| 162 | #define DMABCRL_DTIE0A 0x01 |
| 163 | |
| 164 | #define ADCSR_ADF 0x80 |
| 165 | #define ADCSR_ADIE 0x40 |
| 166 | #define ADCSR_ADST 0x20 |
| 167 | #define ADCSR_SCAN 0x10 |
| 168 | |
| 169 | enum |
| 170 | { |
| 171 | PIN_P10, PIN_P11, PIN_P12, PIN_P13, PIN_P14, PIN_P15, PIN_P16, PIN_P17, |
| 172 | PIN_P20, PIN_P21, PIN_P22, PIN_P23, PIN_P24, PIN_P25, PIN_P26, PIN_P27, |
| 173 | PIN_P30, PIN_P31, PIN_P32, PIN_P33, PIN_P34, PIN_P35, |
| 174 | PIN_P40, PIN_P41, PIN_P42, PIN_P43, PIN_P44, PIN_P45, PIN_P46, PIN_P47, |
| 175 | PIN_P50, PIN_P51, PIN_P52, PIN_P53, |
| 176 | PIN_P60, PIN_P61, PIN_P62, PIN_P63, PIN_P64, PIN_P65, PIN_P66, PIN_P67, |
| 177 | PIN_PA0, PIN_PA1, PIN_PA2, PIN_PA3, PIN_PA4, PIN_PA5, PIN_PA6, PIN_PA7, |
| 178 | PIN_PB0, PIN_PB1, PIN_PB2, PIN_PB3, PIN_PB4, PIN_PB5, PIN_PB6, PIN_PB7, |
| 179 | PIN_PC0, PIN_PC1, PIN_PC2, PIN_PC3, PIN_PC4, PIN_PC5, PIN_PC6, PIN_PC7, |
| 180 | PIN_PD0, PIN_PD1, PIN_PD2, PIN_PD3, PIN_PD4, PIN_PD5, PIN_PD6, PIN_PD7, |
| 181 | PIN_PE0, PIN_PE1, PIN_PE2, PIN_PE3, PIN_PE4, PIN_PE5, PIN_PE6, PIN_PE7, |
| 182 | PIN_PF0, PIN_PF1, PIN_PF2, PIN_PF3, PIN_PF4, PIN_PF5, PIN_PF6, PIN_PF7, |
| 183 | PIN_PG0, PIN_PG1, PIN_PG2, PIN_PG3, PIN_PG4 |
| 184 | }; |
| 185 | |
| 186 | #define PIN_TIOCA0 PIN_P10 |
| 187 | #define PIN_TIOCB0 PIN_P11 |
| 188 | #define PIN_TIOCC0 PIN_P12 |
| 189 | #define PIN_TIOCD0 PIN_P13 |
| 190 | #define PIN_TIOCA1 PIN_P14 |
| 191 | #define PIN_TIOCB1 PIN_P15 |
| 192 | #define PIN_TIOCA2 PIN_P16 |
| 193 | #define PIN_TIOCB2 PIN_P17 |
| 194 | |
| 195 | #define PIN_TCLKA PIN_P12 |
| 196 | #define PIN_TCLKB PIN_P13 |
| 197 | #define PIN_TCLKC PIN_P15 |
| 198 | #define PIN_TCLKD PIN_P17 |
| 199 | |
| 200 | #define PIN_TXD0 PIN_P30 |
| 201 | #define PIN_TXD1 PIN_P31 |
| 202 | #define PIN_RXD0 PIN_P32 |
| 203 | #define PIN_RXD1 PIN_P33 |
| 204 | #define PIN_SCK0 PIN_P34 |
| 205 | #define PIN_SCK1 PIN_P35 |
| 206 | |
| 207 | #define PIN_TIOCA3 PIN_P20 |
| 208 | #define PIN_TIOCB3 PIN_P21 |
| 209 | #define PIN_TIOCC3 PIN_P22 |
| 210 | #define PIN_TIOCD3 PIN_P23 |
| 211 | #define PIN_TIOCA4 PIN_P24 |
| 212 | #define PIN_TIOCB4 PIN_P25 |
| 213 | #define PIN_TIOCA5 PIN_P26 |
| 214 | #define PIN_TIOCB5 PIN_P27 |
| 215 | |
| 216 | #define PIN_TMRI0 PIN_P22 |
| 217 | #define PIN_TMCI0 PIN_P23 |
| 218 | #define PIN_TMRI1 PIN_P24 |
| 219 | #define PIN_TMCI1 PIN_P25 |
| 220 | #define PIN_TMO0 PIN_P26 |
| 221 | #define PIN_TMO1 PIN_P27 |
| 222 | |
| 223 | const int TPU_0_DIV[] = { 1, 4, 16, 64, 0, 0, 0,0 }; |
| 224 | const int TPU_1_DIV[] = { 1, 4, 16, 64, 0, 0, 256, 0 }; |
| 225 | const int TPU_2_DIV[] = { 1, 4, 16, 64, 0, 0, 0, 1024 }; |
| 226 | const int TPU_3_DIV[] = { 1, 4, 16, 64, 0, 1024, 256, 4096 }; |
| 227 | const int TPU_4_DIV[] = { 1, 4, 16, 64, 0, 0, 1024, 0 }; |
| 228 | const int TPU_5_DIV[] = { 1, 4, 16, 64, 0, 0, 256, 0 }; |
| 229 | |
| 230 | const int H8S_IO_SMR[] = { H8S_IO_SMR0, H8S_IO_SMR1, H8S_IO_SMR2 }; |
| 231 | const int H8S_IO_BRR[] = { H8S_IO_BRR0, H8S_IO_BRR1, H8S_IO_BRR2 }; |
| 232 | const int H8S_IO_SCR[] = { H8S_IO_SCR0, H8S_IO_SCR1, H8S_IO_SCR2 }; |
| 233 | const int H8S_IO_TDR[] = { H8S_IO_TDR0, H8S_IO_TDR1, H8S_IO_TDR2 }; |
| 234 | const int H8S_IO_SSR[] = { H8S_IO_SSR0, H8S_IO_SSR1, H8S_IO_SSR2 }; |
| 235 | const int H8S_IO_RDR[] = { H8S_IO_RDR0, H8S_IO_RDR1, H8S_IO_RDR2 }; |
| 236 | |
| 237 | const int H8S_INT_TXI[] = { H8S_INT_TXI0, H8S_INT_TXI1, H8S_INT_TXI2 }; |
| 238 | const int H8S_INT_RXI[] = { H8S_INT_RXI0, H8S_INT_RXI1, H8S_INT_RXI2 }; |
| 239 | |
| 240 | const int H8S_IO_TCORA[] = { H8S_IO_TCORA0, H8S_IO_TCORA1 }; |
| 241 | const int H8S_IO_TCORB[] = { H8S_IO_TCORB0, H8S_IO_TCORB1 }; |
| 242 | const int H8S_IO_TCR[] = { H8S_IO_TCR0, H8S_IO_TCR1 }; |
| 243 | const int H8S_IO_TCNT[] = { H8S_IO_TCNT0, H8S_IO_TCNT1 }; |
| 244 | const int H8S_IO_TCSR[] = { H8S_IO_TCSR0, H8S_IO_TCSR1 }; |
| 245 | |
| 246 | const int H8S_INT_OVI[] = { H8S_INT_OVI0, H8S_INT_OVI1 }; |
| 247 | const int H8S_INT_CMIA[] = { H8S_INT_CMIA0, H8S_INT_CMIA1 }; |
| 248 | const int H8S_INT_CMIB[] = { H8S_INT_CMIB0, H8S_INT_CMIB1 }; |
| 249 | |
| 250 | const int H8S_IO_TGRA_H[] = { H8S_IO_TGR0A_H, H8S_IO_TGR1A_H, H8S_IO_TGR2A_H, H8S_IO_TGR3A_H, H8S_IO_TGR4A_H, H8S_IO_TGR5A_H }; |
| 251 | const int H8S_IO_TGRA_L[] = { H8S_IO_TGR0A_L, H8S_IO_TGR1A_L, H8S_IO_TGR2A_L, H8S_IO_TGR3A_L, H8S_IO_TGR4A_L, H8S_IO_TGR5A_L }; |
| 252 | const int H8S_IO_TGRB_H[] = { H8S_IO_TGR0B_H, H8S_IO_TGR1B_H, H8S_IO_TGR2B_H, H8S_IO_TGR3B_H, H8S_IO_TGR4B_H, H8S_IO_TGR5B_H }; |
| 253 | const int H8S_IO_TGRB_L[] = { H8S_IO_TGR0B_L, H8S_IO_TGR1B_L, H8S_IO_TGR2B_L, H8S_IO_TGR3B_L, H8S_IO_TGR4B_L, H8S_IO_TGR5B_L }; |
| 254 | const int H8S_IO_TGRC_H[] = { H8S_IO_TGR0C_H, 0, 0, H8S_IO_TGR3C_H, 0, 0 }; |
| 255 | const int H8S_IO_TGRC_L[] = { H8S_IO_TGR0C_L, 0, 0, H8S_IO_TGR3C_L, 0, 0 }; |
| 256 | const int H8S_IO_TGRD_H[] = { H8S_IO_TGR0D_H, 0, 0, H8S_IO_TGR3D_H, 0, 0 }; |
| 257 | const int H8S_IO_TGRD_L[] = { H8S_IO_TGR0D_L, 0, 0, H8S_IO_TGR3D_L, 0, 0 }; |
| 258 | const int H8S_IO_TCNT_H[] = { H8S_IO_TCNT0_H, H8S_IO_TCNT1_H, H8S_IO_TCNT2_H, H8S_IO_TCNT3_H, H8S_IO_TCNT4_H, H8S_IO_TCNT5_H }; |
| 259 | const int H8S_IO_TCNT_L[] = { H8S_IO_TCNT0_L, H8S_IO_TCNT1_L, H8S_IO_TCNT2_L, H8S_IO_TCNT3_L, H8S_IO_TCNT4_L, H8S_IO_TCNT5_L }; |
| 260 | const int H8S_IO_TIOR_H[] = { H8S_IO_TIOR0_H, H8S_IO_TIOR1, H8S_IO_TIOR2, H8S_IO_TIOR3_H, H8S_IO_TIOR4, H8S_IO_TIOR5 }; |
| 261 | const int H8S_IO_TIOR_L[] = { H8S_IO_TIOR0_L, 0, 0, H8S_IO_TIOR3_L, 0, 0 }; |
| 262 | const int H8S_IO_TTCR[] = { H8S_IO_TTCR0, H8S_IO_TTCR1, H8S_IO_TTCR2, H8S_IO_TTCR3, H8S_IO_TTCR4, H8S_IO_TTCR5 }; |
| 263 | const int H8S_IO_TIER[] = { H8S_IO_TIER0, H8S_IO_TIER1, H8S_IO_TIER2, H8S_IO_TIER3, H8S_IO_TIER4, H8S_IO_TIER5 }; |
| 264 | const int H8S_IO_TSR[] = { H8S_IO_TSR0, H8S_IO_TSR1, H8S_IO_TSR2, H8S_IO_TSR3, H8S_IO_TSR4, H8S_IO_TSR5 }; |
| 265 | |
| 266 | const int H8S_INT_TCIV[] = { H8S_INT_TCI0V, H8S_INT_TCI1V, H8S_INT_TCI2V, H8S_INT_TCI3V, H8S_INT_TCI4V, H8S_INT_TCI5V }; |
| 267 | const int H8S_INT_TCIU[] = { 0, H8S_INT_TCI1U, H8S_INT_TCI2U, 0, H8S_INT_TCI4U, H8S_INT_TCI5U }; |
| 268 | const int H8S_INT_TGIA[] = { H8S_INT_TGI0A, H8S_INT_TGI1A, H8S_INT_TGI2A, H8S_INT_TGI3A, H8S_INT_TGI4A, H8S_INT_TGI5A }; |
| 269 | const int H8S_INT_TGIB[] = { H8S_INT_TGI0B, H8S_INT_TGI1B, H8S_INT_TGI2B, H8S_INT_TGI3B, H8S_INT_TGI4B, H8S_INT_TGI5B }; |
| 270 | const int H8S_INT_TGIC[] = { H8S_INT_TGI0C, 0, 0, H8S_INT_TGI3C, 0, 0 }; |
| 271 | const int H8S_INT_TGID[] = { H8S_INT_TGI0D, 0, 0, H8S_INT_TGI3D, 0, 0 }; |
| 272 | |
| 273 | const int PIN_TIOCA[] = { PIN_TIOCA0, PIN_TIOCA1, PIN_TIOCA2, PIN_TIOCA3, PIN_TIOCA4, PIN_TIOCA5 }; |
| 274 | const int PIN_TIOCB[] = { PIN_TIOCB0, PIN_TIOCB1, PIN_TIOCB2, PIN_TIOCB3, PIN_TIOCB4, PIN_TIOCB5 }; |
| 275 | const int PIN_TIOCC[] = { PIN_TIOCC0, 0, 0, PIN_TIOCC3, 0, 0 }; |
| 276 | const int PIN_TIOCD[] = { PIN_TIOCD0, 0, 0, PIN_TIOCD3, 0, 0 }; |
| 277 | |
| 278 | const int TCR_CCLR_AND[] = { 7, 3, 3, 7, 3, 3 }; |
| 279 | |
| 280 | // prototypes |
| 281 | |
| 282 | void h8s_tmr_x_reset( h83xx_state *h8, int x); |
| 283 | void h8s_tpu_x_reset( h83xx_state *h8, int x); |
| 284 | void h8s_tpu_x_tick( h83xx_state *h8, int x); |
| 285 | |
| 23 | 286 | //////////// |
| 24 | 287 | // DTVECR // |
| 25 | 288 | //////////// |
| r12440 | r12441 | |
| 32 | 295 | |
| 33 | 296 | static TIMER_CALLBACK( h8s_tmr_callback ); |
| 34 | 297 | static TIMER_CALLBACK( h8s_tpu_callback ); |
| 35 | | #ifdef ENABLE_SCI_TIMER |
| 36 | 298 | static TIMER_CALLBACK( h8s_sci_callback ); |
| 37 | | #endif |
| 38 | 299 | |
| 39 | 300 | ///////////// |
| 40 | 301 | // TIMER.C // |
| 41 | 302 | ///////////// |
| 42 | 303 | |
| 43 | | #ifdef ENABLE_SCI_TIMER |
| 44 | | static void timer_adjust_pulse(emu_timer *timer, UINT32 hz, int num) |
| 304 | UINT16 ptr_read_16( void *ptr) |
| 45 | 305 | { |
| 46 | | timer->adjust(ATTOTIME_IN_HZ( hz), num, ATTOTIME_IN_HZ( hz)); |
| 306 | return (*(((UINT8*)ptr) + 0) << 8) | (*(((UINT8*)ptr) + 1) << 0); |
| 47 | 307 | } |
| 48 | | #endif |
| 49 | 308 | |
| 309 | void ptr_write_16( void *ptr, UINT16 data) |
| 310 | { |
| 311 | *(((UINT8*)ptr) + 0) = (data >> 8) & 0xFF; |
| 312 | *(((UINT8*)ptr) + 1) = (data >> 0) & 0xFF; |
| 313 | } |
| 314 | |
| 315 | int device_icount_min_timer_icount1( h83xx_state *h8, emu_timer *timer) |
| 316 | { |
| 317 | return (timer->elapsed() * h8->device->unscaled_clock()).as_double(); |
| 318 | } |
| 319 | |
| 50 | 320 | void h8s2xxx_interrupt_request(h83xx_state *h8, UINT32 vecnum) |
| 51 | 321 | { |
| 52 | 322 | UINT8 idx, bit; |
| 53 | 323 | idx = vecnum >> 5; |
| 54 | 324 | bit = vecnum & 0x1F; |
| 55 | 325 | h8->irq_req[idx] |= (1 << bit); |
| 56 | | // logerror( "irq_req = %08X %08X %08X\n", h8->irq_req[0], h8->irq_req[1], h8->irq_req[2]); |
| 57 | 326 | } |
| 58 | 327 | |
| 59 | 328 | void h8s_dtce_execute(h83xx_state *h8, UINT32 addr_dtce, UINT8 mask_dtce, UINT32 addr_dtvecr) |
| r12440 | r12441 | |
| 72 | 341 | dtc_dar = (data[1] >> 0) & 0xFFFFFF; |
| 73 | 342 | dtc_cra = (data[2] >> 16) & 0xFFFF; |
| 74 | 343 | dtc_crb = (data[2] >> 0) & 0xFFFF; |
| 75 | | _logerror( 3, "dtc : vect %08X mra %02X sar %08X mrb %02X dar %08X cra %04X crb %04X\n", dtc_vect, dtc_mra, dtc_sar, dtc_mrb, dtc_dar, dtc_cra, dtc_crb); |
| 344 | verboselog( h8->device->machine(), 3, "dtc : vect %08X mra %02X sar %08X mrb %02X dar %08X cra %04X crb %04X\n", dtc_vect, dtc_mra, dtc_sar, dtc_mrb, dtc_dar, dtc_cra, dtc_crb); |
| 76 | 345 | // execute |
| 77 | 346 | if ((dtc_mra & 0x0E) != 0x00) fatalerror("H8S: dtc unsupported MRA %x\n", dtc_mra&0x0e); |
| 78 | 347 | sz = 1 << (dtc_mra & 0x01); |
| r12440 | r12441 | |
| 135 | 404 | |
| 136 | 405 | void h8s_periph_reset(h83xx_state *h8) |
| 137 | 406 | { |
| 138 | | h8->per_regs[H8S_IO_SSR0] = 0x84; |
| 139 | | h8->per_regs[H8S_IO_SSR1] = 0x84; |
| 140 | | h8->per_regs[H8S_IO_SSR2] = 0x84; |
| 141 | | h8->per_regs[H8S_IO_TDR0] = 0xFF; |
| 142 | | h8->per_regs[H8S_IO_TDR1] = 0xFF; |
| 143 | | h8->per_regs[H8S_IO_TDR2] = 0xFF; |
| 144 | | h8->per_regs[H8S_IO_BRR0] = 0xFF; |
| 145 | | h8->per_regs[H8S_IO_BRR1] = 0xFF; |
| 146 | | h8->per_regs[H8S_IO_BRR2] = 0xFF; |
| 407 | const int tpu_max = (h8->device->type() == H8S2323) ? 6 : 3; |
| 408 | if ((h8->device->type() == H8S2241) || (h8->device->type() == H8S2246)) |
| 409 | { |
| 410 | memcpy( h8->per_regs, H8S_RESET_H8S_IO_224x, sizeof( h8->per_regs)); |
| 411 | } |
| 412 | else if (h8->device->type() == H8S2323) |
| 413 | { |
| 414 | memcpy( h8->per_regs, H8S_RESET_H8S_IO_2323, sizeof( h8->per_regs)); |
| 415 | } |
| 416 | for (int i = 0; i < 2; i++) h8s_tmr_x_reset( h8, i); |
| 417 | for (int i = 0; i < tpu_max; i++) h8s_tpu_x_reset( h8, i); |
| 147 | 418 | } |
| 148 | 419 | |
| 149 | | /////////// |
| 150 | | // TIMER // |
| 151 | | /////////// |
| 420 | ///////////////// |
| 421 | // TIMER 8-BIT // |
| 422 | ///////////////// |
| 152 | 423 | |
| 153 | | typedef struct |
| 424 | void h8s_tmr_init(h83xx_state *h8) |
| 154 | 425 | { |
| 155 | | UINT32 reg_tcsr, reg_tcr, reg_tcnt; |
| 156 | | UINT8 int_ovi; |
| 157 | | } H8S_TMR_ENTRY; |
| 426 | for (int i = 0; i < 2; i++) |
| 427 | { |
| 428 | h8->tmr[i].timer = h8->device->machine().scheduler().timer_alloc(FUNC(h8s_tmr_callback), h8); |
| 429 | h8->tmr[i].timer->adjust(attotime::never, i); |
| 430 | } |
| 431 | } |
| 158 | 432 | |
| 159 | | const H8S_TMR_ENTRY H8S_TMR_TABLE[] = |
| 433 | void h8s_tmr_x_reset( h83xx_state *h8, int x) |
| 160 | 434 | { |
| 161 | | // TMR 0 |
| 435 | H8S2XXX_TMR *tmr = &h8->tmr[x]; |
| 436 | tmr->cycles_per_tick = 0; |
| 437 | tmr->timer->adjust(attotime::never, x); |
| 438 | } |
| 439 | |
| 440 | UINT64 h8s_tmr_x_calculate_ticks( h83xx_state *h8, int x, UINT8 tcnt) |
| 441 | { |
| 442 | UINT64 cycles1, cycles2; |
| 443 | UINT8 tcor; |
| 444 | // overflow |
| 445 | if (tcnt == 0) cycles1 = 0xFF + 1; else cycles1 = (UINT8)(0xFF - tcnt + 1); |
| 446 | // tcora |
| 447 | tcor = h8->per_regs[H8S_IO_TCORA[x]]; |
| 448 | if (tcnt == tcor) cycles2 = 0xFF + 1; else cycles2 = (UINT8)(tcor - tcnt); |
| 449 | if ((cycles2 > 0) && (cycles2 < cycles1)) cycles1 = cycles2; |
| 450 | // tcorb |
| 451 | tcor = h8->per_regs[H8S_IO_TCORB[x]]; |
| 452 | if (tcnt == tcor) cycles2 = 0xFF + 1; else cycles2 = (UINT8)(tcor - tcnt); |
| 453 | if ((cycles2 > 0) && (cycles2 < cycles1)) cycles1 = cycles2; |
| 454 | // done |
| 455 | return cycles1; |
| 456 | } |
| 457 | |
| 458 | void h8s_tmr_x_update( h83xx_state *h8, int x) |
| 459 | { |
| 460 | H8S2XXX_TMR *tmr = &h8->tmr[x]; |
| 461 | UINT64 cycles; |
| 462 | int div = 0; |
| 463 | UINT8 tcr, tcnt; |
| 464 | tcr = h8->per_regs[H8S_IO_TCR[x]]; |
| 465 | switch ((tcr >> 0) & 7) |
| 162 | 466 | { |
| 163 | | H8S_IO_TCSR0, H8S_IO_TCR0, H8S_IO_TCNT0, |
| 164 | | H8S_INT_OVI0 |
| 165 | | }, |
| 166 | | // TMR 1 |
| 467 | case 1 : div = 8; break; |
| 468 | case 2 : div = 64; break; |
| 469 | case 3 : div = 8192; break; |
| 470 | // default : OS_MessageBox( NULL, "tmr_x_update", "error", 0); break; |
| 471 | } |
| 472 | tmr->cycles_per_tick = div; |
| 473 | tcnt = h8->per_regs[H8S_IO_TCNT[x]]; |
| 474 | verboselog( h8->device->machine(), 5, "TMR %d - update (div %d tcnt %02X)\n", x, div, tcnt); |
| 475 | // update timer |
| 476 | cycles = h8s_tmr_x_calculate_ticks( h8, x, tcnt) * tmr->cycles_per_tick; |
| 477 | tmr->timer_cycles = cycles; |
| 478 | tmr->timer->adjust(attotime::from_hz(h8->device->unscaled_clock() / cycles), x); |
| 479 | } |
| 480 | |
| 481 | UINT8 h8s_tmr_x_calculate_tcnt( h83xx_state *h8, int x) |
| 482 | { |
| 483 | H8S2XXX_TMR *tmr = &h8->tmr[x]; |
| 484 | UINT8 tcnt; |
| 485 | tcnt = h8->per_regs[H8S_IO_TCNT[x]]; |
| 486 | if (tmr->timer->enabled()) |
| 167 | 487 | { |
| 168 | | H8S_IO_TCSR1, H8S_IO_TCR1, H8S_IO_TCNT1, |
| 169 | | H8S_INT_OVI1 |
| 488 | tcnt = (UINT8)(tcnt + ((device_icount_min_timer_icount1( h8, tmr->timer)) / tmr->cycles_per_tick)); |
| 170 | 489 | } |
| 171 | | }; |
| 490 | return tcnt; |
| 491 | } |
| 172 | 492 | |
| 173 | | const UINT32 TCR_CKS[] = { 0, 8, 64, 8192 }; |
| 174 | | |
| 175 | | const H8S_TMR_ENTRY *h8s_tmr_entry( int num) |
| 493 | void h8s_tmr_x_start( h83xx_state *h8, int x) |
| 176 | 494 | { |
| 177 | | return &H8S_TMR_TABLE[num]; |
| 495 | verboselog( h8->device->machine(), 5, "TMR %d - start\n", x); |
| 496 | // ... |
| 497 | h8s_tmr_x_update( h8, x); |
| 178 | 498 | } |
| 179 | 499 | |
| 180 | | static TIMER_CALLBACK( h8s_tmr_callback) |
| 500 | void h8s_tmr_x_stop( h83xx_state *h8, int x) |
| 181 | 501 | { |
| 182 | | h83xx_state *h8 = (h83xx_state *)ptr; |
| 183 | | const H8S_TMR_ENTRY *info = h8s_tmr_entry( param); |
| 184 | | _logerror( 2, "h8s_tmr_callback (%d)\n", param); |
| 502 | H8S2XXX_TMR *tmr = &h8->tmr[x]; |
| 503 | UINT8 tcnt; |
| 504 | // ... |
| 505 | verboselog( h8->device->machine(), 5, "TMR %d - stop\n", x); |
| 506 | // calculate tcnt |
| 507 | tcnt = h8s_tmr_x_calculate_tcnt( h8, x); |
| 508 | // update tcnt |
| 509 | h8->per_regs[H8S_IO_TCNT[x]] = tcnt; |
| 185 | 510 | // disable timer |
| 186 | | h8->tmr[param].timer->adjust(attotime::never, param); |
| 187 | | // set timer overflow flag |
| 188 | | h8->per_regs[info->reg_tcsr] |= 0x20; |
| 189 | | // overflow interrupt |
| 190 | | if (h8->per_regs[info->reg_tcr] & 0x20) h8s2xxx_interrupt_request(h8, info->int_ovi); |
| 511 | tmr->timer->reset(); |
| 191 | 512 | } |
| 192 | 513 | |
| 193 | | void h8s_tmr_init(h83xx_state *h8) |
| 514 | UINT8 h8s_tmr_x_tcnt_change( h83xx_state *h8, int x, UINT8 tcnt) |
| 194 | 515 | { |
| 195 | | int i; |
| 196 | | for (i=0;i<2;i++) |
| 516 | UINT8 tcr, tcor; |
| 517 | int clear = 0; |
| 518 | // ... |
| 519 | verboselog( h8->device->machine(), 9, "TMR %d - tmr_x_tcnt_change (%02X)\n", x, tcnt); |
| 520 | // ... |
| 521 | tcr = h8->per_regs[H8S_IO_TCR[x]]; |
| 522 | // overflow |
| 523 | if (tcnt == 0) |
| 197 | 524 | { |
| 198 | | h8->tmr[i].timer = h8->device->machine().scheduler().timer_alloc(FUNC(h8s_tmr_callback), h8); |
| 199 | | h8->tmr[i].timer->adjust(attotime::never, i); |
| 525 | verboselog( h8->device->machine(), 9, "TMR %d - overflow match\n", x); |
| 526 | h8->per_regs[H8S_IO_TCSR[x]] |= TCSR_OVF; |
| 527 | if ((tcr & TCR_OVIE) != 0) |
| 528 | { |
| 529 | h8s2xxx_interrupt_request( h8, H8S_INT_OVI[x]); |
| 530 | } |
| 200 | 531 | } |
| 532 | // tcora |
| 533 | tcor = h8->per_regs[H8S_IO_TCORA[x]]; |
| 534 | if (tcnt == tcor) |
| 535 | { |
| 536 | verboselog( h8->device->machine(), 9, "TMR %d - tcora match\n", x); |
| 537 | h8->per_regs[H8S_IO_TCSR[x]] |= TCSR_CMFA; |
| 538 | if ((tcr & TCR_CMIEA) != 0) |
| 539 | { |
| 540 | h8s2xxx_interrupt_request( h8, H8S_INT_CMIA[x]); |
| 541 | } |
| 542 | if (((tcr >> 3) & 3) == 1) // CCLR 1 -> "clear by compare match a" |
| 543 | { |
| 544 | clear = 1; |
| 545 | } |
| 546 | } |
| 547 | // tcorb |
| 548 | tcor = h8->per_regs[H8S_IO_TCORB[x]]; |
| 549 | if (tcnt == tcor) |
| 550 | { |
| 551 | verboselog( h8->device->machine(), 9, "TMR %d - tcorb match\n", x); |
| 552 | h8->per_regs[H8S_IO_TCSR[x]] |= TCSR_CMFB; |
| 553 | if ((tcr & TCR_CMIEB) != 0) |
| 554 | { |
| 555 | h8s2xxx_interrupt_request( h8, H8S_INT_CMIB[x]); |
| 556 | } |
| 557 | if (((tcr >> 3) & 3) == 2) // CCLR 2 -> "clear by compare match b" |
| 558 | { |
| 559 | clear = 1; |
| 560 | } |
| 561 | } |
| 562 | // ... |
| 563 | if (clear) |
| 564 | { |
| 565 | verboselog( h8->device->machine(), 5, "TMR %d - tcnt clear\n", x); |
| 566 | tcnt = 0; |
| 567 | } |
| 568 | // ... |
| 569 | return tcnt; |
| 201 | 570 | } |
| 202 | 571 | |
| 203 | | void h8s_tmr_resync(h83xx_state *h8, int num) |
| 572 | void h8s_tmr_x_callback( h83xx_state *h8, int x) |
| 204 | 573 | { |
| 205 | | const H8S_TMR_ENTRY *info = h8s_tmr_entry(num); |
| 206 | | UINT8 cks, tcr, tcnt; |
| 207 | | // get timer data |
| 208 | | tcr = h8->per_regs[info->reg_tcr]; |
| 209 | | tcnt = h8->per_regs[info->reg_tcnt]; |
| 210 | | // |
| 211 | | cks = tcr & 3; |
| 212 | | if (cks != 0) |
| 574 | H8S2XXX_TMR *tmr = &h8->tmr[x]; |
| 575 | UINT64 cycles; |
| 576 | UINT8 tcnt; |
| 577 | // calculate tcnt |
| 578 | tcnt = h8->per_regs[H8S_IO_TCNT[x]]; |
| 579 | tcnt = (UINT8)(tcnt + tmr->timer_cycles / tmr->cycles_per_tick); |
| 580 | // ... |
| 581 | tcnt = h8s_tmr_x_tcnt_change( h8, x, tcnt); |
| 582 | // update tcnt |
| 583 | h8->per_regs[H8S_IO_TCNT[x]] = tcnt; |
| 584 | // update timer |
| 585 | cycles = h8s_tmr_x_calculate_ticks( h8, x, tcnt) * tmr->cycles_per_tick; |
| 586 | tmr->timer_cycles = cycles; |
| 587 | tmr->timer->adjust(attotime::from_hz(h8->device->unscaled_clock() / cycles), x); |
| 588 | } |
| 589 | |
| 590 | void h8s_tmr_x_write_tcr( h83xx_state *h8, int x, UINT8 data) |
| 591 | { |
| 592 | UINT8 old_data = h8->per_regs[H8S_IO_TCR[x]]; |
| 593 | h8->per_regs[H8S_IO_TCR[x]] = data; |
| 594 | if ((data & 0x07) != (old_data & 0x07)) |
| 213 | 595 | { |
| 214 | | UINT32 cycles, hz; |
| 215 | | cycles = TCR_CKS[cks] * (0xFF - tcnt); |
| 216 | | if (cycles == 0) cycles = 1; // cybiko game "lost in labyrinth" => divide by zero |
| 217 | | hz = h8->device->unscaled_clock() / cycles; |
| 218 | | _logerror( 2, "cycles %d hz %d\n", cycles, hz); |
| 219 | | h8->tmr[num].timer->adjust(attotime::from_hz(hz), num); |
| 596 | if ((data & 0x07) != 0) |
| 597 | { |
| 598 | h8s_tmr_x_start( h8, x); |
| 599 | } |
| 600 | else |
| 601 | { |
| 602 | h8s_tmr_x_stop( h8, x); |
| 603 | } |
| 220 | 604 | } |
| 221 | | else |
| 605 | } |
| 606 | |
| 607 | void h8s_tmr_x_write_tcnt( h83xx_state *h8, int x, UINT8 data) |
| 608 | { |
| 609 | H8S2XXX_TMR *tmr = &h8->tmr[x]; |
| 610 | h8->per_regs[H8S_IO_TCNT[x]] = data; |
| 611 | if (tmr->timer->enabled()) |
| 222 | 612 | { |
| 223 | | _logerror( 2, "time never\n"); |
| 224 | | h8->tmr[num].timer->adjust(attotime::never, num); |
| 613 | h8s_tmr_x_update( h8, x); |
| 225 | 614 | } |
| 226 | 615 | } |
| 227 | 616 | |
| 228 | | ///////// |
| 229 | | // TPU // |
| 230 | | ///////// |
| 617 | void h8s_tmr_x_write_tcor( h83xx_state *h8, int x) |
| 618 | { |
| 619 | H8S2XXX_TMR *tmr = &h8->tmr[x]; |
| 620 | if ((tmr->timer->enabled()) && (tmr->cycles_per_tick != 0)) |
| 621 | { |
| 622 | UINT8 tcnt1, tcnt2; |
| 623 | UINT64 cycles; |
| 624 | tcnt1 = h8->per_regs[H8S_IO_TCNT[x]]; |
| 625 | tcnt2 = (UINT8)(tcnt1 + ((device_icount_min_timer_icount1( h8, tmr->timer)) / tmr->cycles_per_tick)); |
| 626 | cycles = h8s_tmr_x_calculate_ticks( h8, x, tcnt2) * tmr->cycles_per_tick; |
| 627 | cycles = cycles + (tcnt2 - tcnt1) * tmr->cycles_per_tick; |
| 628 | tmr->timer_cycles = cycles; |
| 629 | tmr->timer->adjust(attotime::from_hz(h8->device->unscaled_clock() / cycles), x); |
| 630 | } |
| 631 | } |
| 231 | 632 | |
| 232 | | const UINT32 TPSC[] = { 1, 4, 16, 64, 0, 0, 256, 0 }; |
| 633 | UINT8 h8s_tmr_x_read_tcnt( h83xx_state *h8, int x) |
| 634 | { |
| 635 | return h8s_tmr_x_calculate_tcnt( h8, x); |
| 636 | } |
| 233 | 637 | |
| 234 | | void set_p1dr_tiocb1(h83xx_state *h8, int data) |
| 638 | void h8s_tmr_x_write_tcora( h83xx_state *h8, int x, UINT8 data) |
| 235 | 639 | { |
| 236 | | UINT8 p1dr; |
| 237 | | p1dr = h8->per_regs[H8S_IO_P1DR]; |
| 238 | | if (data) p1dr |= H8S_P1_TIOCB1; else p1dr &= ~H8S_P1_TIOCB1; |
| 239 | | h8->io->write_byte(H8S_IO_ADDR(H8S_IO_P1DR), p1dr); |
| 240 | | h8->per_regs[H8S_IO_P1DR] = p1dr; |
| 640 | h8->per_regs[H8S_IO_TCORA[x]] = data; |
| 641 | h8s_tmr_x_write_tcor( h8, x); |
| 241 | 642 | } |
| 242 | 643 | |
| 243 | | static TIMER_CALLBACK( h8s_tpu_callback) |
| 644 | void h8s_tmr_x_write_tcorb( h83xx_state *h8, int x, UINT8 data) |
| 244 | 645 | { |
| 646 | h8->per_regs[H8S_IO_TCORB[x]] = data; |
| 647 | h8s_tmr_x_write_tcor( h8, x); |
| 648 | } |
| 649 | |
| 650 | static TIMER_CALLBACK( h8s_tmr_callback) |
| 651 | { |
| 245 | 652 | h83xx_state *h8 = (h83xx_state *)ptr; |
| 246 | | H8S2XXX_TPU *tpu = &h8->tpu[param]; |
| 247 | | _logerror( 2, "h8s_tpu_callback (%d)\n", param); |
| 248 | | switch (param) |
| 653 | h8s_tmr_x_callback( h8, param); |
| 654 | } |
| 655 | |
| 656 | ////////////////// |
| 657 | // TIMER 16-BIT // |
| 658 | ////////////////// |
| 659 | |
| 660 | void h8s_tpu_init(h83xx_state *h8) |
| 661 | { |
| 662 | const int tpu_max = (h8->device->type() == H8S2323) ? 6 : 3; |
| 663 | for (int i = 0; i < tpu_max; i++) |
| 249 | 664 | { |
| 250 | | case 1 : |
| 665 | h8->tpu[i].timer = h8->device->machine().scheduler().timer_alloc(FUNC(h8s_tpu_callback), h8); |
| 666 | h8->tpu[i].timer->adjust(attotime::never, i); |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | void h8s_tpu_x_reset( h83xx_state *h8, int x) |
| 671 | { |
| 672 | H8S2XXX_TPU *tpu = &h8->tpu[x]; |
| 673 | tpu->cycles_per_tick = 0; |
| 674 | tpu->timer->reset(); |
| 675 | } |
| 676 | |
| 677 | UINT16 h8s_tpu_x_calculate_tcnt( h83xx_state *h8, int x) |
| 678 | { |
| 679 | H8S2XXX_TPU *tpu = &h8->tpu[x]; |
| 680 | UINT16 tcnt; |
| 681 | tcnt = ptr_read_16( h8->per_regs + H8S_IO_TCNT_H[x]); |
| 682 | if ((tpu->timer->enabled()) && (tpu->cycles_per_tick > 0)) |
| 683 | { |
| 684 | tcnt = (UINT16)(tcnt + ((device_icount_min_timer_icount1( h8, tpu->timer)) / tpu->cycles_per_tick)); |
| 685 | } |
| 686 | return tcnt; |
| 687 | } |
| 688 | |
| 689 | UINT64 h8s_tpu_x_calculate_ticks( h83xx_state *h8, int x, UINT16 tcnt) |
| 690 | { |
| 691 | UINT64 cycles1, cycles2; |
| 692 | UINT16 tgr; |
| 693 | // overflow |
| 694 | if (tcnt == 0) cycles1 = 0xFFFF + 1; else cycles1 = (UINT16)(0xFFFF - tcnt + 1); |
| 695 | // tgra |
| 696 | tgr = ptr_read_16( h8->per_regs + H8S_IO_TGRA_H[x]); |
| 697 | if (tcnt == tgr) cycles2 = 0xFFFF + 1; else cycles2 = (UINT16)(tgr - tcnt); |
| 698 | if ((cycles2 > 0) && (cycles2 < cycles1)) cycles1 = cycles2; |
| 699 | // tgrb |
| 700 | tgr = ptr_read_16( h8->per_regs + H8S_IO_TGRB_H[x]); |
| 701 | if (tcnt == tgr) cycles2 = 0xFFFF + 1; else cycles2 = (UINT16)(tgr - tcnt); |
| 702 | if ((cycles2 > 0) && (cycles2 < cycles1)) cycles1 = cycles2; |
| 703 | // tgrc |
| 704 | if ((x == 0) || (x == 3)) |
| 705 | { |
| 706 | tgr = ptr_read_16( h8->per_regs + H8S_IO_TGRC_H[x]); |
| 707 | if (tcnt == tgr) cycles2 = 0xFFFF + 1; else cycles2 = (UINT16)(tgr - tcnt); |
| 708 | if ((cycles2 > 0) && (cycles2 < cycles1)) cycles1 = cycles2; |
| 709 | } |
| 710 | // tgrd |
| 711 | if ((x == 0) || (x == 3)) |
| 712 | { |
| 713 | tgr = ptr_read_16( h8->per_regs + H8S_IO_TGRD_H[x]); |
| 714 | if (tcnt == tgr) cycles2 = 0xFFFF + 1; else cycles2 = (UINT16)(tgr - tcnt); |
| 715 | if ((cycles2 > 0) && (cycles2 < cycles1)) cycles1 = cycles2; |
| 716 | } |
| 717 | // done |
| 718 | return cycles1; |
| 719 | } |
| 720 | |
| 721 | void h8s_pin_write( h83xx_state *h8, int pin, int data) |
| 722 | { |
| 723 | switch (pin) |
| 724 | { |
| 725 | case PIN_TIOCB1 : |
| 251 | 726 | { |
| 252 | | UINT32 hz, cycles; |
| 253 | | int tiocb1, vecnum; |
| 254 | | // get info |
| 255 | | vecnum = tpu->item[tpu->tgrcur].irq; |
| 256 | | tiocb1 = tpu->item[tpu->tgrcur].out; |
| 257 | | if (tpu->tgrcur >= tpu->tgrmax) tpu->tgrcur = 0; |
| 258 | | cycles = tpu->item[tpu->tgrcur+1].tgr - tpu->item[tpu->tgrcur+0].tgr; |
| 259 | | tpu->tgrcur++; |
| 260 | | // adjust timer |
| 261 | | hz = h8->device->unscaled_clock() / (tpu->prescaler * cycles); |
| 262 | | tpu->timer->adjust(attotime::from_hz(hz), 1); |
| 263 | | // output |
| 264 | | set_p1dr_tiocb1(h8, tiocb1); |
| 265 | | // interrupt |
| 266 | | if (vecnum != 0) h8s2xxx_interrupt_request(h8, vecnum); |
| 727 | UINT8 p1dr; |
| 728 | p1dr = h8->per_regs[H8S_IO_P1DR]; |
| 729 | if (data) p1dr |= H8S_P1_TIOCB1; else p1dr &= ~H8S_P1_TIOCB1; |
| 730 | h8->io->write_byte(H8S_IO_ADDR(H8S_IO_P1DR), p1dr); |
| 731 | h8->per_regs[H8S_IO_P1DR] = p1dr; |
| 267 | 732 | } |
| 268 | 733 | break; |
| 269 | 734 | } |
| 270 | 735 | } |
| 271 | 736 | |
| 272 | | void h8s_tpu_init(h83xx_state *h8) |
| 737 | int h8s_pin_read( h83xx_state *h8, int pin) |
| 273 | 738 | { |
| 274 | | int i; |
| 275 | | for (i=0;i<3;i++) |
| 739 | switch (pin) |
| 276 | 740 | { |
| 277 | | h8->tpu[i].timer = h8->device->machine().scheduler().timer_alloc(FUNC(h8s_tpu_callback), h8); |
| 278 | | h8->tpu[i].timer->adjust(attotime::never, i); |
| 741 | case PIN_TIOCB1 : return (h8->per_regs[H8S_IO_P1DR] & H8S_P1_TIOCB1) ? 1 : 0; |
| 279 | 742 | } |
| 743 | return 0; |
| 280 | 744 | } |
| 281 | 745 | |
| 282 | | void h8s_tpu_start(h83xx_state *h8, int num) |
| 746 | void h8s_tioc_pin_update( h83xx_state *h8, int io, int pin) |
| 283 | 747 | { |
| 284 | | UINT8 ttcr, tior, tier, tsr; |
| 285 | | UINT16 tgra, tgrb; //, tcnt; |
| 286 | | UINT32 hz, i, cycles; |
| 287 | | H8S2XXX_TPU *tpu = &h8->tpu[num]; |
| 288 | | switch (num) |
| 748 | switch (io) |
| 289 | 749 | { |
| 290 | | case 1 : |
| 750 | case 1 : h8s_pin_write( h8, pin, 0); break; |
| 751 | case 2 : h8s_pin_write( h8, pin, 1); break; |
| 752 | case 3 : h8s_pin_write( h8, pin, h8s_pin_read( h8, pin) ? 0 : 1); break; |
| 753 | case 5 : h8s_pin_write( h8, pin, 0); break; |
| 754 | case 6 : h8s_pin_write( h8, pin, 1); break; |
| 755 | case 7 : h8s_pin_write( h8, pin, h8s_pin_read( h8, pin) ? 0 : 1); break; |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | void h8s_tioc_pin_reset( h83xx_state *h8, int io, int pin) |
| 760 | { |
| 761 | switch (io) |
| 762 | { |
| 763 | case 1 : h8s_pin_write( h8, pin, 0); break; |
| 764 | case 2 : h8s_pin_write( h8, pin, 0); break; |
| 765 | case 3 : h8s_pin_write( h8, pin, 0); break; |
| 766 | case 5 : h8s_pin_write( h8, pin, 1); break; |
| 767 | case 6 : h8s_pin_write( h8, pin, 1); break; |
| 768 | case 7 : h8s_pin_write( h8, pin, 1); break; |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | void h8s_tpu_x_tioc_reset( h83xx_state *h8, int x) |
| 773 | { |
| 774 | UINT8 tior; |
| 775 | int cclr; |
| 776 | // ... |
| 777 | cclr = (h8->per_regs[H8S_IO_TTCR[x]] >> 5) & TCR_CCLR_AND[x]; |
| 778 | // tioca & tiocb |
| 779 | tior = h8->per_regs[H8S_IO_TIOR_H[x]]; |
| 780 | if (cclr != 1) h8s_tioc_pin_reset( h8, (tior >> 0) & 0x0F, PIN_TIOCA[x]); |
| 781 | if (cclr != 2) h8s_tioc_pin_reset( h8, (tior >> 4) & 0x0F, PIN_TIOCB[x]); |
| 782 | // tiocc & tiocd |
| 783 | if ((x == 0) || (x == 3)) |
| 784 | { |
| 785 | tior = h8->per_regs[H8S_IO_TIOR_L[x]]; |
| 786 | if (cclr != 5) h8s_tioc_pin_reset( h8, (tior >> 0) & 0x0F, PIN_TIOCC[x]); |
| 787 | if (cclr != 6) h8s_tioc_pin_reset( h8, (tior >> 4) & 0x0F, PIN_TIOCD[x]); |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | void h8s_tpu_x_overflow( h83xx_state *h8, int x) |
| 792 | { |
| 793 | if (x == 2) |
| 794 | { |
| 795 | UINT8 tcr = h8->per_regs[H8S_IO_TTCR[1]]; |
| 796 | if (((tcr >> 0) & 7) == 7) |
| 291 | 797 | { |
| 292 | | ttcr = h8->per_regs[H8S_IO_TTCR1]; |
| 293 | | tior = h8->per_regs[H8S_IO_TIOR1]; |
| 294 | | tier = h8->per_regs[H8S_IO_TIER1]; |
| 295 | | tsr = h8->per_regs[H8S_IO_TSR1]; |
| 296 | | tgra = (h8->per_regs[H8S_IO_TGR1A+0] << 8) | (h8->per_regs[H8S_IO_TGR1A+1] << 0); |
| 297 | | tgrb = (h8->per_regs[H8S_IO_TGR1B+0] << 8) | (h8->per_regs[H8S_IO_TGR1B+1] << 0); |
| 298 | | // tcnt = (h8->per_regs[H8S_IO_TTCNT1+0] << 8) | (h8->per_regs[H8S_IO_TTCNT1+1] << 0); |
| 798 | h8s_tpu_x_tick( h8, 1); |
| 799 | } |
| 800 | } |
| 801 | if (x == 5) |
| 802 | { |
| 803 | UINT8 tcr = h8->per_regs[H8S_IO_TTCR[4]]; |
| 804 | if (((tcr >> 0) & 7) == 7) |
| 805 | { |
| 806 | h8s_tpu_x_tick( h8, 4); |
| 807 | } |
| 808 | } |
| 809 | } |
| 299 | 810 | |
| 300 | | //printf( "TTCR %02X TIOR %02X TIER %02X TSR %02X TGRA %04X TGRB %04X TCNT %04X\n", ttcr, tior, tier, tsr, tgra, tgrb, tcnt); |
| 301 | | |
| 302 | | if ((ttcr != 0x21) || (tior != 0x56) || ((tier != 0x00) && (tier != 0x01)) || (tsr != 0x00)) |
| 811 | UINT16 h8s_tpu_x_tcnt_change( h83xx_state *h8, int x, UINT16 tcnt) |
| 812 | { |
| 813 | UINT16 tgr; |
| 814 | UINT8 tcr, tier, tior; |
| 815 | int clear = 0; |
| 816 | // ... |
| 817 | verboselog( h8->device->machine(), 9, "TPU %d - tpu_x_tcnt_change (%04X)\n", x, tcnt); |
| 818 | // ... |
| 819 | tcr = h8->per_regs[H8S_IO_TTCR[x]]; |
| 820 | tier = h8->per_regs[H8S_IO_TIER[x]]; |
| 821 | // overflow |
| 822 | if (tcnt == 0) |
| 823 | { |
| 824 | verboselog( h8->device->machine(), 9, "TPU %d - overflow match\n", x); |
| 825 | h8->per_regs[H8S_IO_TSR[x]] |= TSR_TCFV; |
| 826 | if (tier & TIER_TCIEV) |
| 827 | { |
| 828 | h8s2xxx_interrupt_request( h8, H8S_INT_TCIV[x]); |
| 829 | } |
| 830 | h8s_tpu_x_overflow( h8, x); |
| 831 | } |
| 832 | // tgra |
| 833 | tgr = ptr_read_16( h8->per_regs + H8S_IO_TGRA_H[x]); |
| 834 | if (tcnt == tgr) |
| 835 | { |
| 836 | verboselog( h8->device->machine(), 9, "TPU %d - tgra match\n", x); |
| 837 | h8->per_regs[H8S_IO_TSR[x]] |= TSR_TGFA; |
| 838 | if (tier & TIER_TGIEA) |
| 839 | { |
| 840 | h8s2xxx_interrupt_request( h8, H8S_INT_TGIA[x]); |
| 841 | } |
| 842 | if (((tcr >> 5) & TCR_CCLR_AND[x]) == 1) // CCLR 1 -> "TCNT cleared by TGRA compare match/input capture" |
| 843 | { |
| 844 | clear = 1; |
| 845 | } |
| 846 | else |
| 847 | { |
| 848 | tior = h8->per_regs[H8S_IO_TIOR_H[x]]; |
| 849 | h8s_tioc_pin_update( h8, (tior >> 0) & 0x0F, PIN_TIOCA[x]); |
| 850 | } |
| 851 | } |
| 852 | // tgrb |
| 853 | tgr = ptr_read_16( h8->per_regs + H8S_IO_TGRB_H[x]); |
| 854 | if (tcnt == tgr) |
| 855 | { |
| 856 | verboselog( h8->device->machine(), 9, "TPU %d - tgrb match\n", x); |
| 857 | h8->per_regs[H8S_IO_TSR[x]] |= TSR_TGFB; |
| 858 | if (tier & TIER_TGIEB) |
| 859 | { |
| 860 | h8s2xxx_interrupt_request( h8, H8S_INT_TGIB[x]); |
| 861 | } |
| 862 | if (((tcr >> 5) & TCR_CCLR_AND[x]) == 2) // CCLR 2 -> "TCNT cleared by TGRB compare match/input capture" |
| 863 | { |
| 864 | clear = 1; |
| 865 | } |
| 866 | else |
| 867 | { |
| 868 | tior = h8->per_regs[H8S_IO_TIOR_H[x]]; |
| 869 | h8s_tioc_pin_update( h8, (tior >> 4) & 0x0F, PIN_TIOCB[x]); |
| 870 | } |
| 871 | } |
| 872 | // tgrc |
| 873 | if ((x == 0) || (x == 3)) |
| 874 | { |
| 875 | tgr = ptr_read_16( h8->per_regs + H8S_IO_TGRC_H[x]); |
| 876 | if (tcnt == tgr) |
| 877 | { |
| 878 | verboselog( h8->device->machine(), 9, "TPU %d - tgrc match\n", x); |
| 879 | h8->per_regs[H8S_IO_TSR[x]] |= TSR_TGFC; |
| 880 | if (tier & TIER_TGIEC) |
| 303 | 881 | { |
| 304 | | fatalerror( "TPU: not supported\n"); |
| 882 | h8s2xxx_interrupt_request( h8, H8S_INT_TGIC[x]); |
| 305 | 883 | } |
| 306 | | |
| 307 | | // start |
| 308 | | i = 0; |
| 309 | | tpu->item[i].tgr = 0; |
| 310 | | tpu->item[i].out = (i + 1) & 1; |
| 311 | | tpu->item[i].irq = 0; |
| 312 | | // TGRB |
| 313 | | if (tgrb < tgra) i = 1; else i = 2; |
| 314 | | tpu->item[i].tgr = tgrb; |
| 315 | | tpu->item[i].out = (i + 1) & 1; |
| 316 | | if (tier & 2) tpu->item[i].irq = H8S_INT_TGI1B; else tpu->item[i].irq = 0; |
| 317 | | // TGRA |
| 318 | | if (tgrb < tgra) i = 2; else i = 1; |
| 319 | | tpu->item[i].tgr = tgra; |
| 320 | | tpu->item[i].out = (i + 1) & 1; |
| 321 | | if (tier & 1) tpu->item[i].irq = H8S_INT_TGI1A; else tpu->item[i].irq = 0; |
| 322 | | // ... |
| 323 | | tpu->tgrcur = 0; |
| 324 | | tpu->tgrmax = 2; |
| 325 | | tpu->prescaler = TPSC[ttcr & 7]; |
| 326 | | cycles = tpu->item[1].tgr - tpu->item[0].tgr; |
| 327 | | // ajust timer |
| 328 | | hz = h8->device->unscaled_clock() / (tpu->prescaler * cycles); |
| 329 | | tpu->timer->adjust(attotime::from_hz(hz), num); |
| 330 | | // output |
| 331 | | set_p1dr_tiocb1(h8, tpu->item[0].out); |
| 332 | | // |
| 333 | | tpu->tgrcur++; |
| 884 | if (((tcr >> 5) & TCR_CCLR_AND[x]) == 5) // CCLR 5 -> "TCNT cleared by TGRC compare match/input capture" |
| 885 | { |
| 886 | clear = 1; |
| 887 | } |
| 888 | else |
| 889 | { |
| 890 | tior = h8->per_regs[H8S_IO_TIOR_L[x]]; |
| 891 | h8s_tioc_pin_update( h8, (tior >> 0) & 0x0F, PIN_TIOCC[x]); |
| 892 | } |
| 334 | 893 | } |
| 335 | 894 | } |
| 895 | // tgrd |
| 896 | if ((x == 0) || (x == 3)) |
| 897 | { |
| 898 | tgr = ptr_read_16( h8->per_regs + H8S_IO_TGRD_H[x]); |
| 899 | if (tcnt == tgr) |
| 900 | { |
| 901 | verboselog( h8->device->machine(), 9, "TPU %d - tgrd match\n", x); |
| 902 | h8->per_regs[H8S_IO_TSR[x]] |= TSR_TGFD; |
| 903 | if (tier & TIER_TGIED) |
| 904 | { |
| 905 | h8s2xxx_interrupt_request( h8, H8S_INT_TGID[x]); |
| 906 | } |
| 907 | if (((tcr >> 5) & TCR_CCLR_AND[x]) == 6) // CCLR 6 -> "TCNT cleared by TGRD compare match/input capture" |
| 908 | { |
| 909 | clear = 1; |
| 910 | } |
| 911 | else |
| 912 | { |
| 913 | tior = h8->per_regs[H8S_IO_TIOR_L[x]]; |
| 914 | h8s_tioc_pin_update( h8, (tior >> 4) & 0x0F, PIN_TIOCD[x]); |
| 915 | } |
| 916 | } |
| 917 | } |
| 918 | // ... |
| 919 | if (clear) |
| 920 | { |
| 921 | verboselog( h8->device->machine(), 9, "TPU %d - tcnt clear\n", x); |
| 922 | h8s_tpu_x_tioc_reset( h8, x); |
| 923 | tcnt = 0; |
| 924 | } |
| 925 | // ... |
| 926 | return tcnt; |
| 336 | 927 | } |
| 337 | 928 | |
| 338 | | void h8s_tpu_stop(h83xx_state *h8, int num) |
| 929 | void h8s_tpu_x_callback( h83xx_state *h8, int x) |
| 339 | 930 | { |
| 340 | | h8->tpu[num].timer->adjust(attotime::never, num); |
| 931 | H8S2XXX_TPU *tpu = &h8->tpu[x]; |
| 932 | UINT64 cycles; |
| 933 | UINT16 tcnt; |
| 934 | // calculate tcnt |
| 935 | tcnt = ptr_read_16( h8->per_regs + H8S_IO_TCNT_H[x]); |
| 936 | tcnt = (UINT16)(tcnt + tpu->timer_cycles / tpu->cycles_per_tick); |
| 937 | // ... |
| 938 | tcnt = h8s_tpu_x_tcnt_change( h8, x, tcnt); |
| 939 | // update tcnt |
| 940 | ptr_write_16( h8->per_regs + H8S_IO_TCNT_H[x], tcnt); |
| 941 | // update timer |
| 942 | cycles = h8s_tpu_x_calculate_ticks( h8, x, tcnt) * tpu->cycles_per_tick; |
| 943 | tpu->timer_cycles = cycles; |
| 944 | tpu->timer->adjust(attotime::from_hz(h8->device->unscaled_clock() / cycles), x); |
| 341 | 945 | } |
| 342 | 946 | |
| 343 | | void h8s_tpu_resync(h83xx_state *h8, UINT8 data) |
| 947 | void h8s_tpu_x_tick( h83xx_state *h8, int x) |
| 344 | 948 | { |
| 345 | | if (data & 1) h8s_tpu_start(h8, 0); else h8s_tpu_stop(h8, 0); |
| 346 | | if (data & 2) h8s_tpu_start(h8, 1); else h8s_tpu_stop(h8, 1); |
| 347 | | if (data & 4) h8s_tpu_start(h8, 2); else h8s_tpu_stop(h8, 2); |
| 949 | UINT16 tcnt; |
| 950 | // calculate tcnt |
| 951 | tcnt = ptr_read_16( h8->per_regs + H8S_IO_TCNT_H[x]); |
| 952 | tcnt = (UINT16)(tcnt + 1); |
| 953 | // ... |
| 954 | tcnt = h8s_tpu_x_tcnt_change( h8, x, tcnt); |
| 955 | // update tcnt |
| 956 | ptr_write_16( h8->per_regs + H8S_IO_TCNT_H[x], tcnt); |
| 348 | 957 | } |
| 349 | 958 | |
| 959 | int h8s_tpu_x_get_div( h83xx_state *h8, int x) |
| 960 | { |
| 961 | UINT8 tcr; |
| 962 | int tpsc; |
| 963 | const int *TPU_X_DIV[] = { TPU_0_DIV, TPU_1_DIV, TPU_2_DIV, TPU_3_DIV, TPU_4_DIV, TPU_5_DIV }; |
| 964 | tcr = h8->per_regs[H8S_IO_TTCR[x]]; |
| 965 | tpsc = (tcr >> 0) & 7; |
| 966 | return TPU_X_DIV[x][tpsc]; |
| 967 | } |
| 968 | |
| 969 | void h8s_tpu_x_update( h83xx_state *h8, int x) |
| 970 | { |
| 971 | H8S2XXX_TPU *tpu = &h8->tpu[x]; |
| 972 | // ... |
| 973 | tpu->cycles_per_tick = h8s_tpu_x_get_div( h8, x); |
| 974 | // update timer |
| 975 | if (tpu->cycles_per_tick != 0) |
| 976 | { |
| 977 | UINT16 tcnt; |
| 978 | UINT64 cycles; |
| 979 | tcnt = ptr_read_16( h8->per_regs + H8S_IO_TCNT_H[x]); |
| 980 | cycles = h8s_tpu_x_calculate_ticks( h8, x, tcnt) * tpu->cycles_per_tick; |
| 981 | tpu->timer_cycles = cycles; |
| 982 | tpu->timer->adjust(attotime::from_hz(h8->device->unscaled_clock() / cycles), x); |
| 983 | } |
| 984 | else |
| 985 | { |
| 986 | tpu->timer->reset(); |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | void h8s_tpu_x_start( h83xx_state *h8, int x) |
| 991 | { |
| 992 | verboselog( h8->device->machine(), 5, "TPU %d - start\n", x); |
| 993 | // ... |
| 994 | h8s_tpu_x_update( h8, x); |
| 995 | } |
| 996 | |
| 997 | void h8s_tpu_x_stop( h83xx_state *h8, int x) |
| 998 | { |
| 999 | H8S2XXX_TPU *tpu = &h8->tpu[x]; |
| 1000 | UINT16 tcnt; |
| 1001 | // ... |
| 1002 | verboselog( h8->device->machine(), 5, "TPU %d - stop\n", x); |
| 1003 | // calculate tcnt |
| 1004 | tcnt = h8s_tpu_x_calculate_tcnt( h8, x); |
| 1005 | // update tcnt |
| 1006 | ptr_write_16( h8->per_regs + H8S_IO_TCNT_H[x], tcnt); |
| 1007 | // disable timer |
| 1008 | tpu->timer->reset(); |
| 1009 | } |
| 1010 | |
| 1011 | UINT16 h8s_tpu_x_read_tcnt( h83xx_state *h8, int x) |
| 1012 | { |
| 1013 | return h8s_tpu_x_calculate_tcnt( h8, x); |
| 1014 | } |
| 1015 | |
| 1016 | void h8s_tpu_x_write_tcnt( h83xx_state *h8, int x, UINT16 data) |
| 1017 | { |
| 1018 | H8S2XXX_TPU *tpu = &h8->tpu[x]; |
| 1019 | verboselog( h8->device->machine(), 9, "TPU %d - write tcnt (%04X)\n", x, data); |
| 1020 | ptr_write_16( h8->per_regs + H8S_IO_TCNT_H[x], data); |
| 1021 | if (tpu->timer->enabled()) |
| 1022 | { |
| 1023 | h8s_tpu_x_update( h8, x); |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | void h8s_tpu_x_write_tgr( h83xx_state *h8, int x) |
| 1028 | { |
| 1029 | H8S2XXX_TPU *tpu = &h8->tpu[x]; |
| 1030 | if ((tpu->timer->enabled()) && (tpu->cycles_per_tick != 0)) |
| 1031 | { |
| 1032 | UINT16 tcnt1, tcnt2; |
| 1033 | UINT64 cycles; |
| 1034 | tcnt1 = ptr_read_16( h8->per_regs + H8S_IO_TCNT_H[x]); |
| 1035 | tcnt2 = (UINT16)(tcnt1 + ((device_icount_min_timer_icount1( h8, tpu->timer)) / tpu->cycles_per_tick)); |
| 1036 | cycles = h8s_tpu_x_calculate_ticks( h8, x, tcnt2) * tpu->cycles_per_tick; |
| 1037 | cycles = cycles + (tcnt2 - tcnt1) * tpu->cycles_per_tick; |
| 1038 | tpu->timer_cycles = cycles; |
| 1039 | tpu->timer->adjust(attotime::from_hz(h8->device->unscaled_clock() / cycles), x); |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | void h8s_tpu_x_write_tgra( h83xx_state *h8, int x, UINT16 data) |
| 1044 | { |
| 1045 | verboselog( h8->device->machine(), 9, "TPU %d - write tgra (%04X)\n", x, data); |
| 1046 | ptr_write_16( h8->per_regs + H8S_IO_TGRA_H[x], data); |
| 1047 | h8s_tpu_x_write_tgr( h8, x); |
| 1048 | } |
| 1049 | |
| 1050 | void h8s_tpu_x_write_tgrb( h83xx_state *h8, int x, UINT16 data) |
| 1051 | { |
| 1052 | verboselog( h8->device->machine(), 9, "TPU %d - write tgrb (%04X)\n", x, data); |
| 1053 | ptr_write_16( h8->per_regs + H8S_IO_TGRB_H[x], data); |
| 1054 | h8s_tpu_x_write_tgr( h8, x); |
| 1055 | } |
| 1056 | |
| 1057 | void h8s_tpu_x_write_tgrc( h83xx_state *h8, int x, UINT16 data) |
| 1058 | { |
| 1059 | verboselog( h8->device->machine(), 9, "TPU %d - write tgrc (%04X)\n", x, data); |
| 1060 | ptr_write_16( h8->per_regs + H8S_IO_TGRC_H[x], data); |
| 1061 | h8s_tpu_x_write_tgr( h8, x); |
| 1062 | } |
| 1063 | |
| 1064 | void h8s_tpu_x_write_tgrd( h83xx_state *h8, int x, UINT16 data) |
| 1065 | { |
| 1066 | verboselog( h8->device->machine(), 9, "TPU %d - write tgrd (%04X)\n", x, data); |
| 1067 | ptr_write_16( h8->per_regs + H8S_IO_TGRD_H[x], data); |
| 1068 | h8s_tpu_x_write_tgr( h8, x); |
| 1069 | } |
| 1070 | |
| 1071 | void h8s_tpu_x_write_tior( h83xx_state *h8, int x) |
| 1072 | { |
| 1073 | UINT8 tstr; |
| 1074 | tstr = h8->per_regs[H8S_IO_TSTR]; |
| 1075 | if ((tstr & (1 << x)) == 0) |
| 1076 | { |
| 1077 | h8s_tpu_x_tioc_reset( h8, x); |
| 1078 | } |
| 1079 | } |
| 1080 | |
| 1081 | void h8s_tpu_0_write_tior_h( h83xx_state *h8, UINT8 data) |
| 1082 | { |
| 1083 | h8->per_regs[H8S_IO_TIOR0_H] = data; |
| 1084 | h8s_tpu_x_write_tior( h8, 0); |
| 1085 | } |
| 1086 | |
| 1087 | void h8s_tpu_0_write_tior_l( h83xx_state *h8, UINT8 data) |
| 1088 | { |
| 1089 | h8->per_regs[H8S_IO_TIOR0_L] = data; |
| 1090 | h8s_tpu_x_write_tior( h8, 0); |
| 1091 | } |
| 1092 | |
| 1093 | void h8s_tpu_1_write_tior( h83xx_state *h8, UINT8 data) |
| 1094 | { |
| 1095 | h8->per_regs[H8S_IO_TIOR1] = data; |
| 1096 | h8s_tpu_x_write_tior( h8, 1); |
| 1097 | } |
| 1098 | |
| 1099 | void h8s_tpu_2_write_tior( h83xx_state *h8, UINT8 data) |
| 1100 | { |
| 1101 | h8->per_regs[H8S_IO_TIOR2] = data; |
| 1102 | h8s_tpu_x_write_tior( h8, 2); |
| 1103 | } |
| 1104 | |
| 1105 | void h8s_tpu_3_write_tior_h( h83xx_state *h8, UINT8 data) |
| 1106 | { |
| 1107 | h8->per_regs[H8S_IO_TIOR3_H] = data; |
| 1108 | h8s_tpu_x_write_tior( h8, 3); |
| 1109 | } |
| 1110 | |
| 1111 | void h8s_tpu_3_write_tior_l( h83xx_state *h8, UINT8 data) |
| 1112 | { |
| 1113 | h8->per_regs[H8S_IO_TIOR3_L] = data; |
| 1114 | h8s_tpu_x_write_tior( h8, 3); |
| 1115 | } |
| 1116 | |
| 1117 | void h8s_tpu_4_write_tior( h83xx_state *h8, UINT8 data) |
| 1118 | { |
| 1119 | h8->per_regs[H8S_IO_TIOR4] = data; |
| 1120 | h8s_tpu_x_write_tior( h8, 4); |
| 1121 | } |
| 1122 | |
| 1123 | void h8s_tpu_5_write_tior( h83xx_state *h8, UINT8 data) |
| 1124 | { |
| 1125 | h8->per_regs[H8S_IO_TIOR5] = data; |
| 1126 | h8s_tpu_x_write_tior( h8, 5); |
| 1127 | } |
| 1128 | |
| 1129 | void h8s_tpu_write_tstr( h83xx_state *h8, UINT8 data) |
| 1130 | { |
| 1131 | const int tpu_max = (h8->device->type() == H8S2323) ? 6 : 3; |
| 1132 | UINT8 old_data = h8->per_regs[H8S_IO_TSTR]; |
| 1133 | int i; |
| 1134 | h8->per_regs[H8S_IO_TSTR] = data; |
| 1135 | for (i = 0; i < tpu_max; i++) |
| 1136 | { |
| 1137 | if ((data & (1 << i)) != (old_data & (1 << i))) |
| 1138 | { |
| 1139 | if ((data & (1 << i)) != 0) |
| 1140 | { |
| 1141 | h8s_tpu_x_start( h8, i); |
| 1142 | } |
| 1143 | else |
| 1144 | { |
| 1145 | h8s_tpu_x_stop( h8, i); |
| 1146 | } |
| 1147 | } |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | static TIMER_CALLBACK( h8s_tpu_callback) |
| 1152 | { |
| 1153 | h83xx_state *h8 = (h83xx_state *)ptr; |
| 1154 | h8s_tpu_x_callback( h8, param); |
| 1155 | } |
| 1156 | |
| 350 | 1157 | ///////////////////////////////// |
| 351 | 1158 | // SERIAL CONTROLLER INTERFACE // |
| 352 | 1159 | ///////////////////////////////// |
| r12440 | r12441 | |
| 394 | 1201 | int i; |
| 395 | 1202 | for (i=0;i<3;i++) |
| 396 | 1203 | { |
| 397 | | #ifdef ENABLE_SCI_TIMER |
| 398 | 1204 | h8->sci[i].timer = h8->device->machine().scheduler().timer_alloc(FUNC(h8s_sci_callback), h8); |
| 399 | 1205 | h8->sci[i].timer->adjust(attotime::never, i); |
| 400 | | #endif |
| 401 | 1206 | } |
| 402 | 1207 | } |
| 403 | 1208 | |
| 404 | | #ifdef ENABLE_SCI_TIMER |
| 405 | 1209 | static TIMER_CALLBACK(h8s_sci_callback) |
| 406 | 1210 | { |
| 407 | | // h83xx_state *h8 = (h83xx_state *)ptr; |
| 408 | | _logerror( 2, "h8s_sci_callback (%d)\n", param); |
| 1211 | h83xx_state *h8 = (h83xx_state *)ptr; |
| 1212 | verboselog( h8->device->machine(), 7, "h8s_sci_callback (%d)\n", param); |
| 409 | 1213 | } |
| 410 | | #endif |
| 411 | 1214 | |
| 412 | 1215 | void h8s_sci_start(h83xx_state *h8, int num) |
| 413 | 1216 | { |
| 414 | | #ifdef ENABLE_SCI_TIMER |
| 1217 | #if 0 |
| 415 | 1218 | h8->sci[num].timer->adjust(h8->sci[num].bitrate, num); |
| 416 | 1219 | #endif |
| 417 | 1220 | } |
| 418 | 1221 | |
| 419 | 1222 | void h8s_sci_stop(h83xx_state *h8, int num) |
| 420 | 1223 | { |
| 421 | | #ifdef ENABLE_SCI_TIMER |
| 422 | 1224 | h8->sci[num].timer->adjust(attotime::never, num); |
| 423 | | #endif |
| 424 | 1225 | } |
| 425 | 1226 | |
| 426 | 1227 | void h8s_sci_execute(h83xx_state *h8, int num) |
| r12440 | r12441 | |
| 428 | 1229 | UINT8 scr, tdr, ssr, rdr, tsr, rsr, pdr, port; |
| 429 | 1230 | int i; |
| 430 | 1231 | const H8S_SCI_ENTRY *info = h8s_sci_entry( num); |
| 431 | | // logerror( "h8s_sci_execute(%d)\n", num); |
| 1232 | verboselog( h8->device->machine(), 5, "h8s_sci_execute(%d)\n", num); |
| 432 | 1233 | // load regs |
| 433 | 1234 | scr = h8->per_regs[info->reg_scr]; |
| 434 | 1235 | tdr = h8->per_regs[info->reg_tdr]; |
| r12440 | r12441 | |
| 491 | 1292 | brr = h8->per_regs[info->reg_brr]; |
| 492 | 1293 | scr = h8->per_regs[info->reg_scr]; |
| 493 | 1294 | smr = h8->per_regs[info->reg_smr]; |
| 494 | | _logerror( 2, "BRR %02X SCR %02X SMR %02X\n", brr, scr, smr); |
| 1295 | verboselog( h8->device->machine(), 2, "BRR %02X SCR %02X SMR %02X\n", brr, scr, smr); |
| 495 | 1296 | // calculate bitrate |
| 496 | 1297 | cke = (scr >> 0) & 3; |
| 497 | 1298 | mode = (smr >> 7) & 1; |
| 498 | 1299 | bitrate = (UINT32)((h8->device->unscaled_clock() / (brr + 1)) / (SMR_MODE[mode] * SCR_CKE[cke])); |
| 499 | | _logerror( 2, "SCI%d bitrate %d\n", num, bitrate); |
| 1300 | verboselog( h8->device->machine(), 2, "SCI%d bitrate %d\n", num, bitrate); |
| 500 | 1301 | // store bitrate |
| 501 | | #ifdef ENABLE_SCI_TIMER |
| 502 | 1302 | h8->sci[num].bitrate = bitrate; |
| 503 | | #endif |
| 504 | 1303 | } |
| 505 | 1304 | |
| 506 | 1305 | //////////////////////////// |
| 507 | 1306 | // INTERNAL I/O REGISTERS // |
| 508 | 1307 | //////////////////////////// |
| 509 | 1308 | |
| 510 | | void h8s2xxx_per_regs_w_byte(h83xx_state *h8, int offset, UINT8 data) |
| 1309 | void h8s_onchip_reg_write_8(h83xx_state *h8, int offset, UINT8 data) |
| 511 | 1310 | { |
| 512 | | h8->per_regs[offset] = data; |
| 1311 | verboselog( h8->device->machine(), 9, "%08X | %08X <- %02X\n", h8->ppc, H8S_IO_ADDR(offset), data); |
| 513 | 1312 | switch (offset) |
| 514 | 1313 | { |
| 515 | 1314 | // SCI 0 |
| 516 | | case H8S_IO_SSR0 : if ((data & H8S_SSR_TDRE) == 0) h8s_sci_execute(h8, 0); break; |
| 517 | | case H8S_IO_SCR0 : if (data & H8S_SCR_TIE) h8s2xxx_interrupt_request(h8, h8s_sci_entry(0)->int_tx); break; |
| 518 | | case H8S_IO_BRR0 : h8s_sci_rate(h8, 0); h8s_sci_start(h8, 0); break; |
| 1315 | case H8S_IO_SSR0 : h8->per_regs[offset] = data; if ((data & H8S_SSR_TDRE) == 0) h8s_sci_execute(h8, 0); break; |
| 1316 | case H8S_IO_SCR0 : h8->per_regs[offset] = data; if (data & H8S_SCR_TIE) h8s2xxx_interrupt_request(h8, h8s_sci_entry(0)->int_tx); break; |
| 1317 | case H8S_IO_BRR0 : h8->per_regs[offset] = data; h8s_sci_rate(h8, 0); h8s_sci_start(h8, 0); break; |
| 519 | 1318 | // SCI 1 |
| 520 | | case H8S_IO_SSR1 : if ((data & H8S_SSR_TDRE) == 0) h8s_sci_execute(h8, 1); break; |
| 521 | | case H8S_IO_SCR1 : if (data & H8S_SCR_RIE) h8s2xxx_interrupt_request(h8, h8s_sci_entry(1)->int_rx); break; |
| 522 | | case H8S_IO_BRR1 : h8s_sci_rate(h8, 1); h8s_sci_start(h8, 1); break; |
| 1319 | case H8S_IO_SSR1 : h8->per_regs[offset] = data; if ((data & H8S_SSR_TDRE) == 0) h8s_sci_execute(h8, 1); break; |
| 1320 | case H8S_IO_SCR1 : h8->per_regs[offset] = data; if (data & H8S_SCR_RIE) h8s2xxx_interrupt_request(h8, h8s_sci_entry(1)->int_rx); break; |
| 1321 | case H8S_IO_BRR1 : h8->per_regs[offset] = data; h8s_sci_rate(h8, 1); h8s_sci_start(h8, 1); break; |
| 523 | 1322 | // SCI 2 |
| 524 | | case H8S_IO_SSR2 : if ((data & H8S_SSR_TDRE) == 0) h8s_sci_execute(h8, 2); break; |
| 525 | | case H8S_IO_SCR2 : if (data & H8S_SCR_TIE) h8s2xxx_interrupt_request(h8, h8s_sci_entry(2)->int_tx); break; |
| 526 | | case H8S_IO_BRR2 : h8s_sci_rate(h8, 2); h8s_sci_start(h8, 2); break; |
| 527 | | // TMR 0 (8-bit) |
| 528 | | case H8S_IO_TCR0 : h8s_tmr_resync(h8, 0); break; |
| 529 | | case H8S_IO_TCNT0 : h8s_tmr_resync(h8, 0); break; |
| 1323 | case H8S_IO_SSR2 : h8->per_regs[offset] = data; if ((data & H8S_SSR_TDRE) == 0) h8s_sci_execute(h8, 2); break; |
| 1324 | case H8S_IO_SCR2 : h8->per_regs[offset] = data; if (data & H8S_SCR_TIE) h8s2xxx_interrupt_request(h8, h8s_sci_entry(2)->int_tx); break; |
| 1325 | case H8S_IO_BRR2 : h8->per_regs[offset] = data; h8s_sci_rate(h8, 2); h8s_sci_start(h8, 2); break; |
| 1326 | // TMR 0 |
| 1327 | case H8S_IO_TCR0 : h8s_tmr_x_write_tcr( h8, 0, data); break; |
| 1328 | case H8S_IO_TCNT0 : h8s_tmr_x_write_tcnt( h8, 0, data); break; |
| 1329 | case H8S_IO_TCORA0 : h8s_tmr_x_write_tcora( h8, 0, data); break; |
| 1330 | case H8S_IO_TCORB0 : h8s_tmr_x_write_tcorb( h8, 0, data); break; |
| 530 | 1331 | // TMR 1 |
| 531 | | case H8S_IO_TCR1 : h8s_tmr_resync(h8, 1); break; |
| 532 | | case H8S_IO_TCNT1 : h8s_tmr_resync(h8, 1); break; |
| 1332 | case H8S_IO_TCR1 : h8s_tmr_x_write_tcr( h8, 1, data); break; |
| 1333 | case H8S_IO_TCNT1 : h8s_tmr_x_write_tcnt( h8, 1, data); break; |
| 1334 | case H8S_IO_TCORA1 : h8s_tmr_x_write_tcora( h8, 1, data); break; |
| 1335 | case H8S_IO_TCORB1 : h8s_tmr_x_write_tcorb( h8, 1, data); break; |
| 533 | 1336 | // ports |
| 534 | | case H8S_IO_P3DR : h8->io->write_byte( H8S_IO_ADDR( offset), data); break; |
| 535 | | case H8S_IO_PFDR : h8->io->write_byte( H8S_IO_ADDR( offset), data); break; |
| 536 | | case H8S_IO_PFDDR : h8->io->write_byte( H8S_IO_ADDR( offset), data); break; |
| 1337 | case H8S_IO_P1DR : case H8S_IO_P2DR : case H8S_IO_P3DR : case H8S_IO_P4DR : case H8S_IO_P5DR : |
| 1338 | case H8S_IO_PADR : case H8S_IO_PBDR : case H8S_IO_PCDR : case H8S_IO_PDDR : case H8S_IO_PEDR : |
| 1339 | case H8S_IO_PFDR : h8->per_regs[offset] = data; h8->io->write_byte( H8S_IO_ADDR( offset), data); break; |
| 1340 | // ... |
| 1341 | case H8S_IO_PFDDR : h8->per_regs[offset] = data; h8->io->write_byte( H8S_IO_ADDR( offset), data); break; |
| 537 | 1342 | // TPU |
| 538 | | case H8S_IO_TSTR : h8s_tpu_resync(h8, data); break; |
| 1343 | case H8S_IO_TSTR : h8s_tpu_write_tstr( h8, data); break; |
| 1344 | // DMA |
| 1345 | case H8S_IO_DMABCRL : |
| 1346 | { |
| 1347 | h8->per_regs[offset] = data; |
| 1348 | if (h8->device->type() == H8S2323) |
| 1349 | { |
| 1350 | if ((data & 0x40) && (data & 0x80)) |
| 1351 | { |
| 1352 | UINT32 i, dma_src, dma_dst; |
| 1353 | UINT16 dma_cnt, dma_con; |
| 1354 | int sz; |
| 1355 | dma_src = h8->program->read_dword( H8S_IO_ADDR(H8S_IO_MAR1AH)); |
| 1356 | dma_dst = h8->program->read_dword( H8S_IO_ADDR(H8S_IO_MAR1BH)); |
| 1357 | dma_cnt = h8->program->read_word( H8S_IO_ADDR(H8S_IO_ETCR1A)); |
| 1358 | dma_con = h8->program->read_word( H8S_IO_ADDR(H8S_IO_DMACR1A)); |
| 1359 | sz = (dma_con & 0x8000) ? 2 : 1; |
| 1360 | for (i=0;i<dma_cnt;i++) |
| 1361 | { |
| 1362 | if (dma_con & 0x8000) h8->program->write_word( dma_dst, h8->program->read_word( dma_src)); else h8->program->write_byte( dma_dst, h8->program->read_byte( dma_src)); |
| 1363 | if (dma_con & 0x2000) { if (dma_con & 0x4000) dma_src -= sz; else dma_src += sz; } |
| 1364 | if (dma_con & 0x0020) { if (dma_con & 0x0040) dma_dst -= sz; else dma_dst += sz; } |
| 1365 | } |
| 1366 | h8->per_regs[H8S_IO_DMABCRL] &= ~0x40; |
| 1367 | } |
| 1368 | } |
| 1369 | } |
| 1370 | break; |
| 1371 | // ... |
| 1372 | default : |
| 1373 | { |
| 1374 | h8->per_regs[offset] = data; |
| 1375 | } |
| 1376 | break; |
| 539 | 1377 | } |
| 540 | 1378 | } |
| 541 | 1379 | |
| 542 | | UINT8 h8s2xxx_per_regs_r_byte(h83xx_state *h8, int offset) |
| 1380 | void h8s_onchip_reg_write_16(h83xx_state *h8, int offset, UINT16 data) |
| 543 | 1381 | { |
| 1382 | verboselog( h8->device->machine(), 9, "%08X | %08X <- %04X\n", h8->ppc, H8S_IO_ADDR(offset), data); |
| 1383 | switch (offset) |
| 1384 | { |
| 1385 | // TPU 0 |
| 1386 | case H8S_IO_TCNT0_H : h8s_tpu_x_write_tcnt( h8, 0, data); break; |
| 1387 | case H8S_IO_TGR0A_H : h8s_tpu_x_write_tgra( h8, 0, data); break; |
| 1388 | case H8S_IO_TGR0B_H : h8s_tpu_x_write_tgrb( h8, 0, data); break; |
| 1389 | case H8S_IO_TGR0C_H : h8s_tpu_x_write_tgrc( h8, 0, data); break; |
| 1390 | case H8S_IO_TGR0D_H : h8s_tpu_x_write_tgrd( h8, 0, data); break; |
| 1391 | // TPU 1 |
| 1392 | case H8S_IO_TCNT1_H : h8s_tpu_x_write_tcnt( h8, 1, data); break; |
| 1393 | case H8S_IO_TGR1A_H : h8s_tpu_x_write_tgra( h8, 1, data); break; |
| 1394 | case H8S_IO_TGR1B_H : h8s_tpu_x_write_tgrb( h8, 1, data); break; |
| 1395 | // TPU 2 |
| 1396 | case H8S_IO_TCNT2_H : h8s_tpu_x_write_tcnt( h8, 2, data); break; |
| 1397 | case H8S_IO_TGR2A_H : h8s_tpu_x_write_tgra( h8, 2, data); break; |
| 1398 | case H8S_IO_TGR2B_H : h8s_tpu_x_write_tgrb( h8, 2, data); break; |
| 1399 | // TPU 3 |
| 1400 | case H8S_IO_TCNT3_H : if (h8->device->type() == H8S2323) h8s_tpu_x_write_tcnt( h8, 3, data); break; |
| 1401 | case H8S_IO_TGR3A_H : if (h8->device->type() == H8S2323) h8s_tpu_x_write_tgra( h8, 3, data); break; |
| 1402 | case H8S_IO_TGR3B_H : if (h8->device->type() == H8S2323) h8s_tpu_x_write_tgrb( h8, 3, data); break; |
| 1403 | case H8S_IO_TGR3C_H : if (h8->device->type() == H8S2323) h8s_tpu_x_write_tgrc( h8, 3, data); break; |
| 1404 | case H8S_IO_TGR3D_H : if (h8->device->type() == H8S2323) h8s_tpu_x_write_tgrd( h8, 3, data); break; |
| 1405 | // TPU 4 |
| 1406 | case H8S_IO_TCNT4_H : if (h8->device->type() == H8S2323) h8s_tpu_x_write_tcnt( h8, 4, data); break; |
| 1407 | case H8S_IO_TGR4A_H : if (h8->device->type() == H8S2323) h8s_tpu_x_write_tgra( h8, 4, data); break; |
| 1408 | case H8S_IO_TGR4B_H : if (h8->device->type() == H8S2323) h8s_tpu_x_write_tgrb( h8, 4, data); break; |
| 1409 | // TPU 5 |
| 1410 | case H8S_IO_TCNT5_H : if (h8->device->type() == H8S2323) h8s_tpu_x_write_tcnt( h8, 5, data); break; |
| 1411 | case H8S_IO_TGR5A_H : if (h8->device->type() == H8S2323) h8s_tpu_x_write_tgra( h8, 5, data); break; |
| 1412 | case H8S_IO_TGR5B_H : if (h8->device->type() == H8S2323) h8s_tpu_x_write_tgrb( h8, 5, data); break; |
| 1413 | // ... |
| 1414 | default : |
| 1415 | { |
| 1416 | h8s_onchip_reg_write_8( h8, offset + 0, (data >> 8) & 0xFF); |
| 1417 | h8s_onchip_reg_write_8( h8, offset + 1, (data >> 0) & 0xFF); |
| 1418 | } |
| 1419 | break; |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | UINT8 h8s_onchip_reg_read_8(h83xx_state *h8, int offset) |
| 1424 | { |
| 544 | 1425 | UINT8 data; |
| 545 | 1426 | switch (offset) |
| 546 | 1427 | { |
| r12440 | r12441 | |
| 557 | 1438 | } |
| 558 | 1439 | break; |
| 559 | 1440 | // ports |
| 560 | | case H8S_IO_PORT1 : data = h8->io->read_byte( H8S_IO_ADDR( offset)); break; |
| 1441 | case H8S_IO_PORT1 : case H8S_IO_PORT2 : case H8S_IO_PORT3 : case H8S_IO_PORT4 : case H8S_IO_PORT5 : |
| 1442 | case H8S_IO_PORTA : case H8S_IO_PORTB : case H8S_IO_PORTC : case H8S_IO_PORTD : case H8S_IO_PORTE : |
| 561 | 1443 | case H8S_IO_PORTF : data = h8->io->read_byte( H8S_IO_ADDR( offset)); break; |
| 1444 | // ... |
| 562 | 1445 | case H8S_IO_P3DR : data = 0; break; // todo: without this cybiko hangs |
| 1446 | // TMR 0 |
| 1447 | case H8S_IO_TCNT0 : data = h8s_tmr_x_read_tcnt( h8, 0); break; |
| 1448 | // TMR 1 |
| 1449 | case H8S_IO_TCNT1 : data = h8s_tmr_x_read_tcnt( h8, 1); break; |
| 1450 | // ... |
| 563 | 1451 | // default |
| 564 | 1452 | default : data = h8->per_regs[offset]; break; |
| 565 | 1453 | } |
| 1454 | verboselog( h8->device->machine(), 9, "%08X | %08X -> %02X\n", h8->ppc, H8S_IO_ADDR(offset), data); |
| 566 | 1455 | return data; |
| 567 | 1456 | } |
| 568 | 1457 | |
| 569 | | WRITE8_HANDLER( h8s2241_per_regs_w_byte ) |
| 1458 | UINT16 h8s_onchip_reg_read_16(h83xx_state *h8, int offset) |
| 570 | 1459 | { |
| 571 | | h83xx_state *h8 = get_safe_token(&space->device()); |
| 572 | | _logerror( 3, "[%08X] h8s2241_per_regs_w_byte (%08X/%02X)\n", h8->pc, H8S_IO_ADDR( offset), data); |
| 573 | | h8s2xxx_per_regs_w_byte(h8, offset, data); |
| 1460 | UINT16 data = 0; |
| 1461 | switch (offset) |
| 1462 | { |
| 1463 | case H8S_IO_TCNT0_H : data = h8s_tpu_x_read_tcnt( h8, 0); break; |
| 1464 | case H8S_IO_TCNT1_H : data = h8s_tpu_x_read_tcnt( h8, 1); break; |
| 1465 | case H8S_IO_TCNT2_H : data = h8s_tpu_x_read_tcnt( h8, 2); break; |
| 1466 | case H8S_IO_TCNT3_H : if (h8->device->type() == H8S2323) data = h8s_tpu_x_read_tcnt( h8, 3); break; |
| 1467 | case H8S_IO_TCNT4_H : if (h8->device->type() == H8S2323) data = h8s_tpu_x_read_tcnt( h8, 4); break; |
| 1468 | case H8S_IO_TCNT5_H : if (h8->device->type() == H8S2323) data = h8s_tpu_x_read_tcnt( h8, 5); break; |
| 1469 | default : |
| 1470 | { |
| 1471 | UINT8 b[2]; |
| 1472 | b[0] = h8s_onchip_reg_read_8( h8, offset + 0); |
| 1473 | b[1] = h8s_onchip_reg_read_8( h8, offset + 1); |
| 1474 | data = (b[0] << 8) | (b[1] << 0); |
| 1475 | } |
| 1476 | break; |
| 1477 | } |
| 1478 | verboselog( h8->device->machine(), 9, "%08X | %08X -> %04X\n", h8->ppc, H8S_IO_ADDR(offset), data); |
| 1479 | return data; |
| 574 | 1480 | } |
| 575 | 1481 | |
| 576 | | READ8_HANDLER( h8s2241_per_regs_r_byte ) |
| 1482 | void h8s2241_per_regs_write_8(h83xx_state *h8, int offset, UINT8 data) |
| 577 | 1483 | { |
| 578 | | h83xx_state *h8 = get_safe_token(&space->device()); |
| 579 | | UINT8 data = 0; |
| 580 | | _logerror( 3, "[%08X] h8s2241_per_regs_r_byte (%08X)\n", h8->pc, H8S_IO_ADDR( offset)); |
| 581 | | data = h8s2xxx_per_regs_r_byte(h8, offset); |
| 582 | | _logerror( 3, "%02X\n", data); |
| 583 | | return data; |
| 1484 | h8s_onchip_reg_write_8(h8, offset, data); |
| 584 | 1485 | } |
| 585 | 1486 | |
| 586 | | WRITE8_HANDLER( h8s2246_per_regs_w_byte ) |
| 1487 | UINT8 h8s2241_per_regs_read_8(h83xx_state *h8, int offset) |
| 587 | 1488 | { |
| 588 | | h83xx_state *h8 = get_safe_token(&space->device()); |
| 589 | | _logerror( 3, "[%08X] h8s2246_per_regs_w_byte (%08X/%02X)\n", h8->pc, H8S_IO_ADDR( offset), data); |
| 590 | | h8s2xxx_per_regs_w_byte(h8, offset, data); |
| 1489 | return h8s_onchip_reg_read_8(h8, offset); |
| 591 | 1490 | } |
| 592 | 1491 | |
| 593 | | READ8_HANDLER( h8s2246_per_regs_r_byte ) |
| 1492 | void h8s2241_per_regs_write_16(h83xx_state *h8, int offset, UINT16 data) |
| 594 | 1493 | { |
| 595 | | h83xx_state *h8 = get_safe_token(&space->device()); |
| 596 | | UINT8 data=0; |
| 597 | | _logerror( 3, "[%08X] h8s2246_per_regs_r_byte (%08X)\n", h8->pc, H8S_IO_ADDR( offset)); |
| 598 | | data = h8s2xxx_per_regs_r_byte(h8, offset); |
| 599 | | _logerror( 3, "%02X\n", data); |
| 600 | | return data; |
| 1494 | h8s_onchip_reg_write_16(h8, offset, data); |
| 601 | 1495 | } |
| 602 | 1496 | |
| 603 | | WRITE8_HANDLER( h8s2323_per_regs_w_byte ) |
| 1497 | UINT16 h8s2241_per_regs_read_16(h83xx_state *h8, int offset) |
| 604 | 1498 | { |
| 605 | | h83xx_state *h8 = get_safe_token(&space->device()); |
| 606 | | _logerror( 3, "[%08X] h8s2323_per_regs_w_byte (%08X/%02X)\n", h8->pc, H8S_IO_ADDR( offset), data); |
| 607 | | h8s2xxx_per_regs_w_byte(h8, offset, data); |
| 608 | | switch (offset) |
| 609 | | { |
| 610 | | case H8S_IO_DMABCRL : |
| 611 | | { |
| 612 | | if ((data & 0x40) && (data & 0x80)) |
| 613 | | { |
| 614 | | UINT32 i, dma_src, dma_dst; |
| 615 | | UINT16 dma_cnt, dma_con; |
| 616 | | int sz; |
| 617 | | dma_src = h8->program->read_dword( H8S_IO_ADDR(H8S_IO_MAR1AH)); |
| 618 | | dma_dst = h8->program->read_dword( H8S_IO_ADDR(H8S_IO_MAR1BH)); |
| 619 | | dma_cnt = h8->program->read_word( H8S_IO_ADDR(H8S_IO_ETCR1A)); |
| 620 | | dma_con = h8->program->read_word( H8S_IO_ADDR(H8S_IO_DMACR1A)); |
| 621 | | sz = (dma_con & 0x8000) ? 2 : 1; |
| 622 | | for (i=0;i<dma_cnt;i++) |
| 623 | | { |
| 624 | | if (dma_con & 0x8000) h8->program->write_word( dma_dst, h8->program->read_word( dma_src)); else h8->program->write_byte( dma_dst, h8->program->read_byte( dma_src)); |
| 625 | | if (dma_con & 0x2000) { if (dma_con & 0x4000) dma_src -= sz; else dma_src += sz; } |
| 626 | | if (dma_con & 0x0020) { if (dma_con & 0x0040) dma_dst -= sz; else dma_dst += sz; } |
| 627 | | } |
| 628 | | h8->per_regs[H8S_IO_DMABCRL] &= ~0x40; |
| 629 | | } |
| 630 | | } |
| 631 | | break; |
| 632 | | } |
| 1499 | return h8s_onchip_reg_read_16(h8, offset); |
| 633 | 1500 | } |
| 634 | 1501 | |
| 635 | | READ8_HANDLER( h8s2323_per_regs_r_byte ) |
| 1502 | void h8s2246_per_regs_write_8(h83xx_state *h8, int offset, UINT8 data) |
| 636 | 1503 | { |
| 637 | | h83xx_state *h8 = get_safe_token(&space->device()); |
| 638 | | UINT8 data=0; |
| 639 | | _logerror( 3, "[%08X] h8s2323_per_regs_r_byte (%08X)\n", h8->pc, H8S_IO_ADDR( offset)); |
| 640 | | switch (offset) |
| 641 | | { |
| 642 | | // timer hack for cybiko xtreme (increase timer value after low byte has been read) |
| 643 | | case H8S_IO_TTCNT5 + 1 : |
| 644 | | { |
| 645 | | UINT16 tcnt = (h8->per_regs[H8S_IO_TTCNT5+0] << 8) + (h8->per_regs[H8S_IO_TTCNT5+1] << 0); |
| 646 | | tcnt = tcnt + 1000; |
| 647 | | data = h8->per_regs[offset]; |
| 648 | | h8->per_regs[H8S_IO_TTCNT5+0] = (tcnt >> 8) & 0xFF; |
| 649 | | h8->per_regs[H8S_IO_TTCNT5+1] = (tcnt >> 0) & 0xFF; |
| 650 | | break; |
| 651 | | } |
| 652 | | // skip "recharge the batteries" |
| 653 | | case H8S_IO_PORTA : data = h8->per_regs[offset] | (1 << 6); break; |
| 654 | | // default |
| 655 | | default : data = h8s2xxx_per_regs_r_byte(h8, offset); break; |
| 656 | | } |
| 657 | | _logerror( 3, "%02X\n", data); |
| 658 | | return data; |
| 1504 | h8s_onchip_reg_write_8(h8, offset, data); |
| 659 | 1505 | } |
| 1506 | |
| 1507 | UINT8 h8s2246_per_regs_read_8(h83xx_state *h8, int offset) |
| 1508 | { |
| 1509 | return h8s_onchip_reg_read_8(h8, offset); |
| 1510 | } |
| 1511 | |
| 1512 | void h8s2246_per_regs_write_16(h83xx_state *h8, int offset, UINT16 data) |
| 1513 | { |
| 1514 | h8s_onchip_reg_write_16(h8, offset, data); |
| 1515 | } |
| 1516 | |
| 1517 | UINT16 h8s2246_per_regs_read_16(h83xx_state *h8, int offset) |
| 1518 | { |
| 1519 | return h8s_onchip_reg_read_16(h8, offset); |
| 1520 | } |
| 1521 | |
| 1522 | void h8s2323_per_regs_write_8(h83xx_state *h8, int offset, UINT8 data) |
| 1523 | { |
| 1524 | h8s_onchip_reg_write_8(h8, offset, data); |
| 1525 | } |
| 1526 | |
| 1527 | UINT8 h8s2323_per_regs_read_8(h83xx_state *h8, int offset) |
| 1528 | { |
| 1529 | return h8s_onchip_reg_read_8(h8, offset); |
| 1530 | } |
| 1531 | |
| 1532 | void h8s2323_per_regs_write_16(h83xx_state *h8, int offset, UINT16 data) |
| 1533 | { |
| 1534 | h8s_onchip_reg_write_16(h8, offset, data); |
| 1535 | } |
| 1536 | |
| 1537 | UINT16 h8s2323_per_regs_read_16(h83xx_state *h8, int offset) |
| 1538 | { |
| 1539 | return h8s_onchip_reg_read_16(h8, offset); |
| 1540 | } |