3
Hitachi H8S/2xxx MCU peripherals
5
(c) 2001-2007 Tim Schuerewegen
18
#define VERBOSE_LEVEL ( 0 )
20
INLINE void ATTR_PRINTF(3,4) verboselog( running_machine &machine, int n_level, const char *s_fmt, ...)
22
if (VERBOSE_LEVEL >= n_level)
27
vsprintf( buf, s_fmt, v);
29
logerror( "%s: %s", machine.describe_context( ), buf);
33
const UINT8 H8S_RESET_H8S_IO_224x[0x1C0] = // values from "e602100_h8s2245.pdf"
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
65
const UINT8 H8S_RESET_H8S_IO_2323[0x1C0] = // values from "rej09b0220_h8s2329.pdf"
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
102
#define SSR_TDRE 0x80
103
#define SSR_RDRF 0x40
104
#define SSR_ORER 0x20
107
#define SSR_TEND 0x04
113
#define SMR_STOP 0x08
115
#define SMR_CKS1 0x02
116
#define SMR_CKS0 0x01
118
#define TCSR_CMFB 0x80
119
#define TCSR_CMFA 0x40
120
#define TCSR_OVF 0x20
122
#define TCR_CMIEB 0x80
123
#define TCR_CMIEA 0x40
124
#define TCR_OVIE 0x20
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
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
141
#define DTC_MRA_MD_NORMAL 0
142
#define DTC_MRA_MD_REPEAT 1
143
#define DTC_MRA_MD_BLOCK 2
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
151
#define DTC_MRB_CHNE 0x80
152
#define DTC_MRB_DISEL 0x40
153
#define DTC_MRB_CHNS 0x20
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
164
#define ADCSR_ADF 0x80
165
#define ADCSR_ADIE 0x40
166
#define ADCSR_ADST 0x20
167
#define ADCSR_SCAN 0x10
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
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
195
#define PIN_TCLKA PIN_P12
196
#define PIN_TCLKB PIN_P13
197
#define PIN_TCLKC PIN_P15
198
#define PIN_TCLKD PIN_P17
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
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
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
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 };
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 };
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 };
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 };
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 };
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 };
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 };
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 };
278
const int TCR_CCLR_AND[] = { 7, 3, 3, 7, 3, 3 };
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);
290
#define DTVECR_ADDR(x) (0x400 + (x << 1))
296
static TIMER_CALLBACK( h8s_tmr_callback );
297
static TIMER_CALLBACK( h8s_tpu_callback );
298
static TIMER_CALLBACK( h8s_sci_callback );
304
UINT16 ptr_read_16( void *ptr)
306
return (*(((UINT8*)ptr) + 0) << 8) | (*(((UINT8*)ptr) + 1) << 0);
309
void ptr_write_16( void *ptr, UINT16 data)
311
*(((UINT8*)ptr) + 0) = (data >> 8) & 0xFF;
312
*(((UINT8*)ptr) + 1) = (data >> 0) & 0xFF;
315
int device_icount_min_timer_icount1( h83xx_state *h8, emu_timer *timer)
317
return (timer->elapsed() * h8->device->unscaled_clock()).as_double();
320
void h8s2xxx_interrupt_request(h83xx_state *h8, UINT32 vecnum)
325
h8->irq_req[idx] |= (1 << bit);
328
void h8s_dtce_execute(h83xx_state *h8, UINT32 addr_dtce, UINT8 mask_dtce, UINT32 addr_dtvecr)
330
UINT32 data[3], dtc_vect, dtc_sar, dtc_dar, cnt, i;
331
UINT8 dtc_mra, dtc_mrb, sz;
332
UINT16 dtc_cra, dtc_crb;
334
dtc_vect = 0xFF0000 | h8->program->read_word(addr_dtvecr);
335
data[0] = h8->program->read_dword( dtc_vect + 0);
336
data[1] = h8->program->read_dword( dtc_vect + 4);
337
data[2] = h8->program->read_dword( dtc_vect + 8);
338
dtc_mra = (data[0] >> 24) & 0xFF;
339
dtc_sar = (data[0] >> 0) & 0xFFFFFF;
340
dtc_mrb = (data[1] >> 24) & 0xFF;
341
dtc_dar = (data[1] >> 0) & 0xFFFFFF;
342
dtc_cra = (data[2] >> 16) & 0xFFFF;
343
dtc_crb = (data[2] >> 0) & 0xFFFF;
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);
346
if ((dtc_mra & 0x0E) != 0x00) fatalerror("H8S: dtc unsupported MRA %x\n", dtc_mra&0x0e);
347
sz = 1 << (dtc_mra & 0x01);
351
if (dtc_sar == H8S_IO_ADDR( H8S_IO_RDR1)) h8->program->write_byte( H8S_IO_ADDR( H8S_IO_SSR1), h8->program->read_byte( H8S_IO_ADDR( H8S_IO_SSR1)) & (~H8S_SSR_TDRE));
352
if (dtc_mra & 0x01) h8->program->write_word( dtc_dar, h8->program->read_word( dtc_sar)); else h8->program->write_byte( dtc_dar, h8->program->read_byte( dtc_sar));
353
if (dtc_dar == H8S_IO_ADDR( H8S_IO_TDR0)) h8->program->write_byte( H8S_IO_ADDR( H8S_IO_SSR0), h8->program->read_byte( H8S_IO_ADDR( H8S_IO_SSR0)) & (~H8S_SSR_TDRE));
354
if (dtc_mra & 0x80) { if (dtc_mra & 0x40) dtc_sar -= sz; else dtc_sar += sz; }
355
if (dtc_mra & 0x20) { if (dtc_mra & 0x10) dtc_dar -= sz; else dtc_dar += sz; }
357
h8->program->write_byte( addr_dtce, h8->program->read_byte( addr_dtce) & (~mask_dtce));
360
void h8s_dtce_check(h83xx_state *h8, int vecnum)
368
case H8S_INT_IRQ0 : dtce = H8S_IO_DTCEA; bit = 7; break;
369
case H8S_INT_IRQ1 : dtce = H8S_IO_DTCEA; bit = 6; break;
370
case H8S_INT_IRQ2 : dtce = H8S_IO_DTCEA; bit = 5; break;
371
case H8S_INT_IRQ3 : dtce = H8S_IO_DTCEA; bit = 4; break;
372
case H8S_INT_IRQ4 : dtce = H8S_IO_DTCEA; bit = 3; break;
373
case H8S_INT_IRQ5 : dtce = H8S_IO_DTCEA; bit = 2; break;
374
case H8S_INT_IRQ6 : dtce = H8S_IO_DTCEA; bit = 1; break;
375
case H8S_INT_IRQ7 : dtce = H8S_IO_DTCEA; bit = 0; break;
377
case H8S_INT_ADI : dtce = H8S_IO_DTCEB; bit = 6; break;
378
case H8S_INT_TGI0A : dtce = H8S_IO_DTCEB; bit = 5; break;
379
case H8S_INT_TGI0B : dtce = H8S_IO_DTCEB; bit = 4; break;
380
case H8S_INT_TGI0C : dtce = H8S_IO_DTCEB; bit = 3; break;
381
case H8S_INT_TGI0D : dtce = H8S_IO_DTCEB; bit = 2; break;
382
case H8S_INT_TGI1A : dtce = H8S_IO_DTCEB; bit = 1; break;
383
case H8S_INT_TGI1B : dtce = H8S_IO_DTCEB; bit = 0; break;
385
case H8S_INT_TGI2A : dtce = H8S_IO_DTCEC; bit = 7; break;
386
case H8S_INT_TGI2B : dtce = H8S_IO_DTCEC; bit = 6; break;
388
case H8S_INT_CMIA0 : dtce = H8S_IO_DTCED; bit = 3; break;
389
case H8S_INT_CMIB0 : dtce = H8S_IO_DTCED; bit = 2; break;
390
case H8S_INT_CMIA1 : dtce = H8S_IO_DTCED; bit = 1; break;
391
case H8S_INT_CMIB1 : dtce = H8S_IO_DTCED; bit = 0; break;
393
case H8S_INT_RXI0 : dtce = H8S_IO_DTCEE; bit = 3; break;
394
case H8S_INT_TXI0 : dtce = H8S_IO_DTCEE; bit = 2; break;
395
case H8S_INT_RXI1 : dtce = H8S_IO_DTCEE; bit = 1; break;
396
case H8S_INT_TXI1 : dtce = H8S_IO_DTCEE; bit = 0; break;
398
case H8S_INT_RXI2 : dtce = H8S_IO_DTCEF; bit = 7; break;
399
case H8S_INT_TXI2 : dtce = H8S_IO_DTCEF; bit = 6; break;
402
if ((dtce != 0) && (h8->per_regs[dtce] & (1 << bit))) h8s_dtce_execute(h8, H8S_IO_ADDR( dtce), (1 << bit), DTVECR_ADDR( vecnum));
405
void h8s_periph_reset(h83xx_state *h8)
407
const int tpu_max = (h8->device->type() == H8S2323) ? 6 : 3;
408
if ((h8->device->type() == H8S2241) || (h8->device->type() == H8S2246))
410
memcpy( h8->per_regs, H8S_RESET_H8S_IO_224x, sizeof( h8->per_regs));
412
else if (h8->device->type() == H8S2323)
414
memcpy( h8->per_regs, H8S_RESET_H8S_IO_2323, sizeof( h8->per_regs));
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);
424
void h8s_tmr_init(h83xx_state *h8)
426
for (int i = 0; i < 2; i++)
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);
433
void h8s_tmr_x_reset( h83xx_state *h8, int x)
435
H8S2XXX_TMR *tmr = &h8->tmr[x];
436
tmr->cycles_per_tick = 0;
437
tmr->timer->adjust(attotime::never, x);
440
UINT64 h8s_tmr_x_calculate_ticks( h83xx_state *h8, int x, UINT8 tcnt)
442
UINT64 cycles1, cycles2;
445
if (tcnt == 0) cycles1 = 0xFF + 1; else cycles1 = (UINT8)(0xFF - tcnt + 1);
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;
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;
458
void h8s_tmr_x_update( h83xx_state *h8, int x)
460
H8S2XXX_TMR *tmr = &h8->tmr[x];
464
tcr = h8->per_regs[H8S_IO_TCR[x]];
465
switch ((tcr >> 0) & 7)
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;
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);
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);
481
UINT8 h8s_tmr_x_calculate_tcnt( h83xx_state *h8, int x)
483
H8S2XXX_TMR *tmr = &h8->tmr[x];
485
tcnt = h8->per_regs[H8S_IO_TCNT[x]];
486
if (tmr->timer->enabled())
488
tcnt = (UINT8)(tcnt + ((device_icount_min_timer_icount1( h8, tmr->timer)) / tmr->cycles_per_tick));
493
void h8s_tmr_x_start( h83xx_state *h8, int x)
495
verboselog( h8->device->machine(), 5, "TMR %d - start\n", x);
497
h8s_tmr_x_update( h8, x);
500
void h8s_tmr_x_stop( h83xx_state *h8, int x)
502
H8S2XXX_TMR *tmr = &h8->tmr[x];
505
verboselog( h8->device->machine(), 5, "TMR %d - stop\n", x);
507
tcnt = h8s_tmr_x_calculate_tcnt( h8, x);
509
h8->per_regs[H8S_IO_TCNT[x]] = tcnt;
514
UINT8 h8s_tmr_x_tcnt_change( h83xx_state *h8, int x, UINT8 tcnt)
519
verboselog( h8->device->machine(), 9, "TMR %d - tmr_x_tcnt_change (%02X)\n", x, tcnt);
521
tcr = h8->per_regs[H8S_IO_TCR[x]];
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)
529
h8s2xxx_interrupt_request( h8, H8S_INT_OVI[x]);
533
tcor = h8->per_regs[H8S_IO_TCORA[x]];
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)
540
h8s2xxx_interrupt_request( h8, H8S_INT_CMIA[x]);
542
if (((tcr >> 3) & 3) == 1) // CCLR 1 -> "clear by compare match a"
548
tcor = h8->per_regs[H8S_IO_TCORB[x]];
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)
555
h8s2xxx_interrupt_request( h8, H8S_INT_CMIB[x]);
557
if (((tcr >> 3) & 3) == 2) // CCLR 2 -> "clear by compare match b"
565
verboselog( h8->device->machine(), 5, "TMR %d - tcnt clear\n", x);
572
void h8s_tmr_x_callback( h83xx_state *h8, int x)
574
H8S2XXX_TMR *tmr = &h8->tmr[x];
578
tcnt = h8->per_regs[H8S_IO_TCNT[x]];
579
tcnt = (UINT8)(tcnt + tmr->timer_cycles / tmr->cycles_per_tick);
581
tcnt = h8s_tmr_x_tcnt_change( h8, x, tcnt);
583
h8->per_regs[H8S_IO_TCNT[x]] = tcnt;
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);
590
void h8s_tmr_x_write_tcr( h83xx_state *h8, int x, UINT8 data)
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))
596
if ((data & 0x07) != 0)
598
h8s_tmr_x_start( h8, x);
602
h8s_tmr_x_stop( h8, x);
607
void h8s_tmr_x_write_tcnt( h83xx_state *h8, int x, UINT8 data)
609
H8S2XXX_TMR *tmr = &h8->tmr[x];
610
h8->per_regs[H8S_IO_TCNT[x]] = data;
611
if (tmr->timer->enabled())
613
h8s_tmr_x_update( h8, x);
617
void h8s_tmr_x_write_tcor( h83xx_state *h8, int x)
619
H8S2XXX_TMR *tmr = &h8->tmr[x];
620
if ((tmr->timer->enabled()) && (tmr->cycles_per_tick != 0))
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);
633
UINT8 h8s_tmr_x_read_tcnt( h83xx_state *h8, int x)
635
return h8s_tmr_x_calculate_tcnt( h8, x);
638
void h8s_tmr_x_write_tcora( h83xx_state *h8, int x, UINT8 data)
640
h8->per_regs[H8S_IO_TCORA[x]] = data;
641
h8s_tmr_x_write_tcor( h8, x);
644
void h8s_tmr_x_write_tcorb( h83xx_state *h8, int x, UINT8 data)
646
h8->per_regs[H8S_IO_TCORB[x]] = data;
647
h8s_tmr_x_write_tcor( h8, x);
650
static TIMER_CALLBACK( h8s_tmr_callback)
652
h83xx_state *h8 = (h83xx_state *)ptr;
653
h8s_tmr_x_callback( h8, param);
660
void h8s_tpu_init(h83xx_state *h8)
662
const int tpu_max = (h8->device->type() == H8S2323) ? 6 : 3;
663
for (int i = 0; i < tpu_max; i++)
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);
670
void h8s_tpu_x_reset( h83xx_state *h8, int x)
672
H8S2XXX_TPU *tpu = &h8->tpu[x];
673
tpu->cycles_per_tick = 0;
677
UINT16 h8s_tpu_x_calculate_tcnt( h83xx_state *h8, int x)
679
H8S2XXX_TPU *tpu = &h8->tpu[x];
681
tcnt = ptr_read_16( h8->per_regs + H8S_IO_TCNT_H[x]);
682
if ((tpu->timer->enabled()) && (tpu->cycles_per_tick > 0))
684
tcnt = (UINT16)(tcnt + ((device_icount_min_timer_icount1( h8, tpu->timer)) / tpu->cycles_per_tick));
689
UINT64 h8s_tpu_x_calculate_ticks( h83xx_state *h8, int x, UINT16 tcnt)
691
UINT64 cycles1, cycles2;
694
if (tcnt == 0) cycles1 = 0xFFFF + 1; else cycles1 = (UINT16)(0xFFFF - tcnt + 1);
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;
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;
704
if ((x == 0) || (x == 3))
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;
711
if ((x == 0) || (x == 3))
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;
721
void h8s_pin_write( h83xx_state *h8, int pin, int data)
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;
737
int h8s_pin_read( h83xx_state *h8, int pin)
741
case PIN_TIOCB1 : return (h8->per_regs[H8S_IO_P1DR] & H8S_P1_TIOCB1) ? 1 : 0;
746
void h8s_tioc_pin_update( h83xx_state *h8, int io, int pin)
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;
759
void h8s_tioc_pin_reset( h83xx_state *h8, int io, int pin)
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;
772
void h8s_tpu_x_tioc_reset( h83xx_state *h8, int x)
777
cclr = (h8->per_regs[H8S_IO_TTCR[x]] >> 5) & TCR_CCLR_AND[x];
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]);
783
if ((x == 0) || (x == 3))
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]);
791
void h8s_tpu_x_overflow( h83xx_state *h8, int x)
795
UINT8 tcr = h8->per_regs[H8S_IO_TTCR[1]];
796
if (((tcr >> 0) & 7) == 7)
798
h8s_tpu_x_tick( h8, 1);
803
UINT8 tcr = h8->per_regs[H8S_IO_TTCR[4]];
804
if (((tcr >> 0) & 7) == 7)
806
h8s_tpu_x_tick( h8, 4);
811
UINT16 h8s_tpu_x_tcnt_change( h83xx_state *h8, int x, UINT16 tcnt)
814
UINT8 tcr, tier, tior;
817
verboselog( h8->device->machine(), 9, "TPU %d - tpu_x_tcnt_change (%04X)\n", x, tcnt);
819
tcr = h8->per_regs[H8S_IO_TTCR[x]];
820
tier = h8->per_regs[H8S_IO_TIER[x]];
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)
828
h8s2xxx_interrupt_request( h8, H8S_INT_TCIV[x]);
830
h8s_tpu_x_overflow( h8, x);
833
tgr = ptr_read_16( h8->per_regs + H8S_IO_TGRA_H[x]);
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)
840
h8s2xxx_interrupt_request( h8, H8S_INT_TGIA[x]);
842
if (((tcr >> 5) & TCR_CCLR_AND[x]) == 1) // CCLR 1 -> "TCNT cleared by TGRA compare match/input capture"
848
tior = h8->per_regs[H8S_IO_TIOR_H[x]];
849
h8s_tioc_pin_update( h8, (tior >> 0) & 0x0F, PIN_TIOCA[x]);
853
tgr = ptr_read_16( h8->per_regs + H8S_IO_TGRB_H[x]);
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)
860
h8s2xxx_interrupt_request( h8, H8S_INT_TGIB[x]);
862
if (((tcr >> 5) & TCR_CCLR_AND[x]) == 2) // CCLR 2 -> "TCNT cleared by TGRB compare match/input capture"
868
tior = h8->per_regs[H8S_IO_TIOR_H[x]];
869
h8s_tioc_pin_update( h8, (tior >> 4) & 0x0F, PIN_TIOCB[x]);
873
if ((x == 0) || (x == 3))
875
tgr = ptr_read_16( h8->per_regs + H8S_IO_TGRC_H[x]);
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)
882
h8s2xxx_interrupt_request( h8, H8S_INT_TGIC[x]);
884
if (((tcr >> 5) & TCR_CCLR_AND[x]) == 5) // CCLR 5 -> "TCNT cleared by TGRC compare match/input capture"
890
tior = h8->per_regs[H8S_IO_TIOR_L[x]];
891
h8s_tioc_pin_update( h8, (tior >> 0) & 0x0F, PIN_TIOCC[x]);
896
if ((x == 0) || (x == 3))
898
tgr = ptr_read_16( h8->per_regs + H8S_IO_TGRD_H[x]);
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)
905
h8s2xxx_interrupt_request( h8, H8S_INT_TGID[x]);
907
if (((tcr >> 5) & TCR_CCLR_AND[x]) == 6) // CCLR 6 -> "TCNT cleared by TGRD compare match/input capture"
913
tior = h8->per_regs[H8S_IO_TIOR_L[x]];
914
h8s_tioc_pin_update( h8, (tior >> 4) & 0x0F, PIN_TIOCD[x]);
921
verboselog( h8->device->machine(), 9, "TPU %d - tcnt clear\n", x);
922
h8s_tpu_x_tioc_reset( h8, x);
929
void h8s_tpu_x_callback( h83xx_state *h8, int x)
931
H8S2XXX_TPU *tpu = &h8->tpu[x];
935
tcnt = ptr_read_16( h8->per_regs + H8S_IO_TCNT_H[x]);
936
tcnt = (UINT16)(tcnt + tpu->timer_cycles / tpu->cycles_per_tick);
938
tcnt = h8s_tpu_x_tcnt_change( h8, x, tcnt);
940
ptr_write_16( h8->per_regs + H8S_IO_TCNT_H[x], tcnt);
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);
947
void h8s_tpu_x_tick( h83xx_state *h8, int x)
951
tcnt = ptr_read_16( h8->per_regs + H8S_IO_TCNT_H[x]);
952
tcnt = (UINT16)(tcnt + 1);
954
tcnt = h8s_tpu_x_tcnt_change( h8, x, tcnt);
956
ptr_write_16( h8->per_regs + H8S_IO_TCNT_H[x], tcnt);
959
int h8s_tpu_x_get_div( h83xx_state *h8, int x)
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];
969
void h8s_tpu_x_update( h83xx_state *h8, int x)
971
H8S2XXX_TPU *tpu = &h8->tpu[x];
973
tpu->cycles_per_tick = h8s_tpu_x_get_div( h8, x);
975
if (tpu->cycles_per_tick != 0)
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);
990
void h8s_tpu_x_start( h83xx_state *h8, int x)
992
verboselog( h8->device->machine(), 5, "TPU %d - start\n", x);
994
h8s_tpu_x_update( h8, x);
997
void h8s_tpu_x_stop( h83xx_state *h8, int x)
999
H8S2XXX_TPU *tpu = &h8->tpu[x];
1002
verboselog( h8->device->machine(), 5, "TPU %d - stop\n", x);
1004
tcnt = h8s_tpu_x_calculate_tcnt( h8, x);
1006
ptr_write_16( h8->per_regs + H8S_IO_TCNT_H[x], tcnt);
1008
tpu->timer->reset();
1011
UINT16 h8s_tpu_x_read_tcnt( h83xx_state *h8, int x)
1013
return h8s_tpu_x_calculate_tcnt( h8, x);
1016
void h8s_tpu_x_write_tcnt( h83xx_state *h8, int x, UINT16 data)
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())
1023
h8s_tpu_x_update( h8, x);
1027
void h8s_tpu_x_write_tgr( h83xx_state *h8, int x)
1029
H8S2XXX_TPU *tpu = &h8->tpu[x];
1030
if ((tpu->timer->enabled()) && (tpu->cycles_per_tick != 0))
1032
UINT16 tcnt1, tcnt2;
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);
1043
void h8s_tpu_x_write_tgra( h83xx_state *h8, int x, UINT16 data)
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);
1050
void h8s_tpu_x_write_tgrb( h83xx_state *h8, int x, UINT16 data)
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);
1057
void h8s_tpu_x_write_tgrc( h83xx_state *h8, int x, UINT16 data)
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);
1064
void h8s_tpu_x_write_tgrd( h83xx_state *h8, int x, UINT16 data)
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);
1071
void h8s_tpu_x_write_tior( h83xx_state *h8, int x)
1074
tstr = h8->per_regs[H8S_IO_TSTR];
1075
if ((tstr & (1 << x)) == 0)
1077
h8s_tpu_x_tioc_reset( h8, x);
1081
void h8s_tpu_0_write_tior_h( h83xx_state *h8, UINT8 data)
1083
h8->per_regs[H8S_IO_TIOR0_H] = data;
1084
h8s_tpu_x_write_tior( h8, 0);
1087
void h8s_tpu_0_write_tior_l( h83xx_state *h8, UINT8 data)
1089
h8->per_regs[H8S_IO_TIOR0_L] = data;
1090
h8s_tpu_x_write_tior( h8, 0);
1093
void h8s_tpu_1_write_tior( h83xx_state *h8, UINT8 data)
1095
h8->per_regs[H8S_IO_TIOR1] = data;
1096
h8s_tpu_x_write_tior( h8, 1);
1099
void h8s_tpu_2_write_tior( h83xx_state *h8, UINT8 data)
1101
h8->per_regs[H8S_IO_TIOR2] = data;
1102
h8s_tpu_x_write_tior( h8, 2);
1105
void h8s_tpu_3_write_tior_h( h83xx_state *h8, UINT8 data)
1107
h8->per_regs[H8S_IO_TIOR3_H] = data;
1108
h8s_tpu_x_write_tior( h8, 3);
1111
void h8s_tpu_3_write_tior_l( h83xx_state *h8, UINT8 data)
1113
h8->per_regs[H8S_IO_TIOR3_L] = data;
1114
h8s_tpu_x_write_tior( h8, 3);
1117
void h8s_tpu_4_write_tior( h83xx_state *h8, UINT8 data)
1119
h8->per_regs[H8S_IO_TIOR4] = data;
1120
h8s_tpu_x_write_tior( h8, 4);
1123
void h8s_tpu_5_write_tior( h83xx_state *h8, UINT8 data)
1125
h8->per_regs[H8S_IO_TIOR5] = data;
1126
h8s_tpu_x_write_tior( h8, 5);
1129
void h8s_tpu_write_tstr( h83xx_state *h8, UINT8 data)
1131
const int tpu_max = (h8->device->type() == H8S2323) ? 6 : 3;
1132
UINT8 old_data = h8->per_regs[H8S_IO_TSTR];
1134
h8->per_regs[H8S_IO_TSTR] = data;
1135
for (i = 0; i < tpu_max; i++)
1137
if ((data & (1 << i)) != (old_data & (1 << i)))
1139
if ((data & (1 << i)) != 0)
1141
h8s_tpu_x_start( h8, i);
1145
h8s_tpu_x_stop( h8, i);
1151
static TIMER_CALLBACK( h8s_tpu_callback)
1153
h83xx_state *h8 = (h83xx_state *)ptr;
1154
h8s_tpu_x_callback( h8, param);
1157
/////////////////////////////////
1158
// SERIAL CONTROLLER INTERFACE //
1159
/////////////////////////////////
1163
UINT32 reg_smr, reg_brr, reg_scr, reg_tdr, reg_ssr, reg_rdr;
1164
UINT32 reg_pdr, reg_port;
1165
UINT8 port_mask_sck, port_mask_txd, port_mask_rxd;
1166
UINT8 int_tx, int_rx;
1169
const H8S_SCI_ENTRY H8S_SCI_TABLE[] =
1173
H8S_IO_SMR0, H8S_IO_BRR0, H8S_IO_SCR0, H8S_IO_TDR0, H8S_IO_SSR0, H8S_IO_RDR0,
1174
H8S_IO_P3DR, H8S_IO_PORT3,
1175
H8S_P3_SCK0, H8S_P3_TXD0, H8S_P3_RXD0,
1176
H8S_INT_TXI0, H8S_INT_RXI0
1180
H8S_IO_SMR1, H8S_IO_BRR1, H8S_IO_SCR1, H8S_IO_TDR1, H8S_IO_SSR1, H8S_IO_RDR1,
1181
H8S_IO_P3DR, H8S_IO_PORT3,
1182
H8S_P3_SCK1, H8S_P3_TXD1, H8S_P3_RXD1,
1183
H8S_INT_TXI1, H8S_INT_RXI1
1187
H8S_IO_SMR2, H8S_IO_BRR2, H8S_IO_SCR2, H8S_IO_TDR2, H8S_IO_SSR2, H8S_IO_RDR2,
1188
H8S_IO_P5DR, H8S_IO_PORT5,
1189
H8S_P5_SCK2, H8S_P5_TXD2, H8S_P5_RXD2,
1190
H8S_INT_TXI2, H8S_INT_RXI2
1194
const H8S_SCI_ENTRY *h8s_sci_entry( int num)
1196
return &H8S_SCI_TABLE[num];
1199
void h8s_sci_init(h83xx_state *h8)
1204
h8->sci[i].timer = h8->device->machine().scheduler().timer_alloc(FUNC(h8s_sci_callback), h8);
1205
h8->sci[i].timer->adjust(attotime::never, i);
1209
static TIMER_CALLBACK(h8s_sci_callback)
1211
h83xx_state *h8 = (h83xx_state *)ptr;
1212
verboselog( h8->device->machine(), 7, "h8s_sci_callback (%d)\n", param);
1215
void h8s_sci_start(h83xx_state *h8, int num)
1218
h8->sci[num].timer->adjust(h8->sci[num].bitrate, num);
1222
void h8s_sci_stop(h83xx_state *h8, int num)
1224
h8->sci[num].timer->adjust(attotime::never, num);
1227
void h8s_sci_execute(h83xx_state *h8, int num)
1229
UINT8 scr, tdr, ssr, rdr, tsr, rsr, pdr, port;
1231
const H8S_SCI_ENTRY *info = h8s_sci_entry( num);
1232
verboselog( h8->device->machine(), 5, "h8s_sci_execute(%d)\n", num);
1234
scr = h8->per_regs[info->reg_scr];
1235
tdr = h8->per_regs[info->reg_tdr];
1236
ssr = h8->per_regs[info->reg_ssr];
1237
rdr = h8->per_regs[info->reg_rdr];
1240
pdr = h8->per_regs[info->reg_pdr] & (~info->port_mask_sck);
1241
// move byte from TDR to TSR
1242
if (scr & H8S_SCR_TE)
1245
ssr |= H8S_SSR_TDRE;
1247
// generate transmit data empty interrupt
1248
if ((scr & H8S_SCR_TIE) && (ssr & H8S_SSR_TDRE)) h8s2xxx_interrupt_request(h8, info->int_tx);
1249
// transmit/receive bits
1253
if (scr & H8S_SCR_TE)
1255
if (tsr & (1 << i)) pdr = pdr | info->port_mask_txd; else pdr = pdr & (~info->port_mask_txd);
1256
h8->io->write_byte( H8S_IO_ADDR( info->reg_pdr), pdr);
1258
// clock high to low
1259
h8->io->write_byte( H8S_IO_ADDR( info->reg_pdr), pdr | info->port_mask_sck);
1260
h8->io->write_byte( H8S_IO_ADDR( info->reg_pdr), pdr);
1262
if (scr & H8S_SCR_RE)
1264
port = h8->io->read_byte(H8S_IO_ADDR( info->reg_port));
1265
if (port & info->port_mask_rxd) rsr = rsr | (1 << i);
1268
// move byte from RSR to RDR
1269
if (scr & H8S_SCR_RE)
1272
//ssr |= H8S_SSR_RDRF;
1274
// generate receive data full interrupt
1275
if ((scr & H8S_SCR_RIE) && (ssr & H8S_SSR_RDRF)) h8s2xxx_interrupt_request(h8, info->int_rx);
1277
h8->per_regs[info->reg_scr] = scr;
1278
h8->per_regs[info->reg_tdr] = tdr;
1279
h8->per_regs[info->reg_ssr] = ssr;
1280
h8->per_regs[info->reg_rdr] = rdr;
1283
const double SCR_CKE[] = { 0.5, 2, 8, 32 }; // = 2 ^ ((2 * cke) - 1)
1284
const int SMR_MODE[] = { 64, 8 };
1286
void h8s_sci_rate(h83xx_state *h8, int num)
1288
UINT8 brr, scr, smr, cke, mode;
1290
const H8S_SCI_ENTRY *info = h8s_sci_entry( num);
1292
brr = h8->per_regs[info->reg_brr];
1293
scr = h8->per_regs[info->reg_scr];
1294
smr = h8->per_regs[info->reg_smr];
1295
verboselog( h8->device->machine(), 2, "BRR %02X SCR %02X SMR %02X\n", brr, scr, smr);
1296
// calculate bitrate
1297
cke = (scr >> 0) & 3;
1298
mode = (smr >> 7) & 1;
1299
bitrate = (UINT32)((h8->device->unscaled_clock() / (brr + 1)) / (SMR_MODE[mode] * SCR_CKE[cke]));
1300
verboselog( h8->device->machine(), 2, "SCI%d bitrate %d\n", num, bitrate);
1302
h8->sci[num].bitrate = bitrate;
1305
////////////////////////////
1306
// INTERNAL I/O REGISTERS //
1307
////////////////////////////
1309
void h8s_onchip_reg_write_8(h83xx_state *h8, int offset, UINT8 data)
1311
verboselog( h8->device->machine(), 9, "%08X | %08X <- %02X\n", h8->ppc, H8S_IO_ADDR(offset), data);
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;
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;
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;
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;
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;
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;
1341
case H8S_IO_PFDDR : h8->per_regs[offset] = data; h8->io->write_byte( H8S_IO_ADDR( offset), data); break;
1343
case H8S_IO_TSTR : h8s_tpu_write_tstr( h8, data); break;
1345
case H8S_IO_DMABCRL :
1347
h8->per_regs[offset] = data;
1348
if (h8->device->type() == H8S2323)
1350
if ((data & 0x40) && (data & 0x80))
1352
UINT32 i, dma_src, dma_dst;
1353
UINT16 dma_cnt, dma_con;
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++)
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; }
1366
h8->per_regs[H8S_IO_DMABCRL] &= ~0x40;
1374
h8->per_regs[offset] = data;
1380
void h8s_onchip_reg_write_16(h83xx_state *h8, int offset, UINT16 data)
1382
verboselog( h8->device->machine(), 9, "%08X | %08X <- %04X\n", h8->ppc, H8S_IO_ADDR(offset), data);
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;
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;
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;
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;
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;
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;
1416
h8s_onchip_reg_write_8( h8, offset + 0, (data >> 8) & 0xFF);
1417
h8s_onchip_reg_write_8( h8, offset + 1, (data >> 0) & 0xFF);
1423
UINT8 h8s_onchip_reg_read_8(h83xx_state *h8, int offset)
1429
case H8S_IO_SSR0 : data = H8S_SSR_TDRE | H8S_SSR_TEND; break;
1430
case H8S_IO_RDR0 : data = h8->io->read_byte( H8S_IO_ADDR( offset)); break;
1432
case H8S_IO_SSR1 : data = H8S_SSR_TDRE | H8S_SSR_TEND; break;
1436
data = h8->per_regs[offset];
1437
if (!(h8->per_regs[H8S_IO_SCR2] & H8S_SCR_TE)) data |= H8S_SSR_TDRE;
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 :
1443
case H8S_IO_PORTF : data = h8->io->read_byte( H8S_IO_ADDR( offset)); break;
1445
case H8S_IO_P3DR : data = 0; break; // todo: without this cybiko hangs
1447
case H8S_IO_TCNT0 : data = h8s_tmr_x_read_tcnt( h8, 0); break;
1449
case H8S_IO_TCNT1 : data = h8s_tmr_x_read_tcnt( h8, 1); break;
1452
default : data = h8->per_regs[offset]; break;
1454
verboselog( h8->device->machine(), 9, "%08X | %08X -> %02X\n", h8->ppc, H8S_IO_ADDR(offset), data);
1458
UINT16 h8s_onchip_reg_read_16(h83xx_state *h8, int offset)
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;
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);
1478
verboselog( h8->device->machine(), 9, "%08X | %08X -> %04X\n", h8->ppc, H8S_IO_ADDR(offset), data);
1482
void h8s2241_per_regs_write_8(h83xx_state *h8, int offset, UINT8 data)
1484
h8s_onchip_reg_write_8(h8, offset, data);
1487
UINT8 h8s2241_per_regs_read_8(h83xx_state *h8, int offset)
1489
return h8s_onchip_reg_read_8(h8, offset);
1492
void h8s2241_per_regs_write_16(h83xx_state *h8, int offset, UINT16 data)
1494
h8s_onchip_reg_write_16(h8, offset, data);
1497
UINT16 h8s2241_per_regs_read_16(h83xx_state *h8, int offset)
1499
return h8s_onchip_reg_read_16(h8, offset);
1502
void h8s2246_per_regs_write_8(h83xx_state *h8, int offset, UINT8 data)
1504
h8s_onchip_reg_write_8(h8, offset, data);
1507
UINT8 h8s2246_per_regs_read_8(h83xx_state *h8, int offset)
1509
return h8s_onchip_reg_read_8(h8, offset);
1512
void h8s2246_per_regs_write_16(h83xx_state *h8, int offset, UINT16 data)
1514
h8s_onchip_reg_write_16(h8, offset, data);
1517
UINT16 h8s2246_per_regs_read_16(h83xx_state *h8, int offset)
1519
return h8s_onchip_reg_read_16(h8, offset);
1522
void h8s2323_per_regs_write_8(h83xx_state *h8, int offset, UINT8 data)
1524
h8s_onchip_reg_write_8(h8, offset, data);
1527
UINT8 h8s2323_per_regs_read_8(h83xx_state *h8, int offset)
1529
return h8s_onchip_reg_read_8(h8, offset);
1532
void h8s2323_per_regs_write_16(h83xx_state *h8, int offset, UINT16 data)
1534
h8s_onchip_reg_write_16(h8, offset, data);
1537
UINT16 h8s2323_per_regs_read_16(h83xx_state *h8, int offset)
1539
return h8s_onchip_reg_read_16(h8, offset);