~ubuntu-branches/ubuntu/precise/mame/precise-proposed

« back to all changes in this revision

Viewing changes to src/emu/cpu/h83002/h8speriph.c

  • Committer: Package Import Robot
  • Author(s): Cesare Falco
  • Date: 2011-11-30 18:50:10 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111130185010-02hcxybht1mn082w
Tags: 0.144-0ubuntu1
* New upstream release (LP: #913550)
* mame.install:
  - Added artwork/ images to be used with -effect switch
  - Be more selective with hash/ contents
* contrib/mame.ini: added /usr/share/games/mame/artwork/ to artpath

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
    Hitachi H8S/2xxx MCU peripherals
 
4
 
 
5
    (c) 2001-2007 Tim Schuerewegen
 
6
 
 
7
    H8S/2241
 
8
    H8S/2246
 
9
    H8S/2323
 
10
 
 
11
*/
 
12
 
 
13
#include "emu.h"
 
14
#include "debugger.h"
 
15
#include "h8.h"
 
16
#include "h8priv.h"
 
17
 
 
18
#define VERBOSE_LEVEL ( 0 )
 
19
 
 
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
}
 
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
 
 
286
////////////
 
287
// DTVECR //
 
288
////////////
 
289
 
 
290
#define DTVECR_ADDR(x) (0x400 + (x << 1))
 
291
 
 
292
///////////////
 
293
// MEMCONV.H //
 
294
///////////////
 
295
 
 
296
static TIMER_CALLBACK( h8s_tmr_callback );
 
297
static TIMER_CALLBACK( h8s_tpu_callback );
 
298
static TIMER_CALLBACK( h8s_sci_callback );
 
299
 
 
300
/////////////
 
301
// TIMER.C //
 
302
/////////////
 
303
 
 
304
UINT16 ptr_read_16( void *ptr)
 
305
{
 
306
        return (*(((UINT8*)ptr) + 0) << 8) | (*(((UINT8*)ptr) + 1) << 0);
 
307
}
 
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
 
 
320
void h8s2xxx_interrupt_request(h83xx_state *h8, UINT32 vecnum)
 
321
{
 
322
        UINT8 idx, bit;
 
323
        idx = vecnum >> 5;
 
324
        bit = vecnum & 0x1F;
 
325
        h8->irq_req[idx] |= (1 << bit);
 
326
}
 
327
 
 
328
void h8s_dtce_execute(h83xx_state *h8, UINT32 addr_dtce, UINT8 mask_dtce, UINT32 addr_dtvecr)
 
329
{
 
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;
 
333
        // get dtc info
 
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);
 
345
        // execute
 
346
        if ((dtc_mra & 0x0E) != 0x00) fatalerror("H8S: dtc unsupported MRA %x\n", dtc_mra&0x0e);
 
347
        sz = 1 << (dtc_mra & 0x01);
 
348
        cnt = dtc_cra;
 
349
        for (i=0;i<cnt;i++)
 
350
        {
 
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; }
 
356
        }
 
357
        h8->program->write_byte( addr_dtce, h8->program->read_byte( addr_dtce) & (~mask_dtce));
 
358
}
 
359
 
 
360
void h8s_dtce_check(h83xx_state *h8,  int vecnum)
 
361
{
 
362
        UINT32 dtce = 0;
 
363
        int bit = 0;
 
364
        // get dtce info
 
365
        switch (vecnum)
 
366
        {
 
367
                // DTCEA
 
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;
 
376
                // DTCEB
 
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;
 
384
                // DTCEC
 
385
                case H8S_INT_TGI2A : dtce = H8S_IO_DTCEC; bit = 7; break;
 
386
                case H8S_INT_TGI2B : dtce = H8S_IO_DTCEC; bit = 6; break;
 
387
                // DTCED
 
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;
 
392
                // DTCEE
 
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;
 
397
                // DTCEF
 
398
                case H8S_INT_RXI2  : dtce = H8S_IO_DTCEF; bit = 7; break;
 
399
                case H8S_INT_TXI2  : dtce = H8S_IO_DTCEF; bit = 6; break;
 
400
        }
 
401
        // execute
 
402
        if ((dtce != 0) && (h8->per_regs[dtce] & (1 << bit))) h8s_dtce_execute(h8, H8S_IO_ADDR( dtce), (1 << bit), DTVECR_ADDR( vecnum));
 
403
}
 
404
 
 
405
void h8s_periph_reset(h83xx_state *h8)
 
406
{
 
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);
 
418
}
 
419
 
 
420
/////////////////
 
421
// TIMER 8-BIT //
 
422
/////////////////
 
423
 
 
424
void h8s_tmr_init(h83xx_state *h8)
 
425
{
 
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
}
 
432
 
 
433
void h8s_tmr_x_reset( h83xx_state *h8, int x)
 
434
{
 
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)
 
466
        {
 
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())
 
487
        {
 
488
                tcnt = (UINT8)(tcnt + ((device_icount_min_timer_icount1( h8, tmr->timer)) / tmr->cycles_per_tick));
 
489
        }
 
490
        return tcnt;
 
491
}
 
492
 
 
493
void h8s_tmr_x_start( h83xx_state *h8, int x)
 
494
{
 
495
        verboselog( h8->device->machine(), 5, "TMR %d - start\n", x);
 
496
        // ...
 
497
        h8s_tmr_x_update( h8, x);
 
498
}
 
499
 
 
500
void h8s_tmr_x_stop( h83xx_state *h8, int x)
 
501
{
 
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;
 
510
        // disable timer
 
511
        tmr->timer->reset();
 
512
}
 
513
 
 
514
UINT8 h8s_tmr_x_tcnt_change( h83xx_state *h8, int x, UINT8 tcnt)
 
515
{
 
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)
 
524
        {
 
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
                }
 
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;
 
570
}
 
571
 
 
572
void h8s_tmr_x_callback( h83xx_state *h8, int x)
 
573
{
 
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))
 
595
        {
 
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
                }
 
604
        }
 
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())
 
612
        {
 
613
                h8s_tmr_x_update( h8, x);
 
614
        }
 
615
}
 
616
 
 
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
}
 
632
 
 
633
UINT8 h8s_tmr_x_read_tcnt( h83xx_state *h8, int x)
 
634
{
 
635
        return h8s_tmr_x_calculate_tcnt( h8, x);
 
636
}
 
637
 
 
638
void h8s_tmr_x_write_tcora( h83xx_state *h8, int x, UINT8 data)
 
639
{
 
640
        h8->per_regs[H8S_IO_TCORA[x]] = data;
 
641
        h8s_tmr_x_write_tcor( h8, x);
 
642
}
 
643
 
 
644
void h8s_tmr_x_write_tcorb( h83xx_state *h8, int x, UINT8 data)
 
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
{
 
652
        h83xx_state *h8 = (h83xx_state *)ptr;
 
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++)
 
664
        {
 
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 :
 
726
                {
 
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;
 
732
                }
 
733
                break;
 
734
        }
 
735
}
 
736
 
 
737
int h8s_pin_read( h83xx_state *h8, int pin)
 
738
{
 
739
        switch (pin)
 
740
        {
 
741
                case PIN_TIOCB1 : return (h8->per_regs[H8S_IO_P1DR] & H8S_P1_TIOCB1) ? 1 : 0;
 
742
        }
 
743
        return 0;
 
744
}
 
745
 
 
746
void h8s_tioc_pin_update( h83xx_state *h8, int io, int pin)
 
747
{
 
748
        switch (io)
 
749
        {
 
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)
 
797
                {
 
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
}
 
810
 
 
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)
 
881
                        {
 
882
                                h8s2xxx_interrupt_request( h8, H8S_INT_TGIC[x]);
 
883
                        }
 
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
                        }
 
893
                }
 
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;
 
927
}
 
928
 
 
929
void h8s_tpu_x_callback( h83xx_state *h8, int x)
 
930
{
 
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);
 
945
}
 
946
 
 
947
void h8s_tpu_x_tick( h83xx_state *h8, int x)
 
948
{
 
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);
 
957
}
 
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
 
 
1157
/////////////////////////////////
 
1158
// SERIAL CONTROLLER INTERFACE //
 
1159
/////////////////////////////////
 
1160
 
 
1161
typedef struct
 
1162
{
 
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;
 
1167
} H8S_SCI_ENTRY;
 
1168
 
 
1169
const H8S_SCI_ENTRY H8S_SCI_TABLE[] =
 
1170
{
 
1171
        // SCI 0
 
1172
        {
 
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
 
1177
        },
 
1178
        // SCI 1
 
1179
        {
 
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
 
1184
        },
 
1185
        // SCI 2
 
1186
        {
 
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
 
1191
        }
 
1192
};
 
1193
 
 
1194
const H8S_SCI_ENTRY *h8s_sci_entry( int num)
 
1195
{
 
1196
        return &H8S_SCI_TABLE[num];
 
1197
}
 
1198
 
 
1199
void h8s_sci_init(h83xx_state *h8)
 
1200
{
 
1201
        int i;
 
1202
        for (i=0;i<3;i++)
 
1203
        {
 
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);
 
1206
        }
 
1207
}
 
1208
 
 
1209
static TIMER_CALLBACK(h8s_sci_callback)
 
1210
{
 
1211
        h83xx_state *h8 = (h83xx_state *)ptr;
 
1212
        verboselog( h8->device->machine(), 7, "h8s_sci_callback (%d)\n", param);
 
1213
}
 
1214
 
 
1215
void h8s_sci_start(h83xx_state *h8, int num)
 
1216
{
 
1217
        #if 0
 
1218
        h8->sci[num].timer->adjust(h8->sci[num].bitrate, num);
 
1219
        #endif
 
1220
}
 
1221
 
 
1222
void h8s_sci_stop(h83xx_state *h8, int num)
 
1223
{
 
1224
        h8->sci[num].timer->adjust(attotime::never, num);
 
1225
}
 
1226
 
 
1227
void h8s_sci_execute(h83xx_state *h8, int num)
 
1228
{
 
1229
        UINT8 scr, tdr, ssr, rdr, tsr, rsr, pdr, port;
 
1230
        int i;
 
1231
        const H8S_SCI_ENTRY *info = h8s_sci_entry( num);
 
1232
        verboselog( h8->device->machine(), 5, "h8s_sci_execute(%d)\n", num);
 
1233
        // load regs
 
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];
 
1238
        tsr = 0;
 
1239
        rsr = 0;
 
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)
 
1243
        {
 
1244
                tsr = tdr;
 
1245
                ssr |= H8S_SSR_TDRE;
 
1246
        }
 
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
 
1250
        for (i=0;i<8;i++)
 
1251
        {
 
1252
                // write bit
 
1253
                if (scr & H8S_SCR_TE)
 
1254
                {
 
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);
 
1257
                }
 
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);
 
1261
                // read bit
 
1262
                if (scr & H8S_SCR_RE)
 
1263
                {
 
1264
                        port = h8->io->read_byte(H8S_IO_ADDR( info->reg_port));
 
1265
                        if (port & info->port_mask_rxd) rsr = rsr | (1 << i);
 
1266
                }
 
1267
        }
 
1268
        // move byte from RSR to RDR
 
1269
        if (scr & H8S_SCR_RE)
 
1270
        {
 
1271
                rdr = rsr;
 
1272
                //ssr |= H8S_SSR_RDRF;
 
1273
        }
 
1274
        // generate receive data full interrupt
 
1275
        if ((scr & H8S_SCR_RIE) && (ssr & H8S_SSR_RDRF)) h8s2xxx_interrupt_request(h8, info->int_rx);
 
1276
        // save regs
 
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;
 
1281
}
 
1282
 
 
1283
const double SCR_CKE[] = { 0.5, 2, 8, 32 }; // = 2 ^ ((2 * cke) - 1)
 
1284
const int SMR_MODE[] = { 64, 8 };
 
1285
 
 
1286
void h8s_sci_rate(h83xx_state *h8, int num)
 
1287
{
 
1288
        UINT8 brr, scr, smr, cke, mode;
 
1289
        UINT32 bitrate;
 
1290
        const H8S_SCI_ENTRY *info = h8s_sci_entry( num);
 
1291
        // read regs
 
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);
 
1301
        // store bitrate
 
1302
        h8->sci[num].bitrate = bitrate;
 
1303
}
 
1304
 
 
1305
////////////////////////////
 
1306
// INTERNAL I/O REGISTERS //
 
1307
////////////////////////////
 
1308
 
 
1309
void h8s_onchip_reg_write_8(h83xx_state *h8, int offset, UINT8 data)
 
1310
{
 
1311
        verboselog( h8->device->machine(), 9, "%08X | %08X <- %02X\n", h8->ppc, H8S_IO_ADDR(offset), data);
 
1312
        switch (offset)
 
1313
        {
 
1314
                // SCI 0
 
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;
 
1318
                // SCI 1
 
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;
 
1322
                // SCI 2
 
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;
 
1331
                // TMR 1
 
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;
 
1336
                // ports
 
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;
 
1342
                // TPU
 
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;
 
1377
        }
 
1378
}
 
1379
 
 
1380
void h8s_onchip_reg_write_16(h83xx_state *h8, int offset, UINT16 data)
 
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
{
 
1425
        UINT8 data;
 
1426
        switch (offset)
 
1427
        {
 
1428
                // SCI 0
 
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;
 
1431
                // SCI 1
 
1432
                case H8S_IO_SSR1  : data = H8S_SSR_TDRE | H8S_SSR_TEND; break;
 
1433
                // SCI 2
 
1434
                case H8S_IO_SSR2 :
 
1435
                {
 
1436
                        data = h8->per_regs[offset];
 
1437
                        if (!(h8->per_regs[H8S_IO_SCR2] & H8S_SCR_TE)) data |= H8S_SSR_TDRE;
 
1438
                }
 
1439
                break;
 
1440
                // ports
 
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;
 
1444
                // ...
 
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
                // ...
 
1451
                // default
 
1452
                default : data = h8->per_regs[offset]; break;
 
1453
        }
 
1454
        verboselog( h8->device->machine(), 9, "%08X | %08X -> %02X\n", h8->ppc, H8S_IO_ADDR(offset), data);
 
1455
        return data;
 
1456
}
 
1457
 
 
1458
UINT16 h8s_onchip_reg_read_16(h83xx_state *h8, int offset)
 
1459
{
 
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;
 
1480
}
 
1481
 
 
1482
void h8s2241_per_regs_write_8(h83xx_state *h8, int offset, UINT8 data)
 
1483
{
 
1484
        h8s_onchip_reg_write_8(h8, offset, data);
 
1485
}
 
1486
 
 
1487
UINT8 h8s2241_per_regs_read_8(h83xx_state *h8, int offset)
 
1488
{
 
1489
        return h8s_onchip_reg_read_8(h8, offset);
 
1490
}
 
1491
 
 
1492
void h8s2241_per_regs_write_16(h83xx_state *h8, int offset, UINT16 data)
 
1493
{
 
1494
        h8s_onchip_reg_write_16(h8, offset, data);
 
1495
}
 
1496
 
 
1497
UINT16 h8s2241_per_regs_read_16(h83xx_state *h8, int offset)
 
1498
{
 
1499
        return h8s_onchip_reg_read_16(h8, offset);
 
1500
}
 
1501
 
 
1502
void h8s2246_per_regs_write_8(h83xx_state *h8, int offset, UINT8 data)
 
1503
{
 
1504
        h8s_onchip_reg_write_8(h8, offset, data);
 
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
}